add ExternalReference, DmpExternalReference entities

This commit is contained in:
amentis 2023-10-24 18:47:13 +03:00
parent a68ddd42ce
commit bf8edfad92
19 changed files with 1488 additions and 0 deletions

View File

@ -62,4 +62,15 @@ public final class Permission {
public static String ViewDescriptionTemplateTypePage = "ViewDescriptionTemplateTypePage"; public static String ViewDescriptionTemplateTypePage = "ViewDescriptionTemplateTypePage";
public static String ViewDmpBlueprintPage = "ViewDmpBlueprintPage"; public static String ViewDmpBlueprintPage = "ViewDmpBlueprintPage";
//ExternalReference
public static String BrowseExternalReference = "BrowseExternalReference";
public static String EditExternalReference = "EditExternalReference";
public static String DeleteExternalReference = "DeleteExternalReference";
//DmpExternalReference
public static String BrowseDmpExternalReference = "BrowseDmpExternalReference";
public static String EditDmpExternalReference = "EditDmpExternalReference";
public static String DeleteDmpExternalReference = "DeleteDmpExternalReference";
} }

View File

@ -0,0 +1,28 @@
package eu.eudat.commons.enums;
import eu.eudat.data.converters.enums.DatabaseEnum;
import java.util.Map;
public enum SourceType implements DatabaseEnum<Short> {
Internal((short) 0),
External((short) 1);
private final Short value;
SourceType(Short value) {
this.value = value;
}
@Override
public Short getValue() {
return value;
}
private static final Map<Short, SourceType> map = EnumUtils.getEnumValueMap(SourceType.class);
public static SourceType of(Short i) {
return map.get(i);
}
}

View File

@ -0,0 +1,62 @@
package eu.eudat.data;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import java.util.UUID;
@Entity
@Table(name = "\"ExternalReference\"")
public class DmpExternalReferenceEntity {
@Id
@Column(name = "id", columnDefinition = "uuid", updatable = false, nullable = false)
private UUID id;
public static final String _id = "id";
@Column(name = "dmp_id", columnDefinition = "uuid", nullable = false)
private UUID dmpId;
public static final String _dmpId = "dmpId";
@Column(name = "reference_id", columnDefinition = "uuid", nullable = false)
private UUID referenceId;
public static final String _referenceId = "referenceId";
@Column(name = "data")
private String data;
public static final String _data = "data";
public UUID getId() {
return id;
}
public void setId(UUID id) {
this.id = id;
}
public UUID getDmpId() {
return dmpId;
}
public void setDmpId(UUID dmpId) {
this.dmpId = dmpId;
}
public UUID getReferenceId() {
return referenceId;
}
public void setReferenceId(UUID referenceId) {
this.referenceId = referenceId;
}
public String getData() {
return data;
}
public void setData(String data) {
this.data = data;
}
}

View File

