This commit is contained in:
Efstratios Giannopoulos 2024-02-07 17:23:47 +02:00
parent 6e767f1e5e
commit f8251aaf43
3 changed files with 27 additions and 3 deletions

View File

@ -36,6 +36,7 @@ public class ReferenceQuery extends QueryBase<ReferenceEntity> {
private Collection<ReferenceType> referenceTypes; private Collection<ReferenceType> referenceTypes;
private Collection<String> references; private Collection<String> references;
private Collection<String> sources;
private Collection<UUID> excludedIds; private Collection<UUID> excludedIds;
@ -111,6 +112,21 @@ public class ReferenceQuery extends QueryBase<ReferenceEntity> {
return this; return this;
} }
public ReferenceQuery sources(String value) {
this.sources = List.of(value);
return this;
}
public ReferenceQuery sources(String... value) {
this.sources = Arrays.asList(value);
return this;
}
public ReferenceQuery sources(Collection<String> values) {
this.sources = values;
return this;
}
public ReferenceQuery excludedIds(Collection<UUID> values) { public ReferenceQuery excludedIds(Collection<UUID> values) {
this.excludedIds = values; this.excludedIds = values;
return this; return this;
@ -177,7 +193,7 @@ public class ReferenceQuery extends QueryBase<ReferenceEntity> {
@Override @Override
protected Boolean isFalseQuery() { protected Boolean isFalseQuery() {
return this.isEmpty(this.ids) || this.isEmpty(this.isActives) || this.isEmpty(this.excludedIds) || this.isEmpty(this.referenceTypes) || this.isEmpty(this.referenceSourceTypes)|| this.isFalseQuery(this.dmpReferenceQuery); return this.isEmpty(this.ids) || this.isEmpty(this.isActives) || this.isEmpty(this.sources) ||this.isEmpty(this.excludedIds) || this.isEmpty(this.referenceTypes) || this.isEmpty(this.referenceSourceTypes)|| this.isFalseQuery(this.dmpReferenceQuery);
} }
@Override @Override
@ -219,6 +235,12 @@ public class ReferenceQuery extends QueryBase<ReferenceEntity> {
inClause.value(item); inClause.value(item);
predicates.add(inClause); predicates.add(inClause);
} }
if (this.sources != null) {
CriteriaBuilder.In<String> inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(ReferenceEntity._source));
for (String item : this.sources)
inClause.value(item);
predicates.add(inClause);
}
if (this.excludedIds != null) { if (this.excludedIds != null) {
CriteriaBuilder.In<UUID> notInClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(ReferenceEntity._id)); CriteriaBuilder.In<UUID> notInClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(ReferenceEntity._id));
for (UUID item : this.excludedIds) for (UUID item : this.excludedIds)

View File

@ -509,12 +509,13 @@ public class DescriptionServiceImpl implements DescriptionService {
referenceEntity = this.entityManager.find(ReferenceEntity.class, referencePersist.getId()); referenceEntity = this.entityManager.find(ReferenceEntity.class, referencePersist.getId());
if (referenceEntity == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{referencePersist.getId(), Reference.class.getSimpleName()}, LocaleContextHolder.getLocale())); if (referenceEntity == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{referencePersist.getId(), Reference.class.getSimpleName()}, LocaleContextHolder.getLocale()));
} else { } else {
referenceEntity = this.queryFactory.query(ReferenceQuery.class).sourceTypes(referencePersist.getSourceType()).references(referencePersist.getReference()).first(); referenceEntity = this.queryFactory.query(ReferenceQuery.class).sourceTypes(referencePersist.getSourceType()).sources(referencePersist.getSource()).isActive(IsActive.Active).references(referencePersist.getReference()).first();
if (referenceEntity == null){ if (referenceEntity == null){
referenceEntity = new ReferenceEntity(); referenceEntity = new ReferenceEntity();
referenceEntity.setId(UUID.randomUUID()); referenceEntity.setId(UUID.randomUUID());
referenceEntity.setIsActive(IsActive.Active); referenceEntity.setIsActive(IsActive.Active);
referenceEntity.setCreatedAt(Instant.now()); referenceEntity.setCreatedAt(Instant.now());
referenceEntity.setType(referencePersist.getType());
referenceEntity.setDefinition(this.xmlHandlingService.toXmlSafe(this.buildDefinitionEntity(referencePersist.getDefinition()))); referenceEntity.setDefinition(this.xmlHandlingService.toXmlSafe(this.buildDefinitionEntity(referencePersist.getDefinition())));
referenceEntity.setUpdatedAt(Instant.now()); referenceEntity.setUpdatedAt(Instant.now());

View File

@ -647,12 +647,13 @@ public class DmpServiceImpl implements DmpService {
referenceEntity = this.entityManager.find(ReferenceEntity.class, referencePersist.getId()); referenceEntity = this.entityManager.find(ReferenceEntity.class, referencePersist.getId());
if (referenceEntity == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{referencePersist.getId(), Reference.class.getSimpleName()}, LocaleContextHolder.getLocale())); if (referenceEntity == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{referencePersist.getId(), Reference.class.getSimpleName()}, LocaleContextHolder.getLocale()));
} else { } else {
referenceEntity = this.queryFactory.query(ReferenceQuery.class).sourceTypes(referencePersist.getSourceType()).references(referencePersist.getReference()).first(); referenceEntity = this.queryFactory.query(ReferenceQuery.class).sourceTypes(referencePersist.getSourceType()).sources(referencePersist.getSource()).isActive(IsActive.Active).references(referencePersist.getReference()).first();
if (referenceEntity == null){ if (referenceEntity == null){
referenceEntity = new ReferenceEntity(); referenceEntity = new ReferenceEntity();
referenceEntity.setId(UUID.randomUUID()); referenceEntity.setId(UUID.randomUUID());
referenceEntity.setIsActive(IsActive.Active); referenceEntity.setIsActive(IsActive.Active);
referenceEntity.setCreatedAt(Instant.now()); referenceEntity.setCreatedAt(Instant.now());
referenceEntity.setType(referencePersist.getType());
referenceEntity.setDefinition(this.xmlHandlingService.toXmlSafe(this.buildDefinitionEntity(referencePersist.getDefinition()))); referenceEntity.setDefinition(this.xmlHandlingService.toXmlSafe(this.buildDefinitionEntity(referencePersist.getDefinition())));
referenceEntity.setUpdatedAt(Instant.now()); referenceEntity.setUpdatedAt(Instant.now());