reference-type-refactor

This commit is contained in:
Efstratios Giannopoulos 2024-02-08 18:12:47 +02:00
parent e5946f90cd
commit 4f1b05ab20
100 changed files with 2376 additions and 2617 deletions

View File

@ -23,6 +23,7 @@ public final class Permission {
public static String PublicBrowseUser = "PublicBrowseUser"; public static String PublicBrowseUser = "PublicBrowseUser";
public static String PublicBrowseDashboardStatistics = "PublicBrowseDashboardStatistics"; public static String PublicBrowseDashboardStatistics = "PublicBrowseDashboardStatistics";
public static String PublicSendContactSupport = "PublicSendContactSupport"; public static String PublicSendContactSupport = "PublicSendContactSupport";
public static String PublicBrowseReferenceType = "PublicBrowseReferenceType";
//Elastic //Elastic
public static String ManageElastic = "ManageElastic"; public static String ManageElastic = "ManageElastic";

View File

@ -7,11 +7,13 @@ import java.util.Map;
public enum DmpBlueprintFieldCategory implements DatabaseEnum<Short> { public enum DmpBlueprintFieldCategory implements DatabaseEnum<Short> {
System((short) 0), System((short) 0),
Extra((short) 1); Extra((short) 1),
Reference((short) 1);
public static class Names { public static class Names {
public static final String System = "system"; public static final String System = "system";
public static final String Extra = "extra"; public static final String Extra = "extra";
public static final String Reference = "reference";
} }
private final Short value; private final Short value;

View File

@ -7,17 +7,11 @@ import java.util.Map;
public enum DmpBlueprintSystemFieldType implements DatabaseEnum<Short> { public enum DmpBlueprintSystemFieldType implements DatabaseEnum<Short> {
Text((short)0), //TODO: Rename to "Title" Title((short)0),
HtmlText((short)1), //TODO: Rename to "Description" Description((short)1),
Researchers((short)2), //TODO: replace by reference type Language((short)2),
Organizations((short)3), //TODO: replace by reference type Contact((short)3),
Language((short)4), AccessRights((short)4);
Contact((short)5),
Funder((short)6), //TODO: replace by reference type
Grant((short)7), //TODO: replace by reference type
Project((short)8), //TODO: replace by reference type
License((short)9), //TODO: replace by reference type
AccessRights((short)10);
private final Short value; private final Short value;
DmpBlueprintSystemFieldType(Short value) { DmpBlueprintSystemFieldType(Short value) {

View File

@ -6,42 +6,29 @@ import eu.eudat.data.converters.enums.DatabaseEnum;
import java.util.Map; import java.util.Map;
public enum FieldType implements DatabaseEnum<String> { public enum FieldType implements DatabaseEnum<String> {
EXTERNAL_SELECT(Names.ExternalSelect), //TODO: remove
SELECT(Names.Select), SELECT(Names.Select),
BOOLEAN_DECISION(Names.BooleanDecision), BOOLEAN_DECISION(Names.BooleanDecision),
RADIO_BOX(Names.RadioBox), RADIO_BOX(Names.RadioBox),
INTERNAL_DMP_ENTRIES_RESEARCHERS(Names.InternalDmpResearchers), //TODO: remove
INTERNAL_DMP_ENTRIES_DMPS(Names.InternalDmpDmps), //TODO: rename InternalEntitiesDmps INTERNAL_DMP_ENTRIES_DMPS(Names.InternalDmpDmps), //TODO: rename InternalEntitiesDmps
INTERNAL_DMP_ENTRIES_DATASETS(Names.InternalDmpDescriptions), INTERNAL_DMP_ENTRIES_DATASETS(Names.InternalDmpDescriptions),//TODO: rename InternalEntitiesDescriptions
CHECK_BOX(Names.CheckBox), CHECK_BOX(Names.CheckBox),
FREE_TEXT(Names.FreeText), FREE_TEXT(Names.FreeText),
TEXT_AREA(Names.TextArea), TEXT_AREA(Names.TextArea),
RICH_TEXT_AREA(Names.RichTextarea), RICH_TEXT_AREA(Names.RichTextarea),
UPLOAD(Names.Upload), UPLOAD(Names.Upload),
DATE_PICKER(Names.DatePicker), DATE_PICKER(Names.DatePicker),
EXTERNAL_DATASETS(Names.ExternalDatasets), //TODO: replace with reference type
DATA_REPOSITORIES(Names.DataRepositories), //TODO: replace with reference type
JOURNAL_REPOSITORIES(Names.JournalRepositories), //TODO: replace with reference type
PUB_REPOSITORIES(Names.PubRepositories), //TODO: replace with reference type
LICENSES(Names.Licenses), //TODO: replace with reference type
TAXONOMIES(Names.Taxonomies), //TODO: replace with reference type
PUBLICATIONS(Names.Publications), //TODO: replace with reference type
REGISTRIES(Names.Registries), //TODO: replace with reference type
SERVICES(Names.Services), //TODO: replace with reference type
TAGS(Names.Tags), TAGS(Names.Tags),
RESEARCHERS(Names.Researchers), //TODO: replace with reference type EXTERNAL_DATASETS(Names.ExternalDatasets),
ORGANIZATIONS(Names.Organizations), //TODO: replace with reference type REFERENCE_TYPES(Names.ReferenceTypes),
DATASET_IDENTIFIER(Names.DatasetIdentifier), DATASET_IDENTIFIER(Names.DatasetIdentifier),
CURRENCY(Names.Currency), CURRENCY(Names.Currency),
VALIDATION(Names.Validation); VALIDATION(Names.Validation);
private final String value; private final String value;
public static class Names { public static class Names {
public static final String ExternalSelect = "externalSelect";
public static final String Select = "select"; public static final String Select = "select";
public static final String BooleanDecision = "booleanDecision"; public static final String BooleanDecision = "booleanDecision";
public static final String RadioBox = "radiobox"; public static final String RadioBox = "radiobox";
public static final String InternalDmpResearchers = "internalDmpResearchers";
public static final String InternalDmpDmps = "internalDmpDmps"; public static final String InternalDmpDmps = "internalDmpDmps";
public static final String InternalDmpDescriptions = "internalDmpDatasets"; public static final String InternalDmpDescriptions = "internalDmpDatasets";
public static final String CheckBox = "checkBox"; public static final String CheckBox = "checkBox";
@ -50,21 +37,12 @@ public enum FieldType implements DatabaseEnum<String> {
public static final String RichTextarea = "richTextarea"; public static final String RichTextarea = "richTextarea";
public static final String Upload = "upload"; public static final String Upload = "upload";
public static final String DatePicker = "datePicker"; public static final String DatePicker = "datePicker";
public static final String ExternalDatasets = "externalDatasets";
public static final String DataRepositories = "dataRepositories";
public static final String JournalRepositories = "journalRepositories";
public static final String PubRepositories = "pubRepositories";
public static final String Licenses = "licenses";
public static final String Taxonomies = "taxonomies";
public static final String Publications = "publications";
public static final String Registries = "registries";
public static final String Services = "services";
public static final String Tags = "tags"; public static final String Tags = "tags";
public static final String Researchers = "researchers";
public static final String Organizations = "organizations";
public static final String DatasetIdentifier = "datasetIdentifier"; public static final String DatasetIdentifier = "datasetIdentifier";
public static final String Currency = "currency"; public static final String Currency = "currency";
public static final String Validation = "validation"; public static final String Validation = "validation";
public static final String ReferenceTypes = "referenceTypes";
public static final String ExternalDatasets = "externalDatasets";
} }
FieldType(String value) { FieldType(String value) {
@ -82,15 +60,9 @@ public enum FieldType implements DatabaseEnum<String> {
return map.get(i); return map.get(i);
} }
public static boolean isNotImplemented(FieldType fieldType){
return fieldType.equals(FieldType.EXTERNAL_SELECT);
}
public static boolean isReferenceType(FieldType fieldType){ public static boolean isReferenceType(FieldType fieldType){
return fieldType.equals(FieldType.ORGANIZATIONS) || fieldType.equals(FieldType.RESEARCHERS) || fieldType.equals(FieldType.SERVICES) || return fieldType.equals(FieldType.REFERENCE_TYPES);
fieldType.equals(FieldType.REGISTRIES) || fieldType.equals(FieldType.PUBLICATIONS) || fieldType.equals(FieldType.TAXONOMIES)||
fieldType.equals(FieldType.LICENSES) || fieldType.equals(FieldType.DATA_REPOSITORIES) || fieldType.equals(FieldType.PUB_REPOSITORIES)||
fieldType.equals(FieldType.JOURNAL_REPOSITORIES) || fieldType.equals(FieldType.EXTERNAL_DATASETS);
} }
public static boolean isTextType(FieldType fieldType){ public static boolean isTextType(FieldType fieldType){
@ -100,7 +72,7 @@ public enum FieldType implements DatabaseEnum<String> {
} }
public static boolean isTextListType(FieldType fieldType){ public static boolean isTextListType(FieldType fieldType){
return fieldType.equals(FieldType.SELECT) || fieldType.equals(FieldType.TAGS) || fieldType.equals(FieldType.INTERNAL_DMP_ENTRIES_RESEARCHERS) || fieldType.equals(FieldType.INTERNAL_DMP_ENTRIES_DMPS) || return fieldType.equals(FieldType.SELECT) || fieldType.equals(FieldType.TAGS) || fieldType.equals(FieldType.INTERNAL_DMP_ENTRIES_DMPS) ||
fieldType.equals(FieldType.INTERNAL_DMP_ENTRIES_DATASETS); fieldType.equals(FieldType.INTERNAL_DMP_ENTRIES_DATASETS);
} }

View File

@ -1,39 +0,0 @@
package eu.eudat.commons.enums;
import com.fasterxml.jackson.annotation.JsonValue;
import eu.eudat.data.converters.enums.DatabaseEnum;
import java.util.Map;
public enum ReferenceType implements DatabaseEnum<Short> {
Taxonomies((short) 0),
Licenses((short) 1),
Publications((short) 2),
Journals((short) 3),
PubRepositories((short) 4),
DataRepositories((short) 5),
Registries((short) 6),
Services((short) 7),
Project((short) 8),
Funder((short) 9),
Datasets((short) 10),
Organizations((short) 11),
Grants((short) 12),
Researcher((short) 13);
private final Short value;
ReferenceType(Short value) {
this.value = value;
}
@JsonValue
public Short getValue() {
return value;
}
private static final Map<Short, ReferenceType> map = EnumUtils.getEnumValueMap(ReferenceType.class);
public static ReferenceType of(Short i) {
return map.get(i);
}
}

View File

@ -30,7 +30,7 @@ public class FieldEntity {
@XmlElement(name = UploadDataEntity.XmlElementName, type = UploadDataEntity.class), @XmlElement(name = UploadDataEntity.XmlElementName, type = UploadDataEntity.class),
@XmlElement(name = RadioBoxDataEntity.XmlElementName, type = RadioBoxDataEntity.class), @XmlElement(name = RadioBoxDataEntity.XmlElementName, type = RadioBoxDataEntity.class),
@XmlElement(name = SelectDataEntity.XmlElementName, type = SelectDataEntity.class), @XmlElement(name = SelectDataEntity.XmlElementName, type = SelectDataEntity.class),
@XmlElement(name = ExternalSelectDataEntity.XmlElementName, type = ExternalSelectDataEntity.class), @XmlElement(name = ReferenceTypeDataEntity.XmlElementName, type = ReferenceTypeDataEntity.class)
}) })
private BaseFieldDataEntity data; private BaseFieldDataEntity data;
@XmlElementWrapper(name = "validations") @XmlElementWrapper(name = "validations")

View File

@ -1,171 +0,0 @@
package eu.eudat.commons.types.descriptiontemplate.fielddata;
import jakarta.xml.bind.annotation.*;
import java.util.List;
@XmlAccessorType(XmlAccessType.FIELD)
public class ExternalSelectDataEntity extends LabelAndMultiplicityDataEntity {
public static final String XmlElementName = "externalSelectData";
@XmlAccessorType(XmlAccessType.FIELD)
public static class ExternalSelectAuthDataEntity {
@XmlAttribute(name="url")
private String url;
@XmlAttribute(name="method")
private String method;
@XmlAttribute(name="body")
private String body;
@XmlAttribute(name="path")
private String path;
@XmlAttribute(name="type")
private String type;
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public String getMethod() {
return method;
}
public void setMethod(String method) {
this.method = method;
}
public String getBody() {
return body;
}
public void setBody(String body) {
this.body = body;
}
public String getPath() {
return path;
}
public void setPath(String path) {
this.path = path;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
}
@XmlAccessorType(XmlAccessType.FIELD)
public static class ExternalSelectSourceBindingEntity {
@XmlAttribute(name="label")
private String label;
@XmlAttribute(name="value")
private String value;
@XmlAttribute(name="source")
private String source;
public String getLabel() {
return label;
}
public void setLabel(String label) {
this.label = label;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
public String getSource() {
return source;
}
public void setSource(String source) {
this.source = source;
}
}
@XmlAccessorType(XmlAccessType.FIELD)
public static class ExternalSelectSourceEntity {
@XmlAttribute(name="url")
private String url;
@XmlAttribute(name="method")
private String method;
@XmlAttribute(name="optionsRoot")
private String optionsRoot;
@XmlElement(name="sourceBinding")
private ExternalSelectSourceBindingEntity sourceBinding;
@XmlAttribute(name="hasAuth")
private Boolean hasAuth;
@XmlElement(name="auth")
private ExternalSelectAuthDataEntity auth;
public String getOptionsRoot() {
return optionsRoot;
}
public void setOptionsRoot(String optionsRoot) {
this.optionsRoot = optionsRoot;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public Boolean getHasAuth() {
return hasAuth;
}
public void setHasAuth(Boolean hasAuth) {
this.hasAuth = hasAuth;
}
public ExternalSelectAuthDataEntity getAuth() {
return auth;
}
public void setAuth(ExternalSelectAuthDataEntity auth) {
this.auth = auth;
}
public ExternalSelectSourceBindingEntity getSourceBinding() {
return sourceBinding;
}
public void setSourceBinding(ExternalSelectSourceBindingEntity sourceBinding) {
this.sourceBinding = sourceBinding;
}
public String getMethod() {
return method;
}
public void setMethod(String method) {
this.method = method;
}
}
@XmlElementWrapper(name = "sources")
@XmlElement(name = "source")
private List<ExternalSelectSourceEntity> sources;
public List<ExternalSelectSourceEntity> getSources() {
return sources;
}
public void setSources(List<ExternalSelectSourceEntity> externalSelectSourceEntityList) {
this.sources = externalSelectSourceEntityList;
}
}

View File

@ -0,0 +1,33 @@
package eu.eudat.commons.types.descriptiontemplate.fielddata;
import jakarta.xml.bind.annotation.XmlAccessType;
import jakarta.xml.bind.annotation.XmlAccessorType;
import jakarta.xml.bind.annotation.XmlAttribute;
import java.util.UUID;
@XmlAccessorType(XmlAccessType.FIELD)
public class ReferenceTypeDataEntity extends BaseFieldDataEntity {
public static final String XmlElementName = "referenceTypeData";
@XmlAttribute(name = "multipleSelect")
private Boolean multipleSelect;
@XmlAttribute(name = "referenceTypeId")
private UUID referenceTypeId;
public Boolean getMultipleSelect() {
return multipleSelect;
}
public void setMultipleSelect(Boolean multipleSelect) {
this.multipleSelect = multipleSelect;
}
public UUID getReferenceTypeId() {
return referenceTypeId;
}
public void setReferenceTypeId(UUID referenceTypeId) {
this.referenceTypeId = referenceTypeId;
}
}

View File

@ -40,7 +40,7 @@ public class FieldImportExport {
@XmlElement(name = UploadDataImportExport.XmlElementName, type = UploadDataImportExport.class), @XmlElement(name = UploadDataImportExport.XmlElementName, type = UploadDataImportExport.class),
@XmlElement(name = RadioBoxDataImportExport.XmlElementName, type = RadioBoxDataImportExport.class), @XmlElement(name = RadioBoxDataImportExport.XmlElementName, type = RadioBoxDataImportExport.class),
@XmlElement(name = SelectDataImportExport.XmlElementName, type = SelectDataImportExport.class), @XmlElement(name = SelectDataImportExport.XmlElementName, type = SelectDataImportExport.class),
@XmlElement(name = ExternalSelectImportExport.XmlElementName, type = ExternalSelectImportExport.class), @XmlElement(name = ReferenceTypeDataImportExport.XmlElementName, type = ReferenceTypeDataImportExport.class),
}) })
private BaseFieldDataImportExport data; private BaseFieldDataImportExport data;

View File

@ -1,174 +0,0 @@
package eu.eudat.commons.types.descriptiontemplate.importexport.fielddata;
import jakarta.xml.bind.annotation.*;
import java.util.List;
@XmlAccessorType(XmlAccessType.FIELD)
public class ExternalSelectImportExport extends LabelAndMultiplicityDataImportExport {
public static final String XmlElementName = "externalSelectData";
@XmlAccessorType(XmlAccessType.FIELD)
public static class ExternalSelectAuthImportExport {
@XmlAttribute(name="url")
private String url;
@XmlAttribute(name="method")
private String method;
@XmlAttribute(name="body")
private String body;
@XmlAttribute(name="path")
private String path;
@XmlAttribute(name="type")
private String type;
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public String getMethod() {
return method;
}
public void setMethod(String method) {
this.method = method;
}
public String getBody() {
return body;
}
public void setBody(String body) {
this.body = body;
}
public String getPath() {
return path;
}
public void setPath(String path) {
this.path = path;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
}
@XmlAccessorType(XmlAccessType.FIELD)
public static class ExternalSelectSourceBindingImportExport {
@XmlAttribute(name="label")
private String label;
@XmlAttribute(name="value")
private String value;
@XmlAttribute(name="source")
private String source;
public String getLabel() {
return label;
}
public void setLabel(String label) {
this.label = label;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
public String getSource() {
return source;
}
public void setSource(String source) {
this.source = source;
}
}
@XmlAccessorType(XmlAccessType.FIELD)
public static class ExternalSelectSourceImportExport {
@XmlAttribute(name="url")
private String url;
@XmlAttribute(name="method")
private String method;
@XmlAttribute(name="optionsRoot")
private String optionsRoot;
@XmlElement(name="sourceBinding")
private ExternalSelectSourceBindingImportExport sourceBinding;
@XmlAttribute(name="hasAuth")
private Boolean hasAuth;
@XmlElement(name="auth")
private ExternalSelectAuthImportExport auth;
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public String getMethod() {
return method;
}
public void setMethod(String method) {
this.method = method;
}
public String getOptionsRoot() {
return optionsRoot;
}
public void setOptionsRoot(String optionsRoot) {
this.optionsRoot = optionsRoot;
}
public ExternalSelectSourceBindingImportExport getSourceBinding() {
return sourceBinding;
}
public void setSourceBinding(ExternalSelectSourceBindingImportExport sourceBinding) {
this.sourceBinding = sourceBinding;
}
public Boolean getHasAuth() {
return hasAuth;
}
public void setHasAuth(Boolean hasAuth) {
this.hasAuth = hasAuth;
}
public ExternalSelectAuthImportExport getAuth() {
return auth;
}
public void setAuth(ExternalSelectAuthImportExport auth) {
this.auth = auth;
}
}
@XmlElementWrapper(name = "sources")
@XmlElement(name = "source")
private List<ExternalSelectSourceImportExport> sources;
public List<ExternalSelectSourceImportExport> getSources() {
return sources;
}
public void setSources(List<ExternalSelectSourceImportExport> sources) {
this.sources = sources;
}
}

View File

@ -20,3 +20,4 @@ public class LabelAndMultiplicityDataImportExport extends BaseFieldDataImportExp
} }
} }

View File

@ -0,0 +1,34 @@
package eu.eudat.commons.types.descriptiontemplate.importexport.fielddata;
import jakarta.xml.bind.annotation.XmlAccessType;
import jakarta.xml.bind.annotation.XmlAccessorType;
import jakarta.xml.bind.annotation.XmlAttribute;
import java.util.UUID;
@XmlAccessorType(XmlAccessType.FIELD)
public class ReferenceTypeDataImportExport extends BaseFieldDataImportExport {
public static final String XmlElementName = "labelAndMultiplicityData";
@XmlAttribute(name = "multipleSelect")
private Boolean multipleSelect;
@XmlAttribute(name = "referenceTypeId")
private UUID referenceTypeId;
public Boolean getMultipleSelect() {
return multipleSelect;
}
public void setMultipleSelect(Boolean multipleSelect) {
this.multipleSelect = multipleSelect;
}
public UUID getReferenceTypeId() {
return referenceTypeId;
}
public void setReferenceTypeId(UUID referenceTypeId) {
this.referenceTypeId = referenceTypeId;
}
}

View File

@ -2,7 +2,9 @@ package eu.eudat.commons.types.dmpblueprint;
import jakarta.xml.bind.annotation.*; import jakarta.xml.bind.annotation.*;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.UUID;
@XmlRootElement(name = "root") @XmlRootElement(name = "root")
@XmlAccessorType(XmlAccessType.FIELD) @XmlAccessorType(XmlAccessType.FIELD)
@ -17,4 +19,18 @@ public class DefinitionEntity {
public void setSections(List<SectionEntity> sections) { public void setSections(List<SectionEntity> sections) {
this.sections = sections; this.sections = sections;
} }
public List<FieldEntity> getAllField(){
List<FieldEntity> fieldEntities = new ArrayList<>();
if (this.getSections() != null){
for (SectionEntity sectionEntity: this.getSections()) {
fieldEntities.addAll(sectionEntity.getAllField());
}
}
return fieldEntities;
}
public List<FieldEntity> getFieldById(UUID id) {
return this.getAllField().stream().filter(x-> id.equals(x.getId())).toList();
}
} }

View File

@ -0,0 +1,22 @@
package eu.eudat.commons.types.dmpblueprint;
import jakarta.xml.bind.annotation.XmlAccessType;
import jakarta.xml.bind.annotation.XmlAccessorType;
import jakarta.xml.bind.annotation.XmlAttribute;
import java.util.UUID;
@XmlAccessorType(XmlAccessType.FIELD)
public class ReferenceFieldEntity extends FieldEntity {
@XmlAttribute(name="referenceTypeId")
private UUID referenceTypeId;
public UUID getReferenceTypeId() {
return referenceTypeId;
}
public void setReferenceTypeId(UUID referenceTypeId) {
this.referenceTypeId = referenceTypeId;
}
}

View File

@ -3,6 +3,7 @@ package eu.eudat.commons.types.dmpblueprint;
import eu.eudat.commons.enums.DmpBlueprintFieldCategory; import eu.eudat.commons.enums.DmpBlueprintFieldCategory;
import jakarta.xml.bind.annotation.*; import jakarta.xml.bind.annotation.*;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
@ -25,6 +26,7 @@ public class SectionEntity {
@XmlElements({ @XmlElements({
@XmlElement(name = DmpBlueprintFieldCategory.Names.Extra, type = ExtraFieldEntity.class), @XmlElement(name = DmpBlueprintFieldCategory.Names.Extra, type = ExtraFieldEntity.class),
@XmlElement(name = DmpBlueprintFieldCategory.Names.System, type = SystemFieldEntity.class), @XmlElement(name = DmpBlueprintFieldCategory.Names.System, type = SystemFieldEntity.class),
@XmlElement(name = DmpBlueprintFieldCategory.Names.Reference, type = ReferenceFieldEntity.class),
}) })
private List<FieldEntity> fields; private List<FieldEntity> fields;
@ -84,4 +86,8 @@ public class SectionEntity {
this.descriptionTemplates = descriptionTemplates; this.descriptionTemplates = descriptionTemplates;
} }
public List<FieldEntity> getAllField(){
return this.getFields() != null ? this.getFields() : new ArrayList<>();
}
} }

View File

@ -5,6 +5,8 @@ import jakarta.xml.bind.annotation.XmlAccessType;
import jakarta.xml.bind.annotation.XmlAccessorType; import jakarta.xml.bind.annotation.XmlAccessorType;
import jakarta.xml.bind.annotation.XmlAttribute; import jakarta.xml.bind.annotation.XmlAttribute;
import java.util.UUID;
@XmlAccessorType(XmlAccessType.FIELD) @XmlAccessorType(XmlAccessType.FIELD)
public class SystemFieldEntity extends FieldEntity { public class SystemFieldEntity extends FieldEntity {

View File

@ -0,0 +1,84 @@
package eu.eudat.commons.types.dmpblueprint.importexport;
import jakarta.xml.bind.annotation.XmlAccessType;
import jakarta.xml.bind.annotation.XmlAccessorType;
import jakarta.xml.bind.annotation.XmlAttribute;
import java.util.UUID;
@XmlAccessorType(XmlAccessType.FIELD)
public class ReferenceFieldImportExport {
@XmlAttribute(name = "id")
private UUID id;
@XmlAttribute(name = "referenceTypeId")
private UUID referenceTypeId;
@XmlAttribute(name = "label")
private String label;
@XmlAttribute(name = "placeholder")
private String placeholder;
@XmlAttribute(name = "description")
private String description;
@XmlAttribute(name = "ordinal")
private int ordinal;
@XmlAttribute(name = "required")
private boolean required;
public UUID getId() {
return id;
}
public void setId(UUID id) {
this.id = id;
}
public UUID getReferenceTypeId() {
return referenceTypeId;
}
public void setReferenceTypeId(UUID referenceTypeId) {
this.referenceTypeId = referenceTypeId;
}
public String getLabel() {
return label;
}
public void setLabel(String label) {
this.label = label;
}
public String getPlaceholder() {
return placeholder;
}
public void setPlaceholder(String placeholder) {
this.placeholder = placeholder;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public int getOrdinal() {
return ordinal;
}
public void setOrdinal(int ordinal) {
this.ordinal = ordinal;
}
public boolean isRequired() {
return required;
}
public void setRequired(boolean required) {
this.required = required;
}
}

View File

@ -22,6 +22,9 @@ public class SectionImportExport {
@XmlElementWrapper(name = "extraFields") @XmlElementWrapper(name = "extraFields")
@XmlElement(name = "extraField") @XmlElement(name = "extraField")
private List<ExtraFieldImportExport> extraFields; private List<ExtraFieldImportExport> extraFields;
@XmlElementWrapper(name = "referenceFields")
@XmlElement(name = "referenceField")
private List<ReferenceFieldImportExport> referenceFields;
@XmlAttribute(name = "hasTemplates") @XmlAttribute(name = "hasTemplates")
private boolean hasTemplates; private boolean hasTemplates;
@XmlElementWrapper(name = "descriptionTemplates") @XmlElementWrapper(name = "descriptionTemplates")
@ -76,6 +79,14 @@ public class SectionImportExport {
this.extraFields = extraFields; this.extraFields = extraFields;
} }
public List<ReferenceFieldImportExport> getReferenceFields() {
return referenceFields;
}
public void setReferenceFields(List<ReferenceFieldImportExport> referenceFields) {
this.referenceFields = referenceFields;
}
public boolean isHasTemplates() { public boolean isHasTemplates() {
return hasTemplates; return hasTemplates;
} }

View File

@ -2,10 +2,8 @@ package eu.eudat.data;
import eu.eudat.commons.enums.IsActive; import eu.eudat.commons.enums.IsActive;
import eu.eudat.commons.enums.ReferenceSourceType; import eu.eudat.commons.enums.ReferenceSourceType;
import eu.eudat.commons.enums.ReferenceType;
import eu.eudat.data.converters.enums.IsActiveConverter; import eu.eudat.data.converters.enums.IsActiveConverter;
import eu.eudat.data.converters.enums.ReferenceSourceTypeConverter; import eu.eudat.data.converters.enums.ReferenceSourceTypeConverter;
import eu.eudat.data.converters.enums.ReferenceTypeConverter;
import eu.eudat.data.tenant.TenantScopedBaseEntity; import eu.eudat.data.tenant.TenantScopedBaseEntity;
import jakarta.persistence.*; import jakarta.persistence.*;
@ -30,10 +28,9 @@ public class ReferenceEntity extends TenantScopedBaseEntity {
public static final int _labelLength = 500; public static final int _labelLength = 500;
@Column(name = "type", nullable = false) @Column(name = "type", nullable = false)
@Convert(converter = ReferenceTypeConverter.class) private UUID typeId;
private ReferenceType type;
public static final String _type = "type"; public static final String _typeId = "typeId";
@Column(name = "description") @Column(name = "description")
private String description; private String description;
@ -109,12 +106,12 @@ public class ReferenceEntity extends TenantScopedBaseEntity {
this.label = label; this.label = label;
} }
public ReferenceType getType() { public UUID getTypeId() {
return type; return typeId;
} }
public void setType(ReferenceType type) { public void setTypeId(UUID typeId) {
this.type = type; this.typeId = typeId;
} }
public String getDescription() { public String getDescription() {

View File

@ -1,48 +0,0 @@
package eu.eudat.data.converters;
import jakarta.persistence.AttributeConverter;
import jakarta.persistence.Converter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;
/**
* Created by ikalyvas on 9/25/2018.
*/
@Converter
public class DateToUTCConverter implements AttributeConverter<Date, Date> {
private static final Logger logger = LoggerFactory.getLogger(DateToUTCConverter.class);
@Override
public Date convertToDatabaseColumn(Date attribute) {
if(attribute == null) return null;
DateFormat formatterIST = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
formatterIST.setTimeZone(TimeZone.getTimeZone("UTC"));
try {
String date = formatterIST.format(attribute);
return formatterIST.parse(date);
} catch (ParseException e) {
logger.error(e.getMessage(), e);
}
return null;
}
@Override
public Date convertToEntityAttribute(Date dbData) {
if(dbData == null) return null;
DateFormat formatterIST = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
formatterIST.setTimeZone(TimeZone.getTimeZone("UTC"));
try {
String date = formatterIST.format(dbData);
return formatterIST.parse(date);
} catch (ParseException e) {
logger.error(e.getMessage(), e);
}
return null;
}
}

View File

@ -1,11 +0,0 @@
package eu.eudat.data.converters.enums;
import eu.eudat.commons.enums.ReferenceType;
import jakarta.persistence.Converter;
@Converter
public class ReferenceTypeConverter extends DatabaseEnumConverter<ReferenceType, Short> {
public ReferenceType of(Short i) {
return ReferenceType.of(i);
}
}

View File

@ -1,14 +0,0 @@
package eu.eudat.data.old.helpers;
import jakarta.persistence.Tuple;
import java.util.List;
public class EntityBinder {
public static <T> T fromTuple(List<Tuple> tuple, String path) {
try {
return (T) tuple.get(0).get(path);
}catch (IllegalArgumentException illegalArgument){
return null;
}
}
}

View File

@ -0,0 +1,27 @@
package eu.eudat.model;
public class DashboardReferenceTypeStatistics {
private long count;
public static final String _count = "count";
private PublicReferenceType referenceType;
public static final String _referenceType = "referenceType";
public long getCount() {
return count;
}
public void setCount(long count) {
this.count = count;
}
public PublicReferenceType getReferenceType() {
return referenceType;
}
public void setReferenceType(PublicReferenceType referenceType) {
this.referenceType = referenceType;
}
}

View File

@ -1,5 +1,8 @@
package eu.eudat.model; package eu.eudat.model;
import java.util.List;
import java.util.UUID;
public class DashboardStatistics { public class DashboardStatistics {
private long dmpCount; private long dmpCount;
@ -8,15 +11,7 @@ public class DashboardStatistics {
private long descriptionCount; private long descriptionCount;
public static final String _descriptionCount = "descriptionCount"; private List<DashboardReferenceTypeStatistics> referenceTypeStatistics;
private long organizationCount;
public static final String _organizationCount = "organizationCount";
private long grantCount;
public static final String _grantCount = "grantCount";
public long getDmpCount() { public long getDmpCount() {
return dmpCount; return dmpCount;
@ -34,19 +29,11 @@ public class DashboardStatistics {
this.descriptionCount = descriptionCount; this.descriptionCount = descriptionCount;
} }
public long getOrganizationCount() { public List<DashboardReferenceTypeStatistics> getReferenceTypeStatistics() {
return organizationCount; return referenceTypeStatistics;
} }
public void setOrganizationCount(long organizationCount) { public void setReferenceTypeStatistics(List<DashboardReferenceTypeStatistics> referenceTypeStatistics) {
this.organizationCount = organizationCount; this.referenceTypeStatistics = referenceTypeStatistics;
}
public long getGrantCount() {
return grantCount;
}
public void setGrantCount(long grantCount) {
this.grantCount = grantCount;
} }
} }

View File

@ -1,12 +1,5 @@
package eu.eudat.model; package eu.eudat.model;
import eu.eudat.commons.enums.IsActive;
import eu.eudat.commons.enums.ReferenceSourceType;
import eu.eudat.commons.enums.ReferenceType;
import eu.eudat.model.referencedefinition.Definition;
import java.time.Instant;
import java.util.List;
import java.util.UUID; import java.util.UUID;
public class PublicReference { public class PublicReference {
@ -17,7 +10,7 @@ public class PublicReference {
private String label; private String label;
public static final String _label = "label"; public static final String _label = "label";
private ReferenceType type; private PublicReferenceType type;
public static final String _type = "type"; public static final String _type = "type";
private String description; private String description;
@ -42,11 +35,11 @@ public class PublicReference {
this.label = label; this.label = label;
} }
public ReferenceType getType() { public PublicReferenceType getType() {
return type; return type;
} }
public void setType(ReferenceType type) { public void setType(PublicReferenceType type) {
this.type = type; this.type = type;
} }
@ -66,3 +59,5 @@ public class PublicReference {
this.reference = reference; this.reference = reference;
} }
} }

View File

@ -0,0 +1,30 @@
package eu.eudat.model;
import java.util.UUID;
public class PublicReferenceType {
private UUID id;
public static final String _id = "id";
private String name;
public static final String _name = "name";
public UUID getId() {
return id;
}
public void setId(UUID id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}

View File

@ -1,6 +1,5 @@
package eu.eudat.model; package eu.eudat.model;
import eu.eudat.commons.enums.ReferenceType;
import eu.eudat.commons.enums.IsActive; import eu.eudat.commons.enums.IsActive;
import eu.eudat.commons.enums.ReferenceSourceType; import eu.eudat.commons.enums.ReferenceSourceType;
import eu.eudat.model.referencedefinition.Definition; import eu.eudat.model.referencedefinition.Definition;

View File

@ -1,10 +1,20 @@
package eu.eudat.model.builder; package eu.eudat.model.builder;
import eu.eudat.authorization.AuthorizationFlags; import eu.eudat.authorization.AuthorizationFlags;
import eu.eudat.commons.enums.IsActive;
import eu.eudat.convention.ConventionService; import eu.eudat.convention.ConventionService;
import eu.eudat.data.DmpReferenceEntity;
import eu.eudat.data.ReferenceEntity; import eu.eudat.data.ReferenceEntity;
import eu.eudat.model.PublicDmp;
import eu.eudat.model.PublicDmpUser;
import eu.eudat.model.PublicReference; import eu.eudat.model.PublicReference;
import eu.eudat.model.PublicReferenceType;
import eu.eudat.query.DmpQuery;
import eu.eudat.query.ReferenceTypeQuery;
import gr.cite.tools.data.builder.BuilderFactory;
import gr.cite.tools.data.query.QueryFactory;
import gr.cite.tools.exception.MyApplicationException; import gr.cite.tools.exception.MyApplicationException;
import gr.cite.tools.fieldset.BaseFieldSet;
import gr.cite.tools.fieldset.FieldSet; import gr.cite.tools.fieldset.FieldSet;
import gr.cite.tools.logging.DataLogEntry; import gr.cite.tools.logging.DataLogEntry;
import gr.cite.tools.logging.LoggerService; import gr.cite.tools.logging.LoggerService;
@ -15,17 +25,22 @@ import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.*; import java.util.*;
import java.util.stream.Collectors;
@Component @Component
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class PublicReferenceBuilder extends BaseBuilder<PublicReference, ReferenceEntity>{ public class PublicReferenceBuilder extends BaseBuilder<PublicReference, ReferenceEntity>{
private final BuilderFactory builderFactory;
private final QueryFactory queryFactory;
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None); private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
@Autowired @Autowired
public PublicReferenceBuilder( public PublicReferenceBuilder(
ConventionService conventionService) { ConventionService conventionService, BuilderFactory builderFactory, QueryFactory queryFactory) {
super(conventionService, new LoggerService(LoggerFactory.getLogger(PublicReferenceBuilder.class))); super(conventionService, new LoggerService(LoggerFactory.getLogger(PublicReferenceBuilder.class)));
this.builderFactory = builderFactory;
this.queryFactory = queryFactory;
} }
public PublicReferenceBuilder authorize(EnumSet<AuthorizationFlags> values) { public PublicReferenceBuilder authorize(EnumSet<AuthorizationFlags> values) {
@ -40,6 +55,10 @@ public class PublicReferenceBuilder extends BaseBuilder<PublicReference, Referen
if (fields == null || data == null || fields.isEmpty()) if (fields == null || data == null || fields.isEmpty())
return new ArrayList<>(); return new ArrayList<>();
FieldSet typeFields = fields.extractPrefixed(this.asPrefix(PublicReference._type));
Map<UUID, PublicReferenceType> typeItemsMap = this.collectReferenceTypes(typeFields, data);
List<PublicReference> models = new ArrayList<>(); List<PublicReference> models = new ArrayList<>();
for (ReferenceEntity d : data) { for (ReferenceEntity d : data) {
PublicReference m = new PublicReference(); PublicReference m = new PublicReference();
@ -47,10 +66,39 @@ public class PublicReferenceBuilder extends BaseBuilder<PublicReference, Referen
if (fields.hasField(this.asIndexer(PublicReference._label))) m.setLabel(d.getLabel()); if (fields.hasField(this.asIndexer(PublicReference._label))) m.setLabel(d.getLabel());
if (fields.hasField(this.asIndexer(PublicReference._reference))) m.setReference(d.getReference()); if (fields.hasField(this.asIndexer(PublicReference._reference))) m.setReference(d.getReference());
if (fields.hasField(this.asIndexer(PublicReference._description))) m.setDescription(d.getDescription()); if (fields.hasField(this.asIndexer(PublicReference._description))) m.setDescription(d.getDescription());
if (fields.hasField(this.asIndexer(PublicReference._type))) m.setType(d.getType()); if (!typeFields.isEmpty() && typeItemsMap != null && typeItemsMap.containsKey(d.getTypeId())) m.setType(typeItemsMap.get(d.getTypeId()));
models.add(m); models.add(m);
} }
this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0)); this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0));
return models; return models;
} }
private Map<UUID, PublicReferenceType> collectReferenceTypes(FieldSet fields, List<ReferenceEntity> data) throws MyApplicationException {
if (fields.isEmpty() || data.isEmpty())
return null;
this.logger.debug("checking related - {}", PublicReferenceType.class.getSimpleName());
Map<UUID, PublicReferenceType> itemMap;
if (!fields.hasOtherField(this.asIndexer(PublicReferenceType._id))) {
itemMap = this.asEmpty(
data.stream().map(ReferenceEntity::getTypeId).distinct().collect(Collectors.toList()),
x -> {
PublicReferenceType item = new PublicReferenceType();
item.setId(x);
return item;
},
PublicReferenceType::getId);
} else {
FieldSet clone = new BaseFieldSet(fields.getFields()).ensure(PublicReferenceType._id);
ReferenceTypeQuery q = this.queryFactory.query(ReferenceTypeQuery.class).authorize(this.authorize).isActive(IsActive.Active).ids(data.stream().map(ReferenceEntity::getTypeId).distinct().collect(Collectors.toList()));
itemMap = this.builderFactory.builder(PublicReferenceTypeBuilder.class).authorize(this.authorize).asForeignKey(q, clone, PublicReferenceType::getId);
}
if (!fields.hasField(PublicReferenceType._id)) {
itemMap.values().stream().filter(Objects::nonNull).peek(x -> x.setId(null)).collect(Collectors.toList());
}
return itemMap;
}
} }

View File

@ -0,0 +1,53 @@
package eu.eudat.model.builder;
import eu.eudat.authorization.AuthorizationFlags;
import eu.eudat.convention.ConventionService;
import eu.eudat.data.ReferenceTypeEntity;
import eu.eudat.model.PublicReferenceType;
import gr.cite.tools.exception.MyApplicationException;
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.*;
@Component
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class PublicReferenceTypeBuilder extends BaseBuilder<PublicReferenceType, ReferenceTypeEntity>{
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
@Autowired
public PublicReferenceTypeBuilder(
ConventionService conventionService) {
super(conventionService, new LoggerService(LoggerFactory.getLogger(PublicReferenceTypeBuilder.class)));
}
public PublicReferenceTypeBuilder authorize(EnumSet<AuthorizationFlags> values) {
this.authorize = values;
return this;
}
@Override
public List<PublicReferenceType> build(FieldSet fields, List<ReferenceTypeEntity> 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<PublicReferenceType> models = new ArrayList<>();
for (ReferenceTypeEntity d : data) {
PublicReferenceType m = new PublicReferenceType();
if (fields.hasField(this.asIndexer(PublicReferenceType._id))) m.setId(d.getId());
if (fields.hasField(this.asIndexer(PublicReferenceType._name))) m.setName(d.getName());
models.add(m);
}
this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0));
return models;
}
}

View File

@ -8,9 +8,11 @@ import eu.eudat.data.DescriptionEntity;
import eu.eudat.data.ReferenceEntity; import eu.eudat.data.ReferenceEntity;
import eu.eudat.model.DmpReference; import eu.eudat.model.DmpReference;
import eu.eudat.model.Reference; import eu.eudat.model.Reference;
import eu.eudat.model.ReferenceType;
import eu.eudat.model.User; import eu.eudat.model.User;
import eu.eudat.model.builder.referencedefinition.DefinitionBuilder; import eu.eudat.model.builder.referencedefinition.DefinitionBuilder;
import eu.eudat.query.DmpReferenceQuery; import eu.eudat.query.DmpReferenceQuery;
import eu.eudat.query.ReferenceTypeQuery;
import eu.eudat.query.UserQuery; import eu.eudat.query.UserQuery;
import gr.cite.tools.data.builder.BuilderFactory; import gr.cite.tools.data.builder.BuilderFactory;
import gr.cite.tools.data.query.QueryFactory; import gr.cite.tools.data.query.QueryFactory;
@ -68,6 +70,9 @@ public class ReferenceBuilder extends BaseBuilder<Reference, ReferenceEntity>{
FieldSet userFields = fields.extractPrefixed(this.asPrefix(Reference._createdBy)); FieldSet userFields = fields.extractPrefixed(this.asPrefix(Reference._createdBy));
Map<UUID, User> userItemsMap = this.collectUsers(userFields, data); Map<UUID, User> userItemsMap = this.collectUsers(userFields, data);
FieldSet typeFields = fields.extractPrefixed(this.asPrefix(Reference._type));
Map<UUID, ReferenceType> typeItemsMap = this.collectReferenceTypes(typeFields, data);
List<Reference> models = new ArrayList<>(); List<Reference> models = new ArrayList<>();
for (ReferenceEntity d : data) { for (ReferenceEntity d : data) {
Reference m = new Reference(); Reference m = new Reference();
@ -86,7 +91,7 @@ public class ReferenceBuilder extends BaseBuilder<Reference, ReferenceEntity>{
if (fields.hasField(this.asIndexer(Reference._description))) m.setDescription(d.getDescription()); if (fields.hasField(this.asIndexer(Reference._description))) m.setDescription(d.getDescription());
if (fields.hasField(this.asIndexer(Reference._source))) m.setSource(d.getSource()); if (fields.hasField(this.asIndexer(Reference._source))) m.setSource(d.getSource());
if (fields.hasField(this.asIndexer(Reference._sourceType))) m.setSourceType(d.getSourceType()); if (fields.hasField(this.asIndexer(Reference._sourceType))) m.setSourceType(d.getSourceType());
if (fields.hasField(this.asIndexer(Reference._type))) m.setType(d.getType()); if (!typeFields.isEmpty() && typeItemsMap != null && typeItemsMap.containsKey(d.getTypeId())) m.setType(typeItemsMap.get(d.getTypeId()));
if (dmpReferenceMap != null && !dmpReferenceMap.isEmpty() && dmpReferenceMap.containsKey(d.getId())) m.setDmpReferences(dmpReferenceMap.get(d.getId())); if (dmpReferenceMap != null && !dmpReferenceMap.isEmpty() && dmpReferenceMap.containsKey(d.getId())) m.setDmpReferences(dmpReferenceMap.get(d.getId()));
if (!userFields.isEmpty() && userItemsMap != null && userItemsMap.containsKey(d.getCreatedById())) m.setCreatedBy(userItemsMap.get(d.getCreatedById())); if (!userFields.isEmpty() && userItemsMap != null && userItemsMap.containsKey(d.getCreatedById())) m.setCreatedBy(userItemsMap.get(d.getCreatedById()));
models.add(m); models.add(m);
@ -95,6 +100,36 @@ public class ReferenceBuilder extends BaseBuilder<Reference, ReferenceEntity>{
return models; return models;
} }
private Map<UUID, ReferenceType> collectReferenceTypes(FieldSet fields, List<ReferenceEntity> data) throws MyApplicationException {
if (fields.isEmpty() || data.isEmpty())
return null;
this.logger.debug("checking related - {}", ReferenceType.class.getSimpleName());
Map<UUID, ReferenceType> itemMap;
if (!fields.hasOtherField(this.asIndexer(ReferenceType._id))) {
itemMap = this.asEmpty(
data.stream().map(ReferenceEntity::getTypeId).distinct().collect(Collectors.toList()),
x -> {
ReferenceType item = new ReferenceType();
item.setId(x);
return item;
},
ReferenceType::getId);
} else {
FieldSet clone = new BaseFieldSet(fields.getFields()).ensure(ReferenceType._id);
ReferenceTypeQuery q = this.queryFactory.query(ReferenceTypeQuery.class).authorize(this.authorize).ids(data.stream().map(ReferenceEntity::getTypeId).distinct().collect(Collectors.toList()));
itemMap = this.builderFactory.builder(ReferenceTypeBuilder.class).authorize(this.authorize).asForeignKey(q, clone, ReferenceType::getId);
}
if (!fields.hasField(ReferenceType._id)) {
itemMap.forEach((id, item) -> {
if (item != null)
item.setId(null);
});
}
return itemMap;
}
private Map<UUID, User> collectUsers(FieldSet fields, List<ReferenceEntity> data) throws MyApplicationException { private Map<UUID, User> collectUsers(FieldSet fields, List<ReferenceEntity> data) throws MyApplicationException {
if (fields.isEmpty() || data.isEmpty()) if (fields.isEmpty() || data.isEmpty())
return null; return null;

View File

@ -80,11 +80,9 @@ public class DescriptionFieldDepositBuilder extends BaseDepositBuilder<Descripti
} }
switch (field.getData().getFieldType()) { switch (field.getData().getFieldType()) {
case EXTERNAL_SELECT -> m.setFieldType(FieldType.AUTO_COMPLETE);
case SELECT -> m.setFieldType(FieldType.WORD_LIST); case SELECT -> m.setFieldType(FieldType.WORD_LIST);
case BOOLEAN_DECISION -> m.setFieldType(FieldType.BOOLEAN_DECISION); case BOOLEAN_DECISION -> m.setFieldType(FieldType.BOOLEAN_DECISION);
case RADIO_BOX -> m.setFieldType(FieldType.RADIO_BOX); case RADIO_BOX -> m.setFieldType(FieldType.RADIO_BOX);
case INTERNAL_DMP_ENTRIES_RESEARCHERS -> m.setFieldType(FieldType.INTERNAL_DMP_ENTRIES_RESEARCHERS);
case INTERNAL_DMP_ENTRIES_DMPS -> m.setFieldType(FieldType.INTERNAL_DMP_ENTRIES_DMPS); case INTERNAL_DMP_ENTRIES_DMPS -> m.setFieldType(FieldType.INTERNAL_DMP_ENTRIES_DMPS);
case INTERNAL_DMP_ENTRIES_DATASETS -> m.setFieldType(FieldType.INTERNAL_DMP_ENTRIES_DATASETS); case INTERNAL_DMP_ENTRIES_DATASETS -> m.setFieldType(FieldType.INTERNAL_DMP_ENTRIES_DATASETS);
case CHECK_BOX -> m.setFieldType(FieldType.CHECK_BOX); case CHECK_BOX -> m.setFieldType(FieldType.CHECK_BOX);
@ -94,20 +92,11 @@ public class DescriptionFieldDepositBuilder extends BaseDepositBuilder<Descripti
case UPLOAD -> m.setFieldType(FieldType.UPLOAD); case UPLOAD -> m.setFieldType(FieldType.UPLOAD);
case DATE_PICKER -> m.setFieldType(FieldType.DATE_PICKER); case DATE_PICKER -> m.setFieldType(FieldType.DATE_PICKER);
case EXTERNAL_DATASETS -> m.setFieldType(FieldType.EXTERNAL_DATASETS); case EXTERNAL_DATASETS -> m.setFieldType(FieldType.EXTERNAL_DATASETS);
case DATA_REPOSITORIES -> m.setFieldType(FieldType.DATA_REPOSITORIES); // case REFERENCE_TYPES -> m.setFieldType(FieldType.REFERENCE_TYPES); //TODO new reference logic
case JOURNAL_REPOSITORIES -> m.setFieldType(FieldType.JOURNAL_REPOSITORIES);
case PUB_REPOSITORIES -> m.setFieldType(FieldType.PUB_REPOSITORIES);
case LICENSES -> m.setFieldType(FieldType.LICENSES);
case PUBLICATIONS -> m.setFieldType(FieldType.PUBLICATIONS);
case REGISTRIES -> m.setFieldType(FieldType.REGISTRIES);
case SERVICES -> m.setFieldType(FieldType.SERVICES);
case TAGS -> m.setFieldType(FieldType.TAGS); case TAGS -> m.setFieldType(FieldType.TAGS);
case RESEARCHERS -> m.setFieldType(FieldType.RESEARCHERS);
case ORGANIZATIONS -> m.setFieldType(FieldType.ORGANIZATIONS);
case DATASET_IDENTIFIER -> m.setFieldType(FieldType.DATASET_IDENTIFIER); case DATASET_IDENTIFIER -> m.setFieldType(FieldType.DATASET_IDENTIFIER);
case CURRENCY -> m.setFieldType(FieldType.CURRENCY); case CURRENCY -> m.setFieldType(FieldType.CURRENCY);
case VALIDATION -> m.setFieldType(FieldType.VALIDATION); case VALIDATION -> m.setFieldType(FieldType.VALIDATION);
case TAXONOMIES -> m.setFieldType(FieldType.TAXONOMIES);
default -> throw new MyApplicationException("unrecognized type " + field.getData().getFieldType()); default -> throw new MyApplicationException("unrecognized type " + field.getData().getFieldType());
} }
} }

View File

@ -6,7 +6,6 @@ import eu.eudat.commons.types.reference.DefinitionEntity;
import eu.eudat.convention.ConventionService; import eu.eudat.convention.ConventionService;
import eu.eudat.data.ReferenceEntity; import eu.eudat.data.ReferenceEntity;
import eu.eudat.depositinterface.enums.ReferenceSourceType; import eu.eudat.depositinterface.enums.ReferenceSourceType;
import eu.eudat.depositinterface.enums.ReferenceType;
import eu.eudat.depositinterface.models.ReferenceDepositModel; import eu.eudat.depositinterface.models.ReferenceDepositModel;
import gr.cite.tools.data.builder.BuilderFactory; import gr.cite.tools.data.builder.BuilderFactory;
import gr.cite.tools.exception.MyApplicationException; import gr.cite.tools.exception.MyApplicationException;
@ -67,23 +66,7 @@ public class ReferenceDepositBuilder extends BaseDepositBuilder<ReferenceDeposit
case External -> m.setSourceType(ReferenceSourceType.External); case External -> m.setSourceType(ReferenceSourceType.External);
default -> throw new MyApplicationException("unrecognized type " + d.getSourceType().getValue()); default -> throw new MyApplicationException("unrecognized type " + d.getSourceType().getValue());
} }
switch (d.getType()){ // m.setType(d.getTypeId()); //TODO new reference logic
case Taxonomies -> m.setType(ReferenceType.Taxonomies);
case Licenses -> m.setType(ReferenceType.Licenses);
case Publications -> m.setType(ReferenceType.Publications);
case Journals -> m.setType(ReferenceType.Journals);
case PubRepositories -> m.setType(ReferenceType.PubRepositories);
case DataRepositories -> m.setType(ReferenceType.DataRepositories);
case Registries -> m.setType(ReferenceType.Registries);
case Services -> m.setType(ReferenceType.Services);
case Project -> m.setType(ReferenceType.Project);
case Funder -> m.setType(ReferenceType.Funder);
case Datasets -> m.setType(ReferenceType.Datasets);
case Organizations -> m.setType(ReferenceType.Organizations);
case Grants -> m.setType(ReferenceType.Grants);
case Researcher -> m.setType(ReferenceType.Researcher);
default -> throw new MyApplicationException("unrecognized type " + d.getType().getValue());
}
models.add(new DepositBuilderItemResponse<>(m, d)); models.add(new DepositBuilderItemResponse<>(m, d));
} }
this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0)); this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0));

