49 lines
1.2 KiB
Java
49 lines
1.2 KiB
Java
package eu.eudat.models.rda.mapper;
|
|
|
|
import com.fasterxml.jackson.databind.JsonNode;
|
|
import eu.eudat.models.rda.License;
|
|
|
|
import java.net.URI;
|
|
import java.util.HashMap;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
|
|
public class LicenseRDAMapper {
|
|
|
|
public static License toRDA(JsonNode node) {
|
|
License rda = new License();
|
|
String rdaProperty = node.get("rdaProperty").asText();
|
|
String value = node.get("value").asText();
|
|
|
|
if (rdaProperty.contains("license_ref")) {
|
|
rda.setLicenseRef(URI.create(value));
|
|
rda.setAdditionalProperty("license_refId", node.get("id").asText());
|
|
} else if (rdaProperty.contains("start_date")) {
|
|
rda.setStartDate(value);
|
|
rda.setAdditionalProperty("start_dateId", node.get("id").asText());
|
|
}
|
|
|
|
return rda;
|
|
}
|
|
|
|
public static Map<String, String> toProperties(List<License> rdas) {
|
|
Map<String, String> properties = new HashMap<>();
|
|
|
|
rdas.forEach(rda -> {
|
|
rda.getAdditionalProperties().entrySet().forEach(entry -> {
|
|
switch (entry.getKey()) {
|
|
case "license_refId":
|
|
properties.put(entry.getValue().toString(), rda.getLicenseRef().toString());
|
|
break;
|
|
case "start_dateId":
|
|
properties.put(entry.getValue().toString(), rda.getStartDate());
|
|
break;
|
|
}
|
|
|
|
});
|
|
});
|
|
|
|
return properties;
|
|
}
|
|
}
|