rename External Reference to Reference

This commit is contained in:
amentis 2023-10-26 12:07:04 +03:00
parent 129dbd163a
commit bbb21fadba
26 changed files with 460 additions and 471 deletions

View File

@ -8,8 +8,8 @@ import jakarta.persistence.Table;
import java.util.UUID;
@Entity
@Table(name = "\"DmpExternalReference\"")
public class DmpExternalReferenceEntity {
@Table(name = "\"DmpReference\"")
public class DmpReferenceEntity {
@Id
@Column(name = "id", columnDefinition = "uuid", updatable = false, nullable = false)

View File

@ -12,8 +12,8 @@ import java.time.Instant;
import java.util.UUID;
@Entity
@Table(name = "\"ExternalReference\"")
public class ExternalReferenceEntity {
@Table(name = "\"Reference\"")
public class ReferenceEntity {
@Id
@Column(name = "id", columnDefinition = "uuid", updatable = false, nullable = false)

View File

@ -93,6 +93,9 @@ public class Dmp {
public static final String _dmpDescriptions = "dmpDescriptions";
public static final String _dmpExternalReferences = "dmpExternalReferences";
private List<DmpReference> dmpReferences;
public UUID getId() {
return id;
}
@ -260,4 +263,12 @@ public class Dmp {
public void setDmpDescriptions(List<Description> dmpDescriptions) {
this.dmpDescriptions = dmpDescriptions;
}
public List<DmpReference> getDmpExternalReferences() {
return dmpReferences;
}
public void setDmpExternalReferences(List<DmpReference> dmpReferences) {
this.dmpReferences = dmpReferences;
}
}

View File

@ -34,9 +34,6 @@ public class DmpBlueprint {
public final static String _hash = "hash";
private String hash;
public static final String _dmpExternalReferences = "dmpExternalReferences";
private List<DmpExternalReference> dmpExternalReferences;
public UUID getId() {
return id;
}
@ -100,14 +97,6 @@ public class DmpBlueprint {
public void setDefinition(Definition definition) {
this.definition = definition;
}
public List<DmpExternalReference> getDmpExternalReferences() {
return dmpExternalReferences;
}
public void setDmpExternalReferences(List<DmpExternalReference> dmpExternalReferences) {
this.dmpExternalReferences = dmpExternalReferences;
}
}

View File

@ -2,15 +2,15 @@ package eu.eudat.model;
import java.util.UUID;
public class DmpExternalReference {
public class DmpReference {
private UUID id;
public static final String _id = "id";
private DmpBlueprint dmp;
private Dmp dmp;
public static final String _dmp = "dmp";
private ExternalReference externalReference;
private Reference reference;
public static final String _externalReference = "externalReference";
private String data;
@ -24,20 +24,20 @@ public class DmpExternalReference {
this.id = id;
}
public DmpBlueprint getDmp() {
public Dmp getDmp() {
return dmp;
}
public void setDmp(DmpBlueprint dmp) {
public void setDmp(Dmp dmp) {
this.dmp = dmp;
}
public ExternalReference getExternalReference() {
return externalReference;
public Reference getExternalReference() {
return reference;
}
public void setExternalReference(ExternalReference externalReference) {
this.externalReference = externalReference;
public void setExternalReference(Reference reference) {
this.reference = reference;
}
public String getData() {

View File

@ -8,7 +8,7 @@ import java.time.Instant;
import java.util.List;
import java.util.UUID;
public class ExternalReference {
public class Reference {
private UUID id;
public static final String _id = "id";
@ -49,7 +49,7 @@ public class ExternalReference {
//private UserInfo createdBy; ToDo
//public static final String _createdBy = "createdBy";
private List<DmpExternalReference> dmpExternalReferences;
private List<DmpReference> dmpReferences;
public static final String _dmpExternalReferences = "dmpExternalReferences";
public UUID getId() {
@ -148,11 +148,11 @@ public class ExternalReference {
this.updatedAt = updatedAt;
}
public List<DmpExternalReference> getDmpExternalReferences() {
return dmpExternalReferences;
public List<DmpReference> getDmpExternalReferences() {
return dmpReferences;
}
public void setDmpExternalReferences(List<DmpExternalReference> dmpExternalReferences) {
this.dmpExternalReferences = dmpExternalReferences;
public void setDmpExternalReferences(List<DmpReference> dmpReferences) {
this.dmpReferences = dmpReferences;
}
}

View File

@ -6,14 +6,9 @@ import eu.eudat.commons.types.dmpblueprint.DefinitionEntity;
import eu.eudat.convention.ConventionService;
import eu.eudat.data.DmpBlueprintEntity;
import eu.eudat.model.DmpBlueprint;
import eu.eudat.model.DmpExternalReference;
import eu.eudat.model.ExternalReference;
import eu.eudat.model.builder.dmpblueprintdefinition.DefinitionBuilder;
import eu.eudat.query.DmpExternalReferenceQuery;
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;
@ -24,24 +19,21 @@ 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 DmpBlueprintBuilder extends BaseBuilder<DmpBlueprint, DmpBlueprintEntity> {
private final BuilderFactory builderFactory;
private final QueryFactory queryFactory;
private final XmlHandlingService xmlHandlingService;
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
@Autowired
public DmpBlueprintBuilder(
ConventionService conventionService,
BuilderFactory builderFactory, QueryFactory queryFactory, XmlHandlingService xmlHandlingService) {
BuilderFactory builderFactory, XmlHandlingService xmlHandlingService) {
super(conventionService, new LoggerService(LoggerFactory.getLogger(DmpBlueprintBuilder.class)));
this.builderFactory = builderFactory;
this.queryFactory = queryFactory;
this.xmlHandlingService = xmlHandlingService;
}
@ -57,9 +49,6 @@ public class DmpBlueprintBuilder extends BaseBuilder<DmpBlueprint, DmpBlueprintE
if (fields == null || data == null || fields.isEmpty())
return new ArrayList<>();
FieldSet definitionFields = fields.extractPrefixed(this.asPrefix(DmpBlueprint._definition));
FieldSet dmpExternalReferencesFields = fields.extractPrefixed(this.asPrefix(ExternalReference._dmpExternalReferences));
Map<UUID, List<DmpExternalReference>> dmpExternalReferenceMap = this.collectDmpExternalReferences(dmpExternalReferencesFields, data);
List<DmpBlueprint> models = new ArrayList<>();
for (DmpBlueprintEntity d : data) {
DmpBlueprint m = new DmpBlueprint();
@ -74,29 +63,9 @@ public class DmpBlueprintBuilder extends BaseBuilder<DmpBlueprint, DmpBlueprintE
DefinitionEntity definition = this.xmlHandlingService.xmlSerializableFromXmlSafe(DefinitionEntity.class, d.getDefinition());
m.setDefinition(this.builderFactory.builder(DefinitionBuilder.class).authorize(this.authorize).build(definitionFields, definition));
}
if (dmpExternalReferenceMap != null && !dmpExternalReferenceMap.isEmpty() && dmpExternalReferenceMap.containsKey(d.getId())) m.setDmpExternalReferences(dmpExternalReferenceMap.get(d.getId()));
models.add(m);
models.add(m);
}
this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0));
return models;
}
private Map<UUID, List<DmpExternalReference>> collectDmpExternalReferences(FieldSet fields, List<DmpBlueprintEntity> datas) throws MyApplicationException {
if (fields.isEmpty() || datas.isEmpty()) return null;
this.logger.debug("checking related - {}", DmpExternalReference.class.getSimpleName());
Map<UUID, List<DmpExternalReference>> itemMap = null;
FieldSet clone = new BaseFieldSet(fields.getFields()).ensure(this.asIndexer(DmpExternalReference._dmp, DmpBlueprint._id));
DmpExternalReferenceQuery query = this.queryFactory.query(DmpExternalReferenceQuery.class).authorize(this.authorize).dmpIds(datas.stream().map(x -> x.getId()).distinct().collect(Collectors.toList()));
itemMap = this.builderFactory.builder(DmpExternalReferenceBuilder.class).authorize(this.authorize).authorize(this.authorize).asMasterKey(query, clone, x -> x.getDmp().getId());
if (!fields.hasField(this.asIndexer(DmpExternalReference._dmp, DmpBlueprint._id))) {
itemMap.values().stream().flatMap(List::stream).filter(x -> x != null && x.getDmp() != null).map(x -> {
x.getDmp().setId(null);
return x;
}).collect(Collectors.toList());
}
return itemMap;
}
}

View File

@ -3,9 +3,9 @@ package eu.eudat.model.builder;
import eu.eudat.authorization.AuthorizationFlags;
import eu.eudat.convention.ConventionService;
import eu.eudat.data.DmpEntity;
import eu.eudat.model.Description;
import eu.eudat.model.Dmp;
import eu.eudat.model.*;
import eu.eudat.query.DescriptionQuery;
import eu.eudat.query.DmpReferenceQuery;
import gr.cite.tools.data.builder.BuilderFactory;
import gr.cite.tools.data.query.QueryFactory;
import gr.cite.tools.exception.MyApplicationException;
@ -57,6 +57,8 @@ public class DmpBuilder extends BaseBuilder<Dmp, DmpEntity> {
FieldSet dmpDescriptionsFields = fields.extractPrefixed(this.asPrefix(Dmp._dmpDescriptions));
Map<UUID, List<Description>> dmpDescriptionsMap = this.collectDmpDescriptions(dmpDescriptionsFields, data);
FieldSet dmpReferencesFields = fields.extractPrefixed(this.asPrefix(Reference._dmpExternalReferences));
Map<UUID, List<DmpReference>> dmpReferenceMap = this.collectDmpReferences(dmpReferencesFields, data);
for (DmpEntity d : data) {
Dmp m = new Dmp();
@ -96,6 +98,7 @@ public class DmpBuilder extends BaseBuilder<Dmp, DmpEntity> {
if (!dmpDescriptionsFields.isEmpty() && dmpDescriptionsMap != null && dmpDescriptionsMap.containsKey(d.getId()))
m.setDmpDescriptions(dmpDescriptionsMap.get(d.getId()));
if (dmpReferenceMap != null && !dmpReferenceMap.isEmpty() && dmpReferenceMap.containsKey(d.getId())) m.setDmpExternalReferences(dmpReferenceMap.get(d.getId()));
models.add(m);
}
this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0));
@ -123,4 +126,22 @@ public class DmpBuilder extends BaseBuilder<Dmp, DmpEntity> {
return itemMap;
}
private Map<UUID, List<DmpReference>> collectDmpReferences(FieldSet fields, List<DmpEntity> datas) throws MyApplicationException {
if (fields.isEmpty() || datas.isEmpty()) return null;
this.logger.debug("checking related - {}", DmpReference.class.getSimpleName());
Map<UUID, List<DmpReference>> itemMap = null;
FieldSet clone = new BaseFieldSet(fields.getFields()).ensure(this.asIndexer(DmpReference._dmp, Dmp._id));
DmpReferenceQuery query = this.queryFactory.query(DmpReferenceQuery.class).authorize(this.authorize).dmpIds(datas.stream().map(x -> x.getId()).distinct().collect(Collectors.toList()));
itemMap = this.builderFactory.builder(DmpReferenceBuilder.class).authorize(this.authorize).authorize(this.authorize).asMasterKey(query, clone, x -> x.getDmp().getId());
if (!fields.hasField(this.asIndexer(DmpReference._dmp, Dmp._id))) {
itemMap.values().stream().flatMap(List::stream).filter(x -> x != null && x.getDmp() != null).map(x -> {
x.getDmp().setId(null);
return x;
}).collect(Collectors.toList());
}
return itemMap;
}
}

View File

@ -1,130 +0,0 @@
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,130 @@
package eu.eudat.model.builder;
import eu.eudat.authorization.AuthorizationFlags;
import eu.eudat.convention.ConventionService;
import eu.eudat.data.DmpReferenceEntity;
import eu.eudat.model.Dmp;
import eu.eudat.model.DmpReference;
import eu.eudat.model.Reference;
import eu.eudat.query.DmpQuery;
import eu.eudat.query.ReferenceQuery;
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 DmpReferenceBuilder extends BaseBuilder<DmpReference, DmpReferenceEntity>{
private final BuilderFactory builderFactory;
private final QueryFactory queryFactory;
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
@Autowired
public DmpReferenceBuilder(
ConventionService conventionService,
BuilderFactory builderFactory, QueryFactory queryFactory) {
super(conventionService, new LoggerService(LoggerFactory.getLogger(DmpReferenceBuilder.class)));
this.builderFactory = builderFactory;
this.queryFactory = queryFactory;
}
public DmpReferenceBuilder authorize(EnumSet<AuthorizationFlags> values) {
this.authorize = values;
return this;
}
@Override
public List<DmpReference> build(FieldSet fields, List<DmpReferenceEntity> 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 referenceFields = fields.extractPrefixed(this.asPrefix(DmpReference._externalReference));
Map<UUID, Reference> referenceItemsMap = this.collectReferences(referenceFields, data);
FieldSet dmpFields = fields.extractPrefixed(this.asPrefix(DmpReference._dmp));
Map<UUID, Dmp> dmpItemsMap = this.collectDmps(dmpFields, data);
List<DmpReference> models = new ArrayList<>();
for (DmpReferenceEntity d : data) {
DmpReference m = new DmpReference();
if (fields.hasField(this.asIndexer(DmpReference._id))) m.setId(d.getId());
if (fields.hasField(this.asIndexer(DmpReference._data))) m.setData(d.getData());
if(!referenceFields.isEmpty() && referenceItemsMap != null && referenceItemsMap.containsKey(d.getReferenceId())){
m.setExternalReference(referenceItemsMap.get(d.getReferenceId()));
}
if(!dmpFields.isEmpty() && dmpItemsMap != null && dmpItemsMap.containsKey(d.getDmpId())){
m.setDmp(dmpItemsMap.get(d.getDmpId()));
}
models.add(m);
}
this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0));
return models;
}
private Map<UUID, Reference> collectReferences(FieldSet fields, List<DmpReferenceEntity> data) throws MyApplicationException {
if (fields.isEmpty() || data.isEmpty()) return null;
this.logger.debug("checking related - {}", Reference.class.getSimpleName());
Map<UUID, Reference> itemMap;
if (!fields.hasOtherField(this.asIndexer(Reference._id))) {
itemMap = this.asEmpty(
data.stream().map(x -> x.getReferenceId()).distinct().collect(Collectors.toList()),
x -> {
Reference item = new Reference();
item.setId(x);
return item;
},
Reference::getId);
} else {
FieldSet clone = new BaseFieldSet(fields.getFields()).ensure(Reference._id);
ReferenceQuery q = this.queryFactory.query(ReferenceQuery.class).authorize(this.authorize).ids(data.stream().map(x -> x.getReferenceId()).distinct().collect(Collectors.toList()));
itemMap = this.builderFactory.builder(ReferenceBuilder.class).authorize(this.authorize).asForeignKey(q, clone, Reference::getId);
}
if (!fields.hasField(Reference._id)) {
itemMap.values().stream().filter(Objects::nonNull).peek(x -> x.setId(null)).collect(Collectors.toList());
}
return itemMap;
}
private Map<UUID, Dmp> collectDmps(FieldSet fields, List<DmpReferenceEntity> data) throws MyApplicationException {
if (fields.isEmpty() || data.isEmpty()) return null;
this.logger.debug("checking related - {}", Dmp.class.getSimpleName());
Map<UUID, Dmp> itemMap;
if (!fields.hasOtherField(this.asIndexer(Dmp._id))) {
itemMap = this.asEmpty(
data.stream().map(x -> x.getDmpId()).distinct().collect(Collectors.toList()),
x -> {
Dmp item = new Dmp();
item.setId(x);
return item;
},
Dmp::getId);
} else {
FieldSet clone = new BaseFieldSet(fields.getFields()).ensure(Dmp._id);
DmpQuery q = this.queryFactory.query(DmpQuery.class).authorize(this.authorize).ids(data.stream().map(x -> x.getDmpId()).distinct().collect(Collectors.toList()));
itemMap = this.builderFactory.builder(DmpBuilder.class).authorize(this.authorize).asForeignKey(q, clone, Dmp::getId);
}
if (!fields.hasField(Dmp._id)) {
itemMap.values().stream().filter(Objects::nonNull).peek(x -> x.setId(null)).collect(Collectors.toList());
}
return itemMap;
}
}

View File

@ -1,101 +0,0 @@
package eu.eudat.model.builder;
import eu.eudat.authorization.AuthorizationFlags;
import eu.eudat.convention.ConventionService;
import eu.eudat.data.ExternalReferenceEntity;
import eu.eudat.model.DmpExternalReference;
import eu.eudat.model.ExternalReference;
import eu.eudat.query.DmpExternalReferenceQuery;
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 ExternalReferenceBuilder extends BaseBuilder<ExternalReference, ExternalReferenceEntity>{
private final BuilderFactory builderFactory;
private final QueryFactory queryFactory;
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
@Autowired
public ExternalReferenceBuilder(
ConventionService conventionService,
BuilderFactory builderFactory, QueryFactory queryFactory) {
super(conventionService, new LoggerService(LoggerFactory.getLogger(ExternalReferenceBuilder.class)));
this.builderFactory = builderFactory;
this.queryFactory = queryFactory;
}
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));
FieldSet dmpExternalReferencesFields = fields.extractPrefixed(this.asPrefix(ExternalReference._dmpExternalReferences));
Map<UUID, List<DmpExternalReference>> dmpExternalReferenceMap = this.collectDmpExternalReferences(dmpExternalReferencesFields, data);
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
// }
if (!dmpExternalReferenceMap.isEmpty() && dmpExternalReferenceMap != null && dmpExternalReferenceMap.containsKey(d.getId())) m.setDmpExternalReferences(dmpExternalReferenceMap.get(d.getId()));
models.add(m);
}
this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0));
return models;
}
private Map<UUID, List<DmpExternalReference>> collectDmpExternalReferences(FieldSet fields, List<ExternalReferenceEntity> datas) throws MyApplicationException {
if (fields.isEmpty() || datas.isEmpty()) return null;
this.logger.debug("checking related - {}", DmpExternalReference.class.getSimpleName());
Map<UUID, List<DmpExternalReference>> itemMap = null;
FieldSet clone = new BaseFieldSet(fields.getFields()).ensure(this.asIndexer(DmpExternalReference._externalReference, ExternalReference._id));
DmpExternalReferenceQuery query = this.queryFactory.query(DmpExternalReferenceQuery.class).authorize(this.authorize).referenceIds(datas.stream().map(x -> x.getId()).distinct().collect(Collectors.toList()));
itemMap = this.builderFactory.builder(DmpExternalReferenceBuilder.class).authorize(this.authorize).authorize(this.authorize).asMasterKey(query, clone, x -> x.getExternalReference().getId());
if (!fields.hasField(this.asIndexer(DmpExternalReference._externalReference, ExternalReference._id))) {
itemMap.values().stream().flatMap(List::stream).filter(x -> x != null && x.getExternalReference() != null).map(x -> {
x.getExternalReference().setId(null);
return x;
}).collect(Collectors.toList());
}
return itemMap;
}
}

View File

@ -0,0 +1,101 @@
package eu.eudat.model.builder;
import eu.eudat.authorization.AuthorizationFlags;
import eu.eudat.convention.ConventionService;
import eu.eudat.data.ReferenceEntity;
import eu.eudat.model.DmpReference;
import eu.eudat.model.Reference;
import eu.eudat.query.DmpReferenceQuery;
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 ReferenceBuilder extends BaseBuilder<Reference, ReferenceEntity>{
private final BuilderFactory builderFactory;
private final QueryFactory queryFactory;
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
@Autowired
public ReferenceBuilder(
ConventionService conventionService,
BuilderFactory builderFactory, QueryFactory queryFactory) {
super(conventionService, new LoggerService(LoggerFactory.getLogger(ReferenceBuilder.class)));
this.builderFactory = builderFactory;
this.queryFactory = queryFactory;
}
public ReferenceBuilder authorize(EnumSet<AuthorizationFlags> values) {
this.authorize = values;
return this;
}
@Override
public List<Reference> build(FieldSet fields, List<ReferenceEntity> 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));
FieldSet dmpReferencesFields = fields.extractPrefixed(this.asPrefix(Reference._dmpExternalReferences));
Map<UUID, List<DmpReference>> dmpReferenceMap = this.collectDmpReferences(dmpReferencesFields, data);
List<Reference> models = new ArrayList<>();
for (ReferenceEntity d : data) {
Reference m = new Reference();
if (fields.hasField(this.asIndexer(Reference._id))) m.setId(d.getId());
if (fields.hasField(this.asIndexer(Reference._label))) m.setLabel(d.getLabel());
if (fields.hasField(this.asIndexer(Reference._createdAt))) m.setCreatedAt(d.getCreatedAt());
if (fields.hasField(this.asIndexer(Reference._updatedAt))) m.setUpdatedAt(d.getUpdatedAt());
if (fields.hasField(this.asIndexer(Reference._isActive))) m.setIsActive(d.getIsActive());
if (fields.hasField(this.asIndexer(Reference._definition))) m.setReference(d.getDefinition());
if (fields.hasField(this.asIndexer(Reference._reference))) m.setReference(d.getReference());
if (fields.hasField(this.asIndexer(Reference._abbreviation))) m.setAbbreviation(d.getAbbreviation());
if (fields.hasField(this.asIndexer(Reference._description))) m.setDescription(d.getDescription());
if (fields.hasField(this.asIndexer(Reference._source))) m.setSource(d.getSource());
if (fields.hasField(this.asIndexer(Reference._sourceType))) m.setSourceType(d.getSourceType());
if (fields.hasField(this.asIndexer(Reference._type))) m.setType(d.getType());
// if (!userInfoFields.isEmpty() && d.getCreatedBy() != null){
// //ToDo
// }
if (!dmpReferenceMap.isEmpty() && dmpReferenceMap != null && dmpReferenceMap.containsKey(d.getId())) m.setDmpExternalReferences(dmpReferenceMap.get(d.getId()));
models.add(m);
}
this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0));
return models;
}
private Map<UUID, List<DmpReference>> collectDmpReferences(FieldSet fields, List<ReferenceEntity> datas) throws MyApplicationException {
if (fields.isEmpty() || datas.isEmpty()) return null;
this.logger.debug("checking related - {}", DmpReference.class.getSimpleName());
Map<UUID, List<DmpReference>> itemMap = null;
FieldSet clone = new BaseFieldSet(fields.getFields()).ensure(this.asIndexer(DmpReference._externalReference, Reference._id));
DmpReferenceQuery query = this.queryFactory.query(DmpReferenceQuery.class).authorize(this.authorize).referenceIds(datas.stream().map(x -> x.getId()).distinct().collect(Collectors.toList()));
itemMap = this.builderFactory.builder(DmpReferenceBuilder.class).authorize(this.authorize).authorize(this.authorize).asMasterKey(query, clone, x -> x.getExternalReference().getId());
if (!fields.hasField(this.asIndexer(DmpReference._externalReference, Reference._id))) {
itemMap.values().stream().flatMap(List::stream).filter(x -> x != null && x.getExternalReference() != null).map(x -> {
x.getExternalReference().setId(null);
return x;
}).collect(Collectors.toList());
}
return itemMap;
}
}

View File

@ -41,8 +41,6 @@ public class DmpBlueprintCensor extends BaseCensor {
this.authService.authorizeForce(Permission.BrowseDmpBlueprint);
FieldSet definitionFields = fields.extractPrefixed(this.asIndexerPrefix(DmpBlueprint._definition));
this.censorFactory.censor(DefinitionCensor.class).censor(definitionFields, userId);
FieldSet dmpExternalReferencesFields = fields.extractPrefixed(this.asIndexerPrefix(DmpBlueprint._dmpExternalReferences));
this.censorFactory.censor(DmpExternalReferenceCensor.class).censor(dmpExternalReferencesFields, userId);
}
}

