From f098932e6af09fdd68d705f298921fead852a6d5 Mon Sep 17 00:00:00 2001 From: Costantino Perciante Date: Wed, 19 Apr 2017 12:39:59 +0000 Subject: [PATCH] fixed error thrown on create item git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/widgets/ckan-metadata-publisher-widget@146956 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../server/CKANPublisherServicesImpl.java | 172 +++++++++--------- 1 file changed, 89 insertions(+), 83 deletions(-) diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/CKANPublisherServicesImpl.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/CKANPublisherServicesImpl.java index 85ce7cd..c5d3855 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/CKANPublisherServicesImpl.java +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/CKANPublisherServicesImpl.java @@ -260,7 +260,7 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C vocabulary = new DiscoverTagsList(context).getTagsVocabulary(); getThreadLocalRequest().getSession().setAttribute(keyPerVocabulary, vocabulary); } - + logger.debug("Vocabulary for tags is " + vocabulary); return vocabulary; @@ -269,97 +269,103 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C @Override public DatasetMetadataBean createCKanDataset(DatasetMetadataBean toCreate) throws Exception{ - logger.debug("Request for creating a dataset with these information " + toCreate); + try{ + logger.debug("Request for creating a dataset with these information " + toCreate); - String userName = Utils.getCurrentUser(getThreadLocalRequest()).getUsername(); + String userName = Utils.getCurrentUser(getThreadLocalRequest()).getUsername(); - String title = toCreate.getTitle(); - String organizationNameOrId = toCreate.getSelectedOrganization(); - String author = toCreate.getAuthorFullName(); - String authorMail = toCreate.getAuthorEmail(); - String maintainer = toCreate.getMaintainer(); - String maintainerMail = toCreate.getMaintainerEmail(); - long version = toCreate.getVersion(); - String description = toCreate.getDescription(); - String chosenLicense = toCreate.getLicense(); - String licenseId = findLicenseIdByLicense(chosenLicense); - List listOfTags = toCreate.getTags(); - Map> customFields = toCreate.getCustomFields(); + String title = toCreate.getTitle(); + String organizationNameOrId = toCreate.getSelectedOrganization(); + String author = toCreate.getAuthorFullName(); + String authorMail = toCreate.getAuthorEmail(); + String maintainer = toCreate.getMaintainer(); + String maintainerMail = toCreate.getMaintainerEmail(); + long version = toCreate.getVersion(); + String description = toCreate.getDescription(); + String chosenLicense = toCreate.getLicense(); + String licenseId = findLicenseIdByLicense(chosenLicense); + List listOfTags = toCreate.getTags(); + Map> customFields = toCreate.getCustomFields(); - // add Type for custom fields - if(toCreate.getChosenType() != null) - customFields.put("system:type", Arrays.asList(toCreate.getChosenType())); + // add Type for custom fields + if(toCreate.getChosenType() != null) + customFields.put("system:type", Arrays.asList(toCreate.getChosenType())); - boolean setPublic = toCreate.getVisibility(); + boolean setPublic = toCreate.getVisibility(); - // get the list of resources and convert to ResourceBean - List resources = null; - ResourceElementBean resourcesToAdd = toCreate.getResourceRoot(); - - // we need to copy such resource in the .catalogue area of the user's ws - if(resourcesToAdd != null){ - resources = WorkspaceUtils.copyResourcesToUserCatalogueArea(toCreate.getId(), userName, toCreate); - } - - logger.debug("The user wants to publish in organization with name " + organizationNameOrId); - String scope = getScopeFromOrgName(organizationNameOrId); - DataCatalogue utils = getCatalogue(scope); - String userApiKey = utils.getApiKeyFromUsername(userName); - - String datasetId = utils.createCKanDatasetMultipleCustomFields - (userApiKey, title, null, organizationNameOrId, author, authorMail, maintainer, - maintainerMail, version, description, licenseId, listOfTags, customFields, resources, setPublic); - - if(datasetId != null){ - - logger.info("Dataset created!"); - toCreate.setId(datasetId); - - // retrieve the url - String datasetUrl = utils.getUnencryptedUrlFromDatasetIdOrName(datasetId); - toCreate.setSource(datasetUrl); - - // add also this information as custom field - Map> addField = new HashMap>(); - addField.put(ITEM_URL_FIELD, Arrays.asList(datasetUrl)); - utils.patchProductCustomFields(datasetId, userApiKey, addField); - - // start a thread that will associate this dataset with the group - if(/*toCreate.getChosenType() != null ||*/ toCreate.getGroups() != null){ - - AssociationToGroupAndNotifyThread threadAssociationToGroup = - new AssociationToGroupAndNotifyThread( - toCreate.getGroups(), - null, //toCreate.getChosenType(), TODO - datasetUrl, - datasetId, - toCreate.getTitle(), - Utils.getCurrentUser(getThreadLocalRequest()).getFullname(), - userName, - utils, - organizationNameOrId, - getThreadLocalRequest() - ); - threadAssociationToGroup.start(); + // get the list of resources and convert to ResourceBean + List resources = null; + ResourceElementBean resourcesToAdd = toCreate.getResourceRoot(); + // we need to copy such resource in the .catalogue area of the user's ws + if(resourcesToAdd != null){ + resources = WorkspaceUtils.copyResourcesToUserCatalogueArea(toCreate.getId(), userName, toCreate); } - // launch notification thread - WritePostCatalogueManagerThread threadWritePost = - new WritePostCatalogueManagerThread( - userName, - scope, - toCreate.getTitle(), - datasetUrl, - false, // send notification to other people - toCreate.getTags(), - Utils.getCurrentUser(getThreadLocalRequest()).getFullname() - ); - threadWritePost.start(); + logger.debug("The user wants to publish in organization with name " + organizationNameOrId); + String scope = getScopeFromOrgName(organizationNameOrId); + DataCatalogue utils = getCatalogue(scope); + String userApiKey = utils.getApiKeyFromUsername(userName); - return toCreate; - }else{ - logger.error("Failed to create the dataset"); + String datasetId = utils.createCKanDatasetMultipleCustomFields + (userApiKey, title, null, organizationNameOrId, author, authorMail, maintainer, + maintainerMail, version, description, licenseId, listOfTags, customFields, resources, setPublic); + + if(datasetId != null){ + + logger.info("Dataset created!"); + toCreate.setId(datasetId); + + // retrieve the url + String datasetUrl = utils.getUnencryptedUrlFromDatasetIdOrName(datasetId); + toCreate.setSource(datasetUrl); + + // add also this information as custom field + Map> addField = new HashMap>(); + addField.put(ITEM_URL_FIELD, Arrays.asList(datasetUrl)); + utils.patchProductCustomFields(datasetId, userApiKey, addField); + + // start a thread that will associate this dataset with the group + if(/*toCreate.getChosenType() != null ||*/ toCreate.getGroups() != null){ + + AssociationToGroupAndNotifyThread threadAssociationToGroup = + new AssociationToGroupAndNotifyThread( + toCreate.getGroups(), + null, //toCreate.getChosenType(), TODO + datasetUrl, + datasetId, + toCreate.getTitle(), + Utils.getCurrentUser(getThreadLocalRequest()).getFullname(), + userName, + utils, + organizationNameOrId, + getThreadLocalRequest() + ); + threadAssociationToGroup.start(); + + } + + // launch notification thread + WritePostCatalogueManagerThread threadWritePost = + new WritePostCatalogueManagerThread( + userName, + scope, + toCreate.getTitle(), + datasetUrl, + false, // send notification to other people + toCreate.getTags(), + Utils.getCurrentUser(getThreadLocalRequest()).getFullname() + ); + threadWritePost.start(); + + return toCreate; + }else{ + logger.error("Failed to create the dataset"); + } + + }catch(Exception e){ + logger.error("Error while creating item ", e); + throw new Exception(e.getMessage()); } return null;