View File

@ -1,163 +0,0 @@
package eu.eudat.model.builder.descriptiontemplatedefinition.fielddata;
import eu.eudat.authorization.AuthorizationFlags;
import eu.eudat.commons.types.descriptiontemplate.fielddata.ExternalSelectDataEntity;
import eu.eudat.convention.ConventionService;
import eu.eudat.model.builder.BaseBuilder;
import eu.eudat.model.descriptiontemplatedefinition.fielddata.ExternalSelectData;
import gr.cite.tools.data.builder.BuilderFactory;
import gr.cite.tools.exception.MyApplicationException;
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.*;
@Component
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class ExternalSelectDataBuilder extends BaseFieldDataBuilder<ExternalSelectData, ExternalSelectDataEntity> {
private final BuilderFactory builderFactory;
@Autowired
public ExternalSelectDataBuilder(ConventionService conventionService, BuilderFactory builderFactory) {
super(conventionService, new LoggerService(LoggerFactory.getLogger(ExternalSelectDataBuilder.class)));
this.builderFactory = builderFactory;
}
@Override
protected ExternalSelectData getInstance() {
return new ExternalSelectData();
}
@Override
protected void buildChild(FieldSet fields, ExternalSelectDataEntity d, ExternalSelectData m) {
FieldSet sourcesFields = fields.extractPrefixed(this.asPrefix(ExternalSelectData._sources));
if (fields.hasField(this.asIndexer(ExternalSelectData._multipleSelect))) m.setMultipleSelect(d.getMultipleSelect());
if (!sourcesFields.isEmpty() && d.getSources() != null) m.setSources(this.builderFactory.builder(ExternalSelectSourceBuilder.class).authorize(this.authorize).build(sourcesFields, d.getSources()));
}
@Component
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public static class ExternalSelectSourceBindingBuilder extends BaseBuilder<ExternalSelectData.ExternalSelectSourceBinding, ExternalSelectDataEntity.ExternalSelectSourceBindingEntity> {
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
@Autowired
public ExternalSelectSourceBindingBuilder(
ConventionService conventionService) {
super(conventionService, new LoggerService(LoggerFactory.getLogger(SelectDataBuilder.SelectOptionBuilder.class)));
}
public ExternalSelectSourceBindingBuilder authorize(EnumSet<AuthorizationFlags> values) {
this.authorize = values;
return this;
}
@Override
public List<ExternalSelectData.ExternalSelectSourceBinding> build(FieldSet fields, List<ExternalSelectDataEntity.ExternalSelectSourceBindingEntity> 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<ExternalSelectData.ExternalSelectSourceBinding> models = new ArrayList<>();
for (ExternalSelectDataEntity.ExternalSelectSourceBindingEntity d : data) {
ExternalSelectData.ExternalSelectSourceBinding m = new ExternalSelectData.ExternalSelectSourceBinding();
if (fields.hasField(this.asIndexer(ExternalSelectData.ExternalSelectSourceBinding._label))) m.setLabel(d.getLabel());
if (fields.hasField(this.asIndexer(ExternalSelectData.ExternalSelectSourceBinding._value))) m.setValue(d.getValue());
if (fields.hasField(this.asIndexer(ExternalSelectData.ExternalSelectSourceBinding._source))) m.setSource(d.getSource());
models.add(m);
}
this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0));
return models;
}
}
@Component
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public static class ExternalSelectSourceBuilder extends BaseBuilder<ExternalSelectData.ExternalSelectSource, ExternalSelectDataEntity.ExternalSelectSourceEntity> {
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
private final BuilderFactory builderFactory;
@Autowired
public ExternalSelectSourceBuilder(
ConventionService conventionService, BuilderFactory builderFactory) {
super(conventionService, new LoggerService(LoggerFactory.getLogger(ExternalSelectSourceBuilder.class)));
this.builderFactory = builderFactory;
}
public ExternalSelectSourceBuilder authorize(EnumSet<AuthorizationFlags> values) {
this.authorize = values;
return this;
}
@Override
public List<ExternalSelectData.ExternalSelectSource> build(FieldSet fields, List<ExternalSelectDataEntity.ExternalSelectSourceEntity> 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<>();
FieldSet sourceBindingFields = fields.extractPrefixed(this.asPrefix(ExternalSelectData.ExternalSelectSource._sourceBinding));
FieldSet authFields = fields.extractPrefixed(this.asPrefix(ExternalSelectData.ExternalSelectSource._auth));
List<ExternalSelectData.ExternalSelectSource> models = new ArrayList<>();
for (ExternalSelectDataEntity.ExternalSelectSourceEntity d : data) {
ExternalSelectData.ExternalSelectSource m = new ExternalSelectData.ExternalSelectSource();
if (fields.hasField(this.asIndexer(ExternalSelectData.ExternalSelectSource._url))) m.setUrl(d.getUrl());
if (fields.hasField(this.asIndexer(ExternalSelectData.ExternalSelectSource._optionsRoot))) m.setOptionsRoot(d.getOptionsRoot());
if (fields.hasField(this.asIndexer(ExternalSelectData.ExternalSelectSource._hasAuth))) m.setHasAuth(d.getHasAuth());
if (fields.hasField(this.asIndexer(ExternalSelectData.ExternalSelectSource._method))) m.setMethod(d.getMethod());
if (!sourceBindingFields.isEmpty() && d.getSourceBinding() != null) m.setSourceBinding(this.builderFactory.builder(ExternalSelectSourceBindingBuilder.class).authorize(this.authorize).build(sourceBindingFields, d.getSourceBinding()));
if (!authFields.isEmpty() && d.getAuth() != null) m.setAuth(this.builderFactory.builder(ExternalSelectAuthDataBuilder.class).authorize(this.authorize).build(authFields, d.getAuth()));
models.add(m);
}
this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0));
return models;
}
}
@Component
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public static class ExternalSelectAuthDataBuilder extends BaseBuilder<ExternalSelectData.ExternalSelectAuthData, ExternalSelectDataEntity.ExternalSelectAuthDataEntity> {
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
@Autowired
public ExternalSelectAuthDataBuilder(
ConventionService conventionService) {
super(conventionService, new LoggerService(LoggerFactory.getLogger(ExternalSelectAuthDataBuilder.class)));
}
public ExternalSelectAuthDataBuilder authorize(EnumSet<AuthorizationFlags> values) {
this.authorize = values;
return this;
}
@Override
public List<ExternalSelectData.ExternalSelectAuthData> build(FieldSet fields, List<ExternalSelectDataEntity.ExternalSelectAuthDataEntity> 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<ExternalSelectData.ExternalSelectAuthData> models = new ArrayList<>();
for (ExternalSelectDataEntity.ExternalSelectAuthDataEntity d : data) {
ExternalSelectData.ExternalSelectAuthData m = new ExternalSelectData.ExternalSelectAuthData();
if (fields.hasField(this.asIndexer(ExternalSelectData.ExternalSelectAuthData._url))) m.setUrl(d.getUrl());
if (fields.hasField(this.asIndexer(ExternalSelectData.ExternalSelectAuthData._method))) m.setMethod(d.getMethod());
if (fields.hasField(this.asIndexer(ExternalSelectData.ExternalSelectAuthData._body))) m.setBody(d.getBody());
if (fields.hasField(this.asIndexer(ExternalSelectData.ExternalSelectAuthData._path))) m.setPath(d.getPath());
if (fields.hasField(this.asIndexer(ExternalSelectData.ExternalSelectAuthData._type))) m.setType(d.getType());
models.add(m);
}
this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0));
return models;
}
}
}

View File

@ -0,0 +1,31 @@
package eu.eudat.model.builder.descriptiontemplatedefinition.fielddata;
import eu.eudat.commons.types.descriptiontemplate.fielddata.ReferenceTypeDataEntity;
import eu.eudat.convention.ConventionService;
import eu.eudat.model.descriptiontemplatedefinition.fielddata.ReferenceTypeData;
import gr.cite.tools.fieldset.FieldSet;
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;
@Component
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class ReferenceTypeDataBuilder extends BaseFieldDataBuilder<ReferenceTypeData, ReferenceTypeDataEntity> {
@Autowired
public ReferenceTypeDataBuilder(ConventionService conventionService) {
super(conventionService, new LoggerService(LoggerFactory.getLogger(ReferenceTypeDataBuilder.class)));
}
protected ReferenceTypeData getInstance() {
return new ReferenceTypeData();
}
@Override
protected void buildChild(FieldSet fields, ReferenceTypeDataEntity d, ReferenceTypeData m) {
if (fields.hasField(this.asIndexer(ReferenceTypeData._multipleSelect))) m.setMultipleSelect(d.getMultipleSelect());
if (fields.hasField(this.asIndexer(ReferenceTypeData._referenceTypeId))) m.setReferenceTypeId(d.getReferenceTypeId());
}
}

View File

@ -1,19 +1,14 @@
package eu.eudat.model.builder.dmpblueprintdefinition; package eu.eudat.model.builder.dmpblueprintdefinition;
import eu.eudat.authorization.AuthorizationFlags; import eu.eudat.authorization.AuthorizationFlags;
import eu.eudat.commons.types.dmpblueprint.DescriptionTemplateEntity;
import eu.eudat.commons.types.dmpblueprint.ExtraFieldEntity;
import eu.eudat.commons.types.dmpblueprint.FieldEntity; import eu.eudat.commons.types.dmpblueprint.FieldEntity;
import eu.eudat.convention.ConventionService; import eu.eudat.convention.ConventionService;
import eu.eudat.model.builder.BaseBuilder; import eu.eudat.model.builder.BaseBuilder;
import eu.eudat.model.dmpblueprintdefinition.DescriptionTemplate;
import eu.eudat.model.dmpblueprintdefinition.ExtraField;
import eu.eudat.model.dmpblueprintdefinition.Field; import eu.eudat.model.dmpblueprintdefinition.Field;
import gr.cite.tools.exception.MyApplicationException; import gr.cite.tools.exception.MyApplicationException;
import gr.cite.tools.fieldset.FieldSet; import gr.cite.tools.fieldset.FieldSet;
import gr.cite.tools.logging.DataLogEntry; import gr.cite.tools.logging.DataLogEntry;
import gr.cite.tools.logging.LoggerService; import gr.cite.tools.logging.LoggerService;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.ConfigurableBeanFactory; import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope; import org.springframework.context.annotation.Scope;

View File

@ -0,0 +1,32 @@
package eu.eudat.model.builder.dmpblueprintdefinition;
import eu.eudat.commons.types.dmpblueprint.ReferenceFieldEntity;
import eu.eudat.convention.ConventionService;
import eu.eudat.model.dmpblueprintdefinition.ReferenceField;
import gr.cite.tools.fieldset.FieldSet;
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;
@Component
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class ReferenceFieldBuilder extends FieldBuilder<ReferenceField, ReferenceFieldEntity> {
@Autowired
public ReferenceFieldBuilder(
ConventionService conventionService) {
super(conventionService, new LoggerService(LoggerFactory.getLogger(ReferenceFieldBuilder.class)));
}
protected ReferenceField getInstance() {
return new ReferenceField();
}
protected ReferenceField buildChild(FieldSet fields, ReferenceFieldEntity data, ReferenceField model) {
if (fields.hasField(this.asIndexer(ReferenceField._referenceTypeId))) model.setReferenceTypeId(data.getReferenceTypeId());
return model;
}
}

View File

@ -2,10 +2,7 @@ package eu.eudat.model.builder.dmpblueprintdefinition;
import eu.eudat.authorization.AuthorizationFlags; import eu.eudat.authorization.AuthorizationFlags;
import eu.eudat.commons.enums.DmpBlueprintFieldCategory; import eu.eudat.commons.enums.DmpBlueprintFieldCategory;
import eu.eudat.commons.types.dmpblueprint.ExtraFieldEntity; import eu.eudat.commons.types.dmpblueprint.*;
import eu.eudat.commons.types.dmpblueprint.FieldEntity;
import eu.eudat.commons.types.dmpblueprint.SectionEntity;
import eu.eudat.commons.types.dmpblueprint.SystemFieldEntity;
import eu.eudat.convention.ConventionService; import eu.eudat.convention.ConventionService;
import eu.eudat.model.builder.BaseBuilder; import eu.eudat.model.builder.BaseBuilder;
import eu.eudat.model.dmpblueprintdefinition.Section; import eu.eudat.model.dmpblueprintdefinition.Section;
@ -63,11 +60,13 @@ public class SectionBuilder extends BaseBuilder<Section, SectionEntity> {
if (fields.hasField(this.asIndexer(Section._hasTemplates))) m.setHasTemplates(d.getHasTemplates()); if (fields.hasField(this.asIndexer(Section._hasTemplates))) m.setHasTemplates(d.getHasTemplates());
if (!descriptionTemplatesFields.isEmpty() && d.getDescriptionTemplates() != null) m.setDescriptionTemplates(this.builderFactory.builder(DescriptionTemplateBuilder.class).authorize(this.authorize).build(descriptionTemplatesFields, d.getDescriptionTemplates())); if (!descriptionTemplatesFields.isEmpty() && d.getDescriptionTemplates() != null) m.setDescriptionTemplates(this.builderFactory.builder(DescriptionTemplateBuilder.class).authorize(this.authorize).build(descriptionTemplatesFields, d.getDescriptionTemplates()));
if (!fieldsFields.isEmpty() && d.getFields() != null) { if (!fieldsFields.isEmpty() && d.getFields() != null) {
List<SystemFieldEntity> systemFieldEntities = d.getFields().stream().filter(x-> DmpBlueprintFieldCategory.System.equals(x.getCategory())).map(x-> (SystemFieldEntity)x).toList();
List<ExtraFieldEntity> extraFieldEntities = d.getFields().stream().filter(x-> DmpBlueprintFieldCategory.Extra.equals(x.getCategory())).map(x-> (ExtraFieldEntity)x).toList();
m.setFields(new ArrayList<>()); m.setFields(new ArrayList<>());
List<SystemFieldEntity> systemFieldEntities = d.getFields().stream().filter(x-> DmpBlueprintFieldCategory.System.equals(x.getCategory())).map(x-> (SystemFieldEntity)x).toList();
m.getFields().addAll(this.builderFactory.builder(SystemFieldBuilder.class).authorize(this.authorize).build(fieldsFields, systemFieldEntities)); m.getFields().addAll(this.builderFactory.builder(SystemFieldBuilder.class).authorize(this.authorize).build(fieldsFields, systemFieldEntities));
List<ExtraFieldEntity> extraFieldEntities = d.getFields().stream().filter(x-> DmpBlueprintFieldCategory.Extra.equals(x.getCategory())).map(x-> (ExtraFieldEntity)x).toList();
m.getFields().addAll(this.builderFactory.builder(ExtraFieldBuilder.class).authorize(this.authorize).build(fieldsFields, extraFieldEntities)); m.getFields().addAll(this.builderFactory.builder(ExtraFieldBuilder.class).authorize(this.authorize).build(fieldsFields, extraFieldEntities));
List<ReferenceFieldEntity> referenceFieldEntities = d.getFields().stream().filter(x-> DmpBlueprintFieldCategory.Reference.equals(x.getCategory())).map(x-> (ReferenceFieldEntity)x).toList();
m.getFields().addAll(this.builderFactory.builder(ReferenceFieldBuilder.class).authorize(this.authorize).build(fieldsFields, referenceFieldEntities));
} }
models.add(m); models.add(m);
} }

