|
|
|
@ -9,10 +9,13 @@ import eu.eudat.data.entities.DatasetProfile;
|
|
|
|
|
import eu.eudat.elastic.entities.Tag;
|
|
|
|
|
import eu.eudat.logic.managers.DatasetManager;
|
|
|
|
|
import eu.eudat.logic.managers.DatasetProfileManager;
|
|
|
|
|
import eu.eudat.logic.managers.LicenseManager;
|
|
|
|
|
import eu.eudat.logic.proxy.config.entities.DefaultPrefillingMapping;
|
|
|
|
|
import eu.eudat.logic.proxy.config.entities.PrefillingFixedMapping;
|
|
|
|
|
import eu.eudat.logic.proxy.config.entities.PrefillingGet;
|
|
|
|
|
import eu.eudat.logic.proxy.config.entities.PrefillingMapping;
|
|
|
|
|
import eu.eudat.logic.proxy.config.exceptions.HugeResultSet;
|
|
|
|
|
import eu.eudat.logic.proxy.config.exceptions.NoURLFound;
|
|
|
|
|
import eu.eudat.logic.utilities.helpers.StreamDistinctBy;
|
|
|
|
|
import eu.eudat.logic.utilities.json.JsonSearcher;
|
|
|
|
|
import eu.eudat.models.data.components.commons.datafield.AutoCompleteData;
|
|
|
|
@ -20,6 +23,7 @@ import eu.eudat.models.data.datasetprofile.DatasetProfileOverviewModel;
|
|
|
|
|
import eu.eudat.models.data.datasetprofile.RenderStyle;
|
|
|
|
|
import eu.eudat.models.data.datasetwizard.DatasetWizardModel;
|
|
|
|
|
import eu.eudat.models.data.externaldataset.ExternalAutocompleteFieldModel;
|
|
|
|
|
import eu.eudat.models.data.license.LicenseModel;
|
|
|
|
|
import org.json.JSONObject;
|
|
|
|
|
|
|
|
|
|
import java.lang.reflect.InvocationTargetException;
|
|
|
|
@ -33,7 +37,7 @@ public class PrefillingMapper {
|
|
|
|
|
private static final ObjectMapper mapper = new ObjectMapper().configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true);
|
|
|
|
|
|
|
|
|
|
public static DatasetWizardModel mapPrefilledEntityToDatasetWizard(Map<String, Object> prefilledEntity, PrefillingGet prefillingGet, String type,
|
|
|
|
|
DatasetProfile profile, DatasetManager datasetManager) throws Exception {
|
|
|
|
|
DatasetProfile profile, DatasetManager datasetManager, LicenseManager licenseManager) throws Exception {
|
|
|
|
|
DatasetWizardModel datasetWizardModel = new DatasetWizardModel();
|
|
|
|
|
datasetWizardModel.setProfile(new DatasetProfileOverviewModel().fromDataModel(profile));
|
|
|
|
|
Dataset dataset = new Dataset();
|
|
|
|
@ -50,17 +54,17 @@ public class PrefillingMapper {
|
|
|
|
|
sourceValue = ((Map)sourceValue).get(sourceKey);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
setValue(prefillingMapping, mapper.writeValueAsString(sourceValue), datasetWizardModel, parentNode, properties, type);
|
|
|
|
|
setValue(prefillingMapping, mapper.writeValueAsString(sourceValue), datasetWizardModel, parentNode, properties, type, licenseManager);
|
|
|
|
|
}
|
|
|
|
|
for (PrefillingFixedMapping fixedMapping: prefillingGet.getFixedMappings()) {
|
|
|
|
|
setValue(fixedMapping, fixedMapping.getValue(), datasetWizardModel, parentNode, properties, type);
|
|
|
|
|
setValue(fixedMapping, fixedMapping.getValue(), datasetWizardModel, parentNode, properties, type, licenseManager);
|
|
|
|
|
}
|
|
|
|
|
dataset.setProperties(mapper.writeValueAsString(properties));
|
|
|
|
|
datasetWizardModel.setDatasetProfileDefinition(datasetManager.getPagedProfile(datasetWizardModel, dataset));
|
|
|
|
|
return datasetWizardModel;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void setValue(PrefillingMapping prefillingMapping, String value, DatasetWizardModel datasetWizardModel, JsonNode parentNode, Map<String, Object> properties, String type) throws InvocationTargetException, IllegalAccessException, JsonProcessingException {
|
|
|
|
|
private static void setValue(PrefillingMapping prefillingMapping, String value, DatasetWizardModel datasetWizardModel, JsonNode parentNode, Map<String, Object> properties, String type, LicenseManager licenseManager) throws InvocationTargetException, IllegalAccessException, JsonProcessingException {
|
|
|
|
|
String trimRegex = prefillingMapping.getTrimRegex() != null ? prefillingMapping.getTrimRegex() : "";
|
|
|
|
|
if (!value.startsWith("\"") && !value.startsWith("[") && !value.equals("null")) {
|
|
|
|
|
value = "\"" + value + "\"";
|
|
|
|
@ -158,6 +162,17 @@ public class PrefillingMapper {
|
|
|
|
|
}
|
|
|
|
|
properties.put(id, datasetID.toString());
|
|
|
|
|
break;
|
|
|
|
|
case LICENSES:
|
|
|
|
|
try {
|
|
|
|
|
List<LicenseModel> licenses = licenseManager.getLicenses("", "");
|
|
|
|
|
String finalParsedValue = parsedValue;
|
|
|
|
|
licenses = licenses.stream().filter(license -> license.getPid().equals(finalParsedValue)).collect(Collectors.toList());
|
|
|
|
|
properties.put(id, licenses);
|
|
|
|
|
}
|
|
|
|
|
catch (NoURLFound | HugeResultSet e){
|
|
|
|
|
properties.put(id, parsedValue);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
if (!parsedValues.isEmpty())
|
|
|
|
|
properties.put(id, String.join(", ", parsedValues));
|
|
|
|
|