Formatted code
This commit is contained in:
parent
63246f7cce
commit
11cd97e1c7
|
@ -18,7 +18,6 @@ public class CustomField implements Comparable<CustomField> {
|
||||||
private int indexCategory = Integer.MAX_VALUE;
|
private int indexCategory = Integer.MAX_VALUE;
|
||||||
private int indexMetadataField = Integer.MAX_VALUE;
|
private int indexMetadataField = Integer.MAX_VALUE;
|
||||||
|
|
||||||
|
|
||||||
private void init(String key, String value, int indexCategory, int indexMetadataField) {
|
private void init(String key, String value, int indexCategory, int indexMetadataField) {
|
||||||
if(key == null || value == null || key.isEmpty()) {
|
if(key == null || value == null || key.isEmpty()) {
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
|
@ -41,7 +40,6 @@ public class CustomField implements Comparable<CustomField> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public CustomField(JsonNode object) {
|
public CustomField(JsonNode object) {
|
||||||
super();
|
super();
|
||||||
init(object.get("key").asText(), object.get("value").asText(), -1, -1);
|
init(object.get("key").asText(), object.get("value").asText(), -1, -1);
|
||||||
|
@ -91,7 +89,6 @@ public class CustomField implements Comparable<CustomField> {
|
||||||
this.qualifiedKey = qualifiedKey;
|
this.qualifiedKey = qualifiedKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public int getIndexCategory() {
|
public int getIndexCategory() {
|
||||||
return indexCategory;
|
return indexCategory;
|
||||||
}
|
}
|
||||||
|
|
|
@ -181,7 +181,9 @@ public abstract class CKAN {
|
||||||
try {
|
try {
|
||||||
String gotName = jsonNode.get(NAME_KEY).asText();
|
String gotName = jsonNode.get(NAME_KEY).asText();
|
||||||
if(!gotName.matches(nameRegex)) {
|
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) {
|
if(name == null) {
|
||||||
|
@ -228,8 +230,8 @@ public abstract class CKAN {
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected GXHTTPStringRequest getGXHTTPStringRequest(String path, boolean post)
|
||||||
protected GXHTTPStringRequest getGXHTTPStringRequest(String path, boolean post) throws UnsupportedEncodingException {
|
throws UnsupportedEncodingException {
|
||||||
String catalogueURL = CKANInstance.getInstance().getCKANURL();
|
String catalogueURL = CKANInstance.getInstance().getCKANURL();
|
||||||
|
|
||||||
GXHTTPStringRequest gxhttpStringRequest = HTTPUtility.createGXHTTPStringRequest(catalogueURL, path, post);
|
GXHTTPStringRequest gxhttpStringRequest = HTTPUtility.createGXHTTPStringRequest(catalogueURL, path, post);
|
||||||
|
|
|
@ -33,7 +33,6 @@ public class CKANGroup extends CKAN {
|
||||||
|
|
||||||
public static final String GROUPS_KEY = "groups";
|
public static final String GROUPS_KEY = "groups";
|
||||||
|
|
||||||
|
|
||||||
public CKANGroup() {
|
public CKANGroup() {
|
||||||
super();
|
super();
|
||||||
LIST = GROUP_LIST;
|
LIST = GROUP_LIST;
|
||||||
|
|
|
@ -120,7 +120,6 @@ public class CKANInstance {
|
||||||
serviceEndpoint = serviceEndpoints.get(0);
|
serviceEndpoint = serviceEndpoints.get(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Iterator<AccessPoint> accessPointIterator = serviceEndpoint.profile().accessPoints().iterator();
|
Iterator<AccessPoint> accessPointIterator = serviceEndpoint.profile().accessPoints().iterator();
|
||||||
while(accessPointIterator.hasNext()) {
|
while(accessPointIterator.hasNext()) {
|
||||||
AccessPoint accessPoint = accessPointIterator.next();
|
AccessPoint accessPoint = accessPointIterator.next();
|
||||||
|
@ -143,7 +142,8 @@ public class CKANInstance {
|
||||||
// retrieve option for user alert
|
// retrieve option for user alert
|
||||||
notificationToUsersEnabled = false;
|
notificationToUsersEnabled = false;
|
||||||
if(accessPoint.propertyMap().containsKey(ALERT_USERS_ON_POST_CREATION)) {
|
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;
|
notificationToUsersEnabled = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,7 +41,6 @@ public class CKANOrganization extends CKAN {
|
||||||
protected static final String USERNAME_KEY = "username";
|
protected static final String USERNAME_KEY = "username";
|
||||||
protected static final String ROLE_KEY = "role";
|
protected static final String ROLE_KEY = "role";
|
||||||
|
|
||||||
|
|
||||||
public CKANOrganization() {
|
public CKANOrganization() {
|
||||||
super();
|
super();
|
||||||
LIST = ORGANIZATION_LIST;
|
LIST = ORGANIZATION_LIST;
|
||||||
|
|
|
@ -169,8 +169,6 @@ public class CKANPackage extends CKAN {
|
||||||
objectNode.remove(CAPACITY_KEY);
|
objectNode.remove(CAPACITY_KEY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
CKANUser ckanUser = CKANUserCache.getCurrrentCKANUser();
|
CKANUser ckanUser = CKANUserCache.getCurrrentCKANUser();
|
||||||
|
|
||||||
objectNode.put(AUTHOR_KEY, ckanUser.getName());
|
objectNode.put(AUTHOR_KEY, ckanUser.getName());
|
||||||
|
@ -271,7 +269,8 @@ public class CKANPackage extends CKAN {
|
||||||
arrayNode.add(name);
|
arrayNode.add(name);
|
||||||
} catch(Exception e) {
|
} catch(Exception e) {
|
||||||
try {
|
try {
|
||||||
logger.error("Unable to get the ID of {}. the result will not be included in the result", mapper.writeValueAsString(node));
|
logger.error("Unable to get the ID of {}. the result will not be included in the result",
|
||||||
|
mapper.writeValueAsString(node));
|
||||||
} catch(Exception ex) {
|
} catch(Exception ex) {
|
||||||
logger.error("", ex);
|
logger.error("", ex);
|
||||||
}
|
}
|
||||||
|
@ -361,7 +360,9 @@ public class CKANPackage extends CKAN {
|
||||||
logger.info("The request explicitly disabled the Social Post.");
|
logger.info("The request explicitly disabled the Social Post.");
|
||||||
}
|
}
|
||||||
} catch(Exception 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);
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -432,8 +433,6 @@ public class CKANPackage extends CKAN {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if(jsonNode.has(RESOURCES_KEY)) {
|
if(jsonNode.has(RESOURCES_KEY)) {
|
||||||
ArrayNode resourcesToBeSend = mapper.createArrayNode();
|
ArrayNode resourcesToBeSend = mapper.createArrayNode();
|
||||||
ArrayNode receivedResources = (ArrayNode) jsonNode.get(RESOURCES_KEY);
|
ArrayNode receivedResources = (ArrayNode) jsonNode.get(RESOURCES_KEY);
|
||||||
|
@ -445,7 +444,8 @@ public class CKANPackage extends CKAN {
|
||||||
ckanResource = originalResources.get(resourceId);
|
ckanResource = originalResources.get(resourceId);
|
||||||
originalResources.remove(resourceId);
|
originalResources.remove(resourceId);
|
||||||
} else {
|
} else {
|
||||||
throw new BadRequestException("The content cotains a resource with id " + resourceId + " which does not exists") ;
|
throw new BadRequestException(
|
||||||
|
"The content cotains a resource with id " + resourceId + " which does not exists");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
resourceNode = ckanResource.createOrUpdate(resourceNode);
|
resourceNode = ckanResource.createOrUpdate(resourceNode);
|
||||||
|
|
|
@ -44,13 +44,10 @@ public class CKANUser extends CKAN {
|
||||||
public static final String EMAIL = "email";
|
public static final String EMAIL = "email";
|
||||||
public static final String PASSWORD = "password";
|
public static final String PASSWORD = "password";
|
||||||
|
|
||||||
|
|
||||||
private static final String API_KEY = "apikey";
|
private static final String API_KEY = "apikey";
|
||||||
|
|
||||||
public enum Role {
|
public enum Role {
|
||||||
MEMBER("Catalogue-Member", "member"),
|
MEMBER("Catalogue-Member", "member"), EDITOR("Catalogue-Editor", "editor"), ADMIN("Catalogue-Admin", "admin");
|
||||||
EDITOR("Catalogue-Editor", "editor"),
|
|
||||||
ADMIN("Catalogue-Admin", "admin");
|
|
||||||
|
|
||||||
private final String portalRole;
|
private final String portalRole;
|
||||||
private final String ckanRole;
|
private final String ckanRole;
|
||||||
|
@ -117,8 +114,6 @@ public class CKANUser extends CKAN {
|
||||||
PURGE = null;
|
PURGE = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public String create() {
|
public String create() {
|
||||||
RandomString randomString = new RandomString(12);
|
RandomString randomString = new RandomString(12);
|
||||||
ObjectNode objectNode = mapper.createObjectNode();
|
ObjectNode objectNode = mapper.createObjectNode();
|
||||||
|
|
|
@ -12,6 +12,8 @@ import javax.cache.expiry.CreatedExpiryPolicy;
|
||||||
import javax.cache.expiry.Duration;
|
import javax.cache.expiry.Duration;
|
||||||
import javax.cache.spi.CachingProvider;
|
import javax.cache.spi.CachingProvider;
|
||||||
|
|
||||||
|
import org.gcube.gcat.utils.ContextUtility;
|
||||||
|
|
||||||
public abstract class CKANUserCache {
|
public abstract class CKANUserCache {
|
||||||
|
|
||||||
private static final CacheManager cacheManager;
|
private static final CacheManager cacheManager;
|
||||||
|
@ -28,13 +30,9 @@ public abstract class CKANUserCache {
|
||||||
|
|
||||||
userCacheConfiguration = new MutableConfiguration<String,CKANUser>().setTypes(String.class, CKANUser.class)
|
userCacheConfiguration = new MutableConfiguration<String,CKANUser>().setTypes(String.class, CKANUser.class)
|
||||||
.setStoreByValue(false)
|
.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>>();
|
userCachePerCkanInstance = new HashMap<String,Cache<String,CKANUser>>();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private CKANUserCache() {
|
private CKANUserCache() {
|
||||||
|
@ -48,11 +46,12 @@ public abstract class CKANUserCache {
|
||||||
userCachePerCkanInstance.put(ckanURL, userCache);
|
userCachePerCkanInstance.put(ckanURL, userCache);
|
||||||
}
|
}
|
||||||
|
|
||||||
String ckanUserName = CKANUser.getCKANUsername();
|
String gcubeUsername = ContextUtility.getUsername();
|
||||||
CKANUser ckanUser = userCache.get(ckanUserName);
|
CKANUser ckanUser = userCache.get(gcubeUsername);
|
||||||
if(ckanUser == null) {
|
if(ckanUser == null) {
|
||||||
ckanUser = new CKANUser();
|
ckanUser = new CKANUser();
|
||||||
ckanUser.retrieve();
|
ckanUser.retrieve();
|
||||||
|
userCache.put(gcubeUsername, ckanUser);
|
||||||
}
|
}
|
||||||
return ckanUser;
|
return ckanUser;
|
||||||
}
|
}
|
||||||
|
|
|
@ -154,7 +154,6 @@ public class ISProfile {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public boolean createOrUpdate(String name, String xml) throws SAXException {
|
public boolean createOrUpdate(String name, String xml) throws SAXException {
|
||||||
try {
|
try {
|
||||||
MetadataUtility metadataUtility = new MetadataUtility();
|
MetadataUtility metadataUtility = new MetadataUtility();
|
||||||
|
|
|
@ -60,7 +60,6 @@ public class MetadataUtility {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public List<NamespaceCategory> getNamespaceCategories() throws Exception {
|
public List<NamespaceCategory> getNamespaceCategories() throws Exception {
|
||||||
return dataCalogueMetadataFormatReader.getListOfNamespaceCategories();
|
return dataCalogueMetadataFormatReader.getListOfNamespaceCategories();
|
||||||
|
|
||||||
|
|
|
@ -24,8 +24,7 @@ public class BaseREST {
|
||||||
|
|
||||||
protected ResponseBuilder addLocation(ResponseBuilder responseBuilder, String id) {
|
protected ResponseBuilder addLocation(ResponseBuilder responseBuilder, String id) {
|
||||||
return responseBuilder.header(LOCATION_HEADER,
|
return responseBuilder.header(LOCATION_HEADER,
|
||||||
String.format("%s/%s", uriInfo.getAbsolutePath().toString(), id)
|
String.format("%s/%s", uriInfo.getAbsolutePath().toString(), id));
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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";
|
public static final String CANNOT_MANAGE_PROFILE_SCHEMA = "You cannot manage the profile schema";
|
||||||
|
|
||||||
|
|
||||||
static {
|
static {
|
||||||
StringBuilder validationError = new StringBuilder();
|
StringBuilder validationError = new StringBuilder();
|
||||||
validationError.append("The Profile is not valid because of the following error at validation time:\n%s\n\n");
|
validationError.append("The Profile is not valid because of the following error at validation time:\n%s\n\n");
|
||||||
|
|
|
@ -64,7 +64,6 @@ public class REST<C extends CKAN> extends BaseREST implements CRUD<Response, Res
|
||||||
return ckan.update(json);
|
return ckan.update(json);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public String patch(String id, String json) {
|
public String patch(String id, String json) {
|
||||||
setCalledMethod("PATCH /" + COLLECTION_PARAMETER + "/{" + ID_PARAMETER + "}");
|
setCalledMethod("PATCH /" + COLLECTION_PARAMETER + "/{" + ID_PARAMETER + "}");
|
||||||
C ckan = getInstance();
|
C ckan = getInstance();
|
||||||
|
@ -93,5 +92,4 @@ public class REST<C extends CKAN> extends BaseREST implements CRUD<Response, Res
|
||||||
return delete(id, true);
|
return delete(id, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,6 @@ public class ScienceCatalogueExceptionMapper implements ExceptionMapper<Excepti
|
||||||
}
|
}
|
||||||
MediaType mediaType = MediaType.TEXT_PLAIN_TYPE;
|
MediaType mediaType = MediaType.TEXT_PLAIN_TYPE;
|
||||||
|
|
||||||
|
|
||||||
if(WebApplicationException.class.isAssignableFrom(exception.getClass())) {
|
if(WebApplicationException.class.isAssignableFrom(exception.getClass())) {
|
||||||
Response gotResponse = ((WebApplicationException) exception).getResponse();
|
Response gotResponse = ((WebApplicationException) exception).getResponse();
|
||||||
status = Status.fromStatusCode(gotResponse.getStatusInfo().getStatusCode());
|
status = Status.fromStatusCode(gotResponse.getStatusInfo().getStatusCode());
|
||||||
|
|
|
@ -103,7 +103,6 @@ public class PortalUser {
|
||||||
return eMail;
|
return eMail;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public List<String> getRoles() {
|
public List<String> getRoles() {
|
||||||
if(roles == null) {
|
if(roles == null) {
|
||||||
JsonNode jsonNode = getOAuthUserProfile().get(OAUTH_USER_PROFILE_ROLES_KEY);
|
JsonNode jsonNode = getOAuthUserProfile().get(OAUTH_USER_PROFILE_ROLES_KEY);
|
||||||
|
|
|
@ -24,12 +24,12 @@ public class Constants {
|
||||||
*/
|
*/
|
||||||
protected static final Map<String,String> applicationTokens;
|
protected static final Map<String,String> applicationTokens;
|
||||||
|
|
||||||
|
|
||||||
public static String getCatalogueApplicationToken() {
|
public static String getCatalogueApplicationToken() {
|
||||||
try {
|
try {
|
||||||
return applicationTokens.get(ContextUtility.getCurrentContext());
|
return applicationTokens.get(ContextUtility.getCurrentContext());
|
||||||
} catch(Exception e) {
|
} catch(Exception e) {
|
||||||
throw new InternalServerErrorException("Unable to retrieve Application Token for context " + ContextUtility.getCurrentContext(), e);
|
throw new InternalServerErrorException(
|
||||||
|
"Unable to retrieve Application Token for context " + ContextUtility.getCurrentContext(), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -33,7 +33,8 @@ public class HTTPUtility {
|
||||||
return result;
|
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 gxhttpStringRequest = GXHTTPStringRequest.newRequest(url);
|
||||||
gxhttpStringRequest.from(Constants.CATALOGUE_NAME);
|
gxhttpStringRequest.from(Constants.CATALOGUE_NAME);
|
||||||
if(post) {
|
if(post) {
|
||||||
|
|
|
@ -52,7 +52,8 @@ public class CatalogueStorageHubManagement {
|
||||||
CatalogueMetadata catalogueMetadata = new CatalogueMetadata(itemID);
|
CatalogueMetadata catalogueMetadata = new CatalogueMetadata(itemID);
|
||||||
storageHubManagement.setCheckMetadata(catalogueMetadata);
|
storageHubManagement.setCheckMetadata(catalogueMetadata);
|
||||||
Metadata metadata = catalogueMetadata.getMetadata(persistedURL, originalFilename, resourceID);
|
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();
|
mimeType = storageHubManagement.getMimeType();
|
||||||
return persistedURL;
|
return persistedURL;
|
||||||
} finally {
|
} finally {
|
||||||
|
@ -73,7 +74,6 @@ public class CatalogueStorageHubManagement {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected void internalAddRevisionID(String resourceID, String revisionID) throws Exception {
|
protected void internalAddRevisionID(String resourceID, String revisionID) throws Exception {
|
||||||
FileContainer fileContainer = storageHubManagement.getCreatedFile();
|
FileContainer fileContainer = storageHubManagement.getCreatedFile();
|
||||||
Metadata metadata = fileContainer.get().getMetadata();
|
Metadata metadata = fileContainer.get().getMetadata();
|
||||||
|
|
|
@ -16,7 +16,6 @@ public class CKANGroupTest extends ContextTest {
|
||||||
logger.debug("{}", ret);
|
logger.debug("{}", ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void read() throws Exception {
|
public void read() throws Exception {
|
||||||
CKANGroup ckanGroup = new CKANGroup();
|
CKANGroup ckanGroup = new CKANGroup();
|
||||||
|
|
Loading…
Reference in New Issue