@ -0,0 +1,177 @@
package eu.eudat.data;
import eu.eudat.commons.enums.ExternalReferencesType;
import eu.eudat.commons.enums.IsActive;
import eu.eudat.commons.enums.SourceType;
import eu.eudat.data.converters.enums.ExternalReferencesTypeConverter;
import eu.eudat.data.converters.enums.IsActiveConverter;
import jakarta.persistence.*;
import org.hibernate.annotations.Type;
import java.time.Instant;
import java.util.UUID;
@Entity
@Table(name = "\"ExternalReference\"")
public class ExternalReferenceEntity {
@Id
@Column(name = "id", columnDefinition = "uuid", updatable = false, nullable = false)
private UUID id;
public static final String _id = "id";
@Column(name = "label", length = 500, nullable = false)
private String label;
public static final String _label = "label";
@Column(name = "type", nullable = false)
@Convert(converter = ExternalReferencesTypeConverter.class)
private ExternalReferencesType type;
public static final String _type = "type";
@Column(name = "description")
private String description;
public static final String _description = "description";
@Type(eu.eudat.configurations.typedefinition.XMLType.class)
@Column(name = "definition", columnDefinition = "xml")
private String definition;
public static final String _definition = "definition";
@Column(name = "reference", length = 1024, nullable = false)
private String reference;
public static final String _reference = "reference";
@Column(name = "abbreviation", length = 50)
private String abbreviation;
public static final String _abbreviation = "abbreviation";
@Column(name = "source", length = 1024)
private String source;
public static final String _source = "source";
@Column(name = "source_type", nullable = false)
private SourceType sourceType;
public static final String _sourceType = "sourceType";
@Column(name = "is_active", nullable = false)
@Convert(converter = IsActiveConverter.class)
private IsActive isActive;
public static final String _isActive = "isActive";
@Column(name = "created_at", nullable = false)
private Instant createdAt;
public static final String _createdAt = "createdAt";
@Column(name = "updated_at", nullable = false)
private Instant updatedAt;
public static final String _updatedAt = "updatedAt";
@Column(name = "created_by", columnDefinition = "uuid")
private UUID createdBy;
public static final String _createdBy = "createdBy";
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 ExternalReferencesType getType() {
return type;
}
public void setType(ExternalReferencesType type) {
this.type = type;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getDefinition() {
return definition;
}
public void setDefinition(String definition) {
this.definition = definition;
}
public String getReference() {
return reference;
}
public void setReference(String reference) {
this.reference = reference;
}
public String getAbbreviation() {
return abbreviation;
}
public void setAbbreviation(String abbreviation) {
this.abbreviation = abbreviation;
}
public String getSource() {
return source;
}
public void setSource(String source) {
this.source = source;
}
public SourceType getSourceType() {
return sourceType;
}
public void setSourceType(SourceType sourceType) {
this.sourceType = sourceType;
}
public IsActive getIsActive() {
return isActive;
}
public void setIsActive(IsActive isActive) {
this.isActive = isActive;
}
public Instant getCreatedAt() {
return createdAt;
}
public void setCreatedAt(Instant createdAt) {
this.createdAt = createdAt;
}
public Instant getUpdatedAt() {
return updatedAt;
}
public void setUpdatedAt(Instant updatedAt) {
this.updatedAt = updatedAt;
}
public UUID getCreatedBy() {
return createdBy;
}
public void setCreatedBy(UUID createdBy) {
this.createdBy = createdBy;
}
}

View File

@ -0,0 +1,11 @@
package eu.eudat.data.converters.enums;
import eu.eudat.commons.enums.ExternalReferencesType;
import jakarta.persistence.Converter;
@Converter
public class ExternalReferencesTypeConverter extends DatabaseEnumConverter<ExternalReferencesType, Short> {
public ExternalReferencesType of(Short i) {
return ExternalReferencesType.of(i);
}
}

View File

@ -0,0 +1,11 @@
package eu.eudat.data.converters.enums;
import eu.eudat.commons.enums.SourceType;
import jakarta.persistence.Converter;
@Converter
public class SourceTypeConverter extends DatabaseEnumConverter<SourceType, Short>{
public SourceType of(Short i) {
return SourceType.of(i);
}
}

View File

@ -0,0 +1,50 @@
package eu.eudat.model;
import java.util.UUID;
public class DmpExternalReference {
private UUID id;
public static final String _id = "id";
private DmpBlueprint dmp;
public static final String _dmp = "dmp";
private ExternalReference externalReference;
public static final String _externalReference = "externalReference";
private String data;
public static final String _data = "data";
public UUID getId() {
return id;
}
public void setId(UUID id) {
this.id = id;
}
public DmpBlueprint getDmp() {
return dmp;
}
public void setDmp(DmpBlueprint dmp) {
this.dmp = dmp;
}
public ExternalReference getExternalReference() {
return externalReference;
}
public void setExternalReference(ExternalReference externalReference) {
this.externalReference = externalReference;
}
public String getData() {
return data;
}
public void setData(String data) {
this.data = data;
}
}

View File

@ -0,0 +1,147 @@
package eu.eudat.model;
import eu.eudat.commons.enums.ExternalReferencesType;
import eu.eudat.commons.enums.IsActive;
import eu.eudat.commons.enums.SourceType;
import java.time.Instant;
import java.util.UUID;
public class ExternalReference {
private UUID id;
public static final String _id = "id";
private String label;
public static final String _label = "label";
private ExternalReferencesType type;
public static final String _type = "type";
private String description;
public static final String _description = "description";
private String definition;
public static final String _definition = "definition";
private String reference;
public static final String _reference = "reference";
private String abbreviation;
public static final String _abbreviation = "abbreviation";
private String source;
public static final String _source = "source";
private SourceType sourceType;
public static final String _sourceType = "sourceType";
private IsActive isActive;
public static final String _isActive = "isActive";
private Instant createdAt;
public static final String _createdAt = "createdAt";
private Instant updatedAt;
public static final String _updatedAt = "updatedAt";
//private UserInfo createdBy; ToDo
//public static final String _createdBy = "createdBy";
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 ExternalReferencesType getType() {
return type;
}
public void setType(ExternalReferencesType type) {
this.type = type;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getDefinition() {
return definition;
}
public void setDefinition(String definition) {
this.definition = definition;
}
public String getReference() {
return reference;
}
public void setReference(String reference) {
this.reference = reference;
}
public String getAbbreviation() {
return abbreviation;
}
public void setAbbreviation(String abbreviation) {
this.abbreviation = abbreviation;
}
public String getSource() {
return source;
}
public void setSource(String source) {
this.source = source;
}
public SourceType getSourceType() {
return sourceType;
}
public void setSourceType(SourceType sourceType) {
this.sourceType = sourceType;
}
public IsActive getIsActive() {
return isActive;
}
public void setIsActive(IsActive isActive) {
this.isActive = isActive;
}
public Instant getCreatedAt() {
return createdAt;
}
public void setCreatedAt(Instant createdAt) {
this.createdAt = createdAt;
}
public Instant getUpdatedAt() {
return updatedAt;
}
public void setUpdatedAt(Instant updatedAt) {
this.updatedAt = updatedAt;
}
}

View File

@ -0,0 +1,130 @@
package eu.eudat.model.builder;
import eu.eudat.authorization.AuthorizationFlags;
import eu.eudat.convention.ConventionService;
import eu.eudat.data.DmpExternalReferenceEntity;
import eu.eudat.model.DmpBlueprint;
import eu.eudat.model.DmpExternalReference;
import eu.eudat.model.ExternalReference;
import eu.eudat.query.DmpBlueprintQuery;
import eu.eudat.query.ExternalReferenceQuery;
import gr.cite.tools.data.builder.BuilderFactory;
import gr.cite.tools.data.query.QueryFactory;
import gr.cite.tools.exception.MyApplicationException;
import gr.cite.tools.fieldset.BaseFieldSet;
import gr.cite.tools.fieldset.FieldSet;
import gr.cite.tools.logging.DataLogEntry;
import gr.cite.tools.logging.LoggerService;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import java.util.*;
import java.util.stream.Collectors;
@Component
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class DmpExternalReferenceBuilder extends BaseBuilder<DmpExternalReference, DmpExternalReferenceEntity>{
private final BuilderFactory builderFactory;
private final QueryFactory queryFactory;
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
@Autowired
public DmpExternalReferenceBuilder(
ConventionService conventionService,
BuilderFactory builderFactory, QueryFactory queryFactory) {
super(conventionService, new LoggerService(LoggerFactory.getLogger(DmpExternalReferenceBuilder.class)));
this.builderFactory = builderFactory;
this.queryFactory = queryFactory;
}
public DmpExternalReferenceBuilder authorize(EnumSet<AuthorizationFlags> values) {
this.authorize = values;
return this;
}
@Override
public List<DmpExternalReference> build(FieldSet fields, List<DmpExternalReferenceEntity> data) throws MyApplicationException {
this.logger.debug("building for {} items requesting {} fields", Optional.ofNullable(data).map(List::size).orElse(0), Optional.ofNullable(fields).map(FieldSet::getFields).map(Set::size).orElse(0));
this.logger.trace(new DataLogEntry("requested fields", fields));
if (fields == null || data == null || fields.isEmpty())
return new ArrayList<>();
FieldSet externalReferenceFields = fields.extractPrefixed(this.asPrefix(DmpExternalReference._externalReference));
Map<UUID, ExternalReference> externalReferenceItemsMap = this.collectExternalReferences(externalReferenceFields, data);
FieldSet dmpFields = fields.extractPrefixed(this.asPrefix(DmpExternalReference._dmp));
Map<UUID, DmpBlueprint> dmpBlueprintItemsMap = this.collectDmps(dmpFields, data);
List<DmpExternalReference> models = new ArrayList<>();
for (DmpExternalReferenceEntity d : data) {
DmpExternalReference m = new DmpExternalReference();
if (fields.hasField(this.asIndexer(DmpExternalReference._id))) m.setId(d.getId());
if (fields.hasField(this.asIndexer(DmpExternalReference._data))) m.setData(d.getData());
if(!externalReferenceFields.isEmpty() && externalReferenceItemsMap != null && externalReferenceItemsMap.containsKey(d.getReferenceId())){
m.setExternalReference(externalReferenceItemsMap.get(d.getReferenceId()));
}
if(!dmpFields.isEmpty() && dmpBlueprintItemsMap != null && dmpBlueprintItemsMap.containsKey(d.getDmpId())){
m.setDmp(dmpBlueprintItemsMap.get(d.getDmpId()));
}
models.add(m);
}
this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0));
return models;
}
private Map<UUID, ExternalReference> collectExternalReferences(FieldSet fields, List<DmpExternalReferenceEntity> data) throws MyApplicationException {
if (fields.isEmpty() || data.isEmpty()) return null;
this.logger.debug("checking related - {}", ExternalReference.class.getSimpleName());
Map<UUID, ExternalReference> itemMap;
if (!fields.hasOtherField(this.asIndexer(ExternalReference._id))) {
itemMap = this.asEmpty(
data.stream().map(x -> x.getReferenceId()).distinct().collect(Collectors.toList()),
x -> {
ExternalReference item = new ExternalReference();
item.setId(x);
return item;
},
ExternalReference::getId);
} else {
FieldSet clone = new BaseFieldSet(fields.getFields()).ensure(ExternalReference._id);
ExternalReferenceQuery q = this.queryFactory.query(ExternalReferenceQuery.class).authorize(this.authorize).ids(data.stream().map(x -> x.getReferenceId()).distinct().collect(Collectors.toList()));
itemMap = this.builderFactory.builder(ExternalReferenceBuilder.class).authorize(this.authorize).asForeignKey(q, clone, ExternalReference::getId);
}
if (!fields.hasField(ExternalReference._id)) {
itemMap.values().stream().filter(Objects::nonNull).peek(x -> x.setId(null)).collect(Collectors.toList());
}
return itemMap;
}
private Map<UUID, DmpBlueprint> collectDmps(FieldSet fields, List<DmpExternalReferenceEntity> data) throws MyApplicationException {
if (fields.isEmpty() || data.isEmpty()) return null;
this.logger.debug("checking related - {}", DmpBlueprint.class.getSimpleName());
Map<UUID, DmpBlueprint> itemMap;
if (!fields.hasOtherField(this.asIndexer(DmpBlueprint._id))) {
itemMap = this.asEmpty(
data.stream().map(x -> x.getDmpId()).distinct().collect(Collectors.toList()),
x -> {
DmpBlueprint item = new DmpBlueprint();
item.setId(x);
return item;
},
DmpBlueprint::getId);
} else {
FieldSet clone = new BaseFieldSet(fields.getFields()).ensure(DmpBlueprint._id);
DmpBlueprintQuery q = this.queryFactory.query(DmpBlueprintQuery.class).authorize(this.authorize).ids(data.stream().map(x -> x.getDmpId()).distinct().collect(Collectors.toList()));
itemMap = this.builderFactory.builder(DmpBlueprintBuilder.class).authorize(this.authorize).asForeignKey(q, clone, DmpBlueprint::getId);
}
if (!fields.hasField(DmpBlueprint._id)) {
itemMap.values().stream().filter(Objects::nonNull).peek(x -> x.setId(null)).collect(Collectors.toList());
}
return itemMap;
}
}

