2016-12-01 19:19:22 +01:00
|
|
|
package org.gcube.data_catalogue.grsf_publish_ws.json.input;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
2017-07-31 18:29:48 +02:00
|
|
|
import java.util.Arrays;
|
2016-12-01 19:19:22 +01:00
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
import javax.validation.constraints.NotNull;
|
|
|
|
import javax.validation.constraints.Size;
|
|
|
|
|
|
|
|
import org.gcube.data_catalogue.grsf_publish_ws.custom_annotations.CustomField;
|
|
|
|
import org.gcube.data_catalogue.grsf_publish_ws.utils.HelperMethods;
|
2017-03-08 17:09:34 +01:00
|
|
|
import org.gcube.datacatalogue.ckanutillibrary.shared.ResourceBean;
|
2016-12-01 19:19:22 +01:00
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
|
|
import com.fasterxml.jackson.annotation.JsonAnySetter;
|
|
|
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The base class contains basic information needed to publish something in the data catalogue.
|
|
|
|
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
|
|
|
|
*/
|
|
|
|
public class Base {
|
|
|
|
|
2017-07-31 18:29:48 +02:00
|
|
|
private static final List<String> FIELDS_TO_IGNORE = Arrays.asList("author", "author_contact", "stock_uri", "fishery_uri", "reference_year", "reporting_year", "water_area",
|
|
|
|
"environment", "state_of_marine_resource");
|
|
|
|
|
2016-12-01 19:19:22 +01:00
|
|
|
private static Logger logger = LoggerFactory.getLogger(Base.class);
|
2017-07-27 16:45:18 +02:00
|
|
|
public static final String UUID_KB_KEY = "GRSF UUID";
|
2016-12-01 19:19:22 +01:00
|
|
|
|
2017-07-12 18:05:35 +02:00
|
|
|
@JsonProperty("catalog_id") //used on patch/update product call
|
|
|
|
private String catalogId;
|
|
|
|
|
2016-12-01 19:19:22 +01:00
|
|
|
@JsonProperty("description")
|
|
|
|
private String description;
|
|
|
|
|
|
|
|
@JsonProperty("license_id")
|
|
|
|
private String license;
|
|
|
|
|
|
|
|
// filled automatically by the service
|
|
|
|
@JsonProperty("author")
|
|
|
|
private String author;
|
2017-07-10 16:41:24 +02:00
|
|
|
|
2016-12-01 19:19:22 +01:00
|
|
|
// filled automatically by the service
|
|
|
|
@JsonProperty("author_contact")
|
|
|
|
private String authorContact;
|
|
|
|
|
2016-12-03 11:50:38 +01:00
|
|
|
@JsonProperty("version")
|
|
|
|
private Long version;
|
|
|
|
|
2016-12-01 19:19:22 +01:00
|
|
|
@JsonProperty("maintainer")
|
|
|
|
private String maintainer;
|
|
|
|
|
|
|
|
@JsonProperty("maintainer_contact")
|
|
|
|
private String maintainerContact;
|
|
|
|
|
|
|
|
@JsonProperty("extras_fields")
|
|
|
|
private Map<String, List<String>> extrasFields = new HashMap<>();
|
|
|
|
|
|
|
|
@JsonProperty("extras_resources")
|
|
|
|
private List<ResourceBean> extrasResources = new ArrayList<ResourceBean>();
|
|
|
|
|
2017-08-01 10:26:33 +02:00
|
|
|
@JsonProperty("grsf_uuid")
|
2017-06-07 11:04:44 +02:00
|
|
|
@CustomField(key=UUID_KB_KEY)
|
2017-08-01 10:26:33 +02:00
|
|
|
@NotNull(message="grsf_uuid cannot be null")
|
|
|
|
@Size(min=1, message="grsf_uuid cannot be empty")
|
2016-12-01 19:19:22 +01:00
|
|
|
private String uuid;
|
|
|
|
|
|
|
|
public Base() {
|
|
|
|
super();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-07-12 18:05:35 +02:00
|
|
|
* @param id
|
2016-12-01 19:19:22 +01:00
|
|
|
* @param description
|
|
|
|
* @param license
|
|
|
|
* @param author
|
|
|
|
* @param authorContact
|
2017-07-12 18:05:35 +02:00
|
|
|
* @param version
|
2016-12-01 19:19:22 +01:00
|
|
|
* @param maintainer
|
|
|
|
* @param maintainerContact
|
|
|
|
* @param extrasFields
|
|
|
|
* @param extrasResources
|
|
|
|
* @param uuid
|
|
|
|
*/
|
2017-07-12 18:05:35 +02:00
|
|
|
public Base(String id, String description, String license, String author,
|
|
|
|
String authorContact, Long version, String maintainer,
|
2016-12-01 19:19:22 +01:00
|
|
|
String maintainerContact, Map<String, List<String>> extrasFields,
|
|
|
|
List<ResourceBean> extrasResources, String uuid) {
|
|
|
|
super();
|
2017-07-12 18:05:35 +02:00
|
|
|
this.catalogId = id;
|
2016-12-01 19:19:22 +01:00
|
|
|
this.description = description;
|
|
|
|
this.license = license;
|
|
|
|
this.author = author;
|
|
|
|
this.authorContact = authorContact;
|
2017-07-12 18:05:35 +02:00
|
|
|
this.version = version;
|
2016-12-01 19:19:22 +01:00
|
|
|
this.maintainer = maintainer;
|
|
|
|
this.maintainerContact = maintainerContact;
|
|
|
|
this.extrasFields = extrasFields;
|
|
|
|
this.extrasResources = extrasResources;
|
|
|
|
this.uuid = uuid;
|
|
|
|
}
|
|
|
|
|
2017-07-12 18:05:35 +02:00
|
|
|
public String getCatalogId() {
|
|
|
|
return catalogId;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setCatalogId(String catalogId) {
|
|
|
|
this.catalogId = catalogId;
|
|
|
|
}
|
|
|
|
|
2016-12-01 19:19:22 +01:00
|
|
|
public String getDescription() {
|
|
|
|
return description;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setDescription(String description) {
|
|
|
|
this.description = description;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getLicense() {
|
|
|
|
return license;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setLicense(String license) {
|
|
|
|
this.license = license;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getAuthor() {
|
|
|
|
return author;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setAuthor(String author) {
|
|
|
|
this.author = author;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Long getVersion() {
|
|
|
|
return version;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setVersion(Long version) {
|
|
|
|
this.version = version;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getAuthorContact() {
|
|
|
|
return authorContact;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setAuthorContact(String authorContact) {
|
|
|
|
this.authorContact = authorContact;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getMaintainer() {
|
|
|
|
return maintainer;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setMaintainer(String maintainer) {
|
|
|
|
this.maintainer = maintainer;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getMaintainerContact() {
|
|
|
|
return maintainerContact;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setMaintainerContact(String maintainerContact) {
|
|
|
|
this.maintainerContact = maintainerContact;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Map<String, List<String>> getExtrasFields() {
|
|
|
|
return extrasFields;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setExtrasFields(Map<String, List<String>> extrasFields) {
|
|
|
|
this.extrasFields = extrasFields;
|
|
|
|
}
|
|
|
|
|
|
|
|
public List<ResourceBean> getExtrasResources() {
|
|
|
|
return extrasResources;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setExtrasResources(List<ResourceBean> extrasResources) {
|
|
|
|
this.extrasResources = extrasResources;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getUuid() {
|
|
|
|
return uuid;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setUuid(String uuid) {
|
|
|
|
this.uuid = uuid;
|
|
|
|
}
|
2017-07-10 16:41:24 +02:00
|
|
|
|
2016-12-01 19:19:22 +01:00
|
|
|
/**
|
|
|
|
* Use for generics object (unrecognized from Jackson) to be put into the map
|
|
|
|
* @param key
|
|
|
|
* @param value
|
|
|
|
*/
|
|
|
|
@JsonAnySetter
|
|
|
|
private void genericSetter(String key, Object value){
|
|
|
|
|
|
|
|
logger.info("Found extra property: [" + key + "," + value + "]");
|
2017-07-31 18:29:48 +02:00
|
|
|
|
|
|
|
if(FIELDS_TO_IGNORE.contains(key)){
|
|
|
|
logger.debug("Ignoring it");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-12-01 19:19:22 +01:00
|
|
|
List<String> values = new ArrayList<String>();
|
|
|
|
if(extrasFields.containsKey(key))
|
|
|
|
values = extrasFields.get(key);
|
|
|
|
else
|
|
|
|
values = new ArrayList<String>();
|
|
|
|
|
|
|
|
values.add(HelperMethods.removeHTML(value.toString()));
|
|
|
|
extrasFields.put(key, values);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String toString() {
|
2017-07-12 18:05:35 +02:00
|
|
|
return "Base [catalogId=" + catalogId + ", description=" + description + ", license="
|
|
|
|
+ license + ", author=" + author + ", authorContact="
|
|
|
|
+ authorContact + ", version=" + version + ", maintainer="
|
2016-12-01 19:19:22 +01:00
|
|
|
+ maintainer + ", maintainerContact=" + maintainerContact
|
|
|
|
+ ", extrasFields=" + extrasFields + ", extrasResources="
|
|
|
|
+ extrasResources + ", uuid=" + uuid + "]";
|
|
|
|
}
|
|
|
|
|
2017-07-12 18:05:35 +02:00
|
|
|
}
|