Commit 80aed22b authored by Vijay Akula's avatar Vijay Akula

Provided the account name in domains json response

parent 7d429dda
......@@ -4,6 +4,7 @@ import com.nisum.myteam.exception.handler.MyTeamException;
import com.nisum.myteam.exception.handler.ResponseDetails;
import com.nisum.myteam.model.dao.Account;
import com.nisum.myteam.service.IAccountService;
import com.nisum.myteam.statuscodes.AccountStatus;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
......@@ -23,135 +24,125 @@ import java.util.stream.Collectors;
@RestController
public class AccountController {
@Autowired
private IAccountService accountService;
@Autowired
private IAccountService accountService;
@RequestMapping(value = "/accounts", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<?> createAccount(@Valid @RequestBody Account account, HttpServletRequest request)
throws MyTeamException {
@RequestMapping(value = "/accounts", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<?> createAccount(@Valid @RequestBody Account account, HttpServletRequest request)
throws MyTeamException {
log.info("Serving the Account Creation action");
boolean isAccountExists = accountService.isAccountExists(account);
log.info("is Account exists with the name " + account.getAccountName() + ":::" + isAccountExists);
if (!isAccountExists) {
Account accountPersisted = accountService.createAccount(account);
ResponseDetails respDetails = null;
boolean isAccountExists = accountService.isAccountExists(account);
log.info("is Account exists with the name " + account.getAccountName() + ":::" + isAccountExists);
if (!isAccountExists) {
Account accountPersisted = accountService.createAccount(account);
ResponseDetails createResponseDetails = new ResponseDetails(new Date(), 601, "Account has been created",
"Account description",null, request.getContextPath(), "details", accountPersisted);
return new ResponseEntity<ResponseDetails>(createResponseDetails, HttpStatus.OK);
respDetails = new ResponseDetails(new Date(), AccountStatus.CREATE.getCode(), AccountStatus.CREATE.getMessage(),
"Account description", null, request.getContextPath(), "details", accountPersisted);
}
ResponseDetails responseDetails = new ResponseDetails(new Date(), 602, "An Account is already existed",
"Choose the different account name",null, request.getRequestURI(), "details", account);
}
respDetails = new ResponseDetails(new Date(), AccountStatus.ALREADY_EXISTED.getCode(), AccountStatus.ALREADY_EXISTED.getMessage(),
"Choose the different account name", null, request.getRequestURI(), "details", account);
return new ResponseEntity<ResponseDetails>(responseDetails, HttpStatus.OK);
}
return new ResponseEntity<ResponseDetails>(respDetails, HttpStatus.OK);
}
@RequestMapping(value = "/accounts/{accountId}", method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<?> updateAccount(@RequestBody Account account, @PathVariable String accountId,
HttpServletRequest request) throws MyTeamException {
log.info("Updating the account with details::"+account);
boolean isAccountExists = accountService.isAccountExists(account);
if (isAccountExists == true) {
Account accountPersisted = accountService.updateAccountAndRolesForDMS(account);
@RequestMapping(value = "/accounts/{accountId}", method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<?> updateAccount(@RequestBody Account account, @PathVariable String accountId,
HttpServletRequest request) throws MyTeamException {
log.info("Updating the account with details::" + account);
ResponseDetails respDetails = null;
boolean isAccountExists = accountService.isAccountExists(account);
if (isAccountExists == true) {
Account accountPersisted = accountService.updateAccountAndRolesForDMS(account);
ResponseDetails updateRespDetails = new ResponseDetails(new Date(), 604, "Account has been updated",
"status description",null, request.getContextPath(), "details", accountPersisted);
respDetails = new ResponseDetails(new Date(), AccountStatus.UPDATE.getCode(), AccountStatus.UPDATE.getMessage(),
"status description", null, request.getContextPath(), "details", accountPersisted);
}
respDetails = new ResponseDetails(new Date(), AccountStatus.NOT_FOUND.getCode(), AccountStatus.NOT_FOUND.getMessage(),
"Choose the correct updating account name", null, request.getRequestURI(), "details", account);
return new ResponseEntity<ResponseDetails>(updateRespDetails, HttpStatus.OK);
return new ResponseEntity<ResponseDetails>(respDetails, HttpStatus.OK);
}
ResponseDetails responseDetails = new ResponseDetails(new Date(), 605, "Account is Not found",
"Choose the correct updating account name",null, request.getRequestURI(), "details", account);
}
return new ResponseEntity<ResponseDetails>(responseDetails, HttpStatus.OK);
}
@RequestMapping(value = "/accounts/{accountId}", method = RequestMethod.DELETE, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<?> deleteAccount(@PathVariable String accountId, HttpServletRequest request)
throws MyTeamException {
log.info("Deleting account with accountId:" + accountId);
Account accountDeleted = accountService.deleteAccount(accountId);
ResponseDetails deleteRespDetails = new ResponseDetails(new Date(), AccountStatus.DELETE.getCode(),
AccountStatus.DELETE.getMessage(), "status description", null, request.getRequestURI(), "details",
accountDeleted);
return new ResponseEntity<ResponseDetails>(deleteRespDetails, HttpStatus.OK);
@RequestMapping(value = "/accounts/{accountId}", method = RequestMethod.DELETE, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<?> deleteAccount(@PathVariable String accountId, HttpServletRequest request)
throws MyTeamException {
log.info("Deleting account with accountId:" + accountId);
Account accountDeleted = accountService.deleteAccount(accountId);
ResponseDetails deleteRespDetails = new ResponseDetails(new Date(), 604,
"Account has been deleted successfully", "status description", null,request.getRequestURI(), "details",
accountDeleted);
}
return new ResponseEntity<ResponseDetails>(deleteRespDetails, HttpStatus.OK);
@RequestMapping(value = "/accounts", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<?> getAccounts(HttpServletRequest request) throws MyTeamException {
List<Map<Object, Object>> accountsList = accountService.getAccountsList();
log.info("The accounts list::" + accountsList);
}
ResponseDetails getRespDetails = new ResponseDetails(new Date(), AccountStatus.GET_ACCOUNTS.getCode(), AccountStatus.GET_ACCOUNTS.getMessage(),
"Accounts list", accountsList, request.getRequestURI(), "details", null);
@RequestMapping(value = "/accounts", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<?> getAccounts(HttpServletRequest request) throws MyTeamException {
List<Map<Object, Object>> accountsList = accountService.getAccountsList();
log.info("The accounts list::" + accountsList);
return new ResponseEntity<ResponseDetails>(getRespDetails, HttpStatus.OK);
ResponseDetails getRespDetails = new ResponseDetails(new Date(), 604, "Retrieved the accounts successfully",
"Accounts list", accountsList, request.getRequestURI(), "details", null);
}
return new ResponseEntity<ResponseDetails>(getRespDetails, HttpStatus.OK);
}
@RequestMapping(value = "/accounts/names", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<?> getAccountNames(HttpServletRequest request) throws MyTeamException {
List<Account> acountsList = accountService.getAccounts();
List<String> accountNamesList = new ArrayList<>();
@RequestMapping(value = "/accounts/names", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<?> getAccountNames(HttpServletRequest request) throws MyTeamException {
List<Account> acountsList = accountService.getAccounts();
List<String> accountNamesList = new ArrayList<>();
for (Account account : acountsList) {
accountNamesList.add(account.getAccountName());
}
log.info("The account names list::" + accountNamesList);
for (Account account : acountsList) {
accountNamesList.add(account.getAccountName());
}
log.info("The account names list::" + accountNamesList);
ResponseDetails getRespDetails = new ResponseDetails(new Date(), AccountStatus.GET_ACCOUNT_NAMES.getCode(),
AccountStatus.GET_ACCOUNT_NAMES.getMessage(), "Account names list", accountNamesList,
request.getRequestURI(), "details", null);
ResponseDetails getRespDetails = new ResponseDetails(new Date(), 604,
"Retrieved the account names successfully", "Account names list", accountNamesList,
request.getRequestURI(), "details", null);
return new ResponseEntity<ResponseDetails>(getRespDetails, HttpStatus.OK);
return new ResponseEntity<ResponseDetails>(getRespDetails, HttpStatus.OK);
}
}
//get the accounts based on status(Active or inactive)
@RequestMapping(value = "/accounts/status", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<List<Account>> getAccounts(@RequestParam("status")String status) throws MyTeamException {
List<Account> accountsList = accountService.getAccountsAll().stream()
.filter(e -> "Active".equalsIgnoreCase(e.getStatus())).collect(Collectors.toList());
return new ResponseEntity<>(accountsList, HttpStatus.OK);
}
//get the accounts based on status(Active or inactive)
@RequestMapping(value = "/accounts/status", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<List<Account>> getAccounts(@RequestParam("status") String status) throws MyTeamException {
List<Account> accountsList = accountService.getAccountsAll().stream()
.filter(e -> "Active".equalsIgnoreCase(e.getStatus())).collect(Collectors.toList());
return new ResponseEntity<>(accountsList, HttpStatus.OK);
}
@RequestMapping(value = "/accounts/accountId/{accId}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<?> getAccountName(@PathVariable("accId") String accountId, HttpServletRequest request) throws MyTeamException {
@RequestMapping(value = "/accounts/accountId/{accId}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<?> getAccountName(@PathVariable("accId") String accountId, HttpServletRequest request) throws MyTeamException {
log.info("Serving the Account Name Get action: accountId:"+accountId);
if (accountId != null && !"".equalsIgnoreCase(accountId)) {
log.info("Serving the Account Name Get action: accountId:" + accountId);
ResponseDetails getRespDetails = null;
if (accountId != null && !"".equalsIgnoreCase(accountId)) {
boolean isAccountExists = accountService.isAccountExists(accountId);
if (isAccountExists) {
getRespDetails = new ResponseDetails(new Date(), AccountStatus.GET_ACCOUNT.getCode(), AccountStatus.GET_ACCOUNT.getMessage(),
"Account Name", accountService.getAccountById(accountId), request.getRequestURI(), "details", null);
boolean isAccountExists = accountService.isAccountExists(accountId);
}
getRespDetails = new ResponseDetails(new Date(), AccountStatus.NOT_FOUND.getCode(), AccountStatus.NOT_FOUND.getMessage(),
"Account Name", null, request.getRequestURI(), "details", null);
log.info("is Account exists with the name " + isAccountExists);
if (isAccountExists) {
ResponseDetails getRespDetails = new ResponseDetails(new Date(), 604, "Retrieved the account Name successfully",
"Account Name", accountService.getAccountById(accountId), request.getRequestURI(), "details", null);
return new ResponseEntity<ResponseDetails>(getRespDetails, HttpStatus.OK);
}
getRespDetails = new ResponseDetails(new Date(), AccountStatus.NOT_VALID_ID.getCode(), AccountStatus.NOT_VALID_ID.getMessage(),
"Please provide Valid account Id", null, request.getRequestURI(), "details", null);
}
return new ResponseEntity<ResponseDetails>(getRespDetails, HttpStatus.OK);
ResponseDetails getRespDetails = new ResponseDetails(new Date(), 604, "Account Does Not Exists",
"Account Name", null, request.getRequestURI(), "details", null);
return new ResponseEntity<ResponseDetails>(getRespDetails, HttpStatus.OK);
}
ResponseDetails getRespDetails = new ResponseDetails(new Date(), 604, "Please provide Valid account Id",
"Account Name", null, request.getRequestURI(), "details", null);
return new ResponseEntity<ResponseDetails>(getRespDetails, HttpStatus.OK);
}
}
}
package com.nisum.myteam.model.vo;
import lombok.*;
import java.util.HashMap;
import java.util.List;
@Setter
@Getter
@NoArgsConstructor
@AllArgsConstructor
@ToString
public class DomainVO {
private String Id;
private String domainId;
private String domainName;
private String accountId;
private String accountName;
private String status;
private List<HashMap<String,String>> deliveryManagers;
}
......@@ -3,6 +3,7 @@ package com.nisum.myteam.service;
import java.util.List;
import java.util.Set;
import com.nisum.myteam.model.vo.DomainVO;
import org.springframework.stereotype.Service;
import com.mongodb.WriteResult;
......@@ -26,15 +27,13 @@ public interface IDomainService {
WriteResult delete(String id) throws MyTeamException;
List<Domain> getDomainsList() throws MyTeamException;
List<DomainVO> getDomainsList() throws MyTeamException;
Set<String> accountsAssignedToDeliveryLead(String empId) throws MyTeamException;
List<Domain> getDomainsUnderAccount(String accountId)throws MyTeamException;
Domain getDomainById(String domainId);
}
package com.nisum.myteam.service.impl;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.springframework.beans.factory.annotation.Autowired;
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 org.springframework.util.StringUtils;
import com.mongodb.WriteResult;
import com.nisum.myteam.exception.handler.MyTeamException;
import com.nisum.myteam.model.dao.Domain;
import com.nisum.myteam.model.dao.Employee;
import com.nisum.myteam.model.vo.DomainVO;
import com.nisum.myteam.repository.DomainRepo;
import com.nisum.myteam.service.IAccountService;
import com.nisum.myteam.service.IDomainService;
import com.nisum.myteam.service.IEmployeeRoleService;
import com.nisum.myteam.service.IRoleService;
import com.nisum.myteam.utils.CommomUtil;
import com.nisum.myteam.utils.MyTeamUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
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 org.springframework.util.StringUtils;
import java.util.*;
/**
* @author Vijay
......@@ -48,7 +43,9 @@ public class DomainService implements IDomainService {
@Autowired
private IEmployeeRoleService roleMappingService;
@Autowired
private IAccountService accountService;
public boolean isDomainExists(Domain domainReq) {
boolean isDomainExists = false;
......@@ -140,13 +137,25 @@ public class DomainService implements IDomainService {
}
@Override
public List<Domain> getDomainsList() throws MyTeamException {
List<Domain> domainsPersistedList = domainRepo.findAll();
for (Domain domainPersisted : domainsPersistedList) {
domainPersisted.setDeliveryManagers(prepareEmployeeList(domainPersisted));
public List<DomainVO> getDomainsList() throws MyTeamException {
List<DomainVO> domainVOS = new ArrayList<>();
for (Domain domainPersisted : domainRepo.findAll()) {
DomainVO domainVO = new DomainVO();
domainVO.setId(domainPersisted.getId().toString());
domainVO.setAccountId(domainPersisted.getAccountId());
domainVO.setAccountName(accountService.getAccountById(domainPersisted.getAccountId()).getAccountName());
domainVO.setDomainId(domainPersisted.getDomainId());
domainVO.setDomainName(domainPersisted.getDomainName());
domainVO.setStatus(domainPersisted.getStatus());
domainVO.setDeliveryManagers(prepareEmployeeList(domainPersisted));
domainVOS.add(domainVO);
}
return domainsPersistedList;
return domainVOS;
}
@Override
......
package com.nisum.myteam.statuscodes;
public enum AccountStatus {
CREATE(600, "Account has been created"),
UPDATE(601, "Account has been updated"),
DELETE(602, "Account has been deleted successfully"),
GET_ACCOUNTS(603, "Retrieved the accounts successfully"),
GET_ACCOUNT(604, "Retrieved the account successfully"),
GET_ACCOUNT_NAMES(605, "Retrieved the account names successfully"),
ALREADY_EXISTED(606, "An Account is already existed"),
NOT_FOUND(607, "Account is Not found"),
NOT_VALID_ID(608, "AccountId is not valid");
private int code;
private String message;
private String description;
private AccountStatus(int code, String message) {
this.code = code;
this.message = message;
}
public int getCode() {
return this.code;
}
public String getMessage() {
return this.message;
}
}
\ No newline at end of file
package com.nisum.myteam.statuscodes;
public class BillingStatus {
}
package com.nisum.myteam.statuscodes;
public enum DomainStatus {
CREATE(600, "Account has been created"),
UPDATE(601, "Account has been updated");
private int code;
private String message;
private DomainStatus(int code, String message) {
this.code = code;
this.message = message;
}
public int getCode() {
return this.code;
}
public String getMessage() {
return this.message;
}
}
package com.nisum.myteam.statuscodes;
public enum EmployeeStatus {
}
package com.nisum.myteam.statuscodes;
public class ProjectStatus {
}
package com.nisum.myteam.statuscodes;
public class ResourceStatus {
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment