diff --git a/dmp-backend/core/src/main/java/eu/eudat/audit/AuditableAction.java b/dmp-backend/core/src/main/java/eu/eudat/audit/AuditableAction.java index 5c7571155..c8ad61c07 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/audit/AuditableAction.java +++ b/dmp-backend/core/src/main/java/eu/eudat/audit/AuditableAction.java @@ -145,8 +145,7 @@ public class AuditableAction { public static final EventId PrefillingSource_Lookup = new EventId(260001, "PrefillingSource_Lookup"); public static final EventId PrefillingSource_Persist = new EventId(260002, "PrefillingSource_Persist"); public static final EventId PrefillingSource_Delete = new EventId(260003, "PrefillingSource_Delete"); - public static final EventId PrefillingSource_Generate = new EventId(260005, "PrefillingSource_Generate"); - public static final EventId PrefillingSource_GenerateWithData = new EventId(260006, "PrefillingSource_GenerateWithData"); + public static final EventId PrefillingSource_Generate = new EventId(260004, "PrefillingSource_Generate"); } diff --git a/dmp-backend/core/src/main/java/eu/eudat/commons/types/prefillingsource/PrefillingEntity.java b/dmp-backend/core/src/main/java/eu/eudat/commons/types/prefillingsource/PrefillingEntity.java deleted file mode 100644 index fa17dcea1..000000000 --- a/dmp-backend/core/src/main/java/eu/eudat/commons/types/prefillingsource/PrefillingEntity.java +++ /dev/null @@ -1,65 +0,0 @@ -package eu.eudat.commons.types.prefillingsource; - -import eu.eudat.commons.JsonHandlingService; - -import java.util.Map; - -public class PrefillingEntity { - private String pid; - private String name; - private Map data; - private String key; - private String tag; - - public String getPid() { - return pid; - } - - public void setPid(String pid) { - this.pid = pid; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public Map getData() { - return data; - } - - public void setData(Map data) { - this.data = data; - } - - public String getKey() { - return key; - } - - public void setKey(String key) { - this.key = key; - } - - public String getTag() { - return tag; - } - - public void setTag(String tag) { - this.tag = tag; - } - - public static PrefillingEntity build(Map fetchedData, JsonHandlingService jsonHandlingService){ - PrefillingEntity m = new PrefillingEntity(); - - m.setPid(fetchedData.getOrDefault("pid", null)); - m.setName(fetchedData.getOrDefault("name", null)); - m.setKey(fetchedData.getOrDefault("key", null)); - m.setTag(fetchedData.getOrDefault("tag", null)); - m.setData(jsonHandlingService.fromJsonSafe(Map.class,fetchedData.getOrDefault("data", null))); - - return m; - } -} diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/Prefilling.java b/dmp-backend/core/src/main/java/eu/eudat/model/Prefilling.java index 12a05fd32..b23e44a3d 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/Prefilling.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/Prefilling.java @@ -4,10 +4,12 @@ import java.util.Map; public class Prefilling { - private String pid; - public static final String _pid = "pid"; - private String name; - public static final String _name = "name"; + private String id; + public static final String _id = "reference_id"; + + private String label; + public static final String _label = "label"; + private Map data; public static final String _data = "data"; private String key; @@ -15,20 +17,20 @@ public class Prefilling { private String tag; public static final String _tag = "tag"; - public String getPid() { - return pid; + public String getId() { + return id; } - public void setPid(String pid) { - this.pid = pid; + public void setId(String id) { + this.id = id; } - public String getName() { - return name; + public String getLabel() { + return label; } - public void setName(String name) { - this.name = name; + public void setLabel(String label) { + this.label = label; } public Map getData() { diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/builder/PrefillingBuilder.java b/dmp-backend/core/src/main/java/eu/eudat/model/builder/PrefillingBuilder.java deleted file mode 100644 index c302467b0..000000000 --- a/dmp-backend/core/src/main/java/eu/eudat/model/builder/PrefillingBuilder.java +++ /dev/null @@ -1,92 +0,0 @@ -package eu.eudat.model.builder; - -import eu.eudat.authorization.AuthorizationFlags; -import eu.eudat.commons.types.prefillingsource.PrefillingEntity; -import eu.eudat.convention.ConventionService; -import eu.eudat.data.UserEntity; -import eu.eudat.model.Prefilling; -import eu.eudat.model.User; -import eu.eudat.model.UserContactInfo; -import eu.eudat.query.UserContactInfoQuery; -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 PrefillingBuilder extends BaseBuilder { - - private final QueryFactory queryFactory; - - private final BuilderFactory builderFactory; - - private EnumSet authorize = EnumSet.of(AuthorizationFlags.None); - - @Autowired - public PrefillingBuilder(ConventionService conventionService, - QueryFactory queryFactory, - BuilderFactory builderFactory) { - super(conventionService, new LoggerService(LoggerFactory.getLogger(PrefillingBuilder.class))); - this.queryFactory = queryFactory; - this.builderFactory = builderFactory; - } - - public PrefillingBuilder authorize(EnumSet values) { - this.authorize = values; - return this; - } - - @Override - public List build(FieldSet fields, List 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<>(); - - List models = new ArrayList<>(); - - for (PrefillingEntity d : data) { - Prefilling m = new Prefilling(); - if (fields.hasField(this.asIndexer(Prefilling._pid))) m.setPid(d.getPid()); - if (fields.hasField(this.asIndexer(Prefilling._name))) m.setName(d.getName()); - if (fields.hasField(this.asIndexer(Prefilling._key))) m.setKey(d.getKey()); - if (fields.hasField(this.asIndexer(Prefilling._tag))) m.setTag(d.getTag()); - if (fields.hasField(this.asIndexer(Prefilling._data))) m.setData(d.getData()); - models.add(m); - } - this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0)); - - return models; - } - - private Map> collectUserContactInfos(FieldSet fields, List data) throws MyApplicationException { - if (fields.isEmpty() || data.isEmpty()) return null; - this.logger.debug("checking related - {}", UserContactInfo.class.getSimpleName()); - - Map> itemMap; - FieldSet clone = new BaseFieldSet(fields.getFields()).ensure(this.asIndexer(UserContactInfo._user, User._id)); - UserContactInfoQuery query = this.queryFactory.query(UserContactInfoQuery.class).authorize(this.authorize).userIds(data.stream().map(UserEntity::getId).distinct().collect(Collectors.toList())); - itemMap = this.builderFactory.builder(UserContactInfoBuilder.class).authorize(this.authorize).asMasterKey(query, clone, x -> x.getUser().getId()); - - if (!fields.hasField(this.asIndexer(UserContactInfo._user, User._id))) { - itemMap.values().stream().flatMap(List::stream).filter(x -> x != null && x.getUser() != null).peek(x -> { - x.getUser().setId(null); - }); - } - - return itemMap; - } - -} diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/persist/DescriptionProfilingRequest.java b/dmp-backend/core/src/main/java/eu/eudat/model/persist/DescriptionProfilingRequest.java index d1f89e0fe..4d622c99a 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/persist/DescriptionProfilingRequest.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/persist/DescriptionProfilingRequest.java @@ -13,10 +13,17 @@ import org.springframework.stereotype.Component; import java.util.Arrays; import java.util.List; +import java.util.Map; import java.util.UUID; public class DescriptionProfilingRequest { + private Map data; + public static final String _data = "data"; + + private String prefillId; + public static final String _prefillId = "prefillId"; + private UUID prefillingSourceId; public static final String _prefillingSourceId = "prefillingSourceId"; @@ -28,6 +35,21 @@ public class DescriptionProfilingRequest { private BaseFieldSet project; public static final String _project = "project"; + public Map getData() { + return data; + } + + public void setData(Map data) { + this.data = data; + } + + public String getPrefillId() { + return prefillId; + } + + public void setPrefillId(String prefillId) { + this.prefillId = prefillId; + } public UUID getPrefillingSourceId() { return prefillingSourceId; @@ -80,10 +102,16 @@ public class DescriptionProfilingRequest { .failOn(DescriptionProfilingRequest._descriptionTemplateId).failWith(messageSource.getMessage("Validation_Required", new Object[]{DescriptionProfilingRequest._descriptionTemplateId}, LocaleContextHolder.getLocale())), this.spec() .must(() -> this.isValidGuid(item.getPrefillingSourceId())) - .failOn(DescriptionProfilingRequest._prefillingSourceId).failWith(messageSource.getMessage("Validation_Required", new Object[]{DescriptionProfilingRequest._prefillingSourceId}, LocaleContextHolder.getLocale())) -// this.spec() TODO + .failOn(DescriptionProfilingRequest._prefillingSourceId).failWith(messageSource.getMessage("Validation_Required", new Object[]{DescriptionProfilingRequest._prefillingSourceId}, LocaleContextHolder.getLocale())), + this.spec() + .must(() -> !this.isEmpty(item.getPrefillId())) + .failOn(DescriptionProfilingRequest._prefillId).failWith(messageSource.getMessage("Validation_Required", new Object[]{DescriptionProfilingRequest._prefillId}, LocaleContextHolder.getLocale())) +// this.spec() +// .must(() -> item.getData() != null) +// .failOn(DescriptionProfilingWithDataRequest._data).failWith(messageSource.getMessage("Validation_Required", new Object[]{DescriptionProfilingWithDataRequest._data}, LocaleContextHolder.getLocale())) +// this.spec() // .must(() -> item.getProject() != null) -// .failOn(DescriptionProfilingRequest._project).failWith(messageSource.getMessage("Validation_Required", new Object[]{DescriptionProfilingRequest._project}, LocaleContextHolder.getLocale())) +// .failOn(DescriptionProfilingWithDataRequest._project).failWith(messageSource.getMessage("Validation_Required", new Object[]{DescriptionProfilingWithDataRequest._project}, LocaleContextHolder.getLocale())) ); } } diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/persist/DescriptionProfilingWithDataRequest.java b/dmp-backend/core/src/main/java/eu/eudat/model/persist/DescriptionProfilingWithDataRequest.java deleted file mode 100644 index 63790b828..000000000 --- a/dmp-backend/core/src/main/java/eu/eudat/model/persist/DescriptionProfilingWithDataRequest.java +++ /dev/null @@ -1,106 +0,0 @@ -package eu.eudat.model.persist; - -import eu.eudat.commons.validation.BaseValidator; -import gr.cite.tools.validation.specification.Specification; -import eu.eudat.convention.ConventionService; -import eu.eudat.errorcode.ErrorThesaurusProperties; -import gr.cite.tools.fieldset.BaseFieldSet; -import org.springframework.beans.factory.config.ConfigurableBeanFactory; -import org.springframework.context.MessageSource; -import org.springframework.context.annotation.Scope; -import org.springframework.context.i18n.LocaleContextHolder; -import org.springframework.stereotype.Component; - -import java.util.Arrays; -import java.util.List; -import java.util.Map; -import java.util.UUID; - -public class DescriptionProfilingWithDataRequest { - - private Map data; - public static final String _data = "data"; - - private UUID prefillingSourceId; - - public static final String _prefillingSourceId = "prefillingSourceId"; - - private UUID descriptionTemplateId; - - public static final String _descriptionTemplateId = "descriptionTemplateId"; - - private BaseFieldSet project; - public static final String _project = "project"; - - public Map getData() { - return data; - } - - public void setData(Map data) { - this.data = data; - } - - public UUID getPrefillingSourceId() { - return prefillingSourceId; - } - - public void setPrefillingSourceId(UUID prefillingSourceId) { - this.prefillingSourceId = prefillingSourceId; - } - - public UUID getDescriptionTemplateId() { - return descriptionTemplateId; - } - - public void setDescriptionTemplateId(UUID descriptionTemplateId) { - this.descriptionTemplateId = descriptionTemplateId; - } - - public BaseFieldSet getProject() { - return project; - } - - public void setProject(BaseFieldSet project) { - this.project = project; - } - - @Component(DescriptionProfilingWithDataRequestValidator.ValidatorName) - @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) - public static class DescriptionProfilingWithDataRequestValidator extends BaseValidator { - - public static final String ValidatorName = "DescriptionProfilingWithDataRequestValidator"; - - private final MessageSource messageSource; - - - protected DescriptionProfilingWithDataRequestValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource) { - super(conventionService, errors); - this.messageSource = messageSource; - } - - @Override - protected Class modelClass() { - return DescriptionProfilingWithDataRequest.class; - } - - @Override - protected List specifications(DescriptionProfilingWithDataRequest item) { - return Arrays.asList( - this.spec() - .must(() -> this.isValidGuid(item.getDescriptionTemplateId())) - .failOn(DescriptionProfilingWithDataRequest._descriptionTemplateId).failWith(messageSource.getMessage("Validation_Required", new Object[]{DescriptionProfilingWithDataRequest._descriptionTemplateId}, LocaleContextHolder.getLocale())), - this.spec() - .must(() -> this.isValidGuid(item.getPrefillingSourceId())) - .failOn(DescriptionProfilingWithDataRequest._prefillingSourceId).failWith(messageSource.getMessage("Validation_Required", new Object[]{DescriptionProfilingWithDataRequest._prefillingSourceId}, LocaleContextHolder.getLocale())) -// this.spec() TODO -// .must(() -> item.getData() != null) -// .failOn(DescriptionProfilingWithDataRequest._data).failWith(messageSource.getMessage("Validation_Required", new Object[]{DescriptionProfilingWithDataRequest._data}, LocaleContextHolder.getLocale())) -// this.spec() -// .must(() -> item.getProject() != null) -// .failOn(DescriptionProfilingWithDataRequest._project).failWith(messageSource.getMessage("Validation_Required", new Object[]{DescriptionProfilingWithDataRequest._project}, LocaleContextHolder.getLocale())) - ); - } - } - -} - diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/persist/PrefillingSearchRequest.java b/dmp-backend/core/src/main/java/eu/eudat/model/persist/PrefillingSearchRequest.java new file mode 100644 index 000000000..31a3f7cfc --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/model/persist/PrefillingSearchRequest.java @@ -0,0 +1,73 @@ +package eu.eudat.model.persist; + +import eu.eudat.commons.validation.BaseValidator; +import gr.cite.tools.validation.specification.Specification; +import eu.eudat.convention.ConventionService; +import eu.eudat.errorcode.ErrorThesaurusProperties; +import gr.cite.tools.fieldset.BaseFieldSet; +import org.springframework.beans.factory.config.ConfigurableBeanFactory; +import org.springframework.context.MessageSource; +import org.springframework.context.annotation.Scope; +import org.springframework.context.i18n.LocaleContextHolder; +import org.springframework.stereotype.Component; + +import java.util.Arrays; +import java.util.List; +import java.util.UUID; + +public class PrefillingSearchRequest { + + private String like; + public static final String _like = "like"; + + private UUID prefillingSourceId; + + public static final String _prefillingSourceId = "prefillingSourceId"; + + public String getLike() { + return like; + } + + public void setLike(String like) { + this.like = like; + } + + public UUID getPrefillingSourceId() { + return prefillingSourceId; + } + + public void setPrefillingSourceId(UUID prefillingSourceId) { + this.prefillingSourceId = prefillingSourceId; + } + + @Component(PrefillingSearchRequestValidator.ValidatorName) + @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) + public static class PrefillingSearchRequestValidator extends BaseValidator { + + public static final String ValidatorName = "PrefillingSearchRequestValidator"; + + private final MessageSource messageSource; + + + protected PrefillingSearchRequestValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource) { + super(conventionService, errors); + this.messageSource = messageSource; + } + + @Override + protected Class modelClass() { + return PrefillingSearchRequest.class; + } + + @Override + protected List specifications(PrefillingSearchRequest item) { + return Arrays.asList( + this.spec() + .must(() -> this.isValidGuid(item.getPrefillingSourceId())) + .failOn(PrefillingSearchRequest._prefillingSourceId).failWith(messageSource.getMessage("Validation_Required", new Object[]{PrefillingSearchRequest._prefillingSourceId}, LocaleContextHolder.getLocale())) + ); + } + } + +} + diff --git a/dmp-backend/core/src/main/java/eu/eudat/service/externalfetcher/ExternalFetcherServiceImpl.java b/dmp-backend/core/src/main/java/eu/eudat/service/externalfetcher/ExternalFetcherServiceImpl.java index 38354f2e0..2b06a74d8 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/service/externalfetcher/ExternalFetcherServiceImpl.java +++ b/dmp-backend/core/src/main/java/eu/eudat/service/externalfetcher/ExternalFetcherServiceImpl.java @@ -271,15 +271,19 @@ public class ExternalFetcherServiceImpl implements ExternalFetcherService { private ExternalDataResult jsonToExternalDataResult(DocumentContext jsonContext, ResultsConfiguration resultsConfigurationEntity) { ExternalDataResult result = new ExternalDataResult(); if (this.conventionService.isNullOrEmpty(resultsConfigurationEntity.getResultsArrayPath())) return new ExternalDataResult(); - List> rawData = jsonContext.read(resultsConfigurationEntity.getResultsArrayPath()); + Object jsonData = jsonContext.read(resultsConfigurationEntity.getResultsArrayPath()); + List> rawData = new ArrayList<>(); + if (jsonData instanceof List) { + rawData = (List>) jsonData; + }else{ + rawData.add((Map)jsonData); + } result.setRawData(rawData); if (this.conventionService.isListNullOrEmpty(rawData) || this.conventionService.isListNullOrEmpty(resultsConfigurationEntity.getFieldsMapping())) return new ExternalDataResult(); - - List results = jsonContext.read(resultsConfigurationEntity.getResultsArrayPath()); List> parsedData = new ArrayList<>(); - for(Object resultItem : results){ + for(Object resultItem : result.getRawData()){ Map map = new HashMap<>(); boolean isValid = true; for(ResultFieldsMappingConfiguration field : resultsConfigurationEntity.getFieldsMapping()) { diff --git a/dmp-backend/core/src/main/java/eu/eudat/service/prefillingsource/PrefillingSourceService.java b/dmp-backend/core/src/main/java/eu/eudat/service/prefillingsource/PrefillingSourceService.java index ace0c720c..ead478ab2 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/service/prefillingsource/PrefillingSourceService.java +++ b/dmp-backend/core/src/main/java/eu/eudat/service/prefillingsource/PrefillingSourceService.java @@ -1,9 +1,10 @@ package eu.eudat.service.prefillingsource; import eu.eudat.model.Description; +import eu.eudat.model.Prefilling; import eu.eudat.model.PrefillingSource; +import eu.eudat.model.persist.PrefillingSearchRequest; import eu.eudat.model.persist.DescriptionProfilingRequest; -import eu.eudat.model.persist.DescriptionProfilingWithDataRequest; import eu.eudat.model.persist.PrefillingSourcePersist; import gr.cite.tools.exception.MyApplicationException; import gr.cite.tools.exception.MyForbiddenException; @@ -16,6 +17,7 @@ import org.xml.sax.SAXException; import javax.management.InvalidApplicationException; import javax.xml.parsers.ParserConfigurationException; import java.io.IOException; +import java.util.List; import java.util.UUID; public interface PrefillingSourceService { @@ -24,8 +26,8 @@ public interface PrefillingSourceService { void deleteAndSave(UUID id) throws MyForbiddenException, InvalidApplicationException; - Description getPrefilledDescription(DescriptionProfilingRequest model) throws JAXBException, ParserConfigurationException, IOException, InstantiationException, IllegalAccessException, SAXException; + List searchPrefillings(PrefillingSearchRequest model); - Description getPrefilledDescriptionUsingData(DescriptionProfilingWithDataRequest model) throws JAXBException, ParserConfigurationException, IOException, InstantiationException, IllegalAccessException, SAXException; + Description getPrefilledDescription(DescriptionProfilingRequest model, FieldSet fields) throws JAXBException, ParserConfigurationException, IOException, InstantiationException, IllegalAccessException, SAXException; } diff --git a/dmp-backend/core/src/main/java/eu/eudat/service/prefillingsource/PrefillingSourceServiceImpl.java b/dmp-backend/core/src/main/java/eu/eudat/service/prefillingsource/PrefillingSourceServiceImpl.java index 7985ef706..a7562b085 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/service/prefillingsource/PrefillingSourceServiceImpl.java +++ b/dmp-backend/core/src/main/java/eu/eudat/service/prefillingsource/PrefillingSourceServiceImpl.java @@ -23,8 +23,8 @@ import eu.eudat.model.builder.DescriptionTemplateBuilder; import eu.eudat.model.builder.PrefillingSourceBuilder; import eu.eudat.model.deleter.PrefillingSourceDeleter; import eu.eudat.model.descriptionproperties.*; +import eu.eudat.model.persist.PrefillingSearchRequest; import eu.eudat.model.persist.DescriptionProfilingRequest; -import eu.eudat.model.persist.DescriptionProfilingWithDataRequest; import eu.eudat.model.persist.PrefillingSourcePersist; import eu.eudat.model.persist.externalfetcher.*; import eu.eudat.model.persist.prefillingsourcedefinition.PrefillingSourceDefinitionFieldPersist; @@ -309,19 +309,38 @@ public class PrefillingSourceServiceImpl implements PrefillingSourceService { this.deleterFactory.deleter(PrefillingSourceDeleter.class).deleteAndSaveByIds(List.of(id)); } - public Description getPrefilledDescription(DescriptionProfilingRequest model) throws JAXBException, ParserConfigurationException, IOException, InstantiationException, IllegalAccessException, SAXException { + public List searchPrefillings(PrefillingSearchRequest model) { PrefillingSourceEntity prefillingSourceEntity = this.queryFactory.query(PrefillingSourceQuery.class).ids(model.getPrefillingSourceId()).isActive(IsActive.Active).first(); - if (prefillingSourceEntity == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{model.getPrefillingSourceId(), PrefillingSource.class.getSimpleName()}, LocaleContextHolder.getLocale())); + if (prefillingSourceEntity == null) + throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{model.getPrefillingSourceId(), PrefillingSource.class.getSimpleName()}, LocaleContextHolder.getLocale())); - DescriptionProfilingWithDataRequest descriptionProfilingWithDataRequest = new DescriptionProfilingWithDataRequest(); - descriptionProfilingWithDataRequest.setPrefillingSourceId(model.getPrefillingSourceId()); - descriptionProfilingWithDataRequest.setProject(model.getProject()); - descriptionProfilingWithDataRequest.setDescriptionTemplateId(model.getDescriptionTemplateId()); - validatorFactory.validator(DescriptionProfilingWithDataRequest.DescriptionProfilingWithDataRequestValidator.ValidatorName).validateForce(descriptionProfilingWithDataRequest); - return this.getPrefilledDescriptionUsingData(descriptionProfilingWithDataRequest); + PrefillingSourceDefinitionEntity prefillingSourceDefinition = this.xmlHandlingService.fromXmlSafe(PrefillingSourceDefinitionEntity.class, prefillingSourceEntity.getDefinition()); + if (prefillingSourceDefinition == null) + throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{model.getPrefillingSourceId(), PrefillingSourceDefinition.class.getSimpleName()}, LocaleContextHolder.getLocale())); + + ExternalReferenceCriteria externalReferenceCriteria = new ExternalReferenceCriteria(); + externalReferenceCriteria.setLike(model.getLike()); + + ExternalDataResult externalData = this.externalFetcherService.getExternalData(Stream.of(prefillingSourceDefinition.getSearchConfiguration()).collect(Collectors.toList()), externalReferenceCriteria, null); + if (externalData == null || this.conventionService.isListNullOrEmpty(externalData.getResults())) { + return null; + } + + List prefillings = new ArrayList<>(); + for (Map result : externalData.getResults()) { + Prefilling prefilling = new Prefilling(); + prefilling.setId(result.getOrDefault(Prefilling._id, null)); + prefilling.setLabel(result.getOrDefault(Prefilling._label, null)); + prefilling.setKey(result.getOrDefault(Prefilling._key, null)); + prefilling.setTag(result.getOrDefault(Prefilling._tag, null)); + + prefillings.add(prefilling); + } + + return prefillings; } - public Description getPrefilledDescriptionUsingData(DescriptionProfilingWithDataRequest model) throws JAXBException, ParserConfigurationException, IOException, InstantiationException, IllegalAccessException, SAXException { + public Description getPrefilledDescription(DescriptionProfilingRequest model, FieldSet fieldSet) throws JAXBException, ParserConfigurationException, IOException, InstantiationException, IllegalAccessException, SAXException { PrefillingSourceEntity prefillingSourceEntity = this.queryFactory.query(PrefillingSourceQuery.class).ids(model.getPrefillingSourceId()).first(); if (prefillingSourceEntity == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{model.getPrefillingSourceId(), PrefillingSource.class.getSimpleName()}, LocaleContextHolder.getLocale())); @@ -329,7 +348,10 @@ public class PrefillingSourceServiceImpl implements PrefillingSourceService { PrefillingSourceDefinitionEntity prefillingSourceDefinition = this.xmlHandlingService.fromXmlSafe(PrefillingSourceDefinitionEntity.class, prefillingSourceEntity.getDefinition()); if (prefillingSourceDefinition == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{model.getPrefillingSourceId(), PrefillingSourceDefinition.class.getSimpleName()}, LocaleContextHolder.getLocale())); - ExternalDataResult externalData = this.externalFetcherService.getExternalData(Stream.of(prefillingSourceDefinition.getGetConfiguration()).collect(Collectors.toList()), new ExternalReferenceCriteria(), null); + ExternalReferenceCriteria externalReferenceCriteria = new ExternalReferenceCriteria(); + externalReferenceCriteria.setLike(model.getPrefillId()); + + ExternalDataResult externalData = this.externalFetcherService.getExternalData(Stream.of(prefillingSourceDefinition.getGetConfiguration()).collect(Collectors.toList()), externalReferenceCriteria, null); if (externalData == null || this.conventionService.isListNullOrEmpty(externalData.getResults())) { return null; } @@ -339,7 +361,7 @@ public class PrefillingSourceServiceImpl implements PrefillingSourceService { eu.eudat.commons.types.descriptiontemplate.DefinitionEntity descriptionTemplateDefinition = this.xmlHandlingService.fromXml(eu.eudat.commons.types.descriptiontemplate.DefinitionEntity.class, descriptionTemplateEntity.getDefinition()); Description description = new Description(); - description.setDescriptionTemplate(this.builderFactory.builder(DescriptionTemplateBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).build(model.getProject(), descriptionTemplateEntity)); + description.setDescriptionTemplate(this.builderFactory.builder(DescriptionTemplateBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).build(fieldSet, descriptionTemplateEntity)); return mapPrefilledEntityToDescription(description, descriptionTemplateDefinition, prefillingSourceDefinition, prefillingSourceEntity.getLabel(), externalData.getResults().getFirst());//TODO } diff --git a/dmp-backend/web/src/main/java/eu/eudat/controllers/PrefillingSourceController.java b/dmp-backend/web/src/main/java/eu/eudat/controllers/PrefillingSourceController.java index 8ed3be40a..070e3323e 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/controllers/PrefillingSourceController.java +++ b/dmp-backend/web/src/main/java/eu/eudat/controllers/PrefillingSourceController.java @@ -9,9 +9,10 @@ import eu.eudat.model.Prefilling; import eu.eudat.model.PrefillingSource; import eu.eudat.model.builder.PrefillingSourceBuilder; import eu.eudat.model.censorship.DescriptionCensor; +import eu.eudat.model.censorship.PrefillingCensor; import eu.eudat.model.censorship.PrefillingSourceCensor; +import eu.eudat.model.persist.PrefillingSearchRequest; import eu.eudat.model.persist.DescriptionProfilingRequest; -import eu.eudat.model.persist.DescriptionProfilingWithDataRequest; import eu.eudat.model.persist.PrefillingSourcePersist; import eu.eudat.model.result.QueryResult; import eu.eudat.query.PrefillingSourceQuery; @@ -144,14 +145,14 @@ public class PrefillingSourceController { this.auditService.track(AuditableAction.PrefillingSource_Delete, "id", id); } - @PostMapping("generate") - @ValidationFilterAnnotation(validator = DescriptionProfilingRequest.DescriptionProfilingRequestValidator.ValidatorName, argumentName = "model") - public Description generate(@RequestBody DescriptionProfilingRequest model) throws MyApplicationException, MyForbiddenException, MyNotFoundException, JAXBException, ParserConfigurationException, IOException, InstantiationException, IllegalAccessException, SAXException { - logger.debug(new MapLogEntry("persisting" + Prefilling.class.getSimpleName()).And("model", model)); + @PostMapping("search") + @ValidationFilterAnnotation(validator = PrefillingSearchRequest.PrefillingSearchRequestValidator.ValidatorName, argumentName = "model") + public List search(@RequestBody PrefillingSearchRequest model) throws MyApplicationException, MyForbiddenException, MyNotFoundException, JAXBException, ParserConfigurationException, IOException, InstantiationException, IllegalAccessException, SAXException { + logger.debug(new MapLogEntry("searching" + Prefilling.class.getSimpleName()).And("model", model)); - this.censorFactory.censor(DescriptionCensor.class).censor(model.getProject(), null); + this.censorFactory.censor(PrefillingCensor.class).censor(null, null); - Description item = this.prefillingSourceService.getPrefilledDescription(model); + List item = this.prefillingSourceService.searchPrefillings(model); this.auditService.track(AuditableAction.PrefillingSource_Generate, Map.ofEntries( new AbstractMap.SimpleEntry("model", model) @@ -160,16 +161,16 @@ public class PrefillingSourceController { return item; } - @PostMapping("generate-with-data") - @ValidationFilterAnnotation(validator = DescriptionProfilingWithDataRequest.DescriptionProfilingWithDataRequestValidator.ValidatorName, argumentName = "model") - public Description generateWithData(@RequestBody DescriptionProfilingWithDataRequest model) throws MyApplicationException, MyForbiddenException, MyNotFoundException, JAXBException, ParserConfigurationException, IOException, InstantiationException, IllegalAccessException, SAXException { + @PostMapping("generate") + @ValidationFilterAnnotation(validator = DescriptionProfilingRequest.DescriptionProfilingRequestValidator.ValidatorName, argumentName = "model") + public Description generate(@RequestBody DescriptionProfilingRequest model, FieldSet fieldSet) throws MyApplicationException, MyForbiddenException, MyNotFoundException, JAXBException, ParserConfigurationException, IOException, InstantiationException, IllegalAccessException, SAXException { logger.debug(new MapLogEntry("persisting" + Prefilling.class.getSimpleName()).And("model", model)); - this.censorFactory.censor(DescriptionCensor.class).censor(model.getProject(), null); + this.censorFactory.censor(DescriptionCensor.class).censor(fieldSet, null); - Description item = this.prefillingSourceService.getPrefilledDescriptionUsingData(model); + Description item = this.prefillingSourceService.getPrefilledDescription(model, fieldSet); - this.auditService.track(AuditableAction.PrefillingSource_GenerateWithData, Map.ofEntries( + this.auditService.track(AuditableAction.PrefillingSource_Generate, Map.ofEntries( new AbstractMap.SimpleEntry("model", model) )); diff --git a/dmp-frontend/src/app/core/core-service.module.ts b/dmp-frontend/src/app/core/core-service.module.ts index f7b5e8ecd..b151c7d8f 100644 --- a/dmp-frontend/src/app/core/core-service.module.ts +++ b/dmp-frontend/src/app/core/core-service.module.ts @@ -1,5 +1,4 @@ import { ModuleWithProviders, NgModule, Optional, SkipSelf } from '@angular/core'; -import { PrefillingService } from "@app/core/services/prefilling.service"; import { CookieService } from 'ngx-cookie-service'; import { AdminAuthGuard } from './admin-auth-guard.service'; import { AuthGuard } from './auth-guard.service'; @@ -89,7 +88,6 @@ export class CoreServiceModule { PrincipalService, SupportiveMaterialService, LanguageInfoService, - PrefillingService, DescriptionTemplateTypeService, HttpErrorHandlingService, QueryParamsService, diff --git a/dmp-frontend/src/app/core/model/description-profiling-request/description-profiling-request.ts b/dmp-frontend/src/app/core/model/description-profiling-request/description-profiling-request.ts index 2300e6942..380c90024 100644 --- a/dmp-frontend/src/app/core/model/description-profiling-request/description-profiling-request.ts +++ b/dmp-frontend/src/app/core/model/description-profiling-request/description-profiling-request.ts @@ -1,12 +1,14 @@ import { Guid } from "@common/types/guid"; +export interface PrefillingSearchRequest { + like: string; + prefillingSourceId: Guid; +} + export interface DescriptionProfilingRequest { prefillingSourceId: Guid; descriptionTemplateId: Guid; -} - -export interface DescriptionProfilingWithDataRequest { - prefillingSourceId: Guid; - descriptionTemplateId: Guid; data: Map; + prefillId: string; + project: string[]; } \ No newline at end of file diff --git a/dmp-frontend/src/app/core/model/prefilling-source/prefilling-source.ts b/dmp-frontend/src/app/core/model/prefilling-source/prefilling-source.ts index b107e281b..e77dcbe2f 100644 --- a/dmp-frontend/src/app/core/model/prefilling-source/prefilling-source.ts +++ b/dmp-frontend/src/app/core/model/prefilling-source/prefilling-source.ts @@ -27,6 +27,13 @@ export interface PrefillingSourceDefinitionFixedValueField { fixedValue: string; } +export interface Prefilling { + id: string, + label: string, + key: string, + tag: string +} + // Persist export interface PrefillingSourcePersist extends BaseEntityPersist{ diff --git a/dmp-frontend/src/app/core/services/prefilling-source/prefilling-source.service.ts b/dmp-frontend/src/app/core/services/prefilling-source/prefilling-source.service.ts index 5c6d36802..f596027e5 100644 --- a/dmp-frontend/src/app/core/services/prefilling-source/prefilling-source.service.ts +++ b/dmp-frontend/src/app/core/services/prefilling-source/prefilling-source.service.ts @@ -1,6 +1,6 @@ import { Injectable } from '@angular/core'; import { IsActive } from '@app/core/common/enum/is-active.enum'; -import { PrefillingSource, PrefillingSourcePersist } from '@app/core/model/prefilling-source/prefilling-source'; +import { Prefilling, PrefillingSource, PrefillingSourcePersist } from '@app/core/model/prefilling-source/prefilling-source'; import { PrefillingSourceLookup } from '@app/core/query/prefilling-source.lookup'; import { MultipleAutoCompleteConfiguration } from '@app/library/auto-complete/multiple/multiple-auto-complete-configuration'; import { SingleAutoCompleteConfiguration } from '@app/library/auto-complete/single/single-auto-complete-configuration'; @@ -12,7 +12,7 @@ import { catchError, map } from 'rxjs/operators'; import { nameof } from 'ts-simple-nameof'; import { ConfigurationService } from '../configuration/configuration.service'; import { BaseHttpV2Service } from '../http/base-http-v2.service'; -import { DescriptionProfilingRequest, DescriptionProfilingWithDataRequest } from '@app/core/model/description-profiling-request/description-profiling-request'; +import { PrefillingSearchRequest, DescriptionProfilingRequest } from '@app/core/model/description-profiling-request/description-profiling-request'; import { Description } from '@app/core/model/description/description'; @Injectable() @@ -57,19 +57,20 @@ export class PrefillingSourceService { catchError((error: any) => throwError(error))); } - generate(item: DescriptionProfilingRequest): Observable { - const url = `${this.apiBase}/generate`; + search(item: PrefillingSearchRequest): Observable { + const url = `${this.apiBase}/search`; return this.http - .post(url, item).pipe( + .post(url, item).pipe( catchError((error: any) => throwError(error))); } - generateWithData(item: DescriptionProfilingWithDataRequest): Observable { - const url = `${this.apiBase}/generate-with-data`; + generate(item: DescriptionProfilingRequest, reqFields: string[] = []): Observable { + const url = `${this.apiBase}/generate`; + const options = { params: { f: reqFields } }; return this.http - .post(url, item).pipe( + .post(url, item, options).pipe( catchError((error: any) => throwError(error))); } diff --git a/dmp-frontend/src/app/core/services/prefilling.service.ts b/dmp-frontend/src/app/core/services/prefilling.service.ts deleted file mode 100644 index 4cf7ec2f9..000000000 --- a/dmp-frontend/src/app/core/services/prefilling.service.ts +++ /dev/null @@ -1,27 +0,0 @@ -import { HttpClient, HttpHeaders } from "@angular/common/http"; -import { Injectable } from "@angular/core"; -import { ConfigurationService } from "@app/core/services/configuration/configuration.service"; -import { BaseHttpV2Service } from "./http/base-http-v2.service"; - -@Injectable() -export class PrefillingService { - private readonly actionUrl: string; - private headers = new HttpHeaders(); - - constructor(private http: BaseHttpV2Service, private httpClient: HttpClient, private configurationService: ConfigurationService) { - this.actionUrl = configurationService.server + 'prefilling/'; - } - - //TODO: refactor - // public getPrefillingList(like: string): Observable { - // return this.http.get(this.actionUrl + 'list?like=' + encodeURIComponent(like), { headers: this.headers }); - // } - - // public getPrefillingDataset(pid: string, profileId: string, configId: string): Observable { - // return this.http.get(this.actionUrl + '/generate/' + encodeURIComponent(pid) + '?configId=' + encodeURIComponent(configId) + '&profileId=' + encodeURIComponent(profileId), { headers: this.headers }); - // } - - // public getPrefillingDatasetUsingData(data: any, profileId: string, configId: string): Observable { - // return this.http.post(this.actionUrl + '/generateUsingData' + '?configId=' + encodeURIComponent(configId) + '&profileId=' + encodeURIComponent(profileId), data, { headers: this.headers }); - // } -} diff --git a/dmp-frontend/src/app/ui/admin/prefilling-source/editor/prefilling-source-editor.component.ts b/dmp-frontend/src/app/ui/admin/prefilling-source/editor/prefilling-source-editor.component.ts index 2a0d88c19..5b042bcd3 100644 --- a/dmp-frontend/src/app/ui/admin/prefilling-source/editor/prefilling-source-editor.component.ts +++ b/dmp-frontend/src/app/ui/admin/prefilling-source/editor/prefilling-source-editor.component.ts @@ -105,7 +105,7 @@ export class PrefillingSourceEditorComponent extends BaseEditor { if (result) { + result.dmp = this.item.dmp; + result.dmpDescriptionTemplate = this.item.dmpDescriptionTemplate; + this.prepareForm(result); // this.descriptionModel = this.descriptionModel.fromModel(result); // this.descriptionModel.dmp = data; // this.descriptionModel.dmpSectionIndex = this.dmpSectionIndex; diff --git a/dmp-frontend/src/app/ui/description/editor/prefill-description/prefill-description.component.html b/dmp-frontend/src/app/ui/description/editor/prefill-description/prefill-description.component.html index 8b78f17a5..488fd3944 100644 --- a/dmp-frontend/src/app/ui/description/editor/prefill-description/prefill-description.component.html +++ b/dmp-frontend/src/app/ui/description/editor/prefill-description/prefill-description.component.html @@ -45,17 +45,17 @@ {{'GENERAL.VALIDATION.REQUIRED' | translate}} - +
diff --git a/dmp-frontend/src/app/ui/description/editor/prefill-description/prefill-description.component.ts b/dmp-frontend/src/app/ui/description/editor/prefill-description/prefill-description.component.ts index 108cbbab4..73f4ce789 100644 --- a/dmp-frontend/src/app/ui/description/editor/prefill-description/prefill-description.component.ts +++ b/dmp-frontend/src/app/ui/description/editor/prefill-description/prefill-description.component.ts @@ -1,18 +1,22 @@ import { Component, Inject, OnInit } from "@angular/core"; import { UntypedFormBuilder, UntypedFormGroup, Validators } from "@angular/forms"; import { MAT_DIALOG_DATA, MatDialog, MatDialogRef } from "@angular/material/dialog"; -import { DescriptionProfilingRequest } from "@app/core/model/description-profiling-request/description-profiling-request"; +import { PrefillingSearchRequest, DescriptionProfilingRequest } from "@app/core/model/description-profiling-request/description-profiling-request"; import { DescriptionTemplate } from "@app/core/model/description-template/description-template"; import { Dmp } from "@app/core/model/dmp/dmp"; +import { Prefilling } from "@app/core/model/prefilling-source/prefilling-source"; import { DmpBlueprintService } from "@app/core/services/dmp/dmp-blueprint.service"; import { PrefillingSourceService } from "@app/core/services/prefilling-source/prefilling-source.service"; import { ProgressIndicationService } from "@app/core/services/progress-indication/progress-indication-service"; +import { SingleAutoCompleteConfiguration } from "@app/library/auto-complete/single/single-auto-complete-configuration"; +import { DescriptionTemplateEditorResolver } from "@app/ui/admin/description-template/editor/description-template-editor.resolver"; import { BaseComponent } from "@common/base/base.component"; import { FormService } from "@common/forms/form-service"; import { Guid } from "@common/types/guid"; import { TranslateService } from "@ngx-translate/core"; import { UUID } from "crypto"; -import { takeUntil } from "rxjs/operators"; +import { Observable } from "rxjs"; +import { map, takeUntil } from "rxjs/operators"; @Component({ selector: 'prefill-description-component', @@ -22,7 +26,7 @@ import { takeUntil } from "rxjs/operators"; export class PrefillDescriptionDialogComponent extends BaseComponent implements OnInit { progressIndication = false; - // prefillAutoCompleteConfiguration: SingleAutoCompleteConfiguration; + prefillAutoCompleteConfiguration: SingleAutoCompleteConfiguration; prefillSelected: boolean = false; prefillForm: UntypedFormGroup; @@ -53,18 +57,20 @@ export class PrefillDescriptionDialogComponent extends BaseComponent implements this.prefillForm = this.fb.group({ type: this.fb.control(false), descriptionTemplateId: this.fb.control(null, Validators.required), - prefillingSourceId: this.fb.control(null, Validators.required) + prefillingSourceId: this.fb.control(null, Validators.required), + prefillId: this.fb.control(null, Validators.required), }) // if (this.data.availableProfiles && this.data.availableProfiles.length === 1) { // this.addProfileIfUsedLessThanMax(this.data.availableProfiles[0]); // } - // this.prefillAutoCompleteConfiguration = { - // filterFn: this.searchDescriptions.bind(this), - // loadDataOnStart: false, - // displayFn: (item) => (item['name'].length > 60) ? (item['name'].substr(0, 60) + "...") : item['name'], - // titleFn: (item) => item['name'], - // subtitleFn: (item) => item['pid'] - // }; + this.prefillAutoCompleteConfiguration = { + filterFn: this.searchDescriptions.bind(this), + loadDataOnStart: false, + displayFn: (item) => (item['label'].length > 60) ? (item['label'].substr(0, 60) + "...") : item['label'], + titleFn: (item) => item['label'], + subtitleFn: (item) => item['id'], + valueAssign: (item) => item['id'], + }; } // addProfileIfUsedLessThanMax(profile: DescriptionProfileModel) { @@ -170,17 +176,22 @@ export class PrefillDescriptionDialogComponent extends BaseComponent implements return object1 && object2 && object1.id === object2.id; } - // searchDescriptions(query: string): Observable { - // return this.prefillingService.getPrefillingList(query).pipe(map(prefilling => prefilling.sort((a, b) => { - // if (a.name > b.name) { - // return 1; - // } else if (a.name < b.name) { - // return -1; - // } else { - // return 0; - // } - // }))); - // } + searchDescriptions(query: string): Observable { + const request: PrefillingSearchRequest= { + like: query, + prefillingSourceId: this.prefillForm.get('prefillingSourceId').value + }; + + return this.prefillingSourceService.search(request).pipe(map(prefilling => prefilling.sort((a, b) => { + if (a.label > b.label) { + return 1; + } else if (a.label < b.label) { + return -1; + } else { + return 0; + } + }))); + } next() { // if (this.isPrefilled) { @@ -201,10 +212,15 @@ export class PrefillDescriptionDialogComponent extends BaseComponent implements // } const formData = this.formService.getValue(this.prefillForm.value) as DescriptionProfilingRequest; - this.prefillingSourceService.generate(formData) - .pipe(takeUntil(this._destroyed)).subscribe( + this.prefillingSourceService.generate(formData, DescriptionTemplateEditorResolver.lookupFields()) + .pipe(takeUntil(this._destroyed)).subscribe(description => { + if (description) { + this.closeDialog(description); + } else { + this.closeDialog(); + } + } ); - this.closeDialog(); } closeDialog(result = null): void {