Merge branch 'dmp-refactoring' of code-repo.d4science.org:MaDgiK-CITE/argos into dmp-refactoring
This commit is contained in:
commit
6443654343
|
@ -49,6 +49,11 @@ public class DescriptionTemplateTypeService {
|
||||||
return builderFactory.builder(DescriptionTemplateTypeBuilder.class).build(lookup.getProject(), data);
|
return builderFactory.builder(DescriptionTemplateTypeBuilder.class).build(lookup.getProject(), data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public long count(DescriptionTemplateTypeLookup lookup) {
|
||||||
|
DescriptionTemplateTypeQuery query = lookup.enrich(queryFactory);
|
||||||
|
return query.count();
|
||||||
|
}
|
||||||
|
|
||||||
public DescriptionTemplateType get(UUID id) {
|
public DescriptionTemplateType get(UUID id) {
|
||||||
DescriptionTemplateTypeQuery query = applicationContext.getBean(DescriptionTemplateTypeQuery.class);
|
DescriptionTemplateTypeQuery query = applicationContext.getBean(DescriptionTemplateTypeQuery.class);
|
||||||
|
|
||||||
|
|
|
@ -1,36 +0,0 @@
|
||||||
package eu.eudat.controllers.v2;
|
|
||||||
|
|
||||||
import eu.eudat.model.result.QueryResult;
|
|
||||||
import gr.cite.tools.data.query.Lookup;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.function.BiFunction;
|
|
||||||
import java.util.function.Function;
|
|
||||||
|
|
||||||
public class BaseController {
|
|
||||||
|
|
||||||
public static <T, L extends Lookup> QueryResult<T> extractQueryResultWithCount(Function<L, List<T>> service, L lookup) {
|
|
||||||
return extractQueryResultWithCountWhen(service, lookup, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static <T, L extends Lookup> QueryResult<T> extractQueryResultWithCountWhen(Function<L, List<T>> service, L lookup, Function<T, Boolean> when) {
|
|
||||||
List<T> result = service.apply(lookup);
|
|
||||||
lookup.setPage(null);
|
|
||||||
List<T> all = service.apply(lookup);
|
|
||||||
long count = all.size();
|
|
||||||
if (when == null) return new QueryResult<>(result, count);
|
|
||||||
long countOverride = count;
|
|
||||||
for (T item : all) {
|
|
||||||
if (!when.apply(item)) countOverride--;
|
|
||||||
}
|
|
||||||
return new QueryResult<>(result, count, countOverride);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static <T, L extends Lookup> QueryResult<T> extractQueryResultWithCount(BiFunction<String, L, List<T>> service, String name, L lookup) {
|
|
||||||
List<T> result = service.apply(name, lookup);
|
|
||||||
lookup.setPage(null);
|
|
||||||
long count = service.apply(name, lookup).size();
|
|
||||||
return new QueryResult<>(result, count);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -15,6 +15,7 @@ import gr.cite.tools.exception.MyNotFoundException;
|
||||||
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 gr.cite.tools.logging.MapLogEntry;
|
import gr.cite.tools.logging.MapLogEntry;
|
||||||
|
import org.opensaml.xml.signature.Q;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.context.MessageSource;
|
import org.springframework.context.MessageSource;
|
||||||
import org.springframework.context.i18n.LocaleContextHolder;
|
import org.springframework.context.i18n.LocaleContextHolder;
|
||||||
|
@ -25,11 +26,10 @@ import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import java.util.AbstractMap;
|
import java.util.AbstractMap;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import static eu.eudat.controllers.v2.BaseController.extractQueryResultWithCount;
|
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@CrossOrigin
|
@CrossOrigin
|
||||||
@Transactional
|
@Transactional
|
||||||
|
@ -59,9 +59,12 @@ public class DescriptionTemplateTypeV2Controller {
|
||||||
|
|
||||||
censorFactory.censor(DescriptionTemplateTypeCensor.class).censor(lookup.getProject());
|
censorFactory.censor(DescriptionTemplateTypeCensor.class).censor(lookup.getProject());
|
||||||
|
|
||||||
|
List<DescriptionTemplateType> models = descriptionTemplateTypeService.query(lookup);
|
||||||
|
long count = (lookup.getMetadata() != null && lookup.getMetadata().getCountAll()) ? descriptionTemplateTypeService.count(lookup) : models.size();
|
||||||
|
|
||||||
auditService.track(AuditableAction.DescriptionTemplateType_Query, "lookup", lookup);
|
auditService.track(AuditableAction.DescriptionTemplateType_Query, "lookup", lookup);
|
||||||
|
|
||||||
return extractQueryResultWithCount(descriptionTemplateTypeService::query, lookup);
|
return new QueryResult<>(models, count);
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("{id}")
|
@GetMapping("{id}")
|
||||||
|
|
Loading…
Reference in New Issue