View File

@ -0,0 +1,72 @@
package eu.eudat.model.builder;
import eu.eudat.authorization.AuthorizationFlags;
import eu.eudat.convention.ConventionService;
import eu.eudat.data.ExternalReferenceEntity;
import eu.eudat.model.ExternalReference;
import gr.cite.tools.data.builder.BuilderFactory;
import gr.cite.tools.exception.MyApplicationException;
import gr.cite.tools.fieldset.FieldSet;
import gr.cite.tools.logging.DataLogEntry;
import gr.cite.tools.logging.LoggerService;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import java.util.*;
@Component
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class ExternalReferenceBuilder extends BaseBuilder<ExternalReference, ExternalReferenceEntity>{
private final BuilderFactory builderFactory;
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
@Autowired
public ExternalReferenceBuilder(
ConventionService conventionService,
BuilderFactory builderFactory) {
super(conventionService, new LoggerService(LoggerFactory.getLogger(ExternalReferenceBuilder.class)));
this.builderFactory = builderFactory;
}
public ExternalReferenceBuilder authorize(EnumSet<AuthorizationFlags> values) {
this.authorize = values;
return this;
}
@Override
public List<ExternalReference> build(FieldSet fields, List<ExternalReferenceEntity> data) throws MyApplicationException {
this.logger.debug("building for {} items requesting {} fields", Optional.ofNullable(data).map(List::size).orElse(0), Optional.ofNullable(fields).map(FieldSet::getFields).map(Set::size).orElse(0));
this.logger.trace(new DataLogEntry("requested fields", fields));
if (fields == null || data == null || fields.isEmpty())
return new ArrayList<>();
// FieldSet userInfoFields = fields.extractPrefixed(this.asPrefix(ExternalReference._createdBy));
List<ExternalReference> models = new ArrayList<>();
for (ExternalReferenceEntity d : data) {
ExternalReference m = new ExternalReference();
if (fields.hasField(this.asIndexer(ExternalReference._id))) m.setId(d.getId());
if (fields.hasField(this.asIndexer(ExternalReference._label))) m.setLabel(d.getLabel());
if (fields.hasField(this.asIndexer(ExternalReference._createdAt))) m.setCreatedAt(d.getCreatedAt());
if (fields.hasField(this.asIndexer(ExternalReference._updatedAt))) m.setUpdatedAt(d.getUpdatedAt());
if (fields.hasField(this.asIndexer(ExternalReference._isActive))) m.setIsActive(d.getIsActive());
if (fields.hasField(this.asIndexer(ExternalReference._definition))) m.setReference(d.getDefinition());
if (fields.hasField(this.asIndexer(ExternalReference._reference))) m.setReference(d.getReference());
if (fields.hasField(this.asIndexer(ExternalReference._abbreviation))) m.setAbbreviation(d.getAbbreviation());
if (fields.hasField(this.asIndexer(ExternalReference._description))) m.setDescription(d.getDescription());
if (fields.hasField(this.asIndexer(ExternalReference._source))) m.setSource(d.getSource());
if (fields.hasField(this.asIndexer(ExternalReference._sourceType))) m.setSourceType(d.getSourceType());
if (fields.hasField(this.asIndexer(ExternalReference._type))) m.setType(d.getType());
// if (!userInfoFields.isEmpty() && d.getCreatedBy() != null){
// //Todo
// }
models.add(m);
}
this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0));
return models;
}
}

