Add excludedTags, bug fixes

This commit is contained in:
Efstratios Giannopoulos 2024-01-03 14:06:26 +02:00
parent 88b4bb0d2f
commit 71343c51e5
10 changed files with 81 additions and 152 deletions

View File

@ -1,8 +1,8 @@
package eu.eudat.model.builder.descriptiontemplatedefinition.fielddata; package eu.eudat.model.builder.descriptiontemplatedefinition.fielddata;
import eu.eudat.commons.types.descriptiontemplate.fielddata.DataRepositoryDataEntity; import eu.eudat.commons.types.descriptiontemplate.fielddata.PublicationRepositoryDataEntity;
import eu.eudat.convention.ConventionService; import eu.eudat.convention.ConventionService;
import eu.eudat.model.descriptiontemplatedefinition.fielddata.DataRepositoryData; import eu.eudat.model.descriptiontemplatedefinition.fielddata.PublicationRepositoryData;
import gr.cite.tools.fieldset.FieldSet; import gr.cite.tools.fieldset.FieldSet;
import gr.cite.tools.logging.LoggerService; import gr.cite.tools.logging.LoggerService;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -13,19 +13,19 @@ import org.springframework.stereotype.Component;
@Component @Component
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class PublicationRepositoryDataBuilder extends BaseFieldDataBuilder<DataRepositoryData, DataRepositoryDataEntity> { public class PublicationRepositoryDataBuilder extends BaseFieldDataBuilder<PublicationRepositoryData, PublicationRepositoryDataEntity> {
@Autowired @Autowired
public PublicationRepositoryDataBuilder(ConventionService conventionService) { public PublicationRepositoryDataBuilder(ConventionService conventionService) {
super(conventionService, new LoggerService(LoggerFactory.getLogger(PublicationRepositoryDataBuilder.class))); super(conventionService, new LoggerService(LoggerFactory.getLogger(PublicationRepositoryDataBuilder.class)));
} }
protected DataRepositoryData getInstance() { protected PublicationRepositoryData getInstance() {
return new DataRepositoryData(); return new PublicationRepositoryData();
} }
@Override @Override
protected void buildChild(FieldSet fields, DataRepositoryDataEntity d, DataRepositoryData m) { protected void buildChild(FieldSet fields, PublicationRepositoryDataEntity d, PublicationRepositoryData m) {
if (fields.hasField(this.asIndexer(DataRepositoryData._multiAutoComplete))) m.setMultiAutoComplete(d.getMultiAutoComplete()); if (fields.hasField(this.asIndexer(PublicationRepositoryData._multiAutoComplete))) m.setMultiAutoComplete(d.getMultiAutoComplete());
} }
} }

View File

