bug fix: license api-fields didnt get prefilled
This commit is contained in:
parent
b891907724
commit
cfd0707f2a
|
@ -28,13 +28,15 @@ public class PrefillingManager {
|
|||
private final ConfigLoader configLoader;
|
||||
private final ObjectMapper objectMapper;
|
||||
private final DatasetManager datasetManager;
|
||||
private final LicenseManager licenseManager;
|
||||
|
||||
@Autowired
|
||||
public PrefillingManager(ApiContext apiContext, ConfigLoader configLoader, DatasetManager datasetManager) {
|
||||
public PrefillingManager(ApiContext apiContext, ConfigLoader configLoader, DatasetManager datasetManager, LicenseManager licenseManager) {
|
||||
this.apiContext = apiContext;
|
||||
this.configLoader = configLoader;
|
||||
this.objectMapper = new ObjectMapper();
|
||||
this.datasetManager = datasetManager;
|
||||
this.licenseManager = licenseManager;
|
||||
}
|
||||
|
||||
public List<Prefilling> getPrefillings(String like, String configId) {
|
||||
|
@ -50,7 +52,7 @@ public class PrefillingManager {
|
|||
PrefillingGet prefillingGet = prefillingConfig.getPrefillingGet();
|
||||
Map<String, Object> prefillingEntity = getSingle(prefillingGet.getUrl(), prefillId);
|
||||
DatasetProfile datasetProfile = apiContext.getOperationsContext().getDatabaseRepository().getDatasetProfileDao().find(profileId);
|
||||
return PrefillingMapper.mapPrefilledEntityToDatasetWizard(prefillingEntity, prefillingGet, prefillingConfig.getType(), datasetProfile, datasetManager);
|
||||
return PrefillingMapper.mapPrefilledEntityToDatasetWizard(prefillingEntity, prefillingGet, prefillingConfig.getType(), datasetProfile, datasetManager, licenseManager);
|
||||
}
|
||||
|
||||
private Map<String, Object> getSingle(String url, String id) {
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -1214,9 +1214,6 @@ but not
|
|||
<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>
|
||||
</prefillingGet>
|
||||
</config>
|
||||
|
|
Loading…
Reference in New Issue