Migration controller refactoring

This commit is contained in:
Thomas Georgios Giannos 2023-11-21 11:41:11 +02:00
parent 99bf7d29f9
commit f6a6bab04d
1 changed files with 26 additions and 10 deletions

View File

@ -1,14 +1,16 @@
package eu.old.eudat.publicapi.migration;
import eu.eudat.commons.enums.DmpAccessType;
import eu.eudat.commons.enums.DmpStatus;
import eu.eudat.commons.enums.DmpVersionStatus;
import eu.eudat.commons.enums.IsActive;
import eu.eudat.commons.enums.*;
import eu.eudat.data.DmpEntity;
import eu.eudat.data.ReferenceEntity;
import eu.old.eudat.data.dao.criteria.DataManagementPlanCriteria;
import eu.old.eudat.data.dao.criteria.OrganisationCriteria;
import eu.old.eudat.data.dao.entities.DMPDao;
import eu.old.eudat.data.entities.DMP;
import eu.old.eudat.data.entities.Organisation;
import eu.old.eudat.logic.services.operations.DatabaseRepository;
import eu.old.eudat.models.data.dmp.DataManagementPlan;
import eu.old.eudat.queryable.QueryableList;
import io.swagger.annotations.Api;
import jakarta.persistence.EntityManager;
import jakarta.persistence.PersistenceContext;
@ -35,23 +37,32 @@ public class MigrationController {
this.entityManager = entityManager;
}
public QueryableList<DMP> dmpQueryableList() {
return databaseRepository.getDmpDao().asQueryable();
}
public QueryableList<Organisation> organizationQueryableList() {
return databaseRepository.getOrganisationDao().asQueryable();
}
@GetMapping("dmps/all/count")
public Long count() {
return dmpQueryableList().count();
}
@GetMapping("dmps/all/{skip}/{take}")
public List<DataManagementPlan> getDmps(@PathVariable("skip") Integer skip, @PathVariable("take") Integer take) {
DataManagementPlanCriteria criteria = new DataManagementPlanCriteria();
List<DMP> dmps = databaseRepository.getDmpDao()
.getWithCriteria(criteria)
List<DMP> dmps = dmpQueryableList()
.orderBy((builder, root) -> builder.desc(root.get("created")))
.skip(skip)
.take(take)
.toList();
List<DataManagementPlan> results = dmps.stream().map(x -> {
return dmps.stream().map(x -> {
DataManagementPlan dmp = new DataManagementPlan();
dmp.fromDataModel(x);
return dmp;
}).toList();
return results;
}
@GetMapping("dmps/collectInfo")
@ -88,6 +99,11 @@ public class MigrationController {
dmpEntity.setStatus(DmpStatus.of((short) dataManagementPlan.getStatus()));
}
dmpMigrationCollectedInfo.dmpEntity = dmpEntity;
//Collect dmp Organization info
collectedInfoList.add(dmpMigrationCollectedInfo);
}
return collectedInfoList;