further changes due to requests in ticket #8719

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/data-catalogue/grsf-publisher-ws@149332 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Costantino Perciante 2017-06-07 09:04:44 +00:00
parent 7363174702
commit 6d76255071
5 changed files with 46 additions and 26 deletions

View File

@ -19,6 +19,10 @@
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>

View File

@ -26,6 +26,7 @@ import com.fasterxml.jackson.annotation.JsonProperty;
public class Base {
private static Logger logger = LoggerFactory.getLogger(Base.class);
public static final String UUID_KB_KEY = "UUID Knowledge Base";
@JsonProperty("description")
private String description;
@ -57,7 +58,7 @@ public class Base {
private List<ResourceBean> extrasResources = new ArrayList<ResourceBean>();
@JsonProperty("uuid_knowledge_base")
@CustomField(key="UUID Knowledge Base")
@CustomField(key=UUID_KB_KEY)
@NotNull(message="uuid_knowledge_base cannot be null")
@Size(min=1, message="uuid_knowledge_base cannot be empty")
private String uuid;

View File

@ -36,6 +36,9 @@ public class CommonServiceUtils {
private static final int TIME_SERIES_TAKE_LAST_VALUES = 5;
private static final String REGEX_TAGS = "[^\\s\\w-_.]";
public static final String SYSTEM_TYPE = "system:type";
// item url property
public static final String ITEM_URL_FIELD = "UUID";
/**
* Retrieve the list of licenses for stocks and fisheries

View File

@ -29,6 +29,7 @@ import org.gcube.common.authorization.library.provider.AuthorizationProvider;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.common.authorization.library.utils.Caller;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.data_catalogue.grsf_publish_ws.json.input.Base;
import org.gcube.data_catalogue.grsf_publish_ws.json.input.Common;
import org.gcube.data_catalogue.grsf_publish_ws.json.input.DeleteProductBean;
import org.gcube.data_catalogue.grsf_publish_ws.json.input.FisheryRecord;
@ -59,9 +60,6 @@ public class GrsfPublisherFisheryService {
// the default license for these records
private static final String DEFAULT_FISHERY_LICENSE = "CC-BY-SA-4.0";
// item url property
private static final String ITEM_URL_FIELD = "Item URL";
// the context
@Context ServletContext contextServlet;
@ -129,7 +127,7 @@ public class GrsfPublisherFisheryService {
String role = catalogue.getRoleOfUserInOrganization(username, organization, apiKey);
logger.info("Role of the user " + username + " is " + role);
if(role == null || role.isEmpty())
throw new Exception("You are not authorized to create a product. Please check you have the Catalogue-Administrator role!");
@ -229,16 +227,16 @@ public class GrsfPublisherFisheryService {
// set the visibility of the datatest according the context
boolean publicDataset = context.equals((String)contextServlet.getInitParameter(HelperMethods.PUBLIC_CONTEX_KEY));
// add the SYSTEM_TYPE
customFields.put(CommonServiceUtils.SYSTEM_TYPE, Arrays.asList(sourceInPath.getOrigName()));
// convert extras' keys to keys with namespace
Map<String, String> namespaces = HelperMethods.getFieldToFieldNameSpaceMapping(HelperMethods.GENERIC_RESOURCE_NAME_MAP_KEY_NAMESPACES_FISHERY);
if(namespaces == null)
throw new Exception("Failed to retrieve the namespaces for the key fields!");
customFields = HelperMethods.replaceFieldsKey(customFields, namespaces);
logger.info("Invoking creation method..");
@ -272,7 +270,7 @@ public class GrsfPublisherFisheryService {
// add the "Product URL" to the field
Map<String, List<String>> addField = new HashMap<String, List<String>>();
addField.put(ITEM_URL_FIELD, Arrays.asList(itemUrl));
addField.put(CommonServiceUtils.ITEM_URL_FIELD, Arrays.asList(itemUrl));
catalogue.patchProductCustomFields(id, apiKey, addField);
if(!groups.isEmpty()){
@ -365,18 +363,18 @@ public class GrsfPublisherFisheryService {
// check it is in the right source and it is a fishery
String grsfType = fisheryInCkan.getExtrasAsHashMap().get(Common.GRSF_TYPE_KEY);
String groupToCheck = sourceInPath.equals(Sources.GRSF) ? "grsf-group" : sourceInPath.getOrigName().toLowerCase();
if(catalogue.isDatasetInGroup(groupToCheck, recordToDelete.getId()) && Product_Type.FISHERY.getOrigName().equals(grsfType)){
logger.warn("Ok, this is a fishery of the right source, removing it");
boolean deleted = catalogue.deleteProduct(fisheryInCkan.getId(), catalogue.getApiKeyFromUsername(username), true);
if(deleted){
logger.info("Fishery DELETED AND PURGED!");
status = Status.OK;
responseBean.setId(fisheryInCkan.getId());
}
else{
@ -499,9 +497,17 @@ public class GrsfPublisherFisheryService {
// retrieve the product url
Map<String, String> customFields = dataset.getExtrasAsHashMap();
if(customFields.containsKey(ITEM_URL_FIELD))
result.put("url", customFields.get(ITEM_URL_FIELD));
else
boolean found = false;
Set<String> KeySet = customFields.keySet();
for (String key : KeySet) {
if(key.contains(CommonServiceUtils.ITEM_URL_FIELD) && !key.contains(Base.UUID_KB_KEY)){
result.put("url", customFields.get(key));
found = true;
break;
}
}
if(!found)
result.put("url", catalogue.getUnencryptedUrlFromDatasetIdOrName(dataset.getId()));
responseBean.setResult(result);

View File

@ -29,6 +29,7 @@ import org.gcube.common.authorization.library.provider.AuthorizationProvider;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.common.authorization.library.utils.Caller;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.data_catalogue.grsf_publish_ws.json.input.Base;
import org.gcube.data_catalogue.grsf_publish_ws.json.input.Common;
import org.gcube.data_catalogue.grsf_publish_ws.json.input.DeleteProductBean;
import org.gcube.data_catalogue.grsf_publish_ws.json.input.RefersToBean;
@ -64,9 +65,6 @@ public class GrsfPublisherStockService {
// Logger
private static final org.slf4j.Logger logger = LoggerFactory.getLogger(GrsfPublisherStockService.class);
// item url property
private static final String ITEM_URL_FIELD = "Item URL";
@GET
@Path("hello")
@Produces(MediaType.TEXT_PLAIN)
@ -265,7 +263,7 @@ public class GrsfPublisherStockService {
// add the "Product URL" to the field
Map<String, List<String>> addField = new HashMap<String, List<String>>();
addField.put(ITEM_URL_FIELD, Arrays.asList(itemUrl));
addField.put(CommonServiceUtils.ITEM_URL_FIELD, Arrays.asList(itemUrl));
catalogue.patchProductCustomFields(id, apiKey, addField);
if(!groups.isEmpty()){
@ -488,9 +486,17 @@ public class GrsfPublisherStockService {
// retrieve the product url
Map<String, String> customFields = dataset.getExtrasAsHashMap();
if(customFields.containsKey(ITEM_URL_FIELD))
result.put("url", customFields.get(ITEM_URL_FIELD));
else
boolean found = false;
Set<String> KeySet = customFields.keySet();
for (String key : KeySet) {
if(key.contains(CommonServiceUtils.ITEM_URL_FIELD) && !key.contains(Base.UUID_KB_KEY)){
result.put("url", customFields.get(key));
found = true;
break;
}
}
if(!found)
result.put("url", catalogue.getUnencryptedUrlFromDatasetIdOrName(dataset.getId()));
responseBean.setResult(result);