From a422814bb255560ef0bd60f0f6535a061a09f7ad Mon Sep 17 00:00:00 2001 From: Francesco Mangiacrapa Date: Fri, 12 Jun 2015 10:24:01 +0000 Subject: [PATCH] 219: Workspace: modify the WorkspaceItem properties Task-Url: https://support.d4science.org/issues/219 Added dialog EditProperties and relative RPC git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/user/workspace-tree-widget@115344 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../workspace/client/resources/Icons.java | 3 + .../workspace/client/resources/Resources.java | 5 + .../client/resources/icons/pencil16.png | Bin 0 -> 3312 bytes .../client/rpc/GWTWorkspaceService.java | 17 + .../client/rpc/GWTWorkspaceServiceAsync.java | 14 + .../view/windows/DialogEditProperties.java | 151 +++++ .../client/view/windows/DialogGetInfo.java | 154 ++--- .../exceptions/WrongItemTypeException.java | 18 +- .../workspace/server/GWTWorkspaceBuilder.java | 527 +++++++++++++++--- .../server/GWTWorkspaceServiceImpl.java | 100 +++- .../server/NoGcubeItemTypeException.java | 20 + 11 files changed, 852 insertions(+), 157 deletions(-) create mode 100644 src/main/java/org/gcube/portlets/user/workspace/client/resources/icons/pencil16.png create mode 100644 src/main/java/org/gcube/portlets/user/workspace/client/view/windows/DialogEditProperties.java create mode 100644 src/main/java/org/gcube/portlets/user/workspace/server/NoGcubeItemTypeException.java diff --git a/src/main/java/org/gcube/portlets/user/workspace/client/resources/Icons.java b/src/main/java/org/gcube/portlets/user/workspace/client/resources/Icons.java index 09c1094..bd60f92 100644 --- a/src/main/java/org/gcube/portlets/user/workspace/client/resources/Icons.java +++ b/src/main/java/org/gcube/portlets/user/workspace/client/resources/Icons.java @@ -375,5 +375,8 @@ public interface Icons extends ClientBundle { */ @Source("icons/edit-permissions.png") ImageResource permissions(); + + @Source("icons/pencil16.png") + ImageResource pencil(); } diff --git a/src/main/java/org/gcube/portlets/user/workspace/client/resources/Resources.java b/src/main/java/org/gcube/portlets/user/workspace/client/resources/Resources.java index 8d7d97b..2253829 100644 --- a/src/main/java/org/gcube/portlets/user/workspace/client/resources/Resources.java +++ b/src/main/java/org/gcube/portlets/user/workspace/client/resources/Resources.java @@ -294,6 +294,11 @@ public class Resources { return AbstractImagePrototype.create(ICONS.documents()); } + public static AbstractImagePrototype getIconPencil(){ + + return AbstractImagePrototype.create(ICONS.pencil()); + } + public static AbstractImagePrototype getIconHistory(){ return AbstractImagePrototype.create(ICONS.history()); diff --git a/src/main/java/org/gcube/portlets/user/workspace/client/resources/icons/pencil16.png b/src/main/java/org/gcube/portlets/user/workspace/client/resources/icons/pencil16.png new file mode 100644 index 0000000000000000000000000000000000000000..6966739a1a09bc21c4fafb5901e442ab2d77c59b GIT binary patch literal 3312 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 listLogins, String aclType) throws Exception; + Map loadGcubeItemProperties(String itemId) throws Exception; + + /** + * @param itemId + * @return + * @throws Exception + */ + String getHTMLGcubeItemProperties(String itemId) throws Exception; + + /** + * @param itemId + * @param properties + * @throws Exception + */ + void setGcubeItemProperties(String itemId, Map properties) throws Exception; + } diff --git a/src/main/java/org/gcube/portlets/user/workspace/client/rpc/GWTWorkspaceServiceAsync.java b/src/main/java/org/gcube/portlets/user/workspace/client/rpc/GWTWorkspaceServiceAsync.java index afbb22f..7ed2680 100644 --- a/src/main/java/org/gcube/portlets/user/workspace/client/rpc/GWTWorkspaceServiceAsync.java +++ b/src/main/java/org/gcube/portlets/user/workspace/client/rpc/GWTWorkspaceServiceAsync.java @@ -3,6 +3,7 @@ package org.gcube.portlets.user.workspace.client.rpc; import java.util.ArrayList; import java.util.Date; import java.util.List; +import java.util.Map; import org.gcube.portlets.user.workspace.client.model.BulkCreatorModel; import org.gcube.portlets.user.workspace.client.model.FileDetailsModel; @@ -230,4 +231,17 @@ public interface GWTWorkspaceServiceAsync { void validateACLToUser(String folderId, List listLogins, String aclType, AsyncCallback callback); + /** + * @param itemId + * @param asyncCallback + */ + void loadGcubeItemProperties(String itemId, + AsyncCallback> asyncCallback); + + void getHTMLGcubeItemProperties(String itemId, + AsyncCallback callback); + + void setGcubeItemProperties(String itemId, Map properties, + AsyncCallback callback); + } diff --git a/src/main/java/org/gcube/portlets/user/workspace/client/view/windows/DialogEditProperties.java b/src/main/java/org/gcube/portlets/user/workspace/client/view/windows/DialogEditProperties.java new file mode 100644 index 0000000..f57564c --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/workspace/client/view/windows/DialogEditProperties.java @@ -0,0 +1,151 @@ +/** + * + */ +package org.gcube.portlets.user.workspace.client.view.windows; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.gcube.portlets.user.workspace.client.AppControllerExplorer; +import org.gcube.portlets.user.workspace.client.model.FileModel; + +import com.extjs.gxt.ui.client.Style.HorizontalAlignment; +import com.extjs.gxt.ui.client.Style.Scroll; +import com.extjs.gxt.ui.client.event.BaseEvent; +import com.extjs.gxt.ui.client.event.Events; +import com.extjs.gxt.ui.client.event.Listener; +import com.extjs.gxt.ui.client.widget.Dialog; +import com.extjs.gxt.ui.client.widget.form.TextField; +import com.extjs.gxt.ui.client.widget.layout.FormLayout; +import com.google.gwt.core.client.GWT; +import com.google.gwt.user.client.Command; +import com.google.gwt.user.client.rpc.AsyncCallback; + +/** + * The Class DialogEditProperties. + * + * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it + * Jun 11, 2015 + */ +public class DialogEditProperties extends Dialog{ + + private FileModel item; + private int widthDialog = 450; + private int heigthDialog = 300; + private Command commad; + private List> fields; + private FormLayout layout; + + /** + * Instantiates a new dialog edit properties. + * + * @param itemId + * the item id + */ + public DialogEditProperties(FileModel item, Command command) { + this.item = item; + this.commad = command; + + layout = new FormLayout(); + layout.setLabelWidth(90); + layout.setDefaultWidth(300); + setLayout(layout); + + setHeading(item.getName() + " set properties"); + setButtonAlign(HorizontalAlignment.RIGHT); + setModal(true); + // setBodyBorder(true); + setBodyStyle("padding: 9px; background: none"); + setWidth(widthDialog); + setHeight(350); + setScrollMode(Scroll.AUTOY); + setResizable(false); + setButtons(Dialog.OK); + + getButtonById(Dialog.OK).setText("Save"); + + getButtonById(Dialog.OK).addListener(Events.Select, new Listener() { + + @Override + public void handleEvent(BaseEvent be) { + saveProperties(); + } + }); + } + + + /* (non-Javadoc) + * @see com.extjs.gxt.ui.client.widget.Window#show() + */ + @Override + public void show() { + resetForm(); + loadGcubeItemProperties(); + super.show(); + } + + /** + * + */ + private void resetForm() { + if(fields!=null) + fields.clear(); + fields = null; + removeAll(); + } + + private void saveProperties(){ + Map prp = new HashMap(fields.size()); + for (TextField field : fields) { + prp.put(field.getFieldLabel(), field.getValue()); + } + AppControllerExplorer.rpcWorkspaceService.setGcubeItemProperties(item.getIdentifier(), prp, new AsyncCallback() { + + @Override + public void onFailure(Throwable caught) { + new MessageBoxAlert("Error", caught.getMessage(), null); + + } + + @Override + public void onSuccess(Void result) { + commad.execute(); + } + }); + + } + + + private void loadGcubeItemProperties(){ +// mask("Loading properties..."); + AppControllerExplorer.rpcWorkspaceService.loadGcubeItemProperties(item.getIdentifier(), new AsyncCallback>() { + + @Override + public void onSuccess(Map result) { +// unmask(); + setProperties(result); + } + + @Override + public void onFailure(Throwable caught) { +// unmask(); + GWT.log("an error occured in loadGcubeItemProperties "+item + " "+caught.getMessage()); + } + }); + } + + private void setProperties(Map result) { + fields = new ArrayList>(result.size()); + for (String key: result.keySet()) { + TextField field = new TextField(); + field.setFieldLabel(key); + field.setValue(result.get(key)); + add(field); + fields.add(field); + } + layout(true); + } + +} diff --git a/src/main/java/org/gcube/portlets/user/workspace/client/view/windows/DialogGetInfo.java b/src/main/java/org/gcube/portlets/user/workspace/client/view/windows/DialogGetInfo.java index 78d97d3..e315227 100644 --- a/src/main/java/org/gcube/portlets/user/workspace/client/view/windows/DialogGetInfo.java +++ b/src/main/java/org/gcube/portlets/user/workspace/client/view/windows/DialogGetInfo.java @@ -8,6 +8,7 @@ import org.gcube.portlets.user.workspace.client.ConstantsExplorer; import org.gcube.portlets.user.workspace.client.model.FileGridModel; import org.gcube.portlets.user.workspace.client.model.FileModel; import org.gcube.portlets.user.workspace.client.model.InfoContactModel; +import org.gcube.portlets.user.workspace.client.resources.Resources; import com.extjs.gxt.ui.client.Style.HorizontalAlignment; import com.extjs.gxt.ui.client.Style.Scroll; @@ -21,8 +22,12 @@ import com.extjs.gxt.ui.client.widget.form.TextArea; import com.extjs.gxt.ui.client.widget.form.TextField; import com.extjs.gxt.ui.client.widget.layout.FormLayout; import com.google.gwt.core.client.GWT; +import com.google.gwt.event.dom.client.ClickEvent; +import com.google.gwt.event.dom.client.ClickHandler; import com.google.gwt.i18n.client.NumberFormat; +import com.google.gwt.user.client.Command; import com.google.gwt.user.client.rpc.AsyncCallback; +import com.google.gwt.user.client.ui.Image; /** * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it @@ -49,10 +54,13 @@ public class DialogGetInfo extends Dialog { private TextField txtShared = new TextField(); // private TextArea textAreaSharedWith = new TextArea(); private Html htmlUsersWidget = new Html(); + private Html htmlPropertiesWidget = new Html(); private final NumberFormat number = ConstantsExplorer.numberFormatterKB; - +// private TextField txtGcubeItemProperties; + private HorizontalPanel hpGcubeProperties; + private DialogEditProperties editProperties = null; - public DialogGetInfo(FileModel fileModel) { + public DialogGetInfo(final FileModel fileModel) { FormLayout layout = new FormLayout(); layout.setLabelWidth(90); @@ -86,13 +94,51 @@ public class DialogGetInfo extends Dialog { loadLocation(fileModel.getIdentifier()); add(txtLocation); - - + txtAreaDescription.setFieldLabel("Description"); txtAreaDescription.setHeight(30); txtAreaDescription.setReadOnly(true); add(txtAreaDescription); + //GCUBE PROPERTIES + hpGcubeProperties = new HorizontalPanel(); + hpGcubeProperties.setStyleAttribute("padding-top", "6px"); + hpGcubeProperties.setStyleAttribute("margin-bottom", "6px"); + Label labelProperties = new Label("Properties"); + labelProperties.setTitle("Gcube Properties"); + labelProperties.setStyleAttribute("padding-right", "47px"); + hpGcubeProperties.add(labelProperties); + loadGcubeItemProperties(fileModel.getIdentifier()); + htmlPropertiesWidget.setHeight(heightTextArea); + htmlPropertiesWidget.setWidth("270px"); + + Image imgProperties = Resources.getIconPencil().createImage(); //EDIT PROPERTIES + hpGcubeProperties.add(imgProperties); + + final Command cmdReloadProperties = new Command() { + + @Override + public void execute() { + loadGcubeItemProperties(fileModel.getIdentifier()); + } + }; + + imgProperties.addClickHandler(new ClickHandler() { + + @Override + public void onClick(ClickEvent event) { + if(editProperties==null) + editProperties = new DialogEditProperties(fileModel, cmdReloadProperties); + + editProperties.show(); + + } + }); + htmlPropertiesWidget.setStyleAttribute("margin-left", "5px"); + hpGcubeProperties.add(htmlPropertiesWidget); + hpGcubeProperties.setScrollMode(Scroll.AUTOY); + add(hpGcubeProperties); + setVisibleGcubeProperties(false); if(fileModel.isDirectory()){ txtAreaDescription.setValue(fileModel.getDescription()); @@ -121,16 +167,11 @@ public class DialogGetInfo extends Dialog { txtCreated = new TextField(); txtCreated.setFieldLabel("Created"); txtCreated.setReadOnly(true); -// if(fileModel instanceof FileGridModel) -// textFieldSetValue(txtCreated, ((FileGridModel) fileModel).getCreationDate().toString()); -// else -// loadCreationDate(fileModel.getIdentifier()); - + loadCreationDate(fileModel.getIdentifier()); add(txtCreated); - txtLastMofication = new TextField(); txtLastMofication.setFieldLabel("Last Mofication"); txtLastMofication.setReadOnly(true); @@ -139,7 +180,6 @@ public class DialogGetInfo extends Dialog { else loadLastModificationDate(fileModel.getIdentifier()); -// loadLastModificationDate(fileModel.getIdentifier()); add(txtLastMofication); txtSize = new TextField(); @@ -152,15 +192,15 @@ public class DialogGetInfo extends Dialog { loadSize(fileModel.getIdentifier()); add(txtSize); - - + + //SHARED txtShared = new TextField(); txtShared.setFieldLabel("Shared"); txtShared.setReadOnly(true); textFieldSetValue(txtShared,fileModel.isShared()+""); add(txtShared); - + //USERS SHARED if(fileModel.isShared()){ HorizontalPanel hp = new HorizontalPanel(); @@ -168,14 +208,6 @@ public class DialogGetInfo extends Dialog { Label label = new Label("Shared with"); label.setStyleAttribute("padding-right", "39px"); hp.add(label); - /* - textAreaSharedWith.setFieldLabel("Shared with"); - textAreaSharedWith.setHeight(heightTextArea); - textAreaSharedWith.setReadOnly(true); - loadListSharedContacts(fileModel.getIdentifier()); - add(textAreaSharedWith); - */ -// htmlUsersWidget.setStyleAttribute("border", "1px solid #B5B8C8"); loadACLsDescriptionForSharedFolder(fileModel.getIdentifier()); htmlUsersWidget.setHeight(heightTextArea); htmlUsersWidget.setWidth("297px"); @@ -192,12 +224,13 @@ public class DialogGetInfo extends Dialog { hide(); } }); - - -// System.out.println("fileModel in getinfo "+fileModel); this.show(); } + private void setVisibleGcubeProperties(boolean bool){ + hpGcubeProperties.setVisible(bool); + } + /** * @param identifier */ @@ -263,9 +296,7 @@ public class DialogGetInfo extends Dialog { private void loadOwner(final String itemId){ txtOwner.mask(); - -// System.out.println("owner by id "+itemId); - + AppControllerExplorer.rpcWorkspaceService.getOwnerByItemId(itemId, new AsyncCallback() { @Override @@ -282,6 +313,39 @@ public class DialogGetInfo extends Dialog { }); } + + + private void loadGcubeItemProperties(final String itemId){ + GWT.log("Load GcubeItemProperties"); + htmlPropertiesWidget.mask(); + AppControllerExplorer.rpcWorkspaceService.getHTMLGcubeItemProperties(itemId, new AsyncCallback() { + + @Override + public void onFailure(Throwable caught) { + htmlPropertiesWidget.unmask(); + GWT.log("an error occured in load properties by Id "+itemId + " "+caught.getMessage()); + setVisibleGcubeProperties(true); + htmlPropertiesWidget.setHtml("Error on recovering properties"); + + } + + @Override + public void onSuccess(String result) { +// setVisibleGcubeProperties(true); + htmlPropertiesWidget.unmask(); + if(result!=null){ + setVisibleGcubeProperties(true); + htmlPropertiesWidget.setHtml(result); + } +// else{ +// htmlPropertiesWidget.setHeight(20); +// htmlPropertiesWidget.setHtml("None"); +// } + } + }); + } + + private void loadSize(final String itemId){ GWT.log("Load size"); txtSize.mask(); @@ -325,37 +389,6 @@ public class DialogGetInfo extends Dialog { }); } -// private void loadListSharedContacts(String sharedId){ -// -// textAreaSharedWith.mask(); -// -// AppControllerExplorer.rpcWorkspaceService.getListUserSharedBySharedItem(sharedId, new AsyncCallback>() { -// -// @Override -// public void onFailure(Throwable caught) { -// textAreaSharedWith.unmask(); -// -// } -// -// @Override -// public void onSuccess(List result) { -// -// String users = ""; -// -// for (int i = 0; i < result.size()-1; i++) { -// users+= result.get(i).getName() + ", "; -// } -// -// if(result.size()>1) -// users += result.get(result.size()-1).getName(); -// -// textAreaSharedWith.setValue(users); -// -// textAreaSharedWith.unmask(); -// } -// }); -// } - private void loadACLsDescriptionForSharedFolder(String sharedId){ htmlUsersWidget.mask(); @@ -423,7 +456,4 @@ public class DialogGetInfo extends Dialog { }); } - - - } \ No newline at end of file diff --git a/src/main/java/org/gcube/portlets/user/workspace/client/workspace/exceptions/WrongItemTypeException.java b/src/main/java/org/gcube/portlets/user/workspace/client/workspace/exceptions/WrongItemTypeException.java index 33c3e84..28fc709 100644 --- a/src/main/java/org/gcube/portlets/user/workspace/client/workspace/exceptions/WrongItemTypeException.java +++ b/src/main/java/org/gcube/portlets/user/workspace/client/workspace/exceptions/WrongItemTypeException.java @@ -3,18 +3,28 @@ */ package org.gcube.portlets.user.workspace.client.workspace.exceptions; + /** - * @author Federico De Faveri defaveri@isti.cnr.it + * The Class WrongItemTypeException. * + * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it + * Jun 11, 2015 */ public class WrongItemTypeException extends Exception{ - private static final long serialVersionUID = 3660227882791095368L; + /** + * + */ + private static final long serialVersionUID = -6229136748121940285L; + + /** + * Instantiates a new wrong item type exception. + * + * @param message the message + */ public WrongItemTypeException(String message) { super(message); } - - } diff --git a/src/main/java/org/gcube/portlets/user/workspace/server/GWTWorkspaceBuilder.java b/src/main/java/org/gcube/portlets/user/workspace/server/GWTWorkspaceBuilder.java index 920bfa9..5c8321f 100644 --- a/src/main/java/org/gcube/portlets/user/workspace/server/GWTWorkspaceBuilder.java +++ b/src/main/java/org/gcube/portlets/user/workspace/server/GWTWorkspaceBuilder.java @@ -88,8 +88,9 @@ import com.thoughtworks.xstream.XStream; /** - * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it + * The Class GWTWorkspaceBuilder. * + * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it */ public class GWTWorkspaceBuilder { @@ -103,15 +104,16 @@ public class GWTWorkspaceBuilder { /** - * @param logger - */ + * Instantiates a new GWT workspace builder. + */ public GWTWorkspaceBuilder() { } /** - * Used in test mode - * @return + * Used in test mode. + * + * @return the hash test users */ public static HashMap getHashTestUsers(){ @@ -137,6 +139,12 @@ public class GWTWorkspaceBuilder { return hashTestUser; } + /** + * To date. + * + * @param calendar the calendar + * @return the date + */ protected Date toDate(Calendar calendar) { if (calendar == null) return new Date(0); @@ -144,6 +152,12 @@ public class GWTWorkspaceBuilder { } + /** + * To date format to string. + * + * @param calendar the calendar + * @return the string + */ protected String toDateFormatToString(Calendar calendar){ SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM, yyyy HH:mm:ss z"); @@ -154,6 +168,12 @@ public class GWTWorkspaceBuilder { } + /** + * To date format. + * + * @param calendar the calendar + * @return the date + */ protected Date toDateFormat(Calendar calendar){ SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM, yyyy HH:mm:ss z"); @@ -173,6 +193,12 @@ public class GWTWorkspaceBuilder { } + /** + * Gets the date. + * + * @param calendar the calendar + * @return the date + */ private Date getDate(Calendar calendar) { Date resultdate = null; @@ -186,6 +212,13 @@ public class GWTWorkspaceBuilder { } + /** + * Builds the gwt properties. + * + * @param metadata the metadata + * @return the GWT properties + * @throws InternalErrorException the internal error exception + */ protected GWTProperties buildGWTProperties(Properties metadata) throws InternalErrorException { //FIXME temp solution @@ -194,16 +227,35 @@ public class GWTWorkspaceBuilder { } + /** + * Builds the image url. + * + * @param id the id + * @return the string + */ protected String buildImageUrl(String id) { return buildImageServiceUrl(id, ImageRequestType.IMAGE); } + /** + * Builds the thumbnail url. + * + * @param id the id + * @return the string + */ protected String buildThumbnailUrl(String id) { return buildImageServiceUrl(id, ImageRequestType.THUMBNAIL); } + /** + * Builds the image service url. + * + * @param id the id + * @param requestType the request type + * @return the string + */ protected String buildImageServiceUrl(String id, ImageRequestType requestType){ StringBuilder sb = new StringBuilder(); sb.append(IMAGE_SERVICE_URL); @@ -586,7 +638,16 @@ public class GWTWorkspaceBuilder { ///////////////////////*********************USED //ADD FRANCESCO - @SuppressWarnings("unchecked") + /** + * Builds the gwt workspace image. + * + * @param item the item + * @param isInteralImage the is interal image + * @param fullDetails the full details + * @return the GWT workspace item + * @throws InternalErrorException the internal error exception + */ +@SuppressWarnings("unchecked") protected GWTWorkspaceItem buildGWTWorkspaceImage(WorkspaceItem item, boolean isInteralImage, boolean fullDetails) throws InternalErrorException { @@ -598,9 +659,9 @@ public class GWTWorkspaceBuilder { GCubeItem image = (GCubeItem) item; //Cast OLD Image Document - List links = (List) new XStream().fromXML(image.getItemProperties().get(NodeProperty.ALTERNATIVES.toString())); - List parts = (List) new XStream().fromXML(image.getItemProperties().get(NodeProperty.PARTS.toString())); - Map metadatas = (Map) new XStream().fromXML(image.getItemProperties().get(NodeProperty.METADATA.toString())); + List links = (List) new XStream().fromXML(image.getProperties().getPropertyValue(NodeProperty.ALTERNATIVES.toString())); + List parts = (List) new XStream().fromXML(image.getProperties().getPropertyValue(NodeProperty.PARTS.toString())); + Map metadatas = (Map) new XStream().fromXML(image.getProperties().getPropertyValue(NodeProperty.METADATA.toString())); Map gwtmetadatas = getMetadatas(metadatas, image.getId()); gwtImage = (GWTImageDocument) new GWTImageDocument( @@ -615,17 +676,17 @@ public class GWTWorkspaceBuilder { null, buildImageUrl(image.getId()), buildThumbnailUrl(image.getId()), - Integer.parseInt(image.getItemProperties().get(NodeProperty.IMAGE_WIDTH.toString())), - Integer.parseInt(image.getItemProperties().get(NodeProperty.IMAGE_HEIGHT.toString())), - Integer.parseInt(image.getItemProperties().get(NodeProperty.THUMBNAIL_WIDTH.toString())), - Integer.parseInt(image.getItemProperties().get(NodeProperty.THUMBNAIL_HEIGHT.toString())), + Integer.parseInt(image.getProperties().getPropertyValue(NodeProperty.IMAGE_WIDTH.toString())), + Integer.parseInt(image.getProperties().getPropertyValue(NodeProperty.IMAGE_HEIGHT.toString())), + Integer.parseInt(image.getProperties().getPropertyValue(NodeProperty.THUMBNAIL_WIDTH.toString())), + Integer.parseInt(image.getProperties().getPropertyValue(NodeProperty.THUMBNAIL_HEIGHT.toString())), -1, image.getLength(), image.getMimeType(), - image.getItemProperties().get(NodeProperty.OID.toString()), + image.getProperties().getPropertyValue(NodeProperty.OID.toString()), gwtmetadatas, new LinkedHashMap(), - image.getItemProperties().get(NodeProperty.COLLECTION_NAME.toString()), + image.getProperties().getPropertyValue(NodeProperty.COLLECTION_NAME.toString()), links.size(), parts.size()); } @@ -674,6 +735,14 @@ public class GWTWorkspaceBuilder { + /** + * Builds the gwt external url. + * + * @param url the url + * @param parent the parent + * @return the GWT external url + * @throws InternalErrorException the internal error exception + */ protected GWTExternalUrl buildGWTExternalUrl(ExternalUrl url, GWTWorkspaceFolder parent) throws InternalErrorException { GWTProperties gwtProperties = buildGWTProperties(url.getProperties()); @@ -694,23 +763,29 @@ public class GWTWorkspaceBuilder { } + /** + * Builds the gwt worspace url. + * + * @param item the item + * @param isInternalUrl the is internal url + * @param fullDetails the full details + * @return the GWT workspace item + * @throws InternalErrorException the internal error exception + */ @SuppressWarnings("unchecked") protected GWTWorkspaceItem buildGWTWorspaceUrl(WorkspaceItem item, boolean isInternalUrl, boolean fullDetails) throws InternalErrorException { GWTWorkspaceItem gwtUrl = null; - GWTProperties gwtProperties = buildGWTProperties(item.getProperties()); - -// GWTUrlDocument gwtUrlDocument = null; - + if(isInternalUrl){ GCubeItem document = (GCubeItem) item; //Cast OLD UrlDocument // UrlDocument document = (UrlDocument) item; //Cast - List links = (List) new XStream().fromXML(document.getItemProperties().get(NodeProperty.ALTERNATIVES.toString())); - List parts = (List) new XStream().fromXML(document.getItemProperties().get(NodeProperty.PARTS.toString())); - Map metadatas = (Map) new XStream().fromXML(document.getItemProperties().get(NodeProperty.METADATA.toString())); + List links = (List) new XStream().fromXML(document.getProperties().getPropertyValue(NodeProperty.ALTERNATIVES.toString())); + List parts = (List) new XStream().fromXML(document.getProperties().getPropertyValue(NodeProperty.PARTS.toString())); + Map metadatas = (Map) new XStream().fromXML(document.getProperties().getPropertyValue(NodeProperty.METADATA.toString())); Map gwtmetadatas = getMetadatas(metadatas, document.getId()); gwtUrl = new GWTUrlDocument( @@ -724,49 +799,47 @@ public class GWTWorkspaceBuilder { GWTWorkspaceItemAction.valueOf(document.getLastAction().toString()), null, document.getLength(), - document.getItemProperties().get(NodeProperty.OID.toString()), + document.getProperties().getPropertyValue(NodeProperty.OID.toString()), document.getMimeType(), gwtmetadatas, new LinkedHashMap(), - document.getItemProperties().get(NodeProperty.COLLECTION_NAME.toString()), + document.getProperties().getPropertyValue(NodeProperty.COLLECTION_NAME.toString()), links.size(), parts.size(), - document.getItemProperties().get(NodeProperty.URL.toString())); + document.getProperties().getPropertyValue(NodeProperty.URL.toString())); } else{ ExternalUrl document = (ExternalUrl) item; //Cast if(fullDetails){ - gwtUrl = new GWTExternalUrl( - toDate(document.getCreationTime()), - document.getId(), - gwtProperties, - document.getName(), - document.getOwner().getPortalLogin(), - document.getDescription(), - toDate(document.getLastModificationTime()), - GWTWorkspaceItemAction.valueOf(document.getLastAction().toString()), - null, - document.getLength(), - document.getUrl()); - + toDate(document.getCreationTime()), + document.getId(), + gwtProperties, + document.getName(), + document.getOwner().getPortalLogin(), + document.getDescription(), + toDate(document.getLastModificationTime()), + GWTWorkspaceItemAction.valueOf(document.getLastAction().toString()), + null, + document.getLength(), + document.getUrl()); } - else{ - + else gwtUrl = new GWTExternalUrl(document.getUrl()); - - } - - } - return gwtUrl; - } + /** + * Gets the metadatas. + * + * @param metadatas the metadatas + * @param documentId the document id + * @return the metadatas + */ protected Map getMetadatas(Map metadatas, String documentId) { Map gwtmetadatas = new LinkedHashMap(); @@ -776,6 +849,13 @@ public class GWTWorkspaceBuilder { return gwtmetadatas; } + /** + * Gets the metadata. + * + * @param metadata the metadata + * @param documentId the document id + * @return the metadata + */ protected GWTDocumentMetadata getMetadata(DocumentMetadata metadata, String documentId) { return new GWTDocumentMetadata(metadata.getSchemaName(), @@ -788,6 +868,13 @@ public class GWTWorkspaceBuilder { //*****************************************************NEW + /** + * Builds the workspace file model root. + * + * @param workspaceRoot the workspace root + * @return the folder model + * @throws InternalErrorException the internal error exception + */ public FolderModel buildWorkspaceFileModelRoot(WorkspaceFolder workspaceRoot) throws InternalErrorException { logger.trace("workspace id: "+ workspaceRoot.getId()); @@ -801,6 +888,14 @@ public class GWTWorkspaceBuilder { } + /** + * Builds the gxt list file model item. + * + * @param workspaceFolder the workspace folder + * @param parentFolderModel the parent folder model + * @return the list + * @throws InternalErrorException the internal error exception + */ protected List buildGXTListFileModelItem(WorkspaceItem workspaceFolder, FileModel parentFolderModel) throws InternalErrorException { @@ -833,6 +928,13 @@ public class GWTWorkspaceBuilder { } + /** + * Builds the gxt list file model item for attachs. + * + * @param listWorspaceItems the list worspace items + * @return the list + * @throws InternalErrorException the internal error exception + */ protected List buildGXTListFileModelItemForAttachs(List listWorspaceItems) throws InternalErrorException { @@ -876,9 +978,10 @@ public class GWTWorkspaceBuilder { /** - * - * @param listPortalLogin - * @return + * Builds the gxt info contacts from portal logins. + * + * @param listPortalLogin the list portal login + * @return the list */ public List buildGxtInfoContactsFromPortalLogins(List listPortalLogin){ @@ -893,9 +996,10 @@ public class GWTWorkspaceBuilder { } /** - * - * @param portalLogin - * @return + * Builds the gxt info contact from portal login. + * + * @param portalLogin the portal login + * @return the info contact model */ protected InfoContactModel buildGxtInfoContactFromPortalLogin(String portalLogin){ @@ -910,9 +1014,10 @@ public class GWTWorkspaceBuilder { /** - * Used in test mode - * @param listPortalLogin - * @return + * Used in test mode. + * + * @param listPortalLogin the list portal login + * @return the list */ protected List buildGxtInfoContactFromPortalLoginTestMode(List listPortalLogin){ @@ -925,6 +1030,14 @@ public class GWTWorkspaceBuilder { } + /** + * Builds the gxt file model item. + * + * @param item the item + * @param parentFolderModel the parent folder model + * @return the file model + * @throws InternalErrorException the internal error exception + */ protected FileModel buildGXTFileModelItem(WorkspaceItem item, FileModel parentFolderModel) throws InternalErrorException { @@ -988,6 +1101,13 @@ public class GWTWorkspaceBuilder { } + /** + * Builds the gxt list file grid model item for search. + * + * @param listSearchItems the list search items + * @return the list + * @throws InternalErrorException the internal error exception + */ public List buildGXTListFileGridModelItemForSearch(List listSearchItems) throws InternalErrorException { @@ -1002,6 +1122,14 @@ public class GWTWorkspaceBuilder { return listFileGridModel; } + /** + * Builds the gxt file grid model item for search. + * + * @param item the item + * @param parentFileModel the parent file model + * @return the file grid model + * @throws InternalErrorException the internal error exception + */ private FileGridModel buildGXTFileGridModelItemForSearch(SearchItem item, FileModel parentFileModel) throws InternalErrorException{ FileGridModel fileGridModel = null; @@ -1062,6 +1190,14 @@ public class GWTWorkspaceBuilder { } + /** + * Builds the gxt list file grid model item. + * + * @param listWorkspaceItems the list workspace items + * @param parentFileModel the parent file model + * @return the list + * @throws InternalErrorException the internal error exception + */ protected List buildGXTListFileGridModelItem(List listWorkspaceItems, FileModel parentFileModel) throws InternalErrorException { @@ -1080,6 +1216,14 @@ public class GWTWorkspaceBuilder { return listFileGridModel; } + /** + * Builds the gxt file grid model item. + * + * @param item the item + * @param parentFileModel the parent file model + * @return the file grid model + * @throws InternalErrorException the internal error exception + */ public FileGridModel buildGXTFileGridModelItem(WorkspaceItem item, FileModel parentFileModel) throws InternalErrorException{ @@ -1149,6 +1293,13 @@ public class GWTWorkspaceBuilder { } + /** + * Sets the folder item type for search. + * + * @param fileModel the file model + * @param searchFolderItem the search folder item + * @return the file model + */ protected FileModel setFolderItemTypeForSearch(FileModel fileModel, SearchFolderItem searchFolderItem){ if(searchFolderItem.getFolderItemType()==null){ @@ -1233,6 +1384,13 @@ public class GWTWorkspaceBuilder { + /** + * Sets the folder item type. + * + * @param fileModel the file model + * @param worspaceFolderItem the worspace folder item + * @return the file model + */ protected FileModel setFolderItemType(FileModel fileModel, FolderItem worspaceFolderItem){ switch(worspaceFolderItem.getFolderItemType()) @@ -1336,6 +1494,13 @@ public class GWTWorkspaceBuilder { return fileModel; } + /** + * Gets the publi link for folder item. + * + * @param worspaceFolderItem the worspace folder item + * @return the publi link for folder item + * @throws InternalErrorException the internal error exception + */ public String getPubliLinkForFolderItem(FolderItem worspaceFolderItem) throws InternalErrorException{ if(worspaceFolderItem==null) @@ -1385,11 +1550,12 @@ public class GWTWorkspaceBuilder { } /** - * - * @param wsFolder - * @param parent - * @return - * @throws InternalErrorException + * Builds the gxt folder model item. + * + * @param wsFolder the ws folder + * @param parent the parent + * @return the folder model + * @throws InternalErrorException the internal error exception */ public FolderModel buildGXTFolderModelItem(WorkspaceFolder wsFolder, FileModel parent) throws InternalErrorException { @@ -1426,11 +1592,13 @@ public class GWTWorkspaceBuilder { /** * TODO ********TEMPORARY SOLUTION HL MUST MANAGE SPECIAL FOLDER AS WORKSPACESPECIALFOLDER**** - * REMOVE THIS METHOD AND ADDING INSTANCE OF AT buildGXTFolderModelItem - * @param wsFolder - * @param parent - * @return - * @throws InternalErrorException + * REMOVE THIS METHOD AND ADDING INSTANCE OF AT buildGXTFolderModelItem. + * + * @param wsFolder the ws folder + * @param parent the parent + * @param specialFolderName the special folder name + * @return the folder model + * @throws InternalErrorException the internal error exception */ public FolderModel buildGXTFolderModelItemHandleSpecialFolder(WorkspaceFolder wsFolder, FileModel parent, String specialFolderName) throws InternalErrorException { @@ -1467,6 +1635,14 @@ public class GWTWorkspaceBuilder { } + /** + * Builds the gwt workspace file details. + * + * @param wsItem the ws item + * @param item the item + * @return the file details model + * @throws InternalErrorException the internal error exception + */ public FileDetailsModel buildGWTWorkspaceFileDetails(WorkspaceItem wsItem, FileModel item) throws InternalErrorException { FileDetailsModel fileDetailsModel = new FileDetailsModel( @@ -1485,6 +1661,13 @@ public class GWTWorkspaceBuilder { return fileDetailsModel; } + /** + * Gets the folder item type category. + * + * @param item the item + * @return the folder item type category + * @throws InternalErrorException the internal error exception + */ protected String getFolderItemTypeCategory(SearchItem item) throws InternalErrorException{ switch (item.getType()) { @@ -1535,6 +1718,14 @@ public class GWTWorkspaceBuilder { } + /** + * Filter list file grid model item by category. + * + * @param listSearchItem the list search item + * @param category the category + * @return the list + * @throws InternalErrorException the internal error exception + */ public List filterListFileGridModelItemByCategory(List listSearchItem, String category) throws InternalErrorException { List filteredList = new ArrayList(); @@ -1560,6 +1751,13 @@ public class GWTWorkspaceBuilder { } + /** + * Builds the gxt list smart folder model. + * + * @param listWorkspaceSmartFolder the list workspace smart folder + * @return the list + * @throws InternalErrorException the internal error exception + */ public List buildGXTListSmartFolderModel(List listWorkspaceSmartFolder) throws InternalErrorException { List listSmartFolder = new ArrayList(); @@ -1570,6 +1768,14 @@ public class GWTWorkspaceBuilder { } + /** + * Builds the gxt smart folder model. + * + * @param wsFolder the ws folder + * @param query the query + * @return the smart folder model + * @throws InternalErrorException the internal error exception + */ public SmartFolderModel buildGXTSmartFolderModel(WorkspaceSmartFolder wsFolder, String query) throws InternalErrorException { SmartFolderModel smartFolderModel = new SmartFolderModel( @@ -1581,6 +1787,13 @@ public class GWTWorkspaceBuilder { return smartFolderModel; } + /** + * Builds the gxt list scope model. + * + * @param listFilteredScopes the list filtered scopes + * @param mapPortalScopes the map portal scopes + * @return the list + */ public List buildGXTListScopeModel(List listFilteredScopes, Map mapPortalScopes) { List listScopeModel = new ArrayList(); @@ -1598,6 +1811,13 @@ public class GWTWorkspaceBuilder { } + /** + * Builds the gxt list contacts model from user model. + * + * @param listUsers the list users + * @return the list + * @throws InternalErrorException the internal error exception + */ public List buildGXTListContactsModelFromUserModel(List listUsers) throws InternalErrorException { List listContactsModel = new ArrayList(); @@ -1622,10 +1842,11 @@ public class GWTWorkspaceBuilder { } /** - * - * @param list - * @return - * @throws InternalErrorException + * Builds the gxt list contacts model from gcube group. + * + * @param list the list + * @return the list + * @throws InternalErrorException the internal error exception */ public List buildGXTListContactsModelFromGcubeGroup(List list) throws InternalErrorException { @@ -1670,10 +1891,11 @@ public class GWTWorkspaceBuilder { /** - * - * @param listContactsModel + * Builds the list login from contanct model. + * + * @param listContactsModel the list contacts model * @return list of portal logins - * @throws InternalErrorException + * @throws InternalErrorException the internal error exception */ public List buildListLoginFromContanctModel(List listContactsModel) throws InternalErrorException { @@ -1689,6 +1911,14 @@ public class GWTWorkspaceBuilder { + /** + * Builds the gxt list message model for grid. + * + * @param listMessages the list messages + * @param typeMessages the type messages + * @return the list + * @throws InternalErrorException the internal error exception + */ public List buildGXTListMessageModelForGrid(List listMessages, String typeMessages) throws InternalErrorException { List listMessageModel = new ArrayList(); @@ -1718,6 +1948,15 @@ public class GWTWorkspaceBuilder { return listMessageModel; } + /** + * Builds the gxt message model. + * + * @param mess the mess + * @param listWorkspaceItems the list workspace items + * @param messageType the message type + * @return the message model + * @throws InternalErrorException the internal error exception + */ public MessageModel buildGXTMessageModel(WorkspaceMessage mess, List listWorkspaceItems, String messageType) throws InternalErrorException { @@ -1734,10 +1973,11 @@ public class GWTWorkspaceBuilder { /** - * - * @param user + * Builds the gxt info contact model. + * + * @param user the user * @return InfoContactModel - * @throws InternalErrorException + * @throws InternalErrorException the internal error exception */ public InfoContactModel buildGXTInfoContactModel(User user) throws InternalErrorException{ @@ -1747,6 +1987,13 @@ public class GWTWorkspaceBuilder { return new InfoContactModel(); } + /** + * Builds the gxt list bulk creator model. + * + * @param listFBC the list fbc + * @return the list + * @throws InternalErrorException the internal error exception + */ public List buildGXTListBulkCreatorModel(List listFBC) throws InternalErrorException { List listBulkCreatorModel = new ArrayList(); @@ -1780,7 +2027,11 @@ public class GWTWorkspaceBuilder { /** - * @param accouting + * Builds the gxt accounting item. + * + * @param accoutings the accoutings + * @param gxtEntryType the gxt entry type + * @return the list */ public List buildGXTAccountingItem(List accoutings, GxtAccountingEntryType gxtEntryType) { @@ -2020,8 +2271,10 @@ public class GWTWorkspaceBuilder { /** - * @param readers - * @return + * Builds the gxt accounting item from readers. + * + * @param readers the readers + * @return the list */ public List buildGXTAccountingItemFromReaders(List readers) { @@ -2061,13 +2314,22 @@ public class GWTWorkspaceBuilder { /** - * @param infoContactModel + * Sets the user logged. + * + * @param infoContactModel the new user logged */ public void setUserLogged(InfoContactModel infoContactModel) { this.userLogged = infoContactModel; } + /** + * Gets the workspace acl from ac ls. + * + * @param types the types + * @return the workspace acl from ac ls + * @throws Exception the exception + */ public List getWorkspaceACLFromACLs(List types) throws Exception{ List acls = new ArrayList(); @@ -2103,6 +2365,13 @@ public class GWTWorkspaceBuilder { return acls; } + /** + * Builds the gxt list trash content. + * + * @param trash the trash + * @return the list + * @throws Exception the exception + */ public List buildGXTListTrashContent(WorkspaceTrashFolder trash) throws Exception { List trashContent = trash.listTrashItems(); @@ -2133,10 +2402,11 @@ public class GWTWorkspaceBuilder { } /** - * - * @param trashedItem - * @return - * @throws InternalErrorException + * Builds the gxt trash model item. + * + * @param trashedItem the trashed item + * @return the file trashed model + * @throws InternalErrorException the internal error exception */ public FileTrashedModel buildGXTTrashModelItem(WorkspaceTrashItem trashedItem) throws InternalErrorException{ @@ -2172,6 +2442,14 @@ public class GWTWorkspaceBuilder { } + /** + * Builds the gxt trash model item by id. + * + * @param itemId the item id + * @param trash the trash + * @return the file trashed model + * @throws InternalErrorException the internal error exception + */ public FileTrashedModel buildGXTTrashModelItemById(String itemId, WorkspaceTrashFolder trash) throws InternalErrorException{ return null; @@ -2179,10 +2457,12 @@ public class GWTWorkspaceBuilder { /** - * @param aclOwner - * @return + * Gets the formatted html acl from ac ls. + * + * @param aclOwner the acl owner + * @return the formatted html acl from ac ls */ - public String getFormattedHtmlACLFromACLs(Map> aclOwner) { + public String getFormatHtmlACLFromACLs(Map> aclOwner) { String html = "
"; @@ -2210,9 +2490,10 @@ public class GWTWorkspaceBuilder { } /** - * returns dynamically the formated size - * @param size - * @return + * returns dynamically the formated size. + * + * @param size the size + * @return the string */ public static String formatFileSize(long size) { String formattedSize = null; @@ -2240,6 +2521,13 @@ public class GWTWorkspaceBuilder { return formattedSize; } + /** + * Gets the item description for type by id. + * + * @param item the item + * @return the item description for type by id + * @throws Exception the exception + */ public String getItemDescriptionForTypeById(WorkspaceItem item) throws Exception { if(item==null) @@ -2290,4 +2578,65 @@ public class GWTWorkspaceBuilder { throw new Exception(error); } } + + /** + * Gets the format html gcube item properties. + * + * @param item the item + * @return Format HTML. A DIV HTML containing gcube item properties. If item is a GcubeItem and contains properties return HTML, null otherwise + */ + public String getFormatHtmlGcubeItemProperties(WorkspaceItem item) { + + Map properties = getGcubeItemProperties(item); + + if(properties!=null){ + + if(properties.size()==0){ + try { + logger.warn("Gcube Item Properties not found for item: "+item.getId()); + } catch (InternalErrorException e) { + //SILENT + } + return null; + } + + String html = "
"; + + for (String key : properties.keySet()) { + String value = properties.get(key); + + html+=""+key+": "; + html+=""; + html+=value; + html+="
"; + } + html+="
"; + + return html; + } + return null; + } + + + + /** + * Gets the gcube item properties. + * + * @param item the item + * @return the gcube item properties + */ + public Map getGcubeItemProperties(WorkspaceItem item) { + + if(item instanceof GCubeItem){ + GCubeItem gItem = (GCubeItem) item; + try { + return gItem.getProperties().getProperties(); + } catch (InternalErrorException e) { + logger.error("Error in server getItemProperties: ", e); + return null; + } + + } + return null; + } } diff --git a/src/main/java/org/gcube/portlets/user/workspace/server/GWTWorkspaceServiceImpl.java b/src/main/java/org/gcube/portlets/user/workspace/server/GWTWorkspaceServiceImpl.java index 096cb25..0b35181 100644 --- a/src/main/java/org/gcube/portlets/user/workspace/server/GWTWorkspaceServiceImpl.java +++ b/src/main/java/org/gcube/portlets/user/workspace/server/GWTWorkspaceServiceImpl.java @@ -35,6 +35,7 @@ import org.gcube.common.homelibrary.home.workspace.exceptions.WorkspaceFolderNot import org.gcube.common.homelibrary.home.workspace.exceptions.WrongDestinationException; import org.gcube.common.homelibrary.home.workspace.folder.FolderItem; import org.gcube.common.homelibrary.home.workspace.folder.items.ExternalUrl; +import org.gcube.common.homelibrary.home.workspace.folder.items.GCubeItem; import org.gcube.common.homelibrary.home.workspace.search.SearchItem; import org.gcube.common.homelibrary.home.workspace.sharing.WorkspaceMessage; import org.gcube.common.homelibrary.home.workspace.trash.WorkspaceTrashFolder; @@ -3222,7 +3223,7 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT * Gets the AC ls description for shared folder id. * * @param folderId the folder id - * @return Formatted HTML DIV containing ACLs description for folderId + * @return Format HTML - A DIV HTML containing ACLs description for folderId * @throws Exception the exception */ @Override @@ -3231,7 +3232,7 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT WorkspaceFolder wsFolder = getSharedWorkspaceFolderForId(folderId); GWTWorkspaceBuilder builder = getGWTWorkspaceBuilder(); - return builder.getFormattedHtmlACLFromACLs(wsFolder.getACLOwner()); + return builder.getFormatHtmlACLFromACLs(wsFolder.getACLOwner()); } catch (Exception e) { workspaceLogger.error("Error in server get getACLForFolderId", e); String error = ConstantsExplorer.SERVER_ERROR +" get ACL rules for selected folder. "+e.getMessage(); @@ -3746,5 +3747,100 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT } } + /* (non-Javadoc) + * @see org.gcube.portlets.user.workspace.client.rpc.GWTWorkspaceService#loadGcubeItemProperties(java.lang.String) + */ + @Override + public Map loadGcubeItemProperties(String itemId) throws Exception { + workspaceLogger.info("Getting GcubeItemProperties for itemId: "+itemId); + if(itemId==null || itemId.isEmpty()){ + workspaceLogger.warn("Getting GcubeItemProperties identifier is null or empty, returning null"); + return null; + } + + try { + + Workspace workspace = getWorkspace(); + WorkspaceItem item = workspace.getItem(itemId); + GWTWorkspaceBuilder builder = getGWTWorkspaceBuilder(); + Map mapProperties = builder.getGcubeItemProperties(item); + if(mapProperties!=null) + workspaceLogger.info("Returning "+mapProperties.size()+" properties"); + else + workspaceLogger.info("Returning null properties"); + + return mapProperties; + } catch (Exception e) { + workspaceLogger.error("Error in server GcubeItemProperties: ", e); + String error = ConstantsExplorer.SERVER_ERROR +" getting gcube item properties for item id: "+itemId; + throw new Exception(error); + } + } + + + /** + * Gets the HTML gcube item properties. + * + * @param itemId the item id + * @return The Gcube Item Properties in HTML format if itemId is a GcubeItem and contains properties, null otherwise + * @throws Exception the exception + */ + @Override + public String getHTMLGcubeItemProperties(String itemId) throws Exception { + workspaceLogger.info("Getting FormattedGcubeItemProperties for itemId: "+itemId); + if(itemId==null || itemId.isEmpty()){ + workspaceLogger.warn("Getting FormattedGcubeItemProperties identifier is null or empty, returning null"); + return null; + } + + try { + + Workspace workspace = getWorkspace(); + WorkspaceItem item = workspace.getItem(itemId); + GWTWorkspaceBuilder builder = getGWTWorkspaceBuilder(); + return builder.getFormatHtmlGcubeItemProperties(item); + + } catch (Exception e) { + workspaceLogger.error("Error in server FormattedGcubeItemProperties: ", e); + String error = ConstantsExplorer.SERVER_ERROR +" getting gcube item properties for item id: "+itemId; + throw new Exception(error); + } + } + + /** + * Sets the gcube item properties. + * + * @param itemId the item id + * @param properties the properties + * @throws Exception the exception + */ + @Override + public void setGcubeItemProperties(String itemId, Map properties) throws Exception { + workspaceLogger.info("Set GcubeItemProperties for itemId: "+itemId); + if(itemId==null || itemId.isEmpty()){ + workspaceLogger.warn("Set GcubeItemProperties, identifier is null or empty, returning null"); + throw new Exception("The item id is null or empty"); + } + + try { + + Workspace workspace = getWorkspace(); + WorkspaceItem item = workspace.getItem(itemId); + if(item instanceof GCubeItem){ + GCubeItem gItem = (GCubeItem) item; + for (String key : properties.keySet()) //ADD PROPERTIES + gItem.getProperties().addProperty(key, properties.get(key)); + }else + throw new NoGcubeItemTypeException("The item is not a Gcube Item"); + + } catch (NoGcubeItemTypeException e){ + workspaceLogger.error("Error in server FormattedGcubeItemProperties: ", e); + throw new Exception(e.getMessage()); + } catch (Exception e) { + workspaceLogger.error("Error in server FormattedGcubeItemProperties: ", e); + String error = ConstantsExplorer.SERVER_ERROR +" setting gcube item properties for item id: "+itemId; + throw new Exception(error); + } + } } diff --git a/src/main/java/org/gcube/portlets/user/workspace/server/NoGcubeItemTypeException.java b/src/main/java/org/gcube/portlets/user/workspace/server/NoGcubeItemTypeException.java new file mode 100644 index 0000000..e4e2884 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/workspace/server/NoGcubeItemTypeException.java @@ -0,0 +1,20 @@ +/** + * + */ +package org.gcube.portlets.user.workspace.server; + +/** + * @author Federico De Faveri defaveri@isti.cnr.it + * + */ +public class NoGcubeItemTypeException extends Exception{ + + private static final long serialVersionUID = 3660227882791095368L; + + public NoGcubeItemTypeException(String message) { + super(message); + } + + + +}