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
88eb83a8
Commit
88eb83a8
authored
Jul 27, 2018
by
bsatyanarayana-nisum-com
Committed by
rbonthala-nisum-com
Jul 27, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
MT-97_3 : SNS :: Update_RoleTable_While_Account_CRUD_operations (#74)
parent
913d2950
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
89 additions
and
41 deletions
+89
-41
AccountRepo.java
src/main/java/com/nisum/mytime/repository/AccountRepo.java
+4
-0
AccountServiceImpl.java
...ain/java/com/nisum/mytime/service/AccountServiceImpl.java
+85
-41
No files found.
src/main/java/com/nisum/mytime/repository/AccountRepo.java
View file @
88eb83a8
package
com
.
nisum
.
mytime
.
repository
;
import
java.util.List
;
import
org.springframework.data.mongodb.repository.MongoRepository
;
import
com.nisum.mytime.model.Account
;
...
...
@@ -9,4 +11,6 @@ public interface AccountRepo extends MongoRepository<Account, String> {
Account
findByAccountName
(
String
accontName
);
Account
findByAccountId
(
String
accountId
);
List
<
Account
>
findByaccountNameAndAccountId
(
String
accountName
,
String
accountId
);
}
\ No newline at end of file
src/main/java/com/nisum/mytime/service/AccountServiceImpl.java
View file @
88eb83a8
...
...
@@ -16,7 +16,6 @@ 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.AccountRepo
;
import
com.nisum.mytime.utils.CommomUtil
;
...
...
@@ -45,8 +44,9 @@ public class AccountServiceImpl implements AccountService {
String
roleId
=
roleInfoService
.
getRole
(
MyTimeUtils
.
ACCOUNT
);
List
<
Account
>
accounts
=
validateAccounts
(
account
.
getAccountName
());
if
(
action
!=
null
&&
action
.
equals
(
MyTimeUtils
.
STRING_N
))
{
//N means adding New Account
List
<
Account
>
accounts
=
validateAccounts
(
account
.
getAccountName
());
if
(
!
accounts
.
isEmpty
()
&&
accounts
.
size
()
>
0
){
response
=
"Account already exist"
;
...
...
@@ -67,47 +67,54 @@ public class AccountServiceImpl implements AccountService {
}
}
}
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
;
}
}
}
if
(
!
accounts
.
isEmpty
()
&&
accounts
.
size
()
>
0
){
response
=
"Account already exist with updated name"
;
}
else
{
List
<
String
>
employeeIds
=
null
;
List
<
Account
>
accountList
=
null
;
List
<
String
>
dmsAddedByUser
=
null
;
List
<
String
>
dmsDeletedByUser
=
null
;
Map
<
String
,
Integer
>
dmsCount
=
new
HashMap
<
String
,
Integer
>();
Account
accountBeforeUpdate
=
accountRepo
.
findByAccountId
(
account
.
getAccountId
());
List
<
String
>
updatedAccDms
=
account
.
getDeliveryManagers
();
List
<
String
>
beforeAccUpdateDms
=
accountBeforeUpdate
.
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
)
{
if
(
dmsCount
.
get
(
empId
)==
1
)
{
//Service call for RoleMapping
roleMappingService
.
deleteRole
(
empId
,
roleId
);
}
}
//account.setStatus(MyTimeUtils.STRING_Y);
account
.
setStatus
(
accountBeforeUpdate
.
getStatus
());
accountResult
=
accountRepo
.
save
(
account
);
roleMappingService
.
saveUniqueEmployeeAndRole
(
dmsAddedByUser
,
roleId
);
response
=
"Updated succesfully"
;
}
for
(
String
empId
:
dmsDeletedByUser
)
{
int
occurrences
=
Collections
.
frequency
(
accountEmpIds
,
empId
);
if
(
occurrences
==
1
)
{
//Service call for RoleMapping
roleMappingService
.
deleteRole
(
empId
,
roleId
);
}
}
account
.
setStatus
(
MyTimeUtils
.
STRING_Y
);
accountResult
=
accountRepo
.
save
(
account
);
response
=
"Updated succesfully"
;
}
return
response
;
}
...
...
@@ -168,11 +175,40 @@ public class AccountServiceImpl implements AccountService {
// updating the status to "InActive".
public
Account
deleteAccount
(
String
accountId
)
throws
MyTimeException
{
int
occurrences
=
0
;
List
<
Account
>
accountsList
=
null
;
List
<
String
>
accountDms
=
null
;
List
<
String
>
accountsDms
=
new
ArrayList
<
String
>();
String
roleId
=
roleInfoService
.
getRole
(
MyTimeUtils
.
ACCOUNT
);
accountsList
=
accountRepo
.
findAll
();
List
<
String
>
deletedAccountDms
=
accountRepo
.
findByAccountId
(
accountId
).
getDeliveryManagers
();
for
(
Account
account
:
accountsList
)
{
accountDms
=
account
.
getDeliveryManagers
();
for
(
String
accountDm:
accountDms
)
accountsDms
.
add
(
accountDm
);
accountDms
=
null
;
}
for
(
String
dmId
:
deletedAccountDms
)
{
occurrences
=
Collections
.
frequency
(
accountsDms
,
dmId
);
if
(
occurrences
==
1
)
{
//Service call for RoleMapping
roleMappingService
.
deleteRole
(
dmId
,
roleId
);
}
}
Query
query
=
new
Query
(
Criteria
.
where
(
MyTimeUtils
.
ACCOUNT_ID
).
is
(
accountId
));
Update
update
=
new
Update
();
update
.
set
(
MyTimeUtils
.
STATUS
,
MyTimeUtils
.
STRING_N
);
FindAndModifyOptions
options
=
new
FindAndModifyOptions
();
options
.
upsert
(
true
);
return
mongoTemplate
.
findAndModify
(
query
,
update
,
options
,
Account
.
class
);
}
...
...
@@ -181,5 +217,13 @@ public class AccountServiceImpl implements AccountService {
private
String
generateAccountId
()
throws
MyTimeException
{
return
(
MyTimeUtils
.
ACC
+
MyTimeUtils
.
ZERO_
)
+
(
getAccounts
().
size
()
+
MyTimeUtils
.
ONE
);
}
private
boolean
duplicateCheck
(
String
accountName
,
String
accountId
){
boolean
check
=
false
;
List
<
Account
>
accountList
=
accountRepo
.
findByaccountNameAndAccountId
(
accountName
,
accountId
);
if
(
accountList
.
size
()>
0
)
check
=
true
;
return
check
;
}
}
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