Adding clone dmp persist model, exposing new version and clone methods to the API

This commit is contained in:
Thomas Georgios Giannos 2023-11-09 14:10:32 +02:00
parent 41fc3407eb
commit 009dad8cba
8 changed files with 134 additions and 7 deletions

View File

@ -31,6 +31,8 @@ public class AuditableAction {
public static final EventId Dmp_Lookup = new EventId(5001, "Dmp_Lookup"); public static final EventId Dmp_Lookup = new EventId(5001, "Dmp_Lookup");
public static final EventId Dmp_Persist = new EventId(5002, "Dmp_Persist"); public static final EventId Dmp_Persist = new EventId(5002, "Dmp_Persist");
public static final EventId Dmp_Delete = new EventId(5003, "Dmp_Delete"); public static final EventId Dmp_Delete = new EventId(5003, "Dmp_Delete");
public static final EventId Dmp_Clone = new EventId(5004, "Dmp_Clone");
public static final EventId Dmp_PersistNewVersion = new EventId(5005, "Dmp_PersistNewVersion");
public static final EventId Description_Query = new EventId(6000, "Description_Query"); public static final EventId Description_Query = new EventId(6000, "Description_Query");
public static final EventId Description_Lookup = new EventId(6001, "Description_Lookup"); public static final EventId Description_Lookup = new EventId(6001, "Description_Lookup");

View File

@ -50,6 +50,7 @@ public final class Permission {
public static String BrowseDmp = "BrowseDmp"; public static String BrowseDmp = "BrowseDmp";
public static String EditDmp = "EditDmp"; public static String EditDmp = "EditDmp";
public static String DeleteDmp = "DeleteDmp"; public static String DeleteDmp = "DeleteDmp";
public static String CloneDmp = "CloneDmp";
public static String CreateNewVersionDmp = "CreateNewVersionDmp"; public static String CreateNewVersionDmp = "CreateNewVersionDmp";
//DmpBlueprint //DmpBlueprint

View File

@ -0,0 +1,59 @@
package eu.eudat.model.persist;
import eu.eudat.commons.validation.ValidId;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import org.apache.commons.compress.utils.Lists;
import java.util.List;
import java.util.UUID;
public class CloneDmpPersist {
@NotNull(message = "{validation.empty}")
@ValidId(message = "{validation.invalidid}")
private UUID id = null;
@NotNull(message = "{validation.empty}")
@NotEmpty(message = "{validation.empty}")
private String label = null;
@NotNull(message = "{validation.empty}")
@NotEmpty(message = "{validation.empty}")
private String description = null;
@NotNull(message = "{validation.empty}")
private List<UUID> descriptions = Lists.newArrayList();
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 String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public List<UUID> getDescriptions() {
return descriptions;
}
public void setDescriptions(List<UUID> descriptions) {
this.descriptions = descriptions;
}
}

View File

@ -25,7 +25,11 @@ public class NewVersionDmpPersist {
private String description = null; private String description = null;
@NotNull(message = "{validation.empty}") @NotNull(message = "{validation.empty}")
private List<UUID> descriptionTemplates = Lists.newArrayList(); @ValidId(message = "{validation.invalidid}")
private UUID blueprintId = null;
@NotNull(message = "{validation.empty}")
private List<UUID> descriptions = Lists.newArrayList();
private String hash; private String hash;
@ -53,12 +57,20 @@ public class NewVersionDmpPersist {
this.description = description; this.description = description;
} }
public List<UUID> getDescriptionTemplates() { public UUID getBlueprintId() {
return descriptionTemplates; return blueprintId;
} }
public void setDescriptionTemplates(List<UUID> descriptionTemplates) { public void setBlueprintId(UUID blueprintId) {
this.descriptionTemplates = descriptionTemplates; this.blueprintId = blueprintId;
}
public List<UUID> getDescriptions() {
return descriptions;
}
public void setDescriptions(List<UUID> descriptions) {
this.descriptions = descriptions;
} }
public String getHash() { public String getHash() {
@ -68,4 +80,5 @@ public class NewVersionDmpPersist {
public void setHash(String hash) { public void setHash(String hash) {
this.hash = hash; this.hash = hash;
} }
} }

View File

@ -1,10 +1,9 @@
package eu.eudat.service.dmp; package eu.eudat.service.dmp;
import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.JsonProcessingException;
import eu.eudat.model.DescriptionTemplate;
import eu.eudat.model.Dmp; import eu.eudat.model.Dmp;
import eu.eudat.model.persist.CloneDmpPersist;
import eu.eudat.model.persist.DmpPersist; import eu.eudat.model.persist.DmpPersist;
import eu.eudat.model.persist.NewVersionDescriptionTemplatePersist;
import eu.eudat.model.persist.NewVersionDmpPersist; import eu.eudat.model.persist.NewVersionDmpPersist;
import gr.cite.tools.exception.MyApplicationException; import gr.cite.tools.exception.MyApplicationException;
import gr.cite.tools.exception.MyForbiddenException; import gr.cite.tools.exception.MyForbiddenException;
@ -26,4 +25,6 @@ public interface DmpService {
Dmp createNewVersion(NewVersionDmpPersist model, FieldSet fields) throws MyForbiddenException, MyValidationException, MyApplicationException, MyNotFoundException, InvalidApplicationException, JAXBException, ParserConfigurationException, JsonProcessingException, TransformerException; Dmp createNewVersion(NewVersionDmpPersist model, FieldSet fields) throws MyForbiddenException, MyValidationException, MyApplicationException, MyNotFoundException, InvalidApplicationException, JAXBException, ParserConfigurationException, JsonProcessingException, TransformerException;
Dmp buildClone(CloneDmpPersist model, FieldSet fields) throws MyForbiddenException, MyValidationException, MyApplicationException, MyNotFoundException;
} }

View File

@ -208,6 +208,15 @@ public class DmpServiceImpl implements DmpService {
return this.builderFactory.builder(DmpBuilder.class).authorize(AuthorizationFlags.OwnerOrPermissionOrMemberOrPublic).build(BaseFieldSet.build(fields, Dmp._id), data); return this.builderFactory.builder(DmpBuilder.class).authorize(AuthorizationFlags.OwnerOrPermissionOrMemberOrPublic).build(BaseFieldSet.build(fields, Dmp._id), data);
} }
@Override
public Dmp buildClone(CloneDmpPersist model, FieldSet fields) throws MyForbiddenException, MyValidationException, MyApplicationException, MyNotFoundException {
logger.debug(new MapLogEntry("cloning dmp").And("model", model).And("fields", fields));
this.authorizationService.authorizeForce(Permission.CloneDmp);
return null;
}
private DmpEntity patchAndSave(DmpPersist model) throws JsonProcessingException { private DmpEntity patchAndSave(DmpPersist model) throws JsonProcessingException {
Boolean isUpdate = this.conventionService.isValidGuid(model.getId()); Boolean isUpdate = this.conventionService.isValidGuid(model.getId());

View File

@ -7,7 +7,9 @@ import eu.eudat.data.DmpEntity;
import eu.eudat.model.Dmp; import eu.eudat.model.Dmp;
import eu.eudat.model.builder.DmpBuilder; import eu.eudat.model.builder.DmpBuilder;
import eu.eudat.model.censorship.DmpCensor; import eu.eudat.model.censorship.DmpCensor;
import eu.eudat.model.persist.CloneDmpPersist;
import eu.eudat.model.persist.DmpPersist; import eu.eudat.model.persist.DmpPersist;
import eu.eudat.model.persist.NewVersionDmpPersist;
import eu.eudat.model.result.QueryResult; import eu.eudat.model.result.QueryResult;
import eu.eudat.query.DmpQuery; import eu.eudat.query.DmpQuery;
import eu.eudat.query.lookup.DmpLookup; import eu.eudat.query.lookup.DmpLookup;
@ -23,6 +25,7 @@ import gr.cite.tools.fieldset.FieldSet;
import gr.cite.tools.logging.LoggerService; import gr.cite.tools.logging.LoggerService;
import gr.cite.tools.logging.MapLogEntry; import gr.cite.tools.logging.MapLogEntry;
import gr.cite.tools.validation.MyValidate; import gr.cite.tools.validation.MyValidate;
import jakarta.xml.bind.JAXBException;
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;
@ -30,6 +33,8 @@ import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.management.InvalidApplicationException; import javax.management.InvalidApplicationException;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.TransformerException;
import java.util.*; import java.util.*;
@RestController @RestController
@ -125,4 +130,34 @@ public class DmpController {
this.auditService.track(AuditableAction.Dmp_Delete, "id", id); this.auditService.track(AuditableAction.Dmp_Delete, "id", id);
} }
@PostMapping("clone")
public Dmp buildClone(@MyValidate @RequestBody CloneDmpPersist persist, FieldSet fieldSet) throws MyApplicationException, MyForbiddenException, MyNotFoundException {
logger.debug(new MapLogEntry("clone" + Dmp.class.getSimpleName()).And("model", persist).And("fields", fieldSet));
this.censorFactory.censor(DmpCensor.class).censor(fieldSet, null);
Dmp model = this.dmpService.buildClone(persist, fieldSet);
this.auditService.track(AuditableAction.Dmp_Clone, Map.ofEntries(
new AbstractMap.SimpleEntry<String, Object>("model", persist),
new AbstractMap.SimpleEntry<String, Object>("fields", fieldSet)
));
return model;
}
@PostMapping("new-version")
@Transactional
public Dmp createNewVersion(@MyValidate @RequestBody NewVersionDmpPersist model, FieldSet fieldSet) throws MyApplicationException, MyForbiddenException, MyNotFoundException, JAXBException, JsonProcessingException, TransformerException, InvalidApplicationException, ParserConfigurationException {
logger.debug(new MapLogEntry("persisting" + NewVersionDmpPersist.class.getSimpleName()).And("model", model).And("fieldSet", fieldSet));
Dmp persisted = this.dmpService.createNewVersion(model, fieldSet);
this.auditService.track(AuditableAction.Dmp_PersistNewVersion, Map.ofEntries(
new AbstractMap.SimpleEntry<String, Object>("model", model),
new AbstractMap.SimpleEntry<String, Object>("fields", fieldSet)
));
return persisted;
}
} }

View File

@ -242,6 +242,13 @@ permissions:
clients: [ ] clients: [ ]
allowAnonymous: false allowAnonymous: false
allowAuthenticated: false allowAuthenticated: false
CloneDmp:
roles:
- Admin
claims: [ ]
clients: [ ]
allowAnonymous: false
allowAuthenticated: false
CreateNewVersionDmp: CreateNewVersionDmp:
roles: roles:
- Admin - Admin