From 11cd97e1c7ca83e96ee6c8c688e05b3c46939bfc Mon Sep 17 00:00:00 2001 From: Luca Frosini Date: Mon, 16 Sep 2019 14:48:18 +0200 Subject: [PATCH] Formatted code --- .../org/gcube/gcat/oldutils/CustomField.java | 3 -- .../org/gcube/gcat/persistence/ckan/CKAN.java | 10 ++-- .../gcat/persistence/ckan/CKANGroup.java | 23 ++++---- .../gcat/persistence/ckan/CKANInstance.java | 10 ++-- .../gcat/persistence/ckan/CKANLicense.java | 12 ++--- .../persistence/ckan/CKANOrganization.java | 5 +- .../gcat/persistence/ckan/CKANPackage.java | 54 +++++++++---------- .../gcat/persistence/ckan/CKANResource.java | 16 +++--- .../gcube/gcat/persistence/ckan/CKANUser.java | 53 +++++++++--------- .../gcat/persistence/ckan/CKANUserCache.java | 17 +++--- .../gcat/persistence/ckan/CKANUtility.java | 2 +- .../org/gcube/gcat/profile/ISProfile.java | 5 +- .../gcube/gcat/profile/MetadataUtility.java | 9 ++-- .../java/org/gcube/gcat/rest/BaseREST.java | 5 +- src/main/java/org/gcube/gcat/rest/Group.java | 4 +- src/main/java/org/gcube/gcat/rest/Item.java | 4 +- .../java/org/gcube/gcat/rest/License.java | 2 +- .../java/org/gcube/gcat/rest/Profile.java | 1 - src/main/java/org/gcube/gcat/rest/REST.java | 4 +- .../java/org/gcube/gcat/rest/Resource.java | 4 +- .../rest/ScienceCatalogueExceptionMapper.java | 9 ++-- src/main/java/org/gcube/gcat/rest/User.java | 2 +- .../org/gcube/gcat/social/PortalUser.java | 7 ++- .../org/gcube/gcat/social/SocialService.java | 4 +- .../java/org/gcube/gcat/utils/Constants.java | 10 ++-- .../org/gcube/gcat/utils/ContextUtility.java | 18 +++---- .../org/gcube/gcat/utils/HTTPUtility.java | 5 +- .../org/gcube/gcat/utils/RandomString.java | 22 ++++---- .../org/gcube/gcat/utils/URIResolver.java | 8 +-- .../gcat/workspace/CatalogueMetadata.java | 2 +- .../CatalogueStorageHubManagement.java | 14 ++--- .../gcat/persistence/ckan/CKANGroupTest.java | 3 +- 32 files changed, 165 insertions(+), 182 deletions(-) diff --git a/src/main/java/org/gcube/gcat/oldutils/CustomField.java b/src/main/java/org/gcube/gcat/oldutils/CustomField.java index 96adcc5..5fc5e6f 100644 --- a/src/main/java/org/gcube/gcat/oldutils/CustomField.java +++ b/src/main/java/org/gcube/gcat/oldutils/CustomField.java @@ -17,7 +17,6 @@ public class CustomField implements Comparable { 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 { } } - 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 { this.qualifiedKey = qualifiedKey; } - public int getIndexCategory() { return indexCategory; } diff --git a/src/main/java/org/gcube/gcat/persistence/ckan/CKAN.java b/src/main/java/org/gcube/gcat/persistence/ckan/CKAN.java index 01c2917..265f534 100644 --- a/src/main/java/org/gcube/gcat/persistence/ckan/CKAN.java +++ b/src/main/java/org/gcube/gcat/persistence/ckan/CKAN.java @@ -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); diff --git a/src/main/java/org/gcube/gcat/persistence/ckan/CKANGroup.java b/src/main/java/org/gcube/gcat/persistence/ckan/CKANGroup.java index e6c3ebc..2dfa4a5 100644 --- a/src/main/java/org/gcube/gcat/persistence/ckan/CKANGroup.java +++ b/src/main/java/org/gcube/gcat/persistence/ckan/CKANGroup.java @@ -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 getGroups() { - if(result==null) { + if(result == null) { read(); } List groups = new ArrayList(); @@ -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 iterator = arrayNode.iterator(); while(iterator.hasNext()) { groups.add(iterator.next().asText()); diff --git a/src/main/java/org/gcube/gcat/persistence/ckan/CKANInstance.java b/src/main/java/org/gcube/gcat/persistence/ckan/CKANInstance.java index 2cb237b..56daf36 100644 --- a/src/main/java/org/gcube/gcat/persistence/ckan/CKANInstance.java +++ b/src/main/java/org/gcube/gcat/persistence/ckan/CKANInstance.java @@ -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 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 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); diff --git a/src/main/java/org/gcube/gcat/persistence/ckan/CKANLicense.java b/src/main/java/org/gcube/gcat/persistence/ckan/CKANLicense.java index 775c984..0a6389e 100644 --- a/src/main/java/org/gcube/gcat/persistence/ckan/CKANLicense.java +++ b/src/main/java/org/gcube/gcat/persistence/ckan/CKANLicense.java @@ -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; } } diff --git a/src/main/java/org/gcube/gcat/persistence/ckan/CKANOrganization.java b/src/main/java/org/gcube/gcat/persistence/ckan/CKANOrganization.java index cc0bb3d..bd09bc1 100644 --- a/src/main/java/org/gcube/gcat/persistence/ckan/CKANOrganization.java +++ b/src/main/java/org/gcube/gcat/persistence/ckan/CKANOrganization.java @@ -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() { diff --git a/src/main/java/org/gcube/gcat/persistence/ckan/CKANPackage.java b/src/main/java/org/gcube/gcat/persistence/ckan/CKANPackage.java index 7792c40..d335f2d 100644 --- a/src/main/java/org/gcube/gcat/persistence/ckan/CKANPackage.java +++ b/src/main/java/org/gcube/gcat/persistence/ckan/CKANPackage.java @@ -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 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 queryParameters = uriInfo.getQueryParameters(); + MultivaluedMap 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 originalResources = new HashMap<>(); - ArrayNode originalResourcesarrayNode = (ArrayNode) result.get(RESOURCES_KEY); - if(originalResources!=null) { + Map 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); diff --git a/src/main/java/org/gcube/gcat/persistence/ckan/CKANResource.java b/src/main/java/org/gcube/gcat/persistence/ckan/CKANResource.java index 735e816..f28f23b 100644 --- a/src/main/java/org/gcube/gcat/persistence/ckan/CKANResource.java +++ b/src/main/java/org/gcube/gcat/persistence/ckan/CKANResource.java @@ -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 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 } diff --git a/src/main/java/org/gcube/gcat/persistence/ckan/CKANUser.java b/src/main/java/org/gcube/gcat/persistence/ckan/CKANUser.java index 56b9281..2b2c3ab 100644 --- a/src/main/java/org/gcube/gcat/persistence/ckan/CKANUser.java +++ b/src/main/java/org/gcube/gcat/persistence/ckan/CKANUser.java @@ -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 ROLE_BY_PORTAL_ROLE; - protected static final Map ROLE_BY_CKAN_ROLE; + + protected static final Map ROLE_BY_PORTAL_ROLE; + protected static final Map ROLE_BY_CKAN_ROLE; static { - ROLE_BY_PORTAL_ROLE = new HashMap(); + ROLE_BY_PORTAL_ROLE = new HashMap(); // 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(); + ROLE_BY_CKAN_ROLE = new HashMap(); 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 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; diff --git a/src/main/java/org/gcube/gcat/persistence/ckan/CKANUserCache.java b/src/main/java/org/gcube/gcat/persistence/ckan/CKANUserCache.java index 20e3ff0..5a94f8a 100644 --- a/src/main/java/org/gcube/gcat/persistence/ckan/CKANUserCache.java +++ b/src/main/java/org/gcube/gcat/persistence/ckan/CKANUserCache.java @@ -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().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>(); - - - - } private CKANUserCache() { @@ -43,16 +41,17 @@ public abstract class CKANUserCache { public static CKANUser getCurrrentCKANUser() { String ckanURL = CKANInstance.getInstance().getCKANURL(); Cache 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; } diff --git a/src/main/java/org/gcube/gcat/persistence/ckan/CKANUtility.java b/src/main/java/org/gcube/gcat/persistence/ckan/CKANUtility.java index b3f21d3..5602bcd 100644 --- a/src/main/java/org/gcube/gcat/persistence/ckan/CKANUtility.java +++ b/src/main/java/org/gcube/gcat/persistence/ckan/CKANUtility.java @@ -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); } } diff --git a/src/main/java/org/gcube/gcat/profile/ISProfile.java b/src/main/java/org/gcube/gcat/profile/ISProfile.java index fdbeb87..38359bd 100644 --- a/src/main/java/org/gcube/gcat/profile/ISProfile.java +++ b/src/main/java/org/gcube/gcat/profile/ISProfile.java @@ -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); diff --git a/src/main/java/org/gcube/gcat/profile/MetadataUtility.java b/src/main/java/org/gcube/gcat/profile/MetadataUtility.java index eeb6ff5..ed14931 100644 --- a/src/main/java/org/gcube/gcat/profile/MetadataUtility.java +++ b/src/main/java/org/gcube/gcat/profile/MetadataUtility.java @@ -23,7 +23,7 @@ public class MetadataUtility { */ private Map metadataProfiles; - public MetadataUtility() throws Exception{ + public MetadataUtility() throws Exception { dataCalogueMetadataFormatReader = new DataCalogueMetadataFormatReader(); } @@ -31,8 +31,8 @@ public class MetadataUtility { dataCalogueMetadataFormatReader.validateProfile(xmlProfile); } - public Map getMetadataProfiles() throws Exception{ - if(metadataProfiles==null) { + public Map getMetadataProfiles() throws Exception { + if(metadataProfiles == null) { metadataProfiles = new HashMap<>(); List 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 getNamespaceCategories() throws Exception { return dataCalogueMetadataFormatReader.getListOfNamespaceCategories(); diff --git a/src/main/java/org/gcube/gcat/rest/BaseREST.java b/src/main/java/org/gcube/gcat/rest/BaseREST.java index 6405e40..1830510 100644 --- a/src/main/java/org/gcube/gcat/rest/BaseREST.java +++ b/src/main/java/org/gcube/gcat/rest/BaseREST.java @@ -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)); } } diff --git a/src/main/java/org/gcube/gcat/rest/Group.java b/src/main/java/org/gcube/gcat/rest/Group.java index a89e814..e9e8b03 100644 --- a/src/main/java/org/gcube/gcat/rest/Group.java +++ b/src/main/java/org/gcube/gcat/rest/Group.java @@ -22,7 +22,7 @@ import org.gcube.gcat.persistence.ckan.CKANGroup; * @author Luca Frosini (ISTI - CNR) */ @Path(Group.GROUPS) -public class Group extends REST implements org.gcube.gcat.api.interfaces.Group{ +public class Group extends REST implements org.gcube.gcat.api.interfaces.Group { protected static final String GROUP_ID_PARAMETER = "GROUP_ID"; @@ -86,7 +86,7 @@ public class Group extends REST 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)); diff --git a/src/main/java/org/gcube/gcat/rest/Item.java b/src/main/java/org/gcube/gcat/rest/Item.java index 3589f00..89f031f 100644 --- a/src/main/java/org/gcube/gcat/rest/Item.java +++ b/src/main/java/org/gcube/gcat/rest/Item.java @@ -22,7 +22,7 @@ import org.gcube.gcat.persistence.ckan.CKANPackage; * @author Luca Frosini (ISTI - CNR) */ @Path(Item.ITEMS) -public class Item extends REST implements org.gcube.gcat.api.interfaces.Item{ +public class Item extends REST implements org.gcube.gcat.api.interfaces.Item { public static final String ITEM_ID_PARAMETER = "ITEM_ID"; @@ -88,7 +88,7 @@ public class Item extends REST 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)); diff --git a/src/main/java/org/gcube/gcat/rest/License.java b/src/main/java/org/gcube/gcat/rest/License.java index efcf83d..fbccf11 100644 --- a/src/main/java/org/gcube/gcat/rest/License.java +++ b/src/main/java/org/gcube/gcat/rest/License.java @@ -12,7 +12,7 @@ import org.gcube.gcat.persistence.ckan.CKANLicense; */ @Path(License.LICENSES) public class License extends REST implements org.gcube.gcat.api.interfaces.License { - + public License() { super(LICENSES, null, CKANLicense.class); } diff --git a/src/main/java/org/gcube/gcat/rest/Profile.java b/src/main/java/org/gcube/gcat/rest/Profile.java index 38cea48..bfe3865 100644 --- a/src/main/java/org/gcube/gcat/rest/Profile.java +++ b/src/main/java/org/gcube/gcat/rest/Profile.java @@ -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"); diff --git a/src/main/java/org/gcube/gcat/rest/REST.java b/src/main/java/org/gcube/gcat/rest/REST.java index 8160f8f..45b8ab8 100644 --- a/src/main/java/org/gcube/gcat/rest/REST.java +++ b/src/main/java/org/gcube/gcat/rest/REST.java @@ -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 extends BaseREST implements CRUD { +public class REST extends BaseREST implements CRUD { protected final String COLLECTION_PARAMETER; protected final String ID_PARAMETER; @@ -64,7 +64,6 @@ public class REST extends BaseREST implements CRUD extends BaseREST implements CRUD { +@Provider +public class ScienceCatalogueExceptionMapper implements ExceptionMapper { @Override public Response toResponse(Exception exception) { @@ -19,15 +19,14 @@ public class ScienceCatalogueExceptionMapper implements ExceptionMapper 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 diff --git a/src/main/java/org/gcube/gcat/social/PortalUser.java b/src/main/java/org/gcube/gcat/social/PortalUser.java index f82cf1c..9d2e6ee 100644 --- a/src/main/java/org/gcube/gcat/social/PortalUser.java +++ b/src/main/java/org/gcube/gcat/social/PortalUser.java @@ -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 getRoles() { if(roles == null) { JsonNode jsonNode = getOAuthUserProfile().get(OAUTH_USER_PROFILE_ROLES_KEY); roles = new ArrayList(); if(jsonNode.isArray()) { ArrayNode arrayNode = (ArrayNode) jsonNode; - if(arrayNode.size()>0) { + if(arrayNode.size() > 0) { Iterator 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(); diff --git a/src/main/java/org/gcube/gcat/social/SocialService.java b/src/main/java/org/gcube/gcat/social/SocialService.java index 1f945a9..383ec00 100644 --- a/src/main/java/org/gcube/gcat/social/SocialService.java +++ b/src/main/java/org/gcube/gcat/social/SocialService.java @@ -28,7 +28,7 @@ public class SocialService { private String serviceBasePath; // Map - private static Map socialServicePerContext; + private static Map 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); } diff --git a/src/main/java/org/gcube/gcat/utils/Constants.java b/src/main/java/org/gcube/gcat/utils/Constants.java index f7c6eef..ff97647 100644 --- a/src/main/java/org/gcube/gcat/utils/Constants.java +++ b/src/main/java/org/gcube/gcat/utils/Constants.java @@ -24,15 +24,15 @@ public class Constants { */ protected static final Map 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); } } diff --git a/src/main/java/org/gcube/gcat/utils/ContextUtility.java b/src/main/java/org/gcube/gcat/utils/ContextUtility.java index 2757822..1d0b627 100644 --- a/src/main/java/org/gcube/gcat/utils/ContextUtility.java +++ b/src/main/java/org/gcube/gcat/utils/ContextUtility.java @@ -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); } } diff --git a/src/main/java/org/gcube/gcat/utils/HTTPUtility.java b/src/main/java/org/gcube/gcat/utils/HTTPUtility.java index 6474fdd..da9a50b 100644 --- a/src/main/java/org/gcube/gcat/utils/HTTPUtility.java +++ b/src/main/java/org/gcube/gcat/utils/HTTPUtility.java @@ -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(); diff --git a/src/main/java/org/gcube/gcat/utils/RandomString.java b/src/main/java/org/gcube/gcat/utils/RandomString.java index 5efc74d..4eef60c 100644 --- a/src/main/java/org/gcube/gcat/utils/RandomString.java +++ b/src/main/java/org/gcube/gcat/utils/RandomString.java @@ -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); } diff --git a/src/main/java/org/gcube/gcat/utils/URIResolver.java b/src/main/java/org/gcube/gcat/utils/URIResolver.java index 48e42c2..a90be3a 100644 --- a/src/main/java/org/gcube/gcat/utils/URIResolver.java +++ b/src/main/java/org/gcube/gcat/utils/URIResolver.java @@ -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"); } diff --git a/src/main/java/org/gcube/gcat/workspace/CatalogueMetadata.java b/src/main/java/org/gcube/gcat/workspace/CatalogueMetadata.java index 630860e..f881dd4 100644 --- a/src/main/java/org/gcube/gcat/workspace/CatalogueMetadata.java +++ b/src/main/java/org/gcube/gcat/workspace/CatalogueMetadata.java @@ -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"; diff --git a/src/main/java/org/gcube/gcat/workspace/CatalogueStorageHubManagement.java b/src/main/java/org/gcube/gcat/workspace/CatalogueStorageHubManagement.java index 306af54..8bab6e8 100644 --- a/src/main/java/org/gcube/gcat/workspace/CatalogueStorageHubManagement.java +++ b/src/main/java/org/gcube/gcat/workspace/CatalogueStorageHubManagement.java @@ -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(); } } diff --git a/src/test/java/org/gcube/gcat/persistence/ckan/CKANGroupTest.java b/src/test/java/org/gcube/gcat/persistence/ckan/CKANGroupTest.java index 37f973e..4c1b949 100644 --- a/src/test/java/org/gcube/gcat/persistence/ckan/CKANGroupTest.java +++ b/src/test/java/org/gcube/gcat/persistence/ckan/CKANGroupTest.java @@ -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();