View File

@ -0,0 +1,47 @@
package eu.eudat.model.censorship;
import eu.eudat.authorization.Permission;
import eu.eudat.convention.ConventionService;
import eu.eudat.model.DmpExternalReference;
import gr.cite.commons.web.authz.service.AuthorizationService;
import gr.cite.tools.data.censor.CensorFactory;
import gr.cite.tools.fieldset.FieldSet;
import gr.cite.tools.logging.DataLogEntry;
import gr.cite.tools.logging.LoggerService;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import java.util.UUID;
@Component
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class DmpExternalReferenceCensor extends BaseCensor {
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(DmpExternalReferenceCensor.class));
protected final AuthorizationService authService;
protected final CensorFactory censorFactory;
public DmpExternalReferenceCensor(ConventionService conventionService,
AuthorizationService authService,
CensorFactory censorFactory) {
super(conventionService);
this.authService = authService;
this.censorFactory = censorFactory;
}
public void censor(FieldSet fields, UUID userId) {
logger.debug(new DataLogEntry("censoring fields", fields));
if (fields == null || fields.isEmpty())
return;
this.authService.authorizeForce(Permission.BrowseDmpExternalReference);
FieldSet dmpFields = fields.extractPrefixed(this.asIndexerPrefix(DmpExternalReference._dmp));
this.censorFactory.censor(DmpBlueprintCensor.class).censor(dmpFields, userId);
FieldSet externalReferenceFields = fields.extractPrefixed(this.asIndexerPrefix(DmpExternalReference._externalReference));
this.censorFactory.censor(ExternalReferenceCensor.class).censor(externalReferenceFields, userId);
}
}

View File

@ -0,0 +1,48 @@
package eu.eudat.model.censorship;
import eu.eudat.authorization.Permission;
import eu.eudat.convention.ConventionService;
import eu.eudat.model.DmpBlueprint;
import eu.eudat.model.ExternalReference;
import eu.eudat.model.censorship.dmpblueprintdefinition.DefinitionCensor;
import gr.cite.commons.web.authz.service.AuthorizationService;
import gr.cite.tools.data.censor.CensorFactory;
import gr.cite.tools.fieldset.FieldSet;
import gr.cite.tools.logging.DataLogEntry;
import gr.cite.tools.logging.LoggerService;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import java.util.UUID;
@Component
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class ExternalReferenceCensor extends BaseCensor {
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(ExternalReferenceCensor.class));
protected final AuthorizationService authService;
protected final CensorFactory censorFactory;
public ExternalReferenceCensor(ConventionService conventionService,
AuthorizationService authService,
CensorFactory censorFactory) {
super(conventionService);
this.authService = authService;
this.censorFactory = censorFactory;
}
public void censor(FieldSet fields, UUID userId) {
logger.debug(new DataLogEntry("censoring fields", fields));
if (fields == null || fields.isEmpty())
return;
this.authService.authorizeForce(Permission.BrowseExternalReference);
//ToDo
//FieldSet definitionFields = fields.extractPrefixed(this.asIndexerPrefix(ExternalReference._createdBy));
//this.censorFactory.censor(UserInfo.class).censor(definitionFields, userId);
}
}

