Commit cccf47bb authored by b v s satyanarayana's avatar b v s satyanarayana

MT-53 :SNS :: ImportEmployeeDataValidations

parent c14c38e3
...@@ -15,6 +15,7 @@ import org.springframework.web.bind.annotation.RequestMapping; ...@@ -15,6 +15,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import com.nisum.mytime.exception.handler.MyTimeException; import com.nisum.mytime.exception.handler.MyTimeException;
import com.nisum.mytime.model.Account; import com.nisum.mytime.model.Account;
...@@ -30,8 +31,11 @@ import com.nisum.mytime.model.Skill; ...@@ -30,8 +31,11 @@ import com.nisum.mytime.model.Skill;
import com.nisum.mytime.service.RoleMappingService; import com.nisum.mytime.service.RoleMappingService;
import com.nisum.mytime.service.UserService; import com.nisum.mytime.service.UserService;
import lombok.extern.slf4j.Slf4j;
@RestController @RestController
@RequestMapping("/user") @RequestMapping("/user")
@Slf4j
public class UserController { public class UserController {
@Autowired @Autowired
...@@ -276,5 +280,14 @@ public class UserController { ...@@ -276,5 +280,14 @@ public class UserController {
.collect(Collectors.toList()); .collect(Collectors.toList());
return new ResponseEntity<>(domains, HttpStatus.OK); return new ResponseEntity<>(domains, HttpStatus.OK);
} }
@RequestMapping(value = "/fileUpload", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public ResponseEntity<String> exportDataFromFile(@RequestParam(value = "file") MultipartFile file, @RequestParam(value="empId") String loginEmpId)
throws MyTimeException {
log.info("Uploaded file: {} with size: {}", file.getOriginalFilename(), file.getSize());
String result = userService.exportDataFromExcelFile(file,loginEmpId);
return new ResponseEntity<>(result, HttpStatus.OK);
}
} }
\ No newline at end of file
...@@ -9,9 +9,7 @@ import org.springframework.http.ResponseEntity; ...@@ -9,9 +9,7 @@ import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import com.nisum.mytime.exception.handler.MyTimeException; import com.nisum.mytime.exception.handler.MyTimeException;
import com.nisum.mytime.model.EmployeeVisa; import com.nisum.mytime.model.EmployeeVisa;
...@@ -19,11 +17,8 @@ import com.nisum.mytime.model.TravelRequest; ...@@ -19,11 +17,8 @@ import com.nisum.mytime.model.TravelRequest;
import com.nisum.mytime.model.Visa; import com.nisum.mytime.model.Visa;
import com.nisum.mytime.service.VisaService; import com.nisum.mytime.service.VisaService;
import lombok.extern.slf4j.Slf4j;
@RestController @RestController
@RequestMapping("/visa") @RequestMapping("/visa")
@Slf4j
public class VisaController { public class VisaController {
@Autowired @Autowired
...@@ -84,13 +79,4 @@ public class VisaController { ...@@ -84,13 +79,4 @@ public class VisaController {
visaService.deleteEmployeeVisas(eVisa); visaService.deleteEmployeeVisas(eVisa);
return new ResponseEntity<>("Success", HttpStatus.OK); return new ResponseEntity<>("Success", HttpStatus.OK);
} }
@RequestMapping(value = "/fileUpload", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public ResponseEntity<String> exportDataFromFile(@RequestParam(value = "file") MultipartFile file, @RequestParam(value="empId") String loginEmpId)
throws MyTimeException {
log.info("Uploaded file: {} with size: {}", file.getOriginalFilename(), file.getSize());
String result = visaService.exportDataFromExcelFile(file,loginEmpId);
return new ResponseEntity<>(result, HttpStatus.OK);
}
} }
\ No newline at end of file
...@@ -15,7 +15,7 @@ import lombok.Setter; ...@@ -15,7 +15,7 @@ import lombok.Setter;
import lombok.ToString; import lombok.ToString;
@Setter @Setter
@Getter @Getter
@AllArgsConstructor @AllArgsConstructor
@NoArgsConstructor @NoArgsConstructor
@ToString @ToString
...@@ -109,4 +109,31 @@ public class EmployeeRoles implements Serializable { ...@@ -109,4 +109,31 @@ public class EmployeeRoles implements Serializable {
private String modifiedBy; private String modifiedBy;
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((employeeId == null) ? 0 : employeeId.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
EmployeeRoles other = (EmployeeRoles) obj;
if (employeeId == null) {
if (other.employeeId != null)
return false;
} else if (!employeeId.equals(other.employeeId))
return false;
return true;
}
} }
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;
...@@ -20,5 +21,8 @@ public interface EmployeeRolesRepo ...@@ -20,5 +21,8 @@ public interface EmployeeRolesRepo
List<EmployeeRoles> findByEmpStatusOrderByEmployeeNameAsc(String empStatus); List<EmployeeRoles> findByEmpStatusOrderByEmployeeNameAsc(String empStatus);
List<EmployeeRoles> findByEmpStatus(String status); List<EmployeeRoles> findByEmpStatus(String status);
List<EmployeeRoles> findByEmployeeIdIn(Set<String> empIdsSet);
} }
\ No newline at end of file
package com.nisum.mytime.repository; package com.nisum.mytime.repository;
import java.util.List;
import org.springframework.data.mongodb.repository.MongoRepository; import org.springframework.data.mongodb.repository.MongoRepository;
import com.nisum.mytime.model.Location; import com.nisum.mytime.model.Location;
public interface LocationRepo extends MongoRepository<Location, String> { public interface LocationRepo extends MongoRepository<Location, String> {
List<Location> findByLocationAndActiveStatus(String location, boolean activeStatus);
} }
\ No newline at end of file
package com.nisum.mytime.repository; package com.nisum.mytime.repository;
import java.util.List;
import org.springframework.data.mongodb.repository.MongoRepository; import org.springframework.data.mongodb.repository.MongoRepository;
import com.nisum.mytime.model.MasterData; import com.nisum.mytime.model.MasterData;
public interface MasterDataRepo extends MongoRepository<MasterData, String> { public interface MasterDataRepo extends MongoRepository<MasterData, String> {
List<MasterData> findByMasterDataTypeAndMasterDataNameAndActiveStatus(String masterDataType, String masterDataName, boolean activeStatus);
} }
\ No newline at end of file
...@@ -3,6 +3,8 @@ package com.nisum.mytime.service; ...@@ -3,6 +3,8 @@ package com.nisum.mytime.service;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import org.springframework.web.multipart.MultipartFile;
import com.nisum.mytime.exception.handler.MyTimeException; import com.nisum.mytime.exception.handler.MyTimeException;
import com.nisum.mytime.model.Account; import com.nisum.mytime.model.Account;
import com.nisum.mytime.model.AccountInfo; import com.nisum.mytime.model.AccountInfo;
...@@ -78,4 +80,6 @@ public interface UserService { ...@@ -78,4 +80,6 @@ public interface UserService {
public List<Domains> getDomains(String accountId)throws MyTimeException; public List<Domains> getDomains(String accountId)throws MyTimeException;
public boolean verifyRole(String empId, String roleName); public boolean verifyRole(String empId, String roleName);
String exportDataFromExcelFile(MultipartFile file, String empId) throws MyTimeException;
} }
...@@ -35,6 +35,4 @@ public interface VisaService { ...@@ -35,6 +35,4 @@ public interface VisaService {
TravelRequest updateTravelRequest(TravelRequest e); TravelRequest updateTravelRequest(TravelRequest e);
void deleteEmployeeVisas(TravelRequest e); void deleteEmployeeVisas(TravelRequest e);
String exportDataFromExcelFile(MultipartFile file,String empId) throws MyTimeException;
} }
...@@ -7,28 +7,20 @@ import java.util.List; ...@@ -7,28 +7,20 @@ import java.util.List;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import com.nisum.mytime.exception.handler.MyTimeException;
import com.nisum.mytime.model.EmployeeRoles;
import com.nisum.mytime.model.EmployeeVisa; import com.nisum.mytime.model.EmployeeVisa;
import com.nisum.mytime.model.TravelRequest; import com.nisum.mytime.model.TravelRequest;
import com.nisum.mytime.model.Visa; import com.nisum.mytime.model.Visa;
import com.nisum.mytime.repository.EmployeeRolesRepo;
import com.nisum.mytime.repository.EmployeeVisaRepo; import com.nisum.mytime.repository.EmployeeVisaRepo;
import com.nisum.mytime.repository.TravelRepo; import com.nisum.mytime.repository.TravelRepo;
import com.nisum.mytime.repository.VisaRepo; import com.nisum.mytime.repository.VisaRepo;
import com.poiji.bind.Poiji;
import com.poiji.exception.PoijiExcelType;
import com.poiji.option.PoijiOptions;
import lombok.extern.slf4j.Slf4j;
/** /**
* @author nisum * @author nisum
* *
*/ */
@Service @Service
@Slf4j
public class VisaServiceImpl implements VisaService { public class VisaServiceImpl implements VisaService {
@Autowired @Autowired
...@@ -41,6 +33,10 @@ public class VisaServiceImpl implements VisaService { ...@@ -41,6 +33,10 @@ public class VisaServiceImpl implements VisaService {
@Autowired @Autowired
private UserService userService; private UserService userService;
@Autowired
private EmployeeRolesRepo employeeRolesRepo;
@Override @Override
public List<Visa> getAllVisas() { public List<Visa> getAllVisas() {
...@@ -87,88 +83,4 @@ public class VisaServiceImpl implements VisaService { ...@@ -87,88 +83,4 @@ public class VisaServiceImpl implements VisaService {
travelRepo.delete(e); travelRepo.delete(e);
} }
@Override }
public String exportDataFromExcelFile(MultipartFile file, String empId)
throws MyTimeException {
String result = "Failure";
int counter = 0;
try {
PoijiOptions options = PoijiOptions.PoijiOptionsBuilder.settings()
.preferNullOverDefault(true).datePattern("dd-MMM-yyyy")
.build();
List<EmployeeRoles> employees = Poiji.fromExcel(
file.getInputStream(), PoijiExcelType.XLS,
EmployeeRoles.class, options);
if (!employees.isEmpty()) {
for (EmployeeRoles employee : employees) {
System.out.println("test employee" + employee);
if (null != employee.getEmployeeId())
findAndModifyEmployeeRole(employee,empId);
else
counter++;
}
if (counter == 0) {
result = "Success";
log.info("Exported {} employee records from file: {}",
employees.size(), file.getOriginalFilename());
} else {
log.info(
"Uploaded file: {}, does not contain valid employee records",
file.getOriginalFilename());
}
}
} catch (Exception e) {
log.error(
"Exception occured while exporting the data from excel file due to: {}",
e);
throw new MyTimeException("");
}
return result;
}
private void findAndModifyEmployeeRole(EmployeeRoles employee,String empId) {
/*
* Query query = new
* Query(Criteria.where("employeeId").is(employee.getEmployeeId()))
* .addCriteria(Criteria.where("emailId").is(employee.getEmailId()));
* Update update = new Update(); update.set("employeeId",
* employee.getEmployeeId()); update.set("employeeName",
* employee.getEmployeeName()); update.set("emailId",
* employee.getEmailId()); update.set("role", employee.getRole());
* update.set("functionalGroup", employee.getFunctionalGroup());
* update.set("empStatus", employee.getEmpStatus());
* update.set("employmentType", employee.getEmploymentType());
* update.set("empLocation", employee.getEmpLocation());
* update.set("domain", employee.getDomain()); update.set("designation",
* employee.getDesignation()); update.set("dateOfBirth",
* employee.getDateOfBirth()); update.set("dateOfJoining",
* employee.getDateOfJoining()); update.set("shift",
* employee.getShift()); update.set("baseTechnology",
* employee.getBaseTechnology()); update.set("technologyKnown",
* employee.getTechnologyKnown()); update.set("mobileNumber",
* employee.getMobileNumber()); update.set("alternateMobileNumber",
* employee.getAlternateMobileNumber()); update.set("personalEmailId",
* employee.getPersonalEmailId()); update.set("createdOn", new Date());
* update.set("lastModifiedOn", new Date()); FindAndModifyOptions
* options = new FindAndModifyOptions(); options.returnNew(true);
* options.upsert(true); mongoTemplate.findAndModify(query, update,
* options, EmployeeRoles.class);
* log.info("Inserted Employee record with Id: {}",
* employee.getEmployeeId());
*/
EmployeeRoles emp = userService.getEmployeesRoleData(employee.getEmployeeId());
if (emp == null) {
try {
if(employee.getRole()==null || employee.getRole().isEmpty()) {
employee.setRole("Employee");
}
userService.assigingEmployeeRole(employee,empId);
} catch (MyTimeException e) {
e.printStackTrace();
}
}
}
}
...@@ -9,13 +9,15 @@ public class MyTimeUtils { ...@@ -9,13 +9,15 @@ public class MyTimeUtils {
} }
public final static String driverUrl = "jdbc:ucanaccess://"; //public final static String driverUrl = "jdbc:ucanaccess://";
public final static String msdriveUrl ="jdbc:sqlserver://"; //public final static String msdriveUrl ="jdbc:sqlserver://";
public final static DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); public final static DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
public final static DateFormat tdf = new SimpleDateFormat("HH:mm"); public final static DateFormat tdf = new SimpleDateFormat("HH:mm");
public final static DateFormat dfmt = new SimpleDateFormat("yyyy-MM-dd"); public final static DateFormat dfmt = new SimpleDateFormat("yyyy-MM-dd");
//public final static DateFormat dfmtDdMmmYyyy = new SimpleDateFormat("dd-MM-yyyy");
public final static String UNDER_SCORE = "_"; public final static String UNDER_SCORE = "_";
public final static String DATE_OF_LOGIN = "dateOfLogin"; public final static String DATE_OF_LOGIN = "dateOfLogin";
public final static String EMPLOYEE = "Employee";
public final static String EMPLOYEE_ID = "employeeId"; public final static String EMPLOYEE_ID = "employeeId";
public final static String EMPLOYEE_NAME = "employeeName"; public final static String EMPLOYEE_NAME = "employeeName";
public final static String FIRST_LOGIN = "firstLogin"; public final static String FIRST_LOGIN = "firstLogin";
...@@ -53,6 +55,7 @@ public class MyTimeUtils { ...@@ -53,6 +55,7 @@ public class MyTimeUtils {
public static final String ACTIVE = "Active"; public static final String ACTIVE = "Active";
public static final String IN_ACTIVE = "InActive"; public static final String IN_ACTIVE = "InActive";
public static final String IN_ACTIVE_SPACE = "In Active"; public static final String IN_ACTIVE_SPACE = "In Active";
public static final String IN_HYPEN_ACTIVE_SPACE = "In-Active";
public final static String TEAMDETAILS_COLLECTION_NAME = "TeamDetails"; public final static String TEAMDETAILS_COLLECTION_NAME = "TeamDetails";
public final static String BILLINGDETAILS_COLLECTION_NAME = "BillingDetails"; public final static String BILLINGDETAILS_COLLECTION_NAME = "BillingDetails";
public final static String ENDDATE_COLUMN = "endDate"; public final static String ENDDATE_COLUMN = "endDate";
...@@ -109,9 +112,28 @@ public class MyTimeUtils { ...@@ -109,9 +112,28 @@ 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 int INT_TWO = 2;
public final static int INT_TWENTY = 20;
public final static String DM= "DM"; public final static String DM= "DM";
public final static String DL= "DL"; public final static String DL= "DL";
public final static String L= "L"; public final static String L= "L";
public final static String EMPTY_STRING = "";
public final static String MALE = "Male";
public final static String FEMALE ="Female";
public final static String YES = "Yes";
public final static String NO = "No";
public final static long EMPID_START = 16001;
public final static long EMPID_END = 99999;
public final static String MASTERDATA_FG = "FunctionalGrp";
public final static String MASTERDATA_DESIGNATION = "designations";
public final static String MASTERDATAD_EMLOYMENT_TYPE = "EmpType";
public final static String MASTERDATA_ROLES = "roles";
public final static String FULL_TIME ="Full Time";
} }
...@@ -42,7 +42,7 @@ myApp ...@@ -42,7 +42,7 @@ myApp
$http $http
.post( .post(
appConfig.appUri appConfig.appUri
+ "visa/fileUpload?empId="+empId, + "user/fileUpload?empId="+empId,
formData, formData,
{ {
transformRequest : angular.identity, transformRequest : angular.identity,
......
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