DmpBlueprint refactor

This commit is contained in:
Efstratios Giannopoulos 2023-10-23 18:13:34 +03:00
parent 10615c6fa9
commit 167d3d4a4b
13 changed files with 148 additions and 544 deletions

View File

@ -6,7 +6,9 @@ import eu.eudat.commons.types.xml.XmlBuilder;
import eu.eudat.convention.ConventionService; import eu.eudat.convention.ConventionService;
import eu.eudat.data.DmpBlueprintEntity; import eu.eudat.data.DmpBlueprintEntity;
import eu.eudat.model.DmpBlueprint; import eu.eudat.model.DmpBlueprint;
import eu.eudat.model.dmpblueprintdefinition.Definition; import eu.eudat.model.builder.dmpblueprintdefinition.DefinitionBuilder;
import eu.eudat.model.builder.dmpblueprintdefinition.SectionBuilder;
import gr.cite.tools.data.builder.BuilderFactory;
import gr.cite.tools.exception.MyApplicationException; import gr.cite.tools.exception.MyApplicationException;
import gr.cite.tools.fieldset.FieldSet; import gr.cite.tools.fieldset.FieldSet;
import gr.cite.tools.logging.DataLogEntry; import gr.cite.tools.logging.DataLogEntry;
@ -23,13 +25,15 @@ import java.util.*;
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class DmpBlueprintBuilder extends BaseBuilder<DmpBlueprint, DmpBlueprintEntity> { public class DmpBlueprintBuilder extends BaseBuilder<DmpBlueprint, DmpBlueprintEntity> {
private final BuilderFactory builderFactory;
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None); private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
@Autowired @Autowired
public DmpBlueprintBuilder( public DmpBlueprintBuilder(
ConventionService conventionService ConventionService conventionService,
) { BuilderFactory builderFactory) {
super(conventionService, new LoggerService(LoggerFactory.getLogger(DmpBlueprintBuilder.class))); super(conventionService, new LoggerService(LoggerFactory.getLogger(DmpBlueprintBuilder.class)));
this.builderFactory = builderFactory;
} }
public DmpBlueprintBuilder authorize(EnumSet<AuthorizationFlags> values) { public DmpBlueprintBuilder authorize(EnumSet<AuthorizationFlags> values) {
@ -55,6 +59,10 @@ public class DmpBlueprintBuilder extends BaseBuilder<DmpBlueprint, DmpBlueprintE
if (fields.hasField(this.asIndexer(DmpBlueprint._isActive))) m.setIsActive(d.getIsActive()); if (fields.hasField(this.asIndexer(DmpBlueprint._isActive))) m.setIsActive(d.getIsActive());
if (fields.hasField(this.asIndexer(DmpBlueprint._status))) m.setStatus(d.getStatus()); if (fields.hasField(this.asIndexer(DmpBlueprint._status))) m.setStatus(d.getStatus());
if (fields.hasField(this.asIndexer(DmpBlueprint._hash))) m.setHash(this.hashValue(d.getUpdatedAt())); if (fields.hasField(this.asIndexer(DmpBlueprint._hash))) m.setHash(this.hashValue(d.getUpdatedAt()));
if (!definitionFields.isEmpty() && d.getDefinition() != null){
DefinitionEntity definition = new DefinitionEntity().fromXml(XmlBuilder.fromXml(d.getDefinition()).getDocumentElement());
m.setDefinition(this.builderFactory.builder(DefinitionBuilder.class).authorize(this.authorize).build(definitionFields, definition));
}
models.add(m); models.add(m);
} }
this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0)); this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0));

View File

@ -53,6 +53,14 @@ public class DmpBlueprintLookup extends Lookup {
this.excludedIds = excludeIds; this.excludedIds = excludeIds;
} }
public List<DmpBlueprintStatus> getStatuses() {
return statuses;
}
public void setStatuses(List<DmpBlueprintStatus> statuses) {
this.statuses = statuses;
}
public DmpBlueprintQuery enrich(QueryFactory queryFactory) { public DmpBlueprintQuery enrich(QueryFactory queryFactory) {
DmpBlueprintQuery query = queryFactory.query(DmpBlueprintQuery.class); DmpBlueprintQuery query = queryFactory.query(DmpBlueprintQuery.class);
if (this.like != null) query.like(this.like); if (this.like != null) query.like(this.like);

View File

@ -1,5 +1,7 @@
package eu.eudat.service.dmpblueprint; package eu.eudat.service.dmpblueprint;
import eu.eudat.commons.enums.DmpBlueprintSystemFieldType;
import eu.eudat.data.DmpBlueprintEntity;
import eu.eudat.model.DmpBlueprint; import eu.eudat.model.DmpBlueprint;
import eu.eudat.model.persist.DmpBlueprintPersist; import eu.eudat.model.persist.DmpBlueprintPersist;
import gr.cite.tools.exception.MyApplicationException; import gr.cite.tools.exception.MyApplicationException;
@ -16,5 +18,7 @@ public interface DmpBlueprintService {
DmpBlueprint persist(DmpBlueprintPersist model, FieldSet fields) throws MyForbiddenException, MyValidationException, MyApplicationException, MyNotFoundException, InvalidApplicationException; DmpBlueprint persist(DmpBlueprintPersist model, FieldSet fields) throws MyForbiddenException, MyValidationException, MyApplicationException, MyNotFoundException, InvalidApplicationException;
void deleteAndSave(UUID id) throws MyForbiddenException, InvalidApplicationException; void deleteAndSave(UUID id) throws MyForbiddenException, InvalidApplicationException;
boolean fieldInBlueprint(DmpBlueprintEntity dmpBlueprintEntity, DmpBlueprintSystemFieldType type);
boolean fieldInBlueprint(UUID id, DmpBlueprintSystemFieldType type);
} }

View File

@ -3,6 +3,7 @@ package eu.eudat.service.dmpblueprint;
import eu.eudat.authorization.AuthorizationFlags; import eu.eudat.authorization.AuthorizationFlags;
import eu.eudat.authorization.Permission; import eu.eudat.authorization.Permission;
import eu.eudat.commons.enums.DmpBlueprintFieldCategory; import eu.eudat.commons.enums.DmpBlueprintFieldCategory;
import eu.eudat.commons.enums.DmpBlueprintSystemFieldType;
import eu.eudat.commons.enums.IsActive; import eu.eudat.commons.enums.IsActive;
import eu.eudat.commons.types.dmpblueprint.*; import eu.eudat.commons.types.dmpblueprint.*;
import eu.eudat.commons.types.xml.XmlBuilder; import eu.eudat.commons.types.xml.XmlBuilder;
@ -10,6 +11,7 @@ import eu.eudat.convention.ConventionService;
import eu.eudat.data.DmpBlueprintEntity; import eu.eudat.data.DmpBlueprintEntity;
import eu.eudat.model.DmpBlueprint; import eu.eudat.model.DmpBlueprint;
import eu.eudat.model.builder.DmpBlueprintBuilder; import eu.eudat.model.builder.DmpBlueprintBuilder;
import eu.eudat.model.builder.dmpblueprintdefinition.DefinitionBuilder;
import eu.eudat.model.deleter.DmpBlueprintDeleter; import eu.eudat.model.deleter.DmpBlueprintDeleter;
import eu.eudat.model.persist.DmpBlueprintPersist; import eu.eudat.model.persist.DmpBlueprintPersist;
import eu.eudat.model.persist.dmpblueprintdefinition.*; import eu.eudat.model.persist.dmpblueprintdefinition.*;
@ -193,5 +195,30 @@ public class DmpBlueprintServiceImpl implements DmpBlueprintService {
this.deleterFactory.deleter(DmpBlueprintDeleter.class).deleteAndSaveByIds(List.of(id)); this.deleterFactory.deleter(DmpBlueprintDeleter.class).deleteAndSaveByIds(List.of(id));
} }
public boolean fieldInBlueprint(DmpBlueprintEntity dmpBlueprintEntity, DmpBlueprintSystemFieldType type) {
DefinitionEntity definition = new DefinitionEntity().fromXml(XmlBuilder.fromXml(dmpBlueprintEntity.getDefinition()).getDocumentElement());
if (definition == null || definition.getSections() == null) return false;
for(SectionEntity section: definition.getSections()){
if (section.getFields() == null) continue;
for(FieldEntity field: section.getFields()){
if(field.getCategory().equals(DmpBlueprintFieldCategory.System)){
SystemFieldEntity systemField = (SystemFieldEntity)field;
if(systemField.getType().equals(type)){
return true;
}
}
}
}
return false;
}
public boolean fieldInBlueprint(UUID id, DmpBlueprintSystemFieldType type) {
DmpBlueprintEntity data = this.entityManager.find(DmpBlueprintEntity.class, id);
if (data == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{id, DmpBlueprint.class.getSimpleName()}, LocaleContextHolder.getLocale()));
return this.fieldInBlueprint(data, type);
}
} }

View File