@ -22,7 +22,8 @@ import java.util.*;
public class TagQuery extends QueryBase<TagEntity> { public class TagQuery extends QueryBase<TagEntity> {
private String like; private String like;
private Collection<String> labels; private Collection<String> tags;
private Collection<String> excludedTags;
private Collection<UUID> ids; private Collection<UUID> ids;
@ -57,18 +58,33 @@ public class TagQuery extends QueryBase<TagEntity> {
return this; return this;
} }
public TagQuery labels(String value) { public TagQuery tags(String value) {
this.labels = List.of(value); this.tags = List.of(value);
return this; return this;
} }
public TagQuery labels(String... value) { public TagQuery tags(String... value) {
this.labels = Arrays.asList(value); this.tags = Arrays.asList(value);
return this; return this;
} }
public TagQuery labels(Collection<String> values) { public TagQuery tags(Collection<String> values) {
this.labels = values; this.tags = values;
return this;
}
public TagQuery excludedTags(String value) {
this.excludedTags = List.of(value);
return this;
}
public TagQuery excludedTags(String... value) {
this.excludedTags = Arrays.asList(value);
return this;
}
public TagQuery excludedTags(Collection<String> values) {
this.excludedTags = values;
return this; return this;
} }
@ -127,7 +143,8 @@ public class TagQuery extends QueryBase<TagEntity> {
return return
this.isEmpty(this.ids) || this.isEmpty(this.ids) ||
this.isEmpty(this.isActives) || this.isEmpty(this.isActives) ||
this.isEmpty(this.labels) || this.isEmpty(this.tags) ||
this.isEmpty(this.excludedTags) ||
this.isEmpty(this.excludedIds) || this.isEmpty(this.excludedIds) ||
this.isEmpty(this.createdByIds); this.isEmpty(this.createdByIds);
} }
@ -149,12 +166,18 @@ public class TagQuery extends QueryBase<TagEntity> {
inClause.value(item); inClause.value(item);
predicates.add(inClause); predicates.add(inClause);
} }
if (this.labels != null) { if (this.tags != null) {
CriteriaBuilder.In<String> inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(TagEntity._label)); CriteriaBuilder.In<String> inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(TagEntity._label));
for (String item : this.labels) for (String item : this.tags)
inClause.value(item); inClause.value(item);
predicates.add(inClause); predicates.add(inClause);
} }
if (this.excludedTags != null) {
CriteriaBuilder.In<String> notInClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(TagEntity._label));
for (String item : this.excludedTags)
notInClause.value(item);
predicates.add(notInClause.not());
}
if (this.excludedIds != null) { if (this.excludedIds != null) {
CriteriaBuilder.In<UUID> notInClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(TagEntity._id)); CriteriaBuilder.In<UUID> notInClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(TagEntity._id));
for (UUID item : this.excludedIds) for (UUID item : this.excludedIds)

View File

