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:
Costantino Perciante 2017-04-25 14:14:59 +00:00
parent fa8d07ec3c
commit b13612460a
4 changed files with 95 additions and 92 deletions

View File

@ -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.

View File

@ -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

View File

@ -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) {

View File

@ -282,10 +282,9 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
@Override
public DatasetBean createCKanDataset(DatasetBean toCreate) throws Exception{
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();
@ -375,7 +374,13 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
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);
}