@ -1,27 +0,0 @@
package eu.eudat.data.query.items.dmpblueprint;
import eu.eudat.data.dao.criteria.DataManagementPlanBlueprintCriteria;
import eu.eudat.data.DmpBlueprintEntity;
import eu.eudat.data.query.PaginationService;
import eu.eudat.data.query.definition.TableQuery;
import eu.eudat.queryable.QueryableList;
import java.util.UUID;
public class DataManagementPlanBlueprintTableRequest extends TableQuery<DataManagementPlanBlueprintCriteria, DmpBlueprintEntity, UUID> {
@Override
public QueryableList<DmpBlueprintEntity> applyCriteria() {
QueryableList<DmpBlueprintEntity> query = this.getQuery();
if (this.getCriteria().getLike() != null && !this.getCriteria().getLike().isEmpty())
query.where((builder, root) -> builder.like(root.get("label"), "%" + this.getCriteria().getLike() + "%"));
if (this.getCriteria().getStatus() != null)
query.where((builder, root) -> builder.equal(root.get("status"), this.getCriteria().getStatus()));
return query;
}
@Override
public QueryableList<DmpBlueprintEntity> applyPaging(QueryableList<DmpBlueprintEntity> items) {
return PaginationService.applyPaging(items, this);
}
}

View File

@ -1,160 +0,0 @@
package eu.eudat.controllers;
import eu.eudat.authorization.Permission;
import eu.eudat.data.dao.criteria.RequestItem;
import eu.eudat.data.DmpBlueprintEntity;
import eu.eudat.data.old.DescriptionTemplate;
import eu.eudat.data.query.items.dmpblueprint.DataManagementPlanBlueprintTableRequest;
import eu.eudat.data.query.items.table.dmpprofile.DataManagementPlanProfileTableRequest;
import eu.eudat.exceptions.dmpblueprint.DmpBlueprintUsedException;
import eu.eudat.logic.managers.DataManagementProfileManager;
import eu.eudat.logic.services.ApiContext;
import eu.eudat.models.data.helpermodels.Tuple;
import eu.eudat.models.data.helpers.common.AutoCompleteLookupItem;
import eu.eudat.models.data.helpers.common.DataTableData;
import eu.eudat.models.data.helpers.responses.ResponseItem;
import eu.eudat.models.data.listingmodels.DataManagementPlanBlueprintListingModel;
import eu.eudat.types.ApiMessageCode;
import gr.cite.commons.web.authz.service.AuthorizationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import jakarta.validation.Valid;
import javax.management.InvalidApplicationException;
import javax.xml.xpath.XPathExpressionException;
import java.io.IOException;
import java.util.List;
/**
* Created by ikalyvas on 3/21/2018.
*/
@RestController
@CrossOrigin
@RequestMapping(value = {"/api/dmpprofile"})
public class DMPProfileController extends BaseController {
private final DataManagementProfileManager dataManagementProfileManager;
private final AuthorizationService authorizationService;
@Autowired
public DMPProfileController(ApiContext apiContext, DataManagementProfileManager dataManagementProfileManager, AuthorizationService authorizationService) {
super(apiContext);
this.dataManagementProfileManager = dataManagementProfileManager;
this.authorizationService = authorizationService;
}
// @Transactional
// @RequestMapping(method = RequestMethod.POST, consumes = "application/json", produces = "application/json")
// public @ResponseBody
// ResponseEntity<ResponseItem<DmpBlueprintEntity>> createOrUpdate(@RequestBody DataManagementPlanProfileListingModel dataManagementPlan) throws Exception {
// this.authorizationService.authorizeForce(Permission.AdminRole);
//
// this.dataManagementProfileManager.createOrUpdate(dataManagementPlan);
// return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DmpBlueprintEntity>().status(ApiMessageCode.SUCCESS_MESSAGE).message("Created"));
// }
@Transactional
@RequestMapping(method = RequestMethod.POST, value = {"/blueprint"}, consumes = "application/json", produces = "application/json")
public @ResponseBody
ResponseEntity<ResponseItem<DmpBlueprintEntity>> createOrUpdateBlueprint(@RequestBody DataManagementPlanBlueprintListingModel dataManagementPlan) throws Exception {
this.authorizationService.authorizeForce(Permission.AdminRole);
this.dataManagementProfileManager.createOrUpdateBlueprint(dataManagementPlan);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DmpBlueprintEntity>().status(ApiMessageCode.SUCCESS_MESSAGE).message("Created"));
}
// @RequestMapping(method = RequestMethod.GET, value = {"/getSingle/{id}"}, produces = "application/json")
// public @ResponseBody
// ResponseEntity<ResponseItem<DataManagementPlanProfileListingModel>> getSingle(@PathVariable String id) throws IllegalAccessException, InstantiationException, InvalidApplicationException {
// this.authorizationService.authorizeForce(Permission.AuthenticatedRole);
//
// DataManagementPlanProfileListingModel dataManagementPlanProfileListingModel = this.dataManagementProfileManager.getSingle(id);
// return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DataManagementPlanProfileListingModel>().status(ApiMessageCode.NO_MESSAGE).payload(dataManagementPlanProfileListingModel));
// }
@RequestMapping(method = RequestMethod.GET, value = {"/getSingleBlueprint/{id}"}, produces = "application/json")
public @ResponseBody
ResponseEntity<ResponseItem<DataManagementPlanBlueprintListingModel>> getSingleBlueprint(@PathVariable String id) throws InvalidApplicationException {
this.authorizationService.authorizeForce(Permission.AuthenticatedRole);
DataManagementPlanBlueprintListingModel dataManagementPlanBlueprintListingModel = this.dataManagementProfileManager.getSingleBlueprint(id);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DataManagementPlanBlueprintListingModel>().status(ApiMessageCode.NO_MESSAGE).payload(dataManagementPlanBlueprintListingModel));
}
// @RequestMapping(method = RequestMethod.POST, value = {"/getPaged"}, consumes = "application/json", produces = "application/json")
// public @ResponseBody
// ResponseEntity<ResponseItem<DataTableData<DataManagementPlanProfileListingModel>>> getPaged(@Valid @RequestBody DataManagementPlanProfileTableRequest dataManagementPlanProfileTableRequest) throws Exception {
// this.authorizationService.authorizeForce(Permission.AuthenticatedRole);
//
// DataTableData<DataManagementPlanProfileListingModel> dataTable = this.dataManagementProfileManager.getPaged(dataManagementPlanProfileTableRequest);
// return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DataTableData<DataManagementPlanProfileListingModel>>().status(ApiMessageCode.NO_MESSAGE).payload(dataTable));
// }
@RequestMapping(method = RequestMethod.POST, value = {"/getPagedBlueprint"}, consumes = "application/json", produces = "application/json")
public @ResponseBody
ResponseEntity<ResponseItem<DataTableData<DataManagementPlanBlueprintListingModel>>> getPagedBlueprint(@Valid @RequestBody DataManagementPlanBlueprintTableRequest dataManagementPlanBlueprintTableRequest) throws Exception {
this.authorizationService.authorizeForce(Permission.AuthenticatedRole);
DataTableData<DataManagementPlanBlueprintListingModel> dataTable = this.dataManagementProfileManager.getPagedBlueprint(dataManagementPlanBlueprintTableRequest);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DataTableData<DataManagementPlanBlueprintListingModel>>().status(ApiMessageCode.NO_MESSAGE).payload(dataTable));
}
@Transactional
@RequestMapping(method = RequestMethod.POST, value = {"/clone/{id}"}, consumes = "application/json", produces = "application/json")
public ResponseEntity<ResponseItem<DataManagementPlanBlueprintListingModel>> clone(@PathVariable String id) throws InvalidApplicationException {
this.authorizationService.authorizeForce(Permission.AdminRole);
DataManagementPlanBlueprintListingModel dmpBlueprint = this.dataManagementProfileManager.getSingleBlueprint(id);
dmpBlueprint.setLabel(dmpBlueprint.getLabel() + " new ");
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DataManagementPlanBlueprintListingModel>().payload(dmpBlueprint));
}
@Transactional
@RequestMapping(method = RequestMethod.DELETE, value = {"{id}"}, consumes = "application/json", produces = "application/json")
public @ResponseBody
ResponseEntity<ResponseItem<Void>> inactivate(@PathVariable String id) {
this.authorizationService.authorizeForce(Permission.AdminRole);
try {
this.dataManagementProfileManager.inactivate(id);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<Void>().status(ApiMessageCode.SUCCESS_MESSAGE));
} catch (DmpBlueprintUsedException | InvalidApplicationException exception) {
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<Void>().status(ApiMessageCode.UNSUCCESS_DELETE).message(exception.getMessage()));
}
}
@RequestMapping(method = RequestMethod.GET, value = {"/getXml/{id}"}, produces = "application/json")
public @ResponseBody
ResponseEntity getXml( @RequestHeader("Content-Type") String contentType, @PathVariable String id) throws IOException, InvalidApplicationException {
this.authorizationService.authorizeForce(Permission.AuthenticatedRole);
if (contentType.equals("application/xml")) {
DataManagementPlanBlueprintListingModel dataManagementPlanBlueprintListingModel = this.dataManagementProfileManager.getSingleBlueprint(id);
return this.dataManagementProfileManager.getDocument(dataManagementPlanBlueprintListingModel);
}else {
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<DataManagementPlanBlueprintListingModel>().status(ApiMessageCode.ERROR_MESSAGE).message("NOT AUTHORIZE"));
}
}
@RequestMapping(method = RequestMethod.POST, value = {"/upload"})
public ResponseEntity<Object> setDatasetProfileXml(@RequestParam("file") MultipartFile file) throws Exception {
this.authorizationService.authorizeForce(Permission.AdminRole);
eu.eudat.logic.utilities.documents.xml.dmpXml.dmpBlueprintModel.DmpBlueprint dmpBlueprintModel = this.dataManagementProfileManager.createDmpProfileFromXml(file);
DataManagementPlanBlueprintListingModel dmpBlueprint = dmpBlueprintModel.toDmpProfileCompositeModel(file.getOriginalFilename());
this.dataManagementProfileManager.createOrUpdateBlueprint(dmpBlueprint);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<DescriptionTemplate>>()
.status(ApiMessageCode.SUCCESS_MESSAGE).message(""));
}
// @RequestMapping(method = RequestMethod.POST, value = {"/search/autocomplete"})
// public ResponseEntity<Object> getExternalAutocomplete(@RequestBody RequestItem<AutoCompleteLookupItem> lookupItem) throws XPathExpressionException, InvalidApplicationException {
// List<Tuple<String, String>> items = this.dataManagementProfileManager.getExternalAutocomplete(lookupItem);
// return ResponseEntity.status(HttpStatus.OK).body(items);
// }
}