View File

@ -0,0 +1,72 @@
package eu.eudat.model.deleter;
import eu.eudat.data.DmpExternalReferenceEntity;
import eu.eudat.query.DmpExternalReferenceQuery;
import gr.cite.tools.data.deleter.Deleter;
import gr.cite.tools.data.deleter.DeleterFactory;
import gr.cite.tools.data.query.QueryFactory;
import gr.cite.tools.logging.LoggerService;
import gr.cite.tools.logging.MapLogEntry;
import jakarta.persistence.EntityManager;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import javax.management.InvalidApplicationException;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
@Component
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class DmpExternalReferenceDeleter implements Deleter {
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(DmpExternalReferenceDeleter.class));
private final EntityManager entityManager;
protected final QueryFactory queryFactory;
protected final DeleterFactory deleterFactory;
@Autowired
public DmpExternalReferenceDeleter(
EntityManager entityManager,
QueryFactory queryFactory,
DeleterFactory deleterFactory
) {
this.entityManager = entityManager;
this.queryFactory = queryFactory;
this.deleterFactory = deleterFactory;
}
public void deleteAndSaveByIds(List<UUID> ids) throws InvalidApplicationException {
logger.debug(new MapLogEntry("collecting to delete").And("count", Optional.ofNullable(ids).map(List::size).orElse(0)).And("ids", ids));
List<DmpExternalReferenceEntity> data = this.queryFactory.query(DmpExternalReferenceQuery.class).ids(ids).collect();
logger.trace("retrieved {} items", Optional.ofNullable(data).map(List::size).orElse(0));
this.deleteAndSave(data);
}
public void deleteAndSave(List<DmpExternalReferenceEntity> data) throws InvalidApplicationException {
logger.debug("will delete {} items", Optional.ofNullable(data).map(List::size).orElse(0));
this.delete(data);
logger.trace("saving changes");
this.entityManager.flush();
logger.trace("changes saved");
}
public void delete(List<DmpExternalReferenceEntity> data) throws InvalidApplicationException {
logger.debug("will delete {} items", Optional.ofNullable(data).map(List::size).orElse(0));
if (data == null || data.isEmpty())
return;
for (DmpExternalReferenceEntity item : data) {
logger.trace("deleting item {}", item.getId());
logger.trace("updating item");
this.entityManager.merge(item);
logger.trace("updated item");
}
}
}

View File

@ -0,0 +1,78 @@
package eu.eudat.model.deleter;
import eu.eudat.commons.enums.IsActive;
import eu.eudat.data.ExternalReferenceEntity;
import eu.eudat.query.ExternalReferenceQuery;
import gr.cite.tools.data.deleter.Deleter;
import gr.cite.tools.data.deleter.DeleterFactory;
import gr.cite.tools.data.query.QueryFactory;
import gr.cite.tools.logging.LoggerService;
import gr.cite.tools.logging.MapLogEntry;
import jakarta.persistence.EntityManager;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import javax.management.InvalidApplicationException;
import java.time.Instant;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
@Component
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class ExternalReferenceDeleter implements Deleter {
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(ExternalReferenceDeleter.class));
private final EntityManager entityManager;
protected final QueryFactory queryFactory;
protected final DeleterFactory deleterFactory;
@Autowired
public ExternalReferenceDeleter(
EntityManager entityManager,
QueryFactory queryFactory,
DeleterFactory deleterFactory
) {
this.entityManager = entityManager;
this.queryFactory = queryFactory;
this.deleterFactory = deleterFactory;
}
public void deleteAndSaveByIds(List<UUID> ids) throws InvalidApplicationException {
logger.debug(new MapLogEntry("collecting to delete").And("count", Optional.ofNullable(ids).map(List::size).orElse(0)).And("ids", ids));
List<ExternalReferenceEntity> data = this.queryFactory.query(ExternalReferenceQuery.class).ids(ids).collect();
logger.trace("retrieved {} items", Optional.ofNullable(data).map(List::size).orElse(0));
this.deleteAndSave(data);
}
public void deleteAndSave(List<ExternalReferenceEntity> data) throws InvalidApplicationException {
logger.debug("will delete {} items", Optional.ofNullable(data).map(List::size).orElse(0));
this.delete(data);
logger.trace("saving changes");
this.entityManager.flush();
logger.trace("changes saved");
}
public void delete(List<ExternalReferenceEntity> data) throws InvalidApplicationException {
logger.debug("will delete {} items", Optional.ofNullable(data).map(List::size).orElse(0));
if (data == null || data.isEmpty())
return;
Instant now = Instant.now();
for (ExternalReferenceEntity item : data) {
logger.trace("deleting item {}", item.getId());
item.setIsActive(IsActive.Inactive);
item.setUpdatedAt(now);
logger.trace("updating item");
this.entityManager.merge(item);
logger.trace("updated item");
}
}
}

View File

