From ef8143944591add51293e340db54c24d164a4d09 Mon Sep 17 00:00:00 2001 From: Costantino Perciante Date: Thu, 9 Jun 2016 16:58:19 +0000 Subject: [PATCH] The widget is almost finished. Profile information are also shown now. git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/widgets/ckan-metadata-publisher-widget@129045 82a268e6-3cf1-43bd-a215-b396298e98cf --- .settings/org.eclipse.wst.common.component | 3 + .../client/ui/CreateDatasetForm.java | 276 ++++++++++++++---- .../client/ui/CreateDatasetForm.ui.xml | 64 ++-- .../client/ui/MetaDataFieldSkeleton.java | 198 +++++++++++++ .../client/ui/MetaDataFieldSkeleton.ui.xml | 21 ++ .../server/CKANPublisherServicesImpl.java | 97 ++++-- .../shared/DatasetMetadataBean.java | 10 +- .../shared/MetaDataProfileBean.java | 62 ++++ .../shared/MetaDataTypeWrapper.java | 107 +++++++ .../shared/MetadataFieldWrapper.java | 205 +++++++++++++ 10 files changed, 927 insertions(+), 116 deletions(-) create mode 100644 src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/MetaDataFieldSkeleton.java create mode 100644 src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/MetaDataFieldSkeleton.ui.xml create mode 100644 src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/shared/MetaDataProfileBean.java create mode 100644 src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/shared/MetaDataTypeWrapper.java create mode 100644 src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/shared/MetadataFieldWrapper.java diff --git a/.settings/org.eclipse.wst.common.component b/.settings/org.eclipse.wst.common.component index 0190c48..5dbcbf7 100644 --- a/.settings/org.eclipse.wst.common.component +++ b/.settings/org.eclipse.wst.common.component @@ -5,6 +5,9 @@ + + uses + diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/CreateDatasetForm.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/CreateDatasetForm.java index d0af196..3741eac 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/CreateDatasetForm.java +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/CreateDatasetForm.java @@ -7,7 +7,6 @@ import java.util.List; import java.util.Map; import java.util.Map.Entry; -import org.gcube.datacatalogue.ckanutillibrary.models.MetaDataBean; import org.gcube.portlets.user.gcubewidgets.client.elements.Span; import org.gcube.portlets.widgets.ckandatapublisherwidget.client.CKanPublisherService; import org.gcube.portlets.widgets.ckandatapublisherwidget.client.CKanPublisherServiceAsync; @@ -15,12 +14,16 @@ import org.gcube.portlets.widgets.ckandatapublisherwidget.client.events.DeleteCu import org.gcube.portlets.widgets.ckandatapublisherwidget.client.events.DeleteCustomFieldEventHandler; import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.DatasetMetadataBean; import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.LicensesBean; +import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.MetaDataProfileBean; +import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.MetadataFieldWrapper; import com.github.gwtbootstrap.client.ui.AlertBlock; import com.github.gwtbootstrap.client.ui.Button; import com.github.gwtbootstrap.client.ui.CheckBox; import com.github.gwtbootstrap.client.ui.ControlGroup; +import com.github.gwtbootstrap.client.ui.Form; import com.github.gwtbootstrap.client.ui.ListBox; +import com.github.gwtbootstrap.client.ui.Paragraph; import com.github.gwtbootstrap.client.ui.Tab; import com.github.gwtbootstrap.client.ui.TabPanel; import com.github.gwtbootstrap.client.ui.TextArea; @@ -29,12 +32,13 @@ import com.github.gwtbootstrap.client.ui.base.ListItem; import com.github.gwtbootstrap.client.ui.constants.AlertType; import com.github.gwtbootstrap.client.ui.resources.Bootstrap.Tabs; import com.google.gwt.core.client.GWT; +import com.google.gwt.event.dom.client.ChangeEvent; +import com.google.gwt.event.dom.client.ChangeHandler; import com.google.gwt.event.dom.client.ClickEvent; 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.MatchResult; import com.google.gwt.regexp.shared.RegExp; import com.google.gwt.uibinder.client.UiBinder; import com.google.gwt.uibinder.client.UiField; @@ -47,7 +51,7 @@ import com.google.gwt.user.client.ui.VerticalPanel; import com.google.gwt.user.client.ui.Widget; /** - * Edit metadata form for ckan dataset. + * Create metadata form for ckan dataset. * @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it) */ public class CreateDatasetForm extends Composite{ @@ -84,10 +88,16 @@ public class CreateDatasetForm extends Composite{ @UiField Button addResourcesButton; @UiField Button resetButton; @UiField AlertBlock infoBlock; + @UiField AlertBlock onContinueAlertBlock; @UiField AlertBlock onCreateAlertBlock; @UiField VerticalPanel resourcesPanel; - @UiField VerticalPanel metadataPanel; - @UiField ListBox metadataFormatListbox; + @UiField VerticalPanel metadataFieldsPanel; + @UiField ListBox metadataProfilesFormatListbox; + @UiField Form formFirstStep; + @UiField Form formSecondStep; + @UiField Button continueButton; + @UiField Button goBackButton; + @UiField Paragraph selectedProfile; // tab panel private TabPanel tabPanel; @@ -116,6 +126,9 @@ public class CreateDatasetForm extends Composite{ // workspace request? private boolean isWorkspaceRequest = false; + // the list of MetaDataFieldSkeleton added + List listOfMetadataFields = new ArrayList(); + /** * Invoked in the most general case * @param owner @@ -131,8 +144,8 @@ public class CreateDatasetForm extends Composite{ // set info block setAlertBlock("Retrieving information, please wait...", AlertType.INFO, true); - // disable create button - createButton.setEnabled(false); + // disable continue/reset button + continueButton.setEnabled(false); resetButton.setEnabled(false); // get back the licenses and the metadata information @@ -179,7 +192,7 @@ public class CreateDatasetForm extends Composite{ // everything went ok setAlertBlock("", AlertType.ERROR, false); - createButton.setEnabled(true); + continueButton.setEnabled(true); resetButton.setEnabled(true); }else{ @@ -211,26 +224,10 @@ public class CreateDatasetForm extends Composite{ }); // hide the Add resources checkbox - resourcesControlGroup.setVisible(false); + resourcesControlGroup.removeFromParent(); } - /** - * Add the items to the listbox and put data into the metadataPanel - * @param receivedBean - */ - protected void prepareMetadataList(DatasetMetadataBean receivedBean) { - - List beans = receivedBean.getMetadataList(); - - for(MetaDataBean metadataBean: beans){ - - //metadataFormatListbox.addItem(metadataBean.getType().getName()); - - } - - } - /** * Invoked when the workspace is used. * @param idFolderWorkspace @@ -250,8 +247,8 @@ public class CreateDatasetForm extends Composite{ // set info block setAlertBlock("Retrieving information, please wait...", AlertType.INFO, true); - // disable create button - createButton.setEnabled(false); + // disable continue button + continueButton.setEnabled(false); resetButton.setEnabled(false); // get back the licenses and the metadata information from the workspace @@ -287,8 +284,6 @@ public class CreateDatasetForm extends Composite{ // retrieve custom fields Map customFieldsMap = bean.getCustomFields(); - GWT.log("Custom fields is " + customFieldsMap); - if(customFieldsMap != null){ // get the keys and put them as tags @@ -329,7 +324,7 @@ public class CreateDatasetForm extends Composite{ // everything went ok setAlertBlock("", AlertType.ERROR, false); - createButton.setEnabled(true); + continueButton.setEnabled(true); resetButton.setEnabled(true); }else{ @@ -362,6 +357,63 @@ public class CreateDatasetForm extends Composite{ } + /** + * Add the items to the listbox and put data into the metadataPanel + * @param receivedBean + */ + protected void prepareMetadataList(DatasetMetadataBean receivedBean) { + + List beans = receivedBean.getMetadataList(); + + for(MetaDataProfileBean metadataBean: beans){ + + metadataProfilesFormatListbox.addItem(metadataBean.getType().getName()); + + // add handler on select + metadataProfilesFormatListbox.addChangeHandler(new ChangeHandler() { + + @Override + public void onChange(ChangeEvent event) { + + String selectedItem = metadataProfilesFormatListbox.getSelectedItemText(); + + if(selectedItem.equals("none")){ + // hide the panel + metadataFieldsPanel.clear(); + metadataFieldsPanel.setVisible(false); + }else{ + + metadataFieldsPanel.clear(); + addFields(selectedItem); + } + } + }); + } + } + + protected void addFields(String selectedItem) { + + for(MetaDataProfileBean bean: receivedBean.getMetadataList()){ + + if(bean.getType().getName().equals(selectedItem)){ + + // prepare the data + List fields = bean.getMetadataFields(); + + // clear old data + listOfMetadataFields.clear(); + + for (MetadataFieldWrapper field : fields) { + MetaDataFieldSkeleton fieldWidget = new MetaDataFieldSkeleton(field); + metadataFieldsPanel.add(fieldWidget); + listOfMetadataFields.add(fieldWidget); + } + + metadataFieldsPanel.setVisible(true); + } + } + } + /** * Bind on events */ @@ -390,19 +442,37 @@ public class CreateDatasetForm extends Composite{ } + @UiHandler("continueButton") + void onContinueButton(ClickEvent e){ + + // validate data + String errorMsg = validateDataOnContinue(); + + if(errorMsg == null){ + formFirstStep.setVisible(false); + formSecondStep.setVisible(true); + selectedProfile.setText("Selected Profile is " + metadataProfilesFormatListbox.getSelectedItemText()); + }else{ + alertOnContinue("Please check inserted data [" + errorMsg + "]", AlertType.ERROR); + } + + } + + @UiHandler("goBackButton") + void onGoBackButton(ClickEvent e){ + + // swap forms + formFirstStep.setVisible(true); + formSecondStep.setVisible(false); + + } + @UiHandler("createButton") void createDatasetEvent(ClickEvent e){ - // validate data - boolean areDataValid = validateData(); + boolean profileDataValid = areProfileDataValid(); - // Collect current data and send them to the server - if(!areDataValid){ - - alertOnCreate("Please check inserted data ", AlertType.ERROR); - - } - else{ + if(profileDataValid){ String title = titleTextBox.getValue(); String description = descriptionTextarea.getText(); @@ -433,6 +503,12 @@ public class CreateDatasetForm extends Composite{ Map customFieldsMap = new HashMap(); // prepare custom fields + for (MetaDataFieldSkeleton field : listOfMetadataFields) { + + customFieldsMap.put(field.getFieldName(), field.getFieldCurrentValue()); + + } + for(CustomFieldEntry customEntry : customFieldEntriesList){ String key = customEntry.getKey(); @@ -445,7 +521,7 @@ public class CreateDatasetForm extends Composite{ // invoke the create method createButton.setEnabled(false); - resetButton.setEnabled(false); + goBackButton.setEnabled(false); alertOnCreate("Trying to create dataset, please wait", AlertType.INFO); @@ -465,7 +541,7 @@ public class CreateDatasetForm extends Composite{ if(!resourcesControlGroup.isVisible()){ createButton.setVisible(false); - resetButton.setVisible(false); + goBackButton.setVisible(false); // show the add resources button addResourcesButton.setVisible(true); @@ -519,11 +595,57 @@ public class CreateDatasetForm extends Composite{ } }); + }else{ + + alertOnCreate("Please check the inserted values", AlertType.ERROR); + } } /** - * On create show alert box and enable buttons + * Test if profile data are valid + * @return + */ + private boolean areProfileDataValid() { + + for (MetaDataFieldSkeleton field : listOfMetadataFields) { + + if(!field.isFieldValueValid()) + return false; + } + + return true; + } + + /** + * On continue show alert box and enable buttons + * @param text + * @param type + */ + private void alertOnContinue(String text, AlertType type){ + + onContinueAlertBlock.setText(text); + onContinueAlertBlock.setType(type); + onContinueAlertBlock.setVisible(true); + continueButton.setEnabled(true); + resetButton.setEnabled(true); + + // hide after some seconds + Timer t = new Timer() { + + @Override + public void run() { + + onContinueAlertBlock.setVisible(false); + + } + }; + + t.schedule(4000); + } + + /** + * On continue show alert box and enable buttons * @param text * @param type */ @@ -533,7 +655,7 @@ public class CreateDatasetForm extends Composite{ onCreateAlertBlock.setType(type); onCreateAlertBlock.setVisible(true); createButton.setEnabled(true); - resetButton.setEnabled(true); + goBackButton.setEnabled(true); // hide after some seconds Timer t = new Timer() { @@ -546,43 +668,63 @@ public class CreateDatasetForm extends Composite{ } }; - t.schedule(2000); + t.schedule(4000); } /** * Validate data * @return true on success, false otherwise */ - private boolean validateData() { - - boolean correct = true; + private String validateDataOnContinue() { + + String errorMessage = null; + + if(titleTextBox.getText().isEmpty()){ + errorMessage = "Missing title"; + return errorMessage; + } - if(titleTextBox.getText().isEmpty()) - correct = false; - // email reg expression String regexMail = "\\b[\\w.%-]+@[-.\\w]+\\.[A-Za-z]{2,4}\\b"; - - correct &= validateByRegExpression(maintainerEmailTextbox.getText(), regexMail); - + if(!validateByRegExpression(maintainerEmailTextbox.getText(), regexMail)){ + errorMessage = "Not valid maintainer email"; + return errorMessage; + } + // name reg expression String regexName = "^[a-zA-Z\\s]+"; - - correct &= validateByRegExpression(maintainerTextbox.getText(), regexName); + if(!validateByRegExpression(maintainerTextbox.getText(), regexName)){ + errorMessage = "Not valid maintainer name"; // TODO + return errorMessage; + } - return correct; + // 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"; + } + + return errorMessage; } + /** + * Checks if a metadata profile has been chosen and its fields have been fulfilled + * @return + */ + private boolean checkSelectedMetaDataProfile() { + return metadataProfilesFormatListbox.getSelectedItemText().equals("none"); + } + + /** + * Validate a text against a regular expression. + * @param textToValidate + * @param regex + * @return + */ private boolean validateByRegExpression(String textToValidate, String regex){ - RegExp pattern = RegExp.compile(regex); - MatchResult matcher = pattern.exec(textToValidate); - - GWT.log("Matcher is " + matcher); - - return (matcher != null); + return pattern.test(textToValidate); } - + @UiHandler("resetButton") void resetFormEvent(ClickEvent e){ @@ -629,6 +771,14 @@ public class CreateDatasetForm extends Composite{ tagWidget.getWidget(1).removeFromParent(); } + + // disable profile fields + for (MetaDataFieldSkeleton field : listOfMetadataFields) { + + field.freeze(); + + } + } /** diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/CreateDatasetForm.ui.xml b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/CreateDatasetForm.ui.xml index dfdbcf0..4ccbcc2 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/CreateDatasetForm.ui.xml +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/CreateDatasetForm.ui.xml @@ -33,10 +33,14 @@ .tagsPanelStyle { display: inline-block; } + + .selected-profile { + font-weight: bold; + } + ui:field="formFirstStep" visible="true"> @@ -62,18 +66,6 @@ - - - - - - - - - - - - Description: @@ -196,18 +188,45 @@ - Metadata - Format: + Metadata + Profile: - + + none - - + + + + + Continue + Reset + + + + + + + + + Insert Metadata Profile Information + + * + is required + + + + + + + @@ -230,7 +249,7 @@ - + Create - Reset + Go + Back diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/MetaDataFieldSkeleton.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/MetaDataFieldSkeleton.java new file mode 100644 index 0000000..9e0b9d8 --- /dev/null +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/MetaDataFieldSkeleton.java @@ -0,0 +1,198 @@ +package org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui; + +import java.util.List; + +import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.MetadataFieldWrapper; + +import com.github.gwtbootstrap.client.ui.CheckBox; +import com.github.gwtbootstrap.client.ui.ListBox; +import com.github.gwtbootstrap.client.ui.TextBox; +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; +import com.google.gwt.user.client.ui.SimplePanel; +import com.google.gwt.user.client.ui.Widget; + +public class MetaDataFieldSkeleton extends Composite{ + + private static MetaDataFieldSkeletonUiBinder uiBinder = GWT + .create(MetaDataFieldSkeletonUiBinder.class); + + interface MetaDataFieldSkeletonUiBinder extends + UiBinder { + } + + @UiField Element mandatorySymbol; + @UiField SpanElement name; + @UiField SimplePanel elementPanel; + @UiField SpanElement noteFieldContainer; + @UiField SpanElement noteField; + + // the element that holds the value (it could be a checkbox, textbox or listbox) + private Widget holder; + + // the field this object rapresents + private MetadataFieldWrapper field; + + public MetaDataFieldSkeleton(MetadataFieldWrapper field) { + initWidget(uiBinder.createAndBindUi(this)); + + // prepare information + this.field = field; + + // save the name + name.setInnerText(field.getFieldName() + ":"); + + // check if it is mandatory + if(!field.getMandatory()) + mandatorySymbol.getStyle().setDisplay(Display.NONE); + + if(field.getIsBoolean()){ + + // its a checkbox + holder = new CheckBox(); + + if(field.getDefaulValue() != null) + ((CheckBox)holder).setValue(Boolean.valueOf(field.getDefaulValue())); + + // add to the elementPanel + elementPanel.add(holder); + + }else{ + + // it could be a listbox or a textbox according to the vocabulary fields + if(field.getVocabulary() == null || field.getVocabulary().isEmpty()){ + + // textbox + holder = new TextBox(); + + if(field.getDefaulValue() != null) + ((TextBox)holder).setText(field.getDefaulValue()); + + // add to the elementPanel + elementPanel.add(holder); + + + }else{ + + // listbox + holder = new ListBox(); + + // get vocabulary fields + List vocabulary = field.getVocabulary(); + + for (String term : vocabulary) { + + ((ListBox)holder).addItem(term); + + } + + // set default value + ((ListBox)holder).setSelectedValue(field.getDefaulValue()); + + // add to the elementPanel + elementPanel.add(holder); + + } + + } + + // set the notes, if any + if(field.getNote() != null && !field.getNote().isEmpty()){ + noteField.setInnerText(field.getNote()); + noteFieldContainer.getStyle().setDisplay(Display.INITIAL); + + }else{ + + noteFieldContainer.getStyle().setDisplay(Display.NONE); + } + } + + /** + * Check if this field has a valid values + * @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)) + return true; + + // current value + String value; + + // we validate only listbox and textbox + if(holder.getClass().equals(ListBox.class)) + value = ((ListBox)holder).getSelectedItemText(); + else if(holder.getClass().equals(TextBox.class)){ + value = ((TextBox)holder).getText(); + + // if thereis not a validator... + if(validator == null){ + if(value.isEmpty() && field.getMandatory()) + return false; + else if(value.isEmpty() && !field.getMandatory()) + return true; + else if(!value.isEmpty()) + return true; + } + } + else + return true; // it's a checkbox + + RegExp pattern = RegExp.compile(validator); + return pattern.test(value); + + } + + /** + * Returns the current value of the field + * @return + */ + public String getFieldCurrentValue(){ + + String value; + + // we validate only listbox and textbox + if(holder.getClass().equals(ListBox.class)) + value = ((ListBox)holder).getSelectedItemText(); + else if(holder.getClass().equals(TextBox.class)) + value = ((TextBox)holder).getText(); + else + value = ((CheckBox)holder).getValue().toString(); + + return value; + } + + /** + * Returns the current value of the field + * @return + */ + public String getFieldName(){ + + return field.getFieldName(); + + } + + /** + * Freeze this widget (after on create) + */ + public void freeze() { + + if(holder.getClass().equals(ListBox.class)) + ((ListBox)holder).setEnabled(false); + else if(holder.getClass().equals(TextBox.class)) + ((TextBox)holder).setEnabled(false); + else + ((CheckBox)holder).setEnabled(false); + + } + +} diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/MetaDataFieldSkeleton.ui.xml b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/MetaDataFieldSkeleton.ui.xml new file mode 100644 index 0000000..2083b8f --- /dev/null +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/MetaDataFieldSkeleton.ui.xml @@ -0,0 +1,21 @@ + + + + + + * + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/CKANPublisherServicesImpl.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/CKANPublisherServicesImpl.java index 107cd1e..d53c2f1 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/CKANPublisherServicesImpl.java +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/CKANPublisherServicesImpl.java @@ -22,10 +22,18 @@ import org.gcube.common.homelibrary.home.workspace.folder.FolderItem; import org.gcube.common.homelibrary.home.workspace.folder.items.GCubeItem; import org.gcube.common.scope.api.ScopeProvider; import org.gcube.datacatalogue.ckanutillibrary.CKanUtilsFactory; -import org.gcube.datacatalogue.ckanutillibrary.models.MetaDataBean; +import org.gcube.datacatalogue.metadatadiscovery.DataCalogueMetadataFormatReader; +import org.gcube.datacatalogue.metadatadiscovery.bean.MetadataType; +import org.gcube.datacatalogue.metadatadiscovery.bean.jaxb.MetadataField; +import org.gcube.datacatalogue.metadatadiscovery.bean.jaxb.MetadataFormat; +import org.gcube.datacatalogue.metadatadiscovery.bean.jaxb.MetadataValidator; +import org.gcube.datacatalogue.metadatadiscovery.bean.jaxb.MetadataVocabulary; import org.gcube.portlets.widgets.ckandatapublisherwidget.client.CKanPublisherService; import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.DatasetMetadataBean; import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.LicensesBean; +import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.MetaDataProfileBean; +import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.MetaDataTypeWrapper; +import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.MetadataFieldWrapper; import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.ResourceBean; import org.gcube.vomanagement.usermanagement.UserManager; import org.gcube.vomanagement.usermanagement.impl.LiferayUserManager; @@ -154,26 +162,65 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C return null; } - + /** * Retrieve the list of metadata beans * @return */ - private List getMetaDataBeanList(){ - - logger.debug("Request for metadata beans list"); - - try{ - - String currentScope = getCurrentScope(); - return CKanUtilsFactory.getInstance().getCkanUtilsForScope(currentScope).getMetadataList(); - - }catch(Exception e){ - logger.error("Unable to retrieve metadata", e); + public List getMetadataProfilesList() { + + List beans = new ArrayList(); + + try { + + ScopeProvider.instance.set("/gcube/devsec/devVRE"); // TODO remove + DataCalogueMetadataFormatReader reader = new DataCalogueMetadataFormatReader(); + + for (MetadataType mt : reader.getListOfMetadataTypes()) { + MetadataFormat metadata = reader.getMetadataFormatForMetadataType(mt); + + // we need to wrap the list of metadata + List wrapperList = new ArrayList(); + List toWrap = metadata.getMetadataFields(); + for(MetadataField metadataField: toWrap){ + + MetadataFieldWrapper wrapperObj = new MetadataFieldWrapper(); + wrapperObj.setDefaulValue(metadataField.getDefaulValue()); + wrapperObj.setFieldName(metadataField.getFieldName()); + wrapperObj.setIsBoolean(metadataField.getIsBoolean()); + wrapperObj.setMandatory(metadataField.getMandatory()); + wrapperObj.setNote(metadataField.getNote()); + + MetadataValidator validator = metadataField.getValidator(); + if(validator != null) + wrapperObj.setValidator(validator.getRegularExpression()); + + MetadataVocabulary vocabulary = metadataField.getVocabulary(); + if(vocabulary != null) + wrapperObj.setVocabulary(vocabulary.getVocabularyFields()); + + // add to the list + wrapperList.add(wrapperObj); + + } + + // wrap the mt as well + MetaDataTypeWrapper typeWrapper = new MetaDataTypeWrapper(); + typeWrapper.setDescription(mt.getDescription()); + typeWrapper.setId(mt.getId()); + typeWrapper.setName(mt.getName()); + MetaDataProfileBean bean = new MetaDataProfileBean(typeWrapper, wrapperList); + beans.add(bean); + } + + logger.debug("List of beans is " + beans); + return beans; + + } catch (Exception e) { + logger.error("Error while retrieving metadata beans ", e); } - + return null; - } @Override @@ -249,11 +296,11 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C } bean.setResourcesIds(childrenIds); - + // retrieve the metadata - List metadataBeans = getMetaDataBeanList(); + List metadataBeans = getMetadataProfilesList(); bean.setMetadataList(metadataBeans); - + } }catch(Exception e){ @@ -299,11 +346,11 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C bean.setResourcesIds(childrenIds); } - + // retrieve the metadata - List metadataBeans = getMetaDataBeanList(); + List metadataBeans = getMetadataProfilesList(); bean.setMetadataList(metadataBeans); - + }catch(Exception e){ logger.error("Error while building bean into dev mode", e); } @@ -548,7 +595,7 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C if(createdRes != null){ logger.debug("Resource " + createdRes.getName() + " is now available"); - + // set its id and turn it to the client resourceBean.setId(createdRes.getId()); return resourceBean; @@ -571,7 +618,7 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C logger.debug("Request for deleting resource " + resource); try{ - + // retrieve ckan's catalog url String ckanPortalUrl = getCatalogueUrl(); @@ -583,12 +630,12 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C client.deleteResource(resource.getId()); return true; - + }catch(Exception e){ logger.error("Unable to delete such resource", e); } return false; } - + } diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/shared/DatasetMetadataBean.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/shared/DatasetMetadataBean.java index 98e5268..25f971c 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/shared/DatasetMetadataBean.java +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/shared/DatasetMetadataBean.java @@ -4,8 +4,6 @@ import java.io.Serializable; import java.util.List; import java.util.Map; -import org.gcube.datacatalogue.ckanutillibrary.models.MetaDataBean; - /** * This bean will contain during ckan metadata creation the following information * (related to the workspace folder that represents a dataset) @@ -47,7 +45,7 @@ public class DatasetMetadataBean implements Serializable { private String selectedOrganization; private List resourcesIds; // in case of workspace, this is the list of children's ids private boolean addResources; // if true, add these files as resources to the dataset - private List metadataList; + private List metadataList; public DatasetMetadataBean(){ super(); @@ -81,7 +79,7 @@ public class DatasetMetadataBean implements Serializable { String maintainerEmail, String ownerIdentifier, List organizationList, String selectedOrganization, List resourcesIds, boolean addResources, - List metadataList) { + List metadataList) { super(); this.id = id; this.title = title; @@ -104,11 +102,11 @@ public class DatasetMetadataBean implements Serializable { this.metadataList = metadataList; } - public List getMetadataList() { + public List getMetadataList() { return metadataList; } - public void setMetadataList(List metadataList) { + public void setMetadataList(List metadataList) { this.metadataList = metadataList; } diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/shared/MetaDataProfileBean.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/shared/MetaDataProfileBean.java new file mode 100644 index 0000000..3eb9391 --- /dev/null +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/shared/MetaDataProfileBean.java @@ -0,0 +1,62 @@ +package org.gcube.portlets.widgets.ckandatapublisherwidget.shared; + +import java.io.Serializable; +import java.util.List; + +/** + * A MetaDataProfileBean with its children (MetaDataFormat) + * @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it) + */ +public class MetaDataProfileBean implements Serializable{ + + private static final long serialVersionUID = -7377022025375553568L; + + private MetaDataTypeWrapper type; // the type + private List metadataFields; // the fields of this type + + public MetaDataProfileBean(){ + super(); + } + + /** + * @param type + * @param metadataFields + */ + public MetaDataProfileBean(MetaDataTypeWrapper type, List metadataFields) { + super(); + this.type = type; + this.metadataFields = metadataFields; + } + /** + * @return the type + */ + public MetaDataTypeWrapper getType() { + return type; + } + /** + * @param type the type to set + */ + public void setType(MetaDataTypeWrapper type) { + this.type = type; + } + /** + * @return the metadataFields + */ + public List getMetadataFields() { + return metadataFields; + } + /** + * @param metadataFields the metadataFields to set + */ + public void setMetadataFields(List metadataFields) { + this.metadataFields = metadataFields; + } + /* (non-Javadoc) + * @see java.lang.Object#toString() + */ + @Override + public String toString() { + return "MetaDataBean [type=" + type + ", metadataFields=" + + metadataFields + "]"; + } +} diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/shared/MetaDataTypeWrapper.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/shared/MetaDataTypeWrapper.java new file mode 100644 index 0000000..3cf5d8e --- /dev/null +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/shared/MetaDataTypeWrapper.java @@ -0,0 +1,107 @@ +package org.gcube.portlets.widgets.ckandatapublisherwidget.shared; + +import java.io.Serializable; + +/** + * The Class MetadataTypeWrapper + * @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it) + */ +public class MetaDataTypeWrapper implements Serializable{ + + private static final long serialVersionUID = 2609935614105035447L; + private String id; + private String name; + private String description; + + /** + * Instantiates a new metadata type. + */ + public MetaDataTypeWrapper() { + + } + + /** + * Instantiates a new metadata type. + * + * @param id the id + * @param name the name + * @param description the description + */ + public MetaDataTypeWrapper(String id, String name, String description) { + + super(); + this.id = id; + this.name = name; + this.description = description; + } + + /** + * Gets the id. + * + * @return the id + */ + public String getId() { + + return id; + } + + /** + * Gets the name. + * + * @return the name + */ + public String getName() { + + return name; + } + + /** + * Gets the description. + * + * @return the description + */ + public String getDescription() { + + return description; + } + + /** + * Sets the id. + * + * @param id the id to set + */ + public void setId(String id) { + + this.id = id; + } + + /** + * Sets the name. + * + * @param name the name to set + */ + public void setName(String name) { + + this.name = name; + } + + /** + * Sets the description. + * + * @param description the description to set + */ + public void setDescription(String description) { + + this.description = description; + } + + /* (non-Javadoc) + * @see java.lang.Object#toString() + */ + @Override + public String toString() { + return "MetaDataTypeWrapper [id=" + id + ", name=" + name + + ", description=" + description + "]"; + } + +} diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/shared/MetadataFieldWrapper.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/shared/MetadataFieldWrapper.java new file mode 100644 index 0000000..41dde55 --- /dev/null +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/shared/MetadataFieldWrapper.java @@ -0,0 +1,205 @@ +package org.gcube.portlets.widgets.ckandatapublisherwidget.shared; + + +import java.io.Serializable; +import java.util.List; + +/** + * The Class MetadataFieldWrapper. + * @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it) + */ +public class MetadataFieldWrapper implements Serializable{ + + private static final long serialVersionUID = -8476731365884466698L; + private String fieldName; + private Boolean mandatory = false; + private Boolean isBoolean = false; + private String defaulValue; + private String note; + private List vocabulary; + private String validator; + + /** + * Instantiates a new metadata field. + */ + public MetadataFieldWrapper() { + super(); + } + + /** + * Instantiates a new metadata field. + * + * @param fieldName the field name + * @param mandatory the mandatory + * @param isBoolean the is boolean + * @param defaulValue the defaul value + * @param note the note + * @param vocabulary the vocabulary + * @param validator the validator + */ + public MetadataFieldWrapper( + String fieldName, Boolean mandatory, Boolean isBoolean, + String defaulValue, String note, List vocabulary, + String validator) { + super(); + this.fieldName = fieldName; + this.mandatory = mandatory; + this.isBoolean = isBoolean; + this.defaulValue = defaulValue; + this.note = note; + this.vocabulary = vocabulary; + this.validator = validator; + } + + /** + * Gets the field name. + * + * @return the fieldName + */ + public String getFieldName() { + + return fieldName; + } + + /** + * Gets the mandatory. + * + * @return the mandatory + */ + public Boolean getMandatory() { + + return mandatory; + } + + /** + * Gets the checks if is boolean. + * + * @return the isBoolean + */ + public Boolean getIsBoolean() { + + return isBoolean; + } + + /** + * Gets the defaul value. + * + * @return the defaulValue + */ + public String getDefaulValue() { + + return defaulValue; + } + + /** + * Gets the note. + * + * @return the note + */ + public String getNote() { + + return note; + } + + /** + * Gets the vocabulary. + * + * @return the vocabulary + */ + public List getVocabulary() { + + return vocabulary; + } + + /** + * Gets the validator. + * + * @return the validator + */ + public String getValidator() { + + return validator; + } + + /** + * Sets the field name. + * + * @param fieldName the fieldName to set + */ + public void setFieldName(String fieldName) { + + this.fieldName = fieldName; + } + + /** + * Sets the mandatory. + * + * @param mandatory the mandatory to set + */ + public void setMandatory(Boolean mandatory) { + + this.mandatory = mandatory; + } + + /** + * Sets the checks if is boolean. + * + * @param isBoolean the isBoolean to set + */ + public void setIsBoolean(Boolean isBoolean) { + + this.isBoolean = isBoolean; + } + + /** + * Sets the defaul value. + * + * @param defaulValue the defaulValue to set + */ + public void setDefaulValue(String defaulValue) { + + this.defaulValue = defaulValue; + } + + /** + * Sets the note. + * + * @param note the note to set + */ + public void setNote(String note) { + + this.note = note; + } + + /** + * Sets the vocabulary. + * + * @param vocabulary the vocabulary to set + */ + public void setVocabulary(List vocabulary) { + + this.vocabulary = vocabulary; + } + + /** + * Sets the validator. + * + * @param validator the validator to set + */ + public void setValidator(String validator) { + + this.validator = validator; + } + + /* (non-Javadoc) + * @see java.lang.Object#toString() + */ + @Override + public String toString() { + return "MetadataFieldWrapper [fieldName=" + fieldName + ", mandatory=" + + mandatory + ", isBoolean=" + isBoolean + ", defaulValue=" + + defaulValue + ", note=" + note + ", vocabulary=" + vocabulary + + ", validator=" + validator + "]"; + } + +}