minor fixes

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/data-catalogue/grsf-publisher-ws@151061 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Costantino Perciante 2017-07-13 15:22:32 +00:00
parent f0606f9743
commit ba5c4a44cc
4 changed files with 24 additions and 27 deletions

View File

@ -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<Entry<CkanOrganization, RolesCkanGroupOrOrg>> roles = catalogue.getUserRoleByOrganization(username, apiKey).get(organization).entrySet().iterator();
while (roles.hasNext()) {
Map.Entry<CkanOrganization, RolesCkanGroupOrOrg> entry = (Map.Entry<CkanOrganization, RolesCkanGroupOrOrg>) roles
.next();
role = RolesCkanGroupOrOrg.convertToCkanCapacity(entry.getValue());
}
String role = catalogue.getRoleOfUserInOrganization(username, organization, apiKey);
// Iterator<Entry<CkanOrganization, RolesCkanGroupOrOrg>> roles = catalogue.getUserRoleByOrganization(username, apiKey).get(organization).entrySet().iterator();
//
// while (roles.hasNext()) {
// Map.Entry<CkanOrganization, RolesCkanGroupOrOrg> entry = (Map.Entry<CkanOrganization, RolesCkanGroupOrOrg>) roles
// .next();
// role = RolesCkanGroupOrOrg.convertToCkanCapacity(entry.getValue());
// }
logger.info("Role of the user " + username + " is " + role + " in " + organization);

View File

@ -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());
}

View File

@ -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<String, String> namespaces = HelperMethods.getFieldToFieldNameSpaceMapping(HelperMethods.GENERIC_RESOURCE_NAME_MAP_KEY_NAMESPACES_FISHERY);
Map<String, String> 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());
}

View File

@ -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...");
}
}