Commit 87dbd1f2 authored by Vijay Akula's avatar Vijay Akula

Added methods for Accounts and Domains

parent 1828c372
package com.nisum.myteam.controller;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
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.PathVariable;
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.myteam.exception.handler.MyTeamException;
import com.nisum.myteam.exception.handler.ResponseDetails;
import com.nisum.myteam.model.Account;
import com.nisum.myteam.service.IAccountService;
import lombok.extern.slf4j.Slf4j;
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.*;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@Slf4j
@RestController
......@@ -47,7 +37,7 @@ public class AccountController {
Account accountPersisted = accountService.createAccount(account);
ResponseDetails createResponseDetails = new ResponseDetails(new Date(), 601, "Account has been created",
"status description",null, request.getContextPath(), "details", accountPersisted);
"Account description",null, request.getContextPath(), "details", accountPersisted);
return new ResponseEntity<ResponseDetails>(createResponseDetails, HttpStatus.OK);
}
......@@ -133,5 +123,36 @@ public class AccountController {
.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 {
log.info("Serving the Account Name Get action: accountId:"+accountId);
if (accountId != null && !"".equalsIgnoreCase(accountId)) {
boolean isAccountExists = accountService.isAccountExists(accountId);
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);
}
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);
}
}
\ No newline at end of file
......@@ -64,14 +64,6 @@ public class DomainController {
}
@RequestMapping(value = "/domains", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<?> getDomains(HttpServletRequest request) throws MyTeamException {
ResponseDetails getRespDetails = new ResponseDetails(new Date(), 804, "Retrieved the domains successfully",
"Domains list", domainService.getDomainsList(), request.getRequestURI(), "details", null);
return new ResponseEntity<ResponseDetails>(getRespDetails, HttpStatus.OK);
}
@RequestMapping(value = "/domains", method = RequestMethod.PUT, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<?> updateDomain(@RequestBody Domain domain, HttpServletRequest request)
......@@ -104,6 +96,16 @@ public class DomainController {
}
@RequestMapping(value = "/domains", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<?> getDomains(HttpServletRequest request) throws MyTeamException {
ResponseDetails getRespDetails = new ResponseDetails(new Date(), 804, "Retrieved the domains successfully",
"Domains list", domainService.getDomainsList(), request.getRequestURI(), "details", null);
return new ResponseEntity<ResponseDetails>(getRespDetails, HttpStatus.OK);
}
//getting domains list under accountId which is an active.
@RequestMapping(value = "/domains/{accountId}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<List<Domain>> getDomains(@PathVariable("accountId") String accountId) throws MyTeamException {
......@@ -112,4 +114,7 @@ public class DomainController {
return new ResponseEntity<>(domains, HttpStatus.OK);
}
}
\ No newline at end of file
......@@ -17,6 +17,7 @@ import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import org.bson.types.ObjectId;
@Setter
@Getter
......@@ -28,10 +29,10 @@ public class Account implements Serializable {
private static final long serialVersionUID = 1L;
// private ObjectId id;
@Id
private ObjectId id;
@NotNull
private String accountId;
@NotNull
@Size(min=2,max=50,message="Name should have atlast 2 and less than 50 characters")
......
......@@ -15,6 +15,7 @@ import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import org.bson.types.ObjectId;
@Setter
@Getter
......@@ -26,7 +27,9 @@ public class Domain implements Serializable {
private static final long serialVersionUID = 1L;
// private ObjectId id;
//private ObjectId id;
@Id
private String domainId;
@NotNull
......
......@@ -15,4 +15,4 @@ public interface AccountRepo extends MongoRepository<Account, String> {
List<Account> findByaccountNameAndAccountId(String accountName,String accountId);
Account findByAccountNameIgnoreCase(String accountName);
}
\ No newline at end of file
}
......@@ -16,6 +16,10 @@ public interface IAccountService {
Account updateAccount(Account account) throws MyTeamException;
boolean isAccountExists(Account account);
boolean isAccountExists(String accountId);
public Account getAccountById(String accountId);
List<Account> getAccounts() throws MyTeamException;
......@@ -25,4 +29,7 @@ public interface IAccountService {
public List<Account> getAccountsAll() throws MyTeamException;
}
......@@ -39,6 +39,8 @@ import lombok.extern.slf4j.Slf4j;
@Slf4j
public class EmployeeService implements IEmployeeService {
@Autowired
private EmployeeRepo employeeRepo;
......@@ -196,7 +198,11 @@ public class EmployeeService implements IEmployeeService {
@Override
public Employee getEmployeeById(String employeeId) {
return employeeRepo.findByEmployeeId(employeeId);
log.info("The employeeId::"+employeeId);
Employee employee=employeeRepo.findByEmployeeId(employeeId);
log.info("Employee Found in Repo::"+employee);
return employee;
}
@Override
......@@ -296,7 +302,14 @@ public class EmployeeService implements IEmployeeService {
@Override
public boolean verifyEmployeeRole(String empId, String roleName) {
boolean flag = false;
String role = getEmployeeById(empId).getRole();
log.info("The employeeId::"+empId);
Employee employee=getEmployeeById(empId);
log.info("Employee::::in EmployeeService::"+employee);
String role = employee.getRole();
log.info("The employee role::"+role);
if (null != role && "" != role && !"Admin".equalsIgnoreCase(role)) {
Set<String> roleSet = employeeRoleService.empRolesMapInfoByEmpId(empId);
if (null != roleSet && !roleSet.isEmpty() && MyTeamUtils.INT_ZERO < roleSet.size()) {
......
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