View File

@ -42,6 +42,8 @@ public class DmpCensor extends BaseCensor {
FieldSet dmpDescriptionsFields = fields.extractPrefixed(this.asIndexerPrefix(Dmp._dmpDescriptions));
this.censorFactory.censor(DescriptionCensor.class).censor(dmpDescriptionsFields, userId);
FieldSet dmpExternalReferencesFields = fields.extractPrefixed(this.asIndexerPrefix(Dmp._dmpExternalReferences));
this.censorFactory.censor(DmpReferenceCensor.class).censor(dmpExternalReferencesFields, userId);
}
}

View File

@ -2,7 +2,7 @@ package eu.eudat.model.censorship;
import eu.eudat.authorization.Permission;
import eu.eudat.convention.ConventionService;
import eu.eudat.model.DmpExternalReference;
import eu.eudat.model.DmpReference;
import gr.cite.commons.web.authz.service.AuthorizationService;
import gr.cite.tools.data.censor.CensorFactory;
import gr.cite.tools.fieldset.FieldSet;
@ -17,14 +17,14 @@ import java.util.UUID;
@Component
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class DmpExternalReferenceCensor extends BaseCensor {
public class DmpReferenceCensor extends BaseCensor {
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(DmpExternalReferenceCensor.class));
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(DmpReferenceCensor.class));
protected final AuthorizationService authService;
protected final CensorFactory censorFactory;
public DmpExternalReferenceCensor(ConventionService conventionService,
public DmpReferenceCensor(ConventionService conventionService,
AuthorizationService authService,
CensorFactory censorFactory) {
super(conventionService);
@ -38,10 +38,10 @@ public class DmpExternalReferenceCensor extends BaseCensor {
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);
FieldSet dmpFields = fields.extractPrefixed(this.asIndexerPrefix(DmpReference._dmp));
this.censorFactory.censor(DmpCensor.class).censor(dmpFields, userId);
FieldSet externalReferenceFields = fields.extractPrefixed(this.asIndexerPrefix(DmpReference._externalReference));
this.censorFactory.censor(ReferenceCensor.class).censor(externalReferenceFields, userId);
}
}

