add dependencies to reference type source base

This commit is contained in:
amentis 2023-11-21 12:51:26 +02:00
parent e62d765796
commit e1985368aa
33 changed files with 1385 additions and 226 deletions

View File

@ -0,0 +1,44 @@
package eu.eudat.commons.types.referencetype;
import jakarta.xml.bind.annotation.XmlAccessType;
import jakarta.xml.bind.annotation.XmlAccessorType;
import jakarta.xml.bind.annotation.XmlAttribute;
import jakarta.xml.bind.annotation.XmlRootElement;
@XmlRootElement(name = "property")
@XmlAccessorType(XmlAccessType.FIELD)
public class DependencyPropertyEntity {
@XmlAttribute(name = "code")
private String code;
@XmlAttribute(name = "target")
private String target;
@XmlAttribute(name = "required")
private Boolean required;
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public String getTarget() {
return target;
}
public void setTarget(String target) {
this.target = target;
}
public Boolean getRequired() {
return required;
}
public void setRequired(Boolean required) {
this.required = required;
}
}

View File

@ -2,6 +2,9 @@ package eu.eudat.commons.types.referencetype;
import eu.eudat.commons.enums.ReferenceTypeSourceType;
import jakarta.xml.bind.annotation.XmlElement;
import jakarta.xml.bind.annotation.XmlElementWrapper;
import java.util.List;
public abstract class ReferenceTypeSourceBaseConfigurationEntity {
@ -12,7 +15,7 @@ public abstract class ReferenceTypeSourceBaseConfigurationEntity {
private Integer ordinal;
private ReferenceTypeSourceType type;
private List<ReferenceTypeSourceBaseDependencyEntity> dependencies;
public ReferenceTypeSourceType getType() {
return type;
}
@ -48,4 +51,14 @@ public abstract class ReferenceTypeSourceBaseConfigurationEntity {
public void setType(ReferenceTypeSourceType type) {
this.type = type;
}
public List<ReferenceTypeSourceBaseDependencyEntity> getDependencies() {
return dependencies;
}
@XmlElementWrapper
@XmlElement(name = "dependency")
public void setDependencies(List<ReferenceTypeSourceBaseDependencyEntity> dependencies) {
this.dependencies = dependencies;
}
}

View File

@ -0,0 +1,55 @@
package eu.eudat.commons.types.referencetype;
import jakarta.xml.bind.annotation.*;
import java.util.List;
@XmlRootElement(name = "dependency")
@XmlAccessorType(XmlAccessType.FIELD)
public class ReferenceTypeSourceBaseDependencyEntity {
@XmlAttribute(name = "referenceTypeCode")
private String referenceTypeCode;
@XmlAttribute(name = "key")
private String key;
@XmlAttribute(name = "required")
private Boolean required;
@XmlElementWrapper(name = "properties")
@XmlElement(name = "property")
private List<DependencyPropertyEntity> properties;
public String getReferenceTypeCode() {
return referenceTypeCode;
}
public void setReferenceTypeCode(String referenceTypeCode) {
this.referenceTypeCode = referenceTypeCode;
}
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
public Boolean getRequired() {
return required;
}
public void setRequired(Boolean required) {
this.required = required;
}
public List<DependencyPropertyEntity> getProperties() {
return properties;
}
public void setProperties(List<DependencyPropertyEntity> properties) {
this.properties = properties;
}
}

View File

@ -0,0 +1,59 @@
package eu.eudat.model.builder.referencetypedefinition;
import eu.eudat.authorization.AuthorizationFlags;
import eu.eudat.commons.types.referencetype.DependencyPropertyEntity;
import eu.eudat.convention.ConventionService;
import eu.eudat.model.builder.BaseBuilder;
import eu.eudat.model.referencetypedefinition.DependencyProperty;
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 DependencyPropertyBuilder extends BaseBuilder<DependencyProperty, DependencyPropertyEntity> {
private final BuilderFactory builderFactory;
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
@Autowired
public DependencyPropertyBuilder(
ConventionService conventionService, BuilderFactory builderFactory) {
super(conventionService, new LoggerService(LoggerFactory.getLogger(DependencyPropertyBuilder.class)));
this.builderFactory = builderFactory;
}
public DependencyPropertyBuilder authorize(EnumSet<AuthorizationFlags> values) {
this.authorize = values;
return this;
}
@Override
public List<DependencyProperty> build(FieldSet fields, List<DependencyPropertyEntity> 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<DependencyProperty> models = new ArrayList<>();
for (DependencyPropertyEntity d : data) {
DependencyProperty m = new DependencyProperty();
if (fields.hasField(this.asIndexer(DependencyProperty._code))) m.setCode(d.getCode());
if (fields.hasField(this.asIndexer(DependencyProperty._target))) m.setTarget(d.getTarget());
if (fields.hasField(this.asIndexer(DependencyProperty._required))) m.setRequired(d.getRequired());
models.add(m);
}
this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0));
return models;
}
}

View File

@ -5,6 +5,7 @@ import eu.eudat.commons.types.referencetype.ReferenceTypeSourceBaseConfiguration
import eu.eudat.convention.ConventionService;
import eu.eudat.model.builder.BaseBuilder;
import eu.eudat.model.referencetypedefinition.ReferenceTypeSourceBaseConfiguration;
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;
@ -21,12 +22,14 @@ import java.util.*;
public abstract class ReferenceTypeSourceBaseConfigurationBuilder<Model extends ReferenceTypeSourceBaseConfiguration, Entity extends ReferenceTypeSourceBaseConfigurationEntity> extends BaseBuilder<Model, Entity> {
protected EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
protected final BuilderFactory builderFactory;
@Autowired
public ReferenceTypeSourceBaseConfigurationBuilder(
ConventionService conventionService,
LoggerService logger) {
LoggerService logger, BuilderFactory builderFactory) {
super(conventionService, logger);
this.builderFactory = builderFactory;
}
public ReferenceTypeSourceBaseConfigurationBuilder authorize(EnumSet<AuthorizationFlags> values) {
@ -44,6 +47,7 @@ public abstract class ReferenceTypeSourceBaseConfigurationBuilder<Model extends
if (fields == null || data == null || fields.isEmpty())
return new ArrayList<>();
FieldSet dependenciesFields = fields.extractPrefixed(this.asPrefix(Model._dependencies));
List<Model> models = new ArrayList<>();
for (Entity d : data) {
Model m = this.getInstance();
@ -51,6 +55,8 @@ public abstract class ReferenceTypeSourceBaseConfigurationBuilder<Model extends
if (fields.hasField(this.asIndexer(Model._label))) m.setLabel(d.getLabel());
if (fields.hasField(this.asIndexer(Model._ordinal))) m.setOrdinal(d.getOrdinal());
if (fields.hasField(this.asIndexer(Model._type))) m.setType(d.getType());
if (!dependenciesFields.isEmpty() && d.getDependencies() != null) m.setDependencies(this.builderFactory.builder(ReferenceTypeSourceBaseDependencyBuilder.class).authorize(this.authorize).build(dependenciesFields, d.getDependencies()));
this.buildChild(fields, d, m);
models.add(m);
}

View File

@ -0,0 +1,62 @@
package eu.eudat.model.builder.referencetypedefinition;
import eu.eudat.authorization.AuthorizationFlags;
import eu.eudat.commons.types.referencetype.ReferenceTypeSourceBaseDependencyEntity;
import eu.eudat.convention.ConventionService;
import eu.eudat.model.builder.BaseBuilder;
import eu.eudat.model.referencetypedefinition.ReferenceTypeSourceBaseDependency;
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 ReferenceTypeSourceBaseDependencyBuilder extends BaseBuilder<ReferenceTypeSourceBaseDependency, ReferenceTypeSourceBaseDependencyEntity> {
private final BuilderFactory builderFactory;
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
@Autowired
public ReferenceTypeSourceBaseDependencyBuilder(
ConventionService conventionService, BuilderFactory builderFactory) {
super(conventionService, new LoggerService(LoggerFactory.getLogger(ReferenceTypeSourceBaseDependencyBuilder.class)));
this.builderFactory = builderFactory;
}
public ReferenceTypeSourceBaseDependencyBuilder authorize(EnumSet<AuthorizationFlags> values) {
this.authorize = values;
return this;
}
@Override
public List<ReferenceTypeSourceBaseDependency> build(FieldSet fields, List<ReferenceTypeSourceBaseDependencyEntity> 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 propertiesFields = fields.extractPrefixed(this.asPrefix(ReferenceTypeSourceBaseDependency._properties));
List<ReferenceTypeSourceBaseDependency> models = new ArrayList<>();
for (ReferenceTypeSourceBaseDependencyEntity d : data) {
ReferenceTypeSourceBaseDependency m = new ReferenceTypeSourceBaseDependency();
if (fields.hasField(this.asIndexer(ReferenceTypeSourceBaseDependency._referenceTypeCode))) m.setReferenceTypeCode(d.getReferenceTypeCode());
if (fields.hasField(this.asIndexer(ReferenceTypeSourceBaseDependency._key))) m.setKey(d.getKey());
if (fields.hasField(this.asIndexer(ReferenceTypeSourceBaseDependency._required))) m.setRequired(d.getRequired());
if (!propertiesFields.isEmpty() && d.getProperties() != null) m.setProperties(this.builderFactory.builder(DependencyPropertyBuilder.class).authorize(this.authorize).build(propertiesFields, d.getProperties()));
models.add(m);
}
this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0));
return models;
}
}

View File

@ -25,7 +25,7 @@ public class ReferenceTypeSourceExternalApiConfigurationBuilder extends Referenc
@Autowired
public ReferenceTypeSourceExternalApiConfigurationBuilder(
ConventionService conventionService, BuilderFactory builderFactory) {
super(conventionService, new LoggerService(LoggerFactory.getLogger(ReferenceTypeSourceExternalApiConfigurationBuilder.class)));
super(conventionService, new LoggerService(LoggerFactory.getLogger(ReferenceTypeSourceExternalApiConfigurationBuilder.class)), builderFactory);
this.builderFactory = builderFactory;
}

View File

@ -25,7 +25,7 @@ public class ReferenceTypeSourceStaticOptionConfigurationBuilder extends Referen
@Autowired
public ReferenceTypeSourceStaticOptionConfigurationBuilder(
ConventionService conventionService, BuilderFactory builderFactory) {
super(conventionService, new LoggerService(LoggerFactory.getLogger(ReferenceTypeSourceStaticOptionConfigurationBuilder.class)));
super(conventionService, new LoggerService(LoggerFactory.getLogger(ReferenceTypeSourceStaticOptionConfigurationBuilder.class)), builderFactory);
this.builderFactory = builderFactory;
}

View File

@ -3,7 +3,7 @@ package eu.eudat.model.censorship;
import eu.eudat.authorization.Permission;
import eu.eudat.convention.ConventionService;
import eu.eudat.model.ReferenceType;
import eu.eudat.model.censorship.referencetype.ReferenceTypeDefinitionCensor;
import eu.eudat.model.censorship.referencetypedefinition.ReferenceTypeDefinitionCensor;
import gr.cite.commons.web.authz.service.AuthorizationService;
import gr.cite.tools.data.censor.CensorFactory;
import gr.cite.tools.fieldset.FieldSet;

View File

@ -1,4 +1,4 @@
package eu.eudat.model.censorship.referencetype;
package eu.eudat.model.censorship.referencetypedefinition;
import eu.eudat.authorization.Permission;
import eu.eudat.convention.ConventionService;
@ -16,13 +16,13 @@ import java.util.UUID;
@Component
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class ReferenceTypeSourceBaseConfigurationCensor extends BaseCensor {
public class DependencyPropertyCensor extends BaseCensor {
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(ReferenceTypeSourceBaseConfigurationCensor.class));
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(DependencyPropertyCensor.class));
protected final AuthorizationService authService;
public ReferenceTypeSourceBaseConfigurationCensor(ConventionService conventionService,
public DependencyPropertyCensor(ConventionService conventionService,
AuthorizationService authService) {
super(conventionService);
this.authService = authService;

View File

@ -1,4 +1,4 @@
package eu.eudat.model.censorship.referencetype;
package eu.eudat.model.censorship.referencetypedefinition;
import eu.eudat.authorization.Permission;
import eu.eudat.convention.ConventionService;

View File

@ -1,4 +1,4 @@
package eu.eudat.model.censorship.referencetype;
package eu.eudat.model.censorship.referencetypedefinition;
import eu.eudat.authorization.Permission;
import eu.eudat.convention.ConventionService;

View File

@ -0,0 +1,45 @@
package eu.eudat.model.censorship.referencetypedefinition;
import eu.eudat.authorization.Permission;
import eu.eudat.convention.ConventionService;
import eu.eudat.model.censorship.BaseCensor;
import eu.eudat.model.referencetypedefinition.ReferenceTypeSourceBaseConfiguration;
import gr.cite.commons.web.authz.service.AuthorizationService;
import gr.cite.tools.data.censor.CensorFactory;
import gr.cite.tools.fieldset.FieldSet;
import gr.cite.tools.logging.DataLogEntry;
import gr.cite.tools.logging.LoggerService;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import java.util.UUID;
@Component
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class ReferenceTypeSourceBaseConfigurationCensor extends BaseCensor {
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(ReferenceTypeSourceBaseConfigurationCensor.class));
protected final AuthorizationService authService;
protected final CensorFactory censorFactory;
public ReferenceTypeSourceBaseConfigurationCensor(ConventionService conventionService,
AuthorizationService authService, CensorFactory censorFactory) {
super(conventionService);
this.authService = authService;
this.censorFactory = censorFactory;
}
public void censor(FieldSet fields, UUID userId) {
logger.debug(new DataLogEntry("censoring fields", fields));
if (fields == null || fields.isEmpty())
return;
this.authService.authorizeForce(Permission.BrowseReferenceType);
FieldSet dependenciesFields = fields.extractPrefixed(this.asIndexerPrefix(ReferenceTypeSourceBaseConfiguration._dependencies));
this.censorFactory.censor(ReferenceTypeSourceBaseDependencyCensor.class).censor(dependenciesFields, userId);
}
}

View File

@ -0,0 +1,45 @@
package eu.eudat.model.censorship.referencetypedefinition;
import eu.eudat.authorization.Permission;
import eu.eudat.convention.ConventionService;
import eu.eudat.model.censorship.BaseCensor;
import eu.eudat.model.referencetypedefinition.ReferenceTypeSourceBaseDependency;
import gr.cite.commons.web.authz.service.AuthorizationService;
import gr.cite.tools.data.censor.CensorFactory;
import gr.cite.tools.fieldset.FieldSet;
import gr.cite.tools.logging.DataLogEntry;
import gr.cite.tools.logging.LoggerService;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import java.util.UUID;
@Component
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class ReferenceTypeSourceBaseDependencyCensor extends BaseCensor {
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(ReferenceTypeSourceBaseDependencyCensor.class));
protected final AuthorizationService authService;
protected final CensorFactory censorFactory;
public ReferenceTypeSourceBaseDependencyCensor(ConventionService conventionService,
AuthorizationService authService, CensorFactory censorFactory) {
super(conventionService);
this.authService = authService;
this.censorFactory = censorFactory;
}
public void censor(FieldSet fields, UUID userId) {
logger.debug(new DataLogEntry("censoring fields", fields));
if (fields == null || fields.isEmpty())
return;
this.authService.authorizeForce(Permission.BrowseReferenceType);
FieldSet propertiesFields = fields.extractPrefixed(this.asIndexerPrefix( ReferenceTypeSourceBaseDependency._properties));
this.censorFactory.censor(DependencyPropertyCensor.class).censor(propertiesFields, userId);
}
}

View File

@ -0,0 +1,43 @@
package eu.eudat.model.persist.referencetypedefinition;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
public class DependencyPropertyPersist {
@NotNull(message = "{validation.empty}")
@NotEmpty(message = "{validation.empty}")
private String code;
@NotNull(message = "{validation.empty}")
@NotEmpty(message = "{validation.empty}")
private String target;
@NotNull(message = "{validation.empty}")
private Boolean required;
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public String getTarget() {
return target;
}
public void setTarget(String target) {
this.target = target;
}
public Boolean getRequired() {
return required;
}
public void setRequired(Boolean required) {
this.required = required;
}
}

View File