View File

@ -161,14 +161,14 @@ public class DescriptionTemplateDefinitionFileTransformerBuilder extends BaseFil
public BaseFieldDataFileTransformerModel convertData (BaseFieldDataEntity data) { public BaseFieldDataFileTransformerModel convertData (BaseFieldDataEntity data) {
BaseFieldDataFileTransformerModel m; BaseFieldDataFileTransformerModel m;
switch (data) { switch (data) { //TODO new reference logic
case ExternalSelectDataEntity d -> { // case ExternalSelectDataEntity d -> {
m = new ExternalSelectDataFileTransformerModel(); // m = new ExternalSelectDataFileTransformerModel();
m.setLabel(d.getLabel()); // m.setLabel(d.getLabel());
m.setFieldType(FieldType.of(d.getFieldType().getValue())); // m.setFieldType(FieldType.of(d.getFieldType().getValue()));
((ExternalSelectDataFileTransformerModel)m).setMultipleSelect(d.getMultipleSelect()); // ((ExternalSelectDataFileTransformerModel)m).setMultipleSelect(d.getMultipleSelect());
((ExternalSelectDataFileTransformerModel) m).setSources(convertAutoCompleteSingleData(d.getSources())); // ((ExternalSelectDataFileTransformerModel) m).setSources(convertAutoCompleteSingleData(d.getSources()));
} // }
case ExternalDatasetDataEntity d -> { case ExternalDatasetDataEntity d -> {
m = new ExternalDatasetDataFileTransformerModel(); m = new ExternalDatasetDataFileTransformerModel();
m.setLabel(d.getLabel()); m.setLabel(d.getLabel());
@ -221,42 +221,6 @@ public class DescriptionTemplateDefinitionFileTransformerBuilder extends BaseFil
return result; return result;
} }
private List<ExternalSelectDataFileTransformerModel.ExternalSelectSourceFileTransformerModel> convertAutoCompleteSingleData(List<ExternalSelectDataEntity.ExternalSelectSourceEntity> data) {
List<ExternalSelectDataFileTransformerModel.ExternalSelectSourceFileTransformerModel> result = new ArrayList<>();
for (ExternalSelectDataEntity.ExternalSelectSourceEntity d : data) {
ExternalSelectDataFileTransformerModel.ExternalSelectSourceFileTransformerModel m = new ExternalSelectDataFileTransformerModel.ExternalSelectSourceFileTransformerModel();
m.setUrl(d.getUrl());
m.setMethod(d.getMethod());
m.setHasAuth(d.getHasAuth());
m.setOptionsRoot(d.getOptionsRoot());
if (d.getAuth() != null) {
m.setAuth(convertAuthData(d.getAuth()));
}
m.setSourceBinding(convertComboBoxOption(d.getSourceBinding()));
result.add(m);
}
return result;
}
private ExternalSelectDataFileTransformerModel.ExternalSelectSourceBindingFileTransformerModel convertComboBoxOption(ExternalSelectDataEntity.ExternalSelectSourceBindingEntity data) {
ExternalSelectDataFileTransformerModel.ExternalSelectSourceBindingFileTransformerModel m = new ExternalSelectDataFileTransformerModel.ExternalSelectSourceBindingFileTransformerModel();
// m.setUri(data.getUri());
m.setSource(data.getSource());
m.setLabel(data.getLabel());
m.setValue(data.getValue());
return m;
}
private ExternalSelectDataFileTransformerModel.ExternalSelectAuthDataFileTransformerModel convertAuthData(ExternalSelectDataEntity.ExternalSelectAuthDataEntity data) {
ExternalSelectDataFileTransformerModel.ExternalSelectAuthDataFileTransformerModel m = new ExternalSelectDataFileTransformerModel.ExternalSelectAuthDataFileTransformerModel();
m.setMethod(data.getMethod());
m.setUrl(data.getUrl());
m.setType(data.getType());
m.setBody(data.getBody());
m.setPath(data.getPath());
return m;
}
private SelectDataFileTransformerModel.OptionFileTransformerModel convertComboBoxOption(SelectDataEntity.OptionEntity data) { private SelectDataFileTransformerModel.OptionFileTransformerModel convertComboBoxOption(SelectDataEntity.OptionEntity data) {
SelectDataFileTransformerModel.OptionFileTransformerModel m = new SelectDataFileTransformerModel.OptionFileTransformerModel(); SelectDataFileTransformerModel.OptionFileTransformerModel m = new SelectDataFileTransformerModel.OptionFileTransformerModel();
m.setLabel(data.getLabel()); m.setLabel(data.getLabel());

View File

@ -21,6 +21,7 @@ import gr.cite.tools.data.builder.BuilderFactory;
import gr.cite.tools.data.query.QueryFactory; import gr.cite.tools.data.query.QueryFactory;
import gr.cite.tools.exception.MyApplicationException; import gr.cite.tools.exception.MyApplicationException;
import gr.cite.tools.logging.LoggerService; import gr.cite.tools.logging.LoggerService;
import org.apache.commons.lang3.NotImplementedException;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.ConfigurableBeanFactory; import org.springframework.beans.factory.config.ConfigurableBeanFactory;
@ -110,6 +111,8 @@ public class DmpBlueprintFileTransformerBuilder extends BaseFileTransformerBuild
FieldFileTransformerModel m = switch (fieldEntity.getCategory()) { FieldFileTransformerModel m = switch (fieldEntity.getCategory()) {
case System -> new SystemFieldFileTransformerModel(); case System -> new SystemFieldFileTransformerModel();
case Extra -> new ExtraFieldFileTransformerModelFileTransformerModel(); case Extra -> new ExtraFieldFileTransformerModelFileTransformerModel();
case Reference -> throw new NotImplementedException("ReferenceFieldFileTransformerModel");
default -> throw new MyApplicationException("unrecognized type " + fieldEntity.getCategory());
}; };
m.setId(fieldEntity.getId()); m.setId(fieldEntity.getId());
m.setLabel(fieldEntity.getLabel()); m.setLabel(fieldEntity.getLabel());
@ -120,7 +123,8 @@ public class DmpBlueprintFileTransformerBuilder extends BaseFileTransformerBuild
switch (m) { switch (m) {
case SystemFieldFileTransformerModel sm -> sm.setSystemFieldType(DmpBlueprintSystemFieldType.of(((SystemFieldEntity)fieldEntity).getType().getValue())); case SystemFieldFileTransformerModel sm -> sm.setSystemFieldType(DmpBlueprintSystemFieldType.of(((SystemFieldEntity)fieldEntity).getType().getValue()));
case ExtraFieldFileTransformerModelFileTransformerModel sm -> sm.setDataType(DmpBlueprintExtraFieldDataType.of(((ExtraFieldEntity)fieldEntity).getType().getValue())); case ExtraFieldFileTransformerModelFileTransformerModel sm -> sm.setDataType(DmpBlueprintExtraFieldDataType.of(((ExtraFieldEntity)fieldEntity).getType().getValue()));
default -> {} // case ReferenceFieldFileTransformerModelFileTransformerModel sm -> sm.setReferenceTypeId(((ReferenceFieldEntity)fieldEntity).getReferenceTypeId());
default -> throw new MyApplicationException("unrecognized type " + fieldEntity.getCategory());
} }
result.add(m); result.add(m);
}); });

View File

@ -69,23 +69,9 @@ public class ReferenceFileTransformerBuilder extends BaseFileTransformerBuilder<
case External -> m.setSourceType(ReferenceSourceType.External); case External -> m.setSourceType(ReferenceSourceType.External);
default -> throw new MyApplicationException("unrecognized type " + d.getSourceType().getValue()); default -> throw new MyApplicationException("unrecognized type " + d.getSourceType().getValue());
} }
switch (d.getType()){
case Taxonomies -> m.setType(ReferenceType.Taxonomies); //m.setType(d.getTypeId()); //TODO new reference logic
case Licenses -> m.setType(ReferenceType.Licenses);
case Publications -> m.setType(ReferenceType.Publications);
case Journals -> m.setType(ReferenceType.Journals);
case PubRepositories -> m.setType(ReferenceType.PubRepositories);
case DataRepositories -> m.setType(ReferenceType.DataRepositories);
case Registries -> m.setType(ReferenceType.Registries);
case Services -> m.setType(ReferenceType.Services);
case Project -> m.setType(ReferenceType.Project);
case Funder -> m.setType(ReferenceType.Funder);
case Datasets -> m.setType(ReferenceType.Datasets);
case Organizations -> m.setType(ReferenceType.Organizations);
case Grants -> m.setType(ReferenceType.Grants);
case Researcher -> m.setType(ReferenceType.Researcher);
default -> throw new MyApplicationException("unrecognized type " + d.getType().getValue());
}
models.add(new FileTransformerBuilderItemResponse<>(m, d)); models.add(new FileTransformerBuilderItemResponse<>(m, d));
} }
this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0)); this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0));

View File

@ -1,58 +1,58 @@
package eu.eudat.model.builder.referencesearch; //package eu.eudat.model.builder.referencesearch;
//
import eu.eudat.authorization.AuthorizationFlags; //import eu.eudat.authorization.AuthorizationFlags;
import eu.eudat.configurations.referencetype.ReferenceTypeProperties; //import eu.eudat.configurations.referencetype.ReferenceTypeProperties;
import eu.eudat.convention.ConventionService; //import eu.eudat.convention.ConventionService;
import eu.eudat.model.builder.BaseBuilder; //import eu.eudat.model.builder.BaseBuilder;
import eu.eudat.model.referencedefinition.Definition; //import eu.eudat.model.referencedefinition.Definition;
import gr.cite.tools.data.builder.BuilderFactory; //import gr.cite.tools.data.builder.BuilderFactory;
import gr.cite.tools.exception.MyApplicationException; //import gr.cite.tools.exception.MyApplicationException;
import gr.cite.tools.fieldset.FieldSet; //import gr.cite.tools.fieldset.FieldSet;
import gr.cite.tools.logging.DataLogEntry; //import gr.cite.tools.logging.DataLogEntry;
import gr.cite.tools.logging.LoggerService; //import gr.cite.tools.logging.LoggerService;
import org.slf4j.LoggerFactory; //import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; //import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.ConfigurableBeanFactory; //import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope; //import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component; //import org.springframework.stereotype.Component;
//
import java.util.*; //import java.util.*;
//
@Component //@Component
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) //@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class DefinitionSearchBuilder extends BaseBuilder<Definition, Map<String, String>> { //public class DefinitionSearchBuilder extends BaseBuilder<Definition, Map<String, String>> {
//
private final BuilderFactory builderFactory; // private final BuilderFactory builderFactory;
private final ReferenceTypeProperties properties; // private final ReferenceTypeProperties properties;
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None); // private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
//
@Autowired // @Autowired
public DefinitionSearchBuilder( // public DefinitionSearchBuilder(
ConventionService conventionService, BuilderFactory builderFactory, ReferenceTypeProperties properties) { // ConventionService conventionService, BuilderFactory builderFactory, ReferenceTypeProperties properties) {
super(conventionService, new LoggerService(LoggerFactory.getLogger(DefinitionSearchBuilder.class))); // super(conventionService, new LoggerService(LoggerFactory.getLogger(DefinitionSearchBuilder.class)));
this.builderFactory = builderFactory; // this.builderFactory = builderFactory;
this.properties = properties; // this.properties = properties;
} // }
//
public DefinitionSearchBuilder authorize(EnumSet<AuthorizationFlags> values) { // public DefinitionSearchBuilder authorize(EnumSet<AuthorizationFlags> values) {
this.authorize = values; // this.authorize = values;
return this; // return this;
} // }
//
@Override // @Override
public List<Definition> build(FieldSet fields, List<Map<String, String>> data) throws MyApplicationException { // public List<Definition> build(FieldSet fields, List<Map<String, String>> 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.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)); // this.logger.trace(new DataLogEntry("requested fields", fields));
if (data == null) // if (data == null)
return new ArrayList<>(); // return new ArrayList<>();
//
List<Definition> models = new ArrayList<>(); // List<Definition> models = new ArrayList<>();
//for (Map<String, String> d : data) { // //for (Map<String, String> d : data) {
Definition m = new Definition(); // Definition m = new Definition();
m.setFields(this.builderFactory.builder(FieldSearchBuilder.class).authorize(this.authorize).build(null, data)); // m.setFields(this.builderFactory.builder(FieldSearchBuilder.class).authorize(this.authorize).build(null, data));
models.add(m); // models.add(m);
// //}
// this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0));
// return models;
// }
//} //}
this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0));
return models;
}
}

View File

@ -1,89 +1,88 @@
package eu.eudat.model.builder.referencesearch; //package eu.eudat.model.builder.referencesearch;
//
import eu.eudat.authorization.AuthorizationFlags; //import eu.eudat.authorization.AuthorizationFlags;
import eu.eudat.commons.enums.ReferenceFieldDataType; //import eu.eudat.commons.enums.ReferenceFieldDataType;
import eu.eudat.commons.enums.ReferenceType; //import eu.eudat.configurations.referencetype.ReferenceTypeField;
import eu.eudat.configurations.referencetype.ReferenceTypeField; //import eu.eudat.configurations.referencetype.ReferenceTypeProperties;
import eu.eudat.configurations.referencetype.ReferenceTypeProperties; //import eu.eudat.convention.ConventionService;
import eu.eudat.convention.ConventionService; //import eu.eudat.model.builder.BaseBuilder;
import eu.eudat.model.builder.BaseBuilder; //import eu.eudat.model.referencedefinition.Field;
import eu.eudat.model.referencedefinition.Field; //import gr.cite.tools.exception.MyApplicationException;
import gr.cite.tools.exception.MyApplicationException; //import gr.cite.tools.fieldset.FieldSet;
import gr.cite.tools.fieldset.FieldSet; //import gr.cite.tools.logging.DataLogEntry;
import gr.cite.tools.logging.DataLogEntry; //import gr.cite.tools.logging.LoggerService;
import gr.cite.tools.logging.LoggerService; //import org.slf4j.LoggerFactory;
import org.slf4j.LoggerFactory; //import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Autowired; //import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.beans.factory.config.ConfigurableBeanFactory; //import org.springframework.context.annotation.Scope;
import org.springframework.context.annotation.Scope; //import org.springframework.stereotype.Component;
import org.springframework.stereotype.Component; //
//import java.util.*;
import java.util.*; //
//@Component
@Component //@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) //public class FieldSearchBuilder extends BaseBuilder<Field, Map<String, String>> {
public class FieldSearchBuilder extends BaseBuilder<Field, Map<String, String>> { //
// private final ReferenceTypeProperties properties;
private final ReferenceTypeProperties properties; // private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None); //
// @Autowired
@Autowired // public FieldSearchBuilder(
public FieldSearchBuilder( // ConventionService conventionService, ReferenceTypeProperties properties) {
ConventionService conventionService, ReferenceTypeProperties properties) { // super(conventionService, new LoggerService(LoggerFactory.getLogger(FieldSearchBuilder.class)));
super(conventionService, new LoggerService(LoggerFactory.getLogger(FieldSearchBuilder.class))); // this.properties = properties;
this.properties = properties; // }
} //
// public FieldSearchBuilder authorize(EnumSet<AuthorizationFlags> values) {
public FieldSearchBuilder authorize(EnumSet<AuthorizationFlags> values) { // this.authorize = values;
this.authorize = values; // return this;
return this; // }
} //
// @Override
@Override // public List<Field> build(FieldSet fields, List< Map<String, String>> data) throws MyApplicationException {
public List<Field> build(FieldSet fields, List< Map<String, String>> 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.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));
this.logger.trace(new DataLogEntry("requested fields", fields)); // if (data == null)
if (data == null) // return new ArrayList<>();
return new ArrayList<>(); //
// List<Field> models = new ArrayList<>();
List<Field> models = new ArrayList<>(); // for (Map<String, String> d : data) {
for (Map<String, String> d : data) { //
// ReferenceType referenceType = ReferenceType.valueOf(d.getOrDefault("referenceType", null));
ReferenceType referenceType = ReferenceType.valueOf(d.getOrDefault("referenceType", null)); // List<ReferenceTypeField> typeFields = this.getPropertiesFields(referenceType);
List<ReferenceTypeField> typeFields = this.getPropertiesFields(referenceType); // if (typeFields.isEmpty()){
if (typeFields.isEmpty()){ // return new ArrayList<>();
return new ArrayList<>(); // }
} //
// for (ReferenceTypeField typeField: typeFields){
for (ReferenceTypeField typeField: typeFields){ // Field m = new Field();
Field m = new Field(); // m.setCode(typeField.getCode());
m.setCode(typeField.getCode()); // m.setDataType(ReferenceFieldDataType.valueOf(typeField.getDataType()));
m.setDataType(ReferenceFieldDataType.valueOf(typeField.getDataType())); // m.setValue(d.getOrDefault(typeField.getCode(), null));
m.setValue(d.getOrDefault(typeField.getCode(), null)); // models.add(m);
models.add(m); // }
} // }
} // this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0));
this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0)); // return models;
return models; // }
} //
// private List<ReferenceTypeField> getPropertiesFields(ReferenceType referenceType){
private List<ReferenceTypeField> getPropertiesFields(ReferenceType referenceType){ // switch (referenceType) {
switch (referenceType) { // case Taxonomies: return properties.getTaxonomy().get("fields");
case Taxonomies: return properties.getTaxonomy().get("fields"); // case Licenses: return properties.getLicence().get("fields");
case Licenses: return properties.getLicence().get("fields"); // case Publications: return properties.getPublication().get("fields");
case Publications: return properties.getPublication().get("fields"); // case Journals: return properties.getJournal().get("fields");
case Journals: return properties.getJournal().get("fields"); // case PubRepositories: return properties.getPubRepository().get("fields");
case PubRepositories: return properties.getPubRepository().get("fields"); // case DataRepositories: return properties.getDataRepository().get("fields");
case DataRepositories: return properties.getDataRepository().get("fields"); // case Registries: return properties.getRegistry().get("fields");
case Registries: return properties.getRegistry().get("fields"); // case Services: return properties.getService().get("fields");
case Services: return properties.getService().get("fields"); // case Organizations: return properties.getOrganisation().get("fields");
case Organizations: return properties.getOrganisation().get("fields"); // case Datasets: return properties.getDataset().get("fields");
case Datasets: return properties.getDataset().get("fields"); // case Funder: return properties.getFunder().get("fields");
case Funder: return properties.getFunder().get("fields"); // case Grants: return properties.getGrant().get("fields");
case Grants: return properties.getGrant().get("fields"); // case Project: return properties.getProject().get("fields");
case Project: return properties.getProject().get("fields"); // case Researcher: return properties.getResearcher().get("fields");
case Researcher: return properties.getResearcher().get("fields"); // default: return null;
default: return null; // }
} // }
} //}
}

View File

@ -1,103 +1,96 @@
package eu.eudat.model.builder.referencesearch; //package eu.eudat.model.builder.referencesearch;
//
import eu.eudat.authorization.AuthorizationFlags; //import eu.eudat.authorization.AuthorizationFlags;
import eu.eudat.commons.XmlHandlingService; //import eu.eudat.commons.enums.ReferenceSourceType;
import eu.eudat.commons.enums.ReferenceSourceType; //import eu.eudat.convention.ConventionService;
import eu.eudat.commons.enums.ReferenceType; //import eu.eudat.model.Reference;
import eu.eudat.convention.ConventionService; //import eu.eudat.model.builder.BaseBuilder;
import eu.eudat.model.Reference; //import eu.eudat.model.referencedefinition.Definition;
import eu.eudat.model.builder.BaseBuilder; //import eu.eudat.model.referencedefinition.Field;
import eu.eudat.model.referencedefinition.Definition; //import gr.cite.tools.data.builder.BuilderFactory;
import eu.eudat.model.referencedefinition.Field; //import gr.cite.tools.exception.MyApplicationException;
import gr.cite.tools.data.builder.BuilderFactory; //import gr.cite.tools.fieldset.FieldSet;
import gr.cite.tools.data.query.QueryFactory; //import gr.cite.tools.logging.DataLogEntry;
import gr.cite.tools.exception.MyApplicationException; //import gr.cite.tools.logging.LoggerService;
import gr.cite.tools.fieldset.FieldSet; //import org.slf4j.LoggerFactory;
import gr.cite.tools.logging.DataLogEntry; //import org.springframework.beans.factory.annotation.Autowired;
import gr.cite.tools.logging.LoggerService; //import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.slf4j.LoggerFactory; //import org.springframework.context.annotation.Scope;
import org.springframework.beans.factory.annotation.Autowired; //import org.springframework.stereotype.Component;
import org.springframework.beans.factory.config.ConfigurableBeanFactory; //
import org.springframework.context.annotation.Scope; //import java.util.*;
import org.springframework.stereotype.Component; //
//@Component
import java.util.*; //@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
//public class ReferenceSearchBuilder extends BaseBuilder<Reference, Map<String, String>> {
@Component //
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) // private final BuilderFactory builderFactory;
public class ReferenceSearchBuilder extends BaseBuilder<Reference, Map<String, String>> { // private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
//
private final BuilderFactory builderFactory; // @Autowired
private final QueryFactory queryFactory; // public ReferenceSearchBuilder(
private final XmlHandlingService xmlHandlingService; // ConventionService conventionService,
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None); // BuilderFactory builderFactory) {
// super(conventionService, new LoggerService(LoggerFactory.getLogger(ReferenceSearchBuilder.class)));
@Autowired // this.builderFactory = builderFactory;
public ReferenceSearchBuilder( // }
ConventionService conventionService, //
BuilderFactory builderFactory, QueryFactory queryFactory, XmlHandlingService xmlHandlingService) { // public ReferenceSearchBuilder authorize(EnumSet<AuthorizationFlags> values) {
super(conventionService, new LoggerService(LoggerFactory.getLogger(ReferenceSearchBuilder.class))); // this.authorize = values;
this.builderFactory = builderFactory; // return this;
this.queryFactory = queryFactory; // }
this.xmlHandlingService = xmlHandlingService; //
} // @Override
// public List<Reference> build(FieldSet fields, List<Map<String, String>> data) throws MyApplicationException {
public ReferenceSearchBuilder authorize(EnumSet<AuthorizationFlags> values) { // 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.authorize = values; // this.logger.trace(new DataLogEntry("requested fields", fields));
return this; // if (data == null)
} // return new ArrayList<>();
//
@Override // List<Reference> models = new ArrayList<>();
public List<Reference> build(FieldSet fields, List<Map<String, String>> data) throws MyApplicationException { // for (Map<String, String> d : data) {
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)); // Reference m = new Reference();
this.logger.trace(new DataLogEntry("requested fields", fields)); // if (d.containsKey("id")) m.setId(UUID.fromString(d.getOrDefault("id", null)));
if (data == null) // m.setLabel(d.getOrDefault("name", null));
return new ArrayList<>(); // m.setSourceType(ReferenceSourceType.External);
// String type = d.getOrDefault("referenceType", null);
List<Reference> models = new ArrayList<>(); // if (type != null) m.setType(ReferenceType.valueOf(type));
for (Map<String, String> d : data) { //
Reference m = new Reference(); // Definition definition = this.builderFactory.builder(DefinitionSearchBuilder.class).authorize(this.authorize).build(null, d);
if (d.containsKey("id")) m.setId(UUID.fromString(d.getOrDefault("id", null))); // m.setDefinition(definition);
m.setLabel(d.getOrDefault("name", null)); //
m.setSourceType(ReferenceSourceType.External); // switch (m.getType()){
String type = d.getOrDefault("referenceType", null); // case Researcher:
if (type != null) m.setType(ReferenceType.valueOf(type)); // case Organizations:
// case Funder:
Definition definition = this.builderFactory.builder(DefinitionSearchBuilder.class).authorize(this.authorize).build(null, d); // case Grants:
m.setDefinition(definition); // case DataRepositories:
// case PubRepositories:
switch (m.getType()){ // case Journals:
case Researcher: // case Datasets:
case Organizations: // case Registries:
case Funder: // case Services:{
case Grants: // for (Field field : definition.getFields()) {
case DataRepositories: // if (field.getCode().equals("pid") && field.getValue() != null) {
case PubRepositories: // if (d.containsKey("key")) {
case Journals: // m.setReference(d.get("key") + ":" + field.getValue());
case Datasets: // }
case Registries: // }
case Services:{ // if (field.getCode().equals("tag") && field.getValue() != null){
for (Field field : definition.getFields()) { // m.setSource(field.getValue());
if (field.getCode().equals("pid") && field.getValue() != null) { // }
if (d.containsKey("key")) { // }
m.setReference(d.get("key") + ":" + field.getValue()); // }
} // }
} //
if (field.getCode().equals("tag") && field.getValue() != null){ // m.setDescription(d.getOrDefault("description", null));
m.setSource(field.getValue()); // m.setAbbreviation(d.getOrDefault("abbreviation", null));
} //
} // models.add(m);
} //
} // }
// this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0));
m.setDescription(d.getOrDefault("description", null)); // return models;
m.setAbbreviation(d.getOrDefault("abbreviation", null)); // }
//
models.add(m); //}
}
this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0));
return models;
}
}

View File

@ -2,6 +2,8 @@ package eu.eudat.model.censorship;
import eu.eudat.authorization.Permission; import eu.eudat.authorization.Permission;
import eu.eudat.convention.ConventionService; import eu.eudat.convention.ConventionService;
import eu.eudat.model.PublicDmpUser;
import eu.eudat.model.PublicReference;
import eu.eudat.model.Reference; import eu.eudat.model.Reference;
import eu.eudat.model.censorship.referencedefinition.DefinitionCensor; import eu.eudat.model.censorship.referencedefinition.DefinitionCensor;
import gr.cite.commons.web.authz.service.AuthorizationService; import gr.cite.commons.web.authz.service.AuthorizationService;
@ -39,6 +41,8 @@ public class PublicReferenceCensor extends BaseCensor {
return; return;
this.authService.authorizeForce(Permission.PublicBrowseReference); this.authService.authorizeForce(Permission.PublicBrowseReference);
FieldSet typeFields = fields.extractPrefixed(this.asIndexerPrefix(PublicReference._type));
this.censorFactory.censor(PublicReferenceCensor.class).censor(typeFields);
} }
} }

View File

@ -0,0 +1,41 @@
package eu.eudat.model.censorship;
import eu.eudat.authorization.Permission;
import eu.eudat.convention.ConventionService;
import eu.eudat.model.PublicDmpUser;
import gr.cite.commons.web.authz.service.AuthorizationService;
import gr.cite.tools.data.censor.CensorFactory;
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.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
@Component
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class PublicReferenceTypeCensor extends BaseCensor {
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(PublicReferenceTypeCensor.class));
protected final AuthorizationService authService;
protected final CensorFactory censorFactory;
public PublicReferenceTypeCensor(ConventionService conventionService,
AuthorizationService authService,
CensorFactory censorFactory) {
super(conventionService);
this.authService = authService;
this.censorFactory = censorFactory;
}
public void censor(FieldSet fields) {
logger.debug(new DataLogEntry("censoring fields", fields));
if (fields == null || fields.isEmpty())
return;
this.authService.authorizeForce(Permission.PublicBrowseReferenceType);
}
}

View File

@ -45,6 +45,8 @@ public class ReferenceCensor extends BaseCensor {
this.censorFactory.censor(DmpReferenceCensor.class).censor(dmpReferencesFields, userId); this.censorFactory.censor(DmpReferenceCensor.class).censor(dmpReferencesFields, userId);
FieldSet createdByFields = fields.extractPrefixed(this.asIndexerPrefix(Reference._createdBy)); FieldSet createdByFields = fields.extractPrefixed(this.asIndexerPrefix(Reference._createdBy));
this.censorFactory.censor(UserCensor.class).censor(createdByFields, userId); this.censorFactory.censor(UserCensor.class).censor(createdByFields, userId);
FieldSet typeFields = fields.extractPrefixed(this.asIndexerPrefix(Reference._type));
this.censorFactory.censor(ReferenceTypeCensor.class).censor(typeFields, userId);
} }
} }

View File

