2018-06-27 12:29:21 +02:00
package eu.eudat.logic.managers ;
2017-12-20 15:52:09 +01:00
2018-03-21 11:57:56 +01:00
import eu.eudat.data.dao.entities.DMPDao ;
import eu.eudat.data.entities.DMP ;
2018-10-12 10:22:23 +02:00
import eu.eudat.data.entities.Dataset ;
2018-03-21 11:57:56 +01:00
import eu.eudat.data.entities.UserInfo ;
2018-10-12 10:22:23 +02:00
import eu.eudat.exceptions.datasetwizard.DatasetWizardCannotUnlockException ;
import eu.eudat.logic.services.ApiContext ;
2018-06-27 12:29:21 +02:00
import eu.eudat.models.data.datasetwizard.DataManagentPlanListingModel ;
2018-03-21 13:11:02 +01:00
import eu.eudat.data.query.items.item.datasetprofile.DatasetProfileWizardAutocompleteRequest ;
import eu.eudat.data.query.items.item.dataset.DatasetWizardAutocompleteRequest ;
2018-06-27 12:29:21 +02:00
import eu.eudat.models.data.dmp.AssociatedProfile ;
import eu.eudat.models.data.dmp.DataManagementPlan ;
import eu.eudat.models.data.security.Principal ;
2017-12-20 15:52:09 +01:00
import eu.eudat.queryable.QueryableList ;
2020-03-13 17:33:58 +01:00
import java.io.IOException ;
2017-12-21 10:26:11 +01:00
import java.util.LinkedList ;
2017-12-20 15:52:09 +01:00
import java.util.List ;
2018-10-12 10:22:23 +02:00
import java.util.UUID ;
2017-12-20 15:52:09 +01:00
2018-02-01 10:08:06 +01:00
2017-12-20 15:52:09 +01:00
public class DatasetWizardManager {
public static List < DataManagentPlanListingModel > getUserDmps ( DMPDao dmpRepository , DatasetWizardAutocompleteRequest datasetWizardAutocompleteRequest , Principal principal ) throws InstantiationException , IllegalAccessException {
UserInfo userInfo = new UserInfo ( ) ;
userInfo . setId ( principal . getId ( ) ) ;
2018-03-21 11:57:56 +01:00
QueryableList < DMP > items = dmpRepository . getUserDmps ( datasetWizardAutocompleteRequest . getCriteria ( ) , userInfo ) ;
2018-02-21 11:07:31 +01:00
List < DataManagentPlanListingModel > dataManagementPlans = items . select ( item - > new DataManagentPlanListingModel ( ) . fromDataModel ( item ) ) ;
2017-12-20 15:52:09 +01:00
return dataManagementPlans ;
}
2017-12-21 10:26:11 +01:00
public static List < AssociatedProfile > getAvailableProfiles ( DMPDao dmpRepository , DatasetProfileWizardAutocompleteRequest datasetProfileWizardAutocompleteRequest ) throws InstantiationException , IllegalAccessException {
2018-02-16 08:45:18 +01:00
DataManagementPlan dataManagementPlan = new DataManagementPlan ( ) . fromDataModel ( dmpRepository . find ( datasetProfileWizardAutocompleteRequest . getCriteria ( ) . getId ( ) ) ) ;
if ( dataManagementPlan . getProfiles ( ) = = null | | dataManagementPlan . getProfiles ( ) . isEmpty ( ) ) {
2017-12-21 10:26:11 +01:00
return new LinkedList < > ( ) ;
}
2017-12-22 09:31:05 +01:00
List < AssociatedProfile > profiles = dataManagementPlan . getProfiles ( ) ;
2018-01-17 13:03:51 +01:00
return profiles ;
2017-12-21 10:26:11 +01:00
}
2018-10-12 10:22:23 +02:00
public void unlock ( ApiContext apiContext , UUID uuid ) throws DatasetWizardCannotUnlockException {
Dataset dataset = apiContext . getOperationsContext ( ) . getDatabaseRepository ( ) . getDatasetDao ( ) . find ( uuid ) ;
if ( dataset . getDmp ( ) . getStatus ( ) = = DMP . DMPStatus . FINALISED . getValue ( ) ) throw new DatasetWizardCannotUnlockException ( " To perform this action you will need to revert DMP's finalisation " ) ;
dataset . setStatus ( Dataset . Status . SAVED . getValue ( ) ) ;
apiContext . getOperationsContext ( ) . getDatabaseRepository ( ) . getDatasetDao ( ) . createOrUpdate ( dataset ) ;
return ;
}
2018-11-30 15:57:20 +01:00
2020-03-13 17:33:58 +01:00
public void delete ( ApiContext apiContext , UUID uuid ) throws IOException {
2018-11-30 15:57:20 +01:00
Dataset oldDataset = apiContext . getOperationsContext ( ) . getDatabaseRepository ( ) . getDatasetDao ( ) . find ( uuid ) ;
2020-04-01 17:16:06 +02:00
eu . eudat . elastic . entities . Dataset oldDatasetElasitc = apiContext . getOperationsContext ( ) . getElasticRepository ( ) . getDatasetRepository ( ) . findDocument ( uuid . toString ( ) ) ;
2020-03-13 17:33:58 +01:00
oldDataset . setStatus ( Dataset . Status . DELETED . getValue ( ) ) ;
2018-11-30 15:57:20 +01:00
apiContext . getOperationsContext ( ) . getDatabaseRepository ( ) . getDatasetDao ( ) . createOrUpdate ( oldDataset ) ;
2020-04-06 17:34:25 +02:00
if ( oldDatasetElasitc ! = null & & uuid ! = null & & oldDatasetElasitc . getId ( ) ! = null ) {
oldDatasetElasitc . setStatus ( oldDataset . getStatus ( ) ) ;
2020-04-01 17:16:06 +02:00
apiContext . getOperationsContext ( ) . getElasticRepository ( ) . getDatasetRepository ( ) . createOrUpdate ( oldDatasetElasitc ) ;
2020-03-30 14:37:04 +02:00
}
2018-11-30 15:57:20 +01:00
}
2017-12-20 15:52:09 +01:00
}