Merge branch 'dmp-refactoring' of code-repo.d4science.org:MaDgiK-CITE/argos into dmp-refactoring
# Conflicts: # dmp-migration-tool/web/src/main/java/eu/old/eudat/publicapi/migration/MigrationController.java
This commit is contained in:
commit
db6cb44ff8
|
@ -1,6 +1,11 @@
|
|||
package eu.old.eudat.publicapi.migration;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import eu.eudat.commons.JsonHandlingService;
|
||||
import eu.eudat.commons.enums.*;
|
||||
import eu.eudat.commons.types.dmp.DmpBlueprintValueEntity;
|
||||
import eu.eudat.commons.types.dmp.DmpContactEntity;
|
||||
import eu.eudat.commons.types.dmp.DmpPropertiesEntity;
|
||||
import eu.eudat.data.DmpEntity;
|
||||
import eu.old.eudat.data.entities.DMP;
|
||||
import eu.old.eudat.data.entities.Organisation;
|
||||
|
@ -26,13 +31,16 @@ public class MigrationController {
|
|||
|
||||
private final DatabaseRepository databaseRepository;
|
||||
|
||||
private final JsonHandlingService jsonHandlingService;
|
||||
|
||||
@PersistenceContext
|
||||
private final EntityManager entityManager;
|
||||
|
||||
private final OrganizationMigrationService organizationMigrationService;
|
||||
|
||||
public MigrationController(DatabaseRepository databaseRepository, EntityManager entityManager, OrganizationMigrationService organizationMigrationService) {
|
||||
public MigrationController(DatabaseRepository databaseRepository, JsonHandlingService jsonHandlingService, EntityManager entityManager, OrganizationMigrationService organizationMigrationService) {
|
||||
this.databaseRepository = databaseRepository;
|
||||
this.jsonHandlingService = jsonHandlingService;
|
||||
this.entityManager = entityManager;
|
||||
this.organizationMigrationService = organizationMigrationService;
|
||||
}
|
||||
|
@ -66,18 +74,21 @@ public class MigrationController {
|
|||
}
|
||||
|
||||
@GetMapping("dmps/collectInfo")
|
||||
public List<DmpMigrationCollectedInfo> collectDmpsInfo() {
|
||||
public List<DmpMigrationCollectedInfo> collectDmpsInfo() throws JsonProcessingException {
|
||||
List<DmpMigrationCollectedInfo> collectedInfoList = new ArrayList<>();
|
||||
List<DataManagementPlan> dmps = getDmps(0, 4);
|
||||
for (DataManagementPlan dataManagementPlan : dmps) {
|
||||
DmpMigrationCollectedInfo dmpMigrationCollectedInfo = new DmpMigrationCollectedInfo();
|
||||
|
||||
DmpPropertiesEntity dmpProperties = new DmpPropertiesEntity();
|
||||
dmpProperties.setDmpBlueprintValues(new ArrayList<>());
|
||||
dmpProperties.setContacts(new ArrayList<>());
|
||||
|
||||
//Collect basic dmp information
|
||||
DmpEntity dmpEntity = new DmpEntity();
|
||||
dmpEntity.setId(UUID.randomUUID());
|
||||
dmpEntity.setLabel(dataManagementPlan.getLabel());
|
||||
dmpEntity.setDescription(dataManagementPlan.getDescription());
|
||||
dmpEntity.setAccessType(dataManagementPlan.getPublic() ? DmpAccessType.Public : DmpAccessType.Restricted);
|
||||
if (dataManagementPlan.getCreator() != null)
|
||||
dmpEntity.setCreatorId(dataManagementPlan.getCreator().getId());
|
||||
dmpEntity.setGroupId(dataManagementPlan.getGroupId());
|
||||
|
@ -90,20 +101,36 @@ public class MigrationController {
|
|||
if (dataManagementPlan.getFinalized() != null)
|
||||
dmpEntity.setFinalizedAt(dataManagementPlan.getFinalized().toInstant());
|
||||
dmpEntity.setBlueprintId(dataManagementPlan.getProfile().getId());
|
||||
if (dataManagementPlan.getExtraProperties() != null) {
|
||||
if (dataManagementPlan.getExtraProperties().containsKey("language") && dataManagementPlan.getExtraProperties().get("language") != null)
|
||||
dmpEntity.setLanguage((String) dataManagementPlan.getExtraProperties().get("language"));
|
||||
if (dataManagementPlan.getExtraProperties().containsKey("visible") && dataManagementPlan.getExtraProperties().get("visible") != null)
|
||||
dmpEntity.setAccessType((boolean) dataManagementPlan.getExtraProperties().get("visible") ? DmpAccessType.Public : DmpAccessType.Restricted);
|
||||
if (dataManagementPlan.getExtraProperties().containsKey("contact") && dataManagementPlan.getExtraProperties().get("contact") != null) {
|
||||
DmpContactEntity contactEntity = new DmpContactEntity();
|
||||
contactEntity.setUserId((String) dataManagementPlan.getExtraProperties().get("contact"));
|
||||
dmpProperties.getContacts().add(contactEntity);
|
||||
}
|
||||
}
|
||||
if (dataManagementPlan.getProperties() != null) {
|
||||
dataManagementPlan.getProperties().forEach((key,val) -> {
|
||||
DmpBlueprintValueEntity valueEntity = new DmpBlueprintValueEntity();
|
||||
valueEntity.setFieldId(key);
|
||||
valueEntity.setValue((String) val);
|
||||
dmpProperties.getDmpBlueprintValues().add(valueEntity);
|
||||
});
|
||||
}
|
||||
if (dataManagementPlan.getStatus() == 99) {
|
||||
dmpEntity.setIsActive(IsActive.Inactive);
|
||||
} else {
|
||||
dmpEntity.setIsActive(IsActive.Active);
|
||||
dmpEntity.setStatus(DmpStatus.of((short) dataManagementPlan.getStatus()));
|
||||
}
|
||||
dmpEntity.setProperties(jsonHandlingService.toJson(dmpProperties));
|
||||
dmpMigrationCollectedInfo.dmpEntity = dmpEntity;
|
||||
|
||||
//Collect dmp Organization info
|
||||
|
||||
|
||||
|
||||
collectedInfoList.add(dmpMigrationCollectedInfo);
|
||||
}
|
||||
return collectedInfoList;
|
||||
|
@ -111,7 +138,7 @@ public class MigrationController {
|
|||
|
||||
@GetMapping("dmps/migrate")
|
||||
@Transactional
|
||||
public String migrate() {
|
||||
public String migrate() throws JsonProcessingException {
|
||||
for (DmpMigrationCollectedInfo collectedInfo : collectDmpsInfo()) {
|
||||
this.entityManager.persist(collectedInfo.dmpEntity);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue