Commit cc43ba84 authored by Vijay Akula's avatar Vijay Akula

Removed the dependencies of resources and billing in all classes

parent e3d77a40
package com.nisum.myteam.model.dao; //package com.nisum.myteam.model.dao;
//
import java.io.Serializable; //import java.io.Serializable;
import java.util.Date; //import java.util.Date;
//
import com.nisum.myteam.model.AuditFields; //import com.nisum.myteam.model.AuditFields;
import org.bson.types.ObjectId; //import org.bson.types.ObjectId;
import org.springframework.data.annotation.Id; //import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document; //import org.springframework.data.mongodb.core.mapping.Document;
import org.springframework.format.annotation.DateTimeFormat; //import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.format.annotation.DateTimeFormat.ISO; //import org.springframework.format.annotation.DateTimeFormat.ISO;
//
import lombok.AllArgsConstructor; //import lombok.AllArgsConstructor;
import lombok.Getter; //import lombok.Getter;
import lombok.NoArgsConstructor; //import lombok.NoArgsConstructor;
import lombok.Setter; //import lombok.Setter;
import lombok.ToString; //import lombok.ToString;
//
@Setter //@Setter
@Getter //@Getter
@AllArgsConstructor //@AllArgsConstructor
@NoArgsConstructor //@NoArgsConstructor
@ToString //@ToString
@Document(collection = "billing") //@Document(collection = "billing")
public class Billing extends AuditFields implements Serializable { //public class Billing extends AuditFields implements Serializable {
//
public Date getBillingEndDate() { // public Date getBillingEndDate() {
return billingEndDate; // return billingEndDate;
} // }
//
private static final long serialVersionUID = 1L; // private static final long serialVersionUID = 1L;
//
@Id // @Id
private ObjectId id; // private ObjectId id;
private String employeeId; // private String employeeId;
private String employeeName; // private String employeeName;
private String account; // private String account;
private String projectId; // private String projectId;
private String projectName; // private String projectName;
private String billableStatus; // private String billableStatus;
@DateTimeFormat(iso = ISO.DATE) // @DateTimeFormat(iso = ISO.DATE)
private Date billingStartDate; // private Date billingStartDate;
@DateTimeFormat(iso = ISO.DATE) // @DateTimeFormat(iso = ISO.DATE)
private Date billingEndDate; // private Date billingEndDate;
private String comments; // private String comments;
private boolean active; // private boolean active;
// @DateTimeFormat(pattern = "dd-MM-yyyy") // // @DateTimeFormat(pattern = "dd-MM-yyyy")
// private Date createDate; // // private Date createDate;
//
} //}
package com.nisum.myteam.repository; //package com.nisum.myteam.repository;
//
import java.util.List; //import java.util.List;
//
import org.bson.types.ObjectId; //import org.bson.types.ObjectId;
import org.springframework.data.mongodb.repository.MongoRepository; //import org.springframework.data.mongodb.repository.MongoRepository;
//
import com.nisum.myteam.model.dao.Billing; //import com.nisum.myteam.model.dao.Billing;
//
public interface BillingRepo extends MongoRepository<Billing, String> { //public interface BillingRepo extends MongoRepository<Billing, String> {
//
List<Billing> findByProjectId(String projectId); // List<Billing> findByProjectId(String projectId);
//
List<Billing> findByEmployeeId(String employeeId); // List<Billing> findByEmployeeId(String employeeId);
//
Billing findById(ObjectId id); // Billing findById(ObjectId id);
//
List<Billing> findByEmployeeIdAndProjectId(String employeeId, String projectId); // List<Billing> findByEmployeeIdAndProjectId(String employeeId, String projectId);
//
} //}
package com.nisum.myteam.repository; //package com.nisum.myteam.repository;
//
import java.util.List; //import java.util.List;
import java.util.Optional; //import java.util.Optional;
//
import org.bson.types.ObjectId; //import org.bson.types.ObjectId;
import org.springframework.data.mongodb.repository.MongoRepository; //import org.springframework.data.mongodb.repository.MongoRepository;
//
import com.nisum.myteam.model.dao.Resource; //import com.nisum.myteam.model.dao.Resource;
//
public interface ResourceRepo //public interface ResourceRepo
extends MongoRepository<Resource, String> { // extends MongoRepository<Resource, String> {
//
List<Resource> findByProjectId(String projectId); // List<Resource> findByProjectId(String projectId);
//
List<Resource> findByEmployeeId(String employeeId); // List<Resource> findByEmployeeId(String employeeId);
//
Resource findById(ObjectId id); // Resource findById(ObjectId id);
//
Resource findByEmployeeIdAndProjectId(String employeeId,String projectId); // Resource findByEmployeeIdAndProjectId(String employeeId,String projectId);
//
List<Resource> findByEmployeeIdAndActive(String employeeId,boolean status); // List<Resource> findByEmployeeIdAndActive(String employeeId,boolean status);
//
List<Resource> findByEmployeeIdAndProjectIdAndActive(String employeeId, String projectId, boolean status); // List<Resource> findByEmployeeIdAndProjectIdAndActive(String employeeId, String projectId, boolean status);
//
List<Resource> findByAccountAndActiveAndBillableStatus( String account, boolean status, String billableStatus); // List<Resource> findByAccountAndActiveAndBillableStatus( String account, boolean status, String billableStatus);
//
Optional<List<Resource>> findByActiveAndShiftLikeOrderByEmployeeIdDesc( boolean active, String shift); // Optional<List<Resource>> findByActiveAndShiftLikeOrderByEmployeeIdDesc( boolean active, String shift);
} //}
package com.nisum.myteam.service; //package com.nisum.myteam.service;
//
import java.util.List; //import java.util.List;
//
import org.springframework.stereotype.Service; //import org.springframework.stereotype.Service;
//
import com.nisum.myteam.model.dao.Billing; //import com.nisum.myteam.model.dao.Billing;
import com.nisum.myteam.model.dao.Employee; //import com.nisum.myteam.model.dao.Employee;
//
@Service //@Service
public interface IBillingService { //public interface IBillingService {
//
Billing addBilling(Billing billingDetails, String loginEmpId); // Billing addBilling(Billing billingDetails, String loginEmpId);
//
Billing updateBilling(Billing billingDetails, String loginEmpId); // Billing updateBilling(Billing billingDetails, String loginEmpId);
//
void deleteBilling(Billing teamMate); // void deleteBilling(Billing teamMate);
//
Billing addBillingtoResource(Billing billing, Employee employee, String loginEmpId); // Billing addBillingtoResource(Billing billing, Employee employee, String loginEmpId);
//
List<Billing> getBillingsForEmployee(String empId); // List<Billing> getBillingsForEmployee(String empId);
//
List<Billing> getActiveBillings(String empId, String projectId); // List<Billing> getActiveBillings(String empId, String projectId);
//
List<Billing> getBillingsForProject(String empId, String projectId); // List<Billing> getBillingsForProject(String empId, String projectId);
//
} //}
package com.nisum.myteam.service; //package com.nisum.myteam.service;
//
import com.nisum.myteam.exception.handler.MyTeamException; //import com.nisum.myteam.exception.handler.MyTeamException;
import com.nisum.myteam.model.dao.Employee; //import com.nisum.myteam.model.dao.Employee;
import com.nisum.myteam.model.dao.Resource; //import com.nisum.myteam.model.dao.Resource;
import org.bson.types.ObjectId; //import org.bson.types.ObjectId;
import org.springframework.stereotype.Service; //import org.springframework.stereotype.Service;
//
import java.util.HashMap; //import java.util.HashMap;
import java.util.List; //import java.util.List;
//
@Service //@Service
public interface IResourceService { //public interface IResourceService {
//
// Resource addResource(Resource projectTeamMate, String loginEmpId) throws MyTeamException; // Resource addResource(Resource projectTeamMate, String loginEmpId) throws MyTeamException;
// //
// String updateResource(Resource projectTeamMate, String loginEmpId) throws MyTeamException; // String updateResource(Resource projectTeamMate, String loginEmpId) throws MyTeamException;
...@@ -43,6 +43,6 @@ public interface IResourceService { ...@@ -43,6 +43,6 @@ public interface IResourceService {
// public List<Resource> getResourcesUnderDeliveryLead(String empId); // public List<Resource> getResourcesUnderDeliveryLead(String empId);
// //
// public HashMap<String, Object> verifyResourceAssignedToAnyProject(Resource projectTeamMate, String loginEmpId) throws MyTeamException; // public HashMap<String, Object> verifyResourceAssignedToAnyProject(Resource projectTeamMate, String loginEmpId) throws MyTeamException;
//
//
} //}
...@@ -5,7 +5,6 @@ import com.nisum.myteam.exception.handler.MyTeamException; ...@@ -5,7 +5,6 @@ import com.nisum.myteam.exception.handler.MyTeamException;
import com.nisum.myteam.model.AttendenceData; import com.nisum.myteam.model.AttendenceData;
import com.nisum.myteam.model.dao.EmpLoginData; import com.nisum.myteam.model.dao.EmpLoginData;
import com.nisum.myteam.model.dao.Employee; import com.nisum.myteam.model.dao.Employee;
import com.nisum.myteam.repository.ResourceRepo;
import com.nisum.myteam.service.IAttendanceService; import com.nisum.myteam.service.IAttendanceService;
import com.nisum.myteam.service.IEmployeeService; import com.nisum.myteam.service.IEmployeeService;
import com.nisum.myteam.utils.CommomUtil; import com.nisum.myteam.utils.CommomUtil;
...@@ -33,9 +32,6 @@ public class AttendanceService implements IAttendanceService { ...@@ -33,9 +32,6 @@ public class AttendanceService implements IAttendanceService {
@Autowired @Autowired
DbConnection dbConnection; DbConnection dbConnection;
@Autowired
ResourceRepo projectTeamMatesRepo;
@Autowired @Autowired
private PdfReportGenerator pdfReportGenerator; private PdfReportGenerator pdfReportGenerator;
......
package com.nisum.myteam.service.impl; //package com.nisum.myteam.service.impl;
//
import java.util.Comparator; //import java.util.Comparator;
import java.util.List; //import java.util.List;
import java.util.stream.Collectors; //import java.util.stream.Collectors;
//
import org.springframework.beans.factory.annotation.Autowired; //import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate; //import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria; //import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query; //import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Service; //import org.springframework.stereotype.Service;
//
import com.nisum.myteam.model.dao.Billing; //import com.nisum.myteam.model.dao.Billing;
import com.nisum.myteam.model.dao.Employee; //import com.nisum.myteam.model.dao.Employee;
import com.nisum.myteam.repository.BillingRepo; //import com.nisum.myteam.repository.BillingRepo;
import com.nisum.myteam.service.IBillingService; //import com.nisum.myteam.service.IBillingService;
import com.nisum.myteam.utils.MyTeamUtils; //import com.nisum.myteam.utils.MyTeamUtils;
//
import lombok.extern.slf4j.Slf4j; //import lombok.extern.slf4j.Slf4j;
//
@Service //@Service
@Slf4j //@Slf4j
public class BillingService implements IBillingService { //public class BillingService implements IBillingService {
//
@Autowired // @Autowired
private BillingRepo billingRepo; // private BillingRepo billingRepo;
//
@Autowired // @Autowired
private MongoTemplate mongoTemplate; // private MongoTemplate mongoTemplate;
//
@Override // @Override
public Billing addBilling(Billing billing, String loginEmpId) { // public Billing addBilling(Billing billing, String loginEmpId) {
billing.setAuditFields(loginEmpId, MyTeamUtils.CREATE); // billing.setAuditFields(loginEmpId, MyTeamUtils.CREATE);
return billingRepo.save(billing); // return billingRepo.save(billing);
} // }
//
@Override // @Override
public Billing updateBilling(Billing billing, String loginEmpId) { // public Billing updateBilling(Billing billing, String loginEmpId) {
billing.setAuditFields(loginEmpId, MyTeamUtils.UPDATE); // billing.setAuditFields(loginEmpId, MyTeamUtils.UPDATE);
return billingRepo.save(billing); // return billingRepo.save(billing);
} // }
//
@Override // @Override
public void deleteBilling(Billing billing) { // public void deleteBilling(Billing billing) {
billingRepo.delete(billing); // billingRepo.delete(billing);
} // }
//
@Override // @Override
public List<Billing> getBillingsForProject(String empId, String projectId) { // public List<Billing> getBillingsForProject(String empId, String projectId) {
List<Billing> billingsList = billingRepo.findByEmployeeIdAndProjectId(empId, projectId); // List<Billing> billingsList = billingRepo.findByEmployeeIdAndProjectId(empId, projectId);
//
if (billingsList == null || billingsList.size() == 0) { // if (billingsList == null || billingsList.size() == 0) {
return billingsList; // return billingsList;
} else { // } else {
//return billingsList.stream().sorted(Comparator.comparing(Billing::getCreatedOn).reversed()).collect(Collectors.toList()); // //return billingsList.stream().sorted(Comparator.comparing(Billing::getCreatedOn).reversed()).collect(Collectors.toList());
return billingsList.stream().sorted(Comparator.comparing(Billing::getBillingStartDate).reversed()).collect(Collectors.toList()); // return billingsList.stream().sorted(Comparator.comparing(Billing::getBillingStartDate).reversed()).collect(Collectors.toList());
} // }
//
} // }
//
@Override // @Override
public List<Billing> getBillingsForEmployee(String empId) { // public List<Billing> getBillingsForEmployee(String empId) {
List<Billing> billingsList = billingRepo.findByEmployeeId(empId); // List<Billing> billingsList = billingRepo.findByEmployeeId(empId);
if (billingsList == null || billingsList.size() == 0) { // if (billingsList == null || billingsList.size() == 0) {
return billingsList; // return billingsList;
} else { // } else {
log.info("The billing list before sorting::"+billingsList); // log.info("The billing list before sorting::"+billingsList);
//return billingsList.stream().sorted(Comparator.comparing(Billing::getCreatedOn).reversed()).collect(Collectors.toList()); // //return billingsList.stream().sorted(Comparator.comparing(Billing::getCreatedOn).reversed()).collect(Collectors.toList());
return billingsList.stream().sorted(Comparator.comparing(Billing::getBillingStartDate).reversed()).collect(Collectors.toList()); // return billingsList.stream().sorted(Comparator.comparing(Billing::getBillingStartDate).reversed()).collect(Collectors.toList());
//
} // }
} // }
//
@Override // @Override
public List<Billing> getActiveBillings(String empId, String projectId) { // public List<Billing> getActiveBillings(String empId, String projectId) {
Query query = new Query(); // Query query = new Query();
query.addCriteria(Criteria.where("active").is(new Boolean(true))); // query.addCriteria(Criteria.where("active").is(new Boolean(true)));
query.addCriteria(Criteria.where("employeeId").is(empId)); // query.addCriteria(Criteria.where("employeeId").is(empId));
query.addCriteria(Criteria.where("projectId").is(projectId)); // query.addCriteria(Criteria.where("projectId").is(projectId));
//
List<Billing> billingList = mongoTemplate.find(query, Billing.class); // List<Billing> billingList = mongoTemplate.find(query, Billing.class);
//
if (billingList == null || billingList.size() == 0) { // if (billingList == null || billingList.size() == 0) {
return billingList; // return billingList;
} else { // } else {
return billingList.stream().sorted(Comparator.comparing(Billing::getBillingStartDate).reversed()) // return billingList.stream().sorted(Comparator.comparing(Billing::getBillingStartDate).reversed())
.collect(Collectors.toList()); // .collect(Collectors.toList());
} // }
//
} // }
//
public Billing addBillingtoResource(Billing billing, Employee employee, String loginEmpId) { // public Billing addBillingtoResource(Billing billing, Employee employee, String loginEmpId) {
//
billing.setBillingEndDate(employee.getEndDate()); // billing.setBillingEndDate(employee.getEndDate());
billing.setActive(false); // billing.setActive(false);
billing.setAuditFields(loginEmpId, MyTeamUtils.UPDATE); // billing.setAuditFields(loginEmpId, MyTeamUtils.UPDATE);
return billingRepo.save(billing); // return billingRepo.save(billing);
} // }
//
} //}
package com.nisum.myteam.service.impl; //package com.nisum.myteam.service.impl;
//
import java.util.*; //import java.util.*;
import java.util.stream.Collectors; //import java.util.stream.Collectors;
import org.springframework.beans.factory.annotation.Autowired; //import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort; //import org.springframework.data.domain.Sort;
import org.springframework.data.mongodb.core.MongoTemplate; //import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria; //import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query; //import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Service; //import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils; //import org.springframework.util.CollectionUtils;
//
import com.nisum.myteam.exception.handler.MyTeamException; //import com.nisum.myteam.exception.handler.MyTeamException;
import com.nisum.myteam.model.dao.Billing; //import com.nisum.myteam.model.dao.Billing;
import com.nisum.myteam.model.dao.Employee; //import com.nisum.myteam.model.dao.Employee;
import com.nisum.myteam.model.dao.Project; //import com.nisum.myteam.model.dao.Project;
import com.nisum.myteam.model.dao.Resource; //import com.nisum.myteam.model.dao.Resource;
import com.nisum.myteam.repository.BillingRepo; //import com.nisum.myteam.repository.BillingRepo;
import com.nisum.myteam.repository.EmployeeRepo; //import com.nisum.myteam.repository.EmployeeRepo;
import com.nisum.myteam.repository.ProjectRepo; //import com.nisum.myteam.repository.ProjectRepo;
import com.nisum.myteam.repository.ResourceRepo; //import com.nisum.myteam.repository.ResourceRepo;
import com.nisum.myteam.service.IEmployeeRoleService; //import com.nisum.myteam.service.IEmployeeRoleService;
import com.nisum.myteam.service.IResourceService; //import com.nisum.myteam.service.IResourceService;
import com.nisum.myteam.service.IRoleService; //import com.nisum.myteam.service.IRoleService;
import com.nisum.myteam.utils.MyTeamResultDTO; //import com.nisum.myteam.utils.MyTeamResultDTO;
import com.nisum.myteam.utils.MyTeamUtils; //import com.nisum.myteam.utils.MyTeamUtils;
//
import lombok.extern.slf4j.Slf4j; //import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.time.DateUtils; //import org.apache.commons.lang.time.DateUtils;
import org.bson.types.ObjectId; //import org.bson.types.ObjectId;
//
@Service //@Service
@Slf4j //@Slf4j
public class ResourceService implements IResourceService { //public class ResourceService implements IResourceService {
//
@Autowired // @Autowired
private BillingService billingService; // private BillingService billingService;
//
@Autowired // @Autowired
private EmployeeShiftService empShiftService; // private EmployeeShiftService empShiftService;
//
@Autowired // @Autowired
private ResourceRepo resourceRepo; // private ResourceRepo resourceRepo;
//
@Autowired // @Autowired
private MongoTemplate mongoTemplate; // private MongoTemplate mongoTemplate;
//
@Autowired // @Autowired
private IRoleService roleInfoService; // private IRoleService roleInfoService;
//
@Autowired // @Autowired
private IEmployeeRoleService roleMappingService; // private IEmployeeRoleService roleMappingService;
//
@Autowired // @Autowired
private ProjectRepo projectRepo; // private ProjectRepo projectRepo;
//
@Autowired // @Autowired
private BillingRepo billingRepo; // private BillingRepo billingRepo;
//
@Autowired // @Autowired
private ProjectService projectService; // private ProjectService projectService;
//
@Autowired // @Autowired
private EmployeeRepo employeeRepo; // private EmployeeRepo employeeRepo;
//
public Resource save(Resource resource) { // public Resource save(Resource resource) {
return resourceRepo.save(resource); // return resourceRepo.save(resource);
} // }
//
public Resource addResource(Resource resourceReq, String loginEmpId) throws MyTeamException { // public Resource addResource(Resource resourceReq, String loginEmpId) throws MyTeamException {
//
// calling a method // // calling a method
updateProjectEndDateForResource(resourceReq, loginEmpId); // updateProjectEndDateForResource(resourceReq, loginEmpId);
//
resourceReq.setAuditFields(loginEmpId, MyTeamUtils.CREATE); // resourceReq.setAuditFields(loginEmpId, MyTeamUtils.CREATE);
Resource resourcePersisted = resourceRepo.save(resourceReq); // Resource resourcePersisted = resourceRepo.save(resourceReq);
//
//
// Get Active billings for Nisum Bench Project. // // Get Active billings for Nisum Bench Project.
List<Billing> listBD = billingService.getActiveBillings(resourcePersisted.getEmployeeId(), "Nisum0000"); // List<Billing> listBD = billingService.getActiveBillings(resourcePersisted.getEmployeeId(), "Nisum0000");
//
Date startDate = resourcePersisted.getStartDate() != null ? resourcePersisted.getStartDate() : new Date(); // Date startDate = resourcePersisted.getStartDate() != null ? resourcePersisted.getStartDate() : new Date();
if (listBD != null && listBD.size() > 0) { // if (listBD != null && listBD.size() > 0) {
Billing bDetails = listBD.get(0); // Billing bDetails = listBD.get(0);
if (startDate.compareTo(bDetails.getBillingStartDate()) > 0) { // if (startDate.compareTo(bDetails.getBillingStartDate()) > 0) {
bDetails.setBillingEndDate(DateUtils.truncate(DateUtils.addDays(startDate, -1), Calendar.DATE)); // bDetails.setBillingEndDate(DateUtils.truncate(DateUtils.addDays(startDate, -1), Calendar.DATE));
} else { // } else {
bDetails.setBillingEndDate(startDate); // bDetails.setBillingEndDate(startDate);
} // }
bDetails.setActive(false); // bDetails.setActive(false);
billingService.updateBilling(bDetails, loginEmpId); // billingService.updateBilling(bDetails, loginEmpId);
} // }
//
Billing billings = new Billing(); // Billing billings = new Billing();
billings.setEmployeeId(resourcePersisted.getEmployeeId()); // billings.setEmployeeId(resourcePersisted.getEmployeeId());
billings.setEmployeeName(resourcePersisted.getEmployeeName()); // billings.setEmployeeName(resourcePersisted.getEmployeeName());
billings.setProjectId(resourcePersisted.getProjectId()); // billings.setProjectId(resourcePersisted.getProjectId());
billings.setProjectName(resourcePersisted.getProjectName()); // billings.setProjectName(resourcePersisted.getProjectName());
billings.setBillableStatus(resourcePersisted.getBillableStatus()); // billings.setBillableStatus(resourcePersisted.getBillableStatus());
billings.setAccount(resourcePersisted.getAccount()); // billings.setAccount(resourcePersisted.getAccount());
billings.setActive(resourcePersisted.isActive()); // billings.setActive(resourcePersisted.isActive());
if (!resourceReq.getProjectId().equalsIgnoreCase("Nisum0000")) { // if (!resourceReq.getProjectId().equalsIgnoreCase("Nisum0000")) {
billings.setBillingStartDate(DateUtils.truncate(resourcePersisted.getNewBillingStartDate(), Calendar.DATE)); // billings.setBillingStartDate(DateUtils.truncate(resourcePersisted.getNewBillingStartDate(), Calendar.DATE));
} else { // } else {
billings.setBillingStartDate(DateUtils.truncate(resourcePersisted.getStartDate(), Calendar.DATE)); // billings.setBillingStartDate(DateUtils.truncate(resourcePersisted.getStartDate(), Calendar.DATE));
} // }
if (resourcePersisted.getEndDate() != null) { // if (resourcePersisted.getEndDate() != null) {
billings.setBillingEndDate(DateUtils.truncate(resourcePersisted.getEndDate(), Calendar.DATE)); // billings.setBillingEndDate(DateUtils.truncate(resourcePersisted.getEndDate(), Calendar.DATE));
} // }
//
billingService.addBilling(billings, loginEmpId); // billingService.addBilling(billings, loginEmpId);
//
//empShiftService.addEmployeeShift(resourceReq, loginEmpId); // //empShiftService.addEmployeeShift(resourceReq, loginEmpId);
//
// calling method // // calling method
addOrUpdateTeamMateRole(resourceReq.getRole(), resourceReq.getProjectId(), resourceReq.getEmployeeId(), false, // addOrUpdateTeamMateRole(resourceReq.getRole(), resourceReq.getProjectId(), resourceReq.getEmployeeId(), false,
loginEmpId); // loginEmpId);
//
return resourcePersisted; // return resourcePersisted;
} // }
//
public String updateResource(Resource resourceReq, String loginEmpId) throws MyTeamException { // public String updateResource(Resource resourceReq, String loginEmpId) throws MyTeamException {
// String result = null; // // String result = null;
MyTeamResultDTO myResultDto = new MyTeamResultDTO(); // MyTeamResultDTO myResultDto = new MyTeamResultDTO();
myResultDto.setResultCode(MyTeamResultDTO.SUCCESS_CODE); // myResultDto.setResultCode(MyTeamResultDTO.SUCCESS_CODE);
//
myResultDto.setResultData("TeamMate updated successfuly"); // myResultDto.setResultData("TeamMate updated successfuly");
//
Resource existingResource = resourceRepo.findById(resourceReq.getId()); // Resource existingResource = resourceRepo.findById(resourceReq.getId());
log.info("From database: Resource Details::"+existingResource); // log.info("From database: Resource Details::"+existingResource);
//
//
Date resEndDate = resourceReq.getEndDate(); // Date resEndDate = resourceReq.getEndDate();
log.info("ResEndDate::"+resEndDate); // log.info("ResEndDate::"+resEndDate);
List<Billing> listBD = billingService.getActiveBillings(resourceReq.getEmployeeId(), resourceReq.getProjectId()); // List<Billing> listBD = billingService.getActiveBillings(resourceReq.getEmployeeId(), resourceReq.getProjectId());
//
// Handling past or present endDate (To "Inactive" the Resource) // // Handling past or present endDate (To "Inactive" the Resource)
if (resEndDate.compareTo(new Date()) <= 0 && resEndDate.compareTo(existingResource.getEndDate()) != 0) { // if (resEndDate.compareTo(new Date()) <= 0 && resEndDate.compareTo(existingResource.getEndDate()) != 0) {
existingResource.setActive(false); // existingResource.setActive(false);
existingResource.setEndDate(resEndDate); // existingResource.setEndDate(resEndDate);
if (listBD != null && !listBD.isEmpty()) { // if (listBD != null && !listBD.isEmpty()) {
Billing billingDetailsExisting = listBD.get(0); // Billing billingDetailsExisting = listBD.get(0);
Date actualEndDate = resEndDate; // Date actualEndDate = resEndDate;
billingDetailsExisting.setBillingEndDate(actualEndDate); // billingDetailsExisting.setBillingEndDate(actualEndDate);
billingDetailsExisting.setActive(false); // billingDetailsExisting.setActive(false);
billingService.updateBilling(billingDetailsExisting, loginEmpId); // billingService.updateBilling(billingDetailsExisting, loginEmpId);
} // }
//
Project project = projectRepo.findByProjectId(MyTeamUtils.BENCH_PROJECT_ID); // Project project = projectRepo.findByProjectId(MyTeamUtils.BENCH_PROJECT_ID);
//
Resource newBenchAllocation = new Resource(); // Resource newBenchAllocation = new Resource();
Billing billingDetails = new Billing(); // Billing billingDetails = new Billing();
billingDetails.setBillableStatus(MyTeamUtils.BENCH_BILLABILITY_STATUS); // billingDetails.setBillableStatus(MyTeamUtils.BENCH_BILLABILITY_STATUS);
billingDetails.setBillingStartDate(resEndDate); // billingDetails.setBillingStartDate(resEndDate);
billingDetails.setAccount(MyTeamUtils.BENCH_ACCOUNT); // billingDetails.setAccount(MyTeamUtils.BENCH_ACCOUNT);
billingDetails.setActive(true); // billingDetails.setActive(true);
billingDetails.setEmployeeId(existingResource.getEmployeeId()); // billingDetails.setEmployeeId(existingResource.getEmployeeId());
billingDetails.setEmployeeName(existingResource.getEmployeeName()); // billingDetails.setEmployeeName(existingResource.getEmployeeName());
// billingDetails.setCreateDate(new Date());// Commented as added // // billingDetails.setCreateDate(new Date());// Commented as added
// common audit fields // // common audit fields
billingDetails.setProjectId(MyTeamUtils.BENCH_PROJECT_ID); // billingDetails.setProjectId(MyTeamUtils.BENCH_PROJECT_ID);
billingDetails.setProjectName(MyTeamUtils.FREE_POLL); // billingDetails.setProjectName(MyTeamUtils.FREE_POLL);
if (project != null) { // if (project != null) {
billingDetails.setBillingEndDate(project.getProjectEndDate()); // billingDetails.setBillingEndDate(project.getProjectEndDate());
newBenchAllocation.setAccountId(project.getAccountId()); // newBenchAllocation.setAccountId(project.getAccountId());
newBenchAllocation.setDomainId(project.getDomainId()); // newBenchAllocation.setDomainId(project.getDomainId());
newBenchAllocation.setProjectName(project.getProjectName()); // newBenchAllocation.setProjectName(project.getProjectName());
newBenchAllocation.setEndDate(project.getProjectEndDate()); // newBenchAllocation.setEndDate(project.getProjectEndDate());
} // }
billingService.addBilling(billingDetails, loginEmpId); // billingService.addBilling(billingDetails, loginEmpId);
//
newBenchAllocation.setBillableStatus(MyTeamUtils.BENCH_BILLABILITY_STATUS); // newBenchAllocation.setBillableStatus(MyTeamUtils.BENCH_BILLABILITY_STATUS);
newBenchAllocation.setDesignation(existingResource.getDesignation()); // newBenchAllocation.setDesignation(existingResource.getDesignation());
newBenchAllocation.setEmailId(existingResource.getEmailId()); // newBenchAllocation.setEmailId(existingResource.getEmailId());
newBenchAllocation.setEmployeeId(existingResource.getEmployeeId()); // newBenchAllocation.setEmployeeId(existingResource.getEmployeeId());
newBenchAllocation.setActive(true); // newBenchAllocation.setActive(true);
newBenchAllocation.setEmployeeName(existingResource.getEmployeeName()); // newBenchAllocation.setEmployeeName(existingResource.getEmployeeName());
newBenchAllocation.setProjectId(MyTeamUtils.BENCH_PROJECT_ID); // newBenchAllocation.setProjectId(MyTeamUtils.BENCH_PROJECT_ID);
newBenchAllocation.setShift(existingResource.getShift()); // newBenchAllocation.setShift(existingResource.getShift());
newBenchAllocation.setRole(existingResource.getRole()); // newBenchAllocation.setRole(existingResource.getRole());
//
Calendar cal = Calendar.getInstance(); // Calendar cal = Calendar.getInstance();
cal.setTime(resEndDate); // cal.setTime(resEndDate);
cal.add(Calendar.DAY_OF_MONTH, 1); // cal.add(Calendar.DAY_OF_MONTH, 1);
//
newBenchAllocation.setStartDate(DateUtils.truncate(cal.getTime(), Calendar.DATE)); // newBenchAllocation.setStartDate(DateUtils.truncate(cal.getTime(), Calendar.DATE));
newBenchAllocation.setNewBillingStartDate(DateUtils.truncate(cal.getTime(), Calendar.DATE)); // newBenchAllocation.setNewBillingStartDate(DateUtils.truncate(cal.getTime(), Calendar.DATE));
newBenchAllocation.setAuditFields(loginEmpId, MyTeamUtils.CREATE);// Setting // newBenchAllocation.setAuditFields(loginEmpId, MyTeamUtils.CREATE);// Setting
// audit // // audit
// fields // // fields
resourceRepo.save(newBenchAllocation); // resourceRepo.save(newBenchAllocation);
//
myResultDto.setResultCode(MyTeamResultDTO.SUCCESS_CODE); // myResultDto.setResultCode(MyTeamResultDTO.SUCCESS_CODE);
myResultDto.setResultData( // myResultDto.setResultData(
"Resource Successfully moved from " + resourceReq.getProjectName() + " project to Bench."); // "Resource Successfully moved from " + resourceReq.getProjectName() + " project to Bench.");
} else { // } else {
//
//
log.info("Before compare billable status::"); // log.info("Before compare billable status::");
log.info("Existing Resource:::"+existingResource); // log.info("Existing Resource:::"+existingResource);
log.info("Resource Request Details::"+resourceReq); // log.info("Resource Request Details::"+resourceReq);
//
// Handling Resource Project Billability Status change // // Handling Resource Project Billability Status change
if (resourceReq.getBillableStatus() != null && existingResource.getBillableStatus() != null // if (resourceReq.getBillableStatus() != null && existingResource.getBillableStatus() != null
&& !existingResource.getBillableStatus().equalsIgnoreCase(resourceReq.getBillableStatus())) { // && !existingResource.getBillableStatus().equalsIgnoreCase(resourceReq.getBillableStatus())) {
/* // /*
* List<BillingDetails> bDetailsList = // * List<BillingDetails> bDetailsList =
* teamMatesBillingRepo.findByEmployeeId(projectTeamMate. // * teamMatesBillingRepo.findByEmployeeId(projectTeamMate.
* getEmployeeId()).stream() .filter(e -> // * getEmployeeId()).stream() .filter(e ->
* (!e.isActive())).sorted(Comparator.comparing(BillingDetails:: // * (!e.isActive())).sorted(Comparator.comparing(BillingDetails::
* getBillingEndDate).reversed()) .collect(Collectors.toList()); // * getBillingEndDate).reversed()) .collect(Collectors.toList());
*/ // */
String result = validateBillabilityStartDate(listBD, resourceReq); // String result = validateBillabilityStartDate(listBD, resourceReq);
if (result != null) { // Invalid Billability Start date // if (result != null) { // Invalid Billability Start date
return result; // return result;
} // }
if (listBD != null && !listBD.isEmpty()) { // if (listBD != null && !listBD.isEmpty()) {
Billing billingDetails = listBD.get(0); // Billing billingDetails = listBD.get(0);
Calendar cal = Calendar.getInstance(); // Calendar cal = Calendar.getInstance();
cal.setTime(resourceReq.getNewBillingStartDate()); // cal.setTime(resourceReq.getNewBillingStartDate());
cal.add(Calendar.DAY_OF_MONTH, -1); // cal.add(Calendar.DAY_OF_MONTH, -1);
Date startDate = existingResource.getNewBillingStartDate() != null // Date startDate = existingResource.getNewBillingStartDate() != null
? existingResource.getNewBillingStartDate() : existingResource.getStartDate(); // ? existingResource.getNewBillingStartDate() : existingResource.getStartDate();
if (startDate.getDate() == resourceReq.getNewBillingStartDate().getDate()) { // if (startDate.getDate() == resourceReq.getNewBillingStartDate().getDate()) {
billingDetails.setBillingEndDate( // billingDetails.setBillingEndDate(
DateUtils.truncate(resourceReq.getNewBillingStartDate(), Calendar.DATE)); // DateUtils.truncate(resourceReq.getNewBillingStartDate(), Calendar.DATE));
} else { // } else {
billingDetails.setBillingEndDate(DateUtils.truncate(cal.getTime(), Calendar.DATE)); // billingDetails.setBillingEndDate(DateUtils.truncate(cal.getTime(), Calendar.DATE));
} // }
billingDetails.setActive(false); // billingDetails.setActive(false);
billingService.updateBilling(billingDetails, loginEmpId); // billingService.updateBilling(billingDetails, loginEmpId);
} // }
Billing billings = new Billing(); // Billing billings = new Billing();
billings.setEmployeeId(resourceReq.getEmployeeId()); // billings.setEmployeeId(resourceReq.getEmployeeId());
billings.setEmployeeName(resourceReq.getEmployeeName()); // billings.setEmployeeName(resourceReq.getEmployeeName());
billings.setProjectId(resourceReq.getProjectId()); // billings.setProjectId(resourceReq.getProjectId());
billings.setAccount(existingResource.getAccount()); // billings.setAccount(existingResource.getAccount());
billings.setProjectName(resourceReq.getProjectName()); // billings.setProjectName(resourceReq.getProjectName());
billings.setBillableStatus(resourceReq.getBillableStatus()); // billings.setBillableStatus(resourceReq.getBillableStatus());
billings.setActive(true); // billings.setActive(true);
billings.setBillingStartDate(DateUtils.truncate(resourceReq.getNewBillingStartDate(), Calendar.DATE)); // billings.setBillingStartDate(DateUtils.truncate(resourceReq.getNewBillingStartDate(), Calendar.DATE));
billings.setBillingEndDate(DateUtils.truncate(resEndDate, Calendar.DATE)); // billings.setBillingEndDate(DateUtils.truncate(resEndDate, Calendar.DATE));
// billings.setCreateDate(new Date());// Commented as added // // billings.setCreateDate(new Date());// Commented as added
// common audit fields // // common audit fields
billingService.addBilling(billings, loginEmpId); // billingService.addBilling(billings, loginEmpId);
//
existingResource.setBillableStatus(resourceReq.getBillableStatus()); // existingResource.setBillableStatus(resourceReq.getBillableStatus());
existingResource // existingResource
.setNewBillingStartDate(DateUtils.truncate(resourceReq.getNewBillingStartDate(), Calendar.DATE)); // .setNewBillingStartDate(DateUtils.truncate(resourceReq.getNewBillingStartDate(), Calendar.DATE));
//
} else {// Handling Billability Start Date change // } else {// Handling Billability Start Date change
List<Billing> bDetailsList = billingRepo.findByEmployeeId(resourceReq.getEmployeeId()).stream() // List<Billing> bDetailsList = billingRepo.findByEmployeeId(resourceReq.getEmployeeId()).stream()
.filter(e -> (!e.isActive())) // .filter(e -> (!e.isActive()))
.sorted(Comparator.comparing(Billing::getBillingEndDate).reversed()) // .sorted(Comparator.comparing(Billing::getBillingEndDate).reversed())
.collect(Collectors.toList()); // .collect(Collectors.toList());
String result = validateBillabilityStartDate(bDetailsList, resourceReq); // String result = validateBillabilityStartDate(bDetailsList, resourceReq);
if (result != null) { // Invalid Billability Start date // if (result != null) { // Invalid Billability Start date
return result; // return result;
} // }
if (bDetailsList != null && !bDetailsList.isEmpty()) { // if (bDetailsList != null && !bDetailsList.isEmpty()) {
Calendar cal = Calendar.getInstance(); // Calendar cal = Calendar.getInstance();
cal.setTime(resourceReq.getNewBillingStartDate()); // cal.setTime(resourceReq.getNewBillingStartDate());
cal.add(Calendar.DAY_OF_MONTH, -1); // cal.add(Calendar.DAY_OF_MONTH, -1);
Billing preBillingDetails = bDetailsList.get(0); // Billing preBillingDetails = bDetailsList.get(0);
if (preBillingDetails.getBillingStartDate().getDate() == resourceReq.getNewBillingStartDate() // if (preBillingDetails.getBillingStartDate().getDate() == resourceReq.getNewBillingStartDate()
.getDate()) { // .getDate()) {
preBillingDetails.setBillingEndDate( // preBillingDetails.setBillingEndDate(
DateUtils.truncate(resourceReq.getNewBillingStartDate(), Calendar.DATE)); // DateUtils.truncate(resourceReq.getNewBillingStartDate(), Calendar.DATE));
} else { // } else {
preBillingDetails.setBillingEndDate(DateUtils.truncate(cal.getTime(), Calendar.DATE)); // preBillingDetails.setBillingEndDate(DateUtils.truncate(cal.getTime(), Calendar.DATE));
} // }
billingService.updateBilling(preBillingDetails, loginEmpId); // billingService.updateBilling(preBillingDetails, loginEmpId);
} // }
if (listBD != null && !listBD.isEmpty()) { // if (listBD != null && !listBD.isEmpty()) {
Billing billingDetails = listBD.get(0); // Billing billingDetails = listBD.get(0);
billingDetails // billingDetails
.setBillingStartDate(DateUtils.truncate(resourceReq.getNewBillingStartDate(), Calendar.DATE)); // .setBillingStartDate(DateUtils.truncate(resourceReq.getNewBillingStartDate(), Calendar.DATE));
billingDetails.setBillingEndDate(DateUtils.truncate(resEndDate, Calendar.DATE)); // billingDetails.setBillingEndDate(DateUtils.truncate(resEndDate, Calendar.DATE));
billingService.addBilling(billingDetails, loginEmpId); // billingService.addBilling(billingDetails, loginEmpId);
} // }
existingResource // existingResource
.setNewBillingStartDate(DateUtils.truncate(resourceReq.getNewBillingStartDate(), Calendar.DATE)); // .setNewBillingStartDate(DateUtils.truncate(resourceReq.getNewBillingStartDate(), Calendar.DATE));
} // }
if (resEndDate.compareTo(existingResource.getEndDate()) != 0) { // if (resEndDate.compareTo(existingResource.getEndDate()) != 0) {
existingResource.setEndDate(resEndDate); // existingResource.setEndDate(resEndDate);
} // }
} // }
//
if (MyTeamResultDTO.SUCCESS_CODE.equals(myResultDto.getResultCode())) { // if (MyTeamResultDTO.SUCCESS_CODE.equals(myResultDto.getResultCode())) {
// Handling Role change // // Handling Role change
if ((existingResource.getRole() != null && !existingResource.getRole().equalsIgnoreCase(resourceReq.getRole())) // if ((existingResource.getRole() != null && !existingResource.getRole().equalsIgnoreCase(resourceReq.getRole()))
|| (resourceReq.getRole() != null) // || (resourceReq.getRole() != null)
&& !resourceReq.getRole().equalsIgnoreCase(existingResource.getRole())) { // && !resourceReq.getRole().equalsIgnoreCase(existingResource.getRole())) {
existingResource.setRole(resourceReq.getRole()); // existingResource.setRole(resourceReq.getRole());
addOrUpdateTeamMateRole(resourceReq.getRole(), resourceReq.getProjectId(), resourceReq.getEmployeeId(), true, // addOrUpdateTeamMateRole(resourceReq.getRole(), resourceReq.getProjectId(), resourceReq.getEmployeeId(), true,
loginEmpId); // loginEmpId);
} // }
// Handling Shift change // // Handling Shift change
if ((existingResource.getShift() != null // if ((existingResource.getShift() != null
&& !existingResource.getShift().equalsIgnoreCase(resourceReq.getShift())) // && !existingResource.getShift().equalsIgnoreCase(resourceReq.getShift()))
|| (resourceReq.getShift() != null) // || (resourceReq.getShift() != null)
&& !resourceReq.getShift().equalsIgnoreCase(existingResource.getShift())) { // && !resourceReq.getShift().equalsIgnoreCase(existingResource.getShift())) {
//
//empShiftService.updateEmployeeShift(existingResource, loginEmpId); // //empShiftService.updateEmployeeShift(existingResource, loginEmpId);
//
existingResource.setShift(resourceReq.getShift()); // existingResource.setShift(resourceReq.getShift());
Employee employeeDB = employeeRepo.findByEmployeeId(resourceReq.getEmployeeId()); // Employee employeeDB = employeeRepo.findByEmployeeId(resourceReq.getEmployeeId());
employeeDB.setShift(resourceReq.getShift()); // employeeDB.setShift(resourceReq.getShift());
employeeDB.setModifiedBy(loginEmpId); // employeeDB.setModifiedBy(loginEmpId);
employeeDB.setLastModifiedOn(new Date()); // employeeDB.setLastModifiedOn(new Date());
employeeRepo.save(employeeDB); // employeeRepo.save(employeeDB);
} // }
existingResource.setAuditFields(loginEmpId, MyTeamUtils.UPDATE);// Setting // existingResource.setAuditFields(loginEmpId, MyTeamUtils.UPDATE);// Setting
// audit // // audit
// fields // // fields
resourceRepo.save(existingResource); // resourceRepo.save(existingResource);
} // }
return myResultDto.getResultData()[myResultDto.getDataArrayCounter()]; // return myResultDto.getResultData()[myResultDto.getDataArrayCounter()];
} // }
//
private String validateBillabilityStartDate(List<Billing> billingList, Resource resource) { // private String validateBillabilityStartDate(List<Billing> billingList, Resource resource) {
String response = null; // String response = null;
if (billingList != null && billingList.size() > 0) { // if (billingList != null && billingList.size() > 0) {
Billing billing = billingList.get(0); // Billing billing = billingList.get(0);
if (resource.getNewBillingStartDate().compareTo(billing.getBillingStartDate()) < 0) { // if (resource.getNewBillingStartDate().compareTo(billing.getBillingStartDate()) < 0) {
response = "Resource Billability Start Date (" + resource.getNewBillingStartDate() + " ) for " // response = "Resource Billability Start Date (" + resource.getNewBillingStartDate() + " ) for "
+ resource.getBillableStatus() + " status should be later than previous billability (" // + resource.getBillableStatus() + " status should be later than previous billability ("
+ billing.getBillableStatus() + " status) Start Date ( " + billing.getBillingStartDate() + ")."; // + billing.getBillableStatus() + " status) Start Date ( " + billing.getBillingStartDate() + ").";
} // }
} else { // } else {
response = validateAgainstDOJ(resource); // response = validateAgainstDOJ(resource);
} // }
return response; // return response;
} // }
//
//
// @Override //// @Override
public Resource deleteResource(String empId, String projectId, ObjectId id, String loginEmpId) { // public Resource deleteResource(String empId, String projectId, ObjectId id, String loginEmpId) {
Resource existingResource = resourceRepo.findById(id); // Resource existingResource = resourceRepo.findById(id);
existingResource.setActive(false); // existingResource.setActive(false);
existingResource.setEndDate(new Date()); // existingResource.setEndDate(new Date());
Billing billingDetails = new Billing(); // Billing billingDetails = new Billing();
billingDetails.setBillableStatus("Non-Billable"); // billingDetails.setBillableStatus("Non-Billable");
billingDetails.setBillingStartDate(new Date()); // billingDetails.setBillingStartDate(new Date());
billingDetails.setAccount("Nisum"); // billingDetails.setAccount("Nisum");
billingDetails.setActive(true); // billingDetails.setActive(true);
billingDetails.setEmployeeId(existingResource.getEmployeeId()); // billingDetails.setEmployeeId(existingResource.getEmployeeId());
billingDetails.setEmployeeName(existingResource.getEmployeeName()); // billingDetails.setEmployeeName(existingResource.getEmployeeName());
// billingDetails.setCreateDate(new Date());// Commented as added common // // billingDetails.setCreateDate(new Date());// Commented as added common
// audit fields // // audit fields
billingDetails.setProjectId("Nisum0000"); // billingDetails.setProjectId("Nisum0000");
billingDetails.setProjectName(MyTeamUtils.FREE_POLL); // billingDetails.setProjectName(MyTeamUtils.FREE_POLL);
billingService.addBilling(billingDetails, loginEmpId); // billingService.addBilling(billingDetails, loginEmpId);
List<Billing> listBD = billingService.getActiveBillings(empId, projectId); // List<Billing> listBD = billingService.getActiveBillings(empId, projectId);
if (listBD != null && !listBD.isEmpty()) { // if (listBD != null && !listBD.isEmpty()) {
Billing billingDetailsExisting = listBD.get(0); // Billing billingDetailsExisting = listBD.get(0);
Date d = new Date(); // Date d = new Date();
d.setDate(d.getDate() - 1); // d.setDate(d.getDate() - 1);
billingDetailsExisting.setBillingEndDate(d); // billingDetailsExisting.setBillingEndDate(d);
billingDetailsExisting.setActive(false); // billingDetailsExisting.setActive(false);
billingService.updateBilling(billingDetailsExisting, loginEmpId); // billingService.updateBilling(billingDetailsExisting, loginEmpId);
} // }
existingResource.setAuditFields(loginEmpId, MyTeamUtils.UPDATE);// Setting // existingResource.setAuditFields(loginEmpId, MyTeamUtils.UPDATE);// Setting
// audit // // audit
// fields // // fields
resourceRepo.save(existingResource); // resourceRepo.save(existingResource);
Resource resourceBench = new Resource(); // Resource resourceBench = new Resource();
resourceBench.setAccount("Nisum"); // resourceBench.setAccount("Nisum");
resourceBench.setBillableStatus("Non-Billable"); // resourceBench.setBillableStatus("Non-Billable");
resourceBench.setDesignation(existingResource.getDesignation()); // resourceBench.setDesignation(existingResource.getDesignation());
resourceBench.setEmailId(existingResource.getEmailId()); // resourceBench.setEmailId(existingResource.getEmailId());
resourceBench.setEmployeeId(existingResource.getEmployeeId()); // resourceBench.setEmployeeId(existingResource.getEmployeeId());
resourceBench.setActive(true); // resourceBench.setActive(true);
resourceBench.setEmployeeName(existingResource.getEmployeeName()); // resourceBench.setEmployeeName(existingResource.getEmployeeName());
resourceBench.setProjectId("Nisum0000"); // resourceBench.setProjectId("Nisum0000");
resourceBench.setStartDate(new Date()); // resourceBench.setStartDate(new Date());
Project p = projectRepo.findByProjectId("Nisum0000"); // Project p = projectRepo.findByProjectId("Nisum0000");
resourceBench.setProjectName(p.getProjectName()); // resourceBench.setProjectName(p.getProjectName());
// newBenchAllocation.setManagerId(p.getManagerId()); // // newBenchAllocation.setManagerId(p.getManagerId());
// newBenchAllocation.setManagerName(p.getManagerName()); // // newBenchAllocation.setManagerName(p.getManagerName());
resourceBench.setAuditFields(loginEmpId, MyTeamUtils.CREATE);// Setting // resourceBench.setAuditFields(loginEmpId, MyTeamUtils.CREATE);// Setting
// audit // // audit
// fields // // fields
Resource resource=resourceRepo.save(resourceBench); // Resource resource=resourceRepo.save(resourceBench);
//empShiftService.updateEmployeeShift(existingResource, loginEmpId); // //empShiftService.updateEmployeeShift(existingResource, loginEmpId);
//
return resource; // return resource;
} // }
//
// Update ProjectEndDate column data in ProjectTeamMate. // // Update ProjectEndDate column data in ProjectTeamMate.
private void updateProjectEndDateForResource(Resource resource, String loginEmpId) { // private void updateProjectEndDateForResource(Resource resource, String loginEmpId) {
List<Resource> projectTeamMateList = mongoTemplate // List<Resource> projectTeamMateList = mongoTemplate
.find(prepareQuery(resource.getEmployeeId(), MyTeamUtils.ENDDATE_COLUMN), Resource.class); // .find(prepareQuery(resource.getEmployeeId(), MyTeamUtils.ENDDATE_COLUMN), Resource.class);
log.info("the project teamates list is::" + projectTeamMateList); // log.info("the project teamates list is::" + projectTeamMateList);
if (!CollectionUtils.isEmpty(projectTeamMateList)) { // if (!CollectionUtils.isEmpty(projectTeamMateList)) {
Resource teamMate = projectTeamMateList.get(0); // Resource teamMate = projectTeamMateList.get(0);
if (resource.getNewBillingStartDate() != null) { // if (resource.getNewBillingStartDate() != null) {
Date d = resource.getNewBillingStartDate(); // Date d = resource.getNewBillingStartDate();
Calendar cal = Calendar.getInstance(); // Calendar cal = Calendar.getInstance();
cal.setTime(d); // cal.setTime(d);
cal.add(Calendar.DAY_OF_MONTH, -1); // cal.add(Calendar.DAY_OF_MONTH, -1);
Date oneDayLess = cal.getTime(); // Date oneDayLess = cal.getTime();
Date startDate = teamMate.getNewBillingStartDate() != null ? teamMate.getNewBillingStartDate() // Date startDate = teamMate.getNewBillingStartDate() != null ? teamMate.getNewBillingStartDate()
: teamMate.getStartDate(); // : teamMate.getStartDate();
if (startDate.getDate() == resource.getNewBillingStartDate().getDate()) { // if (startDate.getDate() == resource.getNewBillingStartDate().getDate()) {
teamMate.setEndDate(DateUtils.truncate(resource.getEndDate(), Calendar.DATE)); // teamMate.setEndDate(DateUtils.truncate(resource.getEndDate(), Calendar.DATE));
} else { // } else {
teamMate.setEndDate(DateUtils.truncate(oneDayLess, Calendar.DATE)); // teamMate.setEndDate(DateUtils.truncate(oneDayLess, Calendar.DATE));
}
}
teamMate.setActive(false);
teamMate.setAuditFields(loginEmpId, MyTeamUtils.UPDATE);// Setting
// audit
// fields
resourceRepo.save(teamMate);
}
}
private Query prepareQuery(String employeeId, String dateColumn) {
Query query = new Query();
query.addCriteria(Criteria.where(MyTeamUtils.EMPLOYEE_ID).is(employeeId));
query.limit(MyTeamUtils.ONE);
query.with(new Sort(Sort.Direction.DESC, dateColumn));
return query;
}
private void addOrUpdateTeamMateRole(String role, String projectId, String empId, boolean isUpdate,
String loginEmpId) throws MyTeamException {
Project project = projectRepo.findByProjectId(projectId);
int operationType = 0; // 0 = No Operation, 1 = Added, 2 = Removed
if (role != null && role.equals("Lead")) {
if (project.getManagerIds() == null) {
project.setManagerIds(Arrays.asList(empId));
operationType = 1;
} else if (project.getManagerIds() != null && !project.getManagerIds().contains(empId)) {
project.getManagerIds().add(empId);
operationType = 1;
}
} else if (isUpdate && project.getManagerIds() != null && project.getManagerIds().contains(empId)) {
project.getManagerIds().remove(empId);
operationType = 2;
}
if (operationType > 0) {
project.setAuditFields(loginEmpId, MyTeamUtils.UPDATE);
projectRepo.save(project);
Query query = new Query(Criteria.where("employeeId").is(empId).and("role").is("Lead"));
List<Resource> projectMates = mongoTemplate.find(query, Resource.class);
String roleId = roleInfoService.getRole(MyTeamUtils.LEAD);
if (operationType == 1) {
roleMappingService.addEmployeeRole(empId, roleId);
} else if (projectMates.size() == 0 || operationType == 2) {
roleMappingService.deleteRole(empId, roleId);
}
}
}
public void addResources(Employee employee, String loginEmpId) {
List<Resource> resourceList = resourceRepo.findByEmployeeId(employee.getEmployeeId());
if (resourceList != null && !resourceList.isEmpty()) {
for (Resource resource : resourceList) {
resource.setRole(employee.getRole());
resource.setAuditFields(loginEmpId, MyTeamUtils.UPDATE);
resourceRepo.save(resource);
}
}
// return null;
}
//public void inactivateResource(Employee employeeReq, Employee employeeUpdated, String loginEmpId) {
// // inactive the employee from the assigned project
// if (employeeReq.getEmpStatus().equals(MyTeamUtils.IN_ACTIVE_SPACE) && employeeReq.getEndDate() != null
// && employeeReq.getEndDate().compareTo(new Date()) <= 0) {
//
// List<Resource> resourcesList = resourceRepo.findByEmployeeIdAndActive(employeeReq.getEmployeeId(), true);
// if (resourcesList.size() == 1) {
// Resource resource = resourcesList.get(0);
// resource.setActive(false);
// resource.setEndDate(employeeReq.getEndDate());
//
// List<Billing> billingList = billingService.getActiveBillings(resource.getEmployeeId(),
// resource.getProjectId());
// if (billingList != null && !billingList.isEmpty()) {
// billingService.addBillingtoResource(billingList.get(0), employeeUpdated, loginEmpId);
// } // }
// }
//
// teamMate.setActive(false);
// teamMate.setAuditFields(loginEmpId, MyTeamUtils.UPDATE);// Setting
// // audit
// // fields
// resourceRepo.save(teamMate);
// }
//
// }
//
// private Query prepareQuery(String employeeId, String dateColumn) {
// Query query = new Query();
// query.addCriteria(Criteria.where(MyTeamUtils.EMPLOYEE_ID).is(employeeId));
// query.limit(MyTeamUtils.ONE);
// query.with(new Sort(Sort.Direction.DESC, dateColumn));
// return query;
// }
//
// private void addOrUpdateTeamMateRole(String role, String projectId, String empId, boolean isUpdate,
// String loginEmpId) throws MyTeamException {
// Project project = projectRepo.findByProjectId(projectId);
// int operationType = 0; // 0 = No Operation, 1 = Added, 2 = Removed
// if (role != null && role.equals("Lead")) {
// if (project.getManagerIds() == null) {
// project.setManagerIds(Arrays.asList(empId));
// operationType = 1;
// } else if (project.getManagerIds() != null && !project.getManagerIds().contains(empId)) {
// project.getManagerIds().add(empId);
// operationType = 1;
// }
// } else if (isUpdate && project.getManagerIds() != null && project.getManagerIds().contains(empId)) {
// project.getManagerIds().remove(empId);
// operationType = 2;
// }
// if (operationType > 0) {
// project.setAuditFields(loginEmpId, MyTeamUtils.UPDATE);
// projectRepo.save(project);
// Query query = new Query(Criteria.where("employeeId").is(empId).and("role").is("Lead"));
// List<Resource> projectMates = mongoTemplate.find(query, Resource.class);
// String roleId = roleInfoService.getRole(MyTeamUtils.LEAD);
// if (operationType == 1) {
// roleMappingService.addEmployeeRole(empId, roleId);
// } else if (projectMates.size() == 0 || operationType == 2) {
// roleMappingService.deleteRole(empId, roleId);
// }
// }
// }
//
// public void addResources(Employee employee, String loginEmpId) {
// List<Resource> resourceList = resourceRepo.findByEmployeeId(employee.getEmployeeId());
// if (resourceList != null && !resourceList.isEmpty()) {
// for (Resource resource : resourceList) {
// resource.setRole(employee.getRole());
// resource.setAuditFields(loginEmpId, MyTeamUtils.UPDATE); // resource.setAuditFields(loginEmpId, MyTeamUtils.UPDATE);
// resourceRepo.save(resource); // resourceRepo.save(resource);
// empShiftService.updateEmployeeShift(resource, loginEmpId);
// } // }
// } // }
//
// // return null;
// }
//
// //public void inactivateResource(Employee employeeReq, Employee employeeUpdated, String loginEmpId) {
//// // inactive the employee from the assigned project
//// if (employeeReq.getEmpStatus().equals(MyTeamUtils.IN_ACTIVE_SPACE) && employeeReq.getEndDate() != null
//// && employeeReq.getEndDate().compareTo(new Date()) <= 0) {
////
//// List<Resource> resourcesList = resourceRepo.findByEmployeeIdAndActive(employeeReq.getEmployeeId(), true);
//// if (resourcesList.size() == 1) {
//// Resource resource = resourcesList.get(0);
//// resource.setActive(false);
//// resource.setEndDate(employeeReq.getEndDate());
////
//// List<Billing> billingList = billingService.getActiveBillings(resource.getEmployeeId(),
//// resource.getProjectId());
//// if (billingList != null && !billingList.isEmpty()) {
//// billingService.addBillingtoResource(billingList.get(0), employeeUpdated, loginEmpId);
//// }
//// resource.setAuditFields(loginEmpId, MyTeamUtils.UPDATE);
//// resourceRepo.save(resource);
//// empShiftService.updateEmployeeShift(resource, loginEmpId);
//// }
//// }
//// }
//
//
//// @Override
// public List<Resource> findByAccountAndActiveAndBillableStatus(String account, boolean status,
// String billableStatus) {
// return resourceRepo.findByAccountAndActiveAndBillableStatus(account, status, billableStatus);
// }
//
//// @Override
// public List<Resource> getResourcesSortByStartDate(String employeeId) {
// Query query = prepareQuery(employeeId, MyTeamUtils.START_DATE);
// return mongoTemplate.find(query, Resource.class);
// }
//
//// @Override
// public List<Resource> getResourcesForProject(String projectId, String statusFlag) {
// List<Resource> resourcesList = new ArrayList<>();
// List<Resource> resourceListPersisted = resourceRepo.findByProjectId(projectId);
// for (Resource resource : resourceListPersisted) {
// Date endDate = resource.getEndDate();
// if (endDate != null) {
// // Active
// if (statusFlag.equals(MyTeamUtils.ACTIVE) && endDate.compareTo(new Date()) >= 0)
// resourcesList.add(resource);
// else if (statusFlag.equals(MyTeamUtils.IN_ACTIVE) && endDate.compareTo(new Date()) < 0)
// resourcesList.add(resource);
// else if (statusFlag.equals(MyTeamUtils.BOTH))
// resourcesList.add(resource);
// }
// }
// return resourcesList;
// }
//
//// @Override
// public List<Resource> getResourcesForEmployee(String empId) {
// return resourceRepo.findByEmployeeId(empId);
// }
//
// public List<Resource> getResourcesForProject(String projectId) {
// return resourceRepo.findByProjectId(projectId);
// }
//
// public List<Resource> getAllResources() {
// return resourceRepo.findAll();
// }
//
//// @Override
// public List<Resource> getActiveResources(String empId) {
// List<Resource> resourcesList = new ArrayList<>();
// List<Resource> resourcesListPers = resourceRepo.findByEmployeeId(empId);
// for (Resource resource : resourcesListPers) {
// if (resource.isActive()) {
// resourcesList.addAll(resourceRepo.findByProjectId(resource.getProjectId()));
// }
// }
// return resourcesList;
// }
//
//// @Override
// public List<Resource> getResourcesForActiveProjects() {
// List<Project> projects = projectService.getAllProjects();
// List<Resource> resourceList = new ArrayList<>();
// for (Project project : projects) {
// if (!"Completed".equalsIgnoreCase(project.getStatus())) {
// List<Resource> resourceListPersisted = getResourcesForProject(project.getProjectId());
// resourceList.addAll(resourceListPersisted);
// }
//
// }
// return resourceList;
// } // }
//
//// @Override
// @Override // public List<Resource> getResourcesForShift(String shift) {
public List<Resource> findByAccountAndActiveAndBillableStatus(String account, boolean status, // List<Resource> resourcesListPers = null;
String billableStatus) { // List<Resource> resourcesList = new ArrayList<>();
return resourceRepo.findByAccountAndActiveAndBillableStatus(account, status, billableStatus); // List<Project> projects = projectService.getAllProjects();
} // for (Project project : projects) {
// if ("Active".equalsIgnoreCase(project.getStatus())) {
// @Override // resourcesListPers = getResourcesForProject(project.getProjectId());
public List<Resource> getResourcesSortByStartDate(String employeeId) { // for (Resource resource : resourcesListPers) {
Query query = prepareQuery(employeeId, MyTeamUtils.START_DATE); // if (resource.getShift() != null && resource.getShift().equalsIgnoreCase(shift)
return mongoTemplate.find(query, Resource.class); // && resource.isActive()) {
} // resourcesList.add(resource);
// } else if (resource.getShift() == null && "Shift 1(9:00 AM - 6:00 PM)".equalsIgnoreCase(shift)
// @Override // && resource.isActive())
public List<Resource> getResourcesForProject(String projectId, String statusFlag) { // resourcesList.add(resource);
List<Resource> resourcesList = new ArrayList<>(); // }
List<Resource> resourceListPersisted = resourceRepo.findByProjectId(projectId); // }
for (Resource resource : resourceListPersisted) { // }
Date endDate = resource.getEndDate(); // return resourcesList;
if (endDate != null) { // }
// Active //
if (statusFlag.equals(MyTeamUtils.ACTIVE) && endDate.compareTo(new Date()) >= 0) //
resourcesList.add(resource); //
else if (statusFlag.equals(MyTeamUtils.IN_ACTIVE) && endDate.compareTo(new Date()) < 0) //// @Override
resourcesList.add(resource); // public List<Resource> getResourcesUnderDeliveryLead(String deliveryLeadId) {
else if (statusFlag.equals(MyTeamUtils.BOTH)) // List<String> projectIdsList = new ArrayList<>();
resourcesList.add(resource); // List<Resource> resourcesList = new ArrayList<>();
} //
} //
return resourcesList; // List<Project> projectsList = projectRepo.findByDeliveryLeadIds(deliveryLeadId);
} // for (Project project : projectsList)
// projectIdsList.add(project.getProjectId());
// @Override //
public List<Resource> getResourcesForEmployee(String empId) { // Query query = new Query(Criteria.where("projectId").in(projectIdsList));
return resourceRepo.findByEmployeeId(empId); //
} // List<Resource> resourcesListPersisted = mongoTemplate.find(query, Resource.class);
//
public List<Resource> getResourcesForProject(String projectId) { //
return resourceRepo.findByProjectId(projectId); // for (Resource resource : resourcesListPersisted) {
} // if (!resource.getEmployeeId().equals(deliveryLeadId))
// resourcesList.add(resource);
public List<Resource> getAllResources() { // }
return resourceRepo.findAll(); // return resourcesList;
} //
// }
// @Override //
public List<Resource> getActiveResources(String empId) { //
List<Resource> resourcesList = new ArrayList<>(); //
List<Resource> resourcesListPers = resourceRepo.findByEmployeeId(empId); //
for (Resource resource : resourcesListPers) { //// @Override
if (resource.isActive()) { // public HashMap<String,Object> verifyResourceAssignedToAnyProject(Resource resourceReq, String loginEmpId) throws MyTeamException {
resourcesList.addAll(resourceRepo.findByProjectId(resource.getProjectId())); // boolean flag = false;
} // String projectName = null;
} // String fromDate = null;
return resourcesList; // String toDate = null;
} // String result = null;
// HashMap<String, Object> responseMap = new HashMap<>();
// @Override // Resource resourcePersisted = null;
public List<Resource> getResourcesForActiveProjects() { //
List<Project> projects = projectService.getAllProjects(); // List<Resource> resourceList = resourceRepo.findByEmployeeId(resourceReq.getEmployeeId()).stream()
List<Resource> resourceList = new ArrayList<>(); // .filter(e -> !("Nisum0000".equalsIgnoreCase(e.getProjectId())))
for (Project project : projects) { // .sorted(Comparator.comparing(Resource::getEndDate).reversed())
if (!"Completed".equalsIgnoreCase(project.getStatus())) { // .collect(Collectors.toList());
List<Resource> resourceListPersisted = getResourcesForProject(project.getProjectId()); //
resourceList.addAll(resourceListPersisted); // // Checking, if resource has existing project assignment.
} // for (Resource resource : resourceList) {
//
} // log.info("Resource::" + resource);
return resourceList; // if (resource.getEndDate() != null && (resource.getEndDate().compareTo(new Date()) > 0)) {
} // flag = true;
// projectName = resource.getProjectName();
// @Override // fromDate = resource.getStartDate().toString();
public List<Resource> getResourcesForShift(String shift) { // toDate = resource.getEndDate().toString();
List<Resource> resourcesListPers = null; // break;
List<Resource> resourcesList = new ArrayList<>(); // }
List<Project> projects = projectService.getAllProjects(); // }
for (Project project : projects) { // if (flag) {// If yes, error thrown to user.
if ("Active".equalsIgnoreCase(project.getStatus())) { // result = "Resource " + resourceReq.getEmployeeId() + " already Assigned to the " + projectName
resourcesListPers = getResourcesForProject(project.getProjectId()); // + " Project" + " from " + fromDate + "to " + toDate;
for (Resource resource : resourcesListPers) { //
if (resource.getShift() != null && resource.getShift().equalsIgnoreCase(shift) // } else {// If no, validating new project assignment start date against previous project end date.
&& resource.isActive()) { // result = validateNewProjectAssignmentStartDate(resourceList, resourceReq);
resourcesList.add(resource); // if (result == null) {
} else if (resource.getShift() == null && "Shift 1(9:00 AM - 6:00 PM)".equalsIgnoreCase(shift) // resourcePersisted = this.addResource(resourceReq, loginEmpId);
&& resource.isActive()) // result = "TeamMate added successfuly";
resourcesList.add(resource); //
} // }
} // }
} // responseMap.put("message", result);
return resourcesList; // responseMap.put("resourceObj", resourcePersisted);
} // return responseMap;
//
// }
//
// @Override // private String validateNewProjectAssignmentStartDate(List<Resource> resourceList, Resource resourceReq) {
public List<Resource> getResourcesUnderDeliveryLead(String deliveryLeadId) { // String response = null;
List<String> projectIdsList = new ArrayList<>(); // if (resourceList != null && resourceList.size() > 0) {
List<Resource> resourcesList = new ArrayList<>(); // Resource resource = resourceList.get(0);
// if (resourceReq.getNewBillingStartDate().compareTo(resource.getEndDate()) <= 0) {
// response = "Resource Start Date (" + resourceReq.getNewBillingStartDate() +" ) in " + resourceReq.getProjectName()
List<Project> projectsList = projectRepo.findByDeliveryLeadIds(deliveryLeadId); // + " project should be after " + resource.getProjectName() + " project End Date ( " + resource.getEndDate() + ").";
for (Project project : projectsList) // }
projectIdsList.add(project.getProjectId()); // } else {
// response = validateAgainstDOJ(resourceReq);
Query query = new Query(Criteria.where("projectId").in(projectIdsList)); // }
// return response;
List<Resource> resourcesListPersisted = mongoTemplate.find(query, Resource.class); // }
//
// private String validateAgainstDOJ(Resource resource) {
for (Resource resource : resourcesListPersisted) { // String response = null;
if (!resource.getEmployeeId().equals(deliveryLeadId)) // Date empDoj = employeeRepo.findByEmployeeId(resource.getEmployeeId()).getDateOfJoining();
resourcesList.add(resource); // if (resource.getNewBillingStartDate().compareTo(empDoj) < 0) {
} // response = "Resource Start Date (" + resource.getNewBillingStartDate() + " ) in "
return resourcesList; // + resource.getProjectName() + " project should not be before Date of Joining ( " + empDoj + ").";
// }
} // return response;
// }
//
//}
// @Override
public HashMap<String,Object> verifyResourceAssignedToAnyProject(Resource resourceReq, String loginEmpId) throws MyTeamException {
boolean flag = false;
String projectName = null;
String fromDate = null;
String toDate = null;
String result = null;
HashMap<String, Object> responseMap = new HashMap<>();
Resource resourcePersisted = null;
List<Resource> resourceList = resourceRepo.findByEmployeeId(resourceReq.getEmployeeId()).stream()
.filter(e -> !("Nisum0000".equalsIgnoreCase(e.getProjectId())))
.sorted(Comparator.comparing(Resource::getEndDate).reversed())
.collect(Collectors.toList());
// Checking, if resource has existing project assignment.
for (Resource resource : resourceList) {
log.info("Resource::" + resource);
if (resource.getEndDate() != null && (resource.getEndDate().compareTo(new Date()) > 0)) {
flag = true;
projectName = resource.getProjectName();
fromDate = resource.getStartDate().toString();
toDate = resource.getEndDate().toString();
break;
}
}
if (flag) {// If yes, error thrown to user.
result = "Resource " + resourceReq.getEmployeeId() + " already Assigned to the " + projectName
+ " Project" + " from " + fromDate + "to " + toDate;
} else {// If no, validating new project assignment start date against previous project end date.
result = validateNewProjectAssignmentStartDate(resourceList, resourceReq);
if (result == null) {
resourcePersisted = this.addResource(resourceReq, loginEmpId);
result = "TeamMate added successfuly";
}
}
responseMap.put("message", result);
responseMap.put("resourceObj", resourcePersisted);
return responseMap;
}
private String validateNewProjectAssignmentStartDate(List<Resource> resourceList, Resource resourceReq) {
String response = null;
if (resourceList != null && resourceList.size() > 0) {
Resource resource = resourceList.get(0);
if (resourceReq.getNewBillingStartDate().compareTo(resource.getEndDate()) <= 0) {
response = "Resource Start Date (" + resourceReq.getNewBillingStartDate() +" ) in " + resourceReq.getProjectName()
+ " project should be after " + resource.getProjectName() + " project End Date ( " + resource.getEndDate() + ").";
}
} else {
response = validateAgainstDOJ(resourceReq);
}
return response;
}
private String validateAgainstDOJ(Resource resource) {
String response = null;
Date empDoj = employeeRepo.findByEmployeeId(resource.getEmployeeId()).getDateOfJoining();
if (resource.getNewBillingStartDate().compareTo(empDoj) < 0) {
response = "Resource Start Date (" + resource.getNewBillingStartDate() + " ) in "
+ resource.getProjectName() + " project should not be before Date of Joining ( " + empDoj + ").";
}
return response;
}
}
package com.nisum.myteam.statuscodes;
public class BillingStatus {
}
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