fixed checkIfDatasetExists (validation is performed by taking into account the user's selected organization)
git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/widgets/ckan-metadata-publisher-widget@147132 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
fa8d07ec3c
commit
b13612460a
|
@ -66,7 +66,7 @@ public interface CKanPublisherService extends RemoteService {
|
|||
* @param title
|
||||
* @return true if it exists, false otherwise
|
||||
*/
|
||||
boolean datasetIdAlreadyExists(String title);
|
||||
boolean datasetIdAlreadyExists(String title, String orgName);
|
||||
|
||||
/**
|
||||
* Retrieve the list of groups the user can choose to associate this product with.
|
||||
|
|
|
@ -66,7 +66,7 @@ public interface CKanPublisherServiceAsync {
|
|||
* @param title
|
||||
* @return true if it exists, false otherwise
|
||||
*/
|
||||
void datasetIdAlreadyExists(String title, AsyncCallback<Boolean> callback);
|
||||
void datasetIdAlreadyExists(String title, String orgName, AsyncCallback<Boolean> callback);
|
||||
|
||||
// /**
|
||||
// * Return a tree object representing the whole folder hierarchy
|
||||
|
|
|
@ -761,8 +761,7 @@ public class CreateDatasetForm extends Composite{
|
|||
actionsAfterOnContinue();
|
||||
else{
|
||||
alertOnContinue("Checking if a item with such title already exists, please wait...", AlertType.INFO);
|
||||
|
||||
ckanServices.datasetIdAlreadyExists(titleTextBox.getText(), new AsyncCallback<Boolean>() {
|
||||
ckanServices.datasetIdAlreadyExists(titleTextBox.getText(), organizationsListbox.getSelectedItemText(), new AsyncCallback<Boolean>() {
|
||||
|
||||
@Override
|
||||
public void onSuccess(Boolean result) {
|
||||
|
|
|
@ -282,100 +282,105 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
|
|||
@Override
|
||||
public DatasetBean createCKanDataset(DatasetBean 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 = GenericUtils.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 userName = GenericUtils.getCurrentUser(getThreadLocalRequest()).getUsername();
|
||||
// add Type for custom fields
|
||||
if(toCreate.getChosenType() != null)
|
||||
customFields.put(SYS_TYPE, Arrays.asList(toCreate.getChosenType()));
|
||||
|
||||
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();
|
||||
boolean setPublic = toCreate.getVisibility();
|
||||
|
||||
// add Type for custom fields
|
||||
if(toCreate.getChosenType() != null)
|
||||
customFields.put(SYS_TYPE, Arrays.asList(toCreate.getChosenType()));
|
||||
|
||||
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(),
|
||||
GenericUtils.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(),
|
||||
GenericUtils.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(),
|
||||
GenericUtils.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(),
|
||||
GenericUtils.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;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -466,14 +471,13 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean datasetIdAlreadyExists(String title) {
|
||||
|
||||
public boolean datasetIdAlreadyExists(String title, String orgName) {
|
||||
if(title == null || title.isEmpty())
|
||||
return true; // it's an error somehow
|
||||
try{
|
||||
String scope = GenericUtils.getScopeFromClientUrl(getThreadLocalRequest());
|
||||
String scopeFromOrgName = getScopeFromOrgName(orgName);
|
||||
String idFromTitle = UtilMethods.fromProductTitleToName(title);
|
||||
return getCatalogue(scope).existProductWithNameOrId(idFromTitle);
|
||||
return getCatalogue(scopeFromOrgName).existProductWithNameOrId(idFromTitle);
|
||||
}catch(Exception e){
|
||||
logger.error("Unable to check if such a dataset id already exists", e);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue