Merge branch 'Development' of code-repo.d4science.org:MaDgiK-CITE/argos into Development

This commit is contained in:
argirok 2022-02-04 10:05:32 +02:00
commit 938f98100f
24 changed files with 451 additions and 219 deletions

View File

@ -73,7 +73,8 @@ public class Admin extends BaseController {
userDatasetProfile.setRole(0); userDatasetProfile.setRole(0);
getApiContext().getOperationsContext().getDatabaseRepository().getUserDatasetProfileDao().createOrUpdate(userDatasetProfile); getApiContext().getOperationsContext().getDatabaseRepository().getUserDatasetProfileDao().createOrUpdate(userDatasetProfile);
datasetProfileManager.storeDatasetProfileUsers(datasetProfile, profile); datasetProfileManager.storeDatasetProfileUsers(datasetProfile, profile);
metricsManager.increaseValue(MetricNames.DATASET_TEMPLATE, 1, MetricNames.TOTAL);
metricsManager.increaseValue(MetricNames.DATASET_TEMPLATE, 1, MetricsManager.datasetTemplateStatus.get(datasetProfile.getStatus()) );
return ResponseEntity.status(HttpStatus.OK).body(modelDefinition.getId()); return ResponseEntity.status(HttpStatus.OK).body(modelDefinition.getId());
} }

View File

@ -1054,14 +1054,10 @@ public class DatasetManager {
if (!value.toString().equals("\"\"")) { if (!value.toString().equals("\"\"")) {
String stringValue = value.toString().replaceAll("=", ":"); String stringValue = value.toString().replaceAll("=", ":");
JSONArray values = new JSONArray(stringValue); JSONArray values = new JSONArray(stringValue);
if (values != null) { values.iterator().forEachRemaining(element -> {
values.iterator().forEachRemaining(element -> { Map<String, Object> data = ((JSONObject) element).toMap();
Map<String, Object> data = ((JSONObject) element).toMap(); this.addTag(tags, wizardModel.getTags(), data.get("id").toString(), data.get("name").toString());
this.addTag(tags, wizardModel.getTags(), data.get("id").toString(), data.get("name").toString()); });
});
} else {
this.addTag(tags, wizardModel.getTags(), "", value.asText());
}
} }
}); });
} }

View File

