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
This commit is contained in:
Costantino Perciante 2017-04-19 12:39:59 +00:00
parent f894f95409
commit f098932e6a
1 changed files with 89 additions and 83 deletions

View File

@ -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<String> listOfTags = toCreate.getTags();
Map<String, List<String>> 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<String> listOfTags = toCreate.getTags();
Map<String, List<String>> 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<ResourceBean> 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<String, List<String>> addField = new HashMap<String, List<String>>();
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<ResourceBean> 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<String, List<String>> addField = new HashMap<String, List<String>>();
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;