Adds fist part of "Distribution" on RDA export model.

This commit is contained in:
gkolokythas 2020-01-14 14:18:14 +02:00
parent 2958cab113
commit df07884cbe
2 changed files with 37 additions and 36 deletions

View File

@ -1,11 +1,13 @@
package eu.eudat.models.data.rda;
import com.fasterxml.jackson.annotation.JsonIgnore;
import java.util.List;
public class DatasetDistributionRDAExportModel {
private String access_url;
private String available_till;
private int byte_size;
private String byte_size;
private String data_access; // Allowed values: open / shared / closed
private String description;
private String download_url;
@ -28,10 +30,10 @@ public class DatasetDistributionRDAExportModel {
this.available_till = available_till;
}
public int getByte_size() {
public String getByte_size() {
return byte_size;
}
public void setByte_size(int byte_size) {
public void setByte_size(String byte_size) {
this.byte_size = byte_size;
}
@ -84,38 +86,8 @@ public class DatasetDistributionRDAExportModel {
this.title = title;
}
public DatasetDistributionRDAExportModel fromDataModel(String key, Object value) {
DatasetDistributionRDAExportModel distributionModel = new DatasetDistributionRDAExportModel();
switch (key) {
case "access_url":
distributionModel.setAccess_url(value.toString());
break;
case "available_till":
distributionModel.setAvailable_till(value.toString());
break;
case "byte_size":
try { distributionModel.setByte_size(Integer.parseInt(value.toString())); }
catch (NumberFormatException e) { e.printStackTrace(); }
break;
case "data_access":
distributionModel.setData_access(value.toString());
break;
case "description":
distributionModel.setDescription(value.toString());
break;
case "download_url":
distributionModel.setDownload_url(value.toString());
break;
case "format":
break;
case "host":
break;
case "license":
break;
case "title":
distributionModel.setTitle(value.toString());
break;
}
return distributionModel;
@JsonIgnore
public boolean isValid() {
return title != null || data_access != null;
}
}

View File

@ -194,6 +194,9 @@ public class DatasetRDAExportModel {
/*--------- Building data_quality_assurance. ---------*/
datasetRDAExportModel.setData_quality_assurance(buildDataQualityAssurance(datasetDescriptionJson, templateIdsToValues, dataset.getProfile().getDefinition()));
/*--------- Building distribution. ---------*/
datasetRDAExportModel.setDistribution(buildDistribution(datasetDescriptionJson, templateIdsToValues, dataset.getProfile().getDefinition()));
/*--------- Building keywords. ---------*/
datasetRDAExportModel.setKeyword(buildKeywords(datasetDescriptionJson, templateIdsToValues, dataset.getProfile().getDefinition()));
@ -232,6 +235,32 @@ public class DatasetRDAExportModel {
return dataQualityAssuranceList;
}
private List<DatasetDistributionRDAExportModel> buildDistribution(JSONObject datasetDescriptionJson, Map<String, Object> templateIdsToValues, String datasetProfileDefinition) {
DatasetDistributionRDAExportModel distributionModel = new DatasetDistributionRDAExportModel();
distributionModel.setAccess_url(buildSingleProperties("dataset.distribution.access_url", datasetDescriptionJson, templateIdsToValues));
distributionModel.setAvailable_till(buildSingleProperties("dataset.distribution.available_till", datasetDescriptionJson, templateIdsToValues));
distributionModel.setByte_size(buildSingleProperties("dataset.distribution.byte_size", datasetDescriptionJson, templateIdsToValues));
distributionModel.setData_access(buildSingleProperties("dataset.distribution.data_access", datasetDescriptionJson, templateIdsToValues));
distributionModel.setDescription(buildSingleProperties("dataset.distribution.description", datasetDescriptionJson, templateIdsToValues));
distributionModel.setDownload_url(buildSingleProperties("dataset.distribution.download_url", datasetDescriptionJson, templateIdsToValues));
distributionModel.setTitle(buildSingleProperties("dataset.distribution.title", datasetDescriptionJson, templateIdsToValues));
/*--------- Building format. ---------*/
// We currently support the return of only one distribution.
List<DatasetDistributionRDAExportModel> distributionList = new LinkedList<>();
if (distributionModel.isValid()) {
distributionList.add(distributionModel);
} else {
DatasetDistributionRDAExportModel model = new DatasetDistributionRDAExportModel();
model.setDescription("Distribution data was not valid");
distributionList.add(model);
}
return distributionList;
}
private List<String> buildKeywords(JSONObject datasetDescriptionJson, Map<String, Object> templateIdsToValues, String datasetProfileDefinition) {
List<RdaField> keywordFields = getRDAFieldsFromJson(datasetDescriptionJson, new String[]{"dataset.keyword"}, datasetProfileDefinition);
for (RdaField rdaField : keywordFields) {