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
5263cbac
Commit
5263cbac
authored
Jul 18, 2018
by
sakoju-nisum-com
Committed by
rbonthala-nisum-com
Jul 18, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
MT-77 and MT-81: saving and fetching the account details (#19)
parent
85e930bd
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
244 additions
and
3 deletions
+244
-3
AccountController.java
...n/java/com/nisum/mytime/controller/AccountController.java
+69
-0
AccountInfo.java
src/main/java/com/nisum/mytime/model/AccountInfo.java
+36
-0
AccountInfoRepo.java
...ain/java/com/nisum/mytime/repository/AccountInfoRepo.java
+10
-0
AccountService.java
src/main/java/com/nisum/mytime/service/AccountService.java
+17
-0
AccountServiceImpl.java
...ain/java/com/nisum/mytime/service/AccountServiceImpl.java
+99
-0
MyTimeUtils.java
src/main/java/com/nisum/mytime/utils/MyTimeUtils.java
+13
-3
No files found.
src/main/java/com/nisum/mytime/controller/AccountController.java
0 → 100644
View file @
5263cbac
package
com
.
nisum
.
mytime
.
controller
;
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
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMethod
;
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.AccountInfo
;
import
com.nisum.mytime.service.AccountServiceImpl
;
import
com.nisum.mytime.utils.MyTimeUtils
;
@RestController
@RequestMapping
(
"/account"
)
public
class
AccountController
{
@Autowired
private
AccountServiceImpl
accountServiceImpl
;
@RequestMapping
(
value
=
"/addAccount"
,
method
=
RequestMethod
.
POST
,
produces
=
MediaType
.
APPLICATION_JSON_VALUE
,
consumes
=
MediaType
.
APPLICATION_JSON_VALUE
)
public
ResponseEntity
<
AccountInfo
>
addAccount
(
@RequestBody
AccountInfo
accountInfo
)
throws
MyTimeException
{
if
(
StringUtils
.
isEmpty
(
accountInfo
.
getAccountId
()))
{
accountInfo
.
setAccountId
(
getAccountId
());
}
accountInfo
.
setStatus
(
MyTimeUtils
.
ACTIVE
);
AccountInfo
currentAccount
=
accountServiceImpl
.
addAccount
(
accountInfo
);
return
new
ResponseEntity
<>(
currentAccount
,
HttpStatus
.
OK
);
}
// getting the account id.
// accountid format is "Acc001"
private
String
getAccountId
()
throws
MyTimeException
{
return
(
MyTimeUtils
.
ACC_NAME
+
MyTimeUtils
.
ZERO_
)
+
(
accountServiceImpl
.
getAccounts
().
size
()
+
MyTimeUtils
.
ONE
);
}
@RequestMapping
(
value
=
"/getAccounts"
,
method
=
RequestMethod
.
GET
,
produces
=
MediaType
.
APPLICATION_JSON_VALUE
)
public
ResponseEntity
<
List
<
Map
<
Object
,
Object
>>>
getAccounts
()
throws
MyTimeException
{
List
<
Map
<
Object
,
Object
>>
acounts
=
accountServiceImpl
.
getAccountsList
();
return
new
ResponseEntity
<>(
acounts
,
HttpStatus
.
OK
);
}
@RequestMapping
(
value
=
"/getAccountNames"
,
method
=
RequestMethod
.
GET
,
produces
=
MediaType
.
APPLICATION_JSON_VALUE
)
public
ResponseEntity
<
List
<
String
>>
getAccountNames
()
throws
MyTimeException
{
List
<
AccountInfo
>
acounts
=
accountServiceImpl
.
getAccounts
();
List
<
String
>
accountNames
=
new
ArrayList
<>();
for
(
AccountInfo
account
:
acounts
)
{
accountNames
.
add
(
account
.
getAccountName
());
}
return
new
ResponseEntity
<>(
accountNames
,
HttpStatus
.
OK
);
}
@RequestMapping
(
value
=
"/deleteAccount"
,
method
=
RequestMethod
.
DELETE
,
produces
=
MediaType
.
TEXT_PLAIN_VALUE
)
public
ResponseEntity
<
String
>
deleteAccount
(
@RequestParam
(
value
=
"accountId"
)
String
accountId
)
throws
MyTimeException
{
accountServiceImpl
.
deleteAccount
(
accountId
);
return
new
ResponseEntity
<>(
"Success"
,
HttpStatus
.
OK
);
}
}
\ No newline at end of file
src/main/java/com/nisum/mytime/model/AccountInfo.java
0 → 100644
View file @
5263cbac
package
com
.
nisum
.
mytime
.
model
;
import
java.io.Serializable
;
import
java.util.List
;
import
org.bson.types.ObjectId
;
import
org.springframework.data.annotation.Id
;
import
org.springframework.data.mongodb.core.mapping.Document
;
import
lombok.AllArgsConstructor
;
import
lombok.Getter
;
import
lombok.NoArgsConstructor
;
import
lombok.Setter
;
import
lombok.ToString
;
@Setter
@Getter
@AllArgsConstructor
@NoArgsConstructor
@ToString
@Document
(
collection
=
"AccountInfo"
)
public
class
AccountInfo
implements
Serializable
{
private
static
final
long
serialVersionUID
=
1L
;
@Id
private
ObjectId
id
;
private
String
accountId
;
private
String
accountName
;
private
String
status
;
private
String
clientAddress
;
private
String
industryType
;
List
<
String
>
deliveryManagers
;
}
src/main/java/com/nisum/mytime/repository/AccountInfoRepo.java
0 → 100644
View file @
5263cbac
package
com
.
nisum
.
mytime
.
repository
;
import
org.springframework.data.mongodb.repository.MongoRepository
;
import
com.nisum.mytime.model.AccountInfo
;
public
interface
AccountInfoRepo
extends
MongoRepository
<
AccountInfo
,
String
>
{
AccountInfo
findByAccountName
(
String
accontName
);
}
\ No newline at end of file
src/main/java/com/nisum/mytime/service/AccountService.java
0 → 100644
View file @
5263cbac
package
com
.
nisum
.
mytime
.
service
;
import
java.util.List
;
import
java.util.Map
;
import
com.nisum.mytime.exception.handler.MyTimeException
;
import
com.nisum.mytime.model.AccountInfo
;
public
interface
AccountService
{
AccountInfo
addAccount
(
AccountInfo
account
)
throws
MyTimeException
;
List
<
AccountInfo
>
getAccounts
()
throws
MyTimeException
;
List
<
Map
<
Object
,
Object
>>
getAccountsList
()
throws
MyTimeException
;
}
src/main/java/com/nisum/mytime/service/AccountServiceImpl.java
0 → 100644
View file @
5263cbac
package
com
.
nisum
.
mytime
.
service
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.data.mongodb.core.FindAndModifyOptions
;
import
org.springframework.data.mongodb.core.MongoTemplate
;
import
org.springframework.data.mongodb.core.query.Criteria
;
import
org.springframework.data.mongodb.core.query.Query
;
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.AccountInfo
;
import
com.nisum.mytime.model.EmployeeRoles
;
import
com.nisum.mytime.repository.AccountInfoRepo
;
import
com.nisum.mytime.utils.MyTimeUtils
;
@Service
public
class
AccountServiceImpl
implements
AccountService
{
@Autowired
private
MongoTemplate
mongoTemplate
;
@Autowired
private
AccountInfoRepo
accountRepo
;
@Override
public
AccountInfo
addAccount
(
AccountInfo
account
)
throws
MyTimeException
{
return
accountRepo
.
save
(
account
);
}
@Override
public
List
<
AccountInfo
>
getAccounts
()
throws
MyTimeException
{
return
accountRepo
.
findAll
();
}
@Override
public
List
<
Map
<
Object
,
Object
>>
getAccountsList
()
throws
MyTimeException
{
List
<
Map
<
Object
,
Object
>>
updatedAccountList
=
new
ArrayList
<>();
List
<
Map
<
String
,
String
>>
updatedEmployeeList
=
null
;
for
(
AccountInfo
account
:
getAccountInfo
())
{
updatedEmployeeList
=
new
ArrayList
<>();
for
(
EmployeeRoles
employeesRole
:
getEmployeeDetails
(
account
))
{
updatedEmployeeList
.
add
(
getEmployeeDetails
(
employeesRole
));
}
updatedAccountList
.
add
(
getAccuntDetails
(
account
,
updatedEmployeeList
));
}
return
updatedAccountList
;
}
// fetching the employee details using employeeId.
private
List
<
EmployeeRoles
>
getEmployeeDetails
(
AccountInfo
account
)
{
List
<
EmployeeRoles
>
employeeRoles
=
mongoTemplate
.
find
(
new
Query
(
Criteria
.
where
(
MyTimeUtils
.
EMPLOYEE_ID
).
in
(
account
.
getDeliveryManagers
())),
EmployeeRoles
.
class
);
return
employeeRoles
;
}
// fetching the active account details.
private
List
<
AccountInfo
>
getAccountInfo
()
{
List
<
AccountInfo
>
accountList
=
mongoTemplate
.
find
(
new
Query
(
Criteria
.
where
(
MyTimeUtils
.
STATUS
).
is
(
MyTimeUtils
.
ACTIVE
)),
AccountInfo
.
class
);
return
accountList
;
}
private
HashMap
<
String
,
String
>
getEmployeeDetails
(
EmployeeRoles
employeesRole
)
{
HashMap
<
String
,
String
>
employeeDetails
=
new
HashMap
<>();
employeeDetails
.
put
(
MyTimeUtils
.
EMPLOYEE_ID
,
employeesRole
.
getEmployeeId
());
employeeDetails
.
put
(
MyTimeUtils
.
EMPLOYEE_NAME
,
employeesRole
.
getEmployeeName
());
return
employeeDetails
;
}
private
Map
<
Object
,
Object
>
getAccuntDetails
(
AccountInfo
account
,
List
<
Map
<
String
,
String
>>
updatedEmployeeList
)
{
Map
<
Object
,
Object
>
accountDetails
=
new
HashMap
<>();
accountDetails
.
put
(
MyTimeUtils
.
ACC_ID
,
account
.
getId
());
accountDetails
.
put
(
MyTimeUtils
.
ACCOUNT_ID
,
account
.
getAccountId
());
accountDetails
.
put
(
MyTimeUtils
.
ACCOUNT_NAME
,
account
.
getAccountName
());
accountDetails
.
put
(
MyTimeUtils
.
STATUS
,
account
.
getStatus
());
accountDetails
.
put
(
MyTimeUtils
.
CLIENT_ADDRESS
,
account
.
getClientAddress
());
accountDetails
.
put
(
MyTimeUtils
.
INDUSTRY_TYPE
,
account
.
getIndustryType
());
accountDetails
.
put
(
MyTimeUtils
.
DELIVERY_MANAGERS
,
updatedEmployeeList
);
return
accountDetails
;
}
// updating the status to "InActive".
public
AccountInfo
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
);
}
}
src/main/java/com/nisum/mytime/utils/MyTimeUtils.java
View file @
5263cbac
...
@@ -37,6 +37,19 @@ public class MyTimeUtils {
...
@@ -37,6 +37,19 @@ public class MyTimeUtils {
public
final
static
String
ABESENT_QUERY1
=
") AND STATUS='Working' AND EMPLOYEECODE NOT LIKE 'del%' "
;
public
final
static
String
ABESENT_QUERY1
=
") AND STATUS='Working' AND EMPLOYEECODE NOT LIKE 'del%' "
;
public
final
static
String
ABESENT
=
"Absent"
;
public
final
static
String
ABESENT
=
"Absent"
;
public
final
static
String
EMAIL_ID
=
"emailId"
;
public
final
static
String
EMAIL_ID
=
"emailId"
;
public
final
static
String
ACCOUNT_ID
=
"accountId"
;
public
static
final
int
ONE
=
1
;
public
final
static
String
ACC_NAME
=
"Acc"
;
public
static
final
String
ZERO_
=
"00"
;
// Manage account details
public
static
final
String
ACC_ID
=
"id"
;
public
static
final
String
ACCOUNT_NAME
=
"accountName"
;
public
static
final
String
STATUS
=
"status"
;
public
static
final
String
CLIENT_ADDRESS
=
"clientAddress"
;
public
static
final
String
INDUSTRY_TYPE
=
"industryType"
;
public
static
final
String
DELIVERY_MANAGERS
=
"deliveryManagers"
;
public
static
final
String
ACTIVE
=
"Active"
;
public
static
final
String
IN_ACTIVE
=
"InActive"
;
public
final
static
String
TEAMDETAILS_COLLECTION_NAME
=
"TeamDetails"
;
public
final
static
String
TEAMDETAILS_COLLECTION_NAME
=
"TeamDetails"
;
public
final
static
String
BILLINGDETAILS_COLLECTION_NAME
=
"BillingDetails"
;
public
final
static
String
BILLINGDETAILS_COLLECTION_NAME
=
"BillingDetails"
;
public
final
static
String
ENDDATE_COLUMN
=
"endDate"
;
public
final
static
String
ENDDATE_COLUMN
=
"endDate"
;
...
@@ -45,9 +58,6 @@ public class MyTimeUtils {
...
@@ -45,9 +58,6 @@ public class MyTimeUtils {
public
final
static
String
PROJECT_NAME
=
"projectName"
;
public
final
static
String
PROJECT_NAME
=
"projectName"
;
public
final
static
String
SET
=
"$set"
;
public
final
static
String
SET
=
"$set"
;
public
final
static
int
MINUS_ONE
=
-
1
;
public
final
static
int
MINUS_ONE
=
-
1
;
public
final
static
int
ONE
=
1
;
public
final
static
String
FREE_POLL
=
"Free Pool"
;
public
final
static
String
FREE_POLL
=
"Free Pool"
;
public
final
static
String
START_DATE
=
"startDate"
;
public
final
static
String
START_DATE
=
"startDate"
;
}
}
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