use of org.c4sg.entity.UserProject in project c4sg-services by Code4SocialGood.
the class ProjectServiceImpl method isBookmarkPresent.
private void isBookmarkPresent(Integer userId, Integer projectId) {
List<UserProject> userProjects = userProjectDAO.findByUser_IdAndProject_IdAndStatus(userId, projectId, "B");
requireNonNull(userProjects, "Invalid operation");
for (UserProject userProject : userProjects) {
if (userProject.getStatus().equals("B")) {
throw new UserProjectException("Project is already bookmarked");
}
}
}
use of org.c4sg.entity.UserProject in project c4sg-services by Code4SocialGood.
the class ProjectServiceImpl method deleteProject.
/*---------------------------------------User Project code -----------------------------------------------------------*/
/*@Override
public List<ProjectDTO> findByUser(Integer userId, String userProjectStatus) throws ProjectServiceException {
List<Project> projects = projectDAO.findByUserIdAndUserProjectStatus(userId, userProjectStatus);
return projectMapper.getDtosFromEntities(projects);
}*/
/* @Override
public List<ProjectDTO> getApplicationByUserAndStatus(Integer userId, String userProjectStatus) throws ProjectServiceException {
List<Application> applications = applicationDAO.findByUser_IdAndStatus(userId, userProjectStatus);
return projectMapper.getDtosFromApplicationEntities(applications);
} */
/*@Override
public ProjectDTO saveUserProject(Integer userId, Integer projectId, String status ) {
User user = userDAO.findById(userId);
requireNonNull(user, "Invalid User Id");
Project project = projectDAO.findById(projectId);
requireNonNull(project, "Invalid Project Id");
if (status == null || (!status.equals("A") && !status.equals("B") && !status.equals("C") && !status.equals("D"))) {
throw new BadRequestException("Invalid Project Status");
} else {
isRecordExist(userId, projectId, status);
UserProject userProject = new UserProject();
userProject.setUser(user);
userProject.setProject(project);
userProject.setStatus(status);
userProjectDAO.save(userProject);
}
sendEmail(user, project, status);
return projectMapper.getProjectDtoFromEntity(project);
}*/
/*@Override
public ProjectDTO saveApplication(Integer userId, Integer projectId, String status, String comment, String resumeFlag){
User user = userDAO.findById(userId);
requireNonNull(user, "Invalid User Id");
Project project = projectDAO.findById(projectId);
requireNonNull(project, "Invalid Project Id");
if (status == null || (!status.equals("A") && !status.equals("C") && !status.equals("D"))) {
throw new BadRequestException("Invalid Project Status");
} else {
Application application = applicationDAO.findByUser_IdAndProject_Id(userId, projectId);
if(java.util.Objects.isNull(application)){ //create
application = new Application();
application.setUser(user);
application.setProject(project);
application.setStatus(status);
application.setComment(comment);
application.setResumeFlag(resumeFlag);
application.setAppliedTime(new Timestamp(Calendar.getInstance().getTime().getTime()));
} else{ //update
isApplied(application, status);
application.setStatus(status);
application.setComment(comment);
application.setResumeFlag(resumeFlag);
if(status.equals("C")){
application.setAcceptedTime(new Timestamp(Calendar.getInstance().getTime().getTime()));
}else if(status.equals("D")){
application.setDeclinedTime(new Timestamp(Calendar.getInstance().getTime().getTime()));
}
}
applicationDAO.save(application);
//userProjectDAO.save(userProject);
}
sendEmail(user, project, status);
return projectMapper.getProjectDtoFromEntity(project);
} */
public void deleteProject(int id) throws UserProjectException {
Project localProject = projectDAO.findById(id);
if (localProject != null) {
// TODO delete image from S3 by frontend
// userProjectDAO.deleteByProjectStatus(new Integer(id),"B");
applicationDAO.deleteByProject_id(id);
bookmarkDAO.deleteByProject_id(id);
projectSkillDAO.deleteByProjectId(id);
projectDAO.deleteProject(id);
} else {
System.out.println("Project does not exist.");
}
}
use of org.c4sg.entity.UserProject in project c4sg-services by Code4SocialGood.
the class ProjectServiceImpl method saveUserProject.
@Override
public ProjectDTO saveUserProject(Integer userId, Integer projectId, String userProjectStatus) {
User user = userDAO.findById(userId);
requireNonNull(user, "Invalid User Id");
Project project = projectDAO.findById(projectId);
requireNonNull(project, "Invalid Project Id");
if (userProjectStatus == null || (!userProjectStatus.trim().equalsIgnoreCase("A") && !userProjectStatus.trim().equalsIgnoreCase("B"))) {
throw new BadRequestException("Invalid Project Status");
} else if (userProjectStatus.trim().equalsIgnoreCase("A")) {
isUserAppliedPresent(userId, projectId);
UserProject userProject = new UserProject();
userProject.setUser(user);
userProject.setProject(project);
userProject.setStatus("A");
apply(user, project);
userProjectDAO.save(userProject);
} else if (userProjectStatus.trim().equalsIgnoreCase("B")) {
isBookmarkPresent(userId, projectId);
UserProject userProject = new UserProject();
userProject.setUser(user);
userProject.setProject(project);
userProject.setStatus("B");
userProjectDAO.save(userProject);
}
return projectMapper.getProjectDtoFromEntity(project);
}
use of org.c4sg.entity.UserProject in project c4sg-services by Code4SocialGood.
the class ProjectServiceImpl method isUserAppliedPresent.
private void isUserAppliedPresent(Integer userId, Integer projectId) throws UserProjectException {
List<UserProject> userProjects = userProjectDAO.findByUser_IdAndProject_IdAndStatus(userId, projectId, "A");
requireNonNull(userProjects, "Invalid operation");
for (UserProject userProject : userProjects) {
if (userProject.getStatus().equals("A")) {
throw new UserProjectException("Project is already applied for");
}
}
}
Aggregations