View File

@ -2,15 +2,19 @@ package eu.eudat.controllers.v2;
import eu.eudat.audit.AuditableAction; import eu.eudat.audit.AuditableAction;
import eu.eudat.authorization.AuthorizationFlags; import eu.eudat.authorization.AuthorizationFlags;
import eu.eudat.authorization.Permission;
import eu.eudat.data.DmpBlueprintEntity; import eu.eudat.data.DmpBlueprintEntity;
import eu.eudat.data.old.DescriptionTemplate;
import eu.eudat.model.DmpBlueprint; import eu.eudat.model.DmpBlueprint;
import eu.eudat.model.builder.DmpBlueprintBuilder; import eu.eudat.model.builder.DmpBlueprintBuilder;
import eu.eudat.model.censorship.DmpBlueprintCensor; import eu.eudat.model.censorship.DmpBlueprintCensor;
import eu.eudat.model.persist.DmpBlueprintPersist; import eu.eudat.model.persist.DmpBlueprintPersist;
import eu.eudat.model.result.QueryResult; import eu.eudat.model.result.QueryResult;
import eu.eudat.models.data.helpers.responses.ResponseItem;
import eu.eudat.query.DmpBlueprintQuery; import eu.eudat.query.DmpBlueprintQuery;
import eu.eudat.query.lookup.DmpBlueprintLookup; import eu.eudat.query.lookup.DmpBlueprintLookup;
import eu.eudat.service.dmpblueprint.DmpBlueprintService; import eu.eudat.service.dmpblueprint.DmpBlueprintService;
import eu.eudat.types.ApiMessageCode;
import gr.cite.tools.auditing.AuditService; import gr.cite.tools.auditing.AuditService;
import gr.cite.tools.data.builder.BuilderFactory; import gr.cite.tools.data.builder.BuilderFactory;
import gr.cite.tools.data.censor.CensorFactory; import gr.cite.tools.data.censor.CensorFactory;
@ -26,9 +30,13 @@ import jakarta.transaction.Transactional;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.context.MessageSource; import org.springframework.context.MessageSource;
import org.springframework.context.i18n.LocaleContextHolder; import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.management.InvalidApplicationException; import javax.management.InvalidApplicationException;
import java.io.IOException;
import java.util.*; import java.util.*;
@RestController @RestController
@ -128,4 +136,28 @@ public class DmpBlueprintController {
this.auditService.track(AuditableAction.DmpBlueprint_Delete, "id", id); this.auditService.track(AuditableAction.DmpBlueprint_Delete, "id", id);
//this.auditService.trackIdentity(AuditableAction.IdentityTracking_Action); //this.auditService.trackIdentity(AuditableAction.IdentityTracking_Action);
} }
// @RequestMapping(method = RequestMethod.GET, value = {"/getXml/{id}"}, produces = "application/json")
// public @ResponseBody
// ResponseEntity getXml(@RequestHeader("Content-Type") String contentType, @PathVariable String id) throws IOException, InvalidApplicationException {
// this.authorizationService.authorizeForce(Permission.AuthenticatedRole);
//
// if (contentType.equals("application/xml")) {
// DataManagementPlanBlueprintListingModel dataManagementPlanBlueprintListingModel = this.dataManagementProfileManager.getSingleBlueprint(id);
// return this.dataManagementProfileManager.getDocument(dataManagementPlanBlueprintListingModel);
// }else {
// return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<DataManagementPlanBlueprintListingModel>().status(ApiMessageCode.ERROR_MESSAGE).message("NOT AUTHORIZE"));
// }
// }
//
// @RequestMapping(method = RequestMethod.POST, value = {"/upload"})
// public ResponseEntity<Object> setDatasetProfileXml(@RequestParam("file") MultipartFile file) throws Exception {
// this.authorizationService.authorizeForce(Permission.AdminRole);
//
// eu.eudat.logic.utilities.documents.xml.dmpXml.dmpBlueprintModel.DmpBlueprint dmpBlueprintModel = this.dataManagementProfileManager.createDmpProfileFromXml(file);
// DataManagementPlanBlueprintListingModel dmpBlueprint = dmpBlueprintModel.toDmpProfileCompositeModel(file.getOriginalFilename());
// this.dataManagementProfileManager.createOrUpdateBlueprint(dmpBlueprint);
// return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<DescriptionTemplate>>()
// .status(ApiMessageCode.SUCCESS_MESSAGE).message(""));
// }
} }

View File

