Resource managing is almost finished, the editable description must be made working

git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/widgets/ckan-metadata-publisher-widget@130042 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Costantino Perciante 2016-07-06 16:41:43 +00:00
parent 38fae1ceb5
commit b80ffda613
10 changed files with 534 additions and 140 deletions

View File

@ -20,6 +20,7 @@
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
<attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="${webappDirectory}/WEB-INF/classes" path="src/main/resources">

View File

@ -16,7 +16,7 @@ public class CKanMetadataPublisher implements EntryPoint {
public void onModuleLoad() {
// remove comment to the below line for testing the widget
//startExample();
startExample();
}
@ -25,7 +25,7 @@ public class CKanMetadataPublisher implements EntryPoint {
String idFolderWorkspace = "d3a37eb9-1589-4c95-a9d0-c473a02d4f0f";
String owner = "costantino.perciante";
RootPanel.get("ckan-metadata-publisher-div").add(new CreateDatasetForm(owner));
RootPanel.get("ckan-metadata-publisher-div").add(new CreateDatasetForm(idFolderWorkspace ,owner));
}
}

View File

@ -34,5 +34,4 @@ public class AddResourceContainer extends Composite{
public void add(TabPanel w){
resourcesPanel.add(w);
}
}

View File

@ -71,13 +71,6 @@ public class AddResourceToDataset extends Composite{
@Override
public void onClick(ClickEvent event) {
// String currentPath = Window.Location.getHref();
// int datasetIndex = datasetUrl.indexOf("/dataset");
// if(datasetIndex == -1)
// return;
//
// String finalPart = datasetUrl.substring(datasetIndex);
// String finalPath = currentPath + "?" + "path" + "=" + finalPart;
Window.Location.assign(datasetUrl);
}
});
@ -97,7 +90,15 @@ public class AddResourceToDataset extends Composite{
}
// collect data and build up the bean
final ResourceBeanWrapper resource = new ResourceBeanWrapper(resourceUrlTextBox.getText(), resourceNameTextBox.getText(), resourceDescriptionTextArea.getText());
final ResourceBeanWrapper resource =
new ResourceBeanWrapper(
resourceUrlTextBox.getText(),
resourceNameTextBox.getText(),
resourceDescriptionTextArea.getText(),
null,
true,
null,
owner);
// disable add button
addResourceButton.setEnabled(false);

View File

