From e22ba13caf5c049fb0975919f7d5d5741ba7fa32 Mon Sep 17 00:00:00 2001 From: Thomas Georgios Giannos Date: Wed, 8 Nov 2023 11:45:33 +0200 Subject: [PATCH 01/27] Adding user as owner on new dmp persist --- .../eu/eudat/model/censorship/DmpCensor.java | 2 ++ .../eu/eudat/service/dmp/DmpServiceImpl.java | 26 ++++++++++++++++--- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/censorship/DmpCensor.java b/dmp-backend/core/src/main/java/eu/eudat/model/censorship/DmpCensor.java index 30e69539b..e0e84e232 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/censorship/DmpCensor.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/censorship/DmpCensor.java @@ -40,6 +40,8 @@ public class DmpCensor extends BaseCensor { this.authService.authorizeForce(Permission.BrowseDmp); + FieldSet dmpUsersFields = fields.extractPrefixed(this.asIndexerPrefix(Dmp._dmpUsers)); + this.censorFactory.censor(DmpUserCensor.class).censor(dmpUsersFields, userId); FieldSet dmpReferencesFields = fields.extractPrefixed(this.asIndexerPrefix(Dmp._dmpReferences)); this.censorFactory.censor(DmpReferenceCensor.class).censor(dmpReferencesFields, userId); } diff --git a/dmp-backend/core/src/main/java/eu/eudat/service/dmp/DmpServiceImpl.java b/dmp-backend/core/src/main/java/eu/eudat/service/dmp/DmpServiceImpl.java index fe7850b6a..9cc220d52 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/service/dmp/DmpServiceImpl.java +++ b/dmp-backend/core/src/main/java/eu/eudat/service/dmp/DmpServiceImpl.java @@ -5,7 +5,9 @@ import eu.eudat.authorization.AuthorizationFlags; import eu.eudat.authorization.Permission; import eu.eudat.commons.JsonHandlingService; import eu.eudat.commons.XmlHandlingService; +import eu.eudat.commons.enums.DmpUserRole; import eu.eudat.commons.enums.IsActive; +import eu.eudat.commons.scope.user.UserScope; import eu.eudat.commons.types.reference.DefinitionEntity; import eu.eudat.commons.types.reference.FieldEntity; import eu.eudat.convention.ConventionService; @@ -83,6 +85,8 @@ public class DmpServiceImpl implements DmpService { private final JsonHandlingService jsonHandlingService; + private final UserScope userScope; + private final EventBroker eventBroker; @Autowired @@ -91,11 +95,13 @@ public class DmpServiceImpl implements DmpService { AuthorizationService authorizationService, DeleterFactory deleterFactory, BuilderFactory builderFactory, - QueryFactory queryFactory, ConventionService conventionService, + QueryFactory queryFactory, + ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource, - XmlHandlingService xmlHandlingService, JsonHandlingService jsonHandlingService, - EventBroker eventBroker) { + XmlHandlingService xmlHandlingService, + JsonHandlingService jsonHandlingService, + UserScope userScope, EventBroker eventBroker) { this.entityManager = entityManager; this.authorizationService = authorizationService; this.deleterFactory = deleterFactory; @@ -106,6 +112,7 @@ public class DmpServiceImpl implements DmpService { this.messageSource = messageSource; this.xmlHandlingService = xmlHandlingService; this.jsonHandlingService = jsonHandlingService; + this.userScope = userScope; this.eventBroker = eventBroker; } @@ -173,6 +180,7 @@ public class DmpServiceImpl implements DmpService { Boolean isUpdate = this.conventionService.isValidGuid(model.getId()); DmpEntity data; + DmpUserEntity dmpUserEntity = new DmpUserEntity(); if (isUpdate) { data = this.entityManager.find(DmpEntity.class, model.getId()); if (data == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{model.getId(), Dmp.class.getSimpleName()}, LocaleContextHolder.getLocale())); @@ -184,6 +192,14 @@ public class DmpServiceImpl implements DmpService { data.setVersion((short) 1); data.setIsActive(IsActive.Active); data.setCreatedAt(Instant.now()); + + dmpUserEntity.setId(UUID.randomUUID()); + dmpUserEntity.setDmp(data.getId()); + dmpUserEntity.setUser(userScope.getUserIdSafe()); + dmpUserEntity.setRole(DmpUserRole.Owner); + dmpUserEntity.setCreatedAt(Instant.now()); + dmpUserEntity.setUpdatedAt(Instant.now()); + dmpUserEntity.setIsActive(IsActive.Active); } data.setLabel(model.getLabel()); @@ -193,8 +209,10 @@ public class DmpServiceImpl implements DmpService { data.setUpdatedAt(Instant.now()); if (isUpdate) this.entityManager.merge(data); - else + else { this.entityManager.persist(data); + this.entityManager.persist(dmpUserEntity); + } this.entityManager.flush(); From 0bbad595f59f8f4cb8f293a540a81a33fd60f0fe Mon Sep 17 00:00:00 2001 From: sgiannopoulos Date: Wed, 8 Nov 2023 13:37:16 +0200 Subject: [PATCH 02/27] update logging, db configurations --- .gitignore | 1 + .../typedefinition/DataType.java | 13 -- .../typedefinition/DatabaseColumnType.java | 5 - .../PostgreSQLDatabaseColumnType.java | 25 ---- .../typedefinition/PostgreSQLEnumType.java | 31 ----- .../typedefinition/UUIDType.java | 118 ------------------ .../typedefinition/XMLType.java | 95 -------------- .../eudat/data/DescriptionTemplateEntity.java | 7 +- .../eu/eudat/data/DmpBlueprintEntity.java | 14 +-- .../java/eu/eudat/data/DmpUserEntity.java | 1 + .../java/eu/eudat/data/ReferenceEntity.java | 4 +- .../eu/eudat/data/ReferenceTypeEntity.java | 4 +- .../main/java/eu/eudat/data/TagEntity.java | 5 - .../main/java/eu/eudat/data/old/Content.java | 2 - .../src/main/java/eu/eudat/data/old/DMP.java | 2 - .../eu/eudat/data/old/DMPDatasetProfile.java | 2 - .../eu/eudat/data/old/DMPOrganisation.java | 3 - .../java/eu/eudat/data/old/DMPResearcher.java | 3 - .../eu/eudat/data/old/DataRepository.java | 5 +- .../eu/eudat/data/old/EmailConfirmation.java | 2 - .../main/java/eu/eudat/data/old/Funder.java | 7 +- .../main/java/eu/eudat/data/old/Grant.java | 2 - .../java/eu/eudat/data/old/Invitation.java | 6 +- .../src/main/java/eu/eudat/data/old/Lock.java | 2 - .../java/eu/eudat/data/old/Notification.java | 2 - .../java/eu/eudat/data/old/Organisation.java | 9 +- .../main/java/eu/eudat/data/old/Project.java | 6 +- .../main/java/eu/eudat/data/old/Registry.java | 4 +- .../java/eu/eudat/data/old/Researcher.java | 9 +- .../main/java/eu/eudat/data/old/Service.java | 4 +- .../main/java/eu/eudat/data/old/UserDMP.java | 2 - .../main/java/eu/eudat/data/old/UserInfo.java | 4 - .../main/java/eu/eudat/data/old/UserRole.java | 2 - .../mapper/deposit/DMPToDepositMapper.java | 2 +- .../java/eu/eudat/query/DescriptionQuery.java | 4 - .../query/DmpDescriptionTemplateQuery.java | 17 ++- .../java/eu/eudat/query/DmpUserQuery.java | 25 ++++ .../lookup/DmpDescriptionTemplateLookup.java | 10 ++ .../service/DatabaseService.java | 2 +- .../eudat/data/dao/entities/DMPDaoImpl.java | 2 +- dmp-backend/pom.xml | 1 + dmp-backend/web/pom.xml | 5 +- .../main/java/eu/eudat/EuDatApplication.java | 2 + .../DevelDatabaseConfiguration.java | 73 ----------- .../ProductionDatabaseConfiguration.java | 76 ----------- .../resources/config/application-devel.yml | 2 - .../src/main/resources/config/db-devel.yml | 7 +- .../web/src/main/resources/config/db.yml | 33 ++++- .../main/resources/config/logging-devel.yml | 36 ++++++ .../web/src/main/resources/config/logging.yml | 35 +++++- .../main/resources/logging/logback-devel.xml | 61 ++++++--- .../main/resources/logging/logback-docker.xml | 33 ----- .../resources/logging/logback-production.xml | 33 ----- 53 files changed, 230 insertions(+), 630 deletions(-) delete mode 100644 dmp-backend/core/src/main/java/eu/eudat/configurations/typedefinition/DataType.java delete mode 100644 dmp-backend/core/src/main/java/eu/eudat/configurations/typedefinition/DatabaseColumnType.java delete mode 100644 dmp-backend/core/src/main/java/eu/eudat/configurations/typedefinition/PostgreSQLDatabaseColumnType.java delete mode 100644 dmp-backend/core/src/main/java/eu/eudat/configurations/typedefinition/PostgreSQLEnumType.java delete mode 100644 dmp-backend/core/src/main/java/eu/eudat/configurations/typedefinition/UUIDType.java delete mode 100644 dmp-backend/core/src/main/java/eu/eudat/configurations/typedefinition/XMLType.java delete mode 100644 dmp-backend/web/src/main/java/eu/eudat/configurations/DevelDatabaseConfiguration.java delete mode 100644 dmp-backend/web/src/main/java/eu/eudat/configurations/ProductionDatabaseConfiguration.java create mode 100644 dmp-backend/web/src/main/resources/config/logging-devel.yml delete mode 100644 dmp-backend/web/src/main/resources/logging/logback-docker.xml delete mode 100644 dmp-backend/web/src/main/resources/logging/logback-production.xml diff --git a/.gitignore b/.gitignore index 15bf058e9..8823d8abe 100644 --- a/.gitignore +++ b/.gitignore @@ -50,3 +50,4 @@ bin/ openDMP/dmp-backend/uploads/ openDMP/dmp-backend/tmp/ storage/ +logs/ diff --git a/dmp-backend/core/src/main/java/eu/eudat/configurations/typedefinition/DataType.java b/dmp-backend/core/src/main/java/eu/eudat/configurations/typedefinition/DataType.java deleted file mode 100644 index bf144db9d..000000000 --- a/dmp-backend/core/src/main/java/eu/eudat/configurations/typedefinition/DataType.java +++ /dev/null @@ -1,13 +0,0 @@ -package eu.eudat.configurations.typedefinition; - -public enum DataType { - TINY, - SHORT, - INTEGER, - LONG, - DOUBLE, - FLOAT, - DATE, - STRING, - TEXT -} diff --git a/dmp-backend/core/src/main/java/eu/eudat/configurations/typedefinition/DatabaseColumnType.java b/dmp-backend/core/src/main/java/eu/eudat/configurations/typedefinition/DatabaseColumnType.java deleted file mode 100644 index 6e24625b4..000000000 --- a/dmp-backend/core/src/main/java/eu/eudat/configurations/typedefinition/DatabaseColumnType.java +++ /dev/null @@ -1,5 +0,0 @@ -package eu.eudat.configurations.typedefinition; - -public interface DatabaseColumnType { - public String getType(DataType dt); -} diff --git a/dmp-backend/core/src/main/java/eu/eudat/configurations/typedefinition/PostgreSQLDatabaseColumnType.java b/dmp-backend/core/src/main/java/eu/eudat/configurations/typedefinition/PostgreSQLDatabaseColumnType.java deleted file mode 100644 index bf8812277..000000000 --- a/dmp-backend/core/src/main/java/eu/eudat/configurations/typedefinition/PostgreSQLDatabaseColumnType.java +++ /dev/null @@ -1,25 +0,0 @@ -package eu.eudat.configurations.typedefinition; - -public class PostgreSQLDatabaseColumnType implements DatabaseColumnType { - - public String getType(DataType dt) { - switch (dt) { - case TINY: - case SHORT: - case INTEGER: - return "integer"; - case LONG: - return "bigint"; - case FLOAT: - case DOUBLE: - return "numeric"; - case DATE: - return "timestamp"; - case STRING: - return "character varying(250)"; - case TEXT: - return "text"; - } - return "character varying(250)"; - } -} diff --git a/dmp-backend/core/src/main/java/eu/eudat/configurations/typedefinition/PostgreSQLEnumType.java b/dmp-backend/core/src/main/java/eu/eudat/configurations/typedefinition/PostgreSQLEnumType.java deleted file mode 100644 index 20be832a8..000000000 --- a/dmp-backend/core/src/main/java/eu/eudat/configurations/typedefinition/PostgreSQLEnumType.java +++ /dev/null @@ -1,31 +0,0 @@ -package eu.eudat.configurations.typedefinition; - -import org.hibernate.HibernateException; -import org.hibernate.engine.spi.SharedSessionContractImplementor; - -import java.sql.PreparedStatement; -import java.sql.SQLException; -import java.sql.Types; - -/** - * @deprecated hibernate's abstract class is depricated and those type of conversions and checks - * are done by hibernate itself - */ -@Deprecated -public class PostgreSQLEnumType extends org.hibernate.type.EnumType { - - public void nullSafeSet( - PreparedStatement st, - Object value, - int index, - SharedSessionContractImplementor session) - throws HibernateException, SQLException { - st.setObject( - index, - value != null ? - ((Enum) value).name() : - null, - Types.OTHER - ); - } -} \ No newline at end of file diff --git a/dmp-backend/core/src/main/java/eu/eudat/configurations/typedefinition/UUIDType.java b/dmp-backend/core/src/main/java/eu/eudat/configurations/typedefinition/UUIDType.java deleted file mode 100644 index 042fed955..000000000 --- a/dmp-backend/core/src/main/java/eu/eudat/configurations/typedefinition/UUIDType.java +++ /dev/null @@ -1,118 +0,0 @@ -package eu.eudat.configurations.typedefinition; - -import org.hibernate.HibernateException; -import org.hibernate.engine.spi.SharedSessionContractImplementor; -import org.hibernate.usertype.UserType; - -import java.io.Serializable; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.sql.Types; -import java.util.UUID; - -/** - * Currently not used - */ -public class UUIDType implements UserType { - private final int[] sqlTypesSupported = new int[]{Types.NUMERIC}; - private final String CAST_EXCEPTION_TEXT = " cannot be cast to a java.util.UUID"; - - public int[] sqlTypes() { - return sqlTypesSupported; - } - - @Override - public int getSqlType() { - return sqlTypesSupported[0]; - } - - public Class returnedClass() { - return UUID.class; - } - - public boolean equals(UUID x, UUID y) throws HibernateException { - if (x == null) return y == null; - else return x.equals(y); - } - - public int hashCode(UUID x) throws HibernateException { - return x == null ? -1 : x.hashCode(); - } - - @Override - public UUID nullSafeGet(ResultSet rs, int position, SharedSessionContractImplementor session, Object owner) throws SQLException { - assert (position >= 0); - Object value = rs.getObject(position); - if (value == null) return null; - - UUID uuid = UUID.fromString(rs.getString(position)); - return rs.wasNull() ? null : uuid; - } - - public Object nullSafeGet(ResultSet rs, String[] names, Object owner) throws HibernateException, SQLException { - assert (names.length == 1); - Object value = rs.getObject(names[0]); - if (value == null) return null; - - UUID uuid = UUID.fromString(rs.getString(names[0])); - return rs.wasNull() ? null : uuid; - } - - public void nullSafeSet(PreparedStatement st, Object value, int index) throws HibernateException, SQLException { - if (value == null) { - st.setNull(index, Types.NULL); - return; - } - - if (!UUID.class.isAssignableFrom(value.getClass())) - throw new HibernateException(value.getClass().toString() + CAST_EXCEPTION_TEXT); - - UUID uuid = (UUID) value; - st.setObject(index, uuid, Types.OTHER); - } - - public UUID deepCopy(UUID value) throws HibernateException { - if (value == null) return null; - return new UUID(value.getMostSignificantBits(), value.getLeastSignificantBits()); - } - - public boolean isMutable() { - return false; - } - - public Serializable disassemble(UUID value) throws HibernateException { - return value; - } - - public UUID assemble(Serializable cached, Object owner) throws HibernateException { - return (UUID) cached; - } - - public UUID replace(UUID original, Object target, Object owner) throws HibernateException { - return original; - } - -// public Object nullSafeGet(ResultSet rs, String[] names, SessionImplementor session, Object owner) -// throws HibernateException, SQLException -// { -// return nullSafeGet(rs, names, owner); -// } -// -// public void nullSafeSet(PreparedStatement st, Object value, int index, SessionImplementor session) -// throws HibernateException, SQLException -// { -// nullSafeSet(st, value, index); -// -// } - - public Object nullSafeGet(ResultSet rs, String[] names, SharedSessionContractImplementor session, Object owner) - throws HibernateException, SQLException { - return nullSafeGet(rs, names, owner); - } - - public void nullSafeSet(PreparedStatement st, UUID value, int index, SharedSessionContractImplementor session) - throws HibernateException, SQLException { - nullSafeSet(st, value, index); - } -} \ No newline at end of file diff --git a/dmp-backend/core/src/main/java/eu/eudat/configurations/typedefinition/XMLType.java b/dmp-backend/core/src/main/java/eu/eudat/configurations/typedefinition/XMLType.java deleted file mode 100644 index ea4b1f9d0..000000000 --- a/dmp-backend/core/src/main/java/eu/eudat/configurations/typedefinition/XMLType.java +++ /dev/null @@ -1,95 +0,0 @@ -package eu.eudat.configurations.typedefinition; - -import org.hibernate.HibernateException; -import org.hibernate.engine.spi.SharedSessionContractImplementor; -import org.hibernate.usertype.UserType; - -import java.io.Serializable; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.sql.Types; - -/** - * Store and retrieve a PostgreSQL "xml" column as a Java string. - */ -public class XMLType implements UserType { - - private final int[] sqlTypesSupported = new int[]{Types.VARCHAR}; - - public int[] sqlTypes() { - return sqlTypesSupported; - } - - @Override - public int getSqlType() { - return sqlTypesSupported[0]; - } - - public Class returnedClass() { - return String.class; - } - - public boolean equals(String x, String y) throws HibernateException { - if (x == null) { - return y == null; - } else { - return x.equals(y); - } - } - - public int hashCode(String x) throws HibernateException { - return x == null ? -1 : x.hashCode(); - } - - @Override - public String nullSafeGet(ResultSet resultSet, int i, SharedSessionContractImplementor sharedSessionContractImplementor, Object o) throws SQLException { - assert (i >= 0); - String xmldoc = resultSet.getString(i); - return resultSet.wasNull() ? null : xmldoc; - } - - public Object nullSafeGet(ResultSet rs, String[] names, Object owner) throws HibernateException, SQLException { - assert (names.length == 1); - String xmldoc = rs.getString(names[0]); - return rs.wasNull() ? null : xmldoc; - } - - public void nullSafeSet(PreparedStatement st, Object value, int index) throws HibernateException, SQLException { - if (value == null) { - st.setNull(index, Types.OTHER); - } else { - st.setObject(index, value, Types.OTHER); - } - } - - public String deepCopy(String value) throws HibernateException { - return value; - } - - public boolean isMutable() { - return false; - } - - public Serializable disassemble(String value) throws HibernateException { - return value; - } - - public String assemble(Serializable cached, Object owner) throws HibernateException { - return (String) cached; - } - - public String replace(String original, String target, Object owner) throws HibernateException { - return original; - } - - public Object nullSafeGet(ResultSet rs, String[] names, SharedSessionContractImplementor session, Object owner) - throws HibernateException, SQLException { - return nullSafeGet(rs, names, owner); - } - - public void nullSafeSet(PreparedStatement st, String value, int index, SharedSessionContractImplementor session) throws HibernateException, SQLException { - nullSafeSet(st, value, index); - } - -} \ No newline at end of file diff --git a/dmp-backend/core/src/main/java/eu/eudat/data/DescriptionTemplateEntity.java b/dmp-backend/core/src/main/java/eu/eudat/data/DescriptionTemplateEntity.java index d3cc5145c..d8166558c 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/data/DescriptionTemplateEntity.java +++ b/dmp-backend/core/src/main/java/eu/eudat/data/DescriptionTemplateEntity.java @@ -7,10 +7,10 @@ import eu.eudat.data.converters.enums.DescriptionTemplateStatusConverter; import eu.eudat.data.converters.enums.IsActiveConverter; import eu.eudat.queryable.queryableentity.DataEntity; import jakarta.persistence.*; -import org.hibernate.annotations.Type; import java.time.Instant; -import java.util.*; +import java.util.List; +import java.util.UUID; @Entity @@ -26,8 +26,7 @@ public class DescriptionTemplateEntity implements DataEntity { //IGNORE ME @Id @GeneratedValue - @GenericGenerator(name = "uuid2", strategy = "uuid2") @Column(name = "\"Id\"", updatable = false, nullable = false, columnDefinition = "BINARY(16)") private UUID id; diff --git a/dmp-backend/core/src/main/java/eu/eudat/data/old/DMP.java b/dmp-backend/core/src/main/java/eu/eudat/data/old/DMP.java index c00aac796..af9249e04 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/data/old/DMP.java +++ b/dmp-backend/core/src/main/java/eu/eudat/data/old/DMP.java @@ -6,7 +6,6 @@ import eu.eudat.data.DmpBlueprintEntity; import eu.eudat.data.EntityDoiEntity; import eu.eudat.data.converters.DateToUTCConverter; import eu.eudat.queryable.queryableentity.DataEntity; -import org.hibernate.annotations.GenericGenerator; import jakarta.persistence.*; import java.util.*; @@ -90,7 +89,6 @@ public class DMP implements DataEntity { @Id @GeneratedValue - @GenericGenerator(name = "uuid2", strategy = "uuid2") @Column(name = "\"ID\"", updatable = false, nullable = false, columnDefinition = "BINARY(16)") private UUID id; diff --git a/dmp-backend/core/src/main/java/eu/eudat/data/old/DMPDatasetProfile.java b/dmp-backend/core/src/main/java/eu/eudat/data/old/DMPDatasetProfile.java index 744a62927..2342cc1d9 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/data/old/DMPDatasetProfile.java +++ b/dmp-backend/core/src/main/java/eu/eudat/data/old/DMPDatasetProfile.java @@ -2,7 +2,6 @@ package eu.eudat.data.old; import eu.eudat.data.DescriptionTemplateEntity; import eu.eudat.queryable.queryableentity.DataEntity; -import org.hibernate.annotations.GenericGenerator; import jakarta.persistence.*; import java.util.List; @@ -14,7 +13,6 @@ public class DMPDatasetProfile implements DataEntity { @Id @GeneratedValue - @GenericGenerator(name = "uuid2", strategy = "uuid2") @Column(name = "\"ID\"", updatable = false, nullable = false, columnDefinition = "BINARY(16)") private UUID id; diff --git a/dmp-backend/core/src/main/java/eu/eudat/data/old/DMPOrganisation.java b/dmp-backend/core/src/main/java/eu/eudat/data/old/DMPOrganisation.java index e3b9b40c7..920b6351b 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/data/old/DMPOrganisation.java +++ b/dmp-backend/core/src/main/java/eu/eudat/data/old/DMPOrganisation.java @@ -1,8 +1,6 @@ package eu.eudat.data.old; -import org.hibernate.annotations.GenericGenerator; - import jakarta.persistence.*; import java.io.Serializable; import java.util.UUID; @@ -14,7 +12,6 @@ public class DMPOrganisation { @Id @GeneratedValue - @GenericGenerator(name = "uuid2", strategy = "uuid2") @Column(name = "\"ID\"", updatable = false, nullable = false, columnDefinition = "BINARY(16)") private UUID id; diff --git a/dmp-backend/core/src/main/java/eu/eudat/data/old/DMPResearcher.java b/dmp-backend/core/src/main/java/eu/eudat/data/old/DMPResearcher.java index 9f419d6c7..e633606de 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/data/old/DMPResearcher.java +++ b/dmp-backend/core/src/main/java/eu/eudat/data/old/DMPResearcher.java @@ -1,8 +1,6 @@ package eu.eudat.data.old; -import org.hibernate.annotations.GenericGenerator; -import org.hibernate.annotations.Type; import jakarta.persistence.*; import java.util.UUID; @@ -14,7 +12,6 @@ public class DMPResearcher { @Id @GeneratedValue - @GenericGenerator(name = "uuid2", strategy = "uuid2") @Column(name = "\"ID\"", updatable = false, nullable = false, columnDefinition = "BINARY(16)") private UUID id; diff --git a/dmp-backend/core/src/main/java/eu/eudat/data/old/DataRepository.java b/dmp-backend/core/src/main/java/eu/eudat/data/old/DataRepository.java index be5b0d4f4..db1182e29 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/data/old/DataRepository.java +++ b/dmp-backend/core/src/main/java/eu/eudat/data/old/DataRepository.java @@ -3,13 +3,11 @@ package eu.eudat.data.old; import eu.eudat.data.old.helpers.EntityBinder; import eu.eudat.queryable.queryableentity.DataEntity; -import org.hibernate.annotations.Type; import jakarta.persistence.*; import java.io.Serializable; import java.util.Date; import java.util.List; -import java.util.Set; import java.util.UUID; @Entity @@ -32,8 +30,7 @@ public class DataRepository implements Serializable, DataEntity { @Id @GeneratedValue - @GenericGenerator(name = "uuid2", strategy = "uuid2") @Column(name = "\"ID\"", updatable = false, nullable = false) private UUID id; diff --git a/dmp-backend/core/src/main/java/eu/eudat/data/old/Funder.java b/dmp-backend/core/src/main/java/eu/eudat/data/old/Funder.java index 4e4e0810e..3a64acfb8 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/data/old/Funder.java +++ b/dmp-backend/core/src/main/java/eu/eudat/data/old/Funder.java @@ -1,7 +1,6 @@ package eu.eudat.data.old; import eu.eudat.queryable.queryableentity.DataEntity; -import org.hibernate.annotations.Type; import jakarta.persistence.*; import java.util.Date; @@ -73,12 +72,10 @@ public class Funder implements DataEntity { @Column(name = "\"Label\"") private String label; - @Type(eu.eudat.configurations.typedefinition.XMLType.class) - @Column(name = "\"Reference\"", columnDefinition = "xml", nullable = true) + @Column(name = "\"Reference\"", nullable = true) private String reference; - @Type(eu.eudat.configurations.typedefinition.XMLType.class) - @Column(name = "\"Definition\"", columnDefinition = "xml", nullable = true) + @Column(name = "\"Definition\"", nullable = true) private String definition; @Column(name = "\"Status\"", nullable = false) diff --git a/dmp-backend/core/src/main/java/eu/eudat/data/old/Grant.java b/dmp-backend/core/src/main/java/eu/eudat/data/old/Grant.java index e8996e02b..2766087b0 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/data/old/Grant.java +++ b/dmp-backend/core/src/main/java/eu/eudat/data/old/Grant.java @@ -4,7 +4,6 @@ package eu.eudat.data.old; import eu.eudat.data.converters.DateToUTCConverter; import eu.eudat.data.old.helpers.EntityBinder; import eu.eudat.queryable.queryableentity.DataEntity; -import org.hibernate.annotations.Type; import jakarta.persistence.*; import java.util.*; @@ -101,7 +100,6 @@ public class Grant implements DataEntity { @Column(name = "\"Uri\"") private String uri; - @Type(eu.eudat.configurations.typedefinition.XMLType.class) @Column(name = "\"Definition\"", columnDefinition = "xml", nullable = true) private String definition; diff --git a/dmp-backend/core/src/main/java/eu/eudat/data/old/Invitation.java b/dmp-backend/core/src/main/java/eu/eudat/data/old/Invitation.java index b8da71354..4bce27cf9 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/data/old/Invitation.java +++ b/dmp-backend/core/src/main/java/eu/eudat/data/old/Invitation.java @@ -2,8 +2,6 @@ package eu.eudat.data.old; import eu.eudat.data.old.helpers.EntityBinder; import eu.eudat.queryable.queryableentity.DataEntity; -import org.hibernate.annotations.GenericGenerator; -import org.hibernate.annotations.Type; import jakarta.persistence.*; import java.util.List; @@ -16,7 +14,6 @@ public class Invitation implements DataEntity { @Id @GeneratedValue - @GenericGenerator(name = "uuid2", strategy = "uuid2") @Column(name = "\"Id\"", updatable = false, nullable = false) private UUID id; @@ -37,8 +34,7 @@ public class Invitation implements DataEntity { @Column(name = "\"AcceptedInvitation\"", nullable = false) private boolean acceptedInvitation; - @Type(eu.eudat.configurations.typedefinition.XMLType.class) - @Column(name = "\"Properties\"", columnDefinition = "xml", nullable = true) + @Column(name = "\"Properties\"", nullable = true) private String properties; public UUID getId() { diff --git a/dmp-backend/core/src/main/java/eu/eudat/data/old/Lock.java b/dmp-backend/core/src/main/java/eu/eudat/data/old/Lock.java index 4f50dd645..526e1b467 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/data/old/Lock.java +++ b/dmp-backend/core/src/main/java/eu/eudat/data/old/Lock.java @@ -3,7 +3,6 @@ package eu.eudat.data.old; import eu.eudat.data.converters.DateToUTCConverter; import eu.eudat.data.old.helpers.EntityBinder; import eu.eudat.queryable.queryableentity.DataEntity; -import org.hibernate.annotations.GenericGenerator; import jakarta.persistence.*; import java.util.Date; @@ -16,7 +15,6 @@ public class Lock implements DataEntity { @Id @GeneratedValue - @GenericGenerator(name = "uuid2", strategy = "uuid2") @Column(name = "id", updatable = false, nullable = false, columnDefinition = "BINARY(16)") private UUID id; diff --git a/dmp-backend/core/src/main/java/eu/eudat/data/old/Notification.java b/dmp-backend/core/src/main/java/eu/eudat/data/old/Notification.java index 143237d15..3c68e4953 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/data/old/Notification.java +++ b/dmp-backend/core/src/main/java/eu/eudat/data/old/Notification.java @@ -5,7 +5,6 @@ import eu.eudat.commons.enums.old.notification.ContactType; import eu.eudat.commons.enums.old.notification.NotificationType; import eu.eudat.commons.enums.old.notification.NotifyState; import eu.eudat.queryable.queryableentity.DataEntity; -import org.hibernate.annotations.GenericGenerator; import jakarta.persistence.*; import java.util.Date; @@ -18,7 +17,6 @@ public class Notification implements DataEntity { @Id @GeneratedValue - @GenericGenerator(name = "uuid2", strategy = "uuid2") @Column(name = "id", updatable = false, nullable = false, columnDefinition = "BINARY(16)") private UUID id; diff --git a/dmp-backend/core/src/main/java/eu/eudat/data/old/Organisation.java b/dmp-backend/core/src/main/java/eu/eudat/data/old/Organisation.java index 6cfded45d..a14b39fd7 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/data/old/Organisation.java +++ b/dmp-backend/core/src/main/java/eu/eudat/data/old/Organisation.java @@ -3,8 +3,6 @@ package eu.eudat.data.old; import eu.eudat.data.converters.DateToUTCConverter; import eu.eudat.data.old.helpers.EntityBinder; import eu.eudat.queryable.queryableentity.DataEntity; -import org.hibernate.annotations.GenericGenerator; -import org.hibernate.annotations.Type; import jakarta.persistence.*; import java.io.Serializable; @@ -25,7 +23,6 @@ public class Organisation implements Serializable, DataEntity @Id @GeneratedValue - @GenericGenerator(name = "uuid2", strategy = "uuid2") @Column(name = "\"ID\"", updatable = false, nullable = false, columnDefinition = "BINARY(16)") private UUID id; @@ -35,15 +32,13 @@ public class Organisation implements Serializable, DataEntity @Column(name = "\"Abbreviation\"") private String abbreviation; - @Type(eu.eudat.configurations.typedefinition.XMLType.class) - @Column(name = "\"Reference\"", columnDefinition = "xml", nullable = true) + @Column(name = "\"Reference\"", nullable = true) private String reference; @Column(name = "\"Uri\"") private String uri; - @Type(eu.eudat.configurations.typedefinition.XMLType.class) - @Column(name = "\"Definition\"", columnDefinition = "xml", nullable = true) + @Column(name = "\"Definition\"", nullable = true) private String definition; @OneToMany(fetch = FetchType.LAZY) diff --git a/dmp-backend/core/src/main/java/eu/eudat/data/old/Project.java b/dmp-backend/core/src/main/java/eu/eudat/data/old/Project.java index bccc1ef58..90dd6b193 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/data/old/Project.java +++ b/dmp-backend/core/src/main/java/eu/eudat/data/old/Project.java @@ -3,7 +3,6 @@ package eu.eudat.data.old; import eu.eudat.data.converters.DateToUTCConverter; import eu.eudat.data.old.helpers.EntityBinder; import eu.eudat.queryable.queryableentity.DataEntity; -import org.hibernate.annotations.Type; import jakarta.persistence.*; import java.util.*; @@ -80,14 +79,13 @@ public class Project implements DataEntity { @Column(name = "\"Abbreviation\"") private String abbreviation; - @Column(name = "\"Reference\"", columnDefinition = "xml", nullable = true) + @Column(name = "\"Reference\"", nullable = true) private String reference; @Column(name = "\"Uri\"") private String uri; - @Type(eu.eudat.configurations.typedefinition.XMLType.class) - @Column(name = "\"Definition\"", columnDefinition = "xml", nullable = true) + @Column(name = "\"Definition\"", nullable = true) private String definition; @Column(name = "\"StartDate\"", nullable = false) diff --git a/dmp-backend/core/src/main/java/eu/eudat/data/old/Registry.java b/dmp-backend/core/src/main/java/eu/eudat/data/old/Registry.java index 29c860824..3fcf00878 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/data/old/Registry.java +++ b/dmp-backend/core/src/main/java/eu/eudat/data/old/Registry.java @@ -5,7 +5,6 @@ import eu.eudat.data.DescriptionEntity; import eu.eudat.data.converters.DateToUTCConverter; import eu.eudat.data.old.helpers.EntityBinder; import eu.eudat.queryable.queryableentity.DataEntity; -import org.hibernate.annotations.Type; import jakarta.persistence.*; import java.util.Date; @@ -34,8 +33,7 @@ public class Registry implements DataEntity { @Column(name = "\"Uri\"") private String uri; - @Type(eu.eudat.configurations.typedefinition.XMLType.class) - @Column(name = "\"Definition\"", columnDefinition = "xml", nullable = true) + @Column(name = "\"Definition\"", nullable = true) private String definition; @Transient diff --git a/dmp-backend/core/src/main/java/eu/eudat/data/old/Researcher.java b/dmp-backend/core/src/main/java/eu/eudat/data/old/Researcher.java index a11bb1520..e59ef9481 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/data/old/Researcher.java +++ b/dmp-backend/core/src/main/java/eu/eudat/data/old/Researcher.java @@ -4,7 +4,6 @@ package eu.eudat.data.old; import eu.eudat.data.converters.DateToUTCConverter; import eu.eudat.data.old.helpers.EntityBinder; import eu.eudat.queryable.queryableentity.DataEntity; -import org.hibernate.annotations.Type; import jakarta.persistence.*; import java.util.Date; @@ -18,8 +17,6 @@ import java.util.UUID; public class Researcher implements DataEntity { @Id - /*@GeneratedValue - @GenericGenerator(name = "uuid2", strategy = "uuid2")*/ @Column(name = "\"ID\"", updatable = false, nullable = false, columnDefinition = "BINARY(16)") private UUID id; @@ -32,12 +29,10 @@ public class Researcher implements DataEntity { @Column(name = "\"PrimaryEmail\"") private String primaryEmail; - @Type(eu.eudat.configurations.typedefinition.XMLType.class) - @Column(name = "\"Definition\"", columnDefinition = "xml", nullable = true) + @Column(name = "\"Definition\"", nullable = true) private String definition; - @Type(eu.eudat.configurations.typedefinition.XMLType.class) - @Column(name = "\"Reference\"", columnDefinition = "xml", nullable = true) + @Column(name = "\"Reference\"", nullable = true) private String reference; diff --git a/dmp-backend/core/src/main/java/eu/eudat/data/old/Service.java b/dmp-backend/core/src/main/java/eu/eudat/data/old/Service.java index 732b89927..8ade40d65 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/data/old/Service.java +++ b/dmp-backend/core/src/main/java/eu/eudat/data/old/Service.java @@ -3,7 +3,6 @@ package eu.eudat.data.old; import eu.eudat.data.converters.DateToUTCConverter; import eu.eudat.queryable.queryableentity.DataEntity; -import org.hibernate.annotations.Type; import jakarta.persistence.*; import java.util.Date; @@ -32,8 +31,7 @@ public class Service implements DataEntity { @Column(name = "\"Uri\"") private String uri; - @Type(eu.eudat.configurations.typedefinition.XMLType.class) - @Column(name = "\"Definition\"", columnDefinition = "xml", nullable = false) + @Column(name = "\"Definition\"", nullable = false) private String definition; @Column(name = "\"Status\"", nullable = false) diff --git a/dmp-backend/core/src/main/java/eu/eudat/data/old/UserDMP.java b/dmp-backend/core/src/main/java/eu/eudat/data/old/UserDMP.java index a42e2e862..688f1e096 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/data/old/UserDMP.java +++ b/dmp-backend/core/src/main/java/eu/eudat/data/old/UserDMP.java @@ -2,7 +2,6 @@ package eu.eudat.data.old; import eu.eudat.data.old.helpers.EntityBinder; import eu.eudat.queryable.queryableentity.DataEntity; -import org.hibernate.annotations.GenericGenerator; import jakarta.persistence.*; import java.util.LinkedList; @@ -49,7 +48,6 @@ public class UserDMP implements DataEntity { @Id @GeneratedValue - @GenericGenerator(name = "uuid2", strategy = "uuid2") @Column(name = "id", updatable = false, nullable = false, columnDefinition = "BINARY(16)") private UUID id; diff --git a/dmp-backend/core/src/main/java/eu/eudat/data/old/UserInfo.java b/dmp-backend/core/src/main/java/eu/eudat/data/old/UserInfo.java index cb2e04992..a7b615108 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/data/old/UserInfo.java +++ b/dmp-backend/core/src/main/java/eu/eudat/data/old/UserInfo.java @@ -4,8 +4,6 @@ import eu.eudat.data.CredentialEntity; import eu.eudat.data.converters.DateToUTCConverter; import eu.eudat.data.old.helpers.EntityBinder; import eu.eudat.queryable.queryableentity.DataEntity; -import org.hibernate.annotations.GenericGenerator; -import org.hibernate.annotations.Type; import jakarta.persistence.*; import java.util.*; @@ -22,7 +20,6 @@ public class UserInfo implements DataEntity { @Id @GeneratedValue - @GenericGenerator(name = "uuid2", strategy = "uuid2") @Column(name = "id", updatable = false, nullable = false, columnDefinition = "BINARY(16)") private UUID id; public final static String _id = "id"; @@ -65,7 +62,6 @@ public class UserInfo implements DataEntity { public final static String _lastloggedin = "lastloggedin"; - @Type(eu.eudat.configurations.typedefinition.XMLType.class) @Column(name = "additionalinfo", nullable = true) private String additionalinfo; public final static String _additionalinfo = "additionalinfo"; diff --git a/dmp-backend/core/src/main/java/eu/eudat/data/old/UserRole.java b/dmp-backend/core/src/main/java/eu/eudat/data/old/UserRole.java index 0c3c8c385..bf8b58ace 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/data/old/UserRole.java +++ b/dmp-backend/core/src/main/java/eu/eudat/data/old/UserRole.java @@ -2,7 +2,6 @@ package eu.eudat.data.old; import eu.eudat.data.old.helpers.EntityBinder; import eu.eudat.queryable.queryableentity.DataEntity; -import org.hibernate.annotations.GenericGenerator; import jakarta.persistence.*; import java.util.List; @@ -15,7 +14,6 @@ public class UserRole implements DataEntity { @Id @GeneratedValue - @GenericGenerator(name = "uuid2", strategy = "uuid2") @Column(name = "\"Id\"", updatable = false, nullable = false, columnDefinition = "BINARY(16)") private UUID id; diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/mapper/deposit/DMPToDepositMapper.java b/dmp-backend/core/src/main/java/eu/eudat/model/mapper/deposit/DMPToDepositMapper.java index 88bfdfef3..72804b73f 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/mapper/deposit/DMPToDepositMapper.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/mapper/deposit/DMPToDepositMapper.java @@ -6,9 +6,9 @@ import eu.eudat.data.DescriptionEntity; import eu.eudat.data.old.*; import eu.eudat.depositinterface.models.*; import eu.eudat.commons.types.xml.XmlBuilder; -import jakarta.transaction.Transactional; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.transaction.annotation.Transactional; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; diff --git a/dmp-backend/core/src/main/java/eu/eudat/query/DescriptionQuery.java b/dmp-backend/core/src/main/java/eu/eudat/query/DescriptionQuery.java index 3a3fd7208..25205d991 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/query/DescriptionQuery.java +++ b/dmp-backend/core/src/main/java/eu/eudat/query/DescriptionQuery.java @@ -24,9 +24,7 @@ import java.util.*; @Component @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) public class DescriptionQuery extends QueryBase { - private String like; - private Collection ids; private DmpDescriptionTemplateQuery dmpDescriptionTemplateQuery; private Collection excludedIds; @@ -61,8 +59,6 @@ public class DescriptionQuery extends QueryBase { return this; } - - public DescriptionQuery dmpDescriptionTemplateSubQuery(DmpDescriptionTemplateQuery subQuery) { this.dmpDescriptionTemplateQuery = subQuery; return this; diff --git a/dmp-backend/core/src/main/java/eu/eudat/query/DmpDescriptionTemplateQuery.java b/dmp-backend/core/src/main/java/eu/eudat/query/DmpDescriptionTemplateQuery.java index ce457fb1e..964d3888f 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/query/DmpDescriptionTemplateQuery.java +++ b/dmp-backend/core/src/main/java/eu/eudat/query/DmpDescriptionTemplateQuery.java @@ -4,6 +4,7 @@ import eu.eudat.authorization.AuthorizationFlags; import eu.eudat.commons.enums.IsActive; import eu.eudat.data.DescriptionEntity; import eu.eudat.data.DmpDescriptionTemplateEntity; +import eu.eudat.data.DmpEntity; import eu.eudat.model.DmpDescriptionTemplate; import gr.cite.tools.data.query.FieldResolver; import gr.cite.tools.data.query.QueryBase; @@ -11,6 +12,7 @@ import gr.cite.tools.data.query.QueryContext; import jakarta.persistence.Tuple; import jakarta.persistence.criteria.CriteriaBuilder; import jakarta.persistence.criteria.Predicate; +import jakarta.persistence.criteria.Subquery; import org.springframework.beans.factory.config.ConfigurableBeanFactory; import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Component; @@ -25,6 +27,7 @@ public class DmpDescriptionTemplateQuery extends QueryBase ids; private Collection dmpIds; + private DmpQuery dmpQuery; private Collection descriptionTemplateIds; @@ -93,6 +96,11 @@ public class DmpDescriptionTemplateQuery extends QueryBase values) { this.dmpIds = values; return this; + } + + public DmpDescriptionTemplateQuery dmpSubQuery(DmpQuery subQuery) { + this.dmpQuery = subQuery; + return this; } public DmpDescriptionTemplateQuery descriptionTemplateIds(UUID value) { @@ -126,7 +134,7 @@ public class DmpDescriptionTemplateQuery extends QueryBase notInClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(DescriptionEntity._id)); + CriteriaBuilder.In notInClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(DmpDescriptionTemplateEntity._id)); for (UUID item : this.excludedIds) notInClause.value(item); predicates.add(notInClause.not()); } + if (this.dmpQuery != null) { + Subquery subQuery = queryContext.Query.subquery(this.dmpQuery.entityClass()); + this.applySubQuery(this.dmpQuery, queryContext.CriteriaBuilder, subQuery); + predicates.add(queryContext.CriteriaBuilder.in(queryContext.Root.get(DmpDescriptionTemplateEntity._dmpId)).value(subQuery)); + } if (this.dmpIds != null) { CriteriaBuilder.In inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(DmpDescriptionTemplateEntity._dmpId)); for (UUID item : this.dmpIds) diff --git a/dmp-backend/core/src/main/java/eu/eudat/query/DmpUserQuery.java b/dmp-backend/core/src/main/java/eu/eudat/query/DmpUserQuery.java index 262b7480b..711e1bce8 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/query/DmpUserQuery.java +++ b/dmp-backend/core/src/main/java/eu/eudat/query/DmpUserQuery.java @@ -1,8 +1,12 @@ package eu.eudat.query; import eu.eudat.authorization.AuthorizationFlags; +import eu.eudat.authorization.Permission; +import eu.eudat.commons.enums.DmpAccessType; import eu.eudat.commons.enums.DmpUserRole; import eu.eudat.commons.scope.user.UserScope; +import eu.eudat.data.DmpDescriptionTemplateEntity; +import eu.eudat.data.DmpEntity; import eu.eudat.data.DmpUserEntity; import eu.eudat.model.DmpUser; import gr.cite.commons.web.authz.service.AuthorizationService; @@ -12,6 +16,7 @@ import gr.cite.tools.data.query.QueryContext; import jakarta.persistence.Tuple; import jakarta.persistence.criteria.CriteriaBuilder; import jakarta.persistence.criteria.Predicate; +import jakarta.persistence.criteria.Subquery; import org.springframework.beans.factory.config.ConfigurableBeanFactory; import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Component; @@ -121,6 +126,26 @@ public class DmpUserQuery extends QueryBase { return this.isEmpty(this.ids) || this.isEmpty(this.dmpIds) || this.isEmpty(this.userIds); } + @Override + protected Predicate applyAuthZ(QueryContext queryContext) { + if (this.authorize.contains(AuthorizationFlags.None)) return null; + if (this.authorize.contains(AuthorizationFlags.Permission) && this.authService.authorize(Permission.BrowseDmp)) return null; + UUID ownerId = null; + if (this.authorize.contains(AuthorizationFlags.Owner)) ownerId = this.userScope.getUserIdSafe(); + + List predicates = new ArrayList<>(); + if (ownerId != null) { + predicates.add(queryContext.CriteriaBuilder.equal(queryContext.Root.get(DmpUserEntity._user), ownerId)); + + } + if (predicates.size() > 0) { + Predicate[] predicatesArray = predicates.toArray(new Predicate[0]); + return queryContext.CriteriaBuilder.and(predicatesArray); + } else { + return queryContext.CriteriaBuilder.or(); //Creates a false query + } + } + @Override protected Predicate applyFilters(QueryContext queryContext) { List predicates = new ArrayList<>(); diff --git a/dmp-backend/core/src/main/java/eu/eudat/query/lookup/DmpDescriptionTemplateLookup.java b/dmp-backend/core/src/main/java/eu/eudat/query/lookup/DmpDescriptionTemplateLookup.java index 637315f31..23f85a022 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/query/lookup/DmpDescriptionTemplateLookup.java +++ b/dmp-backend/core/src/main/java/eu/eudat/query/lookup/DmpDescriptionTemplateLookup.java @@ -15,6 +15,7 @@ public class DmpDescriptionTemplateLookup extends Lookup { private List ids; private List dmpIds; private List descriptionTemplateIds; + private DmpLookup dmpSubQuery; private List excludedIds; @@ -60,6 +61,14 @@ public class DmpDescriptionTemplateLookup extends Lookup { this.descriptionTemplateIds = descriptionTemplateIds; } + public DmpLookup getDmpSubQuery() { + return dmpSubQuery; + } + + public void setDmpSubQuery(DmpLookup dmpSubQuery) { + this.dmpSubQuery = dmpSubQuery; + } + public DmpDescriptionTemplateQuery enrich(QueryFactory queryFactory) { DmpDescriptionTemplateQuery query = queryFactory.query(DmpDescriptionTemplateQuery.class); if (this.ids != null) query.ids(this.ids); @@ -67,6 +76,7 @@ public class DmpDescriptionTemplateLookup extends Lookup { if (this.descriptionTemplateIds != null) query.ids(this.descriptionTemplateIds); if (this.excludedIds != null) query.excludedIds(this.excludedIds); if (this.isActive != null) query.isActive(this.isActive); + if (this.dmpSubQuery != null) query.dmpSubQuery(this.dmpSubQuery.enrich(queryFactory)); this.enrichCommon(query); diff --git a/dmp-backend/data/src/main/java/eu/eudat/data/dao/databaselayer/service/DatabaseService.java b/dmp-backend/data/src/main/java/eu/eudat/data/dao/databaselayer/service/DatabaseService.java index 6ef82d736..d596ee688 100644 --- a/dmp-backend/data/src/main/java/eu/eudat/data/dao/databaselayer/service/DatabaseService.java +++ b/dmp-backend/data/src/main/java/eu/eudat/data/dao/databaselayer/service/DatabaseService.java @@ -6,8 +6,8 @@ import eu.eudat.queryable.QueryableList; import eu.eudat.queryable.queryableentity.DataEntity; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; -import jakarta.transaction.Transactional; import java.util.Set; diff --git a/dmp-backend/data/src/main/java/eu/eudat/data/dao/entities/DMPDaoImpl.java b/dmp-backend/data/src/main/java/eu/eudat/data/dao/entities/DMPDaoImpl.java index e67a6ac22..efff8b70a 100644 --- a/dmp-backend/data/src/main/java/eu/eudat/data/dao/entities/DMPDaoImpl.java +++ b/dmp-backend/data/src/main/java/eu/eudat/data/dao/entities/DMPDaoImpl.java @@ -12,10 +12,10 @@ import eu.eudat.queryable.types.SelectionField; import eu.eudat.types.grant.GrantStateType; import jakarta.persistence.criteria.Join; import jakarta.persistence.criteria.JoinType; -import jakarta.transaction.Transactional; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Component; +import org.springframework.transaction.annotation.Transactional; import javax.management.InvalidApplicationException; import java.util.Arrays; diff --git a/dmp-backend/pom.xml b/dmp-backend/pom.xml index 68b0418ca..b02a37cf4 100644 --- a/dmp-backend/pom.xml +++ b/dmp-backend/pom.xml @@ -99,6 +99,7 @@ org.hibernate.orm hibernate-core + 6.3.1.Final diff --git a/dmp-backend/web/pom.xml b/dmp-backend/web/pom.xml index e8d5643dd..e09628fa6 100644 --- a/dmp-backend/web/pom.xml +++ b/dmp-backend/web/pom.xml @@ -102,7 +102,10 @@ org.postgresql postgresql - 42.6.0 + + + org.hibernate.orm + hibernate-core +
+ +
+ + + + + {{'REFERENCE-TYPE-EDITOR.NEW' | translate}} + + +
+
+
+ + {{'REFERENCE-TYPE-EDITOR.FIELDS.NAME' | translate}} + + + {{formGroup.get('name').getError('backendError').message}} + + {{'GENERAL.VALIDATION.REQUIRED' | translate}} + +
+
+ + {{'REFERENCE-TYPE-EDITOR.FIELDS.CODE' | translate}} + + + {{formGroup.get('code').getError('backendError').message}} + + {{'GENERAL.VALIDATION.REQUIRED' | translate}} + +
+
+
+
+
+ + + + + Reference Type Fields + + + + +
+ + +
+
+
+ +
+
+ {{'REFERENCE-TYPE-EDITOR.FIELDS.FIELD' | translate}} {{fieldIndex + 1}} +
+ + +
+ +
+
+
+ +
+
+ + {{'REFERENCE-TYPE-EDITOR.FIELDS.CODE' | translate}} + + + {{'GENERAL.VALIDATION.REQUIRED' | translate}} + +
+
+ + {{'REFERENCE-TYPE-EDITOR.FIELDS.DATA-TYPE' | translate}} + + + {{dataType.name}} + + + + {{'GENERAL.VALIDATION.REQUIRED' | translate}} + +
+ +
+
+
+
+
+
+
+
+ + + + Reference Type External API Configuration + + + +
+ +
+
+
+ +
+
+ {{'REFERENCE-TYPE-EDITOR.FIELDS.EXTERNAL-API-CONFIGURATION' | translate}} {{externalApiConfigIndex + 1}} +
+ + +
+ +
+
+
+ +
+
+ + {{'REFERENCE-TYPE-EDITOR.FIELDS.KEY' | translate}} + + + {{'GENERAL.VALIDATION.REQUIRED' | translate}} + +
+
+ + {{'REFERENCE-TYPE-EDITOR.FIELDS.LABEL' | translate}} + + + {{'GENERAL.VALIDATION.REQUIRED' | translate}} + +
+
+ + {{'REFERENCE-TYPE-EDITOR.FIELDS.ORDINAL' | translate}} + + + {{'GENERAL.VALIDATION.REQUIRED' | translate}} + +
+
+ + {{'REFERENCE-TYPE-EDITOR.FIELDS.URL' | translate}} + + + {{'GENERAL.VALIDATION.REQUIRED' | translate}} + +
+
+ + Type + + + {{'GENERAL.VALIDATION.REQUIRED' | translate}} + +
+
+ + {{'REFERENCE-TYPE-EDITOR.FIELDS.PAGINATION-PATH' | translate}} + + + {{'GENERAL.VALIDATION.REQUIRED' | translate}} + +
+
+ + Content Type + + + {{'GENERAL.VALIDATION.REQUIRED' | translate}} + +
+
+ + First Page + + + {{'GENERAL.VALIDATION.REQUIRED' | translate}} + +
+
+ + Request Type + + + {{request}} + + + + {{'GENERAL.VALIDATION.REQUIRED' | translate}} + +
+
+ + Request Body + + + {{'GENERAL.VALIDATION.REQUIRED' | translate}} + +
+
+ + Filter Type + + + {{'GENERAL.VALIDATION.REQUIRED' | translate}} + +
+ + +

{{'REFERENCE-TYPE-EDITOR.FIELDS.RESULTS' | translate}} + +

+
+ + Results Path + + + {{'GENERAL.VALIDATION.REQUIRED' | translate}} + +
+ +
+
+
+ +
+
+

{{'REFERENCE-TYPE-EDITOR.FIELDS.FIELD-MAPPING' | translate}} {{fieldMappingIndex + 1}}

+
+ +
+ +
+
+
+ +
+
+ + {{'REFERENCE-TYPE-EDITOR.FIELDS.CODE' | translate}} + + + {{'GENERAL.VALIDATION.REQUIRED' | translate}} + +
+
+ + Response Path + + + {{'GENERAL.VALIDATION.REQUIRED' | translate}} + +
+
+
+
+
+
+ +

{{'REFERENCE-TYPE-EDITOR.FIELDS.AUTHENTICATION' | translate}}

+
+ + {{'REFERENCE-TYPE-EDITOR.FIELDS.URL' | translate}} + + + {{'GENERAL.VALIDATION.REQUIRED' | translate}} + +
+
+ + Method + + + {{'GENERAL.VALIDATION.REQUIRED' | translate}} + +
+
+ + Token Path + + + {{'GENERAL.VALIDATION.REQUIRED' | translate}} + +
+
+ + Request Body + + + {{'GENERAL.VALIDATION.REQUIRED' | translate}} + +
+
+ + Type + + + {{'GENERAL.VALIDATION.REQUIRED' | translate}} + +
+ + +

{{'REFERENCE-TYPE-EDITOR.FIELDS.QUERIES' | translate}} + +

+
+
+
+ +
+
+

{{'REFERENCE-TYPE-EDITOR.FIELDS.QUERY' | translate}} {{queryIndex + 1}}

+
+ +
+ +
+
+
+ +
+ + Condition + + + {{'GENERAL.VALIDATION.REQUIRED' | translate}} + +
+
+ + Separator + + + {{'GENERAL.VALIDATION.REQUIRED' | translate}} + +
+
+ + Value + + + {{'GENERAL.VALIDATION.REQUIRED' | translate}} + +
+
+ + Ordinal + + + {{'GENERAL.VALIDATION.REQUIRED' | translate}} + +
+
+
+
+
+ +
+
+
+
+
+
+
+
+ + + + diff --git a/dmp-frontend/src/app/ui/admin/reference-type/editor/reference-type-editor.component.scss b/dmp-frontend/src/app/ui/admin/reference-type/editor/reference-type-editor.component.scss new file mode 100644 index 000000000..4372160ca --- /dev/null +++ b/dmp-frontend/src/app/ui/admin/reference-type/editor/reference-type-editor.component.scss @@ -0,0 +1,116 @@ +.dmp-blueprint-editor { + margin-top: 1.3rem; + margin-left: 1em; + margin-right: 3em; + + .remove { + background-color: white; + color: black; + } + + .add { + background-color: white; + color: #009700; + } +} + +::ng-deep .mat-checkbox-checked.mat-accent .mat-checkbox-background, .mat-checkbox-indeterminate.mat-accent .mat-checkbox-background { + background-color: var(--primary-color-3); + // background-color: #0070c0; +} + +::ng-deep .mat-checkbox-disabled.mat-checkbox-checked .mat-checkbox-background, .mat-checkbox-disabled.mat-checkbox-indeterminate .mat-checkbox-background { + background-color: #b0b0b0; +} + +.finalize-btn { + border-radius: 30px; + border: 1px solid var(--primary-color); + background: transparent; + padding-left: 2em; + padding-right: 2em; + box-shadow: 0px 3px 6px #1E202029; + color: var(--primary-color); + &:disabled{ + background-color: #CBCBCB; + color: #FFF; + border: 0px; + } +} + +.action-btn { + border-radius: 30px; + background-color: var(--secondary-color); + border: 1px solid transparent; + padding-left: 2em; + padding-right: 2em; + box-shadow: 0px 3px 6px #1E202029; + + transition-property: background-color, color; + transition-duration: 200ms; + transition-delay: 50ms; + transition-timing-function: ease-in-out; + &:disabled{ + background-color: #CBCBCB; + color: #FFF; + border: 0px; + } +} + +.dlt-section-btn { + margin: 0; + position: absolute; + top: 50%; + -ms-transform: translateY(-50%); + transform: translateY(-50%); +} + +.section-input { + position: relative; +} + +.section-input .arrows { + position: absolute; + top: 0; + left: 50%; + transform: translateX(-50%); +} + +.action-list-item{ + display: flex; + align-items: center; + cursor: pointer; + + .action-list-icon{ + font-size: 1.2em; + // padding-right: 1em; + // width: 14px; + // margin-right: 0.5em; + // margin-left: -.09em; + // height: auto; + color: var(--primary-color); + } + + .action-list-text{ + font-size: 1em; + color: var(--primary-color); + } +} + +.field-delete{ + align-items: center; + display: flex; + cursor: pointer; + + .field-delete-icon{ + font-size: 1.2em; + width: 14px; + color: var(--primary-color); + } + + .field-delete-text{ + font-size: 1em; + margin-left: 0.5em; + color: var(--primary-color); + } +} \ No newline at end of file diff --git a/dmp-frontend/src/app/ui/admin/reference-type/editor/reference-type-editor.component.ts b/dmp-frontend/src/app/ui/admin/reference-type/editor/reference-type-editor.component.ts new file mode 100644 index 000000000..e4ff9be97 --- /dev/null +++ b/dmp-frontend/src/app/ui/admin/reference-type/editor/reference-type-editor.component.ts @@ -0,0 +1,281 @@ + +import { Component, OnInit } from '@angular/core'; +import { FormArray, UntypedFormGroup } from '@angular/forms'; +import { MatDialog } from '@angular/material/dialog'; +import { ActivatedRoute, Router } from '@angular/router'; +import { ReferenceTypeService } from '@app/core/services/reference-type/reference-type.service'; +import { SnackBarNotificationLevel, UiNotificationService } from '@app/core/services/notification/ui-notification-service'; +import { EnumUtils } from '@app/core/services/utilities/enum-utils.service'; +// import { BreadcrumbItem } from '@app/ui/misc/breadcrumb/definition/breadcrumb-item'; +import { CdkDragDrop, moveItemInArray } from '@angular/cdk/drag-drop'; +import { DatePipe } from '@angular/common'; +import { IsActive } from '@app/core/common/enum/is-active.enum'; +import { AppPermission } from '@app/core/common/enum/permission.enum'; +import { ReferenceType, ReferenceTypePersist } from '@app/core/model/reference-type/reference-type'; +import { AuthService } from '@app/core/services/auth/auth.service'; +import { LoggingService } from '@app/core/services/logging/logging-service'; +import { QueryParamsService } from '@app/core/services/utilities/query-params.service'; +import { BaseEditor } from '@common/base/base-editor'; +import { FormService } from '@common/forms/form-service'; +import { ConfirmationDialogComponent } from '@common/modules/confirmation-dialog/confirmation-dialog.component'; +import { HttpErrorHandlingService } from '@common/modules/errors/error-handling/http-error-handling.service'; +import { FilterService } from '@common/modules/text-filter/filter-service'; +import { Guid } from '@common/types/guid'; +import { TranslateService } from '@ngx-translate/core'; +import { map, takeUntil } from 'rxjs/operators'; +import { ReferenceTypeEditorResolver } from './reference-type-editor.resolver'; +import { ReferenceTypeEditorService } from './reference-type-editor.service'; +import { QueryConfigEditorModel, ReferenceTypeEditorModel, ReferenceTypeExternalApiConfigurationEditorModel, ReferenceTypeFieldEditorModel, ResultFieldsMappingConfigurationEditorModel } from './reference-type-editor.model'; +import { DmpBlueprintDefinitionSectionEditorModel } from '@app/ui/admin/dmp-blueprint/editor/dmp-blueprint-editor.model'; +import { ReferenceFieldDataType } from '@app/core/common/enum/reference-field-data-type'; + + +export interface visiblesDataType { + name: string; + type: ReferenceFieldDataType; +} + +@Component({ + selector: 'app-reference-type-editor-component', + templateUrl: 'reference-type-editor.component.html', + styleUrls: ['./reference-type-editor.component.scss'], + providers: [ReferenceTypeEditorService] +}) +export class ReferenceTypeEditorComponent extends BaseEditor implements OnInit { + + isNew = true; + isDeleted = false; + formGroup: UntypedFormGroup = null; + showInactiveDetails = false; + + protected get canDelete(): boolean { + return !this.isDeleted && !this.isNew && this.hasPermission(this.authService.permissionEnum.DeleteReferenceType); + } + + protected get canSave(): boolean { + return !this.isDeleted && this.hasPermission(this.authService.permissionEnum.EditReferenceType); + } + + protected get canFinalize(): boolean { + return !this.isDeleted && this.hasPermission(this.authService.permissionEnum.EditReferenceType); + } + + + private hasPermission(permission: AppPermission): boolean { + return this.authService.hasPermission(permission) || this.editorModel?.permissions?.includes(permission); + } + + constructor( + // BaseFormEditor injected dependencies + protected dialog: MatDialog, + protected language: TranslateService, + protected formService: FormService, + protected router: Router, + protected uiNotificationService: UiNotificationService, + protected httpErrorHandlingService: HttpErrorHandlingService, + protected filterService: FilterService, + protected datePipe: DatePipe, + protected route: ActivatedRoute, + protected queryParamsService: QueryParamsService, + // Rest dependencies. Inject any other needed deps here: + public authService: AuthService, + public enumUtils: EnumUtils, + private referenceTypeService: ReferenceTypeService, + private logger: LoggingService, + private referenceTypeEditorService: ReferenceTypeEditorService + ) { + super(dialog, language, formService, router, uiNotificationService, httpErrorHandlingService, filterService, datePipe, route, queryParamsService); + } + + visiblesDataTypes: visiblesDataType[] = [ + {name: "Text", type: ReferenceFieldDataType.Text}, + {name: "Date", type: ReferenceFieldDataType.Date}, + ] + + requestTypes: string[] = ["GET", "POST"] + + ngOnInit(): void { + super.ngOnInit(); + } + + getItem(itemId: Guid, successFunction: (item: ReferenceType) => void) { + this.referenceTypeService.getSingle(itemId, ReferenceTypeEditorResolver.lookupFields()) + .pipe(map(data => data as ReferenceType), takeUntil(this._destroyed)) + .subscribe( + data => successFunction(data), + error => this.onCallbackError(error) + ); + } + + prepareForm(data: ReferenceType) { + try { + this.editorModel = data ? new ReferenceTypeEditorModel().fromModel(data) : new ReferenceTypeEditorModel(); + this.isDeleted = data ? data.isActive === IsActive.Inactive : false; + this.buildForm(); + } catch (error) { + this.logger.error('Could not parse referenceType item: ' + data + error); + this.uiNotificationService.snackBarNotification(this.language.instant('COMMONS.ERRORS.DEFAULT'), SnackBarNotificationLevel.Error); + } + } + + buildForm() { + this.formGroup = this.editorModel.buildForm(null, this.isDeleted || !this.authService.hasPermission(AppPermission.EditReferenceType)); + console.log(this.formGroup.get('definition')); + this.referenceTypeEditorService.setValidationErrorModel(this.editorModel.validationErrorModel); + } + + refreshData(): void { + this.getItem(this.editorModel.id, (data: ReferenceType) => this.prepareForm(data)); + } + + refreshOnNavigateToData(id?: Guid): void { + this.formGroup.markAsPristine(); + let route = []; + + if (id === null) { + route.push('../..'); + } else if (this.isNew) { + route.push('../' + id); + } else { + route.push('..'); + } + + this.router.navigate(route, { queryParams: { 'lookup': this.queryParamsService.serializeLookup(this.lookupParams), 'lv': ++this.lv }, replaceUrl: true, relativeTo: this.route }); + } + + persistEntity(onSuccess?: (response) => void): void { + const formData = this.formService.getValue(this.formGroup.value) as ReferenceTypePersist; + console.log(formData); + // this.referenceTypeService.persist(formData) + // .pipe(takeUntil(this._destroyed)).subscribe( + // complete => onSuccess ? onSuccess(complete) : this.onCallbackSuccess(complete), + // error => this.onCallbackError(error) + // ); + } + + formSubmit(): void { + this.formService.touchAllFormFields(this.formGroup); + if (!this.isFormValid()) { + return; + } + + this.persistEntity(); + } + + public delete() { + const value = this.formGroup.value; + if (value.id) { + const dialogRef = this.dialog.open(ConfirmationDialogComponent, { + maxWidth: '300px', + data: { + message: this.language.instant('GENERAL.CONFIRMATION-DIALOG.DELETE-ITEM'), + confirmButton: this.language.instant('GENERAL.CONFIRMATION-DIALOG.ACTIONS.CONFIRM'), + cancelButton: this.language.instant('GENERAL.CONFIRMATION-DIALOG.ACTIONS.CANCEL') + } + }); + dialogRef.afterClosed().pipe(takeUntil(this._destroyed)).subscribe(result => { + if (result) { + this.referenceTypeService.delete(value.id).pipe(takeUntil(this._destroyed)) + .subscribe( + complete => this.onCallbackSuccess(), + error => this.onCallbackError(error) + ); + } + }); + } + } + + clearErrorModel() { + this.editorModel.validationErrorModel.clear(); + this.formService.validateAllFormFields(this.formGroup); + } + + // + // + // fields + // + // + addField(): void { + const field: ReferenceTypeFieldEditorModel = new ReferenceTypeFieldEditorModel(); + (this.formGroup.get('definition').get('fields') as FormArray).push(field.buildForm()); + } + + removeField(fieldIndex: number): void { + (this.formGroup.get('definition').get('fields') as FormArray).removeAt(fieldIndex); + } + + dropFields(event: CdkDragDrop) { + const fieldssFormArray = (this.formGroup.get('definition').get('fields') as FormArray); + + moveItemInArray(fieldssFormArray.controls, event.previousIndex, event.currentIndex); + fieldssFormArray.updateValueAndValidity(); + } + + + // + // + // externalApiConfig + // + // + addExternalApiConfig(): void { + const externalApiConfig: ReferenceTypeExternalApiConfigurationEditorModel = new ReferenceTypeExternalApiConfigurationEditorModel(); + (this.formGroup.get('definition').get('externalApiConfig') as FormArray).push(externalApiConfig.buildForm()); + this.addFieldMapping(0); + } + + removeExternalApiConfig(externalApiConfigIndex: number): void { + (this.formGroup.get('definition').get('externalApiConfig') as FormArray).removeAt(externalApiConfigIndex); + } + + dropExternalApiConfig(event: CdkDragDrop) { + const fieldssFormArray = (this.formGroup.get('definition').get('externalApiConfig') as FormArray); + + moveItemInArray(fieldssFormArray.controls, event.previousIndex, event.currentIndex); + fieldssFormArray.updateValueAndValidity(); + } + + // + // + // resultFieldsMapping + // + // + addFieldMapping(externalApiConfigIndex: number): void { + const fieldMapping: ResultFieldsMappingConfigurationEditorModel = new ResultFieldsMappingConfigurationEditorModel(); + ((this.formGroup.get('definition').get('externalApiConfig') as FormArray).at(externalApiConfigIndex).get('results').get('fieldsMapping') as FormArray).push(fieldMapping.buildForm()); + } + + removeFieldMapping(externalApiConfigIndex: number, fieldMappingIndex: number): void { + const formArray = ((this.formGroup.get('definition').get('externalApiConfig') as FormArray).at(externalApiConfigIndex) as FormArray); + (formArray.get('results').get('fieldsMapping') as FormArray).removeAt(fieldMappingIndex); + } + + dropFieldsMapping(event: CdkDragDrop) { + const fieldssFormArray = (this.formGroup.get('definition').get('externalApiConfig').get('fieldsMapping') as FormArray); + + moveItemInArray(fieldssFormArray.controls, event.previousIndex, event.currentIndex); + fieldssFormArray.updateValueAndValidity(); + } + + + // + // + // queries + // + // + addQuery(externalApiConfigIndex: number): void { + const query: QueryConfigEditorModel = new QueryConfigEditorModel(); + ((this.formGroup.get('definition').get('externalApiConfig') as FormArray).at(externalApiConfigIndex).get('queries') as FormArray).push(query.buildForm()); + } + + removeQuery(externalApiConfigIndex: number, fieldMappingIndex: number): void { + const formArray = ((this.formGroup.get('definition').get('externalApiConfig') as FormArray).at(externalApiConfigIndex).get('queries') as FormArray); + formArray.removeAt(fieldMappingIndex); + } + + dropQueries(event: CdkDragDrop) { + const fieldssFormArray = (this.formGroup.get('definition').get('externalApiConfig').get('queries') as FormArray); + + moveItemInArray(fieldssFormArray.controls, event.previousIndex, event.currentIndex); + fieldssFormArray.updateValueAndValidity(); + } +} diff --git a/dmp-frontend/src/app/ui/admin/reference-type/editor/reference-type-editor.model.ts b/dmp-frontend/src/app/ui/admin/reference-type/editor/reference-type-editor.model.ts new file mode 100644 index 000000000..46a67d689 --- /dev/null +++ b/dmp-frontend/src/app/ui/admin/reference-type/editor/reference-type-editor.model.ts @@ -0,0 +1,525 @@ +import { UntypedFormBuilder, UntypedFormGroup, Validators } from "@angular/forms"; +import { ReferenceFieldDataType } from "@app/core/common/enum/reference-field-data-type"; +import { ReferenceType, ReferenceTypeDefinition, ReferenceTypeDefinitionPersist, ReferenceTypePersist, ReferenceTypeFieldPersist,ReferenceTypeField, AuthenticationConfiguration, AuthenticationConfigurationPersist, QueryConfigPersist, QueryConfig, ReferenceTypeExternalApiConfigurationPersist, ResultsConfigurationPersist, ResultFieldsMappingConfigurationPersist, ReferenceTypeExternalApiConfiguration, ResultsConfiguration, ResultFieldsMappingConfiguration } from "@app/core/model/reference-type/reference-type"; +import { BaseEditorModel } from "@common/base/base-form-editor-model"; +import { BackendErrorValidator } from "@common/forms/validation/custom-validator"; +import { ValidationErrorModel } from "@common/forms/validation/error-model/validation-error-model"; +import { Validation, ValidationContext } from "@common/forms/validation/validation-context"; + +export class ReferenceTypeEditorModel extends BaseEditorModel implements ReferenceTypePersist { + name: string; + code: string; + definition: ReferenceTypeDefinitionEditorModel = new ReferenceTypeDefinitionEditorModel(); + + permissions: string[]; + + public validationErrorModel: ValidationErrorModel = new ValidationErrorModel(); + protected formBuilder: UntypedFormBuilder = new UntypedFormBuilder(); + + constructor() { super(); } + + public fromModel(item: ReferenceType): ReferenceTypeEditorModel { + if (item) { + super.fromModel(item); + this.name = item.name; + this.code = item.code; + this.definition = new ReferenceTypeDefinitionEditorModel().fromModel(item.definition); + } + return this; + } + + buildForm(context: ValidationContext = null, disabled: boolean = false): UntypedFormGroup { + if (context == null) { context = this.createValidationContext(); } + + return this.formBuilder.group({ + id: [{ value: this.id, disabled: disabled }, context.getValidation('id').validators], + name: [{ value: this.name, disabled: disabled }, context.getValidation('name').validators], + code: [{ value: this.code, disabled: disabled }, context.getValidation('code').validators], + definition: this.definition.buildForm({ + rootPath: `definition.` + }) + }); + } + + createValidationContext(): ValidationContext { + const baseContext: ValidationContext = new ValidationContext(); + const baseValidationArray: Validation[] = new Array(); + baseValidationArray.push({ key: 'id', validators: [BackendErrorValidator(this.validationErrorModel, 'id')] }); + baseValidationArray.push({ key: 'name', validators: [Validators.required, BackendErrorValidator(this.validationErrorModel, 'name')] }); + baseValidationArray.push({ key: 'code', validators: [Validators.required, BackendErrorValidator(this.validationErrorModel, 'code')] }); + + baseContext.validation = baseValidationArray; + return baseContext; + } +} + +export class ReferenceTypeDefinitionEditorModel implements ReferenceTypeDefinitionPersist { + fields: ReferenceTypeFieldEditorModel[] = []; + externalApiConfig: ReferenceTypeExternalApiConfigurationEditorModel[] = []; + + protected formBuilder: UntypedFormBuilder = new UntypedFormBuilder(); + + constructor( + public validationErrorModel: ValidationErrorModel = new ValidationErrorModel() + ) { } + + public fromModel(item: ReferenceTypeDefinition): ReferenceTypeDefinitionEditorModel { + if (item) { + if (item.fields) { item.fields.map(x => this.fields.push(new ReferenceTypeFieldEditorModel().fromModel(x))); } + if(item.externalApiConfig) { item.externalApiConfig.map(x => this.externalApiConfig.push(new ReferenceTypeExternalApiConfigurationEditorModel().fromModel(x))); } + } + return this; + } + + buildForm(params?: { + context?: ValidationContext, + disabled?: boolean, + rootPath?: string + }): UntypedFormGroup { + let { context = null, disabled = false, rootPath } = params ?? {} + if (context == null) { + context = ReferenceTypeDefinitionEditorModel.createValidationContext({ + validationErrorModel: this.validationErrorModel, + rootPath + }); + } + + return this.formBuilder.group({ + fields: this.formBuilder.array( + (this.fields ?? []).map( + (item, index) => new ReferenceTypeFieldEditorModel( + this.validationErrorModel + ).fromModel(item).buildForm({ + rootPath: `fields[${index}].` + }), context.getValidation('fields') + ) + ), + externalApiConfig: this.formBuilder.array( + (this.externalApiConfig ?? []).map( + (item, index) => new ReferenceTypeExternalApiConfigurationEditorModel( + this.validationErrorModel + ).fromModel(item).buildForm({ + rootPath: `externalApiConfig[${index}].` + }), context.getValidation('externalApiConfig') + ) + ) + }); + } + + static createValidationContext(params: { + rootPath?: string, + validationErrorModel: ValidationErrorModel + }): ValidationContext { + const { rootPath = '', validationErrorModel } = params; + + const baseContext: ValidationContext = new ValidationContext(); + const baseValidationArray: Validation[] = new Array(); + baseValidationArray.push({ key: 'fields', validators: [Validators.required, BackendErrorValidator(validationErrorModel, `${rootPath}fields`)] }); + baseValidationArray.push({ key: 'externalApiConfig', validators: [BackendErrorValidator(validationErrorModel, `${rootPath}externalApiConfig`)] }); + + baseContext.validation = baseValidationArray; + return baseContext; + } + +} + +export class ReferenceTypeFieldEditorModel implements ReferenceTypeFieldPersist { + code: string; + dataType: ReferenceFieldDataType; + + protected formBuilder: UntypedFormBuilder = new UntypedFormBuilder(); + + constructor( + public validationErrorModel: ValidationErrorModel = new ValidationErrorModel() + ) { } + + public fromModel(item: ReferenceTypeField): ReferenceTypeFieldEditorModel { + if (item) { + this.code = item.code; + this.dataType = item.dataType; + } + return this; + } + + buildForm(params?: { + context?: ValidationContext, + disabled?: boolean, + rootPath?: string + }): UntypedFormGroup { + let { context = null, disabled = false, rootPath } = params ?? {} + if (context == null) { + context = ReferenceTypeFieldEditorModel.createValidationContext({ + validationErrorModel: this.validationErrorModel, + rootPath + }); + } + + return this.formBuilder.group({ + code: [{ value: this.code, disabled: disabled }, context.getValidation('code').validators], + dataType: [{ value: this.dataType, disabled: disabled }, context.getValidation('dataType').validators], + }); + } + + static createValidationContext(params: { + rootPath?: string, + validationErrorModel: ValidationErrorModel + }): ValidationContext { + const { rootPath = '', validationErrorModel } = params; + + const baseContext: ValidationContext = new ValidationContext(); + const baseValidationArray: Validation[] = new Array(); + baseValidationArray.push({ key: 'code', validators: [Validators.required, BackendErrorValidator(validationErrorModel, `${rootPath}code`)] }); + baseValidationArray.push({ key: 'dataType', validators: [Validators.required,BackendErrorValidator(validationErrorModel, `${rootPath}dataType`)] }); + + baseContext.validation = baseValidationArray; + return baseContext; + } + +} + +export class ReferenceTypeExternalApiConfigurationEditorModel implements ReferenceTypeExternalApiConfigurationPersist { + public key: string; + public label: string; + public ordinal: number; + public url: string; + public results: ResultsConfigurationEditorModel = new ResultsConfigurationEditorModel(); + public type: string; + public paginationPath: string; + public contentType: string; + public firstPage: string; + public requestType?: string; + public requestBody?: string; + public filterType?: string; + public auth: AuthenticationConfigurationEditorModel = new AuthenticationConfigurationEditorModel(); + public queries?: QueryConfigEditorModel[] = []; + + protected formBuilder: UntypedFormBuilder = new UntypedFormBuilder(); + + constructor( + public validationErrorModel: ValidationErrorModel = new ValidationErrorModel() + ) { } + + fromModel(item: ReferenceTypeExternalApiConfiguration): ReferenceTypeExternalApiConfigurationEditorModel { + this.key = item.key; + this.label = item.label; + this.ordinal = item.ordinal; + this.url = item.url; + this.results = new ResultsConfigurationEditorModel().fromModel(item.results); + this.type = item.type; + this.paginationPath = item.paginationPath; + this.contentType = item.contentType; + this.firstPage = item.firstPage; + this.requestType = item.requestType; + this.requestBody = item.requestBody; + this.filterType = item.filterType; + this.auth = new AuthenticationConfigurationEditorModel().fromModel(item.auth); + if(item.queries) { item.queries.map(x => this.queries.push(new QueryConfigEditorModel().fromModel(x))); } + + return this; + } + + buildForm(params?: { + context?: ValidationContext, + disabled?: boolean, + rootPath?: string + }): UntypedFormGroup { + let { context = null, disabled = false, rootPath } = params ?? {} + if (context == null) { + context = ReferenceTypeExternalApiConfigurationEditorModel.createValidationContext({ + validationErrorModel: this.validationErrorModel, + rootPath + }); + } + + + return this.formBuilder.group({ + key: [{ value: this.key, disabled: disabled }, context.getValidation('key').validators], + label: [{ value: this.label, disabled: disabled }, context.getValidation('label').validators], + ordinal: [{ value: this.ordinal, disabled: disabled }, context.getValidation('ordinal').validators], + url: [{ value: this.url, disabled: disabled }, context.getValidation('url').validators], + results: this.results.buildForm({ + rootPath: `results.` + }), + type: [{ value: this.type, disabled: disabled }, context.getValidation('type').validators], + paginationPath: [{ value: this.paginationPath, disabled: disabled }, context.getValidation('paginationPath').validators], + contentType: [{ value: this.contentType, disabled: disabled }, context.getValidation('contentType').validators], + firstPage: [{ value: this.firstPage, disabled: disabled }, context.getValidation('firstPage').validators], + requestType: [{ value: this.requestType, disabled: disabled }, context.getValidation('requestType').validators], + requestBody: [{ value: this.requestBody, disabled: disabled }, context.getValidation('requestBody').validators], + filterType: [{ value: this.filterType, disabled: disabled }, context.getValidation('filterType').validators], + auth: this.auth.buildForm({ + rootPath: `auth.` + }), + queries: this.formBuilder.array( + (this.queries ?? []).map( + (item, index) => new QueryConfigEditorModel( + this.validationErrorModel + ).fromModel(item).buildForm({ + rootPath: `queries[${index}].` + }), context.getValidation('queries') + ) + ) + }); + } + + static createValidationContext(params: { + rootPath?: string, + validationErrorModel: ValidationErrorModel + }): ValidationContext { + const { rootPath = '', validationErrorModel } = params; + + const baseContext: ValidationContext = new ValidationContext(); + const baseValidationArray: Validation[] = new Array(); + baseValidationArray.push({ key: 'key', validators: [Validators.required, BackendErrorValidator(validationErrorModel, `${rootPath}key`)] }); + baseValidationArray.push({ key: 'label', validators: [Validators.required, BackendErrorValidator(validationErrorModel, `${rootPath}label`)] }); + baseValidationArray.push({ key: 'ordinal', validators: [Validators.required, Validators.pattern("^[0-9]*$"), BackendErrorValidator(validationErrorModel, `${rootPath}ordinal`)] }); + baseValidationArray.push({ key: 'url', validators: [Validators.required, BackendErrorValidator(validationErrorModel, `${rootPath}url`)] }); + baseValidationArray.push({ key: 'type', validators: [Validators.required, BackendErrorValidator(validationErrorModel, `${rootPath}type`)] }); + baseValidationArray.push({ key: 'paginationPath', validators: [Validators.required, BackendErrorValidator(validationErrorModel, `${rootPath}paginationPath`)] }); + baseValidationArray.push({ key: 'contentType', validators: [Validators.required, BackendErrorValidator(validationErrorModel, `${rootPath}contentType`)] }); + baseValidationArray.push({ key: 'firstPage', validators: [Validators.required, Validators.pattern("^[0-9]*$"), BackendErrorValidator(validationErrorModel, `${rootPath}firstPage`)] }); + baseValidationArray.push({ key: 'requestType', validators: [BackendErrorValidator(validationErrorModel, `${rootPath}requestType`)] }); + baseValidationArray.push({ key: 'requestBody', validators: [BackendErrorValidator(validationErrorModel, `${rootPath}requestBody`)] }); + baseValidationArray.push({ key: 'filterType', validators: [BackendErrorValidator(validationErrorModel, `${rootPath}filterType`)] }); + baseValidationArray.push({ key: 'queries', validators: [BackendErrorValidator(validationErrorModel, `${rootPath}queries`)] }); + + baseContext.validation = baseValidationArray; + return baseContext; + } +} + +export class ResultsConfigurationEditorModel implements ResultsConfigurationPersist { + public resultsArrayPath: string; + public fieldsMapping: ResultFieldsMappingConfigurationEditorModel[] =[]; + + protected formBuilder: UntypedFormBuilder = new UntypedFormBuilder(); + + constructor( + public validationErrorModel: ValidationErrorModel = new ValidationErrorModel() + ) { } + + fromModel(item: ResultsConfiguration): ResultsConfigurationEditorModel { + this.resultsArrayPath = item.resultsArrayPath; + if(item.fieldsMapping) { item.fieldsMapping.map(x => this.fieldsMapping.push(new ResultFieldsMappingConfigurationEditorModel().fromModel(x))); } + return this; + } + + buildForm(params?: { + context?: ValidationContext, + disabled?: boolean, + rootPath?: string + }): UntypedFormGroup { + let { context = null, disabled = false, rootPath } = params ?? {} + if (context == null) { + context = ResultsConfigurationEditorModel.createValidationContext({ + validationErrorModel: this.validationErrorModel, + rootPath + }); + } + + return this.formBuilder.group({ + resultsArrayPath: [{ value: this.resultsArrayPath, disabled: disabled }, context.getValidation('resultsArrayPath').validators], + fieldsMapping: this.formBuilder.array( + (this.fieldsMapping ?? []).map( + (item, index) => new ResultFieldsMappingConfigurationEditorModel( + this.validationErrorModel + ).fromModel(item).buildForm({ + rootPath: `fieldsMapping[${index}].` + }), context.getValidation('fieldsMapping') + ) + ) + + }); + } + + static createValidationContext(params: { + rootPath?: string, + validationErrorModel: ValidationErrorModel + }): ValidationContext { + const { rootPath = '', validationErrorModel } = params; + + const baseContext: ValidationContext = new ValidationContext(); + const baseValidationArray: Validation[] = new Array(); + baseValidationArray.push({ key: 'resultsArrayPath', validators: [Validators.required, BackendErrorValidator(validationErrorModel, `${rootPath}resultsArrayPath`)] }); + baseValidationArray.push({ key: 'fieldsMapping', validators: [Validators.required, BackendErrorValidator(validationErrorModel, `${rootPath}fieldsMapping`)] }); + + baseContext.validation = baseValidationArray; + return baseContext; + } +} + +export class ResultFieldsMappingConfigurationEditorModel implements ResultFieldsMappingConfigurationPersist { + public code: string; + public responsePath: string; + + protected formBuilder: UntypedFormBuilder = new UntypedFormBuilder(); + + constructor( + public validationErrorModel: ValidationErrorModel = new ValidationErrorModel() + ) { } + + fromModel(item: ResultFieldsMappingConfiguration): ResultFieldsMappingConfigurationEditorModel { + this.code = item.code; + this.responsePath = item.responsePath; + + return this; + } + + buildForm(params?: { + context?: ValidationContext, + disabled?: boolean, + rootPath?: string + }): UntypedFormGroup { + let { context = null, disabled = false, rootPath } = params ?? {} + if (context == null) { + context = ResultFieldsMappingConfigurationEditorModel.createValidationContext({ + validationErrorModel: this.validationErrorModel, + rootPath + }); + } + + return this.formBuilder.group({ + code: [{ value: this.code, disabled: disabled }, context.getValidation('code').validators], + responsePath: [{ value: this.responsePath, disabled: disabled }, context.getValidation('responsePath').validators], + }); + } + + static createValidationContext(params: { + rootPath?: string, + validationErrorModel: ValidationErrorModel + }): ValidationContext { + const { rootPath = '', validationErrorModel } = params; + + const baseContext: ValidationContext = new ValidationContext(); + const baseValidationArray: Validation[] = new Array(); + baseValidationArray.push({ key: 'code', validators: [Validators.required, BackendErrorValidator(validationErrorModel, `${rootPath}code`)] }); + baseValidationArray.push({ key: 'responsePath', validators: [Validators.required, BackendErrorValidator(validationErrorModel, `${rootPath}responsePath`)] }); + + baseContext.validation = baseValidationArray; + return baseContext; + } +} + +export class AuthenticationConfigurationEditorModel implements AuthenticationConfigurationPersist { + public authUrl: string; + public authMethod: string; + public authTokenPath: string; + public authRequestBody: string; + public type: string; + + protected formBuilder: UntypedFormBuilder = new UntypedFormBuilder(); + + constructor( + public validationErrorModel: ValidationErrorModel = new ValidationErrorModel() + ) { } + + fromModel(item: AuthenticationConfiguration): AuthenticationConfigurationEditorModel { + this.authUrl = item.authUrl; + this.authMethod = item.authMethod; + this.authTokenPath = item.authTokenPath; + this.authRequestBody = item.authRequestBody; + this.type = item.type; + + return this; + } + + buildForm(params?: { + context?: ValidationContext, + disabled?: boolean, + rootPath?: string + }): UntypedFormGroup { + let { context = null, disabled = false, rootPath } = params ?? {} + if (context == null) { + context = AuthenticationConfigurationEditorModel.createValidationContext({ + validationErrorModel: this.validationErrorModel, + rootPath + }); + } + + return this.formBuilder.group({ + authUrl: [{ value: this.authUrl, disabled: disabled }, context.getValidation('authUrl').validators], + authMethod: [{ value: this.authMethod, disabled: disabled }, context.getValidation('authMethod').validators], + authTokenPath: [{ value: this.authTokenPath, disabled: disabled }, context.getValidation('authTokenPath').validators], + authRequestBody: [{ value: this.authRequestBody, disabled: disabled }, context.getValidation('authRequestBody').validators], + type: [{ value: this.type, disabled: disabled }, context.getValidation('type').validators], + }); + } + + static createValidationContext(params: { + rootPath?: string, + validationErrorModel: ValidationErrorModel + }): ValidationContext { + const { rootPath = '', validationErrorModel } = params; + + const baseContext: ValidationContext = new ValidationContext(); + const baseValidationArray: Validation[] = new Array(); + baseValidationArray.push({ key: 'authUrl', validators: [Validators.required, BackendErrorValidator(validationErrorModel, `${rootPath}authUrl`)] }); + baseValidationArray.push({ key: 'authMethod', validators: [BackendErrorValidator(validationErrorModel, `${rootPath}authMethod`)] }); + baseValidationArray.push({ key: 'authTokenPath', validators: [Validators.required, BackendErrorValidator(validationErrorModel, `${rootPath}authTokenPath`)] }); + baseValidationArray.push({ key: 'authRequestBody', validators: [Validators.required, BackendErrorValidator(validationErrorModel, `${rootPath}authRequestBody`)] }); + baseValidationArray.push({ key: 'type', validators: [Validators.required, BackendErrorValidator(validationErrorModel, `${rootPath}type`)] }); + + baseContext.validation = baseValidationArray; + return baseContext; + } +} + +export class QueryConfigEditorModel implements QueryConfigPersist { + public condition: string; + public separator: string; + public value: string; + public ordinal: number; + + protected formBuilder: UntypedFormBuilder = new UntypedFormBuilder(); + + constructor( + public validationErrorModel: ValidationErrorModel = new ValidationErrorModel() + ) { } + + fromModel(item: QueryConfig): QueryConfigEditorModel { + this.condition = item.condition; + this.separator = item.separator; + this.value = item.value; + this.ordinal = item.ordinal; + + return this; + } + + buildForm(params?: { + context?: ValidationContext, + disabled?: boolean, + rootPath?: string + }): UntypedFormGroup { + let { context = null, disabled = false, rootPath } = params ?? {} + if (context == null) { + context = QueryConfigEditorModel.createValidationContext({ + validationErrorModel: this.validationErrorModel, + rootPath + }); + } + + return this.formBuilder.group({ + condition: [{ value: this.condition, disabled: disabled }, context.getValidation('condition').validators], + separator: [{ value: this.separator, disabled: disabled }, context.getValidation('separator').validators], + value: [{ value: this.value, disabled: disabled }, context.getValidation('value').validators], + ordinal: [{ value: this.ordinal, disabled: disabled }, context.getValidation('ordinal').validators], + }); + } + + static createValidationContext(params: { + rootPath?: string, + validationErrorModel: ValidationErrorModel + }): ValidationContext { + const { rootPath = '', validationErrorModel } = params; + + const baseContext: ValidationContext = new ValidationContext(); + const baseValidationArray: Validation[] = new Array(); + baseValidationArray.push({ key: 'condition', validators: [Validators.required, BackendErrorValidator(validationErrorModel, `${rootPath}condition`)] }); + baseValidationArray.push({ key: 'separator', validators: [Validators.required, BackendErrorValidator(validationErrorModel, `${rootPath}separator`)] }); + baseValidationArray.push({ key: 'value', validators: [Validators.required, BackendErrorValidator(validationErrorModel, `${rootPath}value`)] }); + baseValidationArray.push({ key: 'ordinal', validators: [Validators.required, Validators.pattern("^[0-9]*$"), BackendErrorValidator(validationErrorModel, `${rootPath}ordinal`)] }); + + baseContext.validation = baseValidationArray; + return baseContext; + } +} \ No newline at end of file diff --git a/dmp-frontend/src/app/ui/admin/reference-type/editor/reference-type-editor.resolver.ts b/dmp-frontend/src/app/ui/admin/reference-type/editor/reference-type-editor.resolver.ts new file mode 100644 index 000000000..9f5854885 --- /dev/null +++ b/dmp-frontend/src/app/ui/admin/reference-type/editor/reference-type-editor.resolver.ts @@ -0,0 +1,77 @@ +import { Injectable } from '@angular/core'; +import { ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router'; +import { AuthenticationConfiguration, QueryConfig, ReferenceType, ReferenceTypeDefinition, ReferenceTypeField, ReferenceTypeExternalApiConfiguration, ResultsConfiguration, ResultFieldsMappingConfiguration } from '@app/core/model/reference-type/reference-type'; +import { ReferenceTypeService } from '@app/core/services/reference-type/reference-type.service'; +import { BreadcrumbService } from '@app/ui/misc/breadcrumb/breadcrumb.service'; +import { BaseEditorResolver } from '@common/base/base-editor.resolver'; +import { Guid } from '@common/types/guid'; +import { takeUntil, tap } from 'rxjs/operators'; +import { nameof } from 'ts-simple-nameof'; + +@Injectable() +export class ReferenceTypeEditorResolver extends BaseEditorResolver { + + constructor(private ReferenceTypeService: ReferenceTypeService, private breadcrumbService: BreadcrumbService) { + super(); + } + + public static lookupFields(): string[] { + return [ + ...BaseEditorResolver.lookupFields(), + nameof(x => x.id), + nameof(x => x.name), + nameof(x => x.code), + + [nameof(x => x.definition), nameof(x => x.fields), nameof(x => x.code)].join('.'), + [nameof(x => x.definition), nameof(x => x.fields), nameof(x => x.dataType)].join('.'), + + [nameof(x => x.definition), nameof(x => x.externalApiConfig), nameof(x => x.key)].join('.'), + [nameof(x => x.definition), nameof(x => x.externalApiConfig), nameof(x => x.label)].join('.'), + [nameof(x => x.definition), nameof(x => x.externalApiConfig), nameof(x => x.ordinal)].join('.'), + [nameof(x => x.definition), nameof(x => x.externalApiConfig), nameof(x => x.url)].join('.'), + + [nameof(x => x.definition), nameof(x => x.externalApiConfig), nameof(x => x.results), nameof(x => x.resultsArrayPath)].join('.'), + + [nameof(x => x.definition), nameof(x => x.externalApiConfig), nameof(x => x.results), nameof(x => x.fieldsMapping), nameof(x => x.code)].join('.'), + [nameof(x => x.definition), nameof(x => x.externalApiConfig), nameof(x => x.results), nameof(x => x.fieldsMapping), nameof(x => x.responsePath)].join('.'), + + [nameof(x => x.definition), nameof(x => x.externalApiConfig), nameof(x => x.type)].join('.'), + [nameof(x => x.definition), nameof(x => x.externalApiConfig), nameof(x => x.paginationPath)].join('.'), + [nameof(x => x.definition), nameof(x => x.externalApiConfig), nameof(x => x.contentType)].join('.'), + [nameof(x => x.definition), nameof(x => x.externalApiConfig), nameof(x => x.firstPage)].join('.'), + [nameof(x => x.definition), nameof(x => x.externalApiConfig), nameof(x => x.requestType)].join('.'), + [nameof(x => x.definition), nameof(x => x.externalApiConfig), nameof(x => x.requestBody)].join('.'), + [nameof(x => x.definition), nameof(x => x.externalApiConfig), nameof(x => x.filterType)].join('.'), + + [nameof(x => x.definition), nameof(x => x.externalApiConfig), nameof(x => x.results),nameof(x => x.authUrl)].join('.'), + [nameof(x => x.definition), nameof(x => x.externalApiConfig), nameof(x => x.results),nameof(x => x.authMethod)].join('.'), + [nameof(x => x.definition), nameof(x => x.externalApiConfig), nameof(x => x.results),nameof(x => x.authTokenPath)].join('.'), + [nameof(x => x.definition), nameof(x => x.externalApiConfig), nameof(x => x.results),nameof(x => x.authRequestBody)].join('.'), + [nameof(x => x.definition), nameof(x => x.externalApiConfig), nameof(x => x.results),nameof(x => x.type)].join('.'), + + [nameof(x => x.definition), nameof(x => x.externalApiConfig), nameof(x => x.results),nameof(x => x.condition)].join('.'), + [nameof(x => x.definition), nameof(x => x.externalApiConfig), nameof(x => x.results),nameof(x => x.separator)].join('.'), + [nameof(x => x.definition), nameof(x => x.externalApiConfig), nameof(x => x.results),nameof(x => x.value)].join('.'), + [nameof(x => x.definition), nameof(x => x.externalApiConfig), nameof(x => x.results),nameof(x => x.ordinal)].join('.'), + + nameof(x => x.createdAt), + nameof(x => x.updatedAt), + nameof(x => x.isActive) + ] + } + + resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) { + + const fields = [ + ...ReferenceTypeEditorResolver.lookupFields() + ]; + const id = route.paramMap.get('id'); + //const cloneid = route.paramMap.get('cloneid'); + if (id != null) { + return this.ReferenceTypeService.getSingle(Guid.parse(id), fields).pipe(tap(x => this.breadcrumbService.addIdResolvedValue(x.id?.toString(), x.code)), takeUntil(this._destroyed)); + } + // } else if (cloneid != null) { + // return this.ReferenceTypeService.clone(Guid.parse(cloneid), fields).pipe(tap(x => this.breadcrumbService.addIdResolvedValue(x.id?.toString(), x.label)), takeUntil(this._destroyed)); + // } + } +} diff --git a/dmp-frontend/src/app/ui/admin/reference-type/editor/reference-type-editor.service.ts b/dmp-frontend/src/app/ui/admin/reference-type/editor/reference-type-editor.service.ts new file mode 100644 index 000000000..e7f779057 --- /dev/null +++ b/dmp-frontend/src/app/ui/admin/reference-type/editor/reference-type-editor.service.ts @@ -0,0 +1,15 @@ +import { Injectable } from "@angular/core"; +import { ValidationErrorModel } from "@common/forms/validation/error-model/validation-error-model"; + +@Injectable() +export class ReferenceTypeEditorService { + private validationErrorModel: ValidationErrorModel; + + public setValidationErrorModel(validationErrorModel: ValidationErrorModel): void { + this.validationErrorModel = validationErrorModel; + } + + public getValidationErrorModel(): ValidationErrorModel { + return this.validationErrorModel; + } +} diff --git a/dmp-frontend/src/app/ui/admin/reference-type/listing/filters/reference-type-listing-filters.component.html b/dmp-frontend/src/app/ui/admin/reference-type/listing/filters/reference-type-listing-filters.component.html new file mode 100644 index 000000000..ff9454bac --- /dev/null +++ b/dmp-frontend/src/app/ui/admin/reference-type/listing/filters/reference-type-listing-filters.component.html @@ -0,0 +1,36 @@ +
+ + + + + +
+
+
+

{{'REFERENCE-TYPE-LISTING.FILTER.TITLE' | translate}}

+ +
+ + + {{'REFERENCE-TYPE-LISTING.FILTER.IS-ACTIVE' | translate}} + + +
+ + +
+
+
+
+ + +
diff --git a/dmp-frontend/src/app/ui/admin/reference-type/listing/filters/reference-type-listing-filters.component.scss b/dmp-frontend/src/app/ui/admin/reference-type/listing/filters/reference-type-listing-filters.component.scss new file mode 100644 index 000000000..999f5a7c6 --- /dev/null +++ b/dmp-frontend/src/app/ui/admin/reference-type/listing/filters/reference-type-listing-filters.component.scss @@ -0,0 +1,25 @@ +.description-template-type-listing-filters { + +} + +::ng-deep.mat-mdc-menu-panel { + max-width: 100% !important; + height: 100% !important; +} + +:host::ng-deep.mat-mdc-menu-content:not(:empty) { + padding-top: 0 !important; +} + + +.filter-button{ + padding-top: .6rem; + padding-bottom: .6rem; + // .mat-icon{ + // font-size: 1.5em; + // width: 1.2em; + // height: 1.2em; + // } +} + + diff --git a/dmp-frontend/src/app/ui/admin/reference-type/listing/filters/reference-type-listing-filters.component.ts b/dmp-frontend/src/app/ui/admin/reference-type/listing/filters/reference-type-listing-filters.component.ts new file mode 100644 index 000000000..5a0cf7f66 --- /dev/null +++ b/dmp-frontend/src/app/ui/admin/reference-type/listing/filters/reference-type-listing-filters.component.ts @@ -0,0 +1,94 @@ +import { Component, EventEmitter, Input, OnChanges, OnInit, Output, SimpleChanges } from '@angular/core'; +import { IsActive } from '@app/core/common/enum/is-active.enum'; +import { ReferenceTypeFilter } from '@app/core/query/reference-type.lookup'; +import { EnumUtils } from '@app/core/services/utilities/enum-utils.service'; +import { BaseComponent } from '@common/base/base.component'; +import { nameof } from 'ts-simple-nameof'; + +@Component({ + selector: 'app-reference-type-listing-filters', + templateUrl: './reference-type-listing-filters.component.html', + styleUrls: ['./reference-type-listing-filters.component.scss'] +}) +export class ReferenceTypeListingFiltersComponent extends BaseComponent implements OnInit, OnChanges { + + @Input() readonly filter: ReferenceTypeFilter; + @Output() filterChange = new EventEmitter(); + + // * State + internalFilters: ReferenceTypeListingFilters = this._getEmptyFilters(); + + protected appliedFilterCount: number = 0; + constructor( + public enumUtils: EnumUtils, + ) { super(); } + + ngOnInit() { + } + + ngOnChanges(changes: SimpleChanges): void { + const filterChange = changes[nameof(x => x.filter)]?.currentValue as ReferenceTypeFilter; + if (filterChange) { + this.updateFilters() + } + } + + + onSearchTermChange(searchTerm: string): void { + this.applyFilters() + } + + + protected updateFilters(): void { + this.internalFilters = this._parseToInternalFilters(this.filter); + this.appliedFilterCount = this._computeAppliedFilters(this.internalFilters); + } + + protected applyFilters(): void { + const { isActive, like } = this.internalFilters ?? {} + this.filterChange.emit({ + ...this.filter, + like, + isActive: isActive ? [IsActive.Active] : [IsActive.Inactive] + }) + } + + + private _parseToInternalFilters(inputFilter: ReferenceTypeFilter): ReferenceTypeListingFilters { + if (!inputFilter) { + return this._getEmptyFilters(); + } + + let { excludedIds, ids, isActive, like } = inputFilter; + + return { + isActive: (isActive ?? [])?.includes(IsActive.Active) || !isActive?.length, + like: like + } + + } + + private _getEmptyFilters(): ReferenceTypeListingFilters { + return { + isActive: true, + like: null, + } + } + + private _computeAppliedFilters(filters: ReferenceTypeListingFilters): number { + let count = 0; + if (filters?.isActive) { + count++ + } + return count; + } + + clearFilters() { + this.internalFilters = this._getEmptyFilters(); + } +} + +interface ReferenceTypeListingFilters { + isActive: boolean; + like: string; +} diff --git a/dmp-frontend/src/app/ui/admin/reference-type/listing/reference-type-listing.component.html b/dmp-frontend/src/app/ui/admin/reference-type/listing/reference-type-listing.component.html new file mode 100644 index 000000000..0c2430644 --- /dev/null +++ b/dmp-frontend/src/app/ui/admin/reference-type/listing/reference-type-listing.component.html @@ -0,0 +1,108 @@ +
+
+ +
+
+

{{'REFERENCE-TYPE-LISTING.TITLE' | translate}}

+ + +
+
+ +
+
+ + + + + + + + + +
+
+ + + + +
+
+ + {{item?.name | nullifyValue}} +
+
+ + +
+
+ {{enumUtils.toDescriptionTemplateTypeStatusString(item.status) | nullifyValue}} +
+
+
+ + + + {{'REFERENCE-TYPE-LISTING.FIELDS.CREATED-AT' | translate}}: + + {{item?.createdAt | dateTimeFormatter : 'short' | nullifyValue}} + + +
+
+ + + {{'REFERENCE-TYPE-LISTING.FIELDS.UPDATED-AT' | translate}}: + + {{item?.updatedAt | dateTimeFormatter : 'short' | nullifyValue}} + + + +
+
+
+ + + + +
+
+ + + + + + +
+
+
\ No newline at end of file diff --git a/dmp-frontend/src/app/ui/admin/reference-type/listing/reference-type-listing.component.scss b/dmp-frontend/src/app/ui/admin/reference-type/listing/reference-type-listing.component.scss new file mode 100644 index 000000000..6e1b48814 --- /dev/null +++ b/dmp-frontend/src/app/ui/admin/reference-type/listing/reference-type-listing.component.scss @@ -0,0 +1,60 @@ +.description-template-type-listing { + margin-top: 1.3rem; + margin-left: 1rem; + margin-right: 2rem; + + .mat-header-row{ + background: #f3f5f8; + } + .mat-card { + margin: 16px 0; + padding: 0px; + } + + .mat-row { + cursor: pointer; + min-height: 4.5em; + } + + mat-row:hover { + background-color: #eef5f6; + } + .mat-fab-bottom-right { + float: right; + z-index: 5; + } +} +.create-btn { + border-radius: 30px; + background-color: var(--secondary-color); + padding-left: 2em; + padding-right: 2em; + // color: #000; + + .button-text{ + display: inline-block; + } +} + +.dlt-btn { + color: rgba(0, 0, 0, 0.54); +} + +.status-chip{ + + border-radius: 20px; + padding-left: 1em; + padding-right: 1em; + padding-top: 0.2em; + font-size: .8em; +} + +.status-chip-finalized{ + color: #568b5a; + background: #9dd1a1 0% 0% no-repeat padding-box; +} + +.status-chip-draft{ + color: #00c4ff; + background: #d3f5ff 0% 0% no-repeat padding-box; +} diff --git a/dmp-frontend/src/app/ui/admin/reference-type/listing/reference-type-listing.component.ts b/dmp-frontend/src/app/ui/admin/reference-type/listing/reference-type-listing.component.ts new file mode 100644 index 000000000..cd9a4fda0 --- /dev/null +++ b/dmp-frontend/src/app/ui/admin/reference-type/listing/reference-type-listing.component.ts @@ -0,0 +1,171 @@ +import { Component, OnInit, TemplateRef, ViewChild } from '@angular/core'; +import { MatDialog } from '@angular/material/dialog'; +import { ActivatedRoute, Router } from '@angular/router'; +import { IsActive } from '@app/core/common/enum/is-active.enum'; +import { ReferenceType } from '@app/core/model/reference-type/reference-type'; +import { ReferenceTypeLookup } from '@app/core/query/reference-type.lookup'; +import { AuthService } from '@app/core/services/auth/auth.service'; +import { ReferenceTypeService } from '@app/core/services/reference-type/reference-type.service'; +import { SnackBarNotificationLevel, UiNotificationService } from '@app/core/services/notification/ui-notification-service'; +import { EnumUtils } from '@app/core/services/utilities/enum-utils.service'; +import { QueryParamsService } from '@app/core/services/utilities/query-params.service'; +import { BaseListingComponent } from '@common/base/base-listing-component'; +import { PipeService } from '@common/formatting/pipe.service'; +import { DataTableDateTimeFormatPipe } from '@common/formatting/pipes/date-time-format.pipe'; +import { QueryResult } from '@common/model/query-result'; +import { ConfirmationDialogComponent } from '@common/modules/confirmation-dialog/confirmation-dialog.component'; +import { HttpErrorHandlingService } from '@common/modules/errors/error-handling/http-error-handling.service'; +import { ColumnDefinition, ColumnsChangedEvent, HybridListingComponent, PageLoadEvent } from '@common/modules/hybrid-listing/hybrid-listing.component'; +import { Guid } from '@common/types/guid'; +import { TranslateService } from '@ngx-translate/core'; +import { Observable } from 'rxjs'; +import { takeUntil } from 'rxjs/operators'; +import { nameof } from 'ts-simple-nameof'; + +@Component({ + templateUrl: './reference-type-listing.component.html', + styleUrls: ['./reference-type-listing.component.scss'] +}) +export class ReferenceTypeListingComponent extends BaseListingComponent implements OnInit { + publish = false; + userSettingsKey = { key: 'ReferenceTypeListingUserSettings' }; + propertiesAvailableForOrder: ColumnDefinition[]; + //ReferenceTypeStatuses = ReferenceTypeStatus; + + //@ViewChild('ReferenceTypeStatus', { static: true }) ReferenceTypeStatus?: TemplateRef; + @ViewChild('actions', { static: true }) actions?: TemplateRef; + @ViewChild(HybridListingComponent, { static: true }) hybridListingComponent: HybridListingComponent; + + private readonly lookupFields: string[] = [ + nameof(x => x.id), + nameof(x => x.name), + nameof(x => x.code), + nameof(x => x.updatedAt), + nameof(x => x.createdAt), + nameof(x => x.isActive) + ]; + + rowIdentity = x => x.id; + + constructor( + protected router: Router, + protected route: ActivatedRoute, + protected uiNotificationService: UiNotificationService, + protected httpErrorHandlingService: HttpErrorHandlingService, + protected queryParamsService: QueryParamsService, + private referenceTypeService: ReferenceTypeService, + public authService: AuthService, + private pipeService: PipeService, + public enumUtils: EnumUtils, + private language: TranslateService, + private dialog: MatDialog + ) { + super(router, route, uiNotificationService, httpErrorHandlingService, queryParamsService); + // Lookup setup + // Default lookup values are defined in the user settings class. + this.lookup = this.initializeLookup(); + } + + ngOnInit() { + super.ngOnInit(); + } + + protected initializeLookup(): ReferenceTypeLookup { + const lookup = new ReferenceTypeLookup(); + lookup.metadata = { countAll: true }; + lookup.page = { offset: 0, size: this.ITEMS_PER_PAGE }; + lookup.isActive = [IsActive.Active]; + lookup.order = { items: [this.toDescSortField(nameof(x => x.createdAt))] }; + this.updateOrderUiFields(lookup.order); + + lookup.project = { + fields: this.lookupFields + }; + + return lookup; + } + + protected setupColumns() { + this.gridColumns.push(...[{ + prop: nameof(x => x.name), + sortable: true, + languageName: 'REFERENCE-TYPE-LISTING.FIELDS.NAME' + }, + { + prop: nameof(x => x.code), + sortable: true, + languageName: 'REFERENCE-TYPE-LISTING.FIELDS.CODE', + //cellTemplate: this.ReferenceTypeStatus + }, + { + prop: nameof(x => x.createdAt), + sortable: true, + languageName: 'REFERENCE-TYPE-LISTING.FIELDS.CREATED-AT', + pipe: this.pipeService.getPipe(DataTableDateTimeFormatPipe).withFormat('short') + }, + { + prop: nameof(x => x.updatedAt), + sortable: true, + languageName: 'REFERENCE-TYPE-LISTING.FIELDS.UPDATED-AT', + pipe: this.pipeService.getPipe(DataTableDateTimeFormatPipe).withFormat('short') + }, + { + alwaysShown: true, + cellTemplate: this.actions, + maxWidth: 120 + } + ]); + this.propertiesAvailableForOrder = this.gridColumns.filter(x => x.sortable); + } + + // + // Listing Component functions + // + onColumnsChanged(event: ColumnsChangedEvent) { + super.onColumnsChanged(event); + this.onColumnsChangedInternal(event.properties.map(x => x.toString())); + } + + private onColumnsChangedInternal(columns: string[]) { + // Here are defined the projection fields that always requested from the api. + const fields = new Set(this.lookupFields); + this.gridColumns.map(x => x.prop) + .filter(x => !columns?.includes(x as string)) + .forEach(item => { + fields.delete(item as string) + }); + this.lookup.project = { fields: [...fields] }; + this.onPageLoad({ offset: 0 } as PageLoadEvent); + } + + protected loadListing(): Observable> { + return this.referenceTypeService.query(this.lookup); + } + + public deleteType(id: Guid) { + if (id) { + const dialogRef = this.dialog.open(ConfirmationDialogComponent, { + data: { + isDeleteConfirmation: true, + message: this.language.instant('GENERAL.CONFIRMATION-DIALOG.DELETE-ITEM'), + confirmButton: this.language.instant('GENERAL.CONFIRMATION-DIALOG.ACTIONS.CONFIRM'), + cancelButton: this.language.instant('GENERAL.CONFIRMATION-DIALOG.ACTIONS.CANCEL') + } + }); + dialogRef.afterClosed().pipe(takeUntil(this._destroyed)).subscribe(result => { + if (result) { + this.referenceTypeService.delete(id).pipe(takeUntil(this._destroyed)) + .subscribe( + complete => this.onCallbackSuccess(), + error => this.onCallbackError(error) + ); + } + }); + } + } + + onCallbackSuccess(): void { + this.uiNotificationService.snackBarNotification(this.language.instant('GENERAL.SNACK-BAR.SUCCESSFUL-DELETE'), SnackBarNotificationLevel.Success); + this.ngOnInit(); + } +} diff --git a/dmp-frontend/src/app/ui/admin/reference-type/reference-type.module.ts b/dmp-frontend/src/app/ui/admin/reference-type/reference-type.module.ts new file mode 100644 index 000000000..8a4e8ab4d --- /dev/null +++ b/dmp-frontend/src/app/ui/admin/reference-type/reference-type.module.ts @@ -0,0 +1,44 @@ +import { NgModule } from '@angular/core'; +import { EditorModule } from '@tinymce/tinymce-angular'; +import { ReferenceTypeRoutingModule } from './reference-type.routing'; +import { CommonUiModule } from '@common/ui/common-ui.module'; +import { CommonFormsModule } from '@common/forms/common-forms.module'; +import { ReferenceTypeEditorComponent } from './editor/reference-type-editor.component'; +import { CommonModule } from '@angular/common'; +import { HybridListingModule } from '@common/modules/hybrid-listing/hybrid-listing.module'; +import { TextFilterModule } from '@common/modules/text-filter/text-filter.module'; +import { UserSettingsModule } from '@common/modules/user-settings/user-settings.module'; +import { ReferenceTypeListingFiltersComponent } from './listing/filters/reference-type-listing-filters.component'; +import { UrlListingModule } from '@app/library/url-listing/url-listing.module'; +import { ConfirmationDialogModule } from '@common/modules/confirmation-dialog/confirmation-dialog.module'; +import { NgxDropzoneModule } from 'ngx-dropzone'; +import { DragDropModule } from '@angular/cdk/drag-drop'; +import { AutoCompleteModule } from '@app/library/auto-complete/auto-complete.module'; +import { CommonFormattingModule } from '@common/formatting/common-formatting.module'; +import { ReferenceTypeListingComponent } from './listing/reference-type-listing.component'; + + +@NgModule({ + declarations: [ + ReferenceTypeEditorComponent, + ReferenceTypeListingComponent, + ReferenceTypeListingFiltersComponent +], + imports: [ + CommonModule, + CommonUiModule, + CommonFormsModule, + UrlListingModule, + ConfirmationDialogModule, + ReferenceTypeRoutingModule, + EditorModule, + HybridListingModule, + TextFilterModule, + UserSettingsModule, + NgxDropzoneModule, + DragDropModule, + AutoCompleteModule, + CommonFormattingModule + ] +}) +export class ReferenceTypeModule { } diff --git a/dmp-frontend/src/app/ui/admin/reference-type/reference-type.routing.ts b/dmp-frontend/src/app/ui/admin/reference-type/reference-type.routing.ts new file mode 100644 index 000000000..d50a8b00a --- /dev/null +++ b/dmp-frontend/src/app/ui/admin/reference-type/reference-type.routing.ts @@ -0,0 +1,58 @@ +import { NgModule } from '@angular/core'; +import { Routes, RouterModule } from '@angular/router'; +import { AdminAuthGuard } from '@app/core/admin-auth-guard.service'; +import { ReferenceTypeEditorComponent } from './editor/reference-type-editor.component'; +import { ReferenceTypeListingComponent } from './listing/reference-type-listing.component'; +import { AuthGuard } from '@app/core/auth-guard.service'; +import { AppPermission } from '@app/core/common/enum/permission.enum'; +import { BreadcrumbService } from '@app/ui/misc/breadcrumb/breadcrumb.service'; +import { PendingChangesGuard } from '@common/forms/pending-form-changes/pending-form-changes-guard.service'; +import { ReferenceTypeEditorResolver } from './editor/reference-type-editor.resolver'; + + +const routes: Routes = [ + { + path: '', + component: ReferenceTypeListingComponent, + canActivate: [AuthGuard] + }, + { + path: 'new', + component: ReferenceTypeEditorComponent, + canActivate: [AdminAuthGuard], + data: { + authContext: { + permissions: [AppPermission.EditReferenceType] + }, + ...BreadcrumbService.generateRouteDataConfiguration({ + title: 'BREADCRUMBS.NEW-DESCRIPTION-TEMPLATE-TYPE' + }) + } + }, + { + path: ':id', + canActivate: [AuthGuard], + component: ReferenceTypeEditorComponent, + canDeactivate: [PendingChangesGuard], + resolve: { + 'entity': ReferenceTypeEditorResolver + }, + data: { + ...BreadcrumbService.generateRouteDataConfiguration({ + title: 'BREADCRUMBS.EDIT-DESCRIPTION-TEMPLATE-TYPE' + }), + authContext: { + permissions: [AppPermission.EditReferenceType] + } + } + + }, + { path: '**', loadChildren: () => import('@common/modules/page-not-found/page-not-found.module').then(m => m.PageNotFoundModule) }, +]; + +@NgModule({ + imports: [RouterModule.forChild(routes)], + exports: [RouterModule], + providers: [ReferenceTypeEditorResolver] +}) +export class ReferenceTypeRoutingModule { } diff --git a/dmp-frontend/src/app/ui/sidebar/sidebar.component.ts b/dmp-frontend/src/app/ui/sidebar/sidebar.component.ts index a75c8a90d..0c0f9b6d3 100644 --- a/dmp-frontend/src/app/ui/sidebar/sidebar.component.ts +++ b/dmp-frontend/src/app/ui/sidebar/sidebar.component.ts @@ -53,6 +53,7 @@ export const ADMIN_ROUTES: RouteInfo[] = [ { path: '/dmp-blueprints', title: 'SIDE-BAR.DMP-BLUEPRINTS', icon: 'library_books' }, { path: '/description-templates', title: 'SIDE-BAR.DESCRIPTION-TEMPLATES', icon: 'library_books' }, { path: '/description-template-type', title: 'SIDE-BAR.DESCRIPTION-TEMPLATE-TYPES', icon: 'library_books' }, + { path: '/reference-type', title: 'SIDE-BAR.REFERENCE-TYPES', icon: 'library_books' }, { path: '/users', title: 'SIDE-BAR.USERS', icon: 'people' }, { path: '/language-editor', title: 'SIDE-BAR.LANGUAGE-EDITOR', icon: 'language' }, { path: '/supportive-material', title: 'SIDE-BAR.SUPPORTIVE-MATERIAL', icon: 'import_contacts' } diff --git a/dmp-frontend/src/assets/i18n/en.json b/dmp-frontend/src/assets/i18n/en.json index c3d15a006..d90ca7e83 100644 --- a/dmp-frontend/src/assets/i18n/en.json +++ b/dmp-frontend/src/assets/i18n/en.json @@ -171,7 +171,8 @@ "LANGUAGE-EDITOR": "Language Editor", "GUIDE-EDITOR": "User Guide Editor", "LANGUAGE": "Language", - "SIGN-IN": "Sign in to account" + "SIGN-IN": "Sign in to account", + "REFERENCE-TYPE": "Reference Types" }, "FILE-TYPES": { "PDF": "PDF", @@ -332,7 +333,8 @@ "CO-BRANDING": "Co-Branding", "SUPPORT": "Support", "FEEDBACK": "Send feedback", - "SUPPORTIVE-MATERIAL": "Supportive Material" + "SUPPORTIVE-MATERIAL": "Supportive Material", + "REFERENCE-TYPES":"Reference Types" }, "DATASET-PROFILE-EDITOR": { "TITLE": { @@ -1047,6 +1049,33 @@ "SUCCESSFUL-DELETE": "Successful Delete", "UNSUCCESSFUL-DELETE": "This item could not be deleted." }, + "REFERENCE-TYPE-LISTING": { + "TITLE": "Reference Types", + "CREATE-TYPE": "Create Reference Type", + "FIELDS": { + "NAME": "Name", + "CODE": "Code", + "UPDATED-AT": "Updated", + "CREATED-AT": "Created" + }, + "FILTER": { + "TITLE": "Filters", + "IS-ACTIVE": "Is Active", + "CANCEL": "Cancel", + "APPLY-FILTERS": "Apply filters" + }, + "CONFIRM-DELETE-DIALOG": { + "MESSAGE": "Would you like to delete this Reference Type?", + "CONFIRM-BUTTON": "Yes, delete", + "CANCEL-BUTTON": "No" + }, + "ACTIONS": { + "DELETE": "Delete", + "EDIT": "Edit" + }, + "SUCCESSFUL-DELETE": "Successful Delete", + "UNSUCCESSFUL-DELETE": "This item could not be deleted." + }, "DATASET-UPLOAD": { "TITLE": "Import Dataset", "UPLOAD-BUTTON": "Upload", @@ -1075,6 +1104,39 @@ "DELETE": "Delete" } }, + "REFERENCE-TYPE-EDITOR": { + "NEW": "New Reference Type", + "FIELDS": { + "EXTERNAL-API-CONFIGURATION": "External API Configuration", + "RESULTS": "Results", + "FIELD-MAPPING": "Field Mapping", + "AUTHENTICATION": "Authentication", + "QUERIES": "Queries", + "QUERY": "Query", + "NAME": "Name", + "CODE": "Code", + "FIELD": "Field", + "DATA-TYPE": "Data Type", + "KEY": "Key", + "LABEL": "Label", + "ORDINAL": "Ordinal", + "URL": "Url", + "PAGINATION-PATH": "Pagination Path" + }, + "ACTIONS": { + "SAVE": "Save", + "CANCEL": "Cancel", + "DELETE": "Delete", + "ADD-FIELD": "Add Field", + "ADD-CONFIG": "Add Config", + "ADD-QUERY": "Add Query" + } + }, + "CONFIRM-DELETE-DIALOG": { + "MESSAGE": "Would you like to delete this Reference type?", + "CONFIRM-BUTTON": "Yes, delete", + "CANCEL-BUTTON": "No" + }, "DMP-BLUEPRINT-EDITOR": { "TITLE": { "NEW": "New DMP Blueprint", From 3ecb1ed9828af38d4dc14ce429ba03e728af8f0b Mon Sep 17 00:00:00 2001 From: amentis Date: Thu, 9 Nov 2023 18:25:35 +0200 Subject: [PATCH 08/27] rename reference type definition fields and fix listing --- .../DataFieldsUrlConfigurationEntity.java | 131 --------------- .../DataUrlConfigurationEntity.java | 70 -------- .../ReferenceTypeDefinitionEntity.java | 14 +- ...ceTypeExternalApiConfigurationEntity.java} | 38 ++--- ...esultFieldsMappingConfigurationEntity.java | 27 ++++ .../ResultsConfigurationEntity.java | 31 ++++ .../model/builder/ReferenceTypeBuilder.java | 1 + .../DataFieldsUrlConfigurationBuilder.java | 71 --------- .../ReferenceTypeDefinitionBuilder.java | 4 +- ...ceTypeExternalApiConfigurationBuilder.java | 80 ++++++++++ .../ReferenceTypeUrlConfigurationBuilder.java | 81 ---------- ...sultFieldsMappingConfigurationBuilder.java | 58 +++++++ ....java => ResultsConfigurationBuilder.java} | 28 ++-- .../ReferenceTypeDefinitionCensor.java | 4 +- ...ceTypeExternalApiConfigurationCensor.java} | 19 ++- ...sultFieldsMappingConfigurationCensor.java} | 8 +- ...r.java => ResultsConfigurationCensor.java} | 12 +- .../model/persist/ReferenceTypePersist.java | 10 ++ .../AuthenticationConfigurationPersist.java | 8 +- .../DataFieldsUrlConfigurationPersist.java | 104 ------------ .../DataUrlConfigurationPersist.java | 31 ---- .../ReferenceTypeDefinitionPersist.java | 11 +- ...eTypeExternalApiConfigurationPersist.java} | 52 +++--- ...sultFieldsMappingConfigurationPersist.java | 31 ++++ .../ResultsConfigurationPersist.java | 34 ++++ .../DataFieldsUrlConfiguration.java | 149 ------------------ .../DataUrlConfiguration.java | 74 --------- .../ReferenceTypeDefinition.java | 12 +- ...eferenceTypeExternalApiConfiguration.java} | 24 +-- .../ResultFieldsMappingConfiguration.java | 29 ++++ .../ResultsConfiguration.java | 29 ++++ .../ReferenceTypeServiceImpl.java | 48 +++--- .../model/reference-type/reference-type.ts | 10 +- .../editor/reference-type-editor.component.ts | 10 +- .../editor/reference-type-editor.model.ts | 7 +- .../reference-type-listing.component.html | 2 +- .../reference-type/reference-type.routing.ts | 4 +- dmp-frontend/src/assets/i18n/en.json | 4 +- 38 files changed, 472 insertions(+), 888 deletions(-) delete mode 100644 dmp-backend/core/src/main/java/eu/eudat/commons/types/referencetype/DataFieldsUrlConfigurationEntity.java delete mode 100644 dmp-backend/core/src/main/java/eu/eudat/commons/types/referencetype/DataUrlConfigurationEntity.java rename dmp-backend/core/src/main/java/eu/eudat/commons/types/referencetype/{ReferenceTypeUrlConfigurationEntity.java => ReferenceTypeExternalApiConfigurationEntity.java} (77%) create mode 100644 dmp-backend/core/src/main/java/eu/eudat/commons/types/referencetype/ResultFieldsMappingConfigurationEntity.java create mode 100644 dmp-backend/core/src/main/java/eu/eudat/commons/types/referencetype/ResultsConfigurationEntity.java delete mode 100644 dmp-backend/core/src/main/java/eu/eudat/model/builder/referencetypedefinition/DataFieldsUrlConfigurationBuilder.java create mode 100644 dmp-backend/core/src/main/java/eu/eudat/model/builder/referencetypedefinition/ReferenceTypeExternalApiConfigurationBuilder.java delete mode 100644 dmp-backend/core/src/main/java/eu/eudat/model/builder/referencetypedefinition/ReferenceTypeUrlConfigurationBuilder.java create mode 100644 dmp-backend/core/src/main/java/eu/eudat/model/builder/referencetypedefinition/ResultFieldsMappingConfigurationBuilder.java rename dmp-backend/core/src/main/java/eu/eudat/model/builder/referencetypedefinition/{DataUrlConfigurationBuilder.java => ResultsConfigurationBuilder.java} (59%) rename dmp-backend/core/src/main/java/eu/eudat/model/censorship/referencetype/{ReferenceTypeUrlConfigurationCensor.java => ReferenceTypeExternalApiConfigurationCensor.java} (66%) rename dmp-backend/core/src/main/java/eu/eudat/model/censorship/referencetype/{DataFieldsUrlConfigurationCensor.java => ResultFieldsMappingConfigurationCensor.java} (78%) rename dmp-backend/core/src/main/java/eu/eudat/model/censorship/referencetype/{DataUrlConfigurationCensor.java => ResultsConfigurationCensor.java} (74%) delete mode 100644 dmp-backend/core/src/main/java/eu/eudat/model/persist/referencetypedefinition/DataFieldsUrlConfigurationPersist.java delete mode 100644 dmp-backend/core/src/main/java/eu/eudat/model/persist/referencetypedefinition/DataUrlConfigurationPersist.java rename dmp-backend/core/src/main/java/eu/eudat/model/persist/referencetypedefinition/{ReferenceTypeUrlConfigurationPersist.java => ReferenceTypeExternalApiConfigurationPersist.java} (77%) create mode 100644 dmp-backend/core/src/main/java/eu/eudat/model/persist/referencetypedefinition/ResultFieldsMappingConfigurationPersist.java create mode 100644 dmp-backend/core/src/main/java/eu/eudat/model/persist/referencetypedefinition/ResultsConfigurationPersist.java delete mode 100644 dmp-backend/core/src/main/java/eu/eudat/model/referencetypedefinition/DataFieldsUrlConfiguration.java delete mode 100644 dmp-backend/core/src/main/java/eu/eudat/model/referencetypedefinition/DataUrlConfiguration.java rename dmp-backend/core/src/main/java/eu/eudat/model/referencetypedefinition/{ReferenceTypeUrlConfiguration.java => ReferenceTypeExternalApiConfiguration.java} (85%) create mode 100644 dmp-backend/core/src/main/java/eu/eudat/model/referencetypedefinition/ResultFieldsMappingConfiguration.java create mode 100644 dmp-backend/core/src/main/java/eu/eudat/model/referencetypedefinition/ResultsConfiguration.java diff --git a/dmp-backend/core/src/main/java/eu/eudat/commons/types/referencetype/DataFieldsUrlConfigurationEntity.java b/dmp-backend/core/src/main/java/eu/eudat/commons/types/referencetype/DataFieldsUrlConfigurationEntity.java deleted file mode 100644 index d7c12dd5c..000000000 --- a/dmp-backend/core/src/main/java/eu/eudat/commons/types/referencetype/DataFieldsUrlConfigurationEntity.java +++ /dev/null @@ -1,131 +0,0 @@ -package eu.eudat.commons.types.referencetype; - -import jakarta.xml.bind.annotation.XmlElement; - -public class DataFieldsUrlConfigurationEntity { - private String id; - private String name; - private String pid; - private String pidTypeField; - private String uri; - private String description; - private String source; - private String count; -// private String path; -// private String host; - private String types; - private String firstName; - private String lastName; - - public String getId() { - return id; - } - - @XmlElement(name = "id") - public void setId(String id) { - this.id = id; - } - - public String getName() { - return name; - } - - @XmlElement(name = "name") - public void setName(String name) { - this.name = name; - } - - public String getPid() { - return pid; - } - - @XmlElement(name = "pid") - public void setPid(String pid) { - this.pid = pid; - } - - public String getPidTypeField() { - return pidTypeField; - } - - @XmlElement(name = "pidTypeField") - public void setPidTypeField(String pidTypeField) { - this.pidTypeField = pidTypeField; - } - - public String getUri() { - return uri; - } - - @XmlElement(name = "uri") - public void setUri(String uri) { - this.uri = uri; - } - - public String getDescription() { - return description; - } - - @XmlElement(name = "description") - public void setDescription(String description) { - this.description = description; - } - - public String getSource() { - return source; - } - - @XmlElement(name = "source") - public void setSource(String source) { - this.source = source; - } - - public String getCount() { - return count; - } - - @XmlElement(name = "count") - public void setCount(String count) { - this.count = count; - } - -// public String getPath() { -// return path; -// } -// @XmlElement(name = "path") -// public void setPath(String path) { -// this.path = path; -// } -// -// public String getHost() { -// return host; -// } -// @XmlElement(name = "host") -// public void setHost(String host) { -// this.host = host; -// } - - @XmlElement(name = "types") - public String getTypes() { - return types; - } - public void setTypes(String types) { - this.types = types; - } - - @XmlElement(name = "firstName") - public String getFirstName() { - return firstName; - } - public void setFirstName(String firstName) { - this.firstName = firstName; - } - - @XmlElement(name = "lastName") - public String getLastName() { - return lastName; - } - public void setLastName(String lastName) { - this.lastName = lastName; - } -} diff --git a/dmp-backend/core/src/main/java/eu/eudat/commons/types/referencetype/DataUrlConfigurationEntity.java b/dmp-backend/core/src/main/java/eu/eudat/commons/types/referencetype/DataUrlConfigurationEntity.java deleted file mode 100644 index f6b06300e..000000000 --- a/dmp-backend/core/src/main/java/eu/eudat/commons/types/referencetype/DataUrlConfigurationEntity.java +++ /dev/null @@ -1,70 +0,0 @@ -package eu.eudat.commons.types.referencetype; - -import jakarta.xml.bind.annotation.XmlElement; -import jakarta.xml.bind.annotation.XmlElementWrapper; - -import java.util.List; - -public class DataUrlConfigurationEntity { - private String path; - private DataFieldsUrlConfigurationEntity fieldsUrlConfiguration; -// private String parseClass; -// private String parseField; -// private List mergedFields; -// private String mergedFieldName; - - public String getPath() { - return path; - } - - @XmlElement(name = "path") - public void setPath(String path) { - this.path = path; - } - - public DataFieldsUrlConfigurationEntity getFieldsUrlConfiguration() { - return fieldsUrlConfiguration; - } - - @XmlElement(name = "fields") - public void setFieldsUrlConfiguration(DataFieldsUrlConfigurationEntity fieldsUrlConfiguration) { - this.fieldsUrlConfiguration = fieldsUrlConfiguration; - } - -// public String getParseClass() { -// return parseClass; -// } -// -// @XmlElement(name = "parse-class") -// public void setParseClass(String parseClass) { -// this.parseClass = parseClass; -// } -// -// public String getParseField() { -// return parseField; -// } -// -// @XmlElement(name = "parse-field") -// public void setParseField(String parseField) { -// this.parseField = parseField; -// } -// -// public List getMergedFields() { -// return mergedFields; -// } -// -// @XmlElementWrapper(name = "merge-fields") -// @XmlElement(name = "field") -// public void setMergedFields(List mergedFields) { -// this.mergedFields = mergedFields; -// } -// -// public String getMergedFieldName() { -// return mergedFieldName; -// } -// -// @XmlElement(name = "merge-field-name") -// public void setMergedFieldName(String mergedFieldName) { -// this.mergedFieldName = mergedFieldName; -// } -} diff --git a/dmp-backend/core/src/main/java/eu/eudat/commons/types/referencetype/ReferenceTypeDefinitionEntity.java b/dmp-backend/core/src/main/java/eu/eudat/commons/types/referencetype/ReferenceTypeDefinitionEntity.java index a30ba57f9..8e2993f10 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/commons/types/referencetype/ReferenceTypeDefinitionEntity.java +++ b/dmp-backend/core/src/main/java/eu/eudat/commons/types/referencetype/ReferenceTypeDefinitionEntity.java @@ -11,9 +11,9 @@ public class ReferenceTypeDefinitionEntity { @XmlElement(name = "field") private List fields; - @XmlElementWrapper(name = "urls") - @XmlElement(name = "urlConfig") - private List urlConfig; + @XmlElementWrapper(name = "externalApiConfigs") + @XmlElement(name = "externalApiConfig") + private List externalApiConfig; public List getFields() { return fields; @@ -23,11 +23,11 @@ public class ReferenceTypeDefinitionEntity { this.fields = fields; } - public List getUrlConfig() { - return urlConfig; + public List getExternalApiConfig() { + return externalApiConfig; } - public void setUrlConfig(List urlConfig) { - this.urlConfig = urlConfig; + public void setExternalApiConfig(List externalApiConfig) { + this.externalApiConfig = externalApiConfig; } } diff --git a/dmp-backend/core/src/main/java/eu/eudat/commons/types/referencetype/ReferenceTypeUrlConfigurationEntity.java b/dmp-backend/core/src/main/java/eu/eudat/commons/types/referencetype/ReferenceTypeExternalApiConfigurationEntity.java similarity index 77% rename from dmp-backend/core/src/main/java/eu/eudat/commons/types/referencetype/ReferenceTypeUrlConfigurationEntity.java rename to dmp-backend/core/src/main/java/eu/eudat/commons/types/referencetype/ReferenceTypeExternalApiConfigurationEntity.java index 3269cd42a..e97c3411f 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/commons/types/referencetype/ReferenceTypeUrlConfigurationEntity.java +++ b/dmp-backend/core/src/main/java/eu/eudat/commons/types/referencetype/ReferenceTypeExternalApiConfigurationEntity.java @@ -3,21 +3,19 @@ package eu.eudat.commons.types.referencetype; import jakarta.xml.bind.annotation.XmlElement; import jakarta.xml.bind.annotation.XmlElementWrapper; -import jakarta.xml.bind.annotation.XmlRootElement; import java.util.List; -public class ReferenceTypeUrlConfigurationEntity { +public class ReferenceTypeExternalApiConfigurationEntity { private String key; private String label; private Integer ordinal; private String url; - private DataUrlConfigurationEntity data; + private ResultsConfigurationEntity results; private String type; private String paginationPath; private String contentType; - private String funderQuery; - private String firstpage; + private String firstPage; private String requestType = "GET"; private String requestBody = ""; private String filterType = "remote"; @@ -57,18 +55,18 @@ public class ReferenceTypeUrlConfigurationEntity { this.ordinal = ordinal; } - public DataUrlConfigurationEntity getData() { - return data; + public ResultsConfigurationEntity getResults() { + return results; } - @XmlElement(name = "data") - public void setData(DataUrlConfigurationEntity data) { - this.data = data; + @XmlElement(name = "results") + public void setResults(ResultsConfigurationEntity results) { + this.results = results; } public String getPaginationPath() { return paginationPath; } - @XmlElement(name = "paginationpath") + @XmlElement(name = "paginationPath") public void setPaginationPath(String paginationPath) { this.paginationPath = paginationPath; } @@ -84,25 +82,17 @@ public class ReferenceTypeUrlConfigurationEntity { public String getContentType() { return contentType; } - @XmlElement(name = "contenttype") + @XmlElement(name = "contentType") public void setContentType(String contentType) { this.contentType = contentType; } - public String getFunderQuery() { - return funderQuery; - } - @XmlElement(name = "funderQuery") - public void setFunderQuery(String funderQuery) { - this.funderQuery = funderQuery; - } - - public String getFirstpage() { - return firstpage; + public String getFirstPage() { + return firstPage; } @XmlElement(name = "firstPage") - public void setFirstpage(String firstpage) { - this.firstpage = firstpage; + public void setFirstPage(String firstPage) { + this.firstPage = firstPage; } public String getRequestType() { diff --git a/dmp-backend/core/src/main/java/eu/eudat/commons/types/referencetype/ResultFieldsMappingConfigurationEntity.java b/dmp-backend/core/src/main/java/eu/eudat/commons/types/referencetype/ResultFieldsMappingConfigurationEntity.java new file mode 100644 index 000000000..28ecf655f --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/commons/types/referencetype/ResultFieldsMappingConfigurationEntity.java @@ -0,0 +1,27 @@ +package eu.eudat.commons.types.referencetype; + +import jakarta.xml.bind.annotation.XmlElement; + +public class ResultFieldsMappingConfigurationEntity { + private String code; + private String responsePath; + + public String getCode() { + return code; + } + + @XmlElement(name = "code") + public void setCode(String code) { + this.code = code; + } + + public String getResponsePath() { + return responsePath; + } + + @XmlElement(name = "responsePath") + public void setResponsePath(String responsePath) { + this.responsePath = responsePath; + } + +} diff --git a/dmp-backend/core/src/main/java/eu/eudat/commons/types/referencetype/ResultsConfigurationEntity.java b/dmp-backend/core/src/main/java/eu/eudat/commons/types/referencetype/ResultsConfigurationEntity.java new file mode 100644 index 000000000..84eec895b --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/commons/types/referencetype/ResultsConfigurationEntity.java @@ -0,0 +1,31 @@ +package eu.eudat.commons.types.referencetype; + +import jakarta.xml.bind.annotation.XmlElement; +import jakarta.xml.bind.annotation.XmlElementWrapper; + +import java.util.List; + +public class ResultsConfigurationEntity { + private String resultsArrayPath; + private List fieldsMapping; + + public String getResultsArrayPath() { + return resultsArrayPath; + } + + @XmlElement(name = "resultsArrayPath") + public void setResultsArrayPath(String resultsArrayPath) { + this.resultsArrayPath = resultsArrayPath; + } + + public List getFieldsMapping() { + return fieldsMapping; + } + + @XmlElementWrapper + @XmlElement(name = "field") + public void setFieldsMapping(List fieldsMapping) { + this.fieldsMapping = fieldsMapping; + } + +} diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/builder/ReferenceTypeBuilder.java b/dmp-backend/core/src/main/java/eu/eudat/model/builder/ReferenceTypeBuilder.java index 9e18408cc..9379bad25 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/builder/ReferenceTypeBuilder.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/builder/ReferenceTypeBuilder.java @@ -70,6 +70,7 @@ public class ReferenceTypeBuilder extends BaseBuilder { - - private final BuilderFactory builderFactory; - private EnumSet authorize = EnumSet.of(AuthorizationFlags.None); - - @Autowired - public DataFieldsUrlConfigurationBuilder( - ConventionService conventionService, BuilderFactory builderFactory) { - super(conventionService, new LoggerService(LoggerFactory.getLogger(DataFieldsUrlConfigurationBuilder.class))); - this.builderFactory = builderFactory; - } - - public DataFieldsUrlConfigurationBuilder authorize(EnumSet values) { - this.authorize = values; - return this; - } - - @Override - public List build(FieldSet fields, List data) throws MyApplicationException { - this.logger.debug("building for {} items requesting {} fields", Optional.ofNullable(data).map(List::size).orElse(0), Optional.ofNullable(fields).map(FieldSet::getFields).map(Set::size).orElse(0)); - this.logger.trace(new DataLogEntry("requested fields", fields)); - if (fields == null || data == null || fields.isEmpty()) - return new ArrayList<>(); - - List models = new ArrayList<>(); - for (DataFieldsUrlConfigurationEntity d : data) { - DataFieldsUrlConfiguration m = new DataFieldsUrlConfiguration(); - if (fields.hasField(this.asIndexer(DataFieldsUrlConfiguration._id))) m.setId(d.getId()); - if (fields.hasField(this.asIndexer(DataFieldsUrlConfiguration._name))) m.setName(d.getName()); - if (fields.hasField(this.asIndexer(DataFieldsUrlConfiguration._pid))) m.setPid(d.getPid()); - if (fields.hasField(this.asIndexer(DataFieldsUrlConfiguration._pidTypeField))) m.setPidTypeField(d.getPidTypeField()); - if (fields.hasField(this.asIndexer(DataFieldsUrlConfiguration._uri))) m.setUri(d.getUri()); - if (fields.hasField(this.asIndexer(DataFieldsUrlConfiguration._description))) m.setDescription(d.getDescription()); - if (fields.hasField(this.asIndexer(DataFieldsUrlConfiguration._source))) m.setSource(d.getSource()); - if (fields.hasField(this.asIndexer(DataFieldsUrlConfiguration._count))) m.setCount(d.getCount()); -// if (fields.hasField(this.asIndexer(DataFieldsUrlConfiguration._path))) m.setPath(d.getPath()); -// if (fields.hasField(this.asIndexer(DataFieldsUrlConfiguration._host))) m.setHost(d.getHost()); - if (fields.hasField(this.asIndexer(DataFieldsUrlConfiguration._types))) m.setTypes(d.getTypes()); - if (fields.hasField(this.asIndexer(DataFieldsUrlConfiguration._firstName))) m.setFirstName(d.getFirstName()); - if (fields.hasField(this.asIndexer(DataFieldsUrlConfiguration._lastName))) m.setLastName(d.getLastName()); - - models.add(m); - } - this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0)); - return models; - } -} diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/builder/referencetypedefinition/ReferenceTypeDefinitionBuilder.java b/dmp-backend/core/src/main/java/eu/eudat/model/builder/referencetypedefinition/ReferenceTypeDefinitionBuilder.java index 9a60d203f..2d9fb5b62 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/builder/referencetypedefinition/ReferenceTypeDefinitionBuilder.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/builder/referencetypedefinition/ReferenceTypeDefinitionBuilder.java @@ -45,13 +45,13 @@ public class ReferenceTypeDefinitionBuilder extends BaseBuilder(); FieldSet fieldsFields = fields.extractPrefixed(this.asPrefix(ReferenceTypeDefinition._fields)); - FieldSet urlConfigFields = fields.extractPrefixed(this.asPrefix(ReferenceTypeDefinition._urlConfig)); + FieldSet externalApiConfigFields = fields.extractPrefixed(this.asPrefix(ReferenceTypeDefinition._externalApiConfig)); List models = new ArrayList<>(); for (ReferenceTypeDefinitionEntity d : data) { ReferenceTypeDefinition m = new ReferenceTypeDefinition(); if (!fieldsFields.isEmpty() && d.getFields() != null) m.setFields(this.builderFactory.builder(ReferenceTypeFieldBuilder.class).authorize(this.authorize).build(fieldsFields, d.getFields())); - if (!fieldsFields.isEmpty() && d.getFields() != null) m.setUrlConfig(this.builderFactory.builder(ReferenceTypeUrlConfigurationBuilder.class).authorize(this.authorize).build(urlConfigFields, d.getUrlConfig())); + if (!fieldsFields.isEmpty() && d.getFields() != null) m.setExternalApiConfig(this.builderFactory.builder(ReferenceTypeExternalApiConfigurationBuilder.class).authorize(this.authorize).build(externalApiConfigFields, d.getExternalApiConfig())); models.add(m); } this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0)); diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/builder/referencetypedefinition/ReferenceTypeExternalApiConfigurationBuilder.java b/dmp-backend/core/src/main/java/eu/eudat/model/builder/referencetypedefinition/ReferenceTypeExternalApiConfigurationBuilder.java new file mode 100644 index 000000000..a7ee48e02 --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/model/builder/referencetypedefinition/ReferenceTypeExternalApiConfigurationBuilder.java @@ -0,0 +1,80 @@ +package eu.eudat.model.builder.referencetypedefinition; + +import eu.eudat.authorization.AuthorizationFlags; +import eu.eudat.commons.types.referencetype.ReferenceTypeExternalApiConfigurationEntity; +import eu.eudat.convention.ConventionService; +import eu.eudat.model.builder.BaseBuilder; +import eu.eudat.model.referencetypedefinition.ReferenceTypeExternalApiConfiguration; +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 ReferenceTypeExternalApiConfigurationBuilder extends BaseBuilder { + + private final BuilderFactory builderFactory; + private EnumSet authorize = EnumSet.of(AuthorizationFlags.None); + + @Autowired + public ReferenceTypeExternalApiConfigurationBuilder( + ConventionService conventionService, BuilderFactory builderFactory) { + super(conventionService, new LoggerService(LoggerFactory.getLogger(ReferenceTypeExternalApiConfigurationBuilder.class))); + this.builderFactory = builderFactory; + } + + public ReferenceTypeExternalApiConfigurationBuilder authorize(EnumSet values) { + this.authorize = values; + return this; + } + + @Override + public List build(FieldSet fields, List data) throws MyApplicationException { + this.logger.debug("building for {} items requesting {} fields", Optional.ofNullable(data).map(List::size).orElse(0), Optional.ofNullable(fields).map(FieldSet::getFields).map(Set::size).orElse(0)); + this.logger.trace(new DataLogEntry("requested fields", fields)); + if (fields == null || data == null || fields.isEmpty()) + return new ArrayList<>(); + + FieldSet resultsFields = fields.extractPrefixed(this.asPrefix(ReferenceTypeExternalApiConfiguration._results)); + FieldSet authFields = fields.extractPrefixed(this.asPrefix(ReferenceTypeExternalApiConfiguration._auth)); + FieldSet queriesFields = fields.extractPrefixed(this.asPrefix(ReferenceTypeExternalApiConfiguration._queries)); + + List models = new ArrayList<>(); + for (ReferenceTypeExternalApiConfigurationEntity d : data) { + ReferenceTypeExternalApiConfiguration m = new ReferenceTypeExternalApiConfiguration(); + if (fields.hasField(this.asIndexer(ReferenceTypeExternalApiConfiguration._key))) m.setKey(d.getKey()); + if (fields.hasField(this.asIndexer(ReferenceTypeExternalApiConfiguration._label))) m.setLabel(d.getLabel()); + if (fields.hasField(this.asIndexer(ReferenceTypeExternalApiConfiguration._ordinal))) m.setOrdinal(d.getOrdinal()); + if (fields.hasField(this.asIndexer(ReferenceTypeExternalApiConfiguration._url))) m.setUrl(d.getUrl()); + if (!resultsFields.isEmpty() && d.getResults() != null) { + m.setResults(this.builderFactory.builder(ResultsConfigurationBuilder.class).authorize(this.authorize).build(resultsFields, d.getResults())); + } + if (fields.hasField(this.asIndexer(ReferenceTypeExternalApiConfiguration._type))) m.setType(d.getType()); + if (fields.hasField(this.asIndexer(ReferenceTypeExternalApiConfiguration._paginationPath))) m.setPaginationPath(d.getPaginationPath()); + if (fields.hasField(this.asIndexer(ReferenceTypeExternalApiConfiguration._contentType))) m.setContentType(d.getContentType()); + if (fields.hasField(this.asIndexer(ReferenceTypeExternalApiConfiguration._firstPage))) m.setFirstPage(d.getFirstPage()); + if (fields.hasField(this.asIndexer(ReferenceTypeExternalApiConfiguration._requestType))) m.setRequestType(d.getRequestType()); + if (fields.hasField(this.asIndexer(ReferenceTypeExternalApiConfiguration._requestBody))) m.setRequestBody(d.getRequestBody()); + if (fields.hasField(this.asIndexer(ReferenceTypeExternalApiConfiguration._filterType))) m.setFilterType(d.getFilterType()); + if (!authFields.isEmpty() && d.getAuth() != null) { + m.setAuth(this.builderFactory.builder(AuthenticationConfigurationBuilder.class).authorize(this.authorize).build(authFields, d.getAuth())); + } + if (!queriesFields.isEmpty() && d.getQueries() != null) { + m.setQueries(this.builderFactory.builder(QueryConfigBuilder.class).authorize(this.authorize).build(queriesFields, d.getQueries())); + } + + models.add(m); + } + this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0)); + return models; + } +} diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/builder/referencetypedefinition/ReferenceTypeUrlConfigurationBuilder.java b/dmp-backend/core/src/main/java/eu/eudat/model/builder/referencetypedefinition/ReferenceTypeUrlConfigurationBuilder.java deleted file mode 100644 index 433d70b47..000000000 --- a/dmp-backend/core/src/main/java/eu/eudat/model/builder/referencetypedefinition/ReferenceTypeUrlConfigurationBuilder.java +++ /dev/null @@ -1,81 +0,0 @@ -package eu.eudat.model.builder.referencetypedefinition; - -import eu.eudat.authorization.AuthorizationFlags; -import eu.eudat.commons.types.referencetype.ReferenceTypeUrlConfigurationEntity; -import eu.eudat.convention.ConventionService; -import eu.eudat.model.builder.BaseBuilder; -import eu.eudat.model.referencetypedefinition.ReferenceTypeUrlConfiguration; -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 ReferenceTypeUrlConfigurationBuilder extends BaseBuilder { - - private final BuilderFactory builderFactory; - private EnumSet authorize = EnumSet.of(AuthorizationFlags.None); - - @Autowired - public ReferenceTypeUrlConfigurationBuilder( - ConventionService conventionService, BuilderFactory builderFactory) { - super(conventionService, new LoggerService(LoggerFactory.getLogger(ReferenceTypeUrlConfigurationBuilder.class))); - this.builderFactory = builderFactory; - } - - public ReferenceTypeUrlConfigurationBuilder authorize(EnumSet values) { - this.authorize = values; - return this; - } - - @Override - public List build(FieldSet fields, List data) throws MyApplicationException { - this.logger.debug("building for {} items requesting {} fields", Optional.ofNullable(data).map(List::size).orElse(0), Optional.ofNullable(fields).map(FieldSet::getFields).map(Set::size).orElse(0)); - this.logger.trace(new DataLogEntry("requested fields", fields)); - if (fields == null || data == null || fields.isEmpty()) - return new ArrayList<>(); - - FieldSet dataFields = fields.extractPrefixed(this.asPrefix(ReferenceTypeUrlConfiguration._data)); - FieldSet authFields = fields.extractPrefixed(this.asPrefix(ReferenceTypeUrlConfiguration._auth)); - FieldSet queriesFields = fields.extractPrefixed(this.asPrefix(ReferenceTypeUrlConfiguration._queries)); - - List models = new ArrayList<>(); - for (ReferenceTypeUrlConfigurationEntity d : data) { - ReferenceTypeUrlConfiguration m = new ReferenceTypeUrlConfiguration(); - if (fields.hasField(this.asIndexer(ReferenceTypeUrlConfiguration._key))) m.setKey(d.getKey()); - if (fields.hasField(this.asIndexer(ReferenceTypeUrlConfiguration._label))) m.setLabel(d.getLabel()); - if (fields.hasField(this.asIndexer(ReferenceTypeUrlConfiguration._ordinal))) m.setOrdinal(d.getOrdinal()); - if (fields.hasField(this.asIndexer(ReferenceTypeUrlConfiguration._url))) m.setUrl(d.getUrl()); - if (!dataFields.isEmpty() && d.getData() != null) { - m.setData(this.builderFactory.builder(DataUrlConfigurationBuilder.class).authorize(this.authorize).build(dataFields, d.getData())); - } - if (fields.hasField(this.asIndexer(ReferenceTypeUrlConfiguration._type))) m.setType(d.getType()); - if (fields.hasField(this.asIndexer(ReferenceTypeUrlConfiguration._paginationPath))) m.setPaginationPath(d.getPaginationPath()); - if (fields.hasField(this.asIndexer(ReferenceTypeUrlConfiguration._contentType))) m.setContentType(d.getContentType()); - if (fields.hasField(this.asIndexer(ReferenceTypeUrlConfiguration._funderQuery))) m.setFunderQuery(d.getFunderQuery()); - if (fields.hasField(this.asIndexer(ReferenceTypeUrlConfiguration._firstPage))) m.setFirstPage(d.getFirstpage()); - if (fields.hasField(this.asIndexer(ReferenceTypeUrlConfiguration._requestType))) m.setRequestType(d.getRequestType()); - if (fields.hasField(this.asIndexer(ReferenceTypeUrlConfiguration._requestBody))) m.setRequestBody(d.getRequestBody()); - if (fields.hasField(this.asIndexer(ReferenceTypeUrlConfiguration._filterType))) m.setFilterType(d.getFilterType()); - if (!authFields.isEmpty() && d.getAuth() != null) { - m.setAuth(this.builderFactory.builder(AuthenticationConfigurationBuilder.class).authorize(this.authorize).build(authFields, d.getAuth())); - } - if (!queriesFields.isEmpty() && d.getQueries() != null) { - m.setQueries(this.builderFactory.builder(QueryConfigBuilder.class).authorize(this.authorize).build(queriesFields, d.getQueries())); - } - - models.add(m); - } - this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0)); - return models; - } -} diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/builder/referencetypedefinition/ResultFieldsMappingConfigurationBuilder.java b/dmp-backend/core/src/main/java/eu/eudat/model/builder/referencetypedefinition/ResultFieldsMappingConfigurationBuilder.java new file mode 100644 index 000000000..15b90d2f5 --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/model/builder/referencetypedefinition/ResultFieldsMappingConfigurationBuilder.java @@ -0,0 +1,58 @@ +package eu.eudat.model.builder.referencetypedefinition; + +import eu.eudat.authorization.AuthorizationFlags; +import eu.eudat.commons.types.referencetype.ResultFieldsMappingConfigurationEntity; +import eu.eudat.convention.ConventionService; +import eu.eudat.model.builder.BaseBuilder; +import eu.eudat.model.referencetypedefinition.ResultFieldsMappingConfiguration; +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 ResultFieldsMappingConfigurationBuilder extends BaseBuilder { + + private final BuilderFactory builderFactory; + private EnumSet authorize = EnumSet.of(AuthorizationFlags.None); + + @Autowired + public ResultFieldsMappingConfigurationBuilder( + ConventionService conventionService, BuilderFactory builderFactory) { + super(conventionService, new LoggerService(LoggerFactory.getLogger(ResultFieldsMappingConfigurationBuilder.class))); + this.builderFactory = builderFactory; + } + + public ResultFieldsMappingConfigurationBuilder authorize(EnumSet values) { + this.authorize = values; + return this; + } + + @Override + public List build(FieldSet fields, List data) throws MyApplicationException { + this.logger.debug("building for {} items requesting {} fields", Optional.ofNullable(data).map(List::size).orElse(0), Optional.ofNullable(fields).map(FieldSet::getFields).map(Set::size).orElse(0)); + this.logger.trace(new DataLogEntry("requested fields", fields)); + if (fields == null || data == null || fields.isEmpty()) + return new ArrayList<>(); + + List models = new ArrayList<>(); + for (ResultFieldsMappingConfigurationEntity d : data) { + ResultFieldsMappingConfiguration m = new ResultFieldsMappingConfiguration(); + if (fields.hasField(this.asIndexer(ResultFieldsMappingConfiguration._code))) m.setCode(d.getCode()); + if (fields.hasField(this.asIndexer(ResultFieldsMappingConfiguration._responsePath))) m.setResponsePath(d.getResponsePath()); + + models.add(m); + } + this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0)); + return models; + } +} diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/builder/referencetypedefinition/DataUrlConfigurationBuilder.java b/dmp-backend/core/src/main/java/eu/eudat/model/builder/referencetypedefinition/ResultsConfigurationBuilder.java similarity index 59% rename from dmp-backend/core/src/main/java/eu/eudat/model/builder/referencetypedefinition/DataUrlConfigurationBuilder.java rename to dmp-backend/core/src/main/java/eu/eudat/model/builder/referencetypedefinition/ResultsConfigurationBuilder.java index 94cc06c7c..82d85c927 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/builder/referencetypedefinition/DataUrlConfigurationBuilder.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/builder/referencetypedefinition/ResultsConfigurationBuilder.java @@ -1,10 +1,10 @@ package eu.eudat.model.builder.referencetypedefinition; import eu.eudat.authorization.AuthorizationFlags; -import eu.eudat.commons.types.referencetype.DataUrlConfigurationEntity; +import eu.eudat.commons.types.referencetype.ResultsConfigurationEntity; import eu.eudat.convention.ConventionService; import eu.eudat.model.builder.BaseBuilder; -import eu.eudat.model.referencetypedefinition.DataUrlConfiguration; +import eu.eudat.model.referencetypedefinition.ResultsConfiguration; import gr.cite.tools.data.builder.BuilderFactory; import gr.cite.tools.exception.MyApplicationException; import gr.cite.tools.fieldset.FieldSet; @@ -20,38 +20,38 @@ import java.util.*; @Component @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) -public class DataUrlConfigurationBuilder extends BaseBuilder { +public class ResultsConfigurationBuilder extends BaseBuilder { private final BuilderFactory builderFactory; private EnumSet authorize = EnumSet.of(AuthorizationFlags.None); @Autowired - public DataUrlConfigurationBuilder( + public ResultsConfigurationBuilder( ConventionService conventionService, BuilderFactory builderFactory) { - super(conventionService, new LoggerService(LoggerFactory.getLogger(DataUrlConfigurationBuilder.class))); + super(conventionService, new LoggerService(LoggerFactory.getLogger(ResultsConfigurationBuilder.class))); this.builderFactory = builderFactory; } - public DataUrlConfigurationBuilder authorize(EnumSet values) { + public ResultsConfigurationBuilder authorize(EnumSet values) { this.authorize = values; return this; } @Override - public List build(FieldSet fields, List data) throws MyApplicationException { + public List build(FieldSet fields, List data) throws MyApplicationException { this.logger.debug("building for {} items requesting {} fields", Optional.ofNullable(data).map(List::size).orElse(0), Optional.ofNullable(fields).map(FieldSet::getFields).map(Set::size).orElse(0)); this.logger.trace(new DataLogEntry("requested fields", fields)); if (fields == null || data == null || fields.isEmpty()) return new ArrayList<>(); - FieldSet fieldsUrlConfigFields = fields.extractPrefixed(this.asPrefix(DataUrlConfiguration._fieldsUrlConfiguration)); + FieldSet fieldsMappingFields = fields.extractPrefixed(this.asPrefix(ResultsConfiguration._fieldsMapping)); - List models = new ArrayList<>(); - for (DataUrlConfigurationEntity d : data) { - DataUrlConfiguration m = new DataUrlConfiguration(); - if (fields.hasField(this.asIndexer(DataUrlConfiguration._path))) m.setPath(d.getPath()); - if (!fieldsUrlConfigFields.isEmpty() && d.getFieldsUrlConfiguration() != null) { - m.setFieldsUrlConfiguration(this.builderFactory.builder(DataFieldsUrlConfigurationBuilder.class).authorize(this.authorize).build(fieldsUrlConfigFields, d.getFieldsUrlConfiguration())); + List models = new ArrayList<>(); + for (ResultsConfigurationEntity d : data) { + ResultsConfiguration m = new ResultsConfiguration(); + if (fields.hasField(this.asIndexer(ResultsConfiguration._resultsArrayPath))) m.setResultsArrayPath(d.getResultsArrayPath()); + if (!fieldsMappingFields.isEmpty() && d.getFieldsMapping() != null) { + m.setFieldsMapping(this.builderFactory.builder(ResultFieldsMappingConfigurationBuilder.class).authorize(this.authorize).build(fieldsMappingFields, d.getFieldsMapping())); } models.add(m); diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/censorship/referencetype/ReferenceTypeDefinitionCensor.java b/dmp-backend/core/src/main/java/eu/eudat/model/censorship/referencetype/ReferenceTypeDefinitionCensor.java index 07580330b..c9bc73a9c 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/censorship/referencetype/ReferenceTypeDefinitionCensor.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/censorship/referencetype/ReferenceTypeDefinitionCensor.java @@ -42,8 +42,8 @@ public class ReferenceTypeDefinitionCensor extends BaseCensor { FieldSet fieldsFields = fields.extractPrefixed(this.asIndexerPrefix(ReferenceTypeDefinition._fields)); this.censorFactory.censor(ReferenceTypeFieldCensor.class).censor(fieldsFields, userId); - FieldSet urlConfigFields = fields.extractPrefixed(this.asIndexerPrefix(ReferenceTypeDefinition._urlConfig)); - this.censorFactory.censor(ReferenceTypeUrlConfigurationCensor.class).censor(urlConfigFields, userId); + FieldSet externalApiConfigFields = fields.extractPrefixed(this.asIndexerPrefix(ReferenceTypeDefinition._externalApiConfig)); + this.censorFactory.censor(ReferenceTypeExternalApiConfigurationCensor.class).censor(externalApiConfigFields, userId); } } diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/censorship/referencetype/ReferenceTypeUrlConfigurationCensor.java b/dmp-backend/core/src/main/java/eu/eudat/model/censorship/referencetype/ReferenceTypeExternalApiConfigurationCensor.java similarity index 66% rename from dmp-backend/core/src/main/java/eu/eudat/model/censorship/referencetype/ReferenceTypeUrlConfigurationCensor.java rename to dmp-backend/core/src/main/java/eu/eudat/model/censorship/referencetype/ReferenceTypeExternalApiConfigurationCensor.java index 855374875..3134ae286 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/censorship/referencetype/ReferenceTypeUrlConfigurationCensor.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/censorship/referencetype/ReferenceTypeExternalApiConfigurationCensor.java @@ -3,8 +3,7 @@ package eu.eudat.model.censorship.referencetype; import eu.eudat.authorization.Permission; import eu.eudat.convention.ConventionService; import eu.eudat.model.censorship.BaseCensor; -import eu.eudat.model.referencetypedefinition.ReferenceTypeDefinition; -import eu.eudat.model.referencetypedefinition.ReferenceTypeUrlConfiguration; +import eu.eudat.model.referencetypedefinition.ReferenceTypeExternalApiConfiguration; import gr.cite.commons.web.authz.service.AuthorizationService; import gr.cite.tools.data.censor.CensorFactory; import gr.cite.tools.fieldset.FieldSet; @@ -19,15 +18,15 @@ import java.util.UUID; @Component @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) -public class ReferenceTypeUrlConfigurationCensor extends BaseCensor { +public class ReferenceTypeExternalApiConfigurationCensor extends BaseCensor { - private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(ReferenceTypeUrlConfigurationCensor.class)); + private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(ReferenceTypeExternalApiConfigurationCensor.class)); protected final AuthorizationService authService; protected final CensorFactory censorFactory; - public ReferenceTypeUrlConfigurationCensor(ConventionService conventionService, - AuthorizationService authService, CensorFactory censorFactory) { + public ReferenceTypeExternalApiConfigurationCensor(ConventionService conventionService, + AuthorizationService authService, CensorFactory censorFactory) { super(conventionService); this.authService = authService; this.censorFactory = censorFactory; @@ -40,13 +39,13 @@ public class ReferenceTypeUrlConfigurationCensor extends BaseCensor { this.authService.authorizeForce(Permission.BrowseReferenceType); - FieldSet dataFields = fields.extractPrefixed(this.asIndexerPrefix(ReferenceTypeUrlConfiguration._data)); - this.censorFactory.censor(DataUrlConfigurationCensor.class).censor(dataFields, userId); + FieldSet resultsFields = fields.extractPrefixed(this.asIndexerPrefix(ReferenceTypeExternalApiConfiguration._results)); + this.censorFactory.censor(ResultsConfigurationCensor.class).censor(resultsFields, userId); - FieldSet authFields = fields.extractPrefixed(this.asIndexerPrefix(ReferenceTypeUrlConfiguration._auth)); + FieldSet authFields = fields.extractPrefixed(this.asIndexerPrefix(ReferenceTypeExternalApiConfiguration._auth)); this.censorFactory.censor(AuthenticationConfigurationCensor.class).censor(authFields, userId); - FieldSet queriesFields = fields.extractPrefixed(this.asIndexerPrefix(ReferenceTypeUrlConfiguration._queries)); + FieldSet queriesFields = fields.extractPrefixed(this.asIndexerPrefix(ReferenceTypeExternalApiConfiguration._queries)); this.censorFactory.censor(QueryConfigCensor.class).censor(queriesFields, userId); } diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/censorship/referencetype/DataFieldsUrlConfigurationCensor.java b/dmp-backend/core/src/main/java/eu/eudat/model/censorship/referencetype/ResultFieldsMappingConfigurationCensor.java similarity index 78% rename from dmp-backend/core/src/main/java/eu/eudat/model/censorship/referencetype/DataFieldsUrlConfigurationCensor.java rename to dmp-backend/core/src/main/java/eu/eudat/model/censorship/referencetype/ResultFieldsMappingConfigurationCensor.java index e167be5be..b751b8707 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/censorship/referencetype/DataFieldsUrlConfigurationCensor.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/censorship/referencetype/ResultFieldsMappingConfigurationCensor.java @@ -16,14 +16,14 @@ import java.util.UUID; @Component @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) -public class DataFieldsUrlConfigurationCensor extends BaseCensor { +public class ResultFieldsMappingConfigurationCensor extends BaseCensor { - private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(DataFieldsUrlConfigurationCensor.class)); + private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(ResultFieldsMappingConfigurationCensor.class)); protected final AuthorizationService authService; - public DataFieldsUrlConfigurationCensor(ConventionService conventionService, - AuthorizationService authService) { + public ResultFieldsMappingConfigurationCensor(ConventionService conventionService, + AuthorizationService authService) { super(conventionService); this.authService = authService; } diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/censorship/referencetype/DataUrlConfigurationCensor.java b/dmp-backend/core/src/main/java/eu/eudat/model/censorship/referencetype/ResultsConfigurationCensor.java similarity index 74% rename from dmp-backend/core/src/main/java/eu/eudat/model/censorship/referencetype/DataUrlConfigurationCensor.java rename to dmp-backend/core/src/main/java/eu/eudat/model/censorship/referencetype/ResultsConfigurationCensor.java index bfdaf2b81..e8b4764e7 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/censorship/referencetype/DataUrlConfigurationCensor.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/censorship/referencetype/ResultsConfigurationCensor.java @@ -3,7 +3,7 @@ package eu.eudat.model.censorship.referencetype; import eu.eudat.authorization.Permission; import eu.eudat.convention.ConventionService; import eu.eudat.model.censorship.BaseCensor; -import eu.eudat.model.referencetypedefinition.DataUrlConfiguration; +import eu.eudat.model.referencetypedefinition.ResultsConfiguration; import gr.cite.commons.web.authz.service.AuthorizationService; import gr.cite.tools.data.censor.CensorFactory; import gr.cite.tools.fieldset.FieldSet; @@ -18,14 +18,14 @@ import java.util.UUID; @Component @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) -public class DataUrlConfigurationCensor extends BaseCensor { +public class ResultsConfigurationCensor extends BaseCensor { - private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(DataUrlConfigurationCensor.class)); + private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(ResultsConfigurationCensor.class)); protected final AuthorizationService authService; protected final CensorFactory censorFactory; - public DataUrlConfigurationCensor(ConventionService conventionService, + public ResultsConfigurationCensor(ConventionService conventionService, AuthorizationService authService, CensorFactory censorFactory) { super(conventionService); this.authService = authService; @@ -38,8 +38,8 @@ public class DataUrlConfigurationCensor extends BaseCensor { return; this.authService.authorizeForce(Permission.BrowseReferenceType); - FieldSet fieldsUrlFields = fields.extractPrefixed(this.asIndexerPrefix(DataUrlConfiguration._fieldsUrlConfiguration)); - this.censorFactory.censor(DataFieldsUrlConfigurationCensor.class).censor(fieldsUrlFields, userId); + FieldSet fieldsMappingFields = fields.extractPrefixed(this.asIndexerPrefix(ResultsConfiguration._fieldsMapping)); + this.censorFactory.censor(ResultFieldsMappingConfigurationCensor.class).censor(fieldsMappingFields, userId); } } diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/persist/ReferenceTypePersist.java b/dmp-backend/core/src/main/java/eu/eudat/model/persist/ReferenceTypePersist.java index 58ea31ba5..080d876e8 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/persist/ReferenceTypePersist.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/persist/ReferenceTypePersist.java @@ -29,6 +29,8 @@ public class ReferenceTypePersist { @Valid private ReferenceTypeDefinitionPersist definition; + private String hash; + public UUID getId() { return id; } @@ -60,4 +62,12 @@ public class ReferenceTypePersist { public void setDefinition(ReferenceTypeDefinitionPersist definition) { this.definition = definition; } + + public String getHash() { + return hash; + } + + public void setHash(String hash) { + this.hash = hash; + } } diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/persist/referencetypedefinition/AuthenticationConfigurationPersist.java b/dmp-backend/core/src/main/java/eu/eudat/model/persist/referencetypedefinition/AuthenticationConfigurationPersist.java index 66418d90b..8e07dc822 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/persist/referencetypedefinition/AuthenticationConfigurationPersist.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/persist/referencetypedefinition/AuthenticationConfigurationPersist.java @@ -5,16 +5,16 @@ import jakarta.validation.constraints.NotNull; public class AuthenticationConfigurationPersist { @NotNull(message = "{validation.empty}") - private String authUrl; + private String authUrl = null; private String authMethod = "GET"; @NotNull(message = "{validation.empty}") - private String authTokenPath; + private String authTokenPath = null; @NotNull(message = "{validation.empty}") - private String authRequestBody; + private String authRequestBody = null; @NotNull(message = "{validation.empty}") - private String type; + private String type = null; public String getAuthUrl() { return authUrl; diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/persist/referencetypedefinition/DataFieldsUrlConfigurationPersist.java b/dmp-backend/core/src/main/java/eu/eudat/model/persist/referencetypedefinition/DataFieldsUrlConfigurationPersist.java deleted file mode 100644 index 79f06e2ce..000000000 --- a/dmp-backend/core/src/main/java/eu/eudat/model/persist/referencetypedefinition/DataFieldsUrlConfigurationPersist.java +++ /dev/null @@ -1,104 +0,0 @@ -package eu.eudat.model.persist.referencetypedefinition; - -public class DataFieldsUrlConfigurationPersist { - - private String id; - private String name; - private String pid; - private String pidTypeField; - private String uri; - private String description; - private String source; - private String count; - private String types; - private String firstName; - private String lastName; - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getPid() { - return pid; - } - - public void setPid(String pid) { - this.pid = pid; - } - - public String getPidTypeField() { - return pidTypeField; - } - - public void setPidTypeField(String pidTypeField) { - this.pidTypeField = pidTypeField; - } - - public String getUri() { - return uri; - } - - public void setUri(String uri) { - this.uri = uri; - } - - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - - public String getSource() { - return source; - } - - public void setSource(String source) { - this.source = source; - } - - public String getCount() { - return count; - } - - public void setCount(String count) { - this.count = count; - } - - public String getTypes() { - return types; - } - - public void setTypes(String types) { - this.types = types; - } - - public String getFirstName() { - return firstName; - } - - public void setFirstName(String firstName) { - this.firstName = firstName; - } - - public String getLastName() { - return lastName; - } - - public void setLastName(String lastName) { - this.lastName = lastName; - } -} diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/persist/referencetypedefinition/DataUrlConfigurationPersist.java b/dmp-backend/core/src/main/java/eu/eudat/model/persist/referencetypedefinition/DataUrlConfigurationPersist.java deleted file mode 100644 index aeb377cb9..000000000 --- a/dmp-backend/core/src/main/java/eu/eudat/model/persist/referencetypedefinition/DataUrlConfigurationPersist.java +++ /dev/null @@ -1,31 +0,0 @@ -package eu.eudat.model.persist.referencetypedefinition; - -import jakarta.validation.Valid; -import jakarta.validation.constraints.NotEmpty; -import jakarta.validation.constraints.NotNull; - -public class DataUrlConfigurationPersist { - - @NotNull(message = "{validation.empty}") - @NotEmpty(message = "{validation.empty}") - private String path; - - @Valid - private DataFieldsUrlConfigurationPersist fieldsUrlConfiguration; - - public String getPath() { - return path; - } - - public void setPath(String path) { - this.path = path; - } - - public DataFieldsUrlConfigurationPersist getFieldsUrlConfiguration() { - return fieldsUrlConfiguration; - } - - public void setFieldsUrlConfiguration(DataFieldsUrlConfigurationPersist fieldsUrlConfiguration) { - this.fieldsUrlConfiguration = fieldsUrlConfiguration; - } -} diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/persist/referencetypedefinition/ReferenceTypeDefinitionPersist.java b/dmp-backend/core/src/main/java/eu/eudat/model/persist/referencetypedefinition/ReferenceTypeDefinitionPersist.java index 4d7f87998..e70497d93 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/persist/referencetypedefinition/ReferenceTypeDefinitionPersist.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/persist/referencetypedefinition/ReferenceTypeDefinitionPersist.java @@ -1,6 +1,5 @@ package eu.eudat.model.persist.referencetypedefinition; -import eu.eudat.model.persist.dmpblueprintdefinition.SectionPersist; import jakarta.validation.Valid; import jakarta.validation.constraints.NotNull; @@ -14,7 +13,7 @@ public class ReferenceTypeDefinitionPersist { @NotNull(message = "{validation.empty}") @Valid - private List urlConfig = null; + private List externalApiConfig = null; public List getFields() { return fields; @@ -24,11 +23,11 @@ public class ReferenceTypeDefinitionPersist { this.fields = fields; } - public List getUrlConfig() { - return urlConfig; + public List getExternalApiConfig() { + return externalApiConfig; } - public void setUrlConfig(List urlConfig) { - this.urlConfig = urlConfig; + public void setExternalApiConfig(List externalApiConfig) { + this.externalApiConfig = externalApiConfig; } } diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/persist/referencetypedefinition/ReferenceTypeUrlConfigurationPersist.java b/dmp-backend/core/src/main/java/eu/eudat/model/persist/referencetypedefinition/ReferenceTypeExternalApiConfigurationPersist.java similarity index 77% rename from dmp-backend/core/src/main/java/eu/eudat/model/persist/referencetypedefinition/ReferenceTypeUrlConfigurationPersist.java rename to dmp-backend/core/src/main/java/eu/eudat/model/persist/referencetypedefinition/ReferenceTypeExternalApiConfigurationPersist.java index e241392c0..60947f85d 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/persist/referencetypedefinition/ReferenceTypeUrlConfigurationPersist.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/persist/referencetypedefinition/ReferenceTypeExternalApiConfigurationPersist.java @@ -6,44 +6,41 @@ import jakarta.validation.constraints.NotNull; import java.util.List; -public class ReferenceTypeUrlConfigurationPersist { +public class ReferenceTypeExternalApiConfigurationPersist { @NotNull(message = "{validation.empty}") @NotEmpty(message = "{validation.empty}") - private String key; + private String key = null; @NotNull(message = "{validation.empty}") @NotEmpty(message = "{validation.empty}") - private String label; + private String label = null; + + @NotNull(message = "{validation.empty}") + private Integer ordinal = null; @NotNull(message = "{validation.empty}") @NotEmpty(message = "{validation.empty}") - private Integer ordinal; - - @NotNull(message = "{validation.empty}") - @NotEmpty(message = "{validation.empty}") - private String url; + private String url = null; @Valid - private DataUrlConfigurationPersist data; + private ResultsConfigurationPersist results; @NotNull(message = "{validation.empty}") @NotEmpty(message = "{validation.empty}") - private String type; + private String type = null; @NotNull(message = "{validation.empty}") @NotEmpty(message = "{validation.empty}") - private String paginationPath; + private String paginationPath = null; @NotNull(message = "{validation.empty}") @NotEmpty(message = "{validation.empty}") - private String contentType; - - private String funderQuery; + private String contentType = null; @NotNull(message = "{validation.empty}") @NotEmpty(message = "{validation.empty}") - private String firstpage; + private String firstPage = null; private String requestType = "GET"; private String requestBody = ""; @@ -87,12 +84,12 @@ public class ReferenceTypeUrlConfigurationPersist { this.url = url; } - public DataUrlConfigurationPersist getData() { - return data; + public ResultsConfigurationPersist getResults() { + return results; } - public void setData(DataUrlConfigurationPersist data) { - this.data = data; + public void setResults(ResultsConfigurationPersist results) { + this.results = results; } public String getType() { @@ -119,20 +116,13 @@ public class ReferenceTypeUrlConfigurationPersist { this.contentType = contentType; } - public String getFunderQuery() { - return funderQuery; + + public String getFirstPage() { + return firstPage; } - public void setFunderQuery(String funderQuery) { - this.funderQuery = funderQuery; - } - - public String getFirstpage() { - return firstpage; - } - - public void setFirstpage(String firstpage) { - this.firstpage = firstpage; + public void setFirstPage(String firstPage) { + this.firstPage = firstPage; } public String getRequestType() { diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/persist/referencetypedefinition/ResultFieldsMappingConfigurationPersist.java b/dmp-backend/core/src/main/java/eu/eudat/model/persist/referencetypedefinition/ResultFieldsMappingConfigurationPersist.java new file mode 100644 index 000000000..7616066bb --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/model/persist/referencetypedefinition/ResultFieldsMappingConfigurationPersist.java @@ -0,0 +1,31 @@ +package eu.eudat.model.persist.referencetypedefinition; + +import jakarta.validation.constraints.NotEmpty; +import jakarta.validation.constraints.NotNull; + +public class ResultFieldsMappingConfigurationPersist { + + @NotNull(message = "{validation.empty}") + @NotEmpty(message = "{validation.empty}") + private String code; + + @NotNull(message = "{validation.empty}") + @NotEmpty(message = "{validation.empty}") + private String responsePath; + + public String getCode() { + return code; + } + + public void setCode(String code) { + this.code = code; + } + + public String getResponsePath() { + return responsePath; + } + + public void setResponsePath(String responsePath) { + this.responsePath = responsePath; + } +} diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/persist/referencetypedefinition/ResultsConfigurationPersist.java b/dmp-backend/core/src/main/java/eu/eudat/model/persist/referencetypedefinition/ResultsConfigurationPersist.java new file mode 100644 index 000000000..bd35e4051 --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/model/persist/referencetypedefinition/ResultsConfigurationPersist.java @@ -0,0 +1,34 @@ +package eu.eudat.model.persist.referencetypedefinition; + +import jakarta.validation.Valid; +import jakarta.validation.constraints.NotEmpty; +import jakarta.validation.constraints.NotNull; + +import java.util.List; + +public class ResultsConfigurationPersist { + + @NotNull(message = "{validation.empty}") + @NotEmpty(message = "{validation.empty}") + private String resultsArrayPath; + + @NotNull(message = "{validation.empty}") + @Valid + private List fieldsMapping; + + public String getResultsArrayPath() { + return resultsArrayPath; + } + + public void setResultsArrayPath(String resultsArrayPath) { + this.resultsArrayPath = resultsArrayPath; + } + + public List getFieldsMapping() { + return fieldsMapping; + } + + public void setFieldsMapping(List fieldsMapping) { + this.fieldsMapping = fieldsMapping; + } +} diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/referencetypedefinition/DataFieldsUrlConfiguration.java b/dmp-backend/core/src/main/java/eu/eudat/model/referencetypedefinition/DataFieldsUrlConfiguration.java deleted file mode 100644 index d9a48003e..000000000 --- a/dmp-backend/core/src/main/java/eu/eudat/model/referencetypedefinition/DataFieldsUrlConfiguration.java +++ /dev/null @@ -1,149 +0,0 @@ -package eu.eudat.model.referencetypedefinition; - - -public class DataFieldsUrlConfiguration { - - public final static String _id = "id"; - private String id; - - public final static String _name = "name"; - private String name; - - public final static String _pid = "pid"; - private String pid; - - public final static String _pidTypeField = "pidTypeField"; - private String pidTypeField; - - public final static String _uri = "uri"; - private String uri; - - public final static String _description= "description"; - private String description; - - public final static String _source = "source"; - private String source; - - public final static String _count = "count"; - private String count; - -// public final static String _path = "path"; -// private String path; -// -// public final static String _host = "host"; -// private String host; - - public final static String _types = "types"; - private String types; - - public final static String _firstName = "firstName"; - private String firstName; - - public final static String _lastName = "lastName"; - private String lastName; - - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getPid() { - return pid; - } - - public void setPid(String pid) { - this.pid = pid; - } - - public String getPidTypeField() { - return pidTypeField; - } - - public void setPidTypeField(String pidTypeField) { - this.pidTypeField = pidTypeField; - } - - public String getUri() { - return uri; - } - - public void setUri(String uri) { - this.uri = uri; - } - - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - - public String getSource() { - return source; - } - - public void setSource(String source) { - this.source = source; - } - - public String getCount() { - return count; - } - - public void setCount(String count) { - this.count = count; - } - -// public String getPath() { -// return path; -// } -// -// public void setPath(String path) { -// this.path = path; -// } -// -// public String getHost() { -// return host; -// } -// -// public void setHost(String host) { -// this.host = host; -// } - - public String getTypes() { - return types; - } - - public void setTypes(String types) { - this.types = types; - } - - public String getFirstName() { - return firstName; - } - - public void setFirstName(String firstName) { - this.firstName = firstName; - } - - public String getLastName() { - return lastName; - } - - public void setLastName(String lastName) { - this.lastName = lastName; - } -} diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/referencetypedefinition/DataUrlConfiguration.java b/dmp-backend/core/src/main/java/eu/eudat/model/referencetypedefinition/DataUrlConfiguration.java deleted file mode 100644 index 10411ac10..000000000 --- a/dmp-backend/core/src/main/java/eu/eudat/model/referencetypedefinition/DataUrlConfiguration.java +++ /dev/null @@ -1,74 +0,0 @@ -package eu.eudat.model.referencetypedefinition; - - -import java.util.List; - -public class DataUrlConfiguration { - - public final static String _path = "path"; - private String path; - - public final static String _fieldsUrlConfiguration = "fieldsUrlConfiguration"; - private DataFieldsUrlConfiguration fieldsUrlConfiguration; - -// public final static String _parseClass = "parseClass"; -// private String parseClass; -// -// public final static String _parseField = "parseField"; -// private String parseField; -// -// public final static String _mergedFields = "mergedFields"; -// private List mergedFields; -// -// public final static String _mergedFieldName = "mergedFieldName"; -// private String mergedFieldName; - - - public String getPath() { - return path; - } - - public void setPath(String path) { - this.path = path; - } - - public DataFieldsUrlConfiguration getFieldsUrlConfiguration() { - return fieldsUrlConfiguration; - } - - public void setFieldsUrlConfiguration(DataFieldsUrlConfiguration fieldsUrlConfiguration) { - this.fieldsUrlConfiguration = fieldsUrlConfiguration; - } - -// public String getParseClass() { -// return parseClass; -// } -// -// public void setParseClass(String parseClass) { -// this.parseClass = parseClass; -// } -// -// public String getParseField() { -// return parseField; -// } -// -// public void setParseField(String parseField) { -// this.parseField = parseField; -// } -// -// public List getMergedFields() { -// return mergedFields; -// } -// -// public void setMergedFields(List mergedFields) { -// this.mergedFields = mergedFields; -// } -// -// public String getMergedFieldName() { -// return mergedFieldName; -// } -// -// public void setMergedFieldName(String mergedFieldName) { -// this.mergedFieldName = mergedFieldName; -// } -} diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/referencetypedefinition/ReferenceTypeDefinition.java b/dmp-backend/core/src/main/java/eu/eudat/model/referencetypedefinition/ReferenceTypeDefinition.java index 30363a8a3..67e837625 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/referencetypedefinition/ReferenceTypeDefinition.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/referencetypedefinition/ReferenceTypeDefinition.java @@ -7,8 +7,8 @@ public class ReferenceTypeDefinition { public final static String _fields = "fields"; private List fields; - public final static String _urlConfig = "urlConfig"; - private List urlConfig; + public final static String _externalApiConfig = "externalApiConfig"; + private List externalApiConfig; public List getFields() { return fields; @@ -18,11 +18,11 @@ public class ReferenceTypeDefinition { this.fields = fields; } - public List getUrlConfig() { - return urlConfig; + public List getExternalApiConfig() { + return externalApiConfig; } - public void setUrlConfig(List urlConfig) { - this.urlConfig = urlConfig; + public void setExternalApiConfig(List externalApiConfig) { + this.externalApiConfig = externalApiConfig; } } diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/referencetypedefinition/ReferenceTypeUrlConfiguration.java b/dmp-backend/core/src/main/java/eu/eudat/model/referencetypedefinition/ReferenceTypeExternalApiConfiguration.java similarity index 85% rename from dmp-backend/core/src/main/java/eu/eudat/model/referencetypedefinition/ReferenceTypeUrlConfiguration.java rename to dmp-backend/core/src/main/java/eu/eudat/model/referencetypedefinition/ReferenceTypeExternalApiConfiguration.java index d3857e15c..fed65fd8f 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/referencetypedefinition/ReferenceTypeUrlConfiguration.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/referencetypedefinition/ReferenceTypeExternalApiConfiguration.java @@ -3,7 +3,7 @@ package eu.eudat.model.referencetypedefinition; import java.util.List; -public class ReferenceTypeUrlConfiguration { +public class ReferenceTypeExternalApiConfiguration { public final static String _key = "key"; private String key; @@ -18,8 +18,8 @@ public class ReferenceTypeUrlConfiguration { private String url; - public final static String _data = "data"; - private DataUrlConfiguration data; + public final static String _results = "results"; + private ResultsConfiguration results; public final static String _type = "type"; private String type; @@ -30,9 +30,6 @@ public class ReferenceTypeUrlConfiguration { public final static String _contentType = "contentType"; private String contentType; - public final static String _funderQuery = "funderQuery"; - private String funderQuery; - public final static String _firstPage = "firstPage"; private String firstPage; @@ -83,12 +80,12 @@ public class ReferenceTypeUrlConfiguration { this.url = url; } - public DataUrlConfiguration getData() { - return data; + public ResultsConfiguration getResults() { + return results; } - public void setData(DataUrlConfiguration data) { - this.data = data; + public void setResults(ResultsConfiguration results) { + this.results = results; } public String getType() { @@ -115,13 +112,6 @@ public class ReferenceTypeUrlConfiguration { this.contentType = contentType; } - public String getFunderQuery() { - return funderQuery; - } - - public void setFunderQuery(String funderQuery) { - this.funderQuery = funderQuery; - } public String getFirstPage() { return firstPage; diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/referencetypedefinition/ResultFieldsMappingConfiguration.java b/dmp-backend/core/src/main/java/eu/eudat/model/referencetypedefinition/ResultFieldsMappingConfiguration.java new file mode 100644 index 000000000..181fe92e5 --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/model/referencetypedefinition/ResultFieldsMappingConfiguration.java @@ -0,0 +1,29 @@ +package eu.eudat.model.referencetypedefinition; + + +public class ResultFieldsMappingConfiguration { + + public final static String _code = "id"; + private String code; + + public final static String _responsePath = "responsePath"; + private String responsePath; + + + public String getCode() { + return code; + } + + public void setCode(String code) { + this.code = code; + } + + public String getResponsePath() { + return responsePath; + } + + public void setResponsePath(String responsePath) { + this.responsePath = responsePath; + } + +} diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/referencetypedefinition/ResultsConfiguration.java b/dmp-backend/core/src/main/java/eu/eudat/model/referencetypedefinition/ResultsConfiguration.java new file mode 100644 index 000000000..3d52b7d8a --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/model/referencetypedefinition/ResultsConfiguration.java @@ -0,0 +1,29 @@ +package eu.eudat.model.referencetypedefinition; + + +import java.util.List; + +public class ResultsConfiguration { + + public final static String _resultsArrayPath = "resultsArrayPath"; + private String resultsArrayPath; + + public final static String _fieldsMapping = "fieldsMapping"; + private List fieldsMapping; + + public String getResultsArrayPath() { + return resultsArrayPath; + } + + public void setResultsArrayPath(String resultsArrayPath) { + this.resultsArrayPath = resultsArrayPath; + } + + public List getFieldsMapping() { + return fieldsMapping; + } + + public void setFieldsMapping(List fieldsMapping) { + this.fieldsMapping = fieldsMapping; + } +} diff --git a/dmp-backend/core/src/main/java/eu/eudat/service/referencetype/ReferenceTypeServiceImpl.java b/dmp-backend/core/src/main/java/eu/eudat/service/referencetype/ReferenceTypeServiceImpl.java index 086f88020..f52602259 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/service/referencetype/ReferenceTypeServiceImpl.java +++ b/dmp-backend/core/src/main/java/eu/eudat/service/referencetype/ReferenceTypeServiceImpl.java @@ -111,10 +111,10 @@ public class ReferenceTypeServiceImpl implements ReferenceTypeService { data.getFields().add(this.buildFieldEntity(fieldPersist)); } } - if (!this.conventionService.isListNullOrEmpty(persist.getUrlConfig())){ - data.setUrlConfig(new ArrayList<>()); - for (ReferenceTypeUrlConfigurationPersist urlConfigPersist: persist.getUrlConfig()) { - data.getUrlConfig().add(this.buildUrlConfigEntity(urlConfigPersist)); + if (!this.conventionService.isListNullOrEmpty(persist.getExternalApiConfig())){ + data.setExternalApiConfig(new ArrayList<>()); + for (ReferenceTypeExternalApiConfigurationPersist externalApiConfigPersist: persist.getExternalApiConfig()) { + data.getExternalApiConfig().add(this.buildExternalApiConfigEntity(externalApiConfigPersist)); } } @@ -131,20 +131,19 @@ public class ReferenceTypeServiceImpl implements ReferenceTypeService { return data; } - private @NotNull ReferenceTypeUrlConfigurationEntity buildUrlConfigEntity(ReferenceTypeUrlConfigurationPersist persist){ - ReferenceTypeUrlConfigurationEntity data = new ReferenceTypeUrlConfigurationEntity(); + private @NotNull ReferenceTypeExternalApiConfigurationEntity buildExternalApiConfigEntity(ReferenceTypeExternalApiConfigurationPersist persist){ + ReferenceTypeExternalApiConfigurationEntity data = new ReferenceTypeExternalApiConfigurationEntity(); if (persist == null) return data; data.setKey(persist.getKey()); data.setLabel(persist.getLabel()); data.setOrdinal(persist.getOrdinal()); data.setUrl(persist.getUrl()); - if (persist.getData() != null ) data.setData(this.buildDataUrlConfigEntity(persist.getData())); + if (persist.getResults() != null ) data.setResults(this.buildResultsConfigEntity(persist.getResults())); data.setType(persist.getType()); data.setPaginationPath(persist.getPaginationPath()); data.setContentType(persist.getContentType()); - data.setFunderQuery(persist.getFunderQuery()); - data.setFirstpage(persist.getFirstpage()); + data.setFirstPage(persist.getFirstPage()); data.setRequestType(persist.getRequestType()); data.setRequestBody(persist.getRequestBody()); data.setFilterType(persist.getFilterType()); @@ -159,31 +158,28 @@ public class ReferenceTypeServiceImpl implements ReferenceTypeService { return data; } - private @NotNull DataUrlConfigurationEntity buildDataUrlConfigEntity(DataUrlConfigurationPersist persist){ - DataUrlConfigurationEntity data = new DataUrlConfigurationEntity(); + private @NotNull ResultsConfigurationEntity buildResultsConfigEntity(ResultsConfigurationPersist persist){ + ResultsConfigurationEntity data = new ResultsConfigurationEntity(); if (persist == null) return data; - data.setPath(persist.getPath()); - if (persist.getFieldsUrlConfiguration() != null ) data.setFieldsUrlConfiguration(this.buildDataFieldsUrlConfigEntity(persist.getFieldsUrlConfiguration())); + data.setResultsArrayPath(persist.getResultsArrayPath()); + + if (!this.conventionService.isListNullOrEmpty(persist.getFieldsMapping())){ + data.setFieldsMapping(new ArrayList<>()); + for (ResultFieldsMappingConfigurationPersist fieldsMappingPersist: persist.getFieldsMapping()) { + data.getFieldsMapping().add(this.buildResultFieldsMappingConfigEntity(fieldsMappingPersist)); + } + } return data; } - private @NotNull DataFieldsUrlConfigurationEntity buildDataFieldsUrlConfigEntity(DataFieldsUrlConfigurationPersist persist){ - DataFieldsUrlConfigurationEntity data = new DataFieldsUrlConfigurationEntity(); + private @NotNull ResultFieldsMappingConfigurationEntity buildResultFieldsMappingConfigEntity(ResultFieldsMappingConfigurationPersist persist){ + ResultFieldsMappingConfigurationEntity data = new ResultFieldsMappingConfigurationEntity(); if (persist == null) return data; - data.setId(persist.getId()); - data.setName(persist.getName()); - data.setPid(persist.getPid()); - data.setPidTypeField(persist.getPidTypeField()); - data.setUri(persist.getUri()); - data.setDescription(persist.getDescription()); - data.setSource(persist.getSource()); - data.setCount(persist.getCount()); - data.setTypes(persist.getTypes()); - data.setFirstName(persist.getFirstName()); - data.setLastName(persist.getLastName()); + data.setCode(persist.getCode()); + data.setResponsePath(persist.getResponsePath()); return data; } diff --git a/dmp-frontend/src/app/core/model/reference-type/reference-type.ts b/dmp-frontend/src/app/core/model/reference-type/reference-type.ts index 5872dae7b..7a23408ee 100644 --- a/dmp-frontend/src/app/core/model/reference-type/reference-type.ts +++ b/dmp-frontend/src/app/core/model/reference-type/reference-type.ts @@ -1,15 +1,12 @@ import { IsActive } from "@app/core/common/enum/is-active.enum"; import { ReferenceFieldDataType } from "@app/core/common/enum/reference-field-data-type"; +import { BaseEntity, BaseEntityPersist } from "@common/base/base-entity.model"; import { Guid } from "@common/types/guid"; -export interface ReferenceType { - id: Guid; +export interface ReferenceType extends BaseEntity{ name: string; code: string; definition: ReferenceTypeDefinition; - isActive: IsActive; - createdAt: Date; - updatedAt: Date; } export interface ReferenceTypeDefinition{ @@ -68,8 +65,7 @@ export interface QueryConfig{ // Persist -export interface ReferenceTypePersist { - id?: Guid; +export interface ReferenceTypePersist extends BaseEntityPersist{ name: string; code: string; definition: ReferenceTypeDefinitionPersist; diff --git a/dmp-frontend/src/app/ui/admin/reference-type/editor/reference-type-editor.component.ts b/dmp-frontend/src/app/ui/admin/reference-type/editor/reference-type-editor.component.ts index e4ff9be97..b7977580a 100644 --- a/dmp-frontend/src/app/ui/admin/reference-type/editor/reference-type-editor.component.ts +++ b/dmp-frontend/src/app/ui/admin/reference-type/editor/reference-type-editor.component.ts @@ -146,11 +146,11 @@ export class ReferenceTypeEditorComponent extends BaseEditor void): void { const formData = this.formService.getValue(this.formGroup.value) as ReferenceTypePersist; console.log(formData); - // this.referenceTypeService.persist(formData) - // .pipe(takeUntil(this._destroyed)).subscribe( - // complete => onSuccess ? onSuccess(complete) : this.onCallbackSuccess(complete), - // error => this.onCallbackError(error) - // ); + this.referenceTypeService.persist(formData) + .pipe(takeUntil(this._destroyed)).subscribe( + complete => onSuccess ? onSuccess(complete) : this.onCallbackSuccess(complete), + error => this.onCallbackError(error) + ); } formSubmit(): void { diff --git a/dmp-frontend/src/app/ui/admin/reference-type/editor/reference-type-editor.model.ts b/dmp-frontend/src/app/ui/admin/reference-type/editor/reference-type-editor.model.ts index 46a67d689..17d6c60a3 100644 --- a/dmp-frontend/src/app/ui/admin/reference-type/editor/reference-type-editor.model.ts +++ b/dmp-frontend/src/app/ui/admin/reference-type/editor/reference-type-editor.model.ts @@ -20,10 +20,13 @@ export class ReferenceTypeEditorModel extends BaseEditorModel implements Referen public fromModel(item: ReferenceType): ReferenceTypeEditorModel { if (item) { - super.fromModel(item); + this.id = item.id; this.name = item.name; this.code = item.code; this.definition = new ReferenceTypeDefinitionEditorModel().fromModel(item.definition); + this.hash = item.hash; + if (item.createdAt) { this.createdAt = item.createdAt; } + if (item.updatedAt) { this.updatedAt = item.updatedAt; } } return this; } @@ -115,7 +118,7 @@ export class ReferenceTypeDefinitionEditorModel implements ReferenceTypeDefiniti const baseContext: ValidationContext = new ValidationContext(); const baseValidationArray: Validation[] = new Array(); baseValidationArray.push({ key: 'fields', validators: [Validators.required, BackendErrorValidator(validationErrorModel, `${rootPath}fields`)] }); - baseValidationArray.push({ key: 'externalApiConfig', validators: [BackendErrorValidator(validationErrorModel, `${rootPath}externalApiConfig`)] }); + baseValidationArray.push({ key: 'externalApiConfig', validators: [Validators.required, BackendErrorValidator(validationErrorModel, `${rootPath}externalApiConfig`)] }); baseContext.validation = baseValidationArray; return baseContext; diff --git a/dmp-frontend/src/app/ui/admin/reference-type/listing/reference-type-listing.component.html b/dmp-frontend/src/app/ui/admin/reference-type/listing/reference-type-listing.component.html index 0c2430644..26530010e 100644 --- a/dmp-frontend/src/app/ui/admin/reference-type/listing/reference-type-listing.component.html +++ b/dmp-frontend/src/app/ui/admin/reference-type/listing/reference-type-listing.component.html @@ -94,7 +94,7 @@ more_horiz -