@ -0,0 +1,152 @@
package eu.eudat.query;
import eu.eudat.authorization.AuthorizationFlags;
import eu.eudat.commons.scope.user.UserScope;
import eu.eudat.data.DmpExternalReferenceEntity;
import gr.cite.commons.web.authz.service.AuthorizationService;
import gr.cite.tools.data.query.FieldResolver;
import gr.cite.tools.data.query.QueryBase;
import gr.cite.tools.data.query.QueryContext;
import jakarta.persistence.Tuple;
import jakarta.persistence.criteria.CriteriaBuilder;
import jakarta.persistence.criteria.Predicate;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import java.util.*;
@Component
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class DmpExternalReferenceQuery extends QueryBase<DmpExternalReferenceEntity> {
private Collection<UUID> ids;
private Collection<UUID> dmpIds;
private Collection<UUID> referenceIds;
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
public DmpExternalReferenceQuery ids(UUID value) {
this.ids = List.of(value);
return this;
}
public DmpExternalReferenceQuery ids(UUID... value) {
this.ids = Arrays.asList(value);
return this;
}
public DmpExternalReferenceQuery ids(Collection<UUID> values) {
this.ids = values;
return this;
}
public DmpExternalReferenceQuery dmpIds(UUID value) {
this.dmpIds = List.of(value);
return this;
}
public DmpExternalReferenceQuery dmpIds(UUID... value) {
this.dmpIds = Arrays.asList(value);
return this;
}
public DmpExternalReferenceQuery dmpIds(Collection<UUID> values) {
this.dmpIds = values;
return this;
}
public DmpExternalReferenceQuery referenceIds(UUID value) {
this.referenceIds = List.of(value);
return this;
}
public DmpExternalReferenceQuery referenceIds(UUID... value) {
this.referenceIds = Arrays.asList(value);
return this;
}
public DmpExternalReferenceQuery referenceIds(Collection<UUID> values) {
this.referenceIds = values;
return this;
}
public DmpExternalReferenceQuery authorize(EnumSet<AuthorizationFlags> values) {
this.authorize = values;
return this;
}
private final UserScope userScope;
private final AuthorizationService authService;
public DmpExternalReferenceQuery(
UserScope userScope,
AuthorizationService authService
) {
this.userScope = userScope;
this.authService = authService;
}
@Override
protected Class<DmpExternalReferenceEntity> entityClass() {
return DmpExternalReferenceEntity.class;
}
@Override
protected Boolean isFalseQuery() {
return this.isEmpty(this.ids) || this.isEmpty(this.dmpIds) || this.isEmpty(this.referenceIds);
}
@Override
protected <X, Y> Predicate applyFilters(QueryContext<X, Y> queryContext) {
List<Predicate> predicates = new ArrayList<>();
if (this.ids != null) {
CriteriaBuilder.In<UUID> inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(DmpExternalReferenceEntity._id));
for (UUID item : this.ids)
inClause.value(item);
predicates.add(inClause);
}
if (this.dmpIds != null) {
CriteriaBuilder.In<UUID> inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(DmpExternalReferenceEntity._dmpId));
for (UUID item : this.ids)
inClause.value(item);
predicates.add(inClause);
}
if (this.referenceIds != null) {
CriteriaBuilder.In<UUID> inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(DmpExternalReferenceEntity._referenceId));
for (UUID item : this.ids)
inClause.value(item);
predicates.add(inClause);
}
if (!predicates.isEmpty()) {
Predicate[] predicatesArray = predicates.toArray(new Predicate[0]);
return queryContext.CriteriaBuilder.and(predicatesArray);
} else {
return null;
}
}
@Override
protected DmpExternalReferenceEntity convert(Tuple tuple, Set<String> columns) {
DmpExternalReferenceEntity item = new DmpExternalReferenceEntity();
item.setId(QueryBase.convertSafe(tuple, columns, DmpExternalReferenceEntity._id, UUID.class));
item.setReferenceId(QueryBase.convertSafe(tuple, columns, DmpExternalReferenceEntity._dmpId, UUID.class));
item.setReferenceId(QueryBase.convertSafe(tuple, columns, DmpExternalReferenceEntity._referenceId, UUID.class));
item.setData(QueryBase.convertSafe(tuple, columns, DmpExternalReferenceEntity._data, String.class));
return item;
}
@Override
protected String fieldNameOf(FieldResolver item) {
if (item.match(DmpExternalReferenceEntity._id)) return DmpExternalReferenceEntity._id;
else if (item.prefix(DmpExternalReferenceEntity._dmpId)) return DmpExternalReferenceEntity._dmpId;
else if (item.prefix(DmpExternalReferenceEntity._referenceId)) return DmpExternalReferenceEntity._referenceId;
else if (item.match(DmpExternalReferenceEntity._data)) return DmpExternalReferenceEntity._data;
else return null;
}
}

View File

