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
b46b0f61
Commit
b46b0f61
authored
Jul 25, 2018
by
bsatyanarayana-nisum-com
Committed by
tdutta-nisum-com
Jul 25, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
MT-97 : SNS :: Update_RoleTable_While_Account_CRUD_operations (#56)
parent
4a9f9aa5
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
144 additions
and
80 deletions
+144
-80
AccountController.java
...n/java/com/nisum/mytime/controller/AccountController.java
+6
-39
Account.java
src/main/java/com/nisum/mytime/model/Account.java
+6
-2
AccountRepo.java
src/main/java/com/nisum/mytime/repository/AccountRepo.java
+1
-0
AccountService.java
src/main/java/com/nisum/mytime/service/AccountService.java
+4
-4
AccountServiceImpl.java
...ain/java/com/nisum/mytime/service/AccountServiceImpl.java
+97
-12
DomainServiceImpl.java
...main/java/com/nisum/mytime/service/DomainServiceImpl.java
+3
-23
CommomUtil.java
src/main/java/com/nisum/mytime/utils/CommomUtil.java
+27
-0
No files found.
src/main/java/com/nisum/mytime/controller/AccountController.java
View file @
b46b0f61
...
...
@@ -4,7 +4,6 @@ import java.util.ArrayList;
import
java.util.List
;
import
java.util.Map
;
import
org.apache.commons.lang.StringUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.MediaType
;
...
...
@@ -17,9 +16,8 @@ import org.springframework.web.bind.annotation.RequestParam;
import
org.springframework.web.bind.annotation.RestController
;
import
com.nisum.mytime.exception.handler.MyTimeException
;
import
com.nisum.mytime.model.Account
Info
;
import
com.nisum.mytime.model.Account
;
import
com.nisum.mytime.service.AccountServiceImpl
;
import
com.nisum.mytime.utils.MyTimeUtils
;
@RestController
@RequestMapping
(
"/account"
)
...
...
@@ -30,43 +28,12 @@ public class AccountController {
@RequestMapping
(
value
=
"/accounts"
,
method
=
RequestMethod
.
POST
,
produces
=
MediaType
.
TEXT_PLAIN_VALUE
,
consumes
=
MediaType
.
APPLICATION_JSON_VALUE
)
public
ResponseEntity
<
String
>
addAccount
(
@RequestBody
AccountInfo
accountInfo
,
@RequestParam
(
value
=
"action"
)
String
action
)
throws
MyTimeException
{
String
response
=
""
;
AccountInfo
account
=
null
;
if
(
action
!=
null
&&
action
.
equals
(
"N"
))
{
List
<
AccountInfo
>
acounts
=
accountServiceImpl
.
validateAccounts
(
accountInfo
.
getAccountName
());
if
(
!
acounts
.
isEmpty
()
&&
acounts
.
size
()
>
0
){
response
=
"Account already exist"
;
}
else
{
accountInfo
.
setAccountId
(
generateAccountId
());
accountInfo
.
setStatus
(
MyTimeUtils
.
ACTIVE
);
account
=
accountServiceImpl
.
addAccount
(
accountInfo
);
if
(
account
.
getId
()
!=
null
)
{
response
=
"saved Succesfully"
;
}
else
{
response
=
"Error occured while Account creating"
;
}
}
}
else
if
(
action
!=
null
&&
action
.
equals
(
"U"
)){
accountInfo
.
setStatus
(
MyTimeUtils
.
ACTIVE
);
account
=
accountServiceImpl
.
addAccount
(
accountInfo
);
response
=
"updated Succesfully"
;
}
public
ResponseEntity
<
String
>
addAccount
(
@RequestBody
Account
account
,
@RequestParam
(
value
=
"action"
)
String
action
)
throws
MyTimeException
{
String
response
=
accountServiceImpl
.
addAccount
(
account
,
action
);
return
new
ResponseEntity
<>(
response
,
HttpStatus
.
OK
);
}
// generating the account id.
// accountId format is "Acc001"
private
String
generateAccountId
()
throws
MyTimeException
{
return
(
MyTimeUtils
.
ACC
+
MyTimeUtils
.
ZERO_
)
+
(
accountServiceImpl
.
getAccounts
().
size
()
+
MyTimeUtils
.
ONE
);
}
@RequestMapping
(
value
=
"/accounts"
,
method
=
RequestMethod
.
GET
,
produces
=
MediaType
.
APPLICATION_JSON_VALUE
)
public
ResponseEntity
<
List
<
Map
<
Object
,
Object
>>>
getAccounts
()
throws
MyTimeException
{
List
<
Map
<
Object
,
Object
>>
acounts
=
accountServiceImpl
.
getAccountsList
();
...
...
@@ -75,9 +42,9 @@ public class AccountController {
@RequestMapping
(
value
=
"/accountNames"
,
method
=
RequestMethod
.
GET
,
produces
=
MediaType
.
APPLICATION_JSON_VALUE
)
public
ResponseEntity
<
List
<
String
>>
getAccountNames
()
throws
MyTimeException
{
List
<
Account
Info
>
acounts
=
accountServiceImpl
.
getAccounts
();
List
<
Account
>
acounts
=
accountServiceImpl
.
getAccounts
();
List
<
String
>
accountNames
=
new
ArrayList
<>();
for
(
Account
Info
account
:
acounts
)
{
for
(
Account
account
:
acounts
)
{
accountNames
.
add
(
account
.
getAccountName
());
}
return
new
ResponseEntity
<>(
accountNames
,
HttpStatus
.
OK
);
...
...
@@ -93,7 +60,7 @@ public class AccountController {
@RequestMapping
(
value
=
"/accounts/{accountName}"
,
method
=
RequestMethod
.
GET
,
produces
=
MediaType
.
TEXT_PLAIN_VALUE
)
public
ResponseEntity
<
String
>
validateAccounts
(
@PathVariable
(
"accountName"
)
String
accountName
)
throws
MyTimeException
{
String
response
=
""
;
List
<
Account
Info
>
acounts
=
accountServiceImpl
.
validateAccounts
(
accountName
);
List
<
Account
>
acounts
=
accountServiceImpl
.
validateAccounts
(
accountName
);
if
(
acounts
.
size
()>
0
){
response
=
"Account already exist"
;
}
...
...
src/main/java/com/nisum/mytime/model/Account.java
View file @
b46b0f61
...
...
@@ -29,7 +29,11 @@ public class Account implements Serializable {
private
String
accountName
;
private
int
accountProjectSequence
;
private
String
status
;
private
String
domain
;
List
<
String
>
subDomains
;
//private String domain;
//List<String> subDomains;
private
String
clientAddress
;
private
String
industryType
;
private
List
<
String
>
deliveryManagers
;
}
src/main/java/com/nisum/mytime/repository/AccountRepo.java
View file @
b46b0f61
...
...
@@ -7,4 +7,5 @@ import com.nisum.mytime.model.Account;
public
interface
AccountRepo
extends
MongoRepository
<
Account
,
String
>
{
Account
findByAccountName
(
String
accontName
);
Account
findByAccountId
(
String
accountId
);
}
\ No newline at end of file
src/main/java/com/nisum/mytime/service/AccountService.java
View file @
b46b0f61
...
...
@@ -4,16 +4,16 @@ import java.util.List;
import
java.util.Map
;
import
com.nisum.mytime.exception.handler.MyTimeException
;
import
com.nisum.mytime.model.Account
Info
;
import
com.nisum.mytime.model.Account
;
public
interface
AccountService
{
AccountInfo
addAccount
(
AccountInfo
account
)
throws
MyTimeException
;
String
addAccount
(
Account
account
,
String
action
)
throws
MyTimeException
;
List
<
Account
Info
>
getAccounts
()
throws
MyTimeException
;
List
<
Account
>
getAccounts
()
throws
MyTimeException
;
List
<
Map
<
Object
,
Object
>>
getAccountsList
()
throws
MyTimeException
;
List
<
Account
Info
>
validateAccounts
(
String
accountName
)
throws
MyTimeException
;
List
<
Account
>
validateAccounts
(
String
accountName
)
throws
MyTimeException
;
}
src/main/java/com/nisum/mytime/service/AccountServiceImpl.java
View file @
b46b0f61
package
com
.
nisum
.
mytime
.
service
;
import
java.util.ArrayList
;
import
java.util.Collections
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
...
...
@@ -14,9 +15,11 @@ import org.springframework.data.mongodb.core.query.Update;
import
org.springframework.stereotype.Service
;
import
com.nisum.mytime.exception.handler.MyTimeException
;
import
com.nisum.mytime.model.Account
;
import
com.nisum.mytime.model.AccountInfo
;
import
com.nisum.mytime.model.EmployeeRoles
;
import
com.nisum.mytime.repository.AccountInfoRepo
;
import
com.nisum.mytime.repository.AccountRepo
;
import
com.nisum.mytime.utils.CommomUtil
;
import
com.nisum.mytime.utils.MyTimeUtils
;
@Service
...
...
@@ -26,15 +29,91 @@ public class AccountServiceImpl implements AccountService {
private
MongoTemplate
mongoTemplate
;
@Autowired
private
AccountInfoRepo
accountRepo
;
private
AccountRepo
accountRepo
;
@Autowired
private
RoleInfoService
roleInfoService
;
@Autowired
private
RoleMappingService
roleMappingService
;
@Override
public
AccountInfo
addAccount
(
AccountInfo
account
)
throws
MyTimeException
{
return
accountRepo
.
save
(
account
);
public
String
addAccount
(
Account
account
,
String
action
)
throws
MyTimeException
{
String
response
=
""
;
Account
accountResult
=
null
;
String
roleId
=
roleInfoService
.
getRole
(
MyTimeUtils
.
ACCOUNT
);
if
(
action
!=
null
&&
action
.
equals
(
"N"
))
{
//N means adding New Account
List
<
Account
>
accounts
=
validateAccounts
(
account
.
getAccountName
());
if
(
!
accounts
.
isEmpty
()
&&
accounts
.
size
()
>
0
){
response
=
"Account already exist"
;
}
else
{
List
<
String
>
accDms
=
account
.
getDeliveryManagers
();
account
.
setAccountId
(
generateAccountId
());
account
.
setStatus
(
MyTimeUtils
.
ACTIVE
);
accountResult
=
accountRepo
.
save
(
account
);
if
(
accDms
!=
null
&&
!
accDms
.
isEmpty
()
&&
accDms
.
size
()
>
0
)
{
roleMappingService
.
saveUniqueEmployeeAndRole
(
accDms
,
roleId
);
}
if
(
accountResult
.
getId
()
!=
null
)
{
response
=
"Saved succesfully"
;
}
else
{
response
=
"Error occured while account creating"
;
}
}
}
else
if
(
action
!=
null
&&
action
.
equals
(
"U"
)){
//U means updating existing Account
List
<
String
>
employeeIds
=
null
;
List
<
Account
>
accountList
=
null
;
List
<
String
>
dmsAddedByUser
=
null
;
List
<
String
>
dmsDeletedByUser
=
null
;
List
<
String
>
accountEmpIds
=
new
ArrayList
<
String
>();
Map
<
String
,
Integer
>
dmsCount
=
new
HashMap
<
String
,
Integer
>();
List
<
String
>
updatedAccDms
=
account
.
getDeliveryManagers
();
List
<
String
>
beforeAccUpdateDms
=
accountRepo
.
findByAccountId
(
account
.
getAccountId
()).
getDeliveryManagers
();
dmsAddedByUser
=
CommomUtil
.
getAddedManagersList
(
beforeAccUpdateDms
,
updatedAccDms
);
dmsDeletedByUser
=
CommomUtil
.
getDeletedManagersList
(
beforeAccUpdateDms
,
updatedAccDms
);
accountList
=
accountRepo
.
findAll
();
if
(
accountList
!=
null
&&
!
accountList
.
isEmpty
()
&&
accountList
.
size
()
>
0
)
{
for
(
Account
acc
:
accountList
)
{
employeeIds
=
acc
.
getDeliveryManagers
();
if
(
employeeIds
!=
null
&&
!
employeeIds
.
isEmpty
()
&&
employeeIds
.
size
()
>
0
)
{
for
(
String
eId:
employeeIds
)
{
if
(
dmsCount
.
get
(
eId
)!=
null
)
dmsCount
.
put
(
eId
,
dmsCount
.
get
(
eId
)+
1
);
else
dmsCount
.
put
(
eId
,
1
);
employeeIds
=
null
;
}
}
}
}
for
(
String
empId
:
dmsDeletedByUser
)
{
int
occurrences
=
Collections
.
frequency
(
accountEmpIds
,
empId
);
if
(
occurrences
==
1
)
{
//Service call for RoleMapping
roleMappingService
.
deleteRole
(
empId
,
roleId
);
}
}
account
.
setStatus
(
MyTimeUtils
.
ACTIVE
);
accountResult
=
accountRepo
.
save
(
account
);
response
=
"Updated succesfully"
;
}
return
response
;
}
@Override
public
List
<
Account
Info
>
getAccounts
()
throws
MyTimeException
{
public
List
<
Account
>
getAccounts
()
throws
MyTimeException
{
return
accountRepo
.
findAll
();
}
...
...
@@ -42,7 +121,7 @@ public class AccountServiceImpl implements AccountService {
public
List
<
Map
<
Object
,
Object
>>
getAccountsList
()
throws
MyTimeException
{
List
<
Map
<
Object
,
Object
>>
updatedAccountList
=
new
ArrayList
<>();
List
<
Map
<
String
,
String
>>
updatedEmployeeList
=
null
;
for
(
Account
Info
account
:
accountRepo
.
findAll
())
{
for
(
Account
account
:
accountRepo
.
findAll
())
{
updatedEmployeeList
=
new
ArrayList
<>();
for
(
EmployeeRoles
employeesRole
:
getEmployeeDetails
(
account
))
{
updatedEmployeeList
.
add
(
getEmployeeDetails
(
employeesRole
));
...
...
@@ -53,15 +132,15 @@ public class AccountServiceImpl implements AccountService {
}
@Override
public
List
<
Account
Info
>
validateAccounts
(
String
accountName
)
throws
MyTimeException
{
public
List
<
Account
>
validateAccounts
(
String
accountName
)
throws
MyTimeException
{
List
<
Account
Info
>
accountList
=
mongoTemplate
.
find
(
new
Query
(
Criteria
.
where
(
MyTimeUtils
.
ACCOUNT_NAME
).
is
(
accountName
.
trim
())),
AccountInfo
.
class
);
List
<
Account
>
accountList
=
mongoTemplate
.
find
(
new
Query
(
Criteria
.
where
(
MyTimeUtils
.
ACCOUNT_NAME
).
is
(
accountName
.
trim
())),
Account
.
class
);
return
accountList
;
}
// fetching the employee details using employeeId.
private
List
<
EmployeeRoles
>
getEmployeeDetails
(
Account
Info
account
)
{
private
List
<
EmployeeRoles
>
getEmployeeDetails
(
Account
account
)
{
List
<
EmployeeRoles
>
employeeRoles
=
mongoTemplate
.
find
(
new
Query
(
Criteria
.
where
(
MyTimeUtils
.
EMPLOYEE_ID
).
in
(
account
.
getDeliveryManagers
())),
EmployeeRoles
.
class
);
...
...
@@ -75,7 +154,7 @@ public class AccountServiceImpl implements AccountService {
return
employeeDetails
;
}
private
Map
<
Object
,
Object
>
getAccuntDetails
(
Account
Info
account
,
List
<
Map
<
String
,
String
>>
updatedEmployeeList
)
{
private
Map
<
Object
,
Object
>
getAccuntDetails
(
Account
account
,
List
<
Map
<
String
,
String
>>
updatedEmployeeList
)
{
Map
<
Object
,
Object
>
accountDetails
=
new
HashMap
<>();
accountDetails
.
put
(
MyTimeUtils
.
ID_
,
account
.
getId
());
accountDetails
.
put
(
MyTimeUtils
.
ACCOUNT_ID
,
account
.
getAccountId
());
...
...
@@ -88,13 +167,19 @@ public class AccountServiceImpl implements AccountService {
}
// updating the status to "InActive".
public
Account
Info
deleteAccount
(
String
accountId
)
throws
MyTimeException
{
public
Account
deleteAccount
(
String
accountId
)
throws
MyTimeException
{
Query
query
=
new
Query
(
Criteria
.
where
(
MyTimeUtils
.
ACCOUNT_ID
).
is
(
accountId
));
Update
update
=
new
Update
();
update
.
set
(
MyTimeUtils
.
STATUS
,
MyTimeUtils
.
IN_ACTIVE
);
FindAndModifyOptions
options
=
new
FindAndModifyOptions
();
options
.
upsert
(
true
);
return
mongoTemplate
.
findAndModify
(
query
,
update
,
options
,
AccountInfo
.
class
);
return
mongoTemplate
.
findAndModify
(
query
,
update
,
options
,
Account
.
class
);
}
// generating the account id.
// accountId format is "Acc001"
private
String
generateAccountId
()
throws
MyTimeException
{
return
(
MyTimeUtils
.
ACC
+
MyTimeUtils
.
ZERO_
)
+
(
getAccounts
().
size
()
+
MyTimeUtils
.
ONE
);
}
}
src/main/java/com/nisum/mytime/service/DomainServiceImpl.java
View file @
b46b0f61
...
...
@@ -20,7 +20,7 @@ import com.nisum.mytime.model.AccountInfo;
import
com.nisum.mytime.model.Domains
;
import
com.nisum.mytime.model.EmployeeRoles
;
import
com.nisum.mytime.repository.DomainRepo
;
import
com.nisum.mytime.utils.CommomUtil
;
import
com.nisum.mytime.utils.MyTimeUtils
;
...
...
@@ -126,8 +126,8 @@ public class DomainServiceImpl implements DomainService {
if
(
null
!=
domainDetailsFromDb
)
deliveryManagersListFromDb
=
domainDetailsFromDb
.
getDeliveryManagers
();
managersAddedByUser
=
getAddedManagersList
(
deliveryManagersListFromDb
,
deliveryManagersListFromUser
);
managersDeletedByUser
=
getDeletedManagersList
(
deliveryManagersListFromDb
,
deliveryManagersListFromUser
);
managersAddedByUser
=
CommomUtil
.
getAddedManagersList
(
deliveryManagersListFromDb
,
deliveryManagersListFromUser
);
managersDeletedByUser
=
CommomUtil
.
getDeletedManagersList
(
deliveryManagersListFromDb
,
deliveryManagersListFromUser
);
domainList
=
domainRepo
.
findAll
();
String
roleId
=
roleInfoService
.
getRole
(
MyTimeUtils
.
DOMAIN
);
...
...
@@ -190,24 +190,4 @@ public class DomainServiceImpl implements DomainService {
return
selectedDomain
.
get
(
0
);
return
null
;
}
private
List
<
String
>
getAddedManagersList
(
List
<
String
>
fromDb
,
List
<
String
>
fromUser
)
{
List
<
String
>
addedManagers
=
new
ArrayList
<
String
>();
if
(
fromDb
!=
null
)
for
(
String
managerFromUser
:
fromUser
)
{
if
(!
fromDb
.
contains
(
managerFromUser
))
addedManagers
.
add
(
managerFromUser
);
}
return
addedManagers
;
}
private
List
<
String
>
getDeletedManagersList
(
List
<
String
>
fromDb
,
List
<
String
>
fromUser
)
{
List
<
String
>
deletedManager
=
new
ArrayList
<
String
>();
if
(
fromDb
!=
null
)
for
(
String
managerFromDb
:
fromDb
)
{
if
(!
fromUser
.
contains
(
managerFromDb
))
deletedManager
.
add
(
managerFromDb
);
}
return
deletedManager
;
}
}
\ No newline at end of file
src/main/java/com/nisum/mytime/utils/CommomUtil.java
0 → 100644
View file @
b46b0f61
package
com
.
nisum
.
mytime
.
utils
;
import
java.util.ArrayList
;
import
java.util.List
;
public
class
CommomUtil
{
public
static
List
<
String
>
getAddedManagersList
(
List
<
String
>
fromDb
,
List
<
String
>
fromUser
)
{
List
<
String
>
addedManagers
=
new
ArrayList
<
String
>();
if
(
fromDb
!=
null
)
for
(
String
managerFromUser
:
fromUser
)
{
if
(!
fromDb
.
contains
(
managerFromUser
))
addedManagers
.
add
(
managerFromUser
);
}
return
addedManagers
;
}
public
static
List
<
String
>
getDeletedManagersList
(
List
<
String
>
fromDb
,
List
<
String
>
fromUser
)
{
List
<
String
>
deletedManager
=
new
ArrayList
<
String
>();
if
(
fromDb
!=
null
)
for
(
String
managerFromDb
:
fromDb
)
{
if
(!
fromUser
.
contains
(
managerFromDb
))
deletedManager
.
add
(
managerFromDb
);
}
return
deletedManager
;
}
}
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