Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
mytime
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Narendar Vakiti
mytime
Commits
88dd77ec
Commit
88dd77ec
authored
May 22, 2019
by
Md Suleman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Updated validation for adding new allocation and corrected previos logic
parent
2c553eb6
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
9 deletions
+35
-9
ResourceController.java
.../java/com/nisum/myteam/controller/ResourceController.java
+2
-0
ResourceService.java
...n/java/com/nisum/myteam/service/impl/ResourceService.java
+33
-9
No files found.
src/main/java/com/nisum/myteam/controller/ResourceController.java
View file @
88dd77ec
...
...
@@ -50,11 +50,13 @@ public class ResourceController {
if
(
resourceService
.
validateBillingStartEndDateAgainstProjectStartEndDate
(
resourceAllocationReq
,
loginEmpId
))
{
if
(
resourceService
.
validateBillingStartDateAgainstDOJ
(
resourceAllocationReq
))
{
if
(!
resourceService
.
isResourceAssignedToAnyProject
(
resourceAllocationReq
))
{
if
(
resourceService
.
validateAllocationAgainstPrevAllocation
(
resourceAllocationReq
))
{
Resource
resourcePersisted
=
resourceService
.
addResource
(
resourceAllocationReq
,
loginEmpId
);
ResponseDetails
createResponseDetails
=
new
ResponseDetails
(
new
Date
(),
800
,
"Resource has been created"
,
"Resource description"
,
null
,
request
.
getContextPath
(),
"details"
,
resourcePersisted
);
return
new
ResponseEntity
<
ResponseDetails
>(
createResponseDetails
,
HttpStatus
.
OK
);
}
}
}
}
...
...
src/main/java/com/nisum/myteam/service/impl/ResourceService.java
View file @
88dd77ec
...
...
@@ -50,19 +50,26 @@ public class ResourceService implements IResourceService {
public
HashMap
<
String
,
Object
>
respMap
=
new
HashMap
<>();
private
Resource
getLatestAllocation
(
List
<
Resource
>
resourceAllocList
){
Resource
latestAlloc
=
resourceAllocList
.
get
(
0
);
for
(
Resource
resource:
resourceAllocList
){
if
(
latestAlloc
.
getBillingEndDate
().
before
(
resource
.
getBillingEndDate
()))
latestAlloc
=
resource
;
}
return
latestAlloc
;
}
public
Resource
addResource
(
Resource
resourceReq
,
String
loginEmpId
)
throws
MyTeamException
{
List
<
Resource
>
resourceAllocList
=
resourceRepo
.
findByEmployeeIdAndProjectId
(
resourceReq
.
getEmployeeId
(),
resourceReq
.
getProjectId
());
//
List
<
Resource
>
resourceListWithLatestRecord
=
resourceAllocList
.
stream
().
filter
(
res
->
res
.
getBillingEndDate
().
compareTo
(
new
Date
())
>=
0
).
collect
(
Collectors
.
toList
());
if
(
resourceListWithLatestRecord
!=
null
&&
resourceListWithLatestRecord
.
size
()
>
0
)
{
Resource
resourcePrev
=
resourceListWithLatestRecord
.
get
(
0
);
if
(
resourcePrev
.
getBillingEndDate
().
compareTo
(
new
Date
())
==
0
)
{
resourcePrev
.
setBillingEndDate
(
new
Date
());
Resource
prevAllocation
=
this
.
getLatestAllocation
(
resourceAllocList
);
if
(
prevAllocation
!=
null
)
{
if
(
prevAllocation
.
getBillingEndDate
().
compareTo
(
new
Date
())
==
0
)
{
prevAllocation
.
setBillingEndDate
(
new
Date
());
}
else
{
resourcePrev
.
setBillingEndDate
(
MyTeamDateUtils
.
getDayLessThanDate
(
resourceReq
.
getBillingStartDate
()));
//adding resource.
prevAllocation
.
setBillingEndDate
(
MyTeamDateUtils
.
getDayLessThanDate
(
resourceReq
.
getBillingStartDate
()));
//adding resource.
}
this
.
updateExistedResource
(
resourcePrev
);
this
.
updateExistedResource
(
prevAllocation
);
}
return
resourceRepo
.
save
(
resourceReq
);
}
...
...
@@ -142,7 +149,24 @@ public class ResourceService implements IResourceService {
respMap
.
put
(
"resourceObj"
,
resourcePers
);
}
public
boolean
validateAllocationAgainstPrevAllocation
(
Resource
resourceReq
){
boolean
isValid
=
true
;
List
<
Resource
>
resourceAllocList
=
resourceRepo
.
findByEmployeeIdAndProjectId
(
resourceReq
.
getEmployeeId
(),
resourceReq
.
getProjectId
());
Resource
prevAllocation
=
this
.
getLatestAllocation
(
resourceAllocList
);
if
(
prevAllocation
!=
null
)
{
if
(!
prevAllocation
.
getBillingStartDate
().
before
(
resourceReq
.
getBillingStartDate
())){
respMap
.
put
(
"statusCode"
,
811
);
respMap
.
put
(
"message"
,
"Billing start date should be after previous allocation start date"
);
isValid
=
false
;
}
if
(
prevAllocation
.
getBillableStatus
().
equalsIgnoreCase
(
resourceReq
.
getBillableStatus
())){
respMap
.
put
(
"statusCode"
,
811
);
respMap
.
put
(
"message"
,
"Resource is already in "
+
prevAllocation
.
getBillableStatus
()+
" status only"
);
isValid
=
false
;
}
}
return
isValid
;
}
public
boolean
validateBillingStartEndDateAgainstProjectStartEndDate
(
Resource
resource
,
String
loginEmpId
)
throws
MyTeamException
{
boolean
isValid
=
true
;
...
...
@@ -209,7 +233,7 @@ public class ResourceService implements IResourceService {
if
(
resourceListWithLatestRecord
!=
null
&&
resourceListWithLatestRecord
.
size
()
>
0
)
{
Resource
resourcePrev
=
resourceListWithLatestRecord
.
get
(
0
);
//latest resource record.
if
(!
resourcePrev
.
getProjectId
().
equalsIgnoreCase
(
MyTeamUtils
.
BENCH_PROJECT_ID
))
{
if
(!
resourcePrev
.
getProjectId
().
equalsIgnoreCase
(
MyTeamUtils
.
BENCH_PROJECT_ID
)
&&
!
resourceReq
.
getProjectId
().
equalsIgnoreCase
(
resourcePrev
.
getProjectId
())
)
{
message
=
"Resource "
+
resourcePrev
.
getEmployeeId
()
+
" already Assigned to the "
+
projectService
.
getProjectByProjectId
(
resourcePrev
.
getProjectId
()).
getProjectName
()
+
" Project"
+
" from "
+
resourcePrev
.
getBillingStartDate
()
+
"to "
+
resourcePrev
.
getBillingEndDate
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment