Add extra prefilling mapping fields and add better support for prefilling tags

This commit is contained in:
George Kalampokis 2022-01-19 17:51:30 +02:00
parent ce386ac047
commit 8f56b1874b
2 changed files with 19 additions and 3 deletions

View File

@ -344,7 +344,16 @@ public class DatasetWizardModel implements DataModel<Dataset, DatasetWizardModel
Method setterMethod = Arrays.stream(DatasetWizardModel.class.getDeclaredMethods())
.filter(method -> method.getName().equals(methodName)).collect(Collectors.toList()).get(0);
Class<?>[] params = setterMethod.getParameterTypes();
setterMethod.invoke(datasetWizardModel, new ObjectMapper().readValue(value, params[0]));
ObjectMapper mapper = new ObjectMapper();
//GK: Tags Special logic
if (prefillingMapping.getTarget().equals("tags")) {
List<Object> rawTags = (List<Object>) mapper.readValue(value, params[0]);
if (rawTags.get(0) instanceof String) {
List<Tag> parsedTags = rawTags.stream().map(rawTag -> new Tag((String) rawTag, (String) rawTag)).collect(Collectors.toList());
value = mapper.writeValueAsString(parsedTags);
}
}
setterMethod.invoke(datasetWizardModel, mapper.readValue(value, params[0]));
}catch (InvocationTargetException | IllegalAccessException | JsonProcessingException e) {
throw e;
}

View File

@ -1033,10 +1033,17 @@
<mapping source="metadata.title" target="label" />
<mapping source="metadata.description" target="description" />
<mapping source="metadata.license.id" maDmpTarget="dataset.distribution.license.license_ref" />
<mapping source="metadata.keywords" target="tags"/>
<mapping source="metadata.filesize" maDmpTarget="dataset.distribution.byte_size"/>
<mapping source="metadata.language" maDmpTarget="dataset.metadata.language"/>
<mapping source="metadata.dates.valid" maDmpTarget="dataset.distribution.available_until"/>
<mapping source="metadata.access_right" maDmpTarget="dataset.distribution.data_access"/>
<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"/>
</mappings>
<fixedMappings>
<fixedMapping target="tags" value="[{&quot;id&quot;: &quot;test&quot;, &quot;name&quot;: &quot;test&quot;}]"/>
<fixedMapping maDmpTarget="dataset.distribution.host.title" value="zenodo" />
<fixedMapping maDmpTarget="dataset.distribution.host.title" value="Zenodo" />
</fixedMappings>
</prefillingGet>
</config>