Commit 3705b14d authored by bsatyanarayana-nisum-com's avatar bsatyanarayana-nisum-com Committed by tdutta-nisum-com

MT-126_4 :SNS :: DL_should_see_only_his_account_projects (#141)

* MT-126_4 :SNS :: DL_should_see_only_his_account_projects

* MT-126_4 :SNS :: DL_should_see_only_his_account_projects
parent 42546162
...@@ -20,6 +20,7 @@ import com.nisum.mytime.model.Project; ...@@ -20,6 +20,7 @@ import com.nisum.mytime.model.Project;
import com.nisum.mytime.repository.AccountRepo; import com.nisum.mytime.repository.AccountRepo;
import com.nisum.mytime.service.ProjectService; import com.nisum.mytime.service.ProjectService;
import com.nisum.mytime.service.UserService; import com.nisum.mytime.service.UserService;
import com.nisum.mytime.utils.MyTimeUtils;
@RestController @RestController
@RequestMapping("/project") @RequestMapping("/project")
...@@ -27,10 +28,13 @@ public class ProjectController { ...@@ -27,10 +28,13 @@ public class ProjectController {
@Autowired @Autowired
private UserService userService; private UserService userService;
@Autowired @Autowired
private ProjectService projectService; private ProjectService projectService;
@Autowired @Autowired
private AccountRepo accountRepo; private AccountRepo accountRepo;
@RequestMapping(value = "/employee", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) @RequestMapping(value = "/employee", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<EmployeeRoles> getEmployeeRole(@RequestParam("emailId") String emailId) public ResponseEntity<EmployeeRoles> getEmployeeRole(@RequestParam("emailId") String emailId)
throws MyTimeException { throws MyTimeException {
...@@ -68,8 +72,17 @@ public class ProjectController { ...@@ -68,8 +72,17 @@ public class ProjectController {
} }
@RequestMapping(value = "/getProjects", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) @RequestMapping(value = "/getProjects", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<List<HashMap<Object, Object>>> getProjects() throws MyTimeException { public ResponseEntity<List<HashMap<Object, Object>>> getProjects(@RequestParam(value="empId", required = false, defaultValue = MyTimeUtils.ZERO) String empId) throws MyTimeException {
List<HashMap<Object, Object>> projects = projectService.getProjects(); List<HashMap<Object, Object>> projects = null;
if(!MyTimeUtils.ZERO.equals(empId)) {
boolean isDl = userService.verifyRole(empId,MyTimeUtils.DL) ;
if( isDl ){
projects = projectService.deliveryLeadProjects(empId);
}
}else {
projects = projectService.getProjects();
}
return new ResponseEntity<>(projects, HttpStatus.OK); return new ResponseEntity<>(projects, HttpStatus.OK);
} }
......
package com.nisum.mytime.repository; package com.nisum.mytime.repository;
import java.util.List; import java.util.List;
import java.util.Set;
import org.springframework.data.mongodb.repository.MongoRepository; import org.springframework.data.mongodb.repository.MongoRepository;
...@@ -13,4 +14,6 @@ public interface ProjectRepo extends MongoRepository<Project, String> { ...@@ -13,4 +14,6 @@ public interface ProjectRepo extends MongoRepository<Project, String> {
List<Project> findByDeliveryLeadIds(String empId); List<Project> findByDeliveryLeadIds(String empId);
// List<Project> findByManagerId(String managerId); // List<Project> findByManagerId(String managerId);
List<Project> findByAccountIdIn(Set<String> accIdsSet);
} }
\ No newline at end of file
...@@ -2,6 +2,7 @@ package com.nisum.mytime.service; ...@@ -2,6 +2,7 @@ package com.nisum.mytime.service;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Set;
import org.bson.types.ObjectId; import org.bson.types.ObjectId;
...@@ -88,4 +89,8 @@ public interface ProjectService { ...@@ -88,4 +89,8 @@ public interface ProjectService {
throws MyTimeException; throws MyTimeException;
public List<HashMap<Object, Object>> projectsInfoByEmpId(String empId); public List<HashMap<Object, Object>> projectsInfoByEmpId(String empId);
public Set<String> accountsAssignedToDl(String empId);
public List<HashMap<Object, Object>> deliveryLeadProjects(String empId) throws MyTimeException;
} }
package com.nisum.mytime.service; package com.nisum.mytime.service;
import java.time.LocalDate;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Calendar; import java.util.Calendar;
import java.util.Comparator; import java.util.Comparator;
import java.util.Date; import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import org.apache.commons.lang.time.DateUtils; import org.apache.commons.lang.time.DateUtils;
...@@ -85,6 +86,9 @@ public class ProjectServiceImpl implements ProjectService { ...@@ -85,6 +86,9 @@ public class ProjectServiceImpl implements ProjectService {
@Autowired @Autowired
private DomainRepo domainRepo; private DomainRepo domainRepo;
@Autowired
private ProjectService projectService;
@Override @Override
public List<EmpLoginData> employeeLoginsBasedOnDate(long id, public List<EmpLoginData> employeeLoginsBasedOnDate(long id,
...@@ -1055,4 +1059,56 @@ public class ProjectServiceImpl implements ProjectService { ...@@ -1055,4 +1059,56 @@ public class ProjectServiceImpl implements ProjectService {
} }
return projectList; return projectList;
} }
@Override
public Set<String> accountsAssignedToDl(String empId) {
Set<String> accIdsSet = new HashSet<String>() ;
List<Project> prjtsList = projectRepo.findByDeliveryLeadIds(empId);
if(null != prjtsList && !prjtsList.isEmpty() && MyTimeUtils.INT_ZERO < prjtsList.size()) {
for(Project obj : prjtsList) {
accIdsSet.add(obj.getAccountId());
}
}
return accIdsSet;
}
@Override
public List<HashMap<Object, Object>> deliveryLeadProjects(String empId) throws MyTimeException {
List<HashMap<Object, Object>> projectsList = new ArrayList<HashMap<Object, Object>> ();
Set<String> accIdsSet = projectService.accountsAssignedToDl(empId);
List<Project> prjts= projectRepo.findByAccountIdIn(accIdsSet);
if(null != prjts && !prjts.isEmpty() && MyTimeUtils.INT_ZERO < prjts.size()) {
Account account = null;
Domains domain =null;
HashMap<Object, Object> projectMap = new HashMap<>();
for(Project obj : prjts) {
account = accountRepo.findByAccountId(obj.getAccountId());
domain = domainRepo.findByDomainId(obj.getDomainId());
projectMap.put("projectId", obj.getProjectId());
projectMap.put("projectName",obj.getProjectName());
projectMap.put("accountId", obj.getAccountId());
projectMap.put("domainId", obj.getDomainId());
projectMap.put("account", null != account ? account.getAccountName():"");
projectMap.put("domain", null != domain ? domain.getDomainName() : "");
projectMap.put("status", obj.getStatus());
projectMap.put("deliveryLeadIds", null != obj.getDeliveryLeadIds() ? getEmployeeData(obj.getDeliveryLeadIds()) : "");
projectMap.put("managerIds", null != obj.getManagerIds() ? getEmployeeData(obj.getManagerIds()) : "");
projectsList.add(projectMap);
}
}
return projectsList;
}
} }
package com.nisum.mytime.service; package com.nisum.mytime.service;
import java.util.List; import java.util.List;
import java.util.Set;
import com.mongodb.WriteResult; import com.mongodb.WriteResult;
import com.nisum.mytime.exception.handler.MyTimeException; import com.nisum.mytime.exception.handler.MyTimeException;
...@@ -12,4 +13,6 @@ public interface RoleMappingService { ...@@ -12,4 +13,6 @@ public interface RoleMappingService {
WriteResult deleteRole(String employeeId, String roleId) throws MyTimeException; WriteResult deleteRole(String employeeId, String roleId) throws MyTimeException;
String getEmployeeRole(String employeeId); String getEmployeeRole(String employeeId);
public Set<String> empRolesMapInfoByEmpId(String employeeId);
} }
package com.nisum.mytime.service; package com.nisum.mytime.service;
import java.util.HashSet;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -77,5 +79,21 @@ public class RoleMappingServiceImpl implements RoleMappingService { ...@@ -77,5 +79,21 @@ public class RoleMappingServiceImpl implements RoleMappingService {
} }
return roleName; return roleName;
} }
@Override
public Set<String> empRolesMapInfoByEmpId(String employeeId) {
Set<String> roleSet = new HashSet<String>();
List<RoleMappingInfo> listOfEmployeeRoles = roleMappingInfoRepo.findByEmployeeId(employeeId);
if(null != listOfEmployeeRoles && !listOfEmployeeRoles.isEmpty() && MyTimeUtils.INT_ZERO < listOfEmployeeRoles.size()) {
for(RoleMappingInfo obj : listOfEmployeeRoles) {
roleSet.add(obj.getRoleId());
}
}
return roleSet;
}
} }
...@@ -76,4 +76,6 @@ public interface UserService { ...@@ -76,4 +76,6 @@ public interface UserService {
public List<AccountInfo> getAccountsInfo() throws MyTimeException; public List<AccountInfo> getAccountsInfo() throws MyTimeException;
public List<Domains> getDomains(String accountId)throws MyTimeException; public List<Domains> getDomains(String accountId)throws MyTimeException;
public boolean verifyRole(String empId, String roleName);
} }
...@@ -6,6 +6,7 @@ import java.util.Comparator; ...@@ -6,6 +6,7 @@ import java.util.Comparator;
import java.util.Date; import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Set;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -99,6 +100,10 @@ public class UserServiceImpl implements UserService { ...@@ -99,6 +100,10 @@ public class UserServiceImpl implements UserService {
@Autowired @Autowired
private TeamMatesBillingRepo teamMatesBillingRepo; private TeamMatesBillingRepo teamMatesBillingRepo;
@Autowired
private RoleMappingService roleMappingService;
@Override @Override
public Boolean fetchEmployeesData(String perticularDate, public Boolean fetchEmployeesData(String perticularDate,
...@@ -556,4 +561,23 @@ public class UserServiceImpl implements UserService { ...@@ -556,4 +561,23 @@ public class UserServiceImpl implements UserService {
mongoTemplate.save(existingShift); mongoTemplate.save(existingShift);
} }
} }
@Override
public boolean verifyRole(String empId,String roleName) {
boolean flag = false;
String role = getEmployeesRoleData(empId).getRole();
if( null != role && "" != role && !"Admin".equalsIgnoreCase(role) ) {
Set<String> roleSet = roleMappingService .empRolesMapInfoByEmpId(empId);
if(null != roleSet && !roleSet.isEmpty() && MyTimeUtils.INT_ZERO < roleSet.size() ) {
if( roleSet.contains(roleName) ) {
flag = false;
}
}
}
return flag;
}
} }
...@@ -109,5 +109,9 @@ public class MyTimeUtils { ...@@ -109,5 +109,9 @@ public class MyTimeUtils {
public final static String BENCH_BILLABILITY_STATUS="Non-Billable"; public final static String BENCH_BILLABILITY_STATUS="Non-Billable";
public final static int INT_ZERO = 0; public final static int INT_ZERO = 0;
public final static String DM= "DM";
public final static String DL= "DL";
public final static String L= "L";
} }
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