minor model fix and other improvements

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/data-catalogue/grsf-publisher-ws@154873 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Costantino Perciante 2017-10-04 15:30:07 +00:00
parent 1393967788
commit 3252991797
13 changed files with 131 additions and 88 deletions

View File

@ -22,7 +22,7 @@ public class ApplicationException implements ExceptionMapper<Exception> {
return Response return Response
.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()) .status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode())
.type(MediaType.APPLICATION_JSON) .type(MediaType.APPLICATION_JSON)
.entity(new ResponseBean(false, e.getMessage(), null)) .entity(new ResponseBean(false, e.toString(), null))
.build(); .build();
} }
} }

View File

@ -6,10 +6,6 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; 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; import org.gcube.data_catalogue.grsf_publish_ws.utils.HelperMethods;
import org.gcube.datacatalogue.ckanutillibrary.shared.ResourceBean; import org.gcube.datacatalogue.ckanutillibrary.shared.ResourceBean;
import org.slf4j.Logger; import org.slf4j.Logger;
@ -24,11 +20,12 @@ import com.fasterxml.jackson.annotation.JsonProperty;
*/ */
public class Base { public class Base {
private static final List<String> FIELDS_TO_IGNORE = Arrays.asList("author", "author_contact", "stock_uri", "fishery_uri", "reference_year", "reporting_year", "water_area", private static final List<String> FIELDS_TO_IGNORE = Arrays.asList(
"environment", "state_of_marine_resource"); "author", "author_contact", "stock_uri",
"fishery_uri", "reference_year", "reporting_year", "water_area",
"environment", "state_of_marine_resource", "system:type");
private static Logger logger = LoggerFactory.getLogger(Base.class); private static Logger logger = LoggerFactory.getLogger(Base.class);
public static final String UUID_KB_KEY = "GRSF UUID";
@JsonProperty("catalog_id") //used on patch/update product call @JsonProperty("catalog_id") //used on patch/update product call
private String catalogId; private String catalogId;
@ -62,18 +59,12 @@ public class Base {
@JsonProperty("extras_resources") @JsonProperty("extras_resources")
private List<ResourceBean> extrasResources = new ArrayList<ResourceBean>(); private List<ResourceBean> extrasResources = new ArrayList<ResourceBean>();
@JsonProperty("grsf_uuid")
@CustomField(key=UUID_KB_KEY)
@NotNull(message="grsf_uuid cannot be null")
@Size(min=1, message="grsf_uuid cannot be empty")
private String uuid;
public Base() { public Base() {
super(); super();
} }
/** /**
* @param id * @param catalogId
* @param description * @param description
* @param license * @param license
* @param author * @param author
@ -83,14 +74,14 @@ public class Base {
* @param maintainerContact * @param maintainerContact
* @param extrasFields * @param extrasFields
* @param extrasResources * @param extrasResources
* @param uuid
*/ */
public Base(String id, String description, String license, String author, public Base(String catalogId, String description, String license,
String authorContact, Long version, String maintainer, String author, String authorContact, Long version,
String maintainerContact, Map<String, List<String>> extrasFields, String maintainer, String maintainerContact,
List<ResourceBean> extrasResources, String uuid) { Map<String, List<String>> extrasFields,
List<ResourceBean> extrasResources) {
super(); super();
this.catalogId = id; this.catalogId = catalogId;
this.description = description; this.description = description;
this.license = license; this.license = license;
this.author = author; this.author = author;
@ -100,7 +91,6 @@ public class Base {
this.maintainerContact = maintainerContact; this.maintainerContact = maintainerContact;
this.extrasFields = extrasFields; this.extrasFields = extrasFields;
this.extrasResources = extrasResources; this.extrasResources = extrasResources;
this.uuid = uuid;
} }
public String getCatalogId() { public String getCatalogId() {
@ -183,14 +173,6 @@ public class Base {
this.extrasResources = extrasResources; this.extrasResources = extrasResources;
} }
public String getUuid() {
return uuid;
}
public void setUuid(String uuid) {
this.uuid = uuid;
}
/** /**
* Use for generics object (unrecognized from Jackson) to be put into the map * Use for generics object (unrecognized from Jackson) to be put into the map
* @param key * @param key
@ -218,12 +200,12 @@ public class Base {
@Override @Override
public String toString() { public String toString() {
return "Base [catalogId=" + catalogId + ", description=" + description + ", license=" return "Base [catalogId=" + catalogId + ", description=" + description
+ license + ", author=" + author + ", authorContact=" + ", license=" + license + ", author=" + author
+ authorContact + ", version=" + version + ", maintainer=" + ", authorContact=" + authorContact + ", version=" + version
+ maintainer + ", maintainerContact=" + maintainerContact + ", maintainer=" + maintainer + ", maintainerContact="
+ ", extrasFields=" + extrasFields + ", extrasResources=" + maintainerContact + ", extrasFields=" + extrasFields
+ extrasResources + ", uuid=" + uuid + "]"; + ", extrasResources=" + extrasResources + "]";
} }
} }

View File

@ -3,6 +3,8 @@ package org.gcube.data_catalogue.grsf_publish_ws.json.input.record;
import java.util.List; import java.util.List;
import javax.validation.Valid; import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import org.gcube.data_catalogue.grsf_publish_ws.custom_annotations.CkanResource; import org.gcube.data_catalogue.grsf_publish_ws.custom_annotations.CkanResource;
import org.gcube.data_catalogue.grsf_publish_ws.custom_annotations.CustomField; import org.gcube.data_catalogue.grsf_publish_ws.custom_annotations.CustomField;
@ -26,8 +28,9 @@ import com.fasterxml.jackson.annotation.JsonProperty;
*/ */
@JsonIgnoreProperties(value = {"grsf_type", "source"}) @JsonIgnoreProperties(value = {"grsf_type", "source"})
public class Common extends Base{ public class Common extends Base{
public static final String GRSF_DATABASE_SOURCE = "Database Source"; public static final String UUID_KB_KEY = "GRSF UUID";
public static final String DOMAIN = "Domain";
// it is added in case of GRSF record // it is added in case of GRSF record
@JsonProperty("data_owner") @JsonProperty("data_owner")
@ -89,6 +92,16 @@ public class Common extends Base{
@JsonProperty("similar_source_records") @JsonProperty("similar_source_records")
@CustomField(key="Similar Source Records") @CustomField(key="Similar Source Records")
private List<SimilarRecordBean> similarSourceRecords; private List<SimilarRecordBean> similarSourceRecords;
// automatically set
@CustomField(key=DOMAIN)
private String domain;
@JsonProperty("grsf_uuid")
@CustomField(key=UUID_KB_KEY)
@NotNull(message="grsf_uuid cannot be null")
@Size(min=1, message="grsf_uuid cannot be empty")
private String uuid;
public Common() { public Common() {
super(); super();
@ -102,12 +115,14 @@ public class Common extends Base{
* @param shortName * @param shortName
* @param traceabilityFlag * @param traceabilityFlag
* @param status * @param status
* @param grsfType * @param systemType
* @param catches * @param catches
* @param landings * @param landings
* @param species * @param species
* @param similarGRSFRecords * @param similarGRSFRecords
* @param similarSourceRecords * @param similarSourceRecords
* @param domain
* @param uuid
*/ */
public Common(List<String> dataOwner, public Common(List<String> dataOwner,
List<Resource<Sources>> databaseSources, List<Resource<Sources>> databaseSources,
@ -117,7 +132,8 @@ public class Common extends Base{
List<TimeSeriesBean<String, String>> catches, List<TimeSeriesBean<String, String>> catches,
List<TimeSeriesBean<String, String>> landings, List<TimeSeriesBean<String, String>> landings,
List<String> species, List<SimilarRecordBean> similarGRSFRecords, List<String> species, List<SimilarRecordBean> similarGRSFRecords,
List<SimilarRecordBean> similarSourceRecords) { List<SimilarRecordBean> similarSourceRecords, String domain,
String uuid) {
super(); super();
this.dataOwner = dataOwner; this.dataOwner = dataOwner;
this.databaseSources = databaseSources; this.databaseSources = databaseSources;
@ -132,6 +148,24 @@ public class Common extends Base{
this.species = species; this.species = species;
this.similarGRSFRecords = similarGRSFRecords; this.similarGRSFRecords = similarGRSFRecords;
this.similarSourceRecords = similarSourceRecords; this.similarSourceRecords = similarSourceRecords;
this.domain = domain;
this.uuid = uuid;
}
public String getDomain() {
return domain;
}
public void setDomain(String domain) {
this.domain = domain;
}
public String getUuid() {
return uuid;
}
public void setUuid(String uuid) {
this.uuid = uuid;
} }
public String getSystemType() { public String getSystemType() {
@ -279,7 +313,8 @@ public class Common extends Base{
+ systemType + ", catches=" + catches + ", landings=" + systemType + ", catches=" + catches + ", landings="
+ landings + ", species=" + species + ", similarGRSFRecords=" + landings + ", species=" + species + ", similarGRSFRecords="
+ similarGRSFRecords + ", similarSourceRecords=" + similarGRSFRecords + ", similarSourceRecords="
+ similarSourceRecords + "]"; + similarSourceRecords + ", domain=" + domain + ", uuid="
+ uuid + "]";
} }
} }

View File

@ -15,7 +15,7 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonProperty;
/** /**
* A record bean * A fishery record bean.
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it) * @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
*/ */
@JsonIgnoreProperties(ignoreUnknown = true) @JsonIgnoreProperties(ignoreUnknown = true)

View File

@ -19,7 +19,7 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonProperty;
/** /**
* A stock record bean * A stock record bean.
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it) * @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
*/ */
@JsonIgnoreProperties(ignoreUnknown = true) @JsonIgnoreProperties(ignoreUnknown = true)

View File

@ -11,14 +11,14 @@ import com.fasterxml.jackson.annotation.JsonProperty;
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it) * @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
*/ */
@JsonIgnoreProperties(ignoreUnknown = true) // ignore in serialization/deserialization @JsonIgnoreProperties(ignoreUnknown = true) // ignore in serialization/deserialization
public class DeleteProductBean { public class DeleteRecord {
@JsonProperty("id") @JsonProperty("id")
@NotNull(message="id cannot be null") @NotNull(message="id cannot be null")
@Size(min=1, message="id cannot be empty") @Size(min=1, message="id cannot be empty")
private String id; private String id;
public DeleteProductBean() { public DeleteRecord() {
super(); super();
} }
@ -26,7 +26,7 @@ public class DeleteProductBean {
* Create a product deleted bean for the product that had the id 'id' * Create a product deleted bean for the product that had the id 'id'
* @param id * @param id
*/ */
public DeleteProductBean(String id) { public DeleteRecord(String id) {
this.id = id; this.id = id;
} }

View File

@ -1,5 +1,8 @@
package org.gcube.data_catalogue.grsf_publish_ws.json.input.utils; package org.gcube.data_catalogue.grsf_publish_ws.json.input.utils;
import org.gcube.data_catalogue.grsf_publish_ws.json.input.record.Common;
import org.json.simple.JSONObject;
import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonProperty;
/** /**
@ -59,11 +62,18 @@ public class SimilarRecordBean {
@Override @Override
public String toString() { public String toString() {
String toReturn = ""; // in json format
toReturn += url != null ? "url = " + url + ", " : ""; JSONObject obj = new JSONObject();
toReturn += id != null ? "id = " + id + ", " : "";
toReturn += description != null ? "description = " + description : ""; if(url != null && !url.isEmpty())
toReturn = toReturn.endsWith(", ") ? toReturn.substring(0, toReturn.length() - 2) : toReturn; obj.put("url", url);
return toReturn;
if(description != null && !description.isEmpty())
obj.put("description", description);
if(id != null && !id.isEmpty())
obj.put("id", Common.cleanSemanticId(id));
return obj.toJSONString();
} }
} }

View File

@ -15,7 +15,7 @@ public class ResponseCreationBean {
private String kbUuid; // the original uuid given by the KB private String kbUuid; // the original uuid given by the KB
@JsonProperty("product_url") @JsonProperty("product_url")
String itemUrl; private String itemUrl;
@JsonProperty("error") @JsonProperty("error")
private String error; // in case of error private String error; // in case of error

View File

@ -29,8 +29,9 @@ import org.gcube.common.authorization.library.provider.AuthorizationProvider;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider; import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.common.authorization.library.utils.Caller; import org.gcube.common.authorization.library.utils.Caller;
import org.gcube.common.scope.api.ScopeProvider; import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.data_catalogue.grsf_publish_ws.json.input.record.Common;
import org.gcube.data_catalogue.grsf_publish_ws.json.input.record.FisheryRecord; import org.gcube.data_catalogue.grsf_publish_ws.json.input.record.FisheryRecord;
import org.gcube.data_catalogue.grsf_publish_ws.json.input.utils.DeleteProductBean; import org.gcube.data_catalogue.grsf_publish_ws.json.input.utils.DeleteRecord;
import org.gcube.data_catalogue.grsf_publish_ws.json.output.ResponseBean; import org.gcube.data_catalogue.grsf_publish_ws.json.output.ResponseBean;
import org.gcube.data_catalogue.grsf_publish_ws.json.output.ResponseCreationBean; import org.gcube.data_catalogue.grsf_publish_ws.json.output.ResponseCreationBean;
import org.gcube.data_catalogue.grsf_publish_ws.utils.CommonServiceUtils; import org.gcube.data_catalogue.grsf_publish_ws.utils.CommonServiceUtils;
@ -157,7 +158,7 @@ public class GrsfPublisherFisheryService {
if(namespaces == null) if(namespaces == null)
throw new Exception("Failed to retrieve the namespaces for the key fields!"); throw new Exception("Failed to retrieve the namespaces for the key fields!");
customFields = HelperMethods.replaceFieldsKey(customFields, namespaces); customFields = HelperMethods.replaceFieldsKey(customFields, namespaces, !sourceInPath.equals(Sources.GRSF));
String publishInOrganization = CommonServiceUtils.evaluateOrganization(organization, sourceInPath); String publishInOrganization = CommonServiceUtils.evaluateOrganization(organization, sourceInPath);
@ -215,7 +216,7 @@ public class GrsfPublisherFisheryService {
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
public Response deleteFishery( public Response deleteFishery(
@NotNull(message="input value is missing") @NotNull(message="input value is missing")
@Valid DeleteProductBean recordToDelete, @Valid DeleteRecord recordToDelete,
@PathParam("source") String source) throws ValidationException{ @PathParam("source") String source) throws ValidationException{
// retrieve context and username // retrieve context and username
@ -246,10 +247,10 @@ public class GrsfPublisherFisheryService {
} }
// check it is in the right source and it is a fishery // check it is in the right source and it is a fishery
String systemType = fisheryInCkan.getExtrasAsHashMap().get(CommonServiceUtils.SYSTEM_TYPE); String type = fisheryInCkan.getExtrasAsHashMap().get(Common.DOMAIN);
if(fisheryInCkan.getOrganization().getName().equalsIgnoreCase(source) && if(fisheryInCkan.getOrganization().getName().equalsIgnoreCase(source) &&
CommonServiceUtils.SYSTEM_TYPE_FISHERY.equals(systemType)){ Product_Type.FISHERY.getOrigName().equals(type)){
logger.debug("Ok, this is a fishery of the right source, removing it"); logger.debug("Ok, this is a fishery of the right source, removing it");
boolean deleted = catalogue.deleteProduct(fisheryInCkan.getId(), apiKey, true); boolean deleted = catalogue.deleteProduct(fisheryInCkan.getId(), apiKey, true);
@ -310,8 +311,8 @@ public class GrsfPublisherFisheryService {
for (String id : fullGroupListIds) { for (String id : fullGroupListIds) {
CkanDataset dataset = catalogue.getDataset(id, apiKey); CkanDataset dataset = catalogue.getDataset(id, apiKey);
if(dataset != null){ if(dataset != null){
String type = dataset.getExtrasAsHashMap().get(CommonServiceUtils.SYSTEM_TYPE); String type = dataset.getExtrasAsHashMap().get(Common.DOMAIN);
if(CommonServiceUtils.SYSTEM_TYPE_FISHERY.equals(type)) if(Product_Type.FISHERY.getOrigName().equals(type))
datasetsIds.add(id); datasetsIds.add(id);
} }
} }
@ -480,7 +481,7 @@ public class GrsfPublisherFisheryService {
customFields.put(CommonServiceUtils.ITEM_URL_FIELD, Arrays.asList(itemUrl)); customFields.put(CommonServiceUtils.ITEM_URL_FIELD, Arrays.asList(itemUrl));
// replace fields // replace fields
customFields = HelperMethods.replaceFieldsKey(customFields, namespaces); customFields = HelperMethods.replaceFieldsKey(customFields, namespaces, !sourceInPath.equals(Sources.GRSF));
String publishInOrganization = CommonServiceUtils.evaluateOrganization(organization, sourceInPath); String publishInOrganization = CommonServiceUtils.evaluateOrganization(organization, sourceInPath);

View File

@ -29,8 +29,9 @@ import org.gcube.common.authorization.library.provider.AuthorizationProvider;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider; import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.common.authorization.library.utils.Caller; import org.gcube.common.authorization.library.utils.Caller;
import org.gcube.common.scope.api.ScopeProvider; import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.data_catalogue.grsf_publish_ws.json.input.record.Common;
import org.gcube.data_catalogue.grsf_publish_ws.json.input.record.StockRecord; import org.gcube.data_catalogue.grsf_publish_ws.json.input.record.StockRecord;
import org.gcube.data_catalogue.grsf_publish_ws.json.input.utils.DeleteProductBean; import org.gcube.data_catalogue.grsf_publish_ws.json.input.utils.DeleteRecord;
import org.gcube.data_catalogue.grsf_publish_ws.json.output.ResponseBean; import org.gcube.data_catalogue.grsf_publish_ws.json.output.ResponseBean;
import org.gcube.data_catalogue.grsf_publish_ws.json.output.ResponseCreationBean; import org.gcube.data_catalogue.grsf_publish_ws.json.output.ResponseCreationBean;
import org.gcube.data_catalogue.grsf_publish_ws.utils.CommonServiceUtils; import org.gcube.data_catalogue.grsf_publish_ws.utils.CommonServiceUtils;
@ -111,7 +112,7 @@ public class GrsfPublisherStockService {
// check it has admin role or throw exception // check it has admin role or throw exception
CommonServiceUtils.hasAdminRole(username, catalogue, apiKey, organization); CommonServiceUtils.hasAdminRole(username, catalogue, apiKey, organization);
// extend this role to the other organizations in this context // extend this role to the other organizations in this context
CommonServiceUtils.extendRoleToOtherOrganizations(username, catalogue, organization, RolesCkanGroupOrOrg.ADMIN); CommonServiceUtils.extendRoleToOtherOrganizations(username, catalogue, organization, RolesCkanGroupOrOrg.ADMIN);
@ -172,8 +173,8 @@ public class GrsfPublisherStockService {
if(namespaces == null) if(namespaces == null)
throw new Exception("Failed to retrieve the namespaces for the key fields!"); throw new Exception("Failed to retrieve the namespaces for the key fields!");
customFields = HelperMethods.replaceFieldsKey(customFields, namespaces); customFields = HelperMethods.replaceFieldsKey(customFields, namespaces, !sourceInPath.equals(Sources.GRSF));
String publishInOrganization = CommonServiceUtils.evaluateOrganization(organization, sourceInPath); String publishInOrganization = CommonServiceUtils.evaluateOrganization(organization, sourceInPath);
logger.info("Invoking create method.."); logger.info("Invoking create method..");
@ -200,10 +201,10 @@ public class GrsfPublisherStockService {
logger.info("Product created! Id is " + id); logger.info("Product created! Id is " + id);
String description = "Short Name: " + record.getShortName(); String description = "Short Name: " + record.getShortName();
if(sourceInPath.equals(Sources.GRSF)) if(sourceInPath.equals(Sources.GRSF))
description += ", GRSF Semantic Identifier: " + record.getStockId(); description += ", GRSF Semantic Identifier: " + record.getStockId();
CommonServiceUtils.actionsPostCreateOrUpdate( CommonServiceUtils.actionsPostCreateOrUpdate(
id, futureName, record, apiKey, username, organization, null, id, futureName, record, apiKey, username, organization, null,
responseBean, catalogue, namespaces, groups, context, token, responseBean, catalogue, namespaces, groups, context, token,
@ -226,7 +227,7 @@ public class GrsfPublisherStockService {
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
public Response deleteStock( public Response deleteStock(
@NotNull(message="missing input value") @NotNull(message="missing input value")
@Valid DeleteProductBean recordToDelete, @Valid DeleteRecord recordToDelete,
@PathParam("source") String source) throws ValidationException{ @PathParam("source") String source) throws ValidationException{
// retrieve context and username // retrieve context and username
@ -261,10 +262,9 @@ public class GrsfPublisherStockService {
} }
// check it is in the right source and it is a stock // check it is in the right source and it is a stock
String systemType = stockInCkan.getExtrasAsHashMap().get(CommonServiceUtils.SYSTEM_TYPE); String type = stockInCkan.getExtrasAsHashMap().get(Common.DOMAIN);
if(stockInCkan.getOrganization().getName().equalsIgnoreCase(source) && if(stockInCkan.getOrganization().getName().equalsIgnoreCase(source) &&
CommonServiceUtils.SYSTEM_TYPE_STOCK.equals(systemType)){ Product_Type.STOCK.getOrigName().equals(type)){
logger.debug("Ok, this is a stock of the right type, removing it"); logger.debug("Ok, this is a stock of the right type, removing it");
boolean deleted = catalogue.deleteProduct(stockInCkan.getId(), apiKey, true); boolean deleted = catalogue.deleteProduct(stockInCkan.getId(), apiKey, true);
@ -323,8 +323,9 @@ public class GrsfPublisherStockService {
for (String id : fullGroupListIds) { for (String id : fullGroupListIds) {
CkanDataset dataset = catalogue.getDataset(id, catalogue.getApiKeyFromUsername(username)); CkanDataset dataset = catalogue.getDataset(id, catalogue.getApiKeyFromUsername(username));
if(dataset != null){ if(dataset != null){
String type = dataset.getExtrasAsHashMap().get(CommonServiceUtils.SYSTEM_TYPE);
if(CommonServiceUtils.SYSTEM_TYPE_STOCK.equals(type)) String type = dataset.getExtrasAsHashMap().get(Common.DOMAIN);
if(Product_Type.STOCK.getOrigName().equals(type))
datasetsIds.add(id); datasetsIds.add(id);
} }
} }
@ -488,8 +489,8 @@ public class GrsfPublisherStockService {
customFields.put(CommonServiceUtils.ITEM_URL_FIELD, Arrays.asList(itemUrl)); customFields.put(CommonServiceUtils.ITEM_URL_FIELD, Arrays.asList(itemUrl));
// replace fields // replace fields
customFields = HelperMethods.replaceFieldsKey(customFields, namespaces); customFields = HelperMethods.replaceFieldsKey(customFields, namespaces,!sourceInPath.equals(Sources.GRSF));
String publishInOrganization = CommonServiceUtils.evaluateOrganization(organization, sourceInPath); String publishInOrganization = CommonServiceUtils.evaluateOrganization(organization, sourceInPath);
logger.info("Invoking update method.."); logger.info("Invoking update method..");

View File

@ -53,9 +53,9 @@ public class CommonServiceUtils {
private static final int TIME_SERIES_TAKE_LAST_VALUES = 5; private static final int TIME_SERIES_TAKE_LAST_VALUES = 5;
private static final String REGEX_TAGS = "[^\\s\\w-_.]"; private static final String REGEX_TAGS = "[^\\s\\w-_.]";
public static final String SYSTEM_TYPE = "system:type"; public static final String SYSTEM_TYPE = "system:type";
public static final String SYSTEM_TYPE_STOCK = "GRSF Stock"; public static final String SYSTEM_TYPE_FOR_SOURCES = "Source";
public static final String SYSTEM_TYPE_FISHERY = "GRSF Fishery"; public static final String GRSF_DATABASE_SOURCE = "Database Source";
// item url property // item url property
public static final String ITEM_URL_FIELD = "GRSF Record URL"; public static final String ITEM_URL_FIELD = "GRSF Record URL";
private static final String GRSF_ADMIN_ORGANIZATION_NAME = "grsf_admin"; private static final String GRSF_ADMIN_ORGANIZATION_NAME = "grsf_admin";
@ -450,7 +450,7 @@ public class CommonServiceUtils {
} }
// create the Database Source information // create the Database Source information
customFields.put(Common.GRSF_DATABASE_SOURCE, Arrays.asList(databaseSource.trim())); customFields.put(GRSF_DATABASE_SOURCE, Arrays.asList(databaseSource.trim()));
// append to groups: we need to add this record to the correspondent group of the sources // append to groups: we need to add this record to the correspondent group of the sources
addRecordToGroupSources(groups, sourcesList, productType, sourceInPath); addRecordToGroupSources(groups, sourcesList, productType, sourceInPath);
@ -465,9 +465,14 @@ public class CommonServiceUtils {
boolean skipTags = !sourceInPath.equals(Sources.GRSF); // no tags for the Original records boolean skipTags = !sourceInPath.equals(Sources.GRSF); // no tags for the Original records
CommonServiceUtils.getTagsGroupsResourcesExtrasByRecord(tags, skipTags, groups, false, resources, false, customFields, record, username, sourceInPath); CommonServiceUtils.getTagsGroupsResourcesExtrasByRecord(tags, skipTags, groups, false, resources, false, customFields, record, username, sourceInPath);
// set the system type type: fishery or stock // set the domain
record.setSystemType(productType.equals(Product_Type.STOCK)? SYSTEM_TYPE_STOCK : SYSTEM_TYPE_FISHERY); record.setDomain(productType.getOrigName());
// set system type (it is equal to the GRSF Type for GRSF records, "Source" for source records)
record.setSystemType(sourceInPath.equals(Sources.GRSF) ?
productType.equals(Product_Type.FISHERY) ? ((FisheryRecord)record).getType().getOrigName() : ((StockRecord)record).getType().getOrigName()
: SYSTEM_TYPE_FOR_SOURCES);
} }
/** /**

View File

@ -499,7 +499,7 @@ public abstract class HelperMethods {
return catalogue.getProductsIdsInGroupOrOrg(groupName, true, 0, Integer.MAX_VALUE); return catalogue.getProductsIdsInGroupOrOrg(groupName, true, 0, Integer.MAX_VALUE);
} }
/** /**
* Retrieve the identifiers of the products in a given organization. It doesn't use CKAN API because they would return at most 1000 ids. * Retrieve the identifiers of the products in a given organization. It doesn't use CKAN API because they would return at most 1000 ids.
* @param string * @param string
@ -573,7 +573,7 @@ public abstract class HelperMethods {
* @return * @return
*/ */
public static Map<String, List<String>> replaceFieldsKey(Map<String, List<String>> customFields, public static Map<String, List<String>> replaceFieldsKey(Map<String, List<String>> customFields,
Map<String, String> namespaces) { Map<String, String> namespaces, boolean isSourceRecord) {
Map<String, List<String>> toReturn = new HashMap<String, List<String>>(); Map<String, List<String>> toReturn = new HashMap<String, List<String>>();
@ -582,10 +582,20 @@ public abstract class HelperMethods {
while (iterator.hasNext()) { while (iterator.hasNext()) {
Map.Entry<java.lang.String, java.util.List<java.lang.String>> entry = (Map.Entry<java.lang.String, java.util.List<java.lang.String>>) iterator Map.Entry<java.lang.String, java.util.List<java.lang.String>> entry = (Map.Entry<java.lang.String, java.util.List<java.lang.String>>) iterator
.next(); .next();
if(namespaces.containsKey(entry.getKey()))
String usedKey = "";
if(namespaces.containsKey(entry.getKey())){
toReturn.put(namespaces.get(entry.getKey()), entry.getValue()); toReturn.put(namespaces.get(entry.getKey()), entry.getValue());
else usedKey = namespaces.get(entry.getKey());
}
else{
toReturn.put(entry.getKey(), entry.getValue()); toReturn.put(entry.getKey(), entry.getValue());
usedKey = entry.getKey();
}
if(isSourceRecord)
toReturn.put(usedKey.replace("GRSF", "").trim(), entry.getValue());
} }
return toReturn; return toReturn;

View File

@ -26,7 +26,6 @@ import org.gcube.data_catalogue.grsf_publish_ws.json.input.record.Common;
import org.gcube.data_catalogue.grsf_publish_ws.json.input.record.FisheryRecord; import org.gcube.data_catalogue.grsf_publish_ws.json.input.record.FisheryRecord;
import org.gcube.data_catalogue.grsf_publish_ws.json.input.record.StockRecord; import org.gcube.data_catalogue.grsf_publish_ws.json.input.record.StockRecord;
import org.gcube.data_catalogue.grsf_publish_ws.utils.CSVUtils; import org.gcube.data_catalogue.grsf_publish_ws.utils.CSVUtils;
import org.gcube.data_catalogue.grsf_publish_ws.utils.CommonServiceUtils;
import org.gcube.data_catalogue.grsf_publish_ws.utils.HelperMethods; import org.gcube.data_catalogue.grsf_publish_ws.utils.HelperMethods;
import org.gcube.data_catalogue.grsf_publish_ws.utils.cache.CacheImpl; import org.gcube.data_catalogue.grsf_publish_ws.utils.cache.CacheImpl;
import org.gcube.data_catalogue.grsf_publish_ws.utils.cache.CacheInterface; import org.gcube.data_catalogue.grsf_publish_ws.utils.cache.CacheInterface;
@ -157,7 +156,7 @@ public class ManageTimeSeriesThread extends Thread{
// - type of files (e.g., csv) // - type of files (e.g., csv)
// -files (e.g, kbuuid.csv) // -files (e.g, kbuuid.csv)
String recordTypeFolderName = record.getSystemType().equals(CommonServiceUtils.SYSTEM_TYPE_STOCK)? "stock" :"fishery"; String recordTypeFolderName = record.getDomain().toLowerCase();
String productName = record.getClass().equals(StockRecord.class) ? ((StockRecord)record).getStockName() : ((FisheryRecord)record).getFisheryName(); String productName = record.getClass().equals(StockRecord.class) ? ((StockRecord)record).getStockName() : ((FisheryRecord)record).getFisheryName();
String csvFileName = replaceIllegalChars(productName, " "); String csvFileName = replaceIllegalChars(productName, " ");
csvFileName = generateCSVFileName(csvFileName); csvFileName = generateCSVFileName(csvFileName);