@ -1,164 +0,0 @@
package eu.eudat.model.descriptiontemplatedefinition.fielddata;
import java.util.List;
public class ExternalSelectData extends LabelAndMultiplicityData {
private List<ExternalSelectSource> sources;
public final static String _sources = "sources";
public List<ExternalSelectSource> getSources() {
return sources;
}
public void setSources(List<ExternalSelectSource> sources) {
this.sources = sources;
}
public static class ExternalSelectSource {
private String url;
public final static String _url = "url";
private String method;
public final static String _method = "method";
private String optionsRoot;
public final static String _optionsRoot = "optionsRoot";
private ExternalSelectSourceBinding sourceBinding;
public final static String _sourceBinding = "sourceBinding";
private Boolean hasAuth;
public final static String _hasAuth = "hasAuth";
private ExternalSelectAuthData auth;
public final static String _auth = "auth";
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public String getMethod() {
return method;
}
public void setMethod(String method) {
this.method = method;
}
public String getOptionsRoot() {
return optionsRoot;
}
public void setOptionsRoot(String optionsRoot) {
this.optionsRoot = optionsRoot;
}
public ExternalSelectSourceBinding getSourceBinding() {
return sourceBinding;
}
public void setSourceBinding(ExternalSelectSourceBinding sourceBinding) {
this.sourceBinding = sourceBinding;
}
public Boolean getHasAuth() {
return hasAuth;
}
public void setHasAuth(Boolean hasAuth) {
this.hasAuth = hasAuth;
}
public ExternalSelectAuthData getAuth() {
return auth;
}
public void setAuth(ExternalSelectAuthData auth) {
this.auth = auth;
}
}
public static class ExternalSelectSourceBinding {
private String label;
public final static String _label = "label";
private String value;
public final static String _value = "value";
private String source;
public final static String _source = "source";
public String getLabel() {
return label;
}
public void setLabel(String label) {
this.label = label;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
public String getSource() {
return source;
}
public void setSource(String source) {
this.source = source;
}
}
public static class ExternalSelectAuthData {
private String url;
public final static String _url = "url";
private String method;
public final static String _method = "method";
private String body;
public final static String _body = "body";
private String path;
public final static String _path = "path";
private String type;
public final static String _type = "type";
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public String getMethod() {
return method;
}
public void setMethod(String method) {
this.method = method;
}
public String getBody() {
return body;
}
public void setBody(String body) {
this.body = body;
}
public String getPath() {
return path;
}
public void setPath(String path) {
this.path = path;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
}
}

View File

@ -0,0 +1,25 @@
package eu.eudat.model.descriptiontemplatedefinition.fielddata;
import java.util.UUID;
public class ReferenceTypeData extends BaseFieldData {
private Boolean multipleSelect;
public final static String _multipleSelect = "multipleSelect";
private UUID referenceTypeId;
public final static String _referenceTypeId = "referenceTypeId";
public Boolean getMultipleSelect() {
return multipleSelect;
}
public void setMultipleSelect(Boolean multipleSelect) {
this.multipleSelect = multipleSelect;
}
public UUID getReferenceTypeId() {
return referenceTypeId;
}
public void setReferenceTypeId(UUID referenceTypeId) {
this.referenceTypeId = referenceTypeId;
}
}

View File

@ -2,6 +2,7 @@ package eu.eudat.model.dmpblueprintdefinition;
import eu.eudat.commons.enums.DmpBlueprintExtraFieldDataType; import eu.eudat.commons.enums.DmpBlueprintExtraFieldDataType;
public class ExtraField extends Field { public class ExtraField extends Field {
public final static String _dataType = "dataType"; public final static String _dataType = "dataType";
@ -15,3 +16,4 @@ public class ExtraField extends Field {
this.dataType = dataType; this.dataType = dataType;
} }
} }

View File

@ -0,0 +1,17 @@
package eu.eudat.model.dmpblueprintdefinition;
import java.util.UUID;
public class ReferenceField extends Field {
public final static String _referenceTypeId = "referenceTypeId";
private UUID referenceTypeId;
public UUID getReferenceTypeId() {
return referenceTypeId;
}
public void setReferenceTypeId(UUID referenceTypeId) {
this.referenceTypeId = referenceTypeId;
}
}

View File

@ -5,6 +5,7 @@ import eu.eudat.model.publicapi.datasetprofile.DatasetProfilePublicModel;
import eu.eudat.model.publicapi.grant.GrantPublicOverviewModel; import eu.eudat.model.publicapi.grant.GrantPublicOverviewModel;
import eu.eudat.model.publicapi.listingmodels.DatasetPublicListingModel; import eu.eudat.model.publicapi.listingmodels.DatasetPublicListingModel;
import eu.eudat.model.publicapi.user.UserInfoPublicModel; import eu.eudat.model.publicapi.user.UserInfoPublicModel;
import eu.eudat.service.publicapi.PublicApiProperties;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.sql.Date; import java.sql.Date;
@ -13,7 +14,7 @@ import java.util.List;
@Component @Component
public class DescriptionToPublicApiDatasetListingMapper { public class DescriptionToPublicApiDatasetListingMapper {
public DatasetPublicListingModel toPublicListingModel(Description description) { public DatasetPublicListingModel toPublicListingModel(Description description, PublicApiProperties.ReferenceTypeMapConfig config) {
DatasetPublicListingModel model = new DatasetPublicListingModel(); DatasetPublicListingModel model = new DatasetPublicListingModel();
model.setId(description.getId().toString()); model.setId(description.getId().toString());
model.setLabel(description.getLabel()); model.setLabel(description.getLabel());
@ -24,7 +25,7 @@ public class DescriptionToPublicApiDatasetListingMapper {
model.setDmpId(description.getDmp().getId().toString()); model.setDmpId(description.getDmp().getId().toString());
model.setUsers(List.of(UserInfoPublicModel.fromDescriptionCreator(description.getCreatedBy()))); model.setUsers(List.of(UserInfoPublicModel.fromDescriptionCreator(description.getCreatedBy())));
model.setProfile(DatasetProfilePublicModel.fromDataModel(description.getDescriptionTemplate())); model.setProfile(DatasetProfilePublicModel.fromDataModel(description.getDescriptionTemplate()));
model.setGrant(GrantPublicOverviewModel.fromDescriptionReference(description.getDescriptionReferences())); model.setGrant(GrantPublicOverviewModel.fromDescriptionReference(description.getDescriptionReferences(), config));
model.setCreatedAt(Date.from(description.getCreatedAt())); model.setCreatedAt(Date.from(description.getCreatedAt()));
model.setModifiedAt(Date.from(description.getUpdatedAt())); model.setModifiedAt(Date.from(description.getUpdatedAt()));

View File

@ -8,6 +8,7 @@ import eu.eudat.model.publicapi.datasetwizard.RegistryPublicModel;
import eu.eudat.model.publicapi.datasetwizard.ServicePublicModel; import eu.eudat.model.publicapi.datasetwizard.ServicePublicModel;
import eu.eudat.model.publicapi.listingmodels.DataManagementPlanPublicListingModel; import eu.eudat.model.publicapi.listingmodels.DataManagementPlanPublicListingModel;
import eu.eudat.model.publicapi.overviewmodels.DatasetPublicModel; import eu.eudat.model.publicapi.overviewmodels.DatasetPublicModel;
import eu.eudat.service.publicapi.PublicApiProperties;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.sql.Date; import java.sql.Date;
@ -22,7 +23,7 @@ public class DescriptionToPublicApiDatasetMapper {
this.descriptionTemplateToPublicApiDatasetProfileMapper = descriptionTemplateToPublicApiDatasetProfileMapper; this.descriptionTemplateToPublicApiDatasetProfileMapper = descriptionTemplateToPublicApiDatasetProfileMapper;
} }
public DatasetPublicModel toPublicModel(Description description, DataManagementPlanPublicListingModel dmp) { public DatasetPublicModel toPublicModel(Description description, DataManagementPlanPublicListingModel dmp, PublicApiProperties.ReferenceTypeMapConfig config) {
DatasetPublicModel model = new DatasetPublicModel(); DatasetPublicModel model = new DatasetPublicModel();
model.setId(description.getId()); model.setId(description.getId());
model.setLabel(description.getLabel()); model.setLabel(description.getLabel());
@ -36,10 +37,10 @@ public class DescriptionToPublicApiDatasetMapper {
model.setProfile(DatasetProfilePublicModel.fromDataModel(description.getDescriptionTemplate())); model.setProfile(DatasetProfilePublicModel.fromDataModel(description.getDescriptionTemplate()));
if (description.getDescriptionReferences() != null) { if (description.getDescriptionReferences() != null) {
model.setRegistries(description.getDescriptionReferences().stream().map(RegistryPublicModel::fromDescriptionReference).filter(Objects::nonNull).toList()); model.setRegistries(description.getDescriptionReferences().stream().map(x-> RegistryPublicModel.fromDescriptionReference(x, config)).filter(Objects::nonNull).toList());
model.setServices(description.getDescriptionReferences().stream().map(ServicePublicModel::fromDescriptionReference).filter(Objects::nonNull).toList()); model.setServices(description.getDescriptionReferences().stream().map(x-> ServicePublicModel.fromDescriptionReference(x, config)).filter(Objects::nonNull).toList());
model.setDataRepositories(description.getDescriptionReferences().stream().map(DataRepositoryPublicModel::fromDescriptionReference).filter(Objects::nonNull).toList()); model.setDataRepositories(description.getDescriptionReferences().stream().map(x-> DataRepositoryPublicModel.fromDescriptionReference(x, config)).filter(Objects::nonNull).toList());
model.setExternalDatasets(description.getDescriptionReferences().stream().map(ExternalDatasetPublicListingModel::fromDescriptionReference).filter(Objects::nonNull).toList()); model.setExternalDatasets(description.getDescriptionReferences().stream().map(x-> ExternalDatasetPublicListingModel.fromDescriptionReference(x, config)).filter(Objects::nonNull).toList());
} }
model.setCreatedAt(Date.from(description.getCreatedAt())); model.setCreatedAt(Date.from(description.getCreatedAt()));

View File

@ -4,6 +4,7 @@ import eu.eudat.model.Dmp;
import eu.eudat.model.publicapi.listingmodels.DataManagementPlanPublicListingModel; import eu.eudat.model.publicapi.listingmodels.DataManagementPlanPublicListingModel;
import eu.eudat.model.publicapi.researcher.ResearcherPublicModel; import eu.eudat.model.publicapi.researcher.ResearcherPublicModel;
import eu.eudat.model.publicapi.user.UserInfoPublicModel; import eu.eudat.model.publicapi.user.UserInfoPublicModel;
import eu.eudat.service.publicapi.PublicApiProperties;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.sql.Date; import java.sql.Date;
@ -12,7 +13,7 @@ import java.util.Objects;
@Component @Component
public class DmpToPublicApiDmpListingMapper { public class DmpToPublicApiDmpListingMapper {
public DataManagementPlanPublicListingModel toPublicListingModel(Dmp dmp) { public DataManagementPlanPublicListingModel toPublicListingModel(Dmp dmp, PublicApiProperties.ReferenceTypeMapConfig config) {
DataManagementPlanPublicListingModel model = new DataManagementPlanPublicListingModel(); DataManagementPlanPublicListingModel model = new DataManagementPlanPublicListingModel();
model.setId(dmp.getId().toString()); model.setId(dmp.getId().toString());
model.setLabel(dmp.getLabel()); model.setLabel(dmp.getLabel());
@ -20,7 +21,7 @@ public class DmpToPublicApiDmpListingMapper {
model.setGroupId(dmp.getGroupId()); model.setGroupId(dmp.getGroupId());
model.setUsers(dmp.getDmpUsers().stream().map(UserInfoPublicModel::fromDmpUser).toList()); model.setUsers(dmp.getDmpUsers().stream().map(UserInfoPublicModel::fromDmpUser).toList());
model.setResearchers(dmp.getDmpReferences().stream().map(ResearcherPublicModel::fromDmpReference).filter(Objects::nonNull).toList()); model.setResearchers(dmp.getDmpReferences().stream().map(x-> ResearcherPublicModel.fromDmpReference(x, config)).filter(Objects::nonNull).toList());
model.setCreatedAt(Date.from(dmp.getCreatedAt())); model.setCreatedAt(Date.from(dmp.getCreatedAt()));
model.setModifiedAt(Date.from(dmp.getUpdatedAt())); model.setModifiedAt(Date.from(dmp.getUpdatedAt()));

View File

@ -11,6 +11,7 @@ import eu.eudat.model.publicapi.organisation.OrganizationPublicModel;
import eu.eudat.model.publicapi.overviewmodels.DataManagementPlanPublicModel; import eu.eudat.model.publicapi.overviewmodels.DataManagementPlanPublicModel;
import eu.eudat.model.publicapi.researcher.ResearcherPublicModel; import eu.eudat.model.publicapi.researcher.ResearcherPublicModel;
import eu.eudat.model.publicapi.user.UserInfoPublicModel; import eu.eudat.model.publicapi.user.UserInfoPublicModel;
import eu.eudat.service.publicapi.PublicApiProperties;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.sql.Date; import java.sql.Date;
@ -26,7 +27,7 @@ public class DmpToPublicApiDmpMapper {
this.descriptionToPublicApiDatasetMapper = descriptionToPublicApiDatasetMapper; this.descriptionToPublicApiDatasetMapper = descriptionToPublicApiDatasetMapper;
} }
public DataManagementPlanPublicModel toPublicModel(Dmp dmp, List<EntityDoiEntity> doiEntities, List<DmpDescriptionTemplate> descriptionTemplates) { public DataManagementPlanPublicModel toPublicModel(Dmp dmp, List<EntityDoiEntity> doiEntities, List<DmpDescriptionTemplate> descriptionTemplates, PublicApiProperties.ReferenceTypeMapConfig config) {
DataManagementPlanPublicModel model = new DataManagementPlanPublicModel(); DataManagementPlanPublicModel model = new DataManagementPlanPublicModel();
model.setId(dmp.getId().toString()); model.setId(dmp.getId().toString());
model.setLabel(dmp.getLabel()); model.setLabel(dmp.getLabel());
@ -38,13 +39,13 @@ public class DmpToPublicApiDmpMapper {
if (dmp.getDescriptions() != null) { if (dmp.getDescriptions() != null) {
DataManagementPlanPublicListingModel publicListingModel = new DataManagementPlanPublicListingModel(); DataManagementPlanPublicListingModel publicListingModel = new DataManagementPlanPublicListingModel();
publicListingModel.setId(model.getId()); publicListingModel.setId(model.getId());
model.setDatasets(dmp.getDescriptions().stream().map(x -> descriptionToPublicApiDatasetMapper.toPublicModel(x, publicListingModel)).toList()); model.setDatasets(dmp.getDescriptions().stream().map(x -> descriptionToPublicApiDatasetMapper.toPublicModel(x, publicListingModel, config)).toList());
} }
model.setUsers(dmp.getDmpUsers().stream().map(UserInfoPublicModel::fromDmpUser).toList()); model.setUsers(dmp.getDmpUsers().stream().map(UserInfoPublicModel::fromDmpUser).toList());
model.setResearchers(dmp.getDmpReferences().stream().map(ResearcherPublicModel::fromDmpReference).filter(Objects::nonNull).toList()); model.setResearchers(dmp.getDmpReferences().stream().map(x-> ResearcherPublicModel.fromDmpReference(x, config)).filter(Objects::nonNull).toList());
model.setGrant(GrantPublicOverviewModel.fromDmpReferences(dmp.getDmpReferences())); model.setGrant(GrantPublicOverviewModel.fromDmpReferences(dmp.getDmpReferences(), config));
model.setOrganisations(dmp.getDmpReferences().stream().map(OrganizationPublicModel::fromDmpReference).filter(Objects::nonNull).toList()); model.setOrganisations(dmp.getDmpReferences().stream().map(x-> OrganizationPublicModel.fromDmpReference(x, config)).filter(Objects::nonNull).toList());
model.setDois(doiEntities.stream().map(DoiPublicModel::fromDataModel).toList()); model.setDois(doiEntities.stream().map(DoiPublicModel::fromDataModel).toList());
model.setAssociatedProfiles(descriptionTemplates.stream().map(x -> AssociatedProfilePublicModel.fromDmpDescriptionTemplate(x, dmp.getBlueprint())).toList()); model.setAssociatedProfiles(descriptionTemplates.stream().map(x -> AssociatedProfilePublicModel.fromDmpDescriptionTemplate(x, dmp.getBlueprint())).toList());

View File

@ -1,7 +1,6 @@
package eu.eudat.model.persist; package eu.eudat.model.persist;
import eu.eudat.commons.enums.ReferenceSourceType; import eu.eudat.commons.enums.ReferenceSourceType;
import eu.eudat.commons.enums.ReferenceType;
import eu.eudat.commons.validation.BaseValidator; import eu.eudat.commons.validation.BaseValidator;
import gr.cite.tools.validation.ValidatorFactory; import gr.cite.tools.validation.ValidatorFactory;
import gr.cite.tools.validation.specification.Specification; import gr.cite.tools.validation.specification.Specification;
@ -27,9 +26,9 @@ public class ReferencePersist {
public static final String _label = "label"; public static final String _label = "label";
private ReferenceType type; private UUID typeId;
public static final String _type = "type"; public static final String _typeId = "typeId";
private String description; private String description;
@ -73,12 +72,12 @@ public class ReferencePersist {
this.label = label; this.label = label;
} }
public ReferenceType getType() { public UUID getTypeId() {
return type; return typeId;
} }
public void setType(ReferenceType type) { public void setTypeId(UUID typeId) {
this.type = type; this.typeId = typeId;
} }
public String getDescription() { public String getDescription() {
@ -177,8 +176,8 @@ public class ReferencePersist {
.must(() -> this.lessEqualLength(item.getLabel(), ReferenceEntity._labelLength)) .must(() -> this.lessEqualLength(item.getLabel(), ReferenceEntity._labelLength))
.failOn(ReferencePersist._label).failWith(messageSource.getMessage("Validation_MaxLength", new Object[]{ReferencePersist._label}, LocaleContextHolder.getLocale())), .failOn(ReferencePersist._label).failWith(messageSource.getMessage("Validation_MaxLength", new Object[]{ReferencePersist._label}, LocaleContextHolder.getLocale())),
this.spec() this.spec()
.must(() -> !this.isNull(item.getType())) .must(() -> this.isValidGuid(item.getTypeId()))
.failOn(ReferencePersist._type).failWith(messageSource.getMessage("Validation_Required", new Object[]{ReferencePersist._type}, LocaleContextHolder.getLocale())), .failOn(ReferencePersist._typeId).failWith(messageSource.getMessage("Validation_Required", new Object[]{ReferencePersist._typeId}, LocaleContextHolder.getLocale())),
this.spec() this.spec()
.must(() -> !this.isEmpty(item.getReference())) .must(() -> !this.isEmpty(item.getReference()))
.failOn(ReferencePersist._reference).failWith(messageSource.getMessage("Validation_Required", new Object[]{ReferencePersist._reference}, LocaleContextHolder.getLocale())), .failOn(ReferencePersist._reference).failWith(messageSource.getMessage("Validation_Required", new Object[]{ReferencePersist._reference}, LocaleContextHolder.getLocale())),
@ -200,7 +199,6 @@ public class ReferencePersist {
this.spec() this.spec()
.must(() -> !this.isNull(item.getSourceType())) .must(() -> !this.isNull(item.getSourceType()))
.failOn(ReferencePersist._sourceType).failWith(messageSource.getMessage("Validation_Required", new Object[]{ReferencePersist._sourceType}, LocaleContextHolder.getLocale())), .failOn(ReferencePersist._sourceType).failWith(messageSource.getMessage("Validation_Required", new Object[]{ReferencePersist._sourceType}, LocaleContextHolder.getLocale())),
this.refSpec() this.refSpec()
.iff(() -> !this.isNull(item.getDefinition())) .iff(() -> !this.isNull(item.getDefinition()))
.on(ReferencePersist._definition) .on(ReferencePersist._definition)

View File

@ -97,10 +97,6 @@ public class FieldPersist {
protected List<Specification> specifications(FieldPersist item) { protected List<Specification> specifications(FieldPersist item) {
FieldType fieldType = this.fieldEntity != null && this.fieldEntity.getData() != null ? this.fieldEntity.getData().getFieldType() : FieldType.FREE_TEXT; FieldType fieldType = this.fieldEntity != null && this.fieldEntity.getData() != null ? this.fieldEntity.getData().getFieldType() : FieldType.FREE_TEXT;
return Arrays.asList( return Arrays.asList(
this.spec()
.iff(()-> FieldType.isNotImplemented(fieldType))
.must(() -> false)
.failOn(FieldPersist._textValue).failWith("Field Not implemented yet!!"),
this.spec() this.spec()
.iff(()-> FieldType.isTextType(fieldType)) .iff(()-> FieldType.isTextType(fieldType))
.must(() -> !this.isEmpty(item.getTextValue())) .must(() -> !this.isEmpty(item.getTextValue()))
@ -130,7 +126,7 @@ public class FieldPersist {
.must(() -> this.isUUID(item.getTextValue())) .must(() -> this.isUUID(item.getTextValue()))
.failOn(FieldPersist._textValue).failWith(messageSource.getMessage("Validation_UnexpectedValue", new Object[]{FieldPersist._textValue}, LocaleContextHolder.getLocale())), .failOn(FieldPersist._textValue).failWith(messageSource.getMessage("Validation_UnexpectedValue", new Object[]{FieldPersist._textValue}, LocaleContextHolder.getLocale())),
this.spec() this.spec()
.iff(()-> !this.isNull(item.getTextListValue()) && (fieldType.equals(FieldType.INTERNAL_DMP_ENTRIES_DMPS) || fieldType.equals(FieldType.INTERNAL_DMP_ENTRIES_RESEARCHERS) || fieldType.equals(FieldType.INTERNAL_DMP_ENTRIES_DATASETS))) .iff(()-> !this.isNull(item.getTextListValue()) && (fieldType.equals(FieldType.INTERNAL_DMP_ENTRIES_DMPS) || fieldType.equals(FieldType.INTERNAL_DMP_ENTRIES_DATASETS)))
.must(() -> item.getTextListValue().stream().allMatch(this::isUUID)) .must(() -> item.getTextListValue().stream().allMatch(this::isUUID))
.failOn(FieldPersist._textListValue).failWith(messageSource.getMessage("Validation_UnexpectedValue", new Object[]{FieldPersist._textListValue}, LocaleContextHolder.getLocale())), .failOn(FieldPersist._textListValue).failWith(messageSource.getMessage("Validation_UnexpectedValue", new Object[]{FieldPersist._textListValue}, LocaleContextHolder.getLocale())),
this.navSpec() this.navSpec()

View File

@ -21,7 +21,6 @@ import java.util.List;
visible = true, visible = true,
defaultImpl = LabelDataPersist.class) defaultImpl = LabelDataPersist.class)
@JsonSubTypes({ @JsonSubTypes({
@JsonSubTypes.Type(value = ExternalSelectDataPersist.class, name = FieldType.Names.ExternalSelect),
@JsonSubTypes.Type(value = LabelDataPersist.class, name = FieldType.Names.BooleanDecision), @JsonSubTypes.Type(value = LabelDataPersist.class, name = FieldType.Names.BooleanDecision),
@JsonSubTypes.Type(value = LabelAndMultiplicityDataPersist.class, name = FieldType.Names.InternalDmpDescriptions), @JsonSubTypes.Type(value = LabelAndMultiplicityDataPersist.class, name = FieldType.Names.InternalDmpDescriptions),
@JsonSubTypes.Type(value = LabelAndMultiplicityDataPersist.class, name = FieldType.Names.InternalDmpDmps), @JsonSubTypes.Type(value = LabelAndMultiplicityDataPersist.class, name = FieldType.Names.InternalDmpDmps),
@ -29,26 +28,16 @@ import java.util.List;
@JsonSubTypes.Type(value = LabelDataPersist.class, name = FieldType.Names.DatePicker), @JsonSubTypes.Type(value = LabelDataPersist.class, name = FieldType.Names.DatePicker),
@JsonSubTypes.Type(value = ExternalDatasetDataPersist.class, name = FieldType.Names.ExternalDatasets), @JsonSubTypes.Type(value = ExternalDatasetDataPersist.class, name = FieldType.Names.ExternalDatasets),
@JsonSubTypes.Type(value = LabelDataPersist.class, name = FieldType.Names.FreeText), @JsonSubTypes.Type(value = LabelDataPersist.class, name = FieldType.Names.FreeText),
@JsonSubTypes.Type(value = LabelAndMultiplicityDataPersist.class, name = FieldType.Names.Licenses), @JsonSubTypes.Type(value = LabelAndMultiplicityDataPersist.class, name = FieldType.Names.ReferenceTypes),
@JsonSubTypes.Type(value = LabelAndMultiplicityDataPersist.class, name = FieldType.Names.Organizations),
@JsonSubTypes.Type(value = LabelAndMultiplicityDataPersist.class, name = FieldType.Names.Publications),
@JsonSubTypes.Type(value = RadioBoxDataPersist.class, name = FieldType.Names.RadioBox), @JsonSubTypes.Type(value = RadioBoxDataPersist.class, name = FieldType.Names.RadioBox),
@JsonSubTypes.Type(value = LabelAndMultiplicityDataPersist.class, name = FieldType.Names.Registries),
@JsonSubTypes.Type(value = LabelAndMultiplicityDataPersist.class, name = FieldType.Names.InternalDmpResearchers),
@JsonSubTypes.Type(value = LabelAndMultiplicityDataPersist.class, name = FieldType.Names.Researchers),
@JsonSubTypes.Type(value = LabelDataPersist.class, name = FieldType.Names.RichTextarea), @JsonSubTypes.Type(value = LabelDataPersist.class, name = FieldType.Names.RichTextarea),
@JsonSubTypes.Type(value = LabelAndMultiplicityDataPersist.class, name = FieldType.Names.Services),
@JsonSubTypes.Type(value = LabelDataPersist.class, name = FieldType.Names.Tags), @JsonSubTypes.Type(value = LabelDataPersist.class, name = FieldType.Names.Tags),
@JsonSubTypes.Type(value = LabelAndMultiplicityDataPersist.class, name = FieldType.Names.Taxonomies),
@JsonSubTypes.Type(value = LabelDataPersist.class, name = FieldType.Names.TextArea), @JsonSubTypes.Type(value = LabelDataPersist.class, name = FieldType.Names.TextArea),
@JsonSubTypes.Type(value = UploadDataPersist.class, name = FieldType.Names.Upload), @JsonSubTypes.Type(value = UploadDataPersist.class, name = FieldType.Names.Upload),
@JsonSubTypes.Type(value = LabelDataPersist.class, name = FieldType.Names.Validation), @JsonSubTypes.Type(value = LabelDataPersist.class, name = FieldType.Names.Validation),
@JsonSubTypes.Type(value = LabelDataPersist.class, name = FieldType.Names.DatasetIdentifier), @JsonSubTypes.Type(value = LabelDataPersist.class, name = FieldType.Names.DatasetIdentifier),
@JsonSubTypes.Type(value = LabelDataPersist.class, name = FieldType.Names.Currency), @JsonSubTypes.Type(value = LabelDataPersist.class, name = FieldType.Names.Currency),
@JsonSubTypes.Type(value = SelectDataPersist.class, name = FieldType.Names.Select), @JsonSubTypes.Type(value = SelectDataPersist.class, name = FieldType.Names.Select)
@JsonSubTypes.Type(value = LabelAndMultiplicityDataPersist.class, name = FieldType.Names.DataRepositories),
@JsonSubTypes.Type(value = LabelAndMultiplicityDataPersist.class, name = FieldType.Names.JournalRepositories),
@JsonSubTypes.Type(value = LabelAndMultiplicityDataPersist.class, name = FieldType.Names.PubRepositories),
}) })
public abstract class BaseFieldDataPersist { public abstract class BaseFieldDataPersist {

View File

@ -0,0 +1,71 @@
package eu.eudat.model.persist.descriptiontemplatedefinition.fielddata;
import eu.eudat.convention.ConventionService;
import eu.eudat.errorcode.ErrorThesaurusProperties;
import gr.cite.tools.validation.specification.Specification;
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 ReferenceTypeDataPersist extends BaseFieldDataPersist {
private Boolean multipleSelect;
public static final String _multipleSelect = "multipleSelect";
private UUID referenceTypeId;
public final static String _referenceTypeId = "referenceTypeId";
public Boolean getMultipleSelect() {
return multipleSelect;
}
public void setMultipleSelect(Boolean multipleSelect) {
this.multipleSelect = multipleSelect;
}
public UUID getReferenceTypeId() {
return referenceTypeId;
}
public void setReferenceTypeId(UUID referenceTypeId) {
this.referenceTypeId = referenceTypeId;
}
@Component(ReferenceTypeDataPersist.ReferenceTypeDataPersistValidator.ValidatorName)
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public static class ReferenceTypeDataPersistValidator extends BaseFieldDataPersistValidator<ReferenceTypeDataPersist> {
public static final String ValidatorName = "DescriptionTemplate.ReferenceTypeDataPersistValidator";
protected ReferenceTypeDataPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource) {
super(conventionService, errors, messageSource);
}
@Override
protected Class<ReferenceTypeDataPersist> modelClass() {
return ReferenceTypeDataPersist.class;
}
@Override
protected List<Specification> specifications(ReferenceTypeDataPersist item) {
List<Specification> specifications = getBaseSpecifications(item);
specifications.addAll(Arrays.asList(
this.spec()
.must(() -> this.isValidGuid(item.getReferenceTypeId()))
.failOn(ReferenceTypeDataPersist._referenceTypeId).failWith(messageSource.getMessage("Validation_Required", new Object[]{ReferenceTypeDataPersist._referenceTypeId}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isNull(item.getMultipleSelect()))
.failOn(ReferenceTypeDataPersist._multipleSelect).failWith(messageSource.getMessage("Validation_Required", new Object[]{ReferenceTypeDataPersist._multipleSelect}, LocaleContextHolder.getLocale()))
));
return specifications;
}
}
}

View File

@ -0,0 +1,56 @@
package eu.eudat.model.persist.dmpblueprintdefinition;
import eu.eudat.convention.ConventionService;
import eu.eudat.errorcode.ErrorThesaurusProperties;
import gr.cite.tools.validation.specification.Specification;
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.List;
import java.util.UUID;
public class ReferenceFieldPersist extends FieldPersist {
private UUID referenceTypeId;
public static final String _referenceTypeId = "referenceTypeId";
public UUID getReferenceTypeId() {
return referenceTypeId;
}
public void setReferenceTypeId(UUID referenceTypeId) {
this.referenceTypeId = referenceTypeId;
}
@Component(ReferenceFieldPersistPersistValidator.ValidatorName)
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public static class ReferenceFieldPersistPersistValidator extends BaseFieldPersistValidator<ReferenceFieldPersist> {
public static final String ValidatorName = "DmpBlueprint.ReferenceFieldPersistPersistValidator";
protected ReferenceFieldPersistPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource) {
super(conventionService, errors, messageSource);
}
@Override
protected Class<ReferenceFieldPersist> modelClass() {
return ReferenceFieldPersist.class;
}
@Override
protected List<Specification> specifications(ReferenceFieldPersist item) {
List<Specification> specifications = getBaseSpecifications(item);
specifications.add(
this.spec()
.must(() -> !this.isNull(item.getReferenceTypeId()))
.failOn(ReferenceFieldPersist._referenceTypeId).failWith(messageSource.getMessage("Validation_Required", new Object[]{ReferenceFieldPersist._referenceTypeId}, LocaleContextHolder.getLocale()))
);
return specifications;
}
}
}

View File

@ -2,6 +2,7 @@ package eu.eudat.model.persist.dmpblueprintdefinition;
import eu.eudat.commons.enums.DmpBlueprintFieldCategory; import eu.eudat.commons.enums.DmpBlueprintFieldCategory;
import eu.eudat.commons.validation.BaseValidator; import eu.eudat.commons.validation.BaseValidator;
import gr.cite.tools.exception.MyApplicationException;
import gr.cite.tools.validation.ValidatorFactory; import gr.cite.tools.validation.ValidatorFactory;
import gr.cite.tools.validation.specification.Specification; import gr.cite.tools.validation.specification.Specification;
import eu.eudat.convention.ConventionService; import eu.eudat.convention.ConventionService;
@ -145,7 +146,20 @@ public class SectionPersist {
.iff(() -> !this.isListNullOrEmpty(item.getFields())) .iff(() -> !this.isListNullOrEmpty(item.getFields()))
.on(SectionPersist._fields) .on(SectionPersist._fields)
.over(item.getFields()) .over(item.getFields())
.using((itm) -> ((FieldPersist) itm).getCategory() == DmpBlueprintFieldCategory.Extra ? this.validatorFactory.validator(ExtraFieldPersist.ExtraFieldPersistValidator.class) : this.validatorFactory.validator(SystemFieldPersist.SystemFieldPersistValidator.class)), .using((itm) -> {
switch (((FieldPersist) itm).getCategory()){
case Extra -> {
return this.validatorFactory.validator(ExtraFieldPersist.ExtraFieldPersistValidator.class);
}
case System -> {
return this.validatorFactory.validator(SystemFieldPersist.SystemFieldPersistValidator.class);
}
case Reference -> {
return this.validatorFactory.validator(ReferenceFieldPersist.ReferenceFieldPersistPersistValidator.class);
}
default -> throw new MyApplicationException("unrecognized type " + ((FieldPersist) itm).getCategory());
}
}),
this.navSpec() this.navSpec()
.iff(() -> !this.isListNullOrEmpty(item.getDescriptionTemplates())) .iff(() -> !this.isListNullOrEmpty(item.getDescriptionTemplates()))
.on(SectionPersist._descriptionTemplates) .on(SectionPersist._descriptionTemplates)

View File

@ -11,6 +11,7 @@ import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.List; import java.util.List;
import java.util.UUID;
public class SystemFieldPersist extends FieldPersist { public class SystemFieldPersist extends FieldPersist {
@ -54,3 +55,4 @@ public class SystemFieldPersist extends FieldPersist {
} }
} }

View File

@ -1,12 +1,12 @@
package eu.eudat.model.publicapi.datasetwizard; package eu.eudat.model.publicapi.datasetwizard;
import eu.eudat.commons.enums.ReferenceType;
import eu.eudat.model.DescriptionReference; import eu.eudat.model.DescriptionReference;
import eu.eudat.model.Reference; import eu.eudat.model.Reference;
import eu.eudat.model.referencedefinition.Field; import eu.eudat.model.referencedefinition.Field;
import eu.eudat.service.publicapi.PublicApiProperties;
import java.util.Objects;
import java.util.Date;
import java.util.UUID;
public class DataRepositoryPublicModel { public class DataRepositoryPublicModel {
private String id; private String id;
@ -90,8 +90,8 @@ public class DataRepositoryPublicModel {
return null; return null;
} }
public static DataRepositoryPublicModel fromDescriptionReference(DescriptionReference descriptionReference) { public static DataRepositoryPublicModel fromDescriptionReference(DescriptionReference descriptionReference, PublicApiProperties.ReferenceTypeMapConfig config) {
if (descriptionReference.getReference().getType() != ReferenceType.DataRepositories) if (!Objects.equals(descriptionReference.getReference().getType().getId(), config.getDataRepositoryTypeId()))
return null; return null;
DataRepositoryPublicModel model = new DataRepositoryPublicModel(); DataRepositoryPublicModel model = new DataRepositoryPublicModel();
Reference reference = descriptionReference.getReference(); Reference reference = descriptionReference.getReference();

View File

@ -1,11 +1,12 @@
package eu.eudat.model.publicapi.datasetwizard; package eu.eudat.model.publicapi.datasetwizard;
import eu.eudat.commons.enums.ReferenceType;
import eu.eudat.model.DescriptionReference; import eu.eudat.model.DescriptionReference;
import eu.eudat.model.Reference; import eu.eudat.model.Reference;
import eu.eudat.model.referencedefinition.Field; import eu.eudat.model.referencedefinition.Field;
import eu.eudat.service.publicapi.PublicApiProperties;
import java.util.Date; import java.util.Date;
import java.util.Objects;
import java.util.UUID; import java.util.UUID;
public class ExternalDatasetPublicListingModel { public class ExternalDatasetPublicListingModel {
@ -106,8 +107,8 @@ public class ExternalDatasetPublicListingModel {
this.source = source; this.source = source;
} }
public static ExternalDatasetPublicListingModel fromDescriptionReference(DescriptionReference descriptionReference) { public static ExternalDatasetPublicListingModel fromDescriptionReference(DescriptionReference descriptionReference, PublicApiProperties.ReferenceTypeMapConfig config) {
if (descriptionReference.getReference().getType() != ReferenceType.Datasets) if (!Objects.equals(descriptionReference.getReference().getType().getId(), config.getDatasetTypeId()))
return null; return null;
ExternalDatasetPublicListingModel model = new ExternalDatasetPublicListingModel(); ExternalDatasetPublicListingModel model = new ExternalDatasetPublicListingModel();
Reference reference = descriptionReference.getReference(); Reference reference = descriptionReference.getReference();

View File

@ -1,11 +1,11 @@
package eu.eudat.model.publicapi.datasetwizard; package eu.eudat.model.publicapi.datasetwizard;
import eu.eudat.commons.enums.ReferenceType;
import eu.eudat.model.DescriptionReference; import eu.eudat.model.DescriptionReference;
import eu.eudat.model.Reference; import eu.eudat.model.Reference;
import eu.eudat.model.referencedefinition.Field; import eu.eudat.model.referencedefinition.Field;
import eu.eudat.service.publicapi.PublicApiProperties;
import java.util.Date; import java.util.Objects;
import java.util.UUID; import java.util.UUID;
public class RegistryPublicModel { public class RegistryPublicModel {
@ -74,8 +74,8 @@ public class RegistryPublicModel {
return null; return null;
} }
public static RegistryPublicModel fromDescriptionReference(DescriptionReference descriptionReference) { public static RegistryPublicModel fromDescriptionReference(DescriptionReference descriptionReference, PublicApiProperties.ReferenceTypeMapConfig config) {
if (descriptionReference.getReference().getType() != ReferenceType.Registries) if (!Objects.equals(descriptionReference.getReference().getType().getId(), config.getRegistryTypeId()))
return null; return null;
RegistryPublicModel model = new RegistryPublicModel(); RegistryPublicModel model = new RegistryPublicModel();
Reference reference = descriptionReference.getReference(); Reference reference = descriptionReference.getReference();

View File

@ -1,11 +1,12 @@
package eu.eudat.model.publicapi.datasetwizard; package eu.eudat.model.publicapi.datasetwizard;
import eu.eudat.commons.enums.ReferenceType;
import eu.eudat.model.DescriptionReference; import eu.eudat.model.DescriptionReference;
import eu.eudat.model.Reference; import eu.eudat.model.Reference;
import eu.eudat.model.referencedefinition.Field; import eu.eudat.model.referencedefinition.Field;
import eu.eudat.service.publicapi.PublicApiProperties;
import java.util.Date; import java.util.Date;
import java.util.Objects;
import java.util.UUID; import java.util.UUID;
public class ServicePublicModel { public class ServicePublicModel {
@ -74,8 +75,8 @@ public class ServicePublicModel {
return null; return null;
} }
public static ServicePublicModel fromDescriptionReference(DescriptionReference descriptionReference) { public static ServicePublicModel fromDescriptionReference(DescriptionReference descriptionReference, PublicApiProperties.ReferenceTypeMapConfig config) {
if (descriptionReference.getReference().getType() != ReferenceType.Services) if (!Objects.equals(descriptionReference.getReference().getType().getId(), config.getServiceTypeId()))
return null; return null;
ServicePublicModel model = new ServicePublicModel(); ServicePublicModel model = new ServicePublicModel();
Reference reference = descriptionReference.getReference(); Reference reference = descriptionReference.getReference();

View File

@ -1,15 +1,16 @@
package eu.eudat.model.publicapi.grant; package eu.eudat.model.publicapi.grant;
import eu.eudat.commons.enums.ReferenceType;
import eu.eudat.model.DescriptionReference; import eu.eudat.model.DescriptionReference;
import eu.eudat.model.DmpReference; import eu.eudat.model.DmpReference;
import eu.eudat.model.Reference; import eu.eudat.model.Reference;
import eu.eudat.model.publicapi.funder.FunderPublicOverviewModel; import eu.eudat.model.publicapi.funder.FunderPublicOverviewModel;
import eu.eudat.model.referencedefinition.Field; import eu.eudat.model.referencedefinition.Field;
import eu.eudat.service.publicapi.PublicApiProperties;
import java.time.Instant; import java.time.Instant;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Objects;
import java.util.UUID; import java.util.UUID;
public class GrantPublicOverviewModel { public class GrantPublicOverviewModel {
@ -78,17 +79,17 @@ public class GrantPublicOverviewModel {
this.funder = funder; this.funder = funder;
} }
public static GrantPublicOverviewModel fromDmpReferences(List<DmpReference> references) { public static GrantPublicOverviewModel fromDmpReferences(List<DmpReference> references, PublicApiProperties.ReferenceTypeMapConfig config) {
FunderPublicOverviewModel funder = null; FunderPublicOverviewModel funder = null;
for (DmpReference dmpReference : references) { for (DmpReference dmpReference : references) {
if (dmpReference.getReference().getType() == ReferenceType.Funder) { if (!Objects.equals(dmpReference.getReference().getType().getId(), config.getFunderTypeId())) {
funder = new FunderPublicOverviewModel(); funder = new FunderPublicOverviewModel();
Reference reference = dmpReference.getReference(); Reference reference = dmpReference.getReference();
funder.setId(reference.getId()); funder.setId(reference.getId());
funder.setLabel(reference.getLabel()); funder.setLabel(reference.getLabel());
continue; continue;
} }
if (dmpReference.getReference().getType() != ReferenceType.Grants) if (!Objects.equals(dmpReference.getReference().getType().getId(), config.getGrantTypeId()))
continue; continue;
GrantPublicOverviewModel model = new GrantPublicOverviewModel(); GrantPublicOverviewModel model = new GrantPublicOverviewModel();
Reference reference = dmpReference.getReference(); Reference reference = dmpReference.getReference();
@ -110,17 +111,17 @@ public class GrantPublicOverviewModel {
return null; return null;
} }
public static GrantPublicOverviewModel fromDescriptionReference(List<DescriptionReference> references) { public static GrantPublicOverviewModel fromDescriptionReference(List<DescriptionReference> references, PublicApiProperties.ReferenceTypeMapConfig config) {
FunderPublicOverviewModel funder = null; FunderPublicOverviewModel funder = null;
for (DescriptionReference descriptionReference : references) { for (DescriptionReference descriptionReference : references) {
if (descriptionReference.getReference().getType() == ReferenceType.Funder) { if (Objects.equals(descriptionReference.getReference().getType().getId(), config.getFunderTypeId())) {
funder = new FunderPublicOverviewModel(); funder = new FunderPublicOverviewModel();
Reference reference = descriptionReference.getReference(); Reference reference = descriptionReference.getReference();
funder.setId(reference.getId()); funder.setId(reference.getId());
funder.setLabel(reference.getLabel()); funder.setLabel(reference.getLabel());
continue; continue;
} }
if (descriptionReference.getReference().getType() != ReferenceType.Grants) if (Objects.equals(descriptionReference.getReference().getType().getId(), config.getGrantTypeId()))
continue; continue;
GrantPublicOverviewModel model = new GrantPublicOverviewModel(); GrantPublicOverviewModel model = new GrantPublicOverviewModel();
Reference reference = descriptionReference.getReference(); Reference reference = descriptionReference.getReference();

View File

@ -1,8 +1,10 @@
package eu.eudat.model.publicapi.organisation; package eu.eudat.model.publicapi.organisation;
import eu.eudat.commons.enums.ReferenceType;
import eu.eudat.model.DmpReference; import eu.eudat.model.DmpReference;
import eu.eudat.model.Reference; import eu.eudat.model.Reference;
import eu.eudat.service.publicapi.PublicApiProperties;
import java.util.Objects;
public class OrganizationPublicModel { public class OrganizationPublicModel {
private String label; private String label;
@ -46,8 +48,8 @@ public class OrganizationPublicModel {
this.key = key; this.key = key;
} }
public static OrganizationPublicModel fromDmpReference(DmpReference dmpReference) { public static OrganizationPublicModel fromDmpReference(DmpReference dmpReference, PublicApiProperties.ReferenceTypeMapConfig config) {
if (dmpReference.getReference().getType() != ReferenceType.Organizations) if (!Objects.equals(dmpReference.getReference().getType().getId(), config.getOrganizationTypeId()))
return null; return null;
OrganizationPublicModel model = new OrganizationPublicModel(); OrganizationPublicModel model = new OrganizationPublicModel();
Reference reference = dmpReference.getReference(); Reference reference = dmpReference.getReference();

View File

@ -1,12 +1,14 @@
package eu.eudat.model.publicapi.researcher; package eu.eudat.model.publicapi.researcher;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import eu.eudat.commons.enums.ReferenceType;
import eu.eudat.model.DmpReference; import eu.eudat.model.DmpReference;
import eu.eudat.model.Reference; import eu.eudat.model.Reference;
import eu.eudat.service.publicapi.PublicApiProperties;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.util.Objects;
@JsonIgnoreProperties(ignoreUnknown = true) @JsonIgnoreProperties(ignoreUnknown = true)
public class ResearcherPublicModel { public class ResearcherPublicModel {
private static final Logger logger = LoggerFactory.getLogger(ResearcherPublicModel.class); private static final Logger logger = LoggerFactory.getLogger(ResearcherPublicModel.class);
@ -51,8 +53,8 @@ public class ResearcherPublicModel {
this.key = key; this.key = key;
} }
public static ResearcherPublicModel fromDmpReference(DmpReference dmpReference) { public static ResearcherPublicModel fromDmpReference(DmpReference dmpReference, PublicApiProperties.ReferenceTypeMapConfig config) {
if (dmpReference.getReference().getType() != ReferenceType.Researcher) if (!Objects.equals(dmpReference.getReference().getType().getId(), config.getRegistryTypeId()))
return null; return null;
ResearcherPublicModel model = new ResearcherPublicModel(); ResearcherPublicModel model = new ResearcherPublicModel();
Reference reference = dmpReference.getReference(); Reference reference = dmpReference.getReference();

View File

@ -1,7 +1,6 @@
package eu.eudat.query; package eu.eudat.query;
import eu.eudat.authorization.AuthorizationFlags; import eu.eudat.authorization.AuthorizationFlags;
import eu.eudat.commons.enums.ReferenceType;
import eu.eudat.commons.enums.IsActive; import eu.eudat.commons.enums.IsActive;
import eu.eudat.commons.enums.ReferenceSourceType; import eu.eudat.commons.enums.ReferenceSourceType;
import eu.eudat.data.DmpReferenceEntity; import eu.eudat.data.DmpReferenceEntity;
@ -33,17 +32,15 @@ public class ReferenceQuery extends QueryBase<ReferenceEntity> {
private Collection<ReferenceSourceType> referenceSourceTypes; private Collection<ReferenceSourceType> referenceSourceTypes;
private Collection<ReferenceType> referenceTypes; private Collection<UUID> typeIds;
private Collection<String> references; private Collection<String> references;
private Collection<String> sources; private Collection<String> sources;
private Collection<UUID> excludedIds; private Collection<UUID> excludedIds;
private DmpReferenceQuery dmpReferenceQuery; private DmpReferenceQuery dmpReferenceQuery;
private Collection<UUID> referenceTypeIds;
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None); private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
@ -82,18 +79,18 @@ public class ReferenceQuery extends QueryBase<ReferenceEntity> {
return this; return this;
} }
public ReferenceQuery types(ReferenceType value) { public ReferenceQuery typeIds(UUID value) {
this.referenceTypes = List.of(value); this.typeIds = List.of(value);
return this; return this;
} }
public ReferenceQuery types(ReferenceType... value) { public ReferenceQuery typeIds(UUID... value) {
this.referenceTypes = Arrays.asList(value); this.typeIds = Arrays.asList(value);
return this; return this;
} }
public ReferenceQuery types(Collection<ReferenceType> values) { public ReferenceQuery typeIds(Collection<UUID> values) {
this.referenceTypes = values; this.typeIds = values;
return this; return this;
} }
@ -157,21 +154,6 @@ public class ReferenceQuery extends QueryBase<ReferenceEntity> {
return this; return this;
} }
public ReferenceQuery referenceTypeIds(UUID value) {
this.referenceTypeIds = List.of(value);
return this;
}
public ReferenceQuery referenceTypeIds(UUID... value) {
this.referenceTypeIds = Arrays.asList(value);
return this;
}
public ReferenceQuery referenceTypeIds(Collection<UUID> values) {
this.referenceTypeIds = values;
return this;
}
public ReferenceQuery dmpReferenceSubQuery(DmpReferenceQuery value) { public ReferenceQuery dmpReferenceSubQuery(DmpReferenceQuery value) {
this.dmpReferenceQuery = value; this.dmpReferenceQuery = value;
return this; return this;
@ -193,7 +175,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.sources) ||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.typeIds) || this.isEmpty(this.referenceSourceTypes)|| this.isFalseQuery(this.dmpReferenceQuery);
} }
@Override @Override
@ -223,9 +205,9 @@ public class ReferenceQuery extends QueryBase<ReferenceEntity> {
inClause.value(item); inClause.value(item);
predicates.add(inClause); predicates.add(inClause);
} }
if (this.referenceTypes != null) { if (this.typeIds != null) {
CriteriaBuilder.In<ReferenceType> inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(ReferenceEntity._type)); CriteriaBuilder.In<UUID> inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(ReferenceEntity._typeId));
for (ReferenceType item : this.referenceTypes) for (UUID item : this.typeIds)
inClause.value(item); inClause.value(item);
predicates.add(inClause); predicates.add(inClause);
} }
@ -273,7 +255,7 @@ public class ReferenceQuery extends QueryBase<ReferenceEntity> {
item.setReference(QueryBase.convertSafe(tuple, columns, ReferenceEntity._reference, String.class)); item.setReference(QueryBase.convertSafe(tuple, columns, ReferenceEntity._reference, String.class));
item.setSource(QueryBase.convertSafe(tuple, columns, ReferenceEntity._source, String.class)); item.setSource(QueryBase.convertSafe(tuple, columns, ReferenceEntity._source, String.class));
item.setSourceType(QueryBase.convertSafe(tuple, columns, ReferenceEntity._sourceType, ReferenceSourceType.class)); item.setSourceType(QueryBase.convertSafe(tuple, columns, ReferenceEntity._sourceType, ReferenceSourceType.class));
item.setType(QueryBase.convertSafe(tuple, columns, ReferenceEntity._type, ReferenceType.class)); item.setTypeId(QueryBase.convertSafe(tuple, columns, ReferenceEntity._typeId, UUID.class));
item.setCreatedById(QueryBase.convertSafe(tuple, columns, ReferenceEntity._createdById, UUID.class)); item.setCreatedById(QueryBase.convertSafe(tuple, columns, ReferenceEntity._createdById, UUID.class));
return item; return item;
} }
@ -292,7 +274,8 @@ public class ReferenceQuery extends QueryBase<ReferenceEntity> {
else if (item.match(Reference._reference) || item.match(PublicReference._reference)) return ReferenceEntity._reference; else if (item.match(Reference._reference) || item.match(PublicReference._reference)) return ReferenceEntity._reference;
else if (item.match(Reference._source)) return ReferenceEntity._source; else if (item.match(Reference._source)) return ReferenceEntity._source;
else if (item.match(Reference._sourceType)) return ReferenceEntity._sourceType; else if (item.match(Reference._sourceType)) return ReferenceEntity._sourceType;
else if (item.match(Reference._type) || item.match(PublicReference._type)) return ReferenceEntity._type; else if (item.match(Reference._type) || item.match(PublicReference._type)) return ReferenceEntity._typeId;
else if (item.prefix(Reference._type) || item.prefix(PublicReference._type)) return ReferenceEntity._typeId;
else if (item.prefix(Reference._createdBy)) return ReferenceEntity._createdById; else if (item.prefix(Reference._createdBy)) return ReferenceEntity._createdById;
else return null; else return null;
} }

View File

@ -40,7 +40,7 @@ public class ReferenceDefinitionSearchLookup extends Lookup {
public ReferenceQuery enrich(QueryFactory queryFactory) { public ReferenceQuery enrich(QueryFactory queryFactory) {
ReferenceQuery query = queryFactory.query(ReferenceQuery.class); ReferenceQuery query = queryFactory.query(ReferenceQuery.class);
if (this.referenceTypeId != null) query.referenceTypeIds(this.referenceTypeId); if (this.referenceTypeId != null) query.typeIds(this.referenceTypeId);
this.enrichCommon(query); this.enrichCommon(query);

View File

@ -1,6 +1,5 @@
package eu.eudat.query.lookup; package eu.eudat.query.lookup;
import eu.eudat.commons.enums.ReferenceType;
import eu.eudat.commons.enums.IsActive; import eu.eudat.commons.enums.IsActive;
import eu.eudat.commons.enums.ReferenceSourceType; import eu.eudat.commons.enums.ReferenceSourceType;
import eu.eudat.query.ReferenceQuery; import eu.eudat.query.ReferenceQuery;
@ -19,7 +18,7 @@ public class ReferenceLookup extends Lookup {
private Collection<ReferenceSourceType> sourceTypes; private Collection<ReferenceSourceType> sourceTypes;
private Collection<ReferenceType> types; private Collection<UUID> typeIds;
private List<UUID> ids; private List<UUID> ids;
@ -65,19 +64,19 @@ public class ReferenceLookup extends Lookup {
this.sourceTypes = sourceTypes; this.sourceTypes = sourceTypes;
} }
public Collection<ReferenceType> getTypes() { public Collection<UUID> getTypeIds() {
return types; return typeIds;
} }
public void setTypes(Collection<ReferenceType> types) { public void setTypeIds(Collection<UUID> typeIds) {
this.types = types; this.typeIds = typeIds;
} }
public ReferenceQuery enrich(QueryFactory queryFactory) { public ReferenceQuery enrich(QueryFactory queryFactory) {
ReferenceQuery query = queryFactory.query(ReferenceQuery.class); ReferenceQuery query = queryFactory.query(ReferenceQuery.class);
if (this.like != null) query.like(this.like); if (this.like != null) query.like(this.like);
if (this.isActive != null) query.isActive(this.isActive); if (this.isActive != null) query.isActive(this.isActive);
if (this.types != null) query.types(this.types); if (this.typeIds != null) query.typeIds(this.typeIds);
if (this.sourceTypes != null) query.sourceTypes(this.sourceTypes); if (this.sourceTypes != null) query.sourceTypes(this.sourceTypes);
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);

View File

@ -1,15 +1,16 @@
package eu.eudat.query.lookup; package eu.eudat.query.lookup;
import eu.eudat.commons.enums.ReferenceType;
import eu.eudat.query.ReferenceQuery; import eu.eudat.query.ReferenceQuery;
import gr.cite.tools.data.query.Lookup; import gr.cite.tools.data.query.Lookup;
import gr.cite.tools.data.query.QueryFactory; import gr.cite.tools.data.query.QueryFactory;
import java.util.UUID;
public class ReferenceSearchLookup extends Lookup { public class ReferenceSearchLookup extends Lookup {
private String like; private String like;
private ReferenceType type; private UUID typeId;
private String key; private String key;
@ -21,12 +22,12 @@ public class ReferenceSearchLookup extends Lookup {
this.like = like; this.like = like;
} }
public ReferenceType getType() { public UUID getTypeId() {
return type; return typeId;
} }
public void setType(ReferenceType type) { public void setTypeId(UUID typeId) {
this.type = type; this.typeId = typeId;
} }
public String getKey() { public String getKey() {
@ -39,7 +40,7 @@ public class ReferenceSearchLookup extends Lookup {
public ReferenceQuery enrich(QueryFactory queryFactory) { public ReferenceQuery enrich(QueryFactory queryFactory) {
ReferenceQuery query = queryFactory.query(ReferenceQuery.class); ReferenceQuery query = queryFactory.query(ReferenceQuery.class);
if (this.type != null) query.types(this.type); if (this.typeId != null) query.typeIds(this.typeId);
this.enrichCommon(query); this.enrichCommon(query);

View File

@ -1,14 +1,10 @@
package eu.eudat.query.lookup; package eu.eudat.query.lookup;
import eu.eudat.commons.enums.IsActive; import eu.eudat.commons.enums.IsActive;
import eu.eudat.commons.enums.ReferenceSourceType;
import eu.eudat.commons.enums.ReferenceType;
import eu.eudat.query.ReferenceQuery;
import eu.eudat.query.ReferenceTypeQuery; import eu.eudat.query.ReferenceTypeQuery;
import gr.cite.tools.data.query.Lookup; import gr.cite.tools.data.query.Lookup;
import gr.cite.tools.data.query.QueryFactory; import gr.cite.tools.data.query.QueryFactory;
import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;

View File

@ -6,13 +6,13 @@ import eu.eudat.authorization.Permission;
import eu.eudat.commons.JsonHandlingService; import eu.eudat.commons.JsonHandlingService;
import eu.eudat.commons.XmlHandlingService; import eu.eudat.commons.XmlHandlingService;
import eu.eudat.commons.enums.*; import eu.eudat.commons.enums.*;
import eu.eudat.commons.enums.ReferenceType;
import eu.eudat.commons.scope.user.UserScope; import eu.eudat.commons.scope.user.UserScope;
import eu.eudat.commons.types.dashborad.RecentActivityItemEntity; import eu.eudat.commons.types.dashborad.RecentActivityItemEntity;
import eu.eudat.convention.ConventionService; import eu.eudat.convention.ConventionService;
import eu.eudat.errorcode.ErrorThesaurusProperties; import eu.eudat.errorcode.ErrorThesaurusProperties;
import eu.eudat.event.EventBroker; import eu.eudat.event.EventBroker;
import eu.eudat.model.*; import eu.eudat.model.*;
import eu.eudat.model.builder.PublicReferenceTypeBuilder;
import eu.eudat.model.builder.RecentActivityItemBuilder; import eu.eudat.model.builder.RecentActivityItemBuilder;
import eu.eudat.model.result.QueryResult; import eu.eudat.model.result.QueryResult;
import eu.eudat.query.*; import eu.eudat.query.*;
@ -43,58 +43,27 @@ public class DashboardServiceImpl implements DashboardService {
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(DashboardServiceImpl.class)); private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(DashboardServiceImpl.class));
private final EntityManager entityManager;
private final AuthorizationService authorizationService;
private final DeleterFactory deleterFactory;
private final BuilderFactory builderFactory;
private final ConventionService conventionService; private final ConventionService conventionService;
private final AuthorizationService authorizationService;
private final ErrorThesaurusProperties errors; private final BuilderFactory builderFactory;
private final MessageSource messageSource;
private final EventBroker eventBroker;
private final QueryFactory queryFactory; private final QueryFactory queryFactory;
private final JsonHandlingService jsonHandlingService;
private final UserScope userScope; private final UserScope userScope;
private final XmlHandlingService xmlHandlingService; private final DashboardServiceProperties config;
private final ElasticQueryHelperService elasticQueryHelperService; private final ElasticQueryHelperService elasticQueryHelperService;
private final DashboardStatisticsCacheService dashboardStatisticsCacheService; private final DashboardStatisticsCacheService dashboardStatisticsCacheService;
@Autowired @Autowired
public DashboardServiceImpl( public DashboardServiceImpl(
EntityManager entityManager, ConventionService conventionService, AuthorizationService authorizationService,
AuthorizationService authorizationService,
DeleterFactory deleterFactory,
BuilderFactory builderFactory, BuilderFactory builderFactory,
ConventionService conventionService,
ErrorThesaurusProperties errors,
MessageSource messageSource,
EventBroker eventBroker,
QueryFactory queryFactory, QueryFactory queryFactory,
JsonHandlingService jsonHandlingService,
UserScope userScope, UserScope userScope,
XmlHandlingService xmlHandlingService, ElasticQueryHelperService elasticQueryHelperService, DashboardStatisticsCacheService dashboardStatisticsCacheService) { DashboardServiceProperties config, ElasticQueryHelperService elasticQueryHelperService, DashboardStatisticsCacheService dashboardStatisticsCacheService) {
this.entityManager = entityManager;
this.authorizationService = authorizationService;
this.deleterFactory = deleterFactory;
this.builderFactory = builderFactory;
this.conventionService = conventionService; this.conventionService = conventionService;
this.errors = errors; this.authorizationService = authorizationService;
this.messageSource = messageSource; this.builderFactory = builderFactory;
this.eventBroker = eventBroker;
this.queryFactory = queryFactory; this.queryFactory = queryFactory;
this.jsonHandlingService = jsonHandlingService;
this.userScope = userScope; this.userScope = userScope;
this.xmlHandlingService = xmlHandlingService; this.config = config;
this.elasticQueryHelperService = elasticQueryHelperService; this.elasticQueryHelperService = elasticQueryHelperService;
this.dashboardStatisticsCacheService = dashboardStatisticsCacheService; this.dashboardStatisticsCacheService = dashboardStatisticsCacheService;
} }
@ -146,12 +115,19 @@ public class DashboardServiceImpl implements DashboardService {
DashboardStatistics statistics = new DashboardStatistics(); DashboardStatistics statistics = new DashboardStatistics();
statistics.setDmpCount(dmpQuery.authorize(EnumSet.of(Public)).count()); statistics.setDmpCount(dmpQuery.authorize(EnumSet.of(Public)).count());
statistics.setDescriptionCount(this.queryFactory.query(DescriptionQuery.class).isActive(IsActive.Active).dmpSubQuery(dmpQuery).statuses(DescriptionStatus.Finalized).authorize(EnumSet.of(Public)).count()); statistics.setDescriptionCount(this.queryFactory.query(DescriptionQuery.class).isActive(IsActive.Active).dmpSubQuery(dmpQuery).statuses(DescriptionStatus.Finalized).authorize(EnumSet.of(Public)).count());
statistics.setOrganizationCount(this.queryFactory.query(ReferenceQuery.class).isActive(IsActive.Active).types(ReferenceType.Organizations).authorize(EnumSet.of(Public))
.dmpReferenceSubQuery(this.queryFactory.query(DmpReferenceQuery.class).isActives(IsActive.Active) statistics.setReferenceTypeStatistics(new ArrayList<>());
.dmpSubQuery(dmpQuery)).count()); if (!this.conventionService.isListNullOrEmpty(this.config.getReferenceTypeCounters())){
statistics.setGrantCount(this.queryFactory.query(ReferenceQuery.class).isActive(IsActive.Active).types(ReferenceType.Grants).authorize(EnumSet.of(Public)) for (UUID typeId : this.config.getReferenceTypeCounters()){
DashboardReferenceTypeStatistics referenceTypeStatistics = new DashboardReferenceTypeStatistics();
referenceTypeStatistics.setCount(this.queryFactory.query(ReferenceQuery.class).isActive(IsActive.Active).typeIds(typeId).authorize(EnumSet.of(Public))
.dmpReferenceSubQuery(this.queryFactory.query(DmpReferenceQuery.class).isActives(IsActive.Active) .dmpReferenceSubQuery(this.queryFactory.query(DmpReferenceQuery.class).isActives(IsActive.Active)
.dmpSubQuery(dmpQuery)).count()); .dmpSubQuery(dmpQuery)).count());
referenceTypeStatistics.setReferenceType(this.builderFactory.builder(PublicReferenceTypeBuilder.class).build(new BaseFieldSet().ensure(PublicReferenceType._name), this.queryFactory.query(ReferenceTypeQuery.class).ids(typeId).first()));
statistics.getReferenceTypeStatistics().add(referenceTypeStatistics);
}
}
cacheValue = new DashboardStatisticsCacheService.DashboardStatisticsCacheValue(); cacheValue = new DashboardStatisticsCacheService.DashboardStatisticsCacheValue();
cacheValue.setPublic(true); cacheValue.setPublic(true);
cacheValue.setDashboardStatistics(statistics); cacheValue.setDashboardStatistics(statistics);
@ -175,13 +151,18 @@ public class DashboardServiceImpl implements DashboardService {
DashboardStatistics statistics = new DashboardStatistics(); DashboardStatistics statistics = new DashboardStatistics();
statistics.setDmpCount(dmpQuery.authorize(EnumSet.of(AuthorizationFlags.DmpAssociated)).count()); statistics.setDmpCount(dmpQuery.authorize(EnumSet.of(AuthorizationFlags.DmpAssociated)).count());
statistics.setDescriptionCount(this.queryFactory.query(DescriptionQuery.class).isActive(IsActive.Active).dmpSubQuery(dmpQuery).statuses(DescriptionStatus.Finalized).authorize(EnumSet.of(AuthorizationFlags.DmpAssociated)).count()); statistics.setDescriptionCount(this.queryFactory.query(DescriptionQuery.class).isActive(IsActive.Active).dmpSubQuery(dmpQuery).statuses(DescriptionStatus.Finalized).authorize(EnumSet.of(AuthorizationFlags.DmpAssociated)).count());
statistics.setOrganizationCount(this.queryFactory.query(ReferenceQuery.class).isActive(IsActive.Active).types(ReferenceType.Organizations).authorize(EnumSet.of(Owner))
.dmpReferenceSubQuery(this.queryFactory.query(DmpReferenceQuery.class).isActives(IsActive.Active)
.dmpSubQuery(dmpQuery)).count());
statistics.setGrantCount(this.queryFactory.query(ReferenceQuery.class).isActive(IsActive.Active).types(ReferenceType.Grants).authorize(EnumSet.of(Owner))
.dmpReferenceSubQuery(this.queryFactory.query(DmpReferenceQuery.class).isActives(IsActive.Active)
.dmpSubQuery(dmpQuery)).count());
statistics.setReferenceTypeStatistics(new ArrayList<>());
if (!this.conventionService.isListNullOrEmpty(this.config.getReferenceTypeCounters())){
for (UUID typeId : this.config.getReferenceTypeCounters()){
DashboardReferenceTypeStatistics referenceTypeStatistics = new DashboardReferenceTypeStatistics();
referenceTypeStatistics.setCount(this.queryFactory.query(ReferenceQuery.class).isActive(IsActive.Active).typeIds(typeId).authorize(EnumSet.of(Owner))
.dmpReferenceSubQuery(this.queryFactory.query(DmpReferenceQuery.class).isActives(IsActive.Active)
.dmpSubQuery(dmpQuery)).count());
referenceTypeStatistics.setReferenceType(this.builderFactory.builder(PublicReferenceTypeBuilder.class).build(new BaseFieldSet().ensure(PublicReferenceType._name), this.queryFactory.query(ReferenceTypeQuery.class).ids(typeId).first()));
statistics.getReferenceTypeStatistics().add(referenceTypeStatistics);
}
}
cacheValue = new DashboardStatisticsCacheService.DashboardStatisticsCacheValue(this.userScope.getUserId()); cacheValue = new DashboardStatisticsCacheService.DashboardStatisticsCacheValue(this.userScope.getUserId());
cacheValue.setPublic(false); cacheValue.setPublic(false);
cacheValue.setDashboardStatistics(statistics); cacheValue.setDashboardStatistics(statistics);

View File

@ -0,0 +1,21 @@
package eu.eudat.service.dashborad;
import org.springframework.boot.context.properties.ConfigurationProperties;
import java.util.List;
import java.util.UUID;
@ConfigurationProperties(prefix = "dashboard")
public class DashboardServiceProperties {
private List<UUID> referenceTypeCounters;
public List<UUID> getReferenceTypeCounters() {
return referenceTypeCounters;
}
public void setReferenceTypeCounters(List<UUID> referenceTypeCounters) {
this.referenceTypeCounters = referenceTypeCounters;
}
}

View File

@ -0,0 +1,10 @@
package eu.eudat.service.dashborad;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Configuration;
@Configuration
@EnableConfigurationProperties(DashboardServiceProperties.class)
public class PublicApiConfiguration {
}

View File

@ -5,12 +5,12 @@ import eu.eudat.authorization.Permission;
import eu.eudat.commons.JsonHandlingService; import eu.eudat.commons.JsonHandlingService;
import eu.eudat.commons.XmlHandlingService; import eu.eudat.commons.XmlHandlingService;
import eu.eudat.commons.enums.*; import eu.eudat.commons.enums.*;
import eu.eudat.commons.enums.ReferenceType;
import eu.eudat.commons.enums.notification.NotificationContactType; import eu.eudat.commons.enums.notification.NotificationContactType;
import eu.eudat.commons.scope.user.UserScope; import eu.eudat.commons.scope.user.UserScope;
import eu.eudat.commons.types.description.*; import eu.eudat.commons.types.description.*;
import eu.eudat.commons.types.descriptionreference.DescriptionReferenceDataEntity; import eu.eudat.commons.types.descriptionreference.DescriptionReferenceDataEntity;
import eu.eudat.commons.types.descriptiontemplate.FieldSetEntity; import eu.eudat.commons.types.descriptiontemplate.FieldSetEntity;
import eu.eudat.commons.types.descriptiontemplate.fielddata.ReferenceTypeDataEntity;
import eu.eudat.commons.types.descriptiontemplate.fielddata.UploadDataEntity; import eu.eudat.commons.types.descriptiontemplate.fielddata.UploadDataEntity;
import eu.eudat.commons.types.notification.*; import eu.eudat.commons.types.notification.*;
import eu.eudat.commons.types.reference.DefinitionEntity; import eu.eudat.commons.types.reference.DefinitionEntity;
@ -184,7 +184,7 @@ public class DescriptionServiceImpl implements DescriptionService {
this.entityManager.flush(); this.entityManager.flush();
eu.eudat.commons.types.descriptiontemplate.DefinitionEntity definition = this.xmlHandlingService.fromXmlSafe(eu.eudat.commons.types.descriptiontemplate.DefinitionEntity.class, descriptionTemplateEntity.getDefinition()); eu.eudat.commons.types.descriptiontemplate.DefinitionEntity definition = this.xmlHandlingService.fromXmlSafe(eu.eudat.commons.types.descriptiontemplate.DefinitionEntity.class, descriptionTemplateEntity.getDefinition());
Map<String, List<UUID>> fieldToReferenceMap = this.patchAndSaveReferences(this.buildDescriptionReferencePersists(model.getProperties()), data.getId()); Map<String, List<UUID>> fieldToReferenceMap = this.patchAndSaveReferences(this.buildDescriptionReferencePersists(model.getProperties()), data.getId(), definition);
this.entityManager.flush(); this.entityManager.flush();
@ -424,12 +424,6 @@ public class DescriptionServiceImpl implements DescriptionService {
for (UUID id : ids){ for (UUID id : ids){
if (!existingIds.contains(id)) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{id, Description.class.getSimpleName()}, LocaleContextHolder.getLocale())); if (!existingIds.contains(id)) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{id, Description.class.getSimpleName()}, LocaleContextHolder.getLocale()));
} }
} if (FieldType.INTERNAL_DMP_ENTRIES_RESEARCHERS.equals(fieldType) && !this.conventionService.isListNullOrEmpty(persist.getTextListValue())){
List<UUID> ids = persist.getTextListValue().stream().map(UUID::fromString).toList();
Set<UUID> existingIds = this.queryFactory.query(ReferenceQuery.class).ids(ids).types(ReferenceType.Researcher).isActive(IsActive.Active).collectAs(new BaseFieldSet().ensure(Reference._id)).stream().map(ReferenceEntity::getId).collect(Collectors.toSet());
for (UUID id : ids){
if (!existingIds.contains(id)) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{id, Reference.class.getSimpleName()}, LocaleContextHolder.getLocale()));
}
} }
data.setTextListValue(persist.getTextListValue()); data.setTextListValue(persist.getTextListValue());
} }
@ -483,7 +477,7 @@ public class DescriptionServiceImpl implements DescriptionService {
} }
} }
private Map<String, List<UUID>> patchAndSaveReferences(List<DescriptionReferencePersist> models, UUID descriptionId) throws InvalidApplicationException { private Map<String, List<UUID>> patchAndSaveReferences(List<DescriptionReferencePersist> models, UUID descriptionId, eu.eudat.commons.types.descriptiontemplate.DefinitionEntity definition) throws InvalidApplicationException {
if (models == null) models = new ArrayList<>(); if (models == null) models = new ArrayList<>();
Map<String, List<UUID>> fieldToReferenceMap = new HashMap<>(); Map<String, List<UUID>> fieldToReferenceMap = new HashMap<>();
@ -512,13 +506,16 @@ 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()).sources(referencePersist.getSource()).isActive(IsActive.Active).references(referencePersist.getReference()).first(); ReferenceTypeDataEntity fieldEntity = definition.getFieldById(model.getData().getFieldId()).stream().filter(x-> x.getData() != null && x.getData().getFieldType().equals(FieldType.REFERENCE_TYPES)).map(x-> (ReferenceTypeDataEntity)x.getData()).findFirst().orElse(null);
if (fieldEntity == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{model.getData().getFieldId(), ReferenceTypeDataEntity.class.getSimpleName()}, LocaleContextHolder.getLocale()));
referenceEntity = this.queryFactory.query(ReferenceQuery.class).sourceTypes(referencePersist.getSourceType()).typeIds(fieldEntity.getReferenceTypeId()).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.setTypeId(fieldEntity.getReferenceTypeId());
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

@ -12,6 +12,7 @@ import eu.eudat.commons.types.actionconfirmation.DmpInvitationEntity;
import eu.eudat.commons.types.dmp.DmpBlueprintValueEntity; import eu.eudat.commons.types.dmp.DmpBlueprintValueEntity;
import eu.eudat.commons.types.dmp.DmpContactEntity; import eu.eudat.commons.types.dmp.DmpContactEntity;
import eu.eudat.commons.types.dmp.DmpPropertiesEntity; import eu.eudat.commons.types.dmp.DmpPropertiesEntity;
import eu.eudat.commons.types.dmpblueprint.ReferenceFieldEntity;
import eu.eudat.commons.types.dmpreference.DmpReferenceDataEntity; import eu.eudat.commons.types.dmpreference.DmpReferenceDataEntity;
import eu.eudat.commons.types.notification.*; import eu.eudat.commons.types.notification.*;
import eu.eudat.commons.types.reference.DefinitionEntity; import eu.eudat.commons.types.reference.DefinitionEntity;
@ -24,10 +25,7 @@ import eu.eudat.event.DmpTouchedEvent;
import eu.eudat.event.EventBroker; import eu.eudat.event.EventBroker;
import eu.eudat.integrationevent.outbox.notification.NotifyIntegrationEvent; import eu.eudat.integrationevent.outbox.notification.NotifyIntegrationEvent;
import eu.eudat.integrationevent.outbox.notification.NotifyIntegrationEventHandler; import eu.eudat.integrationevent.outbox.notification.NotifyIntegrationEventHandler;
import eu.eudat.model.Dmp; import eu.eudat.model.*;
import eu.eudat.model.DmpUser;
import eu.eudat.model.Reference;
import eu.eudat.model.UserContactInfo;
import eu.eudat.model.builder.DmpBuilder; import eu.eudat.model.builder.DmpBuilder;
import eu.eudat.model.builder.DmpUserBuilder; import eu.eudat.model.builder.DmpUserBuilder;
import eu.eudat.model.deleter.*; import eu.eudat.model.deleter.*;
@ -169,7 +167,12 @@ public class DmpServiceImpl implements DmpService {
DmpEntity data = this.patchAndSave(model); DmpEntity data = this.patchAndSave(model);
this.patchAndSaveReferences(this.buildDmpReferencePersists(model.getProperties()), data.getId()); DmpBlueprintEntity blueprintEntity = this.entityManager.find(DmpBlueprintEntity.class, data.getBlueprintId());
if (blueprintEntity == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{data.getBlueprintId(), DmpBlueprint.class.getSimpleName()}, LocaleContextHolder.getLocale()));
eu.eudat.commons.types.dmpblueprint.DefinitionEntity definition = this.xmlHandlingService.fromXmlSafe(eu.eudat.commons.types.dmpblueprint.DefinitionEntity.class, blueprintEntity.getDefinition());
if (definition == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{data.getBlueprintId(), eu.eudat.commons.types.dmpblueprint.DefinitionEntity.class.getSimpleName()}, LocaleContextHolder.getLocale()));
this.patchAndSaveReferences(this.buildDmpReferencePersists(model.getProperties()), data.getId(), definition);
this.patchAndSaveTemplates(data.getId(), model.getDescriptionTemplates()); this.patchAndSaveTemplates(data.getId(), model.getDescriptionTemplates());
@ -620,7 +623,7 @@ public class DmpServiceImpl implements DmpService {
return dmpReferencePersists; return dmpReferencePersists;
} }
private void patchAndSaveReferences(List<DmpReferencePersist> models, UUID dmpId) throws InvalidApplicationException { private void patchAndSaveReferences(List<DmpReferencePersist> models, UUID dmpId, eu.eudat.commons.types.dmpblueprint.DefinitionEntity blueprintDefinition) throws InvalidApplicationException {
if (models == null) models = new ArrayList<>(); if (models == null) models = new ArrayList<>();
List<DmpReferenceEntity> dmpReferences = this.queryFactory.query(DmpReferenceQuery.class).dmpIds(dmpId).collect(); List<DmpReferenceEntity> dmpReferences = this.queryFactory.query(DmpReferenceQuery.class).dmpIds(dmpId).collect();
@ -647,13 +650,16 @@ 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()).sources(referencePersist.getSource()).isActive(IsActive.Active).references(referencePersist.getReference()).first(); ReferenceFieldEntity fieldEntity = blueprintDefinition.getFieldById(model.getData().getBlueprintFieldId()).stream().filter(x-> x.getCategory().equals(DmpBlueprintFieldCategory.Reference)).map(x-> (ReferenceFieldEntity)x).findFirst().orElse(null);
if (fieldEntity == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{model.getData().getBlueprintFieldId(), ReferenceFieldEntity.class.getSimpleName()}, LocaleContextHolder.getLocale()));
referenceEntity = this.queryFactory.query(ReferenceQuery.class).sourceTypes(referencePersist.getSourceType()).typeIds(fieldEntity.getReferenceTypeId()).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.setTypeId(fieldEntity.getReferenceTypeId());
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

@ -19,7 +19,6 @@ import eu.eudat.model.dmpblueprintdefinition.Section;
import eu.eudat.model.persist.DmpBlueprintPersist; import eu.eudat.model.persist.DmpBlueprintPersist;
import eu.eudat.model.persist.NewVersionDmpBlueprintPersist; import eu.eudat.model.persist.NewVersionDmpBlueprintPersist;
import eu.eudat.model.persist.dmpblueprintdefinition.*; import eu.eudat.model.persist.dmpblueprintdefinition.*;
import eu.eudat.query.DescriptionTemplateQuery;
import eu.eudat.query.DmpBlueprintQuery; import eu.eudat.query.DmpBlueprintQuery;
import eu.eudat.service.responseutils.ResponseUtilsService; import eu.eudat.service.responseutils.ResponseUtilsService;
import gr.cite.commons.web.authz.service.AuthorizationService; import gr.cite.commons.web.authz.service.AuthorizationService;
@ -37,7 +36,6 @@ import gr.cite.tools.logging.MapLogEntry;
import gr.cite.tools.validation.ValidatorFactory; import gr.cite.tools.validation.ValidatorFactory;
import jakarta.persistence.EntityManager; import jakarta.persistence.EntityManager;
import jakarta.xml.bind.JAXBException; import jakarta.xml.bind.JAXBException;
import org.apache.bcel.generic.DADD;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -252,15 +250,26 @@ public class DmpBlueprintServiceImpl implements DmpBlueprintService {
if (persist == null) if (persist == null)
return new ExtraFieldEntity(); return new ExtraFieldEntity();
FieldEntity data; FieldEntity data;
if (DmpBlueprintFieldCategory.Extra.equals(persist.getCategory())) {
switch (persist.getCategory()){
case Extra -> {
ExtraFieldEntity dataTyped = new ExtraFieldEntity(); ExtraFieldEntity dataTyped = new ExtraFieldEntity();
dataTyped.setType(((ExtraFieldPersist) persist).getDataType()); dataTyped.setType(((ExtraFieldPersist) persist).getDataType());
data = dataTyped; data = dataTyped;
} else { }
case System -> {
SystemFieldEntity dataTyped = new SystemFieldEntity(); SystemFieldEntity dataTyped = new SystemFieldEntity();
dataTyped.setType(((SystemFieldPersist) persist).getSystemFieldType()); dataTyped.setType(((SystemFieldPersist) persist).getSystemFieldType());
data = dataTyped; data = dataTyped;
} }
case Reference -> {
ReferenceFieldEntity dataTyped = new ReferenceFieldEntity();
dataTyped.setReferenceTypeId(((ReferenceFieldPersist) persist).getReferenceTypeId());
data = dataTyped;
}
default -> throw new InternalError("unknown type: " + persist.getCategory());
}
data.setId(persist.getId()); data.setId(persist.getId());
data.setCategory(persist.getCategory()); data.setCategory(persist.getCategory());
data.setLabel(persist.getLabel()); data.setLabel(persist.getLabel());
@ -472,6 +481,7 @@ public class DmpBlueprintServiceImpl implements DmpBlueprintService {
} }
} }
xml.setSystemFields(dmpBlueprintSystemFieldModels); xml.setSystemFields(dmpBlueprintSystemFieldModels);
List<ExtraFieldImportExport> dmpBlueprintExtraFieldModels = new LinkedList<>(); List<ExtraFieldImportExport> dmpBlueprintExtraFieldModels = new LinkedList<>();
if (!this.conventionService.isListNullOrEmpty(entity.getFields())) { if (!this.conventionService.isListNullOrEmpty(entity.getFields())) {
for (ExtraFieldEntity systemField : entity.getFields().stream().filter(x -> x.getCategory() == DmpBlueprintFieldCategory.Extra).map(x -> (ExtraFieldEntity) x).toList()) { for (ExtraFieldEntity systemField : entity.getFields().stream().filter(x -> x.getCategory() == DmpBlueprintFieldCategory.Extra).map(x -> (ExtraFieldEntity) x).toList()) {
@ -480,6 +490,14 @@ public class DmpBlueprintServiceImpl implements DmpBlueprintService {
} }
xml.setExtraFields(dmpBlueprintExtraFieldModels); xml.setExtraFields(dmpBlueprintExtraFieldModels);
List<ReferenceFieldImportExport> dmpBlueprintReferenceFieldModels = new LinkedList<>();
if (!this.conventionService.isListNullOrEmpty(entity.getFields())) {
for (ReferenceFieldEntity referenceFieldEntity : entity.getFields().stream().filter(x -> x.getCategory() == DmpBlueprintFieldCategory.Reference).map(x -> (ReferenceFieldEntity) x).toList()) {
dmpBlueprintReferenceFieldModels.add(this.referenceFieldXmlToExport(referenceFieldEntity));
}
}
xml.setReferenceFields(dmpBlueprintReferenceFieldModels);
List<DescriptionTemplateImportExport> dmpBlueprintDescriptionTemplates = new LinkedList<>(); List<DescriptionTemplateImportExport> dmpBlueprintDescriptionTemplates = new LinkedList<>();
if (!this.conventionService.isListNullOrEmpty(entity.getDescriptionTemplates())) { if (!this.conventionService.isListNullOrEmpty(entity.getDescriptionTemplates())) {
for (DescriptionTemplateEntity descriptionTemplate : entity.getDescriptionTemplates()) { for (DescriptionTemplateEntity descriptionTemplate : entity.getDescriptionTemplates()) {
@ -511,6 +529,18 @@ public class DmpBlueprintServiceImpl implements DmpBlueprintService {
return xml; return xml;
} }
private ReferenceFieldImportExport referenceFieldXmlToExport(ReferenceFieldEntity entity) {
ReferenceFieldImportExport xml = new ReferenceFieldImportExport();
xml.setId(entity.getId());
xml.setReferenceTypeId(entity.getReferenceTypeId());
xml.setLabel(entity.getLabel());
xml.setPlaceholder(entity.getPlaceholder());
xml.setDescription(entity.getDescription());
xml.setOrdinal(entity.getOrdinal());
xml.setRequired(entity.isRequired());
return xml;
}
private SystemFieldImportExport systemFieldXmlToExport(SystemFieldEntity entity) { private SystemFieldImportExport systemFieldXmlToExport(SystemFieldEntity entity) {
SystemFieldImportExport xml = new SystemFieldImportExport(); SystemFieldImportExport xml = new SystemFieldImportExport();
xml.setId(entity.getId()); xml.setId(entity.getId());
@ -572,6 +602,11 @@ public class DmpBlueprintServiceImpl implements DmpBlueprintService {
dmpBlueprintFieldModels.add(this.xmlSystemFieldToPersist(systemField)); dmpBlueprintFieldModels.add(this.xmlSystemFieldToPersist(systemField));
} }
} }
if (!this.conventionService.isListNullOrEmpty(importXml.getReferenceFields())) {
for (ReferenceFieldImportExport referenceField : importXml.getReferenceFields()) {
dmpBlueprintFieldModels.add(this.xmlReferenceFieldToPersist(referenceField));
}
}
if (!this.conventionService.isListNullOrEmpty(importXml.getExtraFields())) { if (!this.conventionService.isListNullOrEmpty(importXml.getExtraFields())) {
for (ExtraFieldImportExport extraField : importXml.getExtraFields()) { for (ExtraFieldImportExport extraField : importXml.getExtraFields()) {
dmpBlueprintFieldModels.add(this.xmlExtraFieldToPersist(extraField)); dmpBlueprintFieldModels.add(this.xmlExtraFieldToPersist(extraField));
@ -623,6 +658,19 @@ public class DmpBlueprintServiceImpl implements DmpBlueprintService {
return persist; return persist;
} }
private FieldPersist xmlReferenceFieldToPersist(ReferenceFieldImportExport importXml) {
ReferenceFieldPersist persist = new ReferenceFieldPersist();
persist.setId(importXml.getId());
persist.setCategory(DmpBlueprintFieldCategory.Reference);
persist.setReferenceTypeId(importXml.getReferenceTypeId());
persist.setLabel(importXml.getLabel());
persist.setPlaceholder(importXml.getPlaceholder());
persist.setDescription(importXml.getDescription());
persist.setOrdinal(importXml.getOrdinal());
persist.setRequired(importXml.isRequired());
return persist;
}
//endregion //endregion
} }

View File

@ -1,236 +0,0 @@
package eu.eudat.service.fielddatahelper;
import eu.eudat.authorization.AuthorizationFlags;
import eu.eudat.commons.types.descriptiontemplate.fielddata.ExternalSelectDataEntity;
import eu.eudat.commons.types.descriptiontemplate.importexport.fielddata.*;
import eu.eudat.convention.ConventionService;
import eu.eudat.model.builder.descriptiontemplatedefinition.fielddata.ExternalSelectDataBuilder;
import eu.eudat.model.descriptiontemplatedefinition.fielddata.ExternalSelectData;
import eu.eudat.model.persist.descriptiontemplatedefinition.fielddata.*;
import gr.cite.tools.data.builder.BuilderFactory;
import gr.cite.tools.fieldset.FieldSet;
import gr.cite.tools.validation.Validator;
import gr.cite.tools.validation.ValidatorFactory;
import org.jetbrains.annotations.NotNull;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.List;
@Component
public class ExternalSelectFieldDataHelperService extends BaseFieldDataHelperService<ExternalSelectData, ExternalSelectDataPersist, ExternalSelectDataEntity, ExternalSelectImportExport> {
private final ConventionService conventionService;
private final BuilderFactory builderFactory;
private final ValidatorFactory validatorFactory;
public ExternalSelectFieldDataHelperService(ConventionService conventionService, BuilderFactory builderFactory, ValidatorFactory validatorFactory) {
this.conventionService = conventionService;
this.builderFactory = builderFactory;
this.validatorFactory = validatorFactory;
}
@Override
public ExternalSelectDataEntity newDataInstanceInternal() {
return new ExternalSelectDataEntity();
}
@Override
public ExternalSelectData newModelInstanceInternal() {
return new ExternalSelectData();
}
@Override
public ExternalSelectDataPersist newPersistModelInstanceInternal() {
return new ExternalSelectDataPersist();
}
@Override
protected ExternalSelectImportExport newImportExportInstanceInternal() {
return new ExternalSelectImportExport();
}
@Override
public Class<?> getDataClass() {
return ExternalSelectDataEntity.class;
}
@Override
public Class<?> getModelClass() {
return ExternalSelectData.class;
}
@Override
public Class<?> getPersistModelClass() {
return ExternalSelectDataPersist.class;
}
@Override
public Class<?> getImportExportClass() {
return ExternalSelectImportExport.class;
}
@Override
public Validator getPersistModelValidator() {
return this.validatorFactory.validator(ExternalSelectDataPersist.AutoCompleteDataPersistValidator.class);
}
@Override
public List<ExternalSelectData> buildInternal(FieldSet fieldSet, List<ExternalSelectDataEntity> data, EnumSet<AuthorizationFlags> authorizationFlags){
return this.builderFactory.builder(ExternalSelectDataBuilder.class).authorize(authorizationFlags).build(fieldSet, data);
}
@Override
protected ExternalSelectDataEntity applyPersistInternal(ExternalSelectDataPersist persist, ExternalSelectDataEntity data) {
data.setMultipleSelect(persist.getMultipleSelect());
if (!this.conventionService.isListNullOrEmpty(persist.getSources())){
data.setSources(new ArrayList<>());
for (ExternalSelectDataPersist.ExternalSelectSourcePersist sourcePersist: persist.getSources()) {
data.getSources().add(this.buildAutoCompleteSingleData(sourcePersist));
}
}
return data;
}
private @NotNull ExternalSelectDataEntity.ExternalSelectSourceEntity buildAutoCompleteSingleData(ExternalSelectDataPersist.ExternalSelectSourcePersist persist){
ExternalSelectDataEntity.ExternalSelectSourceEntity data = new ExternalSelectDataEntity.ExternalSelectSourceEntity();
if (persist == null) return data;
data.setUrl(persist.getUrl());
data.setOptionsRoot(persist.getOptionsRoot());
data.setHasAuth(persist.getHasAuth());
if(persist.getSourceBinding() != null) data.setSourceBinding(this.buildOption(persist.getSourceBinding()));
if(persist.getAuth() != null) data.setAuth(this.buildAuthAutoCompleteData(persist.getAuth()));
data.setMethod(persist.getMethod());
return data;
}
private @NotNull ExternalSelectDataEntity.ExternalSelectSourceBindingEntity buildOption(ExternalSelectDataPersist.ExternalSelectSourceBindingPersist persist){
ExternalSelectDataEntity.ExternalSelectSourceBindingEntity data = new ExternalSelectDataEntity.ExternalSelectSourceBindingEntity();
if (persist == null) return data;
data.setLabel(persist.getLabel());
data.setValue(persist.getValue());
data.setSource(persist.getSource());
return data;
}
private @NotNull ExternalSelectDataEntity.ExternalSelectAuthDataEntity buildAuthAutoCompleteData(ExternalSelectDataPersist.ExternalSelectAuthDataPersist persist){
ExternalSelectDataEntity.ExternalSelectAuthDataEntity data = new ExternalSelectDataEntity.ExternalSelectAuthDataEntity();
if (persist == null) return data;
data.setBody(persist.getBody());
data.setUrl(persist.getUrl());
data.setMethod(persist.getMethod());
data.setPath(persist.getPath());
data.setType(persist.getType());
return data;
}
@Override
protected ExternalSelectDataPersist importExportMapDataToPersistInternal(ExternalSelectImportExport data, ExternalSelectDataPersist persist) {
persist.setMultipleSelect(data.getMultipleSelect());
if (!this.conventionService.isListNullOrEmpty(data.getSources())){
persist.setSources(new ArrayList<>());
for (ExternalSelectImportExport.ExternalSelectSourceImportExport autoCompleteSingleData: data.getSources()) {
persist.getSources().add(this.buildAutoCompleteSingleData(autoCompleteSingleData));
}
}
return persist;
}
private @NotNull ExternalSelectDataPersist.ExternalSelectSourcePersist buildAutoCompleteSingleData(ExternalSelectImportExport.ExternalSelectSourceImportExport data){
ExternalSelectDataPersist.ExternalSelectSourcePersist persist = new ExternalSelectDataPersist.ExternalSelectSourcePersist();
if (data == null) return persist;
persist.setUrl(data.getUrl());
persist.setOptionsRoot(data.getOptionsRoot());
persist.setHasAuth(data.getHasAuth());
if(data.getSourceBinding() != null) persist.setSourceBinding(this.buildOption(data.getSourceBinding()));
if(data.getAuth() != null) persist.setAuth(this.buildAuthAutoCompleteData(data.getAuth()));
persist.setMethod(data.getMethod());
return persist;
}
private @NotNull ExternalSelectDataPersist.ExternalSelectSourceBindingPersist buildOption(ExternalSelectImportExport.ExternalSelectSourceBindingImportExport data){
ExternalSelectDataPersist.ExternalSelectSourceBindingPersist persist = new ExternalSelectDataPersist.ExternalSelectSourceBindingPersist();
if (data == null) return persist;
persist.setLabel(data.getLabel());
persist.setValue(data.getValue());
persist.setSource(data.getSource());
return persist;
}
private @NotNull ExternalSelectDataPersist.ExternalSelectAuthDataPersist buildAuthAutoCompleteData(ExternalSelectImportExport.ExternalSelectAuthImportExport data){
ExternalSelectDataPersist.ExternalSelectAuthDataPersist persist = new ExternalSelectDataPersist.ExternalSelectAuthDataPersist();
if (data == null) return persist;
persist.setBody(data.getBody());
persist.setUrl(data.getUrl());
persist.setMethod(data.getMethod());
persist.setPath(data.getPath());
persist.setType(data.getType());
return persist;
}
@Override
protected ExternalSelectImportExport dataToImportExportXmlInternal(ExternalSelectDataEntity data, ExternalSelectImportExport xml) {
xml.setMultipleSelect(data.getMultipleSelect());
if (!this.conventionService.isListNullOrEmpty(data.getSources())){
xml.setSources(new ArrayList<>());
for (ExternalSelectDataEntity.ExternalSelectSourceEntity externalSelectSourceEntity : data.getSources()) {
xml.getSources().add(this.buildAutoCompleteSingleData(externalSelectSourceEntity));
}
}
return xml;
}
@Override
protected boolean isMultiValueInternal(ExternalSelectDataEntity data) {
return data.getMultipleSelect();
}
private @NotNull ExternalSelectImportExport.ExternalSelectSourceImportExport buildAutoCompleteSingleData(ExternalSelectDataEntity.ExternalSelectSourceEntity data){
ExternalSelectImportExport.ExternalSelectSourceImportExport xml = new ExternalSelectImportExport.ExternalSelectSourceImportExport();
if (data == null) return xml;
xml.setUrl(data.getUrl());
xml.setOptionsRoot(data.getOptionsRoot());
xml.setHasAuth(data.getHasAuth());
if(data.getSourceBinding() != null) xml.setSourceBinding(this.buildOption(data.getSourceBinding()));
if(data.getAuth() != null) xml.setAuth(this.buildAuthAutoCompleteData(data.getAuth()));
xml.setMethod(data.getMethod());
return xml;
}
private @NotNull ExternalSelectImportExport.ExternalSelectSourceBindingImportExport buildOption(ExternalSelectDataEntity.ExternalSelectSourceBindingEntity data){
ExternalSelectImportExport.ExternalSelectSourceBindingImportExport xml = new ExternalSelectImportExport.ExternalSelectSourceBindingImportExport();
if (data == null) return xml;
xml.setLabel(data.getLabel());
xml.setValue(data.getValue());
xml.setSource(data.getSource());
return xml;
}
private @NotNull ExternalSelectImportExport.ExternalSelectAuthImportExport buildAuthAutoCompleteData(ExternalSelectDataEntity.ExternalSelectAuthDataEntity data){
ExternalSelectImportExport.ExternalSelectAuthImportExport xml = new ExternalSelectImportExport.ExternalSelectAuthImportExport();
if (data == null) return xml;
xml.setBody(data.getBody());
xml.setUrl(data.getUrl());
xml.setMethod(data.getMethod());
xml.setPath(data.getPath());
xml.setType(data.getType());
return xml;
}
}

View File

@ -15,19 +15,8 @@ public class FieldDataHelperServiceProvider {
BaseFieldDataHelperService<?, ?, ?, ? > item = null; BaseFieldDataHelperService<?, ?, ?, ? > item = null;
switch (type) { switch (type) {
case DATA_REPOSITORIES:
case PUB_REPOSITORIES:
case JOURNAL_REPOSITORIES:
case TAXONOMIES:
case LICENSES:
case PUBLICATIONS:
case REGISTRIES:
case SERVICES:
case RESEARCHERS:
case INTERNAL_DMP_ENTRIES_DATASETS: case INTERNAL_DMP_ENTRIES_DATASETS:
case INTERNAL_DMP_ENTRIES_DMPS: case INTERNAL_DMP_ENTRIES_DMPS: {
case INTERNAL_DMP_ENTRIES_RESEARCHERS:
case ORGANIZATIONS: {
item = this.applicationContext.getBean(LabelAndMultiplicityFieldDataHelperService.class); item = this.applicationContext.getBean(LabelAndMultiplicityFieldDataHelperService.class);
break; break;
} }
@ -60,8 +49,8 @@ public class FieldDataHelperServiceProvider {
item = this.applicationContext.getBean(SelectFieldDataHelperService.class); item = this.applicationContext.getBean(SelectFieldDataHelperService.class);
break; break;
} }
case EXTERNAL_SELECT: { case REFERENCE_TYPES:{
item = this.applicationContext.getBean(ExternalSelectFieldDataHelperService.class); item = this.applicationContext.getBean(ReferenceTypeFieldDataHelperService.class);
break; break;
} }
default: throw new RuntimeException("unrecognized builder " + type.getValue()); default: throw new RuntimeException("unrecognized builder " + type.getValue());

View File

@ -0,0 +1,102 @@
package eu.eudat.service.fielddatahelper;
import eu.eudat.authorization.AuthorizationFlags;
import eu.eudat.commons.types.descriptiontemplate.fielddata.ReferenceTypeDataEntity;
import eu.eudat.commons.types.descriptiontemplate.importexport.fielddata.ReferenceTypeDataImportExport;
import eu.eudat.model.builder.descriptiontemplatedefinition.fielddata.ReferenceTypeDataBuilder;
import eu.eudat.model.descriptiontemplatedefinition.fielddata.ReferenceTypeData;
import eu.eudat.model.persist.descriptiontemplatedefinition.fielddata.ReferenceTypeDataPersist;
import gr.cite.tools.data.builder.BuilderFactory;
import gr.cite.tools.fieldset.FieldSet;
import gr.cite.tools.validation.Validator;
import gr.cite.tools.validation.ValidatorFactory;
import org.springframework.stereotype.Component;
import java.util.EnumSet;
import java.util.List;
@Component
public class ReferenceTypeFieldDataHelperService extends BaseFieldDataHelperService<ReferenceTypeData, ReferenceTypeDataPersist, ReferenceTypeDataEntity, ReferenceTypeDataImportExport> {
private final BuilderFactory builderFactory;
private final ValidatorFactory validatorFactory;
public ReferenceTypeFieldDataHelperService(BuilderFactory builderFactory, ValidatorFactory validatorFactory) {
this.builderFactory = builderFactory;
this.validatorFactory = validatorFactory;
}
@Override
public ReferenceTypeDataEntity newDataInstanceInternal() {
return new ReferenceTypeDataEntity();
}
@Override
public ReferenceTypeData newModelInstanceInternal() {
return new ReferenceTypeData();
}
@Override
public ReferenceTypeDataPersist newPersistModelInstanceInternal() {
return new ReferenceTypeDataPersist();
}
@Override
protected ReferenceTypeDataImportExport newImportExportInstanceInternal() {
return new ReferenceTypeDataImportExport();
}
@Override
public Class<?> getDataClass() {
return ReferenceTypeDataEntity.class;
}
@Override
public Class<?> getModelClass() {
return ReferenceTypeData.class;
}
@Override
public Class<?> getPersistModelClass() {
return ReferenceTypeDataPersist.class;
}
@Override
public Class<?> getImportExportClass() {
return ReferenceTypeDataImportExport.class;
}
@Override
public Validator getPersistModelValidator() {
return this.validatorFactory.validator(ReferenceTypeDataPersist.ReferenceTypeDataPersistValidator.class);
}
@Override
public List<ReferenceTypeData> buildInternal(FieldSet fieldSet, List<ReferenceTypeDataEntity> data, EnumSet<AuthorizationFlags> authorizationFlags){
return this.builderFactory.builder(ReferenceTypeDataBuilder.class).authorize(authorizationFlags).build(fieldSet, data);
}
@Override
protected ReferenceTypeDataEntity applyPersistInternal(ReferenceTypeDataPersist persist, ReferenceTypeDataEntity data) {
data.setMultipleSelect(persist.getMultipleSelect());
data.setReferenceTypeId(persist.getReferenceTypeId());
return data;
}
@Override
protected ReferenceTypeDataPersist importExportMapDataToPersistInternal(ReferenceTypeDataImportExport data, ReferenceTypeDataPersist persist){
persist.setMultipleSelect(data.getMultipleSelect());
persist.setReferenceTypeId(data.getReferenceTypeId());
return persist;
}
@Override
protected ReferenceTypeDataImportExport dataToImportExportXmlInternal(ReferenceTypeDataEntity data, ReferenceTypeDataImportExport xml) {
xml.setMultipleSelect(data.getMultipleSelect());
xml.setReferenceTypeId(data.getReferenceTypeId());
return xml;
}
@Override
protected boolean isMultiValueInternal(ReferenceTypeDataEntity data) {
return data.getMultipleSelect();
}
}

View File

@ -5,38 +5,23 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import eu.eudat.authorization.AuthorizationFlags; import eu.eudat.authorization.AuthorizationFlags;
import eu.eudat.commons.JsonHandlingService; import eu.eudat.commons.JsonHandlingService;
import eu.eudat.commons.XmlHandlingService; import eu.eudat.commons.XmlHandlingService;
import eu.eudat.commons.enums.FieldType;
import eu.eudat.commons.types.descriptiontemplate.FieldEntity; import eu.eudat.commons.types.descriptiontemplate.FieldEntity;
import eu.eudat.commons.types.descriptiontemplate.FieldSetEntity; import eu.eudat.commons.types.descriptiontemplate.FieldSetEntity;
import eu.eudat.commons.types.descriptiontemplate.fielddata.ExternalSelectDataEntity;
import eu.eudat.commons.types.descriptiontemplate.fielddata.LabelAndMultiplicityDataEntity;
import eu.eudat.commons.types.descriptiontemplate.fielddata.SelectDataEntity;
import eu.eudat.commons.types.prefilling.PrefillingEntity; import eu.eudat.commons.types.prefilling.PrefillingEntity;
import eu.eudat.convention.ConventionService; import eu.eudat.convention.ConventionService;
import eu.eudat.data.DescriptionTemplateEntity; import eu.eudat.data.DescriptionTemplateEntity;
import eu.eudat.data.ReferenceEntity;
import eu.eudat.model.*; import eu.eudat.model.*;
import eu.eudat.model.builder.DescriptionTemplateBuilder; import eu.eudat.model.builder.DescriptionTemplateBuilder;
import eu.eudat.model.builder.PrefillingBuilder; import eu.eudat.model.builder.PrefillingBuilder;
import eu.eudat.model.builder.ReferenceBuilder;
import eu.eudat.model.descriptionproperties.Field; import eu.eudat.model.descriptionproperties.Field;
import eu.eudat.model.descriptionproperties.PropertyDefinition; import eu.eudat.model.descriptionproperties.PropertyDefinition;
import eu.eudat.model.descriptionproperties.PropertyDefinitionFieldSet; import eu.eudat.model.descriptionproperties.PropertyDefinitionFieldSet;
import eu.eudat.model.descriptionproperties.PropertyDefinitionFieldSetItem; import eu.eudat.model.descriptionproperties.PropertyDefinitionFieldSetItem;
import eu.eudat.model.persist.DescriptionProfilingRequest; import eu.eudat.model.persist.DescriptionProfilingRequest;
import eu.eudat.model.persist.DescriptionProfilingWithDataRequest; import eu.eudat.model.persist.DescriptionProfilingWithDataRequest;
import eu.eudat.query.ReferenceQuery;
import eu.eudat.service.remotefetcher.ExternalUrlConfigProvider; import eu.eudat.service.remotefetcher.ExternalUrlConfigProvider;
import eu.eudat.service.remotefetcher.RemoteFetcherService;
import eu.eudat.service.remotefetcher.config.AuthenticationConfiguration;
import eu.eudat.service.remotefetcher.config.DataFieldsUrlConfiguration;
import eu.eudat.service.remotefetcher.config.DataUrlConfiguration;
import eu.eudat.service.remotefetcher.config.UrlConfiguration;
import eu.eudat.service.remotefetcher.config.entities.*; import eu.eudat.service.remotefetcher.config.entities.*;
import eu.eudat.service.remotefetcher.criteria.ExternalReferenceCriteria; import eu.eudat.service.remotefetcher.criteria.ExternalReferenceCriteria;
import eu.eudat.service.remotefetcher.criteria.FetchStrategy;
import eu.eudat.service.remotefetcher.models.ExternalAutocompleteFieldResult;
import eu.eudat.utilities.helpers.StreamDistinctBy;
import gr.cite.tools.data.builder.BuilderFactory; import gr.cite.tools.data.builder.BuilderFactory;
import gr.cite.tools.data.query.QueryFactory; import gr.cite.tools.data.query.QueryFactory;
import gr.cite.tools.exception.MyApplicationException; import gr.cite.tools.exception.MyApplicationException;
@ -47,7 +32,6 @@ import gr.cite.tools.logging.MapLogEntry;
import gr.cite.tools.validation.ValidatorFactory; import gr.cite.tools.validation.ValidatorFactory;
import jakarta.persistence.EntityManager; import jakarta.persistence.EntityManager;
import jakarta.xml.bind.JAXBException; import jakarta.xml.bind.JAXBException;
import org.json.JSONObject;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.MessageSource; import org.springframework.context.MessageSource;
@ -62,8 +46,6 @@ import org.xml.sax.SAXException;
import javax.xml.parsers.ParserConfigurationException; import javax.xml.parsers.ParserConfigurationException;
import java.io.IOException; import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.util.*; import java.util.*;
@ -80,7 +62,6 @@ public class PrefillingServiceImpl implements PrefillingService {
private final QueryFactory queryFactory; private final QueryFactory queryFactory;
private final ConventionService conventionService; private final ConventionService conventionService;
private final MessageSource messageSource; private final MessageSource messageSource;
private final RemoteFetcherService remoteFetcherService;
private final JsonHandlingService jsonHandlingService; private final JsonHandlingService jsonHandlingService;
private final ExternalUrlConfigProvider externalUrlConfigProvider; private final ExternalUrlConfigProvider externalUrlConfigProvider;
private final XmlHandlingService xmlHandlingService; private final XmlHandlingService xmlHandlingService;
@ -92,7 +73,6 @@ public class PrefillingServiceImpl implements PrefillingService {
QueryFactory queryFactory, QueryFactory queryFactory,
ConventionService conventionService, ConventionService conventionService,
MessageSource messageSource, MessageSource messageSource,
RemoteFetcherService remoteFetcherService,
JsonHandlingService jsonHandlingService, JsonHandlingService jsonHandlingService,
ExternalUrlConfigProvider externalUrlConfigProvider, ExternalUrlConfigProvider externalUrlConfigProvider,
XmlHandlingService xmlHandlingService, XmlHandlingService xmlHandlingService,
@ -102,7 +82,6 @@ public class PrefillingServiceImpl implements PrefillingService {
this.queryFactory = queryFactory; this.queryFactory = queryFactory;
this.conventionService = conventionService; this.conventionService = conventionService;
this.messageSource = messageSource; this.messageSource = messageSource;
this.remoteFetcherService = remoteFetcherService;
this.jsonHandlingService = jsonHandlingService; this.jsonHandlingService = jsonHandlingService;
this.externalUrlConfigProvider = externalUrlConfigProvider; this.externalUrlConfigProvider = externalUrlConfigProvider;
this.xmlHandlingService = xmlHandlingService; this.xmlHandlingService = xmlHandlingService;
@ -118,17 +97,17 @@ public class PrefillingServiceImpl implements PrefillingService {
List<PrefillingEntity> prefillings = new ArrayList<>(); List<PrefillingEntity> prefillings = new ArrayList<>();
List<Map<String, String>> map; List<Map<String, String>> map;
Map<String, PrefillingConfig> prefillingConfigs = this.externalUrlConfigProvider.getExternalUrls().getPrefillings(); Map<String, PrefillingConfig> prefillingConfigs = this.externalUrlConfigProvider.getExternalUrls().getPrefillings();
for (PrefillingConfig prefillingConfig: prefillingConfigs.values()) { // for (PrefillingConfig prefillingConfig: prefillingConfigs.values()) {//TODO new reference logic
map = remoteFetcherService.getExternalGeneric(externalReferenceCriteria, prefillingConfig.getPrefillingSearch()); // map = remoteFetcherService.getExternalGeneric(externalReferenceCriteria, prefillingConfig.getPrefillingSearch());
prefillings.addAll(map.stream().map(submap -> PrefillingEntity.build(submap, this.jsonHandlingService)).toList()); // prefillings.addAll(map.stream().map(submap -> PrefillingEntity.build(submap, this.jsonHandlingService)).toList());
if (prefillingConfig.getPrefillingSearch().getUrlConfig().isDataInListing()) { // if (prefillingConfig.getPrefillingSearch().getUrlConfig().isDataInListing()) {
List<Map<String, Object>> mapData = remoteFetcherService.getExternalGenericWithData(externalReferenceCriteria, prefillingConfig.getPrefillingSearch()); // List<Map<String, Object>> mapData = remoteFetcherService.getExternalGenericWithData(externalReferenceCriteria, prefillingConfig.getPrefillingSearch());
for (int i = 0; i < mapData.size(); i++) { // for (int i = 0; i < mapData.size(); i++) {
prefillings.get(i).setData(mapData.get(i)); // prefillings.get(i).setData(mapData.get(i));
} // }
prefillings = prefillings.stream().filter(prefilling -> prefilling.getData() != null).collect(Collectors.toList()); // prefillings = prefillings.stream().filter(prefilling -> prefilling.getData() != null).collect(Collectors.toList());
} // }
} // }
return this.builderFactory.builder(PrefillingBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).build(BaseFieldSet.build(lookup.getProject(), Prefilling._pid), prefillings); return this.builderFactory.builder(PrefillingBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).build(BaseFieldSet.build(lookup.getProject(), Prefilling._pid), prefillings);
} }
@ -381,49 +360,49 @@ public class PrefillingServiceImpl implements PrefillingService {
return parsedValues.isEmpty() ? null : String.join(", ", parsedValues); return parsedValues.isEmpty() ? null : String.join(", ", parsedValues);
} }
private Object parseComboBoxValues(FieldEntity fieldEntity, List<String> parsedValues) { // private Object parseComboBoxValues(FieldEntity fieldEntity, List<String> parsedValues) {
List<String> normalizedValues = new ArrayList<>(); // List<String> normalizedValues = new ArrayList<>();
boolean isMultiSelect; // boolean isMultiSelect;
if(fieldEntity.getData().getFieldType().equals(FieldType.EXTERNAL_SELECT)) { // if(fieldEntity.getData().getFieldType().equals(FieldType.EXTERNAL_SELECT)) {
ExternalSelectDataEntity autoCompleteData = (ExternalSelectDataEntity)fieldEntity.getData(); // ExternalSelectDataEntity autoCompleteData = (ExternalSelectDataEntity)fieldEntity.getData();
isMultiSelect = autoCompleteData.getMultipleSelect(); // isMultiSelect = autoCompleteData.getMultipleSelect();
for (String format : parsedValues) { // for (String format : parsedValues) {
List<ExternalAutocompleteFieldResult> result = new ArrayList<>(); // List<ExternalAutocompleteFieldResult> result = new ArrayList<>();
try { // try {
result = this.getAutocomplete(autoCompleteData, format); // result = this.getAutocomplete(autoCompleteData, format);
} // }
catch (Exception e) { // catch (Exception e) {
logger.error(e.getMessage(), e); // logger.error(e.getMessage(), e);
} // }
result = result.stream().filter(StreamDistinctBy.distinctByKey(ExternalAutocompleteFieldResult::getId)).collect(Collectors.toList()); // result = result.stream().filter(StreamDistinctBy.distinctByKey(ExternalAutocompleteFieldResult::getId)).collect(Collectors.toList());
if(!result.isEmpty()){ // if(!result.isEmpty()){
List<String> tempValues = new LinkedList<>(); // List<String> tempValues = new LinkedList<>();
for (ExternalAutocompleteFieldResult f : result) { // for (ExternalAutocompleteFieldResult f : result) {
if (format.equals(f.getId()) || f.getLabel().toUpperCase(Locale.ROOT).contains(format.toUpperCase(Locale.ROOT))) // if (format.equals(f.getId()) || f.getLabel().toUpperCase(Locale.ROOT).contains(format.toUpperCase(Locale.ROOT)))
tempValues.add(this.jsonHandlingService.toJsonSafe(f)); // tempValues.add(this.jsonHandlingService.toJsonSafe(f));
} // }
if (isMultiSelect) // if (isMultiSelect)
normalizedValues.addAll(tempValues); // normalizedValues.addAll(tempValues);
else if (!tempValues.isEmpty()) // else if (!tempValues.isEmpty())
normalizedValues.add(tempValues.get(0)); // normalizedValues.add(tempValues.get(0));
} // }
} // }
return !normalizedValues.isEmpty() ? (isMultiSelect ? normalizedValues : normalizedValues.getFirst()) : null; // return !normalizedValues.isEmpty() ? (isMultiSelect ? normalizedValues : normalizedValues.getFirst()) : null;
} else { // } else {
SelectDataEntity selectDataEntity = (SelectDataEntity)fieldEntity.getData(); // SelectDataEntity selectDataEntity = (SelectDataEntity)fieldEntity.getData();
isMultiSelect = selectDataEntity.getMultipleSelect(); // isMultiSelect = selectDataEntity.getMultipleSelect();
if (selectDataEntity.getOptions() != null) { // if (selectDataEntity.getOptions() != null) {
for (SelectDataEntity.OptionEntity option : selectDataEntity.getOptions()) { // for (SelectDataEntity.OptionEntity option : selectDataEntity.getOptions()) {
if (parsedValues.contains(option.getValue())) { // if (parsedValues.contains(option.getValue())) {
normalizedValues.add(option.getValue()); // normalizedValues.add(option.getValue());
} // }
} // }
} // }
List<String> normalizedStringValues = normalizedValues.stream().map(Object::toString).collect(Collectors.toList()); // List<String> normalizedStringValues = normalizedValues.stream().map(Object::toString).collect(Collectors.toList());
//
return !normalizedValues.isEmpty() ? (isMultiSelect ? String.join(", ", normalizedStringValues) : normalizedValues.getFirst()) : null; // return !normalizedValues.isEmpty() ? (isMultiSelect ? String.join(", ", normalizedStringValues) : normalizedValues.getFirst()) : null;
} // }
} // }
private static List<Tag> parseTags(String value) { private static List<Tag> parseTags(String value) {
if (value == null || value.isEmpty()) if (value == null || value.isEmpty())
@ -438,75 +417,75 @@ public class PrefillingServiceImpl implements PrefillingService {
return parsedTags; return parsedTags;
} }
public List<ExternalAutocompleteFieldResult> getAutocomplete(ExternalSelectDataEntity data, String like) throws URISyntaxException { // public List<ExternalAutocompleteFieldResult> getAutocomplete(ExternalSelectDataEntity data, String like) throws URISyntaxException {
//
List<ExternalAutocompleteFieldResult> result = new LinkedList<>(); // List<ExternalAutocompleteFieldResult> result = new LinkedList<>();
ExternalReferenceCriteria urlCriteria = new ExternalReferenceCriteria(); // ExternalReferenceCriteria urlCriteria = new ExternalReferenceCriteria();
GeneralUrls genericUrls = new GeneralUrls(); // GeneralUrls genericUrls = new GeneralUrls();
int ordinal = 1; // int ordinal = 1;
List<Map<String, String>> rawResults = new ArrayList<>(); // List<Map<String, String>> rawResults = new ArrayList<>();
genericUrls.setFetchMode(FetchStrategy.FIRST); // genericUrls.setFetchMode(FetchStrategy.FIRST);
urlCriteria.setLike(like); // urlCriteria.setLike(like);
for (ExternalSelectDataEntity.ExternalSelectSourceEntity singleData : data.getSources()) { // for (ExternalSelectDataEntity.ExternalSelectSourceEntity singleData : data.getSources()) {
UrlConfiguration urlConfiguration = new UrlConfiguration(); // UrlConfiguration urlConfiguration = new UrlConfiguration();
try { // try {
URI uri; // URI uri;
if (singleData.getUrl().contains("?")) { // if (singleData.getUrl().contains("?")) {
uri = new URI(singleData.getUrl().substring(0, singleData.getUrl().lastIndexOf("?"))); // uri = new URI(singleData.getUrl().substring(0, singleData.getUrl().lastIndexOf("?")));
} else { // } else {
uri = new URI(singleData.getUrl()); // uri = new URI(singleData.getUrl());
} // }
String source = singleData.getSourceBinding().getSource(); // String source = singleData.getSourceBinding().getSource();
source = source != null && !source.isEmpty() ? source : uri.getHost(); // source = source != null && !source.isEmpty() ? source : uri.getHost();
// String uriString = singleData.getSourceBinding().getUrl(); //// String uriString = singleData.getSourceBinding().getUrl();
// uriString = uriString != null && !uriString.isEmpty() ? uriString : "uri"; //// uriString = uriString != null && !uriString.isEmpty() ? uriString : "uri";
String uriString = "uri"; // String uriString = "uri";
String parsedUrl = singleData.getUrl(); // String parsedUrl = singleData.getUrl();
parsedUrl = parsedUrl.replace("%20", " "); // parsedUrl = parsedUrl.replace("%20", " ");
parsedUrl = parsedUrl.replace("%22", "\""); // parsedUrl = parsedUrl.replace("%22", "\"");
while (parsedUrl.contains("&amp;")) { // while (parsedUrl.contains("&amp;")) {
parsedUrl = parsedUrl.replace("&amp;", "&"); // parsedUrl = parsedUrl.replace("&amp;", "&");
} // }
urlConfiguration.setUrl(parsedUrl); // urlConfiguration.setUrl(parsedUrl);
urlConfiguration.setOrdinal(ordinal); // urlConfiguration.setOrdinal(ordinal);
urlConfiguration.setType("External"); // urlConfiguration.setType("External");
urlConfiguration.setContentType(MediaType.APPLICATION_JSON_VALUE); // urlConfiguration.setContentType(MediaType.APPLICATION_JSON_VALUE);
urlConfiguration.setFirstpage("1"); // urlConfiguration.setFirstpage("1");
urlConfiguration.setRequestType(singleData.getMethod() != null ? singleData.getMethod() : "GET"); // urlConfiguration.setRequestType(singleData.getMethod() != null ? singleData.getMethod() : "GET");
DataUrlConfiguration dataUrlConfiguration = new DataUrlConfiguration(); // DataUrlConfiguration dataUrlConfiguration = new DataUrlConfiguration();
dataUrlConfiguration.setPath(singleData.getOptionsRoot()); // dataUrlConfiguration.setPath(singleData.getOptionsRoot());
DataFieldsUrlConfiguration fieldsUrlConfiguration = new DataFieldsUrlConfiguration(); // DataFieldsUrlConfiguration fieldsUrlConfiguration = new DataFieldsUrlConfiguration();
fieldsUrlConfiguration.setId(singleData.getSourceBinding().getValue()); // fieldsUrlConfiguration.setId(singleData.getSourceBinding().getValue());
fieldsUrlConfiguration.setName(singleData.getSourceBinding().getLabel()); // fieldsUrlConfiguration.setName(singleData.getSourceBinding().getLabel());
fieldsUrlConfiguration.setSource(singleData.getSourceBinding().getSource().isEmpty()? null : singleData.getSourceBinding().getSource()); // fieldsUrlConfiguration.setSource(singleData.getSourceBinding().getSource().isEmpty()? null : singleData.getSourceBinding().getSource());
fieldsUrlConfiguration.setUri(uriString); // fieldsUrlConfiguration.setUri(uriString);
dataUrlConfiguration.setFieldsUrlConfiguration(fieldsUrlConfiguration); // dataUrlConfiguration.setFieldsUrlConfiguration(fieldsUrlConfiguration);
urlConfiguration.setKey(source); // urlConfiguration.setKey(source);
urlConfiguration.setLabel(source); // urlConfiguration.setLabel(source);
urlConfiguration.setData(dataUrlConfiguration); // urlConfiguration.setData(dataUrlConfiguration);
if (singleData.getHasAuth()) { // if (singleData.getHasAuth()) {
AuthenticationConfiguration authenticationConfiguration = new AuthenticationConfiguration(); // AuthenticationConfiguration authenticationConfiguration = new AuthenticationConfiguration();
authenticationConfiguration.setAuthUrl(singleData.getAuth().getUrl()); // authenticationConfiguration.setAuthUrl(singleData.getAuth().getUrl());
authenticationConfiguration.setAuthMethod(singleData.getAuth().getMethod()); // authenticationConfiguration.setAuthMethod(singleData.getAuth().getMethod());
authenticationConfiguration.setAuthTokenPath(singleData.getAuth().getPath()); // authenticationConfiguration.setAuthTokenPath(singleData.getAuth().getPath());
authenticationConfiguration.setAuthRequestBody(singleData.getAuth().getBody()); // authenticationConfiguration.setAuthRequestBody(singleData.getAuth().getBody());
authenticationConfiguration.setType(singleData.getAuth().getType()); // authenticationConfiguration.setType(singleData.getAuth().getType());
urlConfiguration.setAuth(authenticationConfiguration); // urlConfiguration.setAuth(authenticationConfiguration);
} // }
genericUrls.getUrls().add(urlConfiguration); // genericUrls.getUrls().add(urlConfiguration);
List<Map<String, String>> singleResults = this.remoteFetcherService.getExternalGeneric(urlCriteria, genericUrls); // List<Map<String, String>> singleResults = this.remoteFetcherService.getExternalGeneric(urlCriteria, genericUrls);
if (!singleResults.isEmpty() && !singleResults.get(0).containsKey("source") && !singleData.getSourceBinding().getSource().isEmpty()) { // if (!singleResults.isEmpty() && !singleResults.get(0).containsKey("source") && !singleData.getSourceBinding().getSource().isEmpty()) {
singleResults.forEach(singleResult -> singleResult.put("source", singleData.getSourceBinding().getSource())); // singleResults.forEach(singleResult -> singleResult.put("source", singleData.getSourceBinding().getSource()));
} // }
rawResults.addAll(singleResults); // rawResults.addAll(singleResults);
genericUrls.getUrls().clear(); // genericUrls.getUrls().clear();
} catch (URISyntaxException e) { // } catch (URISyntaxException e) {
logger.error(e.getMessage(), e); // logger.error(e.getMessage(), e);
} // }
} // }
rawResults.forEach(item -> result.add(new ExternalAutocompleteFieldResult(parseItem(item.get("pid")), parseItem(item.get("name")), parseItem(item.get("source")), parseItem(item.get("uri"))))); // rawResults.forEach(item -> result.add(new ExternalAutocompleteFieldResult(parseItem(item.get("pid")), parseItem(item.get("name")), parseItem(item.get("source")), parseItem(item.get("uri")))));
return result; // return result;
} // }
private static String parseItem(Object item) { private static String parseItem(Object item) {
if (item instanceof String) { if (item instanceof String) {

View File

@ -0,0 +1,10 @@
package eu.eudat.service.publicapi;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Configuration;
@Configuration
@EnableConfigurationProperties(PublicApiProperties.class)
public class PublicApiConfiguration {
}

View File

@ -0,0 +1,93 @@
package eu.eudat.service.publicapi;
import org.springframework.boot.context.properties.ConfigurationProperties;
import java.util.UUID;
@ConfigurationProperties(prefix = "public-api")
public class PublicApiProperties {
private ReferenceTypeMapConfig referenceTypeMap;
public ReferenceTypeMapConfig getReferenceTypeMap() {
return referenceTypeMap;
}
public void setReferenceTypeMap(ReferenceTypeMapConfig referenceTypeMap) {
this.referenceTypeMap = referenceTypeMap;
}
public static class ReferenceTypeMapConfig{
private UUID funderTypeId;
private UUID grantTypeId;
private UUID registryTypeId;
private UUID serviceTypeId;
private UUID dataRepositoryTypeId;
private UUID datasetTypeId;
private UUID researcherTypeId;
private UUID organizationTypeId;
public UUID getFunderTypeId() {
return funderTypeId;
}
public void setFunderTypeId(UUID funderTypeId) {
this.funderTypeId = funderTypeId;
}
public UUID getGrantTypeId() {
return grantTypeId;
}
public void setGrantTypeId(UUID grantTypeId) {
this.grantTypeId = grantTypeId;
}
public UUID getRegistryTypeId() {
return registryTypeId;
}
public void setRegistryTypeId(UUID registryTypeId) {
this.registryTypeId = registryTypeId;
}
public UUID getServiceTypeId() {
return serviceTypeId;
}
public void setServiceTypeId(UUID serviceTypeId) {
this.serviceTypeId = serviceTypeId;
}
public UUID getDataRepositoryTypeId() {
return dataRepositoryTypeId;
}
public void setDataRepositoryTypeId(UUID dataRepositoryTypeId) {
this.dataRepositoryTypeId = dataRepositoryTypeId;
}
public UUID getDatasetTypeId() {
return datasetTypeId;
}
public void setDatasetTypeId(UUID datasetTypeId) {
this.datasetTypeId = datasetTypeId;
}
public UUID getResearcherTypeId() {
return researcherTypeId;
}
public void setResearcherTypeId(UUID researcherTypeId) {
this.researcherTypeId = researcherTypeId;
}
public UUID getOrganizationTypeId() {
return organizationTypeId;
}
public void setOrganizationTypeId(UUID organizationTypeId) {
this.organizationTypeId = organizationTypeId;
}
}
}

View File

@ -24,7 +24,5 @@ public interface ReferenceService {
void deleteAndSave(UUID id) throws MyForbiddenException, InvalidApplicationException; void deleteAndSave(UUID id) throws MyForbiddenException, InvalidApplicationException;
List<Reference> searchReference(ReferenceSearchLookup lookup) throws HugeResultSetException, MyNotFoundException, InvalidApplicationException;
List<Reference> searchReferenceWithDefinition(ReferenceDefinitionSearchLookup lookup) throws HugeResultSetException, MyNotFoundException, InvalidApplicationException; List<Reference> searchReferenceWithDefinition(ReferenceDefinitionSearchLookup lookup) throws HugeResultSetException, MyNotFoundException, InvalidApplicationException;
} }

View File

@ -21,7 +21,6 @@ import eu.eudat.data.ReferenceEntity;
import eu.eudat.data.ReferenceTypeEntity; import eu.eudat.data.ReferenceTypeEntity;
import eu.eudat.model.Reference; import eu.eudat.model.Reference;
import eu.eudat.model.builder.ReferenceBuilder; import eu.eudat.model.builder.ReferenceBuilder;
import eu.eudat.model.builder.referencesearch.ReferenceSearchBuilder;
import eu.eudat.model.deleter.ReferenceDeleter; import eu.eudat.model.deleter.ReferenceDeleter;
import eu.eudat.model.persist.ReferencePersist; import eu.eudat.model.persist.ReferencePersist;
import eu.eudat.model.persist.referencedefinition.DefinitionPersist; import eu.eudat.model.persist.referencedefinition.DefinitionPersist;
@ -30,8 +29,6 @@ import eu.eudat.query.ReferenceQuery;
import eu.eudat.query.ReferenceTypeQuery; import eu.eudat.query.ReferenceTypeQuery;
import eu.eudat.query.lookup.ReferenceDefinitionSearchLookup; import eu.eudat.query.lookup.ReferenceDefinitionSearchLookup;
import eu.eudat.query.lookup.ReferenceSearchLookup; import eu.eudat.query.lookup.ReferenceSearchLookup;
import eu.eudat.service.remotefetcher.RemoteFetcherService;
import eu.eudat.service.remotefetcher.criteria.ExternalReferenceCriteria;
import eu.eudat.service.remotefetcher.criteria.FetchStrategy; import eu.eudat.service.remotefetcher.criteria.FetchStrategy;
import eu.eudat.service.remotefetcher.models.ExternalRefernceResult; import eu.eudat.service.remotefetcher.models.ExternalRefernceResult;
import gr.cite.commons.web.authz.service.AuthorizationService; import gr.cite.commons.web.authz.service.AuthorizationService;
@ -75,7 +72,6 @@ import java.util.stream.Collectors;
public class ReferenceServiceImpl implements ReferenceService { public class ReferenceServiceImpl implements ReferenceService {
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(ReferenceServiceImpl.class)); private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(ReferenceServiceImpl.class));
private final RemoteFetcherService remoteFetcherService;
private final EntityManager entityManager; private final EntityManager entityManager;
private final AuthorizationService authorizationService; private final AuthorizationService authorizationService;
private final DeleterFactory deleterFactory; private final DeleterFactory deleterFactory;
@ -87,7 +83,7 @@ public class ReferenceServiceImpl implements ReferenceService {
private final WebClient client; private final WebClient client;
public ReferenceServiceImpl(RemoteFetcherService remoteFetcherService, public ReferenceServiceImpl(
EntityManager entityManager, EntityManager entityManager,
AuthorizationService authorizationService, AuthorizationService authorizationService,
DeleterFactory deleterFactory, DeleterFactory deleterFactory,
@ -96,7 +92,6 @@ public class ReferenceServiceImpl implements ReferenceService {
MessageSource messageSource, MessageSource messageSource,
QueryFactory queryFactory, QueryFactory queryFactory,
XmlHandlingService xmlHandlingService) { XmlHandlingService xmlHandlingService) {
this.remoteFetcherService = remoteFetcherService;
this.entityManager = entityManager; this.entityManager = entityManager;
this.authorizationService = authorizationService; this.authorizationService = authorizationService;
this.deleterFactory = deleterFactory; this.deleterFactory = deleterFactory;
@ -133,7 +128,7 @@ public class ReferenceServiceImpl implements ReferenceService {
} }
data.setLabel(model.getLabel()); data.setLabel(model.getLabel());
data.setType(model.getType()); data.setTypeId(model.getTypeId());
data.setDescription(model.getDescription()); data.setDescription(model.getDescription());
data.setDefinition(this.xmlHandlingService.toXmlSafe(this.buildDefinitionEntity(model.getDefinition()))); data.setDefinition(this.xmlHandlingService.toXmlSafe(this.buildDefinitionEntity(model.getDefinition())));
data.setUpdatedAt(Instant.now()); data.setUpdatedAt(Instant.now());
@ -196,32 +191,32 @@ public class ReferenceServiceImpl implements ReferenceService {
// return list; // return list;
// } // }
@Override // @Override
public List<Reference> searchReference(ReferenceSearchLookup lookup) throws HugeResultSetException, MyNotFoundException, InvalidApplicationException { // public List<Reference> searchReference(ReferenceSearchLookup lookup) throws HugeResultSetException, MyNotFoundException, InvalidApplicationException {
int initialOffset = 0; // int initialOffset = 0;
if (lookup.getPage() != null && !lookup.getPage().isEmpty()){ // if (lookup.getPage() != null && !lookup.getPage().isEmpty()){
initialOffset = lookup.getPage().getOffset(); // initialOffset = lookup.getPage().getOffset();
lookup.getPage().setOffset(0); // lookup.getPage().setOffset(0);
} // }
//
ExternalReferenceCriteria externalReferenceCriteria = new ExternalReferenceCriteria(lookup.getLike()); // ExternalReferenceCriteria externalReferenceCriteria = new ExternalReferenceCriteria(lookup.getLike());
//
List<Map<String, String>> remoteRepos = remoteFetcherService.getReferences(lookup.getType(), externalReferenceCriteria, lookup.getKey()); // List<Map<String, String>> remoteRepos = remoteFetcherService.getReferences(lookup.getType(), externalReferenceCriteria, lookup.getKey());
//
List<Reference> externalModels = this.builderFactory.builder(ReferenceSearchBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).build(lookup.getProject(), remoteRepos); // List<Reference> externalModels = this.builderFactory.builder(ReferenceSearchBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).build(lookup.getProject(), remoteRepos);
List<Reference> models = this.fetchFromDb(lookup); // List<Reference> models = this.fetchFromDb(lookup);
//
models.addAll(externalModels); // models.addAll(externalModels);
//
if (!this.conventionService.isNullOrEmpty(lookup.getLike())) { models = models.stream().filter(x -> x.getLabel().toLowerCase().contains(lookup.getLike().toLowerCase())).collect(Collectors.toList()); } // if (!this.conventionService.isNullOrEmpty(lookup.getLike())) { models = models.stream().filter(x -> x.getLabel().toLowerCase().contains(lookup.getLike().toLowerCase())).collect(Collectors.toList()); }
models.sort(Comparator.comparing(Reference::getLabel)); // models.sort(Comparator.comparing(Reference::getLabel));
//
if (lookup.getPage() != null && !lookup.getPage().isEmpty()){ // if (lookup.getPage() != null && !lookup.getPage().isEmpty()){
models = models.stream().skip(initialOffset).limit(lookup.getPage().getSize()).toList(); // models = models.stream().skip(initialOffset).limit(lookup.getPage().getSize()).toList();
} // }
//
return models; // return models;
} // }
private List<Reference> fetchFromDb(ReferenceSearchLookup lookup){ private List<Reference> fetchFromDb(ReferenceSearchLookup lookup){
ReferenceQuery query = lookup.enrich(this.queryFactory).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).sourceTypes(ReferenceSourceType.Internal); ReferenceQuery query = lookup.enrich(this.queryFactory).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).sourceTypes(ReferenceSourceType.Internal);

View File

@ -1,22 +1,21 @@
package eu.eudat.service.remotefetcher; //package eu.eudat.service.remotefetcher;
//
import eu.eudat.commons.enums.ReferenceType; //import eu.eudat.commons.exceptions.HugeResultSetException;
import eu.eudat.commons.exceptions.HugeResultSetException; //import eu.eudat.service.remotefetcher.config.entities.GenericUrls;
import eu.eudat.service.remotefetcher.config.entities.GenericUrls; //import eu.eudat.service.remotefetcher.criteria.ExternalReferenceCriteria;
import eu.eudat.service.remotefetcher.criteria.ExternalReferenceCriteria; //import gr.cite.tools.exception.MyNotFoundException;
import gr.cite.tools.exception.MyNotFoundException; //
//import java.util.List;
import java.util.List; //import java.util.Map;
import java.util.Map; //
//public interface RemoteFetcherService {
public interface RemoteFetcherService { // List<Map<String, String>> getReferences(ReferenceType referenceType, ExternalReferenceCriteria externalReferenceCriteria, String key) throws MyNotFoundException, HugeResultSetException;
List<Map<String, String>> getReferences(ReferenceType referenceType, ExternalReferenceCriteria externalReferenceCriteria, String key) throws MyNotFoundException, HugeResultSetException; //
// GenericUrls getExternalUrls(ReferenceType referenceType);
GenericUrls getExternalUrls(ReferenceType referenceType); //
// Integer countEntries(ExternalReferenceCriteria externalReferenceCriteria, String key) throws MyNotFoundException, HugeResultSetException;
Integer countEntries(ExternalReferenceCriteria externalReferenceCriteria, String key) throws MyNotFoundException, HugeResultSetException; //
// List<Map<String, String>> getExternalGeneric(ExternalReferenceCriteria externalReferenceCriteria, GenericUrls genericUrls);
List<Map<String, String>> getExternalGeneric(ExternalReferenceCriteria externalReferenceCriteria, GenericUrls genericUrls); //
// List<Map<String, Object>> getExternalGenericWithData(ExternalReferenceCriteria externalReferenceCriteria, GenericUrls genericUrls);
List<Map<String, Object>> getExternalGenericWithData(ExternalReferenceCriteria externalReferenceCriteria, GenericUrls genericUrls); //}
}

View File

@ -1,152 +1,152 @@
package eu.eudat.service.remotefetcher; //package eu.eudat.service.remotefetcher;
//
import com.fasterxml.jackson.databind.ObjectMapper; //import com.fasterxml.jackson.databind.ObjectMapper;
import com.jayway.jsonpath.DocumentContext; //import com.jayway.jsonpath.DocumentContext;
import eu.eudat.service.remotefetcher.config.DataUrlConfiguration; //import eu.eudat.service.remotefetcher.config.DataUrlConfiguration;
import eu.eudat.service.remotefetcher.criteria.ExternalReferenceCriteria; //import eu.eudat.service.remotefetcher.criteria.ExternalReferenceCriteria;
import eu.eudat.service.remotefetcher.models.ExternalRefernceResult; //import eu.eudat.service.remotefetcher.models.ExternalRefernceResult;
import net.minidev.json.JSONArray; //import net.minidev.json.JSONArray;
import org.slf4j.Logger; //import org.slf4j.Logger;
import org.slf4j.LoggerFactory; //import org.slf4j.LoggerFactory;
//
import java.lang.reflect.InvocationTargetException; //import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method; //import java.lang.reflect.Method;
import java.util.*; //import java.util.*;
import java.util.stream.Collectors; //import java.util.stream.Collectors;
//
public class RemoteFetcherUtils { //public class RemoteFetcherUtils {
private final static Logger logger = LoggerFactory.getLogger(RemoteFetcherUtils.class); // private final static Logger logger = LoggerFactory.getLogger(RemoteFetcherUtils.class);
private static final ObjectMapper mapper = new ObjectMapper(); // private static final ObjectMapper mapper = new ObjectMapper();
//
public static ExternalRefernceResult getFromJson(DocumentContext jsonContext, DataUrlConfiguration jsonDataPath) { // public static ExternalRefernceResult getFromJson(DocumentContext jsonContext, DataUrlConfiguration jsonDataPath) {
return new ExternalRefernceResult(parseData(jsonContext, jsonDataPath), // return new ExternalRefernceResult(parseData(jsonContext, jsonDataPath),
new HashMap<>(1, 1)); // new HashMap<>(1, 1));
} // }
//
public static ExternalRefernceResult getFromJsonWithRecursiveFetching(DocumentContext jsonContext, DataUrlConfiguration jsonDataPath, RemoteFetcherServiceImpl remoteFetcherService, String requestBody, String requestType, String auth) { // public static ExternalRefernceResult getFromJsonWithRecursiveFetching(DocumentContext jsonContext, DataUrlConfiguration jsonDataPath, RemoteFetcherServiceImpl remoteFetcherService, String requestBody, String requestType, String auth) {
ExternalRefernceResult externalRefernceResult = new ExternalRefernceResult(parseData(jsonContext, jsonDataPath), // ExternalRefernceResult externalRefernceResult = new ExternalRefernceResult(parseData(jsonContext, jsonDataPath),
new HashMap<>(1, 1)); // new HashMap<>(1, 1));
//
List<Map<String, String>> multiResults = externalRefernceResult.getResults().stream().map(result -> { // List<Map<String, String>> multiResults = externalRefernceResult.getResults().stream().map(result -> {
ExternalReferenceCriteria externalReferenceCriteria = new ExternalReferenceCriteria(); // ExternalReferenceCriteria externalReferenceCriteria = new ExternalReferenceCriteria();
externalReferenceCriteria.setPath(result.get("path")); // externalReferenceCriteria.setPath(result.get("path"));
externalReferenceCriteria.setHost(result.get("host")); // externalReferenceCriteria.setHost(result.get("host"));
String replacedPath = remoteFetcherService.replaceCriteriaOnUrl(jsonDataPath.getUrlConfiguration().getUrl(), externalReferenceCriteria, jsonDataPath.getUrlConfiguration().getFirstpage(), jsonDataPath.getUrlConfiguration().getQueries()); // String replacedPath = remoteFetcherService.replaceCriteriaOnUrl(jsonDataPath.getUrlConfiguration().getUrl(), externalReferenceCriteria, jsonDataPath.getUrlConfiguration().getFirstpage(), jsonDataPath.getUrlConfiguration().getQueries());
return remoteFetcherService.getResultsFromUrl(replacedPath, jsonDataPath.getUrlConfiguration().getData(), jsonDataPath.getUrlConfiguration().getData().getPath(), jsonDataPath.getUrlConfiguration().getContentType(), requestBody, requestType, auth); // return remoteFetcherService.getResultsFromUrl(replacedPath, jsonDataPath.getUrlConfiguration().getData(), jsonDataPath.getUrlConfiguration().getData().getPath(), jsonDataPath.getUrlConfiguration().getContentType(), requestBody, requestType, auth);
}).filter(Objects::nonNull).map(externalRefernceResult1 -> externalRefernceResult1.getResults().get(0)).collect(Collectors.toList()); // }).filter(Objects::nonNull).map(externalRefernceResult1 -> externalRefernceResult1.getResults().get(0)).collect(Collectors.toList());
return new ExternalRefernceResult(multiResults, new HashMap<>(1, 1)); // return new ExternalRefernceResult(multiResults, new HashMap<>(1, 1));
} // }
//
public static ExternalRefernceResult getFromJsonWithFirstAndLastName(DocumentContext jsonContext, DataUrlConfiguration jsonDataPath) { // public static ExternalRefernceResult getFromJsonWithFirstAndLastName(DocumentContext jsonContext, DataUrlConfiguration jsonDataPath) {
ExternalRefernceResult externalRefernceResult = new ExternalRefernceResult(parseData(jsonContext, jsonDataPath), // ExternalRefernceResult externalRefernceResult = new ExternalRefernceResult(parseData(jsonContext, jsonDataPath),
new HashMap<>(1, 1)); // new HashMap<>(1, 1));
externalRefernceResult.getResults().stream().forEach(entry -> { // externalRefernceResult.getResults().stream().forEach(entry -> {
String name = entry.get(jsonDataPath.getFieldsUrlConfiguration().getFirstName().replace("'", "")) + " " + entry.get(jsonDataPath.getFieldsUrlConfiguration().getLastName().replace("'", "")); // String name = entry.get(jsonDataPath.getFieldsUrlConfiguration().getFirstName().replace("'", "")) + " " + entry.get(jsonDataPath.getFieldsUrlConfiguration().getLastName().replace("'", ""));
entry.put("name", name); // entry.put("name", name);
entry.remove(jsonDataPath.getFieldsUrlConfiguration().getFirstName().replace("'", "")); // entry.remove(jsonDataPath.getFieldsUrlConfiguration().getFirstName().replace("'", ""));
entry.remove(jsonDataPath.getFieldsUrlConfiguration().getLastName().replace("'", "")); // entry.remove(jsonDataPath.getFieldsUrlConfiguration().getLastName().replace("'", ""));
}); // });
return externalRefernceResult; // return externalRefernceResult;
} // }
//
private static List<Map<String, String>> parseData (DocumentContext jsonContext, DataUrlConfiguration jsonDataPath) { // private static List<Map<String, String>> parseData (DocumentContext jsonContext, DataUrlConfiguration jsonDataPath) {
List <Map<String, Object>> rawData = jsonContext.read(jsonDataPath.getPath()); // List <Map<String, Object>> rawData = jsonContext.read(jsonDataPath.getPath());
List<Map<String, String>> parsedData = new ArrayList<>(); // List<Map<String, String>> parsedData = new ArrayList<>();
rawData.forEach(stringObjectMap -> { // rawData.forEach(stringObjectMap -> {
parsedData.add(new LinkedHashMap<>()); // parsedData.add(new LinkedHashMap<>());
Arrays.stream(jsonDataPath.getFieldsUrlConfiguration().getClass().getDeclaredFields()).forEach(field -> { // Arrays.stream(jsonDataPath.getFieldsUrlConfiguration().getClass().getDeclaredFields()).forEach(field -> {
String getterMethodName = "get" + field.getName().substring(0, 1).toUpperCase(Locale.ROOT) + field.getName().substring(1); // String getterMethodName = "get" + field.getName().substring(0, 1).toUpperCase(Locale.ROOT) + field.getName().substring(1);
Method getterMethod = Arrays.stream(jsonDataPath.getFieldsUrlConfiguration().getClass().getDeclaredMethods()).filter(method -> method.getName().equals(getterMethodName)).collect(Collectors.toList()).get(0); // Method getterMethod = Arrays.stream(jsonDataPath.getFieldsUrlConfiguration().getClass().getDeclaredMethods()).filter(method -> method.getName().equals(getterMethodName)).collect(Collectors.toList()).get(0);
try { // try {
String value = ((String) getterMethod.invoke(jsonDataPath.getFieldsUrlConfiguration())); // String value = ((String) getterMethod.invoke(jsonDataPath.getFieldsUrlConfiguration()));
if (value != null) { // if (value != null) {
if (field.getName().equals("pid") || field.getName().equals("pidTypeField")) { // if (field.getName().equals("pid") || field.getName().equals("pidTypeField")) {
String pid = null; // String pid = null;
Object pidObj = stringObjectMap.get(value.split("\\.")[0]); // Object pidObj = stringObjectMap.get(value.split("\\.")[0]);
if(pidObj != null){ // if(pidObj != null){
if(pidObj instanceof Map){ // if(pidObj instanceof Map){
Object o = ((Map<String, Object>) pidObj).get(value.split("\\.")[1]); // Object o = ((Map<String, Object>) pidObj).get(value.split("\\.")[1]);
if(o instanceof String){ // if(o instanceof String){
pid = (String)o; // pid = (String)o;
} // }
else if(o instanceof Integer){ // else if(o instanceof Integer){
pid = String.valueOf(o); // pid = String.valueOf(o);
} // }
} // }
else if(pidObj instanceof List){ // else if(pidObj instanceof List){
Object o = ((List<Map<String,?>>) pidObj).get(0).get(value.split("\\.")[1]); // Object o = ((List<Map<String,?>>) pidObj).get(0).get(value.split("\\.")[1]);
if(o instanceof String){ // if(o instanceof String){
pid = (String)o; // pid = (String)o;
} // }
else if(o instanceof Integer){ // else if(o instanceof Integer){
pid = String.valueOf(o); // pid = String.valueOf(o);
} // }
} // }
} // }
if(pid != null) { // if(pid != null) {
if ((field.getName().equals("pid"))){ // if ((field.getName().equals("pid"))){
parsedData.get(parsedData.size() - 1).put("pid", pid); // parsedData.get(parsedData.size() - 1).put("pid", pid);
} // }
else{ // else{
parsedData.get(parsedData.size() - 1).put("pidTypeField", pid); // parsedData.get(parsedData.size() - 1).put("pidTypeField", pid);
} // }
} // }
} else { // } else {
value = value.replace("'", ""); // value = value.replace("'", "");
if (value.contains(".")) { // if (value.contains(".")) {
String[] parts = value.split("\\."); // String[] parts = value.split("\\.");
Map<String, Object> tempMap = stringObjectMap; // Map<String, Object> tempMap = stringObjectMap;
for (int i = 0; i < parts.length; i++) { // for (int i = 0; i < parts.length; i++) {
if (tempMap.containsKey(parts[i])) { // if (tempMap.containsKey(parts[i])) {
if (i + 1 < parts.length) { // if (i + 1 < parts.length) {
tempMap = (Map<String, Object>) tempMap.get(parts[i]); // tempMap = (Map<String, Object>) tempMap.get(parts[i]);
} else { // } else {
parsedData.get(parsedData.size() - 1).put(field.getName().equals("types") ? "tags" : value, normalizeValue(tempMap.get(parts[i]), (field.getName().equals("types") || field.getName().equals("uri")))); // parsedData.get(parsedData.size() - 1).put(field.getName().equals("types") ? "tags" : value, normalizeValue(tempMap.get(parts[i]), (field.getName().equals("types") || field.getName().equals("uri"))));
} // }
} // }
} // }
} else { // } else {
if (stringObjectMap.containsKey(value)) { // if (stringObjectMap.containsKey(value)) {
parsedData.get(parsedData.size() - 1).put(field.getName().equals("types") ? "tags" : value, normalizeValue(stringObjectMap.get(value), (field.getName().equals("types") || field.getName().equals("uri")))); // parsedData.get(parsedData.size() - 1).put(field.getName().equals("types") ? "tags" : value, normalizeValue(stringObjectMap.get(value), (field.getName().equals("types") || field.getName().equals("uri"))));
} // }
} // }
} // }
} // }
} catch (IllegalAccessException | InvocationTargetException e) { // } catch (IllegalAccessException | InvocationTargetException e) {
logger.error(e.getLocalizedMessage(), e); // logger.error(e.getLocalizedMessage(), e);
} // }
}); // });
}); // });
return parsedData; // return parsedData;
} // }
//
private static String normalizeValue(Object value, boolean jsonString) { // private static String normalizeValue(Object value, boolean jsonString) {
if (value instanceof JSONArray) { // if (value instanceof JSONArray) {
if (jsonString) { // if (jsonString) {
return ((JSONArray)value).toJSONString(); // return ((JSONArray)value).toJSONString();
} // }
JSONArray jarr = (JSONArray) value; // JSONArray jarr = (JSONArray) value;
if (jarr.get(0) instanceof String) { // if (jarr.get(0) instanceof String) {
return jarr.get(0).toString(); // return jarr.get(0).toString();
} else { // } else {
for (Object o : jarr) { // for (Object o : jarr) {
if ((o instanceof Map) && ((Map) o).containsKey("content")) { // if ((o instanceof Map) && ((Map) o).containsKey("content")) {
try { // try {
return ((Map<String, String>) o).get("content"); // return ((Map<String, String>) o).get("content");
} // }
catch (ClassCastException e){ // catch (ClassCastException e){
if(((Map<?, ?>) o).get("content") instanceof Integer) { // if(((Map<?, ?>) o).get("content") instanceof Integer) {
return String.valueOf(((Map<?, ?>) o).get("content")); // return String.valueOf(((Map<?, ?>) o).get("content"));
} // }
return null; // return null;
} // }
} // }
} // }
} // }
} else if (value instanceof Map) { // } else if (value instanceof Map) {
String key = ((Map<String, String>)value).containsKey("$") ? "$" : "content"; // String key = ((Map<String, String>)value).containsKey("$") ? "$" : "content";
return ((Map<String, String>)value).get(key); // return ((Map<String, String>)value).get(key);
} // }
return value != null ? value.toString() : null; // return value != null ? value.toString() : null;
} // }
} //}

View File

@ -20,6 +20,7 @@ import eu.eudat.query.DescriptionQuery;
import eu.eudat.query.DmpQuery; import eu.eudat.query.DmpQuery;
import eu.eudat.query.lookup.DescriptionLookup; import eu.eudat.query.lookup.DescriptionLookup;
import eu.eudat.query.lookup.DmpLookup; import eu.eudat.query.lookup.DmpLookup;
import eu.eudat.service.publicapi.PublicApiProperties;
import eu.eudat.types.ApiMessageCode; import eu.eudat.types.ApiMessageCode;
import gr.cite.tools.data.builder.BuilderFactory; import gr.cite.tools.data.builder.BuilderFactory;
import gr.cite.tools.data.query.QueryFactory; import gr.cite.tools.data.query.QueryFactory;
@ -67,6 +68,8 @@ public class PublicDatasetsDescriptionDocumentation {
private final DescriptionToPublicApiDatasetListingMapper descriptionToPublicApiDatasetListingMapper; private final DescriptionToPublicApiDatasetListingMapper descriptionToPublicApiDatasetListingMapper;
private final PublicApiProperties config;
private final DmpToPublicApiDmpListingMapper dmpToPublicApiDmpListingMapper; private final DmpToPublicApiDmpListingMapper dmpToPublicApiDmpListingMapper;
@Autowired @Autowired
@ -75,12 +78,13 @@ public class PublicDatasetsDescriptionDocumentation {
BuilderFactory builderFactory, BuilderFactory builderFactory,
MessageSource messageSource, MessageSource messageSource,
DescriptionToPublicApiDatasetMapper descriptionToPublicApiDatasetMapper, DescriptionToPublicApiDatasetMapper descriptionToPublicApiDatasetMapper,
DescriptionToPublicApiDatasetListingMapper descriptionToPublicApiDatasetListingMapper, DmpToPublicApiDmpListingMapper dmpToPublicApiDmpListingMapper) { DescriptionToPublicApiDatasetListingMapper descriptionToPublicApiDatasetListingMapper, PublicApiProperties config, DmpToPublicApiDmpListingMapper dmpToPublicApiDmpListingMapper) {
this.queryFactory = queryFactory; this.queryFactory = queryFactory;
this.builderFactory = builderFactory; this.builderFactory = builderFactory;
this.messageSource = messageSource; this.messageSource = messageSource;
this.descriptionToPublicApiDatasetMapper = descriptionToPublicApiDatasetMapper; this.descriptionToPublicApiDatasetMapper = descriptionToPublicApiDatasetMapper;
this.descriptionToPublicApiDatasetListingMapper = descriptionToPublicApiDatasetListingMapper; this.descriptionToPublicApiDatasetListingMapper = descriptionToPublicApiDatasetListingMapper;
this.config = config;
this.dmpToPublicApiDmpListingMapper = dmpToPublicApiDmpListingMapper; this.dmpToPublicApiDmpListingMapper = dmpToPublicApiDmpListingMapper;
} }
@ -103,7 +107,7 @@ public class PublicDatasetsDescriptionDocumentation {
List<DescriptionEntity> data = query.collectAs(lookup.getProject()); List<DescriptionEntity> data = query.collectAs(lookup.getProject());
List<Description> models = this.builderFactory.builder(DescriptionBuilder.class).build(lookup.getProject(), data); List<Description> models = this.builderFactory.builder(DescriptionBuilder.class).build(lookup.getProject(), data);
DataTableData<DatasetPublicListingModel> dataTableData = new DataTableData<>(); DataTableData<DatasetPublicListingModel> dataTableData = new DataTableData<>();
dataTableData.setData(models.stream().map(this.descriptionToPublicApiDatasetListingMapper::toPublicListingModel).toList()); dataTableData.setData(models.stream().map(x-> this.descriptionToPublicApiDatasetListingMapper.toPublicListingModel(x, this.config.getReferenceTypeMap())).toList());
dataTableData.setTotalCount(count); dataTableData.setTotalCount(count);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DataTableData<DatasetPublicListingModel>>().status(ApiMessageCode.NO_MESSAGE).payload(dataTableData)); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DataTableData<DatasetPublicListingModel>>().status(ApiMessageCode.NO_MESSAGE).payload(dataTableData));
} }
@ -130,7 +134,7 @@ public class PublicDatasetsDescriptionDocumentation {
DmpLookup dmpLookup = getDmpLookup(); DmpLookup dmpLookup = getDmpLookup();
Dmp dmp = this.builderFactory.builder(DmpBuilder.class).build(dmpLookup.getProject(), dmpQuery.firstAs(dmpLookup.getProject())); Dmp dmp = this.builderFactory.builder(DmpBuilder.class).build(dmpLookup.getProject(), dmpQuery.firstAs(dmpLookup.getProject()));
DatasetPublicModel dataset = this.descriptionToPublicApiDatasetMapper.toPublicModel(model, this.dmpToPublicApiDmpListingMapper.toPublicListingModel(dmp)); DatasetPublicModel dataset = this.descriptionToPublicApiDatasetMapper.toPublicModel(model, this.dmpToPublicApiDmpListingMapper.toPublicListingModel(dmp, this.config.getReferenceTypeMap()), this.config.getReferenceTypeMap());
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DatasetPublicModel>().status(ApiMessageCode.NO_MESSAGE).payload(dataset)); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DatasetPublicModel>().status(ApiMessageCode.NO_MESSAGE).payload(dataset));
} }
@ -148,6 +152,7 @@ public class PublicDatasetsDescriptionDocumentation {
String.join(".", Description._createdBy, User._name), String.join(".", Description._createdBy, User._name),
String.join(".", Description._descriptionReferences, DescriptionReference._reference, Reference._id), String.join(".", Description._descriptionReferences, DescriptionReference._reference, Reference._id),
String.join(".", Description._descriptionReferences, DescriptionReference._reference, Reference._type), String.join(".", Description._descriptionReferences, DescriptionReference._reference, Reference._type),
String.join(".", Description._descriptionReferences, DescriptionReference._reference, Reference._type, Reference._id),
String.join(".", Description._descriptionReferences, DescriptionReference._reference, Reference._reference), String.join(".", Description._descriptionReferences, DescriptionReference._reference, Reference._reference),
String.join(".", Description._descriptionReferences, DescriptionReference._reference, Reference._label), String.join(".", Description._descriptionReferences, DescriptionReference._reference, Reference._label),
String.join(".", Description._descriptionReferences, DescriptionReference._reference, Reference._abbreviation), String.join(".", Description._descriptionReferences, DescriptionReference._reference, Reference._abbreviation),

View File

@ -20,6 +20,7 @@ import eu.eudat.query.DmpDescriptionTemplateQuery;
import eu.eudat.query.DmpQuery; import eu.eudat.query.DmpQuery;
import eu.eudat.query.EntityDoiQuery; import eu.eudat.query.EntityDoiQuery;
import eu.eudat.query.lookup.DmpLookup; import eu.eudat.query.lookup.DmpLookup;
import eu.eudat.service.publicapi.PublicApiProperties;
import eu.eudat.types.ApiMessageCode; import eu.eudat.types.ApiMessageCode;
import gr.cite.tools.data.builder.BuilderFactory; import gr.cite.tools.data.builder.BuilderFactory;
import gr.cite.tools.data.query.QueryFactory; import gr.cite.tools.data.query.QueryFactory;
@ -65,6 +66,7 @@ public class PublicDmpsDocumentation {
private final DmpToPublicApiDmpMapper dmpToPublicApiDmpMapper; private final DmpToPublicApiDmpMapper dmpToPublicApiDmpMapper;
private final PublicApiProperties config;
private final DmpToPublicApiDmpListingMapper dmpToPublicApiDmpListingMapper; private final DmpToPublicApiDmpListingMapper dmpToPublicApiDmpListingMapper;
@Autowired @Autowired
@ -72,12 +74,13 @@ public class PublicDmpsDocumentation {
QueryFactory queryFactory, QueryFactory queryFactory,
BuilderFactory builderFactory, BuilderFactory builderFactory,
MessageSource messageSource, MessageSource messageSource,
DmpToPublicApiDmpMapper dmpToPublicApiDmpMapper, DmpToPublicApiDmpMapper dmpToPublicApiDmpMapper, PublicApiProperties config,
DmpToPublicApiDmpListingMapper dmpToPublicApiDmpListingMapper) { DmpToPublicApiDmpListingMapper dmpToPublicApiDmpListingMapper) {
this.queryFactory = queryFactory; this.queryFactory = queryFactory;
this.builderFactory = builderFactory; this.builderFactory = builderFactory;
this.messageSource = messageSource; this.messageSource = messageSource;
this.dmpToPublicApiDmpMapper = dmpToPublicApiDmpMapper; this.dmpToPublicApiDmpMapper = dmpToPublicApiDmpMapper;
this.config = config;
this.dmpToPublicApiDmpListingMapper = dmpToPublicApiDmpListingMapper; this.dmpToPublicApiDmpListingMapper = dmpToPublicApiDmpListingMapper;
} }
@ -104,7 +107,7 @@ public class PublicDmpsDocumentation {
List<DmpEntity> data = query.collectAs(lookup.getProject()); List<DmpEntity> data = query.collectAs(lookup.getProject());
List<Dmp> models = this.builderFactory.builder(DmpBuilder.class).build(lookup.getProject(), data); List<Dmp> models = this.builderFactory.builder(DmpBuilder.class).build(lookup.getProject(), data);
DataTableData<DataManagementPlanPublicListingModel> dataTableData = new DataTableData<>(); DataTableData<DataManagementPlanPublicListingModel> dataTableData = new DataTableData<>();
dataTableData.setData(models.stream().map(this.dmpToPublicApiDmpListingMapper::toPublicListingModel).toList()); dataTableData.setData(models.stream().map(x-> this.dmpToPublicApiDmpListingMapper.toPublicListingModel(x, this.config.getReferenceTypeMap())).toList());
dataTableData.setTotalCount(count); dataTableData.setTotalCount(count);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DataTableData<DataManagementPlanPublicListingModel>>().status(ApiMessageCode.NO_MESSAGE).payload(dataTableData)); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DataTableData<DataManagementPlanPublicListingModel>>().status(ApiMessageCode.NO_MESSAGE).payload(dataTableData));
} }
@ -125,7 +128,8 @@ public class PublicDmpsDocumentation {
String.join(".", Dmp._dmpUsers, DmpUser._role), String.join(".", Dmp._dmpUsers, DmpUser._role),
String.join(".", Dmp._dmpReferences, DmpReference._reference, Reference._id), String.join(".", Dmp._dmpReferences, DmpReference._reference, Reference._id),
String.join(".", Dmp._dmpReferences, DmpReference._reference, Reference._type), String.join(".", Dmp._dmpReferences, DmpReference._reference, Reference._type),
String.join(".", Dmp._dmpReferences, DmpReference._reference, Reference._reference), String.join(".", Dmp._dmpReferences, DmpReference._reference, Reference._type),
String.join(".", Dmp._dmpReferences, DmpReference._reference, Reference._type, ReferenceType._id),
String.join(".", Dmp._dmpReferences, DmpReference._reference, Reference._label), String.join(".", Dmp._dmpReferences, DmpReference._reference, Reference._label),
String.join(".", Dmp._dmpReferences, DmpReference._reference, Reference._definition, Definition._fields, Field._code), String.join(".", Dmp._dmpReferences, DmpReference._reference, Reference._definition, Definition._fields, Field._code),
String.join(".", Dmp._dmpReferences, DmpReference._reference, Reference._definition, Definition._fields, Field._dataType), String.join(".", Dmp._dmpReferences, DmpReference._reference, Reference._definition, Definition._fields, Field._dataType),
@ -173,6 +177,7 @@ public class PublicDmpsDocumentation {
String.join(".", Dmp._dmpUsers, DmpUser._role), String.join(".", Dmp._dmpUsers, DmpUser._role),
String.join(".", Dmp._dmpReferences, DmpReference._reference, Reference._id), String.join(".", Dmp._dmpReferences, DmpReference._reference, Reference._id),
String.join(".", Dmp._dmpReferences, DmpReference._reference, Reference._type), String.join(".", Dmp._dmpReferences, DmpReference._reference, Reference._type),
String.join(".", Dmp._dmpReferences, DmpReference._reference, Reference._type, ReferenceType._id),
String.join(".", Dmp._dmpReferences, DmpReference._reference, Reference._reference), String.join(".", Dmp._dmpReferences, DmpReference._reference, Reference._reference),
String.join(".", Dmp._dmpReferences, DmpReference._reference, Reference._label), String.join(".", Dmp._dmpReferences, DmpReference._reference, Reference._label),
String.join(".", Dmp._dmpReferences, DmpReference._reference, Reference._abbreviation), String.join(".", Dmp._dmpReferences, DmpReference._reference, Reference._abbreviation),
@ -193,7 +198,7 @@ public class PublicDmpsDocumentation {
BaseFieldSet templateFieldSet = new BaseFieldSet(); BaseFieldSet templateFieldSet = new BaseFieldSet();
DmpDescriptionTemplateQuery dmpDescriptionTemplateQuery = this.queryFactory.query(DmpDescriptionTemplateQuery.class).dmpIds(UUID.fromString(id)).isActive(IsActive.Active); DmpDescriptionTemplateQuery dmpDescriptionTemplateQuery = this.queryFactory.query(DmpDescriptionTemplateQuery.class).dmpIds(UUID.fromString(id)).isActive(IsActive.Active);
List<DmpDescriptionTemplate> descriptionTemplates = this.builderFactory.builder(DmpDescriptionTemplateBuilder.class).build(templateFieldSet, dmpDescriptionTemplateQuery.collectAs(templateFieldSet)); List<DmpDescriptionTemplate> descriptionTemplates = this.builderFactory.builder(DmpDescriptionTemplateBuilder.class).build(templateFieldSet, dmpDescriptionTemplateQuery.collectAs(templateFieldSet));
DataManagementPlanPublicModel dataManagementPlan = this.dmpToPublicApiDmpMapper.toPublicModel(model, entityDoiQuery.collect(), descriptionTemplates); DataManagementPlanPublicModel dataManagementPlan = this.dmpToPublicApiDmpMapper.toPublicModel(model, entityDoiQuery.collect(), descriptionTemplates, this.config.getReferenceTypeMap());
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DataManagementPlanPublicModel>().status(ApiMessageCode.NO_MESSAGE).payload(dataManagementPlan)); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DataManagementPlanPublicModel>().status(ApiMessageCode.NO_MESSAGE).payload(dataManagementPlan));
} }

View File

@ -93,19 +93,8 @@ public class ReferenceController {
return new QueryResult<>(models, count); return new QueryResult<>(models, count);
} }
@PostMapping("search") @PostMapping("search")
public List<Reference> searchReference(@RequestBody ReferenceSearchLookup lookup) throws HugeResultSetException, MyNotFoundException, InvalidApplicationException {
logger.debug("search {}", Reference.class.getSimpleName());
this.censorFactory.censor(ReferenceCensor.class).censor(lookup.getProject(), null);
List<Reference> references = this.referenceService.searchReference(lookup);
this.auditService.track(AuditableAction.Reference_Search, "lookup", lookup);
return references;
}
@PostMapping("search-with-db-definition")
public List<Reference> searchReferenceWithDefinition(@RequestBody ReferenceDefinitionSearchLookup lookup) throws HugeResultSetException, MyNotFoundException, InvalidApplicationException { public List<Reference> searchReferenceWithDefinition(@RequestBody ReferenceDefinitionSearchLookup lookup) throws HugeResultSetException, MyNotFoundException, InvalidApplicationException {
logger.debug("search with db definition {}", Reference.class.getSimpleName()); logger.debug("search with db definition {}", Reference.class.getSimpleName());

View File

@ -1,7 +1,6 @@
package eu.eudat.logic.managers; package eu.eudat.logic.managers;
import eu.eudat.logic.proxy.config.configloaders.ConfigLoader; import eu.eudat.logic.proxy.config.configloaders.ConfigLoader;
import eu.eudat.service.remotefetcher.RemoteFetcherService;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -20,12 +19,11 @@ public class DatasetProfileManager {
private static final List<String> cache = new ArrayList<>(); private static final List<String> cache = new ArrayList<>();
private final ConfigLoader configLoader; private final ConfigLoader configLoader;
private final RemoteFetcherService remoteFetcherService; // private final RemoteFetcherService remoteFetcherService;
@Autowired @Autowired
public DatasetProfileManager(ConfigLoader configLoader, RemoteFetcherService remoteFetcherService) { public DatasetProfileManager(ConfigLoader configLoader) {
this.configLoader = configLoader; this.configLoader = configLoader;
this.remoteFetcherService = remoteFetcherService;
} }
private static String parseItem(Object item) { private static String parseItem(Object item) {
if (item instanceof String) { if (item instanceof String) {

View File

@ -7,24 +7,25 @@ import org.springframework.stereotype.Component;
import eu.eudat.service.remotefetcher.criteria.ExternalReferenceCriteria; import eu.eudat.service.remotefetcher.criteria.ExternalReferenceCriteria;
import eu.eudat.commons.exceptions.HugeResultSetException; import eu.eudat.commons.exceptions.HugeResultSetException;
import eu.eudat.service.remotefetcher.RemoteFetcherService; //import eu.eudat.service.remotefetcher.RemoteFetcherService;
@Component @Component
public class ValidationManager { public class ValidationManager {
private RemoteFetcherService remoteFetcherService; // private RemoteFetcherService remoteFetcherService;
private final UserScope userScope; private final UserScope userScope;
@Autowired @Autowired
public ValidationManager(RemoteFetcherService remoteFetcherService, UserScope userScope) { public ValidationManager(UserScope userScope) {
super(); super();
this.remoteFetcherService = remoteFetcherService; // this.remoteFetcherService = remoteFetcherService;
this.userScope = userScope; this.userScope = userScope;
} }
public Boolean validateIdentifier(String identifier, String type) throws MyNotFoundException, HugeResultSetException { public Boolean validateIdentifier(String identifier, String type) throws MyNotFoundException, HugeResultSetException {
ExternalReferenceCriteria externalReferenceCriteria = new ExternalReferenceCriteria(identifier); ExternalReferenceCriteria externalReferenceCriteria = new ExternalReferenceCriteria(identifier);
Integer count = this.remoteFetcherService.countEntries(externalReferenceCriteria, type); // Integer count = this.remoteFetcherService.countEntries(externalReferenceCriteria, type);
Integer count = 1;
return this.userScope.isSet() && count > 0; return this.userScope.isSet() && count > 0;
} }

View File

@ -3,7 +3,7 @@ package eu.eudat.logic.services;
import eu.eudat.commons.scope.user.UserScope; import eu.eudat.commons.scope.user.UserScope;
import eu.eudat.service.remotefetcher.criteria.ExternalReferenceCriteria; import eu.eudat.service.remotefetcher.criteria.ExternalReferenceCriteria;
import eu.eudat.commons.exceptions.HugeResultSetException; import eu.eudat.commons.exceptions.HugeResultSetException;
import eu.eudat.service.remotefetcher.RemoteFetcherService; //import eu.eudat.service.remotefetcher.RemoteFetcherService;
import gr.cite.tools.exception.MyNotFoundException; import gr.cite.tools.exception.MyNotFoundException;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -11,19 +11,20 @@ import org.springframework.stereotype.Service;
@Service @Service
public class ExternalValidationService { public class ExternalValidationService {
private RemoteFetcherService remoteFetcherService; // private RemoteFetcherService remoteFetcherService;
private final UserScope userScope; private final UserScope userScope;
@Autowired @Autowired
public ExternalValidationService(RemoteFetcherService remoteFetcherService, UserScope userScope) { public ExternalValidationService(UserScope userScope) {
super(); super();
this.remoteFetcherService = remoteFetcherService; // this.remoteFetcherService = remoteFetcherService;
this.userScope = userScope; this.userScope = userScope;
} }
public Boolean validateIdentifier(String identifier, String type) throws MyNotFoundException, HugeResultSetException { public Boolean validateIdentifier(String identifier, String type) throws MyNotFoundException, HugeResultSetException {
ExternalReferenceCriteria externalReferenceCriteria = new ExternalReferenceCriteria(identifier); ExternalReferenceCriteria externalReferenceCriteria = new ExternalReferenceCriteria(identifier);
Integer count = this.remoteFetcherService.countEntries(externalReferenceCriteria, type); // Integer count = this.remoteFetcherService.countEntries(externalReferenceCriteria, type);
Integer count = 1;
return userScope.isSet() && count > 0; return userScope.isSet() && count > 0;
} }

View File

@ -29,5 +29,7 @@ spring:
optional:classpath:config/queue.yml[.yml], optional:classpath:config/queue-${spring.profiles.active}.yml[.yml], optional:file:../config/queue-${spring.profiles.active}.yml[.yml], optional:classpath:config/queue.yml[.yml], optional:classpath:config/queue-${spring.profiles.active}.yml[.yml], optional:file:../config/queue-${spring.profiles.active}.yml[.yml],
optional:classpath:config/notification.yml[.yml], optional:classpath:config/notification-${spring.profiles.active}.yml[.yml], optional:file:../config/notification-${spring.profiles.active}.yml[.yml], optional:classpath:config/notification.yml[.yml], optional:classpath:config/notification-${spring.profiles.active}.yml[.yml], optional:file:../config/notification-${spring.profiles.active}.yml[.yml],
optional:classpath:config/locale.yml[.yml], optional:classpath:config/locale-${spring.profiles.active}.yml[.yml], optional:file:../config/locale-${spring.profiles.active}.yml[.yml], optional:classpath:config/locale.yml[.yml], optional:classpath:config/locale-${spring.profiles.active}.yml[.yml], optional:file:../config/locale-${spring.profiles.active}.yml[.yml],
optional:classpath:config/public-api.yml[.yml], optional:classpath:config/public-api-${spring.profiles.active}.yml[.yml], optional:file:../config/public-api-${spring.profiles.active}.yml[.yml],
optional:classpath:config/dashboard.yml[.yml], optional:classpath:config/dashboard-${spring.profiles.active}.yml[.yml], optional:file:../config/dashboard-${spring.profiles.active}.yml[.yml],
optional:classpath:config/transformer.yml[.yml], optional:classpath:config/transformer-${spring.profiles.active}.yml[.yml], optional:file:../config/transformer-${spring.profiles.active}.yml[.yml] optional:classpath:config/transformer.yml[.yml], optional:classpath:config/transformer-${spring.profiles.active}.yml[.yml], optional:file:../config/transformer-${spring.profiles.active}.yml[.yml]

View File

@ -0,0 +1,4 @@
dashboard:
reference-type-counters:
- "7eeffb98-58fb-4921-82ec-e27f32f8e738"
- "5b9c284f-f041-4995-96cc-fad7ad13289c"

View File

@ -90,6 +90,11 @@ permissions:
clients: [ ] clients: [ ]
allowAnonymous: true allowAnonymous: true
allowAuthenticated: true allowAuthenticated: true
PublicBrowseReferenceType:
roles: [ ]
clients: [ ]
allowAnonymous: true
allowAuthenticated: true
# Elastic # Elastic
ManageElastic: ManageElastic:
roles: roles:

View File

@ -0,0 +1,10 @@
public-api:
reference-type-map:
funderTypeId: "538928bb-c7c6-452e-b66d-08e539f5f082"
grantTypeId: "5b9c284f-f041-4995-96cc-fad7ad13289c"
registryTypeId: "2beacaad-3223-43ad-ad99-1e5f21328e7b"
serviceTypeId: "9ec2000d-95c7-452e-b356-755fc8e2574c"
dataRepositoryTypeId: "d26b64ba-fda0-4b14-b3ef-9856a492d55a"
datasetTypeId: "a3ce0fb2-d72c-48bb-b322-7401940cb802"
researcherTypeId: "5a2112e7-ea99-4cfe-98a1-68665e26726e"
organizationTypeId: "7eeffb98-58fb-4921-82ec-e27f32f8e738"