@ -20,6 +20,10 @@ public class TagLookup extends Lookup {
private List<UUID> createdByIds; private List<UUID> createdByIds;
private List<String> tags;
private List<String> excludedTags;
public String getLike() { public String getLike() {
return like; return like;
} }
@ -60,11 +64,29 @@ public class TagLookup extends Lookup {
this.createdByIds = createdByIds; this.createdByIds = createdByIds;
} }
public List<String> getTags() {
return tags;
}
public void setTags(List<String> tags) {
this.tags = tags;
}
public List<String> getExcludedTags() {
return excludedTags;
}
public void setExcludedTags(List<String> excludedTags) {
this.excludedTags = excludedTags;
}
public TagQuery enrich(QueryFactory queryFactory) { public TagQuery enrich(QueryFactory queryFactory) {
TagQuery query = queryFactory.query(TagQuery.class); TagQuery query = queryFactory.query(TagQuery.class);
if (this.like != null) query.like(this.like); if (this.like != null) query.like(this.like);
if (this.ids != null) query.ids(this.ids); if (this.ids != null) query.ids(this.ids);
if (this.excludedIds != null) query.excludedIds(this.excludedIds); if (this.excludedIds != null) query.excludedIds(this.excludedIds);
if (this.tags != null) query.tags(this.tags);
if (this.excludedTags != null) query.excludedTags(this.excludedTags);
if (this.isActive != null) query.isActive(this.isActive); if (this.isActive != null) query.isActive(this.isActive);
if (this.createdByIds != null) query.createdByIds(this.createdByIds); if (this.createdByIds != null) query.createdByIds(this.createdByIds);

View File

@ -371,7 +371,7 @@ public class DescriptionServiceImpl implements DescriptionService {
List<DescriptionTagEntity> items = this.queryFactory.query(DescriptionTagQuery.class).isActive(IsActive.Active).descriptionIds(id).collect(); List<DescriptionTagEntity> items = this.queryFactory.query(DescriptionTagQuery.class).isActive(IsActive.Active).descriptionIds(id).collect();
List<TagEntity> tagsAlreadyLinked = this.queryFactory.query(TagQuery.class).isActive(IsActive.Active).ids(items.stream().map(DescriptionTagEntity::getTagId).collect(Collectors.toList())).collect(); List<TagEntity> tagsAlreadyLinked = this.queryFactory.query(TagQuery.class).isActive(IsActive.Active).ids(items.stream().map(DescriptionTagEntity::getTagId).collect(Collectors.toList())).collect();
List<String> tagLabelsToAdd = tagLabels.stream().filter(x-> tagsAlreadyLinked.stream().noneMatch(y-> y.getLabel() != null && y.getLabel().equalsIgnoreCase(x))).toList(); List<String> tagLabelsToAdd = tagLabels.stream().filter(x-> tagsAlreadyLinked.stream().noneMatch(y-> y.getLabel() != null && y.getLabel().equalsIgnoreCase(x))).toList();
List<TagEntity> existingTags = this.queryFactory.query(TagQuery.class).isActive(IsActive.Active).labels(tagLabelsToAdd).createdByIds(this.userScope.getUserId()).collect(); List<TagEntity> existingTags = this.queryFactory.query(TagQuery.class).isActive(IsActive.Active).tags(tagLabelsToAdd).createdByIds(this.userScope.getUserId()).collect();
List<UUID> updatedCreatedIds = new ArrayList<>(); List<UUID> updatedCreatedIds = new ArrayList<>();
for (String tagLabel : tagLabels) { for (String tagLabel : tagLabels) {

View File

@ -1,22 +0,0 @@
package eu.eudat.cache;
import eu.eudat.logic.proxy.config.ExternalUrlCriteria;
import org.springframework.cache.interceptor.KeyGenerator;
import java.lang.reflect.Method;
public class ExternalUrlsKeyGenerator implements KeyGenerator {
@Override
public Object generate(Object o, Method method, Object... params) {
StringBuffer stringBuffer = new StringBuffer();
stringBuffer.append(o.getClass().getSimpleName()).append("_");
stringBuffer.append(method.getName()).append("_");
for (Object param: params) {
if (param instanceof ExternalUrlCriteria) {
ExternalUrlCriteria externalUrlCriteria = (ExternalUrlCriteria) param;
stringBuffer.append(externalUrlCriteria);
}
}
return stringBuffer.toString();
}
}

View File

@ -1,60 +0,0 @@
package eu.eudat.cache;
import com.github.benmanes.caffeine.cache.Caffeine;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cache.CacheManager;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.cache.caffeine.CaffeineCache;
import org.springframework.cache.interceptor.KeyGenerator;
import org.springframework.cache.support.SimpleCacheManager;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;
@Component
@EnableCaching
public class ResponsesCache {
private static final Logger logger = LoggerFactory.getLogger(ResponsesCache.class);
public static long HOW_MANY = 30;
public static TimeUnit TIME_UNIT = TimeUnit.MINUTES;
@Bean
public CacheManager cacheManager5() {
logger.info("Loading ResponsesCache...");
SimpleCacheManager simpleCacheManager = new SimpleCacheManager();
List<CaffeineCache> caches = new ArrayList<CaffeineCache>();
caches.add(new CaffeineCache("repositories", Caffeine.newBuilder().expireAfterAccess(HOW_MANY, TIME_UNIT).build()));
caches.add(new CaffeineCache("pubrepos", Caffeine.newBuilder().expireAfterAccess(HOW_MANY, TIME_UNIT).build()));
caches.add(new CaffeineCache("journals", Caffeine.newBuilder().expireAfterAccess(HOW_MANY, TIME_UNIT).build()));
caches.add(new CaffeineCache("taxonomies", Caffeine.newBuilder().expireAfterAccess(HOW_MANY, TIME_UNIT).build()));
caches.add(new CaffeineCache("publications", Caffeine.newBuilder().expireAfterAccess(HOW_MANY, TIME_UNIT).build()));
caches.add(new CaffeineCache("grants", Caffeine.newBuilder().expireAfterAccess(HOW_MANY, TIME_UNIT).build()));
caches.add(new CaffeineCache("projects", Caffeine.newBuilder().expireAfterAccess(HOW_MANY, TIME_UNIT).build()));
caches.add(new CaffeineCache("funders", Caffeine.newBuilder().expireAfterAccess(HOW_MANY, TIME_UNIT).build()));
caches.add(new CaffeineCache("organisations", Caffeine.newBuilder().expireAfterAccess(HOW_MANY, TIME_UNIT).build()));
caches.add(new CaffeineCache("registries", Caffeine.newBuilder().expireAfterAccess(HOW_MANY, TIME_UNIT).build()));
caches.add(new CaffeineCache("services", Caffeine.newBuilder().expireAfterAccess(HOW_MANY, TIME_UNIT).build()));
caches.add(new CaffeineCache("tags", Caffeine.newBuilder().expireAfterAccess(HOW_MANY, TIME_UNIT).build()));
caches.add(new CaffeineCache("researchers", Caffeine.newBuilder().expireAfterAccess(HOW_MANY, TIME_UNIT).build()));
caches.add(new CaffeineCache("externalDatasets", Caffeine.newBuilder().expireAfterAccess(HOW_MANY, TIME_UNIT).build()));
caches.add(new CaffeineCache("currencies", Caffeine.newBuilder().expireAfterAccess(HOW_MANY, TIME_UNIT).build()));
caches.add(new CaffeineCache("licenses", Caffeine.newBuilder().expireAfterAccess(HOW_MANY, TIME_UNIT).build()));
simpleCacheManager.setCaches(caches);
logger.info("OK");
return simpleCacheManager;
}
@Bean(name = "externalUrlsKeyGenerator")
private KeyGenerator externalUrlsKeyGenerator() {
return new ExternalUrlsKeyGenerator();
}
}

View File

@ -29,7 +29,6 @@ public class WebMVCConfiguration implements WebMvcConfigurer {
@Override @Override
public void addInterceptors(InterceptorRegistry registry) { public void addInterceptors(InterceptorRegistry registry) {
// registry.addInterceptor(new RequestInterceptor(this.apiContext.getHelpersService().getLoggerService()));
registry.addWebRequestInterceptor(userInterceptor).order(1); registry.addWebRequestInterceptor(userInterceptor).order(1);
} }
} }

View File

@ -1,33 +0,0 @@
package eu.eudat.controllers.interceptors;
import eu.eudat.types.WarningLevel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.HandlerInterceptor;
import java.util.Date;
/**
* Created by ikalyvas on 3/1/2018.
*/
@Component
public class RequestInterceptor implements HandlerInterceptor {
private static final Logger logger = LoggerFactory.getLogger(RequestInterceptor.class);
@Autowired
public RequestInterceptor() {
}
@Override
public boolean preHandle(HttpServletRequest request,
HttpServletResponse response, Object handler) throws Exception {
String reqUri = request.getRequestURI();
logger.info("Call to " + reqUri + " method: " + request.getMethod() + " at: " + new Date(), WarningLevel.INFO);
return HandlerInterceptor.super.preHandle(request, response, handler);
}
}

View File

@ -1,7 +1,7 @@
deposit: deposit:
sources: sources:
- url: http://localhost:8082 - url: http://localhost:8082
codes: [ zenodo ] repositoryId: zenodo
issuer-url: ${ZENODO_ISSUER_URI:IDP_APIKEY_ISSUER_URI} issuer-url: ${ZENODO_ISSUER_URI:IDP_APIKEY_ISSUER_URI}
client-id: ${ZENODO_DEPOSIT_CLIENT_ID:} client-id: ${ZENODO_DEPOSIT_CLIENT_ID:}
client-secret: ${ZENODO_DEPOSIT_CLIENT_SECRET:} client-secret: ${ZENODO_DEPOSIT_CLIENT_SECRET:}

View File

@ -67,23 +67,23 @@ export class DmpEditorResolver extends BaseEditorResolver {
public static blueprintLookupFields(prefix?: string): string[] { public static blueprintLookupFields(prefix?: string): string[] {
return [ return [
[prefix ?? '', nameof<DmpBlueprint>(x => x.id)].join('.'), prefix ? prefix + '.' : '' + [nameof<DmpBlueprint>(x => x.id)].join('.'),
[prefix ?? '', nameof<DmpBlueprint>(x => x.definition)].join('.'), prefix ? prefix + '.' : '' + [nameof<DmpBlueprint>(x => x.definition)].join('.'),
[prefix ?? '', nameof<DmpBlueprint>(x => x.definition), nameof<DmpBlueprintDefinition>(x => x.sections), nameof<DmpBlueprintDefinitionSection>(x => x.id)].join('.'), prefix ? prefix + '.' : '' + [nameof<DmpBlueprint>(x => x.definition), nameof<DmpBlueprintDefinition>(x => x.sections), nameof<DmpBlueprintDefinitionSection>(x => x.id)].join('.'),
[prefix ?? '', nameof<DmpBlueprint>(x => x.definition), nameof<DmpBlueprintDefinition>(x => x.sections), nameof<DmpBlueprintDefinitionSection>(x => x.label)].join('.'), prefix ? prefix + '.' : '' + [nameof<DmpBlueprint>(x => x.definition), nameof<DmpBlueprintDefinition>(x => x.sections), nameof<DmpBlueprintDefinitionSection>(x => x.label)].join('.'),
[prefix ?? '', nameof<DmpBlueprint>(x => x.definition), nameof<DmpBlueprintDefinition>(x => x.sections), nameof<DmpBlueprintDefinitionSection>(x => x.ordinal)].join('.'), prefix ? prefix + '.' : '' + [nameof<DmpBlueprint>(x => x.definition), nameof<DmpBlueprintDefinition>(x => x.sections), nameof<DmpBlueprintDefinitionSection>(x => x.ordinal)].join('.'),
[prefix ?? '', nameof<DmpBlueprint>(x => x.definition), nameof<DmpBlueprintDefinition>(x => x.sections), nameof<DmpBlueprintDefinitionSection>(x => x.hasTemplates)].join('.'), prefix ? prefix + '.' : '' + [nameof<DmpBlueprint>(x => x.definition), nameof<DmpBlueprintDefinition>(x => x.sections), nameof<DmpBlueprintDefinitionSection>(x => x.hasTemplates)].join('.'),
[prefix ?? '', nameof<DmpBlueprint>(x => x.definition), nameof<DmpBlueprintDefinition>(x => x.sections), nameof<DmpBlueprintDefinitionSection>(x => x.descriptionTemplates), nameof<DescriptionTemplatesInSection>(x => x.id)].join('.'), prefix ? prefix + '.' : '' + [nameof<DmpBlueprint>(x => x.definition), nameof<DmpBlueprintDefinition>(x => x.sections), nameof<DmpBlueprintDefinitionSection>(x => x.descriptionTemplates), nameof<DescriptionTemplatesInSection>(x => x.id)].join('.'),
[prefix ?? '', nameof<DmpBlueprint>(x => x.definition), nameof<DmpBlueprintDefinition>(x => x.sections), nameof<DmpBlueprintDefinitionSection>(x => x.descriptionTemplates), nameof<DescriptionTemplatesInSection>(x => x.descriptionTemplateId)].join('.'), prefix ? prefix + '.' : '' + [nameof<DmpBlueprint>(x => x.definition), nameof<DmpBlueprintDefinition>(x => x.sections), nameof<DmpBlueprintDefinitionSection>(x => x.descriptionTemplates), nameof<DescriptionTemplatesInSection>(x => x.descriptionTemplateId)].join('.'),
[prefix ?? '', nameof<DmpBlueprint>(x => x.definition), nameof<DmpBlueprintDefinition>(x => x.sections), nameof<DmpBlueprintDefinitionSection>(x => x.fields), nameof<FieldInSection>(x => x.id)].join('.'), prefix ? prefix + '.' : '' + [nameof<DmpBlueprint>(x => x.definition), nameof<DmpBlueprintDefinition>(x => x.sections), nameof<DmpBlueprintDefinitionSection>(x => x.fields), nameof<FieldInSection>(x => x.id)].join('.'),
[prefix ?? '', nameof<DmpBlueprint>(x => x.definition), nameof<DmpBlueprintDefinition>(x => x.sections), nameof<DmpBlueprintDefinitionSection>(x => x.fields), nameof<FieldInSection>(x => x.category)].join('.'), prefix ? prefix + '.' : '' + [nameof<DmpBlueprint>(x => x.definition), nameof<DmpBlueprintDefinition>(x => x.sections), nameof<DmpBlueprintDefinitionSection>(x => x.fields), nameof<FieldInSection>(x => x.category)].join('.'),
[prefix ?? '', nameof<DmpBlueprint>(x => x.definition), nameof<DmpBlueprintDefinition>(x => x.sections), nameof<DmpBlueprintDefinitionSection>(x => x.fields), nameof<FieldInSection>(x => x.dataType)].join('.'), prefix ? prefix + '.' : '' + [nameof<DmpBlueprint>(x => x.definition), nameof<DmpBlueprintDefinition>(x => x.sections), nameof<DmpBlueprintDefinitionSection>(x => x.fields), nameof<FieldInSection>(x => x.dataType)].join('.'),
[prefix ?? '', nameof<DmpBlueprint>(x => x.definition), nameof<DmpBlueprintDefinition>(x => x.sections), nameof<DmpBlueprintDefinitionSection>(x => x.fields), nameof<FieldInSection>(x => x.systemFieldType)].join('.'), prefix ? prefix + '.' : '' + [nameof<DmpBlueprint>(x => x.definition), nameof<DmpBlueprintDefinition>(x => x.sections), nameof<DmpBlueprintDefinitionSection>(x => x.fields), nameof<FieldInSection>(x => x.systemFieldType)].join('.'),
[prefix ?? '', nameof<DmpBlueprint>(x => x.definition), nameof<DmpBlueprintDefinition>(x => x.sections), nameof<DmpBlueprintDefinitionSection>(x => x.fields), nameof<FieldInSection>(x => x.label)].join('.'), prefix ? prefix + '.' : '' + [nameof<DmpBlueprint>(x => x.definition), nameof<DmpBlueprintDefinition>(x => x.sections), nameof<DmpBlueprintDefinitionSection>(x => x.fields), nameof<FieldInSection>(x => x.label)].join('.'),
[prefix ?? '', nameof<DmpBlueprint>(x => x.definition), nameof<DmpBlueprintDefinition>(x => x.sections), nameof<DmpBlueprintDefinitionSection>(x => x.fields), nameof<FieldInSection>(x => x.placeholder)].join('.'), prefix ? prefix + '.' : '' + [nameof<DmpBlueprint>(x => x.definition), nameof<DmpBlueprintDefinition>(x => x.sections), nameof<DmpBlueprintDefinitionSection>(x => x.fields), nameof<FieldInSection>(x => x.placeholder)].join('.'),
[prefix ?? '', nameof<DmpBlueprint>(x => x.definition), nameof<DmpBlueprintDefinition>(x => x.sections), nameof<DmpBlueprintDefinitionSection>(x => x.fields), nameof<FieldInSection>(x => x.description)].join('.'), prefix ? prefix + '.' : '' + [nameof<DmpBlueprint>(x => x.definition), nameof<DmpBlueprintDefinition>(x => x.sections), nameof<DmpBlueprintDefinitionSection>(x => x.fields), nameof<FieldInSection>(x => x.description)].join('.'),
[prefix ?? '', nameof<DmpBlueprint>(x => x.definition), nameof<DmpBlueprintDefinition>(x => x.sections), nameof<DmpBlueprintDefinitionSection>(x => x.fields), nameof<FieldInSection>(x => x.required)].join('.'), prefix ? prefix + '.' : '' + [nameof<DmpBlueprint>(x => x.definition), nameof<DmpBlueprintDefinition>(x => x.sections), nameof<DmpBlueprintDefinitionSection>(x => x.fields), nameof<FieldInSection>(x => x.required)].join('.'),
[prefix ?? '', nameof<DmpBlueprint>(x => x.definition), nameof<DmpBlueprintDefinition>(x => x.sections), nameof<DmpBlueprintDefinitionSection>(x => x.fields), nameof<FieldInSection>(x => x.ordinal)].join('.') prefix ? prefix + '.' : '' + [nameof<DmpBlueprint>(x => x.definition), nameof<DmpBlueprintDefinition>(x => x.sections), nameof<DmpBlueprintDefinitionSection>(x => x.fields), nameof<FieldInSection>(x => x.ordinal)].join('.')
] ]
} }