@ -34,6 +34,7 @@ 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.dom.client.Style.Display;
import com.google.gwt.event.dom.client.ChangeEvent;
import com.google.gwt.event.dom.client.ChangeHandler;
import com.google.gwt.event.dom.client.ClickEvent;
@ -50,6 +51,7 @@ 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.SimplePanel;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;
@ -86,8 +88,6 @@ public class CreateDatasetForm extends Composite{
@UiField TextBox maintainerEmailTextbox;
@UiField ControlGroup customFields;
@UiField Button addCustomFieldButton;
@UiField CheckBox addResourcesCheckBox;
@UiField ControlGroup resourcesControlGroup;
@UiField Button createButton;
@UiField Button resetButton;
@UiField AlertBlock infoBlock;
@ -97,11 +97,17 @@ public class CreateDatasetForm extends Composite{
@UiField ListBox metadataProfilesFormatListbox;
@UiField Form formFirstStep;
@UiField Form formSecondStep;
@UiField Form formThirdStep;
@UiField Button continueButton;
@UiField Button goBackButton;
@UiField Button goBackButtonFirstOrSecondStep;
@UiField Paragraph selectedProfile;
@UiField Button goToDatasetButton;
@UiField Button addResourcesButton;
@UiField CheckBox addResourcesCheckBox;
@UiField ControlGroup resourcesControlGroup;
@UiField SimplePanel workspaceResourcesContainer;
@UiField Button continueThirdStep;
@UiField Button goBackButtonFirstStep;
// tab panel
private TabPanel tabPanel;
@ -133,6 +139,9 @@ public class CreateDatasetForm extends Composite{
// the list of MetaDataFieldSkeleton added
List<MetaDataFieldSkeleton> listOfMetadataFields = new ArrayList<MetaDataFieldSkeleton>();
// resource table
private ResourcesTable resourcesTable;
/**
* Invoked in the most general case
* @param owner
@ -235,9 +244,6 @@ public class CreateDatasetForm extends Composite{
}
});
// hide the Add resources checkbox
resourcesControlGroup.removeFromParent();
}
/**
@ -263,14 +269,11 @@ 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>() {
@Override
public void onSuccess(DatasetMetadataBean bean) {
public void onSuccess(final DatasetMetadataBean bean) {
if(bean != null){
@ -319,6 +322,11 @@ public class CreateDatasetForm extends Composite{
}
}
// enable manage resources checkbox
resourcesControlGroup.setVisible(true);
addResourcesCheckBox.getElement().getStyle().setDisplay(Display.INLINE_BLOCK);
resourcesTable = new ResourcesTable(bean.getResources());
// try to retrieve the licenses
setAlertBlock("Retrieving licenses, please wait...", AlertType.INFO, true);
ckanServices.getLicenses(new AsyncCallback<LicensesBean>() {
@ -342,8 +350,7 @@ public class CreateDatasetForm extends Composite{
licenseListbox.setItemSelected(i, true);
}
// everything went ok
setAlertBlock("", AlertType.ERROR, false);
continueButton.setEnabled(true);
@ -471,24 +478,77 @@ public class CreateDatasetForm extends Composite{
String errorMsg = validateDataOnContinue();
if(errorMsg == null){
formFirstStep.setVisible(false);
formSecondStep.setVisible(true);
selectedProfile.setText("Selected Profile is " + metadataProfilesFormatListbox.getSelectedItemText());
// check what to do
if(isWorkspaceRequest){
if(!addResourcesCheckBox.getValue()){
// we need to show the page to handle resources one by one from the workspace
formFirstStep.setVisible(false);
formSecondStep.setVisible(true);
formThirdStep.setVisible(false);
// add the resources to the container panel
if(workspaceResourcesContainer.getWidget() == null)
workspaceResourcesContainer.add(resourcesTable);
}else{
// resources will be added automatically and we can show the page of the profiles
formFirstStep.setVisible(false);
formThirdStep.setVisible(true);
selectedProfile.setText("Selected Profile is " + metadataProfilesFormatListbox.getSelectedItemText());
}
}else{
// this is not a workspace request
formFirstStep.setVisible(false);
formThirdStep.setVisible(true);
selectedProfile.setText("Selected Profile is " + metadataProfilesFormatListbox.getSelectedItemText());
}
}else{
alertOnContinue("Please check inserted data [" + errorMsg + "]", AlertType.ERROR);
}
}
@UiHandler("goBackButton")
void onGoBackButton(ClickEvent e){
@UiHandler("goBackButtonFirstStep")
void onGoBackButtonFirstStep(ClickEvent e){
// swap forms
formFirstStep.setVisible(true);
formSecondStep.setVisible(false);
formThirdStep.setVisible(false);
}
@UiHandler("goBackButtonFirstOrSecondStep")
void onGoBackButton(ClickEvent e){
// swap forms
if(isWorkspaceRequest && !addResourcesCheckBox.getValue()){
formFirstStep.setVisible(false);
formSecondStep.setVisible(true);
}else{
formFirstStep.setVisible(true);
formSecondStep.setVisible(false);
}
formThirdStep.setVisible(false);
}
@UiHandler("continueThirdStep")
void onContinueThirdStep(ClickEvent e){
// swap forms
formSecondStep.setVisible(false);
formThirdStep.setVisible(true);
}
@UiHandler("createButton")
void createDatasetEvent(ClickEvent e){
@ -506,7 +566,6 @@ public class CreateDatasetForm extends Composite{
String maintainer = maintainerTextbox.getValue();
String maintainerEmail = maintainerEmailTextbox.getValue();
String chosenOrganization = organizationsListbox.getSelectedItemText();
boolean addResources = addResourcesCheckBox.getValue();
// fill the bean
receivedBean.setAuthor(author);
@ -520,7 +579,6 @@ public class CreateDatasetForm extends Composite{
receivedBean.setTitle(title);
receivedBean.setTags(tagsList);
receivedBean.setSelectedOrganization(chosenOrganization);
receivedBean.setAddResources(addResources);
Map<String, String> customFieldsMap = new HashMap<String, String>();
@ -546,7 +604,7 @@ public class CreateDatasetForm extends Composite{
// invoke the create method
createButton.setEnabled(false);
goBackButton.setEnabled(false);
goBackButtonFirstOrSecondStep.setEnabled(false);
ckanServices.createCKanDataset(receivedBean, isWorkspaceRequest, new AsyncCallback<DatasetMetadataBean>() {
@ -570,14 +628,6 @@ public class CreateDatasetForm extends Composite{
@Override
public void onClick(ClickEvent event) {
// String currentPath = Window.Location.getHref();
// int datasetIndex = datasetUrl.indexOf("/dataset");
// if(datasetIndex == -1)
// return;
//
// String finalPart = datasetUrl.substring(datasetIndex);
// String finalPath = currentPath + "?" + "path" + "=" + finalPart;
Window.Location.assign(datasetUrl);
}
});
@ -715,7 +765,7 @@ public class CreateDatasetForm extends Composite{
onCreateAlertBlock.setType(type);
onCreateAlertBlock.setVisible(true);
createButton.setEnabled(true);
goBackButton.setEnabled(true);
goBackButtonFirstOrSecondStep.setEnabled(true);
// hide after some seconds
Timer t = new Timer() {
@ -834,6 +884,7 @@ public class CreateDatasetForm extends Composite{
licenseListbox.setEnabled(false);
organizationsListbox.setEnabled(false);
addCustomFieldButton.setEnabled(false);
addResourcesCheckBox.setEnabled(false);
// freeze tags
for(int i = 0; i < tagsList.size(); i++){
@ -852,7 +903,10 @@ public class CreateDatasetForm extends Composite{
field.freeze();
}
// freeze table of resources
if(resourcesTable != null)
resourcesTable.freezeTable();
}
/**
@ -881,6 +935,19 @@ public class CreateDatasetForm extends Composite{
}
}
@UiHandler("addResourcesCheckBox")
void onAddResourcesCheckboxPress(ClickEvent e){
// we need to set all resources to be added if checkbox value is true
if(addResourcesCheckBox.getValue()){
GWT.log("Set all resources to be add");
resourcesTable.checkAllResources(true);
}
}
/**
* Add the tag as an element
*/

View File

@ -84,9 +84,8 @@
Tags:
</b:ControlLabel>
<b:Controls>
<b:TextBox width="70%"
placeholder="Enter one or more tag for the product" b:id="tags"
ui:field="tagsEnterTextBox" />
<b:TextBox width="70%" placeholder="Enter one or more tag for the product"
b:id="tags" ui:field="tagsEnterTextBox" />
<span style="float:right; width:256px; color: #aaaaaa;">
<b:Icon type="INFO_SIGN" size="TWO_TIMES" />
Tags are meaningful information that can be associated to the
@ -207,6 +206,26 @@
</b:Controls>
</b:ControlGroup>
<!-- If the user checks this box, the resources will be automatically
added, otherwise he has to manage them -->
<b:ControlGroup ui:field="resourcesControlGroup"
visible="false">
<b:ControlLabel for="resourcesAddCheckBox"
title="Automatically add all resources to product">Product
Resources:</b:ControlLabel>
<b:Controls>
<b:CheckBox b:id="resourcesAddCheckBox" width="60%"
title="Automatically add the folder content to the product as resource"
checked="true" ui:field="addResourcesCheckBox">
<b>Add folder content as resources</b>
</b:CheckBox>
<span style="float:right; width:256px; color: #aaaaaa;">
<b:Icon type="INFO_SIGN" size="TWO_TIMES" />
Automatically add folder content as resources of the product
</span>
</b:Controls>
</b:ControlGroup>
<!-- Alert block on continue -->
<b:AlertBlock type="INFO" close="false" animation="true"
visible="false" ui:field="onContinueAlertBlock" styleName="{style.block-alert-style}">
@ -219,8 +238,28 @@
</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}">
Manage Resources
</b:Legend>
<g:SimplePanel ui:field="workspaceResourcesContainer"
visible="true"></g:SimplePanel>
<b:Button title="Continue" ui:field="continueThirdStep"
type="PRIMARY" block="true">Continue</b:Button>
<b:Button title="Go Back" ui:field="goBackButtonFirstStep"
block="true">Go
Back</b:Button>
</b:Fieldset>
</b:Form>
<b:Form type="HORIZONTAL" styleName="{style.form-main-style}"
ui:field="formThirdStep" visible="false">
<b:Fieldset styleName="{style.fieldset-border-style}">
<b:Legend styleName="{style.legend-style}">
@ -258,21 +297,6 @@
</b:Controls>
</b:ControlGroup>
<b:ControlGroup ui:field="resourcesControlGroup"
visible="false">
<b:Controls>
<b:CheckBox
title="Automatically add the folder content to the product as resource"
checked="true" ui:field="addResourcesCheckBox">
<b>Add folder content as resources</b>
</b:CheckBox>
<span style="float:right; width:256px; color: #aaaaaa;">
<b:Icon type="INFO_SIGN" size="TWO_TIMES" />
Automatically add folder content as resources of the product
</span>
</b:Controls>
</b:ControlGroup>
<!-- Alert block on create -->
<b:AlertBlock type="INFO" close="false" animation="true"
visible="false" ui:field="onCreateAlertBlock" styleName="{style.block-alert-style}">
@ -283,7 +307,8 @@
<b:Button title="Create product" ui:field="createButton"
type="PRIMARY" block="true">Create</b:Button>
<b:Button title="Go Back" ui:field="goBackButton" block="true">Go
<b:Button title="Go Back" ui:field="goBackButtonFirstOrSecondStep" block="true">Go
Back</b:Button>
<b:Button title="Go to product" ui:field="goToDatasetButton"

View File

@ -0,0 +1,248 @@
package org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui;
import java.util.Comparator;
import java.util.List;
import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.ResourceBeanWrapper;
import com.github.gwtbootstrap.client.ui.Button;
import com.github.gwtbootstrap.client.ui.CellTable;
import com.google.gwt.cell.client.Cell.Context;
import com.google.gwt.cell.client.CheckboxCell;
import com.google.gwt.cell.client.EditTextCell;
import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.Element;
import com.google.gwt.dom.client.NativeEvent;
import com.google.gwt.dom.client.Style.Unit;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
import com.google.gwt.user.cellview.client.Column;
import com.google.gwt.user.cellview.client.ColumnSortEvent.ListHandler;
import com.google.gwt.user.cellview.client.TextColumn;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.view.client.ListDataProvider;
import com.google.gwt.view.client.Range;
/**
* The resources table class.
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
*/
public class ResourcesTable extends Composite{
// the data provider
protected ListDataProvider<ResourceBeanWrapper> dataProvider = new ListDataProvider<ResourceBeanWrapper>();
// the table that will be displayed
private CellTable<ResourceBeanWrapper> table = new CellTable<ResourceBeanWrapper>();
// save original list
private List<ResourceBeanWrapper> originalResources;
// main panel
private VerticalPanel mainPanel = new VerticalPanel();
// button labels
private static final String SELECT_ALL_LABEL = "Select All";
private static final String DESELECT_ALL_LABEL = "Deselect All";
// maintain the selection status
private boolean selectedAll = true;
final Button selectAllButton = new Button(DESELECT_ALL_LABEL);
// is read only?
private boolean readOnly = false;
public ResourcesTable(List<ResourceBeanWrapper> resources){
super();
initWidget(mainPanel);
// set panel width
mainPanel.setWidth("100%");
// save original resources
this.originalResources = resources;
// add data to the provider
dataProvider.setList(resources);
dataProvider.addDataDisplay(table);
// style of the table
table.setStriped(true);
table.setWidth("100%", false);
table.addStyleName("table-style");
table.setBordered(true);
// visible rows
table.setVisibleRange(new Range(0, originalResources.size()));
table.setRowCount(originalResources.size(), true);
// Add a checked column to add the resource.
Column<ResourceBeanWrapper, Boolean> chosenColumn = new Column<ResourceBeanWrapper, Boolean>(new CheckboxCell(true,false)) {
@Override
public Boolean getValue(ResourceBeanWrapper object) {
return object.isToBeAdded();
}
@Override
public void onBrowserEvent(Context context, final Element parent, final ResourceBeanWrapper res, NativeEvent event) {
event.preventDefault();
res.setToBeAdded(!res.isToBeAdded());
}
@Override
public void render(Context context, ResourceBeanWrapper object,
SafeHtmlBuilder sb) {
if(readOnly){
String checked = object.isToBeAdded() ? "checked" : "unchecked";
sb.appendHtmlConstant("<input type='checkbox'" ).
appendHtmlConstant("tabindex='-1' ").
appendEscaped(checked).appendEscaped(" disabled ").appendHtmlConstant("/>");
}else{
super.render(context, object, sb);
}
}
};
table.addColumn(chosenColumn, "Select");
// Add a text column to show the name (and make it sortable) TODO : make it editable
Column<ResourceBeanWrapper, String> nameColumn = new Column<ResourceBeanWrapper, String>(new EditTextCell()) {
@Override
public String getValue(ResourceBeanWrapper object) {
return object.getName();
}
@Override
public void onBrowserEvent(Context context, Element elem,
ResourceBeanWrapper object, NativeEvent event) {
// TODO Auto-generated method stub
//super.onBrowserEvent(context, elem, object, event);
}
};
ListHandler<ResourceBeanWrapper> nameColHandler = new ListHandler<ResourceBeanWrapper>(dataProvider.getList());
nameColHandler.setComparator(nameColumn, new Comparator<ResourceBeanWrapper>() {
public int compare(ResourceBeanWrapper o1, ResourceBeanWrapper o2) {
return o1.getName().compareTo(o2.getName());
}
});
nameColumn.setSortable(true);
nameColumn.setDefaultSortAscending(false);
table.addColumnSortHandler(nameColHandler);
table.addColumn(nameColumn, "Name");
// Add a date column to show the url
TextColumn<ResourceBeanWrapper> urlColumn = new TextColumn<ResourceBeanWrapper>() {
@Override
public String getValue(ResourceBeanWrapper object) {
return object.getUrl();
}
};
table.addColumn(urlColumn, "Url");
// Add a date column to show the description (and make it sortable)
Column<ResourceBeanWrapper, String> descColumn = new Column<ResourceBeanWrapper, String>(new EditTextCell()) {
@Override
public String getValue(ResourceBeanWrapper object) {
return object.getDescription();
}
@Override
public void onBrowserEvent(Context context, Element elem,
ResourceBeanWrapper object, NativeEvent event) {
event.preventDefault();
if(!readOnly){
super.onBrowserEvent(context, elem, object, event);
GWT.log("Element is " + elem);
}
}
@Override
public void render(Context context, ResourceBeanWrapper object,
SafeHtmlBuilder sb) {
// TODO Auto-generated method stub
super.render(context, object, sb);
GWT.log("Element is " + sb);
}
};
table.addColumn(descColumn, "Description (Editable)");
// sort by columnName
table.getColumnSortList().push(nameColumn);
// set width column chosen
table.setColumnWidth(chosenColumn, 5, Unit.PCT);
table.setColumnWidth(nameColumn, 20, Unit.PCT);
table.setColumnWidth(urlColumn, 45, Unit.PCT);
table.setColumnWidth(descColumn, 30, Unit.PCT);
// add a select all button
selectAllButton.getElement().getStyle().setMarginTop(15, Unit.PX);
selectAllButton.getElement().getStyle().setMarginBottom(15, Unit.PX);
// add handler
selectAllButton.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
selectedAll = !selectedAll;
checkAllResources(selectedAll);
}
});
// add the button
mainPanel.add(selectAllButton);
// add the table
mainPanel.add(table);
}
/**
* Check all resources
*/
public void checkAllResources(boolean value){
if(value)
selectAllButton.setText(DESELECT_ALL_LABEL);
else
selectAllButton.setText(SELECT_ALL_LABEL);
for(ResourceBeanWrapper resource: originalResources)
resource.setToBeAdded(value);
// refresh data
dataProvider.refresh();
}
/**
* Freeze table content and select/deselect all button
*/
public void freezeTable() {
selectAllButton.setEnabled(false);
readOnly = true;
// redraw the table
table.redraw();
}
}

