Merge branch 'dmp-refactoring' of https://code-repo.d4science.org/MaDgiK-CITE/argos into dmp-refactoring

This commit is contained in:
mchouliara 2024-08-29 17:57:07 +03:00
commit 1149668e2f
10 changed files with 234 additions and 17 deletions

View File

@ -49,7 +49,11 @@ public class DescriptionElasticQuery extends ElasticQuery<DescriptionElasticEnti
private Instant finalizedAfter;
private Instant finalizedBefore;
private Collection<UUID> excludedIds;
private Collection<UUID> tenantIds;
private Collection<DescriptionStatus> statuses;
private NestedDescriptionTemplateElasticQuery descriptionTemplateSubQuery;
private NestedReferenceElasticQuery referenceSubQuery;
private NestedTagElasticQuery tagSubQuery;
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
public DescriptionElasticQuery like(String value) {
@ -114,6 +118,21 @@ public class DescriptionElasticQuery extends ElasticQuery<DescriptionElasticEnti
return this;
}
public DescriptionElasticQuery tenantIds(Collection<UUID> values) {
this.tenantIds = values;
return this;
}
public DescriptionElasticQuery tenantIds(UUID value) {
this.tenantIds = List.of(value);
return this;
}
public DescriptionElasticQuery tenantIds(UUID... value) {
this.tenantIds = Arrays.asList(value);
return this;
}
public DescriptionElasticQuery statuses(DescriptionStatus value) {
this.statuses = List.of(value);
return this;
@ -129,6 +148,21 @@ public class DescriptionElasticQuery extends ElasticQuery<DescriptionElasticEnti
return this;
}
public DescriptionElasticQuery descriptionTemplateSubQuery(NestedDescriptionTemplateElasticQuery subQuery) {
this.descriptionTemplateSubQuery = subQuery;
return this;
}
public DescriptionElasticQuery referenceSubQuery(NestedReferenceElasticQuery subQuery) {
this.referenceSubQuery = subQuery;
return this;
}
public DescriptionElasticQuery tagSubQuery(NestedTagElasticQuery subQuery) {
this.tagSubQuery = subQuery;
return this;
}
public DescriptionElasticQuery authorize(EnumSet<AuthorizationFlags> values) {
this.authorize = values;
return this;
@ -247,6 +281,9 @@ public class DescriptionElasticQuery extends ElasticQuery<DescriptionElasticEnti
if (this.excludedIds != null) {
predicates.add(this.not(this.containsUUID(this.elasticFieldOf(DescriptionElasticEntity._id), this.excludedIds)._toQuery())._toQuery());
}
if (this.tenantIds != null) {
predicates.add(this.containsUUID(this.elasticFieldOf(DescriptionElasticEntity._tenantId), this.tenantIds)._toQuery());
}
if (this.statuses != null) {
predicates.add(this.contains(this.elasticFieldOf(DescriptionElasticEntity._status), this.statuses.stream().map(DescriptionStatus::getValue).toList().toArray(new Short[this.statuses.size()]))._toQuery());
}
@ -265,6 +302,15 @@ public class DescriptionElasticQuery extends ElasticQuery<DescriptionElasticEnti
if (this.planSubQuery != null) {
predicates.add(this.planSubQuery.innerPath(DescriptionElasticEntity._plan).applyFilters());
}
if (this.descriptionTemplateSubQuery != null) {
predicates.add(this.nestedQuery( this.descriptionTemplateSubQuery.nestedPath(DescriptionElasticEntity._descriptionTemplate)).build()._toQuery());
}
if (this.referenceSubQuery != null) {
predicates.add(this.nestedQuery( this.referenceSubQuery.nestedPath(DescriptionElasticEntity._references)).build()._toQuery());
}
if (this.tagSubQuery != null) {
predicates.add(this.nestedQuery( this.tagSubQuery.nestedPath(DescriptionElasticEntity._tags)).build()._toQuery());
}
if (!predicates.isEmpty()) {
return this.and(predicates);
} else {

View File

@ -13,16 +13,95 @@ import org.springframework.context.annotation.Scope;
import org.springframework.data.elasticsearch.client.elc.ElasticsearchTemplate;
import org.springframework.stereotype.Component;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.*;
@Component
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class NestedDescriptionTemplateElasticQuery extends ElasticNestedQuery<NestedDescriptionTemplateElasticQuery, NestedDescriptionTemplateElasticEntity, UUID> {
private Collection<UUID> ids;
private Collection<UUID> groupIds;
private Collection<DescriptionTemplateVersionStatus> versionStatuses;
private Collection<UUID> excludedIds;
private Collection<UUID> excludedGroupIds;
private String nestedPath;
public NestedDescriptionTemplateElasticQuery ids(UUID value) {
this.ids = List.of(value);
return this;
}
public NestedDescriptionTemplateElasticQuery ids(UUID... value) {
this.ids = Arrays.asList(value);
return this;
}
public NestedDescriptionTemplateElasticQuery ids(Collection<UUID> value) {
this.ids = value;
return this;
}
public NestedDescriptionTemplateElasticQuery groupIds(UUID value) {
this.groupIds = List.of(value);
return this;
}
public NestedDescriptionTemplateElasticQuery groupIds(UUID... value) {
this.groupIds = Arrays.asList(value);
return this;
}
public NestedDescriptionTemplateElasticQuery groupIds(Collection<UUID> value) {
this.groupIds = value;
return this;
}
public NestedDescriptionTemplateElasticQuery versionStatuses(DescriptionTemplateVersionStatus value) {
this.versionStatuses = List.of(value);
return this;
}
public NestedDescriptionTemplateElasticQuery versionStatuses(DescriptionTemplateVersionStatus... value) {
this.versionStatuses = Arrays.asList(value);
return this;
}
public NestedDescriptionTemplateElasticQuery versionStatuses(Collection<DescriptionTemplateVersionStatus> value) {
this.versionStatuses = value;
return this;
}
public NestedDescriptionTemplateElasticQuery excludedIds(UUID value) {
this.excludedIds = List.of(value);
return this;
}
public NestedDescriptionTemplateElasticQuery excludedIds(UUID... value) {
this.excludedIds = Arrays.asList(value);
return this;
}
public NestedDescriptionTemplateElasticQuery excludedIds(Collection<UUID> value) {
this.excludedIds = value;
return this;
}
public NestedDescriptionTemplateElasticQuery excludedGroupIds(UUID value) {
this.excludedGroupIds = List.of(value);
return this;
}
public NestedDescriptionTemplateElasticQuery excludedGroupIds(UUID... value) {
this.excludedGroupIds = Arrays.asList(value);
return this;
}
public NestedDescriptionTemplateElasticQuery excludedGroupIds(Collection<UUID> value) {
this.excludedGroupIds = value;
return this;
}
@Override
public NestedDescriptionTemplateElasticQuery nestedPath(String value) {
this.nestedPath = value;
@ -54,7 +133,28 @@ public class NestedDescriptionTemplateElasticQuery extends ElasticNestedQuery<Ne
@Override
protected Query applyFilters() {
return null;
List<Query> predicates= new ArrayList<>();
if (this.ids != null) {
predicates.add(this.containsUUID(this.elasticFieldOf(NestedDescriptionTemplateElasticEntity._id), this.ids)._toQuery());
}
if (this.groupIds != null) {
predicates.add(this.containsUUID(this.elasticFieldOf(NestedDescriptionTemplateElasticEntity._groupId), this.groupIds)._toQuery());
}
if (this.excludedIds != null) {
predicates.add(this.not(this.containsUUID(this.elasticFieldOf(NestedDescriptionTemplateElasticEntity._id), this.ids)._toQuery())._toQuery());
}
if (this.excludedGroupIds != null) {
predicates.add(this.not(this.containsUUID(this.elasticFieldOf(NestedDescriptionTemplateElasticEntity._groupId), this.groupIds)._toQuery())._toQuery());
}
if (this.versionStatuses != null) {
predicates.add(this.contains(this.elasticFieldOf(NestedDescriptionTemplateElasticEntity._versionStatus), this.versionStatuses.stream().map(DescriptionTemplateVersionStatus::getValue).toList().toArray(new Short[this.versionStatuses.size()]))._toQuery());
}
if (!predicates.isEmpty()) {
return this.and(predicates);
} else {
return null;
}
}
@Override

View File

@ -56,7 +56,7 @@ public class NestedReferenceElasticQuery extends ElasticNestedQuery<NestedRefere
@Override
protected Boolean isFalseQuery() {
return false;
return this.isEmpty(this.ids);
}
@Override

View File

@ -18,8 +18,24 @@ import java.util.*;
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class NestedTagElasticQuery extends ElasticNestedQuery<NestedTagElasticQuery, NestedTagElasticEntity, UUID> {
private Collection<UUID> ids;
private String nestedPath;
public NestedTagElasticQuery ids(UUID value) {
this.ids = List.of(value);
return this;
}
public NestedTagElasticQuery ids(UUID... value) {
this.ids = Arrays.asList(value);
return this;
}
public NestedTagElasticQuery ids(Collection<UUID> value) {
this.ids = value;
return this;
}
@Override
public NestedTagElasticQuery nestedPath(String value) {
this.nestedPath = value;
@ -40,9 +56,7 @@ public class NestedTagElasticQuery extends ElasticNestedQuery<NestedTagElasticQu
}
@Override
protected Boolean isFalseQuery() {
return false;
}
protected Boolean isFalseQuery() { return this.isEmpty(this.ids); }
@Override
protected Query applyAuthZ() {
@ -51,7 +65,16 @@ public class NestedTagElasticQuery extends ElasticNestedQuery<NestedTagElasticQu
@Override
protected Query applyFilters() {
return null;
List<Query> predicates = new ArrayList<>();
if (ids != null) {
predicates.add(this.containsUUID(this.elasticFieldOf(NestedTagElasticEntity._id), this.ids)._toQuery());
}
if (!predicates.isEmpty()) {
return this.and(predicates);
} else {
return null;
}
}
@Override

View File

@ -161,10 +161,10 @@ public class DescriptionLookup extends Lookup {
if (this.finalizedBefore != null) query.finalizedBefore(this.finalizedBefore);
if (this.planSubQuery != null) query.planSubQuery(this.planSubQuery.enrichElasticInner(queryFactory));
if (this.tenantSubQuery != null) throw new UnsupportedOperationException("");
if (this.descriptionTemplateSubQuery != null) throw new UnsupportedOperationException("");
if (this.descriptionReferenceSubQuery != null) throw new UnsupportedOperationException("");
if (this.descriptionTagSubQuery != null) throw new UnsupportedOperationException("");
if (this.tenantSubQuery != null && this.tenantSubQuery.getIds() != null && !this.tenantSubQuery.getIds().isEmpty()) query.tenantIds(this.tenantSubQuery.getIds());
if (this.descriptionTemplateSubQuery != null) query.descriptionTemplateSubQuery(this.descriptionTemplateSubQuery.enrichElasticInner(queryFactory));
if (this.descriptionReferenceSubQuery != null) query.referenceSubQuery(this.descriptionReferenceSubQuery.enrichElasticInner(queryFactory));
if (this.descriptionTagSubQuery != null) query.tagSubQuery(this.descriptionTagSubQuery.enrichElasticInner(queryFactory));
this.enrichCommon(query);

View File

@ -1,6 +1,7 @@
package org.opencdmp.query.lookup;
import org.opencdmp.commons.enums.IsActive;
import org.opencdmp.elastic.query.NestedReferenceElasticQuery;
import org.opencdmp.query.DescriptionReferenceQuery;
import gr.cite.tools.data.query.Lookup;
import gr.cite.tools.data.query.QueryFactory;
@ -73,4 +74,17 @@ public class DescriptionReferenceLookup extends Lookup {
return query;
}
public NestedReferenceElasticQuery enrichElasticInner(QueryFactory queryFactory) {
NestedReferenceElasticQuery query = queryFactory.query(NestedReferenceElasticQuery.class);
if (this.ids != null) throw new UnsupportedOperationException("");
if (this.excludedIds != null) throw new UnsupportedOperationException("");
if (this.isActives != null) throw new UnsupportedOperationException("");
if (this.descriptionIds != null) throw new UnsupportedOperationException("");
if (this.referenceIds != null) query.ids(this.referenceIds);
this.enrichCommon(query);
return query;
}
}

View File

@ -1,6 +1,7 @@
package org.opencdmp.query.lookup;
import org.opencdmp.commons.enums.IsActive;
import org.opencdmp.elastic.query.NestedTagElasticQuery;
import org.opencdmp.query.DescriptionTagQuery;
import gr.cite.tools.data.query.Lookup;
import gr.cite.tools.data.query.QueryFactory;
@ -73,4 +74,16 @@ public class DescriptionTagLookup extends Lookup {
return query;
}
public NestedTagElasticQuery enrichElasticInner(QueryFactory queryFactory) {
NestedTagElasticQuery query = queryFactory.query(NestedTagElasticQuery.class);
if (this.ids != null) throw new UnsupportedOperationException("");
if (this.excludedIds != null) throw new UnsupportedOperationException("");
if (this.isActives != null) throw new UnsupportedOperationException("");
if (this.descriptionIds != null) throw new UnsupportedOperationException("");
if (this.tagIds != null) query.ids(this.tagIds);
this.enrichCommon(query);
return query;
}
}

View File

@ -5,6 +5,7 @@ import gr.cite.tools.data.query.QueryFactory;
import org.opencdmp.commons.enums.DescriptionTemplateStatus;
import org.opencdmp.commons.enums.DescriptionTemplateVersionStatus;
import org.opencdmp.commons.enums.IsActive;
import org.opencdmp.elastic.query.NestedDescriptionTemplateElasticQuery;
import org.opencdmp.query.DescriptionTemplateQuery;
import java.util.List;
@ -150,4 +151,23 @@ public class DescriptionTemplateLookup extends Lookup {
return query;
}
public NestedDescriptionTemplateElasticQuery enrichElasticInner(QueryFactory queryFactory) {
NestedDescriptionTemplateElasticQuery query = queryFactory.query(NestedDescriptionTemplateElasticQuery.class);
if (this.ids != null) query.ids(this.ids);
if (this.groupIds != null) query.groupIds(this.groupIds);
if (this.versionStatuses != null) query.versionStatuses(this.versionStatuses);
if (this.excludedIds != null) query.excludedIds(this.excludedIds);
if (this.excludedGroupIds != null) query.excludedGroupIds(this.excludedGroupIds);
if (this.like != null) throw new UnsupportedOperationException("");
if (this.isActive != null) throw new UnsupportedOperationException("");
if (this.statuses != null) throw new UnsupportedOperationException("");
if (this.typeIds != null) throw new UnsupportedOperationException("");
if (this.versions != null) throw new UnsupportedOperationException("");
if (this.onlyCanEdit != null) throw new UnsupportedOperationException("");
this.enrichCommon(query);
return query;
}
}

View File

@ -34,8 +34,8 @@
<div class="col-12">
<mat-form-field class="w-100">
<mat-label>{{'REFERENCE-LISTING.FILTER.TYPE' | translate}}</mat-label>
<app-single-auto-complete [(ngModel)]="internalFilters.typeIds" placeholder="{{'REFERENCE-LISTING.FILTER.TYPE' | translate}}" [configuration]="referenceTypeService.singleAutocompleteConfiguration">
</app-single-auto-complete>
<app-multiple-auto-complete [(ngModel)]="internalFilters.typeIds" placeholder="{{'REFERENCE-LISTING.FILTER.TYPE' | translate}}" [configuration]="referenceTypeService.multipleAutocompleteConfiguration">
</app-multiple-auto-complete>
</mat-form-field>
</div>
</div>

View File

@ -44,7 +44,8 @@ export class ReferenceListingComponent extends BaseListingComponent<Reference, R
nameof<Reference>(x => x.label),
nameof<Reference>(x => x.source),
nameof<Reference>(x => x.sourceType),
nameof<Reference>(x => x.type),
nameof<Reference>(x => x.type.id),
nameof<Reference>(x => x.type.name),
nameof<Reference>(x => x.updatedAt),
nameof<Reference>(x => x.createdAt),
nameof<Reference>(x => x.hash),
@ -121,7 +122,7 @@ export class ReferenceListingComponent extends BaseListingComponent<Reference, R
pipe: this.pipeService.getPipe<ReferenceSourceTypePipe>(ReferenceSourceTypePipe)
},
{
prop: nameof<Reference>(x => x.type),
prop: nameof<Reference>(x => x.type.name),
sortable: true,
languageName: 'REFERENCE-LISTING.FIELDS.TYPE',
valueFunction: (item: Reference) => (item?.type?.name)