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
35ed81fb
Commit
35ed81fb
authored
Jul 23, 2018
by
Vijay Chaitanya
Committed by
rbonthala-nisum-com
Jul 23, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update code changes (#44)
parent
6be98c57
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
92 additions
and
47 deletions
+92
-47
DomainController.java
...in/java/com/nisum/mytime/controller/DomainController.java
+7
-27
DomainService.java
src/main/java/com/nisum/mytime/service/DomainService.java
+3
-4
DomainServiceImpl.java
...main/java/com/nisum/mytime/service/DomainServiceImpl.java
+82
-16
No files found.
src/main/java/com/nisum/mytime/controller/DomainController.java
View file @
35ed81fb
...
@@ -33,23 +33,12 @@ public class DomainController {
...
@@ -33,23 +33,12 @@ public class DomainController {
@Autowired
@Autowired
private
DomainService
domainService
;
private
DomainService
domainService
;
@RequestMapping
(
value
=
"/domains"
,
method
=
RequestMethod
.
POST
,
produces
=
MediaType
.
TEXT_PLAIN_VALUE
,
consumes
=
MediaType
.
APPLICATION_JSON_VALUE
)
@RequestMapping
(
value
=
"/domains"
,
method
=
RequestMethod
.
POST
,
produces
=
MediaType
.
TEXT_PLAIN_VALUE
,
consumes
=
MediaType
.
APPLICATION_JSON_VALUE
)
public
ResponseEntity
<
String
>
addDomain
(
@RequestBody
Domains
domains
)
public
ResponseEntity
<
String
>
addDomain
(
@RequestBody
Domains
domains
)
throws
MyTimeException
{
throws
MyTimeException
{
String
response
=
null
;
String
response
=
null
;
if
(
StringUtils
.
isEmpty
(
domains
.
getDomainId
()))
{
response
=
domainService
.
addDomains
(
domains
);
domains
.
setDomainId
(
generateDomainId
());
return
new
ResponseEntity
<>(
response
,
HttpStatus
.
OK
);
}
domains
.
setStatus
(
MyTimeUtils
.
ACTIVE
);
if
(
domains
.
getId
()==
null
){
response
=
"saved Succesfully"
;
}
else
{
response
=
"updated Succesfully"
;
}
domainService
.
addDomain
(
domains
);
return
new
ResponseEntity
<>(
response
,
HttpStatus
.
OK
);
}
}
@RequestMapping
(
value
=
"/domains"
,
method
=
RequestMethod
.
GET
,
produces
=
MediaType
.
APPLICATION_JSON_VALUE
)
@RequestMapping
(
value
=
"/domains"
,
method
=
RequestMethod
.
GET
,
produces
=
MediaType
.
APPLICATION_JSON_VALUE
)
...
@@ -64,18 +53,9 @@ public class DomainController {
...
@@ -64,18 +53,9 @@ public class DomainController {
}
}
@RequestMapping
(
value
=
"/domains/{domainName}/{accountName}"
,
method
=
RequestMethod
.
GET
,
produces
=
MediaType
.
TEXT_PLAIN_VALUE
)
@RequestMapping
(
value
=
"/domains"
,
method
=
RequestMethod
.
PUT
,
produces
=
MediaType
.
TEXT_PLAIN_VALUE
)
public
ResponseEntity
<
String
>
validateDomain
(
@PathVariable
(
"domainName"
)
String
domainName
,
@PathVariable
(
"accountName"
)
String
accountName
)
throws
MyTimeException
{
public
ResponseEntity
<
String
>
updateDomain
(
@RequestBody
Domains
domains
)
throws
MyTimeException
{
String
response
=
null
;
domainService
.
updateDomain
(
domains
);
List
<
Domains
>
domainList
=
domainService
.
validateDomains
(
domainName
,
accountName
);
return
new
ResponseEntity
<>(
"Domain updated successfully"
,
HttpStatus
.
OK
);
if
(
domainList
.
size
()>
0
)
{
}
response
=
"Record already exists"
;
}
return
new
ResponseEntity
<>(
response
,
HttpStatus
.
OK
);
}
private
String
generateDomainId
()
throws
MyTimeException
{
return
(
MyTimeUtils
.
DOM
+
MyTimeUtils
.
ZERO_
)
+
(
domainService
.
getAllDomains
().
size
()
+
1
);
}
}
}
\ No newline at end of file
src/main/java/com/nisum/mytime/service/DomainService.java
View file @
35ed81fb
...
@@ -13,12 +13,11 @@ import com.nisum.mytime.model.Domains;
...
@@ -13,12 +13,11 @@ import com.nisum.mytime.model.Domains;
*/
*/
public
interface
DomainService
{
public
interface
DomainService
{
Domains
addDomain
(
Domains
d
)
throws
MyTimeException
;
String
addDomains
(
Domains
d
)
throws
MyTimeException
;
List
<
HashMap
<
Object
,
Object
>>
getAllDomains
()
throws
MyTimeException
;
List
<
HashMap
<
Object
,
Object
>>
getAllDomains
()
throws
MyTimeException
;
WriteResult
deleteDomain
(
String
i
d
)
throws
MyTimeException
;
String
updateDomain
(
Domains
d
)
throws
MyTimeException
;
List
<
Domains
>
validateDomains
(
String
domainName
,
String
accountName
)
throws
MyTimeException
;
WriteResult
deleteDomain
(
String
id
)
throws
MyTimeException
;
}
}
src/main/java/com/nisum/mytime/service/DomainServiceImpl.java
View file @
35ed81fb
package
com
.
nisum
.
mytime
.
service
;
package
com
.
nisum
.
mytime
.
service
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.Collections
;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.List
;
...
@@ -10,6 +11,7 @@ import org.springframework.data.mongodb.core.query.Criteria;
...
@@ -10,6 +11,7 @@ import org.springframework.data.mongodb.core.query.Criteria;
import
org.springframework.data.mongodb.core.query.Query
;
import
org.springframework.data.mongodb.core.query.Query
;
import
org.springframework.data.mongodb.core.query.Update
;
import
org.springframework.data.mongodb.core.query.Update
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
org.springframework.util.StringUtils
;
import
com.mongodb.WriteResult
;
import
com.mongodb.WriteResult
;
import
com.nisum.mytime.exception.handler.MyTimeException
;
import
com.nisum.mytime.exception.handler.MyTimeException
;
...
@@ -36,11 +38,39 @@ public class DomainServiceImpl implements DomainService {
...
@@ -36,11 +38,39 @@ public class DomainServiceImpl implements DomainService {
@Autowired
@Autowired
private
MongoTemplate
mongoTemplate
;
private
MongoTemplate
mongoTemplate
;
@Autowired
private
RoleInfoService
roleInfoService
;
@Autowired
private
RoleMappingService
roleMappingService
;
@Override
@Override
public
Domains
addDomain
(
Domains
d
)
throws
MyTimeException
{
public
String
addDomains
(
Domains
d
)
throws
MyTimeException
{
return
domainRepo
.
save
(
d
);
String
response
=
null
;
}
List
<
Domains
>
domainList
=
domainRepo
.
findByDomainNameAndAccountName
(
d
.
getDomainName
(),
d
.
getAccountName
());
if
(
domainList
.
size
()>
0
)
{
response
=
"Domain already exists"
;
return
response
;
}
if
(
StringUtils
.
isEmpty
(
d
.
getDomainId
())
&&
d
.
getId
()==
null
)
{
d
.
setDomainId
((
MyTimeUtils
.
DOM
+
MyTimeUtils
.
ZERO_
)
+
(
getAllDomains
().
size
()
+
1
));
}
d
.
setStatus
(
MyTimeUtils
.
ACTIVE
);
if
(
d
.
getId
()==
null
){
response
=
"Domain saved succesfully"
;
}
else
{
response
=
"Domain updated succesfully"
;
}
domainRepo
.
save
(
d
);
String
roleId
=
roleInfoService
.
getRole
(
MyTimeUtils
.
DOMAIN
);
roleMappingService
.
saveUniqueEmployeeAndRole
(
d
.
getDeliveryManagers
(),
roleId
);
return
response
;
}
@Override
@Override
public
List
<
HashMap
<
Object
,
Object
>>
getAllDomains
()
throws
MyTimeException
{
public
List
<
HashMap
<
Object
,
Object
>>
getAllDomains
()
throws
MyTimeException
{
...
@@ -72,21 +102,57 @@ public class DomainServiceImpl implements DomainService {
...
@@ -72,21 +102,57 @@ public class DomainServiceImpl implements DomainService {
}
}
return
updatedDomainList
;
return
updatedDomainList
;
}
}
@Override
public
String
updateDomain
(
Domains
d
)
throws
MyTimeException
{
String
response
=
null
;
List
<
String
>
domEmpIds
=
new
ArrayList
<
String
>();
List
<
String
>
updatedEmpIds
=
new
ArrayList
<
String
>();
domainList
=
domainRepo
.
findAll
();
String
roleId
=
roleInfoService
.
getRole
(
MyTimeUtils
.
DOMAIN
);
for
(
Domains
domain
:
domainList
)
{
List
<
String
>
employeeIds
=
domain
.
getDeliveryManagers
();
for
(
String
eIds:
employeeIds
)
domEmpIds
.
add
(
eIds
);
}
d
.
setStatus
(
MyTimeUtils
.
ACTIVE
);
domainRepo
.
save
(
d
);
Query
selectedDomainQuery
=
new
Query
(
Criteria
.
where
(
MyTimeUtils
.
DOMAIN_ID
).
in
(
d
.
getDomainId
()).
and
(
MyTimeUtils
.
STATUS
).
in
(
MyTimeUtils
.
ACTIVE
)
);
List
<
Domains
>
selectedDomain
=
mongoTemplate
.
find
(
selectedDomainQuery
,
Domains
.
class
);
for
(
String
empId
:
selectedDomain
.
get
(
0
).
getDeliveryManagers
())
{
int
occurrences
=
Collections
.
frequency
(
domEmpIds
,
empId
);
if
(
occurrences
==
0
)
{
//roleMappingService.saveUniqueEmployeeAndRole(empId, roleId);
updatedEmpIds
.
add
(
empId
);
}
}
roleMappingService
.
saveUniqueEmployeeAndRole
(
updatedEmpIds
,
roleId
);
return
response
;
}
@Override
@Override
public
WriteResult
deleteDomain
(
String
id
)
throws
MyTimeException
{
public
WriteResult
deleteDomain
(
String
id
)
throws
MyTimeException
{
Query
query
=
new
Query
(
Criteria
.
where
(
MyTimeUtils
.
DOMAIN_ID
).
is
(
id
));
List
<
String
>
domEmpIds
=
new
ArrayList
<
String
>();
Update
update
=
new
Update
();
String
roleId
=
roleInfoService
.
getRole
(
MyTimeUtils
.
DOMAIN
);
domainList
=
domainRepo
.
findAll
();
Query
selectedDomainQuery
=
new
Query
(
Criteria
.
where
(
MyTimeUtils
.
DOMAIN_ID
).
in
(
id
).
and
(
MyTimeUtils
.
STATUS
).
in
(
MyTimeUtils
.
ACTIVE
)
);
List
<
Domains
>
selectedDomain
=
mongoTemplate
.
find
(
selectedDomainQuery
,
Domains
.
class
);
for
(
Domains
domain
:
domainList
)
{
List
<
String
>
employeeIds
=
domain
.
getDeliveryManagers
();
for
(
String
eIds:
employeeIds
)
domEmpIds
.
add
(
eIds
);
}
for
(
String
empId
:
selectedDomain
.
get
(
0
).
getDeliveryManagers
())
{
int
occurrences
=
Collections
.
frequency
(
domEmpIds
,
empId
);
if
(
occurrences
==
1
)
{
//Service call for RoleMapping
roleMappingService
.
deleteRole
(
empId
,
roleId
);
}
}
Update
update
=
new
Update
();
update
.
set
(
MyTimeUtils
.
STATUS
,
MyTimeUtils
.
IN_ACTIVE
);
update
.
set
(
MyTimeUtils
.
STATUS
,
MyTimeUtils
.
IN_ACTIVE
);
return
mongoTemplate
.
upsert
(
q
uery
,
update
,
Domains
.
class
);
return
mongoTemplate
.
upsert
(
selectedDomainQ
uery
,
update
,
Domains
.
class
);
}
}
@Override
public
List
<
Domains
>
validateDomains
(
String
domainName
,
String
accountName
)
throws
MyTimeException
{
List
<
Domains
>
domainList
=
domainRepo
.
findByDomainNameAndAccountName
(
domainName
,
accountName
);
return
domainList
;
}
}
}
\ No newline at end of file
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