View File

@ -56,7 +56,7 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
public static final String TEST_SCOPE = "/gcube/devsec/devVRE";
public static final String TEST_USER = "test.user";
private final static String TEST_SEC_TOKEN = "4620e6d0-2313-4f48-9d54-eb3efd01a810";
private final static String TEST_SEC_TOKEN = "a1e19695-467f-42b8-966d-bf83dd2382ef";
// ckan keys for ASL
private static final String CKAN_TOKEN_KEY = "ckanToken";
@ -103,7 +103,7 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
*/
public String getDevelopmentUser() {
String user = TEST_USER;
//user = "costantino.perciante";
user = "costantino.perciante";
return user;
}
@ -348,12 +348,12 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
logger.info("DatasetBean request for " + folderId + " and " + owner);
ASLSession aslSession = getASLSession();
String user = aslSession.getUsername();
if(isWithinPortal()){
try{
ASLSession aslSession = getASLSession();
String user = aslSession.getUsername();
// check if session expired
if(user.equals(TEST_USER)){
logger.debug("SESSION EXPIRED");
@ -390,7 +390,8 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
WorkspaceItem retrievedItem = ws.getItem(folderId);
// set some info
bean.setTitle(retrievedItem.getName());
String onlyAlphanumeric = retrievedItem.getName().replaceAll("[^A-Za-z0-9]", "");
bean.setTitle(onlyAlphanumeric);
bean.setDescription(retrievedItem.getDescription());
// retrieve gcube items of the folder
@ -405,8 +406,8 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
childrenIds.add(file.getId());
}
bean.setResourcesIds(childrenIds);
List<ResourceBeanWrapper> listOfResources = getWorkspaceResourcesInformation(childrenIds, ws, user);
bean.setResources(listOfResources);
}
// retrieve the metadata
@ -424,7 +425,8 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
bean.setId(folderId);
bean.setDescription("This is a fantastic description");
bean.setVersion(1);
bean.setTitle("dataset-" + Calendar.getInstance().getTimeInMillis());
String onlyAlphanumeric = "test-creation-blablabla".replaceAll("[^A-Za-z0-9]", "");
bean.setTitle(onlyAlphanumeric + Calendar.getInstance().getTimeInMillis());
bean.setAuthor("Costantino Perciante");
bean.setAuthorEmail("costantino.perciante@isti.cnr.it");
bean.setMaintainer("Costantino Perciante");
@ -452,8 +454,8 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
if(!file.isFolder()) // ok, it's a file
childrenIds.add(file.getId());
}
bean.setResourcesIds(childrenIds);
List<ResourceBeanWrapper> listOfResources = getWorkspaceResourcesInformation(childrenIds, ws, user);
bean.setResources(listOfResources);
}
// retrieve the metadata
@ -511,14 +513,6 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
return null;
}
// get the owner
String username = toCreate.getOwnerIdentifier();
// set dataset info (same id as the folder, if the request comes from the workspace)
String withId = null;
if(isWorkspaceRequest)
withId = toCreate.getId();
String title = toCreate.getTitle();
String organizationNameOrId = toCreate.getSelectedOrganization();
String author = toCreate.getAuthor();
@ -532,41 +526,29 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
List<String> listOfTags = toCreate.getTags();
Map<String, String> customFields = toCreate.getCustomFields();
boolean setPublic = toCreate.getVisibility();
// get the list of resources and convert to ResourceBean
List<ResourceBean> resources = new ArrayList<ResourceBean>();
List<ResourceBeanWrapper> resourcesToAdd = toCreate.getResources();
// build the resource (if it is a workspaceRequest type)
if(toCreate.isAddResources() && isWorkspaceRequest){
if(resourcesToAdd != null && !resourcesToAdd.isEmpty())
for (ResourceBeanWrapper resourceBeanWrapper : resourcesToAdd) {
logger.debug("We need to add resources to the dataset");
try{
Workspace ws = HomeLibrary
.getHomeManagerFactory()
.getHomeManager()
.getHome(toCreate.getOwnerIdentifier()).getWorkspace();
for(String resourceId: toCreate.getResourcesIds()){
FolderItem item = (FolderItem)ws.getItem(resourceId);
ResourceBean newResource = new ResourceBean();
newResource.setDescription(item.getDescription());
newResource.setId(item.getId());
newResource.setUrl(item.getPublicLink(false));
newResource.setName(item.getName());
newResource.setMimeType(item.getMimeType());
newResource.setOwner(username);
resources.add(newResource);
if(resourceBeanWrapper.isToBeAdded()){
resources.add(new ResourceBean(
resourceBeanWrapper.getUrl(),
resourceBeanWrapper.getName(),
resourceBeanWrapper.getDescription(),
resourceBeanWrapper.getId(),
resourceBeanWrapper.getOwner(),
null,
resourceBeanWrapper.getMimeType()));
}
}catch(Exception e){
logger.error("Unable to add those resources to the dataset", e);
}
}
String datasetId = utils.createCKanDataset(getUserCKanTokenFromSession(), withId, title, organizationNameOrId, author,
String datasetId = utils.createCKanDataset(getUserCKanTokenFromSession(), null, title, organizationNameOrId, author,
authorMail, maintainer, maintainerMail, version, description, licenseId,
listOfTags, customFields, resources, setPublic);
@ -688,4 +670,41 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
private String concatenateSessionKeyScope(String key, String scope){
return key.concat(scope);
}
/**
* Build up the resource beans.
* @param resourceIds
* @param ws
* @param username
* @return
*/
public List<ResourceBeanWrapper> getWorkspaceResourcesInformation(
List<String> resourceIds, Workspace ws, String username) {
List<ResourceBeanWrapper> toReturn = null;
try{
toReturn = new ArrayList<>();
for (String resourceId : resourceIds) {
ResourceBeanWrapper newResource = new ResourceBeanWrapper();
FolderItem item = (FolderItem)ws.getItem(resourceId);
newResource.setDescription(item.getDescription());
newResource.setId(item.getId());
newResource.setUrl(item.getPublicLink(true));
newResource.setName(item.getName());
newResource.setToBeAdded(true); // default is true
newResource.setMimeType(item.getMimeType());
newResource.setOwner(username);
toReturn.add(newResource);
}
}catch(Exception e){
logger.error("Unable to retrieve resources' info", e);
}
return toReturn;
}
}

View File

@ -43,8 +43,7 @@ public class DatasetMetadataBean implements Serializable {
private String ownerIdentifier; // owner of the folder into the workspace (e.g., andrea.rossi)
private List<String> organizationList; // list of organization in which the user is present and could create the dataset
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<ResourceBeanWrapper> resources; // in case of workspace, this is the list of children
private List<MetaDataProfileBean> metadataList;
public DatasetMetadataBean(){
@ -78,7 +77,7 @@ public class DatasetMetadataBean implements Serializable {
String author, String authorEmail, String maintainer,
String maintainerEmail, String ownerIdentifier,
List<String> organizationList, String selectedOrganization,
List<String> resourcesIds, boolean addResources,
List<ResourceBeanWrapper> resources,
List<MetaDataProfileBean> metadataList) {
super();
this.id = id;
@ -97,8 +96,7 @@ public class DatasetMetadataBean implements Serializable {
this.ownerIdentifier = ownerIdentifier;
this.organizationList = organizationList;
this.selectedOrganization = selectedOrganization;
this.resourcesIds = resourcesIds;
this.addResources = addResources;
this.resources = resources;
this.metadataList = metadataList;
}
@ -238,20 +236,12 @@ public class DatasetMetadataBean implements Serializable {
this.selectedOrganization = selectedOrganization;
}
public List<String> getResourcesIds() {
return resourcesIds;
public List<ResourceBeanWrapper> getResources() {
return resources;
}
public void setResourcesIds(List<String> resourcesIds) {
this.resourcesIds = resourcesIds;
}
public boolean isAddResources() {
return addResources;
}
public void setAddResources(boolean addResources) {
this.addResources = addResources;
public void setResources(List<ResourceBeanWrapper> resources) {
this.resources = resources;
}
@Override
@ -265,8 +255,7 @@ public class DatasetMetadataBean implements Serializable {
+ ", maintainerEmail=" + maintainerEmail + ", ownerIdentifier="
+ ownerIdentifier + ", organizationList=" + organizationList
+ ", selectedOrganization=" + selectedOrganization
+ ", resourcesIds=" + resourcesIds + ", addResources="
+ addResources + ", metadataList=" + metadataList + "]";
+ ", resources=" + resources + ", metadataList=" + metadataList + "]";
}
}

View File

@ -13,35 +13,33 @@ public class ResourceBeanWrapper implements Serializable{
private String name;
private String description;
private String id;
private boolean toBeAdded;
private String mimeType;
private String owner;
public ResourceBeanWrapper(){
super();
}
/**
* @param url
* @param name
* @param description
*/
public ResourceBeanWrapper(String url, String name, String description) {
super();
this.url = url;
this.name = name;
this.description = description;
}
/**
* @param url
* @param name
* @param description
* @param id
* @param toBeAdded
* @param mimeType
* @param owner
*/
public ResourceBeanWrapper(String url, String name, String description, String id) {
public ResourceBeanWrapper(String url, String name, String description,
String id, boolean toBeAdded, String mimeType, String owner) {
super();
this.url = url;
this.name = name;
this.description = description;
this.id = id;
this.toBeAdded = toBeAdded;
this.mimeType = mimeType;
this.owner = owner;
}
/**
@ -100,9 +98,56 @@ public class ResourceBeanWrapper implements Serializable{
this.id = id;
}
/**
* @return the toBeAdded
*/
public boolean isToBeAdded() {
return toBeAdded;
}
/**
* @param toBeAdded the toBeAdded to set
*/
public void setToBeAdded(boolean toBeAdded) {
this.toBeAdded = toBeAdded;
}
/**
* @return the mimeType
*/
public String getMimeType() {
return mimeType;
}
/**
* @param mimeType the mimeType to set
*/
public void setMimeType(String mimeType) {
this.mimeType = mimeType;
}
/**
* @return the owner
*/
public String getOwner() {
return owner;
}
/**
* @param owner the owner to set
*/
public void setOwner(String owner) {
this.owner = owner;
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
return "ResourceBean [url=" + url + ", name=" + name + ", description="
+ description + ", id=" + id + "]";
return "ResourceBeanWrapper [url=" + url + ", name=" + name
+ ", description=" + description + ", id=" + id
+ ", toBeAdded=" + toBeAdded + ", mimeType=" + mimeType
+ ", owner=" + owner + "]";
}
}