Formatted code
This commit is contained in:
parent
63246f7cce
commit
11cd97e1c7
|
@ -17,7 +17,6 @@ public class CustomField implements Comparable<CustomField> {
|
|||
|
||||
private int indexCategory = Integer.MAX_VALUE;
|
||||
private int indexMetadataField = Integer.MAX_VALUE;
|
||||
|
||||
|
||||
private void init(String key, String value, int indexCategory, int indexMetadataField) {
|
||||
if(key == null || value == null || key.isEmpty()) {
|
||||
|
@ -41,7 +40,6 @@ public class CustomField implements Comparable<CustomField> {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
public CustomField(JsonNode object) {
|
||||
super();
|
||||
init(object.get("key").asText(), object.get("value").asText(), -1, -1);
|
||||
|
@ -91,7 +89,6 @@ public class CustomField implements Comparable<CustomField> {
|
|||
this.qualifiedKey = qualifiedKey;
|
||||
}
|
||||
|
||||
|
||||
public int getIndexCategory() {
|
||||
return indexCategory;
|
||||
}
|
||||
|
|
|
@ -80,7 +80,7 @@ public abstract class CKAN {
|
|||
public void setUriInfo(UriInfo uriInfo) {
|
||||
this.uriInfo = uriInfo;
|
||||
}
|
||||
|
||||
|
||||
public String getApiKey() {
|
||||
if(apiKey == null) {
|
||||
try {
|
||||
|
@ -181,7 +181,9 @@ public abstract class CKAN {
|
|||
try {
|
||||
String gotName = jsonNode.get(NAME_KEY).asText();
|
||||
if(!gotName.matches(nameRegex)) {
|
||||
throw new BadRequestException("The 'name' must be between 2 and 100 characters long and contain only lowercase alphanumeric characters, '-' and '_'. You can validate your name using the regular expression : " + NAME_REGEX);
|
||||
throw new BadRequestException(
|
||||
"The 'name' must be between 2 and 100 characters long and contain only lowercase alphanumeric characters, '-' and '_'. You can validate your name using the regular expression : "
|
||||
+ NAME_REGEX);
|
||||
}
|
||||
|
||||
if(name == null) {
|
||||
|
@ -228,8 +230,8 @@ public abstract class CKAN {
|
|||
return map;
|
||||
}
|
||||
|
||||
|
||||
protected GXHTTPStringRequest getGXHTTPStringRequest(String path, boolean post) throws UnsupportedEncodingException {
|
||||
protected GXHTTPStringRequest getGXHTTPStringRequest(String path, boolean post)
|
||||
throws UnsupportedEncodingException {
|
||||
String catalogueURL = CKANInstance.getInstance().getCKANURL();
|
||||
|
||||
GXHTTPStringRequest gxhttpStringRequest = HTTPUtility.createGXHTTPStringRequest(catalogueURL, path, post);
|
||||
|
|
|
@ -33,7 +33,6 @@ public class CKANGroup extends CKAN {
|
|||
|
||||
public static final String GROUPS_KEY = "groups";
|
||||
|
||||
|
||||
public CKANGroup() {
|
||||
super();
|
||||
LIST = GROUP_LIST;
|
||||
|
@ -45,20 +44,20 @@ public class CKANGroup extends CKAN {
|
|||
PURGE = GROUP_PURGE;
|
||||
}
|
||||
|
||||
private static String fromGroupTitleToName(String groupName){
|
||||
private static String fromGroupTitleToName(String groupName) {
|
||||
if(groupName == null)
|
||||
return null;
|
||||
|
||||
|
||||
String regexGroupNameTransform = "[^A-Za-z0-9-]";
|
||||
String modified = groupName.trim().replaceAll(regexGroupNameTransform, "-").replaceAll("-+", "-").toLowerCase();
|
||||
|
||||
|
||||
if(modified.startsWith("-"))
|
||||
modified = modified.substring(1);
|
||||
if(modified.endsWith("-"))
|
||||
modified = modified.substring(0, modified.length() -1);
|
||||
|
||||
modified = modified.substring(0, modified.length() - 1);
|
||||
|
||||
return modified;
|
||||
|
||||
|
||||
}
|
||||
|
||||
public static String getCKANGroupName(String name) {
|
||||
|
@ -73,15 +72,15 @@ public class CKANGroup extends CKAN {
|
|||
objectNode.put("display_name", name);
|
||||
objectNode.put("description", "");
|
||||
return super.create(mapper.writeValueAsString(objectNode));
|
||||
}catch (WebApplicationException e) {
|
||||
} catch(WebApplicationException e) {
|
||||
throw e;
|
||||
}catch (Exception e) {
|
||||
} catch(Exception e) {
|
||||
throw new InternalServerErrorException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public List<String> getGroups() {
|
||||
if(result==null) {
|
||||
if(result == null) {
|
||||
read();
|
||||
}
|
||||
List<String> groups = new ArrayList<String>();
|
||||
|
@ -89,7 +88,7 @@ public class CKANGroup extends CKAN {
|
|||
JsonNode jsonNode = result.get(GROUPS_KEY);
|
||||
if(jsonNode.isArray()) {
|
||||
ArrayNode arrayNode = (ArrayNode) jsonNode;
|
||||
if(arrayNode.size()>0) {
|
||||
if(arrayNode.size() > 0) {
|
||||
Iterator<JsonNode> iterator = arrayNode.iterator();
|
||||
while(iterator.hasNext()) {
|
||||
groups.add(iterator.next().asText());
|
||||
|
|
|
@ -39,7 +39,7 @@ public class CKANInstance {
|
|||
private final static String SOCIAL_POST = "SOCIAL_POST";
|
||||
private final static String ALERT_USERS_ON_POST_CREATION = "ALERT_USERS_ON_POST_CREATION";
|
||||
private final static String URL_RESOLVER = "URL_RESOLVER";
|
||||
|
||||
|
||||
private static final Map<String,CKANInstance> ckanInstancePerScope;
|
||||
|
||||
protected String ckanURL;
|
||||
|
@ -55,7 +55,7 @@ public class CKANInstance {
|
|||
public static CKANInstance getInstance() {
|
||||
CKANInstance ckanInstance = ckanInstancePerScope.get(ContextUtility.getCurrentContext());
|
||||
if(ckanInstance == null) {
|
||||
ckanInstance = new CKANInstance();
|
||||
ckanInstance = new CKANInstance();
|
||||
ckanInstance.getConfigurationFromIS();
|
||||
ckanInstancePerScope.put(ContextUtility.getCurrentContext(), ckanInstance);
|
||||
}
|
||||
|
@ -120,7 +120,6 @@ public class CKANInstance {
|
|||
serviceEndpoint = serviceEndpoints.get(0);
|
||||
}
|
||||
|
||||
|
||||
Iterator<AccessPoint> accessPointIterator = serviceEndpoint.profile().accessPoints().iterator();
|
||||
while(accessPointIterator.hasNext()) {
|
||||
AccessPoint accessPoint = accessPointIterator.next();
|
||||
|
@ -143,7 +142,8 @@ public class CKANInstance {
|
|||
// retrieve option for user alert
|
||||
notificationToUsersEnabled = false;
|
||||
if(accessPoint.propertyMap().containsKey(ALERT_USERS_ON_POST_CREATION)) {
|
||||
if(accessPoint.propertyMap().get(ALERT_USERS_ON_POST_CREATION).value().trim().equalsIgnoreCase("true")) {
|
||||
if(accessPoint.propertyMap().get(ALERT_USERS_ON_POST_CREATION).value().trim()
|
||||
.equalsIgnoreCase("true")) {
|
||||
notificationToUsersEnabled = true;
|
||||
}
|
||||
}
|
||||
|
@ -155,7 +155,7 @@ public class CKANInstance {
|
|||
|
||||
}
|
||||
|
||||
} catch (WebApplicationException e) {
|
||||
} catch(WebApplicationException e) {
|
||||
throw e;
|
||||
} catch(Exception e) {
|
||||
throw new InternalServerErrorException("Error while getting configuration on IS", e);
|
||||
|
|
|
@ -13,16 +13,16 @@ public class CKANLicense extends CKAN {
|
|||
|
||||
public CKANLicense() {
|
||||
super();
|
||||
LIST = LICENSES_LIST;
|
||||
LIST = LICENSES_LIST;
|
||||
}
|
||||
|
||||
protected static ArrayNode getLicenses() {
|
||||
CKANLicense ckanLicense = new CKANLicense();
|
||||
ckanLicense.list(-1,-1);
|
||||
ckanLicense.list(-1, -1);
|
||||
ArrayNode arrayNode = (ArrayNode) ckanLicense.getJsonNodeResult();
|
||||
return arrayNode;
|
||||
}
|
||||
|
||||
|
||||
public static boolean checkLicenseId(String licenseId) throws Exception {
|
||||
return checkLicenseId(getLicenses(), licenseId);
|
||||
}
|
||||
|
@ -33,15 +33,15 @@ public class CKANLicense extends CKAN {
|
|||
for(JsonNode jsonNode : arrayNode) {
|
||||
try {
|
||||
String id = jsonNode.get(ID_KEY).asText();
|
||||
if(id.compareTo(licenseId)==0) {
|
||||
if(id.compareTo(licenseId) == 0) {
|
||||
return true;
|
||||
}
|
||||
}catch (Exception e) {
|
||||
} catch(Exception e) {
|
||||
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}catch (Exception e) {
|
||||
} catch(Exception e) {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,7 +41,6 @@ public class CKANOrganization extends CKAN {
|
|||
protected static final String USERNAME_KEY = "username";
|
||||
protected static final String ROLE_KEY = "role";
|
||||
|
||||
|
||||
public CKANOrganization() {
|
||||
super();
|
||||
LIST = ORGANIZATION_LIST;
|
||||
|
@ -53,7 +52,7 @@ public class CKANOrganization extends CKAN {
|
|||
PURGE = ORGANIZATION_PURGE;
|
||||
}
|
||||
|
||||
protected static final String ORGANIZATION_PERMISSION_KEY = "permission";
|
||||
protected static final String ORGANIZATION_PERMISSION_KEY = "permission";
|
||||
protected static final String ORGANIZATION_PERMISSION_VALUE_READ = "read";
|
||||
|
||||
public void addUserToOrganisation(String gCubeUsername, String role) {
|
||||
|
@ -65,7 +64,7 @@ public class CKANOrganization extends CKAN {
|
|||
objectNode.put(ROLE_KEY, role);
|
||||
sendPostRequest(ORGANIZATION_MEMBER_CREATE, getAsString(objectNode));
|
||||
logger.debug("User {} successfully added to Organisation {} with role {}", ckanUsername, name, role);
|
||||
|
||||
|
||||
}
|
||||
|
||||
public static String getCKANOrganizationName() {
|
||||
|
|
|
@ -59,7 +59,7 @@ public class CKANPackage extends CKAN {
|
|||
public static final String ITEM_PURGE = CKAN.CKAN_API_PATH + "dataset_purge";
|
||||
|
||||
// limit in https://docs.ckan.org/en/latest/api/index.html#ckan.logic.action.get.package_search
|
||||
protected static final String ROWS_KEY = "rows";
|
||||
protected static final String ROWS_KEY = "rows";
|
||||
// offset in https://docs.ckan.org/en/latest/api/index.html#ckan.logic.action.get.package_search
|
||||
protected static final String START_KEY = "start";
|
||||
|
||||
|
@ -93,7 +93,7 @@ public class CKANPackage extends CKAN {
|
|||
|
||||
public static final String GROUPS_KEY = "groups";
|
||||
public static final String TAGS_KEY = "tags";
|
||||
|
||||
|
||||
protected final List<CKANResource> managedResources;
|
||||
|
||||
protected String itemID;
|
||||
|
@ -151,10 +151,10 @@ public class CKANPackage extends CKAN {
|
|||
if(licenseId == null || licenseId.isEmpty()) {
|
||||
throw new BadRequestException(
|
||||
"You must specify a license identifier for the item. License list can be retrieved using licence collection");
|
||||
}else {
|
||||
} else {
|
||||
try {
|
||||
CKANLicense.checkLicenseId(licenseId);
|
||||
}catch (Exception e) {
|
||||
} catch(Exception e) {
|
||||
throw new BadRequestException(
|
||||
"You must specify an existing license identifier for the item. License list can be retrieved using licence collection");
|
||||
}
|
||||
|
@ -169,8 +169,6 @@ public class CKANPackage extends CKAN {
|
|||
objectNode.remove(CAPACITY_KEY);
|
||||
}
|
||||
|
||||
|
||||
|
||||
CKANUser ckanUser = CKANUserCache.getCurrrentCKANUser();
|
||||
|
||||
objectNode.put(AUTHOR_KEY, ckanUser.getName());
|
||||
|
@ -245,11 +243,11 @@ public class CKANPackage extends CKAN {
|
|||
limit = 1000;
|
||||
}
|
||||
parameters.put(ROWS_KEY, String.valueOf(limit));
|
||||
|
||||
|
||||
if(offset < 0) {
|
||||
offset = 0;
|
||||
}
|
||||
parameters.put(START_KEY, String.valueOf(offset*limit));
|
||||
parameters.put(START_KEY, String.valueOf(offset * limit));
|
||||
|
||||
String organizationName = getOrganizationName();
|
||||
String organizationQueryString = String.format(ORGANIZATION_FILTER_TEMPLATE, organizationName);
|
||||
|
@ -269,10 +267,11 @@ public class CKANPackage extends CKAN {
|
|||
try {
|
||||
String name = node.get(NAME_KEY).asText();
|
||||
arrayNode.add(name);
|
||||
}catch (Exception e) {
|
||||
} catch(Exception e) {
|
||||
try {
|
||||
logger.error("Unable to get the ID of {}. the result will not be included in the result", mapper.writeValueAsString(node));
|
||||
}catch (Exception ex) {
|
||||
logger.error("Unable to get the ID of {}. the result will not be included in the result",
|
||||
mapper.writeValueAsString(node));
|
||||
} catch(Exception ex) {
|
||||
logger.error("", ex);
|
||||
}
|
||||
}
|
||||
|
@ -285,7 +284,7 @@ public class CKANPackage extends CKAN {
|
|||
for(CKANResource ckanResource : managedResources) {
|
||||
try {
|
||||
ckanResource.rollback();
|
||||
}catch (Exception e) {
|
||||
} catch(Exception e) {
|
||||
logger.error("Unable to rollback resource {} to the original value", ckanResource.getResourceID());
|
||||
}
|
||||
|
||||
|
@ -309,13 +308,13 @@ public class CKANPackage extends CKAN {
|
|||
if(jsonNode.has(EXTRAS_KEY)) {
|
||||
extras = (ArrayNode) jsonNode.get(EXTRAS_KEY);
|
||||
for(JsonNode extra : extras) {
|
||||
if(extra.has(EXTRAS_KEY_KEY) && extra.get(EXTRAS_KEY_KEY).asText().compareTo(key)==0) {
|
||||
if(extra.has(EXTRAS_KEY_KEY) && extra.get(EXTRAS_KEY_KEY).asText().compareTo(key) == 0) {
|
||||
((ObjectNode) extra).put(EXTRAS_VALUE_KEY, value);
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}else {
|
||||
} else {
|
||||
extras = mapper.createArrayNode();
|
||||
}
|
||||
|
||||
|
@ -341,11 +340,11 @@ public class CKANPackage extends CKAN {
|
|||
try {
|
||||
boolean socialPost = true;
|
||||
try {
|
||||
MultivaluedMap<String, String> queryParameters = uriInfo.getQueryParameters();
|
||||
MultivaluedMap<String,String> queryParameters = uriInfo.getQueryParameters();
|
||||
if(queryParameters.containsKey(GCatConstants.SOCIAL_POST_PARAMETER)) {
|
||||
socialPost = Boolean.parseBoolean(queryParameters.getFirst(GCatConstants.SOCIAL_POST_PARAMETER));
|
||||
}
|
||||
}catch (Exception e) {
|
||||
} catch(Exception e) {
|
||||
socialPost = true;
|
||||
}
|
||||
|
||||
|
@ -357,11 +356,13 @@ public class CKANPackage extends CKAN {
|
|||
socialService.setTags(arrayNode);
|
||||
socialService.setItemTitle(title);
|
||||
socialService.start();
|
||||
}else {
|
||||
} else {
|
||||
logger.info("The request explicitly disabled the Social Post.");
|
||||
}
|
||||
}catch (Exception e) {
|
||||
logger.warn("error dealing with Social Post. The service will not raise the exception belove. Please contact the administrator to let him know about this message.", e);
|
||||
} catch(Exception e) {
|
||||
logger.warn(
|
||||
"error dealing with Social Post. The service will not raise the exception belove. Please contact the administrator to let him know about this message.",
|
||||
e);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -421,9 +422,9 @@ public class CKANPackage extends CKAN {
|
|||
read();
|
||||
this.itemID = result.get(ID_KEY).asText();
|
||||
|
||||
Map<String, CKANResource> originalResources = new HashMap<>();
|
||||
ArrayNode originalResourcesarrayNode = (ArrayNode) result.get(RESOURCES_KEY);
|
||||
if(originalResources!=null) {
|
||||
Map<String,CKANResource> originalResources = new HashMap<>();
|
||||
ArrayNode originalResourcesarrayNode = (ArrayNode) result.get(RESOURCES_KEY);
|
||||
if(originalResources != null) {
|
||||
for(JsonNode resourceNode : originalResourcesarrayNode) {
|
||||
CKANResource ckanResource = new CKANResource(itemID);
|
||||
ckanResource.setPreviousRepresentation(resourceNode);
|
||||
|
@ -432,20 +433,19 @@ public class CKANPackage extends CKAN {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
if(jsonNode.has(RESOURCES_KEY)) {
|
||||
ArrayNode resourcesToBeSend = mapper.createArrayNode();
|
||||
ArrayNode receivedResources = (ArrayNode) jsonNode.get(RESOURCES_KEY);
|
||||
for(JsonNode resourceNode : receivedResources) {
|
||||
CKANResource ckanResource = new CKANResource(itemID);
|
||||
String resourceId = CKANResource.extractResourceID(resourceNode);
|
||||
if(resourceId!=null) {
|
||||
if(resourceId != null) {
|
||||
if(originalResources.containsKey(resourceId)) {
|
||||
ckanResource = originalResources.get(resourceId);
|
||||
originalResources.remove(resourceId);
|
||||
}else {
|
||||
throw new BadRequestException("The content cotains a resource with id " + resourceId + " which does not exists") ;
|
||||
} else {
|
||||
throw new BadRequestException(
|
||||
"The content cotains a resource with id " + resourceId + " which does not exists");
|
||||
}
|
||||
}
|
||||
resourceNode = ckanResource.createOrUpdate(resourceNode);
|
||||
|
|
|
@ -167,25 +167,25 @@ public class CKANResource extends CKAN {
|
|||
|
||||
protected String getFormat() {
|
||||
String format = null;
|
||||
if(originalFileExtension!=null) {
|
||||
if(originalFileExtension != null) {
|
||||
format = originalFileExtension;
|
||||
}else {
|
||||
} else {
|
||||
try {
|
||||
MimeType mimeTypeClzInstance = ALL_MIME_TYPES.forName(mimeType);
|
||||
format = mimeTypeClzInstance.getExtension();
|
||||
// List<String> extensions = mimeTypeClzInstance.getExtensions();
|
||||
if(format==null || format.compareTo("")==0) {
|
||||
if(format == null || format.compareTo("") == 0) {
|
||||
format = mimeType.split("/")[1].split(";")[0];
|
||||
}
|
||||
} catch(Exception e) {
|
||||
try {
|
||||
format = mimeType.split("/")[1].split(";")[0];
|
||||
}catch (Exception ex) {
|
||||
} catch(Exception ex) {
|
||||
format = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(format!=null && format.startsWith(".")) {
|
||||
if(format != null && format.startsWith(".")) {
|
||||
format = format.substring(1);
|
||||
}
|
||||
return format;
|
||||
|
@ -208,13 +208,13 @@ public class CKANResource extends CKAN {
|
|||
if(name != null) {
|
||||
objectNode.put(NAME_KEY, name);
|
||||
}
|
||||
|
||||
|
||||
if(mimeType != null) {
|
||||
objectNode.put(MIME_TYPE_KEY, mimeType);
|
||||
|
||||
if(!objectNode.has(FORMAT_KEY)) {
|
||||
String format = getFormat();
|
||||
if(format!=null) {
|
||||
if(format != null) {
|
||||
objectNode.put(FORMAT_KEY, format);
|
||||
}
|
||||
}
|
||||
|
@ -292,7 +292,7 @@ public class CKANResource extends CKAN {
|
|||
URL urlToCheck = url;
|
||||
try {
|
||||
urlToCheck = getFinalURL(url);
|
||||
}catch (Exception e) {
|
||||
} catch(Exception e) {
|
||||
// TODO Evaluate if we want to validate the URL. If th URL does not exists the service
|
||||
// could decide refuse the Resource Creation
|
||||
}
|
||||
|
|
|
@ -44,13 +44,10 @@ public class CKANUser extends CKAN {
|
|||
public static final String EMAIL = "email";
|
||||
public static final String PASSWORD = "password";
|
||||
|
||||
|
||||
private static final String API_KEY = "apikey";
|
||||
|
||||
public enum Role {
|
||||
MEMBER("Catalogue-Member", "member"),
|
||||
EDITOR("Catalogue-Editor", "editor"),
|
||||
ADMIN("Catalogue-Admin", "admin");
|
||||
MEMBER("Catalogue-Member", "member"), EDITOR("Catalogue-Editor", "editor"), ADMIN("Catalogue-Admin", "admin");
|
||||
|
||||
private final String portalRole;
|
||||
private final String ckanRole;
|
||||
|
@ -63,22 +60,22 @@ public class CKANUser extends CKAN {
|
|||
public String getPortalRole() {
|
||||
return portalRole;
|
||||
}
|
||||
|
||||
|
||||
public String getCkanRole() {
|
||||
return ckanRole;
|
||||
}
|
||||
|
||||
protected static final Map<String, Role> ROLE_BY_PORTAL_ROLE;
|
||||
protected static final Map<String, Role> ROLE_BY_CKAN_ROLE;
|
||||
|
||||
protected static final Map<String,Role> ROLE_BY_PORTAL_ROLE;
|
||||
protected static final Map<String,Role> ROLE_BY_CKAN_ROLE;
|
||||
|
||||
static {
|
||||
ROLE_BY_PORTAL_ROLE = new HashMap<String, Role>();
|
||||
ROLE_BY_PORTAL_ROLE = new HashMap<String,Role>();
|
||||
|
||||
// null or empty string identify a member
|
||||
ROLE_BY_PORTAL_ROLE.put(null, MEMBER);
|
||||
ROLE_BY_PORTAL_ROLE.put("", MEMBER);
|
||||
|
||||
ROLE_BY_CKAN_ROLE = new HashMap<String, Role>();
|
||||
ROLE_BY_CKAN_ROLE = new HashMap<String,Role>();
|
||||
|
||||
for(Role role : Role.values()) {
|
||||
ROLE_BY_PORTAL_ROLE.put(role.getPortalRole(), role);
|
||||
|
@ -108,17 +105,15 @@ public class CKANUser extends CKAN {
|
|||
|
||||
public CKANUser() {
|
||||
super();
|
||||
LIST = USER_LIST;
|
||||
LIST = USER_LIST;
|
||||
CREATE = USER_CREATE;
|
||||
READ = USER_SHOW;
|
||||
UPDATE = USER_UPDATE;
|
||||
PATCH = null;
|
||||
DELETE = USER_DELETE;
|
||||
PURGE = null;
|
||||
PURGE = null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public String create() {
|
||||
RandomString randomString = new RandomString(12);
|
||||
ObjectNode objectNode = mapper.createObjectNode();
|
||||
|
@ -147,7 +142,7 @@ public class CKANUser extends CKAN {
|
|||
if(objectNode.has(ABOUT)) {
|
||||
ckanJobTitle = objectNode.get(ABOUT).asText();
|
||||
}
|
||||
if(portalJobTitle.compareTo(ckanJobTitle)!=0){
|
||||
if(portalJobTitle.compareTo(ckanJobTitle) != 0) {
|
||||
objectNode = (ObjectNode) result;
|
||||
objectNode.put(ABOUT, portalJobTitle);
|
||||
return true;
|
||||
|
@ -167,7 +162,7 @@ public class CKANUser extends CKAN {
|
|||
if(objectNode.has(FULL_NAME)) {
|
||||
ckanFullname = objectNode.get(FULL_NAME).asText();
|
||||
}
|
||||
if(portalFullname.compareTo(ckanFullname)!=0){
|
||||
if(portalFullname.compareTo(ckanFullname) != 0) {
|
||||
objectNode = (ObjectNode) result;
|
||||
objectNode.put(FULL_NAME, portalFullname);
|
||||
objectNode.put(DISPLAY_NAME, portalFullname);
|
||||
|
@ -188,7 +183,7 @@ public class CKANUser extends CKAN {
|
|||
if(objectNode.has(EMAIL)) {
|
||||
ckanEmail = objectNode.get(EMAIL).asText();
|
||||
}
|
||||
if(portalEmail.compareTo(ckanEmail)!=0){
|
||||
if(portalEmail.compareTo(ckanEmail) != 0) {
|
||||
objectNode = (ObjectNode) result;
|
||||
objectNode.put(EMAIL, portalEmail);
|
||||
return true;
|
||||
|
@ -204,7 +199,7 @@ public class CKANUser extends CKAN {
|
|||
ObjectNode objectNode = (ObjectNode) result;
|
||||
boolean toBeUpdated = false;
|
||||
|
||||
toBeUpdated = checkAndSetEMail(objectNode) || toBeUpdated;
|
||||
toBeUpdated = checkAndSetEMail(objectNode) || toBeUpdated;
|
||||
toBeUpdated = checkAndSetFullName(objectNode) || toBeUpdated;
|
||||
toBeUpdated = checkAndSetJobTitle(objectNode) || toBeUpdated;
|
||||
|
||||
|
@ -217,7 +212,7 @@ public class CKANUser extends CKAN {
|
|||
protected void retrieve() {
|
||||
setApiKey(CKANUtility.getSysAdminAPI());
|
||||
try {
|
||||
if(name==null || name.compareTo("")==0) {
|
||||
if(name == null || name.compareTo("") == 0) {
|
||||
setName(getCKANUsername());
|
||||
}
|
||||
read();
|
||||
|
@ -225,10 +220,10 @@ public class CKANUser extends CKAN {
|
|||
} catch(WebApplicationException e) {
|
||||
if(e.getResponse().getStatusInfo() == Status.NOT_FOUND) {
|
||||
create();
|
||||
}else {
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
addUserToOrganization();
|
||||
}
|
||||
|
||||
|
@ -237,7 +232,7 @@ public class CKANUser extends CKAN {
|
|||
apiKey = result.get(API_KEY).asText();
|
||||
}
|
||||
|
||||
protected static String getCKANUsername(String username){
|
||||
protected static String getCKANUsername(String username) {
|
||||
if(username == null)
|
||||
return null;
|
||||
return username.trim().replaceAll("\\.", "_");
|
||||
|
@ -262,12 +257,12 @@ public class CKANUser extends CKAN {
|
|||
}
|
||||
|
||||
private Role getRole() {
|
||||
if(role==null) {
|
||||
if(role == null) {
|
||||
role = Role.MEMBER;
|
||||
List<String> roles = getPortalUser().getRoles();
|
||||
for(String portalRole : roles){
|
||||
for(String portalRole : roles) {
|
||||
Role gotRole = Role.getRoleFromPortalRole(portalRole);
|
||||
if(gotRole!=null && gotRole.ordinal()>role.ordinal()){
|
||||
if(gotRole != null && gotRole.ordinal() > role.ordinal()) {
|
||||
role = gotRole;
|
||||
}
|
||||
}
|
||||
|
@ -292,15 +287,15 @@ public class CKANUser extends CKAN {
|
|||
objectNode.put("object_type", "user");
|
||||
objectNode.put("capacity", "member");
|
||||
sendPostRequest(ADD_USER_TO_GROUP, getAsString(objectNode));
|
||||
}catch (WebApplicationException e) {
|
||||
} catch(WebApplicationException e) {
|
||||
throw e;
|
||||
}catch (Exception e) {
|
||||
} catch(Exception e) {
|
||||
throw new InternalServerErrorException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public PortalUser getPortalUser() {
|
||||
if(portalUser==null) {
|
||||
if(portalUser == null) {
|
||||
portalUser = new PortalUser();
|
||||
}
|
||||
return portalUser;
|
||||
|
|
|
@ -12,6 +12,8 @@ import javax.cache.expiry.CreatedExpiryPolicy;
|
|||
import javax.cache.expiry.Duration;
|
||||
import javax.cache.spi.CachingProvider;
|
||||
|
||||
import org.gcube.gcat.utils.ContextUtility;
|
||||
|
||||
public abstract class CKANUserCache {
|
||||
|
||||
private static final CacheManager cacheManager;
|
||||
|
@ -28,13 +30,9 @@ public abstract class CKANUserCache {
|
|||
|
||||
userCacheConfiguration = new MutableConfiguration<String,CKANUser>().setTypes(String.class, CKANUser.class)
|
||||
.setStoreByValue(false)
|
||||
.setExpiryPolicyFactory(CreatedExpiryPolicy.factoryOf(new Duration(TimeUnit.HOURS, 3)));
|
||||
.setExpiryPolicyFactory(CreatedExpiryPolicy.factoryOf(new Duration(TimeUnit.MINUTES, 1)));
|
||||
|
||||
userCachePerCkanInstance = new HashMap<String,Cache<String,CKANUser>>();
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
private CKANUserCache() {
|
||||
|
@ -43,16 +41,17 @@ public abstract class CKANUserCache {
|
|||
public static CKANUser getCurrrentCKANUser() {
|
||||
String ckanURL = CKANInstance.getInstance().getCKANURL();
|
||||
Cache<String,CKANUser> userCache = userCachePerCkanInstance.get(ckanURL);
|
||||
if(userCache==null) {
|
||||
if(userCache == null) {
|
||||
userCache = cacheManager.createCache(USERS_CACHE, userCacheConfiguration);
|
||||
userCachePerCkanInstance.put(ckanURL, userCache);
|
||||
}
|
||||
|
||||
String ckanUserName = CKANUser.getCKANUsername();
|
||||
CKANUser ckanUser = userCache.get(ckanUserName);
|
||||
if(ckanUser==null) {
|
||||
String gcubeUsername = ContextUtility.getUsername();
|
||||
CKANUser ckanUser = userCache.get(gcubeUsername);
|
||||
if(ckanUser == null) {
|
||||
ckanUser = new CKANUser();
|
||||
ckanUser.retrieve();
|
||||
userCache.put(gcubeUsername, ckanUser);
|
||||
}
|
||||
return ckanUser;
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@ public class CKANUtility {
|
|||
try {
|
||||
CKANUser ckanUser = CKANUserCache.getCurrrentCKANUser();
|
||||
return ckanUser.getApiKey();
|
||||
}catch (Exception e) {
|
||||
} catch(Exception e) {
|
||||
throw new InternalServerErrorException(e);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,7 +35,7 @@ public class ISProfile {
|
|||
private static Logger logger = LoggerFactory.getLogger(ISProfile.class);
|
||||
|
||||
protected ObjectMapper mapper;
|
||||
|
||||
|
||||
public ISProfile() {
|
||||
mapper = new ObjectMapper();
|
||||
}
|
||||
|
@ -154,7 +154,6 @@ public class ISProfile {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
public boolean createOrUpdate(String name, String xml) throws SAXException {
|
||||
try {
|
||||
MetadataUtility metadataUtility = new MetadataUtility();
|
||||
|
@ -168,7 +167,7 @@ public class ISProfile {
|
|||
}
|
||||
} catch(WebApplicationException e) {
|
||||
throw e;
|
||||
} catch (SAXException e) {
|
||||
} catch(SAXException e) {
|
||||
throw e;
|
||||
} catch(Exception e) {
|
||||
throw new InternalServerErrorException(e);
|
||||
|
|
|
@ -23,7 +23,7 @@ public class MetadataUtility {
|
|||
*/
|
||||
private Map<String,MetadataProfile> metadataProfiles;
|
||||
|
||||
public MetadataUtility() throws Exception{
|
||||
public MetadataUtility() throws Exception {
|
||||
dataCalogueMetadataFormatReader = new DataCalogueMetadataFormatReader();
|
||||
}
|
||||
|
||||
|
@ -31,8 +31,8 @@ public class MetadataUtility {
|
|||
dataCalogueMetadataFormatReader.validateProfile(xmlProfile);
|
||||
}
|
||||
|
||||
public Map<String, MetadataProfile> getMetadataProfiles() throws Exception{
|
||||
if(metadataProfiles==null) {
|
||||
public Map<String,MetadataProfile> getMetadataProfiles() throws Exception {
|
||||
if(metadataProfiles == null) {
|
||||
metadataProfiles = new HashMap<>();
|
||||
List<MetadataProfile> list = dataCalogueMetadataFormatReader.getListOfMetadataProfiles();
|
||||
for(MetadataProfile profile : list) {
|
||||
|
@ -54,13 +54,12 @@ public class MetadataUtility {
|
|||
|
||||
public MetadataFormat getMetadataFormat(String profileName) throws Exception {
|
||||
MetadataProfile profile = getMetadataProfiles().get(profileName);
|
||||
if(profile!=null) {
|
||||
if(profile != null) {
|
||||
return dataCalogueMetadataFormatReader.getMetadataFormatForMetadataProfile(profile);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public List<NamespaceCategory> getNamespaceCategories() throws Exception {
|
||||
return dataCalogueMetadataFormatReader.getListOfNamespaceCategories();
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@ public class BaseREST {
|
|||
|
||||
@Context
|
||||
protected UriInfo uriInfo;
|
||||
|
||||
|
||||
protected static final String LOCATION_HEADER = "Location";
|
||||
|
||||
protected void setCalledMethod(String method) {
|
||||
|
@ -24,8 +24,7 @@ public class BaseREST {
|
|||
|
||||
protected ResponseBuilder addLocation(ResponseBuilder responseBuilder, String id) {
|
||||
return responseBuilder.header(LOCATION_HEADER,
|
||||
String.format("%s/%s", uriInfo.getAbsolutePath().toString(), id)
|
||||
);
|
||||
String.format("%s/%s", uriInfo.getAbsolutePath().toString(), id));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ import org.gcube.gcat.persistence.ckan.CKANGroup;
|
|||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
@Path(Group.GROUPS)
|
||||
public class Group extends REST<CKANGroup> implements org.gcube.gcat.api.interfaces.Group<Response,Response>{
|
||||
public class Group extends REST<CKANGroup> implements org.gcube.gcat.api.interfaces.Group<Response,Response> {
|
||||
|
||||
protected static final String GROUP_ID_PARAMETER = "GROUP_ID";
|
||||
|
||||
|
@ -86,7 +86,7 @@ public class Group extends REST<CKANGroup> implements org.gcube.gcat.api.interfa
|
|||
public Response purge(@PathParam(GROUP_ID_PARAMETER) String id) {
|
||||
return delete(id, true);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Response delete(String name, boolean purge) {
|
||||
return delete(name, new Boolean(purge));
|
||||
|
|
|
@ -22,7 +22,7 @@ import org.gcube.gcat.persistence.ckan.CKANPackage;
|
|||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
@Path(Item.ITEMS)
|
||||
public class Item extends REST<CKANPackage> implements org.gcube.gcat.api.interfaces.Item<Response,Response>{
|
||||
public class Item extends REST<CKANPackage> implements org.gcube.gcat.api.interfaces.Item<Response,Response> {
|
||||
|
||||
public static final String ITEM_ID_PARAMETER = "ITEM_ID";
|
||||
|
||||
|
@ -88,7 +88,7 @@ public class Item extends REST<CKANPackage> implements org.gcube.gcat.api.interf
|
|||
public Response purge(@PathParam(ITEM_ID_PARAMETER) String id) {
|
||||
return super.purge(id);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Response delete(String name, boolean purge) throws WebServiceException {
|
||||
return delete(name, new Boolean(purge));
|
||||
|
|
|
@ -12,7 +12,7 @@ import org.gcube.gcat.persistence.ckan.CKANLicense;
|
|||
*/
|
||||
@Path(License.LICENSES)
|
||||
public class License extends REST<CKANLicense> implements org.gcube.gcat.api.interfaces.License {
|
||||
|
||||
|
||||
public License() {
|
||||
super(LICENSES, null, CKANLicense.class);
|
||||
}
|
||||
|
|
|
@ -39,7 +39,6 @@ public class Profile extends BaseREST implements org.gcube.gcat.api.interfaces.P
|
|||
|
||||
public static final String CANNOT_MANAGE_PROFILE_SCHEMA = "You cannot manage the profile schema";
|
||||
|
||||
|
||||
static {
|
||||
StringBuilder validationError = new StringBuilder();
|
||||
validationError.append("The Profile is not valid because of the following error at validation time:\n%s\n\n");
|
||||
|
|
|
@ -9,7 +9,7 @@ import org.gcube.gcat.ResourceInitializer;
|
|||
import org.gcube.gcat.api.interfaces.CRUD;
|
||||
import org.gcube.gcat.persistence.ckan.CKAN;
|
||||
|
||||
public class REST<C extends CKAN> extends BaseREST implements CRUD<Response, Response> {
|
||||
public class REST<C extends CKAN> extends BaseREST implements CRUD<Response,Response> {
|
||||
|
||||
protected final String COLLECTION_PARAMETER;
|
||||
protected final String ID_PARAMETER;
|
||||
|
@ -64,7 +64,6 @@ public class REST<C extends CKAN> extends BaseREST implements CRUD<Response, Res
|
|||
return ckan.update(json);
|
||||
}
|
||||
|
||||
|
||||
public String patch(String id, String json) {
|
||||
setCalledMethod("PATCH /" + COLLECTION_PARAMETER + "/{" + ID_PARAMETER + "}");
|
||||
C ckan = getInstance();
|
||||
|
@ -93,5 +92,4 @@ public class REST<C extends CKAN> extends BaseREST implements CRUD<Response, Res
|
|||
return delete(id, true);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -78,7 +78,7 @@ public class Resource extends BaseREST implements org.gcube.gcat.api.interfaces.
|
|||
@Produces(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8)
|
||||
public String patch(@PathParam(ITEM_ID_PARAMETER) String itemID,
|
||||
@PathParam(RESOURCE_ID_PARAMETER) String resourceID, String json) {
|
||||
setCalledMethod("PATCH /" + COLLECTION + "/{" + RESOURCE_ID_PARAMETER + "}");
|
||||
setCalledMethod("PATCH /" + COLLECTION + "/{" + RESOURCE_ID_PARAMETER + "}");
|
||||
CKANResource ckanResource = new CKANResource(itemID);
|
||||
ckanResource.setResourceID(resourceID);
|
||||
return ckanResource.patch(json);
|
||||
|
@ -88,7 +88,7 @@ public class Resource extends BaseREST implements org.gcube.gcat.api.interfaces.
|
|||
@Path("/{" + RESOURCE_ID_PARAMETER + "}")
|
||||
public Response delete(@PathParam(ITEM_ID_PARAMETER) String itemID,
|
||||
@PathParam(RESOURCE_ID_PARAMETER) String resourceID) {
|
||||
setCalledMethod("DELETE /" + COLLECTION + "/{" + RESOURCE_ID_PARAMETER + "}");
|
||||
setCalledMethod("DELETE /" + COLLECTION + "/{" + RESOURCE_ID_PARAMETER + "}");
|
||||
CKANResource ckanResource = new CKANResource(itemID);
|
||||
ckanResource.setResourceID(resourceID);
|
||||
ckanResource.delete(false);
|
||||
|
|
|
@ -10,8 +10,8 @@ import javax.ws.rs.ext.Provider;
|
|||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
@Provider
|
||||
public class ScienceCatalogueExceptionMapper implements ExceptionMapper<Exception> {
|
||||
@Provider
|
||||
public class ScienceCatalogueExceptionMapper implements ExceptionMapper<Exception> {
|
||||
|
||||
@Override
|
||||
public Response toResponse(Exception exception) {
|
||||
|
@ -19,15 +19,14 @@ public class ScienceCatalogueExceptionMapper implements ExceptionMapper<Excepti
|
|||
Status status = Status.INTERNAL_SERVER_ERROR;
|
||||
String exceptionMessage = exception.getMessage();
|
||||
try {
|
||||
if(exception.getCause()!=null) {
|
||||
if(exception.getCause() != null) {
|
||||
exceptionMessage = exception.getCause().getMessage();
|
||||
}
|
||||
}catch (Exception e) {
|
||||
} catch(Exception e) {
|
||||
exceptionMessage = exception.getMessage();
|
||||
}
|
||||
MediaType mediaType = MediaType.TEXT_PLAIN_TYPE;
|
||||
|
||||
|
||||
if(WebApplicationException.class.isAssignableFrom(exception.getClass())) {
|
||||
Response gotResponse = ((WebApplicationException) exception).getResponse();
|
||||
status = Status.fromStatusCode(gotResponse.getStatusInfo().getStatusCode());
|
||||
|
|
|
@ -28,7 +28,7 @@ public class User extends REST<CKANUser> implements org.gcube.gcat.api.interface
|
|||
@GET
|
||||
@Produces(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8)
|
||||
public String list() {
|
||||
return super.list(-1,-1);
|
||||
return super.list(-1, -1);
|
||||
}
|
||||
|
||||
@POST
|
||||
|
|
|
@ -82,7 +82,7 @@ public class PortalUser {
|
|||
String ret = HTTPUtility.getResultAsString(httpURLConnection);
|
||||
|
||||
oAuthUserProfile = objectMapper.readTree(ret);
|
||||
}catch (Exception e) {
|
||||
} catch(Exception e) {
|
||||
throw new InternalServerErrorException(e);
|
||||
}
|
||||
}
|
||||
|
@ -103,14 +103,13 @@ public class PortalUser {
|
|||
return eMail;
|
||||
}
|
||||
|
||||
|
||||
public List<String> getRoles() {
|
||||
if(roles == null) {
|
||||
JsonNode jsonNode = getOAuthUserProfile().get(OAUTH_USER_PROFILE_ROLES_KEY);
|
||||
roles = new ArrayList<String>();
|
||||
if(jsonNode.isArray()) {
|
||||
ArrayNode arrayNode = (ArrayNode) jsonNode;
|
||||
if(arrayNode.size()>0) {
|
||||
if(arrayNode.size() > 0) {
|
||||
Iterator<JsonNode> iterator = arrayNode.iterator();
|
||||
while(iterator.hasNext()) {
|
||||
roles.add(iterator.next().asText());
|
||||
|
@ -120,7 +119,7 @@ public class PortalUser {
|
|||
}
|
||||
return roles;
|
||||
}
|
||||
|
||||
|
||||
public String getJobTitle() {
|
||||
if(jobTitle == null) {
|
||||
jobTitle = getOAuthUserProfile().get(OAUTH_USER_PROFILE_JOB_TITLE_KEY).asText();
|
||||
|
|
|
@ -28,7 +28,7 @@ public class SocialService {
|
|||
private String serviceBasePath;
|
||||
|
||||
// Map<String contextFullName, SocialService socialService>
|
||||
private static Map<String, SocialService> socialServicePerContext;
|
||||
private static Map<String,SocialService> socialServicePerContext;
|
||||
|
||||
static {
|
||||
socialServicePerContext = new HashMap<>();
|
||||
|
@ -37,7 +37,7 @@ public class SocialService {
|
|||
public static SocialService getSocialService() throws Exception {
|
||||
String contex = ContextUtility.getCurrentContext();
|
||||
SocialService socialService = socialServicePerContext.get(contex);
|
||||
if(socialService==null) {
|
||||
if(socialService == null) {
|
||||
socialService = new SocialService();
|
||||
socialServicePerContext.put(contex, socialService);
|
||||
}
|
||||
|
|
|
@ -24,15 +24,15 @@ public class Constants {
|
|||
*/
|
||||
protected static final Map<String,String> applicationTokens;
|
||||
|
||||
|
||||
public static String getCatalogueApplicationToken() {
|
||||
try {
|
||||
return applicationTokens.get(ContextUtility.getCurrentContext());
|
||||
}catch (Exception e) {
|
||||
throw new InternalServerErrorException("Unable to retrieve Application Token for context " + ContextUtility.getCurrentContext(), e);
|
||||
} catch(Exception e) {
|
||||
throw new InternalServerErrorException(
|
||||
"Unable to retrieve Application Token for context " + ContextUtility.getCurrentContext(), e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static {
|
||||
try {
|
||||
applicationTokens = new HashMap<>();
|
||||
|
@ -46,7 +46,7 @@ public class Constants {
|
|||
String applicationToken = properties.getProperty(context);
|
||||
applicationTokens.put(context, applicationToken);
|
||||
}
|
||||
}catch (Exception e) {
|
||||
} catch(Exception e) {
|
||||
throw new WebApplicationException(e);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ public class ContextUtility {
|
|||
|
||||
private static Logger logger = LoggerFactory.getLogger(ContextUtility.class);
|
||||
|
||||
public static void setContext(String token) throws ObjectNotFound, Exception{
|
||||
public static void setContext(String token) throws ObjectNotFound, Exception {
|
||||
SecurityTokenProvider.instance.set(token);
|
||||
AuthorizationEntry authorizationEntry = Constants.authorizationService().get(token);
|
||||
ClientInfo clientInfo = authorizationEntry.getClientInfo();
|
||||
|
@ -36,9 +36,9 @@ public class ContextUtility {
|
|||
try {
|
||||
String token = SecurityTokenProvider.instance.get();
|
||||
return Constants.authorizationService().get(token).getContext();
|
||||
}catch (Exception e) {
|
||||
} catch(Exception e) {
|
||||
String context = ScopeProvider.instance.get();
|
||||
if(context!=null) {
|
||||
if(context != null) {
|
||||
return context;
|
||||
}
|
||||
throw new InternalServerErrorException(e);
|
||||
|
@ -48,14 +48,14 @@ public class ContextUtility {
|
|||
public static ClientInfo getClientInfo() {
|
||||
try {
|
||||
Caller caller = AuthorizationProvider.instance.get();
|
||||
if(caller!=null){
|
||||
if(caller != null) {
|
||||
return caller.getClient();
|
||||
}else{
|
||||
} else {
|
||||
String token = SecurityTokenProvider.instance.get();
|
||||
AuthorizationEntry authorizationEntry = Constants.authorizationService().get(token);
|
||||
return authorizationEntry.getClientInfo();
|
||||
}
|
||||
}catch (Exception e) {
|
||||
} catch(Exception e) {
|
||||
throw new InternalServerErrorException(e);
|
||||
}
|
||||
}
|
||||
|
@ -65,7 +65,7 @@ public class ContextUtility {
|
|||
public static String getUsername() {
|
||||
try {
|
||||
return getClientInfo().getId();
|
||||
} catch (Exception e) {
|
||||
} catch(Exception e) {
|
||||
logger.error(GET_USERNAME_ERROR);
|
||||
throw new InternalServerErrorException(GET_USERNAME_ERROR, e);
|
||||
}
|
||||
|
@ -74,8 +74,8 @@ public class ContextUtility {
|
|||
public static boolean isApplication() {
|
||||
try {
|
||||
ClientInfo clientInfo = getClientInfo();
|
||||
return clientInfo.getType() == ClientType.EXTERNALSERVICE ;
|
||||
}catch (Exception e) {
|
||||
return clientInfo.getType() == ClientType.EXTERNALSERVICE;
|
||||
} catch(Exception e) {
|
||||
throw new InternalServerErrorException(e);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,7 +33,8 @@ public class HTTPUtility {
|
|||
return result;
|
||||
}
|
||||
|
||||
public static GXHTTPStringRequest createGXHTTPStringRequest(String url, String path, boolean post) throws UnsupportedEncodingException {
|
||||
public static GXHTTPStringRequest createGXHTTPStringRequest(String url, String path, boolean post)
|
||||
throws UnsupportedEncodingException {
|
||||
GXHTTPStringRequest gxhttpStringRequest = GXHTTPStringRequest.newRequest(url);
|
||||
gxhttpStringRequest.from(Constants.CATALOGUE_NAME);
|
||||
if(post) {
|
||||
|
@ -45,7 +46,7 @@ public class HTTPUtility {
|
|||
}
|
||||
|
||||
public static String getResultAsString(HttpURLConnection httpURLConnection) throws IOException {
|
||||
int responseCode = httpURLConnection.getResponseCode();
|
||||
int responseCode = httpURLConnection.getResponseCode();
|
||||
if(responseCode >= Status.BAD_REQUEST.getStatusCode()) {
|
||||
Status status = Status.fromStatusCode(responseCode);
|
||||
InputStream inputStream = httpURLConnection.getErrorStream();
|
||||
|
|
|
@ -6,30 +6,30 @@ import java.util.Random;
|
|||
* @author Lucio Lelii (ISTI - CNR)
|
||||
*/
|
||||
public class RandomString {
|
||||
|
||||
|
||||
private static final char[] symbols;
|
||||
|
||||
|
||||
static {
|
||||
StringBuilder tmp = new StringBuilder();
|
||||
for (char ch = '0'; ch <= '9'; ++ch)
|
||||
for(char ch = '0'; ch <= '9'; ++ch)
|
||||
tmp.append(ch);
|
||||
for (char ch = 'a'; ch <= 'z'; ++ch)
|
||||
for(char ch = 'a'; ch <= 'z'; ++ch)
|
||||
tmp.append(ch);
|
||||
symbols = tmp.toString().toCharArray();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private final Random random = new Random();
|
||||
|
||||
|
||||
private final char[] buf;
|
||||
|
||||
|
||||
public RandomString(int length) {
|
||||
if (length < 1)
|
||||
if(length < 1)
|
||||
throw new IllegalArgumentException("length < 1: " + length);
|
||||
buf = new char[length];
|
||||
}
|
||||
|
||||
|
||||
public String nextString() {
|
||||
for (int idx = 0; idx < buf.length; ++idx)
|
||||
for(int idx = 0; idx < buf.length; ++idx)
|
||||
buf[idx] = symbols[random.nextInt(symbols.length)];
|
||||
return new String(buf);
|
||||
}
|
||||
|
|
|
@ -33,9 +33,9 @@ public class URIResolver {
|
|||
|
||||
protected StringBuilder getStringBuilder(InputStream inputStream) throws IOException {
|
||||
StringBuilder result = new StringBuilder();
|
||||
try (BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream))) {
|
||||
try(BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream))) {
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
while((line = reader.readLine()) != null) {
|
||||
result.append(line);
|
||||
}
|
||||
}
|
||||
|
@ -52,14 +52,14 @@ public class URIResolver {
|
|||
requestContent.put(ENTITY_TYPE, DATASET);
|
||||
requestContent.put(ENTITY_NAME, name);
|
||||
|
||||
GXHTTPStringRequest gxhttpStringRequest = GXHTTPStringRequest.newRequest(uriResolverURL);
|
||||
GXHTTPStringRequest gxhttpStringRequest = GXHTTPStringRequest.newRequest(uriResolverURL);
|
||||
gxhttpStringRequest.from(Constants.CATALOGUE_NAME);
|
||||
gxhttpStringRequest.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON);
|
||||
gxhttpStringRequest.isExternalCall(true);
|
||||
String body = mapper.writeValueAsString(requestContent);
|
||||
HttpURLConnection httpURLConnection = gxhttpStringRequest.post(body);
|
||||
|
||||
if(httpURLConnection.getResponseCode()!=200) {
|
||||
if(httpURLConnection.getResponseCode() != 200) {
|
||||
throw new InternalServerErrorException("Unable to get Item URL via URI Resolver");
|
||||
}
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ import org.gcube.common.storagehub.model.Metadata;
|
|||
import org.gcube.storagehub.MetadataMatcher;
|
||||
|
||||
public class CatalogueMetadata implements MetadataMatcher {
|
||||
|
||||
|
||||
public static final String ORIGINAL_URL = "OriginalURL";
|
||||
public static final String ORIGINAL_NAME = "OriginalName";
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ public class CatalogueStorageHubManagement {
|
|||
|
||||
protected StorageHubManagement storageHubManagement;
|
||||
|
||||
protected String originalFilename;
|
||||
protected String originalFilename;
|
||||
protected String mimeType;
|
||||
|
||||
public String getOriginalFilename() {
|
||||
|
@ -27,7 +27,7 @@ public class CatalogueStorageHubManagement {
|
|||
public String getMimeType() {
|
||||
return mimeType;
|
||||
}
|
||||
|
||||
|
||||
public CatalogueStorageHubManagement() {
|
||||
this.storageHubManagement = new StorageHubManagement();
|
||||
}
|
||||
|
@ -52,14 +52,15 @@ public class CatalogueStorageHubManagement {
|
|||
CatalogueMetadata catalogueMetadata = new CatalogueMetadata(itemID);
|
||||
storageHubManagement.setCheckMetadata(catalogueMetadata);
|
||||
Metadata metadata = catalogueMetadata.getMetadata(persistedURL, originalFilename, resourceID);
|
||||
persistedURL = storageHubManagement.persistFile(httpURLConnection.getInputStream(), resourceID, mimeType, metadata);
|
||||
persistedURL = storageHubManagement.persistFile(httpURLConnection.getInputStream(), resourceID, mimeType,
|
||||
metadata);
|
||||
mimeType = storageHubManagement.getMimeType();
|
||||
return persistedURL;
|
||||
} finally {
|
||||
applicationMode.end();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void deleteResourcePersistence(String itemID, String resourceID, String mimeType) throws Exception {
|
||||
ApplicationMode applicationMode = new ApplicationMode(Constants.getCatalogueApplicationToken());
|
||||
try {
|
||||
|
@ -72,7 +73,6 @@ public class CatalogueStorageHubManagement {
|
|||
applicationMode.end();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected void internalAddRevisionID(String resourceID, String revisionID) throws Exception {
|
||||
FileContainer fileContainer = storageHubManagement.getCreatedFile();
|
||||
|
@ -91,7 +91,7 @@ public class CatalogueStorageHubManagement {
|
|||
FileContainer createdfile = storageHubManagement.getCreatedFile();
|
||||
createdfile.rename(resourceID);
|
||||
internalAddRevisionID(resourceID, revisionID);
|
||||
}finally {
|
||||
} finally {
|
||||
applicationMode.end();
|
||||
}
|
||||
|
||||
|
@ -102,7 +102,7 @@ public class CatalogueStorageHubManagement {
|
|||
try {
|
||||
applicationMode.start();
|
||||
internalAddRevisionID(resourceID, revisionID);
|
||||
}finally {
|
||||
} finally {
|
||||
applicationMode.end();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,11 +12,10 @@ public class CKANGroupTest extends ContextTest {
|
|||
@Test
|
||||
public void list() throws Exception {
|
||||
CKANGroup ckanGroup = new CKANGroup();
|
||||
String ret = ckanGroup.list(10,0);
|
||||
String ret = ckanGroup.list(10, 0);
|
||||
logger.debug("{}", ret);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void read() throws Exception {
|
||||
CKANGroup ckanGroup = new CKANGroup();
|
||||
|
|
Loading…
Reference in New Issue