2019-08-02 10:27:12 +02:00
|
|
|
package eu.eudat.models.data.external;
|
|
|
|
|
2019-10-03 13:06:44 +02:00
|
|
|
import com.fasterxml.jackson.databind.JsonNode;
|
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
|
|
|
|
|
import java.io.IOException;
|
2019-08-02 10:27:12 +02:00
|
|
|
import java.util.List;
|
|
|
|
import java.util.Map;
|
|
|
|
|
2019-10-03 13:06:44 +02:00
|
|
|
public class ProjectsExternalSourcesModel extends ExternalListingItem<ProjectsExternalSourcesModel> {
|
|
|
|
private static final ObjectMapper mapper = new ObjectMapper();
|
|
|
|
|
2019-08-02 10:27:12 +02:00
|
|
|
@Override
|
|
|
|
public ProjectsExternalSourcesModel fromExternalItem(List<Map<String, String>> values) {
|
|
|
|
for (Map<String, String> item : values) {
|
|
|
|
ExternalSourcesItemModel model = new ExternalSourcesItemModel();
|
2019-10-03 13:06:44 +02:00
|
|
|
try {
|
|
|
|
JsonNode node = mapper.readTree(mapper.writeValueAsBytes(item));
|
|
|
|
JsonNode name = node.get("name");
|
|
|
|
if (name != null && !name.isNull() && name.isObject()) {
|
|
|
|
model.setName(node.get("name").get("$").asText());
|
|
|
|
} else {
|
|
|
|
model.setName(item.get("name"));
|
|
|
|
}
|
|
|
|
|
|
|
|
JsonNode pid = node.get("pid");
|
|
|
|
if (pid != null && !pid.isNull() && pid.isObject()) {
|
|
|
|
model.setRemoteId(node.get("pid").get("$").asText());
|
|
|
|
} else {
|
|
|
|
model.setRemoteId(item.get("pid"));
|
|
|
|
}
|
|
|
|
|
|
|
|
JsonNode uri = node.get("uri");
|
|
|
|
if (uri != null && !uri.isNull() && uri.isObject()) {
|
|
|
|
model.setUri(node.get("uri").get("$").asText());
|
|
|
|
} else {
|
|
|
|
model.setUri(item.get("uri"));
|
|
|
|
}
|
|
|
|
|
|
|
|
JsonNode description = node.get("description");
|
|
|
|
if (description != null && !description.isNull() && description.isObject()) {
|
|
|
|
model.setDescription(node.get("description").get("$").asText());
|
|
|
|
} else {
|
|
|
|
model.setDescription(item.get("description"));
|
|
|
|
}
|
|
|
|
|
|
|
|
JsonNode tag = node.get("tag");
|
|
|
|
if (tag != null && !tag.isNull() && tag.isObject()) {
|
|
|
|
model.setTag(node.get("tag").get("$").asText());
|
|
|
|
} else {
|
|
|
|
model.setTag(item.get("tag"));
|
|
|
|
}
|
|
|
|
|
|
|
|
this.add(model);
|
|
|
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
2019-08-02 10:27:12 +02:00
|
|
|
}
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
}
|