View File

@ -2,7 +2,7 @@ package eu.eudat.model.censorship;
import eu.eudat.authorization.Permission;
import eu.eudat.convention.ConventionService;
import eu.eudat.model.ExternalReference;
import eu.eudat.model.Reference;
import gr.cite.commons.web.authz.service.AuthorizationService;
import gr.cite.tools.data.censor.CensorFactory;
import gr.cite.tools.fieldset.FieldSet;
@ -17,14 +17,14 @@ import java.util.UUID;
@Component
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class ExternalReferenceCensor extends BaseCensor {
public class ReferenceCensor extends BaseCensor {
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(ExternalReferenceCensor.class));
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(ReferenceCensor.class));
protected final AuthorizationService authService;
protected final CensorFactory censorFactory;
public ExternalReferenceCensor(ConventionService conventionService,
public ReferenceCensor(ConventionService conventionService,
AuthorizationService authService,
CensorFactory censorFactory) {
super(conventionService);
@ -38,8 +38,8 @@ public class ExternalReferenceCensor extends BaseCensor {
return;
this.authService.authorizeForce(Permission.BrowseExternalReference);
FieldSet dmpExternalReferencesFields = fields.extractPrefixed(this.asIndexerPrefix(ExternalReference._dmpExternalReferences));
this.censorFactory.censor(DmpExternalReferenceCensor.class).censor(dmpExternalReferencesFields, userId);
FieldSet dmpExternalReferencesFields = fields.extractPrefixed(this.asIndexerPrefix(Reference._dmpExternalReferences));
this.censorFactory.censor(DmpReferenceCensor.class).censor(dmpExternalReferencesFields, userId);
//ToDo
//FieldSet definitionFields = fields.extractPrefixed(this.asIndexerPrefix(ExternalReference._createdBy));
//this.censorFactory.censor(UserInfo.class).censor(definitionFields, userId);

View File

@ -1,7 +1,7 @@
package eu.eudat.model.deleter;
import eu.eudat.data.DmpExternalReferenceEntity;
import eu.eudat.query.DmpExternalReferenceQuery;
import eu.eudat.data.DmpReferenceEntity;
import eu.eudat.query.DmpReferenceQuery;
import gr.cite.tools.data.deleter.Deleter;
import gr.cite.tools.data.deleter.DeleterFactory;
import gr.cite.tools.data.query.QueryFactory;
@ -21,9 +21,9 @@ import java.util.UUID;
@Component
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class DmpExternalReferenceDeleter implements Deleter {
public class DmpReferenceDeleter implements Deleter {
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(DmpExternalReferenceDeleter.class));
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(DmpReferenceDeleter.class));
private final EntityManager entityManager;
protected final QueryFactory queryFactory;
@ -31,7 +31,7 @@ public class DmpExternalReferenceDeleter implements Deleter {
protected final DeleterFactory deleterFactory;
@Autowired
public DmpExternalReferenceDeleter(
public DmpReferenceDeleter(
EntityManager entityManager,
QueryFactory queryFactory,
DeleterFactory deleterFactory
@ -43,12 +43,12 @@ public class DmpExternalReferenceDeleter implements Deleter {
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();
List<DmpReferenceEntity> data = this.queryFactory.query(DmpReferenceQuery.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 {
public void deleteAndSave(List<DmpReferenceEntity> data) throws InvalidApplicationException {
logger.debug("will delete {} items", Optional.ofNullable(data).map(List::size).orElse(0));
this.delete(data);
logger.trace("saving changes");
@ -56,12 +56,12 @@ public class DmpExternalReferenceDeleter implements Deleter {
logger.trace("changes saved");
}
public void delete(List<DmpExternalReferenceEntity> data) throws InvalidApplicationException {
public void delete(List<DmpReferenceEntity> 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) {
for (DmpReferenceEntity item : data) {
logger.trace("deleting item {}", item.getId());
logger.trace("updating item");
this.entityManager.merge(item);

View File

@ -1,8 +1,8 @@
package eu.eudat.model.deleter;
import eu.eudat.commons.enums.IsActive;
import eu.eudat.data.ExternalReferenceEntity;
import eu.eudat.query.ExternalReferenceQuery;
import eu.eudat.data.ReferenceEntity;
import eu.eudat.query.ReferenceQuery;
import gr.cite.tools.data.deleter.Deleter;
import gr.cite.tools.data.deleter.DeleterFactory;
import gr.cite.tools.data.query.QueryFactory;
@ -23,9 +23,9 @@ import java.util.UUID;
@Component
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class ExternalReferenceDeleter implements Deleter {
public class ReferenceDeleter implements Deleter {
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(ExternalReferenceDeleter.class));
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(ReferenceDeleter.class));
private final EntityManager entityManager;
protected final QueryFactory queryFactory;
@ -33,7 +33,7 @@ public class ExternalReferenceDeleter implements Deleter {
protected final DeleterFactory deleterFactory;
@Autowired
public ExternalReferenceDeleter(
public ReferenceDeleter(
EntityManager entityManager,
QueryFactory queryFactory,
DeleterFactory deleterFactory
@ -45,12 +45,12 @@ public class ExternalReferenceDeleter implements Deleter {
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();
List<ReferenceEntity> data = this.queryFactory.query(ReferenceQuery.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 {
public void deleteAndSave(List<ReferenceEntity> data) throws InvalidApplicationException {
logger.debug("will delete {} items", Optional.ofNullable(data).map(List::size).orElse(0));
this.delete(data);
logger.trace("saving changes");
@ -58,14 +58,14 @@ public class ExternalReferenceDeleter implements Deleter {
logger.trace("changes saved");
}
public void delete(List<ExternalReferenceEntity> data) throws InvalidApplicationException {
public void delete(List<ReferenceEntity> 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) {
for (ReferenceEntity item : data) {
logger.trace("deleting item {}", item.getId());
item.setIsActive(IsActive.Inactive);
item.setUpdatedAt(now);

View File

@ -2,7 +2,7 @@ package eu.eudat.query;
import eu.eudat.authorization.AuthorizationFlags;
import eu.eudat.commons.scope.user.UserScope;
import eu.eudat.data.DmpExternalReferenceEntity;
import eu.eudat.data.DmpReferenceEntity;
import gr.cite.commons.web.authz.service.AuthorizationService;
import gr.cite.tools.data.query.FieldResolver;
import gr.cite.tools.data.query.QueryBase;
@ -18,7 +18,7 @@ import java.util.*;
@Component
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class DmpExternalReferenceQuery extends QueryBase<DmpExternalReferenceEntity> {
public class DmpReferenceQuery extends QueryBase<DmpReferenceEntity> {
private Collection<UUID> ids;
@ -29,52 +29,52 @@ public class DmpExternalReferenceQuery extends QueryBase<DmpExternalReferenceEnt
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
public DmpExternalReferenceQuery ids(UUID value) {
public DmpReferenceQuery ids(UUID value) {
this.ids = List.of(value);
return this;
}
public DmpExternalReferenceQuery ids(UUID... value) {
public DmpReferenceQuery ids(UUID... value) {
this.ids = Arrays.asList(value);
return this;
}
public DmpExternalReferenceQuery ids(Collection<UUID> values) {
public DmpReferenceQuery ids(Collection<UUID> values) {
this.ids = values;
return this;
}
public DmpExternalReferenceQuery dmpIds(UUID value) {
public DmpReferenceQuery dmpIds(UUID value) {
this.dmpIds = List.of(value);
return this;
}
public DmpExternalReferenceQuery dmpIds(UUID... value) {
public DmpReferenceQuery dmpIds(UUID... value) {
this.dmpIds = Arrays.asList(value);
return this;
}
public DmpExternalReferenceQuery dmpIds(Collection<UUID> values) {
public DmpReferenceQuery dmpIds(Collection<UUID> values) {
this.dmpIds = values;
return this;
}
public DmpExternalReferenceQuery referenceIds(UUID value) {
public DmpReferenceQuery referenceIds(UUID value) {
this.referenceIds = List.of(value);
return this;
}
public DmpExternalReferenceQuery referenceIds(UUID... value) {
public DmpReferenceQuery referenceIds(UUID... value) {
this.referenceIds = Arrays.asList(value);
return this;
}
public DmpExternalReferenceQuery referenceIds(Collection<UUID> values) {
public DmpReferenceQuery referenceIds(Collection<UUID> values) {
this.referenceIds = values;
return this;
}
public DmpExternalReferenceQuery authorize(EnumSet<AuthorizationFlags> values) {
public DmpReferenceQuery authorize(EnumSet<AuthorizationFlags> values) {
this.authorize = values;
return this;
}
@ -83,7 +83,7 @@ public class DmpExternalReferenceQuery extends QueryBase<DmpExternalReferenceEnt
private final AuthorizationService authService;
public DmpExternalReferenceQuery(
public DmpReferenceQuery(
UserScope userScope,
AuthorizationService authService
) {
@ -92,8 +92,8 @@ public class DmpExternalReferenceQuery extends QueryBase<DmpExternalReferenceEnt
}
@Override
protected Class<DmpExternalReferenceEntity> entityClass() {
return DmpExternalReferenceEntity.class;
protected Class<DmpReferenceEntity> entityClass() {
return DmpReferenceEntity.class;
}
@Override
@ -105,19 +105,19 @@ public class DmpExternalReferenceQuery extends QueryBase<DmpExternalReferenceEnt
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));
CriteriaBuilder.In<UUID> inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(DmpReferenceEntity._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));
CriteriaBuilder.In<UUID> inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(DmpReferenceEntity._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));
CriteriaBuilder.In<UUID> inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(DmpReferenceEntity._referenceId));
for (UUID item : this.ids)
inClause.value(item);
predicates.add(inClause);
@ -131,21 +131,21 @@ public class DmpExternalReferenceQuery extends QueryBase<DmpExternalReferenceEnt
}
@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));
protected DmpReferenceEntity convert(Tuple tuple, Set<String> columns) {
DmpReferenceEntity item = new DmpReferenceEntity();
item.setId(QueryBase.convertSafe(tuple, columns, DmpReferenceEntity._id, UUID.class));
item.setReferenceId(QueryBase.convertSafe(tuple, columns, DmpReferenceEntity._dmpId, UUID.class));
item.setReferenceId(QueryBase.convertSafe(tuple, columns, DmpReferenceEntity._referenceId, UUID.class));
item.setData(QueryBase.convertSafe(tuple, columns, DmpReferenceEntity._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;
if (item.match(DmpReferenceEntity._id)) return DmpReferenceEntity._id;
else if (item.prefix(DmpReferenceEntity._dmpId)) return DmpReferenceEntity._dmpId;
else if (item.prefix(DmpReferenceEntity._referenceId)) return DmpReferenceEntity._referenceId;
else if (item.match(DmpReferenceEntity._data)) return DmpReferenceEntity._data;
else return null;
}

View File

@ -5,8 +5,7 @@ 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 eu.eudat.data.ReferenceEntity;
import gr.cite.commons.web.authz.service.AuthorizationService;
import gr.cite.tools.data.query.FieldResolver;
import gr.cite.tools.data.query.QueryBase;
@ -23,7 +22,7 @@ import java.util.*;
@Component
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class ExternalReferenceQuery extends QueryBase<ExternalReferenceEntity> {
public class ReferenceQuery extends QueryBase<ReferenceEntity> {
private String like;
@ -39,87 +38,87 @@ public class ExternalReferenceQuery extends QueryBase<ExternalReferenceEntity> {
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
public ExternalReferenceQuery like(String value) {
public ReferenceQuery like(String value) {
this.like = value;
return this;
}
public ExternalReferenceQuery ids(UUID value) {
public ReferenceQuery ids(UUID value) {
this.ids = List.of(value);
return this;
}
public ExternalReferenceQuery ids(UUID... value) {
public ReferenceQuery ids(UUID... value) {
this.ids = Arrays.asList(value);
return this;
}
public ExternalReferenceQuery ids(Collection<UUID> values) {
public ReferenceQuery ids(Collection<UUID> values) {
this.ids = values;
return this;
}
public ExternalReferenceQuery isActive(IsActive value) {
public ReferenceQuery isActive(IsActive value) {
this.isActives = List.of(value);
return this;
}
public ExternalReferenceQuery isActive(IsActive... value) {
public ReferenceQuery isActive(IsActive... value) {
this.isActives = Arrays.asList(value);
return this;
}
public ExternalReferenceQuery isActive(Collection<IsActive> values) {
public ReferenceQuery isActive(Collection<IsActive> values) {
this.isActives = values;
return this;
}
public ExternalReferenceQuery externalReferenceTypes(ExternalReferencesType value) {
public ReferenceQuery externalReferenceTypes(ExternalReferencesType value) {
this.externalReferenceTypes = List.of(value);
return this;
}
public ExternalReferenceQuery externalReferenceTypes(ExternalReferencesType... value) {
public ReferenceQuery externalReferenceTypes(ExternalReferencesType... value) {
this.externalReferenceTypes = Arrays.asList(value);
return this;
}
public ExternalReferenceQuery externalReferenceTypes(Collection<ExternalReferencesType> values) {
public ReferenceQuery externalReferenceTypes(Collection<ExternalReferencesType> values) {
this.externalReferenceTypes = values;
return this;
}
public ExternalReferenceQuery excludedIds(Collection<UUID> values) {
public ReferenceQuery excludedIds(Collection<UUID> values) {
this.excludedIds = values;
return this;
}
public ExternalReferenceQuery excludedIds(UUID value) {
public ReferenceQuery excludedIds(UUID value) {
this.excludedIds = List.of(value);
return this;
}
public ExternalReferenceQuery excludedIds(UUID... value) {
public ReferenceQuery excludedIds(UUID... value) {
this.excludedIds = Arrays.asList(value);
return this;
}
public ExternalReferenceQuery sourceTypes(SourceType value) {
public ReferenceQuery sourceTypes(SourceType value) {
this.sourceTypes = List.of(value);
return this;
}
public ExternalReferenceQuery sourceTypes(SourceType... value) {
public ReferenceQuery sourceTypes(SourceType... value) {
this.sourceTypes = Arrays.asList(value);
return this;
}
public ExternalReferenceQuery sourceTypes(Collection<SourceType> values) {
public ReferenceQuery sourceTypes(Collection<SourceType> values) {
this.sourceTypes = values;
return this;
}
public ExternalReferenceQuery authorize(EnumSet<AuthorizationFlags> values) {
public ReferenceQuery authorize(EnumSet<AuthorizationFlags> values) {
this.authorize = values;
return this;
}
@ -128,7 +127,7 @@ public class ExternalReferenceQuery extends QueryBase<ExternalReferenceEntity> {
private final AuthorizationService authService;
public ExternalReferenceQuery(
public ReferenceQuery(
UserScope userScope,
AuthorizationService authService
) {
@ -137,8 +136,8 @@ public class ExternalReferenceQuery extends QueryBase<ExternalReferenceEntity> {
}
@Override
protected Class<ExternalReferenceEntity> entityClass() {
return ExternalReferenceEntity.class;
protected Class<ReferenceEntity> entityClass() {
return ReferenceEntity.class;
}
@Override
@ -150,36 +149,36 @@ public class ExternalReferenceQuery extends QueryBase<ExternalReferenceEntity> {
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));
CriteriaBuilder.In<UUID> inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(ReferenceEntity._id));
for (UUID item : this.ids)
inClause.value(item);
predicates.add(inClause);
}
if (this.like != null && !this.like.isEmpty()) {
predicates.add(queryContext.CriteriaBuilder.or(queryContext.CriteriaBuilder.like(queryContext.Root.get(ExternalReferenceEntity._label), this.like),
queryContext.CriteriaBuilder.like(queryContext.Root.get(ExternalReferenceEntity._description), this.like)
predicates.add(queryContext.CriteriaBuilder.or(queryContext.CriteriaBuilder.like(queryContext.Root.get(ReferenceEntity._label), this.like),
queryContext.CriteriaBuilder.like(queryContext.Root.get(ReferenceEntity._description), this.like)
));
}
if (this.isActives != null) {
CriteriaBuilder.In<IsActive> inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(ExternalReferenceEntity._isActive));
CriteriaBuilder.In<IsActive> inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(ReferenceEntity._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));
CriteriaBuilder.In<SourceType> inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(ReferenceEntity._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));
CriteriaBuilder.In<ExternalReferencesType> inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(ReferenceEntity._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(ExternalReferenceEntity._id));
CriteriaBuilder.In<UUID> notInClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(ReferenceEntity._id));
for (UUID item : this.excludedIds)
notInClause.value(item);
predicates.add(notInClause.not());
@ -193,38 +192,38 @@ public class ExternalReferenceQuery extends QueryBase<ExternalReferenceEntity> {
}
@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));
protected ReferenceEntity convert(Tuple tuple, Set<String> columns) {
ReferenceEntity item = new ReferenceEntity();
item.setId(QueryBase.convertSafe(tuple, columns, ReferenceEntity._id, UUID.class));
item.setLabel(QueryBase.convertSafe(tuple, columns, ReferenceEntity._label, String.class));
item.setDescription(QueryBase.convertSafe(tuple, columns, ReferenceEntity._description, String.class));
item.setCreatedAt(QueryBase.convertSafe(tuple, columns, ReferenceEntity._createdAt, Instant.class));
item.setUpdatedAt(QueryBase.convertSafe(tuple, columns, ReferenceEntity._updatedAt, Instant.class));
item.setIsActive(QueryBase.convertSafe(tuple, columns, ReferenceEntity._isActive, IsActive.class));
item.setDefinition(QueryBase.convertSafe(tuple, columns, ReferenceEntity._definition, String.class));
item.setAbbreviation(QueryBase.convertSafe(tuple, columns, ReferenceEntity._abbreviation, String.class));
item.setReference(QueryBase.convertSafe(tuple, columns, ReferenceEntity._reference, String.class));
item.setSource(QueryBase.convertSafe(tuple, columns, ReferenceEntity._source, String.class));
item.setSourceType(QueryBase.convertSafe(tuple, columns, ReferenceEntity._sourceType, SourceType.class));
item.setType(QueryBase.convertSafe(tuple, columns, ReferenceEntity._type, ExternalReferencesType.class));
item.setCreatedBy(QueryBase.convertSafe(tuple, columns, ReferenceEntity._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;
if (item.match(ReferenceEntity._id)) return ReferenceEntity._id;
else if (item.match(ReferenceEntity._label)) return ReferenceEntity._label;
else if (item.match(ReferenceEntity._description)) return ReferenceEntity._description;
else if (item.match(ReferenceEntity._createdAt)) return ReferenceEntity._createdAt;
else if (item.match(ReferenceEntity._updatedAt)) return ReferenceEntity._updatedAt;
else if (item.match(ReferenceEntity._isActive)) return ReferenceEntity._isActive;
else if (item.match(ReferenceEntity._definition)) return ReferenceEntity._definition;
else if (item.match(ReferenceEntity._abbreviation)) return ReferenceEntity._abbreviation;
else if (item.match(ReferenceEntity._reference)) return ReferenceEntity._reference;
else if (item.match(ReferenceEntity._source)) return ReferenceEntity._source;
else if (item.match(ReferenceEntity._sourceType)) return ReferenceEntity._sourceType;
else if (item.match(ReferenceEntity._type)) return ReferenceEntity._type;
//else if (item.prefix(ExternalReferenceEntity._createdBy)) return ExternalReferenceEntity._createdBy;
else return null;
}

View File

@ -1,13 +1,13 @@
package eu.eudat.query.lookup;
import eu.eudat.query.DmpExternalReferenceQuery;
import eu.eudat.query.DmpReferenceQuery;
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 {
public class DmpReferenceLookup extends Lookup {
private Collection<UUID> ids;
@ -16,8 +16,8 @@ public class DmpExternalReferenceLookup extends Lookup {
private Collection<UUID> referenceIds;
public DmpExternalReferenceQuery enrich(QueryFactory queryFactory) {
DmpExternalReferenceQuery query = queryFactory.query(DmpExternalReferenceQuery.class);
public DmpReferenceQuery enrich(QueryFactory queryFactory) {
DmpReferenceQuery query = queryFactory.query(DmpReferenceQuery.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);

View File

@ -3,7 +3,7 @@ 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 eu.eudat.query.ReferenceQuery;
import gr.cite.tools.data.query.Lookup;
import gr.cite.tools.data.query.QueryFactory;
@ -11,7 +11,7 @@ import java.util.Collection;
import java.util.List;
import java.util.UUID;
public class ExternalReferenceLookup extends Lookup {
public class ReferenceLookup extends Lookup {
private String like;
@ -73,8 +73,8 @@ public class ExternalReferenceLookup extends Lookup {
this.externalReferenceTypes = externalReferenceTypes;
}
public ExternalReferenceQuery enrich(QueryFactory queryFactory) {
ExternalReferenceQuery query = queryFactory.query(ExternalReferenceQuery.class);
public ReferenceQuery enrich(QueryFactory queryFactory) {
ReferenceQuery query = queryFactory.query(ReferenceQuery.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);

View File

@ -5,19 +5,19 @@ import eu.eudat.authorization.AuthorizationFlags;
import eu.eudat.authorization.Permission;
import eu.eudat.commons.enums.ExternalReferencesType;
import eu.eudat.controllers.BaseController;
import eu.eudat.data.ExternalReferenceEntity;
import eu.eudat.data.ReferenceEntity;
import eu.eudat.logic.proxy.config.exceptions.HugeResultSet;
import eu.eudat.logic.proxy.config.exceptions.NoURLFound;
import eu.eudat.logic.services.ApiContext;
import eu.eudat.logic.services.externalreferences.ExternalReferenceService;
import eu.eudat.model.ExternalReference;
import eu.eudat.model.builder.ExternalReferenceBuilder;
import eu.eudat.model.censorship.ExternalReferenceCensor;
import eu.eudat.logic.services.references.ReferenceService;
import eu.eudat.model.Reference;
import eu.eudat.model.builder.ReferenceBuilder;
import eu.eudat.model.censorship.ReferenceCensor;
import eu.eudat.model.result.QueryResult;
import eu.eudat.models.data.FetcherExternalReference;
import eu.eudat.models.data.helpers.responses.ResponseItem;
import eu.eudat.query.ExternalReferenceQuery;
import eu.eudat.query.lookup.ExternalReferenceLookup;
import eu.eudat.query.ReferenceQuery;
import eu.eudat.query.lookup.ReferenceLookup;
import eu.eudat.types.ApiMessageCode;
import gr.cite.commons.web.authz.service.AuthorizationService;
import gr.cite.tools.auditing.AuditService;
@ -47,29 +47,29 @@ import java.util.UUID;
@RestController
@RequestMapping(path = {"api/external-references"})
public class ExternalReferenceController extends BaseController {
public class ReferenceController extends BaseController {
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(ExternalReferenceController.class));
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(ReferenceController.class));
private final BuilderFactory builderFactory;
private final AuditService auditService;
private final ExternalReferenceService externalReferenceService;
private final ReferenceService referenceService;
private final CensorFactory censorFactory;
private final QueryFactory queryFactory;
private final MessageSource messageSource;
private final AuthorizationService authorizationService;
@Autowired
public ExternalReferenceController(
public ReferenceController(
ApiContext apiContext,
BuilderFactory builderFactory,
ExternalReferenceService externalReferenceService,
ReferenceService referenceService,
AuditService auditService,
CensorFactory censorFactory,
QueryFactory queryFactory,
MessageSource messageSource, AuthorizationService authorizationService) {
super(apiContext);
this.builderFactory = builderFactory;
this.externalReferenceService = externalReferenceService;
this.referenceService = referenceService;
this.auditService = auditService;
this.censorFactory = censorFactory;
this.queryFactory = queryFactory;
@ -78,14 +78,14 @@ public class ExternalReferenceController extends BaseController {
}
@PostMapping("query")
public QueryResult<ExternalReference> query(@RequestBody ExternalReferenceLookup lookup) throws MyApplicationException, MyForbiddenException {
logger.debug("querying {}", ExternalReference.class.getSimpleName());
public QueryResult<Reference> query(@RequestBody ReferenceLookup lookup) throws MyApplicationException, MyForbiddenException {
logger.debug("querying {}", Reference.class.getSimpleName());
this.censorFactory.censor(ExternalReferenceCensor.class).censor(lookup.getProject(), null);
this.censorFactory.censor(ReferenceCensor.class).censor(lookup.getProject(), null);
ExternalReferenceQuery query = lookup.enrich(this.queryFactory).authorize(AuthorizationFlags.OwnerOrPermission);
List<ExternalReferenceEntity> datas = query.collectAs(lookup.getProject());
List<ExternalReference> models = this.builderFactory.builder(ExternalReferenceBuilder.class).authorize(AuthorizationFlags.OwnerOrPermission).build(lookup.getProject(), datas);
ReferenceQuery query = lookup.enrich(this.queryFactory).authorize(AuthorizationFlags.OwnerOrPermission);
List<ReferenceEntity> datas = query.collectAs(lookup.getProject());
List<Reference> models = this.builderFactory.builder(ReferenceBuilder.class).authorize(AuthorizationFlags.OwnerOrPermission).build(lookup.getProject(), datas);
long count = (lookup.getMetadata() != null && lookup.getMetadata().getCountAll()) ? query.count() : models.size();
this.auditService.track(AuditableAction.External_Reference_Query, "lookup", lookup);
@ -94,15 +94,15 @@ public class ExternalReferenceController extends BaseController {
}
@GetMapping("{id}")
public ExternalReference get(@PathVariable("id") UUID id, FieldSet fieldSet) throws MyApplicationException, MyForbiddenException, MyNotFoundException {
logger.debug(new MapLogEntry("retrieving" + eu.eudat.model.ExternalReference.class.getSimpleName()).And("id", id).And("fields", fieldSet));
public Reference get(@PathVariable("id") UUID id, FieldSet fieldSet) throws MyApplicationException, MyForbiddenException, MyNotFoundException {
logger.debug(new MapLogEntry("retrieving" + Reference.class.getSimpleName()).And("id", id).And("fields", fieldSet));
this.censorFactory.censor(ExternalReferenceCensor.class).censor(fieldSet, null);
this.censorFactory.censor(ReferenceCensor.class).censor(fieldSet, null);
ExternalReferenceQuery query = this.queryFactory.query(ExternalReferenceQuery.class).authorize(AuthorizationFlags.OwnerOrPermission).ids(id);
ExternalReference model = this.builderFactory.builder(ExternalReferenceBuilder.class).authorize(AuthorizationFlags.OwnerOrPermission).build(fieldSet, query.firstAs(fieldSet));
ReferenceQuery query = this.queryFactory.query(ReferenceQuery.class).authorize(AuthorizationFlags.OwnerOrPermission).ids(id);
Reference model = this.builderFactory.builder(ReferenceBuilder.class).authorize(AuthorizationFlags.OwnerOrPermission).build(fieldSet, query.firstAs(fieldSet));
if (model == null)
throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{id, eu.eudat.model.ExternalReference.class.getSimpleName()}, LocaleContextHolder.getLocale()));
throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{id, Reference.class.getSimpleName()}, LocaleContextHolder.getLocale()));
this.auditService.track(AuditableAction.External_Reference_Lookup, Map.ofEntries(
new AbstractMap.SimpleEntry<String, Object>("id", id),
@ -120,16 +120,16 @@ public class ExternalReferenceController extends BaseController {
this.authorizationService.authorizeForce(Permission.AuthenticatedRole);
ExternalReferencesType externalReferencesType = ExternalReferencesType.of((short) externalType);
List<FetcherExternalReference> fetcherExternalReferences = this.externalReferenceService.searchExternalReference(externalReferencesType, query, type);
List<FetcherExternalReference> fetcherExternalReferences = this.referenceService.searchExternalReference(externalReferencesType, query, type);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<FetcherExternalReference>>().status(ApiMessageCode.NO_MESSAGE).payload(fetcherExternalReferences));
}
@DeleteMapping("{id}")
@Transactional
public void delete(@PathVariable("id") UUID id) throws MyForbiddenException, InvalidApplicationException {
logger.debug(new MapLogEntry("retrieving" + ExternalReference.class.getSimpleName()).And("id", id));
logger.debug(new MapLogEntry("retrieving" + Reference.class.getSimpleName()).And("id", id));
this.externalReferenceService.deleteAndSave(id);
this.referenceService.deleteAndSave(id);
this.auditService.track(AuditableAction.External_Reference_Delete, "id", id);
}

View File

@ -1,4 +1,4 @@
package eu.eudat.logic.services.externalreferences;
package eu.eudat.logic.services.references;
import gr.cite.tools.cache.CacheOptions;
import org.springframework.boot.context.properties.ConfigurationProperties;

View File

@ -1,4 +1,4 @@
package eu.eudat.logic.services.externalreferences;
package eu.eudat.logic.services.references;
import eu.eudat.logic.proxy.config.ExternalUrlCriteria;
import gr.cite.tools.cache.CacheService;

View File

@ -1,4 +1,4 @@
package eu.eudat.logic.services.externalreferences;
package eu.eudat.logic.services.references;
import eu.eudat.authorization.Permission;
import eu.eudat.commons.enums.ExternalReferencesType;
@ -18,7 +18,7 @@ import eu.eudat.logic.proxy.config.exceptions.HugeResultSet;
import eu.eudat.logic.proxy.config.exceptions.NoURLFound;
import eu.eudat.logic.proxy.fetching.RemoteFetcher;
import eu.eudat.logic.services.ApiContext;
import eu.eudat.model.deleter.ExternalReferenceDeleter;
import eu.eudat.model.deleter.ReferenceDeleter;
import eu.eudat.models.data.FetcherExternalReference;
import eu.eudat.queryable.QueryableList;
import gr.cite.commons.web.authz.service.AuthorizationService;
@ -36,9 +36,9 @@ import java.util.*;
import java.util.stream.Collectors;
@org.springframework.stereotype.Service
public class ExternalReferenceService {
public class ReferenceService {
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(ExternalReferenceService.class));
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(ReferenceService.class));
private final ApiContext apiContext;
private final UserScope userScope;
private final RemoteFetcher remoteFetcher;
@ -50,7 +50,7 @@ public class ExternalReferenceService {
private final MessageSource messageSource;
private final QueryFactory queryFactory;
public ExternalReferenceService(ApiContext apiContext,
public ReferenceService(ApiContext apiContext,
UserScope userScope,
RemoteFetcher remoteFetcher,
EntityManager entityManager,
@ -77,7 +77,7 @@ public class ExternalReferenceService {
this.authorizationService.authorizeForce(Permission.DeleteExternalReference);
this.deleterFactory.deleter(ExternalReferenceDeleter.class).deleteAndSaveByIds(List.of(id));
this.deleterFactory.deleter(ReferenceDeleter.class).deleteAndSaveByIds(List.of(id));
}
// external references: