diff --git a/src/main/java/org/gcube/data_catalogue/grsf_publish_ws/services/CommonServiceUtils.java b/src/main/java/org/gcube/data_catalogue/grsf_publish_ws/services/CommonServiceUtils.java index 1f6a007..c3eb303 100644 --- a/src/main/java/org/gcube/data_catalogue/grsf_publish_ws/services/CommonServiceUtils.java +++ b/src/main/java/org/gcube/data_catalogue/grsf_publish_ws/services/CommonServiceUtils.java @@ -6,10 +6,8 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.HashSet; -import java.util.Iterator; import java.util.List; import java.util.Map; -import java.util.Map.Entry; import java.util.Set; import javax.servlet.ServletContext; @@ -39,8 +37,6 @@ import org.gcube.datacatalogue.ckanutillibrary.shared.ResourceBean; import org.gcube.datacatalogue.ckanutillibrary.shared.RolesCkanGroupOrOrg; import org.slf4j.LoggerFactory; -import eu.trentorise.opendata.jackan.model.CkanOrganization; - /** * Services common utils. * @author Costantino Perciante at ISTI-CNR @@ -370,14 +366,14 @@ public class CommonServiceUtils { */ public static void hasAdminRole(String username, DataCatalogue catalogue, String apiKey, String organization) throws Exception{ - String role = null; - Iterator> roles = catalogue.getUserRoleByOrganization(username, apiKey).get(organization).entrySet().iterator(); - - while (roles.hasNext()) { - Map.Entry entry = (Map.Entry) roles - .next(); - role = RolesCkanGroupOrOrg.convertToCkanCapacity(entry.getValue()); - } + String role = catalogue.getRoleOfUserInOrganization(username, organization, apiKey); + // Iterator> roles = catalogue.getUserRoleByOrganization(username, apiKey).get(organization).entrySet().iterator(); + // + // while (roles.hasNext()) { + // Map.Entry entry = (Map.Entry) roles + // .next(); + // role = RolesCkanGroupOrOrg.convertToCkanCapacity(entry.getValue()); + // } logger.info("Role of the user " + username + " is " + role + " in " + organization); diff --git a/src/main/java/org/gcube/data_catalogue/grsf_publish_ws/services/GrsfPublisherFisheryService.java b/src/main/java/org/gcube/data_catalogue/grsf_publish_ws/services/GrsfPublisherFisheryService.java index 4b0e614..1c2305b 100644 --- a/src/main/java/org/gcube/data_catalogue/grsf_publish_ws/services/GrsfPublisherFisheryService.java +++ b/src/main/java/org/gcube/data_catalogue/grsf_publish_ws/services/GrsfPublisherFisheryService.java @@ -392,9 +392,10 @@ public class GrsfPublisherFisheryService { if(catalogue == null){ throw new Exception("There was a problem while serving your request. No catalogue instance was found in this context!"); }else{ - + // get already published record and modify it - CkanDataset recordPublished = catalogue.getDataset(catalogId); + String apiKey = catalogue.getApiKeyFromUsername(username); + CkanDataset recordPublished = catalogue.getDataset(catalogId, apiKey); if(recordPublished == null) throw new Exception("A record with catalogue id " + catalogId + " does not exist!"); @@ -408,7 +409,7 @@ public class GrsfPublisherFisheryService { throw new Exception("Sorry but there was not possible to retrieve your fullname/email!"); } - String apiKey = catalogue.getApiKeyFromUsername(username); + String organization = HelperMethods.retrieveOrgNameFromScope(context); //"grsf_admin"; // check he/she has admin role @@ -505,7 +506,7 @@ public class GrsfPublisherFisheryService { } } }catch(Exception e){ - logger.error("Failed to create fishery record" + e); + logger.error("Failed to update fishery record" + e); status = Status.INTERNAL_SERVER_ERROR; responseBean.setError(e.getMessage()); } diff --git a/src/main/java/org/gcube/data_catalogue/grsf_publish_ws/services/GrsfPublisherStockService.java b/src/main/java/org/gcube/data_catalogue/grsf_publish_ws/services/GrsfPublisherStockService.java index 5e8b1a5..ca69e6a 100644 --- a/src/main/java/org/gcube/data_catalogue/grsf_publish_ws/services/GrsfPublisherStockService.java +++ b/src/main/java/org/gcube/data_catalogue/grsf_publish_ws/services/GrsfPublisherStockService.java @@ -31,7 +31,6 @@ import org.gcube.common.authorization.library.utils.Caller; import org.gcube.common.scope.api.ScopeProvider; import org.gcube.data_catalogue.grsf_publish_ws.json.input.Common; import org.gcube.data_catalogue.grsf_publish_ws.json.input.DeleteProductBean; -import org.gcube.data_catalogue.grsf_publish_ws.json.input.FisheryRecord; import org.gcube.data_catalogue.grsf_publish_ws.json.input.StockRecord; import org.gcube.data_catalogue.grsf_publish_ws.json.output.ResponseBean; import org.gcube.data_catalogue.grsf_publish_ws.json.output.ResponseCreationBean; @@ -369,7 +368,7 @@ public class GrsfPublisherStockService { @Produces(MediaType.APPLICATION_JSON) public Response updateFishery( @NotNull(message="record cannot be null") - @Valid FisheryRecord record, + @Valid StockRecord record, @PathParam("source") String source) throws ValidationException{ @@ -400,7 +399,8 @@ public class GrsfPublisherStockService { }else{ // get already published record and modify it - CkanDataset recordPublished = catalogue.getDataset(catalogId); + String apiKey = catalogue.getApiKeyFromUsername(username); + CkanDataset recordPublished = catalogue.getDataset(catalogId, apiKey); if(recordPublished == null) throw new Exception("A record with catalogue id " + catalogId + " does not exist!"); @@ -413,9 +413,7 @@ public class GrsfPublisherStockService { logger.debug("Author fullname or mail missing, cannot continue"); throw new Exception("Sorry but there was not possible to retrieve your fullname/email!"); } - - String apiKey = catalogue.getApiKeyFromUsername(username); - String organization = HelperMethods.retrieveOrgNameFromScope(context); //"grsf_admin"; + String organization = HelperMethods.retrieveOrgNameFromScope(context); //"grsf_admin"; // check he/she has admin role CommonServiceUtils.hasAdminRole(username, catalogue, apiKey, organization); @@ -465,7 +463,7 @@ public class GrsfPublisherStockService { customFields.put(CommonServiceUtils.SYSTEM_TYPE, Arrays.asList(sourceInPath.getOrigName())); // convert extras' keys to keys with namespace - Map namespaces = HelperMethods.getFieldToFieldNameSpaceMapping(HelperMethods.GENERIC_RESOURCE_NAME_MAP_KEY_NAMESPACES_FISHERY); + Map namespaces = HelperMethods.getFieldToFieldNameSpaceMapping(HelperMethods.GENERIC_RESOURCE_NAME_MAP_KEY_NAMESPACES_STOCK); if(namespaces == null) throw new Exception("Failed to retrieve the namespaces for the key fields!"); @@ -513,7 +511,7 @@ public class GrsfPublisherStockService { } } }catch(Exception e){ - logger.error("Failed to create fishery record" + e); + logger.error("Failed to update stock record", e); status = Status.INTERNAL_SERVER_ERROR; responseBean.setError(e.getMessage()); } diff --git a/src/main/java/org/gcube/data_catalogue/grsf_publish_ws/utils/threads/ManageTimeSeriesThread.java b/src/main/java/org/gcube/data_catalogue/grsf_publish_ws/utils/threads/ManageTimeSeriesThread.java index e943a8f..c4e6c25 100644 --- a/src/main/java/org/gcube/data_catalogue/grsf_publish_ws/utils/threads/ManageTimeSeriesThread.java +++ b/src/main/java/org/gcube/data_catalogue/grsf_publish_ws/utils/threads/ManageTimeSeriesThread.java @@ -209,15 +209,17 @@ public class ManageTimeSeriesThread extends Thread{ if(createdFileOnWorkspace != null){ String publicUrlToSetOnCkan = createdFileOnWorkspace.getPublicLink(true); - logger.info("going to patch the created resource with id " + ckanResource.getId() + " with url " + publicUrlToSetOnCkan); + + // wait for patching.. + Thread.sleep(500); + logger.debug("Going to patch the created resource with id " + ckanResource.getId() + " with url " + publicUrlToSetOnCkan); boolean updated = catalogue.patchResource(ckanResource.getId(), publicUrlToSetOnCkan, resourceToAttachOnCkanName, resourceToAttachOnCkanDescription, "", apiKeyUser); if(updated){ logger.info("Resource has been updated with the new url"); break; }else - logger.error("Error while updating resource..."); - + logger.error("Error while patching resource..."); } }