Dataset creation is divided into three steps now (in the case in which the request doesn't come from the workspace)

git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/widgets/ckan-metadata-publisher-widget@129049 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Costantino Perciante 2016-06-10 10:10:18 +00:00
parent ef81439445
commit f5dfd39e20
11 changed files with 151 additions and 56 deletions

View File

@ -22,9 +22,9 @@ public class CKanMetadataPublisher implements EntryPoint {
private void startExample() {
String idFolderWorkspace = "8b67fc1f-940d-4512-b783-105fba11c270";
String owner = "costantino.perciante";
RootPanel.get("ckan-metadata-publisher-div").add(new CreateDatasetForm(owner));
String idFolderWorkspace = "d3a37eb9-1589-4c95-a9d0-c473a02d4f0f";
String owner = "costantino_perciante";
RootPanel.get("ckan-metadata-publisher-div").add(new CreateDatasetForm(idFolderWorkspace, owner));
}
}

View File

@ -33,9 +33,9 @@ public interface CKanPublisherService extends RemoteService {
* Try to create such dataset starting from the information contained into the toCreate bean.
* @param toCreate
* @param isWorkspaceRequest if the call comes from the workspace
* @return the identifier of the created dataset or null on error
* @return the sent bean full filled with the needed information
*/
String createCKanDataset(DatasetMetadataBean toCreate, boolean isWorkspaceRequest);
DatasetMetadataBean createCKanDataset(DatasetMetadataBean toCreate, boolean isWorkspaceRequest);
/**
* Add this resource to the dataset whose id is datasetId

View File

@ -32,10 +32,10 @@ public interface CKanPublisherServiceAsync {
* Try to create such dataset starting from the information contained into the toCreate bean.
* @param toCreate
* @param isWorkspaceRequest if the call comes from the workspace
* @return <b>true</b> on success, <b>false</b> otherwise
* @return the sent bean full filled with the needed information
*/
void createCKanDataset(DatasetMetadataBean toCreate, boolean isWorkspaceRequest,
AsyncCallback<String> callback);
AsyncCallback<DatasetMetadataBean> callback);
/**
* Add this resource to the dataset whose id is datasetId

View File

@ -0,0 +1,50 @@
package org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui;
import com.github.gwtbootstrap.client.ui.Button;
import com.github.gwtbootstrap.client.ui.TabPanel;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;
/**
* Container for the third phase (add resource to dataset)
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
*/
public class AddResourceContainer extends Composite{
private static AddResourceContainerUiBinder uiBinder = GWT
.create(AddResourceContainerUiBinder.class);
interface AddResourceContainerUiBinder extends
UiBinder<Widget, AddResourceContainer> {
}
@UiField VerticalPanel resourcesPanel;
@UiField Button goToDatasetButton;
public AddResourceContainer(final String datasetUrl) {
initWidget(uiBinder.createAndBindUi(this));
goToDatasetButton.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
Window.Location.assign(datasetUrl);
}
});
}
/**
* Add the form to this panel
* @param w
*/
public void add(TabPanel w){
resourcesPanel.add(w);
}
}

View File

@ -0,0 +1,10 @@
<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
xmlns:g="urn:import:com.google.gwt.user.client.ui" xmlns:b="urn:import:com.github.gwtbootstrap.client.ui">
<g:HTMLPanel>
<b:Button title="Go to dataset" ui:field="goToDatasetButton"
block="true" visible="true">Go to Dataset</b:Button>
<!-- Here will be placed the form for the resources -->
<g:VerticalPanel ui:field="resourcesPanel" width="100%"></g:VerticalPanel>
</g:HTMLPanel>
</ui:UiBinder>

View File

@ -3,6 +3,6 @@
xmlns:g="urn:import:com.google.gwt.user.client.ui">
<g:HTMLPanel>
<h3>Added Resources</h3>
<g:VerticalPanel ui:field="addResourcesPanel" width="97%"></g:VerticalPanel>
<g:VerticalPanel ui:field="addResourcesPanel" width="100%"></g:VerticalPanel>
</g:HTMLPanel>
</ui:UiBinder>

