added check for title and dataset id
git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/widgets/ckan-metadata-publisher-widget@131778 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
52d3efce0c
commit
175d431b33
|
@ -61,7 +61,7 @@ public interface CKanPublisherService extends RemoteService {
|
|||
|
||||
/**
|
||||
* Given the title the user wants to give to the new product to create, a check is performed
|
||||
* to understand if a dataset with the proposed title (and so the id generateda at server side) already exists
|
||||
* to understand if a dataset with the proposed title (and so the id generated at server side) already exists
|
||||
* @param title
|
||||
* @return true if it exists, false otherwise
|
||||
*/
|
||||
|
|
|
@ -62,7 +62,7 @@ public interface CKanPublisherServiceAsync {
|
|||
|
||||
/**
|
||||
* Given the title the user wants to give to the new product to create, a check is performed
|
||||
* to understand if a dataset with the proposed title (and so the id generateda at server side) already exists
|
||||
* to understand if a dataset with the proposed title (and so the id generated at server side) already exists
|
||||
* @param title
|
||||
* @return true if it exists, false otherwise
|
||||
*/
|
||||
|
|
|
@ -76,11 +76,6 @@ import com.google.gwt.user.client.ui.Widget;
|
|||
*/
|
||||
public class CreateDatasetForm extends Composite{
|
||||
|
||||
/**
|
||||
* Create a remote service proxy to talk to the server-side ckan service.
|
||||
*/
|
||||
private final CKanPublisherServiceAsync ckanServices = GWT.create(CKanPublisherService.class);
|
||||
|
||||
private static EditMetadataFormUiBinder uiBinder = GWT
|
||||
.create(EditMetadataFormUiBinder.class);
|
||||
|
||||
|
@ -165,6 +160,12 @@ public class CreateDatasetForm extends Composite{
|
|||
@UiField ControlGroup versionControlGroup;
|
||||
@UiField ControlGroup organizationsGroup;
|
||||
|
||||
// Create a remote service proxy to talk to the server-side ckan service.
|
||||
private final CKanPublisherServiceAsync ckanServices = GWT.create(CKanPublisherService.class);
|
||||
|
||||
private static final String REGEX_TITLE_PRODUCT_SUBWORD = "[^a-zA-Z0-9_.-]";
|
||||
private static final String REGEX_MAIL = "\\b[\\w.%-]+@[-.\\w]+\\.[A-Za-z]{2,4}\\b";
|
||||
|
||||
// error message
|
||||
protected static final String ERROR_PRODUCT_CREATION = "There was an error while trying to publish your product, sorry.. Retry later";
|
||||
|
||||
|
@ -603,9 +604,28 @@ public class CreateDatasetForm extends Composite{
|
|||
void onContinueButton(ClickEvent e){
|
||||
|
||||
// validate data
|
||||
String errorMsg = validateDataOnContinue();
|
||||
final String errorMsg = validateDataOnContinue();
|
||||
|
||||
if(errorMsg == null){
|
||||
if(errorMsg != null){
|
||||
|
||||
alertOnContinue("Please check inserted data [" + errorMsg + "]", AlertType.ERROR);
|
||||
return;
|
||||
|
||||
}else{
|
||||
|
||||
alertOnContinue("Checking if a product with such title already exists, please wait...", AlertType.INFO);
|
||||
|
||||
// better check for title
|
||||
ckanServices.datasetIdAlreadyExists(titleTextBox.getText(), new AsyncCallback<Boolean>() {
|
||||
|
||||
@Override
|
||||
public void onSuccess(Boolean result) {
|
||||
|
||||
if(result){
|
||||
|
||||
alertOnContinue("Sorry but a product with such title already exists, try to change it", AlertType.WARNING);
|
||||
|
||||
}else{
|
||||
// check what to do
|
||||
if(isWorkspaceRequest){
|
||||
|
||||
|
@ -632,8 +652,17 @@ public class CreateDatasetForm extends Composite{
|
|||
else
|
||||
selectedProfile.setText("Selected Profile is " + metadataProfilesFormatListbox.getSelectedItemText());
|
||||
|
||||
}else{
|
||||
alertOnContinue("Please check inserted data [" + errorMsg + "]", AlertType.ERROR);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Throwable caught) {
|
||||
|
||||
alertOnContinue("Sorry but there was a proble while checking if the inserted data are correct", AlertType.ERROR);
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1062,20 +1091,18 @@ public class CreateDatasetForm extends Composite{
|
|||
}
|
||||
|
||||
// better check for the title
|
||||
String regexTitleSubWord = "[^a-zA-Z0-9_.-]";
|
||||
String[] splittedTitle = titleTextBox.getText().split(" ");
|
||||
|
||||
for (String word : splittedTitle) {
|
||||
String replaced = word.replaceAll(regexTitleSubWord, "");
|
||||
String replaced = word.replaceAll(REGEX_TITLE_PRODUCT_SUBWORD, "");
|
||||
if(!replaced.equals(word)){
|
||||
productTitleGroup.setType(ControlGroupType.ERROR);
|
||||
return "Please note that only alphanumeric characters are allowed for the title";
|
||||
return "Please note not all characters are allowed for the title";
|
||||
}
|
||||
}
|
||||
|
||||
// email reg expression
|
||||
String regexMail = "\\b[\\w.%-]+@[-.\\w]+\\.[A-Za-z]{2,4}\\b";
|
||||
if(!validateByRegExpression(maintainerEmailTextbox.getText(), regexMail)){
|
||||
if(!validateByRegExpression(maintainerEmailTextbox.getText(), REGEX_MAIL)){
|
||||
maintainerControlGroup.setType(ControlGroupType.ERROR);
|
||||
return "Not valid maintainer email";
|
||||
}
|
||||
|
|
|
@ -620,7 +620,8 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
|
|||
try{
|
||||
|
||||
String scope = (String)getThreadLocalRequest().getSession().getAttribute(SessionCatalogueAttributes.SCOPE_CLIENT_PORTLET_URL);
|
||||
return getCkanUtilsObj(scope).existProductWithNameOrId(title);
|
||||
String idFromTitle = org.gcube.datacatalogue.ckanutillibrary.utils.UtilMethods.nameFromTitle(title);
|
||||
return getCkanUtilsObj(scope).existProductWithNameOrId(idFromTitle);
|
||||
|
||||
}catch(Exception e){
|
||||
logger.error("Unable to check if such a dataset id already exists", e);
|
||||
|
|
Loading…
Reference in New Issue