56 lines
2.6 KiB
Java
56 lines
2.6 KiB
Java
package eu.eudat.logic.managers;
|
|
|
|
import eu.eudat.data.dao.criteria.ProjectCriteria;
|
|
import eu.eudat.data.dao.entities.ContentDao;
|
|
import eu.eudat.data.dao.entities.ProjectDao;
|
|
import eu.eudat.data.dao.entities.UserInfoDao;
|
|
import eu.eudat.data.entities.*;
|
|
import eu.eudat.logic.services.ApiContext;
|
|
import eu.eudat.logic.services.helpers.FileStorageService;
|
|
import eu.eudat.models.data.dmp.DataManagementPlan;
|
|
import eu.eudat.models.data.security.Principal;
|
|
import org.springframework.stereotype.Component;
|
|
import eu.eudat.data.entities.DMP;
|
|
|
|
import java.io.IOException;
|
|
import java.text.ParseException;
|
|
|
|
@Component
|
|
public class QuickWizardManager {
|
|
|
|
|
|
public static Project createOrUpdate(FileStorageService fileStorageService, ProjectDao projectRepository, ContentDao contentRepository, UserInfoDao userInfoRepository, eu.eudat.models.data.project.Project project, Principal principal) throws ParseException, IOException {
|
|
eu.eudat.data.entities.Project projectEntity = project.toDataModel();
|
|
projectEntity.setType(eu.eudat.data.entities.Project.ProjectType.INTERNAL.getValue());
|
|
projectEntity.setCreationUser(userInfoRepository.find(principal.getId()));
|
|
Project projectEntityRet = projectRepository.createOrUpdate(projectEntity);
|
|
return projectEntityRet;
|
|
}
|
|
|
|
public DMP createOrUpdate(ApiContext apiContext, DataManagementPlan dataManagementPlan, Principal principal) throws Exception {
|
|
DMP newDmp = dataManagementPlan.toDataModel();
|
|
UserInfo user = apiContext.getOperationsContext().getDatabaseRepository().getUserInfoDao().find(principal.getId());
|
|
createProjectIfItDoesntExist(newDmp, apiContext.getOperationsContext().getDatabaseRepository().getProjectDao(), user);
|
|
newDmp.setCreator(user);
|
|
DMP dmpret = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().createOrUpdate(newDmp);
|
|
return dmpret;
|
|
}
|
|
|
|
|
|
private void createProjectIfItDoesntExist(DMP newDmp, ProjectDao projectDao, UserInfo userInfo) {
|
|
if (newDmp.getProject() != null) {
|
|
Project project = newDmp.getProject();
|
|
ProjectCriteria criteria = new ProjectCriteria();
|
|
criteria.setReference(project.getReference());
|
|
eu.eudat.data.entities.Project projectEntity = projectDao.getWithCriteria(criteria).getSingleOrDefault();
|
|
if (projectEntity != null) project.setId(projectEntity.getId());
|
|
else {
|
|
project.setType(Project.ProjectType.EXTERNAL.getValue());
|
|
projectDao.createOrUpdate(project);
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
}
|