minor fixes and improvements
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/data-catalogue/catalogue-ws@147250 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
64efdd8465
commit
e15e6ff66b
|
@ -4,7 +4,8 @@ import org.json.simple.JSONObject;
|
|||
|
||||
/**
|
||||
* A custom field. It also stores index of the category and of the metadata field associated.
|
||||
* If they are missing, indexes are set to Integer.MAX_VALUE
|
||||
* These are used to sort them before pushing the content to CKAN.
|
||||
* If they are missing, indexes are set to Integer.MAX_VALUE.
|
||||
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
|
||||
*/
|
||||
public class CustomField implements Comparable<CustomField>{
|
||||
|
@ -109,7 +110,6 @@ public class CustomField implements Comparable<CustomField>{
|
|||
|
||||
@Override
|
||||
public int compareTo(CustomField o) {
|
||||
|
||||
if(this.indexCategory == o.indexCategory){
|
||||
if(this.indexMetadataField == o.indexMetadataField)
|
||||
return 0;
|
||||
|
@ -119,5 +119,4 @@ public class CustomField implements Comparable<CustomField>{
|
|||
else
|
||||
return this.indexCategory > o.indexCategory ? 1 : -1;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@ import net.sf.ehcache.Cache;
|
|||
import net.sf.ehcache.CacheManager;
|
||||
|
||||
/**
|
||||
* Handle caches via Ehcache
|
||||
* Handle caches via Ehcache stuff.
|
||||
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
|
||||
*/
|
||||
public class CachesManager {
|
||||
|
|
|
@ -39,6 +39,7 @@ import org.gcube.common.scope.impl.ScopeBean.Type;
|
|||
import org.gcube.datacatalogue.catalogue.beans.resource.CustomField;
|
||||
import org.gcube.datacatalogue.ckanutillibrary.server.DataCatalogue;
|
||||
import org.gcube.datacatalogue.ckanutillibrary.server.DataCatalogueFactory;
|
||||
import org.gcube.datacatalogue.ckanutillibrary.server.utils.UtilMethods;
|
||||
import org.gcube.datacatalogue.metadatadiscovery.DataCalogueMetadataFormatReader;
|
||||
import org.gcube.datacatalogue.metadatadiscovery.bean.MetadataProfile;
|
||||
import org.gcube.datacatalogue.metadatadiscovery.bean.jaxb.DataType;
|
||||
|
@ -58,6 +59,8 @@ import org.slf4j.LoggerFactory;
|
|||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
import eu.trentorise.opendata.jackan.model.CkanGroup;
|
||||
|
||||
/**
|
||||
* Utils class and methods.
|
||||
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
|
||||
|
@ -79,13 +82,15 @@ public class CatalogueUtils {
|
|||
public static final String AUTHOR_KEY = "author";
|
||||
public static final String RESOURCES_KEY = "resources";
|
||||
public static final String AUTHOR_EMAIL_KEY = "author_email";
|
||||
public static final String METADATATYPE_KEY = "metadatatype";
|
||||
public static final String TYPE_KEY = "system:type";
|
||||
public static final String OWNER_ORG_KEY = "owner_org";
|
||||
public static final String TITLE_KEY = "title";
|
||||
public static final String VERSION_KEY = "version";
|
||||
public static final String SEPARATOR_MULTIPLE_VALUES_FIELD = ",";
|
||||
public static final int MAX_TAG_CHARS = 100;
|
||||
public static final short MAX_UPLOADABLE_FILE_SIZE_MB = 100;
|
||||
public static final String EMAIL_IN_PROFILE_KEY = "email";
|
||||
public static final String FULLNAME_IN_PROFILE_KEY = "fullname";
|
||||
|
||||
|
||||
// =======================================================================
|
||||
|
@ -117,9 +122,9 @@ public class CatalogueUtils {
|
|||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public static boolean createGroupAsSysAdmin(String title, String groupName, String description) throws Exception{
|
||||
public static CkanGroup createGroupAsSysAdmin(String title, String groupName, String description) throws Exception{
|
||||
|
||||
return getCatalogue().createGroup(groupName, title, description) != null;
|
||||
return getCatalogue().createGroup(groupName, title, description);
|
||||
|
||||
}
|
||||
|
||||
|
@ -191,7 +196,7 @@ public class CatalogueUtils {
|
|||
|
||||
return xmlToReturn;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the categories.
|
||||
* @param context
|
||||
|
@ -200,10 +205,9 @@ public class CatalogueUtils {
|
|||
*/
|
||||
public static List<NamespaceCategory> getNamespaceCategories() throws Exception{
|
||||
|
||||
DataCalogueMetadataFormatReader
|
||||
reader = new DataCalogueMetadataFormatReader();
|
||||
DataCalogueMetadataFormatReader reader = new DataCalogueMetadataFormatReader();
|
||||
return reader.getListOfNamespaceCategories();
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -298,7 +302,7 @@ public class CatalogueUtils {
|
|||
String url = (String)resource.get("url");
|
||||
|
||||
if(url == null || name == null || url.isEmpty() || name.isEmpty())
|
||||
throw new Exception("Resources must have at least a name and an url");
|
||||
throw new Exception("Resources must have at least a name and an url field set!");
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -369,21 +373,21 @@ public class CatalogueUtils {
|
|||
if(extrasArrayOriginal == null || extrasArrayOriginal.isEmpty())
|
||||
throw new Exception("'extras' field is missing in context where metadata profile(s) are defined!");
|
||||
|
||||
// get the metadata profile
|
||||
// get the metadata profile specifying the type
|
||||
CustomField metadataTypeCF = null;
|
||||
List<CustomField> customFields = new ArrayList<CustomField>(extrasArrayOriginal.size());
|
||||
Iterator iterator = extrasArrayOriginal.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
JSONObject object = (JSONObject) iterator.next();
|
||||
CustomField cf = new CustomField(object);
|
||||
if(cf.getKey().equals(METADATATYPE_KEY))
|
||||
if(cf.getKey().equals(TYPE_KEY))
|
||||
metadataTypeCF = cf;
|
||||
else
|
||||
customFields.add(cf);
|
||||
}
|
||||
|
||||
if(metadataTypeCF == null)
|
||||
throw new Exception("'" + METADATATYPE_KEY + "' field is missing in context where metadata profile(s) are defined!");
|
||||
throw new Exception("'" + TYPE_KEY + "' field is missing in context where metadata profile(s) are defined!");
|
||||
|
||||
if(groupsArrayOriginal == null)
|
||||
groupsArrayOriginal = new JSONArray();
|
||||
|
@ -391,11 +395,10 @@ public class CatalogueUtils {
|
|||
if(tagsArrayOriginal == null)
|
||||
tagsArrayOriginal = new JSONArray();
|
||||
|
||||
// fetch the profile by metadatatype
|
||||
// fetch the profile by metadata type specified above
|
||||
MetadataFormat profile = null;
|
||||
String profileNameMatched = null;
|
||||
for (String profileName : profiles) {
|
||||
|
||||
profile = getMetadataProfile(profileName);
|
||||
if(profile.getType().equals(metadataTypeCF.getValue())){
|
||||
profileNameMatched = profileName;
|
||||
|
@ -406,7 +409,7 @@ public class CatalogueUtils {
|
|||
}
|
||||
|
||||
if(profile == null)
|
||||
throw new Exception("'" + METADATATYPE_KEY + "' specified as custom field doesn't match any of the profiles defined in this context!");
|
||||
throw new Exception("'" + TYPE_KEY + "' specified as custom field doesn't match any of the profiles defined in this context!");
|
||||
|
||||
else{
|
||||
|
||||
|
@ -420,29 +423,17 @@ public class CatalogueUtils {
|
|||
extrasArrayUpdated = new JSONArray();
|
||||
List<NamespaceCategory> categories = getNamespaceCategories();
|
||||
List<String> categoriesIds = new ArrayList<String>(categories.size());
|
||||
if(categories == null)
|
||||
if(categoriesIds.isEmpty())
|
||||
logger.warn("No category defined into profile " + profileNameMatched);
|
||||
else{
|
||||
|
||||
for (NamespaceCategory metadataCategory : categories) {
|
||||
for (NamespaceCategory metadataCategory : categories)
|
||||
categoriesIds.add(metadataCategory.getId()); // save them later for matching with custom fields
|
||||
// there is no longer need to submit the categories' JSON information
|
||||
// JSONObject catJsonObj = new JSONObject();
|
||||
// JSONObject value = new JSONObject();
|
||||
// value.put("id", metadataCategory.getId());
|
||||
// value.put("title", metadataCategory.getTitle());
|
||||
// value.put("description", metadataCategory.getDescription());
|
||||
// catJsonObj.put("key", metadataCategory.getCategoryQName());
|
||||
// catJsonObj.put("value", value.toString());
|
||||
// extrasArrayUpdated.add(catJsonObj);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// the list of already validated customFields
|
||||
List<CustomField> validatedCustomFields = new ArrayList<CustomField>(customFields.size());
|
||||
|
||||
// keep track of mandatory (only) fields
|
||||
// keep track of mandatory fields and their cardinality
|
||||
Map<String, Integer> fieldsMandatoryLowerBoundMap = new HashMap<String, Integer>(metadataFields.size());
|
||||
Map<String, Integer> fieldsMandatoryUpperBoundMap = new HashMap<String, Integer>(metadataFields.size());
|
||||
Map<String, Integer> numberFieldsSameKeyMap = new HashMap<String, Integer>(metadataFields.size());
|
||||
|
@ -452,7 +443,7 @@ public class CatalogueUtils {
|
|||
for (MetadataField metadataField : metadataFields) {
|
||||
|
||||
int categoryIdIndex = categoriesIds.indexOf(metadataField.getCategoryRef());
|
||||
logger.trace("Found index for this category (" + metadataField.getCategoryRef() + ")" + categoryIdIndex);
|
||||
logger.debug("Found index for category " + metadataField.getCategoryRef() + " " + categoryIdIndex);
|
||||
List<CustomField> validCFs = validateAgainstMetadataField(
|
||||
metadataIndex,
|
||||
categoryIdIndex,
|
||||
|
@ -481,18 +472,19 @@ public class CatalogueUtils {
|
|||
logger.info("Field with key '" + entry.getKey() + "' has been found " + inserted + " times and its lower bound is " + lowerBound + " and upper bound " + upperBound);
|
||||
|
||||
if(inserted < lowerBound || inserted > upperBound)
|
||||
throw new Exception("Field with key '" + entry.getKey() + "' is mandatory, but it's not present among the provided fields or its cardinality is not respected (" + lowerBound + ").");
|
||||
throw new Exception("Field with key '" + entry.getKey() + "' is mandatory, but it's not present among the provided fields or its cardinality is not respected ([" + lowerBound + ", " + upperBound +"]).");
|
||||
}
|
||||
|
||||
// sort validated custom fields and add to the extrasArrayUpdated json array
|
||||
Collections.sort(validatedCustomFields);
|
||||
|
||||
logger.trace("Sorted list of custom fields is " + validatedCustomFields);
|
||||
logger.debug("Sorted list of custom fields is " + validatedCustomFields);
|
||||
|
||||
// add missing fields with no match (append them at the end, since no metadataIndex or categoryIndex was defined for them)
|
||||
for(CustomField cf : customFields)
|
||||
validatedCustomFields.add(cf);
|
||||
|
||||
// retransform to json
|
||||
for (CustomField customField : validatedCustomFields) {
|
||||
JSONObject jsonObj = new JSONObject();
|
||||
jsonObj.put("key", customField.getQualifiedKey());
|
||||
|
@ -500,7 +492,7 @@ public class CatalogueUtils {
|
|||
extrasArrayUpdated.add(jsonObj);
|
||||
}
|
||||
|
||||
// add metadatatype field as last
|
||||
// add metadata type field as last element
|
||||
JSONObject metadataTypeJSON = new JSONObject();
|
||||
metadataTypeJSON.put("key", metadataTypeCF.getKey());
|
||||
metadataTypeJSON.put("value", metadataTypeCF.getValue());
|
||||
|
@ -564,29 +556,32 @@ public class CatalogueUtils {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
// in case of mandatory fields, keep track of the number of times they appear
|
||||
if(metadataField.getMandatory()){
|
||||
|
||||
// lower bound
|
||||
int lowerBound = 1;
|
||||
if(fieldsMandatoryLowerBoundMap.containsKey(metadataFieldName))
|
||||
lowerBound = fieldsMandatoryLowerBoundMap.get(metadataFieldName) + 1;
|
||||
|
||||
fieldsMandatoryLowerBoundMap.put(metadataFieldName, lowerBound);
|
||||
|
||||
// upper bound
|
||||
boolean hasVocabulary = metadataField.getVocabulary() != null;
|
||||
int upperBound = hasVocabulary ? (metadataField.getVocabulary().isMultiSelection() ? Integer.MAX_VALUE : 1) : 1;
|
||||
|
||||
if(fieldsMandatoryUpperBoundMap.containsKey(metadataFieldName))
|
||||
upperBound += fieldsMandatoryUpperBoundMap.get(metadataFieldName);
|
||||
|
||||
fieldsMandatoryUpperBoundMap.put(metadataFieldName, lowerBound);
|
||||
if(fieldsMandatoryUpperBoundMap.containsKey(metadataFieldName)){
|
||||
try{
|
||||
upperBound = Math.addExact(upperBound, fieldsMandatoryUpperBoundMap.get(metadataFieldName));
|
||||
}catch(ArithmeticException e){
|
||||
upperBound = Integer.MAX_VALUE;
|
||||
}
|
||||
}
|
||||
fieldsMandatoryUpperBoundMap.put(metadataFieldName, upperBound);
|
||||
|
||||
// fields with this same key
|
||||
int countPerFields = fieldsFoundWithThisKey;
|
||||
if(numberFieldsSameKeyMap.containsKey(metadataFieldName))
|
||||
countPerFields = numberFieldsSameKeyMap.get(metadataFieldName) + countPerFields;
|
||||
|
||||
countPerFields += numberFieldsSameKeyMap.get(metadataFieldName);
|
||||
numberFieldsSameKeyMap.put(metadataFieldName, countPerFields);
|
||||
|
||||
}
|
||||
|
@ -604,7 +599,7 @@ public class CatalogueUtils {
|
|||
private static void checkAsTag(CustomField fieldToValidate,
|
||||
MetadataField metadataField, JSONArray tagsArrayOriginal) {
|
||||
MetadataTagging tagging = metadataField.getTagging();
|
||||
if(tagging != null && tagging.getCreate()){
|
||||
if(tagging != null){
|
||||
|
||||
String tag = "";
|
||||
|
||||
|
@ -646,9 +641,9 @@ public class CatalogueUtils {
|
|||
private static void checkAsGroup(CustomField fieldToValidate,
|
||||
MetadataField metadataField, JSONArray groupsArrayOriginal) {
|
||||
|
||||
logger.trace("Custom field is " + fieldToValidate);
|
||||
logger.trace("MetadataField field is " + metadataField);
|
||||
logger.trace("JSONArray field is " + groupsArrayOriginal);
|
||||
logger.debug("Custom field is " + fieldToValidate);
|
||||
logger.debug("MetadataField field is " + metadataField);
|
||||
logger.debug("JSONArray field is " + groupsArrayOriginal);
|
||||
|
||||
MetadataGrouping grouping = metadataField.getGrouping();
|
||||
if(grouping != null){
|
||||
|
@ -673,7 +668,7 @@ public class CatalogueUtils {
|
|||
|
||||
for (String title : groupNames) {
|
||||
JSONObject group = new JSONObject();
|
||||
group.put("name", title);
|
||||
group.put("name", UtilMethods.fromGroupTitleToName(title));
|
||||
groupsArrayOriginal.add(group);
|
||||
}
|
||||
|
||||
|
@ -709,20 +704,17 @@ public class CatalogueUtils {
|
|||
DataType dataType = metadataField.getDataType();
|
||||
String regex = metadataField.getValidator() != null ? metadataField.getValidator().getRegularExpression() : null;
|
||||
boolean hasControlledVocabulary = metadataField.getVocabulary() != null;
|
||||
boolean isMultiselection = hasControlledVocabulary ? metadataField.getVocabulary().isMultiSelection() : false;
|
||||
|
||||
String value = fieldToValidate.getValue();
|
||||
String key = fieldToValidate.getKey();
|
||||
|
||||
// replace key by prepending the qualified name of the category, if needed
|
||||
fieldToValidate.setQualifiedKey(metadataField.getCategoryFieldQName());
|
||||
|
||||
if((value == null || value.isEmpty()))
|
||||
if(metadataField.getMandatory() || hasControlledVocabulary)
|
||||
throw new Exception("Mandatory field with name '" + key + "' doesn't have a value but it is mandatory or has a controlled vocabulary!");
|
||||
else return;
|
||||
|
||||
|
||||
// if(!isMultiselection && !isFirst)
|
||||
// throw new Exception("Field with key '" + key + "' cannot be repeated more than once!");
|
||||
|
||||
switch(dataType){
|
||||
|
||||
case String:
|
||||
|
@ -780,7 +772,7 @@ public class CatalogueUtils {
|
|||
case Boolean:
|
||||
|
||||
if (value.equalsIgnoreCase("true") || value.equalsIgnoreCase("false")) {
|
||||
|
||||
|
||||
}else
|
||||
throw new Exception("Field with key '" + key + "' doesn't seem a valid boolean value!");
|
||||
|
||||
|
@ -793,7 +785,6 @@ public class CatalogueUtils {
|
|||
break;
|
||||
case GeoJSON:
|
||||
|
||||
// validate
|
||||
try{
|
||||
new ObjectMapper().readValue(fieldToValidate.getValue(), GeoJsonObject.class);
|
||||
}catch(Exception e){
|
||||
|
@ -802,14 +793,9 @@ public class CatalogueUtils {
|
|||
|
||||
break;
|
||||
default:
|
||||
|
||||
//???
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
// replace key by prepending the qualified name of the category, if needed
|
||||
fieldToValidate.setQualifiedKey(metadataField.getCategoryFieldQName());
|
||||
|
||||
}
|
||||
|
||||
private static final SimpleDateFormat DATE_SIMPLE = new SimpleDateFormat("yyyy-MM-dd");
|
||||
|
@ -827,7 +813,7 @@ public class CatalogueUtils {
|
|||
DATE_HOUR_MINUTES.parse(value);
|
||||
return true;
|
||||
}catch(Exception e){
|
||||
logger.trace("failed to parse date with hours and minutes, trying the other one");
|
||||
logger.debug("failed to parse date with hours and minutes, trying the other one");
|
||||
try{
|
||||
DATE_SIMPLE.parse(value);
|
||||
return true;
|
||||
|
@ -887,7 +873,7 @@ public class CatalogueUtils {
|
|||
if(authorization != null)
|
||||
request.addHeader(Constants.AUTH_CKAN_HEADER, authorization);
|
||||
|
||||
logger.trace("******* REQUEST URL IS " + requestPath);
|
||||
logger.debug("******* REQUEST URL IS " + requestPath);
|
||||
|
||||
HttpEntity entityRes = client.execute(request).getEntity();
|
||||
String json = EntityUtils.toString(entityRes);
|
||||
|
@ -954,17 +940,17 @@ public class CatalogueUtils {
|
|||
if(requestPath.endsWith("&"))
|
||||
requestPath = requestPath.substring(0, requestPath.length() - 1);
|
||||
|
||||
logger.trace("POST request url is going to be " + requestPath);
|
||||
logger.debug("POST request url is going to be " + requestPath);
|
||||
|
||||
HttpPost request = new HttpPost(requestPath);
|
||||
request.addHeader(Constants.AUTH_CKAN_HEADER, authorization);
|
||||
logger.trace("Sending json to CKAN is " + json);
|
||||
logger.debug("Sending json to CKAN is " + json);
|
||||
StringEntity params = new StringEntity(json, ContentType.APPLICATION_JSON);
|
||||
request.setEntity(params);
|
||||
HttpEntity entityRes = client.execute(request).getEntity();
|
||||
String jsonRes = EntityUtils.toString(entityRes);
|
||||
|
||||
logger.trace("Result from CKAN is " + jsonRes);
|
||||
logger.debug("Result from CKAN is " + jsonRes);
|
||||
|
||||
// substitute "help" field
|
||||
JSONParser parser = new JSONParser();
|
||||
|
@ -1028,17 +1014,17 @@ public class CatalogueUtils {
|
|||
if(requestPath.endsWith("&"))
|
||||
requestPath = requestPath.substring(0, requestPath.length() - 1);
|
||||
|
||||
logger.trace("POST request url is going to be " + requestPath);
|
||||
logger.debug("POST request url is going to be " + requestPath);
|
||||
|
||||
// use jersey client
|
||||
logger.trace("Sending multipart to CKAN " + multiPart);
|
||||
logger.debug("Sending multipart to CKAN " + multiPart);
|
||||
|
||||
FormDataBodyPart upload = multiPart.getField("upload");
|
||||
if(upload != null){
|
||||
File file = upload.getValueAs(File.class);
|
||||
long fileLenghtBytes = file.length();
|
||||
long fileLenghtMegaByte = fileLenghtBytes >> 20;
|
||||
logger.trace("File lenght in MegaByte is " + fileLenghtMegaByte);
|
||||
logger.debug("File lenght in MegaByte is " + fileLenghtMegaByte);
|
||||
|
||||
if(fileLenghtMegaByte > MAX_UPLOADABLE_FILE_SIZE_MB)
|
||||
throw new Exception("Exceeding maximum uploadable file size!");
|
||||
|
@ -1054,7 +1040,7 @@ public class CatalogueUtils {
|
|||
.header(Constants.AUTH_CKAN_HEADER, authorization)
|
||||
.post(Entity.entity(multiPart, multiPart.getMediaType()), JSONObject.class);
|
||||
|
||||
logger.trace("Result from CKAN is " + jsonRes);
|
||||
logger.debug("Result from CKAN is " + jsonRes);
|
||||
|
||||
// substitute "help" field
|
||||
jsonRes.put(HELP_KEY, HELP_URL_GCUBE_CATALOGUE);
|
||||
|
@ -1071,9 +1057,6 @@ public class CatalogueUtils {
|
|||
// SOCIAL FACILITIES
|
||||
// =======================================================================
|
||||
|
||||
public static final String EMAIL_IN_PROFILE_KEY = "email";
|
||||
public static final String FULLNAME_IN_PROFILE_KEY = "fullname";
|
||||
|
||||
/**
|
||||
* Execute the GET http request at this url, and return the result as string
|
||||
* @return
|
||||
|
|
|
@ -72,7 +72,7 @@ public class Constants {
|
|||
// licenses
|
||||
public final static String LICENSES_SHOW = CKAN_API_PATH + "license_list?";
|
||||
|
||||
// ckan capabilities
|
||||
// other capabilities of this services related to gCube Profiles
|
||||
public static final String PROFILES_NAMES_SHOW = "profile_names/";
|
||||
public static final String PROFILE_SHOW = "profile/";
|
||||
|
||||
|
|
|
@ -15,11 +15,15 @@ import org.gcube.resources.discovery.client.queries.api.SimpleQuery;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* Discover the Social Networking Service in the Infrastructure.
|
||||
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
|
||||
*/
|
||||
public class GcoreEndpointReaderSNL {
|
||||
|
||||
private static final String resource = "jersey-servlet";
|
||||
private static final String serviceName = "SocialNetworking";
|
||||
private static final String serviceClass = "Portal";
|
||||
private static final String RESOURCE = "jersey-servlet";
|
||||
private static final String SERVICE_NAME = "SocialNetworking";
|
||||
private static final String SERVICE_CLASSE = "Portal";
|
||||
|
||||
private static Logger logger = LoggerFactory.getLogger(GcoreEndpointReaderSNL.class);
|
||||
private String serviceBasePath;
|
||||
|
@ -35,32 +39,32 @@ public class GcoreEndpointReaderSNL {
|
|||
|
||||
try{
|
||||
SimpleQuery query = queryFor(GCoreEndpoint.class);
|
||||
query.addCondition(String.format("$resource/Profile/ServiceClass/text() eq '%s'",serviceClass));
|
||||
query.addCondition("$resource/Profile/DeploymentData/Status/text() eq 'ready'");
|
||||
query.addCondition(String.format("$resource/Profile/ServiceName/text() eq '%s'",serviceName));
|
||||
query.setResult("$resource/Profile/AccessPoint/RunningInstanceInterfaces//Endpoint[@EntryName/string() eq \""+resource+"\"]/text()");
|
||||
query.addCondition(String.format("$RESOURCE/Profile/SERVICE_CLASSE/text() eq '%s'",SERVICE_CLASSE));
|
||||
query.addCondition("$RESOURCE/Profile/DeploymentData/Status/text() eq 'ready'");
|
||||
query.addCondition(String.format("$RESOURCE/Profile/SERVICE_NAME/text() eq '%s'",SERVICE_NAME));
|
||||
query.setResult("$RESOURCE/Profile/AccessPoint/RunningInstanceInterfaces//Endpoint[@EntryName/string() eq \""+RESOURCE+"\"]/text()");
|
||||
|
||||
DiscoveryClient<String> client = client();
|
||||
List<String> endpoints = client.submit(query);
|
||||
if (endpoints == null || endpoints.isEmpty())
|
||||
throw new Exception("Cannot retrieve the GCoreEndpoint serviceName: "+serviceName +", serviceClass: " +serviceClass +", in scope: "+currentScope);
|
||||
throw new Exception("Cannot retrieve the GCoreEndpoint SERVICE_NAME: "+SERVICE_NAME +", SERVICE_CLASSE: " +SERVICE_CLASSE +", in scope: "+currentScope);
|
||||
|
||||
this.serviceBasePath = endpoints.get(0);
|
||||
|
||||
if(serviceBasePath==null)
|
||||
throw new Exception("Endpoint:"+resource+", is null for serviceName: "+serviceName +", serviceClass: " +serviceClass +", in scope: "+currentScope);
|
||||
throw new Exception("Endpoint:"+RESOURCE+", is null for SERVICE_NAME: "+SERVICE_NAME +", SERVICE_CLASSE: " +SERVICE_CLASSE +", in scope: "+currentScope);
|
||||
|
||||
serviceBasePath = serviceBasePath.endsWith("/") ? serviceBasePath : serviceBasePath + "/";
|
||||
|
||||
}catch(Exception e){
|
||||
String error = "An error occurred during GCoreEndpoint discovery, serviceName: "+serviceName +", serviceClass: " +serviceClass +", in scope: "+currentScope +".";
|
||||
String error = "An error occurred during GCoreEndpoint discovery, SERVICE_NAME: "+SERVICE_NAME +", SERVICE_CLASSE: " +SERVICE_CLASSE +", in scope: "+currentScope +".";
|
||||
logger.error(error, e);
|
||||
throw new Exception(error);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the ResourceEntyName
|
||||
* @return the RESOURCEEntyName
|
||||
*/
|
||||
public String getServiceBasePath() {
|
||||
return serviceBasePath;
|
||||
|
|
|
@ -22,7 +22,7 @@ import org.slf4j.LoggerFactory;
|
|||
|
||||
|
||||
/**
|
||||
* Let the Product Catalogue Manager write a post in a VRE and alert there is a new product
|
||||
* Let the Product Catalogue Manager write a post in a VRE and alert there is a new product.
|
||||
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
|
||||
*/
|
||||
public class WritePostCatalogueManagerThread extends Thread {
|
||||
|
|
|
@ -18,6 +18,10 @@ import org.gcube.datacatalogue.catalogue.utils.Constants;
|
|||
|
||||
|
||||
@Path(Constants.GROUPS)
|
||||
/**
|
||||
* Groups service endpoint.
|
||||
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
|
||||
*/
|
||||
public class Group {
|
||||
|
||||
@GET
|
||||
|
|
|
@ -24,6 +24,10 @@ import org.json.simple.parser.JSONParser;
|
|||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@Path(Constants.ITEMS)
|
||||
/**
|
||||
* Items service endpoint.
|
||||
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
|
||||
*/
|
||||
public class Item {
|
||||
|
||||
private static final org.slf4j.Logger logger = LoggerFactory.getLogger(Item.class);
|
||||
|
@ -52,7 +56,7 @@ public class Item {
|
|||
String context = ScopeProvider.instance.get();
|
||||
|
||||
try{
|
||||
|
||||
|
||||
JSONParser parser = new JSONParser();
|
||||
JSONObject obj = (JSONObject)parser.parse(json);
|
||||
|
||||
|
@ -68,13 +72,13 @@ public class Item {
|
|||
if(profiles != null && !profiles.isEmpty())
|
||||
CatalogueUtils.validateAgainstProfile(obj, caller, profiles);
|
||||
|
||||
CatalogueUtils.delegatePost(caller, context, Constants.ITEM_CREATE, obj.toJSONString(), uriInfo);
|
||||
CatalogueUtils.delegatePost(caller, context, Constants.ITEM_CREATE, obj.toJSONString(), uriInfo);
|
||||
|
||||
// after creation, if it was ok ...
|
||||
if((boolean)obj.get(CatalogueUtils.SUCCESS_KEY)){
|
||||
|
||||
JSONObject result = (JSONObject)obj.get(CatalogueUtils.RESULT_KEY);
|
||||
|
||||
|
||||
new PackageCreatePostActions(
|
||||
username,
|
||||
(String)(result.get(CatalogueUtils.DATASET_KEY)),
|
||||
|
@ -121,6 +125,7 @@ public class Item {
|
|||
|
||||
}
|
||||
|
||||
// TODO PROFILE VALIDATION MUST BE PERFORMED HERE AS WELL
|
||||
// @POST
|
||||
// @Path(Constants.UPDATE_METHOD)
|
||||
// @Consumes(MediaType.APPLICATION_JSON)
|
||||
|
|
|
@ -16,13 +16,14 @@ import org.json.simple.JSONObject;
|
|||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@Path(Constants.PROFILES)
|
||||
/**
|
||||
* Items profiles service endpoint.
|
||||
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
|
||||
*/
|
||||
public class ItemProfile {
|
||||
|
||||
private static final org.slf4j.Logger logger = LoggerFactory.getLogger(ItemProfile.class);
|
||||
|
||||
public final static String PROFILES_GENERIC_TYPE = "DataCatalogueMetadata";
|
||||
public final static int PRETTY_PRINT_INDENT_FACTOR = 4;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@GET
|
||||
@Path(Constants.PROFILES_NAMES_SHOW)
|
||||
|
@ -50,7 +51,6 @@ public class ItemProfile {
|
|||
}
|
||||
|
||||
return json.toJSONString();
|
||||
|
||||
}
|
||||
|
||||
@GET
|
||||
|
@ -63,14 +63,14 @@ public class ItemProfile {
|
|||
String context = ScopeProvider.instance.get();
|
||||
logger.debug("Incoming request for context/name " + context+ "/" + profileName);
|
||||
|
||||
return CatalogueUtils.getProfileSource(profileName);
|
||||
|
||||
// TODO Check how this mapping xml-> json works
|
||||
/*if(accept.equals(MediaType.APPLICATION_JSON)){
|
||||
org.json.JSONObject xmlJSONObj = XML.toJSONObject(content);
|
||||
return xmlJSONObj.toString(PRETTY_PRINT_INDENT_FACTOR);
|
||||
|
||||
}*/
|
||||
|
||||
return CatalogueUtils.getProfileSource(profileName);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -15,6 +15,10 @@ import org.gcube.datacatalogue.catalogue.utils.Constants;
|
|||
|
||||
|
||||
@Path(Constants.LICENSES)
|
||||
/**
|
||||
* Licenses service endpoint.
|
||||
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
|
||||
*/
|
||||
public class License {
|
||||
|
||||
@GET
|
||||
|
|
|
@ -17,9 +17,12 @@ import org.gcube.datacatalogue.catalogue.utils.Constants;
|
|||
|
||||
|
||||
@Path(Constants.ORGANIZATIONS)
|
||||
/**
|
||||
* Organizations service endpoint.
|
||||
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
|
||||
*/
|
||||
public class Organization {
|
||||
|
||||
|
||||
@GET
|
||||
@Path(Constants.SHOW_METHOD)
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
|
|
|
@ -20,6 +20,10 @@ import org.gcube.datacatalogue.catalogue.utils.Constants;
|
|||
import org.glassfish.jersey.media.multipart.FormDataMultiPart;
|
||||
|
||||
@Path(Constants.RESOURCES)
|
||||
/**
|
||||
* Resource service endpoint.
|
||||
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
|
||||
*/
|
||||
public class Resource {
|
||||
|
||||
@GET
|
||||
|
@ -60,16 +64,15 @@ public class Resource {
|
|||
// see also multipart https://www.mkyong.com/webservices/jax-rs/file-upload-example-in-jersey/
|
||||
/*List<BodyPart> bodyParts = multiPart.getBodyParts();
|
||||
for (BodyPart bodyPart : bodyParts) {
|
||||
System.out.println("Body name is " + bodyPart.getContentDisposition().getFileName());
|
||||
logger.info("Body name is " + bodyPart.getContentDisposition().getFileName());
|
||||
}
|
||||
|
||||
Map<String, List<FormDataBodyPart>> fields = multiPart.getFields();
|
||||
System.out.println(fields);*/
|
||||
logger.info(fields);*/
|
||||
|
||||
Caller caller = AuthorizationProvider.instance.get();
|
||||
String context = ScopeProvider.instance.get();
|
||||
return CatalogueUtils.delegatePost(caller, context, Constants.RESOURCE_CREATE, multiPart, uriInfo);
|
||||
//return Response.status(Status.NOT_IMPLEMENTED).build();
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -18,6 +18,10 @@ import org.gcube.datacatalogue.catalogue.utils.Constants;
|
|||
|
||||
|
||||
@Path(Constants.USERS)
|
||||
/**
|
||||
* User service endpoint.
|
||||
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
|
||||
*/
|
||||
public class User {
|
||||
|
||||
@GET
|
||||
|
|
Reference in New Issue