@ -4,9 +4,12 @@ import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import eu.eudat.commons.enums.ReferenceTypeSourceType;
import eu.eudat.commons.validation.ValidEnum;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import java.util.List;
@JsonTypeInfo(
use = JsonTypeInfo.Id.NAME,
include = JsonTypeInfo.As.PROPERTY,
@ -32,6 +35,8 @@ public abstract class ReferenceTypeSourceBaseConfigurationPersist {
@ValidEnum(message = "{validation.empty}")
private ReferenceTypeSourceType type;
@Valid
private List<ReferenceTypeSourceBaseDependencyPersist> dependencies;
public String getKey() {
return key;
@ -64,4 +69,12 @@ public abstract class ReferenceTypeSourceBaseConfigurationPersist {
public void setType(ReferenceTypeSourceType type) {
this.type = type;
}
public List<ReferenceTypeSourceBaseDependencyPersist> getDependencies() {
return dependencies;
}
public void setDependencies(List<ReferenceTypeSourceBaseDependencyPersist> dependencies) {
this.dependencies = dependencies;
}
}

View File

@ -0,0 +1,58 @@
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 ReferenceTypeSourceBaseDependencyPersist {
@NotNull(message = "{validation.empty}")
@NotEmpty(message = "{validation.empty}")
private String referenceTypeCode;
@NotNull(message = "{validation.empty}")
@NotEmpty(message = "{validation.empty}")
private String key;
@NotNull(message = "{validation.empty}")
private Boolean required;
@NotNull(message = "{validation.empty}")
@Valid
private List<DependencyPropertyPersist> properties;
public String getReferenceTypeCode() {
return referenceTypeCode;
}
public void setReferenceTypeCode(String referenceTypeCode) {
this.referenceTypeCode = referenceTypeCode;
}
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
public Boolean getRequired() {
return required;
}
public void setRequired(Boolean required) {
this.required = required;
}
public List<DependencyPropertyPersist> getProperties() {
return properties;
}
public void setProperties(List<DependencyPropertyPersist> properties) {
this.properties = properties;
}
}

View File

@ -0,0 +1,38 @@
package eu.eudat.model.referencetypedefinition;
public class DependencyProperty {
public final static String _code = "code";
private String code;
public final static String _target = "target";
private String target;
public final static String _required = "required";
private Boolean required;
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public String getTarget() {
return target;
}
public void setTarget(String target) {
this.target = target;
}
public Boolean getRequired() {
return required;
}
public void setRequired(Boolean required) {
this.required = required;
}
}

View File

@ -2,6 +2,8 @@ package eu.eudat.model.referencetypedefinition;
import eu.eudat.commons.enums.ReferenceTypeSourceType;
import java.util.List;
public abstract class ReferenceTypeSourceBaseConfiguration {
@ -17,6 +19,9 @@ public abstract class ReferenceTypeSourceBaseConfiguration {
public final static String _type = "type";
private ReferenceTypeSourceType type;
public final static String _dependencies = "dependencies";
private List<ReferenceTypeSourceBaseDependency> dependencies;
public ReferenceTypeSourceType getType() {
return type;
}
@ -48,4 +53,12 @@ public abstract class ReferenceTypeSourceBaseConfiguration {
public void setOrdinal(Integer ordinal) {
this.ordinal = ordinal;
}
public List<ReferenceTypeSourceBaseDependency> getDependencies() {
return dependencies;
}
public void setDependencies(List<ReferenceTypeSourceBaseDependency> dependencies) {
this.dependencies = dependencies;
}
}

View File

@ -0,0 +1,52 @@
package eu.eudat.model.referencetypedefinition;
import java.util.List;
public class ReferenceTypeSourceBaseDependency {
public final static String _referenceTypeCode = "referenceTypeCode";
private String referenceTypeCode;
public final static String _key = "key";
private String key;
public final static String _required = "required";
private Boolean required;
public final static String _properties = "properties";
private List<DependencyProperty> properties;
public String getReferenceTypeCode() {
return referenceTypeCode;
}
public void setReferenceTypeCode(String referenceTypeCode) {
this.referenceTypeCode = referenceTypeCode;
}
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
public Boolean getRequired() {
return required;
}
public void setRequired(Boolean required) {
this.required = required;
}
public List<DependencyProperty> getProperties() {
return properties;
}
public void setProperties(List<DependencyProperty> properties) {
this.properties = properties;
}
}

View File

@ -142,7 +142,7 @@ public class ReferenceTypeQuery extends QueryBase<ReferenceTypeEntity> {
predicates.add(inClause);
}
if (this.codes != null) {
CriteriaBuilder.In<String> inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(ReferenceEntity._type));
CriteriaBuilder.In<String> inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(ReferenceTypeEntity._code));
for (String item : this.codes)
inClause.value(item);
predicates.add(inClause);

View File

@ -23,8 +23,8 @@ import eu.eudat.service.entitydoi.EntityDoiService;
import eu.eudat.utilities.pdf.PDFUtils;
import gr.cite.commons.web.authz.service.AuthorizationService;
import gr.cite.commons.web.oidc.apikey.ApiKeyCacheService;
import gr.cite.commons.web.oidc.apikey.webflux.ApiKeyExchangeFilterFunction;
import gr.cite.commons.web.oidc.apikey.webflux.ApiKeyWebfluxModel;
//import gr.cite.commons.web.oidc.apikey.webflux.ApiKeyExchangeFilterFunction;
//import gr.cite.commons.web.oidc.apikey.webflux.ApiKeyWebfluxModel;
import gr.cite.tools.data.query.Ordering;
import gr.cite.tools.fieldset.BaseFieldSet;
import gr.cite.tools.fieldset.FieldSet;
@ -83,11 +83,11 @@ public class RepositoryDepositService {
DepositProperties.DepositSource source = depositProperties.getSources().stream().filter(depositSource -> depositSource.getCodes().contains(repoId)).findFirst().orElse(null);
if (source != null) {
String host = URI.create(source.getUrl()).getHost();
ApiKeyWebfluxModel apiKeyWebfluxModel = new ApiKeyWebfluxModel(host + "_" + source.getClientId(), source.getIssuerUrl(), source.getClientId(), source.getClientSecret(), source.getScope());
ApiKeyExchangeFilterFunction apiKeyExchangeFilterFunction = new ApiKeyExchangeFilterFunction(this.apiKeyCacheService, apiKeyWebfluxModel);
DepositRepository repository = new DepositRepository(webClientBuilder.baseUrl(source.getUrl() + "/api/deposit").filters(exchangeFilterFunctions -> exchangeFilterFunctions.add(apiKeyExchangeFilterFunction)).build());
source.getCodes().forEach(code -> this.clients.put(code, repository));
return repository;
// ApiKeyWebfluxModel apiKeyWebfluxModel = new ApiKeyWebfluxModel(host + "_" + source.getClientId(), source.getIssuerUrl(), source.getClientId(), source.getClientSecret(), source.getScope());
// ApiKeyExchangeFilterFunction apiKeyExchangeFilterFunction = new ApiKeyExchangeFilterFunction(this.apiKeyCacheService, apiKeyWebfluxModel);
// DepositRepository repository = new DepositRepository(webClientBuilder.baseUrl(source.getUrl() + "/api/deposit").filters(exchangeFilterFunctions -> exchangeFilterFunctions.add(apiKeyExchangeFilterFunction)).build());
// source.getCodes().forEach(code -> this.clients.put(code, repository));
// return repository;
}
return null;
}

View File

@ -185,6 +185,13 @@ public class ReferenceTypeServiceImpl implements ReferenceTypeService {
data.setLabel(persist.getLabel());
data.setOrdinal(persist.getOrdinal());
if (!this.conventionService.isListNullOrEmpty(persist.getDependencies())){
data.setDependencies(new ArrayList<>());
for (ReferenceTypeSourceBaseDependencyPersist dependencyPersist: persist.getDependencies()) {
data.getDependencies().add(this.buildDependencyEntity(dependencyPersist));
}
}
return data;
}
@ -249,6 +256,35 @@ public class ReferenceTypeServiceImpl implements ReferenceTypeService {
return data;
}
private @NotNull ReferenceTypeSourceBaseDependencyEntity buildDependencyEntity(ReferenceTypeSourceBaseDependencyPersist persist){
ReferenceTypeSourceBaseDependencyEntity data = new ReferenceTypeSourceBaseDependencyEntity();
if (persist == null) return data;
data.setReferenceTypeCode(persist.getReferenceTypeCode());
data.setKey(persist.getKey());
data.setRequired(persist.getRequired());
if (!this.conventionService.isListNullOrEmpty(persist.getProperties())){
data.setProperties(new ArrayList<>());
for (DependencyPropertyPersist propertyPersist: persist.getProperties()) {
data.getProperties().add(this.buildPropertyEntity(propertyPersist));
}
}
return data;
}
private @NotNull DependencyPropertyEntity buildPropertyEntity(DependencyPropertyPersist persist){
DependencyPropertyEntity data = new DependencyPropertyEntity();
if (persist == null) return data;
data.setCode(persist.getCode());
data.setTarget(persist.getTarget());
data.setRequired(persist.getRequired());
return data;
}
public void deleteAndSave(UUID id) throws MyForbiddenException, InvalidApplicationException {
logger.debug("deleting : {}", id);

View File

@ -51,6 +51,7 @@ import gr.cite.tools.logging.LoggerService;
import gr.cite.tools.logging.MapLogEntry;
import jakarta.persistence.EntityManager;
import jakarta.xml.bind.JAXBException;
import net.minidev.json.JSONArray;
import org.jetbrains.annotations.NotNull;
import org.slf4j.LoggerFactory;
import org.springframework.context.MessageSource;
@ -323,7 +324,7 @@ public class ReferenceService {
Map<String, String> map = new HashMap<>();
source.getOptions().forEach(option -> {
map.put(option.getCode(), option.getValue());
map.put("label", source.getLabel());
map.put("tag", source.getLabel());
map.put("key", source.getKey());
});
results.add(map);
@ -373,7 +374,7 @@ public class ReferenceService {
.collect(Collectors.toList()));
}
if (fetchStrategy == FetchStrategy.FIRST)
return results.getResults().stream().peek(x -> x.put("label", label)).peek(x -> x.put("key", key)).collect(Collectors.toList());
return results.getResults().stream().peek(x -> x.put("tag", label)).peek(x -> x.put("key", key)).collect(Collectors.toList());
if (results.getPagination() != null && results.getPagination().get("pages") != null) //if has more pages, add them to the pages set
for (int i = 2; i <= results.getPagination().get("pages"); i++)
@ -394,7 +395,7 @@ public class ReferenceService {
Results remainingResults = optionalResults.orElseGet(Results::new);
remainingResults.getResults().addAll(results.getResults());
return remainingResults.getResults().stream().peek(x -> x.put("label", label)).peek(x -> x.put("key", key)).collect(Collectors.toList());
return remainingResults.getResults().stream().peek(x -> x.put("tag", label)).peek(x -> x.put("key", key)).collect(Collectors.toList());
}
else {
return new LinkedList<>();
@ -404,17 +405,29 @@ public class ReferenceService {
private String replaceLookupFields(String urlPath, ReferenceDefinitionSearchLookup lookup, String firstPage, List<QueryConfigEntity> queries){
String completedPath = urlPath;
if (urlPath.contains("{like}")){
if (urlPath.contains("openaire") || urlPath.contains("orcid") ){
if (lookup.getLike() != null) {
completedPath = completedPath.replace("{query}", lookup.getLike());
completedPath = completedPath.replace("{like}", lookup.getLike());
} else {
completedPath = completedPath.replace("{query}", "*");
completedPath = completedPath.replace("{like}", "*");
}
}
if (urlPath.contains("{page}")){
if (urlPath.contains("{like}")){
if (lookup.getLike() != null) {
completedPath = completedPath.replace("{like}", lookup.getLike());
} else {
completedPath = completedPath.replace("{like}", "");
}
}
if (urlPath.contains("{page}")) {
if (lookup.getPage() != null && lookup.getPage().getOffset() > 0) {
completedPath = completedPath.replace("{page}", String.valueOf(lookup.getPage().getOffset()));
} else if (firstPage != null) {
completedPath = completedPath.replace("{page}", firstPage);
} else {
completedPath = completedPath.replace("{page}", "1");
}
@ -428,13 +441,6 @@ public class ReferenceService {
}
}
if (urlPath.contains("openaire")){
if (lookup.getLike() != null) {
completedPath = completedPath.replace("{query}", lookup.getLike());
} else {
completedPath = completedPath.replace("{query}", "*");
}
}
return completedPath;
}
@ -485,20 +491,76 @@ public class ReferenceService {
private static List<Map<String, String>> parseData (DocumentContext jsonContext, ResultsConfigurationEntity resultsEntity) {
List <Map<String, String>> rawData = jsonContext.read(resultsEntity.getResultsArrayPath());
List<Map<String, String>> parsedData = new ArrayList<>();
rawData.forEach(stringObjectMap -> {
for (Map<String, String> stringObjectMap: rawData){
Map<String, String> map = new HashMap<>();
resultsEntity.getFieldsMapping().forEach(field ->{
for(ResultFieldsMappingConfigurationEntity field: resultsEntity.getFieldsMapping()){
String pathValue = field.getResponsePath();
if (stringObjectMap.containsKey(pathValue)){
map.put(field.getCode(), stringObjectMap.get(pathValue));
if (!pathValue.contains(".")){
if (stringObjectMap.containsKey(pathValue)) {
//map.put(field.getCode(), stringObjectMap.get(pathValue));
map.put(field.getCode(), normalizeValue(stringObjectMap.get(pathValue)));
}
}else {
if (stringObjectMap.containsKey(pathValue.split("\\.")[0])){
String value = null;
Object fieldObj = stringObjectMap.get(pathValue.split("\\.")[0]);
if (fieldObj != null){
if (fieldObj instanceof Map){
Object o = ((Map<String, Object>) fieldObj).get(pathValue.split("\\.")[1]);
if(o instanceof String){
value = (String)o;
}
else if(o instanceof Integer){
value = String.valueOf(o);
}
} else if (fieldObj instanceof List) {
Object o = ((List<Map<String,?>>) fieldObj).get(0).get(pathValue.split("\\.")[1]);
if(o instanceof String){
value = (String)o;
}
else if(o instanceof Integer){
value = String.valueOf(o);
}
}
}
if (value != null){
map.put(field.getCode(), value);
}
}
}
}
});
parsedData.add(map);
});
}
return parsedData;
}
private static String normalizeValue(Object value) {
if (value instanceof JSONArray) {
JSONArray jarr = (JSONArray) value;
if (jarr.get(0) instanceof String) {
return jarr.get(0).toString();
} else {
for (Object o : jarr) {
if ((o instanceof Map) && ((Map) o).containsKey("content")) {
try {
return ((Map<String, String>) o).get("content");
}
catch (ClassCastException e){
if(((Map<?, ?>) o).get("content") instanceof Integer) {
return String.valueOf(((Map<?, ?>) o).get("content"));
}
return null;
}
}
}
}
} else if (value instanceof Map) {
String key = ((Map<String, String>)value).containsKey("$") ? "$" : "content";
return ((Map<String, String>)value).get(key);
}
return value != null ? value.toString() : null;
}
}

View File

@ -26,6 +26,7 @@ export interface ReferenceTypeSourceBaseConfiguration extends ReferenceTypeSourc
key: string;
label: string;
ordinal: number;
dependencies: ReferenceTypeSourceBaseDependency[];
}
export interface ReferenceTypeSourceExternalApiConfiguration{
@ -77,6 +78,19 @@ export interface ReferenceTypeStaticOption{
value: string;
}
export interface ReferenceTypeSourceBaseDependency{
referenceTypeCode: string;
key: string;
required: boolean;
properties: DependencyProperty[];
}
export interface DependencyProperty{
code: string;
target: string;
required: boolean;
}
// Persist
@ -103,6 +117,7 @@ export interface ReferenceTypeSourceBaseConfigurationPersist extends ReferenceTy
key: string;
label: string;
ordinal: number;
dependencies?: ReferenceTypeSourceBaseDependencyPersist[];
}
export interface ReferenceTypeSourceExternalApiConfigurationPersist{
@ -155,3 +170,16 @@ export interface ReferenceTypeStaticOptionPersist{
code: string;
value: string;
}
export interface ReferenceTypeSourceBaseDependencyPersist{
referenceTypeCode: string;
key: string;
required: boolean;
properties: DependencyPropertyPersist[];
}
export interface DependencyPropertyPersist{
code: string;
target: string;
required: boolean;
}

View File

@ -8,6 +8,11 @@ import { ConfigurationService } from '../configuration/configuration.service';
import { BaseHttpV2Service } from '../http/base-http-v2.service';
import { ReferenceTypeLookup } from '@app/core/query/reference-type.lookup';
import { ReferenceType, ReferenceTypePersist } from '@app/core/model/reference-type/reference-type';
import { SingleAutoCompleteConfiguration } from '@app/library/auto-complete/single/single-auto-complete-configuration';
import { MultipleAutoCompleteConfiguration } from '@app/library/auto-complete/multiple/multiple-auto-complete-configuration';
import { IsActive } from '@app/core/common/enum/is-active.enum';
import { nameof } from 'ts-simple-nameof';
import { ReferenceTypeEditorResolver } from '@app/ui/admin/reference-type/editor/reference-type-editor.resolver';
@Injectable()
export class ReferenceTypeService {
@ -51,4 +56,59 @@ export class ReferenceTypeService {
catchError((error: any) => throwError(error)));
}
// LOOKUP
public static DefaultReferenceTypeLookup(): ReferenceTypeLookup{
const lookup = new ReferenceTypeLookup();
lookup.project = {
fields: [
...ReferenceTypeEditorResolver.lookupFields()
]
};
lookup.order = { items: [nameof<ReferenceType>(x => x.code)] };
lookup.page = { offset: 0, size: 100 };
lookup.isActive = [IsActive.Active];
return lookup;
}
//
// Autocomplete Commons
//
//
public singleAutocompleteConfiguration: SingleAutoCompleteConfiguration = {
initialItems: (data?: any) => this.query(this.buildAutocompleteLookup()).pipe(map(x => x.items)),
filterFn: (searchQuery: string, data?: any) => this.query(this.buildAutocompleteLookup(searchQuery)).pipe(map(x => x.items)),
getSelectedItem: (selectedItem: any) => this.query(this.buildAutocompleteLookup(null, null, [selectedItem])).pipe(map(x => x.items[0])),
displayFn: (item: ReferenceType) => item.name,
titleFn: (item: ReferenceType) => item.name,
valueAssign: (item: ReferenceType) => item.id,
};
public multipleAutocompleteConfiguration: MultipleAutoCompleteConfiguration = {
initialItems: (excludedItems: any[], data?: any) => this.query(this.buildAutocompleteLookup(null, excludedItems ? excludedItems : null)).pipe(map(x => x.items)),
filterFn: (searchQuery: string, excludedItems: any[]) => this.query(this.buildAutocompleteLookup(searchQuery, excludedItems)).pipe(map(x => x.items)),
getSelectedItems: (selectedItems: any[]) => this.query(this.buildAutocompleteLookup(null, null, selectedItems)).pipe(map(x => x.items)),
displayFn: (item: ReferenceType) => item.name,
titleFn: (item: ReferenceType) => item.name,
valueAssign: (item: ReferenceType) => item.id,
};
private buildAutocompleteLookup(like?: string, excludedIds?: Guid[], ids?: Guid[]): ReferenceTypeLookup {
const lookup: ReferenceTypeLookup = new ReferenceTypeLookup();
lookup.page = { size: 100, offset: 0 };
if (excludedIds && excludedIds.length > 0) { lookup.excludedIds = excludedIds; }
if (ids && ids.length > 0) { lookup.ids = ids; }
lookup.isActive = [IsActive.Active];
lookup.project = {
fields: [
nameof<ReferenceType>(x => x.id),
nameof<ReferenceType>(x => x.name)
]
};
lookup.order = { items: [nameof<ReferenceType>(x => x.name)] };
if (like) { lookup.like = this.filterService.transformLike(like); }
return lookup;
}
}

View File

@ -17,6 +17,9 @@ import { DescriptionTemplateTypeStatus } from '@app/core/common/enum/description
import { DmpBlueprintSystemFieldType } from '@app/core/common/enum/dmp-blueprint-system-field-type';
import { DmpBlueprintStatus } from '@app/core/common/enum/dmp-blueprint-status';
import { DescriptionTemplateStatus } from '@app/core/common/enum/description-template-status';
import { ReferenceFieldDataType } from '@app/core/common/enum/reference-field-data-type';
import { ReferenceTypeSourceType } from '@app/core/common/enum/reference-type-source-type';
import { ReferenceTypeExternalApiHTTPMethodType } from '@app/core/common/enum/reference-type-external-api-http-method-type';
@Injectable()
export class EnumUtils {
@ -235,4 +238,26 @@ export class EnumUtils {
case DmpBlueprintExtraFieldDataType.ExternalAutocomplete: return this.language.instant('TYPES.DMP-BLUEPRINT-EXTRA-FIELD-DATA-TYPE.EXTERNAL-AUTOCOMPLETE');
}
}
toReferenceTypeSourceTypeString(status: ReferenceTypeSourceType): string {
switch (status) {
case ReferenceTypeSourceType.API: return this.language.instant('TYPES.REFERENCE-TYPE-SOURCE-TYPE.API');
case ReferenceTypeSourceType.STATIC: return this.language.instant('TYPES.REFERENCE-TYPE-SOURCE-TYPE.STATIC');
}
}
toReferenceFieldDataTypeString(status: ReferenceFieldDataType): string {
switch (status) {
case ReferenceFieldDataType.Text: return this.language.instant('TYPES.REFERENCE-FIELD-DATA-TYPE.TEXT');
case ReferenceFieldDataType.Date: return this.language.instant('TYPES.REFERENCE-FIELD-DATA-TYPE.DATE');
}
}
toReferenceTypeExternalApiHTTPMethodTypeString(status: ReferenceTypeExternalApiHTTPMethodType): string {
switch (status) {
case ReferenceTypeExternalApiHTTPMethodType.GET: return this.language.instant('TYPES.REFERENCE-TYPE-EXTERNAL-API-HTTP-METHOD-TYPE.GET');
case ReferenceTypeExternalApiHTTPMethodType.POST: return this.language.instant('TYPES.REFERENCE-TYPE-EXTERNAL-API-HTTP-METHOD-TYPE.POST');
}
}
}

View File

@ -1,4 +1,4 @@
<div class="row description-template-type-editor">
<div class="reference-type-editor">
<div class="col-md-8 offset-md-2 colums-gapped">
<div class="row justify-content-between align-items-center">
@ -16,12 +16,6 @@
{{'REFERENCE-TYPE-EDITOR.ACTIONS.DELETE' | translate}}
</button>
</div>
<!-- <div class="col-auto" *ngIf="canFinalize">
<button mat-button class="action-btn" (click)="finalize(); formSubmit()">
<mat-icon>save</mat-icon>
{{'DESCRIPTION-TEMPLATE-TYPE-EDITOR.ACTIONS.FINALIZE' | translate}}
</button>
</div> -->
<div class="col-auto" *ngIf="canSave">
<button mat-button class="action-btn" (click)="formSubmit()">
<mat-icon>save</mat-icon>
@ -57,6 +51,7 @@
{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
</mat-form-field>
</div>
</div>
</form>
</mat-card-content>
@ -65,16 +60,15 @@
<mat-card appearance="outlined">
<mat-card-header>
<mat-card-title *ngIf="isNew">Reference Type Fields</mat-card-title>
<!-- <mat-card-title >{{'REFERENCE-TYPE-EDITOR.FIELDS.LABEL' | translate}}</mat-card-title> -->
<button mat-button class="action-btn" type="button" (click)="addField()" [disabled]="formGroup.disabled">{{'REFERENCE-TYPE-EDITOR.ACTIONS.ADD-FIELD' | translate}}</button>
<!-- <mat-card-title *ngIf="!isNew">{{formGroup.get('name').value}}</mat-card-title> -->
</mat-card-header>
<mat-card-content>
<form (ngSubmit)="formSubmit()" [formGroup]="formGroup" *ngIf="formGroup">
<!-- FIELDS -->
<div class="col-12" cdkDropList (cdkDropListDropped)="dropFields($event)">
<div *ngFor="let field of formGroup.get('definition').get('fields').controls; let fieldIndex=index;" class="row mb-3" cdkDrag [cdkDragDisabled]="formGroup.disabled">
<div class="col-12">
<div *ngFor="let field of formGroup.get('definition').get('fields').controls; let fieldIndex=index;" class="row mb-3">
<div class="col-12">
<mat-card-header>
<div class="row mb-3 d-flex align-items-center">
@ -83,7 +77,7 @@
</div>
<div class="col-auto d-flex">
<button mat-icon-button class="action-list-icon" matTooltip="remove field" (click)="removeField(fieldIndex)" [disabled]="formGroup.disabled">
<button mat-icon-button class="action-list-icon" matTooltip="{{'REFERENCE-TYPE-EDITOR.ACTIONS.REMOVE-FIELD' | translate}}" (click)="removeField(fieldIndex)" [disabled]="formGroup.disabled">
<mat-icon>delete</mat-icon>
</button>
</div>
@ -101,7 +95,7 @@
</div>
<div class="col-6">
<mat-form-field class="w-100">
<mat-label>Description</mat-label>
<mat-label>{{'REFERENCE-TYPE-EDITOR.FIELDS.DESCRIPTION' | translate}}</mat-label>
<input matInput type="text" name="description" [formControl]="field.get('description')">
<mat-error *ngIf="field.get('description').hasError('required')">
{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
@ -119,8 +113,8 @@
<mat-form-field class="w-100">
<mat-label>{{'REFERENCE-TYPE-EDITOR.FIELDS.DATA-TYPE' | translate}}</mat-label>
<mat-select name="dataType" [formControl]="field.get('dataType')">
<mat-option *ngFor="let dataType of visibleDataTypes" [value] = "dataType.type">
{{dataType.name}}
<mat-option *ngFor="let fieldDataType of referenceFieldDataTypeEnum" [value]="fieldDataType">
{{enumUtils.toReferenceFieldDataTypeString(fieldDataType)}}
</mat-option>
</mat-select>
<mat-error *ngIf="field.get('dataType').hasError('required')">
@ -141,16 +135,16 @@
<mat-card appearance="outlined">
<mat-card-header>
<mat-card-title *ngIf="isNew">Reference Type Source</mat-card-title>
<!-- <mat-card-title>{{'REFERENCE-TYPE-EDITOR.FIELDS.LABEL' | translate}}</mat-card-title> -->
<mat-card-header>
<button mat-button class="action-btn" type="button" (click)="addSource()" [disabled]="formGroup.disabled">{{'REFERENCE-TYPE-EDITOR.ACTIONS.ADD-CONFIG' | translate}}</button>
<button mat-button class="action-btn" type="button" (click)="addSource()" [disabled]="formGroup.disabled">{{'REFERENCE-TYPE-EDITOR.ACTIONS.ADD-SOURCE' | translate}}</button>
</mat-card-header>
</mat-card-header>
<mat-card-content>
<form (ngSubmit)="formSubmit()" [formGroup]="formGroup" *ngIf="formGroup">
<!-- Source Config Info -->
<div class="col-12">
<div *ngFor="let source of formGroup.get('definition').get('sources').controls; let sourceIndex=index;" class="row mb-3" cdkDrag [cdkDragDisabled]="formGroup.disabled">
<div *ngFor="let source of formGroup.get('definition').get('sources').controls; let sourceIndex=index;" class="row mb-3">
<div class="col-12">
<mat-card-content>
<div class="row mb-3 d-flex align-items-center">
@ -158,7 +152,7 @@
<mat-card-title>{{'REFERENCE-TYPE-EDITOR.FIELDS.SOURCE-CONFIGURATION' | translate}} {{sourceIndex + 1}}</mat-card-title>
</div>
<div class="col-auto d-flex">
<button mat-icon-button class="action-list-icon" matTooltip="remove Source Configiguration" (click)="removeSource(sourceIndex)" [disabled]="formGroup.disabled">
<button mat-icon-button class="action-list-icon" matTooltip="{{'REFERENCE-TYPE-EDITOR.ACTIONS.REMOVE-SOURCE' | translate}}" (click)="removeSource(sourceIndex)" [disabled]="formGroup.disabled">
<mat-icon>delete</mat-icon>
</button>
</div>
@ -190,10 +184,10 @@
</div>
<div class="col-6">
<mat-form-field class="w-100">
<mat-label>Source Type</mat-label>
<mat-label>{{'REFERENCE-TYPE-EDITOR.FIELDS.SOURCE-TYPE' | translate}}</mat-label>
<mat-select name="type" [formControl]="source.get('type')" required>
<mat-option *ngFor="let vis of visibleSourceTypes" [value] = "vis.type">
{{vis.name}}
<mat-option *ngFor="let sourceType of referenceTypeSourceTypeEnum" [value]="sourceType">
{{enumUtils.toReferenceTypeSourceTypeString(sourceType)}}
</mat-option>
</mat-select>
<mat-error *ngIf="source.get('type').hasError('required')">
@ -201,7 +195,7 @@
</mat-form-field>
</div>
<div class="row" *ngIf="source.get('type').value == 0">
<div class="row" *ngIf="source.get('type').value == referenceTypeSourceType.API">
<div class="col-6">
<mat-form-field class="w-100">
<mat-label>{{'REFERENCE-TYPE-EDITOR.FIELDS.URL' | translate}}</mat-label>
@ -220,7 +214,7 @@
</div>
<div class="col-6">
<mat-form-field class="w-100">
<mat-label>Content Type</mat-label>
<mat-label>{{'REFERENCE-TYPE-EDITOR.FIELDS.CONTENT-TYPE' | translate}}</mat-label>
<input matInput type="text" name="contentType" [formControl]="source.get('contentType')">
<mat-error *ngIf="source.get('contentType').hasError('required')">
{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
@ -228,7 +222,7 @@
</div>
<div class="col-6">
<mat-form-field class="w-100">
<mat-label>First Page</mat-label>
<mat-label>{{'REFERENCE-TYPE-EDITOR.FIELDS.FIRST-PAGE' | translate}}</mat-label>
<input matInput type="text" name="firstPage" [formControl]="source.get('firstPage')">
<mat-error *ngIf="source.get('firstPage').hasError('required')">
{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
@ -236,10 +230,10 @@
</div>
<div class="col-6">
<mat-form-field class="w-100">
<mat-label>HTTP Method</mat-label>
<mat-label>{{'REFERENCE-TYPE-EDITOR.FIELDS.HTTP-METHOD' | translate}}</mat-label>
<mat-select name="httpMethod" [formControl]="source.get('httpMethod')">
<mat-option *ngFor="let vis of visibleHTTPMethodTypes" [value] = "vis.type">
{{vis.name}}
<mat-option *ngFor="let httpMethod of referenceTypeExternalApiHTTPMethodTypeEnum" [value]="httpMethod">
{{enumUtils.toReferenceTypeExternalApiHTTPMethodTypeString(httpMethod)}}
</mat-option>
</mat-select>
<mat-error *ngIf="source.get('httpMethod').hasError('required')">
@ -247,8 +241,8 @@
</mat-form-field>
</div>
<div class="col-6">
<mat-form-field *ngIf="source.get('httpMethod').value == 1" class="w-100">
<mat-label>Request Body</mat-label>
<mat-form-field *ngIf="source.get('httpMethod').value == referenceTypeExternalApiHTTPMethodType.POST" class="w-100">
<mat-label>{{'REFERENCE-TYPE-EDITOR.FIELDS.REQUEST-BODY' | translate}}</mat-label>
<input matInput type="text" name="requestBody" [formControl]="source.get('requestBody')">
<mat-error *ngIf="source.get('requestBody').hasError('required')">
{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
@ -256,7 +250,7 @@
</div>
<div class="col-6">
<mat-form-field class="w-100">
<mat-label>Filter Type</mat-label>
<mat-label>{{'REFERENCE-TYPE-EDITOR.FIELDS.FILTER-TYPE' | translate}}ype</mat-label>
<input matInput type="text" name="filterType" [formControl]="source.get('filterType')">
<mat-error *ngIf="source.get('filterType').hasError('required')">
{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
@ -266,7 +260,7 @@
<h3 class="col-12">{{'REFERENCE-TYPE-EDITOR.FIELDS.RESULTS' | translate}}</h3>
<div class="col-6">
<mat-form-field class="w-100">
<mat-label>Results Path</mat-label>
<mat-label>{{'REFERENCE-TYPE-EDITOR.FIELDS.RESULTS-PATH' | translate}}</mat-label>
<input matInput type="text" name="resultsArrayPath" [formControl]="source.get('results').get('resultsArrayPath')">
<mat-error *ngIf="source.get('results').get('resultsArrayPath').hasError('required')">
{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
@ -274,7 +268,7 @@
</div>
<!-- fields mapping -->
<div class="col-12">
<div *ngFor="let field of source.get('results').get('fieldsMapping').controls; let fieldMappingIndex=index;" class="row mb-3" cdkDrag [cdkDragDisabled]="formGroup.disabled">
<div *ngFor="let field of source.get('results').get('fieldsMapping').controls; let fieldMappingIndex=index;" class="row mb-3">
<div class="col-12">
<mat-card-header>
<div class="row mb-3 d-flex align-items-center">
@ -284,7 +278,7 @@
</div>
</mat-card-header>
<mat-card-content>
<div class="row" *ngIf="fieldMappingIndex < systemFieldsMapping.length">
<!-- <div class="row" *ngIf="fieldMappingIndex < systemFieldsMapping.length">
<div class="col-6">
<mat-form-field class="w-100">
<mat-label>{{'REFERENCE-TYPE-EDITOR.FIELDS.CODE' | translate}}</mat-label>
@ -301,12 +295,14 @@
{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
</mat-form-field>
</div>
</div>
<div class="row" *ngIf="fieldMappingIndex >= systemFieldsMapping.length">
</div> -->
<!-- <div class="row" *ngIf="fieldMappingIndex >= systemFieldsMapping.length"> -->
<div class="row">
<div class="col-6">
<mat-form-field class="w-100">
<mat-label>{{'REFERENCE-TYPE-EDITOR.FIELDS.CODE' | translate}}</mat-label>
<input matInput type="text" [readonly]="true" name="code" [formControl]="field.get('code')" [ngModel]="formGroup.get('definition').get('fields').value[fieldMappingIndex - systemFieldsMapping.length].code">
<!-- <input matInput type="text" [readonly]="true" name="code" [formControl]="field.get('code')" [ngModel]="formGroup.get('definition').get('fields').value[fieldMappingIndex - systemFieldsMapping.length].code"> -->
<input matInput type="text" [readonly]="field.get('code').disabled" name="code" [formControl]="field.get('code')">
<mat-error *ngIf="field.get('code').hasError('required')">
{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
</mat-form-field>
@ -336,10 +332,10 @@
</div>
<div class="col-6">
<mat-form-field class="w-100">
<mat-label>Method</mat-label>
<mat-label>{{'REFERENCE-TYPE-EDITOR.FIELDS.HTTP-METHOD' | translate}}</mat-label>
<mat-select name="httpMethod" [formControl]="source.get('auth').get('authMethod')">
<mat-option *ngFor="let vis of visibleHTTPMethodTypes" [value] = "vis.type">
{{vis.name}}
<mat-option *ngFor="let httpMethod of referenceTypeExternalApiHTTPMethodTypeEnum" [value]="httpMethod">
{{enumUtils.toReferenceTypeExternalApiHTTPMethodTypeString(httpMethod)}}
</mat-option>
</mat-select>
<mat-error *ngIf="source.get('auth').get('authMethod').hasError('required')">
@ -348,7 +344,7 @@
</div>
<div class="col-6">
<mat-form-field class="w-100">
<mat-label>Token Path</mat-label>
<mat-label>{{'REFERENCE-TYPE-EDITOR.FIELDS.TOKEN-PATH' | translate}}</mat-label>
<input matInput type="text" name="authTokenPath" [formControl]="source.get('auth').get('authTokenPath')">
<mat-error *ngIf="source.get('auth').get('authTokenPath').hasError('required')">
{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
@ -356,7 +352,7 @@
</div>
<div class="col-6">
<mat-form-field class="w-100">
<mat-label>Request Body</mat-label>
<mat-label>{{'REFERENCE-TYPE-EDITOR.FIELDS.REQUEST-BODY' | translate}}</mat-label>
<input matInput type="text" name="authRequestBody" [formControl]="source.get('auth').get('authRequestBody')">
<mat-error *ngIf="source.get('auth').get('authRequestBody').hasError('required')">
{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
@ -364,7 +360,7 @@
</div>
<div class="col-6">
<mat-form-field class="w-100">
<mat-label>Type</mat-label>
<mat-label>{{'REFERENCE-TYPE-EDITOR.FIELDS.TYPE' | translate}}</mat-label>
<input matInput type="text" name="type" [formControl]="source.get('auth').get('type')">
<mat-error *ngIf="source.get('auth').get('type').hasError('required')">
{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
@ -374,8 +370,8 @@
<h3 class="col-12">{{'REFERENCE-TYPE-EDITOR.FIELDS.QUERIES' | translate}}
<button mat-button type="button" (click)="addQuery(sourceIndex)" [disabled]="formGroup.disabled">{{'REFERENCE-TYPE-EDITOR.ACTIONS.ADD-QUERY' | translate}}</button>
</h3>
<div class="col-12" cdkDropList (cdkDropListDropped)="dropQueries($event)">
<div *ngFor="let query of source.get('queries').controls; let queryIndex=index;" class="row mb-3" cdkDrag [cdkDragDisabled]="formGroup.disabled">
<div class="col-12">
<div *ngFor="let query of source.get('queries').controls; let queryIndex=index;" class="row mb-3">
<div class="col-12">
<mat-card-header>
<div class="row mb-3 d-flex align-items-center">
@ -383,16 +379,17 @@
<h4 class="col-12">{{'REFERENCE-TYPE-EDITOR.FIELDS.QUERY' | translate}} {{queryIndex + 1}}</h4>
</div>
<div class="col-auto d-flex">
<button mat-icon-button class="action-list-icon" matTooltip="remove query" (click)="removeQuery(queryIndex, fieldMappingIndex)" [disabled]="formGroup.disabled">
<button mat-icon-button class="action-list-icon" matTooltip="{{'REFERENCE-TYPE-EDITOR.ACTIONS.REMOVE-QUERY' | translate}}" (click)="removeQuery(sourceIndex, queryIndex)" [disabled]="formGroup.disabled">
<mat-icon>delete</mat-icon>
</button>
</div>
</div>
</mat-card-header>
<mat-card-content>
<div class="row">
<div class="col-6">
<mat-form-field class="w-100">
<mat-label>Condition</mat-label>
<mat-label>{{'REFERENCE-TYPE-EDITOR.FIELDS.CONDITION' | translate}}</mat-label>
<input matInput type="text" name="condition" [formControl]="query.get('condition')" required>
<mat-error *ngIf="query.get('condition').hasError('required')">
{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
@ -400,7 +397,7 @@
</div>
<div class="col-6">
<mat-form-field class="w-100">
<mat-label>Separator</mat-label>
<mat-label>{{'REFERENCE-TYPE-EDITOR.FIELDS.SEPARATOR' | translate}}</mat-label>
<input matInput type="text" name="separator" [formControl]="query.get('separator')" required>
<mat-error *ngIf="query.get('separator').hasError('required')">
{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
@ -408,7 +405,7 @@
</div>
<div class="col-6">
<mat-form-field class="w-100">
<mat-label>Value</mat-label>
<mat-label>{{'REFERENCE-TYPE-EDITOR.FIELDS.VALUE' | translate}}</mat-label>
<input matInput type="text" name="value" [formControl]="query.get('value')" required>
<mat-error *ngIf="query.get('value').hasError('required')">
{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
@ -422,16 +419,17 @@
{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
</mat-form-field>
</div>
</div>
</mat-card-content>
</div>
</div>
</div>
</div>
<!-- Options -->
<div class="row" *ngIf="source.get('type').value == 1">
<div class="row" *ngIf="source.get('type').value == referenceTypeSourceType.STATIC">
<div class="col-12">
<h3 class="col-12">{{'REFERENCE-TYPE-EDITOR.FIELDS.OPTIONS' | translate}}</h3>
<div *ngFor="let option of source.get('options').controls; let optionsIndex=index;" class="row mb-3" cdkDrag [cdkDragDisabled]="formGroup.disabled">
<div *ngFor="let option of source.get('options').controls; let optionsIndex=index;" class="row mb-3">
<div class="col-12">
<mat-card-header>
<div class="row mb-3 d-flex align-items-center">
@ -441,7 +439,7 @@
</div>
</mat-card-header>
<mat-card-content>
<div class="row" *ngIf="optionsIndex < systemFieldsMapping.length">
<!-- <div class="row" *ngIf="optionsIndex < systemFieldsMapping.length">
<div class="col-6">
<mat-form-field class="w-100">
<mat-label>{{'REFERENCE-TYPE-EDITOR.FIELDS.CODE' | translate}}</mat-label>
@ -459,11 +457,13 @@
</mat-form-field>
</div>
</div>
<div class="row" *ngIf="optionsIndex >= systemFieldsMapping.length">
<div class="row" *ngIf="optionsIndex >= systemFieldsMapping.length"> -->
<div class="row">
<div class="col-6">
<mat-form-field class="w-100">
<mat-label>{{'REFERENCE-TYPE-EDITOR.FIELDS.CODE' | translate}}</mat-label>
<input matInput type="text" [readonly]="true" name="code" [formControl]="option.get('code')" [ngModel]="formGroup.get('definition').get('fields').value[optionsIndex - systemFieldsMapping.length].code">
<!-- <input matInput type="text" [readonly]="true" name="code" [formControl]="option.get('code')" [ngModel]="formGroup.get('definition').get('fields').value[optionsIndex - systemFieldsMapping.length].code"> -->
<input matInput type="text" [readonly]="option.get('code').disabled" name="code" [formControl]="option.get('code')">
<mat-error *ngIf="option.get('code').hasError('required')">
{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
</mat-form-field>
@ -481,9 +481,120 @@
</div>
</div>
</div>
</div>
<!-- Dependencies -->
<h3 class="col-12">{{'REFERENCE-TYPE-EDITOR.FIELDS.DEPENDENCIES' | translate}}
<button mat-button type="button" (click)="addDependency(sourceIndex)" [disabled]="formGroup.disabled">{{'REFERENCE-TYPE-EDITOR.ACTIONS.ADD-DEPENDENCY' | translate}}</button>
</h3>
<div class="col-12">
<div *ngFor="let dependency of source.get('dependencies').controls; let dependencyIndex= index;" class="row mb-3">
<div class="col-12">
<mat-card-header>
<div class="row mb-3 d-flex align-items-center">
<div class="col-auto d-flex">
<h3 class="col-12">{{'REFERENCE-TYPE-EDITOR.FIELDS.DEPENDENCY' | translate}} {{dependencyIndex + 1}}</h3>
</div>
<div class="col-auto d-flex">
<button mat-icon-button class="action-list-icon" matTooltip="{{'REFERENCE-TYPE-EDITOR.ACTIONS.REMOVE-DEPENDENCY' | translate}}" (click)="removeDependency(sourceIndex, dependencyIndex)" [disabled]="formGroup.disabled">
<mat-icon>delete</mat-icon>
</button>
</div>
</div>
</mat-card-header>
<mat-card-content>
<div class="row">
<div class="col-6">
<mat-form-field class="w-100">
<mat-label>{{'REFERENCE-TYPE-EDITOR.FIELDS.CODE' | translate}}</mat-label>
<mat-select [value] ="selectedReferenceTypeCode" (selectionChange)="selectedReferenceTypeChanged($event.value)" name="referenceTypeCode" [formControl]="dependency.get('referenceTypeCode')" required>
<mat-option *ngFor="let referenceType of referenceTypes" [value]="referenceType.code">
{{referenceType.code}}
</mat-option>
</mat-select>
<mat-error *ngIf="dependency.get('referenceTypeCode').hasError('required')">
{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
</mat-form-field>
</div>
<div class="col-6" *ngIf="dependency.get('referenceTypeCode').value">
<mat-form-field class="w-100">
<mat-label>{{'REFERENCE-TYPE-EDITOR.FIELDS.KEY' | translate}}</mat-label>
<mat-select name = 'key' [formControl]="dependency.get('key')" required>
<mat-option *ngFor="let key of sourceKeys" [value]="key">
{{key}}
</mat-option>
</mat-select>
<mat-error *ngIf="dependency.get('key').hasError('required')">
{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
</mat-form-field>
</div>
<div class="col-6">
<mat-form-field class="w-100">
<mat-label>{{'REFERENCE-TYPE-EDITOR.FIELDS.REQUIRED' | translate}}</mat-label>
<input matInput type="text" name="required" [formControl]="dependency.get('required')" required>
<mat-error *ngIf="dependency.get('required').hasError('required')">
{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
</mat-form-field>
</div>
</div>
<!-- Properties -->
<h3 class="col-12">{{'REFERENCE-TYPE-EDITOR.FIELDS.PROPERTIES' | translate}}
<button mat-button type="button" (click)="addProperty(sourceIndex, dependencyIndex)" [disabled]="formGroup.disabled">{{'REFERENCE-TYPE-EDITOR.ACTIONS.ADD-PROPERTY' | translate}}</button>
</h3>
<div class="col-12">
<div *ngFor="let property of dependency.get('properties').controls; let propertyIndex= index;" class="row mb-3">
<div class="col-12">
<div class="row mb-3 d-flex align-items-center">
<div class="col-auto d-flex">
<h4>{{'REFERENCE-TYPE-EDITOR.FIELDS.PROPERTY' | translate}} {{propertyIndex + 1}}</h4>
</div>
<div class="col-auto d-flex">
<button mat-icon-button class="action-list-icon" matTooltip="{{'REFERENCE-TYPE-EDITOR.ACTIONS.REMOVE-PROPERTY' | translate}}" (click)="removeProperty(sourceIndex, dependencyIndex, propertyIndex)" [disabled]="formGroup.disabled">
<mat-icon>delete</mat-icon>
</button>
</div>
</div>
<div class="row">
<div class="col-6">
<mat-form-field class="w-100">
<mat-label>{{'REFERENCE-TYPE-EDITOR.FIELDS.CODE' | translate}}</mat-label>
<mat-select name="code" [formControl]="property.get('code')" required>
<mat-option *ngFor="let code of propertyCodes" [value]="code">
{{code}}
</mat-option>
</mat-select>
<mat-error *ngIf="property.get('code').hasError('required')">
{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
</mat-form-field>
</div>
<div class="col-6">
<mat-form-field class="w-100">
<mat-label>{{'REFERENCE-TYPE-EDITOR.FIELDS.TARGET' | translate}}</mat-label>
<mat-select name = 'target' [formControl]="property.get('target')" required>
<mat-option *ngFor="let targetCode of targetPropertyCodes" [value]="targetCode">
{{targetCode}}
</mat-option>
</mat-select>
<mat-error *ngIf="property.get('target').hasError('required')">
{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
</mat-form-field>
</div>
<div class="col-6">
<mat-form-field class="w-100">
<mat-label>{{'REFERENCE-TYPE-EDITOR.FIELDS.REQUIRED' | translate}}</mat-label>
<input matInput type="text" name="required" [formControl]="property.get('required')" required>
<mat-error *ngIf="property.get('required').hasError('required')">
{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
</mat-form-field>
</div>
</div>
</div>
</div>
</div>
</mat-card-content>
</div>
</div>
</div>
</div>

View File

@ -1,4 +1,4 @@
.dmp-blueprint-editor {
.reference-type-editor {
margin-top: 1.3rem;
margin-left: 1em;
margin-right: 3em;

View File

@ -25,27 +25,13 @@ 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, ReferenceTypeFieldEditorModel, ReferenceTypeSourceBaseConfigurationEditorModel, ReferenceTypeStaticOptionEditorModel, ResultFieldsMappingConfigurationEditorModel } from './reference-type-editor.model';
import { DependencyPropertyEditorModel, QueryConfigEditorModel, ReferenceTypeEditorModel, ReferenceTypeFieldEditorModel, ReferenceTypeSourceBaseConfigurationEditorModel, ReferenceTypeSourceBaseDependencyEditorModel, ReferenceTypeStaticOptionEditorModel, ResultFieldsMappingConfigurationEditorModel } from './reference-type-editor.model';
import { ReferenceFieldDataType } from '@app/core/common/enum/reference-field-data-type';
import { ReferenceTypeSourceType } from '@app/core/common/enum/reference-type-source-type';
import { ReferenceTypeExternalApiHTTPMethodType } from '@app/core/common/enum/reference-type-external-api-http-method-type';
import { ReferenceTypeLookup } from '@app/core/query/reference-type.lookup';
export interface visibleDataType {
name: string;
type: ReferenceFieldDataType;
}
export interface visibleSourceType {
name: string;
type: ReferenceTypeSourceType;
}
export interface visibleHTTPMethodType {
name: string;
type: ReferenceTypeExternalApiHTTPMethodType;
}
@Component({
selector: 'app-reference-type-editor-component',
templateUrl: 'reference-type-editor.component.html',
@ -58,6 +44,16 @@ export class ReferenceTypeEditorComponent extends BaseEditor<ReferenceTypeEditor
isDeleted = false;
formGroup: UntypedFormGroup = null;
showInactiveDetails = false;
referenceTypeSourceType = ReferenceTypeSourceType;
referenceTypeExternalApiHTTPMethodType = ReferenceTypeExternalApiHTTPMethodType;
public referenceTypeSourceTypeEnum = this.enumUtils.getEnumValues(ReferenceTypeSourceType);
public referenceFieldDataTypeEnum = this.enumUtils.getEnumValues(ReferenceFieldDataType);
public referenceTypeExternalApiHTTPMethodTypeEnum = this.enumUtils.getEnumValues(ReferenceTypeExternalApiHTTPMethodType);
referenceTypes: ReferenceType[] = null;
selectedReferenceTypeCode: string = null;
sourceKeys: string[] = [];
propertyCodes: string[] = [];
targetPropertyCodes: string[] = [];
protected get canDelete(): boolean {
return !this.isDeleted && !this.isNew && this.hasPermission(this.authService.permissionEnum.DeleteReferenceType);
@ -98,23 +94,6 @@ export class ReferenceTypeEditorComponent extends BaseEditor<ReferenceTypeEditor
super(dialog, language, formService, router, uiNotificationService, httpErrorHandlingService, filterService, datePipe, route, queryParamsService);
}
visibleDataTypes: visibleDataType[] = [
{name: "Text", type: ReferenceFieldDataType.Text},
{name: "Date", type: ReferenceFieldDataType.Date},
]
visibleSourceTypes: visibleSourceType[] = [
{name: "API", type: ReferenceTypeSourceType.API},
{name: "Static", type: ReferenceTypeSourceType.STATIC},
]
visibleHTTPMethodTypes: visibleHTTPMethodType[] = [
{name: "GET", type: ReferenceTypeExternalApiHTTPMethodType.GET},
{name: "POST", type: ReferenceTypeExternalApiHTTPMethodType.POST},
]
systemFieldsMapping: string[] = ['reference_id', 'label', 'description'];
ngOnInit(): void {
super.ngOnInit();
if((this.formGroup.get('definition').get('sources') as FormArray).length == 0){
@ -134,6 +113,30 @@ export class ReferenceTypeEditorComponent extends BaseEditor<ReferenceTypeEditor
prepareForm(data: ReferenceType) {
try {
this.editorModel = data ? new ReferenceTypeEditorModel().fromModel(data) : new ReferenceTypeEditorModel();
this.getReferenceTypes(this.editorModel.id);
if(data){
this.editorModel.definition.sources.forEach(source => source.dependencies.forEach(dependency => {
this.selectedReferenceTypeChanged(dependency.referenceTypeCode);
}));
this.editorModel.definition.sources.forEach(source => {
if(source.type == ReferenceTypeSourceType.STATIC){
source.options.forEach(option => {
if(!this.propertyCodes.includes(option.code)){
this.propertyCodes.push(option.code);
}
});
}else{
source.results.fieldsMapping.forEach(fieldMapping => {
if(!this.propertyCodes.includes(fieldMapping.code)){
this.propertyCodes.push(fieldMapping.code);
}
});
}
});
}
this.isDeleted = data ? data.isActive === IsActive.Inactive : false;
this.buildForm();
} catch (error) {
@ -167,7 +170,7 @@ export class ReferenceTypeEditorComponent extends BaseEditor<ReferenceTypeEditor
}
persistEntity(onSuccess?: (response) => void): void {
const formData = this.formService.getValue(this.formGroup.value) as ReferenceTypePersist;
const formData = this.formService.getValue(this.formGroup.getRawValue()) as ReferenceTypePersist;
console.log(formData);
this.referenceTypeService.persist(formData)
.pipe(takeUntil(this._destroyed)).subscribe(
@ -221,36 +224,54 @@ export class ReferenceTypeEditorComponent extends BaseEditor<ReferenceTypeEditor
addField(): void {
const field: ReferenceTypeFieldEditorModel = new ReferenceTypeFieldEditorModel();
(this.formGroup.get('definition').get('fields') as FormArray).push(field.buildForm());
// const fieldIndex = (this.formGroup.get('definition').get('fields') as FormArray).length - 1;
// if(((this.formGroup.get('definition').get('fields') as FormArray).at(fieldIndex) as FormArray).get('code').valid){
// }
}
removeField(fieldIndex: number): void {
(this.formGroup.get('definition').get('fields') as FormArray).removeAt(fieldIndex);
const fieldCode =(this.formGroup.get('definition').get('fields') as FormArray).at(fieldIndex).get('code').value
if(this.propertyCodes.length> 0){
if(this.propertyCodes.includes(fieldCode)){
this.propertyCodes.splice(this.propertyCodes.indexOf(fieldCode),1);
}
}
dropFields(event: CdkDragDrop<string[]>) {
const fieldssFormArray = (this.formGroup.get('definition').get('fields') as FormArray);
(this.formGroup.get('definition').get('fields') as FormArray).removeAt(fieldIndex);
moveItemInArray(fieldssFormArray.controls, event.previousIndex, event.currentIndex);
fieldssFormArray.updateValueAndValidity();
const sourceFormArray = ((this.formGroup.get('definition').get('sources') as FormArray));
for(let i=0; i<sourceFormArray.length; i++){
const optionsFormArray = ((this.formGroup.get('definition').get('sources') as FormArray).at(i).get('options') as FormArray);
for(let j=0; j<optionsFormArray.length; j++){
if (fieldCode == ((this.formGroup.get('definition').get('sources') as FormArray).at(i).get('options') as FormArray).at(j).get('code').getRawValue()){
this.removeOption(i,j);
}
}
const fieldMappingFormArray = ((this.formGroup.get('definition').get('sources') as FormArray).at(i).get('results').get('fieldsMapping') as FormArray);
for(let j=0; j<fieldMappingFormArray.length; j++){
if (fieldCode == ((this.formGroup.get('definition').get('sources') as FormArray).at(i).get('results').get('fieldsMapping') as FormArray).at(j).get('code').getRawValue()){
this.removeFieldMapping(i,j);
}
}
}
}
submitFields(): void{
const fieldssFormArray = (this.formGroup.get('definition').get('fields') as FormArray);
const fieldsFormArray = (this.formGroup.get('definition').get('fields') as FormArray);
if (fieldssFormArray.valid){
if (fieldsFormArray.valid){
const sourcesFormArray = (this.formGroup.get('definition').get('sources') as FormArray);
const sourceSize = (this.formGroup.get('definition').get('sources') as FormArray).length;
if(sourceSize && sourceSize > 0){
for(let i =0; i < sourceSize; i++){
this.addFieldMapping(i, fieldssFormArray.at(i).get('code').value);
this.addOption(i, fieldssFormArray.at(i).get('code').value);
if(fieldsFormArray.length > 0){
for(let j=0; j< sourcesFormArray.length; j++){
for(let i =0; i < fieldsFormArray.length; i++){
this.addFieldMapping(j, fieldsFormArray.at(i).get('code').value);
this.addOption(j, fieldsFormArray.at(i).get('code').value);
if(!this.propertyCodes.includes(fieldsFormArray.at(i).get('code').value)){
this.propertyCodes.push(fieldsFormArray.at(i).get('code').value);
}
}
}
}
}
@ -261,16 +282,20 @@ export class ReferenceTypeEditorComponent extends BaseEditor<ReferenceTypeEditor
const source: ReferenceTypeSourceBaseConfigurationEditorModel = new ReferenceTypeSourceBaseConfigurationEditorModel();
(this.formGroup.get('definition').get('sources') as FormArray).push(source.buildForm());
const sourceIndex = (this.formGroup.get('definition').get('sources') as FormArray).length - 1;
this.systemFieldsMapping.forEach(x => {
this.addFieldMapping(sourceIndex, null);
this.addOption(sourceIndex, null);
});
const fieldsSize = (this.formGroup.get('definition').get('fields') as FormArray).length;
if(fieldsSize && fieldsSize > 0){
for(let i =0; i < fieldsSize; i++){
this.addFieldMapping(sourceIndex, null);
this.addOption(sourceIndex, null);
this.addFieldMapping(sourceIndex, "reference_id");
this.addFieldMapping(sourceIndex, "label");
this.addFieldMapping(sourceIndex, "description");
this.addOption(sourceIndex, "reference_id");
this.addOption(sourceIndex, "label");
this.addOption(sourceIndex, "description");
const fieldsFormArray = (this.formGroup.get('definition').get('fields') as FormArray);
if(fieldsFormArray && fieldsFormArray.length > 0){
for(let i =0; i < fieldsFormArray.length; i++){
this.addFieldMapping(sourceIndex, fieldsFormArray.at(i).get('code').value);
this.addOption(sourceIndex, fieldsFormArray.at(i).get('code').value);
}
}
}
@ -286,21 +311,18 @@ export class ReferenceTypeEditorComponent extends BaseEditor<ReferenceTypeEditor
//
addFieldMapping(sourceIndex: number, code: string): void {
const fieldMapping: ResultFieldsMappingConfigurationEditorModel = new ResultFieldsMappingConfigurationEditorModel();
//((this.formGroup.get('definition').get('sources') as FormArray).at(sourceIndex).get('results').get('fieldsMapping') as FormArray).push(fieldMapping.buildForm());
const fieldMappingSize = ((this.formGroup.get('definition').get('sources') as FormArray).at(sourceIndex).get('results').get('fieldsMapping') as FormArray).length;
if (fieldMappingSize>0){
for(let i=0; i<fieldMappingSize; i++){
if(((this.formGroup.get('definition').get('sources') as FormArray).at(sourceIndex).get('results').get('fieldsMapping') as FormArray).at(i).get('code').value == code){
console.log('error');
if(((this.formGroup.get('definition').get('sources') as FormArray).at(sourceIndex).get('results').get('fieldsMapping') as FormArray).at(i).get('code').getRawValue() == code){
return;
};
}
}
}
((this.formGroup.get('definition').get('sources') as FormArray).at(sourceIndex).get('results').get('fieldsMapping') as FormArray).push(fieldMapping.buildForm());
((this.formGroup.get('definition').get('sources') as FormArray).at(sourceIndex).get('results').get('fieldsMapping') as FormArray).at(fieldMappingSize).get('code').setValue('1');
((this.formGroup.get('definition').get('sources') as FormArray).at(sourceIndex).get('results').get('fieldsMapping') as FormArray).at(fieldMappingSize).get('code').patchValue(code);
}
removeFieldMapping(sourceIndex: number, fieldMappingIndex: number): void {
@ -308,13 +330,6 @@ export class ReferenceTypeEditorComponent extends BaseEditor<ReferenceTypeEditor
(formArray.get('results').get('fieldsMapping') as FormArray).removeAt(fieldMappingIndex);
}
dropFieldsMapping(event: CdkDragDrop<string[]>) {
const fieldssFormArray = (this.formGroup.get('definition').get('sources').get('fieldsMapping') as FormArray);
moveItemInArray(fieldssFormArray.controls, event.previousIndex, event.currentIndex);
fieldssFormArray.updateValueAndValidity();
}
//
//
@ -326,16 +341,9 @@ export class ReferenceTypeEditorComponent extends BaseEditor<ReferenceTypeEditor
((this.formGroup.get('definition').get('sources') as FormArray).at(sourceIndex).get('queries') as FormArray).push(query.buildForm());
}
removeQuery(sourceIndex: number, fieldMappingIndex: number): void {
removeQuery(sourceIndex: number, queryIndex: number): void {
const formArray = ((this.formGroup.get('definition').get('sources') as FormArray).at(sourceIndex).get('queries') as FormArray);
formArray.removeAt(fieldMappingIndex);
}
dropQueries(event: CdkDragDrop<string[]>) {
const fieldssFormArray = (this.formGroup.get('definition').get('sources').get('queries') as FormArray);
moveItemInArray(fieldssFormArray.controls, event.previousIndex, event.currentIndex);
fieldssFormArray.updateValueAndValidity();
formArray.removeAt(queryIndex);
}
// Options
@ -346,15 +354,101 @@ export class ReferenceTypeEditorComponent extends BaseEditor<ReferenceTypeEditor
if (optionsSize>0){
for(let i=0; i<optionsSize; i++){
if(((this.formGroup.get('definition').get('sources') as FormArray).at(sourceIndex).get('options') as FormArray).at(i).get('code').value == code){
console.log('error');
if(((this.formGroup.get('definition').get('sources') as FormArray).at(sourceIndex).get('options') as FormArray).at(i).get('code').getRawValue() == code){
return;
};
}
}
}
((this.formGroup.get('definition').get('sources') as FormArray).at(sourceIndex).get('options') as FormArray).push(options.buildForm());
((this.formGroup.get('definition').get('sources') as FormArray).at(sourceIndex).get('options') as FormArray).at(optionsSize).get('code').setValue('1');
((this.formGroup.get('definition').get('sources') as FormArray).at(sourceIndex).get('options') as FormArray).at(optionsSize).get('code').patchValue(code);
}
removeOption(sourceIndex: number, optionIndex: number): void {
const formArray = ((this.formGroup.get('definition').get('sources') as FormArray).at(sourceIndex) as FormArray);
(formArray.get('options') as FormArray).removeAt(optionIndex);
}
// Dependencies
addDependency(sourceIndex: number): void{
const dependency: ReferenceTypeSourceBaseDependencyEditorModel = new ReferenceTypeSourceBaseDependencyEditorModel();
const formArray = (this.formGroup.get('definition').get('sources') as FormArray).at(sourceIndex).get('dependencies') as FormArray;
formArray.push(dependency.buildForm());
this.addProperty(sourceIndex, (formArray.length-1));
}
removeDependency(sourceIndex: number, dependencyIndex: number): void {
const formArray = ((this.formGroup.get('definition').get('sources') as FormArray).at(sourceIndex).get('dependencies') as FormArray);
formArray.removeAt(dependencyIndex);
}
private getReferenceTypes(excludedId?: Guid): void{
const lookup = ReferenceTypeService.DefaultReferenceTypeLookup();
if(excludedId) lookup.excludedIds = [excludedId];
this.referenceTypeService.query(lookup)
.pipe(takeUntil(this._destroyed))
.subscribe(response => {
this.referenceTypes = response.items as ReferenceType[];
});
}
selectedReferenceTypeChanged(code: string): void{
this.selectedReferenceTypeCode = code;
this.sourceKeys = [];
this.targetPropertyCodes = [];
const lookup = ReferenceTypeService.DefaultReferenceTypeLookup();
lookup.codes = [this.selectedReferenceTypeCode];
this.referenceTypeService.query(lookup)
.pipe(takeUntil(this._destroyed))
.subscribe(response => {
if(response.count ==1){
const referenceType = response.items[0] as ReferenceType;
referenceType.definition.sources.forEach(source => {
if(!this.sourceKeys.includes(source.key)) this.sourceKeys.push(source.key)
if(source.type == ReferenceTypeSourceType.API){
source.results.fieldsMapping.forEach(target => {
if(!this.targetPropertyCodes.includes(target.code)) this.targetPropertyCodes.push(target.code)
});
}else{
source.options.forEach(target => {
if(!this.targetPropertyCodes.includes(target.code)) this.targetPropertyCodes.push(target.code)
});
}
});
}
});
}
// Properties
addProperty(sourceIndex: number, dependencyIndex: number): void{
const optionFormArray = ((this.formGroup.get('definition').get('sources') as FormArray).at(sourceIndex).get('options') as FormArray);
for(let i =0; i < optionFormArray.length; i++){
if(!this.propertyCodes.includes(optionFormArray.at(i).get('code').getRawValue())){
this.propertyCodes.push(optionFormArray.at(i).get('code').getRawValue());
}
}
if (((this.formGroup.get('definition').get('sources') as FormArray).at(sourceIndex).get('dependencies') as FormArray).at(dependencyIndex).get('referenceTypeCode').value == null){
return ;
}
const property: DependencyPropertyEditorModel = new DependencyPropertyEditorModel();
(((this.formGroup.get('definition').get('sources') as FormArray).at(sourceIndex).get('dependencies') as FormArray).at(dependencyIndex).get("properties") as FormArray).push(property.buildForm());
}
removeProperty(sourceIndex: number, dependencyIndex: number, propertyIndex: number): void {
const formArray = (((this.formGroup.get('definition').get('sources') as FormArray).at(sourceIndex).get('dependencies') as FormArray).at(dependencyIndex).get("properties") as FormArray);
formArray.removeAt(propertyIndex);
}
}

View File

@ -2,7 +2,7 @@ import { UntypedFormBuilder, UntypedFormGroup, Validators } from "@angular/forms
import { ReferenceFieldDataType } from "@app/core/common/enum/reference-field-data-type";
import { ReferenceTypeExternalApiHTTPMethodType } from "@app/core/common/enum/reference-type-external-api-http-method-type";
import { ReferenceTypeSourceType } from "@app/core/common/enum/reference-type-source-type";
import { ReferenceType, ReferenceTypeDefinition, ReferenceTypeDefinitionPersist, ReferenceTypePersist, ReferenceTypeFieldPersist,ReferenceTypeField, AuthenticationConfiguration, AuthenticationConfigurationPersist, QueryConfigPersist, QueryConfig, ResultsConfigurationPersist, ResultFieldsMappingConfigurationPersist, ResultsConfiguration, ResultFieldsMappingConfiguration, ReferenceTypeSourceBaseConfigurationPersist, ReferenceTypeSourceBaseConfiguration, ReferenceTypeStaticOptionPersist, ReferenceTypeStaticOption } from "@app/core/model/reference-type/reference-type";
import { ReferenceType, ReferenceTypeDefinition, ReferenceTypeDefinitionPersist, ReferenceTypePersist, ReferenceTypeFieldPersist,ReferenceTypeField, AuthenticationConfiguration, AuthenticationConfigurationPersist, QueryConfigPersist, QueryConfig, ResultsConfigurationPersist, ResultFieldsMappingConfigurationPersist, ResultsConfiguration, ResultFieldsMappingConfiguration, ReferenceTypeSourceBaseConfigurationPersist, ReferenceTypeSourceBaseConfiguration, ReferenceTypeStaticOptionPersist, ReferenceTypeStaticOption, DependencyPropertyPersist, DependencyProperty, ReferenceTypeSourceBaseDependency, ReferenceTypeSourceBaseDependencyPersist } 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";
@ -211,6 +211,8 @@ export class ReferenceTypeSourceBaseConfigurationEditorModel implements Referenc
options : ReferenceTypeStaticOptionEditorModel[] = [];
dependencies : ReferenceTypeSourceBaseDependencyEditorModel[] = [];
protected formBuilder: UntypedFormBuilder = new UntypedFormBuilder();
constructor(
@ -235,7 +237,15 @@ export class ReferenceTypeSourceBaseConfigurationEditorModel implements Referenc
if (item.auth) this.auth = new AuthenticationConfigurationEditorModel().fromModel(item.auth);
if(item.queries) { item.queries.map(x => this.queries.push(new QueryConfigEditorModel().fromModel(x))); }
if(item.options) { item.options.map(x => this.options.push(new ReferenceTypeStaticOptionEditorModel().fromModel(x))); }
if(item.options) {
item.options.map(x => this.options.push(new ReferenceTypeStaticOptionEditorModel().fromModel(x)));
} else {
this.options.push(new ReferenceTypeStaticOptionEditorModel().fromModel({code: 'reference_id', value: undefined}));
this.options.push(new ReferenceTypeStaticOptionEditorModel().fromModel({code: 'label', value: undefined}));
this.options.push(new ReferenceTypeStaticOptionEditorModel().fromModel({code: 'description', value: undefined}));
}
if(item.dependencies) { item.dependencies.map(x => this.dependencies.push(new ReferenceTypeSourceBaseDependencyEditorModel().fromModel(x))); }
}
return this;
}
@ -282,7 +292,6 @@ export class ReferenceTypeSourceBaseConfigurationEditorModel implements Referenc
}), context.getValidation('queries')
)
),
options: this.formBuilder.array(
(this.options ?? []).map(
(item, index) => new ReferenceTypeStaticOptionEditorModel(
@ -291,6 +300,15 @@ export class ReferenceTypeSourceBaseConfigurationEditorModel implements Referenc
rootPath: `options[${index}].`
}), context.getValidation('options')
)
),
dependencies: this.formBuilder.array(
(this.dependencies ?? []).map(
(item, index) => new ReferenceTypeSourceBaseDependencyEditorModel(
this.validationErrorModel
).fromModel(item).buildForm({
rootPath: `dependencies[${index}].`
}), context.getValidation('dependencies')
)
)
});
@ -312,7 +330,7 @@ export class ReferenceTypeSourceBaseConfigurationEditorModel implements Referenc
baseValidationArray.push({ key: 'url', validators: [BackendErrorValidator(validationErrorModel, `${rootPath}url`)] });
baseValidationArray.push({ key: 'paginationPath', validators: [BackendErrorValidator(validationErrorModel, `${rootPath}paginationPath`)] });
baseValidationArray.push({ key: 'contentType', validators: [BackendErrorValidator(validationErrorModel, `${rootPath}contentType`)] });
baseValidationArray.push({ key: 'firstPage', validators: [BackendErrorValidator(validationErrorModel, `${rootPath}firstPage`)] });
baseValidationArray.push({ key: 'firstPage', validators: [Validators.pattern("^[0-9]*$"), BackendErrorValidator(validationErrorModel, `${rootPath}firstPage`)] });
baseValidationArray.push({ key: 'httpMethod', validators: [BackendErrorValidator(validationErrorModel, `${rootPath}httpMethod`)] });
baseValidationArray.push({ key: 'requestBody', validators: [BackendErrorValidator(validationErrorModel, `${rootPath}requestBody`)] });
baseValidationArray.push({ key: 'filterType', validators: [BackendErrorValidator(validationErrorModel, `${rootPath}filterType`)] });
@ -321,6 +339,8 @@ export class ReferenceTypeSourceBaseConfigurationEditorModel implements Referenc
baseValidationArray.push({ key: 'options', validators: [BackendErrorValidator(validationErrorModel, `${rootPath}options`)] });
baseValidationArray.push({ key: 'dependencies', validators: [BackendErrorValidator(validationErrorModel, `${rootPath}dependencies`)] });
baseContext.validation = baseValidationArray;
return baseContext;
}
@ -339,6 +359,11 @@ export class ResultsConfigurationEditorModel implements ResultsConfigurationPers
fromModel(item: ResultsConfiguration): ResultsConfigurationEditorModel {
this.resultsArrayPath = item.resultsArrayPath;
if(item.fieldsMapping) { item.fieldsMapping.map(x => this.fieldsMapping.push(new ResultFieldsMappingConfigurationEditorModel().fromModel(x))); }
else {
this.fieldsMapping.push(new ResultFieldsMappingConfigurationEditorModel().fromModel({code: 'reference_id', responsePath: undefined}));
this.fieldsMapping.push(new ResultFieldsMappingConfigurationEditorModel().fromModel({code: 'label', responsePath: undefined}));
this.fieldsMapping.push(new ResultFieldsMappingConfigurationEditorModel().fromModel({code: 'description', responsePath: undefined}));
}
return this;
}
@ -417,7 +442,7 @@ export class ResultFieldsMappingConfigurationEditorModel implements ResultFields
}
return this.formBuilder.group({
code: [{ value: "code", disabled: disabled }, context.getValidation('code').validators],
code: [{ value: "code", disabled: true }, context.getValidation('code').validators],
responsePath: [{ value: this.responsePath, disabled: disabled }, context.getValidation('responsePath').validators],
});
}
@ -594,7 +619,7 @@ export class ReferenceTypeStaticOptionEditorModel implements ReferenceTypeStatic
}
return this.formBuilder.group({
code: [{ value: this.code, disabled: disabled }, context.getValidation('code').validators],
code: [{ value: this.code, disabled: true }, context.getValidation('code').validators],
value: [{ value: this.value, disabled: disabled }, context.getValidation('value').validators],
});
}
@ -614,3 +639,129 @@ export class ReferenceTypeStaticOptionEditorModel implements ReferenceTypeStatic
return baseContext;
}
}
export class ReferenceTypeSourceBaseDependencyEditorModel implements ReferenceTypeSourceBaseDependencyPersist {
public referenceTypeCode: string;
public key: string;
public required = true;
public properties: DependencyPropertyEditorModel[] = [];
protected formBuilder: UntypedFormBuilder = new UntypedFormBuilder();
constructor(
public validationErrorModel: ValidationErrorModel = new ValidationErrorModel()
) { }
fromModel(item: ReferenceTypeSourceBaseDependency): ReferenceTypeSourceBaseDependencyEditorModel {
this.referenceTypeCode = item.referenceTypeCode;
this.key = item.key;
this.required = item.required;
if(item.properties) { item.properties.map(x => this.properties.push(new DependencyPropertyEditorModel().fromModel(x))); }
return this;
}
buildForm(params?: {
context?: ValidationContext,
disabled?: boolean,
rootPath?: string
}): UntypedFormGroup {
let { context = null, disabled = false, rootPath } = params ?? {}
if (context == null) {
context = ReferenceTypeSourceBaseDependencyEditorModel.createValidationContext({
validationErrorModel: this.validationErrorModel,
rootPath
});
}
return this.formBuilder.group({
referenceTypeCode: [{ value: this.referenceTypeCode, disabled: disabled }, context.getValidation('referenceTypeCode').validators],
key: [{ value: this.key, disabled: disabled }, context.getValidation('key').validators],
required: [{ value: this.required, disabled: true }, context.getValidation('required').validators],
properties: this.formBuilder.array(
(this.properties ?? []).map(
(item, index) => new DependencyPropertyEditorModel(
this.validationErrorModel
).fromModel(item).buildForm({
rootPath: `properties[${index}].`
}), context.getValidation('properties')
)
),
});
}
static createValidationContext(params: {
rootPath?: string,
validationErrorModel: ValidationErrorModel
}): ValidationContext {
const { rootPath = '', validationErrorModel } = params;
const baseContext: ValidationContext = new ValidationContext();
const baseValidationArray: Validation[] = new Array<Validation>();
baseValidationArray.push({ key: 'referenceTypeCode', validators: [Validators.required, BackendErrorValidator(validationErrorModel, `${rootPath}referenceTypeCode`)] });
baseValidationArray.push({ key: 'key', validators: [Validators.required, BackendErrorValidator(validationErrorModel, `${rootPath}key`)] });
baseValidationArray.push({ key: 'required', validators: [Validators.required, BackendErrorValidator(validationErrorModel, `${rootPath}required`)] });
baseValidationArray.push({ key: 'properties', validators: [Validators.required, BackendErrorValidator(validationErrorModel, `${rootPath}properties`)] });
baseContext.validation = baseValidationArray;
return baseContext;
}
}
export class DependencyPropertyEditorModel implements DependencyPropertyPersist {
public code: string;
public target: string;
public required = true;
protected formBuilder: UntypedFormBuilder = new UntypedFormBuilder();
constructor(
public validationErrorModel: ValidationErrorModel = new ValidationErrorModel()
) { }
fromModel(item: DependencyProperty): DependencyPropertyEditorModel {
this.code = item.code;
this.target = item.target;
this.required = item.required;
return this;
}
buildForm(params?: {
context?: ValidationContext,
disabled?: boolean,
rootPath?: string
}): UntypedFormGroup {
let { context = null, disabled = false, rootPath } = params ?? {}
if (context == null) {
context = DependencyPropertyEditorModel.createValidationContext({
validationErrorModel: this.validationErrorModel,
rootPath
});
}
return this.formBuilder.group({
code: [{ value: this.code, disabled: disabled }, context.getValidation('code').validators],
target: [{ value: this.target, disabled: disabled }, context.getValidation('target').validators],
required: [{ value: this.required, disabled: true }, context.getValidation('required').validators],
});
}
static createValidationContext(params: {
rootPath?: string,
validationErrorModel: ValidationErrorModel
}): ValidationContext {
const { rootPath = '', validationErrorModel } = params;
const baseContext: ValidationContext = new ValidationContext();
const baseValidationArray: Validation[] = new Array<Validation>();
baseValidationArray.push({ key: 'code', validators: [Validators.required, BackendErrorValidator(validationErrorModel, `${rootPath}code`)] });
baseValidationArray.push({ key: 'target', validators: [Validators.required, BackendErrorValidator(validationErrorModel, `${rootPath}target`)] });
baseValidationArray.push({ key: 'required', validators: [Validators.required, BackendErrorValidator(validationErrorModel, `${rootPath}required`)] });
baseContext.validation = baseValidationArray;
return baseContext;
}
}

View File

@ -1,6 +1,6 @@
import { Injectable } from '@angular/core';
import { ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router';
import { AuthenticationConfiguration, QueryConfig, ReferenceType, ReferenceTypeDefinition, ReferenceTypeField, ReferenceTypeSourceBaseConfiguration, ResultsConfiguration, ResultFieldsMappingConfiguration, ReferenceTypeStaticOption } from '@app/core/model/reference-type/reference-type';
import { AuthenticationConfiguration, QueryConfig, ReferenceType, ReferenceTypeDefinition, ReferenceTypeField, ReferenceTypeSourceBaseConfiguration, ResultsConfiguration, ResultFieldsMappingConfiguration, ReferenceTypeStaticOption, ReferenceTypeSourceBaseDependency, DependencyProperty } 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';
@ -59,6 +59,14 @@ export class ReferenceTypeEditorResolver extends BaseEditorResolver {
[nameof<ReferenceType>(x => x.definition), nameof<ReferenceTypeDefinition>(x => x.sources), nameof<ReferenceTypeSourceBaseConfiguration>(x => x.options),nameof<ReferenceTypeStaticOption>(x => x.code)].join('.'),
[nameof<ReferenceType>(x => x.definition), nameof<ReferenceTypeDefinition>(x => x.sources), nameof<ReferenceTypeSourceBaseConfiguration>(x => x.options),nameof<ReferenceTypeStaticOption>(x => x.value)].join('.'),
[nameof<ReferenceType>(x => x.definition), nameof<ReferenceTypeDefinition>(x => x.sources), nameof<ReferenceTypeSourceBaseConfiguration>(x => x.dependencies),nameof<ReferenceTypeSourceBaseDependency>(x => x.referenceTypeCode)].join('.'),
[nameof<ReferenceType>(x => x.definition), nameof<ReferenceTypeDefinition>(x => x.sources), nameof<ReferenceTypeSourceBaseConfiguration>(x => x.dependencies),nameof<ReferenceTypeSourceBaseDependency>(x => x.key)].join('.'),
[nameof<ReferenceType>(x => x.definition), nameof<ReferenceTypeDefinition>(x => x.sources), nameof<ReferenceTypeSourceBaseConfiguration>(x => x.dependencies),nameof<ReferenceTypeSourceBaseDependency>(x => x.required)].join('.'),
[nameof<ReferenceType>(x => x.definition), nameof<ReferenceTypeDefinition>(x => x.sources), nameof<ReferenceTypeSourceBaseConfiguration>(x => x.dependencies),nameof<ReferenceTypeSourceBaseDependency>(x => x.properties), nameof<DependencyProperty>(x => x.code)].join('.'),
[nameof<ReferenceType>(x => x.definition), nameof<ReferenceTypeDefinition>(x => x.sources), nameof<ReferenceTypeSourceBaseConfiguration>(x => x.dependencies),nameof<ReferenceTypeSourceBaseDependency>(x => x.properties), nameof<DependencyProperty>(x => x.target)].join('.'),
[nameof<ReferenceType>(x => x.definition), nameof<ReferenceTypeDefinition>(x => x.sources), nameof<ReferenceTypeSourceBaseConfiguration>(x => x.dependencies),nameof<ReferenceTypeSourceBaseDependency>(x => x.properties), nameof<DependencyProperty>(x => x.required)].join('.'),
nameof<ReferenceType>(x => x.createdAt),
nameof<ReferenceType>(x => x.updatedAt),
nameof<ReferenceType>(x => x.isActive)

View File

@ -1125,17 +1125,43 @@
"DATA-TYPE": "Data Type",
"KEY": "Key",
"LABEL": "Label",
"DESCRIPTION": "Description",
"ORDINAL": "Ordinal",
"URL": "Url",
"PAGINATION-PATH": "Pagination Path"
"SOURCE-TYPE": "Source Type",
"PAGINATION-PATH": "Pagination Path",
"CONTENT-TYPE": "Content Type",
"HTTP-METHOD": "HTTP Method",
"FIRST-PAGE": "First Page",
"REQUEST-BODY": "Request Body",
"FILTER-TYPE": "Filter Type",
"RESULTS-PATH": "Results Path",
"TOKEN-PATH": "Token Path",
"TYPE": "Type",
"CONDITION": "Condition",
"SEPARATOR": "Separator",
"DEPENDENCIES": "Dependencies",
"DEPENDENCY": "Dependency",
"REQUIRED": "Required",
"PROPERTIES": "Properties",
"PROPERTY": "Property",
"TARGET": "Target"
},
"ACTIONS": {
"SAVE": "Save",
"CANCEL": "Cancel",
"DELETE": "Delete",
"ADD-FIELD": "Add Field",
"ADD-CONFIG": "Add Config",
"ADD-QUERY": "Add Query"
"REMOVE-FIELD": "Remove Field",
"ADD-SOURCE": "Add Source",
"REMOVE-SOURCE": "Remove Source",
"ADD-QUERY": "Add Query",
"REMOVE-QUERY": "Remove Query",
"ADD-DEPENDENCY": "Add Dependency",
"REMOVE-DEPENDENCY": "Remove Dependency",
"ADD-PROPERTY": "Add property",
"REMOVE-PROPERTY": "Remove property"
}
},
"CONFIRM-DELETE-DIALOG": {
@ -1734,6 +1760,18 @@
"NUMBER": "Number",
"TEXT": "Text",
"EXTERNAL-AUTOCOMPLETE": "External AutoComplete"
},
"REFERENCE-FIELD-DATA-TYPE":{
"TEXT": "Text",
"DATE": "Date"
},
"REFERENCE-TYPE-SOURCE-TYPE":{
"API": "API",
"STATIC": "Static"
},
"REFERENCE-TYPE-EXTERNAL-API-HTTP-METHOD-TYPE":{
"GET": "GET",
"POST": "POST"
}
},
"ADDRESEARCHERS-EDITOR": {