Commit 66679862 authored by Rajashekar jadala's avatar Rajashekar jadala Committed by tdutta-nisum-com

MT-80: saving the employee roles based on account/domain/project (#26)

parent aad89757
package com.nisum.mytime.model;
import java.io.Serializable;
import org.bson.types.ObjectId;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;
@Setter
@Getter
@AllArgsConstructor
@NoArgsConstructor
@ToString
@Document(collection = "Role")
public class RoleInfo implements Serializable {
private static final long serialVersionUID = 1L;
@Id
private ObjectId id;
private String roleId;
private String roleName;
private String roleDescription;
}
package com.nisum.mytime.model;
import java.io.Serializable;
import org.bson.types.ObjectId;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;
@Setter
@Getter
@AllArgsConstructor
@NoArgsConstructor
@ToString
@Document(collection = "EmpAssignedRoleMappingInfo")
public class RoleMappingInfo implements Serializable {
private static final long serialVersionUID = 1L;
@Id
private ObjectId id;
String employeeId;
String roleID;
// String active;
// String accountId;
// String domainId;
// String projectId;
}
package com.nisum.mytime.repository;
import org.springframework.data.mongodb.repository.MongoRepository;
import com.nisum.mytime.model.RoleInfo;
public interface RoleInfoRepo extends MongoRepository<RoleInfo, String> {
RoleInfo findByRoleName(String roleName);
}
\ No newline at end of file
package com.nisum.mytime.repository;
import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.data.mongodb.repository.Query;
import com.nisum.mytime.model.RoleMappingInfo;
public interface RoleMappingInfoRepo extends MongoRepository<RoleMappingInfo, String> {
@Query("{'employeeId':?0},{'roleId':?1}")
RoleMappingInfo findByEmployeeIdAndRoleId(String employeeId, String roleId);
}
\ No newline at end of file
package com.nisum.mytime.service;
import com.nisum.mytime.exception.handler.MyTimeException;
import com.nisum.mytime.model.RoleInfo;
public interface RoleInfoService {
public RoleInfo addRole(RoleInfo roleInfo) throws MyTimeException;
public String getRole(String roleName) throws MyTimeException;
}
package com.nisum.mytime.service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.nisum.mytime.exception.handler.MyTimeException;
import com.nisum.mytime.model.RoleInfo;
import com.nisum.mytime.repository.RoleInfoRepo;
@Service
public class RoleInfoServiceImpl implements RoleInfoService {
@Autowired
RoleInfoRepo roleInfoRepo;
@Override
public RoleInfo addRole(RoleInfo roleInfo) throws MyTimeException {
return roleInfoRepo.save(roleInfo);
}
@Override
public String getRole(String roleName) throws MyTimeException {
return roleInfoRepo.findByRoleName(roleName).getRoleId();
}
}
package com.nisum.mytime.service;
import com.nisum.mytime.exception.handler.MyTimeException;
import com.nisum.mytime.model.RoleMappingInfo;
public interface RoleMappingService {
void saveUniqueEmployeeAndRole(String employeeId, String roleId) throws MyTimeException;
RoleMappingInfo updateEmployeeRoleInfo(RoleMappingInfo roleMappingInfo) throws MyTimeException;
RoleMappingInfo getEmployeeAssignedRole() throws MyTimeException;
}
package com.nisum.mytime.service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.nisum.mytime.exception.handler.MyTimeException;
import com.nisum.mytime.model.RoleMappingInfo;
import com.nisum.mytime.repository.RoleMappingInfoRepo;
@Service
public class RoleMappingServiceImpl implements RoleMappingService {
@Autowired
private RoleMappingInfoRepo roleMappingInfoRepo;
@Override
public void saveUniqueEmployeeAndRole(String employeeId, String roleId) throws MyTimeException {
RoleMappingInfo roleMappingInfo;
if (roleMappingInfoRepo.findByEmployeeIdAndRoleId(employeeId, roleId) == null) {
roleMappingInfo = new RoleMappingInfo();
roleMappingInfo.setEmployeeId(employeeId);
roleMappingInfo.setRoleID(roleId);
roleMappingInfo = updateEmployeeRoleInfo(roleMappingInfo);
}
}
@Override
public RoleMappingInfo updateEmployeeRoleInfo(RoleMappingInfo roleMappingInfo) throws MyTimeException {
roleMappingInfoRepo.save(roleMappingInfo);
return roleMappingInfo;
}
@Override
public RoleMappingInfo getEmployeeAssignedRole() {
return null;
}
}
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