@ -0,0 +1,230 @@
package eu.eudat.query;
import eu.eudat.authorization.AuthorizationFlags;
import eu.eudat.commons.enums.ExternalReferencesType;
import eu.eudat.commons.enums.IsActive;
import eu.eudat.commons.enums.SourceType;
import eu.eudat.commons.scope.user.UserScope;
import eu.eudat.data.DmpBlueprintEntity;
import eu.eudat.data.ExternalReferenceEntity;
import gr.cite.commons.web.authz.service.AuthorizationService;
import gr.cite.tools.data.query.FieldResolver;
import gr.cite.tools.data.query.QueryBase;
import gr.cite.tools.data.query.QueryContext;
import jakarta.persistence.Tuple;
import jakarta.persistence.criteria.CriteriaBuilder;
import jakarta.persistence.criteria.Predicate;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import java.time.Instant;
import java.util.*;
@Component
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class ExternalReferenceQuery extends QueryBase<ExternalReferenceEntity> {
private String like;
private Collection<UUID> ids;
private Collection<IsActive> isActives;
private Collection<SourceType> sourceTypes;
private Collection<ExternalReferencesType> externalReferenceTypes;
private Collection<UUID> excludedIds;
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
public ExternalReferenceQuery like(String value) {
this.like = value;
return this;
}
public ExternalReferenceQuery ids(UUID value) {
this.ids = List.of(value);
return this;
}
public ExternalReferenceQuery ids(UUID... value) {
this.ids = Arrays.asList(value);
return this;
}
public ExternalReferenceQuery ids(Collection<UUID> values) {
this.ids = values;
return this;
}
public ExternalReferenceQuery isActive(IsActive value) {
this.isActives = List.of(value);
return this;
}
public ExternalReferenceQuery isActive(IsActive... value) {
this.isActives = Arrays.asList(value);
return this;
}
public ExternalReferenceQuery isActive(Collection<IsActive> values) {
this.isActives = values;
return this;
}
public ExternalReferenceQuery externalReferenceTypes(ExternalReferencesType value) {
this.externalReferenceTypes = List.of(value);
return this;
}
public ExternalReferenceQuery externalReferenceTypes(ExternalReferencesType... value) {
this.externalReferenceTypes = Arrays.asList(value);
return this;
}
public ExternalReferenceQuery externalReferenceTypes(Collection<ExternalReferencesType> values) {
this.externalReferenceTypes = values;
return this;
}
public ExternalReferenceQuery excludedIds(Collection<UUID> values) {
this.excludedIds = values;
return this;
}
public ExternalReferenceQuery excludedIds(UUID value) {
this.excludedIds = List.of(value);
return this;
}
public ExternalReferenceQuery excludedIds(UUID... value) {
this.excludedIds = Arrays.asList(value);
return this;
}
public ExternalReferenceQuery sourceTypes(SourceType value) {
this.sourceTypes = List.of(value);
return this;
}
public ExternalReferenceQuery sourceTypes(SourceType... value) {
this.sourceTypes = Arrays.asList(value);
return this;
}
public ExternalReferenceQuery sourceTypes(Collection<SourceType> values) {
this.sourceTypes = values;
return this;
}
public ExternalReferenceQuery authorize(EnumSet<AuthorizationFlags> values) {
this.authorize = values;
return this;
}
private final UserScope userScope;
private final AuthorizationService authService;
public ExternalReferenceQuery(
UserScope userScope,
AuthorizationService authService
) {
this.userScope = userScope;
this.authService = authService;
}
@Override
protected Class<ExternalReferenceEntity> entityClass() {
return ExternalReferenceEntity.class;
}
@Override
protected Boolean isFalseQuery() {
return this.isEmpty(this.ids) || this.isEmpty(this.isActives) || this.isEmpty(this.excludedIds) || this.isEmpty(this.externalReferenceTypes) || this.isEmpty(this.sourceTypes);
}
@Override
protected <X, Y> Predicate applyFilters(QueryContext<X, Y> queryContext) {
List<Predicate> predicates = new ArrayList<>();
if (this.ids != null) {
CriteriaBuilder.In<UUID> inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(ExternalReferenceEntity._id));
for (UUID item : this.ids)
inClause.value(item);
predicates.add(inClause);
}
if (this.like != null && !this.like.isEmpty()) {
predicates.add(queryContext.CriteriaBuilder.like(queryContext.Root.get(ExternalReferenceEntity._label), this.like));
}
if (this.isActives != null) {
CriteriaBuilder.In<IsActive> inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(ExternalReferenceEntity._isActive));
for (IsActive item : this.isActives)
inClause.value(item);
predicates.add(inClause);
}
if (this.sourceTypes != null) {
CriteriaBuilder.In<SourceType> inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(ExternalReferenceEntity._sourceType));
for (SourceType item : this.sourceTypes)
inClause.value(item);
predicates.add(inClause);
}
if (this.externalReferenceTypes != null) {
CriteriaBuilder.In<ExternalReferencesType> inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(ExternalReferenceEntity._type));
for (ExternalReferencesType item : this.externalReferenceTypes)
inClause.value(item);
predicates.add(inClause);
}
if (this.excludedIds != null) {
CriteriaBuilder.In<UUID> notInClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(DmpBlueprintEntity._id));
for (UUID item : this.excludedIds)
notInClause.value(item);
predicates.add(notInClause.not());
}
if (!predicates.isEmpty()) {
Predicate[] predicatesArray = predicates.toArray(new Predicate[0]);
return queryContext.CriteriaBuilder.and(predicatesArray);
} else {
return null;
}
}
@Override
protected ExternalReferenceEntity convert(Tuple tuple, Set<String> columns) {
ExternalReferenceEntity item = new ExternalReferenceEntity();
item.setId(QueryBase.convertSafe(tuple, columns, ExternalReferenceEntity._id, UUID.class));
item.setLabel(QueryBase.convertSafe(tuple, columns, ExternalReferenceEntity._label, String.class));
item.setDescription(QueryBase.convertSafe(tuple, columns, ExternalReferenceEntity._description, String.class));
item.setCreatedAt(QueryBase.convertSafe(tuple, columns, ExternalReferenceEntity._createdAt, Instant.class));
item.setUpdatedAt(QueryBase.convertSafe(tuple, columns, ExternalReferenceEntity._updatedAt, Instant.class));
item.setIsActive(QueryBase.convertSafe(tuple, columns, ExternalReferenceEntity._isActive, IsActive.class));
item.setDefinition(QueryBase.convertSafe(tuple, columns, ExternalReferenceEntity._definition, String.class));
item.setAbbreviation(QueryBase.convertSafe(tuple, columns, ExternalReferenceEntity._abbreviation, String.class));
item.setReference(QueryBase.convertSafe(tuple, columns, ExternalReferenceEntity._reference, String.class));
item.setSource(QueryBase.convertSafe(tuple, columns, ExternalReferenceEntity._source, String.class));
item.setSourceType(QueryBase.convertSafe(tuple, columns, ExternalReferenceEntity._sourceType, SourceType.class));
item.setType(QueryBase.convertSafe(tuple, columns, ExternalReferenceEntity._type, ExternalReferencesType.class));
//item.setCreatedBy(QueryBase.convertSafe(tuple, columns, ExternalReferenceEntity._createdBy, UUID.class));
return item;
}
@Override
protected String fieldNameOf(FieldResolver item) {
if (item.match(ExternalReferenceEntity._id)) return ExternalReferenceEntity._id;
else if (item.match(ExternalReferenceEntity._label)) return ExternalReferenceEntity._label;
else if (item.match(ExternalReferenceEntity._description)) return ExternalReferenceEntity._description;
else if (item.match(ExternalReferenceEntity._createdAt)) return ExternalReferenceEntity._createdAt;
else if (item.match(ExternalReferenceEntity._updatedAt)) return ExternalReferenceEntity._updatedAt;
else if (item.match(ExternalReferenceEntity._isActive)) return ExternalReferenceEntity._isActive;
else if (item.match(ExternalReferenceEntity._definition)) return ExternalReferenceEntity._definition;
else if (item.match(ExternalReferenceEntity._abbreviation)) return ExternalReferenceEntity._abbreviation;
else if (item.match(ExternalReferenceEntity._reference)) return ExternalReferenceEntity._reference;
else if (item.match(ExternalReferenceEntity._source)) return ExternalReferenceEntity._source;
else if (item.match(ExternalReferenceEntity._sourceType)) return ExternalReferenceEntity._sourceType;
else if (item.match(ExternalReferenceEntity._type)) return ExternalReferenceEntity._type;
//else if (item.prefix(ExternalReferenceEntity._createdBy)) return ExternalReferenceEntity._createdBy;
else return null;
}
}