@ -97,7 +97,6 @@ public class DatasetProfileManager {
DatasetProfile profile = apiContext.getOperationsContext().getDatabaseRepository().getDatasetProfileDao().find(UUID.fromString(id)); DatasetProfile profile = apiContext.getOperationsContext().getDatabaseRepository().getDatasetProfileDao().find(UUID.fromString(id));
apiContext.getOperationsContext().getDatabaseRepository().detachEntity(profile); apiContext.getOperationsContext().getDatabaseRepository().detachEntity(profile);
profile.setId(null); profile.setId(null);
metricsManager.increaseValue(MetricNames.DATASET_TEMPLATE, 1, MetricNames.TOTAL);
return profile; return profile;
} }
@ -253,7 +252,7 @@ public class DatasetProfileManager {
File localFile = convert(multiPartFile); File localFile = convert(multiPartFile);
eu.eudat.logic.utilities.documents.xml.datasetProfileXml.datasetProfileModel.DatasetProfile profile = xmlBuilder.build(localFile); eu.eudat.logic.utilities.documents.xml.datasetProfileXml.datasetProfileModel.DatasetProfile profile = xmlBuilder.build(localFile);
Files.deleteIfExists(localFile.toPath()); Files.deleteIfExists(localFile.toPath());
metricsManager.increaseValue(MetricNames.DATASET_TEMPLATE, 1, MetricNames.TOTAL); metricsManager.increaseValue(MetricNames.DATASET_TEMPLATE, 1, MetricNames.DRAFT);
return profile; return profile;
} catch (IOException e) { } catch (IOException e) {
logger.error(e.getMessage(), e); logger.error(e.getMessage(), e);

View File

@ -32,6 +32,11 @@ public class MetricsManager {
private final static Logger logger = LoggerFactory.getLogger(MetricsManager.class); private final static Logger logger = LoggerFactory.getLogger(MetricsManager.class);
private final Map<String, Gauge> gauges; private final Map<String, Gauge> gauges;
public static final Map<Short, String> datasetTemplateStatus = Stream.of(new Object[][] {
{ DatasetProfile.Status.SAVED.getValue(), MetricNames.DRAFT },
{ DatasetProfile.Status.FINALIZED.getValue(), MetricNames.ACTIVE },
}).collect(Collectors.toMap(data -> (Short) data[0], data -> (String) data[1]));
public void increaseValue(String name, int amount, String label) { public void increaseValue(String name, int amount, String label) {
if(label != null) { if(label != null) {

View File

@ -18,6 +18,7 @@ public class Section {
private String extendedDescription; private String extendedDescription;
private String title; private String title;
private List<Section> section; private List<Section> section;
private Boolean multiplicity;
@XmlAttribute(name = "id") @XmlAttribute(name = "id")
public String getId() { public String getId() {
@ -134,4 +135,13 @@ public class Section {
public void setSection(List<Section> section) { public void setSection(List<Section> section) {
this.section = section; this.section = section;
} }
@XmlAttribute(name = "multiplicity")
public Boolean getMultiplicity() {
return multiplicity;
}
public void setMultiplicity(Boolean multiplicity) {
this.multiplicity = multiplicity;
}
} }

View File

@ -18,6 +18,7 @@ public class Sections {
private String title; private String title;
private List<Section> section; private List<Section> section;
private FieldSets fieldSets; private FieldSets fieldSets;
private Boolean multiplicity;
@XmlAttribute(name = "id") @XmlAttribute(name = "id")
public String getId() { public String getId() {
@ -100,6 +101,15 @@ public class Sections {
this.fieldSets = fieldSets; this.fieldSets = fieldSets;
} }
@XmlAttribute(name = "multiplicity")
public Boolean getMultiplicity() {
return multiplicity;
}
public void setMultiplicity(Boolean multiplicity) {
this.multiplicity = multiplicity;
}
public eu.eudat.models.data.admin.components.datasetprofile.Section toAdminCompositeModelSection() { public eu.eudat.models.data.admin.components.datasetprofile.Section toAdminCompositeModelSection() {
eu.eudat.models.data.admin.components.datasetprofile.Section sectionEntity = new eu.eudat.models.data.admin.components.datasetprofile.Section(); eu.eudat.models.data.admin.components.datasetprofile.Section sectionEntity = new eu.eudat.models.data.admin.components.datasetprofile.Section();
List<eu.eudat.models.data.admin.components.datasetprofile.Section> sectionsListEntity = new LinkedList<>(); List<eu.eudat.models.data.admin.components.datasetprofile.Section> sectionsListEntity = new LinkedList<>();
@ -118,6 +128,7 @@ public class Sections {
sectionEntity.setDescription(description); sectionEntity.setDescription(description);
sectionEntity.setPage(this.page); sectionEntity.setPage(this.page);
sectionEntity.setFieldSets(toAdminCompositeModelSectionFieldSets()); sectionEntity.setFieldSets(toAdminCompositeModelSectionFieldSets());
sectionEntity.setMultiplicity(this.multiplicity);
sectionEntity.setSections(sectionsListEntity); sectionEntity.setSections(sectionsListEntity);

View File

@ -16,6 +16,7 @@ public class Section implements Comparable, ViewStyleDefinition<eu.eudat.models.
private String id; private String id;
private String title; private String title;
private String description; private String description;
private Boolean multiplicity;
public List<Section> getSections() { public List<Section> getSections() {
return sections; return sections;
@ -81,11 +82,20 @@ public class Section implements Comparable, ViewStyleDefinition<eu.eudat.models.
this.ordinal = ordinal; this.ordinal = ordinal;
} }
public Boolean getMultiplicity() {
return multiplicity;
}
public void setMultiplicity(Boolean multiplicity) {
this.multiplicity = multiplicity;
}
@Override @Override
public eu.eudat.models.data.entities.xmlmodels.datasetprofiledefinition.Section toDatabaseDefinition(eu.eudat.models.data.entities.xmlmodels.datasetprofiledefinition.Section item) { public eu.eudat.models.data.entities.xmlmodels.datasetprofiledefinition.Section toDatabaseDefinition(eu.eudat.models.data.entities.xmlmodels.datasetprofiledefinition.Section item) {
if (this.id == null || this.id.isEmpty()) this.id = "section_" + RandomStringUtils.random(5, true, true); if (this.id == null || this.id.isEmpty()) this.id = "section_" + RandomStringUtils.random(5, true, true);
item.setDefaultVisibility(this.defaultVisibility); item.setDefaultVisibility(this.defaultVisibility);
item.setDescription(this.description); item.setDescription(this.description);
item.setMultiplicity(this.multiplicity);
if (this.fieldSets != null) if (this.fieldSets != null)
item.setFieldSets(new ModelBuilder().toViewStyleDefinition(this.fieldSets, eu.eudat.models.data.entities.xmlmodels.datasetprofiledefinition.FieldSet.class)); item.setFieldSets(new ModelBuilder().toViewStyleDefinition(this.fieldSets, eu.eudat.models.data.entities.xmlmodels.datasetprofiledefinition.FieldSet.class));
item.setId(this.id); item.setId(this.id);
@ -108,6 +118,7 @@ public class Section implements Comparable, ViewStyleDefinition<eu.eudat.models.
this.page = item.getPage(); this.page = item.getPage();
this.sections = new ModelBuilder().fromViewStyleDefinition(item.getSections(), Section.class); this.sections = new ModelBuilder().fromViewStyleDefinition(item.getSections(), Section.class);
this.title = item.getTitle(); this.title = item.getTitle();
this.multiplicity = item.getMultiplicity();
} }
@Override @Override
@ -134,6 +145,7 @@ public class Section implements Comparable, ViewStyleDefinition<eu.eudat.models.
shortenSection.setId(this.id); shortenSection.setId(this.id);
shortenSection.setTitle(this.title); shortenSection.setTitle(this.title);
shortenSection.setDescription(this.description); shortenSection.setDescription(this.description);
shortenSection.setMultiplicity(this.multiplicity);
return shortenSection; return shortenSection;
} }

View File

@ -20,11 +20,21 @@ import eu.eudat.models.data.dmp.DataManagementPlan;
import eu.eudat.models.data.externaldataset.ExternalDatasetListingModel; import eu.eudat.models.data.externaldataset.ExternalDatasetListingModel;
import eu.eudat.models.data.user.composite.PagedDatasetProfile; import eu.eudat.models.data.user.composite.PagedDatasetProfile;
import net.minidev.json.JSONValue; import net.minidev.json.JSONValue;
import org.json.JSONArray;
import org.json.JSONObject;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
import org.springframework.web.client.RestTemplate;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.*; import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.Stream;
public class DatasetWizardModel implements DataModel<Dataset, DatasetWizardModel> { public class DatasetWizardModel implements DataModel<Dataset, DatasetWizardModel> {
@ -346,7 +356,7 @@ public class DatasetWizardModel implements DataModel<Dataset, DatasetWizardModel
Class<?>[] params = setterMethod.getParameterTypes(); Class<?>[] params = setterMethod.getParameterTypes();
ObjectMapper mapper = new ObjectMapper(); ObjectMapper mapper = new ObjectMapper();
//GK: Tags Special logic //GK: Tags Special logic
if (prefillingMapping.getTarget().equals("tags")) { if (!value.equals("null") && prefillingMapping.getTarget().equals("tags")) {
List<Object> rawTags = (List<Object>) mapper.readValue(value, params[0]); List<Object> rawTags = (List<Object>) mapper.readValue(value, params[0]);
if (rawTags.get(0) instanceof String) { if (rawTags.get(0) instanceof String) {
List<Tag> parsedTags = rawTags.stream().map(rawTag -> new Tag((String) rawTag, (String) rawTag)).collect(Collectors.toList()); List<Tag> parsedTags = rawTags.stream().map(rawTag -> new Tag((String) rawTag, (String) rawTag)).collect(Collectors.toList());
@ -359,9 +369,73 @@ public class DatasetWizardModel implements DataModel<Dataset, DatasetWizardModel
} }
} else { } else {
List<JsonNode> nodes = JsonSearcher.findNodes(parentNode, "rdaProperty", prefillingMapping.getMaDmpTarget()); List<JsonNode> nodes = JsonSearcher.findNodes(parentNode, "rdaProperty", prefillingMapping.getMaDmpTarget());
if(prefillingMapping.getMaDmpTarget().equals("dataset.distribution.available_until") && !value.equals("null")){
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("uuuu-MM-dd");
LocalDate date = LocalDate.parse(value.replace("\"", ""), formatter);
date = date.plusYears(20);
value = date.toString();
}
for (JsonNode node: nodes) { for (JsonNode node: nodes) {
String id = node.get(0) != null ? node.get(0).get("id").asText() : node.get("id").asText(); String id = node.get(0) != null ? node.get(0).get("id").asText() : node.get("id").asText();
properties.put(id, value); if(prefillingMapping.getMaDmpTarget().equals("dataset.distribution.format") && !value.equals("null")){
JSONArray jsonArr = new JSONArray(value);
List<String> formats = new ArrayList<>();
String extension;
for(int i = 0; i < jsonArr.length(); i++){
JSONObject jsonObj = jsonArr.getJSONObject(i);
String filename = (String) jsonObj.get("filename");
int index = filename.lastIndexOf('.');
extension = (index > 0) ? filename.substring(index+1) : filename;
formats.add(extension);
}
formats = formats.stream().distinct().collect(Collectors.toList());
List<Object> standardFormats = new ArrayList<>();
for(String format: formats) {
RestTemplate restTemplate = new RestTemplate();
String parsedUrl = "https://eestore.paas2.uninett.no/api/fileformat/?search=" + format;
HttpHeaders headers = new HttpHeaders();
headers.setAccept(Collections.singletonList(new MediaType("application", "vnd.api+json")));
HttpEntity<String> entity = new HttpEntity("", headers);
Map<String, Object> data = restTemplate.exchange(parsedUrl, HttpMethod.GET, entity, LinkedHashMap.class).getBody();
jsonArr = new JSONArray(new ObjectMapper().writeValueAsString(data.get("data")));
for(int i = 0; i < jsonArr.length(); i++){
JSONObject jsonObj = jsonArr.getJSONObject(i);
jsonObj = jsonObj.getJSONObject("attributes");
JSONArray extensions = jsonObj.getJSONArray("extensions");
Object formatName = jsonObj.get("name");
boolean found = false;
for(int j = 0; j < extensions.length(); j++){
if(extensions.getString(j).equals(format)){
JSONObject cur = new JSONObject();
cur.put("label", formatName.toString());
standardFormats.add(cur.toString());
found = true;
break;
}
}
if(found){
break;
}
}
}
properties.put(id, standardFormats);
}
else if(prefillingMapping.getMaDmpTarget().equals("dataset.distribution.data_access")){
value = value.replace("\"", "");
if(value.equals("open")){
properties.put(id, value);
}
else if(value.equals("restricted")){
properties.put(id, "shared");
}
else{
properties.put(id, "closed");
}
}
else{
properties.put(id, value.replace("\"", ""));
}
} }
} }
} }

View File

@ -21,6 +21,7 @@ public class Section implements DatabaseViewStyleDefinition, XmlSerializable<Sec
private String extendedDescription; private String extendedDescription;
private List<Section> sections; private List<Section> sections;
private List<FieldSet> fieldSets; private List<FieldSet> fieldSets;
private Boolean multiplicity;
public String getId() { public String getId() {
return id; return id;
@ -102,6 +103,14 @@ public class Section implements DatabaseViewStyleDefinition, XmlSerializable<Sec
this.numbering = numbering; this.numbering = numbering;
} }
public Boolean getMultiplicity() {
return multiplicity;
}
public void setMultiplicity(Boolean multiplicity) {
this.multiplicity = multiplicity;
}
@Override @Override
public Element toXml(Document doc) { public Element toXml(Document doc) {
Element rootElement = doc.createElement("section"); Element rootElement = doc.createElement("section");
@ -109,6 +118,7 @@ public class Section implements DatabaseViewStyleDefinition, XmlSerializable<Sec
rootElement.setAttribute("ordinal", "" + this.ordinal); rootElement.setAttribute("ordinal", "" + this.ordinal);
rootElement.setAttribute("defaultVisibility", "" + this.defaultVisibility); rootElement.setAttribute("defaultVisibility", "" + this.defaultVisibility);
rootElement.setAttribute("page", "" + this.page); rootElement.setAttribute("page", "" + this.page);
rootElement.setAttribute("multiplicity", (this.multiplicity != null ? "" + this.multiplicity : "false"));
Element description = doc.createElement("description"); Element description = doc.createElement("description");
description.setTextContent(this.description); description.setTextContent(this.description);
@ -155,6 +165,7 @@ public class Section implements DatabaseViewStyleDefinition, XmlSerializable<Sec
this.ordinal = Integer.parseInt(element.getAttribute("ordinal")); this.ordinal = Integer.parseInt(element.getAttribute("ordinal"));
this.defaultVisibility = Boolean.valueOf(element.getAttribute("defaultVisibility")); this.defaultVisibility = Boolean.valueOf(element.getAttribute("defaultVisibility"));
this.page = element.getAttribute("page"); this.page = element.getAttribute("page");
this.multiplicity = element.hasAttribute("multiplicity") ? Boolean.valueOf(element.getAttribute("multiplicity")) : false;
Element description = XmlBuilder.getNodeFromListByTagName(element.getChildNodes(), "description"); Element description = XmlBuilder.getNodeFromListByTagName(element.getChildNodes(), "description");
if (description != null) this.description = description.getTextContent(); if (description != null) this.description = description.getTextContent();

View File

@ -19,6 +19,7 @@ public class Section implements Comparable, ViewStyleDefinition<eu.eudat.models.
private String id; private String id;
private String title; private String title;
private String description; private String description;
private Boolean multiplicity;
public List<Section> getSections() { public List<Section> getSections() {
Collections.sort(sections); Collections.sort(sections);
@ -94,6 +95,14 @@ public class Section implements Comparable, ViewStyleDefinition<eu.eudat.models.
this.numbering = numbering; this.numbering = numbering;
} }
public Boolean getMultiplicity() {
return multiplicity;
}
public void setMultiplicity(Boolean multiplicity) {
this.multiplicity = multiplicity;
}
@Override @Override
public eu.eudat.models.data.entities.xmlmodels.datasetprofiledefinition.Section toDatabaseDefinition(eu.eudat.models.data.entities.xmlmodels.datasetprofiledefinition.Section item) { public eu.eudat.models.data.entities.xmlmodels.datasetprofiledefinition.Section toDatabaseDefinition(eu.eudat.models.data.entities.xmlmodels.datasetprofiledefinition.Section item) {
item.setDefaultVisibility(this.defaultVisibility); item.setDefaultVisibility(this.defaultVisibility);
@ -106,6 +115,7 @@ public class Section implements Comparable, ViewStyleDefinition<eu.eudat.models.
if (this.sections != null) if (this.sections != null)
item.setSections(new ModelBuilder().toViewStyleDefinition(this.sections, eu.eudat.models.data.entities.xmlmodels.datasetprofiledefinition.Section.class)); item.setSections(new ModelBuilder().toViewStyleDefinition(this.sections, eu.eudat.models.data.entities.xmlmodels.datasetprofiledefinition.Section.class));
item.setTitle(this.title); item.setTitle(this.title);
item.setMultiplicity(this.multiplicity);
return item; return item;
} }
@ -120,6 +130,7 @@ public class Section implements Comparable, ViewStyleDefinition<eu.eudat.models.
this.page = item.getPage(); this.page = item.getPage();
this.sections = new ModelBuilder().fromViewStyleDefinition(item.getSections(), Section.class); this.sections = new ModelBuilder().fromViewStyleDefinition(item.getSections(), Section.class);
this.title = item.getTitle(); this.title = item.getTitle();
this.multiplicity = item.getMultiplicity();
} }
@Override @Override

View File

@ -1,13 +1,13 @@
package eu.eudat.models.rda.mapper; package eu.eudat.models.rda.mapper;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import eu.eudat.data.entities.DatasetProfile; import eu.eudat.data.entities.DatasetProfile;
import eu.eudat.elastic.criteria.DatasetCriteria;
import eu.eudat.elastic.entities.Tag; import eu.eudat.elastic.entities.Tag;
import eu.eudat.logic.managers.DatasetManager; import eu.eudat.logic.managers.DatasetManager;
import eu.eudat.logic.services.ApiContext; import eu.eudat.logic.services.ApiContext;
import eu.eudat.logic.utilities.json.JavaToJson; import eu.eudat.logic.utilities.helpers.StreamDistinctBy;
import eu.eudat.logic.utilities.json.JsonSearcher; import eu.eudat.logic.utilities.json.JsonSearcher;
import eu.eudat.models.data.datasetprofile.DatasetProfileOverviewModel; import eu.eudat.models.data.datasetprofile.DatasetProfileOverviewModel;
import eu.eudat.models.data.datasetwizard.DatasetWizardModel; import eu.eudat.models.data.datasetwizard.DatasetWizardModel;
@ -19,7 +19,6 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import javax.transaction.Transactional; import javax.transaction.Transactional;
import java.net.URI;
import java.time.Instant; import java.time.Instant;
import java.time.ZoneId; import java.time.ZoneId;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
@ -131,7 +130,7 @@ public class DatasetRDAMapper {
rda.setKeyword(keywordNodes.stream().map(keywordNode -> { rda.setKeyword(keywordNodes.stream().map(keywordNode -> {
JsonNode value = keywordNode.get("value"); JsonNode value = keywordNode.get("value");
if (value.isArray()) { if (value.isArray()) {
return StreamSupport.stream(value.spliterator(), false).map(node -> KeywordRDAMapper.toRDA(node.asText())).flatMap(Collection::stream).collect(Collectors.toList()); return StreamSupport.stream(value.spliterator(), false).map(node -> KeywordRDAMapper.toRDA(node.toString())).flatMap(Collection::stream).collect(Collectors.toList());
} else { } else {
return KeywordRDAMapper.toRDA(keywordNode.get("value").asText()); return KeywordRDAMapper.toRDA(keywordNode.get("value").asText());
} }
@ -331,9 +330,14 @@ public class DatasetRDAMapper {
// if (keywordIds.size() < rda.getKeyword().size()) { // if (keywordIds.size() < rda.getKeyword().size()) {
// takeAll = true; // takeAll = true;
// } // }
DatasetCriteria criteria = new DatasetCriteria();
criteria.setHasTags(true);
List<Tag> tags = this.apiContext.getOperationsContext().getElasticRepository().getDatasetRepository().query(criteria).stream().map(eu.eudat.elastic.entities.Dataset::getTags).flatMap(Collection::stream).filter(StreamDistinctBy.distinctByKey(Tag::getId)).collect(Collectors.toList());
if(!rda.getKeyword().isEmpty()){ if(!rda.getKeyword().isEmpty()){
for (int i = 0; i < keywordIds.size(); i++) { List<Tag> templateTags = tags.stream().filter(tag -> rda.getKeyword().contains(tag.getName())).collect(Collectors.toList());
// if (takeAll) { properties.put(keywordIds.get(0), mapper.writeValueAsString(templateTags));
// for (int i = 0; i < keywordIds.size(); i++) {
// //if (takeAll) {
// List<String> tags = new ArrayList<>(); // List<String> tags = new ArrayList<>();
// for (String keyword : rda.getKeyword()) { // for (String keyword : rda.getKeyword()) {
// tags.add(mapper.writeValueAsString(toTagEntity(keyword))); // tags.add(mapper.writeValueAsString(toTagEntity(keyword)));
@ -342,8 +346,8 @@ public class DatasetRDAMapper {
// } else { // } else {
// properties.put(keywordIds.get(i), mapper.writeValueAsString(toTagEntity(rda.getKeyword().get(i)))); // properties.put(keywordIds.get(i), mapper.writeValueAsString(toTagEntity(rda.getKeyword().get(i))));
// } // }
properties.put(keywordIds.get(i), rda.getKeyword().get(i)); // properties.put(keywordIds.get(i), rda.getKeyword().get(i));
} // }
} }
} }

View File

@ -2,7 +2,9 @@ package eu.eudat.models.rda.mapper;
import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import eu.eudat.elastic.entities.Dataset;
import eu.eudat.elastic.entities.Tag; import eu.eudat.elastic.entities.Tag;
import eu.eudat.logic.services.ApiContext;
import eu.eudat.logic.utilities.json.JavaToJson; import eu.eudat.logic.utilities.json.JavaToJson;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -15,15 +17,15 @@ public class KeywordRDAMapper {
private static final Logger logger = LoggerFactory.getLogger(KeywordRDAMapper.class); private static final Logger logger = LoggerFactory.getLogger(KeywordRDAMapper.class);
public static List<String> toRDA(String value) { public static List<String> toRDA(String value) {
if (!value.isEmpty()) { if (!value.isEmpty() && !value.equals("null")) {
try { try {
ObjectMapper mapper = new ObjectMapper(); ObjectMapper mapper = new ObjectMapper();
String valueJson = JavaToJson.objectStringToJson(value); String valueJson = JavaToJson.objectStringToJson(value);
List<Tag> tags = Arrays.asList(mapper.readValue(valueJson, Tag[].class)); Tag tag = mapper.readValue(valueJson, Tag.class);
return tags.stream().map(Tag::getName).collect(Collectors.toList()); return new ArrayList<>(Collections.singletonList(tag.getName()));
} catch (JsonProcessingException e) { } catch (JsonProcessingException e) {
logger.warn(e.getMessage() + ". Attempting to parse it as a String list."); logger.warn(e.getMessage() + ". Attempting to parse it as a String since its a new tag.");
return new ArrayList<>(Arrays.asList(value.replace(" ", "").split(","))); return new ArrayList<>(Collections.singletonList(value));
} }
} }

View File

@ -1,7 +1,7 @@
package eu.eudat.types; package eu.eudat.types;
public class MetricNames { public class MetricNames {
public static final String DATASET_TEMPLATE = "argos_dataset_templates"; public static final String DATASET_TEMPLATE = "argos_dmp_templates";
public static final String INSTALLATIONS = "installations"; public static final String INSTALLATIONS = "installations";
public static final String USERS = "argos_users"; public static final String USERS = "argos_users";
public static final String DMP = "argos_managed_dmps"; public static final String DMP = "argos_managed_dmps";

View File

@ -1189,11 +1189,20 @@ but not
<mapping source="metadata.dates.valid" maDmpTarget="dataset.distribution.available_until"/> <mapping source="metadata.dates.valid" maDmpTarget="dataset.distribution.available_until"/>
<mapping source="metadata.access_right" maDmpTarget="dataset.distribution.data_access"/> <mapping source="metadata.access_right" maDmpTarget="dataset.distribution.data_access"/>
<mapping source="metadata.publication_date" maDmpTarget="dataset.issued"/> <mapping source="metadata.publication_date" maDmpTarget="dataset.issued"/>
<mapping source="metadata.license.id" maDmpTarget="dataset.distribution.license.license_ref"/>
<mapping source="metadata.license.created" maDmpTarget="dataset.distribution.license.start_date"/> <mapping source="metadata.license.created" maDmpTarget="dataset.distribution.license.start_date"/>
<mapping source="metadata.embargo_date" maDmpTarget="dataset.distribution.license.start_date"/>
<mapping source="files" maDmpTarget="dataset.distribution.format"/>
</mappings> </mappings>
<fixedMappings> <fixedMappings>
<fixedMapping maDmpTarget="dataset.distribution.host.title" value="Zenodo" /> <fixedMapping maDmpTarget="dataset.distribution.host.title" value="Zenodo" />
<fixedMapping maDmpTarget="dataset.metadata.metadata_standard_id.identifier" value="https://schema.datacite.org/meta/kernel-4.4/" />
<fixedMapping maDmpTarget="dataset.metadata.metadata_standard_id.type" value="url" />
<fixedMapping maDmpTarget="dataset.distribution.host.description" value="Repository hosted by Zenodo" />
<fixedMapping maDmpTarget="dataset.distribution.host.url" value="https://zenodo.org" />
<fixedMapping maDmpTarget="dataset.distribution.host.pid_system" value="doi" />
<fixedMapping maDmpTarget="dataset.security_and_privacy.title" value="TBD" />
<fixedMapping maDmpTarget="dataset.security_and_privacy.description" value="TBD" />
<fixedMapping maDmpTarget="dataset.preservation_statement" value="TBD" />
</fixedMappings> </fixedMappings>
</prefillingGet> </prefillingGet>
</config> </config>

View File

@ -1,15 +1,17 @@
import { Component, Input, OnInit } from '@angular/core'; import { ChangeDetectionStrategy, ChangeDetectorRef, Component, Input } from '@angular/core';
import { FormArray, FormGroup, AbstractControl, FormArrayName } from '@angular/forms'; import { FormArray, FormGroup } from '@angular/forms';
import { DatasetDescriptionCompositeFieldEditorModel, DatasetDescriptionFieldEditorModel } from '../../dataset-description-form.model'; import { BaseComponent } from '@common/base/base.component';
import { takeUntil } from 'rxjs/operators';
import { ToCEntry } from '../../dataset-description.component'; import { ToCEntry } from '../../dataset-description.component';
import { VisibilityRulesService } from '../../visibility-rules/visibility-rules.service'; import { VisibilityRulesService } from '../../visibility-rules/visibility-rules.service';
@Component({ @Component({
selector: 'app-form-composite-field', selector: 'app-form-composite-field',
templateUrl: './form-composite-field.component.html', templateUrl: './form-composite-field.component.html',
styleUrls: ['./form-composite-field.component.scss'] styleUrls: ['./form-composite-field.component.scss'],
changeDetection: ChangeDetectionStrategy.OnPush
}) })
export class FormCompositeFieldComponent { export class FormCompositeFieldComponent extends BaseComponent {
@Input() datasetProfileId: String; @Input() datasetProfileId: String;
@Input() form: FormGroup; @Input() form: FormGroup;
@ -19,13 +21,18 @@ export class FormCompositeFieldComponent {
constructor( constructor(
public visibilityRulesService: VisibilityRulesService, public visibilityRulesService: VisibilityRulesService,
private changeDetector: ChangeDetectorRef
//private markForConsiderationService: MarkForConsiderationService, //private markForConsiderationService: MarkForConsiderationService,
) { ) {
super();
this.visibilityRulesService.getElementVisibilityMapObservable().pipe(takeUntil(this._destroyed)).subscribe(x => {
this.changeDetector.markForCheck();
});
} }
ngOnInit() { ngOnInit() {
if(this.tocentry){ if (this.tocentry) {
this.form = this.tocentry.form as FormGroup; this.form = this.tocentry.form as FormGroup;
} }
} }
@ -50,7 +57,7 @@ export class FormCompositeFieldComponent {
deleteCompositeFieldFormGroup() { deleteCompositeFieldFormGroup() {
const compositeFieldId = ((this.form.get('multiplicityItems') as FormArray).get(''+0) as FormGroup).getRawValue().id; const compositeFieldId = ((this.form.get('multiplicityItems') as FormArray).get('' + 0) as FormGroup).getRawValue().id;
const fieldIds = (this.form.get('fields') as FormArray).controls.map(control => control.get('id').value) as string[]; const fieldIds = (this.form.get('fields') as FormArray).controls.map(control => control.get('id').value) as string[];
const numberOfItems = this.form.get('multiplicityItems').get('' + 0).get('fields').value.length; const numberOfItems = this.form.get('multiplicityItems').get('' + 0).get('fields').value.length;
@ -62,7 +69,7 @@ export class FormCompositeFieldComponent {
this.visibilityRulesService.removeAllIdReferences(compositeFieldId); this.visibilityRulesService.removeAllIdReferences(compositeFieldId);
fieldIds.forEach( x => this.visibilityRulesService.removeAllIdReferences(x)); fieldIds.forEach(x => this.visibilityRulesService.removeAllIdReferences(x));
} }
deleteMultipeFieldFromCompositeFormGroup() { deleteMultipeFieldFromCompositeFormGroup() {
@ -77,10 +84,10 @@ export class FormCompositeFieldComponent {
fieldIds.forEach(x => this.visibilityRulesService.removeAllIdReferences(x)); fieldIds.forEach(x => this.visibilityRulesService.removeAllIdReferences(x));
(parent as FormArray).removeAt(index); (parent as FormArray).removeAt(index);
(parent as FormArray).controls.forEach((control, i)=>{ (parent as FormArray).controls.forEach((control, i) => {
try{ try {
control.get('ordinal').setValue(i); control.get('ordinal').setValue(i);
}catch{ } catch {
throw 'Could not find ordinal'; throw 'Could not find ordinal';
} }
}); });

View File

@ -1,5 +1,5 @@
<div *ngIf="form && this.visibilityRulesService.checkElementVisibility(this.form.get('id').value)" [id]="this.form.get('id').value" <div *ngIf="form && visible" [id]="this.form.get('id').value"
[formGroup]="form" [ngSwitch]="this.form.get('viewStyle').value.renderStyle" class="dynamic-form-field row"> [formGroup]="form" [ngSwitch]="renderStyle" class="dynamic-form-field row">
<h5 *ngIf="this.form.get('title').value && !isChild">{{this.form.get('title').value}}</h5> <h5 *ngIf="this.form.get('title').value && !isChild">{{this.form.get('title').value}}</h5>
<mat-icon *ngIf="this.form.get('additionalInformation').value && !isChild" matTooltip="{{this.form.get('additionalInformation').value}}">info</mat-icon> <mat-icon *ngIf="this.form.get('additionalInformation').value && !isChild" matTooltip="{{this.form.get('additionalInformation').value}}">info</mat-icon>

View File

@ -1,5 +1,5 @@
import { Component, Input, OnInit } from '@angular/core'; import { ChangeDetectionStrategy, Component, Input, OnInit, SimpleChanges } from '@angular/core';
import { FormGroup, FormArray, FormControl } from '@angular/forms'; import { FormGroup, FormArray, FormControl } from '@angular/forms';
import { DatasetProfileComboBoxType } from '@app/core/common/enum/dataset-profile-combo-box-type'; import { DatasetProfileComboBoxType } from '@app/core/common/enum/dataset-profile-combo-box-type';
import { DatasetProfileFieldViewStyle } from '@app/core/common/enum/dataset-profile-field-view-style'; import { DatasetProfileFieldViewStyle } from '@app/core/common/enum/dataset-profile-field-view-style';
@ -19,7 +19,7 @@ import { SingleAutoCompleteConfiguration } from '@app/library/auto-complete/sing
import { VisibilityRulesService } from '@app/ui/misc/dataset-description-form/visibility-rules/visibility-rules.service'; import { VisibilityRulesService } from '@app/ui/misc/dataset-description-form/visibility-rules/visibility-rules.service';
import { BaseComponent } from '@common/base/base.component'; import { BaseComponent } from '@common/base/base.component';
import { TranslateService } from '@ngx-translate/core'; import { TranslateService } from '@ngx-translate/core';
import { map, takeUntil } from 'rxjs/operators'; import { distinctUntilChanged, map, takeUntil } from 'rxjs/operators';
import { Observable } from 'rxjs'; import { Observable } from 'rxjs';
import { ExternalSourceItemModel } from '@app/core/model/external-sources/external-source-item'; import { ExternalSourceItemModel } from '@app/core/model/external-sources/external-source-item';
import { ExternalDatasetCriteria } from '@app/core/query/external-dataset/external-dataset-criteria'; import { ExternalDatasetCriteria } from '@app/core/query/external-dataset/external-dataset-criteria';
@ -42,7 +42,8 @@ import {PublicationCriteria} from "@app/core/query/publication/publication-crite
@Component({ @Component({
selector: 'app-form-field', selector: 'app-form-field',
templateUrl: './form-field.component.html', templateUrl: './form-field.component.html',
styleUrls: ['./form-field.component.scss'] styleUrls: ['./form-field.component.scss'],
changeDetection: ChangeDetectionStrategy.OnPush
}) })
export class FormFieldComponent extends BaseComponent implements OnInit { export class FormFieldComponent extends BaseComponent implements OnInit {
@ -52,6 +53,14 @@ export class FormFieldComponent extends BaseComponent implements OnInit {
@Input() isChild: Boolean = false; @Input() isChild: Boolean = false;
@Input() autocompleteOptions: AutoCompleteSingleData; @Input() autocompleteOptions: AutoCompleteSingleData;
visible: boolean = true;
_renderStyle: DatasetProfileFieldViewStyle = null;
get renderStyle() {
//console.log('renderStyle');
return this._renderStyle;
}
// change: Subscription; // change: Subscription;
// trackByFn = (index, item) => item ? item['id'] : null; // trackByFn = (index, item) => item ? item['id'] : null;
@ -103,9 +112,22 @@ export class FormFieldComponent extends BaseComponent implements OnInit {
private datasetService: DatasetService, private datasetService: DatasetService,
private dmpService: DmpService, private dmpService: DmpService,
private currencyService: CurrencyService private currencyService: CurrencyService
) { super(); } ) {
super();
this.visibilityRulesService.getElementVisibilityMapObservable().pipe(takeUntil(this._destroyed)).subscribe(x => {
this.visible = this.visibilityRulesService.checkElementVisibility(this.form?.get('id')?.value);
});
}
ngOnChanges(changes: SimpleChanges) {
if (changes['form']) {
this._renderStyle = this.form.get('viewStyle')?.value?.renderStyle;
}
}
ngOnInit() { ngOnInit() {
if (this.form.get('value').value) { if (this.form.get('value').value) {
this.visibilityRulesService.updateValueAndVisibility(this.form.get('id').value, this.form.get('value').value); this.visibilityRulesService.updateValueAndVisibility(this.form.get('id').value, this.form.get('value').value);
} }
@ -135,20 +157,20 @@ export class FormFieldComponent extends BaseComponent implements OnInit {
this.singleAutoCompleteConfiguration = { this.singleAutoCompleteConfiguration = {
filterFn: this.searchFromAutocomplete.bind(this), filterFn: this.searchFromAutocomplete.bind(this),
initialItems: () => this.searchFromAutocomplete(''), initialItems: () => this.searchFromAutocomplete(''),
displayFn: (item) => {try{return (item != null && item.length > 1) ? JSON.parse(item).label : item['label']}catch{return ''}}, displayFn: (item) => { try { return (item != null && item.length > 1) ? JSON.parse(item).label : item['label'] } catch { return '' } },
titleFn: (item) => {try{return item['label'] }catch{return''}}, titleFn: (item) => { try { return item['label'] } catch { return '' } },
valueAssign: (item) => {try{return JSON.stringify(item)}catch{return''}}, valueAssign: (item) => { try { return JSON.stringify(item) } catch { return '' } },
subtitleFn: (item) => {try{return item['source'] ? this.language.instant('DATASET-WIZARD.EDITOR.FIELDS.EXTERNAL-AUTOCOMPLETE-SUBTITLE') + item['source'] : this.language.instant('DATASET-WIZARD.EDITOR.FIELDS.EXTERNAL-AUTOCOMPLETE-NO-SOURCE')}catch{return''}} subtitleFn: (item) => { try { return item['source'] ? this.language.instant('DATASET-WIZARD.EDITOR.FIELDS.EXTERNAL-AUTOCOMPLETE-SUBTITLE') + item['source'] : this.language.instant('DATASET-WIZARD.EDITOR.FIELDS.EXTERNAL-AUTOCOMPLETE-NO-SOURCE') } catch { return '' } }
}; };
} }
else { else {
this.multipleAutoCompleteConfiguration = { this.multipleAutoCompleteConfiguration = {
filterFn: this.searchFromAutocomplete.bind(this), filterFn: this.searchFromAutocomplete.bind(this),
initialItems: () => this.searchFromAutocomplete(''), initialItems: () => this.searchFromAutocomplete(''),
displayFn: (item) =>{try{return typeof (item) == 'string' ? JSON.parse(item)['label'] : item['label']}catch{return''}}, displayFn: (item) => { try { return typeof (item) == 'string' ? JSON.parse(item)['label'] : item['label'] } catch { return '' } },
titleFn: (item) =>{ try{return typeof (item) == 'string' ? JSON.parse(item)['label'] : item['label']}catch{return''}}, titleFn: (item) => { try { return typeof (item) == 'string' ? JSON.parse(item)['label'] : item['label'] } catch { return '' } },
valueAssign: (item) =>{ try{return typeof (item) == 'string' ? item : JSON.stringify(item)}catch{return''}}, valueAssign: (item) => { try { return typeof (item) == 'string' ? item : JSON.stringify(item) } catch { return '' } },
subtitleFn: (item) => { try{return item['source'] ? this.language.instant('DATASET-WIZARD.EDITOR.FIELDS.EXTERNAL-AUTOCOMPLETE-SUBTITLE') + item['source'] : this.language.instant('DATASET-WIZARD.EDITOR.FIELDS.EXTERNAL-AUTOCOMPLETE-NO-SOURCE')}catch{return''}} subtitleFn: (item) => { try { return item['source'] ? this.language.instant('DATASET-WIZARD.EDITOR.FIELDS.EXTERNAL-AUTOCOMPLETE-SUBTITLE') + item['source'] : this.language.instant('DATASET-WIZARD.EDITOR.FIELDS.EXTERNAL-AUTOCOMPLETE-NO-SOURCE') } catch { return '' } }
} }
} }
} }
@ -158,20 +180,20 @@ export class FormFieldComponent extends BaseComponent implements OnInit {
this.externalDatasetAutoCompleteConfiguration = { this.externalDatasetAutoCompleteConfiguration = {
filterFn: this.searchDatasetExternalDatasets.bind(this), filterFn: this.searchDatasetExternalDatasets.bind(this),
initialItems: () => this.searchDatasetExternalDatasets(''),//.filter(resultItem => (excludedItems || []).map(x => x.id).indexOf(resultItem.id) === -1), initialItems: () => this.searchDatasetExternalDatasets(''),//.filter(resultItem => (excludedItems || []).map(x => x.id).indexOf(resultItem.id) === -1),
displayFn: (item) => { try{return typeof (item) == 'string' ? JSON.parse(item)['name'] : item.name}catch{return''}}, displayFn: (item) => { try { return typeof (item) == 'string' ? JSON.parse(item)['name'] : item.name } catch { return '' } },
titleFn: (item) => { try{return typeof (item) == 'string' ? JSON.parse(item)['name'] : item.name}catch{return''}}, titleFn: (item) => { try { return typeof (item) == 'string' ? JSON.parse(item)['name'] : item.name } catch { return '' } },
subtitleFn: (item) => { try{return item.source ? this.language.instant('TYPES.EXTERNAL-DATASET-TYPE.SOURCE:') + item.source : item.tag ? this.language.instant('TYPES.EXTERNAL-DATASET-TYPE.SOURCE:') + item.tag : this.language.instant('TYPES.EXTERNAL-DATASET-TYPE.NO-SOURCE')}catch{return''}}, subtitleFn: (item) => { try { return item.source ? this.language.instant('TYPES.EXTERNAL-DATASET-TYPE.SOURCE:') + item.source : item.tag ? this.language.instant('TYPES.EXTERNAL-DATASET-TYPE.SOURCE:') + item.tag : this.language.instant('TYPES.EXTERNAL-DATASET-TYPE.NO-SOURCE') } catch { return '' } },
valueAssign: (item) => { try{return typeof (item) == 'string' ? item : JSON.stringify(item)}catch{return''}} valueAssign: (item) => { try { return typeof (item) == 'string' ? item : JSON.stringify(item) } catch { return '' } }
}; };
break; break;
case DatasetProfileFieldViewStyle.DataRepositories: case DatasetProfileFieldViewStyle.DataRepositories:
this.dataRepositoriesAutoCompleteConfiguration = { this.dataRepositoriesAutoCompleteConfiguration = {
filterFn: this.searchDatasetExternalDataRepositories.bind(this), filterFn: this.searchDatasetExternalDataRepositories.bind(this),
initialItems: () => this.searchDatasetExternalDataRepositories(''), initialItems: () => this.searchDatasetExternalDataRepositories(''),
displayFn: (item) => { try{return typeof (item) == 'string' ? JSON.parse(item)['name'] : item.name}catch{return''}}, displayFn: (item) => { try { return typeof (item) == 'string' ? JSON.parse(item)['name'] : item.name } catch { return '' } },
titleFn: (item) => { try{return typeof (item) == 'string' ? JSON.parse(item)['name'] : item.name}catch{return''}}, titleFn: (item) => { try { return typeof (item) == 'string' ? JSON.parse(item)['name'] : item.name } catch { return '' } },
subtitleFn: (item) => { try{return item.source ? this.language.instant('TYPES.EXTERNAL-DATASET-TYPE.SOURCE:') + item.source : item.tag ? this.language.instant('TYPES.EXTERNAL-DATASET-TYPE.SOURCE:') + item.tag : this.language.instant('TYPES.EXTERNAL-DATASET-TYPE.NO-SOURCE')}catch{return''}}, subtitleFn: (item) => { try { return item.source ? this.language.instant('TYPES.EXTERNAL-DATASET-TYPE.SOURCE:') + item.source : item.tag ? this.language.instant('TYPES.EXTERNAL-DATASET-TYPE.SOURCE:') + item.tag : this.language.instant('TYPES.EXTERNAL-DATASET-TYPE.NO-SOURCE') } catch { return '' } },
valueAssign: (item) => { try{return typeof (item) == 'string' ? item : JSON.stringify(item)}catch{return''}} valueAssign: (item) => { try { return typeof (item) == 'string' ? item : JSON.stringify(item) } catch { return '' } }
}; };
break; break;
case DatasetProfileFieldViewStyle.PubRepositories: case DatasetProfileFieldViewStyle.PubRepositories:
@ -228,29 +250,29 @@ export class FormFieldComponent extends BaseComponent implements OnInit {
this.registriesAutoCompleteConfiguration = { this.registriesAutoCompleteConfiguration = {
filterFn: this.searchDatasetExternalRegistries.bind(this), filterFn: this.searchDatasetExternalRegistries.bind(this),
initialItems: () => this.searchDatasetExternalRegistries(''), initialItems: () => this.searchDatasetExternalRegistries(''),
displayFn: (item) => { try{return typeof (item) == 'string' ? JSON.parse(item)['name'] : item.name}catch{return''}}, displayFn: (item) => { try { return typeof (item) == 'string' ? JSON.parse(item)['name'] : item.name } catch { return '' } },
titleFn: (item) => { try{return typeof (item) == 'string' ? JSON.parse(item)['name'] : item.name}catch{return''}}, titleFn: (item) => { try { return typeof (item) == 'string' ? JSON.parse(item)['name'] : item.name } catch { return '' } },
subtitleFn: (item) => { try{return item.source ? this.language.instant('TYPES.EXTERNAL-DATASET-TYPE.SOURCE:') + item.source : this.language.instant('TYPES.EXTERNAL-DATASET-TYPE.NO-SOURCE')}catch{return''}}, subtitleFn: (item) => { try { return item.source ? this.language.instant('TYPES.EXTERNAL-DATASET-TYPE.SOURCE:') + item.source : this.language.instant('TYPES.EXTERNAL-DATASET-TYPE.NO-SOURCE') } catch { return '' } },
valueAssign: (item) => { try{return typeof (item) == 'string' ? item : JSON.stringify(item)}catch{return''}} valueAssign: (item) => { try { return typeof (item) == 'string' ? item : JSON.stringify(item) } catch { return '' } }
}; };
break; break;
case DatasetProfileFieldViewStyle.Services: case DatasetProfileFieldViewStyle.Services:
this.servicesAutoCompleteConfiguration = { this.servicesAutoCompleteConfiguration = {
filterFn: this.searchDatasetExternalServices.bind(this), filterFn: this.searchDatasetExternalServices.bind(this),
initialItems: () => this.searchDatasetExternalServices(''), initialItems: () => this.searchDatasetExternalServices(''),
displayFn: (item) => { try{return typeof (item) == 'string' ? JSON.parse(item)['name'] : item.name}catch{return ''}}, displayFn: (item) => { try { return typeof (item) == 'string' ? JSON.parse(item)['name'] : item.name } catch { return '' } },
titleFn: (item) => { try{return typeof (item) == 'string' ? JSON.parse(item)['name'] : item.name}catch{return''}}, titleFn: (item) => { try { return typeof (item) == 'string' ? JSON.parse(item)['name'] : item.name } catch { return '' } },
subtitleFn: (item) => { try{return item.source ? this.language.instant('TYPES.EXTERNAL-DATASET-TYPE.SOURCE:') + item.source : item.tag ? this.language.instant('TYPES.EXTERNAL-DATASET-TYPE.SOURCE:') + item.tag : this.language.instant('TYPES.EXTERNAL-DATASET-TYPE.NO-SOURCE')}catch{return''}}, subtitleFn: (item) => { try { return item.source ? this.language.instant('TYPES.EXTERNAL-DATASET-TYPE.SOURCE:') + item.source : item.tag ? this.language.instant('TYPES.EXTERNAL-DATASET-TYPE.SOURCE:') + item.tag : this.language.instant('TYPES.EXTERNAL-DATASET-TYPE.NO-SOURCE') } catch { return '' } },
valueAssign: (item) => { try{return typeof (item) == 'string' ? item : JSON.stringify(item)}catch{return''}} valueAssign: (item) => { try { return typeof (item) == 'string' ? item : JSON.stringify(item) } catch { return '' } }
}; };
break; break;
case DatasetProfileFieldViewStyle.Tags: case DatasetProfileFieldViewStyle.Tags:
this.tagsAutoCompleteConfiguration = { this.tagsAutoCompleteConfiguration = {
filterFn: this.filterTags.bind(this), filterFn: this.filterTags.bind(this),
initialItems: (excludedItems: any[]) => this.filterTags('').pipe(map(result => result.filter(resultItem => (excludedItems || []).map(x => x.id).indexOf(resultItem.id) === -1))), initialItems: (excludedItems: any[]) => this.filterTags('').pipe(map(result => result.filter(resultItem => (excludedItems || []).map(x => x.id).indexOf(resultItem.id) === -1))),
displayFn: (item) => { try{return this.showTag(item)}catch{return''}}, displayFn: (item) => { try { return this.showTag(item) } catch { return '' } },
titleFn: (item) => { try{return item['name']}catch{return''}}, titleFn: (item) => { try { return item['name'] } catch { return '' } },
valueAssign: (item) => { try{return this.addTag(item)}catch{return''}} valueAssign: (item) => { try { return this.addTag(item) } catch { return '' } }
}; };
this.parseTags(); this.parseTags();
break; break;
@ -258,20 +280,20 @@ export class FormFieldComponent extends BaseComponent implements OnInit {
this.researchersAutoCompleteConfiguration = { this.researchersAutoCompleteConfiguration = {
filterFn: this.filterResearchers.bind(this), filterFn: this.filterResearchers.bind(this),
initialItems: (excludedItems: any[]) => this.filterResearchers('').pipe(map(result => result.filter(resultItem => (excludedItems || []).map(x => x.id).indexOf(resultItem.id) === -1))), initialItems: (excludedItems: any[]) => this.filterResearchers('').pipe(map(result => result.filter(resultItem => (excludedItems || []).map(x => x.id).indexOf(resultItem.id) === -1))),
displayFn: (item) => { try{return typeof (item) == 'string' ? JSON.parse(item)['name'] : item.name}catch{return''}}, displayFn: (item) => { try { return typeof (item) == 'string' ? JSON.parse(item)['name'] : item.name } catch { return '' } },
titleFn: (item) =>{ try{return typeof (item) == 'string' ? JSON.parse(item)['name'] : item.name}catch{return''}}, titleFn: (item) => { try { return typeof (item) == 'string' ? JSON.parse(item)['name'] : item.name } catch { return '' } },
subtitleFn: (item) => { try{return item['tag'] ? this.language.instant('TYPES.EXTERNAL-DATASET-TYPE.SOURCE:') + item['tag'] : (item['key'] ? this.language.instant('TYPES.EXTERNAL-DATASET-TYPE.SOURCE:') + item['key'] : this.language.instant('TYPES.EXTERNAL-DATASET-TYPE.NO-SOURCE'))}catch{return''}}, subtitleFn: (item) => { try { return item['tag'] ? this.language.instant('TYPES.EXTERNAL-DATASET-TYPE.SOURCE:') + item['tag'] : (item['key'] ? this.language.instant('TYPES.EXTERNAL-DATASET-TYPE.SOURCE:') + item['key'] : this.language.instant('TYPES.EXTERNAL-DATASET-TYPE.NO-SOURCE')) } catch { return '' } },
valueAssign: (item) => { try{return typeof (item) == 'string' ? item : JSON.stringify(item)}catch{return''}} valueAssign: (item) => { try { return typeof (item) == 'string' ? item : JSON.stringify(item) } catch { return '' } }
}; };
break; break;
case DatasetProfileFieldViewStyle.Organizations: case DatasetProfileFieldViewStyle.Organizations:
this.organisationsAutoCompleteConfiguration = { this.organisationsAutoCompleteConfiguration = {
filterFn: this.filterOrganisations.bind(this), filterFn: this.filterOrganisations.bind(this),
initialItems: (excludedItems: any[]) => this.filterOrganisations('').pipe(map(result => result.filter(resultItem => (excludedItems || []).map(x => x.id).indexOf(resultItem.id) === -1))), initialItems: (excludedItems: any[]) => this.filterOrganisations('').pipe(map(result => result.filter(resultItem => (excludedItems || []).map(x => x.id).indexOf(resultItem.id) === -1))),
displayFn:(item) => { try{return typeof (item) == 'string' ? JSON.parse(item)['name'] : item.name}catch{return''}}, displayFn: (item) => { try { return typeof (item) == 'string' ? JSON.parse(item)['name'] : item.name } catch { return '' } },
titleFn: (item) =>{ try{return typeof (item) == 'string' ? JSON.parse(item)['name'] : item.name}catch{return''}}, titleFn: (item) => { try { return typeof (item) == 'string' ? JSON.parse(item)['name'] : item.name } catch { return '' } },
subtitleFn: (item) =>{ try{return item['tag'] ? this.language.instant('TYPES.EXTERNAL-DATASET-TYPE.SOURCE:') + item['tag'] : (item['key'] ? this.language.instant('TYPES.EXTERNAL-DATASET-TYPE.SOURCE:') + item['key'] : this.language.instant('TYPES.EXTERNAL-DATASET-TYPE.NO-SOURCE'))}catch{return''}}, subtitleFn: (item) => { try { return item['tag'] ? this.language.instant('TYPES.EXTERNAL-DATASET-TYPE.SOURCE:') + item['tag'] : (item['key'] ? this.language.instant('TYPES.EXTERNAL-DATASET-TYPE.SOURCE:') + item['key'] : this.language.instant('TYPES.EXTERNAL-DATASET-TYPE.NO-SOURCE')) } catch { return '' } },
valueAssign: (item) =>{ try{return typeof (item) == 'string' ? item : JSON.stringify(item)}catch{return''}} valueAssign: (item) => { try { return typeof (item) == 'string' ? item : JSON.stringify(item) } catch { return '' } }
}; };
break; break;
case DatasetProfileFieldViewStyle.DatasetIdentifier: case DatasetProfileFieldViewStyle.DatasetIdentifier:
@ -284,9 +306,9 @@ export class FormFieldComponent extends BaseComponent implements OnInit {
this.currencyAutoCompleteConfiguration = { this.currencyAutoCompleteConfiguration = {
filterFn: this.searchCurrency.bind(this), filterFn: this.searchCurrency.bind(this),
initialItems: () => this.searchCurrency(''), initialItems: () => this.searchCurrency(''),
displayFn: (item) => { try{return typeof (item) == 'string' ? JSON.parse(item)['name'] : item.name}catch{return''}}, displayFn: (item) => { try { return typeof (item) == 'string' ? JSON.parse(item)['name'] : item.name } catch { return '' } },
titleFn: (item) => { try{return typeof (item) == 'string' ? JSON.parse(item)['name'] : item.name}catch{return''}}, titleFn: (item) => { try { return typeof (item) == 'string' ? JSON.parse(item)['name'] : item.name } catch { return '' } },
valueAssign: (item) => { try{return typeof (item) == 'string' ? item : JSON.stringify(item)}catch{return''}} valueAssign: (item) => { try { return typeof (item) == 'string' ? item : JSON.stringify(item) } catch { return '' } }
}; };
break; break;
case DatasetProfileFieldViewStyle.Validation: case DatasetProfileFieldViewStyle.Validation:
@ -311,7 +333,10 @@ export class FormFieldComponent extends BaseComponent implements OnInit {
// this.form = this.visibilityRulesService.getFormGroup(this.field.id); // this.form = this.visibilityRulesService.getFormGroup(this.field.id);
this.form.get('value').valueChanges this.form.get('value').valueChanges
.pipe(takeUntil(this._destroyed)) .pipe(
takeUntil(this._destroyed),
distinctUntilChanged()
)
.subscribe(item => { .subscribe(item => {
// if (this.form.get('viewStyle').value.renderStyle === DatasetProfileFieldViewStyle.ComboBox && this.form.get('data').value.type === DatasetProfileComboBoxType.WordList && this.form.get('data').value.multiList) { // if (this.form.get('viewStyle').value.renderStyle === DatasetProfileFieldViewStyle.ComboBox && this.form.get('data').value.type === DatasetProfileComboBoxType.WordList && this.form.get('data').value.multiList) {
// item.forEach(element => { // item.forEach(element => {
@ -319,7 +344,7 @@ export class FormFieldComponent extends BaseComponent implements OnInit {
// }); // });
// } else { // } else {
this.visibilityRulesService.updateValueAndVisibility(this.form.get('id').value, item); this.visibilityRulesService.updateValueAndVisibility(this.form.get('id').value, item);
// } // }
}); });
} }
@ -351,7 +376,7 @@ export class FormFieldComponent extends BaseComponent implements OnInit {
} }
autocompleteRequestItem.criteria.like = query; autocompleteRequestItem.criteria.like = query;
if(this.autocompleteOptions){ if (this.autocompleteOptions) {
return this.datasetExternalAutocompleteService.queryApi(autocompleteRequestItem); return this.datasetExternalAutocompleteService.queryApi(autocompleteRequestItem);
} }
return this.datasetExternalAutocompleteService.queryAutocomplete(autocompleteRequestItem); return this.datasetExternalAutocompleteService.queryAutocomplete(autocompleteRequestItem);
@ -385,20 +410,20 @@ export class FormFieldComponent extends BaseComponent implements OnInit {
this.singleAutoCompleteConfiguration = { this.singleAutoCompleteConfiguration = {
filterFn: myfunc.bind(this), filterFn: myfunc.bind(this),
initialItems: (extraData) => myfunc(''), initialItems: (extraData) => myfunc(''),
displayFn: (item) => { try{return (item != null && item.length > 1) ? JSON.parse(item)[title] : item[title]}catch{return''}}, displayFn: (item) => { try { return (item != null && item.length > 1) ? JSON.parse(item)[title] : item[title] } catch { return '' } },
titleFn: (item) => { try{return item[title]}catch{return''}}, titleFn: (item) => { try { return item[title] } catch { return '' } },
valueAssign: (item) => JSON.stringify(item), valueAssign: (item) => JSON.stringify(item),
subtitleFn: (item) => { try{return item[subtitle]}catch{return''}} subtitleFn: (item) => { try { return item[subtitle] } catch { return '' } }
}; };
} }
else { else {
this.multipleAutoCompleteConfiguration = { this.multipleAutoCompleteConfiguration = {
filterFn: myfunc.bind(this), filterFn: myfunc.bind(this),
initialItems: (extraData) => myfunc(''), initialItems: (extraData) => myfunc(''),
displayFn: (item) => { try{return typeof (item) == 'string' ? JSON.parse(item)[title] : item[title]}catch{return''}}, displayFn: (item) => { try { return typeof (item) == 'string' ? JSON.parse(item)[title] : item[title] } catch { return '' } },
titleFn: (item) => { try{return typeof (item) == 'string' ? JSON.parse(item)[title] : item[title]}catch{return''}}, titleFn: (item) => { try { return typeof (item) == 'string' ? JSON.parse(item)[title] : item[title] } catch { return '' } },
valueAssign: (item) => { try{return typeof (item) == 'string' ? item : JSON.stringify(item)}catch{return''}}, valueAssign: (item) => { try { return typeof (item) == 'string' ? item : JSON.stringify(item) } catch { return '' } },
subtitleFn: (item) => { try{return item[subtitle]}catch{return''}} subtitleFn: (item) => { try { return item[subtitle] } catch { return '' } }
} }
} }
} }
@ -479,23 +504,23 @@ export class FormFieldComponent extends BaseComponent implements OnInit {
} }
parseTags() { parseTags() {
try{ try {
let stringValue = this.form.get('value').value; let stringValue = this.form.get('value').value;
if (typeof stringValue === 'string') { if (typeof stringValue === 'string') {
stringValue = (<string>stringValue).replace(new RegExp('{', 'g'), '{"').replace(new RegExp('=', 'g'), '":"').replace(new RegExp(',', 'g'), '",').replace(new RegExp(', ', 'g'), ', "').replace(new RegExp('}', 'g'), '"}'); stringValue = (<string>stringValue).replace(new RegExp('{', 'g'), '{"').replace(new RegExp('=', 'g'), '":"').replace(new RegExp(',', 'g'), '",').replace(new RegExp(', ', 'g'), ', "').replace(new RegExp('}', 'g'), '"}');
stringValue = stringValue.replace(new RegExp('}"', 'g'), '}').replace(new RegExp('"{', 'g'), '{'); stringValue = stringValue.replace(new RegExp('}"', 'g'), '}').replace(new RegExp('"{', 'g'), '{');
} else if (stringValue instanceof Array) { } else if (stringValue instanceof Array) {
const tempArray = new Array(); const tempArray = new Array();
for (let stringTag of stringValue) { for (let stringTag of stringValue) {
tempArray.push(JSON.parse(stringTag)); tempArray.push(JSON.parse(stringTag));
}
stringValue = JSON.stringify(tempArray);
} }
stringValue = JSON.stringify(tempArray); const tagArray = JSON.parse(stringValue);
} this.form.patchValue({ 'value': tagArray });
const tagArray = JSON.parse(stringValue); } catch (e) {
this.form.patchValue({'value': tagArray});
}catch(e){
console.warn('Could not parse tags'); console.warn('Could not parse tags');
} }
} }
@ -524,7 +549,7 @@ export class FormFieldComponent extends BaseComponent implements OnInit {
} else { } else {
item = ev; item = ev;
} }
if (item.name !== '' ) { if (item.name !== '') {
return item; return item;
} }
} }
@ -548,7 +573,7 @@ export class FormFieldComponent extends BaseComponent implements OnInit {
validateId() { validateId() {
const identifier = this.getDatasetIdControl('identifier').value; const identifier = this.getDatasetIdControl('identifier').value;
const type = this.getDatasetIdControl('type').value; const type = this.getDatasetIdControl('type').value;
this.validationIcon= 'loading'; this.validationIcon = 'loading';
this.externalSourcesService.validateIdentifier(identifier, type).pipe(takeUntil(this._destroyed)).subscribe(result => { this.externalSourcesService.validateIdentifier(identifier, type).pipe(takeUntil(this._destroyed)).subscribe(result => {
this.validationIcon = result === true ? 'done' : 'clear'; this.validationIcon = result === true ? 'done' : 'clear';
}); });

View File

@ -1,22 +1,24 @@
import { AfterViewInit, Component, Input, OnInit, OnChanges, SimpleChanges } from '@angular/core'; import { ChangeDetectionStrategy, ChangeDetectorRef, Component, Input, OnChanges, OnInit, SimpleChanges } from '@angular/core';
import { FormGroup, FormArray, AbstractControl } from '@angular/forms'; import { FormArray, FormGroup } from '@angular/forms';
import { BaseComponent } from '@common/base/base.component';
import { takeUntil } from 'rxjs/operators';
import { DatasetDescriptionCompositeFieldEditorModel } from '../../../dataset-description-form.model';
import { FormFocusService } from '../../../form-focus/form-focus.service'; import { FormFocusService } from '../../../form-focus/form-focus.service';
import { VisibilityRulesService } from '../../../visibility-rules/visibility-rules.service';
import { DatasetDescriptionSectionEditorModel, DatasetDescriptionCompositeFieldEditorModel } from '../../../dataset-description-form.model';
import { FormCompositeFieldComponent } from '../../form-composite-field/form-composite-field.component';
import { LinkToScroll } from '../../../tableOfContentsMaterial/table-of-contents'; import { LinkToScroll } from '../../../tableOfContentsMaterial/table-of-contents';
import { VisibilityRulesService } from '../../../visibility-rules/visibility-rules.service';
@Component({ @Component({
selector: 'app-form-section-inner', selector: 'app-form-section-inner',
templateUrl: './form-section-inner.component.html', templateUrl: './form-section-inner.component.html',
styleUrls: ['./form-section-inner.component.scss'] styleUrls: ['./form-section-inner.component.scss'],
changeDetection: ChangeDetectionStrategy.OnPush
}) })
export class FormSectionInnerComponent implements OnInit, OnChanges { export class FormSectionInnerComponent extends BaseComponent implements OnInit, OnChanges {
//@Input() section: DatasetDescriptionSectionEditorModel; //@Input() section: DatasetDescriptionSectionEditorModel;
@Input() datasetProfileId: String; @Input() datasetProfileId: String;
// @Input() compositeFieldFormGroup: FormGroup; // @Input() compositeFieldFormGroup: FormGroup;
@Input() form:FormGroup; @Input() form: FormGroup;
@Input() pathName: string; @Input() pathName: string;
@Input() path: string; @Input() path: string;
// @Input() i: number; // @Input() i: number;
@ -28,8 +30,14 @@ export class FormSectionInnerComponent implements OnInit, OnChanges {
constructor( constructor(
public visibilityRulesService: VisibilityRulesService, public visibilityRulesService: VisibilityRulesService,
private changeDetector: ChangeDetectorRef,
private formFocusService: FormFocusService private formFocusService: FormFocusService
) { } ) {
super();
this.visibilityRulesService.getElementVisibilityMapObservable().pipe(takeUntil(this._destroyed)).subscribe(x => {
this.changeDetector.markForCheck();
});
}
ngOnInit() { ngOnInit() {
// if (this.section) { // if (this.section) {
@ -75,10 +83,10 @@ export class FormSectionInnerComponent implements OnInit, OnChanges {
deleteMultipeFieldFromCompositeFormGroup(compositeFildIndex: number, fildIndex: number) { deleteMultipeFieldFromCompositeFormGroup(compositeFildIndex: number, fildIndex: number) {
const multiplicityItemsArray = (<FormArray>(this.form.get('compositeFields').get('' + compositeFildIndex).get('multiplicityItems'))) const multiplicityItemsArray = (<FormArray>(this.form.get('compositeFields').get('' + compositeFildIndex).get('multiplicityItems')))
multiplicityItemsArray.removeAt(fildIndex); multiplicityItemsArray.removeAt(fildIndex);
multiplicityItemsArray.controls.forEach((control, i)=>{ multiplicityItemsArray.controls.forEach((control, i) => {
try{ try {
control.get('ordinal').setValue(i); control.get('ordinal').setValue(i);
}catch{ } catch {
throw 'Could not find ordinal'; throw 'Could not find ordinal';
} }
}); });

View File

@ -1,22 +1,23 @@
import { AfterViewInit, Component, Input, OnInit, OnChanges, SimpleChanges, Output, EventEmitter } from '@angular/core'; import { ChangeDetectionStrategy, ChangeDetectorRef, Component, EventEmitter, Input, OnChanges, OnInit, Output, SimpleChanges } from '@angular/core';
import { FormGroup, FormArray, AbstractControl } from '@angular/forms'; import { FormArray, FormGroup } from '@angular/forms';
import { FormFocusService } from '../../form-focus/form-focus.service';
import { VisibilityRulesService } from '../../visibility-rules/visibility-rules.service';
import { DatasetDescriptionSectionEditorModel, DatasetDescriptionCompositeFieldEditorModel } from '../../dataset-description-form.model';
import { FormCompositeFieldComponent } from '../form-composite-field/form-composite-field.component';
import { LinkToScroll } from '../../tableOfContentsMaterial/table-of-contents';
import { ToCEntry, ToCEntryType } from '../../dataset-description.component';
import { VisibilityRuleSource } from '../../visibility-rules/models/visibility-rule-source';
import { VisibilityRule } from '../../visibility-rules/models/visibility-rule';
import { Rule } from '@app/core/model/dataset-profile-definition/rule'; import { Rule } from '@app/core/model/dataset-profile-definition/rule';
import { BaseComponent } from '@common/base/base.component';
import { takeUntil } from 'rxjs/operators';
import { DatasetDescriptionCompositeFieldEditorModel } from '../../dataset-description-form.model';
import { ToCEntry, ToCEntryType } from '../../dataset-description.component';
import { FormFocusService } from '../../form-focus/form-focus.service';
import { LinkToScroll } from '../../tableOfContentsMaterial/table-of-contents';
import { VisibilityRuleSource } from '../../visibility-rules/models/visibility-rule-source';
import { VisibilityRulesService } from '../../visibility-rules/visibility-rules.service';
@Component({ @Component({
selector: 'app-form-section', selector: 'app-form-section',
templateUrl: './form-section.component.html', templateUrl: './form-section.component.html',
styleUrls: ['./form-section.component.scss'] styleUrls: ['./form-section.component.scss'],
changeDetection: ChangeDetectionStrategy.OnPush
}) })
export class FormSectionComponent implements OnInit, OnChanges { export class FormSectionComponent extends BaseComponent implements OnInit, OnChanges {
//@Input() section: DatasetDescriptionSectionEditorModel; //@Input() section: DatasetDescriptionSectionEditorModel;
@Input() datasetProfileId: String; @Input() datasetProfileId: String;
@ -33,21 +34,27 @@ export class FormSectionComponent implements OnInit, OnChanges {
@Output() askedToScroll = new EventEmitter<string>(); @Output() askedToScroll = new EventEmitter<string>();
tocentriesType = ToCEntryType; tocentriesType = ToCEntryType;
@Input() TOCENTRY_ID_PREFIX=""; @Input() TOCENTRY_ID_PREFIX = "";
constructor( constructor(
public visibilityRulesService: VisibilityRulesService, public visibilityRulesService: VisibilityRulesService,
private formFocusService: FormFocusService private formFocusService: FormFocusService,
) { } private changeDetector: ChangeDetectorRef
) {
super();
this.visibilityRulesService.getElementVisibilityMapObservable().pipe(takeUntil(this._destroyed)).subscribe(x => {
this.changeDetector.markForCheck();
});
}
ngOnInit() { ngOnInit() {
// if (this.section) { // if (this.section) {
// this.form = this.visibilityRulesService.getFormGroup(this.section.id); // this.form = this.visibilityRulesService.getFormGroup(this.section.id);
// } // }
if(this.tocentry){//maybe not needed as well if (this.tocentry) {//maybe not needed as well
this.form = this.tocentry.form as FormGroup; this.form = this.tocentry.form as FormGroup;
} }
} }
@ -75,30 +82,30 @@ export class FormSectionComponent implements OnInit, OnChanges {
const compositeFieldToBeCloned = (this.form.get('compositeFields').get('' + fieldsetIndex) as FormGroup).getRawValue(); const compositeFieldToBeCloned = (this.form.get('compositeFields').get('' + fieldsetIndex) as FormGroup).getRawValue();
const multiplicityItemsArray = (<FormArray>(this.form.get('compositeFields').get('' + fieldsetIndex).get('multiplicityItems'))); const multiplicityItemsArray = (<FormArray>(this.form.get('compositeFields').get('' + fieldsetIndex).get('multiplicityItems')));
const ordinal = multiplicityItemsArray.length? multiplicityItemsArray.controls.reduce((ordinal, currentControl)=>{ const ordinal = multiplicityItemsArray.length ? multiplicityItemsArray.controls.reduce((ordinal, currentControl) => {
const currentOrdinal = currentControl.get('ordinal').value as number; const currentOrdinal = currentControl.get('ordinal').value as number;
if(currentOrdinal>= ordinal){ if (currentOrdinal >= ordinal) {
return currentOrdinal +1; return currentOrdinal + 1;
} }
return ordinal as number; return ordinal as number;
},0) : 0; }, 0) : 0;
const idMappings = [] as {old: string, new: string}[]; const idMappings = [] as { old: string, new: string }[];
const compositeField: DatasetDescriptionCompositeFieldEditorModel = new DatasetDescriptionCompositeFieldEditorModel().cloneForMultiplicity(compositeFieldToBeCloned, ordinal ,idMappings); const compositeField: DatasetDescriptionCompositeFieldEditorModel = new DatasetDescriptionCompositeFieldEditorModel().cloneForMultiplicity(compositeFieldToBeCloned, ordinal, idMappings);
// ** COMPOSITE FIELD IS SHOWN OR HIDDEN FROM ANOTHER ELEMENT // ** COMPOSITE FIELD IS SHOWN OR HIDDEN FROM ANOTHER ELEMENT
const compositeFieldVisibilityDependencies = this.visibilityRulesService.getVisibilityDependency(compositeFieldToBeCloned); const compositeFieldVisibilityDependencies = this.visibilityRulesService.getVisibilityDependency(compositeFieldToBeCloned);
if(compositeFieldVisibilityDependencies && compositeFieldVisibilityDependencies.length){ if (compositeFieldVisibilityDependencies && compositeFieldVisibilityDependencies.length) {
compositeFieldVisibilityDependencies.forEach(x =>{ compositeFieldVisibilityDependencies.forEach(x => {
const visRule: Rule = { const visRule: Rule = {
targetField: compositeField.id, targetField: compositeField.id,
sourceField: x.sourceControlId, sourceField: x.sourceControlId,
requiredValue: x.sourceControlValue, requiredValue: x.sourceControlValue,
type: '' type: ''
} }
this.visibilityRulesService.addNewRule(visRule); this.visibilityRulesService.addNewRule(visRule);
}); });
@ -111,24 +118,24 @@ export class FormSectionComponent implements OnInit, OnChanges {
try{ try {
if(dependency && dependency.length){ if (dependency && dependency.length) {
// * INNER VISIBILITY DEPENDENCIES // * INNER VISIBILITY DEPENDENCIES
// * IF INNER INPUT HIDES ANOTHER INNER INPUT // * IF INNER INPUT HIDES ANOTHER INNER INPUT
const innerDependency = compositeFieldToBeCloned.fields.reduce((innerD, currentElement )=>{ const innerDependency = compositeFieldToBeCloned.fields.reduce((innerD, currentElement) => {
const innerDependecies = dependency.filter(d => d.sourceControlId === currentElement.id); const innerDependecies = dependency.filter(d => d.sourceControlId === currentElement.id);
return[...innerD, ...innerDependecies]; return [...innerD, ...innerDependecies];
},[]) as VisibilityRuleSource[]; }, []) as VisibilityRuleSource[];
if(innerDependency.length){ if (innerDependency.length) {
//Build visibility source //Build visibility source
const updatedRules = innerDependency.map(x => { const updatedRules = innerDependency.map(x => {
const newId = idMappings.find(y=> y.old === x.sourceControlId); const newId = idMappings.find(y => y.old === x.sourceControlId);
return {...x, sourceControlId: newId.new}; return { ...x, sourceControlId: newId.new };
}); });
// const visRule: VisibilityRule = { // const visRule: VisibilityRule = {
// targetControlId: idMappings.find(x => x.old === element.id).new, // targetControlId: idMappings.find(x => x.old === element.id).new,
@ -140,33 +147,33 @@ export class FormSectionComponent implements OnInit, OnChanges {
return { return {
requiredValue: x.sourceControlValue, requiredValue: x.sourceControlValue,
sourceField: x.sourceControlId, sourceField: x.sourceControlId,
targetField: idMappings.find(l=> l.old === element.id).new, targetField: idMappings.find(l => l.old === element.id).new,
type: '' type: ''
} as Rule; } as Rule;
}); });
rules.forEach(rule =>{ rules.forEach(rule => {
this.visibilityRulesService.addNewRule(rule); this.visibilityRulesService.addNewRule(rule);
}) })
// this.visibilityRulesService.appendVisibilityRule(visRule); // this.visibilityRulesService.appendVisibilityRule(visRule);
} }
} }
// * OUTER DEPENDENCIES // * OUTER DEPENDENCIES
// * IF INNER INPUT HIDES OUTER INPUTS // * IF INNER INPUT HIDES OUTER INPUTS
const innerIds = idMappings.map(x => x.old) as string[]; const innerIds = idMappings.map(x => x.old) as string[];
const outerTargets = this.visibilityRulesService.getVisibilityTargets(element.id).filter( x=> !innerIds.includes(x)); const outerTargets = this.visibilityRulesService.getVisibilityTargets(element.id).filter(x => !innerIds.includes(x));
outerTargets.forEach(target =>{ outerTargets.forEach(target => {
const outerRules = (this.visibilityRulesService.getVisibilityDependency(target) as VisibilityRuleSource[]).filter(x => x.sourceControlId === element.id); const outerRules = (this.visibilityRulesService.getVisibilityDependency(target) as VisibilityRuleSource[]).filter(x => x.sourceControlId === element.id);
const updatedRules = outerRules.map(x => { const updatedRules = outerRules.map(x => {
return {...x ,sourceControlId: idMappings.find(y => y.old === element.id).new}; return { ...x, sourceControlId: idMappings.find(y => y.old === element.id).new };
}); });
// const visRule: VisibilityRule = { // const visRule: VisibilityRule = {
@ -175,7 +182,7 @@ export class FormSectionComponent implements OnInit, OnChanges {
// } // }
const rules = updatedRules.map(x =>{ const rules = updatedRules.map(x => {
return { return {
requiredValue: x.sourceControlValue, requiredValue: x.sourceControlValue,
sourceField: x.sourceControlId, sourceField: x.sourceControlId,
@ -184,12 +191,12 @@ export class FormSectionComponent implements OnInit, OnChanges {
} as Rule; } as Rule;
}) })
rules.forEach(rule =>{ rules.forEach(rule => {
this.visibilityRulesService.addNewRule(rule); this.visibilityRulesService.addNewRule(rule);
}) })
// this.visibilityRulesService.appendVisibilityRule(visRule); // this.visibilityRulesService.appendVisibilityRule(visRule);
}); });
@ -198,16 +205,16 @@ export class FormSectionComponent implements OnInit, OnChanges {
// * IF INNER INPUT IS HIDDEN BY OUTER INPUT // * IF INNER INPUT IS HIDDEN BY OUTER INPUT
if(dependency && dependency.length){ if (dependency && dependency.length) {
const fieldsThatHideInnerElement = dependency.filter(x => !innerIds.includes(x.sourceControlId)); const fieldsThatHideInnerElement = dependency.filter(x => !innerIds.includes(x.sourceControlId));
if( fieldsThatHideInnerElement.length){ if (fieldsThatHideInnerElement.length) {
fieldsThatHideInnerElement.forEach(x =>{ fieldsThatHideInnerElement.forEach(x => {
const visRule: Rule = { const visRule: Rule = {
targetField: idMappings.find(l => l.old === element.id).new, targetField: idMappings.find(l => l.old === element.id).new,
sourceField: x.sourceControlId, sourceField: x.sourceControlId,
requiredValue: x.sourceControlValue, requiredValue: x.sourceControlValue,
type: '' type: ''
} }
const shouldBeVisibile = this.visibilityRulesService.checkTargetVisibilityProvidedBySource(x.sourceControlId, element.id); const shouldBeVisibile = this.visibilityRulesService.checkTargetVisibilityProvidedBySource(x.sourceControlId, element.id);
this.visibilityRulesService.addNewRule(visRule, shouldBeVisibile); this.visibilityRulesService.addNewRule(visRule, shouldBeVisibile);
@ -239,10 +246,10 @@ export class FormSectionComponent implements OnInit, OnChanges {
deleteMultipeFieldFromCompositeFormGroup(compositeFildIndex: number, fildIndex: number) { deleteMultipeFieldFromCompositeFormGroup(compositeFildIndex: number, fildIndex: number) {
const multiplicityItemsArray = (<FormArray>(this.form.get('compositeFields').get('' + compositeFildIndex).get('multiplicityItems'))); const multiplicityItemsArray = (<FormArray>(this.form.get('compositeFields').get('' + compositeFildIndex).get('multiplicityItems')));
multiplicityItemsArray.removeAt(fildIndex); multiplicityItemsArray.removeAt(fildIndex);
multiplicityItemsArray.controls.forEach((control, i)=>{ multiplicityItemsArray.controls.forEach((control, i) => {
try{ try {
control.get('ordinal').setValue(i); control.get('ordinal').setValue(i);
}catch{ } catch {
throw 'Could not find ordinal'; throw 'Could not find ordinal';
} }
}); });
@ -258,7 +265,7 @@ export class FormSectionComponent implements OnInit, OnChanges {
onAskedToScroll(id:string){ onAskedToScroll(id: string) {
this.panelExpanded = true; this.panelExpanded = true;
this.askedToScroll.emit(id); this.askedToScroll.emit(id);
} }

View File

@ -2,7 +2,7 @@ import { ApplicationRef, Injectable, NgZone } from '@angular/core';
import { AbstractControl, FormArray, FormGroup } from '@angular/forms'; import { AbstractControl, FormArray, FormGroup } from '@angular/forms';
import { DatasetProfileFieldViewStyle } from '@app/core/common/enum/dataset-profile-field-view-style'; import { DatasetProfileFieldViewStyle } from '@app/core/common/enum/dataset-profile-field-view-style';
import { isNumeric } from '@app/utilities/enhancers/utils'; import { isNumeric } from '@app/utilities/enhancers/utils';
import { Subject } from 'rxjs'; import { Observable, Subject } from 'rxjs';
import { Rule } from '../../../../core/model/dataset-profile-definition/rule'; import { Rule } from '../../../../core/model/dataset-profile-definition/rule';
import { VisibilityRule } from './models/visibility-rule'; import { VisibilityRule } from './models/visibility-rule';
import { VisibilityRuleSource } from './models/visibility-rule-source'; import { VisibilityRuleSource } from './models/visibility-rule-source';
@ -16,7 +16,8 @@ export class VisibilityRulesService {
private visibilityRuleContext: VisibilityRulesContext; private visibilityRuleContext: VisibilityRulesContext;
private form: AbstractControl; private form: AbstractControl;
private elementVisibilityMap = new Map<String, boolean>(); public elementVisibilityMap = new Map<String, boolean>();
private elementVisibilityMapSubject = new Subject<Map<String, boolean>>();
private elementComputationalMap = new Map<String, Map<String, boolean>>(); /// keep saved the values of each form control validity value private elementComputationalMap = new Map<String, Map<String, boolean>>(); /// keep saved the values of each form control validity value
private _changeMade$ = new Subject<void>(); private _changeMade$ = new Subject<void>();
@ -28,6 +29,10 @@ export class VisibilityRulesService {
} }
getElementVisibilityMapObservable(): Observable<Map<String, boolean>> {
return this.elementVisibilityMapSubject.asObservable();
}
public checkElementVisibility(id: string): boolean { public checkElementVisibility(id: string): boolean {
if (this.visibilityRuleContext.rules.filter(item => item.targetControlId === id).length === 0) { return true; } if (this.visibilityRuleContext.rules.filter(item => item.targetControlId === id).length === 0) { return true; }
return this.elementVisibilityMap.has(id) ? this.elementVisibilityMap.get(id) : false; return this.elementVisibilityMap.has(id) ? this.elementVisibilityMap.get(id) : false;
@ -41,8 +46,12 @@ export class VisibilityRulesService {
} }
public updateValueAndVisibility(id: string, value: any) { public updateValueAndVisibility(id: string, value: any) {
console.log('updateValueAndVisibility');
const visibilityRules = this.visibilityRuleContext.rules.filter(item => item.sourceVisibilityRules.filter(source => source.sourceControlId === id).length > 0); const visibilityRules = this.visibilityRuleContext.rules.filter(item => item.sourceVisibilityRules.filter(source => source.sourceControlId === id).length > 0);
visibilityRules.forEach(item => this.evaluateVisibility(item, value, id)); if (visibilityRules.length > 0) {
visibilityRules.forEach(item => this.evaluateVisibility(item, value, id));
this.elementVisibilityMapSubject.next(this.elementVisibilityMap);
}
} }
private evaluateVisibility(visibilityRule: VisibilityRule, value: any, sourceId: string) {// source controlId is the same private evaluateVisibility(visibilityRule: VisibilityRule, value: any, sourceId: string) {// source controlId is the same
@ -72,7 +81,7 @@ export class VisibilityRulesService {
const shouldBeVisible = visibilityDependencySource.reduce((isVisible, x) => { const shouldBeVisible = visibilityDependencySource.reduce((isVisible, x) => {
const shouldBeHidden = value !== null && (this.parseValue(value) !== this.parseValue(x.sourceControlValue)); const shouldBeHidden = value !== null && (this.parseValue(value) !== this.parseValue(x.sourceControlValue));
return this.VISIBILITY_RULE_LOGIC === 'OR'? (isVisible || !shouldBeHidden) : (isVisible && !shouldBeHidden); return this.VISIBILITY_RULE_LOGIC === 'OR' ? (isVisible || !shouldBeHidden) : (isVisible && !shouldBeHidden);
// if(value !== null && ) // if(value !== null && )
}, this.VISIBILITY_RULE_LOGIC === 'AND'); }, this.VISIBILITY_RULE_LOGIC === 'AND');
visibilityMap.set(sourceId, shouldBeVisible); visibilityMap.set(sourceId, shouldBeVisible);
@ -84,8 +93,10 @@ export class VisibilityRulesService {
const isVisible = this._computeVisibility(targetId); const isVisible = this._computeVisibility(targetId);
this._emitChangesIfNeeded(targetId, isVisible); this._emitChangesIfNeeded(targetId, isVisible);
const previousVisibility = this.elementVisibilityMap.get(targetId);
this.elementVisibilityMap.set(targetId, isVisible); this.elementVisibilityMap.set(targetId, isVisible);
if (!isVisible) {
if (!isVisible && previousVisibility !== isVisible) {
this.resetControlWithId(this.form, targetId); this.resetControlWithId(this.form, targetId);
} }
@ -220,11 +231,18 @@ export class VisibilityRulesService {
private resetFieldFormGroup(formGroup: FormGroup) { private resetFieldFormGroup(formGroup: FormGroup) {
const renderStyle = formGroup.getRawValue().viewStyle.renderStyle; const renderStyle = formGroup.getRawValue().viewStyle.renderStyle;
if (renderStyle === DatasetProfileFieldViewStyle.Validation || renderStyle === DatasetProfileFieldViewStyle.DatasetIdentifier) { if (renderStyle === DatasetProfileFieldViewStyle.Validation || renderStyle === DatasetProfileFieldViewStyle.DatasetIdentifier) {
formGroup.get('value').setValue({ identifier: '', type: '' }); const value = { identifier: '', type: '' };
if (formGroup.get('value').value != value) {
formGroup.get('value').setValue(value, { emitEvent: false });
this.updateValueAndVisibility(formGroup.get('id').value, value);
}
} else { } else {
formGroup.get('value').setValue(formGroup.get('defaultValue').value ? this.parseValue(formGroup.get('defaultValue').value.value) : undefined); const value = formGroup.get('defaultValue').value ? this.parseValue(formGroup.get('defaultValue').value.value) : undefined;
if (formGroup.get('value').value != value) {
formGroup.get('value').setValue(value, { emitEvent: false });
this.updateValueAndVisibility(formGroup.get('id').value, value);
}
} }
} }
private resetCompositeFieldFormGroup(formGroup: FormGroup) { private resetCompositeFieldFormGroup(formGroup: FormGroup) {
@ -342,8 +360,8 @@ export class VisibilityRulesService {
let visibilityMap = this.elementComputationalMap.get(targetId); let visibilityMap = this.elementComputationalMap.get(targetId);
if(!visibilityMap){ if (!visibilityMap) {
visibilityMap = new Map<String, boolean>(); visibilityMap = new Map<String, boolean>();
this.elementComputationalMap.set(targetId, visibilityMap); this.elementComputationalMap.set(targetId, visibilityMap);
} }
@ -352,6 +370,7 @@ export class VisibilityRulesService {
this._emitChangesIfNeeded(targetId, isVisible); this._emitChangesIfNeeded(targetId, isVisible);
this.elementVisibilityMap.set(targetId, isVisible); this.elementVisibilityMap.set(targetId, isVisible);
this.elementVisibilityMapSubject.next(this.elementVisibilityMap);
} }
@ -359,10 +378,10 @@ export class VisibilityRulesService {
* Check what sourceId hides or shows the target field * Check what sourceId hides or shows the target field
* return true if no rule found * return true if no rule found
*/ */
public checkTargetVisibilityProvidedBySource(sourceId: string, targetId: string): boolean{ public checkTargetVisibilityProvidedBySource(sourceId: string, targetId: string): boolean {
const computationalMap = this.elementComputationalMap.get(targetId); const computationalMap = this.elementComputationalMap.get(targetId);
if(computationalMap){ if (computationalMap) {
return !!computationalMap.get(sourceId); return !!computationalMap.get(sourceId);
} }

View File

@ -89,12 +89,6 @@
features of Argos in a concise features of Argos in a concise
way. way.
</li> </li>
<li>
<a href="../assets/media-kit/Factsheet.pdf">
Factsheet
<i class="fas fa-external-link-alt ext-link-icon fa-xs"></i>
</a> containing the basics of Argos and explaining its key features in an adequate level of
</li>
<li> <li>
<a href="https://www.openaire.eu/argos/">Useful Resources <a href="https://www.openaire.eu/argos/">Useful Resources
<i class="fas fa-external-link-alt ext-link-icon fa-xs"></i> <i class="fas fa-external-link-alt ext-link-icon fa-xs"></i>

View File

@ -70,31 +70,58 @@
<section class="page-section user-guide" id="user-guide"> <section class="page-section user-guide" id="user-guide">
<div class="container"> <div class="container">
<div class="col"> <div class="col">
<div class="page-title">Resources</div> <div class="page-title">User Guide</div>
</div> </div>
<div class="col pt-5 pb-3"> <div class="row pt-5 pb-3">
<div class="title-3">User Guide</div> <div class="col">
<div class="title-3 text-center">User</div>
</div>
<div class="col">
<div class="title-3 text-center">Admin</div>
</div>
</div> </div>
<div class="col"> <div class="row d-flex justify-content-center">
<p> <p class="text-center">
Become proficient in using Argos by following the User Guide. Check presentation for additional Become proficient in using Argos by following the User Guide. <br/> Check presentation for additional
hints and leave your thoughts for improvements in the feedback form. hints and leave your thoughts for improvements in the feedback form.
</p> </p>
<ul class="list mb-5">
<li><a href="/user-guide">User Guide</a></li>
<li><a href="../assets/presentations/argos.pdf">
Presentations
<i class="fas fa-external-link-alt ext-link-icon fa-xs"></i>
</a></li>
<li><a href="https://docs.google.com/forms/d/12RSCrUjdSDp2LZLpjDKOi44cN1fLDD2q1-F66SqZIis/viewform?edit_requested=true">
Feedback Form
<i class="fas fa-external-link-alt ext-link-icon fa-xs"></i>
</a></li>
</ul>
</div> </div>
<div class="col d-flex justify-content-center mb-5 pb-5"> <div class="row mb-5 pb-5">
<a href="/user-guide"><button class="normal-btn">View User Guide Online</button></a> <div class="col d-flex justify-content-center">
<ul class="list mb-5">
<li><a href="/user-guide">User Guide</a></li>
<li>
<a href="../assets/media-kit/Factsheet.pdf">
Factsheet
<i class="fas fa-external-link-alt ext-link-icon fa-xs"></i>
</a>
</li>
<li><a href="../assets/presentations/argos.pdf">
Presentations
<i class="fas fa-external-link-alt ext-link-icon fa-xs"></i>
</a></li>
<li><a href="https://docs.google.com/forms/d/12RSCrUjdSDp2LZLpjDKOi44cN1fLDD2q1-F66SqZIis/viewform?edit_requested=true">
Feedback Form
<i class="fas fa-external-link-alt ext-link-icon fa-xs"></i>
</a></li>
</ul>
</div>
<div class="col d-flex justify-content-center">
<ul class="list mb-5">
<li><a href="../assets/media-kit/Argos-Admin-Handbook_14_01_2022.pdf">
Handbook
<i class="fas fa-external-link-alt ext-link-icon fa-xs"></i>
</a></li>
<li><a href="../assets/media-kit/OpenAIRE_ARGOS_Administrators.pdf">
Factsheet
<i class="fas fa-external-link-alt ext-link-icon fa-xs"></i>
</a></li>
</ul>
</div>
</div> </div>
<!-- <div class="col d-flex justify-content-center mb-5 pb-5">-->
<!-- <a href="/user-guide"><button class="normal-btn">View User Guide Online</button></a>-->
<!-- </div>-->
</div> </div>
</section> </section>
<!-- Footer--> <!-- Footer-->