Adding dataset migration service
This commit is contained in:
parent
d426711904
commit
2936cbbb7a
|
@ -64,7 +64,6 @@ public class DescriptionEntity implements DataEntity<DescriptionEntity, UUID> {
|
|||
public static final String _isActive = "isActive";
|
||||
|
||||
@Column(name = "\"finalized_at\"")
|
||||
@Convert(converter = DateToUTCConverter.class)
|
||||
private Instant finalizedAt;
|
||||
|
||||
public static final String _finalizedAt = "finalizedAt";
|
||||
|
|
|
@ -0,0 +1,99 @@
|
|||
package eu.old.eudat.migration;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import eu.eudat.commons.JsonHandlingService;
|
||||
import eu.eudat.commons.enums.*;
|
||||
import eu.eudat.data.DescriptionEntity;
|
||||
import eu.old.eudat.data.entities.Dataset;
|
||||
import eu.old.eudat.logic.services.operations.DatabaseRepository;
|
||||
import eu.old.eudat.models.data.datasetwizard.DatasetWizardModel;
|
||||
import eu.old.eudat.queryable.QueryableList;
|
||||
import jakarta.persistence.EntityManager;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class DatasetMigrationService {
|
||||
|
||||
private final DatabaseRepository databaseRepository;
|
||||
|
||||
private final JsonHandlingService jsonHandlingService;
|
||||
|
||||
private final EntityManager entityManager;
|
||||
|
||||
public DatasetMigrationService(DatabaseRepository databaseRepository, JsonHandlingService jsonHandlingService, EntityManager entityManager) {
|
||||
this.databaseRepository = databaseRepository;
|
||||
this.jsonHandlingService = jsonHandlingService;
|
||||
this.entityManager = entityManager;
|
||||
}
|
||||
|
||||
public QueryableList<Dataset> datasetQueryableList() {
|
||||
return databaseRepository.getDatasetDao().asQueryable();
|
||||
}
|
||||
|
||||
public List<DatasetWizardModel> getDatasets(Integer skip, Integer take) {
|
||||
List<Dataset> datasets = datasetQueryableList()
|
||||
.orderBy((builder, root) -> builder.desc(root.get("created")))
|
||||
.skip(skip)
|
||||
.take(take)
|
||||
.toList();
|
||||
|
||||
return datasets.stream().map(x -> {
|
||||
DatasetWizardModel dataset = new DatasetWizardModel();
|
||||
dataset.fromDataModel(x);
|
||||
return dataset;
|
||||
}).toList();
|
||||
}
|
||||
|
||||
public List<DatasetMigrationCollectedInfo> collectDatasetsInfo() throws JsonProcessingException {
|
||||
List<DatasetMigrationCollectedInfo> collectedInfoList = new ArrayList<>();
|
||||
List<DatasetWizardModel> datasets = getDatasets(0, 4);
|
||||
for (DatasetWizardModel datasetWizardModel : datasets) {
|
||||
DatasetMigrationCollectedInfo datasetMigrationCollectedInfo = new DatasetMigrationCollectedInfo();
|
||||
|
||||
//Collect basic dataset information
|
||||
DescriptionEntity descriptionEntity = new DescriptionEntity();
|
||||
descriptionEntity.setId(datasetWizardModel.getId());
|
||||
descriptionEntity.setDescription(datasetWizardModel.getDescription());
|
||||
descriptionEntity.setCreatedById(datasetWizardModel.getCreatedBy());
|
||||
descriptionEntity.setDmpId(datasetWizardModel.getDmp().getId());
|
||||
descriptionEntity.setLabel(datasetWizardModel.getLabel());
|
||||
if (datasetWizardModel.getCreated() != null)
|
||||
descriptionEntity.setCreatedAt(datasetWizardModel.getCreated().toInstant());
|
||||
if (datasetWizardModel.getModified() != null)
|
||||
descriptionEntity.setUpdatedAt(datasetWizardModel.getModified().toInstant());
|
||||
if (datasetWizardModel.getFinalized() != null)
|
||||
descriptionEntity.setFinalizedAt(datasetWizardModel.getFinalized().toInstant());
|
||||
if (datasetWizardModel.getStatus() == 99) {
|
||||
descriptionEntity.setIsActive(IsActive.Inactive);
|
||||
descriptionEntity.setStatus(DescriptionStatus.Canceled);
|
||||
} else {
|
||||
descriptionEntity.setIsActive(IsActive.Active);
|
||||
descriptionEntity.setStatus(DescriptionStatus.of(datasetWizardModel.getStatus()));
|
||||
}
|
||||
// descriptionEntity.setDmpDescriptionTemplateId(); //TODO MIGRATE DMPDESCRIPTIONTEMPLATES
|
||||
|
||||
datasetMigrationCollectedInfo.descriptionEntity = descriptionEntity;
|
||||
|
||||
collectedInfoList.add(datasetMigrationCollectedInfo);
|
||||
}
|
||||
return collectedInfoList;
|
||||
}
|
||||
|
||||
public String migrate() throws JsonProcessingException {
|
||||
for (DatasetMigrationCollectedInfo collectedInfo : collectDatasetsInfo()) {
|
||||
this.entityManager.persist(collectedInfo.descriptionEntity);
|
||||
}
|
||||
this.entityManager.flush();
|
||||
return "Migrated dmps";
|
||||
}
|
||||
|
||||
public static class DatasetMigrationCollectedInfo {
|
||||
|
||||
public DescriptionEntity descriptionEntity;
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,102 @@
|
|||
package eu.old.eudat.migration;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import eu.eudat.commons.JsonHandlingService;
|
||||
import eu.eudat.commons.enums.DescriptionStatus;
|
||||
import eu.eudat.commons.enums.IsActive;
|
||||
import eu.eudat.data.DescriptionEntity;
|
||||
import eu.eudat.data.DmpDescriptionTemplateEntity;
|
||||
import eu.old.eudat.data.entities.DMPDatasetProfile;
|
||||
import eu.old.eudat.data.entities.Dataset;
|
||||
import eu.old.eudat.logic.services.operations.DatabaseRepository;
|
||||
import eu.old.eudat.models.data.datasetwizard.DatasetWizardModel;
|
||||
import eu.old.eudat.queryable.QueryableList;
|
||||
import jakarta.persistence.EntityManager;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class DmpDatasetProfileMigrationService {
|
||||
|
||||
private final DatabaseRepository databaseRepository;
|
||||
|
||||
private final JsonHandlingService jsonHandlingService;
|
||||
|
||||
private final EntityManager entityManager;
|
||||
|
||||
public DmpDatasetProfileMigrationService(DatabaseRepository databaseRepository, JsonHandlingService jsonHandlingService, EntityManager entityManager) {
|
||||
this.databaseRepository = databaseRepository;
|
||||
this.jsonHandlingService = jsonHandlingService;
|
||||
this.entityManager = entityManager;
|
||||
}
|
||||
|
||||
public QueryableList<DMPDatasetProfile> dmpDatasetProfileQueryableList() {
|
||||
return databaseRepository.getDmpDatasetProfileDao().asQueryable();
|
||||
}
|
||||
|
||||
public List<DMPDatasetProfile> getDatasets(Integer skip, Integer take) {
|
||||
return dmpDatasetProfileQueryableList()
|
||||
// .orderBy((builder, root) -> builder.desc(root.get("created")))
|
||||
.skip(skip)
|
||||
.take(take)
|
||||
.toList();
|
||||
}
|
||||
|
||||
public List<DmpDatasetProfileMigrationCollectedInfo> collectDatasetsInfo() throws JsonProcessingException {
|
||||
List<DmpDatasetProfileMigrationCollectedInfo> collectedInfoList = new ArrayList<>();
|
||||
List<DMPDatasetProfile> dmpDatasetProfiles = getDatasets(0, 4);
|
||||
for (DMPDatasetProfile dmpDatasetProfile : dmpDatasetProfiles) {
|
||||
DmpDatasetProfileMigrationCollectedInfo dmpDatasetProfileMigrationCollectedInfo = new DmpDatasetProfileMigrationCollectedInfo();
|
||||
|
||||
DmpDatasetProfileData data = jsonHandlingService.fromJson(DmpDatasetProfileData.class, dmpDatasetProfile.getData());
|
||||
|
||||
//Collect basic information
|
||||
DmpDescriptionTemplateEntity dmpDescriptionTemplateEntity = new DmpDescriptionTemplateEntity();
|
||||
dmpDescriptionTemplateEntity.setDescriptionTemplateId(dmpDatasetProfile.getDatasetprofile().getId());
|
||||
dmpDescriptionTemplateEntity.setDmpId(dmpDatasetProfile.getDmp().getId());
|
||||
dmpDescriptionTemplateEntity.setCreatedAt(Instant.now());
|
||||
dmpDescriptionTemplateEntity.setUpdatedAt(Instant.now());
|
||||
dmpDescriptionTemplateEntity.setSectionId(null); //TODO
|
||||
dmpDescriptionTemplateEntity.setIsActive(IsActive.Active);
|
||||
|
||||
dmpDatasetProfileMigrationCollectedInfo.dmpDescriptionTemplateEntity = dmpDescriptionTemplateEntity;
|
||||
|
||||
collectedInfoList.add(dmpDatasetProfileMigrationCollectedInfo);
|
||||
}
|
||||
return collectedInfoList;
|
||||
}
|
||||
|
||||
public String migrate() throws JsonProcessingException {
|
||||
for (DmpDatasetProfileMigrationCollectedInfo collectedInfo : collectDatasetsInfo()) {
|
||||
// this.entityManager.persist(collectedInfo.dmpDescriptionTemplateEntity);
|
||||
}
|
||||
this.entityManager.flush();
|
||||
return "Migrated dmps";
|
||||
}
|
||||
|
||||
public static class DmpDatasetProfileMigrationCollectedInfo {
|
||||
|
||||
public DmpDescriptionTemplateEntity dmpDescriptionTemplateEntity;
|
||||
|
||||
}
|
||||
|
||||
@JsonIgnoreProperties({"validationErrorModel"})
|
||||
public static class DmpDatasetProfileData {
|
||||
|
||||
private List<Integer> dmpSectionIndex;
|
||||
|
||||
public List<Integer> getDmpSectionIndex() {
|
||||
return dmpSectionIndex;
|
||||
}
|
||||
|
||||
public void setDmpSectionIndex(List<Integer> dmpSectionIndex) {
|
||||
this.dmpSectionIndex = dmpSectionIndex;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -13,12 +13,9 @@ import eu.eudat.data.DmpEntity;
|
|||
import eu.old.eudat.data.entities.DMP;
|
||||
import eu.old.eudat.logic.services.operations.DatabaseRepository;
|
||||
import eu.old.eudat.models.data.dmp.DataManagementPlan;
|
||||
import eu.old.eudat.publicapi.migration.MigrationController;
|
||||
import eu.old.eudat.queryable.QueryableList;
|
||||
import jakarta.persistence.EntityManager;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
@ -44,7 +41,7 @@ public class DmpMigrationService {
|
|||
return databaseRepository.getDmpDao().asQueryable();
|
||||
}
|
||||
|
||||
public List<DataManagementPlan> getDmps(@PathVariable("skip") Integer skip, @PathVariable("take") Integer take) {
|
||||
public List<DataManagementPlan> getDmps(Integer skip, Integer take) {
|
||||
List<DMP> dmps = dmpQueryableList()
|
||||
.orderBy((builder, root) -> builder.desc(root.get("created")))
|
||||
.skip(skip)
|
||||
|
@ -70,7 +67,7 @@ public class DmpMigrationService {
|
|||
|
||||
//Collect basic dmp information
|
||||
DmpEntity dmpEntity = new DmpEntity();
|
||||
dmpEntity.setId(UUID.randomUUID());
|
||||
dmpEntity.setId(dataManagementPlan.getId());
|
||||
dmpEntity.setLabel(dataManagementPlan.getLabel());
|
||||
dmpEntity.setDescription(dataManagementPlan.getDescription());
|
||||
if (dataManagementPlan.getCreator() != null)
|
||||
|
@ -120,7 +117,6 @@ public class DmpMigrationService {
|
|||
return collectedInfoList;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public String migrate() throws JsonProcessingException {
|
||||
for (DmpMigrationCollectedInfo collectedInfo : collectDmpsInfo()) {
|
||||
this.entityManager.persist(collectedInfo.dmpEntity);
|
||||
|
|
|
@ -22,6 +22,7 @@ public class DatasetWizardModel implements DataModel<Dataset, DatasetWizardModel
|
|||
private String description;
|
||||
private short status;
|
||||
private Date created;
|
||||
private UUID createdBy;
|
||||
private DataManagementPlan dmp;
|
||||
private Integer dmpSectionIndex;
|
||||
private PagedDatasetProfile datasetProfileDefinition;
|
||||
|
@ -33,6 +34,7 @@ public class DatasetWizardModel implements DataModel<Dataset, DatasetWizardModel
|
|||
private DatasetProfileOverviewModel profile;
|
||||
private Boolean isProfileLatestVersion;
|
||||
private Date modified;
|
||||
private Date finalized;
|
||||
|
||||
public UUID getId() {
|
||||
return id;
|
||||
|
@ -83,6 +85,13 @@ public class DatasetWizardModel implements DataModel<Dataset, DatasetWizardModel
|
|||
this.created = created;
|
||||
}
|
||||
|
||||
public UUID getCreatedBy() {
|
||||
return createdBy;
|
||||
}
|
||||
public void setCreatedBy(UUID createdBy) {
|
||||
this.createdBy = createdBy;
|
||||
}
|
||||
|
||||
public DataManagementPlan getDmp() {
|
||||
return dmp;
|
||||
}
|
||||
|
@ -161,6 +170,13 @@ public class DatasetWizardModel implements DataModel<Dataset, DatasetWizardModel
|
|||
this.modified = modified;
|
||||
}
|
||||
|
||||
public Date getFinalized() {
|
||||
return finalized;
|
||||
}
|
||||
public void setFinalized(Date finalized) {
|
||||
this.finalized = finalized;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DatasetWizardModel fromDataModel(Dataset entity) {
|
||||
this.id = entity.getId();
|
||||
|
@ -183,6 +199,7 @@ public class DatasetWizardModel implements DataModel<Dataset, DatasetWizardModel
|
|||
}).collect(Collectors.toList()) : new ArrayList<>();
|
||||
this.services = entity.getServices() != null ? entity.getServices().stream().map(item -> new eu.old.eudat.models.data.dataset.Service().fromDataModel(item.getService())).collect(Collectors.toList()) : new ArrayList<>();
|
||||
this.created = entity.getCreated();
|
||||
this.createdBy = entity.getCreator().getId();
|
||||
this.dmp = new DataManagementPlan().fromDataModelNoDatasets(entity.getDmp());
|
||||
this.dmpSectionIndex = entity.getDmpSectionIndex();
|
||||
this.externalDatasets = entity.getDatasetExternalDatasets() != null ? entity.getDatasetExternalDatasets().stream().map(item -> {
|
||||
|
@ -196,6 +213,7 @@ public class DatasetWizardModel implements DataModel<Dataset, DatasetWizardModel
|
|||
return externalDatasetListingModel;
|
||||
}).collect(Collectors.toList()) : new ArrayList<>();
|
||||
this.modified = entity.getModified();
|
||||
this.finalized = entity.getFinalizedAt();
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -251,7 +269,11 @@ public class DatasetWizardModel implements DataModel<Dataset, DatasetWizardModel
|
|||
entity.setDmpSectionIndex(this.dmpSectionIndex);
|
||||
entity.setDescription(this.description);
|
||||
entity.setCreated(this.created != null ? this.created : new Date());
|
||||
UserInfo userInfo = new UserInfo();
|
||||
userInfo.setId(this.createdBy);
|
||||
entity.setCreator(userInfo);
|
||||
entity.setModified(new Date());
|
||||
entity.setFinalizedAt(this.finalized != null ? this.finalized : new Date());
|
||||
DescriptionTemplate profile = new DescriptionTemplate();
|
||||
profile.setId(this.profile.getId());
|
||||
entity.setProfile(profile);
|
||||
|
|
|
@ -2,7 +2,14 @@ package eu.old.eudat.publicapi.migration;
|
|||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import eu.old.eudat.migration.*;
|
||||
import eu.eudat.commons.JsonHandlingService;
|
||||
import eu.old.eudat.logic.services.operations.DatabaseRepository;
|
||||
import eu.old.eudat.migration.DatasetMigrationService;
|
||||
import eu.old.eudat.migration.DmpDatasetProfileMigrationService;
|
||||
import eu.old.eudat.migration.DmpMigrationService;
|
||||
import eu.old.eudat.migration.OrganizationMigrationService;
|
||||
import io.swagger.annotations.Api;
|
||||
import jakarta.persistence.EntityManager;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
|
@ -22,10 +29,16 @@ public class MigrationController {
|
|||
private final ResearcherMigrationService researcherMigrationService;
|
||||
private final ServiceMigrationService serviceMigrationService;
|
||||
|
||||
private final DatasetMigrationService datasetMigrationService;
|
||||
|
||||
private final DmpDatasetProfileMigrationService dmpDatasetProfileMigrationService;
|
||||
|
||||
private final OrganizationMigrationService organizationMigrationService;
|
||||
|
||||
public MigrationController(
|
||||
DmpMigrationService dmpMigrationService,
|
||||
DatasetMigrationService datasetMigrationService,
|
||||
DmpDatasetProfileMigrationService dmpDatasetProfileMigrationService,
|
||||
DataRepositoryMigrationService dataRepositoryMigrationService,
|
||||
ExternalDatasetMigrationService externalDatasetMigrationService,
|
||||
FunderMigrationService funderMigrationService,
|
||||
|
@ -37,6 +50,8 @@ public class MigrationController {
|
|||
OrganizationMigrationService organizationMigrationService
|
||||
) {
|
||||
this.dmpMigrationService = dmpMigrationService;
|
||||
this.datasetMigrationService = datasetMigrationService;
|
||||
this.dmpDatasetProfileMigrationService = dmpDatasetProfileMigrationService;
|
||||
this.dataRepositoryMigrationService = dataRepositoryMigrationService;
|
||||
this.externalDatasetMigrationService = externalDatasetMigrationService;
|
||||
this.funderMigrationService = funderMigrationService;
|
||||
|
@ -54,7 +69,19 @@ public class MigrationController {
|
|||
return this.dmpMigrationService.migrate();
|
||||
}
|
||||
|
||||
@GetMapping("organizations")
|
||||
@GetMapping("datasets/migrate")
|
||||
@Transactional
|
||||
public String migrateDatasets() throws JsonProcessingException {
|
||||
return this.datasetMigrationService.migrate();
|
||||
}
|
||||
|
||||
@GetMapping("dmp-dataset-profiles/migrate")
|
||||
@Transactional
|
||||
public String migrateDmpDatasetProfiles() throws JsonProcessingException {
|
||||
return this.dmpDatasetProfileMigrationService.migrate();
|
||||
}
|
||||
|
||||
@GetMapping("organizations/migrate")
|
||||
@Transactional
|
||||
public boolean migrateOrganizations() {
|
||||
this.organizationMigrationService.migrate();
|
||||
|
|
Loading…
Reference in New Issue