View File

@ -0,0 +1,30 @@
package eu.eudat.query.lookup;
import eu.eudat.query.DmpExternalReferenceQuery;
import gr.cite.tools.data.query.Lookup;
import gr.cite.tools.data.query.QueryFactory;
import java.util.Collection;
import java.util.UUID;
public class DmpExternalReferenceLookup extends Lookup {
private Collection<UUID> ids;
private Collection<UUID> dmpIds;
private Collection<UUID> referenceIds;
public DmpExternalReferenceQuery enrich(QueryFactory queryFactory) {
DmpExternalReferenceQuery query = queryFactory.query(DmpExternalReferenceQuery.class);
if (this.ids != null) query.ids(this.ids);
if (this.dmpIds != null) query.dmpIds(this.dmpIds);
if (this.referenceIds != null) query.referenceIds(this.referenceIds);
this.enrichCommon(query);
return query;
}
}

View File

@ -0,0 +1,90 @@
package eu.eudat.query.lookup;
import eu.eudat.commons.enums.ExternalReferencesType;
import eu.eudat.commons.enums.IsActive;
import eu.eudat.commons.enums.SourceType;
import eu.eudat.query.ExternalReferenceQuery;
import gr.cite.tools.data.query.Lookup;
import gr.cite.tools.data.query.QueryFactory;
import java.util.Collection;
import java.util.List;
import java.util.UUID;
public class ExternalReferenceLookup extends Lookup {
private String like;
private List<IsActive> isActive;
private Collection<SourceType> sourceTypes;
private Collection<ExternalReferencesType> externalReferenceTypes;
private List<UUID> ids;
private List<UUID> excludedIds;
public String getLike() {
return like;
}
public void setLike(String like) {
this.like = like;
}
public List<IsActive> getIsActive() {
return isActive;
}
public void setIsActive(List<IsActive> isActive) {
this.isActive = isActive;
}
public List<UUID> getIds() {
return ids;
}
public void setIds(List<UUID> ids) {
this.ids = ids;
}
public List<UUID> getExcludedIds() {
return excludedIds;
}
public void setExcludedIds(List<UUID> excludeIds) {
this.excludedIds = excludeIds;
}
public Collection<SourceType> getSourceTypes() {
return sourceTypes;
}
public void setSourceTypes(Collection<SourceType> sourceTypes) {
this.sourceTypes = sourceTypes;
}
public Collection<ExternalReferencesType> getExternalReferenceTypes() {
return externalReferenceTypes;
}
public void setExternalReferenceTypes(Collection<ExternalReferencesType> externalReferenceTypes) {
this.externalReferenceTypes = externalReferenceTypes;
}
public ExternalReferenceQuery enrich(QueryFactory queryFactory) {
ExternalReferenceQuery query = queryFactory.query(ExternalReferenceQuery.class);
if (this.like != null) query.like(this.like);
if (this.isActive != null) query.isActive(this.isActive);
if (this.externalReferenceTypes != null) query.externalReferenceTypes(this.externalReferenceTypes);
if (this.sourceTypes != null) query.sourceTypes(this.sourceTypes);
if (this.ids != null) query.ids(this.ids);
if (this.excludedIds != null) query.excludedIds(this.excludedIds);
this.enrichCommon(query);
return query;
}
}

View File

@ -135,3 +135,45 @@ permissions:
clients: [ ] clients: [ ]
allowAnonymous: false allowAnonymous: false
allowAuthenticated: false allowAuthenticated: false
# ExternalReference Permissions
BrowseExternalReference:
roles:
- Admin
clients: [ ]
allowAnonymous: false
allowAuthenticated: false
EditExternalReference:
roles:
- Admin
clients: [ ]
allowAnonymous: false
allowAuthenticated: false
DeleteExternalReference:
roles:
- Admin
claims: [ ]
clients: [ ]
allowAnonymous: false
allowAuthenticated: false
# DmpExternalReference Permissions
BrowseDmpExternalReference:
roles:
- Admin
clients: [ ]
allowAnonymous: false
allowAuthenticated: false
EditDmpExternalReference:
roles:
- Admin
clients: [ ]
allowAnonymous: false
allowAuthenticated: false
DeleteDmpExternalReference:
roles:
- Admin
claims: [ ]
clients: [ ]
allowAnonymous: false
allowAuthenticated: false