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
This commit is contained in:
Costantino Perciante 2016-06-09 16:58:19 +00:00
parent 1a2cf0db7b
commit ef81439445
10 changed files with 927 additions and 116 deletions

View File

@ -5,6 +5,9 @@
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/target/generated-sources/gwt"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/resources"/>
<dependent-module archiveName="ckan-util-library-1.0.0-SNAPSHOT.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/ckan-util-library/ckan-util-library">
<dependency-type>uses</dependency-type>
</dependent-module>
<property name="context-root" value="ckan-metadata-publisher-widget"/>
<property name="java-output-path" value="/ckan-metadata-publisher-widget/target/ckan-metadata-publisher-widget-1.0.0-SNAPSHOT/WEB-INF/classes"/>
</wb-module>

View File

@ -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<MetaDataFieldSkeleton> listOfMetadataFields = new ArrayList<MetaDataFieldSkeleton>();
/**
* 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<MetaDataBean> 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<String, String> 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<MetaDataProfileBean> 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<MetadataFieldWrapper> 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<String, String> customFieldsMap = new HashMap<String, String>();
// 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();
}
}
/**

View File

@ -33,10 +33,14 @@
.tagsPanelStyle {
display: inline-block;
}
.selected-profile {
font-weight: bold;
}
</ui:style>
<g:HTMLPanel>
<b:Form type="HORIZONTAL" styleName="{style.form-main-style}"
ui:field="form">
ui:field="formFirstStep" visible="true">
<b:Fieldset styleName="{style.fieldset-border-style}">
<b:Legend styleName="{style.legend-style}">
@ -62,18 +66,6 @@
</b:Controls>
</b:ControlGroup>
<!-- <b:ControlGroup> -->
<!-- <b:ControlLabel for="url" title="Dataset url"> -->
<!-- <font color="red">*</font> -->
<!-- URL: -->
<!-- </b:ControlLabel> -->
<!-- <b:Controls> -->
<!-- <b:TextBox alternateSize="LARGE" placeholder="Dataset URL" -->
<!-- b:id="url" title="Dataset URL" ui:field="urlTextbox" /> -->
<!-- </b:Controls> -->
<!-- </b:ControlGroup> -->
<b:ControlGroup>
<b:ControlLabel for="description" title="Dataset description">
Description:
@ -196,18 +188,45 @@
</b:ControlGroup>
<b:ControlGroup>
<b:ControlLabel for="metadataFormat" title="Metadata format">Metadata
Format:</b:ControlLabel>
<b:ControlLabel for="metadataProfilesFormat" title="Metadata profile formats">Metadata
Profile:</b:ControlLabel>
<b:Controls>
<b:ListBox b:id="metadataFormat" alternateSize="LARGE"
title="The metadata format to be used" ui:field="metadataFormatListbox">
<b:ListBox b:id="metadataProfilesFormat" alternateSize="LARGE"
title="The metadata profile format to be used" ui:field="metadataProfilesFormatListbox">
<g:item enabled="true" title="None">none</g:item>
</b:ListBox>
</b:Controls>
</b:ControlGroup>
<!-- Here will be placed the metadata formats -->
<g:VerticalPanel ui:field="metadataPanel" visible="false"
width="100%"></g:VerticalPanel>
<!-- Alert block on continue -->
<b:AlertBlock type="INFO" close="false" animation="true"
visible="false" ui:field="onContinueAlertBlock" styleName="{style.block-alert-style}">
</b:AlertBlock>
<b:Button title="Continue" ui:field="continueButton" type="PRIMARY"
block="true">Continue</b:Button>
<b:Button title="Reset" ui:field="resetButton" block="true">Reset</b:Button>
</b:Fieldset>
</b:Form>
<b:Form type="HORIZONTAL" styleName="{style.form-main-style}"
ui:field="formSecondStep" visible="false">
<b:Fieldset styleName="{style.fieldset-border-style}">
<b:Legend styleName="{style.legend-style}">
Insert Metadata Profile Information
<small>
<span style="color:red;">*</span>
is required
</small>
</b:Legend>
<b:Paragraph ui:field="selectedProfile" styleName="{style.selected-profile}"></b:Paragraph>
<!-- Here will be placed the metadata fields formats -->
<g:VerticalPanel ui:field="metadataFieldsPanel"
visible="false" width="100%"></g:VerticalPanel>
<!-- Custom fields can be dinamically added -->
<b:ControlGroup ui:field="customFields">
@ -230,7 +249,7 @@
</b:Controls>
</b:ControlGroup>
<b:ControlGroup ui:field="resourcesControlGroup">
<b:ControlGroup ui:field="resourcesControlGroup" visible="false">
<b:Controls>
<b:CheckBox
title="Automatically add the folder content to the dataset as resource"
@ -258,7 +277,8 @@
<b:Button title="Create dataset" ui:field="createButton"
type="PRIMARY" block="true">Create</b:Button>
<b:Button title="Reset" ui:field="resetButton" block="true">Reset</b:Button>
<b:Button title="Go Back" ui:field="goBackButton" block="true">Go
Back</b:Button>
</b:Fieldset>
</b:Form>

View File

@ -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<Widget, MetaDataFieldSkeleton> {
}
@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<String> 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);
}
}

View File

@ -0,0 +1,21 @@
<!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:ControlGroup>
<b:ControlLabel>
<font color="red" ui:field="mandatorySymbol">*</font>
<!-- Name goes here -->
<span ui:field="name"></span>
</b:ControlLabel>
<b:Controls>
<!-- Listbox or Checkbox or Textbox according to isBoolean field -->
<g:SimplePanel ui:field="elementPanel" ></g:SimplePanel>
<span style="float:right; width:256px; color: #aaaaaa;" ui:field="noteFieldContainer" display="none">
<b:Icon type="INFO_SIGN" size="TWO_TIMES"/>
<span ui:field="noteField" visible="false"></span>
</span>
</b:Controls>
</b:ControlGroup>
</g:HTMLPanel>
</ui:UiBinder>

View File

@ -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<MetaDataBean> 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<MetaDataProfileBean> getMetadataProfilesList() {
List<MetaDataProfileBean> beans = new ArrayList<MetaDataProfileBean>();
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<MetadataFieldWrapper> wrapperList = new ArrayList<MetadataFieldWrapper>();
List<MetadataField> 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<MetaDataBean> metadataBeans = getMetaDataBeanList();
List<MetaDataProfileBean> 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<MetaDataBean> metadataBeans = getMetaDataBeanList();
List<MetaDataProfileBean> 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;
}
}

View File

@ -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<String> 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<MetaDataBean> metadataList;
private List<MetaDataProfileBean> metadataList;
public DatasetMetadataBean(){
super();
@ -81,7 +79,7 @@ public class DatasetMetadataBean implements Serializable {
String maintainerEmail, String ownerIdentifier,
List<String> organizationList, String selectedOrganization,
List<String> resourcesIds, boolean addResources,
List<MetaDataBean> metadataList) {
List<MetaDataProfileBean> metadataList) {
super();
this.id = id;
this.title = title;
@ -104,11 +102,11 @@ public class DatasetMetadataBean implements Serializable {
this.metadataList = metadataList;
}
public List<MetaDataBean> getMetadataList() {
public List<MetaDataProfileBean> getMetadataList() {
return metadataList;
}
public void setMetadataList(List<MetaDataBean> metadataList) {
public void setMetadataList(List<MetaDataProfileBean> metadataList) {
this.metadataList = metadataList;
}

View File

@ -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<MetadataFieldWrapper> metadataFields; // the fields of this type
public MetaDataProfileBean(){
super();
}
/**
* @param type
* @param metadataFields
*/
public MetaDataProfileBean(MetaDataTypeWrapper type, List<MetadataFieldWrapper> 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<MetadataFieldWrapper> getMetadataFields() {
return metadataFields;
}
/**
* @param metadataFields the metadataFields to set
*/
public void setMetadataFields(List<MetadataFieldWrapper> metadataFields) {
this.metadataFields = metadataFields;
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
return "MetaDataBean [type=" + type + ", metadataFields="
+ metadataFields + "]";
}
}

View File

@ -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 + "]";
}
}

View File

@ -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<String> 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<String> 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<String> 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<String> 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 + "]";
}
}