@ -69,6 +69,7 @@ import eu.eudat.models.data.project.ProjectDMPEditorModel;
import eu.eudat.models.data.user.composite.PagedDatasetProfile; import eu.eudat.models.data.user.composite.PagedDatasetProfile;
import eu.eudat.models.data.userinfo.UserListingModel; import eu.eudat.models.data.userinfo.UserListingModel;
import eu.eudat.queryable.QueryableList; import eu.eudat.queryable.QueryableList;
import eu.eudat.service.dmpblueprint.DmpBlueprintService;
import eu.eudat.types.MetricNames; import eu.eudat.types.MetricNames;
import gr.cite.commons.web.authz.service.AuthorizationService; import gr.cite.commons.web.authz.service.AuthorizationService;
import org.apache.poi.xwpf.usermodel.XWPFDocument; import org.apache.poi.xwpf.usermodel.XWPFDocument;
@ -118,7 +119,6 @@ public class DataManagementPlanManager {
private ApiContext apiContext; private ApiContext apiContext;
private DatasetManager datasetManager; private DatasetManager datasetManager;
private DataManagementProfileManager dataManagementProfileManager;
private DatabaseRepository databaseRepository; private DatabaseRepository databaseRepository;
private Environment environment; private Environment environment;
private RDAManager rdaManager; private RDAManager rdaManager;
@ -128,14 +128,13 @@ public class DataManagementPlanManager {
private List<RepositoryDeposit> repositoriesDeposit; private List<RepositoryDeposit> repositoriesDeposit;
private final UserScope userScope; private final UserScope userScope;
private final AuthorizationService authorizationService; private final AuthorizationService authorizationService;
private final DmpBlueprintService dmpBlueprintService;
@Autowired @Autowired
public DataManagementPlanManager(ApiContext apiContext, DatasetManager datasetManager, DataManagementProfileManager dataManagementProfileManager, Environment environment, RDAManager rdaManager, UserManager userManager, public DataManagementPlanManager(ApiContext apiContext, DatasetManager datasetManager, Environment environment, RDAManager rdaManager, UserManager userManager,
MetricsManager metricsManager, ConfigLoader configLoader, List<RepositoryDeposit> repositoriesDeposit, UserScope userScope, AuthorizationService authorizationService) { MetricsManager metricsManager, ConfigLoader configLoader, List<RepositoryDeposit> repositoriesDeposit, UserScope userScope, AuthorizationService authorizationService, DmpBlueprintService dmpBlueprintService) {
this.apiContext = apiContext; this.apiContext = apiContext;
this.datasetManager = datasetManager; this.datasetManager = datasetManager;
this.dataManagementProfileManager = dataManagementProfileManager;
this.databaseRepository = apiContext.getOperationsContext().getDatabaseRepository(); this.databaseRepository = apiContext.getOperationsContext().getDatabaseRepository();
this.environment = environment; this.environment = environment;
this.rdaManager = rdaManager; this.rdaManager = rdaManager;
@ -144,6 +143,7 @@ public class DataManagementPlanManager {
this.configLoader = configLoader; this.configLoader = configLoader;
this.userScope = userScope; this.userScope = userScope;
this.authorizationService = authorizationService; this.authorizationService = authorizationService;
this.dmpBlueprintService = dmpBlueprintService;
this.objectMapper = new ObjectMapper(); this.objectMapper = new ObjectMapper();
this.repositoriesDeposit = repositoriesDeposit; this.repositoriesDeposit = repositoriesDeposit;
} }
@ -509,18 +509,18 @@ public class DataManagementPlanManager {
UserInfo user = apiContext.getOperationsContext().getDatabaseRepository().getUserInfoDao().find(this.userScope.getUserId()); UserInfo user = apiContext.getOperationsContext().getDatabaseRepository().getUserInfoDao().find(this.userScope.getUserId());
newDmp.setCreator(user); newDmp.setCreator(user);
if(this.dataManagementProfileManager.fieldInBlueprint(newDmp.getProfile(), DmpBlueprintSystemFieldType.Organizations)) { if(this.dmpBlueprintService.fieldInBlueprint(newDmp.getProfile(), DmpBlueprintSystemFieldType.Organizations)) {
createOrganisationsIfTheyDontExist(newDmp, apiContext.getOperationsContext().getDatabaseRepository().getOrganisationDao()); createOrganisationsIfTheyDontExist(newDmp, apiContext.getOperationsContext().getDatabaseRepository().getOrganisationDao());
} }
if(this.dataManagementProfileManager.fieldInBlueprint(newDmp.getProfile(), DmpBlueprintSystemFieldType.Researchers)) { if(this.dmpBlueprintService.fieldInBlueprint(newDmp.getProfile(), DmpBlueprintSystemFieldType.Researchers)) {
createResearchersIfTheyDontExist(newDmp, apiContext.getOperationsContext().getDatabaseRepository().getResearcherDao(), user); createResearchersIfTheyDontExist(newDmp, apiContext.getOperationsContext().getDatabaseRepository().getResearcherDao(), user);
} }
if(this.dataManagementProfileManager.fieldInBlueprint(newDmp.getProfile(), DmpBlueprintSystemFieldType.Funder)) { if(this.dmpBlueprintService.fieldInBlueprint(newDmp.getProfile(), DmpBlueprintSystemFieldType.Funder)) {
createFunderIfItDoesntExist(newDmp, apiContext.getOperationsContext().getDatabaseRepository().getFunderDao()); createFunderIfItDoesntExist(newDmp, apiContext.getOperationsContext().getDatabaseRepository().getFunderDao());
} }
if(this.dataManagementProfileManager.fieldInBlueprint(newDmp.getProfile(), DmpBlueprintSystemFieldType.Grant)) { if(this.dmpBlueprintService.fieldInBlueprint(newDmp.getProfile(), DmpBlueprintSystemFieldType.Grant)) {
createGrantIfItDoesntExist(newDmp, apiContext.getOperationsContext().getDatabaseRepository().getGrantDao()); createGrantIfItDoesntExist(newDmp, apiContext.getOperationsContext().getDatabaseRepository().getGrantDao());
if(this.dataManagementProfileManager.fieldInBlueprint(newDmp.getProfile(), DmpBlueprintSystemFieldType.Project)) { if(this.dmpBlueprintService.fieldInBlueprint(newDmp.getProfile(), DmpBlueprintSystemFieldType.Project)) {
if (newDmp.getProject() != null && newDmp.getGrant() != null && (newDmp.getProject().getLabel() == null || newDmp.getProject().getLabel().trim().isEmpty())) { if (newDmp.getProject() != null && newDmp.getGrant() != null && (newDmp.getProject().getLabel() == null || newDmp.getProject().getLabel().trim().isEmpty())) {
newDmp.setProject(newDmp.getProject().projectFromGrant(newDmp.getGrant())); newDmp.setProject(newDmp.getProject().projectFromGrant(newDmp.getGrant()));
} }
@ -546,16 +546,16 @@ public class DataManagementPlanManager {
} }
} }
if(this.dataManagementProfileManager.fieldInBlueprint(newDmp.getProfile(), DmpBlueprintSystemFieldType.Grant)) { if(this.dmpBlueprintService.fieldInBlueprint(newDmp.getProfile(), DmpBlueprintSystemFieldType.Grant)) {
if (newDmp.getGrant() != null && newDmp.getGrant().getType().equals(Grant.GrantType.INTERNAL.getValue())) { if (newDmp.getGrant() != null && newDmp.getGrant().getType().equals(Grant.GrantType.INTERNAL.getValue())) {
checkIfUserCanEditGrant(newDmp, user); checkIfUserCanEditGrant(newDmp, user);
} }
assignGrandUserIfInternal(newDmp, user); assignGrandUserIfInternal(newDmp, user);
} }
if(this.dataManagementProfileManager.fieldInBlueprint(newDmp.getProfile(), DmpBlueprintSystemFieldType.Funder)) { if(this.dmpBlueprintService.fieldInBlueprint(newDmp.getProfile(), DmpBlueprintSystemFieldType.Funder)) {
assignFunderUserIfInternal(newDmp, user); assignFunderUserIfInternal(newDmp, user);
} }
if(this.dataManagementProfileManager.fieldInBlueprint(newDmp.getProfile(), DmpBlueprintSystemFieldType.Project)) { if(this.dmpBlueprintService.fieldInBlueprint(newDmp.getProfile(), DmpBlueprintSystemFieldType.Project)) {
assignProjectUserIfInternal(newDmp, user); assignProjectUserIfInternal(newDmp, user);
} }
@ -565,7 +565,7 @@ public class DataManagementPlanManager {
} }
} }
if(this.dataManagementProfileManager.fieldInBlueprint(newDmp.getProfile(), DmpBlueprintSystemFieldType.Grant)) { if(this.dmpBlueprintService.fieldInBlueprint(newDmp.getProfile(), DmpBlueprintSystemFieldType.Grant)) {
if (newDmp.getGrant() != null) { if (newDmp.getGrant() != null) {
apiContext.getOperationsContext().getDatabaseRepository().getGrantDao().createOrUpdate(newDmp.getGrant()); apiContext.getOperationsContext().getDatabaseRepository().getGrantDao().createOrUpdate(newDmp.getGrant());
} }
@ -665,16 +665,16 @@ public class DataManagementPlanManager {
checkDmpValidationRules(tempDMP); checkDmpValidationRules(tempDMP);
} }
UserInfo user = apiContext.getOperationsContext().getDatabaseRepository().getUserInfoDao().find(this.userScope.getUserId()); UserInfo user = apiContext.getOperationsContext().getDatabaseRepository().getUserInfoDao().find(this.userScope.getUserId());
if(this.dataManagementProfileManager.fieldInBlueprint(tempDMP.getProfile(), DmpBlueprintSystemFieldType.Organizations)) { if(this.dmpBlueprintService.fieldInBlueprint(tempDMP.getProfile(), DmpBlueprintSystemFieldType.Organizations)) {
createOrganisationsIfTheyDontExist(tempDMP, apiContext.getOperationsContext().getDatabaseRepository().getOrganisationDao()); createOrganisationsIfTheyDontExist(tempDMP, apiContext.getOperationsContext().getDatabaseRepository().getOrganisationDao());
} }
if(this.dataManagementProfileManager.fieldInBlueprint(tempDMP.getProfile(), DmpBlueprintSystemFieldType.Researchers)) { if(this.dmpBlueprintService.fieldInBlueprint(tempDMP.getProfile(), DmpBlueprintSystemFieldType.Researchers)) {
createResearchersIfTheyDontExist(tempDMP, apiContext.getOperationsContext().getDatabaseRepository().getResearcherDao(), user); createResearchersIfTheyDontExist(tempDMP, apiContext.getOperationsContext().getDatabaseRepository().getResearcherDao(), user);
} }
if(this.dataManagementProfileManager.fieldInBlueprint(tempDMP.getProfile(), DmpBlueprintSystemFieldType.Funder)) { if(this.dmpBlueprintService.fieldInBlueprint(tempDMP.getProfile(), DmpBlueprintSystemFieldType.Funder)) {
createFunderIfItDoesntExist(tempDMP, apiContext.getOperationsContext().getDatabaseRepository().getFunderDao()); createFunderIfItDoesntExist(tempDMP, apiContext.getOperationsContext().getDatabaseRepository().getFunderDao());
} }
if(this.dataManagementProfileManager.fieldInBlueprint(tempDMP.getProfile(), DmpBlueprintSystemFieldType.Grant)) { if(this.dmpBlueprintService.fieldInBlueprint(tempDMP.getProfile(), DmpBlueprintSystemFieldType.Grant)) {
createGrantIfItDoesntExist(tempDMP, apiContext.getOperationsContext().getDatabaseRepository().getGrantDao()); createGrantIfItDoesntExist(tempDMP, apiContext.getOperationsContext().getDatabaseRepository().getGrantDao());
} }
@ -714,18 +714,18 @@ public class DataManagementPlanManager {
newDmp.setDmpProperties(oldDmp.getDmpProperties()); newDmp.setDmpProperties(oldDmp.getDmpProperties());
UserInfo user = apiContext.getOperationsContext().getBuilderFactory().getBuilder(UserInfoBuilder.class).id(this.userScope.getUserId()).build(); UserInfo user = apiContext.getOperationsContext().getBuilderFactory().getBuilder(UserInfoBuilder.class).id(this.userScope.getUserId()).build();
newDmp.setCreator(user); newDmp.setCreator(user);
if(this.dataManagementProfileManager.fieldInBlueprint(newDmp.getProfile(), DmpBlueprintSystemFieldType.Organizations)) { if(this.dmpBlueprintService.fieldInBlueprint(newDmp.getProfile(), DmpBlueprintSystemFieldType.Organizations)) {
createOrganisationsIfTheyDontExist(newDmp, databaseRepository.getOrganisationDao()); createOrganisationsIfTheyDontExist(newDmp, databaseRepository.getOrganisationDao());
} }
if(this.dataManagementProfileManager.fieldInBlueprint(newDmp.getProfile(), DmpBlueprintSystemFieldType.Researchers)) { if(this.dmpBlueprintService.fieldInBlueprint(newDmp.getProfile(), DmpBlueprintSystemFieldType.Researchers)) {
createResearchersIfTheyDontExist(newDmp, databaseRepository.getResearcherDao(), user); createResearchersIfTheyDontExist(newDmp, databaseRepository.getResearcherDao(), user);
} }
if(this.dataManagementProfileManager.fieldInBlueprint(newDmp.getProfile(), DmpBlueprintSystemFieldType.Funder)) { if(this.dmpBlueprintService.fieldInBlueprint(newDmp.getProfile(), DmpBlueprintSystemFieldType.Funder)) {
createFunderIfItDoesntExist(newDmp, databaseRepository.getFunderDao()); createFunderIfItDoesntExist(newDmp, databaseRepository.getFunderDao());
} }
if(this.dataManagementProfileManager.fieldInBlueprint(newDmp.getProfile(), DmpBlueprintSystemFieldType.Grant)) { if(this.dmpBlueprintService.fieldInBlueprint(newDmp.getProfile(), DmpBlueprintSystemFieldType.Grant)) {
createGrantIfItDoesntExist(newDmp, databaseRepository.getGrantDao()); createGrantIfItDoesntExist(newDmp, databaseRepository.getGrantDao());
if(this.dataManagementProfileManager.fieldInBlueprint(newDmp.getProfile(), DmpBlueprintSystemFieldType.Project)) { if(this.dmpBlueprintService.fieldInBlueprint(newDmp.getProfile(), DmpBlueprintSystemFieldType.Project)) {
if (newDmp.getProject() != null && newDmp.getGrant() != null && (newDmp.getProject().getLabel() == null || newDmp.getProject().getLabel().trim().isEmpty())) { if (newDmp.getProject() != null && newDmp.getGrant() != null && (newDmp.getProject().getLabel() == null || newDmp.getProject().getLabel().trim().isEmpty())) {
newDmp.setProject(newDmp.getProject().projectFromGrant(newDmp.getGrant())); newDmp.setProject(newDmp.getProject().projectFromGrant(newDmp.getGrant()));
} }
@ -737,19 +737,19 @@ public class DataManagementPlanManager {
newDmp.setVersion(oldDmp.getVersion() + 1); newDmp.setVersion(oldDmp.getVersion() + 1);
newDmp.setId(null); newDmp.setId(null);
if(this.dataManagementProfileManager.fieldInBlueprint(newDmp.getProfile(), DmpBlueprintSystemFieldType.Grant)) { if(this.dmpBlueprintService.fieldInBlueprint(newDmp.getProfile(), DmpBlueprintSystemFieldType.Grant)) {
if (newDmp.getGrant() != null && newDmp.getGrant().getType().equals(Grant.GrantType.INTERNAL.getValue())) { if (newDmp.getGrant() != null && newDmp.getGrant().getType().equals(Grant.GrantType.INTERNAL.getValue())) {
checkIfUserCanEditGrant(newDmp, user); checkIfUserCanEditGrant(newDmp, user);
} }
assignGrandUserIfInternal(newDmp, user); assignGrandUserIfInternal(newDmp, user);
} }
if(this.dataManagementProfileManager.fieldInBlueprint(newDmp.getProfile(), DmpBlueprintSystemFieldType.Funder)) { if(this.dmpBlueprintService.fieldInBlueprint(newDmp.getProfile(), DmpBlueprintSystemFieldType.Funder)) {
assignFunderUserIfInternal(newDmp, user); assignFunderUserIfInternal(newDmp, user);
} }
if(this.dataManagementProfileManager.fieldInBlueprint(newDmp.getProfile(), DmpBlueprintSystemFieldType.Project)) { if(this.dmpBlueprintService.fieldInBlueprint(newDmp.getProfile(), DmpBlueprintSystemFieldType.Project)) {
assignProjectUserIfInternal(newDmp, user); assignProjectUserIfInternal(newDmp, user);
} }
if(this.dataManagementProfileManager.fieldInBlueprint(newDmp.getProfile(), DmpBlueprintSystemFieldType.Grant)) { if(this.dmpBlueprintService.fieldInBlueprint(newDmp.getProfile(), DmpBlueprintSystemFieldType.Grant)) {
if (newDmp.getGrant() != null) { if (newDmp.getGrant() != null) {
if (newDmp.getGrant().getStartdate() == null) { if (newDmp.getGrant().getStartdate() == null) {
newDmp.getGrant().setStartdate(new Date()); newDmp.getGrant().setStartdate(new Date());
@ -803,18 +803,18 @@ public class DataManagementPlanManager {
UserInfo user = apiContext.getOperationsContext().getBuilderFactory().getBuilder(UserInfoBuilder.class).id(this.userScope.getUserId()).build(); UserInfo user = apiContext.getOperationsContext().getBuilderFactory().getBuilder(UserInfoBuilder.class).id(this.userScope.getUserId()).build();
newDmp.setCreator(user); newDmp.setCreator(user);
if(this.dataManagementProfileManager.fieldInBlueprint(newDmp.getProfile(), DmpBlueprintSystemFieldType.Organizations)) { if(this.dmpBlueprintService.fieldInBlueprint(newDmp.getProfile(), DmpBlueprintSystemFieldType.Organizations)) {
createOrganisationsIfTheyDontExist(newDmp, databaseRepository.getOrganisationDao()); createOrganisationsIfTheyDontExist(newDmp, databaseRepository.getOrganisationDao());
} }
if(this.dataManagementProfileManager.fieldInBlueprint(newDmp.getProfile(), DmpBlueprintSystemFieldType.Researchers)) { if(this.dmpBlueprintService.fieldInBlueprint(newDmp.getProfile(), DmpBlueprintSystemFieldType.Researchers)) {
createResearchersIfTheyDontExist(newDmp, databaseRepository.getResearcherDao(), user); createResearchersIfTheyDontExist(newDmp, databaseRepository.getResearcherDao(), user);
} }
if(this.dataManagementProfileManager.fieldInBlueprint(newDmp.getProfile(), DmpBlueprintSystemFieldType.Funder)) { if(this.dmpBlueprintService.fieldInBlueprint(newDmp.getProfile(), DmpBlueprintSystemFieldType.Funder)) {
createFunderIfItDoesntExist(newDmp, databaseRepository.getFunderDao()); createFunderIfItDoesntExist(newDmp, databaseRepository.getFunderDao());
} }
if(this.dataManagementProfileManager.fieldInBlueprint(newDmp.getProfile(), DmpBlueprintSystemFieldType.Grant)) { if(this.dmpBlueprintService.fieldInBlueprint(newDmp.getProfile(), DmpBlueprintSystemFieldType.Grant)) {
createGrantIfItDoesntExist(newDmp, databaseRepository.getGrantDao()); createGrantIfItDoesntExist(newDmp, databaseRepository.getGrantDao());
if(this.dataManagementProfileManager.fieldInBlueprint(newDmp.getProfile(), DmpBlueprintSystemFieldType.Project)) { if(this.dmpBlueprintService.fieldInBlueprint(newDmp.getProfile(), DmpBlueprintSystemFieldType.Project)) {
if (newDmp.getProject() != null && newDmp.getGrant() != null && (newDmp.getProject().getLabel() == null || newDmp.getProject().getLabel().trim().isEmpty())) { if (newDmp.getProject() != null && newDmp.getGrant() != null && (newDmp.getProject().getLabel() == null || newDmp.getProject().getLabel().trim().isEmpty())) {
newDmp.setProject(newDmp.getProject().projectFromGrant(newDmp.getGrant())); newDmp.setProject(newDmp.getProject().projectFromGrant(newDmp.getGrant()));
} }
@ -826,19 +826,19 @@ public class DataManagementPlanManager {
newDmp.setVersion(0); newDmp.setVersion(0);
newDmp.setId(null); newDmp.setId(null);
if(this.dataManagementProfileManager.fieldInBlueprint(newDmp.getProfile(), DmpBlueprintSystemFieldType.Grant)) { if(this.dmpBlueprintService.fieldInBlueprint(newDmp.getProfile(), DmpBlueprintSystemFieldType.Grant)) {
if (newDmp.getGrant() != null && newDmp.getGrant().getType().equals(Grant.GrantType.INTERNAL.getValue())) { if (newDmp.getGrant() != null && newDmp.getGrant().getType().equals(Grant.GrantType.INTERNAL.getValue())) {
checkIfUserCanEditGrant(newDmp, user); checkIfUserCanEditGrant(newDmp, user);
} }
assignGrandUserIfInternal(newDmp, user); assignGrandUserIfInternal(newDmp, user);
} }
if(this.dataManagementProfileManager.fieldInBlueprint(newDmp.getProfile(), DmpBlueprintSystemFieldType.Funder)) { if(this.dmpBlueprintService.fieldInBlueprint(newDmp.getProfile(), DmpBlueprintSystemFieldType.Funder)) {
assignFunderUserIfInternal(newDmp, user); assignFunderUserIfInternal(newDmp, user);
} }
if(this.dataManagementProfileManager.fieldInBlueprint(newDmp.getProfile(), DmpBlueprintSystemFieldType.Project)) { if(this.dmpBlueprintService.fieldInBlueprint(newDmp.getProfile(), DmpBlueprintSystemFieldType.Project)) {
assignProjectUserIfInternal(newDmp, user); assignProjectUserIfInternal(newDmp, user);
} }
if(this.dataManagementProfileManager.fieldInBlueprint(newDmp.getProfile(), DmpBlueprintSystemFieldType.Grant)) { if(this.dmpBlueprintService.fieldInBlueprint(newDmp.getProfile(), DmpBlueprintSystemFieldType.Grant)) {
if (newDmp.getGrant() != null) { if (newDmp.getGrant() != null) {
databaseRepository.getGrantDao().createOrUpdate(newDmp.getGrant()); databaseRepository.getGrantDao().createOrUpdate(newDmp.getGrant());
} }
@ -1111,7 +1111,7 @@ public class DataManagementPlanManager {
datasetElastic.setStatus(dataset1.getStatus()); datasetElastic.setStatus(dataset1.getStatus());
datasetElastic.setDmp(dataset1.getDmp().getId()); datasetElastic.setDmp(dataset1.getDmp().getId());
datasetElastic.setGroup(dataset1.getDmp().getGroupId()); datasetElastic.setGroup(dataset1.getDmp().getGroupId());
if(this.dataManagementProfileManager.fieldInBlueprint(dataset1.getDmp().getProfile(), DmpBlueprintSystemFieldType.Grant)) { if(this.dmpBlueprintService.fieldInBlueprint(dataset1.getDmp().getProfile(), DmpBlueprintSystemFieldType.Grant)) {
datasetElastic.setGrant(dataset1.getDmp().getGrant().getId()); datasetElastic.setGrant(dataset1.getDmp().getGrant().getId());
} }
if (dataset1.getDmp().getUsers() != null) { if (dataset1.getDmp().getUsers() != null) {
@ -1134,7 +1134,7 @@ public class DataManagementPlanManager {
}).collect(Collectors.toList())); }).collect(Collectors.toList()));
} }
datasetElastic.setPublic(dataset1.getDmp().isPublic()); datasetElastic.setPublic(dataset1.getDmp().isPublic());
if(this.dataManagementProfileManager.fieldInBlueprint(dataset1.getDmp().getProfile(), DmpBlueprintSystemFieldType.Grant)) { if(this.dmpBlueprintService.fieldInBlueprint(dataset1.getDmp().getProfile(), DmpBlueprintSystemFieldType.Grant)) {
datasetElastic.setGrantStatus(dataset1.getDmp().getGrant().getStatus()); datasetElastic.setGrantStatus(dataset1.getDmp().getGrant().getStatus());
} }
@ -1375,9 +1375,8 @@ public class DataManagementPlanManager {
// XWPFParagraph parBreakDatasets = document.createParagraph(); // XWPFParagraph parBreakDatasets = document.createParagraph();
DmpBlueprintEntity dmpProfile = dmpEntity.getProfile(); DmpBlueprintEntity dmpProfile = dmpEntity.getProfile();
DataManagementPlanBlueprintListingModel dmpBlueprintModel = new DataManagementPlanBlueprintListingModel(); DefinitionEntity dmpBlueprint = new DefinitionEntity().fromXml(XmlBuilder.fromXml(dmpProfile.getDefinition()).getDocumentElement());
dmpBlueprintModel.fromDataModel(dmpProfile);
DefinitionEntity dmpBlueprint = dmpBlueprintModel.getDefinition();
for(SectionEntity section: dmpBlueprint.getSections()){ for(SectionEntity section: dmpBlueprint.getSections()){
wordBuilder.addParagraphContent("Section " + section.getOrdinal(), document, ParagraphStyle.HEADER1, BigInteger.ZERO, 0); wordBuilder.addParagraphContent("Section " + section.getOrdinal(), document, ParagraphStyle.HEADER1, BigInteger.ZERO, 0);
XWPFParagraph sectionInfoParagraph = document.createParagraph(); XWPFParagraph sectionInfoParagraph = document.createParagraph();
@ -1791,7 +1790,7 @@ public class DataManagementPlanManager {
// Funder. // Funder.
Element funder = xmlDoc.createElement("funder"); Element funder = xmlDoc.createElement("funder");
if (this.dataManagementProfileManager.fieldInBlueprint(dmp.getProfile(), DmpBlueprintSystemFieldType.Grant) && this.dataManagementProfileManager.fieldInBlueprint(dmp.getProfile(), DmpBlueprintSystemFieldType.Funder)) { if (this.dmpBlueprintService.fieldInBlueprint(dmp.getProfile(), DmpBlueprintSystemFieldType.Grant) && this.dmpBlueprintService.fieldInBlueprint(dmp.getProfile(), DmpBlueprintSystemFieldType.Funder)) {
Element funderLabel = xmlDoc.createElement("label"); Element funderLabel = xmlDoc.createElement("label");
Element funderId = xmlDoc.createElement("id"); Element funderId = xmlDoc.createElement("id");
funderLabel.setTextContent(dmp.getGrant().getFunder().getLabel()); funderLabel.setTextContent(dmp.getGrant().getFunder().getLabel());
@ -1809,7 +1808,7 @@ public class DataManagementPlanManager {
dmpElement.appendChild(funder); dmpElement.appendChild(funder);
// Grant. // Grant.
Element grant = xmlDoc.createElement("grant"); Element grant = xmlDoc.createElement("grant");
if (this.dataManagementProfileManager.fieldInBlueprint(dmp.getProfile(), DmpBlueprintSystemFieldType.Grant)) { if (this.dmpBlueprintService.fieldInBlueprint(dmp.getProfile(), DmpBlueprintSystemFieldType.Grant)) {
Element grantLabel = xmlDoc.createElement("label"); Element grantLabel = xmlDoc.createElement("label");
Element grantId = xmlDoc.createElement("id"); Element grantId = xmlDoc.createElement("id");
grantLabel.setTextContent(dmp.getGrant().getLabel()); grantLabel.setTextContent(dmp.getGrant().getLabel());
@ -1827,7 +1826,7 @@ public class DataManagementPlanManager {
dmpElement.appendChild(grant); dmpElement.appendChild(grant);
// Project. // Project.
Element project = xmlDoc.createElement("project"); Element project = xmlDoc.createElement("project");
if (this.dataManagementProfileManager.fieldInBlueprint(dmp.getProfile(), DmpBlueprintSystemFieldType.Project)) { if (this.dmpBlueprintService.fieldInBlueprint(dmp.getProfile(), DmpBlueprintSystemFieldType.Project)) {
Element projectId = xmlDoc.createElement("id"); Element projectId = xmlDoc.createElement("id");
Element projectLabel = xmlDoc.createElement("label"); Element projectLabel = xmlDoc.createElement("label");
Element projectDescription = xmlDoc.createElement("description"); Element projectDescription = xmlDoc.createElement("description");
@ -1874,7 +1873,9 @@ public class DataManagementPlanManager {
Element extraFields = xmlDoc.createElement("extraFields"); Element extraFields = xmlDoc.createElement("extraFields");
Map<String, Object> dmpProperties = new ObjectMapper().readValue(dmp.getProperties(), new TypeReference<Map<String, Object>>() {}); Map<String, Object> dmpProperties = new ObjectMapper().readValue(dmp.getProperties(), new TypeReference<Map<String, Object>>() {});
DefinitionEntity blueprint = this.dataManagementProfileManager.getSingleBlueprint(dmp.getProfile().getId().toString()).getDefinition();
DefinitionEntity blueprint = new DefinitionEntity().fromXml(XmlBuilder.fromXml(dmp.getProfile().getDefinition()).getDocumentElement());
blueprint.getSections().forEach(section -> { blueprint.getSections().forEach(section -> {
section.getFields().forEach(fieldModel -> { section.getFields().forEach(fieldModel -> {
if (fieldModel.getCategory() == DmpBlueprintFieldCategory.Extra) { if (fieldModel.getCategory() == DmpBlueprintFieldCategory.Extra) {
@ -2090,7 +2091,7 @@ public class DataManagementPlanManager {
} }
dm.setProperties(dmpPropertiesMap); dm.setProperties(dmpPropertiesMap);
if (this.dataManagementProfileManager.fieldInBlueprint(dmpProfileImportModel.getDmpProfileId().toString(), DmpBlueprintSystemFieldType.Funder)) { if (this.dmpBlueprintService.fieldInBlueprint(dmpProfileImportModel.getDmpProfileId(), DmpBlueprintSystemFieldType.Funder)) {
eu.eudat.models.data.funder.Funder funder = new eu.eudat.models.data.funder.Funder(); eu.eudat.models.data.funder.Funder funder = new eu.eudat.models.data.funder.Funder();
FunderImportModels funderImport = dataManagementPlans.get(0).getFunderImportModels(); FunderImportModels funderImport = dataManagementPlans.get(0).getFunderImportModels();
funder.setId(funderImport.getId()); funder.setId(funderImport.getId());
@ -2101,7 +2102,7 @@ public class DataManagementPlanManager {
dm.setFunder(funderEditor); dm.setFunder(funderEditor);
} }
if (this.dataManagementProfileManager.fieldInBlueprint(dmpProfileImportModel.getDmpProfileId().toString(), DmpBlueprintSystemFieldType.Grant)) { if (this.dmpBlueprintService.fieldInBlueprint(dmpProfileImportModel.getDmpProfileId(), DmpBlueprintSystemFieldType.Grant)) {
eu.eudat.models.data.grant.Grant grant = new eu.eudat.models.data.grant.Grant(); eu.eudat.models.data.grant.Grant grant = new eu.eudat.models.data.grant.Grant();
GrantImportModels grantImport = dataManagementPlans.get(0).getGrantImport(); GrantImportModels grantImport = dataManagementPlans.get(0).getGrantImport();
grant.setId(grantImport.getId()); grant.setId(grantImport.getId());
@ -2114,7 +2115,7 @@ public class DataManagementPlanManager {
dm.setGrant(grantEditor); dm.setGrant(grantEditor);
} }
if (this.dataManagementProfileManager.fieldInBlueprint(dmpProfileImportModel.getDmpProfileId().toString(), DmpBlueprintSystemFieldType.Project)) { if (this.dmpBlueprintService.fieldInBlueprint(dmpProfileImportModel.getDmpProfileId(), DmpBlueprintSystemFieldType.Project)) {
eu.eudat.models.data.project.Project project = new eu.eudat.models.data.project.Project(); eu.eudat.models.data.project.Project project = new eu.eudat.models.data.project.Project();
ProjectImportModels projectImport = dataManagementPlans.get(0).getProjectImportModels(); ProjectImportModels projectImport = dataManagementPlans.get(0).getProjectImportModels();
project.setId(projectImport.getId()); project.setId(projectImport.getId());

View File

@ -1,198 +0,0 @@
package eu.eudat.logic.managers;
import com.jayway.jsonpath.DocumentContext;
import com.jayway.jsonpath.JsonPath;
import eu.eudat.commons.enums.DmpBlueprintStatus;
import eu.eudat.commons.enums.IsActive;
import eu.eudat.commons.types.dmpblueprint.ExternalAutoCompleteEntity;
import eu.eudat.commons.types.dmpblueprint.FieldEntity;
import eu.eudat.commons.types.dmpblueprint.SectionEntity;
import eu.eudat.commons.types.dmpblueprint.SystemFieldEntity;
import eu.eudat.data.dao.criteria.DataManagementPlanCriteria;
import eu.eudat.data.dao.criteria.RequestItem;
import eu.eudat.data.DmpBlueprintEntity;
import eu.eudat.data.query.items.dmpblueprint.DataManagementPlanBlueprintTableRequest;
import eu.eudat.exceptions.dmpblueprint.DmpBlueprintUsedException;
import eu.eudat.logic.services.operations.DatabaseRepository;
import eu.eudat.commons.types.xml.XmlBuilder;
import eu.eudat.logic.utilities.documents.helpers.FileEnvelope;
import eu.eudat.logic.utilities.documents.xml.dmpXml.ExportXmlBuilderDmpBlueprint;
import eu.eudat.logic.utilities.documents.xml.dmpXml.ImportXmlBuilderDmpBlueprint;
import eu.eudat.commons.enums.DmpBlueprintFieldCategory;
import eu.eudat.commons.enums.DmpBlueprintSystemFieldType;
import eu.eudat.models.data.helpermodels.Tuple;
import eu.eudat.models.data.helpers.common.AutoCompleteLookupItem;
import eu.eudat.models.data.helpers.common.DataTableData;
import eu.eudat.models.data.listingmodels.DataManagementPlanBlueprintListingModel;
//import eu.eudat.models.data.listingmodels.DataManagementPlanProfileListingModel;
import eu.eudat.queryable.QueryableList;
import eu.eudat.logic.services.ApiContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;
import jakarta.activation.MimetypesFileTypeMap;
import javax.management.InvalidApplicationException;
import javax.xml.xpath.*;
import java.io.*;
import java.nio.file.Files;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import org.springframework.http.*;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.multipart.MultipartFile;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
/**
* Created by ikalyvas on 3/21/2018.
*/
@Component
public class DataManagementProfileManager {
private static final Logger logger = LoggerFactory.getLogger(DataManagementProfileManager.class);
private ApiContext apiContext;
private DatabaseRepository databaseRepository;
private Environment environment;
@Autowired
public DataManagementProfileManager(ApiContext apiContext, Environment environment) {
this.apiContext = apiContext;
this.databaseRepository = apiContext.getOperationsContext().getDatabaseRepository();
this.environment = environment;
}
public DataTableData<DataManagementPlanBlueprintListingModel> getPagedBlueprint(DataManagementPlanBlueprintTableRequest dataManagementPlanBlueprintTableRequest) throws Exception {
QueryableList<DmpBlueprintEntity> items = apiContext.getOperationsContext().getDatabaseRepository().getDmpProfileDao().getWithCriteriaBlueprint(dataManagementPlanBlueprintTableRequest.getCriteria());
QueryableList<DmpBlueprintEntity> pagedItems = PaginationManager.applyPaging(items, dataManagementPlanBlueprintTableRequest);
DataTableData<DataManagementPlanBlueprintListingModel> dataTable = new DataTableData<>();
CompletableFuture itemsFuture = pagedItems
.selectAsync(item -> new DataManagementPlanBlueprintListingModel().fromDataModel(item)).whenComplete((resultList, throwable) -> dataTable.setData(resultList));
CompletableFuture countFuture = items.countAsync().whenComplete((count, throwable) -> dataTable.setTotalCount(count));
CompletableFuture.allOf(itemsFuture, countFuture).join();
return dataTable;
}
public DataManagementPlanBlueprintListingModel getSingleBlueprint(String id) throws InvalidApplicationException {
DmpBlueprintEntity dmpBlueprint = databaseRepository.getDmpProfileDao().find(UUID.fromString(id));
DataManagementPlanBlueprintListingModel dataManagementPlanBlueprintListingModel = new DataManagementPlanBlueprintListingModel();
dataManagementPlanBlueprintListingModel.fromDataModel(dmpBlueprint);
return dataManagementPlanBlueprintListingModel;
}
public boolean fieldInBlueprint(String id, DmpBlueprintSystemFieldType type) throws InvalidApplicationException {
DmpBlueprintEntity dmpBlueprint = databaseRepository.getDmpProfileDao().find(UUID.fromString(id));
return this.fieldInBlueprint(dmpBlueprint, type);
}
public boolean fieldInBlueprint(DmpBlueprintEntity dmpProfile, DmpBlueprintSystemFieldType type) {
DataManagementPlanBlueprintListingModel dmpBlueprint = new DataManagementPlanBlueprintListingModel();
dmpBlueprint.fromDataModel(dmpProfile);
for(SectionEntity section: dmpBlueprint.getDefinition().getSections()){
for(FieldEntity field: section.getFields()){
if(field.getCategory().equals(DmpBlueprintFieldCategory.System)){
SystemFieldEntity systemField = (SystemFieldEntity)field;
if(systemField.getType().equals(type)){
return true;
}
}
}
}
return false;
}
public void createOrUpdateBlueprint(DataManagementPlanBlueprintListingModel dataManagementPlanBlueprintListingModel) throws Exception {
DmpBlueprintEntity dmpBlueprint = dataManagementPlanBlueprintListingModel.toDataModel();
apiContext.getOperationsContext().getDatabaseRepository().getDmpProfileDao().createOrUpdate(dmpBlueprint);
}
public void inactivate(String id) throws InvalidApplicationException {
DmpBlueprintEntity dmpBlueprint = databaseRepository.getDmpProfileDao().find(UUID.fromString(id));
DataManagementPlanCriteria dataManagementPlanCriteria = new DataManagementPlanCriteria();
dataManagementPlanCriteria.setProfile(dmpBlueprint);
if (DmpBlueprintStatus.Draft.equals(dmpBlueprint.getStatus()) || databaseRepository.getDmpDao().getWithCriteria(dataManagementPlanCriteria).count() == 0) {
dmpBlueprint.setIsActive(IsActive.Inactive);
databaseRepository.getDmpProfileDao().createOrUpdate(dmpBlueprint);
} else {
throw new DmpBlueprintUsedException("This blueprint can not deleted, because DMPs are associated with it");
}
}
public ResponseEntity<byte[]> getDocument(DataManagementPlanBlueprintListingModel dmpProfile) throws IOException {
FileEnvelope envelope = getXmlDocument(dmpProfile);
InputStream resource = new FileInputStream(envelope.getFile());
logger.info("Mime Type of " + envelope.getFilename() + " is " +
new MimetypesFileTypeMap().getContentType(envelope.getFile()));
HttpHeaders responseHeaders = new HttpHeaders();
responseHeaders.setContentLength(envelope.getFile().length());
responseHeaders.setContentType(MediaType.APPLICATION_OCTET_STREAM);
String fileName = envelope.getFilename().replace(" ", "_").replace(",", "_");
responseHeaders.set("Content-Disposition", "attachment;filename=" + fileName + ".xml");
responseHeaders.set("Access-Control-Expose-Headers", "Content-Disposition");
responseHeaders.get("Access-Control-Expose-Headers").add("Content-Type");
byte[] content = org.apache.poi.util.IOUtils.toByteArray(resource);
resource.close();
Files.deleteIfExists(envelope.getFile().toPath());
return new ResponseEntity<>(content,
responseHeaders,
HttpStatus.OK);
}
public FileEnvelope getXmlDocument(DataManagementPlanBlueprintListingModel dmpProfile) throws IOException {
ExportXmlBuilderDmpBlueprint xmlBuilder = new ExportXmlBuilderDmpBlueprint();
File file = xmlBuilder.build(dmpProfile, environment);
FileEnvelope fileEnvelope = new FileEnvelope();
fileEnvelope.setFile(file);
fileEnvelope.setFilename(dmpProfile.getLabel());
return fileEnvelope;
}
public eu.eudat.logic.utilities.documents.xml.dmpXml.dmpBlueprintModel.DmpBlueprint createDmpProfileFromXml(MultipartFile multiPartFile) {
ImportXmlBuilderDmpBlueprint xmlBuilder = new ImportXmlBuilderDmpBlueprint();
try {
return xmlBuilder.build(convert(multiPartFile));
} catch (IOException e) {
logger.error(e.getMessage(), e);
}
return null;
}
private File convert(MultipartFile file) throws IOException {
File convFile = new File(this.environment.getProperty("temp.temp") + file.getOriginalFilename());
convFile.createNewFile();
FileOutputStream fos = new FileOutputStream(convFile);
fos.write(file.getBytes());
fos.close();
return convFile;
}
public static List<Tuple<String, String>> externalAutocompleteRequest(String url, String optionsRoot, String label, String value, String like) {
List<Tuple<String, String>> result = new LinkedList<>();
RestTemplate restTemplate = new RestTemplate();
HttpHeaders headers = new HttpHeaders();
headers.setAccept(Collections.singletonList(MediaType.valueOf("application/vnd.api+json; charset=utf-8")));
headers.setContentType(MediaType.APPLICATION_JSON);
HttpEntity<String> entity = new HttpEntity<>("parameters", headers);
ResponseEntity<Object> response = restTemplate.exchange(url + "?search=" + like, HttpMethod.GET, entity, Object.class);
DocumentContext jsonContext = JsonPath.parse(response.getBody());
List<Map<String, String>> jsonItems = jsonContext.read(optionsRoot + "['" + label + "','" + value + "']");
jsonItems.forEach(item -> result.add(new Tuple<>(item.get(value), item.get(label))));
return result;
}
}

View File

@ -4,7 +4,8 @@ import eu.eudat.commons.types.dmpblueprint.DefinitionEntity;
import eu.eudat.commons.types.xml.XmlBuilder; import eu.eudat.commons.types.xml.XmlBuilder;
import eu.eudat.commons.types.dmpblueprint.SectionEntity; import eu.eudat.commons.types.dmpblueprint.SectionEntity;
import eu.eudat.models.data.listingmodels.DataManagementPlanBlueprintListingModel; import eu.eudat.data.DmpBlueprintEntity;
import eu.eudat.model.DmpBlueprint;
import org.springframework.core.env.Environment; import org.springframework.core.env.Environment;
import org.w3c.dom.Document; import org.w3c.dom.Document;
import org.w3c.dom.Element; import org.w3c.dom.Element;
@ -18,7 +19,7 @@ import java.util.UUID;
public class ExportXmlBuilderDmpBlueprint { public class ExportXmlBuilderDmpBlueprint {
public File build(DataManagementPlanBlueprintListingModel dmpProfile, Environment environment) throws IOException { public File build(DmpBlueprintEntity dmpProfile, Environment environment) throws IOException {
File xmlFile = new File(environment.getProperty("temp.temp") + UUID.randomUUID() + ".xml"); File xmlFile = new File(environment.getProperty("temp.temp") + UUID.randomUUID() + ".xml");
BufferedWriter writer = new BufferedWriter(new FileWriter(xmlFile, true)); BufferedWriter writer = new BufferedWriter(new FileWriter(xmlFile, true));
@ -26,7 +27,7 @@ public class ExportXmlBuilderDmpBlueprint {
Element root = xmlDoc.createElement("root"); Element root = xmlDoc.createElement("root");
Element definition = xmlDoc.createElement("definition"); Element definition = xmlDoc.createElement("definition");
// Element root = xmlDoc.createElement(dmpProfile.getLabel()); // Element root = xmlDoc.createElement(dmpProfile.getLabel());
definition.appendChild(createDefinition(dmpProfile.getDefinition(), xmlDoc)); definition.appendChild(createDefinition(new DefinitionEntity().fromXml(XmlBuilder.fromXml(dmpProfile.getDefinition()).getDocumentElement()), xmlDoc));
root.appendChild(definition); root.appendChild(definition);
xmlDoc.appendChild(root); xmlDoc.appendChild(root);
String xml = XmlBuilder.generateXml(xmlDoc); String xml = XmlBuilder.generateXml(xmlDoc);

View File

@ -14,17 +14,17 @@ public class ImportXmlBuilderDmpBlueprint {
private static final Logger logger = LoggerFactory.getLogger(ImportXmlBuilderDmpBlueprint.class); private static final Logger logger = LoggerFactory.getLogger(ImportXmlBuilderDmpBlueprint.class);
public DmpBlueprint build(File xmlFile) throws IOException { public DmpBlueprint build(File xmlFile) throws IOException {
DmpBlueprint dmpProfile = new DmpBlueprint(); DmpBlueprint dmpBlueprint = new DmpBlueprint();
JAXBContext jaxbContext = null; JAXBContext jaxbContext = null;
try { try {
jaxbContext = JAXBContext.newInstance(DmpBlueprint.class); jaxbContext = JAXBContext.newInstance(DmpBlueprint.class);
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
dmpProfile = (DmpBlueprint) unmarshaller.unmarshal(xmlFile); dmpBlueprint = (DmpBlueprint) unmarshaller.unmarshal(xmlFile);
} catch (JAXBException e) { } catch (JAXBException e) {
logger.error(e.getMessage(), e); logger.error(e.getMessage(), e);
} }
return dmpProfile; return dmpBlueprint;
} }
} }

View File

@ -1,10 +1,13 @@
package eu.eudat.logic.utilities.documents.xml.dmpXml.dmpBlueprintModel; package eu.eudat.logic.utilities.documents.xml.dmpXml.dmpBlueprintModel;
import eu.eudat.commons.enums.DmpBlueprintStatus; import eu.eudat.commons.enums.DmpBlueprintStatus;
import eu.eudat.commons.types.xml.XmlBuilder;
import eu.eudat.data.DmpBlueprintEntity; import eu.eudat.data.DmpBlueprintEntity;
import jakarta.xml.bind.annotation.XmlElement; import jakarta.xml.bind.annotation.XmlElement;
import jakarta.xml.bind.annotation.XmlRootElement; import jakarta.xml.bind.annotation.XmlRootElement;
import org.w3c.dom.Document;
import javax.management.InvalidApplicationException;
import java.time.Instant; import java.time.Instant;
import java.util.Date; import java.util.Date;
@ -22,14 +25,16 @@ public class DmpBlueprint {
this.dmpBlueprintDefinition = dmpBlueprintDefinition; this.dmpBlueprintDefinition = dmpBlueprintDefinition;
} }
public eu.eudat.models.data.listingmodels.DataManagementPlanBlueprintListingModel toDmpProfileCompositeModel(String label) { public DmpBlueprintEntity toDmpProfileCompositeModel(String label) {
eu.eudat.models.data.listingmodels.DataManagementPlanBlueprintListingModel dmpProfileModel = new eu.eudat.models.data.listingmodels.DataManagementPlanBlueprintListingModel(); DmpBlueprintEntity dmpProfileModel = new DmpBlueprintEntity();
dmpProfileModel.setLabel(label); dmpProfileModel.setLabel(label);
dmpProfileModel.setStatus(DmpBlueprintStatus.Draft); dmpProfileModel.setStatus(DmpBlueprintStatus.Draft);
dmpProfileModel.setCreated(Instant.now()); dmpProfileModel.setCreatedAt(Instant.now());
dmpProfileModel.setModified(Instant.now()); dmpProfileModel.setUpdatedAt(Instant.now());
if (this.dmpBlueprintDefinition != null) { if (this.dmpBlueprintDefinition != null) {
dmpProfileModel.setDefinition(this.dmpBlueprintDefinition.toDmpBlueprintCompositeModel()); Document document = XmlBuilder.getDocument();
document.appendChild(this.dmpBlueprintDefinition.toDmpBlueprintCompositeModel().toXml(document));
dmpProfileModel.setDefinition(XmlBuilder.generateXml(document));
} }
return dmpProfileModel; return dmpProfileModel;
} }

View File

@ -1,97 +0,0 @@
package eu.eudat.models.data.listingmodels;
import eu.eudat.commons.enums.DmpBlueprintStatus;
import eu.eudat.commons.types.dmpblueprint.DefinitionEntity;
import eu.eudat.data.DmpBlueprintEntity;
import eu.eudat.commons.types.xml.XmlBuilder;
import eu.eudat.models.DataModel;
import org.w3c.dom.Document;
import java.time.Instant;
import java.util.UUID;
public class DataManagementPlanBlueprintListingModel implements DataModel<DmpBlueprintEntity, DataManagementPlanBlueprintListingModel> {
private UUID id;
private String label;
private DefinitionEntity definition;
private DmpBlueprintStatus status;
private Instant created = null;
private Instant modified = Instant.now();
public UUID getId() {
return id;
}
public void setId(UUID id) {
this.id = id;
}
public String getLabel() {
return label;
}
public void setLabel(String label) {
this.label = label;
}
public DefinitionEntity getDefinition() {
return definition;
}
public void setDefinition(DefinitionEntity definition) {
this.definition = definition;
}
public DmpBlueprintStatus getStatus() {
return status;
}
public void setStatus(DmpBlueprintStatus status) {
this.status = status;
}
public Instant getCreated() {
return created;
}
public void setCreated(Instant created) {
this.created = created;
}
public Instant getModified() {
return modified;
}
public void setModified(Instant modified) {
this.modified = modified;
}
@Override
public DataManagementPlanBlueprintListingModel fromDataModel(DmpBlueprintEntity entity) {
this.id = entity.getId();
this.created = entity.getCreatedAt();
this.definition = new DefinitionEntity().fromXml(XmlBuilder.fromXml(entity.getDefinition()).getDocumentElement());
this.modified = entity.getUpdatedAt();
this.label = entity.getLabel();
this.status = entity.getStatus();
return this;
}
@Override
public DmpBlueprintEntity toDataModel() throws Exception {
Document document = XmlBuilder.getDocument();
document.appendChild(this.definition.toXml(document));
DmpBlueprintEntity dmpBlueprint = new DmpBlueprintEntity();
dmpBlueprint.setCreatedAt(this.created == null ? Instant.now() : this.created);
dmpBlueprint.setDefinition(XmlBuilder.generateXml(document));
dmpBlueprint.setId(this.id);
dmpBlueprint.setLabel(this.label);
dmpBlueprint.setStatus(this.status);
dmpBlueprint.setUpdatedAt(this.modified == null ? Instant.now() : this.modified);
return dmpBlueprint;
}
@Override
public String getHint() {
return null;
}
}