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
|
* 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
|
* @param title
|
||||||
* @return true if it exists, false otherwise
|
* @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
|
* 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
|
* @param title
|
||||||
* @return true if it exists, false otherwise
|
* @return true if it exists, false otherwise
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -76,11 +76,6 @@ import com.google.gwt.user.client.ui.Widget;
|
||||||
*/
|
*/
|
||||||
public class CreateDatasetForm extends Composite{
|
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
|
private static EditMetadataFormUiBinder uiBinder = GWT
|
||||||
.create(EditMetadataFormUiBinder.class);
|
.create(EditMetadataFormUiBinder.class);
|
||||||
|
|
||||||
|
@ -165,6 +160,12 @@ public class CreateDatasetForm extends Composite{
|
||||||
@UiField ControlGroup versionControlGroup;
|
@UiField ControlGroup versionControlGroup;
|
||||||
@UiField ControlGroup organizationsGroup;
|
@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
|
// error message
|
||||||
protected static final String ERROR_PRODUCT_CREATION = "There was an error while trying to publish your product, sorry.. Retry later";
|
protected static final String ERROR_PRODUCT_CREATION = "There was an error while trying to publish your product, sorry.. Retry later";
|
||||||
|
|
||||||
|
@ -603,37 +604,65 @@ public class CreateDatasetForm extends Composite{
|
||||||
void onContinueButton(ClickEvent e){
|
void onContinueButton(ClickEvent e){
|
||||||
|
|
||||||
// validate data
|
// validate data
|
||||||
String errorMsg = validateDataOnContinue();
|
final String errorMsg = validateDataOnContinue();
|
||||||
|
|
||||||
if(errorMsg == null){
|
if(errorMsg != null){
|
||||||
// check what to do
|
|
||||||
if(isWorkspaceRequest){
|
|
||||||
|
|
||||||
// we need to show the page to handle resources one by one from the workspace
|
alertOnContinue("Please check inserted data [" + errorMsg + "]", AlertType.ERROR);
|
||||||
formFirstStep.setVisible(false);
|
return;
|
||||||
boolean resourcesPresent = receivedBean.getResources() != null && receivedBean.getResources().size() > 0 ? true : false;
|
|
||||||
formSecondStep.setVisible(resourcesPresent);
|
|
||||||
formThirdStep.setVisible(!resourcesPresent);
|
|
||||||
|
|
||||||
// add the resources to the container panel
|
|
||||||
if(workspaceResourcesContainer.getWidget() == null)
|
|
||||||
workspaceResourcesContainer.add(resourcesTable);
|
|
||||||
|
|
||||||
}else{
|
|
||||||
|
|
||||||
// this is not a workspace request
|
|
||||||
formFirstStep.setVisible(false);
|
|
||||||
formThirdStep.setVisible(true);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
if(metadataProfilesFormatListbox.getSelectedItemText().equals("none"))
|
|
||||||
selectedProfile.setText("");
|
|
||||||
else
|
|
||||||
selectedProfile.setText("Selected Profile is " + metadataProfilesFormatListbox.getSelectedItemText());
|
|
||||||
|
|
||||||
}else{
|
}else{
|
||||||
alertOnContinue("Please check inserted data [" + errorMsg + "]", AlertType.ERROR);
|
|
||||||
|
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){
|
||||||
|
|
||||||
|
// we need to show the page to handle resources one by one from the workspace
|
||||||
|
formFirstStep.setVisible(false);
|
||||||
|
boolean resourcesPresent = receivedBean.getResources() != null && receivedBean.getResources().size() > 0 ? true : false;
|
||||||
|
formSecondStep.setVisible(resourcesPresent);
|
||||||
|
formThirdStep.setVisible(!resourcesPresent);
|
||||||
|
|
||||||
|
// add the resources to the container panel
|
||||||
|
if(workspaceResourcesContainer.getWidget() == null)
|
||||||
|
workspaceResourcesContainer.add(resourcesTable);
|
||||||
|
|
||||||
|
}else{
|
||||||
|
|
||||||
|
// this is not a workspace request
|
||||||
|
formFirstStep.setVisible(false);
|
||||||
|
formThirdStep.setVisible(true);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if(metadataProfilesFormatListbox.getSelectedItemText().equals("none"))
|
||||||
|
selectedProfile.setText("");
|
||||||
|
else
|
||||||
|
selectedProfile.setText("Selected Profile is " + metadataProfilesFormatListbox.getSelectedItemText());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@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
|
// better check for the title
|
||||||
String regexTitleSubWord = "[^a-zA-Z0-9_.-]";
|
|
||||||
String[] splittedTitle = titleTextBox.getText().split(" ");
|
String[] splittedTitle = titleTextBox.getText().split(" ");
|
||||||
|
|
||||||
for (String word : splittedTitle) {
|
for (String word : splittedTitle) {
|
||||||
String replaced = word.replaceAll(regexTitleSubWord, "");
|
String replaced = word.replaceAll(REGEX_TITLE_PRODUCT_SUBWORD, "");
|
||||||
if(!replaced.equals(word)){
|
if(!replaced.equals(word)){
|
||||||
productTitleGroup.setType(ControlGroupType.ERROR);
|
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
|
// email reg expression
|
||||||
String regexMail = "\\b[\\w.%-]+@[-.\\w]+\\.[A-Za-z]{2,4}\\b";
|
if(!validateByRegExpression(maintainerEmailTextbox.getText(), REGEX_MAIL)){
|
||||||
if(!validateByRegExpression(maintainerEmailTextbox.getText(), regexMail)){
|
|
||||||
maintainerControlGroup.setType(ControlGroupType.ERROR);
|
maintainerControlGroup.setType(ControlGroupType.ERROR);
|
||||||
return "Not valid maintainer email";
|
return "Not valid maintainer email";
|
||||||
}
|
}
|
||||||
|
|
|
@ -620,7 +620,8 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
|
||||||
try{
|
try{
|
||||||
|
|
||||||
String scope = (String)getThreadLocalRequest().getSession().getAttribute(SessionCatalogueAttributes.SCOPE_CLIENT_PORTLET_URL);
|
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){
|
}catch(Exception e){
|
||||||
logger.error("Unable to check if such a dataset id already exists", e);
|
logger.error("Unable to check if such a dataset id already exists", e);
|
||||||
|
|
Loading…
Reference in New Issue