View File

@ -30,6 +30,7 @@ import com.github.gwtbootstrap.client.ui.TextArea;
import com.github.gwtbootstrap.client.ui.TextBox;
import com.github.gwtbootstrap.client.ui.base.ListItem;
import com.github.gwtbootstrap.client.ui.constants.AlertType;
import com.github.gwtbootstrap.client.ui.constants.ButtonType;
import com.github.gwtbootstrap.client.ui.resources.Bootstrap.Tabs;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ChangeEvent;
@ -39,14 +40,15 @@ import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.dom.client.KeyCodes;
import com.google.gwt.event.dom.client.KeyDownEvent;
import com.google.gwt.event.shared.HandlerManager;
import com.google.gwt.regexp.shared.RegExp;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.Timer;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.HTMLPanel;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;
@ -68,6 +70,7 @@ public class CreateDatasetForm extends Composite{
UiBinder<Widget, CreateDatasetForm> {
}
@UiField HTMLPanel createDatasetMainPanel;
@UiField TextBox titleTextBox;
@UiField TextArea descriptionTextarea;
@UiField TextBox tagsEnterTextBox;
@ -85,12 +88,10 @@ public class CreateDatasetForm extends Composite{
@UiField CheckBox addResourcesCheckBox;
@UiField ControlGroup resourcesControlGroup;
@UiField Button createButton;
@UiField Button addResourcesButton;
@UiField Button resetButton;
@UiField AlertBlock infoBlock;
@UiField AlertBlock onContinueAlertBlock;
@UiField AlertBlock onCreateAlertBlock;
@UiField VerticalPanel resourcesPanel;
@UiField VerticalPanel metadataFieldsPanel;
@UiField ListBox metadataProfilesFormatListbox;
@UiField Form formFirstStep;
@ -98,6 +99,8 @@ public class CreateDatasetForm extends Composite{
@UiField Button continueButton;
@UiField Button goBackButton;
@UiField Paragraph selectedProfile;
@UiField Button goToDatasetButton;
@UiField Button addResourcesButton;
// tab panel
private TabPanel tabPanel;
@ -251,6 +254,9 @@ public class CreateDatasetForm extends Composite{
continueButton.setEnabled(false);
resetButton.setEnabled(false);
// set to visible the checkbox to add resources of the workspace
resourcesControlGroup.setVisible(true);
// get back the licenses and the metadata information from the workspace
ckanServices.getDatasetBean(idFolderWorkspace, owner, new AsyncCallback<DatasetMetadataBean>() {
@ -525,40 +531,63 @@ public class CreateDatasetForm extends Composite{
alertOnCreate("Trying to create dataset, please wait", AlertType.INFO);
ckanServices.createCKanDataset(receivedBean, isWorkspaceRequest, new AsyncCallback<String>() {
ckanServices.createCKanDataset(receivedBean, isWorkspaceRequest, new AsyncCallback<DatasetMetadataBean>() {
@Override
public void onSuccess(final String datasetId) {
public void onSuccess(final DatasetMetadataBean createdDatasetBean) {
if(datasetId != null){
if(createdDatasetBean != null){
alertOnCreate("Dataset correctly created!", AlertType.SUCCESS);
// disable dataset fields
disableDatasetFields();
// if we are in the "general case" we need to show a form for adding resources
if(!resourcesControlGroup.isVisible()){
// show the go to dataset button
final String datasetUrl = createdDatasetBean.getSource();
goToDatasetButton.setVisible(true);
goToDatasetButton.addClickHandler(new ClickHandler() {
createButton.setVisible(false);
goBackButton.setVisible(false);
@Override
public void onClick(ClickEvent event) {
Window.Location.assign(datasetUrl);
}
});
// if we are in the "general case" we need to show a form for adding resources
if(isWorkspaceRequest)
{
// leave to back button, but remove create and add go to dataset
createButton.removeFromParent();
resetButton.setEnabled(false);
// set go to dataset as primary
goToDatasetButton.setType(ButtonType.PRIMARY);
}else{
// remove create button
createButton.removeFromParent();
// show the add resources button
addResourcesButton.setVisible(true);
addResourcesButton.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
// hide the button
addResourcesButton.setVisible(false);
// remove content of the main panel
createDatasetMainPanel.clear();
// TabPanel
tabPanel = new TabPanel(Tabs.ABOVE);
tabPanel.setWidth("100%");
// add the form
resourceForm = new AddResourceToDataset(eventBus, datasetId, owner);
resourceForm = new AddResourceToDataset(eventBus, createdDatasetBean.getId(), owner);
// tab for the form
Tab formContainer = new Tab();
@ -574,16 +603,21 @@ public class CreateDatasetForm extends Composite{
// add tabs to resources panel
tabPanel.selectTab(0);
resourcesPanel.add(tabPanel);
resourcesPanel.setVisible(true);
// form container
AddResourceContainer container = new AddResourceContainer(datasetUrl);
container.add(tabPanel);
// add the new content of the main panel
createDatasetMainPanel.add(container);
}
});
}
}else{
alertOnCreate("Unable to create this dataset, please retry later", AlertType.ERROR);
alertOnCreate("Unable to create this dataset, maybe it exists?", AlertType.ERROR);
}
}
@ -591,13 +625,13 @@ public class CreateDatasetForm extends Composite{
@Override
public void onFailure(Throwable caught) {
alertOnCreate("Unable to create this dataset, please retry later", AlertType.ERROR);
alertOnCreate("Unable to create this dataset, maybe it exists?", AlertType.ERROR);
}
});
}else{
alertOnCreate("Please check the inserted values", AlertType.ERROR);
alertOnCreate("Please check the inserted values and the mandatory fields", AlertType.ERROR);
}
}
@ -683,6 +717,13 @@ public class CreateDatasetForm extends Composite{
errorMessage = "Missing title";
return errorMessage;
}
// name reg expression
String regexName = "^[a-zA-Z\\s]+";
if(!validateByRegExpression(maintainerTextbox.getText(), regexName)){
errorMessage = "Not valid maintainer name"; // TODO
return errorMessage;
}
// email reg expression
String regexMail = "\\b[\\w.%-]+@[-.\\w]+\\.[A-Za-z]{2,4}\\b";
@ -691,13 +732,6 @@ public class CreateDatasetForm extends Composite{
return errorMessage;
}
// name reg expression
String regexName = "^[a-zA-Z\\s]+";
if(!validateByRegExpression(maintainerTextbox.getText(), regexName)){
errorMessage = "Not valid maintainer name"; // TODO
return errorMessage;
}
// check if metadata profile is different from none and its mandatory fields have been fulfilled
if(checkSelectedMetaDataProfile()){
errorMessage = "You must select a metadata profile different frome none";
@ -721,8 +755,7 @@ public class CreateDatasetForm extends Composite{
* @return
*/
private boolean validateByRegExpression(String textToValidate, String regex){
RegExp pattern = RegExp.compile(regex);
return pattern.test(textToValidate);
return textToValidate.matches(regex);
}
@UiHandler("resetButton")

View File

@ -38,7 +38,7 @@
font-weight: bold;
}
</ui:style>
<g:HTMLPanel>
<g:HTMLPanel ui:field="createDatasetMainPanel">
<b:Form type="HORIZONTAL" styleName="{style.form-main-style}"
ui:field="formFirstStep" visible="true">
<b:Fieldset styleName="{style.fieldset-border-style}">
@ -249,7 +249,8 @@
</b:Controls>
</b:ControlGroup>
<b:ControlGroup ui:field="resourcesControlGroup" visible="false">
<b:ControlGroup ui:field="resourcesControlGroup"
visible="false">
<b:Controls>
<b:CheckBox
title="Automatically add the folder content to the dataset as resource"
@ -258,7 +259,7 @@
</b:CheckBox>
<span style="float:right; width:256px; color: #aaaaaa;">
<b:Icon type="INFO_SIGN" size="TWO_TIMES" />
Automatically add folder' files as resources of the dataset
Automatically add folder content as resources of the dataset
</span>
</b:Controls>
</b:ControlGroup>
@ -269,17 +270,16 @@
</b:AlertBlock>
<b:Button title="Add resources to the just created dataset"
type="PRIMARY" visible="false" ui:field="addResourcesButton">Add Resources</b:Button>
<!-- Here will be placed the form for the resources -->
<g:VerticalPanel ui:field="resourcesPanel" visible="false"
width="100%"></g:VerticalPanel>
block="true" type="PRIMARY" visible="false" ui:field="addResourcesButton">Add Resources</b:Button>
<b:Button title="Create dataset" ui:field="createButton"
type="PRIMARY" block="true">Create</b:Button>
<b:Button title="Go Back" ui:field="goBackButton" block="true">Go
Back</b:Button>
<b:Button title="Go to dataset" ui:field="goToDatasetButton"
block="true" visible="false">Go to Dataset</b:Button>
</b:Fieldset>
</b:Form>
</g:HTMLPanel>

View File

@ -11,7 +11,6 @@ import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.Element;
import com.google.gwt.dom.client.SpanElement;
import com.google.gwt.dom.client.Style.Display;
import com.google.gwt.regexp.shared.RegExp;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.Composite;
@ -118,11 +117,11 @@ public class MetaDataFieldSkeleton extends Composite{
* @return
*/
public boolean isFieldValueValid() {
String validator = field.getValidator();
// if validator is not present and it is not a textbox
if((validator == null || validator.isEmpty()) && !holder.getClass().equals(TextBox.class))
if((validator == null || validator.isEmpty()) && !(holder.getClass().equals(TextBox.class) && field.getMandatory()))
return true;
// current value
@ -134,7 +133,7 @@ public class MetaDataFieldSkeleton extends Composite{
else if(holder.getClass().equals(TextBox.class)){
value = ((TextBox)holder).getText();
// if thereis not a validator...
// if there is not a validator...
if(validator == null){
if(value.isEmpty() && field.getMandatory())
return false;
@ -145,10 +144,9 @@ public class MetaDataFieldSkeleton extends Composite{
}
}
else
return true; // it's a checkbox
return true; // it's a checkbox (the value doesn't matter)
RegExp pattern = RegExp.compile(validator);
return pattern.test(value);
return value.matches(validator);
}

View File

@ -386,7 +386,7 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
}
@Override
public String createCKanDataset(DatasetMetadataBean toCreate, boolean isWorkspaceRequest) {
public DatasetMetadataBean createCKanDataset(DatasetMetadataBean toCreate, boolean isWorkspaceRequest) {
// retrieve ckan's catalog url
String ckanPortalUrl = getCatalogueUrl();
@ -509,6 +509,10 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
try{
res = client.createDataset(dataset);
// add source and id to the incoming bean
toCreate.setId(res.getId());
toCreate.setSource(getCatalogueUrl() + "/dataset/" + res.getName());
}catch(Exception e){
@ -524,7 +528,7 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
return null;
}
return res.getId();
return toCreate;
}
/**
@ -533,9 +537,9 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
* @return
*/
private String nameFromTitle(String title) {
String convertedName = title.replaceAll(" ", "-");
String convertedName = title.replaceAll(" ", "_").replaceAll(".", "_");
convertedName = convertedName.toLowerCase();
if(convertedName.endsWith("-"))
if(convertedName.endsWith("_"))
convertedName = convertedName.substring(0, convertedName.length() - 2);
return convertedName;

View File

@ -15,7 +15,7 @@ import org.junit.Test;
public class Tests {
//@Test
@Test
public void test() throws WorkspaceFolderNotFoundException, InternalErrorException, HomeNotFoundException, UserNotFoundException, ItemNotFoundException{
ScopeProvider.instance.set("/gcube");
@ -28,7 +28,7 @@ public class Tests {
List<WorkspaceItem> childrens = ws.getRoot().getChildren();
for (WorkspaceItem workspaceItem : childrens) {
if(workspaceItem.getName().equals("CkanTest1137")){
if(workspaceItem.getName().equals("test-ckan-folder")){
System.out.println("Dir has id " + workspaceItem.getId());