From 7442e8a6716691c4fc54e5f8a903fa74d76d8f1c Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Thu, 27 Aug 2020 17:42:08 +0200 Subject: [PATCH 01/44] migrated the method 'createGroup' --- pom.xml | 33 ++++++++++++------- .../server/CKANPublisherServicesImpl.java | 33 +++++++++++++++++-- 2 files changed, 52 insertions(+), 14 deletions(-) diff --git a/pom.xml b/pom.xml index be7b9c9..35933b7 100644 --- a/pom.xml +++ b/pom.xml @@ -13,7 +13,7 @@ org.gcube.portlets.widgets ckan-metadata-publisher-widget - 1.6.1 + 2.0.0-SNAPSHOT gCube Ckan metadata publisher widget @@ -145,18 +145,29 @@ [2.0.0,) provided + + + + + + + + + + + + + + - org.gcube.data-catalogue - ckan-util-library - [2.0.0, 3.0.0-SNAPSHOT) - compile - - - org.gcube.data-catalogue - gcubedatacatalogue-metadata-discovery - - + org.gcube.datacatalogue + catalogue-util-library + 0.1.0-SNAPSHOT + system + /home/francesco/git/catalogue-util-library/target/catalogue-util-library-0.1.0-SNAPSHOT.jar + + org.gcube.core common-scope-maps diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/CKANPublisherServicesImpl.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/CKANPublisherServicesImpl.java index 48d0ed6..1e3f05a 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/CKANPublisherServicesImpl.java +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/CKANPublisherServicesImpl.java @@ -48,9 +48,9 @@ import com.liferay.portal.kernel.log.Log; import com.liferay.portal.kernel.log.LogFactoryUtil; import com.liferay.portal.service.UserLocalServiceUtil; -import eu.trentorise.opendata.jackan.model.CkanGroup; import eu.trentorise.opendata.jackan.model.CkanLicense; + /** * Server side of the data publisher. * @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it) @@ -328,12 +328,33 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C logger.debug("The user wants to publish in organization with name " + organizationNameOrId); String scope = getScopeFromOrgName(organizationNameOrId); DataCatalogue utils = getCatalogue(scope); - String userApiKey = utils.getApiKeyFromUsername(userName); + String datasetId = utils.createCKanDatasetMultipleCustomFields(userName, + title, + null, + organizationNameOrId, + author, + authorMail, + maintainer, + maintainerMail, + version, + description, + licenseId, + listOfTags, + customFields, + resources, + setPublic, + true); + + /** + * OLD CODE + + String userApiKey = utils.getApiKeyFromUsername(userName); + String datasetId = utils.createCKanDatasetMultipleCustomFields (userApiKey, title, null, organizationNameOrId, author, authorMail, maintainer, maintainerMail, version, description, licenseId, listOfTags, customFields, resources, setPublic); - + */ if(datasetId != null){ logger.info("Dataset created!"); @@ -344,9 +365,15 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C toCreate.setSource(datasetUrl); // add also this information as custom field + /** + * TODO NEEDED TO BE CHECK + * + * OLD CODE NOT NEEDED. NOW IT IS PERFORMED BY gCAT Map> addField = new HashMap>(); addField.put(ITEM_URL_FIELD, Arrays.asList(datasetUrl)); utils.patchProductCustomFields(datasetId, userApiKey, addField, false); + + */ // start a thread that will associate this dataset with the group if(/*toCreate.getChosenType() != null ||*/ toCreate.getGroups() != null){ From 1395dd63ebfc3d03380c265b591b92556f2a220c Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Thu, 11 Feb 2021 11:09:41 +0100 Subject: [PATCH 02/44] merged with bug fixes releaed in v1.6.2 --- CHANGELOG.md | 8 ++++ .../ui/metadata/MetaDataFieldSkeleton.java | 42 ++++++++++++------- 2 files changed, 36 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5066dce..0690ed3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,14 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [v1.6.2] - 2021-02-08 + +**Bug Fixes** + +[#20446] Catalogue Publishing Widget: field value unexpectedly added in case of optional field +[#20663] Fixing Time_Interval placeholder + + ## [v1.6.1] [r4.24.0] - 2020-06-18 **New Features** diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/metadata/MetaDataFieldSkeleton.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/metadata/MetaDataFieldSkeleton.java index 34932d7..5dd231b 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/metadata/MetaDataFieldSkeleton.java +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/metadata/MetaDataFieldSkeleton.java @@ -309,11 +309,12 @@ public class MetaDataFieldSkeleton extends Composite{ if(field.isMultiSelection()) tempListBox.setTitle(TOOLTIP_MULTISELECTION); - // if it is not mandatory, add a disabled option - if(!field.getMandatory()){ + // if it is not mandatory and not multi-selection, add a disabled option (placeholder) + if(!field.getMandatory() && !field.isMultiSelection()){ tempListBox.addItem("Select " + field.getFieldName()); - tempListBox.setSelectedValue("Select " + field.getFieldName()); + tempListBox.setValue(0, ""); tempListBox.getElement().getElementsByTagName("option").getItem(0).setAttribute("disabled", "disabled"); + tempListBox.setSelectedValue("Select " + field.getFieldName()); } // get vocabulary fields @@ -637,13 +638,20 @@ public class MetaDataFieldSkeleton extends Composite{ case Time_Interval: manipulatedTemp = rangesList.get(0).getCurrentValue().replaceAll(DataTimeBox.MISSING_RANGE_VALUE_START, "").replaceAll(DataTimeBox.MISSING_RANGE_VALUE_END, UPPER_RANGE_NOT_SPECIFIED); - if(toReturn.equals(DataTimeBox.RANGE_SEPARATOR_START_END + UPPER_RANGE_NOT_SPECIFIED)) - manipulatedTemp = ""; - + + //fixed by Francesco, see #20663#note-12 + if(!field.getMandatory()) { + if(manipulatedTemp.equals(DataTimeBox.RANGE_SEPARATOR_START_END + UPPER_RANGE_NOT_SPECIFIED)) + manipulatedTemp = ""; + } + // split to check if the extreme are equals - String[] temp = manipulatedTemp.split(DataTimeBox.RANGE_SEPARATOR_START_END); - if(temp[0].equals(temp[1])) - manipulatedTemp = temp[0]; + //fixed by Francesco + if(!manipulatedTemp.isEmpty()) { + String[] temp = manipulatedTemp.split(DataTimeBox.RANGE_SEPARATOR_START_END); + if(temp[0].equals(temp[1])) + manipulatedTemp = temp[0]; + } toReturn.add(manipulatedTemp); break; @@ -679,7 +687,7 @@ public class MetaDataFieldSkeleton extends Composite{ toReturn.add(((TextBox)holder).getText()); else{ - // handle multiselected case + // handle single and multi-selected case for(int i = 0; i < ((ListBox)holder).getItemCount(); i++){ if(((ListBox)holder).isItemSelected(i)){ toReturn.add(((ListBox)holder).getItemText(i)); @@ -687,11 +695,17 @@ public class MetaDataFieldSkeleton extends Composite{ } // if it was not mandatory but there was no choice, returning empty string - if(!field.getMandatory()) - if(toReturn.equals("Select " + field.getFieldName())){ - toReturn.clear(); - toReturn.add(""); + if(!field.getMandatory()) { + //Task #20446 - bug fix. Ignoring the placeholder + if(toReturn.size()==1) { + String placeholder = "Select " + field.getFieldName(); + if(toReturn.get(0).equals(placeholder)){ + GWT.log("Skipping placeholder: "+placeholder); + toReturn.clear(); + //toReturn.add(""); + } } + } } break; From 37254e0096e2858cbc25994d12a9fe052d81ab87 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Thu, 11 Feb 2021 16:13:23 +0100 Subject: [PATCH 03/44] porting to catalogue-util-library should be completed --- ...se.wst.common.project.facet.core.prefs.xml | 7 + ....eclipse.wst.common.project.facet.core.xml | 1 + CHANGELOG.md | 7 + pom.xml | 31 +- .../server/CKANPublisherServicesImpl.java | 96 +-- .../AssociationToGroupAndNotifyThread.java | 321 ++++----- .../WritePostCatalogueManagerThread.java | 647 +++++++++--------- .../server/utils/CatalogueRoleManager.java | 3 +- 8 files changed, 563 insertions(+), 550 deletions(-) create mode 100644 .settings/org.eclipse.wst.common.project.facet.core.prefs.xml diff --git a/.settings/org.eclipse.wst.common.project.facet.core.prefs.xml b/.settings/org.eclipse.wst.common.project.facet.core.prefs.xml new file mode 100644 index 0000000..cc81385 --- /dev/null +++ b/.settings/org.eclipse.wst.common.project.facet.core.prefs.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/.settings/org.eclipse.wst.common.project.facet.core.xml b/.settings/org.eclipse.wst.common.project.facet.core.xml index 3f2dd2b..fe92fc5 100644 --- a/.settings/org.eclipse.wst.common.project.facet.core.xml +++ b/.settings/org.eclipse.wst.common.project.facet.core.xml @@ -4,4 +4,5 @@ + diff --git a/CHANGELOG.md b/CHANGELOG.md index 0690ed3..c678c50 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [v2.0.0-SNAPSHOT] - 2021-02-11 + +**Enhancements** + +[#19764] Porting ckan-metadata-publisher-widget to catalogue-util-library + + ## [v1.6.2] - 2021-02-08 **Bug Fixes** diff --git a/pom.xml b/pom.xml index 35933b7..6440917 100644 --- a/pom.xml +++ b/pom.xml @@ -146,28 +146,27 @@ provided - - - - - - - - - - - - + + + + + + + + + + + + + org.gcube.datacatalogue catalogue-util-library - 0.1.0-SNAPSHOT - system - /home/francesco/git/catalogue-util-library/target/catalogue-util-library-0.1.0-SNAPSHOT.jar + [0.1.0-SNAPSHOT, 1.0.0) + compile - org.gcube.core common-scope-maps diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/CKANPublisherServicesImpl.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/CKANPublisherServicesImpl.java index 1e3f05a..699114f 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/CKANPublisherServicesImpl.java +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/CKANPublisherServicesImpl.java @@ -5,7 +5,6 @@ import java.util.Arrays; import java.util.Calendar; import java.util.Collections; import java.util.Comparator; -import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Map.Entry; @@ -20,9 +19,9 @@ import org.gcube.datacatalogue.ckanutillibrary.server.utils.CatalogueUtilMethods import org.gcube.datacatalogue.ckanutillibrary.server.utils.SessionCatalogueAttributes; import org.gcube.datacatalogue.ckanutillibrary.shared.ResourceBean; import org.gcube.datacatalogue.ckanutillibrary.shared.RolesCkanGroupOrOrg; +import org.gcube.datacatalogue.ckanutillibrary.shared.jackan.model.CkanGroup; +import org.gcube.datacatalogue.ckanutillibrary.shared.jackan.model.CkanLicense; import org.gcube.portlets.widgets.ckandatapublisherwidget.client.CKanPublisherService; -import org.gcube.portlets.widgets.ckandatapublisherwidget.server.threads.AssociationToGroupAndNotifyThread; -import org.gcube.portlets.widgets.ckandatapublisherwidget.server.threads.WritePostCatalogueManagerThread; import org.gcube.portlets.widgets.ckandatapublisherwidget.server.utils.CatalogueRoleManager; import org.gcube.portlets.widgets.ckandatapublisherwidget.server.utils.DiscoverTagsList; import org.gcube.portlets.widgets.ckandatapublisherwidget.server.utils.GenericUtils; @@ -48,7 +47,7 @@ import com.liferay.portal.kernel.log.Log; import com.liferay.portal.kernel.log.LogFactoryUtil; import com.liferay.portal.service.UserLocalServiceUtil; -import eu.trentorise.opendata.jackan.model.CkanLicense; + /** @@ -328,8 +327,8 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C logger.debug("The user wants to publish in organization with name " + organizationNameOrId); String scope = getScopeFromOrgName(organizationNameOrId); DataCatalogue utils = getCatalogue(scope); - - String datasetId = utils.createCKanDatasetMultipleCustomFields(userName, + + String datasetId = utils.createCkanDatasetMultipleCustomFields(userName, title, null, organizationNameOrId, @@ -344,6 +343,7 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C customFields, resources, setPublic, + true, true); /** @@ -374,41 +374,43 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C utils.patchProductCustomFields(datasetId, userApiKey, addField, false); */ + + //TODO SHOULD BE NOTIFIED by gCAT // start a thread that will associate this dataset with the group - if(/*toCreate.getChosenType() != null ||*/ toCreate.getGroups() != null){ - - AssociationToGroupAndNotifyThread threadAssociationToGroup = - new AssociationToGroupAndNotifyThread( - toCreate.getGroups(), - toCreate.getGroupsForceCreation(), - null, //toCreate.getChosenType(), TODO - datasetUrl, - datasetId, - toCreate.getTitle(), - GenericUtils.getCurrentUser(getThreadLocalRequest()).getFullname(), - userName, - utils, - organizationNameOrId, - getThreadLocalRequest() - ); - threadAssociationToGroup.start(); - - } - - // launch notification thread - WritePostCatalogueManagerThread threadWritePost = - new WritePostCatalogueManagerThread( - userName, - scope, - toCreate.getTitle(), - datasetUrl, - false, // send notification to other people - toCreate.getTags(), - GenericUtils.getCurrentUser(getThreadLocalRequest()).getFullname(), - GenericUtils.getCurrentClientUrl(getThreadLocalRequest()) - ); - threadWritePost.start(); +// if(/*toCreate.getChosenType() != null ||*/ toCreate.getGroups() != null){ +// +// AssociationToGroupAndNotifyThread threadAssociationToGroup = +// new AssociationToGroupAndNotifyThread( +// toCreate.getGroups(), +// toCreate.getGroupsForceCreation(), +// null, //toCreate.getChosenType(), TODO +// datasetUrl, +// datasetId, +// toCreate.getTitle(), +// GenericUtils.getCurrentUser(getThreadLocalRequest()).getFullname(), +// userName, +// utils, +// organizationNameOrId, +// getThreadLocalRequest() +// ); +// threadAssociationToGroup.start(); +// +// } +// +// // launch notification thread +// WritePostCatalogueManagerThread threadWritePost = +// new WritePostCatalogueManagerThread( +// userName, +// scope, +// toCreate.getTitle(), +// datasetUrl, +// false, // send notification to other people +// toCreate.getTags(), +// GenericUtils.getCurrentUser(getThreadLocalRequest()).getFullname(), +// GenericUtils.getCurrentClientUrl(getThreadLocalRequest()) +// ); +// threadWritePost.start(); return toCreate; }else{ @@ -450,7 +452,7 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C // get the scope in which we should discover the ckan instance given the organization name in which the dataset was created String scope = getScopeFromOrgName(resource.getOrganizationNameDatasetParent()); DataCatalogue catalogue = getCatalogue(scope); - String resourceId = catalogue.addResourceToDataset(resourceBean, catalogue.getApiKeyFromUsername(username)); + String resourceId = catalogue.addResourceToDataset(resourceBean); if(resourceId != null){ logger.debug("Resource " + resource.getName() + " is now available"); @@ -475,13 +477,11 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C return deleted; }else{ - String username = GenericUtils.getCurrentUser(getThreadLocalRequest()).getUsername(); try{ // get the scope in which we should discover the ckan instance given the organization name in which the dataset was created String scope = getScopeFromOrgName(resource.getOrganizationNameDatasetParent()); DataCatalogue catalogue = getCatalogue(scope); - deleted = catalogue. - deleteResourceFromDataset(resource.getOriginalIdInWorkspace(), catalogue.getApiKeyFromUsername(username)); + deleted = catalogue.deleteResourceFromDataset(resource.getOriginalIdInWorkspace()); if(deleted){ logger.info("Resource described by " + resource + " deleted"); }else @@ -565,7 +565,10 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C List toReturn = new ArrayList(); if(isWithinPortal()){ - String username = GenericUtils.getCurrentUser(getThreadLocalRequest()).getUsername(); + GCubeUser user = GenericUtils.getCurrentUser(getThreadLocalRequest()); + String username = null; + if(user!=null) + username = user.getUsername(); logger.debug("Request for user " + username + " groups. Organization name is " + orgName); @@ -584,10 +587,9 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C //Fixing Incident #12563 try{ DataCatalogue catalogue = getCatalogue(scope); - String apiKey = catalogue.getApiKeyFromUsername(username); //Fixing Incident #12563 - if(apiKey!=null && !apiKey.isEmpty()){ - Map> mapRoleGroup = catalogue.getUserRoleByGroup(username, apiKey); + if(username!=null && !username.isEmpty()){ + Map> mapRoleGroup = catalogue.getUserRoleByGroup(username); Set>> set = mapRoleGroup.entrySet(); for (Entry> entry : set) { Set> subSet = entry.getValue().entrySet(); diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/threads/AssociationToGroupAndNotifyThread.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/threads/AssociationToGroupAndNotifyThread.java index 3266249..c252731 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/threads/AssociationToGroupAndNotifyThread.java +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/threads/AssociationToGroupAndNotifyThread.java @@ -1,160 +1,161 @@ -package org.gcube.portlets.widgets.ckandatapublisherwidget.server.threads; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.Map; - -import javax.servlet.http.HttpServletRequest; - -import org.gcube.common.portal.mailing.EmailNotification; -import org.gcube.datacatalogue.ckanutillibrary.server.DataCatalogue; -import org.gcube.datacatalogue.ckanutillibrary.server.utils.CatalogueUtilMethods; -import org.gcube.datacatalogue.ckanutillibrary.shared.RolesCkanGroupOrOrg; -import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.OrganizationBean; -import org.gcube.vomanagement.usermanagement.UserManager; -import org.gcube.vomanagement.usermanagement.impl.LiferayUserManager; - -import com.liferay.portal.kernel.log.Log; -import com.liferay.portal.kernel.log.LogFactoryUtil; - -import eu.trentorise.opendata.jackan.model.CkanGroup; - -/** - * Associate the dataset to a group and send notifications to group's admins. - * @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it) - */ -public class AssociationToGroupAndNotifyThread extends Thread { - - //private static final Logger logger = LoggerFactory.getLogger(AssociationToGroupAndNotifyThread.class); - private static final Log logger = LogFactoryUtil.getLog(AssociationToGroupAndNotifyThread.class); - private static final String PRODUCT_ASSOCIATED_TO_GROUP_SUBJECT = "Item $TITLE added to group $GROUP"; - private static final String PRODUCT_ASSOCIATED_TO_GROUP_BODY = "Dear user,
a new item named '$TITLE' has been " - + "just published by $USER_FULLNAME in $GROUP .
" - + "You can find it here $DATASET_URL"; - - private String groupTitle; - private String datasetId; - private String username; - private String datasetTitle; - private String userFullName; - private DataCatalogue catalogue; - // private String organization; - private List groups; - private HttpServletRequest request; - private String datasetUrl; - private List groupsForceCreation; - - /** - * @param list - * @param groupTitle - * @param datasetId - * @param username - * @param catalogue - */ - public AssociationToGroupAndNotifyThread(List groups, List groupsForceCreation, String groupTitle, String datasetUrl, String datasetId, String datasetTitle, String userFullName, - String username, DataCatalogue catalogue, String organization, HttpServletRequest request) { - this.request = request; - this.groups = groups == null ? new ArrayList() : groups; - this.groupsForceCreation = groupsForceCreation; - this.groupTitle = groupTitle; - this.datasetId = datasetId; - this.username = username; - this.catalogue = catalogue; - // this.organization = organization; - this.datasetTitle = datasetTitle; - this.userFullName = userFullName; - this.datasetUrl = datasetUrl; - } - - @Override - public void run() { - - logger.info("Association thread started to put the dataset with id = "+ datasetId + " into group with title " + groupTitle + " for user " + username); - - // force creation of groups if needed - if(groupsForceCreation != null){ - logger.info("Groups that must be created before association are " + groupsForceCreation); - for (OrganizationBean groupToForce : groupsForceCreation) { - try{ - CkanGroup group = catalogue.createGroup(groupToForce.getName(), groupToForce.getTitle(), ""); - if(group == null) - logger.error("Unable to retrieve or create group with name " + groupToForce); - else - groups.add(new OrganizationBean(group.getTitle(), group.getName(), false, groupToForce.isPropagateUp())); - }catch(Exception e){ - logger.error("Failed to check if a group with this info " + groupToForce + " already exists or can be created"); - } - } - - } - - logger.info("Other groups to which the product should be associate are " + groups); - - if(groups != null) - for (OrganizationBean groupBean : groups) { - boolean putIntoGroup = catalogue.assignDatasetToGroup(groupBean.getName(), datasetId, catalogue.getApiKeyFromUsername(username), groupBean.isPropagateUp()); - logger.info("Was product put into group" + groupBean.getTitle() + "? " + putIntoGroup); - if(putIntoGroup) - notifyGroupAdmins(catalogue, groupBean.getName() ,groupBean.getTitle(), username); - } - - } - - /** - * Send a notification to the group admin(s) about the just added product - * @param username - * @param groupTitle - * @param catalogue - */ - private void notifyGroupAdmins(DataCatalogue catalogue, String groupName, String groupTitle, String username){ - - // get the groups admin - Map> userAndRoles = catalogue.getRolesAndUsersGroup(groupName); - - if(userAndRoles.containsKey(RolesCkanGroupOrOrg.ADMIN)){ - - List admins = userAndRoles.get(RolesCkanGroupOrOrg.ADMIN); - List adminsEmails = new ArrayList(); - - for(int i = 0; i < admins.size(); i++){ - String convertedName = CatalogueUtilMethods.fromCKanUsernameToUsername(admins.get(i)); - admins.set(i, convertedName); - } - - // remove the same user who published the product if he/she is an admin of the group - int indexOfUser = admins.indexOf(username); - if(indexOfUser >= 0) - admins.remove(indexOfUser); - - // further cleaning of the list (for users that are only in ckan... sysadmin for example) - UserManager um = new LiferayUserManager(); - Iterator adminIt = admins.iterator(); - - while (adminIt.hasNext()) { - String admin = (String) adminIt.next(); - try{ - adminsEmails.add(um.getUserByUsername(admin).getEmail()); - }catch(Exception e){ - logger.error("User with username " + admin + " doesn't exist in Liferay"); - adminIt.remove(); - } - } - - logger.info("The list of admins for group " + groupTitle + " is " + admins); - - if(admins.isEmpty()) - return; - - // send the email - EmailNotification mailToSend = new EmailNotification( - adminsEmails, - PRODUCT_ASSOCIATED_TO_GROUP_SUBJECT.replace("$TITLE", datasetTitle).replace("$GROUP", groupTitle), - PRODUCT_ASSOCIATED_TO_GROUP_BODY.replace("$TITLE", datasetTitle).replace("$GROUP", groupTitle).replace("$USER_FULLNAME", userFullName).replace("$DATASET_URL", datasetUrl), - request); - mailToSend.sendEmail(); - - }else - logger.warn("It seems there is no user with role Admin in group " + groupTitle); - } -} +//package org.gcube.portlets.widgets.ckandatapublisherwidget.server.threads; +// +//import java.util.ArrayList; +//import java.util.Iterator; +//import java.util.List; +//import java.util.Map; +// +//import javax.servlet.http.HttpServletRequest; +// +//import org.gcube.common.portal.mailing.EmailNotification; +//import org.gcube.datacatalogue.ckanutillibrary.server.DataCatalogue; +//import org.gcube.datacatalogue.ckanutillibrary.server.utils.CatalogueUtilMethods; +//import org.gcube.datacatalogue.ckanutillibrary.shared.RolesCkanGroupOrOrg; +//import org.gcube.datacatalogue.ckanutillibrary.shared.jackan.model.CkanGroup; +//import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.OrganizationBean; +//import org.gcube.vomanagement.usermanagement.UserManager; +//import org.gcube.vomanagement.usermanagement.impl.LiferayUserManager; +// +//import com.liferay.portal.kernel.log.Log; +//import com.liferay.portal.kernel.log.LogFactoryUtil; +// +// +// +///** +// * Associate the dataset to a group and send notifications to group's admins. +// * @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it) +// */ +//public class AssociationToGroupAndNotifyThread extends Thread { +// +// //private static final Logger logger = LoggerFactory.getLogger(AssociationToGroupAndNotifyThread.class); +// private static final Log logger = LogFactoryUtil.getLog(AssociationToGroupAndNotifyThread.class); +// private static final String PRODUCT_ASSOCIATED_TO_GROUP_SUBJECT = "Item $TITLE added to group $GROUP"; +// private static final String PRODUCT_ASSOCIATED_TO_GROUP_BODY = "Dear user,
a new item named '$TITLE' has been " +// + "just published by $USER_FULLNAME in $GROUP .
" +// + "You can find it here $DATASET_URL"; +// +// private String groupTitle; +// private String datasetId; +// private String username; +// private String datasetTitle; +// private String userFullName; +// private DataCatalogue catalogue; +// // private String organization; +// private List groups; +// private HttpServletRequest request; +// private String datasetUrl; +// private List groupsForceCreation; +// +// /** +// * @param list +// * @param groupTitle +// * @param datasetId +// * @param username +// * @param catalogue +// */ +// public AssociationToGroupAndNotifyThread(List groups, List groupsForceCreation, String groupTitle, String datasetUrl, String datasetId, String datasetTitle, String userFullName, +// String username, DataCatalogue catalogue, String organization, HttpServletRequest request) { +// this.request = request; +// this.groups = groups == null ? new ArrayList() : groups; +// this.groupsForceCreation = groupsForceCreation; +// this.groupTitle = groupTitle; +// this.datasetId = datasetId; +// this.username = username; +// this.catalogue = catalogue; +// // this.organization = organization; +// this.datasetTitle = datasetTitle; +// this.userFullName = userFullName; +// this.datasetUrl = datasetUrl; +// } +// +// @Override +// public void run() { +// +// logger.info("Association thread started to put the dataset with id = "+ datasetId + " into group with title " + groupTitle + " for user " + username); +// +// // force creation of groups if needed +// if(groupsForceCreation != null){ +// logger.info("Groups that must be created before association are " + groupsForceCreation); +// for (OrganizationBean groupToForce : groupsForceCreation) { +// try{ +// CkanGroup group = catalogue.createGroup(groupToForce.getName(), groupToForce.getTitle(), ""); +// if(group == null) +// logger.error("Unable to retrieve or create group with name " + groupToForce); +// else +// groups.add(new OrganizationBean(group.getTitle(), group.getName(), false, groupToForce.isPropagateUp())); +// }catch(Exception e){ +// logger.error("Failed to check if a group with this info " + groupToForce + " already exists or can be created"); +// } +// } +// +// } +// +// logger.info("Other groups to which the product should be associate are " + groups); +// +// if(groups != null) +// for (OrganizationBean groupBean : groups) { +// boolean putIntoGroup = catalogue.assignDatasetToGroup(groupBean.getName(), datasetId, groupBean.isPropagateUp()); +// logger.info("Was product put into group" + groupBean.getTitle() + "? " + putIntoGroup); +// if(putIntoGroup) +// notifyGroupAdmins(catalogue, groupBean.getName() ,groupBean.getTitle(), username); +// } +// +// } +// +// /** +// * Send a notification to the group admin(s) about the just added product +// * @param username +// * @param groupTitle +// * @param catalogue +// */ +// private void notifyGroupAdmins(DataCatalogue catalogue, String groupName, String groupTitle, String username){ +// +// // get the groups admin +// Map> userAndRoles = catalogue.getRolesAndUsersGroup(groupName); +// +// if(userAndRoles.containsKey(RolesCkanGroupOrOrg.ADMIN)){ +// +// List admins = userAndRoles.get(RolesCkanGroupOrOrg.ADMIN); +// List adminsEmails = new ArrayList(); +// +// for(int i = 0; i < admins.size(); i++){ +// String convertedName = CatalogueUtilMethods.fromCKanUsernameToUsername(admins.get(i)); +// admins.set(i, convertedName); +// } +// +// // remove the same user who published the product if he/she is an admin of the group +// int indexOfUser = admins.indexOf(username); +// if(indexOfUser >= 0) +// admins.remove(indexOfUser); +// +// // further cleaning of the list (for users that are only in ckan... sysadmin for example) +// UserManager um = new LiferayUserManager(); +// Iterator adminIt = admins.iterator(); +// +// while (adminIt.hasNext()) { +// String admin = (String) adminIt.next(); +// try{ +// adminsEmails.add(um.getUserByUsername(admin).getEmail()); +// }catch(Exception e){ +// logger.error("User with username " + admin + " doesn't exist in Liferay"); +// adminIt.remove(); +// } +// } +// +// logger.info("The list of admins for group " + groupTitle + " is " + admins); +// +// if(admins.isEmpty()) +// return; +// +// // send the email +// EmailNotification mailToSend = new EmailNotification( +// adminsEmails, +// PRODUCT_ASSOCIATED_TO_GROUP_SUBJECT.replace("$TITLE", datasetTitle).replace("$GROUP", groupTitle), +// PRODUCT_ASSOCIATED_TO_GROUP_BODY.replace("$TITLE", datasetTitle).replace("$GROUP", groupTitle).replace("$USER_FULLNAME", userFullName).replace("$DATASET_URL", datasetUrl), +// request); +// mailToSend.sendEmail(); +// +// }else +// logger.warn("It seems there is no user with role Admin in group " + groupTitle); +// } +//} diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/threads/WritePostCatalogueManagerThread.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/threads/WritePostCatalogueManagerThread.java index a98593f..8ab084e 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/threads/WritePostCatalogueManagerThread.java +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/threads/WritePostCatalogueManagerThread.java @@ -1,325 +1,322 @@ -package org.gcube.portlets.widgets.ckandatapublisherwidget.server.threads; - -import java.io.IOException; -import java.net.HttpURLConnection; -import java.util.List; - -import org.gcube.common.authorization.library.provider.SecurityTokenProvider; -import org.gcube.common.scope.api.ScopeProvider; -import org.gcube.portlets.widgets.ckandatapublisherwidget.server.utils.GCoreEndPointReaderSocial; -import org.gcube.portlets.widgets.ckandatapublisherwidget.server.utils.GenericUtils; -import org.json.simple.JSONObject; -import org.json.simple.parser.JSONParser; - -import com.liferay.portal.kernel.log.Log; -import com.liferay.portal.kernel.log.LogFactoryUtil; - -import eu.trentorise.opendata.jackan.internal.org.apache.http.Header; -import eu.trentorise.opendata.jackan.internal.org.apache.http.HttpEntity; -import eu.trentorise.opendata.jackan.internal.org.apache.http.HttpResponse; -import eu.trentorise.opendata.jackan.internal.org.apache.http.client.ClientProtocolException; -import eu.trentorise.opendata.jackan.internal.org.apache.http.client.methods.HttpPost; -import eu.trentorise.opendata.jackan.internal.org.apache.http.entity.StringEntity; -import eu.trentorise.opendata.jackan.internal.org.apache.http.impl.client.CloseableHttpClient; -import eu.trentorise.opendata.jackan.internal.org.apache.http.impl.client.HttpClientBuilder; -import eu.trentorise.opendata.jackan.internal.org.apache.http.util.EntityUtils; - - -/** - * Let the Product Catalogue Manager write a post in a VRE and alert there is a new product - * @author Costantino Perciante at ISTI-CNR - * (costantino.perciante@isti.cnr.it) - */ -public class WritePostCatalogueManagerThread extends Thread { - - public static final String APPLICATION_ID_CATALOGUE_MANAGER = "org.gcube.datacatalogue.ProductCatalogue"; - private static final String NOTIFICATION_MESSAGE = "Dear members,\n$USER_FULLNAME just published the item '$PRODUCT_TITLE'.\nYou can find it at: $PRODUCT_URL\n"; - private static final String SOCIAL_SERVICE_APPLICATION_TOKEN = "2/tokens/generate-application-token"; - private static final String SOCIAL_SERVICE_WRITE_APPLICATION_POST = "2/posts/write-post-app"; - private static final String MEDIATYPE_JSON = "application/json"; - private static final Log logger = LogFactoryUtil.getLog(WritePostCatalogueManagerThread.class); - private String username; - private String scope; - private String productTitle; - private String productUrl; - private boolean enableNotification; - private List hashtags; - private String userFullName; - private String userCurrentUrl; - - /** - * @param token - * @param scope - * @param productTitle - * @param productUrl - * @param enableNotification - * @param hashtags - * @param userFullName - */ - public WritePostCatalogueManagerThread( - String username, String scope, - String productTitle, String productUrl, boolean enableNotification, - List hashtags, String userFullName, String userCurrentUrl) { - super(); - this.username = username; - this.scope = scope; - this.productTitle = productTitle; - this.productUrl = productUrl; - this.enableNotification = enableNotification; - this.hashtags = hashtags; - this.userFullName = userFullName; - this.userCurrentUrl = userCurrentUrl; - } - - @Override - public void run() { - - try{ - // evaluate user's token for this scope - String token = GenericUtils.tryGetElseCreateToken(username, scope); - - if(token == null){ - logger.warn("Unable to proceed, user's token is not available"); - return; - } - - logger.info("Started request to write application post " - + "for new product created. Scope is " + scope + " and " - + "token is " + token.substring(0, 10) + "****************"); - - // set token and scope - ScopeProvider.instance.set(scope); - SecurityTokenProvider.instance.set(token); - - //see Feature #17577 - /*final String profilePageURL = GCubePortalConstants.PREFIX_GROUP_URL + extractOrgFriendlyURL(userCurrentUrl) + GCubePortalConstants.USER_PROFILE_FRIENDLY_URL; - - userFullName = ""+userFullName+ - " "; - */ - - userFullName = "@"+username; - - // write - writeProductPost( - productTitle, - productUrl, - userFullName, - hashtags, - enableNotification - ); - - }catch(Exception e){ - logger.error("Failed to write the post because of the following error ", e); - }finally{ - SecurityTokenProvider.instance.reset(); - ScopeProvider.instance.reset(); - } - } - - public static String extractOrgFriendlyURL(String portalURL) { - String groupRegEx = "/group/"; - if (portalURL.contains(groupRegEx)) { - String[] splits = portalURL.split(groupRegEx); - String friendlyURL = splits[1]; - if (friendlyURL.contains("/")) { - friendlyURL = friendlyURL.split("/")[0]; - } else { - friendlyURL = friendlyURL.split("\\?")[0].split("\\#")[0]; - } - return "/"+friendlyURL; - } - return null; - } - - /** - * Send notification to vre members about the created product by writing a post. - * @param productName the title of the product - * @param productUrl the url of the product - * @param hashtags a list of product's hashtags - */ - private static void writeProductPost(String productName, String productUrl, String userFullname, List hashtags, boolean enablePostNotification){ - - // discover service endpoint for the social networking library - String currentScope = ScopeProvider.instance.get(); - String tokenUser = SecurityTokenProvider.instance.get(); - - logger.info("Current scope for writeProductPost is " + currentScope + " and token is " + tokenUser.substring(0, 10) + "***************"); - String basePath = new GCoreEndPointReaderSocial(currentScope).getBasePath(); - - if(basePath == null){ - - logger.error("Unable to write a post because there is no social networking service available"); - - }else{ - - // check base path form - basePath = basePath.endsWith("/") ? basePath : basePath + "/"; - - try(CloseableHttpClient client = HttpClientBuilder.create().build();){ - - String pathTokenApp = basePath + SOCIAL_SERVICE_APPLICATION_TOKEN + "?gcube-token=" + tokenUser; - String tokenApp = requireAppToken(client, pathTokenApp); - if(tokenApp != null){ - String pathWritePost = basePath + SOCIAL_SERVICE_WRITE_APPLICATION_POST + "?gcube-token=" + tokenApp; - writePost(client, pathWritePost, productName, productUrl, userFullname, hashtags, enablePostNotification); - } - - }catch(Exception e){ - logger.error("Failed to create a post", e); - } - } - } - - /** - * Require the application token - * @param tokenUser - * @param basePath - * @param client - * @return - */ - private static String requireAppToken(CloseableHttpClient client, String path){ - - String token = null; - try{ - - JSONObject request = new JSONObject(); - request.put("app_id", APPLICATION_ID_CATALOGUE_MANAGER); - HttpResponse response = performRequest(client, path, request.toJSONString()); - - int statusTokenGenerate = response.getStatusLine().getStatusCode(); - - if(statusTokenGenerate == HttpURLConnection.HTTP_CREATED){ - - // extract token - JSONObject obj = getJSONObject(response); - if(((Boolean) obj.get("success"))) - token = (String)obj.get("result"); - else - return null; - - }else if(statusTokenGenerate == HttpURLConnection.HTTP_MOVED_TEMP - || statusTokenGenerate == HttpURLConnection.HTTP_MOVED_PERM - || statusTokenGenerate == HttpURLConnection.HTTP_SEE_OTHER){ - - // re-execute - Header[] locations = response.getHeaders("Location"); - Header lastLocation = locations[locations.length - 1]; - String realLocation = lastLocation.getValue(); - logger.debug("New location is " + realLocation); - token = requireAppToken(client, realLocation); - - }else - return null; - - }catch(Exception e){ - logger.error("Failed to retrieve application token", e); - } - - logger.info("Returning app token " + (token != null ? token.substring(0, 10) + "*************************" : null)); - return token; - } - - /** - * Write post request - * @param client - * @param applicationToken - * @param productName - * @param productUrl - * @param userFullname - * @param hashtags - */ - private static void writePost(CloseableHttpClient client, String path, String productName, String productUrl, String userFullname, List hashtags, - boolean enablePostNotification) { - - try{ - - // replace - String message = NOTIFICATION_MESSAGE.replace("$PRODUCT_TITLE", productName).replace("$PRODUCT_URL", productUrl).replace("$USER_FULLNAME", userFullname); - - if(hashtags != null && !hashtags.isEmpty()) - for (String hashtag : hashtags) { - String modifiedHashtag = hashtag.replaceAll(" ", "_").replace("_+", "_"); - if(modifiedHashtag.endsWith("_")) - modifiedHashtag = modifiedHashtag.substring(0, modifiedHashtag.length() - 1); - message += " #" + modifiedHashtag; // ckan accepts tag with empty spaces, we don't - } - - JSONObject request = new JSONObject(); - request.put("text", message); - request.put("enable_notification", enablePostNotification); - logger.info("The post that is going to be written is ->\n" + request.toJSONString()); - HttpResponse response = performRequest(client, path, request.toJSONString()); - int statusWritePost = response.getStatusLine().getStatusCode(); - - if(statusWritePost == HttpURLConnection.HTTP_CREATED){ - - // extract token - JSONObject obj = getJSONObject(response); - if(((Boolean) obj.get("success"))) - logger.info("Post written"); - else - logger.info("Failed to write the post " + obj.get("message")); - - }else if(statusWritePost == HttpURLConnection.HTTP_MOVED_TEMP - || statusWritePost == HttpURLConnection.HTTP_MOVED_PERM - || statusWritePost == HttpURLConnection.HTTP_SEE_OTHER){ - - // re-execute - Header[] locations = response.getHeaders("Location"); - Header lastLocation = locations[locations.length - 1]; - String realLocation = lastLocation.getValue(); - logger.debug("New location is " + realLocation); - writePost(client, realLocation, productName, productUrl, userFullname, hashtags, enablePostNotification); - - }else - throw new RuntimeException("Failed to write the post "); - - }catch(Exception e){ - logger.error("Failed to write the post ", e); - } - - } - - /** - * Convert the json response to a map - * @param response - * @return - */ - private static JSONObject getJSONObject(HttpResponse response){ - - JSONObject toReturn = null; - HttpEntity entity = response.getEntity(); - - if (entity != null) { - try { - String jsonString = EntityUtils.toString(response.getEntity()); - JSONParser parser = new JSONParser(); - toReturn = (JSONObject)parser.parse(jsonString); - }catch(Exception e){ - logger.error("Failed to read json object", e); - } - } - - logger.debug("Returning " + toReturn.toJSONString()); - return toReturn; - } - - /** - * Perform an http request post request with json entity - * @throws IOException - * @throws ClientProtocolException - */ - private static HttpResponse performRequest(CloseableHttpClient client, String path, String entity) throws ClientProtocolException, IOException{ - - HttpPost request = new HttpPost(path); - StringEntity stringEntity = new StringEntity(entity); - stringEntity.setContentType(MEDIATYPE_JSON); - request.setEntity(stringEntity); - return client.execute(request); - - } - -} \ No newline at end of file +//package org.gcube.portlets.widgets.ckandatapublisherwidget.server.threads; +// +//import java.io.IOException; +//import java.net.HttpURLConnection; +//import java.util.List; +// +//import org.apache.http.HttpEntity; +//import org.apache.http.HttpResponse; +//import org.apache.http.client.ClientProtocolException; +//import org.apache.http.client.methods.HttpPost; +//import org.apache.http.entity.StringEntity; +//import org.apache.http.impl.client.CloseableHttpClient; +//import org.apache.http.impl.client.HttpClientBuilder; +//import org.apache.http.util.EntityUtils; +//import org.gcube.common.authorization.library.provider.SecurityTokenProvider; +//import org.gcube.common.scope.api.ScopeProvider; +//import org.gcube.portlets.widgets.ckandatapublisherwidget.server.utils.GCoreEndPointReaderSocial; +//import org.gcube.portlets.widgets.ckandatapublisherwidget.server.utils.GenericUtils; +// +//import com.google.gwt.json.client.JSONParser; +//import com.liferay.portal.kernel.log.Log; +//import com.liferay.portal.kernel.log.LogFactoryUtil; +// +// +///** +// * Let the Product Catalogue Manager write a post in a VRE and alert there is a new product +// * @author Costantino Perciante at ISTI-CNR +// * (costantino.perciante@isti.cnr.it) +// */ +//public class WritePostCatalogueManagerThread extends Thread { +// +// public static final String APPLICATION_ID_CATALOGUE_MANAGER = "org.gcube.datacatalogue.ProductCatalogue"; +// private static final String NOTIFICATION_MESSAGE = "Dear members,\n$USER_FULLNAME just published the item '$PRODUCT_TITLE'.\nYou can find it at: $PRODUCT_URL\n"; +// private static final String SOCIAL_SERVICE_APPLICATION_TOKEN = "2/tokens/generate-application-token"; +// private static final String SOCIAL_SERVICE_WRITE_APPLICATION_POST = "2/posts/write-post-app"; +// private static final String MEDIATYPE_JSON = "application/json"; +// private static final Log logger = LogFactoryUtil.getLog(WritePostCatalogueManagerThread.class); +// private String username; +// private String scope; +// private String productTitle; +// private String productUrl; +// private boolean enableNotification; +// private List hashtags; +// private String userFullName; +// private String userCurrentUrl; +// +// /** +// * @param token +// * @param scope +// * @param productTitle +// * @param productUrl +// * @param enableNotification +// * @param hashtags +// * @param userFullName +// */ +// public WritePostCatalogueManagerThread( +// String username, String scope, +// String productTitle, String productUrl, boolean enableNotification, +// List hashtags, String userFullName, String userCurrentUrl) { +// super(); +// this.username = username; +// this.scope = scope; +// this.productTitle = productTitle; +// this.productUrl = productUrl; +// this.enableNotification = enableNotification; +// this.hashtags = hashtags; +// this.userFullName = userFullName; +// this.userCurrentUrl = userCurrentUrl; +// } +// +// @Override +// public void run() { +// +// try{ +// // evaluate user's token for this scope +// String token = GenericUtils.tryGetElseCreateToken(username, scope); +// +// if(token == null){ +// logger.warn("Unable to proceed, user's token is not available"); +// return; +// } +// +// logger.info("Started request to write application post " +// + "for new product created. Scope is " + scope + " and " +// + "token is " + token.substring(0, 10) + "****************"); +// +// // set token and scope +// ScopeProvider.instance.set(scope); +// SecurityTokenProvider.instance.set(token); +// +// //see Feature #17577 +// /*final String profilePageURL = GCubePortalConstants.PREFIX_GROUP_URL + extractOrgFriendlyURL(userCurrentUrl) + GCubePortalConstants.USER_PROFILE_FRIENDLY_URL; +// +// userFullName = ""+userFullName+ +// " "; +// */ +// +// userFullName = "@"+username; +// +// // write +// writeProductPost( +// productTitle, +// productUrl, +// userFullName, +// hashtags, +// enableNotification +// ); +// +// }catch(Exception e){ +// logger.error("Failed to write the post because of the following error ", e); +// }finally{ +// SecurityTokenProvider.instance.reset(); +// ScopeProvider.instance.reset(); +// } +// } +// +// public static String extractOrgFriendlyURL(String portalURL) { +// String groupRegEx = "/group/"; +// if (portalURL.contains(groupRegEx)) { +// String[] splits = portalURL.split(groupRegEx); +// String friendlyURL = splits[1]; +// if (friendlyURL.contains("/")) { +// friendlyURL = friendlyURL.split("/")[0]; +// } else { +// friendlyURL = friendlyURL.split("\\?")[0].split("\\#")[0]; +// } +// return "/"+friendlyURL; +// } +// return null; +// } +// +// /** +// * Send notification to vre members about the created product by writing a post. +// * @param productName the title of the product +// * @param productUrl the url of the product +// * @param hashtags a list of product's hashtags +// */ +// private static void writeProductPost(String productName, String productUrl, String userFullname, List hashtags, boolean enablePostNotification){ +// +// // discover service endpoint for the social networking library +// String currentScope = ScopeProvider.instance.get(); +// String tokenUser = SecurityTokenProvider.instance.get(); +// +// logger.info("Current scope for writeProductPost is " + currentScope + " and token is " + tokenUser.substring(0, 10) + "***************"); +// String basePath = new GCoreEndPointReaderSocial(currentScope).getBasePath(); +// +// if(basePath == null){ +// +// logger.error("Unable to write a post because there is no social networking service available"); +// +// }else{ +// +// // check base path form +// basePath = basePath.endsWith("/") ? basePath : basePath + "/"; +// +// try(CloseableHttpClient client = HttpClientBuilder.create().build();){ +// +// String pathTokenApp = basePath + SOCIAL_SERVICE_APPLICATION_TOKEN + "?gcube-token=" + tokenUser; +// String tokenApp = requireAppToken(client, pathTokenApp); +// if(tokenApp != null){ +// String pathWritePost = basePath + SOCIAL_SERVICE_WRITE_APPLICATION_POST + "?gcube-token=" + tokenApp; +// writePost(client, pathWritePost, productName, productUrl, userFullname, hashtags, enablePostNotification); +// } +// +// }catch(Exception e){ +// logger.error("Failed to create a post", e); +// } +// } +// } +// +// /** +// * Require the application token +// * @param tokenUser +// * @param basePath +// * @param client +// * @return +// */ +// private static String requireAppToken(CloseableHttpClient client, String path){ +// +// String token = null; +// try{ +// +// JSONObject request = new JSONObject(); +// request.put("app_id", APPLICATION_ID_CATALOGUE_MANAGER); +// HttpResponse response = performRequest(client, path, request.toJSONString()); +// +// int statusTokenGenerate = response.getStatusLine().getStatusCode(); +// +// if(statusTokenGenerate == HttpURLConnection.HTTP_CREATED){ +// +// // extract token +// JSONObject obj = getJSONObject(response); +// if(((Boolean) obj.get("success"))) +// token = (String)obj.get("result"); +// else +// return null; +// +// }else if(statusTokenGenerate == HttpURLConnection.HTTP_MOVED_TEMP +// || statusTokenGenerate == HttpURLConnection.HTTP_MOVED_PERM +// || statusTokenGenerate == HttpURLConnection.HTTP_SEE_OTHER){ +// +// // re-execute +// Header[] locations = response.getHeaders("Location"); +// Header lastLocation = locations[locations.length - 1]; +// String realLocation = lastLocation.getValue(); +// logger.debug("New location is " + realLocation); +// token = requireAppToken(client, realLocation); +// +// }else +// return null; +// +// }catch(Exception e){ +// logger.error("Failed to retrieve application token", e); +// } +// +// logger.info("Returning app token " + (token != null ? token.substring(0, 10) + "*************************" : null)); +// return token; +// } +// +// /** +// * Write post request +// * @param client +// * @param applicationToken +// * @param productName +// * @param productUrl +// * @param userFullname +// * @param hashtags +// */ +// private static void writePost(CloseableHttpClient client, String path, String productName, String productUrl, String userFullname, List hashtags, +// boolean enablePostNotification) { +// +// try{ +// +// // replace +// String message = NOTIFICATION_MESSAGE.replace("$PRODUCT_TITLE", productName).replace("$PRODUCT_URL", productUrl).replace("$USER_FULLNAME", userFullname); +// +// if(hashtags != null && !hashtags.isEmpty()) +// for (String hashtag : hashtags) { +// String modifiedHashtag = hashtag.replaceAll(" ", "_").replace("_+", "_"); +// if(modifiedHashtag.endsWith("_")) +// modifiedHashtag = modifiedHashtag.substring(0, modifiedHashtag.length() - 1); +// message += " #" + modifiedHashtag; // ckan accepts tag with empty spaces, we don't +// } +// +// JSONObject request = new JSONObject(); +// request.put("text", message); +// request.put("enable_notification", enablePostNotification); +// logger.info("The post that is going to be written is ->\n" + request.toJSONString()); +// HttpResponse response = performRequest(client, path, request.toJSONString()); +// int statusWritePost = response.getStatusLine().getStatusCode(); +// +// if(statusWritePost == HttpURLConnection.HTTP_CREATED){ +// +// // extract token +// JSONObject obj = getJSONObject(response); +// if(((Boolean) obj.get("success"))) +// logger.info("Post written"); +// else +// logger.info("Failed to write the post " + obj.get("message")); +// +// }else if(statusWritePost == HttpURLConnection.HTTP_MOVED_TEMP +// || statusWritePost == HttpURLConnection.HTTP_MOVED_PERM +// || statusWritePost == HttpURLConnection.HTTP_SEE_OTHER){ +// +// // re-execute +// Header[] locations = response.getHeaders("Location"); +// Header lastLocation = locations[locations.length - 1]; +// String realLocation = lastLocation.getValue(); +// logger.debug("New location is " + realLocation); +// writePost(client, realLocation, productName, productUrl, userFullname, hashtags, enablePostNotification); +// +// }else +// throw new RuntimeException("Failed to write the post "); +// +// }catch(Exception e){ +// logger.error("Failed to write the post ", e); +// } +// +// } +// +// /** +// * Convert the json response to a map +// * @param response +// * @return +// */ +// private static JSONObject getJSONObject(HttpResponse response){ +// +// JSONObject toReturn = null; +// HttpEntity entity = response.getEntity(); +// +// if (entity != null) { +// try { +// String jsonString = EntityUtils.toString(response.getEntity()); +// JSONParser parser = new JSONParser(); +// toReturn = (JSONObject)parser.parse(jsonString); +// }catch(Exception e){ +// logger.error("Failed to read json object", e); +// } +// } +// +// logger.debug("Returning " + toReturn.toJSONString()); +// return toReturn; +// } +// +// /** +// * Perform an http request post request with json entity +// * @throws IOException +// * @throws ClientProtocolException +// */ +// private static HttpResponse performRequest(CloseableHttpClient client, String path, String entity) throws ClientProtocolException, IOException{ +// +// HttpPost request = new HttpPost(path); +// StringEntity stringEntity = new StringEntity(entity); +// stringEntity.setContentType(MEDIATYPE_JSON); +// request.setEntity(stringEntity); +// return client.execute(request); +// +// } +// +//} \ No newline at end of file diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/utils/CatalogueRoleManager.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/utils/CatalogueRoleManager.java index 1c1ca35..120d8b8 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/utils/CatalogueRoleManager.java +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/utils/CatalogueRoleManager.java @@ -6,6 +6,7 @@ import java.util.Set; import org.gcube.datacatalogue.ckanutillibrary.server.DataCatalogue; import org.gcube.datacatalogue.ckanutillibrary.shared.RolesCkanGroupOrOrg; +import org.gcube.datacatalogue.ckanutillibrary.shared.jackan.model.CkanOrganization; import org.gcube.portlets.widgets.ckandatapublisherwidget.server.CKANPublisherServicesImpl; import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.OrganizationBean; import org.gcube.vomanagement.usermanagement.GroupManager; @@ -23,8 +24,6 @@ import org.gcube.vomanagement.usermanagement.model.GatewayRolesNames; import com.liferay.portal.kernel.log.Log; import com.liferay.portal.kernel.log.LogFactoryUtil; -import eu.trentorise.opendata.jackan.model.CkanOrganization; - /** * Facilities to check roles into the catalogue. */ From b611ffd6cad8eeaf133007df70655eded8e8fbc5 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Fri, 12 Feb 2021 15:47:36 +0100 Subject: [PATCH 04/44] updated at [0.2.0-SNAPSHOT, 1.0.0) the ranage of catalogue-util-library --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 6440917..66ca1ea 100644 --- a/pom.xml +++ b/pom.xml @@ -163,7 +163,7 @@ org.gcube.datacatalogue catalogue-util-library - [0.1.0-SNAPSHOT, 1.0.0) + [0.2.0-SNAPSHOT, 1.0.0) compile From 4574d01bf2b867fe0f823563e537a6328d2e583b Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Fri, 12 Feb 2021 16:39:30 +0100 Subject: [PATCH 05/44] refactored catalogue-util-library --- pom.xml | 2 +- .../server/CKANPublisherServicesImpl.java | 35 ++++++++++++------- .../server/utils/CatalogueRoleManager.java | 6 ++-- .../server/utils/DiscoverTagsList.java | 2 +- .../server/utils/GenericUtils.java | 2 +- .../server/utils/MetadataDiscovery.java | 4 +-- .../server/utils/WorkspaceUtils.java | 4 +-- 7 files changed, 32 insertions(+), 23 deletions(-) diff --git a/pom.xml b/pom.xml index 66ca1ea..98122e0 100644 --- a/pom.xml +++ b/pom.xml @@ -163,7 +163,7 @@ org.gcube.datacatalogue catalogue-util-library - [0.2.0-SNAPSHOT, 1.0.0) + [0.3.0-SNAPSHOT, 1.0.0) compile diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/CKANPublisherServicesImpl.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/CKANPublisherServicesImpl.java index 699114f..7dba39b 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/CKANPublisherServicesImpl.java +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/CKANPublisherServicesImpl.java @@ -13,14 +13,14 @@ import java.util.concurrent.ConcurrentHashMap; import javax.servlet.http.HttpSession; -import org.gcube.datacatalogue.ckanutillibrary.server.DataCatalogue; -import org.gcube.datacatalogue.ckanutillibrary.server.DataCatalogueFactory; -import org.gcube.datacatalogue.ckanutillibrary.server.utils.CatalogueUtilMethods; -import org.gcube.datacatalogue.ckanutillibrary.server.utils.SessionCatalogueAttributes; -import org.gcube.datacatalogue.ckanutillibrary.shared.ResourceBean; -import org.gcube.datacatalogue.ckanutillibrary.shared.RolesCkanGroupOrOrg; -import org.gcube.datacatalogue.ckanutillibrary.shared.jackan.model.CkanGroup; -import org.gcube.datacatalogue.ckanutillibrary.shared.jackan.model.CkanLicense; +import org.gcube.datacatalogue.utillibrary.server.DataCatalogue; +import org.gcube.datacatalogue.utillibrary.server.DataCatalogueFactory; +import org.gcube.datacatalogue.utillibrary.server.utils.CatalogueUtilMethods; +import org.gcube.datacatalogue.utillibrary.server.utils.SessionCatalogueAttributes; +import org.gcube.datacatalogue.utillibrary.shared.ResourceBean; +import org.gcube.datacatalogue.utillibrary.shared.RolesCkanGroupOrOrg; +import org.gcube.datacatalogue.utillibrary.shared.jackan.model.CkanGroup; +import org.gcube.datacatalogue.utillibrary.shared.jackan.model.CkanLicense; import org.gcube.portlets.widgets.ckandatapublisherwidget.client.CKanPublisherService; import org.gcube.portlets.widgets.ckandatapublisherwidget.server.utils.CatalogueRoleManager; import org.gcube.portlets.widgets.ckandatapublisherwidget.server.utils.DiscoverTagsList; @@ -236,11 +236,11 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C bean.setVersion(1); String onlyAlphanumeric = "test-creation-blablabla".replaceAll("[^A-Za-z0-9]", ""); bean.setTitle(onlyAlphanumeric + Calendar.getInstance().getTimeInMillis()); - bean.setAuthorName("Costantino"); - bean.setAuthorSurname("Perciante"); - bean.setAuthorEmail("costantino.perciante@isti.cnr.it"); - bean.setMaintainer("Costantino Perciante"); - bean.setMaintainerEmail("costantino.perciante@isti.cnr.it"); + bean.setAuthorName("Francesco"); + bean.setAuthorSurname("Mangiacrapa"); + bean.setAuthorEmail("francesco.mangiacrapa@isti.cnr.it"); + bean.setMaintainer("Francesco Mangiacrapa"); + bean.setMaintainerEmail("francesco.mangiacrapa@isti.cnr.it"); //UPDATED By Francesco String scope = GenericUtils.getCurrentContext(this.getThreadLocalRequest(), false); @@ -294,6 +294,15 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C public DatasetBean createCKanDataset(DatasetBean toCreate) throws Exception{ try{ + + + if (!isWithinPortal()) { + logger.info("DETECTED DEV MODE"); + GenericUtils.getCurrentContext(getThreadLocalRequest(), true); + GenericUtils.getCurrentToken(getThreadLocalRequest(), true); + } + + logger.info("Request for creating a dataset with these information " + toCreate); String userName = GenericUtils.getCurrentUser(getThreadLocalRequest()).getUsername(); String title = toCreate.getTitle(); diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/utils/CatalogueRoleManager.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/utils/CatalogueRoleManager.java index 120d8b8..42278fc 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/utils/CatalogueRoleManager.java +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/utils/CatalogueRoleManager.java @@ -4,9 +4,9 @@ import java.util.HashSet; import java.util.List; import java.util.Set; -import org.gcube.datacatalogue.ckanutillibrary.server.DataCatalogue; -import org.gcube.datacatalogue.ckanutillibrary.shared.RolesCkanGroupOrOrg; -import org.gcube.datacatalogue.ckanutillibrary.shared.jackan.model.CkanOrganization; +import org.gcube.datacatalogue.utillibrary.server.DataCatalogue; +import org.gcube.datacatalogue.utillibrary.shared.RolesCkanGroupOrOrg; +import org.gcube.datacatalogue.utillibrary.shared.jackan.model.CkanOrganization; import org.gcube.portlets.widgets.ckandatapublisherwidget.server.CKANPublisherServicesImpl; import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.OrganizationBean; import org.gcube.vomanagement.usermanagement.GroupManager; diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/utils/DiscoverTagsList.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/utils/DiscoverTagsList.java index 7dc66f2..8d6e52a 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/utils/DiscoverTagsList.java +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/utils/DiscoverTagsList.java @@ -10,7 +10,7 @@ import javax.xml.parsers.DocumentBuilderFactory; import org.gcube.common.resources.gcore.utils.XPathHelper; import org.gcube.common.scope.api.ScopeProvider; -import org.gcube.datacatalogue.ckanutillibrary.shared.ex.ApplicationProfileNotFoundException; +import org.gcube.datacatalogue.utillibrary.shared.ex.ApplicationProfileNotFoundException; import org.gcube.portlets.widgets.ckandatapublisherwidget.server.CKANPublisherServicesImpl; import org.gcube.resources.discovery.client.api.DiscoveryClient; import org.gcube.resources.discovery.client.queries.api.Query; diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/utils/GenericUtils.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/utils/GenericUtils.java index b3346ca..4f80440 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/utils/GenericUtils.java +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/utils/GenericUtils.java @@ -15,7 +15,7 @@ import org.gcube.common.authorization.library.provider.SecurityTokenProvider; import org.gcube.common.authorization.library.provider.UserInfo; import org.gcube.common.portal.PortalContext; import org.gcube.common.scope.api.ScopeProvider; -import org.gcube.datacatalogue.ckanutillibrary.server.ApplicationProfileScopePerUrlReader; +import org.gcube.datacatalogue.utillibrary.server.ApplicationProfileScopePerUrlReader; import org.gcube.vomanagement.usermanagement.GroupManager; import org.gcube.vomanagement.usermanagement.exception.GroupRetrievalFault; import org.gcube.vomanagement.usermanagement.exception.UserManagementSystemException; diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/utils/MetadataDiscovery.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/utils/MetadataDiscovery.java index e484f45..ac2641f 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/utils/MetadataDiscovery.java +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/utils/MetadataDiscovery.java @@ -10,8 +10,6 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpSession; import org.gcube.common.scope.api.ScopeProvider; -import org.gcube.datacatalogue.ckanutillibrary.server.utils.CatalogueUtilMethods; -import org.gcube.datacatalogue.ckanutillibrary.server.utils.SessionCatalogueAttributes; import org.gcube.datacatalogue.metadatadiscovery.DataCalogueMetadataFormatReader; import org.gcube.datacatalogue.metadatadiscovery.bean.MetadataProfile; import org.gcube.datacatalogue.metadatadiscovery.bean.jaxb.MetadataField; @@ -21,6 +19,8 @@ import org.gcube.datacatalogue.metadatadiscovery.bean.jaxb.MetadataTagging; import org.gcube.datacatalogue.metadatadiscovery.bean.jaxb.MetadataValidator; import org.gcube.datacatalogue.metadatadiscovery.bean.jaxb.MetadataVocabulary; import org.gcube.datacatalogue.metadatadiscovery.bean.jaxb.NamespaceCategory; +import org.gcube.datacatalogue.utillibrary.server.utils.CatalogueUtilMethods; +import org.gcube.datacatalogue.utillibrary.server.utils.SessionCatalogueAttributes; import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.metadata.CategoryWrapper; import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.metadata.DataTypeWrapper; import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.metadata.FieldAsGroup; diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/utils/WorkspaceUtils.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/utils/WorkspaceUtils.java index 283ce3e..c9c4760 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/utils/WorkspaceUtils.java +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/utils/WorkspaceUtils.java @@ -18,8 +18,8 @@ import org.gcube.common.homelibrary.home.workspace.catalogue.WorkspaceCatalogue; 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.datacatalogue.ckanutillibrary.server.utils.CatalogueUtilMethods; -import org.gcube.datacatalogue.ckanutillibrary.shared.ResourceBean; +import org.gcube.datacatalogue.utillibrary.server.utils.CatalogueUtilMethods; +import org.gcube.datacatalogue.utillibrary.shared.ResourceBean; import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.DatasetBean; import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.ResourceElementBean; From ca6f85c91379c025a0a2964556faf78f2b4dfc59 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Tue, 16 Feb 2021 17:58:35 +0100 Subject: [PATCH 06/44] updated inherits of org.gcube.datacatalogue.utillibrary.CkanUtilLibrary --- .../ckandatapublisherwidget/CKanMetadataPublisher.gwt.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/CKanMetadataPublisher.gwt.xml b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/CKanMetadataPublisher.gwt.xml index b2174ff..97d480b 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/CKanMetadataPublisher.gwt.xml +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/CKanMetadataPublisher.gwt.xml @@ -9,7 +9,7 @@ - + From ca659c194dba0c7ff8c54c22f3ffb923f8478e06 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Wed, 17 Feb 2021 11:19:34 +0100 Subject: [PATCH 07/44] imported catalogue-util-library [1.0.0-SNAPSHOT, 2.0.0) --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 98122e0..92083ec 100644 --- a/pom.xml +++ b/pom.xml @@ -163,7 +163,7 @@ org.gcube.datacatalogue catalogue-util-library - [0.3.0-SNAPSHOT, 1.0.0) + [1.0.0-SNAPSHOT, 2.0.0) compile From 0e2b8fe4205a4c34dee6065f945930c7c2d435db Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Wed, 17 Feb 2021 15:40:53 +0100 Subject: [PATCH 08/44] fixed error message --- .../server/CKANPublisherServicesImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/CKANPublisherServicesImpl.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/CKANPublisherServicesImpl.java index 7dba39b..c607036 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/CKANPublisherServicesImpl.java +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/CKANPublisherServicesImpl.java @@ -428,7 +428,7 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C }catch(Exception e){ logger.error("Error while creating item ", e); - throw new Exception("An error occurred while creating the item " + e.getMessage()); + throw new Exception(e.getMessage()); } return null; From fec44f2b961137cfae2307778f1ef70fca183c4e Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Thu, 18 Feb 2021 14:49:02 +0100 Subject: [PATCH 09/44] integrated with StorageHubWrapper --- CHANGELOG.md | 1 + pom.xml | 53 ++- .../server/CKANPublisherServicesImpl.java | 257 ++++++++---- .../server/utils/WorkspaceUtils.java | 377 +++++++++++++----- 4 files changed, 484 insertions(+), 204 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c678c50..faf9dbc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm **Enhancements** [#19764] Porting ckan-metadata-publisher-widget to catalogue-util-library +[#20680] Ported to SHUB ## [v1.6.2] - 2021-02-08 diff --git a/pom.xml b/pom.xml index 92083ec..074fddc 100644 --- a/pom.xml +++ b/pom.xml @@ -121,24 +121,33 @@ [2.0.0, 3.0.0-SNAPSHOT) provided
+ org.gcube.common - home-library - [2.5.0,) - provided - - - asm-all - asm - - - - - org.gcube.common - home-library-jcr - [2.5.0,) - provided + storagehub-client-wrapper + [1.0.0, 2.0.0-SNAPSHOT) + compile + + + + + + + + + + + + + + + + + + + + org.gcube.dvos usermanagement-core @@ -146,20 +155,6 @@ provided - - - - - - - - - - - - - - org.gcube.datacatalogue catalogue-util-library diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/CKANPublisherServicesImpl.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/CKANPublisherServicesImpl.java index c607036..5b24a85 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/CKANPublisherServicesImpl.java +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/CKANPublisherServicesImpl.java @@ -13,6 +13,9 @@ import java.util.concurrent.ConcurrentHashMap; import javax.servlet.http.HttpSession; +import org.gcube.common.portal.PortalContext; +import org.gcube.common.storagehubwrapper.server.StorageHubWrapper; +import org.gcube.common.storagehubwrapper.server.tohl.Workspace; import org.gcube.datacatalogue.utillibrary.server.DataCatalogue; import org.gcube.datacatalogue.utillibrary.server.DataCatalogueFactory; import org.gcube.datacatalogue.utillibrary.server.utils.CatalogueUtilMethods; @@ -68,10 +71,24 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C // map private ConcurrentHashMap mapOrganizationScope = new ConcurrentHashMap(); + /** - * Retrieve an instance of the library for the scope + * Dev mode set contexts. + */ + private void devModeSetContexts() { + if (!isWithinPortal()) { + logger.info("DETECTED DEV MODE"); + GenericUtils.getCurrentContext(getThreadLocalRequest(), true); + GenericUtils.getCurrentToken(getThreadLocalRequest(), true); + } + + } + + /** + * Retrieve an instance of the library for the scope. + * * @param scope if it is null it is evaluated from the session - * @return + * @return the catalogue */ public DataCatalogue getCatalogue(String scope){ @@ -88,11 +105,13 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C } /** - * Retrieve the list of organizations in which the user can publish (roles ADMIN/EDITOR) - * @param username + * Retrieve the list of organizations in which the user can publish (roles ADMIN/EDITOR). + * + * @param username the username + * @param scope the scope * @return the list of organizations - * @throws GroupRetrievalFault - * @throws UserManagementSystemException + * @throws UserManagementSystemException the user management system exception + * @throws GroupRetrievalFault the group retrieval fault */ private List getUserOrganizationsListAdmin(String username, String scope) throws UserManagementSystemException, GroupRetrievalFault { @@ -118,7 +137,8 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C } /** - * Online or in development mode? + * Online or in development mode?. + * * @return true if you're running into the portal, false if in development */ private boolean isWithinPortal() { @@ -131,11 +151,25 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C return false; } } + + /** + * Gets the workspace from storage hub. + * + * @return the workspace from storage hub + * @throws Exception + * the exception + */ + protected Workspace getWorkspaceFromStorageHub() throws Exception { + GCubeUser user = PortalContext.getConfiguration().getCurrentUser(this.getThreadLocalRequest()); + StorageHubWrapper storageHubWrapper = WorkspaceUtils.getStorageHubWrapper(this.getThreadLocalRequest(), null, user); + return storageHubWrapper.getWorkspace(); + } /** * Find a license id given the license text. - * @param chosenLicense - * @return + * + * @param chosenLicense the chosen license + * @return the string */ private String findLicenseIdByLicense(String chosenLicense) { @@ -145,6 +179,11 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C } + /** + * Gets the licenses. + * + * @return the licenses + */ @Override public List getLicenses() { @@ -178,7 +217,15 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C return licensesBean; } + + /** + * Gets the dataset bean. + * + * @param folderId the folder id + * @return the dataset bean + * @throws Exception the exception + */ @Override public DatasetBean getDatasetBean(String folderId) throws Exception{ @@ -193,7 +240,6 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C String scope = GenericUtils.getScopeFromClientUrl(getThreadLocalRequest()); logger.debug("Scope recovered from session is " + scope); - logger.debug("Request dataset metadata bean for folder with id " + folderId + " whose owner is " + userName); @@ -217,7 +263,8 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C // if the request comes from the workspace if(folderId != null && !folderId.isEmpty()){ - WorkspaceUtils.handleWorkspaceResources(folderId, userName, bean); + Workspace workspace = getWorkspaceFromStorageHub(); + WorkspaceUtils.handleWorkspaceResources(folderId, userName, bean, workspace); } }catch(Exception e){ @@ -251,7 +298,8 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C bean.setOwnerIdentifier(userName); if(folderId != null && !folderId.isEmpty()){ - WorkspaceUtils.handleWorkspaceResources(folderId, userName, bean); + Workspace workspace = getWorkspaceFromStorageHub(); + WorkspaceUtils.handleWorkspaceResources(folderId, userName, bean, workspace); } }catch(Exception e){ logger.error("Error while building bean into dev mode", e); @@ -264,9 +312,10 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C } /** - * Discover from the IS the vocabulary of tags for this scope, if present + * Discover from the IS the vocabulary of tags for this scope, if present. + * + * @param context the context * @return a list of tags vocabulary - * @throws Exception */ private List discoverTagsVocabulary(String context){ @@ -285,24 +334,30 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C return vocabulary; } + /** + * Gets the tags for organization. + * + * @param orgName the org name + * @return the tags for organization + * @throws Exception the exception + */ @Override public List getTagsForOrganization(String orgName) throws Exception{ return discoverTagsVocabulary(getScopeFromOrgName(orgName)); } + /** + * Creates the C kan dataset. + * + * @param toCreate the to create + * @return the dataset bean + * @throws Exception the exception + */ @Override public DatasetBean createCKanDataset(DatasetBean toCreate) throws Exception{ try{ - - - if (!isWithinPortal()) { - logger.info("DETECTED DEV MODE"); - GenericUtils.getCurrentContext(getThreadLocalRequest(), true); - GenericUtils.getCurrentToken(getThreadLocalRequest(), true); - } - - + devModeSetContexts(); logger.info("Request for creating a dataset with these information " + toCreate); String userName = GenericUtils.getCurrentUser(getThreadLocalRequest()).getUsername(); String title = toCreate.getTitle(); @@ -329,8 +384,14 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C ResourceElementBean resourcesToAdd = toCreate.getResourceRoot(); // we need to copy such resource in the .catalogue area of the user's ws +// if(resourcesToAdd != null){ +// resources = WorkspaceUtils.copyResourcesToUserCatalogueArea(toCreate.getId(), userName, toCreate); +// } + + //converting to resources to be added if(resourcesToAdd != null){ - resources = WorkspaceUtils.copyResourcesToUserCatalogueArea(toCreate.getId(), userName, toCreate); + Workspace workspace = getWorkspaceFromStorageHub(); + resources = WorkspaceUtils.toResources(toCreate, workspace, userName); } logger.debug("The user wants to publish in organization with name " + organizationNameOrId); @@ -434,75 +495,84 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C return null; } - + + /** + * Adds the resource to dataset. + * + * @param resource the resource + * @param datasetId the dataset id + * @return the resource element bean + * @throws Exception the exception + */ @Override public ResourceElementBean addResourceToDataset(ResourceElementBean resource, String datasetId) throws Exception{ + logger.info("called addResourceToDataset"); + devModeSetContexts(); String username = GenericUtils.getCurrentUser(getThreadLocalRequest()).getUsername(); - logger.debug("Incoming request for creating new resource for dataset with id " + datasetId + " and organization name of the dataset is " + resource.getOrganizationNameDatasetParent()); logger.debug("Owner is " + username + " and resource is " + resource); - if(!isWithinPortal()){ + ResourceBean resourceBean = new ResourceBean( + resource.getUrl(), + resource.getName(), + resource.getDescription(), + null, + username, + datasetId, + null); - logger.warn("Running outside the portal"); + // get the scope in which we should discover the ckan instance given the organization name in which the dataset was created + String scope = getScopeFromOrgName(resource.getOrganizationNameDatasetParent()); + DataCatalogue catalogue = getCatalogue(scope); + String resourceId = catalogue.addResourceToDataset(resourceBean); + + if(resourceId != null){ + logger.info("Resource " + resource.getName() + " is now available"); + // set its id and turn it to the client + resource.setOriginalIdInWorkspace(resourceId); return resource; + } - }else{ - - ResourceBean resourceBean = new ResourceBean( - resource.getUrl(), - resource.getName(), - resource.getDescription(), - null, - username, - datasetId, - null); + logger.debug("No resource created"); + return null; + } + /** + * Delete resource from dataset. + * + * @param resource the resource + * @return true, if successful + * @throws Exception the exception + */ + @Override + public boolean deleteResourceFromDataset(ResourceElementBean resource) throws Exception{ + logger.debug("Request for deleting resource " + resource); + boolean deleted = false; + devModeSetContexts(); + try{ // get the scope in which we should discover the ckan instance given the organization name in which the dataset was created String scope = getScopeFromOrgName(resource.getOrganizationNameDatasetParent()); DataCatalogue catalogue = getCatalogue(scope); - String resourceId = catalogue.addResourceToDataset(resourceBean); - - if(resourceId != null){ - logger.debug("Resource " + resource.getName() + " is now available"); - // set its id and turn it to the client - resource.setOriginalIdInWorkspace(resourceId); - return resource; - } - - logger.debug("No resource created"); - return null; - } - } - - @Override - public boolean deleteResourceFromDataset(ResourceElementBean resource) throws Exception{ - - logger.debug("Request for deleting resource " + resource); - boolean deleted = false; - - if(!isWithinPortal()){ - logger.warn("Running outside the portal"); - return deleted; - }else{ - - try{ - // get the scope in which we should discover the ckan instance given the organization name in which the dataset was created - String scope = getScopeFromOrgName(resource.getOrganizationNameDatasetParent()); - DataCatalogue catalogue = getCatalogue(scope); - deleted = catalogue.deleteResourceFromDataset(resource.getOriginalIdInWorkspace()); - if(deleted){ - logger.info("Resource described by " + resource + " deleted"); - }else - logger.error("Resource described by " + resource + " NOT deleted"); - }catch(Exception e){ - logger.error("Error while trying to delete resource described by " + resource, e); - throw new Exception("Error while trying to delete resource." + e.getMessage()); - } - return deleted; + deleted = catalogue.deleteResourceFromDataset(resource.getOriginalIdInWorkspace()); + if(deleted){ + logger.info("Resource described by " + resource + " deleted"); + }else + logger.error("Resource described by " + resource + " NOT deleted"); + }catch(Exception e){ + logger.error("Error while trying to delete resource described by " + resource, e); + throw new Exception("Error while trying to delete resource." + e.getMessage()); } + return deleted; + } + /** + * Gets the profiles. + * + * @param orgName the org name + * @return the profiles + * @throws Exception the exception + */ @Override public List getProfiles(String orgName) throws Exception{ @@ -520,6 +590,14 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C return toReturn; } + /** + * Dataset id already exists. + * + * @param title the title + * @param orgName the org name + * @return true, if successful + * @throws Exception the exception + */ @Override public boolean datasetIdAlreadyExists(String title, String orgName) throws Exception{ if(title == null || title.isEmpty()) @@ -537,7 +615,10 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C /** * The method tries to retrieve the scope related to the organization using the map first, - * if no match is found, it retrieves such information by using liferay + * if no match is found, it retrieves such information by using liferay. + * + * @param orgName the org name + * @return the scope from org name */ private String getScopeFromOrgName(String orgName){ @@ -568,6 +649,12 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C return toReturn; } + /** + * Gets the user groups. + * + * @param orgName the org name + * @return the user groups + */ @Override public List getUserGroups(String orgName) { @@ -621,6 +708,13 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C } + /** + * Checks if is publisher user. + * + * @param isWorkspaceRequest the is workspace request + * @return true, if is publisher user + * @throws Exception the exception + */ @Override public boolean isPublisherUser(boolean isWorkspaceRequest) throws Exception{ @@ -689,6 +783,13 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C } } + /** + * Checks if is geo JSON valid. + * + * @param geoJson the geo json + * @return true, if is geo JSON valid + * @throws Exception the exception + */ @Override public boolean isGeoJSONValid(String geoJson) throws Exception { try{ diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/utils/WorkspaceUtils.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/utils/WorkspaceUtils.java index c9c4760..84fec73 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/utils/WorkspaceUtils.java +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/utils/WorkspaceUtils.java @@ -1,5 +1,6 @@ package org.gcube.portlets.widgets.ckandatapublisherwidget.server.utils; +import java.net.URL; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; @@ -8,24 +9,33 @@ import java.util.List; import java.util.Map; import java.util.Map.Entry; -import org.gcube.common.homelibary.model.items.type.FolderItemType; -import org.gcube.common.homelibrary.home.HomeLibrary; -import org.gcube.common.homelibrary.home.exceptions.InternalErrorException; -import org.gcube.common.homelibrary.home.workspace.Workspace; -import org.gcube.common.homelibrary.home.workspace.WorkspaceFolder; -import org.gcube.common.homelibrary.home.workspace.WorkspaceItem; -import org.gcube.common.homelibrary.home.workspace.catalogue.WorkspaceCatalogue; -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.datacatalogue.utillibrary.server.utils.CatalogueUtilMethods; +import javax.servlet.http.HttpServletRequest; + +import org.gcube.common.portal.PortalContext; +import org.gcube.common.storagehubwrapper.server.StorageHubWrapper; +import org.gcube.common.storagehubwrapper.server.tohl.Workspace; +import org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceItem; +import org.gcube.common.storagehubwrapper.shared.tohl.impl.URLFile; +import org.gcube.common.storagehubwrapper.shared.tohl.items.FileItem; +import org.gcube.common.storagehubwrapper.shared.tohl.items.GCubeItem; +import org.gcube.common.storagehubwrapper.shared.tohl.items.PropertyMap; import org.gcube.datacatalogue.utillibrary.shared.ResourceBean; import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.DatasetBean; import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.ResourceElementBean; +import org.gcube.vomanagement.usermanagement.model.GCubeUser; import com.liferay.portal.kernel.log.Log; import com.liferay.portal.kernel.log.LogFactoryUtil; +import com.liferay.portal.service.UserLocalServiceUtil; + +/** + * The Class WorkspaceUtils. + * + * @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it) + * + * Feb 18, 2021 + */ public class WorkspaceUtils { //private static final org.slf4j.Logger logger = LoggerFactory.getLogger(WorkspaceUtils.class); @@ -33,24 +43,75 @@ public class WorkspaceUtils { private static final String RESOURCES_NAME_SEPARATOR = "_"; private static final String STRIP_NOT_ALPHANUMERIC = "[^A-Za-z0-9.-_]"; + /** - * This method receives a folder id within the user's workspace and set the list of resources in the dataset bean to be returned - * @param folderId - * @param owner - * @param bean - * @param userName + * Checks if is within portal. + * + * @return true if you're running into the portal, false if in development + */ + public static boolean isWithinPortal() { + try { + UserLocalServiceUtil.getService(); + return true; + } catch (Exception ex) { + logger.trace("Development Mode ON"); + return false; + } + } + + /** + * Gets the storage hub wrapper. + * + * @param request + * the request + * @param scopeGroupId + * the scope group id. If scopeGroupId is null the scope is read + * by using the request else by using the scopeGroupId + * @param user + * the user + * @return the storage hub wrapper * @throws Exception + * the exception + */ + public static StorageHubWrapper getStorageHubWrapper(final HttpServletRequest request, String scopeGroupId, + GCubeUser user) throws Exception { + + if (user == null || user.getUsername().isEmpty()) + throw new Exception("Session expired"); + + try { + String scope; + PortalContext pContext = PortalContext.getConfiguration(); + if (isWithinPortal() && scopeGroupId != null) { + scope = pContext.getCurrentScope(scopeGroupId); + logger.debug(scope + " has retrieved by using the scopeGroupId=" + scopeGroupId); + } else + scope = pContext.getCurrentScope(request); + + logger.debug("Getting " + StorageHubWrapper.class.getSimpleName() + " for user: " + user.getUsername() + + " by using the scope: " + scope); + String token = pContext.getCurrentUserToken(scope, user.getUsername()); + return new StorageHubWrapper(scope, token, false, false, true); + } catch (Exception e) { + logger.error("Error during getting storageHub wrapper", e); + throw new Exception("Error on gettig the StorageHub wrapper for userId: " + user); + } + } + + /** + * This method receives a folder id within the user's workspace and set the list of resources in the dataset bean to be returned. + * + * @param folderId the folder id + * @param userName the user name + * @param bean the bean + * @param workspace the workspace + * @throws Exception the exception */ public static void handleWorkspaceResources(String folderId, String userName, - DatasetBean bean) throws Exception { + DatasetBean bean, Workspace workspace) throws Exception { - // get workspace - Workspace ws = HomeLibrary - .getHomeManagerFactory() - .getHomeManager() - .getHome().getWorkspace(); - WorkspaceItem originalFolderOrFile = ws.getItem(folderId); + WorkspaceItem originalFolderOrFile = workspace.getItem(folderId); logger.debug("Item retrieved is " + originalFolderOrFile); @@ -89,7 +150,7 @@ public class WorkspaceUtils { } // set them into the bean - bean.setResourceRoot(WorkspaceUtils.getTreeFromFolder(folderId, ws)); + bean.setResourceRoot(WorkspaceUtils.getTreeFromFolder(folderId, workspace)); } } @@ -104,35 +165,77 @@ public class WorkspaceUtils { if(item instanceof GCubeItem){ GCubeItem gItem = (GCubeItem) item; try { - if(gItem.getProperties()!=null){ - Map map = gItem.getProperties().getProperties(); - HashMap properties = new HashMap(map.size()); //TO PREVENT GWT SERIALIZATION ERROR - for (String key : map.keySet()) - properties.put(key, map.get(key)); + Map properties = null; + if(gItem.getPropertyMap()!=null){ + Map map = toSimpleMap(gItem.getPropertyMap()); + if(map!=null) { + properties = new HashMap(map.size()); //TO PREVENT GWT SERIALIZATION ERROR + for (String key : map.keySet()) + properties.put(key, map.get(key)); + } return properties; } - } catch (InternalErrorException e) { + } catch (Exception e) { logger.error("Error in server getItemProperties: ", e); } } return null; } + + /** + * To simple map. + * + * @param propertyMap the property map + * @return the map + */ + public static Map toSimpleMap(PropertyMap propertyMap) { + + if (propertyMap == null) + return null; + + try { + Map properties = null; + Map map = propertyMap.getValues(); + + if (map != null) { + properties = new HashMap(map.size()); + for (String key : map.keySet()) { + Object theValue = map.get(key); + properties.put(key, (String) theValue); + } + } + + if(properties!=null) + logger.error("Converted: "+properties.size()+" property/properties"); + + return properties; + } catch (Exception e) { + logger.error("Error on converting a PropertyMap to simple Map: ", e); + return null; + } + } + /** - * Returns a tree object - * @param workspaceFolderId - * @param ws + * Returns a tree object. + * + * @param workspaceFolderId the workspace folder id + * @param workspace the workspace * @return ResourceElementBean a tree object - * @throws Exception + * @throws Exception the exception */ - public static ResourceElementBean getTreeFromFolder(String workspaceFolderId, Workspace ws) throws Exception{ + public static ResourceElementBean getTreeFromFolder(String workspaceFolderId, Workspace workspace) throws Exception{ ResourceElementBean rootElem = new ResourceElementBean(); - String pathSeparator = ws.getPathSeparator(); - WorkspaceItem initialItem = ws.getItem(workspaceFolderId); + String pathSeparator = "/"; + + //String pathSeparator = ws.getPathSeparator(); + + + WorkspaceItem initialItem = workspace.getItem(workspaceFolderId); String fullPathBase = initialItem.getPath(); - fullPathBase = fullPathBase.endsWith(ws.getPathSeparator()) ? fullPathBase : fullPathBase + ws.getPathSeparator(); + fullPathBase = fullPathBase.endsWith(pathSeparator) ? fullPathBase : fullPathBase + pathSeparator; rootElem.setFolder(initialItem.isFolder()); rootElem.setFullPath(initialItem.getPath().replace(fullPathBase, "")); rootElem.setName(initialItem.getName()); @@ -142,20 +245,27 @@ public class WorkspaceUtils { // recursive visiting if(initialItem.isFolder()) - visit(rootElem, initialItem, fullPathBase, pathSeparator); + visit(rootElem, initialItem, workspace, fullPathBase, pathSeparator); logger.debug("Tree that is going to be returned is " + rootElem); return rootElem; } /** - * Recursive visit of a workspace item - * @param rootElem - * @param initialItemWS - * @throws InternalErrorException + * Recursive visit of a workspace item. + * + * @param parent the parent + * @param initialItemWS the initial item WS + * @param workspace the ws + * @param fullPathBase the full path base + * @param pathSeparator the path separator + * @throws Exception the exception */ - private static void visit(ResourceElementBean parent, WorkspaceItem initialItemWS, String fullPathBase, String pathSeparator) throws InternalErrorException { - List children = initialItemWS.getChildren(); + private static void visit(ResourceElementBean parent, WorkspaceItem initialItemWS, Workspace workspace, String fullPathBase, String pathSeparator) throws Exception { + //List children = initialItemWS.getChildren(); + + List children = workspace.getChildren(initialItemWS.getId()); + ArrayList childrenInTree = new ArrayList(children.size()); for (WorkspaceItem item : children) { // logger.debug("Path BEFORE REPLACE is " + item.getPath()); @@ -173,16 +283,17 @@ public class WorkspaceUtils { childrenInTree.add(elem); logger.trace("Elem is " + elem); if(item.isFolder()) - visit(elem, item, fullPathBase, pathSeparator); + visit(elem, item, workspace, fullPathBase, pathSeparator); } // add these list as child of the rootElem parent.setChildren(childrenInTree); } /** - * Replaces the "/" char with a custom one and return an editable name for the user - * @param rootElem - * @param pathSeparatorInWs + * Replaces the "/" char with a custom one and return an editable name for the user. + * + * @param rootElem the root elem + * @param pathSeparatorInWs the path separator in ws */ private static void extractEditableNameFromPath(ResourceElementBean rootElem, String pathSeparatorInWs) { @@ -198,47 +309,24 @@ public class WorkspaceUtils { fullPath = fullPath.replaceAll(pathSeparatorInWs, RESOURCES_NAME_SEPARATOR) + elemName; rootElem.setEditableName(fullPath); } - + + /** * Copy into the .catalogue area folder the checked resources. * There is no difference among a single-file-publish and a folder-publish. - * @param folderId - * @param userName - * @param bean - * @return + * + * @param bean the bean + * @param workspace the workspace + * @param username the username + * @return the list + * @throws Exception the exception */ - public static List copyResourcesToUserCatalogueArea(String folderOrFileId, String userName, DatasetBean bean) throws Exception{ + public static List toResources(DatasetBean bean, Workspace workspace, String username) throws Exception{ logger.debug("Request to copy onto catalogue area...."); List resources = new ArrayList(); - WorkspaceItem copiedFolder = null; - WorkspaceCatalogue userCatalogue = null; ResourceElementBean rootResource = bean.getResourceRoot(); - // into the .catalogue area of the user's workspace - Workspace ws = HomeLibrary - .getHomeManagerFactory() - .getHomeManager() - .getHome() - .getWorkspace(); - - // Retrieve the catalogue of the user - userCatalogue = ws.getCatalogue(); - - // get workspace item (it could be a file or a folder) - WorkspaceItem originalItem = ws.getItem(folderOrFileId); - - // copy the folder in the catalogue if it is a folder, or create a new folder - long referenceTime = System.currentTimeMillis(); - if(originalItem.isFolder()){ - copiedFolder = userCatalogue.addWorkspaceItem(folderOrFileId, userCatalogue.getId()); // add to .catalogue root area - copiedFolder.setDescription(bean.getDescription()); - ((WorkspaceFolder)copiedFolder).rename(CatalogueUtilMethods.fromProductTitleToName(bean.getTitle()) + "_" + referenceTime); - } - else{ - copiedFolder = userCatalogue.createFolder(CatalogueUtilMethods.fromProductTitleToName(bean.getTitle()) + "_" + referenceTime, bean.getDescription()); - } - // retrieve the children List resourcesToAdd = rootResource.getChildren(); @@ -250,35 +338,130 @@ public class WorkspaceUtils { logger.debug("Resource to add is " + resource); // ok it is a file, so copy it into the copiedFolder - WorkspaceItem copiedFile = userCatalogue.addWorkspaceItem(resource.getOriginalIdInWorkspace(), copiedFolder.getId()); + WorkspaceItem wsItem = workspace.getItem(resource.getOriginalIdInWorkspace()); + + String mimeType = null; + if(wsItem instanceof FileItem) { + mimeType = ((FileItem)wsItem).getMimeType(); + } - // name and description could have been edited - copiedFile.setDescription(resource.getDescription()); - - // check if it is an external url + // check if it is an URLFile String externalUrl = null; try{ - boolean isExternalUrl = ((FolderItem)copiedFile).getFolderItemType().equals(FolderItemType.EXTERNAL_URL); - externalUrl = isExternalUrl ? ((ExternalUrl)copiedFile).getUrl() : null; + if(wsItem instanceof URLFile) { + URLFile urlFile = (URLFile) wsItem; + externalUrl = urlFile.getValue()!=null?urlFile.getValue().toString():null; + } + }catch(Exception e){ logger.warn("Unable to check if it is an external url file ", e); } + + String resourceURL = externalUrl; + + //it is not a URLFile + if(resourceURL==null) { + //getting public link of file + URL publicLink = workspace.getPublicLinkForFile(resource.getOriginalIdInWorkspace()); + if(publicLink!=null) + resourceURL = publicLink.toString(); + } - resources.add(new ResourceBean( - externalUrl != null ? externalUrl : copiedFile.getPublicLink(true), + resources.add(new ResourceBean(resourceURL, resource.getEditableName(), - copiedFile.getDescription(), - copiedFile.getId(), - userName, + resource.getDescription(), + wsItem.getId(), + username, null, // dataset id, to be set - ((FolderItem)copiedFile).getMimeType())); - - // postpone rename operation - copiedFile.rename(resource.getEditableName()); + mimeType)); } } return resources; } + +// //MOVED TO GCAT +// /** +// * Copy into the .catalogue area folder the checked resources. +// * There is no difference among a single-file-publish and a folder-publish. +// * @param folderId +// * @param userName +// * @param bean +// * @return +// */ +// public static List copyResourcesToUserCatalogueArea(String folderOrFileId, String userName, DatasetBean bean) throws Exception{ +// +// logger.debug("Request to copy onto catalogue area...."); +// List resources = new ArrayList(); +// WorkspaceItem copiedFolder = null; +// WorkspaceCatalogue userCatalogue = null; +// ResourceElementBean rootResource = bean.getResourceRoot(); +// +// // into the .catalogue area of the user's workspace +// Workspace ws = HomeLibrary +// .getHomeManagerFactory() +// .getHomeManager() +// .getHome() +// .getWorkspace(); +// +// // Retrieve the catalogue of the user +// userCatalogue = ws.getCatalogue(); +// +// // get workspace item (it could be a file or a folder) +// WorkspaceItem originalItem = ws.getItem(folderOrFileId); +// +// // copy the folder in the catalogue if it is a folder, or create a new folder +// long referenceTime = System.currentTimeMillis(); +// if(originalItem.isFolder()){ +// copiedFolder = userCatalogue.addWorkspaceItem(folderOrFileId, userCatalogue.getId()); // add to .catalogue root area +// copiedFolder.setDescription(bean.getDescription()); +// ((WorkspaceFolder)copiedFolder).rename(CatalogueUtilMethods.fromProductTitleToName(bean.getTitle()) + "_" + referenceTime); +// } +// else{ +// copiedFolder = userCatalogue.createFolder(CatalogueUtilMethods.fromProductTitleToName(bean.getTitle()) + "_" + referenceTime, bean.getDescription()); +// } +// +// // retrieve the children +// List resourcesToAdd = rootResource.getChildren(); +// +// // copy only the selected ones +// for(ResourceElementBean resource : resourcesToAdd){ +// +// if (resource.isToBeAdded()) { +// +// logger.debug("Resource to add is " + resource); +// +// // ok it is a file, so copy it into the copiedFolder +// WorkspaceItem copiedFile = userCatalogue.addWorkspaceItem(resource.getOriginalIdInWorkspace(), copiedFolder.getId()); +// +// // name and description could have been edited +// copiedFile.setDescription(resource.getDescription()); +// +// // check if it is an external url +// String externalUrl = null; +// try{ +// boolean isExternalUrl = ((FolderItem)copiedFile).getFolderItemType().equals(FolderItemType.EXTERNAL_URL); +// externalUrl = isExternalUrl ? ((ExternalUrl)copiedFile).getUrl() : null; +// }catch(Exception e){ +// logger.warn("Unable to check if it is an external url file ", e); +// } +// +// resources.add(new ResourceBean( +// externalUrl != null ? externalUrl : copiedFile.getPublicLink(true), +// resource.getEditableName(), +// copiedFile.getDescription(), +// copiedFile.getId(), +// userName, +// null, // dataset id, to be set +// ((FolderItem)copiedFile).getMimeType())); +// +// // postpone rename operation +// copiedFile.rename(resource.getEditableName()); +// } +// +// } +// return resources; +// } + } \ No newline at end of file From 32b68f5f606763584b2bb18fca280c1f4bc26c2d Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Thu, 18 Feb 2021 14:57:13 +0100 Subject: [PATCH 10/44] removed commented code --- pom.xml | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/pom.xml b/pom.xml index 074fddc..1ff07df 100644 --- a/pom.xml +++ b/pom.xml @@ -129,25 +129,6 @@ compile - - - - - - - - - - - - - - - - - - - org.gcube.dvos usermanagement-core From 27e356be521e779af74814863308bef85ef822e1 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Tue, 23 Feb 2021 18:17:53 +0100 Subject: [PATCH 11/44] setting title instead of name --- .../server/utils/WorkspaceUtils.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/utils/WorkspaceUtils.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/utils/WorkspaceUtils.java index 84fec73..8b35843 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/utils/WorkspaceUtils.java +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/utils/WorkspaceUtils.java @@ -114,6 +114,11 @@ public class WorkspaceUtils { WorkspaceItem originalFolderOrFile = workspace.getItem(folderId); logger.debug("Item retrieved is " + originalFolderOrFile); + + String title = originalFolderOrFile.getTitle() != null && !originalFolderOrFile.getTitle().isEmpty() + ? originalFolderOrFile.getTitle() + : originalFolderOrFile.getName(); + title = title.replaceAll(STRIP_NOT_ALPHANUMERIC, " "); if(!originalFolderOrFile.isFolder()){ @@ -124,12 +129,12 @@ public class WorkspaceUtils { resource.setName(originalFolderOrFile.getName()); resource.setOriginalIdInWorkspace(folderId); bean.setResourceRoot(resource); - bean.setTitle(originalFolderOrFile.getName().replaceAll(STRIP_NOT_ALPHANUMERIC, " ")); + bean.setTitle(title); bean.setDescription(originalFolderOrFile.getDescription()); }else{ - String onlyAlphanumericTitle = originalFolderOrFile.getName().replaceAll(STRIP_NOT_ALPHANUMERIC, " "); + String onlyAlphanumericTitle = title; bean.setTitle(onlyAlphanumericTitle); bean.setDescription(originalFolderOrFile.getDescription()); @@ -308,6 +313,7 @@ public class WorkspaceUtils { fullPath = rootElem.getFullPath().substring(0, lastIndex); fullPath = fullPath.replaceAll(pathSeparatorInWs, RESOURCES_NAME_SEPARATOR) + elemName; rootElem.setEditableName(fullPath); + logger.info("Editable name for resource name: "+rootElem.getName()+", is: " + rootElem.getEditableName()); } From 8fd559b730968748117642c1a8993a0e70bd6758 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Thu, 25 Feb 2021 16:57:34 +0100 Subject: [PATCH 12/44] #19568 Unify and extend the tags allowed values #20828 Revisited title size and format --- CHANGELOG.md | 2 ++ .../client/ui/form/CreateDatasetForm.java | 12 +++++++++--- .../client/ui/tags/TagsPanel.java | 2 +- .../client/ui/utils/InfoIconsLabels.java | 4 ++-- 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index faf9dbc..de2e2f4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,8 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm [#19764] Porting ckan-metadata-publisher-widget to catalogue-util-library [#20680] Ported to SHUB +[#19568] Unify and extend the tags allowed values +[#20828] Revisited title size and format ## [v1.6.2] - 2021-02-08 diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/form/CreateDatasetForm.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/form/CreateDatasetForm.java index f0b625a..0112ebf 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/form/CreateDatasetForm.java +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/form/CreateDatasetForm.java @@ -167,7 +167,7 @@ public class CreateDatasetForm extends Composite{ // Create a remote service proxy to talk to the server-side ckan service. private final CKanPublisherServiceAsync ckanServices = GWT.create(CKanPublisherService.class); - private static final String REGEX_TITLE_PRODUCT_SUBWORD = "[^a-zA-Z0-9_.-]"; + //private static final String REGEX_TITLE_PRODUCT_SUBWORD = "[^a-zA-Z0-9_.-]"; private static final String REGEX_MAIL = "\\b[\\w.%-]+@[-.\\w]+\\.[A-Za-z]{2,4}\\b"; private static final String NONE_PROFILE = "none"; @@ -1381,17 +1381,23 @@ public class CreateDatasetForm extends Composite{ productTitleGroup.setType(ControlGroupType.ERROR); return "Missing title"; } + + if(title.length()<2) { + productTitleGroup.setType(ControlGroupType.ERROR); + return "The field title is too short"; + } // better check for the title - String[] splittedTitle = title.split(" "); + //String[] splittedTitle = title.split(" "); + /* No check, see #20828 for (String word : splittedTitle) { String replaced = word.replaceAll(REGEX_TITLE_PRODUCT_SUBWORD, ""); if(!replaced.equals(word)){ productTitleGroup.setType(ControlGroupType.ERROR); return "Please note not all characters are allowed for the title"; } - } + }*/ // email reg expression String maintainerMail = maintainerEmailTextbox.getText(); diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/tags/TagsPanel.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/tags/TagsPanel.java index 2473a5f..8fcc5ec 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/tags/TagsPanel.java +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/tags/TagsPanel.java @@ -48,7 +48,7 @@ public class TagsPanel extends Composite{ @UiField ListBox tagsEnterListBox; // regular expression for tags - private static final String REGEX_TAG = "^[a-zA-Z0-9]*$"; + private static final String REGEX_TAG = "^[a-zA-Z0-9._-]*$"; // tags list private List tagsList = new ArrayList(); diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/utils/InfoIconsLabels.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/utils/InfoIconsLabels.java index b26c2a4..09e3787 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/utils/InfoIconsLabels.java +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/utils/InfoIconsLabels.java @@ -26,7 +26,7 @@ public class InfoIconsLabels { public static final String TAGS_INFO_ID_POPUP = "tags-popup-panel-info"; public static final String TAGS_INFO_CAPTION = "Tags"; public static final String TAGS_INFO_TEXT = "Tags are meaningful information that can be associated to the " - + "item and by means of them it can be retrieved. A tag can contain only alphanumeric characters. " + + "item and by means of them it can be retrieved. A tag can contain only alphanumeric characters or symbols . (dot) - (hyphen minus) _ (underscore)." + "If the tag is composed by a single word it must have a size of at least two characters." + "Examples of good tags: \"This is a sample tag\", \"tagY\". Example of bad tag: \"c\"." + " You must push ENTER for attaching a tag, or use the provided list of predefined tags. In the latter case" @@ -80,7 +80,7 @@ public class InfoIconsLabels { // TITLE public static final String TITLE_INFO_ID_POPUP = "title-popup-panel-info"; - public static final String TITLE_INFO_TEXT = "Item Title must contain only alphanumer characters, dots, underscore or hyphen minus. No others symbols are allowed. Please note that this field will be always visible, despite the item's visibility."; + public static final String TITLE_INFO_TEXT = "The title of the item. Please note that this field will be always visible, despite the item's visibility."; public static final String TITLE_INFO_CAPTION = "Item Title"; // DESCRIPTION From 277aedb975a0ee4e234ace0e00c54ee5fde39677 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Tue, 2 Mar 2021 14:42:10 +0100 Subject: [PATCH 13/44] aligned with the new method 'addResourceToDataset(ResourceBean resourceBean, String organizationName, String username)' --- .../server/CKANPublisherServicesImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/CKANPublisherServicesImpl.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/CKANPublisherServicesImpl.java index 5b24a85..59a3f60 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/CKANPublisherServicesImpl.java +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/CKANPublisherServicesImpl.java @@ -524,7 +524,7 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C // get the scope in which we should discover the ckan instance given the organization name in which the dataset was created String scope = getScopeFromOrgName(resource.getOrganizationNameDatasetParent()); DataCatalogue catalogue = getCatalogue(scope); - String resourceId = catalogue.addResourceToDataset(resourceBean); + String resourceId = catalogue.addResourceToDataset(resourceBean, resource.getOrganizationNameDatasetParent(), username); if(resourceId != null){ logger.info("Resource " + resource.getName() + " is now available"); From bfd9e0184133c67d54057d5149574a60b6f752e1 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Tue, 2 Mar 2021 15:09:52 +0100 Subject: [PATCH 14/44] done #20801 --- .../server/CKANPublisherServicesImpl.java | 14 ++++++++------ .../server/utils/GenericUtils.java | 11 ++++++++--- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/CKANPublisherServicesImpl.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/CKANPublisherServicesImpl.java index 59a3f60..4d1674c 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/CKANPublisherServicesImpl.java +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/CKANPublisherServicesImpl.java @@ -615,10 +615,7 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C /** * The method tries to retrieve the scope related to the organization using the map first, - * if no match is found, it retrieves such information by using liferay. - * - * @param orgName the org name - * @return the scope from org name + * if no match is found, it retrieves such information by using liferay */ private String getScopeFromOrgName(String orgName){ @@ -629,11 +626,16 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C String toReturn = null; if(isWithinPortal()){ - if(mapOrganizationScope.containsKey(orgName)) + if(mapOrganizationScope.containsKey(orgName)) { toReturn = mapOrganizationScope.get(orgName); - else{ + }else{ try{ String evaluatedScope = GenericUtils.retrieveScopeFromOrganizationName(orgName); + //see #20801 + if(evaluatedScope==null || evaluatedScope.isEmpty()) { + logger.warn("Scope detected for OrganizationName: "+orgName+" is null or empty, skipping filling 'mapOrganizationScope' and returning null"); + return toReturn; + } mapOrganizationScope.put(orgName, evaluatedScope); toReturn = evaluatedScope; }catch(Exception e){ diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/utils/GenericUtils.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/utils/GenericUtils.java index 4f80440..9e8cb19 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/utils/GenericUtils.java +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/utils/GenericUtils.java @@ -52,13 +52,18 @@ public class GenericUtils { GroupManager gm = new LiferayGroupManager(); List groups = gm.listGroups(); for (GCubeGroup gCubeGroup : groups) { - if(gCubeGroup.getGroupName().equalsIgnoreCase(organizationName)) - return gm.getInfrastructureScope(gCubeGroup.getGroupId()); + if(gCubeGroup.getGroupName().equalsIgnoreCase(organizationName)) { + String theScope = gm.getInfrastructureScope(gCubeGroup.getGroupId()); + logger.info("For organizationName: " + organizationName+" by using "+LiferayGroupManager.class.getSimpleName()+ " got the scope: "+theScope +", returning it"); + return theScope; + } } - + + logger.info("No scope detected for organizationName: " + organizationName +" by using "+LiferayGroupManager.class.getSimpleName()); return null; } + /** * First check to retrieve the token, else create it. * From 07e66d5dedf5fc1a0dc695f5435100fee42c8117 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Tue, 2 Mar 2021 16:02:51 +0100 Subject: [PATCH 15/44] aligned with 'deleteResourceFromDataset(String resourceId, String username)' --- .../server/CKANPublisherServicesImpl.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/CKANPublisherServicesImpl.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/CKANPublisherServicesImpl.java index 4d1674c..df034cc 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/CKANPublisherServicesImpl.java +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/CKANPublisherServicesImpl.java @@ -553,7 +553,8 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C // get the scope in which we should discover the ckan instance given the organization name in which the dataset was created String scope = getScopeFromOrgName(resource.getOrganizationNameDatasetParent()); DataCatalogue catalogue = getCatalogue(scope); - deleted = catalogue.deleteResourceFromDataset(resource.getOriginalIdInWorkspace()); + String username = GenericUtils.getCurrentUser(getThreadLocalRequest()).getUsername(); + deleted = catalogue.deleteResourceFromDataset(resource.getOriginalIdInWorkspace(),username); if(deleted){ logger.info("Resource described by " + resource + " deleted"); }else @@ -619,7 +620,7 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C */ private String getScopeFromOrgName(String orgName){ - logger.debug("Request for scope related to orgName " + orgName + "[ map that will be used is " + mapOrganizationScope.toString() + " ]"); + logger.info("Request for scope related to orgName " + orgName + " [map that will be used is " + mapOrganizationScope.toString() + "]"); if(orgName == null || orgName.isEmpty()) throw new IllegalArgumentException("orgName cannot be empty or null!"); @@ -647,7 +648,7 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C toReturn = GenericUtils.getCurrentContext(this.getThreadLocalRequest(), false); mapOrganizationScope.put(orgName, toReturn); } - logger.debug("Returning scope " + toReturn); + logger.info("Returning scope " + toReturn); return toReturn; } From beddee26b53aa2b883fd2987b7bd21a635a6b1ac Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Tue, 2 Mar 2021 18:29:26 +0100 Subject: [PATCH 16/44] added JUnit Test Case --- .classpath | 11 +- .settings/org.eclipse.wst.common.component | 1 + .../TestPublishingWidget.java | 107 ++++++++++++++++++ src/test/resources/.gitignore | 3 + 4 files changed, 114 insertions(+), 8 deletions(-) create mode 100644 src/test/java/org/gcube/portlets/widgets/ckandatapublisherwidget/TestPublishingWidget.java create mode 100644 src/test/resources/.gitignore diff --git a/.classpath b/.classpath index ce7b7f2..510cf3c 100644 --- a/.classpath +++ b/.classpath @@ -6,13 +6,7 @@ - - - - - - - + @@ -25,8 +19,8 @@ - + @@ -34,5 +28,6 @@ + diff --git a/.settings/org.eclipse.wst.common.component b/.settings/org.eclipse.wst.common.component index 0190c48..5c79e39 100644 --- a/.settings/org.eclipse.wst.common.component +++ b/.settings/org.eclipse.wst.common.component @@ -5,6 +5,7 @@ + diff --git a/src/test/java/org/gcube/portlets/widgets/ckandatapublisherwidget/TestPublishingWidget.java b/src/test/java/org/gcube/portlets/widgets/ckandatapublisherwidget/TestPublishingWidget.java new file mode 100644 index 0000000..6b26f4a --- /dev/null +++ b/src/test/java/org/gcube/portlets/widgets/ckandatapublisherwidget/TestPublishingWidget.java @@ -0,0 +1,107 @@ +package org.gcube.portlets.widgets.ckandatapublisherwidget; + + +import java.util.Arrays; +import java.util.Calendar; + +import org.gcube.common.scope.api.ScopeProvider; +import org.gcube.common.storagehubwrapper.server.StorageHubWrapper; +import org.gcube.datacatalogue.utillibrary.server.DataCatalogueFactory; +import org.gcube.portlets.widgets.ckandatapublisherwidget.server.utils.WorkspaceUtils; +import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.DatasetBean; +import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.OrganizationBean; +import org.junit.Test; +import org.slf4j.LoggerFactory; + + + +/** + * The Class TestDataCatalogueLib. + * + * @author Francesco Mangiacrapa at ISTI-CNR Pisa (Italy) + * Jun 1, 2020 + */ +public class TestPublishingWidget { + + private static final org.slf4j.Logger LOG = LoggerFactory.getLogger(TestPublishingWidget.class); + + private String scope = "/gcube"; + //private String testUser = "costantino_perciante"; + private String testUser = "francesco.mangiacrapa"; + private String authorizationToken = ""; + + /** + * Before. + * + * @throws Exception the exception + */ + //@Before + public void before() throws Exception{ + } + + /** + * Factory test. + * + * @throws Exception the exception + */ + //@Test + public void factoryTest() throws Exception{ + + DataCatalogueFactory factory = DataCatalogueFactory.getFactory(); + + while(true){ + factory.getUtilsPerScope(scope); + Thread.sleep(60* 1000 * 3); + factory.getUtilsPerScope(scope); + break; + } + + for (int i = 0; i < 5; i++) { + Thread.sleep(1000); + factory.getUtilsPerScope(scope); + } + + } + + @Test + public void getDatasetBeanTest() throws Exception{ + ScopeProvider.instance.set(scope); + String userName = testUser; + String token = authorizationToken; + + String folderId = "6399daa7-2173-4314-b4f7-2afa24eae8f8"; + DatasetBean bean; + try{ + bean = new DatasetBean(); + bean.setId(folderId); + bean.setDescription("This is a fantastic description"); + bean.setVersion(1); + String onlyAlphanumeric = "test-creation-blablabla".replaceAll("[^A-Za-z0-9]", ""); + bean.setTitle(onlyAlphanumeric + Calendar.getInstance().getTimeInMillis()); + bean.setAuthorName("Francesco"); + bean.setAuthorSurname("Mangiacrapa"); + bean.setAuthorEmail("francesco.mangiacrapa@isti.cnr.it"); + bean.setMaintainer("Francesco Mangiacrapa"); + bean.setMaintainerEmail("francesco.mangiacrapa@isti.cnr.it"); + + //UPDATED By Francesco + String vreName = scope.substring(scope.lastIndexOf("/")+1,scope.length()); + LOG.debug("In dev mode using the scope: "+scope+" and VRE name: "+vreName); + bean.setOrganizationList(Arrays.asList(new OrganizationBean(vreName, vreName.toLowerCase(), true))); + + bean.setOwnerIdentifier(userName); + + if(folderId != null && !folderId.isEmpty()){ + StorageHubWrapper storageHubWrapper = new StorageHubWrapper(scope, token, false, false, true); + WorkspaceUtils.handleWorkspaceResources(folderId, userName, bean, storageHubWrapper.getWorkspace()); + } + }catch(Exception e){ + LOG.error("Error while building bean into dev mode", e); + throw new Exception("Error while retrieving basic information " + e.getMessage()); + } + + LOG.info("Got dataset: "+bean); + } + + +} diff --git a/src/test/resources/.gitignore b/src/test/resources/.gitignore new file mode 100644 index 0000000..abcb271 --- /dev/null +++ b/src/test/resources/.gitignore @@ -0,0 +1,3 @@ +/devsec.gcubekey +/gcube.gcubekey +/log4j.properties From d2846cd9f45852f3f14a30b754ea2cac4efe06e0 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Fri, 5 Mar 2021 17:58:56 +0100 Subject: [PATCH 17/44] integrating with Workspace Explorer and updating Manage Resources --- pom.xml | 9 +- .../CKanMetadataPublisher.gwt.xml | 19 +- .../client/CKanMetadataPublisher.java | 32 +- .../TwinColumnSelectionMainPanel.java | 22 +- .../client/ui/form/CreateDatasetForm.java | 27 +- .../SelectResourceByWEMainPanel.java | 192 ++++++++++++ .../SelectResourceByWEMainPanel.ui.xml | 26 ++ .../ui/workspace/SelectResourceWidget.java | 45 +++ .../ui/workspace/SelectResourceWidget.ui.xml | 17 ++ .../server/CKANPublisherServicesImpl.java | 4 +- .../server/utils/WorkspaceUtils.java | 247 +++++++-------- .../shared/ResourceElementBean.java | 287 +++++++++++++++--- .../CKanMetadataPublisher.gwt.xml | 19 +- .../TestPublishingWidget.java | 2 +- 14 files changed, 729 insertions(+), 219 deletions(-) create mode 100644 src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/SelectResourceByWEMainPanel.java create mode 100644 src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/SelectResourceByWEMainPanel.ui.xml create mode 100644 src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/SelectResourceWidget.java create mode 100644 src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/SelectResourceWidget.ui.xml diff --git a/pom.xml b/pom.xml index 1ff07df..1f21d3d 100644 --- a/pom.xml +++ b/pom.xml @@ -121,14 +121,14 @@ [2.0.0, 3.0.0-SNAPSHOT) provided - + org.gcube.common storagehub-client-wrapper [1.0.0, 2.0.0-SNAPSHOT) compile - + org.gcube.dvos usermanagement-core @@ -149,6 +149,11 @@ provided + + org.gcube.portlets.widgets + workspace-explorer + [2.0.0, 3.0.0-SNAPSHOT) + org.gcube.portlets.user gcube-widgets diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/CKanMetadataPublisher.gwt.xml b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/CKanMetadataPublisher.gwt.xml index 97d480b..7322fbe 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/CKanMetadataPublisher.gwt.xml +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/CKanMetadataPublisher.gwt.xml @@ -6,17 +6,24 @@ - - + + - - - - + + + + + + diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/CKanMetadataPublisher.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/CKanMetadataPublisher.java index 2a693fd..0a064ce 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/CKanMetadataPublisher.java +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/CKanMetadataPublisher.java @@ -4,9 +4,9 @@ import java.util.ArrayList; import java.util.List; import org.gcube.portlets.widgets.ckandatapublisherwidget.client.openlayerwidget.GeoJsonAreaSelectionDialog; -import org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.TwinColumnSelection.TwinColumnSelectionMainPanel; import org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.form.CreateDatasetForm; import org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.metadata.MetaDataFieldSkeleton; +import org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.workspace.SelectResourceByWEMainPanel; import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.ResourceElementBean; import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.metadata.DataTypeWrapper; import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.metadata.MetadataFieldWrapper; @@ -51,6 +51,8 @@ public class CKanMetadataPublisher implements EntryPoint { // startTwinColumn(); //testSpatialWidget(); + + testManageResources(); } @@ -256,9 +258,7 @@ public class CKanMetadataPublisher implements EntryPoint { // test resources @SuppressWarnings("unused") - private void startTwinColumn() { - - TwinColumnSelectionMainPanel resourcesTwinPanel; + private void testManageResources() { Modal m = new Modal(); m.setTitle("Title ......"); @@ -268,26 +268,14 @@ public class CKanMetadataPublisher implements EntryPoint { r.setFolder(true); r.setName("Root"); r.setParent(null); + r.setChildrenSize(5); + r.setOriginalIdInWorkspace("4ab50488-67d7-4664-9a0f-88a1de043399"); + List children = new ArrayList(); + + SelectResourceByWEMainPanel resourcesSelectByWEMainPanel = new SelectResourceByWEMainPanel(r); - // random strings - for (int i = 0; i < 10; i++) { - - ResourceElementBean child = new ResourceElementBean(); - child.setFolder(false); - child.setName("BLUE_ECONOMY_WP6_TECHNO_ECONOMIC_ANALYSIS_MODEL.CITE.PPTX" + i); - child.setEditableName("BLUE_ECONOMY_WP6_TECHNO_ECONOMIC_ANALYSIS_MODEL.CITE.PPTX" + i); - child.setParent(r); - child.setFullPath("/" + "BLUE_ECONOMY_WP6_TECHNO_ECONOMIC_ANALYSIS_MODEL.CITE.PPTX" + + i); - children.add(child); - - } - - r.setChildren(children); - - // create random childs - resourcesTwinPanel = new TwinColumnSelectionMainPanel(r); - m.add(resourcesTwinPanel); + m.add(resourcesSelectByWEMainPanel); m.show(); } diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/TwinColumnSelection/TwinColumnSelectionMainPanel.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/TwinColumnSelection/TwinColumnSelectionMainPanel.java index 67b3d9c..909f0cc 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/TwinColumnSelection/TwinColumnSelectionMainPanel.java +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/TwinColumnSelection/TwinColumnSelectionMainPanel.java @@ -153,8 +153,8 @@ public class TwinColumnSelectionMainPanel extends Composite{ cellListLeft.setKeyboardPagingPolicy(KeyboardPagingPolicy.INCREASE_RANGE); // set page size - int size = initialBean.isFolder() ? initialBean.getChildren().size() : 1; - cellListLeft.setPageSize(size); + //int size = initialBean.isFolder() ? initialBean.getChildren().size() : 1; + cellListLeft.setPageSize(0); // Add a selection model so we can select cells. selectionModelLeft = new MultiSelectionModel(ResourceElementBean.KEY_PROVIDER); @@ -191,8 +191,8 @@ public class TwinColumnSelectionMainPanel extends Composite{ GWT.log("Clicked on element " + pathBean.resourceFolder.getName()); //breadcrumbsUpdater(); ResourceElementBean folder = pathBean.resourceFolder; - Collections.sort(folder.getChildren()); - dataProviderLeft.setList(folder.getChildren()); + /*Collections.sort(folder.getChildren()); + dataProviderLeft.setList(folder.getChildren());*/ dataProviderLeft.refresh(); } @@ -202,10 +202,10 @@ public class TwinColumnSelectionMainPanel extends Composite{ breadcrumbs.add(navElem); //breadcrumbsUpdater(); - Collections.sort(selectedBean.getChildren()); + /*Collections.sort(selectedBean.getChildren()); GWT.log("Children " + selectedBean.getChildren()); dataProviderLeft.setList(selectedBean.getChildren()); - cellListLeft.setPageSize(selectedBean.getChildren().size()); + cellListLeft.setPageSize(selectedBean.getChildren().size());*/ dataProviderLeft.refresh(); } selectionModelLeft.setSelected(selectedBean, false); @@ -218,8 +218,8 @@ public class TwinColumnSelectionMainPanel extends Composite{ // set the list into the provider if(initialBean.isFolder()){ - Collections.sort(this.initialBean.getChildren()); - dataProviderLeft.setList(this.initialBean.getChildren()); + /*Collections.sort(this.initialBean.getChildren()); + dataProviderLeft.setList(this.initialBean.getChildren());*/ }else dataProviderLeft.setList(Arrays.asList(this.initialBean)); @@ -239,8 +239,8 @@ public class TwinColumnSelectionMainPanel extends Composite{ //breadcrumbsUpdater(); // set back the root content list - dataProviderLeft.setList(initialBean.getChildren()); - cellListLeft.setPageSize(initialBean.getChildren().size()); + /*dataProviderLeft.setList(initialBean.getChildren()); + cellListLeft.setPageSize(initialBean.getChildren().size());*/ dataProviderLeft.refresh(); } @@ -511,7 +511,7 @@ public class TwinColumnSelectionMainPanel extends Composite{ } } - toReturn.setChildren(children); + /*toReturn.setChildren(children);*/ return toReturn; } diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/form/CreateDatasetForm.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/form/CreateDatasetForm.java index 0112ebf..b93f95f 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/form/CreateDatasetForm.java +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/form/CreateDatasetForm.java @@ -15,7 +15,6 @@ import org.gcube.portlets.widgets.ckandatapublisherwidget.client.events.CloseCre import org.gcube.portlets.widgets.ckandatapublisherwidget.client.events.CloseCreationFormEventHandler; import org.gcube.portlets.widgets.ckandatapublisherwidget.client.events.DeleteCustomFieldEvent; import org.gcube.portlets.widgets.ckandatapublisherwidget.client.events.DeleteCustomFieldEventHandler; -import org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.TwinColumnSelection.TwinColumnSelectionMainPanel; import org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.metadata.CategoryPanel; import org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.metadata.CustomFieldEntry; import org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.metadata.MetaDataFieldSkeleton; @@ -24,6 +23,7 @@ import org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.resources.Ad import org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.resources.AddedResourcesSummary; import org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.tags.TagsPanel; import org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.utils.InfoIconsLabels; +import org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.workspace.SelectResourceByWEMainPanel; import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.DatasetBean; import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.OrganizationBean; import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.licenses.LicenseBean; @@ -205,7 +205,10 @@ public class CreateDatasetForm extends Composite{ private boolean isWorkspaceRequest = false; // resource table - private TwinColumnSelectionMainPanel resourcesTwinPanel; + //private TwinColumnSelectionMainPanel resourcesTwinPanel; + + // resource table + private SelectResourceByWEMainPanel resourcesSelectByWEMainPanel; // List of opened popup'ids private List popupOpenedIds = new ArrayList(); @@ -361,7 +364,8 @@ public class CreateDatasetForm extends Composite{ alertNoResources.setType(AlertType.WARNING); alertNoResources.setVisible(true); }else - resourcesTwinPanel = new TwinColumnSelectionMainPanel(bean.getResourceRoot()); + //resourcesSelectByWEMainPanel = new TwinColumnSelectionMainPanel(bean.getResourceRoot()); + resourcesSelectByWEMainPanel = new SelectResourceByWEMainPanel(bean.getResourceRoot()); } // set organizations @@ -856,7 +860,7 @@ public class CreateDatasetForm extends Composite{ // add the resources to the container panel if(workspaceResourcesContainer.getWidget() == null){ workspaceResourcesContainer.getElement().getStyle().setMarginLeft(20, Unit.PX); - workspaceResourcesContainer.add(resourcesTwinPanel); + workspaceResourcesContainer.add(resourcesSelectByWEMainPanel); } }else{ @@ -1022,8 +1026,11 @@ public class CreateDatasetForm extends Composite{ receivedBean.setSelectedOrganization(chosenOrganization); receivedBean.setGroups(groups); receivedBean.setGroupsForceCreation(groupsToForceCreation); - if(resourcesTwinPanel != null) - receivedBean.setResourceRoot(resourcesTwinPanel.getResourcesToPublish()); + + + if(resourcesSelectByWEMainPanel != null) + receivedBean.setResourceRoot(resourcesSelectByWEMainPanel.getResourcesToPublish()); + receivedBean.setCustomFields(customFieldsMap); // alert @@ -1496,8 +1503,8 @@ public class CreateDatasetForm extends Composite{ } // freeze table of resources - if(resourcesTwinPanel != null) - resourcesTwinPanel.freeze(); + if(resourcesSelectByWEMainPanel != null) + resourcesSelectByWEMainPanel.freeze(); } /** @@ -1574,8 +1581,8 @@ public class CreateDatasetForm extends Composite{ */ private boolean hideManageResources(){ - return receivedBean.getResourceRoot() == null || receivedBean.getResourceRoot().isFolder() && (receivedBean.getResourceRoot().getChildren() == null || - receivedBean.getResourceRoot().getChildren().isEmpty()); + return receivedBean.getResourceRoot() == null || receivedBean.getResourceRoot().isFolder() && (receivedBean.getResourceRoot().getChildrenSize() == null || + receivedBean.getResourceRoot().getChildrenSize()==0); } } \ No newline at end of file diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/SelectResourceByWEMainPanel.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/SelectResourceByWEMainPanel.java new file mode 100644 index 0000000..5aa1f89 --- /dev/null +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/SelectResourceByWEMainPanel.java @@ -0,0 +1,192 @@ +package org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.workspace; + +import java.util.HashMap; +import java.util.Map; + +import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.ResourceElementBean; +import org.gcube.portlets.widgets.wsexplorer.client.explore.WorkspaceResourcesBExplorerPanel; +import org.gcube.portlets.widgets.wsexplorer.client.explore.WorkspaceResourcesExplorerPanel; +import org.gcube.portlets.widgets.wsexplorer.client.notification.WorkspaceExplorerSelectBNotification.WorskpaceExplorerSelectBNotificationListener; +import org.gcube.portlets.widgets.wsexplorer.client.view.grid.ItemsTable.DISPLAY_FIELD; +import org.gcube.portlets.widgets.wsexplorer.shared.Item; + +import com.github.gwtbootstrap.client.ui.Button; +import com.google.gwt.core.client.GWT; +import com.google.gwt.event.dom.client.ClickEvent; +import com.google.gwt.event.dom.client.ClickHandler; +import com.google.gwt.uibinder.client.UiBinder; +import com.google.gwt.uibinder.client.UiField; +import com.google.gwt.user.client.Window; +import com.google.gwt.user.client.ui.Composite; +import com.google.gwt.user.client.ui.VerticalPanel; +import com.google.gwt.user.client.ui.Widget; + +/** + * The Class SelectResourceByWEMainPanel. + * + * @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it) + * + * Mar 5, 2021 + */ +public class SelectResourceByWEMainPanel extends Composite { + + /** The ui binder. */ + private static SelectResourceByWEMainPanelUiBinder uiBinder = GWT.create(SelectResourceByWEMainPanelUiBinder.class); + + private static boolean frozen = false; + private final ResourceElementBean initialBean; + + @UiField + VerticalPanel wsContainer; + @UiField + VerticalPanel selectResourcesContainer; + + @UiField + Button buttSelectResource; + + private Item selectedWEItem; + + Map mapSelectedResources = new HashMap(); + + /** + * The Interface SelectResourceByWEMainPanelUiBinder. + * + * @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it) + * + * Mar 5, 2021 + */ + interface SelectResourceByWEMainPanelUiBinder extends UiBinder { + } + + /** + * Instantiates a new select resource by WE main panel. + */ + public SelectResourceByWEMainPanel(ResourceElementBean initialBean) { + initWidget(uiBinder.createAndBindUi(this)); + + this.frozen = false; + + this.initialBean = initialBean; + + WorkspaceResourcesExplorerPanel rp = null; + + DISPLAY_FIELD[] displayFields = new DISPLAY_FIELD[] { DISPLAY_FIELD.ICON, DISPLAY_FIELD.NAME, + DISPLAY_FIELD.OWNER }; + + try { + String wsRootId = initialBean.isFolder() ? initialBean.getOriginalIdInWorkspace() + : initialBean.getParent().getOriginalIdInWorkspace(); + // WorkspaceResourcesBExplorerPanel(String folderId, boolean showOnlyFolders, + // List showProperties, FilterCriteria filter, boolean showGcubeInfo, + // DISPLAY_FIELD sortByColumn) throws Exception { + WorkspaceResourcesBExplorerPanel workspaceExplorerPanel = new WorkspaceResourcesBExplorerPanel(wsRootId, + false); + WorskpaceExplorerSelectBNotificationListener wsResourceExplorerListener = new WorskpaceExplorerSelectBNotificationListener() { + + + + @Override + public void onSelectedItem(Item item) { + GWT.log("Listener Selected Item " + item); + selectedWEItem = item; + } + + @Override + public void onFailed(Throwable throwable) { + // Log.error(throwable.getLocalizedMessage()); + throwable.printStackTrace(); + } + + + @Override + public void onAborted() { + + } + + @Override + public void onNotValidSelection() { + selectedWEItem = null; + } + + @Override + public void onBreadcrumbChanged(Item item) { + GWT.log("Breadcrumb Changed: " + item); + + } + }; + + workspaceExplorerPanel.addWorkspaceExplorerSelectNotificationListener(wsResourceExplorerListener); + wsContainer.add(workspaceExplorerPanel); + + } catch (Exception e) { + e.printStackTrace(); + } + + if(!initialBean.isFolder()) { + addSelectResource(initialBean.getOriginalIdInWorkspace(), initialBean.getName(),initialBean.getFullPath()); + } + + + buttSelectResource.addClickHandler(new ClickHandler() { + + @Override + public void onClick(ClickEvent event) { + if(selectedWEItem!=null) { + addSelectResource(selectedWEItem.getId(), selectedWEItem.getName(), selectedWEItem.getPath()); + } + + } + }); + + } + + public void addSelectResource(String wsItemId, String name, String path) { + + SelectResourceWidget selWidg = mapSelectedResources.get(wsItemId); + if (selWidg != null) { + Window.alert("Item '" + name + "' already selected"); + return; + } + + ResourceElementBean rb = new ResourceElementBean(); + rb.setOriginalIdInWorkspace(wsItemId); + rb.setName(name); + rb.setFullPath(path); + rb.setEditableName(name); + selWidg = new SelectResourceWidget(rb); + + mapSelectedResources.put(wsItemId, selWidg); + + selectResourcesContainer.add(selWidg); + + } + + public ResourceElementBean getResourcesToPublish() { + // TODO Auto-generated method stub + Window.alert("getResourcesToPublish() must be implemented"); + + /*List current = dataProviderRight.getList(); + + ResourceElementBean toReturn = new ResourceElementBean(); + List children = new ArrayList(); + + for (ResourceElementBean resource : current) { + if(resource.isToBeAdded() && !resource.isFolder()){ // be sure ... + ResourceElementBean beanWithoutChildren = new ResourceElementBean(resource); + beanWithoutChildren.setName(resource.getEditableName()); + children.add(beanWithoutChildren); + } + } + + toReturn.setToPublish(children); + return toReturn;*/ + return null; + + } + + public void freeze() { + // TODO Auto-generated method stub + Window.alert("freeze() must be implemented"); + } + +} diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/SelectResourceByWEMainPanel.ui.xml b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/SelectResourceByWEMainPanel.ui.xml new file mode 100644 index 0000000..e3cc515 --- /dev/null +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/SelectResourceByWEMainPanel.ui.xml @@ -0,0 +1,26 @@ + + + + .important { + font-weight: bold; + } + + + + + + + + Select Resource + + + + + Selected + + + + \ No newline at end of file diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/SelectResourceWidget.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/SelectResourceWidget.java new file mode 100644 index 0000000..526715e --- /dev/null +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/SelectResourceWidget.java @@ -0,0 +1,45 @@ +package org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.workspace; + +import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.ResourceElementBean; + +import com.github.gwtbootstrap.client.ui.Button; +import com.google.gwt.core.client.GWT; +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.Label; +import com.google.gwt.user.client.ui.Widget; + +public class SelectResourceWidget extends Composite { + + private static SelectResourceWidgetUiBinder uiBinder = GWT.create(SelectResourceWidgetUiBinder.class); + + interface SelectResourceWidgetUiBinder extends UiBinder { + } + + public SelectResourceWidget() { + initWidget(uiBinder.createAndBindUi(this)); + } + + @UiField + Button buttonDelete; + + @UiField + Button buttonEdit; + + @UiField + Label fieldName; + + private ResourceElementBean resourceBean; + + + public SelectResourceWidget(ResourceElementBean rb) { + initWidget(uiBinder.createAndBindUi(this)); + + this.resourceBean = rb; + + this.fieldName.setText(rb.getEditableName()); + + } + +} diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/SelectResourceWidget.ui.xml b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/SelectResourceWidget.ui.xml new file mode 100644 index 0000000..2c5e0e9 --- /dev/null +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/SelectResourceWidget.ui.xml @@ -0,0 +1,17 @@ + + + + .important { + font-weight: bold; + } + + + + + + + + + \ No newline at end of file diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/CKANPublisherServicesImpl.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/CKANPublisherServicesImpl.java index df034cc..f89303f 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/CKANPublisherServicesImpl.java +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/CKANPublisherServicesImpl.java @@ -264,7 +264,7 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C // if the request comes from the workspace if(folderId != null && !folderId.isEmpty()){ Workspace workspace = getWorkspaceFromStorageHub(); - WorkspaceUtils.handleWorkspaceResources(folderId, userName, bean, workspace); + WorkspaceUtils.toWorkspaceResource(folderId, userName, bean, workspace); } }catch(Exception e){ @@ -299,7 +299,7 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C if(folderId != null && !folderId.isEmpty()){ Workspace workspace = getWorkspaceFromStorageHub(); - WorkspaceUtils.handleWorkspaceResources(folderId, userName, bean, workspace); + WorkspaceUtils.toWorkspaceResource(folderId, userName, bean, workspace); } }catch(Exception e){ logger.error("Error while building bean into dev mode", e); diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/utils/WorkspaceUtils.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/utils/WorkspaceUtils.java index 8b35843..b11e45f 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/utils/WorkspaceUtils.java +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/utils/WorkspaceUtils.java @@ -99,65 +99,69 @@ public class WorkspaceUtils { } /** - * This method receives a folder id within the user's workspace and set the list of resources in the dataset bean to be returned. - * - * @param folderId the folder id + * This method receives an item-id within the user's workspace and setit in the dataset bean to be returned. + * revisited by Francesco + * + * @param wsItemId the ws item id * @param userName the user name * @param bean the bean * @param workspace the workspace * @throws Exception the exception */ - public static void handleWorkspaceResources(String folderId, String userName, + public static void toWorkspaceResource(String wsItemId, String userName, DatasetBean bean, Workspace workspace) throws Exception { - WorkspaceItem originalFolderOrFile = workspace.getItem(folderId); + WorkspaceItem originalFolderOrFile = workspace.getItem(wsItemId); logger.debug("Item retrieved is " + originalFolderOrFile); String title = originalFolderOrFile.getTitle() != null && !originalFolderOrFile.getTitle().isEmpty() ? originalFolderOrFile.getTitle() : originalFolderOrFile.getName(); + title = title.replaceAll(STRIP_NOT_ALPHANUMERIC, " "); + bean.setTitle(title); + + ResourceElementBean resourceEB = new ResourceElementBean(); + resourceEB.setOriginalIdInWorkspace(wsItemId); + resourceEB.setName(originalFolderOrFile.getName()); + resourceEB.setDescription(originalFolderOrFile.getDescription()); + resourceEB.setFolder(originalFolderOrFile.isFolder()); + resourceEB.setEditableName(originalFolderOrFile.getName()); - if(!originalFolderOrFile.isFolder()){ + //in case of folder + if(originalFolderOrFile.isFolder()) { - ResourceElementBean resource = new ResourceElementBean(); - resource.setDescription(originalFolderOrFile.getDescription()); - resource.setFolder(false); - resource.setEditableName(originalFolderOrFile.getName()); - resource.setName(originalFolderOrFile.getName()); - resource.setOriginalIdInWorkspace(folderId); - bean.setResourceRoot(resource); - bean.setTitle(title); - bean.setDescription(originalFolderOrFile.getDescription()); - - }else{ - - String onlyAlphanumericTitle = title; - bean.setTitle(onlyAlphanumericTitle); - bean.setDescription(originalFolderOrFile.getDescription()); - - // Create the folder in the catalogue + // loading gcube properties Map folderItems = getGcubeItemProperties(originalFolderOrFile); - if(folderItems != null){ + if(folderItems != null && folderItems.size()>0){ // transform this properties Map> tempItems = new HashMap>(folderItems.size()); Iterator> iterator = folderItems.entrySet().iterator(); while (iterator.hasNext()) { - Map.Entry entry = (Map.Entry) iterator - .next(); + Map.Entry entry = (Map.Entry) iterator.next(); tempItems.put(entry.getKey(), Arrays.asList(entry.getValue())); } + //setting properties as custom fields bean.setCustomFields(tempItems); } - - // set them into the bean - bean.setResourceRoot(WorkspaceUtils.getTreeFromFolder(folderId, workspace)); + + String pathSeparator = "/"; + String fullPathBase = originalFolderOrFile.getPath(); + fullPathBase = fullPathBase.endsWith(pathSeparator) ? fullPathBase : fullPathBase + pathSeparator; + resourceEB.setFullPath(originalFolderOrFile.getPath().replace(fullPathBase, "")); + resourceEB.setChildrenSize(workspace.getChildren(originalFolderOrFile.getId()).size()); + //WorkspaceUtils.extractEditableNameFromPath(resourceEB, pathSeparator); } - + + //setting parent id + ResourceElementBean theParent = new ResourceElementBean(); + theParent.setOriginalIdInWorkspace(originalFolderOrFile.getParentId()); + resourceEB.setParent(theParent); + bean.setResourceRoot(resourceEB); } /** Gets the gcube item properties. @@ -222,99 +226,98 @@ public class WorkspaceUtils { } - /** - * Returns a tree object. - * - * @param workspaceFolderId the workspace folder id - * @param workspace the workspace - * @return ResourceElementBean a tree object - * @throws Exception the exception - */ - public static ResourceElementBean getTreeFromFolder(String workspaceFolderId, Workspace workspace) throws Exception{ +// /** +// * Returns ResourceElementBean corresponding to workspaceFolderId +// * +// * @param workspaceFolderId the workspace folder id +// * @param workspace the workspace +// * @return ResourceElementBean a tree object +// * @throws Exception the exception +// */ +// public static ResourceElementBean toResourceEBFromFolder(String workspaceFolderId, Workspace workspace) throws Exception{ +// +// ResourceElementBean rootElem = new ResourceElementBean(); +// String pathSeparator = "/"; +// +// //String pathSeparator = ws.getPathSeparator(); +// +// WorkspaceItem initialItem = workspace.getItem(workspaceFolderId); +// String fullPathBase = initialItem.getPath(); +// fullPathBase = fullPathBase.endsWith(pathSeparator) ? fullPathBase : fullPathBase + pathSeparator; +// rootElem.setFolder(initialItem.isFolder()); +// rootElem.setFullPath(initialItem.getPath().replace(fullPathBase, "")); +// rootElem.setName(initialItem.getName()); +// rootElem.setOriginalIdInWorkspace(initialItem.getId()); +// rootElem.setDescription(initialItem.getDescription()); +// extractEditableNameFromPath(rootElem, pathSeparator); +// +// // recursive visiting +//// if(initialItem.isFolder()) +//// visit(rootElem, initialItem, workspace, fullPathBase, pathSeparator); +// +// logger.debug("Tree that is going to be returned is " + rootElem); +// return rootElem; +// } - ResourceElementBean rootElem = new ResourceElementBean(); - String pathSeparator = "/"; - - //String pathSeparator = ws.getPathSeparator(); - - - WorkspaceItem initialItem = workspace.getItem(workspaceFolderId); - String fullPathBase = initialItem.getPath(); - fullPathBase = fullPathBase.endsWith(pathSeparator) ? fullPathBase : fullPathBase + pathSeparator; - rootElem.setFolder(initialItem.isFolder()); - rootElem.setFullPath(initialItem.getPath().replace(fullPathBase, "")); - rootElem.setName(initialItem.getName()); - rootElem.setOriginalIdInWorkspace(initialItem.getId()); - rootElem.setDescription(initialItem.getDescription()); - extractEditableNameFromPath(rootElem, pathSeparator); +// /** +// * Recursive visit of a workspace item. +// * +// * @param parent the parent +// * @param initialItemWS the initial item WS +// * @param workspace the ws +// * @param fullPathBase the full path base +// * @param pathSeparator the path separator +// * @throws Exception the exception +// */ +// private static void visit(ResourceElementBean parent, WorkspaceItem initialItemWS, Workspace workspace, String fullPathBase, String pathSeparator) throws Exception { +// //List children = initialItemWS.getChildren(); +// +// List children = workspace.getChildren(initialItemWS.getId()); +// +// ArrayList childrenInTree = new ArrayList(children.size()); +// for (WorkspaceItem item : children) { +// // logger.debug("Path BEFORE REPLACE is " + item.getPath()); +// // logger.debug("Path AFTER REPLACE is " + item.getPath().replace(fullPathBase, "")); +// // logger.debug("Name is " + item.getName()); +// // logger.debug("id is " + item.getId()); +// ResourceElementBean elem = new ResourceElementBean(); +// elem.setFolder(item.isFolder()); +// elem.setOriginalIdInWorkspace(item.getId()); +// elem.setFullPath(item.getPath().replace(fullPathBase, "")); +// elem.setParent(parent); +// elem.setName(item.getName()); +// elem.setDescription(item.getDescription()); +// extractEditableNameFromPath(elem, pathSeparator); +// childrenInTree.add(elem); +// logger.trace("Elem is " + elem); +// if(item.isFolder()) +// visit(elem, item, workspace, fullPathBase, pathSeparator); +// } +// // add these list as child of the rootElem +// parent.setChildren(childrenInTree); +// } - // recursive visiting - if(initialItem.isFolder()) - visit(rootElem, initialItem, workspace, fullPathBase, pathSeparator); - - logger.debug("Tree that is going to be returned is " + rootElem); - return rootElem; - } - - /** - * Recursive visit of a workspace item. - * - * @param parent the parent - * @param initialItemWS the initial item WS - * @param workspace the ws - * @param fullPathBase the full path base - * @param pathSeparator the path separator - * @throws Exception the exception - */ - private static void visit(ResourceElementBean parent, WorkspaceItem initialItemWS, Workspace workspace, String fullPathBase, String pathSeparator) throws Exception { - //List children = initialItemWS.getChildren(); - - List children = workspace.getChildren(initialItemWS.getId()); - - ArrayList childrenInTree = new ArrayList(children.size()); - for (WorkspaceItem item : children) { - // logger.debug("Path BEFORE REPLACE is " + item.getPath()); - // logger.debug("Path AFTER REPLACE is " + item.getPath().replace(fullPathBase, "")); - // logger.debug("Name is " + item.getName()); - // logger.debug("id is " + item.getId()); - ResourceElementBean elem = new ResourceElementBean(); - elem.setFolder(item.isFolder()); - elem.setOriginalIdInWorkspace(item.getId()); - elem.setFullPath(item.getPath().replace(fullPathBase, "")); - elem.setParent(parent); - elem.setName(item.getName()); - elem.setDescription(item.getDescription()); - extractEditableNameFromPath(elem, pathSeparator); - childrenInTree.add(elem); - logger.trace("Elem is " + elem); - if(item.isFolder()) - visit(elem, item, workspace, fullPathBase, pathSeparator); - } - // add these list as child of the rootElem - parent.setChildren(childrenInTree); - } - - /** - * Replaces the "/" char with a custom one and return an editable name for the user. - * - * @param rootElem the root elem - * @param pathSeparatorInWs the path separator in ws - */ - private static void extractEditableNameFromPath(ResourceElementBean rootElem, String pathSeparatorInWs) { - - if(rootElem == null) - return; - - String elemName = rootElem.getName(); - String fullPath = rootElem.getFullPath(); - logger.info("Element original is " + rootElem); - - int lastIndex = rootElem.getFullPath().lastIndexOf(elemName); - fullPath = rootElem.getFullPath().substring(0, lastIndex); - fullPath = fullPath.replaceAll(pathSeparatorInWs, RESOURCES_NAME_SEPARATOR) + elemName; - rootElem.setEditableName(fullPath); - logger.info("Editable name for resource name: "+rootElem.getName()+", is: " + rootElem.getEditableName()); - } +// /** +// * Replaces the "/" char with a custom one and return an editable name for the user. +// * +// * @param rootElem the root elem +// * @param pathSeparatorInWs the path separator in ws +// */ +// public static void extractEditableNameFromPath(ResourceElementBean rootElem, String pathSeparatorInWs) { +// +// if(rootElem == null) +// return; +// +// String elemName = rootElem.getName(); +// String fullPath = rootElem.getFullPath(); +// logger.info("Element original is " + rootElem); +// +// int lastIndex = rootElem.getFullPath().lastIndexOf(elemName); +// fullPath = rootElem.getFullPath().substring(0, lastIndex); +// fullPath = fullPath.replaceAll(pathSeparatorInWs, RESOURCES_NAME_SEPARATOR) + elemName; +// rootElem.setEditableName(fullPath); +// logger.info("Editable name for resource name: "+rootElem.getName()+", is: " + rootElem.getEditableName()); +// } /** @@ -334,7 +337,7 @@ public class WorkspaceUtils { ResourceElementBean rootResource = bean.getResourceRoot(); // retrieve the children - List resourcesToAdd = rootResource.getChildren(); + List resourcesToAdd = rootResource.getToPublish(); // copy only the selected ones for(ResourceElementBean resource : resourcesToAdd){ diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/shared/ResourceElementBean.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/shared/ResourceElementBean.java index 064ff1d..ef3241e 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/shared/ResourceElementBean.java +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/shared/ResourceElementBean.java @@ -6,29 +6,62 @@ import java.util.List; import com.google.gwt.view.client.ProvidesKey; +// TODO: Auto-generated Javadoc /** * A resource element bean. Contains part of the logic used into the TwinColumn widget * @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it) + * + * @author revisited by Francesco Mangiacrapa */ public class ResourceElementBean implements Comparable, Serializable{ + /** The Constant serialVersionUID. */ private static final long serialVersionUID = -1230871392599580669L; + + /** The name. */ private String name; + + /** The editable name. */ private String editableName; + + /** The to be added. */ private boolean toBeAdded; + + /** The is folder. */ private boolean isFolder; + + /** The full path. */ private String fullPath; + + /** The original id in workspace. */ private String originalIdInWorkspace; + + /** The mime type. */ private String mimeType; + + /** The url. */ private String url; + + /** The description. */ private String description; + + /** The organization name dataset parent. */ private String organizationNameDatasetParent; // the organization name in which the parent dataset was created + + /** The parent. */ private ResourceElementBean parent; - private List children; + + /** The children size. */ + private Integer childrenSize; + + /** The to publish. */ + private List toPublish; //Resources that must be published + /** The next id. */ // to generate the GWT identifiers private static int nextId = 0; + /** The identifier GWT. */ // identifier of this instance private int identifierGWT; @@ -43,8 +76,9 @@ public class ResourceElementBean implements Comparable, Ser }; /** - * Copy constructor - * @param another + * Copy constructor. + * + * @param another the another */ public ResourceElementBean(ResourceElementBean another) { this.name = another.name; @@ -59,7 +93,7 @@ public class ResourceElementBean implements Comparable, Ser } /** - * Default constructor + * Default constructor. */ public ResourceElementBean(){ super(); @@ -68,43 +102,47 @@ public class ResourceElementBean implements Comparable, Ser } /** - * @param identifier - * @param parentFolder - * @param name - * @param movedToRight - * @param isFolder + * Instantiates a new resource element bean. + * + * @param parent the parent + * @param name the name + * @param isFolder the is folder + * @param childrenSize the children size + * @param fullPath the full path */ public ResourceElementBean( ResourceElementBean parent, String name, boolean isFolder, - List children, + Integer childrenSize, String fullPath) { this.identifierGWT = nextId; nextId++; this.parent = parent; this.name = name; this.isFolder = isFolder; - this.children = children; + this.childrenSize = childrenSize; this.fullPath = fullPath; } /** - * @param name - * @param toBeAdded - * @param isFolder - * @param parent - * @param children - * @param fullPath - * @param originalIdInWorkspace - * @param mimeType - * @param url - * @param description - * @param organizationNameDatasetParent + * Instantiates a new resource element bean. + * + * @param name the name + * @param toBeAdded the to be added + * @param isFolder the is folder + * @param parent the parent + * @param childrenSize the children size + * @param fullPath the full path + * @param originalIdInWorkspace the original id in workspace + * @param mimeType the mime type + * @param url the url + * @param description the description + * @param organizationNameDatasetParent the organization name dataset parent */ public ResourceElementBean(String name, boolean toBeAdded, boolean isFolder, ResourceElementBean parent, - List children, String fullPath, + Integer childrenSize, String fullPath, String originalIdInWorkspace, String mimeType, String url, String description, String organizationNameDatasetParent) { super(); @@ -114,7 +152,7 @@ public class ResourceElementBean implements Comparable, Ser this.toBeAdded = toBeAdded; this.isFolder = isFolder; this.parent = parent; - this.children = children; + this.childrenSize = childrenSize; this.fullPath = fullPath; this.originalIdInWorkspace = originalIdInWorkspace; this.mimeType = mimeType; @@ -123,103 +161,247 @@ public class ResourceElementBean implements Comparable, Ser this.organizationNameDatasetParent = organizationNameDatasetParent; } + /** + * Gets the parent. + * + * @return the parent + */ public ResourceElementBean getParent() { return parent; } + /** + * Sets the parent. + * + * @param parent the new parent + */ public void setParent(ResourceElementBean parent) { this.parent = parent; } + /** + * Gets the name. + * + * @return the name + */ public String getName() { return name; } + /** + * Sets the name. + * + * @param name the new name + */ public void setName(String name) { this.name = name; } + /** + * Checks if is to be added. + * + * @return true, if is to be added + */ public boolean isToBeAdded() { return toBeAdded; } + /** + * Sets the to be added. + * + * @param toBeAdded the new to be added + */ public void setToBeAdded(boolean toBeAdded) { this.toBeAdded = toBeAdded; } + /** + * Gets the mime type. + * + * @return the mime type + */ public String getMimeType() { return mimeType; } + /** + * Sets the mime type. + * + * @param mimeType the new mime type + */ public void setMimeType(String mimeType) { this.mimeType = mimeType; } + /** + * Gets the url. + * + * @return the url + */ public String getUrl() { return url; } + /** + * Sets the url. + * + * @param url the new url + */ public void setUrl(String url) { this.url = url; } + /** + * Gets the description. + * + * @return the description + */ public String getDescription() { return description; } + /** + * Sets the description. + * + * @param description the new description + */ public void setDescription(String description) { this.description = description; } + /** + * Gets the organization name dataset parent. + * + * @return the organization name dataset parent + */ public String getOrganizationNameDatasetParent() { return organizationNameDatasetParent; } + /** + * Sets the organization name dataset parent. + * + * @param organizationNameDatasetParent the new organization name dataset parent + */ public void setOrganizationNameDatasetParent( String organizationNameDatasetParent) { this.organizationNameDatasetParent = organizationNameDatasetParent; } + /** + * Checks if is folder. + * + * @return true, if is folder + */ public boolean isFolder() { return isFolder; } + /** + * Sets the folder. + * + * @param isFolder the new folder + */ public void setFolder(boolean isFolder) { this.isFolder = isFolder; } - public List getChildren() { - return children; + /** + * Gets the children size. + * + * @return the children size + */ + public Integer getChildrenSize() { + return childrenSize; } - public void setChildren(List children) { - this.children = children; + /** + * Sets the children size. + * + * @param size the new children size + */ + public void setChildrenSize(Integer size) { + this.childrenSize = size; } + /** + * Gets the full path. + * + * @return the full path + */ public String getFullPath() { return fullPath; } + /** + * Sets the full path. + * + * @param fullPath the new full path + */ public void setFullPath(String fullPath) { this.fullPath = fullPath; } + /** + * Gets the original id in workspace. + * + * @return the original id in workspace + */ public String getOriginalIdInWorkspace() { return originalIdInWorkspace; } + /** + * Sets the original id in workspace. + * + * @param originalIdInWorkspace the new original id in workspace + */ public void setOriginalIdInWorkspace(String originalIdInWorkspace) { this.originalIdInWorkspace = originalIdInWorkspace; } + /** + * Gets the editable name. + * + * @return the editable name + */ public String getEditableName() { return editableName; } + /** + * Sets the editable name. + * + * @param newName the new editable name + */ public void setEditableName(String newName) { this.editableName = newName; } + + /** + * Gets the to publish. + * + * @return the to publish + */ + public List getToPublish() { + return toPublish; + } + /** + * Sets the to publish. + * + * @param toPublish the new to publish + */ + public void setToPublish(List toPublish) { + this.toPublish = toPublish; + } + + /** + * Equals. + * + * @param o the o + * @return true, if successful + */ @Override public boolean equals(Object o) { boolean toReturn = false; @@ -230,23 +412,54 @@ public class ResourceElementBean implements Comparable, Ser return toReturn; } + /** + * Compare to. + * + * @param o the o + * @return the int + */ @Override public int compareTo(ResourceElementBean o) { int toReturn = (o == null || o.fullPath == null) ? -1 : -o.fullPath.compareTo(fullPath); return toReturn; } + /** + * To string. + * + * @return the string + */ @Override public String toString() { - return "ResourceElementBean [identifierGWT=" + identifierGWT - + ", name=" + name + ", editableName=" + editableName - + ", toBeAdded=" + toBeAdded + ", isFolder=" + isFolder - + ", fullPath=" + fullPath + ", originalIdInWorkspace=" - + originalIdInWorkspace + ", mimeType=" + mimeType + ", url=" - + url + ", description=" + description - + ", organizationNameDatasetParent=" - + organizationNameDatasetParent + ", parent=" + parent - + ", children number=" + (children == null ? 0 : children.size()) + "]"; + StringBuilder builder = new StringBuilder(); + builder.append("ResourceElementBean [name="); + builder.append(name); + builder.append(", editableName="); + builder.append(editableName); + builder.append(", toBeAdded="); + builder.append(toBeAdded); + builder.append(", isFolder="); + builder.append(isFolder); + builder.append(", fullPath="); + builder.append(fullPath); + builder.append(", originalIdInWorkspace="); + builder.append(originalIdInWorkspace); + builder.append(", mimeType="); + builder.append(mimeType); + builder.append(", url="); + builder.append(url); + builder.append(", description="); + builder.append(description); + builder.append(", organizationNameDatasetParent="); + builder.append(organizationNameDatasetParent); + builder.append(", parent="); + builder.append(parent); + builder.append(", childrenSize="); + builder.append(childrenSize); + builder.append(", identifierGWT="); + builder.append(identifierGWT); + builder.append("]"); + return builder.toString(); } } diff --git a/src/main/resources/org/gcube/portlets/widgets/ckandatapublisherwidget/CKanMetadataPublisher.gwt.xml b/src/main/resources/org/gcube/portlets/widgets/ckandatapublisherwidget/CKanMetadataPublisher.gwt.xml index b2174ff..7322fbe 100644 --- a/src/main/resources/org/gcube/portlets/widgets/ckandatapublisherwidget/CKanMetadataPublisher.gwt.xml +++ b/src/main/resources/org/gcube/portlets/widgets/ckandatapublisherwidget/CKanMetadataPublisher.gwt.xml @@ -6,17 +6,24 @@ - - + + - - - - + + + + + + diff --git a/src/test/java/org/gcube/portlets/widgets/ckandatapublisherwidget/TestPublishingWidget.java b/src/test/java/org/gcube/portlets/widgets/ckandatapublisherwidget/TestPublishingWidget.java index 6b26f4a..dcfc06c 100644 --- a/src/test/java/org/gcube/portlets/widgets/ckandatapublisherwidget/TestPublishingWidget.java +++ b/src/test/java/org/gcube/portlets/widgets/ckandatapublisherwidget/TestPublishingWidget.java @@ -93,7 +93,7 @@ public class TestPublishingWidget { if(folderId != null && !folderId.isEmpty()){ StorageHubWrapper storageHubWrapper = new StorageHubWrapper(scope, token, false, false, true); - WorkspaceUtils.handleWorkspaceResources(folderId, userName, bean, storageHubWrapper.getWorkspace()); + WorkspaceUtils.toWorkspaceResource(folderId, userName, bean, storageHubWrapper.getWorkspace()); } }catch(Exception e){ LOG.error("Error while building bean into dev mode", e); From 79e51db104ac7a28496820c770a4d266ecc765d5 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Mon, 8 Mar 2021 17:51:04 +0100 Subject: [PATCH 18/44] in progress --- .classpath | 8 +- .../client/CKanMetadataPublisher.java | 8 +- .../client/ui/form/CreateDatasetForm.java | 18 +-- .../client/ui/form/CreateDatasetForm.ui.xml | 7 +- .../SelectResourceByWEMainPanel.java | 129 +++++++++++------- .../SelectResourceByWEMainPanel.ui.xml | 38 ++++-- .../ui/workspace/SelectResourceWidget.java | 4 + .../ui/workspace/SelectResourceWidget.ui.xml | 12 +- 8 files changed, 144 insertions(+), 80 deletions(-) diff --git a/.classpath b/.classpath index 510cf3c..5fe0d51 100644 --- a/.classpath +++ b/.classpath @@ -6,7 +6,13 @@ - + + + + + + + diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/CKanMetadataPublisher.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/CKanMetadataPublisher.java index 0a064ce..2cbba2b 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/CKanMetadataPublisher.java +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/CKanMetadataPublisher.java @@ -265,11 +265,15 @@ public class CKanMetadataPublisher implements EntryPoint { m.setWidth("1200px"); m.getElement().getStyle().setMarginLeft(-30, Unit.PCT); ResourceElementBean r = new ResourceElementBean(); - r.setFolder(true); + r.setFolder(false); r.setName("Root"); r.setParent(null); r.setChildrenSize(5); - r.setOriginalIdInWorkspace("4ab50488-67d7-4664-9a0f-88a1de043399"); + r.setOriginalIdInWorkspace("31d7ec0c-8d31-47d7-9139-c52b5e124349"); + + ResourceElementBean parent = new ResourceElementBean(); + parent.setOriginalIdInWorkspace("91409eba-0bf6-4aa5-8d73-3536bf181587"); + r.setParent(parent); List children = new ArrayList(); diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/form/CreateDatasetForm.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/form/CreateDatasetForm.java index b93f95f..456fa0a 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/form/CreateDatasetForm.java +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/form/CreateDatasetForm.java @@ -1247,15 +1247,15 @@ public class CreateDatasetForm extends Composite{ ); // resources field - InfoIconsLabels.preparePopupPanelAndPopover( - InfoIconsLabels.RESOURCES_INFO_ID_POPUP, - InfoIconsLabels.RESOURCES_INFO_TEXT, - InfoIconsLabels.RESOURCES_INFO_CAPTION, - infoIconResources, - popoverResources, - focusPanelResources, - popupOpenedIds - ); +// InfoIconsLabels.preparePopupPanelAndPopover( +// InfoIconsLabels.RESOURCES_INFO_ID_POPUP, +// InfoIconsLabels.RESOURCES_INFO_TEXT, +// InfoIconsLabels.RESOURCES_INFO_CAPTION, +// infoIconResources, +// popoverResources, +// focusPanelResources, +// popupOpenedIds +// ); // title InfoIconsLabels.preparePopupPanelAndPopover( diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/form/CreateDatasetForm.ui.xml b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/form/CreateDatasetForm.ui.xml index cf4440a..d22c431 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/form/CreateDatasetForm.ui.xml +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/form/CreateDatasetForm.ui.xml @@ -320,7 +320,6 @@ Manage Resources - @@ -329,13 +328,9 @@ - + - - - Continue diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/SelectResourceByWEMainPanel.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/SelectResourceByWEMainPanel.java index 5aa1f89..8badec8 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/SelectResourceByWEMainPanel.java +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/SelectResourceByWEMainPanel.java @@ -4,20 +4,25 @@ import java.util.HashMap; import java.util.Map; import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.ResourceElementBean; -import org.gcube.portlets.widgets.wsexplorer.client.explore.WorkspaceResourcesBExplorerPanel; import org.gcube.portlets.widgets.wsexplorer.client.explore.WorkspaceResourcesExplorerPanel; -import org.gcube.portlets.widgets.wsexplorer.client.notification.WorkspaceExplorerSelectBNotification.WorskpaceExplorerSelectBNotificationListener; +import org.gcube.portlets.widgets.wsexplorer.client.notification.WorkspaceExplorerSelectNotification.WorskpaceExplorerSelectNotificationListener; import org.gcube.portlets.widgets.wsexplorer.client.view.grid.ItemsTable.DISPLAY_FIELD; import org.gcube.portlets.widgets.wsexplorer.shared.Item; +import com.github.gwtbootstrap.client.ui.AccordionGroup; +import com.github.gwtbootstrap.client.ui.Alert; import com.github.gwtbootstrap.client.ui.Button; +import com.github.gwtbootstrap.client.ui.constants.AlertType; +import com.github.gwtbootstrap.client.ui.constants.ButtonType; import com.google.gwt.core.client.GWT; import com.google.gwt.event.dom.client.ClickEvent; import com.google.gwt.event.dom.client.ClickHandler; import com.google.gwt.uibinder.client.UiBinder; import com.google.gwt.uibinder.client.UiField; +import com.google.gwt.user.client.Timer; import com.google.gwt.user.client.Window; import com.google.gwt.user.client.ui.Composite; +import com.google.gwt.user.client.ui.HTMLPanel; import com.google.gwt.user.client.ui.VerticalPanel; import com.google.gwt.user.client.ui.Widget; @@ -41,9 +46,18 @@ public class SelectResourceByWEMainPanel extends Composite { @UiField VerticalPanel selectResourcesContainer; + @UiField + Alert showAlert; + @UiField Button buttSelectResource; + @UiField + AccordionGroup buttPickResources; + + @UiField + HTMLPanel containerPickResources; + private Item selectedWEItem; Map mapSelectedResources = new HashMap(); @@ -67,57 +81,60 @@ public class SelectResourceByWEMainPanel extends Composite { this.frozen = false; this.initialBean = initialBean; + //this.buttPickResources.setType(ButtonType.LINK); WorkspaceResourcesExplorerPanel rp = null; DISPLAY_FIELD[] displayFields = new DISPLAY_FIELD[] { DISPLAY_FIELD.ICON, DISPLAY_FIELD.NAME, - DISPLAY_FIELD.OWNER }; + DISPLAY_FIELD.OWNER, DISPLAY_FIELD.CREATION_DATE}; try { - String wsRootId = initialBean.isFolder() ? initialBean.getOriginalIdInWorkspace() - : initialBean.getParent().getOriginalIdInWorkspace(); - // WorkspaceResourcesBExplorerPanel(String folderId, boolean showOnlyFolders, - // List showProperties, FilterCriteria filter, boolean showGcubeInfo, - // DISPLAY_FIELD sortByColumn) throws Exception { - WorkspaceResourcesBExplorerPanel workspaceExplorerPanel = new WorkspaceResourcesBExplorerPanel(wsRootId, - false); - WorskpaceExplorerSelectBNotificationListener wsResourceExplorerListener = new WorskpaceExplorerSelectBNotificationListener() { - + + String wsRootId = null; + if(initialBean.isFolder()) { + wsRootId = initialBean.getOriginalIdInWorkspace(); + }else { + //is file + wsRootId= initialBean.getParent()!=null? initialBean.getParent().getOriginalIdInWorkspace():null; + } + + //loads the WE only if the root is not null + if(wsRootId!=null) { + + WorkspaceResourcesExplorerPanel workspaceExplorerPanel = new WorkspaceResourcesExplorerPanel(wsRootId,false,null, null,false,null,displayFields); + WorskpaceExplorerSelectNotificationListener wsResourceExplorerListener = new WorskpaceExplorerSelectNotificationListener() { - - @Override - public void onSelectedItem(Item item) { - GWT.log("Listener Selected Item " + item); - selectedWEItem = item; - } - - @Override - public void onFailed(Throwable throwable) { - // Log.error(throwable.getLocalizedMessage()); - throwable.printStackTrace(); - } + @Override + public void onSelectedItem(Item item) { + GWT.log("Listener Selected Item " + item); + selectedWEItem = item; + } + + @Override + public void onFailed(Throwable throwable) { + // Log.error(throwable.getLocalizedMessage()); + throwable.printStackTrace(); + } + + + @Override + public void onAborted() { + + } + + @Override + public void onNotValidSelection() { + selectedWEItem = null; + } + }; + + workspaceExplorerPanel.addWorkspaceExplorerSelectNotificationListener(wsResourceExplorerListener); + wsContainer.add(workspaceExplorerPanel); + }else { + containerPickResources.setVisible(false); + } - @Override - public void onAborted() { - - } - - @Override - public void onNotValidSelection() { - selectedWEItem = null; - } - - @Override - public void onBreadcrumbChanged(Item item) { - GWT.log("Breadcrumb Changed: " + item); - - } - }; - - workspaceExplorerPanel.addWorkspaceExplorerSelectNotificationListener(wsResourceExplorerListener); - wsContainer.add(workspaceExplorerPanel); - } catch (Exception e) { e.printStackTrace(); } @@ -131,7 +148,7 @@ public class SelectResourceByWEMainPanel extends Composite { @Override public void onClick(ClickEvent event) { - if(selectedWEItem!=null) { + if(selectedWEItem!=null && !selectedWEItem.isFolder()) { addSelectResource(selectedWEItem.getId(), selectedWEItem.getName(), selectedWEItem.getPath()); } @@ -144,7 +161,7 @@ public class SelectResourceByWEMainPanel extends Composite { SelectResourceWidget selWidg = mapSelectedResources.get(wsItemId); if (selWidg != null) { - Window.alert("Item '" + name + "' already selected"); + showAlertMsg(AlertType.WARNING,"Item '" + name + "' already selected",true); return; } @@ -156,10 +173,28 @@ public class SelectResourceByWEMainPanel extends Composite { selWidg = new SelectResourceWidget(rb); mapSelectedResources.put(wsItemId, selWidg); - selectResourcesContainer.add(selWidg); } + + private void showAlertMsg(AlertType type, String txt, boolean autoHide) { + showAlert.setType(type); + showAlert.setText(txt); + showAlert.setVisible(true); + showAlert.setClose(true); + if(autoHide) { + Timer timer = new Timer() { + + @Override + public void run() { + showAlert.setVisible(false); + + } + }; + + timer.schedule(5000); + } + } public ResourceElementBean getResourcesToPublish() { // TODO Auto-generated method stub diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/SelectResourceByWEMainPanel.ui.xml b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/SelectResourceByWEMainPanel.ui.xml index e3cc515..3c0a414 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/SelectResourceByWEMainPanel.ui.xml +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/SelectResourceByWEMainPanel.ui.xml @@ -6,21 +6,35 @@ .important { font-weight: bold; } + + .margin-bottom-40 { + margin-bottom: 40px; + } + + .max-height-250 { + max-height: 250px; + overflow-y: auto; + } - - - - - - - Select Resource - - - - + + Selected + + + + + + + + Select + + + + + \ No newline at end of file diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/SelectResourceWidget.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/SelectResourceWidget.java index 526715e..7be131d 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/SelectResourceWidget.java +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/SelectResourceWidget.java @@ -3,6 +3,7 @@ package org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.workspace; import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.ResourceElementBean; import com.github.gwtbootstrap.client.ui.Button; +import com.github.gwtbootstrap.client.ui.constants.ButtonType; import com.google.gwt.core.client.GWT; import com.google.gwt.uibinder.client.UiBinder; import com.google.gwt.uibinder.client.UiField; @@ -40,6 +41,9 @@ public class SelectResourceWidget extends Composite { this.fieldName.setText(rb.getEditableName()); + buttonEdit.setType(ButtonType.LINK); + buttonDelete.setType(ButtonType.LINK); + } } diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/SelectResourceWidget.ui.xml b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/SelectResourceWidget.ui.xml index 2c5e0e9..141a063 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/SelectResourceWidget.ui.xml +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/SelectResourceWidget.ui.xml @@ -6,11 +6,17 @@ .important { font-weight: bold; } + .selected-resources { + } + + .selected-resources td { + vertical-align: middle !important; + } - - - + + + From 3a9ac6eecc6f52655bcbb1d1595adc4ef2fb238c Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Mon, 8 Mar 2021 18:28:25 +0100 Subject: [PATCH 19/44] in progress --- .../client/ui/workspace/SelectResourceByWEMainPanel.java | 5 ++--- .../ui/workspace/SelectResourceByWEMainPanel.ui.xml | 9 ++++----- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/SelectResourceByWEMainPanel.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/SelectResourceByWEMainPanel.java index 8badec8..1a24e3e 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/SelectResourceByWEMainPanel.java +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/SelectResourceByWEMainPanel.java @@ -13,7 +13,6 @@ import com.github.gwtbootstrap.client.ui.AccordionGroup; import com.github.gwtbootstrap.client.ui.Alert; import com.github.gwtbootstrap.client.ui.Button; import com.github.gwtbootstrap.client.ui.constants.AlertType; -import com.github.gwtbootstrap.client.ui.constants.ButtonType; import com.google.gwt.core.client.GWT; import com.google.gwt.event.dom.client.ClickEvent; import com.google.gwt.event.dom.client.ClickHandler; @@ -97,10 +96,10 @@ public class SelectResourceByWEMainPanel extends Composite { //is file wsRootId= initialBean.getParent()!=null? initialBean.getParent().getOriginalIdInWorkspace():null; } - + //loads the WE only if the root is not null if(wsRootId!=null) { - + WorkspaceResourcesExplorerPanel workspaceExplorerPanel = new WorkspaceResourcesExplorerPanel(wsRootId,false,null, null,false,null,displayFields); WorskpaceExplorerSelectNotificationListener wsResourceExplorerListener = new WorskpaceExplorerSelectNotificationListener() { diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/SelectResourceByWEMainPanel.ui.xml b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/SelectResourceByWEMainPanel.ui.xml index 3c0a414..82aec99 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/SelectResourceByWEMainPanel.ui.xml +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/SelectResourceByWEMainPanel.ui.xml @@ -21,17 +21,16 @@ Selected - - + + - + - Select + Select From f4846b0a668a4716c2e89e486e4415fd797d777e Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Tue, 9 Mar 2021 19:02:26 +0100 Subject: [PATCH 20/44] in progress on "Manage Resources" --- .../client/CKanMetadataPublisher.java | 4 +- .../ResourceInfoForm.ui.xml | 118 ++++++++++-------- .../client/ui/form/CreateDatasetForm.java | 18 +-- .../client/ui/utils/InfoIconsLabels.java | 4 +- .../EditPublishingResourceEvent.java | 62 +++++++++ .../EditPublishingResourceEventHandler.java | 22 ++++ .../RemovePublishingResourceEvent.java | 59 +++++++++ .../RemovePublishingResourceEventHandler.java | 22 ++++ .../SelectResourceByWEMainPanel.java | 102 +++++++++++++-- .../SelectResourceByWEMainPanel.ui.xml | 44 +++++-- .../ui/workspace/SelectResourceWidget.java | 41 +++++- .../server/utils/WorkspaceUtils.java | 12 +- 12 files changed, 411 insertions(+), 97 deletions(-) create mode 100644 src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/EditPublishingResourceEvent.java create mode 100644 src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/EditPublishingResourceEventHandler.java create mode 100644 src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/RemovePublishingResourceEvent.java create mode 100644 src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/RemovePublishingResourceEventHandler.java diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/CKanMetadataPublisher.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/CKanMetadataPublisher.java index 2cbba2b..c75ec32 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/CKanMetadataPublisher.java +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/CKanMetadataPublisher.java @@ -266,10 +266,10 @@ public class CKanMetadataPublisher implements EntryPoint { m.getElement().getStyle().setMarginLeft(-30, Unit.PCT); ResourceElementBean r = new ResourceElementBean(); r.setFolder(false); - r.setName("Root"); + r.setName("Mangiacrapra_Introducing_myself.pptx"); r.setParent(null); r.setChildrenSize(5); - r.setOriginalIdInWorkspace("31d7ec0c-8d31-47d7-9139-c52b5e124349"); + r.setOriginalIdInWorkspace("8489e2ab-7487-404f-97ff-5aecc35c241f"); ResourceElementBean parent = new ResourceElementBean(); parent.setOriginalIdInWorkspace("91409eba-0bf6-4aa5-8d73-3536bf181587"); diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/TwinColumnSelection/ResourceInfoForm.ui.xml b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/TwinColumnSelection/ResourceInfoForm.ui.xml index c9d29ce..bc64abf 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/TwinColumnSelection/ResourceInfoForm.ui.xml +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/TwinColumnSelection/ResourceInfoForm.ui.xml @@ -1,6 +1,7 @@ + xmlns:g="urn:import:com.google.gwt.user.client.ui" + xmlns:b="urn:import:com.github.gwtbootstrap.client.ui"> .legend-style { width: 100%; @@ -28,61 +29,68 @@ .control-group { margin-bottom: 0px !important; } + + .custom-input { + + } + - - - - - Resource Information - - - - - Name: - - - - - - - - Path: - - - - - - - - Description: - - - - - - - - Format: - - - - - - - - Update - - + + + + + Resource Information + + + + + Name: + + + + + + + + Path: + + + + + + + + Description: + + + + + + + + Format: + + + + + + + + Update + + \ No newline at end of file diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/form/CreateDatasetForm.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/form/CreateDatasetForm.java index 456fa0a..b93f95f 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/form/CreateDatasetForm.java +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/form/CreateDatasetForm.java @@ -1247,15 +1247,15 @@ public class CreateDatasetForm extends Composite{ ); // resources field -// InfoIconsLabels.preparePopupPanelAndPopover( -// InfoIconsLabels.RESOURCES_INFO_ID_POPUP, -// InfoIconsLabels.RESOURCES_INFO_TEXT, -// InfoIconsLabels.RESOURCES_INFO_CAPTION, -// infoIconResources, -// popoverResources, -// focusPanelResources, -// popupOpenedIds -// ); + InfoIconsLabels.preparePopupPanelAndPopover( + InfoIconsLabels.RESOURCES_INFO_ID_POPUP, + InfoIconsLabels.RESOURCES_INFO_TEXT, + InfoIconsLabels.RESOURCES_INFO_CAPTION, + infoIconResources, + popoverResources, + focusPanelResources, + popupOpenedIds + ); // title InfoIconsLabels.preparePopupPanelAndPopover( diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/utils/InfoIconsLabels.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/utils/InfoIconsLabels.java index 09e3787..7f3f316 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/utils/InfoIconsLabels.java +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/utils/InfoIconsLabels.java @@ -70,8 +70,8 @@ public class InfoIconsLabels { // RESOURCES public static final String RESOURCES_INFO_ID_POPUP = "resouces-popup-panel-info"; public static final String RESOURCES_INFO_CAPTION = "Manage resource items"; - public static final String RESOURCES_INFO_TEXT = "Move the files you want to attach to the item on the right panel below. Double click on the item for changing resource's name or description." - + " Please consider that any complex hierarchy structure you may have will be flatten."; + public static final String RESOURCES_INFO_TEXT = "Select the files you want to attach to the publishing item. Click on 'Trash' to remote it. Click on 'Edit' for changing resource's name or description." + + " You can add others files by using the 'Add files from...' facility. To navigate a folder perform a 'double click' on it. Please consider that any complex hierarchy structure you may have will be flatten."; // CUSTOM FIELDS public static final String CUSTOM_FIELDS_INFO_ID_POPUP = "custom-fields-popup-panel-info"; diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/EditPublishingResourceEvent.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/EditPublishingResourceEvent.java new file mode 100644 index 0000000..64d292b --- /dev/null +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/EditPublishingResourceEvent.java @@ -0,0 +1,62 @@ +package org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.workspace; + +import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.ResourceElementBean; + +import com.google.gwt.event.shared.GwtEvent; + + +// TODO: Auto-generated Javadoc +/** + * The Class EditPublishingResourceEvent. + * + * @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it) + * + * Mar 9, 2021 + */ +public class EditPublishingResourceEvent extends GwtEvent { + + /** The type. */ + public static Type TYPE = new Type(); + + /** The resource. */ + private ResourceElementBean resource; + + + /** + * Instantiates a new edits the publishing resource event. + * + * @param resource the resource + */ + public EditPublishingResourceEvent(ResourceElementBean resource) { + this.resource = resource; + } + + /** + * Gets the resource. + * + * @return the resource + */ + public ResourceElementBean getResource() { + return resource; + } + + /** + * Gets the associated type. + * + * @return the associated type + */ + @Override + public Type getAssociatedType() { + return TYPE; + } + + /** + * Dispatch. + * + * @param handler the handler + */ + @Override + protected void dispatch(EditPublishingResourceEventHandler handler) { + handler.onEditResource(this); + } +} diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/EditPublishingResourceEventHandler.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/EditPublishingResourceEventHandler.java new file mode 100644 index 0000000..333fa76 --- /dev/null +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/EditPublishingResourceEventHandler.java @@ -0,0 +1,22 @@ +package org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.workspace; + +import com.google.gwt.event.shared.EventHandler; + + +// TODO: Auto-generated Javadoc +/** + * The Interface EditPublishingResourceEventHandler. + * + * @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it) + * + * Mar 9, 2021 + */ +public interface EditPublishingResourceEventHandler extends EventHandler { + + /** + * On edit resource. + * + * @param editResourceEvent the edit resource event + */ + void onEditResource(EditPublishingResourceEvent editResourceEvent); +} diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/RemovePublishingResourceEvent.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/RemovePublishingResourceEvent.java new file mode 100644 index 0000000..c3973e1 --- /dev/null +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/RemovePublishingResourceEvent.java @@ -0,0 +1,59 @@ +package org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.workspace; + +import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.ResourceElementBean; + +import com.google.gwt.event.shared.GwtEvent; + +/** + * The Class RemovePublishingResourceEvent. + * + * @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it) + * + * Mar 9, 2021 + */ +public class RemovePublishingResourceEvent extends GwtEvent { + + /** The type. */ + public static Type TYPE = new Type(); + + /** The resource. */ + private ResourceElementBean resource; + + /** + * Instantiates a new removes the publishing resource event. + * + * @param resource the resource + */ + public RemovePublishingResourceEvent(ResourceElementBean resource) { + this.resource = resource; + } + + /** + * Gets the resource. + * + * @return the resource + */ + public ResourceElementBean getResource() { + return resource; + } + + /** + * Gets the associated type. + * + * @return the associated type + */ + @Override + public Type getAssociatedType() { + return TYPE; + } + + /** + * Dispatch. + * + * @param handler the handler + */ + @Override + protected void dispatch(RemovePublishingResourceEventHandler handler) { + handler.onRemoveResource(this); + } +} diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/RemovePublishingResourceEventHandler.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/RemovePublishingResourceEventHandler.java new file mode 100644 index 0000000..93c2031 --- /dev/null +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/RemovePublishingResourceEventHandler.java @@ -0,0 +1,22 @@ +package org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.workspace; + +import com.google.gwt.event.shared.EventHandler; + + +// TODO: Auto-generated Javadoc +/** + * The Interface RemovePublishingResourceEventHandler. + * + * @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it) + * + * Mar 9, 2021 + */ +public interface RemovePublishingResourceEventHandler extends EventHandler { + + /** + * On remove resource. + * + * @param removeResourceEvent the remove resource event + */ + void onRemoveResource(RemovePublishingResourceEvent removeResourceEvent); +} diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/SelectResourceByWEMainPanel.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/SelectResourceByWEMainPanel.java index 1a24e3e..b8b20d4 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/SelectResourceByWEMainPanel.java +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/SelectResourceByWEMainPanel.java @@ -3,6 +3,7 @@ package org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.workspace; import java.util.HashMap; import java.util.Map; +import org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.TwinColumnSelection.ResourceInfoForm; import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.ResourceElementBean; import org.gcube.portlets.widgets.wsexplorer.client.explore.WorkspaceResourcesExplorerPanel; import org.gcube.portlets.widgets.wsexplorer.client.notification.WorkspaceExplorerSelectNotification.WorskpaceExplorerSelectNotificationListener; @@ -12,10 +13,14 @@ import org.gcube.portlets.widgets.wsexplorer.shared.Item; import com.github.gwtbootstrap.client.ui.AccordionGroup; import com.github.gwtbootstrap.client.ui.Alert; import com.github.gwtbootstrap.client.ui.Button; +import com.github.gwtbootstrap.client.ui.Label; import com.github.gwtbootstrap.client.ui.constants.AlertType; +import com.github.gwtbootstrap.client.ui.constants.LabelType; 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.event.dom.client.HasAllDragAndDropHandlers; +import com.google.gwt.event.shared.HandlerManager; import com.google.gwt.uibinder.client.UiBinder; import com.google.gwt.uibinder.client.UiField; import com.google.gwt.user.client.Timer; @@ -57,8 +62,16 @@ public class SelectResourceByWEMainPanel extends Composite { @UiField HTMLPanel containerPickResources; + @UiField + Label labelNothing; + + @UiField + HTMLPanel editPanel; + private Item selectedWEItem; + public final static HandlerManager eventBus = new HandlerManager(null); + Map mapSelectedResources = new HashMap(); /** @@ -76,30 +89,33 @@ public class SelectResourceByWEMainPanel extends Composite { */ public SelectResourceByWEMainPanel(ResourceElementBean initialBean) { initWidget(uiBinder.createAndBindUi(this)); - - this.frozen = false; - + SelectResourceByWEMainPanel.frozen = false; this.initialBean = initialBean; - //this.buttPickResources.setType(ButtonType.LINK); - - WorkspaceResourcesExplorerPanel rp = null; - - DISPLAY_FIELD[] displayFields = new DISPLAY_FIELD[] { DISPLAY_FIELD.ICON, DISPLAY_FIELD.NAME, - DISPLAY_FIELD.OWNER, DISPLAY_FIELD.CREATION_DATE}; + this.labelNothing.setType(LabelType.INFO); + try { String wsRootId = null; + String rootName = null; if(initialBean.isFolder()) { wsRootId = initialBean.getOriginalIdInWorkspace(); + rootName = initialBean.getName(); }else { //is file - wsRootId= initialBean.getParent()!=null? initialBean.getParent().getOriginalIdInWorkspace():null; + + if(initialBean.getParent()!=null) { + wsRootId = initialBean.getParent().getOriginalIdInWorkspace(); + rootName = initialBean.getParent().getName(); + } } //loads the WE only if the root is not null if(wsRootId!=null) { + DISPLAY_FIELD[] displayFields = new DISPLAY_FIELD[] { DISPLAY_FIELD.ICON, DISPLAY_FIELD.NAME, + DISPLAY_FIELD.OWNER, DISPLAY_FIELD.CREATION_DATE}; + WorkspaceResourcesExplorerPanel workspaceExplorerPanel = new WorkspaceResourcesExplorerPanel(wsRootId,false,null, null,false,null,displayFields); WorskpaceExplorerSelectNotificationListener wsResourceExplorerListener = new WorskpaceExplorerSelectNotificationListener() { @@ -132,6 +148,10 @@ public class SelectResourceByWEMainPanel extends Composite { }else { containerPickResources.setVisible(false); } + + if(rootName!=null) { + buttPickResources.setHeading("Add files from "+rootName); + } } catch (Exception e) { @@ -141,7 +161,12 @@ public class SelectResourceByWEMainPanel extends Composite { if(!initialBean.isFolder()) { addSelectResource(initialBean.getOriginalIdInWorkspace(), initialBean.getName(),initialBean.getFullPath()); } + + addHandlers(); + } + + private void addHandlers() { buttSelectResource.addClickHandler(new ClickHandler() { @@ -154,8 +179,54 @@ public class SelectResourceByWEMainPanel extends Composite { } }); + eventBus.addHandler(RemovePublishingResourceEvent.TYPE, new RemovePublishingResourceEventHandler() { + + @Override + public void onRemoveResource(RemovePublishingResourceEvent removeResourceEvent) { + if(removeResourceEvent.getResource()!=null) { + removePublishingResource(removeResourceEvent.getResource()); + } + } + + }); + + eventBus.addHandler(EditPublishingResourceEvent.TYPE, new EditPublishingResourceEventHandler() { + + @Override + public void onEditResource(EditPublishingResourceEvent editResourceEvent) { + if(editResourceEvent.getResource()!=null) { + editPublishingResource(editResourceEvent.getResource()); + } + + } + + + }); + } + private void editPublishingResource(ResourceElementBean resource) { + + SelectResourceWidget theRW = mapSelectedResources.get(resource.getOriginalIdInWorkspace()); + if(theRW!=null) { + + ResourceInfoForm rif = new ResourceInfoForm(resource, null); + editPanel.add(rif); + } + + } + + private void removePublishingResource(ResourceElementBean resource) { + + SelectResourceWidget theRW = mapSelectedResources.get(resource.getOriginalIdInWorkspace()); + if(theRW!=null) { + selectResourcesContainer.remove(theRW); + mapSelectedResources.remove(resource.getOriginalIdInWorkspace()); + } + + showNothingResourceSelected(); + } + public void addSelectResource(String wsItemId, String name, String path) { SelectResourceWidget selWidg = mapSelectedResources.get(wsItemId); @@ -163,7 +234,7 @@ public class SelectResourceByWEMainPanel extends Composite { showAlertMsg(AlertType.WARNING,"Item '" + name + "' already selected",true); return; } - + ResourceElementBean rb = new ResourceElementBean(); rb.setOriginalIdInWorkspace(wsItemId); rb.setName(name); @@ -174,6 +245,15 @@ public class SelectResourceByWEMainPanel extends Composite { mapSelectedResources.put(wsItemId, selWidg); selectResourcesContainer.add(selWidg); + showNothingResourceSelected(); + + } + + private void showNothingResourceSelected() { + if(mapSelectedResources.size()==0) { + labelNothing.setVisible(true); + }else + labelNothing.setVisible(false); } private void showAlertMsg(AlertType type, String txt, boolean autoHide) { diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/SelectResourceByWEMainPanel.ui.xml b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/SelectResourceByWEMainPanel.ui.xml index 82aec99..2ab7607 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/SelectResourceByWEMainPanel.ui.xml +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/SelectResourceByWEMainPanel.ui.xml @@ -7,33 +7,55 @@ font-weight: bold; } - .margin-bottom-40 { - margin-bottom: 40px; + .custom-header { + margin-top: 0px !important; + } + + .custom-header h1 { + font-size: 18px !important; } .max-height-250 { max-height: 250px; overflow-y: auto; } + + .no-border { + border: 0px !important; + } + + .margin-top-10 { + margin-top: 10px; + } + + .margin-top-20 { + margin-top: 20px; + } - - Selected - - + + Publishing Resources + + + Nothing + + + - + + + heading="Add files from..." defaultOpen="false" + addStyleNames="{style.no-border}"> - Select + Select - - \ No newline at end of file diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/SelectResourceWidget.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/SelectResourceWidget.java index 7be131d..e5d677e 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/SelectResourceWidget.java +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/SelectResourceWidget.java @@ -5,6 +5,8 @@ import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.ResourceElement import com.github.gwtbootstrap.client.ui.Button; import com.github.gwtbootstrap.client.ui.constants.ButtonType; import com.google.gwt.core.client.GWT; +import com.google.gwt.event.dom.client.ClickEvent; +import com.google.gwt.event.dom.client.ClickHandler; import com.google.gwt.uibinder.client.UiBinder; import com.google.gwt.uibinder.client.UiField; import com.google.gwt.user.client.ui.Composite; @@ -24,26 +26,53 @@ public class SelectResourceWidget extends Composite { @UiField Button buttonDelete; - + @UiField Button buttonEdit; - + @UiField Label fieldName; private ResourceElementBean resourceBean; - public SelectResourceWidget(ResourceElementBean rb) { initWidget(uiBinder.createAndBindUi(this)); - + this.resourceBean = rb; - + this.fieldName.setText(rb.getEditableName()); - + buttonEdit.setType(ButtonType.LINK); + buttonDelete.setType(ButtonType.LINK); + addHandlers(); + + } + + private void addHandlers() { + + buttonEdit.addClickHandler(new ClickHandler() { + + @Override + public void onClick(ClickEvent event) { + SelectResourceByWEMainPanel.eventBus.fireEvent(new EditPublishingResourceEvent(resourceBean)); + + } + }); + + buttonDelete.addClickHandler(new ClickHandler() { + + @Override + public void onClick(ClickEvent event) { + SelectResourceByWEMainPanel.eventBus.fireEvent(new RemovePublishingResourceEvent(resourceBean)); + } + }); + + } + + public ResourceElementBean getResourceBean() { + return resourceBean; } } diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/utils/WorkspaceUtils.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/utils/WorkspaceUtils.java index b11e45f..2330412 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/utils/WorkspaceUtils.java +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/utils/WorkspaceUtils.java @@ -159,7 +159,17 @@ public class WorkspaceUtils { //setting parent id ResourceElementBean theParent = new ResourceElementBean(); - theParent.setOriginalIdInWorkspace(originalFolderOrFile.getParentId()); + + if(originalFolderOrFile.getParentId()!=null) { + try { + WorkspaceItem parentItem = workspace.getItem(originalFolderOrFile.getParentId()); + theParent.setOriginalIdInWorkspace(parentItem.getId()); + theParent.setName(parentItem.getName()); + }catch (Exception e) { + logger.warn("Error on loading the parent item with id: "+originalFolderOrFile.getParentId()+" skipping it"); + } + } + resourceEB.setParent(theParent); bean.setResourceRoot(resourceEB); } From 9e5f98f1ba34d6b37569bda8bce3ed8ab36d4d9b Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Fri, 12 Mar 2021 12:37:40 +0100 Subject: [PATCH 21/44] enhancements --- .../ResourceInfoForm.ui.xml | 118 +++++++-------- .../EditPublishingResourceEvent.java | 62 -------- .../EditPublishingResourceEventHandler.java | 22 --- .../client/ui/workspace/ResourceInfoForm.java | 138 ++++++++++++++++++ .../ui/workspace/ResourceInfoForm.ui.xml | 97 ++++++++++++ .../SelectResourceByWEMainPanel.java | 32 +--- .../SelectResourceByWEMainPanel.ui.xml | 2 +- ...idget.java => SelectedResourceWidget.java} | 53 ++++++- ...t.ui.xml => SelectedResourceWidget.ui.xml} | 13 +- 9 files changed, 351 insertions(+), 186 deletions(-) delete mode 100644 src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/EditPublishingResourceEvent.java delete mode 100644 src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/EditPublishingResourceEventHandler.java create mode 100644 src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/ResourceInfoForm.java create mode 100644 src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/ResourceInfoForm.ui.xml rename src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/{SelectResourceWidget.java => SelectedResourceWidget.java} (55%) rename src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/{SelectResourceWidget.ui.xml => SelectedResourceWidget.ui.xml} (59%) diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/TwinColumnSelection/ResourceInfoForm.ui.xml b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/TwinColumnSelection/ResourceInfoForm.ui.xml index bc64abf..c9d29ce 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/TwinColumnSelection/ResourceInfoForm.ui.xml +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/TwinColumnSelection/ResourceInfoForm.ui.xml @@ -1,7 +1,6 @@ + xmlns:g="urn:import:com.google.gwt.user.client.ui" xmlns:b="urn:import:com.github.gwtbootstrap.client.ui"> .legend-style { width: 100%; @@ -29,68 +28,61 @@ .control-group { margin-bottom: 0px !important; } - - .custom-input { - - } - - - - - - Resource Information - - - - - Name: - - - - - - - - Path: - - - - - - - - Description: - - - - - - - - Format: - - - - - - - - Update - - + + + + + Resource Information + + + + + Name: + + + + + + + + Path: + + + + + + + + Description: + + + + + + + + Format: + + + + + + + + Update + + \ No newline at end of file diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/EditPublishingResourceEvent.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/EditPublishingResourceEvent.java deleted file mode 100644 index 64d292b..0000000 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/EditPublishingResourceEvent.java +++ /dev/null @@ -1,62 +0,0 @@ -package org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.workspace; - -import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.ResourceElementBean; - -import com.google.gwt.event.shared.GwtEvent; - - -// TODO: Auto-generated Javadoc -/** - * The Class EditPublishingResourceEvent. - * - * @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it) - * - * Mar 9, 2021 - */ -public class EditPublishingResourceEvent extends GwtEvent { - - /** The type. */ - public static Type TYPE = new Type(); - - /** The resource. */ - private ResourceElementBean resource; - - - /** - * Instantiates a new edits the publishing resource event. - * - * @param resource the resource - */ - public EditPublishingResourceEvent(ResourceElementBean resource) { - this.resource = resource; - } - - /** - * Gets the resource. - * - * @return the resource - */ - public ResourceElementBean getResource() { - return resource; - } - - /** - * Gets the associated type. - * - * @return the associated type - */ - @Override - public Type getAssociatedType() { - return TYPE; - } - - /** - * Dispatch. - * - * @param handler the handler - */ - @Override - protected void dispatch(EditPublishingResourceEventHandler handler) { - handler.onEditResource(this); - } -} diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/EditPublishingResourceEventHandler.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/EditPublishingResourceEventHandler.java deleted file mode 100644 index 333fa76..0000000 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/EditPublishingResourceEventHandler.java +++ /dev/null @@ -1,22 +0,0 @@ -package org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.workspace; - -import com.google.gwt.event.shared.EventHandler; - - -// TODO: Auto-generated Javadoc -/** - * The Interface EditPublishingResourceEventHandler. - * - * @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it) - * - * Mar 9, 2021 - */ -public interface EditPublishingResourceEventHandler extends EventHandler { - - /** - * On edit resource. - * - * @param editResourceEvent the edit resource event - */ - void onEditResource(EditPublishingResourceEvent editResourceEvent); -} diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/ResourceInfoForm.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/ResourceInfoForm.java new file mode 100644 index 0000000..209cd66 --- /dev/null +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/ResourceInfoForm.java @@ -0,0 +1,138 @@ +package org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.workspace; + +import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.ResourceElementBean; + +import com.github.gwtbootstrap.client.ui.Button; +import com.github.gwtbootstrap.client.ui.ControlGroup; +import com.github.gwtbootstrap.client.ui.TextArea; +import com.github.gwtbootstrap.client.ui.TextBox; +import com.github.gwtbootstrap.client.ui.constants.ControlGroupType; +import com.github.gwtbootstrap.client.ui.constants.IconType; +import com.google.gwt.core.client.GWT; +import com.google.gwt.dom.client.Style.Float; +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.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.HasHorizontalAlignment; +import com.google.gwt.user.client.ui.HorizontalPanel; +import com.google.gwt.user.client.ui.Widget; + +/** + * A resource information form panel + * @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it) + */ +public class ResourceInfoForm extends Composite{ + + @UiField + public TextBox resourceName; + @UiField + public TextBox resourcePath; + @UiField + public TextBox resourceFormat; + @UiField + public TextArea resourceDescription; + @UiField + public Button updateResourceButton; + @UiField + Button closeButton; + @UiField + HorizontalPanel commandPanel; + @UiField + ControlGroup controlName; + + private ResourceElementBean resourceBean; + + private static ResourceInfoFormUiBinder uiBinder = GWT + .create(ResourceInfoFormUiBinder.class); + + interface ResourceInfoFormUiBinder extends + UiBinder { + } + + public ResourceInfoForm(final ResourceElementBean resource) { + initWidget(uiBinder.createAndBindUi(this)); + + resourceBean = resource; + resourceDescription.setText(resource.getDescription()); + resourceFormat.setText(resource.getMimeType() == null? "Unavailable" : resource.getMimeType()); + resourceName.setText(resource.getEditableName()); + resourcePath.setText(resource.getFullPath()); + closeButton.getElement().getStyle().setFloat(Float.RIGHT); + closeButton.setIcon(IconType.REMOVE_CIRCLE); + commandPanel.setCellHorizontalAlignment(updateResourceButton, HasHorizontalAlignment.ALIGN_RIGHT); + commandPanel.getElement().getStyle().setMarginTop(10, Unit.PX); + updateResourceButton.addClickHandler(new ClickHandler() { + + @Override + public void onClick(ClickEvent event) { + resourceBean.setDescription(resourceDescription.getText()); + + removeError(controlName); + String newName = resourceName.getText(); + if(newName == null || newName.isEmpty()){ + showError(controlName); + }else{ + resourceBean.setEditableName(newName); + clearPanel(); + } + } + }); + + closeButton.addClickHandler(new ClickHandler() { + + @Override + public void onClick(ClickEvent event) { + + clearPanel(); + + } + }); + } + + public String getResourceName() { + return resourceName.getText(); + } + + public void setResourceName(String resourceName) { + this.resourceName.setText(resourceName); + } + + public String getResourcePath() { + return resourcePath.getText(); + } + + public void setResourcePath(String resourcePath) { + this.resourcePath.setText(resourcePath); + } + + public String getResourceFormat() { + return resourceFormat.getText(); + } + + public void setResourceFormat(String resourceFormat) { + this.resourceFormat.setText(resourceFormat); + } + + public String getResourceDescription() { + return resourceDescription.getText(); + } + + public void removeError(ControlGroup control) { + control.setType(ControlGroupType.NONE); + } + + public void showError(ControlGroup control) { + control.setType(ControlGroupType.ERROR); + } + + protected void clearPanel() { + this.removeFromParent(); + } + + public ResourceElementBean getResourceBean() { + return resourceBean; + } +} diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/ResourceInfoForm.ui.xml b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/ResourceInfoForm.ui.xml new file mode 100644 index 0000000..762e04d --- /dev/null +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/ResourceInfoForm.ui.xml @@ -0,0 +1,97 @@ + + + + .legend-style { + width: 100%; + padding: 10px; + margin-bottom: 0px; + font-size: 14px; + } + + .panel-style { + padding: 5px; + border: 1px solid #bbb; + border-radius: 5px; + height: 320px; + width: 700px; + margin-left: 70px; + margin-bottom: 20px; + } + + .labels-style { + color: #999; + } + + .controls-style { + margin-left: 10px !important; + } + + .control-group { + margin-bottom: 0px !important; + } + + .custom-input input, textarea { + width: 350px; + } + + + + + + Resource Information + + + + + Name: + + + + + + + + Path: + + + + + + + + Description: + + + + + + + + Format: + + + + + + + + Update + + + + + \ No newline at end of file diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/SelectResourceByWEMainPanel.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/SelectResourceByWEMainPanel.java index b8b20d4..b24596d 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/SelectResourceByWEMainPanel.java +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/SelectResourceByWEMainPanel.java @@ -3,7 +3,6 @@ package org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.workspace; import java.util.HashMap; import java.util.Map; -import org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.TwinColumnSelection.ResourceInfoForm; import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.ResourceElementBean; import org.gcube.portlets.widgets.wsexplorer.client.explore.WorkspaceResourcesExplorerPanel; import org.gcube.portlets.widgets.wsexplorer.client.notification.WorkspaceExplorerSelectNotification.WorskpaceExplorerSelectNotificationListener; @@ -19,7 +18,6 @@ import com.github.gwtbootstrap.client.ui.constants.LabelType; 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.event.dom.client.HasAllDragAndDropHandlers; import com.google.gwt.event.shared.HandlerManager; import com.google.gwt.uibinder.client.UiBinder; import com.google.gwt.uibinder.client.UiField; @@ -72,7 +70,7 @@ public class SelectResourceByWEMainPanel extends Composite { public final static HandlerManager eventBus = new HandlerManager(null); - Map mapSelectedResources = new HashMap(); + Map mapSelectedResources = new HashMap(); /** * The Interface SelectResourceByWEMainPanelUiBinder. @@ -190,35 +188,13 @@ public class SelectResourceByWEMainPanel extends Composite { }); - eventBus.addHandler(EditPublishingResourceEvent.TYPE, new EditPublishingResourceEventHandler() { - - @Override - public void onEditResource(EditPublishingResourceEvent editResourceEvent) { - if(editResourceEvent.getResource()!=null) { - editPublishingResource(editResourceEvent.getResource()); - } - - } - - - }); } - private void editPublishingResource(ResourceElementBean resource) { - - SelectResourceWidget theRW = mapSelectedResources.get(resource.getOriginalIdInWorkspace()); - if(theRW!=null) { - - ResourceInfoForm rif = new ResourceInfoForm(resource, null); - editPanel.add(rif); - } - - } private void removePublishingResource(ResourceElementBean resource) { - SelectResourceWidget theRW = mapSelectedResources.get(resource.getOriginalIdInWorkspace()); + SelectedResourceWidget theRW = mapSelectedResources.get(resource.getOriginalIdInWorkspace()); if(theRW!=null) { selectResourcesContainer.remove(theRW); mapSelectedResources.remove(resource.getOriginalIdInWorkspace()); @@ -229,7 +205,7 @@ public class SelectResourceByWEMainPanel extends Composite { public void addSelectResource(String wsItemId, String name, String path) { - SelectResourceWidget selWidg = mapSelectedResources.get(wsItemId); + SelectedResourceWidget selWidg = mapSelectedResources.get(wsItemId); if (selWidg != null) { showAlertMsg(AlertType.WARNING,"Item '" + name + "' already selected",true); return; @@ -240,7 +216,7 @@ public class SelectResourceByWEMainPanel extends Composite { rb.setName(name); rb.setFullPath(path); rb.setEditableName(name); - selWidg = new SelectResourceWidget(rb); + selWidg = new SelectedResourceWidget(rb); mapSelectedResources.put(wsItemId, selWidg); selectResourcesContainer.add(selWidg); diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/SelectResourceByWEMainPanel.ui.xml b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/SelectResourceByWEMainPanel.ui.xml index 2ab7607..31a4e44 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/SelectResourceByWEMainPanel.ui.xml +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/SelectResourceByWEMainPanel.ui.xml @@ -37,7 +37,7 @@ Publishing Resources - + Nothing diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/SelectResourceWidget.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/SelectedResourceWidget.java similarity index 55% rename from src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/SelectResourceWidget.java rename to src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/SelectedResourceWidget.java index e5d677e..3f111fe 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/SelectResourceWidget.java +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/SelectedResourceWidget.java @@ -10,32 +10,64 @@ import com.google.gwt.event.dom.client.ClickHandler; import com.google.gwt.uibinder.client.UiBinder; import com.google.gwt.uibinder.client.UiField; import com.google.gwt.user.client.ui.Composite; +import com.google.gwt.user.client.ui.HTMLPanel; import com.google.gwt.user.client.ui.Label; import com.google.gwt.user.client.ui.Widget; -public class SelectResourceWidget extends Composite { +/** + * The Class SelectResourceWidget. + * + * @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it) + * + * Mar 12, 2021 + */ +public class SelectedResourceWidget extends Composite { - private static SelectResourceWidgetUiBinder uiBinder = GWT.create(SelectResourceWidgetUiBinder.class); + /** The ui binder. */ + private static SelectedResourceWidgetUiBinder uiBinder = GWT.create(SelectedResourceWidgetUiBinder.class); - interface SelectResourceWidgetUiBinder extends UiBinder { + /** + * The Interface SelectResourceWidgetUiBinder. + * + * @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it) + * + * Mar 12, 2021 + */ + interface SelectedResourceWidgetUiBinder extends UiBinder { } - public SelectResourceWidget() { + /** + * Instantiates a new select resource widget. + */ + public SelectedResourceWidget() { initWidget(uiBinder.createAndBindUi(this)); } + /** The button delete. */ @UiField Button buttonDelete; + /** The button edit. */ @UiField Button buttonEdit; + /** The field name. */ @UiField Label fieldName; + + /** The edit panel. */ + @UiField + HTMLPanel editPanel; + /** The resource bean. */ private ResourceElementBean resourceBean; - public SelectResourceWidget(ResourceElementBean rb) { + /** + * Instantiates a new select resource widget. + * + * @param rb the rb + */ + public SelectedResourceWidget(ResourceElementBean rb) { initWidget(uiBinder.createAndBindUi(this)); this.resourceBean = rb; @@ -50,14 +82,18 @@ public class SelectResourceWidget extends Composite { } + /** + * Adds the handlers. + */ private void addHandlers() { buttonEdit.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { - SelectResourceByWEMainPanel.eventBus.fireEvent(new EditPublishingResourceEvent(resourceBean)); + ResourceInfoForm rif = new ResourceInfoForm(resourceBean); + editPanel.add(rif); } }); @@ -71,6 +107,11 @@ public class SelectResourceWidget extends Composite { } + /** + * Gets the resource bean. + * + * @return the resource bean + */ public ResourceElementBean getResourceBean() { return resourceBean; } diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/SelectResourceWidget.ui.xml b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/SelectedResourceWidget.ui.xml similarity index 59% rename from src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/SelectResourceWidget.ui.xml rename to src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/SelectedResourceWidget.ui.xml index 141a063..50e7a49 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/SelectResourceWidget.ui.xml +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/SelectedResourceWidget.ui.xml @@ -6,7 +6,9 @@ .important { font-weight: bold; } + .selected-resources { + } .selected-resources td { @@ -14,10 +16,13 @@ } - - - + + + - + + \ No newline at end of file From 5656ab218b3cf52e41d0666e883038756325d449 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Mon, 15 Mar 2021 10:15:28 +0100 Subject: [PATCH 22/44] in progress on revisiting "Manage Resources" --- CHANGELOG.md | 1 + .../client/ui/utils/InfoIconsLabels.java | 4 +- .../client/ui/workspace/ResourceInfoForm.java | 1 + .../ui/workspace/ResourceInfoForm.ui.xml | 9 ++- .../SelectResourceByWEMainPanel.java | 79 ++++++++++++------- .../SelectResourceByWEMainPanel.ui.xml | 13 +-- .../ui/workspace/SelectedResourceWidget.java | 34 +++++--- .../workspace/SelectedResourceWidget.ui.xml | 26 +++++- .../public/CKanMetadataPublisher.css | 4 + 9 files changed, 114 insertions(+), 57 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index de2e2f4..16cc007 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm [#20680] Ported to SHUB [#19568] Unify and extend the tags allowed values [#20828] Revisited title size and format +[#20868] Redesigned the "Manage Resources" user experience ## [v1.6.2] - 2021-02-08 diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/utils/InfoIconsLabels.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/utils/InfoIconsLabels.java index 7f3f316..ebe779f 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/utils/InfoIconsLabels.java +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/utils/InfoIconsLabels.java @@ -70,8 +70,8 @@ public class InfoIconsLabels { // RESOURCES public static final String RESOURCES_INFO_ID_POPUP = "resouces-popup-panel-info"; public static final String RESOURCES_INFO_CAPTION = "Manage resource items"; - public static final String RESOURCES_INFO_TEXT = "Select the files you want to attach to the publishing item. Click on 'Trash' to remote it. Click on 'Edit' for changing resource's name or description." - + " You can add others files by using the 'Add files from...' facility. To navigate a folder perform a 'double click' on it. Please consider that any complex hierarchy structure you may have will be flatten."; + public static final String RESOURCES_INFO_TEXT = "Select the files you want to attach to the publishing item. Click on 'Pencil' for changing resource's name or description. Click on 'Trash' to remove the resource." + + " You can add others files by using the 'Add files from...' facility: (i) to navigate a folder perform a 'double click' on it; (ii) to choose a file select it and press 'Select'. Please consider that any complex hierarchy structure you may have will be flatten."; // CUSTOM FIELDS public static final String CUSTOM_FIELDS_INFO_ID_POPUP = "custom-fields-popup-panel-info"; diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/ResourceInfoForm.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/ResourceInfoForm.java index 209cd66..3e35839 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/ResourceInfoForm.java +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/ResourceInfoForm.java @@ -75,6 +75,7 @@ public class ResourceInfoForm extends Composite{ if(newName == null || newName.isEmpty()){ showError(controlName); }else{ + resourceBean.setName(newName); resourceBean.setEditableName(newName); clearPanel(); } diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/ResourceInfoForm.ui.xml b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/ResourceInfoForm.ui.xml index 762e04d..98c045c 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/ResourceInfoForm.ui.xml +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/ResourceInfoForm.ui.xml @@ -16,7 +16,6 @@ border-radius: 5px; height: 320px; width: 700px; - margin-left: 70px; margin-bottom: 20px; } @@ -32,9 +31,13 @@ margin-bottom: 0px !important; } - .custom-input input, textarea { + .custom-input input { width: 350px; } + + .custom-input textarea { + width: 355px; + } @@ -71,7 +74,7 @@ Description: - diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/SelectResourceByWEMainPanel.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/SelectResourceByWEMainPanel.java index b24596d..0e5a287 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/SelectResourceByWEMainPanel.java +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/SelectResourceByWEMainPanel.java @@ -1,6 +1,8 @@ package org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.workspace; +import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import java.util.Map; import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.ResourceElementBean; @@ -22,8 +24,8 @@ import com.google.gwt.event.shared.HandlerManager; import com.google.gwt.uibinder.client.UiBinder; import com.google.gwt.uibinder.client.UiField; import com.google.gwt.user.client.Timer; -import com.google.gwt.user.client.Window; import com.google.gwt.user.client.ui.Composite; +import com.google.gwt.user.client.ui.FlowPanel; import com.google.gwt.user.client.ui.HTMLPanel; import com.google.gwt.user.client.ui.VerticalPanel; import com.google.gwt.user.client.ui.Widget; @@ -41,12 +43,14 @@ public class SelectResourceByWEMainPanel extends Composite { private static SelectResourceByWEMainPanelUiBinder uiBinder = GWT.create(SelectResourceByWEMainPanelUiBinder.class); private static boolean frozen = false; + private final ResourceElementBean initialBean; @UiField VerticalPanel wsContainer; + @UiField - VerticalPanel selectResourcesContainer; + FlowPanel selectResourcesContainer; @UiField Alert showAlert; @@ -63,14 +67,11 @@ public class SelectResourceByWEMainPanel extends Composite { @UiField Label labelNothing; - @UiField - HTMLPanel editPanel; - private Item selectedWEItem; public final static HandlerManager eventBus = new HandlerManager(null); - Map mapSelectedResources = new HashMap(); + private Map mapSelectedResources = new HashMap(); /** * The Interface SelectResourceByWEMainPanelUiBinder. @@ -147,9 +148,9 @@ public class SelectResourceByWEMainPanel extends Composite { containerPickResources.setVisible(false); } - if(rootName!=null) { - buttPickResources.setHeading("Add files from "+rootName); - } +// if(rootName!=null) { +// buttPickResources.setHeading("Add files from "+rootName); +// } } catch (Exception e) { @@ -157,7 +158,7 @@ public class SelectResourceByWEMainPanel extends Composite { } if(!initialBean.isFolder()) { - addSelectResource(initialBean.getOriginalIdInWorkspace(), initialBean.getName(),initialBean.getFullPath()); + addSelectResource(initialBean.getOriginalIdInWorkspace(), initialBean.getName(),initialBean.getFullPath(), initialBean.isFolder()); } addHandlers(); @@ -171,7 +172,7 @@ public class SelectResourceByWEMainPanel extends Composite { @Override public void onClick(ClickEvent event) { if(selectedWEItem!=null && !selectedWEItem.isFolder()) { - addSelectResource(selectedWEItem.getId(), selectedWEItem.getName(), selectedWEItem.getPath()); + addSelectResource(selectedWEItem.getId(), selectedWEItem.getName(), selectedWEItem.getPath(), selectedWEItem.isFolder()); } } @@ -203,7 +204,7 @@ public class SelectResourceByWEMainPanel extends Composite { showNothingResourceSelected(); } - public void addSelectResource(String wsItemId, String name, String path) { + public void addSelectResource(String wsItemId, String name, String path, boolean isFolder) { SelectedResourceWidget selWidg = mapSelectedResources.get(wsItemId); if (selWidg != null) { @@ -216,6 +217,7 @@ public class SelectResourceByWEMainPanel extends Composite { rb.setName(name); rb.setFullPath(path); rb.setEditableName(name); + rb.setFolder(isFolder); selWidg = new SelectedResourceWidget(rb); mapSelectedResources.put(wsItemId, selWidg); @@ -251,32 +253,49 @@ public class SelectResourceByWEMainPanel extends Composite { } } - public ResourceElementBean getResourcesToPublish() { - // TODO Auto-generated method stub - Window.alert("getResourcesToPublish() must be implemented"); + + + public void freeze() { - /*List current = dataProviderRight.getList(); + GWT.log("called freeze into selected resources"); + frozen = true; + selectResourcesContainer.getElement().setAttribute("disabled", "disabled"); + containerPickResources.getElement().setAttribute("disabled", "disabled"); + //buttPickResources.getElement().getStyle().setProperty("pointer-events","none"); + buttSelectResource.setEnabled(false); + + } + + + /** + * Returns the root parent with the children as files to save + * @return the resources to save + */ + public ResourceElementBean getResourcesToPublish(){ ResourceElementBean toReturn = new ResourceElementBean(); List children = new ArrayList(); - - for (ResourceElementBean resource : current) { - if(resource.isToBeAdded() && !resource.isFolder()){ // be sure ... - ResourceElementBean beanWithoutChildren = new ResourceElementBean(resource); - beanWithoutChildren.setName(resource.getEditableName()); - children.add(beanWithoutChildren); + + for (String wsItemId : mapSelectedResources.keySet()) { + SelectedResourceWidget selecWC = mapSelectedResources.get(wsItemId); + ResourceElementBean theResource = selecWC.getResourceBean(); + + if(!theResource.isFolder()){ // be sure ... + children.add(theResource); } + } - - toReturn.setToPublish(children); - return toReturn;*/ - return null; - + return toReturn; } - public void freeze() { - // TODO Auto-generated method stub - Window.alert("freeze() must be implemented"); + + /** + * @return the freezed + */ + public static boolean isFroozen() { + + return frozen; } + } diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/SelectResourceByWEMainPanel.ui.xml b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/SelectResourceByWEMainPanel.ui.xml index 31a4e44..b4a21ec 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/SelectResourceByWEMainPanel.ui.xml +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/SelectResourceByWEMainPanel.ui.xml @@ -20,10 +20,6 @@ overflow-y: auto; } - .no-border { - border: 0px !important; - } - .margin-top-10 { margin-top: 10px; } @@ -37,18 +33,17 @@ Publishing Resources - + Nothing - - - + + addStyleNames="accordion-no-border-inner"> diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/SelectedResourceWidget.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/SelectedResourceWidget.java index 3f111fe..a14888b 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/SelectedResourceWidget.java +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/SelectedResourceWidget.java @@ -53,7 +53,10 @@ public class SelectedResourceWidget extends Composite { /** The field name. */ @UiField - Label fieldName; + com.github.gwtbootstrap.client.ui.Label fieldName; + + @UiField + Label fieldDescription; /** The edit panel. */ @UiField @@ -69,19 +72,24 @@ public class SelectedResourceWidget extends Composite { */ public SelectedResourceWidget(ResourceElementBean rb) { initWidget(uiBinder.createAndBindUi(this)); - - this.resourceBean = rb; - - this.fieldName.setText(rb.getEditableName()); - buttonEdit.setType(ButtonType.LINK); - buttonDelete.setType(ButtonType.LINK); - + this.resourceBean = rb; + updateFields(); addHandlers(); } + private void updateFields() { + this.fieldName.setText(resourceBean.getEditableName()); + + if(resourceBean.getDescription()!=null && !resourceBean.getDescription().isEmpty()) { + this.fieldDescription.setVisible(true); + this.fieldDescription.setText(resourceBean.getDescription()); + }else + this.fieldDescription.setVisible(false); + } + /** * Adds the handlers. */ @@ -91,9 +99,15 @@ public class SelectedResourceWidget extends Composite { @Override public void onClick(ClickEvent event) { + editPanel.clear(); + ResourceInfoForm resourceInformationInfo = new ResourceInfoForm(resourceBean) { + protected void onUnload() { + super.onUnload(); + updateFields(); + }; + }; + editPanel.add(resourceInformationInfo); - ResourceInfoForm rif = new ResourceInfoForm(resourceBean); - editPanel.add(rif); } }); diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/SelectedResourceWidget.ui.xml b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/SelectedResourceWidget.ui.xml index 50e7a49..3b0c9d4 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/SelectedResourceWidget.ui.xml +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/SelectedResourceWidget.ui.xml @@ -14,14 +14,34 @@ .selected-resources td { vertical-align: middle !important; } + + .margin-bottom-8 { + margin-bottom: 8px; + } + + .descr-text { + font-style: italic; + padding-left: 105px; + font-size: 12px; + } + + .icon-my-style { + font-size: 1.2em; + margin-right: 10px; + margin-left: 10px; + vertical-align: middle; + } - + + + - + diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/public/CKanMetadataPublisher.css b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/public/CKanMetadataPublisher.css index 14475b3..8d0bdc6 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/public/CKanMetadataPublisher.css +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/public/CKanMetadataPublisher.css @@ -49,4 +49,8 @@ .GeoJson-DialogBox{ width: 100% !important; +} + +.accordion-no-border-inner .accordion-inner { + border: 0px; } \ No newline at end of file From e4b8d6c276e80210742302e03b7bf8bb0accca9c Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Mon, 15 Mar 2021 15:45:09 +0100 Subject: [PATCH 23/44] Added Wizard with list of Steps --- .../client/ui/form/CreateDatasetForm.java | 46 ++++- .../client/ui/form/CreateDatasetForm.ui.xml | 1 + .../client/ui/utils/WizardCreator.java | 159 ++++++++++++++++++ .../client/ui/utils/WizardCreator.ui.xml | 10 ++ .../SelectResourceByWEMainPanel.ui.xml | 2 +- .../workspace/SelectedResourceWidget.ui.xml | 2 +- .../public/CKanMetadataPublisher.css | 76 ++++++++- 7 files changed, 289 insertions(+), 7 deletions(-) create mode 100644 src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/utils/WizardCreator.java create mode 100644 src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/utils/WizardCreator.ui.xml diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/form/CreateDatasetForm.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/form/CreateDatasetForm.java index b93f95f..776e42b 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/form/CreateDatasetForm.java +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/form/CreateDatasetForm.java @@ -1,6 +1,7 @@ package org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.form; import java.util.ArrayList; +import java.util.Arrays; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; @@ -23,6 +24,7 @@ import org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.resources.Ad import org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.resources.AddedResourcesSummary; import org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.tags.TagsPanel; import org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.utils.InfoIconsLabels; +import org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.utils.WizardCreator; import org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.workspace.SelectResourceByWEMainPanel; import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.DatasetBean; import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.OrganizationBean; @@ -163,6 +165,8 @@ public class CreateDatasetForm extends Composite{ @UiField ControlGroup versionControlGroup; @UiField ControlGroup organizationsGroup; @UiField ControlGroup groupsControlGroup; + + @UiField HTMLPanel wizardCreatorPanel; // Create a remote service proxy to talk to the server-side ckan service. private final CKanPublisherServiceAsync ckanServices = GWT.create(CKanPublisherService.class); @@ -215,6 +219,7 @@ public class CreateDatasetForm extends Composite{ // map of organization name title private Map nameTitleOrganizationMap = new HashMap(); + private WizardCreator wizCreator; /** * Invoked in the most general case @@ -268,6 +273,18 @@ public class CreateDatasetForm extends Composite{ initWidget(uiBinder.createAndBindUi(this)); this.eventBus = eventBus; this.isWorkspaceRequest = isWorkspaceRequest; + + List listOfSteps = null; + if(isWorkspaceRequest) { + listOfSteps = Arrays.asList("Insert Base Information","Select Item Resources", "Insert Profile Information and Publish"); + }else { + listOfSteps = Arrays.asList("Insert Base Information", "Insert Profile Information and Publish"); + } + + this.wizCreator = new WizardCreator(listOfSteps); + wizardCreatorPanel.add(wizCreator); + + bind(); prepareInfoIcons(); @@ -854,8 +871,17 @@ public class CreateDatasetForm extends Composite{ // we need to show the page to handle resources one by one from the workspace formFirstStep.setVisible(false); - formSecondStep.setVisible(!hideManageResources()); - formThirdStep.setVisible(hideManageResources()); + boolean hideManageRes = hideManageResources(); + int stepActive = -1; + if(hideManageRes) { + stepActive = 3; + }else { + stepActive = 2; + } + + formSecondStep.setVisible(!hideManageRes); + formThirdStep.setVisible(hideManageRes); + wizCreator.activeStep(stepActive); // add the resources to the container panel if(workspaceResourcesContainer.getWidget() == null){ @@ -868,6 +894,7 @@ public class CreateDatasetForm extends Composite{ // this is not a workspace request formFirstStep.setVisible(false); formThirdStep.setVisible(true); + wizCreator.activeStep(3); } @@ -884,6 +911,7 @@ public class CreateDatasetForm extends Composite{ // swap forms formFirstStep.setVisible(true); + wizCreator.activeStep(1); formSecondStep.setVisible(false); formThirdStep.setVisible(false); @@ -895,9 +923,18 @@ public class CreateDatasetForm extends Composite{ // swap forms if(isWorkspaceRequest){ - formFirstStep.setVisible(hideManageResources()); - formSecondStep.setVisible(!hideManageResources()); + boolean hideManageRes = hideManageResources(); + int stepActive = -1; + if(hideManageRes) { + stepActive = 1; + }else { + stepActive = 2; + } + formFirstStep.setVisible(hideManageRes); + formSecondStep.setVisible(!hideManageRes); + wizCreator.activeStep(stepActive); }else{ + wizCreator.activeStep(1); formFirstStep.setVisible(true); formSecondStep.setVisible(false); } @@ -911,6 +948,7 @@ public class CreateDatasetForm extends Composite{ // swap forms formSecondStep.setVisible(false); formThirdStep.setVisible(true); + wizCreator.activeStep(3); } diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/form/CreateDatasetForm.ui.xml b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/form/CreateDatasetForm.ui.xml index d22c431..eb22060 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/form/CreateDatasetForm.ui.xml +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/form/CreateDatasetForm.ui.xml @@ -50,6 +50,7 @@ } + diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/utils/WizardCreator.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/utils/WizardCreator.java new file mode 100644 index 0000000..f7f267b --- /dev/null +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/utils/WizardCreator.java @@ -0,0 +1,159 @@ +package org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.utils; + +import java.util.ArrayList; +import java.util.List; + +import org.gcube.portlets.widgets.ckandatapublisherwidget.client.openlayerwidget.GeoJsonAreaSelectionDialog; +import org.gcube.portlets.widgets.openlayerbasicwidgets.client.widgets.GeometryType; + +import com.google.gwt.core.client.GWT; +import com.google.gwt.core.client.Scheduler; +import com.google.gwt.core.client.Scheduler.ScheduledCommand; +import com.google.gwt.dom.client.Element; +import com.google.gwt.dom.client.NodeList; +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.HTML; +import com.google.gwt.user.client.ui.HTMLPanel; +import com.google.gwt.user.client.ui.Widget; + +/** + * The Class WizardCreator. + * + * @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it) + * + * Mar 15, 2021 + */ +public class WizardCreator extends Composite { + + /** The ui binder. */ + private static WizardCreatorUiBinder uiBinder = GWT.create(WizardCreatorUiBinder.class); + + /** + * The Interface WizardCreatorUiBinder. + * + * @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it) + * + * Mar 15, 2021 + */ + interface WizardCreatorUiBinder extends UiBinder { + } + + /** The title of steps. */ + private List titleOfSteps; + + /** The html steps. */ + private List htmlSteps; + + /** The wizard container. */ + @UiField + HTMLPanel theWizardContainer; + + + /** + * Instantiates a new wizard creator. + * + * @param titleOfSteps the title of steps + */ + public WizardCreator(List titleOfSteps) { + initWidget(uiBinder.createAndBindUi(this)); + this.titleOfSteps = titleOfSteps; + createSteps(); + } + + + /** + * Creates the steps. + */ + private void createSteps() { + + if(titleOfSteps==null) + return; + + int i = 1; + htmlSteps = new ArrayList<>(titleOfSteps.size()); + for (String step : titleOfSteps) { + HTML toHML = createStep(i, step); + htmlSteps.add(toHML); + theWizardContainer.add(toHML); + i++; + } + + + Scheduler.get().scheduleDeferred(new ScheduledCommand() { + @Override + public void execute() { + activeStep(1); + } + }); + } + + /** + * Active step. + * + * @param stepNumber the step number + */ + public void activeStep(int stepNumber) { + disableAllBadge(); + + int index = stepNumber-1; + if(index>=0) { + HTML html = htmlSteps.get(index); + html.getElement().addClassName("current"); +// NodeList spans = html.getElement().getElementsByTagName("span"); +// if(spans!=null && spans.getLength()>0) { +// Element el = spans.getItem(0); +// el.addClassName("badge-inverse"); +// } + } + } + + private void disableAllBadge() { + for (HTML html : htmlSteps) { + html.getElement().removeClassName("current"); +// NodeList spans = html.getElement().getElementsByTagName("span"); +// if(spans!=null && spans.getLength()>0) { +// Element el = spans.getItem(0); +// el.removeClassName("badge-inverse"); +// } + } + + } + + + /** + * Creates the step. + * + * @param stepNumber the step number + * @param stepTitle the step title + * @return the string + */ + private HTML createStep(int stepNumber, String stepTitle) { + + StringBuilder builder = new StringBuilder(); + builder.append(""); + builder.append(stepNumber+"."); + builder.append(""); + builder.append(" "+stepTitle); + + + return new HTML(builder.toString()); + + } + + public static class HTMLNoDiv extends HTML{ + + public static HTML noDiv(String theHtml) { + HTML html = new HTML() { + + }; + + html.setHTML(theHtml); + return html; + } + } + + + +} diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/utils/WizardCreator.ui.xml b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/utils/WizardCreator.ui.xml new file mode 100644 index 0000000..4c5ed16 --- /dev/null +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/utils/WizardCreator.ui.xml @@ -0,0 +1,10 @@ + + + + + + + \ No newline at end of file diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/SelectResourceByWEMainPanel.ui.xml b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/SelectResourceByWEMainPanel.ui.xml index b4a21ec..13b4395 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/SelectResourceByWEMainPanel.ui.xml +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/SelectResourceByWEMainPanel.ui.xml @@ -31,7 +31,7 @@ - Publishing Resources + Select Item Resources diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/SelectedResourceWidget.ui.xml b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/SelectedResourceWidget.ui.xml index 3b0c9d4..b6e3419 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/SelectedResourceWidget.ui.xml +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/SelectedResourceWidget.ui.xml @@ -34,7 +34,7 @@ - + Date: Mon, 15 Mar 2021 16:03:05 +0100 Subject: [PATCH 24/44] removed tests --- .../ckandatapublisherwidget/client/CKanMetadataPublisher.java | 2 +- .../client/ui/workspace/SelectResourceByWEMainPanel.ui.xml | 2 +- .../widgets/ckandatapublisherwidget/TestPublishingWidget.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/CKanMetadataPublisher.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/CKanMetadataPublisher.java index c75ec32..e03381e 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/CKanMetadataPublisher.java +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/CKanMetadataPublisher.java @@ -52,7 +52,7 @@ public class CKanMetadataPublisher implements EntryPoint { //testSpatialWidget(); - testManageResources(); + //testManageResources(); } diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/SelectResourceByWEMainPanel.ui.xml b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/SelectResourceByWEMainPanel.ui.xml index 13b4395..c9a42e0 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/SelectResourceByWEMainPanel.ui.xml +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/SelectResourceByWEMainPanel.ui.xml @@ -35,7 +35,7 @@ - Nothing + no file selected diff --git a/src/test/java/org/gcube/portlets/widgets/ckandatapublisherwidget/TestPublishingWidget.java b/src/test/java/org/gcube/portlets/widgets/ckandatapublisherwidget/TestPublishingWidget.java index dcfc06c..0e85a4e 100644 --- a/src/test/java/org/gcube/portlets/widgets/ckandatapublisherwidget/TestPublishingWidget.java +++ b/src/test/java/org/gcube/portlets/widgets/ckandatapublisherwidget/TestPublishingWidget.java @@ -63,7 +63,7 @@ public class TestPublishingWidget { } - @Test + //@Test public void getDatasetBeanTest() throws Exception{ ScopeProvider.instance.set(scope); String userName = testUser; From 4a102a4a0cd89c6e3f38f6e2b2c7205730407891 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Mon, 15 Mar 2021 16:35:42 +0100 Subject: [PATCH 25/44] updated step wizard select --- pom.xml | 1 + .../client/ui/form/CreateDatasetForm.java | 20 +++++++++++++------ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/pom.xml b/pom.xml index 1f21d3d..cbf524e 100644 --- a/pom.xml +++ b/pom.xml @@ -153,6 +153,7 @@ org.gcube.portlets.widgets workspace-explorer [2.0.0, 3.0.0-SNAPSHOT) + compile org.gcube.portlets.user diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/form/CreateDatasetForm.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/form/CreateDatasetForm.java index 776e42b..81e0a92 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/form/CreateDatasetForm.java +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/form/CreateDatasetForm.java @@ -219,6 +219,7 @@ public class CreateDatasetForm extends Composite{ // map of organization name title private Map nameTitleOrganizationMap = new HashMap(); + private WizardCreator wizCreator; /** @@ -881,7 +882,7 @@ public class CreateDatasetForm extends Composite{ formSecondStep.setVisible(!hideManageRes); formThirdStep.setVisible(hideManageRes); - wizCreator.activeStep(stepActive); + activeWizardStep(stepActive); // add the resources to the container panel if(workspaceResourcesContainer.getWidget() == null){ @@ -894,7 +895,7 @@ public class CreateDatasetForm extends Composite{ // this is not a workspace request formFirstStep.setVisible(false); formThirdStep.setVisible(true); - wizCreator.activeStep(3); + activeWizardStep(3); } @@ -904,6 +905,12 @@ public class CreateDatasetForm extends Composite{ selectedProfile.setText("Selected Type is " + metadataTypeListbox.getSelectedItemText()); } + + private void activeWizardStep(int step) { + if(wizCreator!=null) { + wizCreator.activeStep(step); + } + } @UiHandler("goBackButtonFirstStep") @@ -911,7 +918,7 @@ public class CreateDatasetForm extends Composite{ // swap forms formFirstStep.setVisible(true); - wizCreator.activeStep(1); + activeWizardStep(1); formSecondStep.setVisible(false); formThirdStep.setVisible(false); @@ -932,11 +939,12 @@ public class CreateDatasetForm extends Composite{ } formFirstStep.setVisible(hideManageRes); formSecondStep.setVisible(!hideManageRes); - wizCreator.activeStep(stepActive); + activeWizardStep(stepActive); }else{ - wizCreator.activeStep(1); + formFirstStep.setVisible(true); formSecondStep.setVisible(false); + activeWizardStep(1); } formThirdStep.setVisible(false); @@ -948,7 +956,7 @@ public class CreateDatasetForm extends Composite{ // swap forms formSecondStep.setVisible(false); formThirdStep.setVisible(true); - wizCreator.activeStep(3); + activeWizardStep(3); } From fa950e4d3ee3387f787103d569cc8c9c5d55de8e Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Thu, 18 Mar 2021 10:06:43 +0100 Subject: [PATCH 26/44] added workspace-explorer in the web.xml --- .../CKanMetadataPublisher.gwt.xml | 16 ++++++---------- .../CKanMetadataPublisher.gwt.xml | 16 ++++++---------- src/main/webapp/WEB-INF/web.xml | 10 ++++++++++ 3 files changed, 22 insertions(+), 20 deletions(-) diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/CKanMetadataPublisher.gwt.xml b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/CKanMetadataPublisher.gwt.xml index 7322fbe..2269409 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/CKanMetadataPublisher.gwt.xml +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/CKanMetadataPublisher.gwt.xml @@ -6,17 +6,13 @@ - - + + - - - - + + + + diff --git a/src/main/resources/org/gcube/portlets/widgets/ckandatapublisherwidget/CKanMetadataPublisher.gwt.xml b/src/main/resources/org/gcube/portlets/widgets/ckandatapublisherwidget/CKanMetadataPublisher.gwt.xml index 7322fbe..2269409 100644 --- a/src/main/resources/org/gcube/portlets/widgets/ckandatapublisherwidget/CKanMetadataPublisher.gwt.xml +++ b/src/main/resources/org/gcube/portlets/widgets/ckandatapublisherwidget/CKanMetadataPublisher.gwt.xml @@ -6,17 +6,13 @@ - - + + - - - - + + + + diff --git a/src/main/webapp/WEB-INF/web.xml b/src/main/webapp/WEB-INF/web.xml index 1f5a954..79df877 100644 --- a/src/main/webapp/WEB-INF/web.xml +++ b/src/main/webapp/WEB-INF/web.xml @@ -11,11 +11,21 @@ org.gcube.portlets.widgets.ckandatapublisherwidget.server.CKANPublisherServicesImpl + + workspaceExplorer + org.gcube.portlets.widgets.wsexplorer.server.WorkspaceExplorerServiceImpl + + ckanpublisherservices /CKanMetadataPublisher/ckanservices + + workspaceExplorer + /CKanMetadataPublisher/WorkspaceExplorerService + + From 1d0caf6c17ace0058d4fbcf3c91b4ba2b94b0a63 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Thu, 18 Mar 2021 12:06:47 +0100 Subject: [PATCH 27/44] removed unused import --- .classpath | 8 +------- .../client/ui/utils/WizardCreator.java | 5 ----- 2 files changed, 1 insertion(+), 12 deletions(-) diff --git a/.classpath b/.classpath index 5fe0d51..510cf3c 100644 --- a/.classpath +++ b/.classpath @@ -6,13 +6,7 @@ - - - - - - - + diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/utils/WizardCreator.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/utils/WizardCreator.java index f7f267b..6db7cae 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/utils/WizardCreator.java +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/utils/WizardCreator.java @@ -3,14 +3,9 @@ package org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.utils; import java.util.ArrayList; import java.util.List; -import org.gcube.portlets.widgets.ckandatapublisherwidget.client.openlayerwidget.GeoJsonAreaSelectionDialog; -import org.gcube.portlets.widgets.openlayerbasicwidgets.client.widgets.GeometryType; - import com.google.gwt.core.client.GWT; import com.google.gwt.core.client.Scheduler; import com.google.gwt.core.client.Scheduler.ScheduledCommand; -import com.google.gwt.dom.client.Element; -import com.google.gwt.dom.client.NodeList; import com.google.gwt.uibinder.client.UiBinder; import com.google.gwt.uibinder.client.UiField; import com.google.gwt.user.client.ui.Composite; From 5b2831f5dc07e8c3de0da5670816af54d098e1a0 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Thu, 18 Mar 2021 16:03:06 +0100 Subject: [PATCH 28/44] just fixed the format --- .../ckandatapublisherwidget/CKanMetadataPublisher.gwt.xml | 6 ++---- .../ckandatapublisherwidget/CKanMetadataPublisher.gwt.xml | 6 ++---- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/CKanMetadataPublisher.gwt.xml b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/CKanMetadataPublisher.gwt.xml index 2269409..55363b4 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/CKanMetadataPublisher.gwt.xml +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/CKanMetadataPublisher.gwt.xml @@ -14,11 +14,9 @@ - + - + - + - + Date: Fri, 19 Mar 2021 11:28:12 +0100 Subject: [PATCH 29/44] replaced wizard css class name with wizard-creator --- .../client/ui/utils/WizardCreator.ui.xml | 2 +- .../public/CKanMetadataPublisher.css | 26 +++++++++---------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/utils/WizardCreator.ui.xml b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/utils/WizardCreator.ui.xml index 4c5ed16..68c8844 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/utils/WizardCreator.ui.xml +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/utils/WizardCreator.ui.xml @@ -3,7 +3,7 @@ xmlns:g="urn:import:com.google.gwt.user.client.ui" xmlns:b="urn:import:com.github.gwtbootstrap.client.ui"> - diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/public/CKanMetadataPublisher.css b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/public/CKanMetadataPublisher.css index f19ca4b..9b14018 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/public/CKanMetadataPublisher.css +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/public/CKanMetadataPublisher.css @@ -56,16 +56,16 @@ } -/* WIZARD CLASSES */ +/* WIZARD-CREATOR CLASSES */ -.wizard { +.wizard-creator { width: 100%; border-spacing: 6px; border-collapse: separate; display: table; } -.wizard div { +.wizard-creator div { padding: 10px 12px 10px; background: #efefef; position: relative; @@ -73,7 +73,7 @@ display: table-cell; } -.wizard div:before { +.wizard-creator div:before { width: 0; height: 0; border-top: 20px inset transparent; @@ -85,7 +85,7 @@ left: 0; } -.wizard div:after { +.wizard-creator div:after { width: 0; height: 0; border-top: 20px inset transparent; @@ -98,33 +98,33 @@ z-index: 2; } -.wizard div:first-child:before, -.wizard div:last-child:after { +.wizard-creator div:first-child:before, +.wizard-creator div:last-child:after { border: none; } -.wizard div:first-child { +.wizard-creator div:first-child { border-radius: 4px 0 0 4px; } -.wizard div:last-child { +.wizard-creator div:last-child { border-radius: 0 4px 4px 0; } -.wizard .badge-wiz { +.wizard-creator .badge-wiz { margin: 0 5px 0 18px; } -.wizard div:first-child .badge { +.wizard-creator div:first-child .badge { margin-left: 0; } -.wizard .current { +.wizard-creator .current { background: #007ACC; color: #fff; } -.wizard .current:after { +.wizard-creator .current:after { border-left-color: #007ACC; } From 475d74228bca57d93c1ce0f16de0de57fdbc0ca6 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Fri, 19 Mar 2021 14:42:16 +0100 Subject: [PATCH 30/44] bug fixing --- .../client/ui/form/CreateDatasetForm.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/form/CreateDatasetForm.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/form/CreateDatasetForm.java index 81e0a92..082a95f 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/form/CreateDatasetForm.java +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/form/CreateDatasetForm.java @@ -279,7 +279,7 @@ public class CreateDatasetForm extends Composite{ if(isWorkspaceRequest) { listOfSteps = Arrays.asList("Insert Base Information","Select Item Resources", "Insert Profile Information and Publish"); }else { - listOfSteps = Arrays.asList("Insert Base Information", "Insert Profile Information and Publish"); + listOfSteps = Arrays.asList("Insert Base Information", "Insert Profile Information and Publish", "Add Resources"); } this.wizCreator = new WizardCreator(listOfSteps); @@ -895,7 +895,7 @@ public class CreateDatasetForm extends Composite{ // this is not a workspace request formFirstStep.setVisible(false); formThirdStep.setVisible(true); - activeWizardStep(3); + activeWizardStep(2); } From b8b94a58e45c070b03c5a5d05f65c8b5c7c5ce15 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Fri, 19 Mar 2021 17:39:48 +0100 Subject: [PATCH 31/44] bug fixing resouces to publish --- .../client/ui/form/CreateDatasetForm.java | 3 ++- .../ui/workspace/SelectResourceByWEMainPanel.java | 6 +++++- .../server/utils/WorkspaceUtils.java | 14 ++++++++++++-- .../shared/ResourceElementBean.java | 2 +- 4 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/form/CreateDatasetForm.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/form/CreateDatasetForm.java index 082a95f..9a880c8 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/form/CreateDatasetForm.java +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/form/CreateDatasetForm.java @@ -1074,8 +1074,9 @@ public class CreateDatasetForm extends Composite{ receivedBean.setGroupsForceCreation(groupsToForceCreation); - if(resourcesSelectByWEMainPanel != null) + if(resourcesSelectByWEMainPanel != null) { receivedBean.setResourceRoot(resourcesSelectByWEMainPanel.getResourcesToPublish()); + } receivedBean.setCustomFields(customFieldsMap); diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/SelectResourceByWEMainPanel.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/SelectResourceByWEMainPanel.java index 0e5a287..36efd7c 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/SelectResourceByWEMainPanel.java +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/SelectResourceByWEMainPanel.java @@ -279,15 +279,19 @@ public class SelectResourceByWEMainPanel extends Composite { for (String wsItemId : mapSelectedResources.keySet()) { SelectedResourceWidget selecWC = mapSelectedResources.get(wsItemId); ResourceElementBean theResource = selecWC.getResourceBean(); + theResource.setToBeAdded(true); if(!theResource.isFolder()){ // be sure ... children.add(theResource); } } + + toReturn.setToPublish(children); + GWT.log("resources to publish are: "+toReturn.getToPublish()); return toReturn; } - + /** * @return the freezed diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/utils/WorkspaceUtils.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/utils/WorkspaceUtils.java index 2330412..62f3c08 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/utils/WorkspaceUtils.java +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/utils/WorkspaceUtils.java @@ -341,13 +341,23 @@ public class WorkspaceUtils { * @throws Exception the exception */ public static List toResources(DatasetBean bean, Workspace workspace, String username) throws Exception{ - - logger.debug("Request to copy onto catalogue area...."); + logger.debug("Called to Resources...: "); + List resources = new ArrayList(); ResourceElementBean rootResource = bean.getResourceRoot(); + + if(rootResource==null) { + logger.info("No resource root, returning empty list of resources"); + return resources; + } // retrieve the children List resourcesToAdd = rootResource.getToPublish(); + + if(resourcesToAdd==null) { + logger.info("No resource to add, returning empty list of resources"); + return resources; + } // copy only the selected ones for(ResourceElementBean resource : resourcesToAdd){ diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/shared/ResourceElementBean.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/shared/ResourceElementBean.java index ef3241e..f840530 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/shared/ResourceElementBean.java +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/shared/ResourceElementBean.java @@ -54,7 +54,7 @@ public class ResourceElementBean implements Comparable, Ser /** The children size. */ private Integer childrenSize; - /** The to publish. */ +// /** The to publish. */ private List toPublish; //Resources that must be published /** The next id. */ From af2b4e342ac08f9ff2d6a8eeb8940e9cefd16a07 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Mon, 22 Mar 2021 12:12:07 +0100 Subject: [PATCH 32/44] Improved style-sheets. Improved mapping ws bean to resource bean --- .../client/ui/form/CreateDatasetForm.ui.xml | 157 +++++++++++------- .../SelectResourceByWEMainPanel.ui.xml | 14 +- .../server/utils/WorkspaceUtils.java | 26 ++- 3 files changed, 121 insertions(+), 76 deletions(-) diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/form/CreateDatasetForm.ui.xml b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/form/CreateDatasetForm.ui.xml index eb22060..c74c815 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/form/CreateDatasetForm.ui.xml +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/form/CreateDatasetForm.ui.xml @@ -1,6 +1,7 @@ .form-main-style { @@ -45,7 +46,7 @@ font-weight: bold; } - .the-margin-left{ + .the-margin-left { margin-left: 5px; } @@ -64,8 +65,9 @@ - + @@ -73,13 +75,15 @@ Title : - + - + @@ -87,18 +91,21 @@ - + Description: - - + @@ -118,7 +125,8 @@ - + @@ -126,7 +134,8 @@ - Selected + Selected License Url: @@ -138,7 +147,8 @@ - Visibility: + Visibility: @@ -149,7 +159,8 @@ - + @@ -162,7 +173,8 @@ to publish the item">Publish in: + width="91%" title="Publish in this organization" + ui:field="organizationsListbox"> @@ -173,8 +185,9 @@ Version: - + @@ -185,13 +198,14 @@ + placeholder="Joe Bloggs" enabled="false" b:id="author" + title="Item author" ui:field="authorTextbox" /> - + @@ -199,7 +213,8 @@ - + * Author Email: @@ -211,7 +226,8 @@ - + @@ -219,18 +235,20 @@ - + Maintainer: - + - + @@ -238,18 +256,21 @@ - + Maintainer Email: - - + - + @@ -257,7 +278,8 @@ - Types: + Types: - + @@ -277,10 +300,11 @@ - Item Groups: + Item Groups: - @@ -288,7 +312,8 @@ - + @@ -302,12 +327,12 @@ - + - Continue + Continue Reset @@ -318,18 +343,20 @@ ui:field="formSecondStep" visible="false"> - Manage Resources + Select Item Resources - - - - - - - - + + + + + + + + - + - + @@ -380,18 +409,22 @@ - + - + Go to the Item - + Add Resources + block="true" type="PRIMARY" visible="false" + ui:field="addResourcesButton">Add Resources Create diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/SelectResourceByWEMainPanel.ui.xml b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/SelectResourceByWEMainPanel.ui.xml index c9a42e0..0f6a912 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/SelectResourceByWEMainPanel.ui.xml +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/SelectResourceByWEMainPanel.ui.xml @@ -8,11 +8,9 @@ } .custom-header { - margin-top: 0px !important; - } - - .custom-header h1 { + margin: 0; font-size: 18px !important; + color: #222; } .max-height-250 { @@ -24,14 +22,14 @@ margin-top: 10px; } - .margin-top-20 { - margin-top: 20px; + .margin-top-30 { + margin-top: 30px; } - Select Item Resources + Selected Items @@ -40,7 +38,7 @@ + addStyleNames="{style.margin-top-30}"> diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/utils/WorkspaceUtils.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/utils/WorkspaceUtils.java index 62f3c08..82ec1b6 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/utils/WorkspaceUtils.java +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/utils/WorkspaceUtils.java @@ -111,7 +111,6 @@ public class WorkspaceUtils { public static void toWorkspaceResource(String wsItemId, String userName, DatasetBean bean, Workspace workspace) throws Exception { - WorkspaceItem originalFolderOrFile = workspace.getItem(wsItemId); logger.debug("Item retrieved is " + originalFolderOrFile); @@ -149,14 +148,29 @@ public class WorkspaceUtils { bean.setCustomFields(tempItems); } - String pathSeparator = "/"; - String fullPathBase = originalFolderOrFile.getPath(); - fullPathBase = fullPathBase.endsWith(pathSeparator) ? fullPathBase : fullPathBase + pathSeparator; - resourceEB.setFullPath(originalFolderOrFile.getPath().replace(fullPathBase, "")); resourceEB.setChildrenSize(workspace.getChildren(originalFolderOrFile.getId()).size()); - //WorkspaceUtils.extractEditableNameFromPath(resourceEB, pathSeparator); + }else { + //it is a file, removing extension + int indexOfDot = title.lastIndexOf("."); + String suffix = title.substring(indexOfDot, title.length()); + if(suffix.length()>=1 && suffix.length()<=4) { + //I'm considering last .suffix as an file extension so removing it. + title = title.substring(0,indexOfDot); + bean.setTitle(title); + } } + //Replacing /Home/user.name with "" + String fullPathBase = originalFolderOrFile.getPath(); + logger.debug("Path is: "+fullPathBase); + String prefixNodeWorkspace = String.format("/%s/%s", "Home",userName); + logger.debug("Searching: "+prefixNodeWorkspace); + if(fullPathBase.startsWith(prefixNodeWorkspace)){ + logger.info("Removing from path the prefix: "+prefixNodeWorkspace); + fullPathBase = fullPathBase.replaceFirst(prefixNodeWorkspace, ""); + } + resourceEB.setFullPath(fullPathBase); + //setting parent id ResourceElementBean theParent = new ResourceElementBean(); From f02743a5368ccba2324e03cb9a664982aa543d29 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Mon, 22 Mar 2021 16:20:43 +0100 Subject: [PATCH 33/44] removed last wizard title "add resources" --- .../client/ui/form/CreateDatasetForm.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/form/CreateDatasetForm.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/form/CreateDatasetForm.java index 9a880c8..ac843c2 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/form/CreateDatasetForm.java +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/form/CreateDatasetForm.java @@ -279,7 +279,7 @@ public class CreateDatasetForm extends Composite{ if(isWorkspaceRequest) { listOfSteps = Arrays.asList("Insert Base Information","Select Item Resources", "Insert Profile Information and Publish"); }else { - listOfSteps = Arrays.asList("Insert Base Information", "Insert Profile Information and Publish", "Add Resources"); + listOfSteps = Arrays.asList("Insert Base Information", "Insert Profile Information and Publish"); } this.wizCreator = new WizardCreator(listOfSteps); From a8900c41e1f33deecbe56e5f20dbcfc9ef3ef5d3 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Mon, 22 Mar 2021 17:47:05 +0100 Subject: [PATCH 34/44] improved css --- .../client/ui/form/CreateDatasetForm.ui.xml | 2 +- .../ui/workspace/SelectResourceByWEMainPanel.ui.xml | 2 +- .../client/ui/workspace/SelectedResourceWidget.java | 2 +- .../ui/workspace/SelectedResourceWidget.ui.xml | 13 +++++++++++-- 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/form/CreateDatasetForm.ui.xml b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/form/CreateDatasetForm.ui.xml index c74c815..a952ea0 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/form/CreateDatasetForm.ui.xml +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/form/CreateDatasetForm.ui.xml @@ -356,7 +356,7 @@ + width="95%" visible="true"> - + Selected Items diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/SelectedResourceWidget.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/SelectedResourceWidget.java index a14888b..3835c5a 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/SelectedResourceWidget.java +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/SelectedResourceWidget.java @@ -53,7 +53,7 @@ public class SelectedResourceWidget extends Composite { /** The field name. */ @UiField - com.github.gwtbootstrap.client.ui.Label fieldName; + Label fieldName; @UiField Label fieldDescription; diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/SelectedResourceWidget.ui.xml b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/SelectedResourceWidget.ui.xml index b6e3419..009dec0 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/SelectedResourceWidget.ui.xml +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/SelectedResourceWidget.ui.xml @@ -25,6 +25,14 @@ font-size: 12px; } + .title-text { + font-weight: bold; + font-size: 14px; + display: inline; + vertical-align: middle; + color: #222; + } + .icon-my-style { font-size: 1.2em; margin-right: 10px; @@ -34,12 +42,13 @@ - + - + From ea2adf14a2304cb01abd0defe3f58ed168b283e9 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Tue, 23 Mar 2021 11:14:20 +0100 Subject: [PATCH 35/44] removed the package ui/TwinColumnSelection. Revisited css with !important attribute --- .../TwinColumnSelection/ResourceCellLeft.java | 46 -- .../ResourceCellRight.java | 65 -- .../TwinColumnSelection/ResourceInfoForm.java | 143 ----- .../ResourceInfoForm.ui.xml | 88 --- .../ShowMorePagerPanel.java | 101 ---- .../TwinColumnSelectionMainPanel.java | 571 ------------------ .../TwinColumnSelectionMainPanel.ui.xml | 58 -- .../client/ui/form/CreateDatasetForm.ui.xml | 14 +- .../client/ui/utils/GcubeDialogExtended.java | 2 +- .../SelectResourceByWEMainPanel.java | 20 +- .../SelectResourceByWEMainPanel.ui.xml | 4 +- .../public/CKanMetadataPublisher.css | 8 +- .../server/utils/WorkspaceUtils.java | 1 + .../shared/ResourceElementBean.java | 28 +- 14 files changed, 46 insertions(+), 1103 deletions(-) delete mode 100644 src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/TwinColumnSelection/ResourceCellLeft.java delete mode 100644 src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/TwinColumnSelection/ResourceCellRight.java delete mode 100644 src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/TwinColumnSelection/ResourceInfoForm.java delete mode 100644 src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/TwinColumnSelection/ResourceInfoForm.ui.xml delete mode 100644 src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/TwinColumnSelection/ShowMorePagerPanel.java delete mode 100644 src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/TwinColumnSelection/TwinColumnSelectionMainPanel.java delete mode 100644 src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/TwinColumnSelection/TwinColumnSelectionMainPanel.ui.xml diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/TwinColumnSelection/ResourceCellLeft.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/TwinColumnSelection/ResourceCellLeft.java deleted file mode 100644 index 1a9c681..0000000 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/TwinColumnSelection/ResourceCellLeft.java +++ /dev/null @@ -1,46 +0,0 @@ -package org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.TwinColumnSelection; - -import org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.icons.Images; -import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.ResourceElementBean; - -import com.google.gwt.cell.client.AbstractCell; -import com.google.gwt.core.client.GWT; -import com.google.gwt.safehtml.shared.SafeHtmlBuilder; -import com.google.gwt.user.client.ui.Image; -/** - * Cell that renders left side panel objects - * @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it) - */ -public class ResourceCellLeft extends AbstractCell{ - private static final Images image = GWT.create(Images.class); - private static final String tipFile = "Hold down the Control (ctrl) or Command button to select multiple options"; - private static final String tipFolder = "Click on the folder to navigate it"; - - @Override - public void render(com.google.gwt.cell.client.Cell.Context context, - ResourceElementBean value, SafeHtmlBuilder sb) { - - if (value == null || value.isToBeAdded()) { - return; - } - - Image file = new Image(image.fileIcon()); - Image folder = new Image(image.folderIcon()); - file.setWidth("15px"); - file.setHeight("15px"); - folder.setWidth("15px"); - folder.setHeight("15px"); - - String whichTip = value.isFolder() ? tipFolder : tipFile; - sb.appendHtmlConstant("
"); - sb.appendHtmlConstant(""); - sb.appendHtmlConstant(value.isFolder() ? folder.toString() : file.toString()); - sb.appendHtmlConstant(""); - sb.appendHtmlConstant(""); - sb.appendHtmlConstant(""); - sb.appendEscaped(value.getName()); - sb.appendHtmlConstant(""); - sb.appendHtmlConstant(""); - sb.appendHtmlConstant("
"); - } -} diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/TwinColumnSelection/ResourceCellRight.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/TwinColumnSelection/ResourceCellRight.java deleted file mode 100644 index e4f7748..0000000 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/TwinColumnSelection/ResourceCellRight.java +++ /dev/null @@ -1,65 +0,0 @@ -package org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.TwinColumnSelection; - -import org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.icons.Images; -import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.ResourceElementBean; - -import com.google.gwt.cell.client.AbstractCell; -import com.google.gwt.cell.client.ValueUpdater; -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.safehtml.shared.SafeHtmlBuilder; -import com.google.gwt.user.client.ui.Image; - -/** - * Cell that renders right side panel objects - * @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it) - */ -public class ResourceCellRight extends AbstractCell{ - - private static final Images image = GWT.create(Images.class); - private static final String tip = "Hold down the Control (CTRL) or Command button to select multiple options. Double click to access " - + "this resource information"; - - public ResourceCellRight() { - super("keydown", "dblclick"); - } - - @Override - public void render(com.google.gwt.cell.client.Cell.Context context, - ResourceElementBean value, SafeHtmlBuilder sb) { - - if (value == null || !value.isToBeAdded() || value.isFolder()) { - return; - } - - Image file = new Image(image.fileIcon()); - file.setWidth("15px"); - file.setHeight("15px"); - - sb.appendHtmlConstant("
"); - sb.appendHtmlConstant(""); - sb.appendHtmlConstant(file.toString()); - sb.appendHtmlConstant(""); - sb.appendHtmlConstant(""); - sb.appendHtmlConstant(""); - sb.appendEscaped(value.getEditableName()); - sb.appendHtmlConstant(""); - sb.appendHtmlConstant(""); - sb.appendHtmlConstant("
"); - } - - @Override - public void onBrowserEvent(com.google.gwt.cell.client.Cell.Context context, - Element parent, ResourceElementBean value, NativeEvent event, - ValueUpdater valueUpdater) { - if(value == null || TwinColumnSelectionMainPanel.isFroozen()) - return; - super.onBrowserEvent(context, parent, value, event, valueUpdater); - ResourceInfoForm info = new ResourceInfoForm(value, valueUpdater); - if(TwinColumnSelectionMainPanel.detailContainer.getWidget() != null) - TwinColumnSelectionMainPanel.detailContainer.clear(); - TwinColumnSelectionMainPanel.detailContainer.add(info); - TwinColumnSelectionMainPanel.detailContainer.setVisible(true); - } -} diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/TwinColumnSelection/ResourceInfoForm.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/TwinColumnSelection/ResourceInfoForm.java deleted file mode 100644 index f2205c7..0000000 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/TwinColumnSelection/ResourceInfoForm.java +++ /dev/null @@ -1,143 +0,0 @@ -package org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.TwinColumnSelection; - -import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.ResourceElementBean; - -import com.github.gwtbootstrap.client.ui.Button; -import com.github.gwtbootstrap.client.ui.ControlGroup; -import com.github.gwtbootstrap.client.ui.TextArea; -import com.github.gwtbootstrap.client.ui.TextBox; -import com.github.gwtbootstrap.client.ui.constants.ControlGroupType; -import com.github.gwtbootstrap.client.ui.constants.IconType; -import com.google.gwt.cell.client.ValueUpdater; -import com.google.gwt.core.client.GWT; -import com.google.gwt.dom.client.Style.Float; -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.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.HasHorizontalAlignment; -import com.google.gwt.user.client.ui.HorizontalPanel; -import com.google.gwt.user.client.ui.Widget; - -/** - * A resource information form panel - * @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it) - */ -public class ResourceInfoForm extends Composite{ - - @UiField - public TextBox resourceName; - @UiField - public TextBox resourcePath; - @UiField - public TextBox resourceFormat; - @UiField - public TextArea resourceDescription; - @UiField - public Button updateResourceButton; - @UiField - Button closeButton; - @UiField - HorizontalPanel commandPanel; - @UiField - ControlGroup controlName; - - private ResourceElementBean resourceBean; - - private static ResourceInfoFormUiBinder uiBinder = GWT - .create(ResourceInfoFormUiBinder.class); - - interface ResourceInfoFormUiBinder extends - UiBinder { - } - - public ResourceInfoForm() { - initWidget(uiBinder.createAndBindUi(this)); - } - - public ResourceInfoForm(final ResourceElementBean resource, final ValueUpdater valueUpdater) { - initWidget(uiBinder.createAndBindUi(this)); - - resourceBean = resource; - resourceDescription.setText(resource.getDescription()); - resourceFormat.setText(resource.getMimeType() == null? "Unavailable" : resource.getMimeType()); - resourceName.setText(resource.getEditableName()); - resourcePath.setText(resource.getFullPath()); - closeButton.getElement().getStyle().setFloat(Float.RIGHT); - closeButton.setIcon(IconType.REMOVE_CIRCLE); - commandPanel.setCellHorizontalAlignment(updateResourceButton, HasHorizontalAlignment.ALIGN_RIGHT); - commandPanel.getElement().getStyle().setMarginTop(10, Unit.PX); - updateResourceButton.addClickHandler(new ClickHandler() { - - @Override - public void onClick(ClickEvent event) { - resourceBean.setDescription(resourceDescription.getText()); - - removeError(controlName); - String newName = resourceName.getText(); - if(newName == null || newName.isEmpty()){ - showError(controlName); - }else{ - resourceBean.setEditableName(newName); - valueUpdater.update(resourceBean); - } - } - }); - - closeButton.addClickHandler(new ClickHandler() { - - @Override - public void onClick(ClickEvent event) { - - clearPanel(); - - } - }); - } - - public String getResourceName() { - return resourceName.getText(); - } - - public void setResourceName(String resourceName) { - this.resourceName.setText(resourceName); - } - - public String getResourcePath() { - return resourcePath.getText(); - } - - public void setResourcePath(String resourcePath) { - this.resourcePath.setText(resourcePath); - } - - public String getResourceFormat() { - return resourceFormat.getText(); - } - - public void setResourceFormat(String resourceFormat) { - this.resourceFormat.setText(resourceFormat); - } - - public String getResourceDescription() { - return resourceDescription.getText(); - } - - public void setResourceDescription(String resourceDescription) { - this.resourceDescription.setText(resourceDescription); - } - - public void removeError(ControlGroup control) { - control.setType(ControlGroupType.NONE); - } - - public void showError(ControlGroup control) { - control.setType(ControlGroupType.ERROR); - } - - protected void clearPanel() { - this.removeFromParent(); - } -} diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/TwinColumnSelection/ResourceInfoForm.ui.xml b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/TwinColumnSelection/ResourceInfoForm.ui.xml deleted file mode 100644 index c9d29ce..0000000 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/TwinColumnSelection/ResourceInfoForm.ui.xml +++ /dev/null @@ -1,88 +0,0 @@ - - - - .legend-style { - width: 100%; - padding: 10px; - margin-bottom: 0px; - font-size: 14px; - } - - .panel-style { - padding: 5px; - border: 1px solid #bbb; - border-radius: 5px; - height: 400px; - width: 95%; - } - - .labels-style { - color: #999; - } - - .controls-style { - margin-left: 10px !important; - } - - .control-group { - margin-bottom: 0px !important; - } - - - - - - Resource Information - - - - - Name: - - - - - - - - Path: - - - - - - - - Description: - - - - - - - - Format: - - - - - - - - Update - - - - - \ No newline at end of file diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/TwinColumnSelection/ShowMorePagerPanel.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/TwinColumnSelection/ShowMorePagerPanel.java deleted file mode 100644 index 8a8f4cf..0000000 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/TwinColumnSelection/ShowMorePagerPanel.java +++ /dev/null @@ -1,101 +0,0 @@ -package org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.TwinColumnSelection; - -import com.google.gwt.event.dom.client.ScrollEvent; -import com.google.gwt.event.dom.client.ScrollHandler; -import com.google.gwt.user.cellview.client.AbstractPager; -import com.google.gwt.user.client.ui.ScrollPanel; -import com.google.gwt.user.client.ui.Widget; -import com.google.gwt.view.client.HasRows; - -/** - * Basically a scroll panel - * Partially changed from the code at http://samples.gwtproject.org/samples/Showcase/Showcase.html#!CwCellList - * @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it) - */ -public class ShowMorePagerPanel extends AbstractPager{ - - /** - * The default increment size. - */ - public static final int DEFAULT_INCREMENT = 10; - - /** - * The increment size. - */ - private int incrementSize = DEFAULT_INCREMENT; - - /** - * The last scroll position. - */ - private int lastScrollPos = 0; - - /** - * The scrollable panel. - */ - private final ScrollPanel scrollable = new ScrollPanel(); - - /** - * Construct a new {@link ShowMorePagerPanel}. - */ - public ShowMorePagerPanel() { - initWidget(scrollable); - - // Do not let the scrollable take tab focus. - scrollable.getElement().setTabIndex(-1); - - // Handle scroll events. - scrollable.addScrollHandler(new ScrollHandler() { - public void onScroll(ScrollEvent event) { - // If scrolling up, ignore the event. - int oldScrollPos = lastScrollPos; - lastScrollPos = scrollable.getVerticalScrollPosition(); - if (oldScrollPos >= lastScrollPos) { - return; - } - - HasRows display = getDisplay(); - if (display == null) { - return; - } - int maxScrollTop = scrollable.getWidget().getOffsetHeight() - - scrollable.getOffsetHeight(); - if (lastScrollPos >= maxScrollTop) { - // We are near the end, so increase the page size. - int newPageSize = Math.min( - display.getVisibleRange().getLength() + incrementSize, - display.getRowCount()); - display.setVisibleRange(0, newPageSize); - } - } - }); - } - - /** - * Get the number of rows by which the range is increased when the scrollbar - * reaches the bottom. - * @return the increment size - */ - public int getIncrementSize() { - return incrementSize; - } - - @Override - public void setDisplay(HasRows display) { - assert display instanceof Widget : "display must extend Widget"; - scrollable.setWidget((Widget) display); - super.setDisplay(display); - } - - /** - * Set the number of rows by which the range is increased when the scrollbar - * reaches the bottom. - * @param incrementSize the incremental number of rows - */ - public void setIncrementSize(int incrementSize) { - this.incrementSize = incrementSize; - } - - @Override - protected void onRangeOrRowCountChanged() { - } -} diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/TwinColumnSelection/TwinColumnSelectionMainPanel.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/TwinColumnSelection/TwinColumnSelectionMainPanel.java deleted file mode 100644 index 909f0cc..0000000 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/TwinColumnSelection/TwinColumnSelectionMainPanel.java +++ /dev/null @@ -1,571 +0,0 @@ -package org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.TwinColumnSelection; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.Iterator; -import java.util.List; -import java.util.Set; - -import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.ResourceElementBean; - -import com.github.gwtbootstrap.client.ui.Breadcrumbs; -import com.github.gwtbootstrap.client.ui.Button; -import com.github.gwtbootstrap.client.ui.FluidContainer; -import com.github.gwtbootstrap.client.ui.NavLink; -import com.google.gwt.cell.client.ValueUpdater; -import com.google.gwt.core.client.GWT; -import com.google.gwt.dom.client.Style.BorderStyle; -import com.google.gwt.dom.client.Style.FontWeight; -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.uibinder.client.UiBinder; -import com.google.gwt.uibinder.client.UiField; -import com.google.gwt.user.cellview.client.CellList; -import com.google.gwt.user.cellview.client.HasKeyboardPagingPolicy.KeyboardPagingPolicy; -import com.google.gwt.user.client.ui.Composite; -import com.google.gwt.user.client.ui.SimplePanel; -import com.google.gwt.user.client.ui.VerticalPanel; -import com.google.gwt.user.client.ui.Widget; -import com.google.gwt.view.client.ListDataProvider; -import com.google.gwt.view.client.MultiSelectionModel; -import com.google.gwt.view.client.SelectionChangeEvent; - -/** - * The twin column panels for selection of the files to attach to the catalague product. - * @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it) - * @author Francesco Mangiacrapa at ISTI-CNR - */ -public class TwinColumnSelectionMainPanel extends Composite{ - - @UiField - VerticalPanel leftContainer; - @UiField - VerticalPanel rightContainer; - @UiField - VerticalPanel buttonsPanel; - @UiField - Button allToRightButton; - @UiField - Button toRightButton; - @UiField - Button toLeftButton; - @UiField - Button allToLeftButton; - // @UiField - // Popover popoverResourceSelection; - // @UiField - // Button resourceInfoButton; - @UiField - Breadcrumbs breadcrumbs; - @UiField - FluidContainer mainContainerResourcesSelection; - // @UiField - // Button getResources; - @UiField - public static SimplePanel detailContainer; - - /** - * The breadcrumb subpath with the linked folder - * @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it) - */ - private class PathBean{ - NavLink link; - ResourceElementBean resourceFolder; - - PathBean(NavLink link, ResourceElementBean resourceFolder){ - this.link = link; - this.resourceFolder = resourceFolder; - } - } - - private static boolean frozen = false; - private List pathListBeans = new ArrayList(); - private static final String PANEL_BORDER_COLOR = "#8899a6"; - private static final String PANEL_HEIGHT = "400px"; - private ShowMorePagerPanel showMorePanelLeft = new ShowMorePagerPanel(); - private ShowMorePagerPanel showMorePanelRight = new ShowMorePagerPanel(); - private CellList cellListLeft; - private CellList cellListRight; - private ListDataProvider dataProviderLeft = new ListDataProvider(); - private ListDataProvider dataProviderRight = new ListDataProvider(); - private MultiSelectionModel selectionModelRight; - private MultiSelectionModel selectionModelLeft; - private final ResourceElementBean initialBean; - // private final static HTML aboutHeader = new HTML("Resource Manager"); - // private final static HTML aboutBody = new HTML("

Move the files you want to attach to the product on the right panel below." - // + " Please consider that any complex hierarchy structure you may have will be flatten.

"); - - // private static final short PATH_THRESHOLD = 1; // TODO - - private static TwinColumnSelectionMainPanelUiBinder uiBinder = GWT - .create(TwinColumnSelectionMainPanelUiBinder.class); - - interface TwinColumnSelectionMainPanelUiBinder extends - UiBinder { - } - - public TwinColumnSelectionMainPanel(ResourceElementBean initialBean) { - initWidget(uiBinder.createAndBindUi(this)); - frozen = false; - - GWT.log(initialBean.toString()); - - this.initialBean = initialBean; - - buttonsPanel.getElement().getStyle().setMarginTop(50, Unit.PCT); - allToRightButton.getElement().getStyle().setMarginBottom(4, Unit.PX); - toRightButton.getElement().getStyle().setMarginBottom(4, Unit.PX); - toLeftButton.getElement().getStyle().setMarginBottom(4, Unit.PX); - allToLeftButton.getElement().getStyle().setMarginBottom(4, Unit.PX); - - buttonsPanel.getElement().setAttribute("align", "center"); - // popoverResourceSelection.setPlacement(Placement.LEFT); - // popoverResourceSelection.setHeading(aboutHeader.getHTML()); - // popoverResourceSelection.setText(aboutBody.getHTML()); - // resourceInfoButton.getElement().getStyle().setFloat(Float.RIGHT); - // resourceInfoButton.getElement().getStyle().setPaddingRight(0, Unit.PX); - mainContainerResourcesSelection.getElement().getStyle().setPadding(10, Unit.PX); - - breadcrumbs.getElement().getStyle().setBackgroundColor("white"); - breadcrumbs.getElement().getStyle().setFontWeight(FontWeight.BOLD); - breadcrumbs.getElement().getStyle().setMarginLeft(0, Unit.PX); - mainContainerResourcesSelection.getElement().getStyle().setMarginLeft(10, Unit.PX); - mainContainerResourcesSelection.getElement().getStyle().setMarginBottom(20, Unit.PX); - mainContainerResourcesSelection.getElement().getStyle().setMarginTop(0, Unit.PX); - - prepareHandlers(); - initLeftSidePanel(initialBean); - initRightSidePanel(); - } - - /** - * Initialize the left side panel - */ - private void initLeftSidePanel(final ResourceElementBean initialBean) { - - // initialize the left side list - ResourceCellLeft cell = new ResourceCellLeft(); - - // Set a key provider that provides a unique key for each object. - cellListLeft = new CellList(cell, ResourceElementBean.KEY_PROVIDER); - cellListLeft.setKeyboardPagingPolicy(KeyboardPagingPolicy.INCREASE_RANGE); - - // set page size - //int size = initialBean.isFolder() ? initialBean.getChildren().size() : 1; - cellListLeft.setPageSize(0); - - // Add a selection model so we can select cells. - selectionModelLeft = new MultiSelectionModel(ResourceElementBean.KEY_PROVIDER); - cellListLeft.setSelectionModel(selectionModelLeft); - - // perform an action on selection - selectionModelLeft.addSelectionChangeHandler(new SelectionChangeEvent.Handler() { - - public void onSelectionChange(SelectionChangeEvent event) { - - if(frozen) - return; - - Iterator selectedObjectsIterator = selectionModelLeft.getSelectedSet().iterator(); - - while (selectedObjectsIterator.hasNext()) { - ResourceElementBean selectedBean = selectedObjectsIterator.next(); - if(selectedBean.isFolder()){ - - // a single folder selected - if(selectionModelLeft.getSelectedSet().size() == 1){ - - // update path - final NavLink navElem = new NavLink(selectedBean.getName()); - navElem.getElement().getStyle().setFontWeight(FontWeight.BOLD); - final PathBean pathBean = new PathBean(navElem, selectedBean); - - navElem.addClickHandler(new ClickHandler() { - - @Override - public void onClick(ClickEvent event) { - - removeStartingFromBreadcrumbs(navElem, pathBean); - GWT.log("Clicked on element " + pathBean.resourceFolder.getName()); - //breadcrumbsUpdater(); - ResourceElementBean folder = pathBean.resourceFolder; - /*Collections.sort(folder.getChildren()); - dataProviderLeft.setList(folder.getChildren());*/ - dataProviderLeft.refresh(); - - } - }); - - pathListBeans.add(pathBean); - breadcrumbs.add(navElem); - //breadcrumbsUpdater(); - - /*Collections.sort(selectedBean.getChildren()); - GWT.log("Children " + selectedBean.getChildren()); - dataProviderLeft.setList(selectedBean.getChildren()); - cellListLeft.setPageSize(selectedBean.getChildren().size());*/ - dataProviderLeft.refresh(); - } - selectionModelLeft.setSelected(selectedBean, false); - } - } - // enable the buttons that allows to move the objects to the right - enableMoveToRightButtons(selectionModelLeft.getSelectedSet()); - } - }); - - // set the list into the provider - if(initialBean.isFolder()){ - /*Collections.sort(this.initialBean.getChildren()); - dataProviderLeft.setList(this.initialBean.getChildren());*/ - }else - dataProviderLeft.setList(Arrays.asList(this.initialBean)); - - // add root to breadcrumb - final NavLink root = new NavLink(initialBean.getName()); - final PathBean pathBean = new PathBean(root, initialBean); - root.getElement().getStyle().setFontWeight(FontWeight.BOLD); - pathListBeans.add(pathBean); - breadcrumbs.add(root); - - root.addClickHandler(new ClickHandler() { - - @Override - public void onClick(ClickEvent event) { - - removeStartingFromBreadcrumbs(root, pathBean); - //breadcrumbsUpdater(); - - // set back the root content list - /*dataProviderLeft.setList(initialBean.getChildren()); - cellListLeft.setPageSize(initialBean.getChildren().size());*/ - dataProviderLeft.refresh(); - - } - }); - - // set the cell list into the provider - dataProviderLeft.addDataDisplay(cellListLeft); - - // manage showMorePanelLeft - showMorePanelLeft.setDisplay(cellListLeft); - showMorePanelLeft.setHeight(PANEL_HEIGHT); - showMorePanelLeft.getElement().getStyle().setBorderStyle(BorderStyle.SOLID); - showMorePanelLeft.getElement().getStyle().setBorderWidth(2, Unit.PX); - showMorePanelLeft.getElement().getStyle().setBorderColor(PANEL_BORDER_COLOR); - - // add the list to the leftContainerPanel - leftContainer.add(showMorePanelLeft); - } - - /** - * Update the path - * @param navElem - * @param pathBean - */ - public void removeStartingFromBreadcrumbs(NavLink navElem, PathBean pathBean){ - - // remove data after - Iterator iteratorBreadcrumb = breadcrumbs.iterator(); - Iterator iteratorListPath = pathListBeans.iterator(); - - boolean delete = false; - while(iteratorBreadcrumb.hasNext()){ - Widget current = iteratorBreadcrumb.next(); - - if(delete){ - current.removeFromParent(); - iteratorBreadcrumb.remove(); - } - - if(!delete && navElem.equals(current)) - delete = true; - } - - delete = false; - while(iteratorListPath.hasNext()){ - PathBean current = iteratorListPath.next(); - - if(delete) - iteratorListPath.remove(); - - if(!delete && pathBean.equals(current)) - delete = true; - } - - } - - /** - * Initialize the left side panel - */ - private void initRightSidePanel() { - - // initialize the left side list - ResourceCellRight cell = new ResourceCellRight(); - - // Set a key provider that provides a unique key for each object. - cellListRight = new CellList(cell, ResourceElementBean.KEY_PROVIDER); - cellListRight.setKeyboardPagingPolicy(KeyboardPagingPolicy.INCREASE_RANGE); - cellListRight.setValueUpdater(new ValueUpdater() { - - @Override - public void update(ResourceElementBean value) { - - // just redraw the list - cellListRight.redraw(); - - } - }); - - // Add a selection model so we can select cells. - selectionModelRight = new MultiSelectionModel(ResourceElementBean.KEY_PROVIDER); - cellListRight.setSelectionModel(selectionModelRight); - - // perform an action on selection - selectionModelRight.addSelectionChangeHandler(new SelectionChangeEvent.Handler() { - public void onSelectionChange(SelectionChangeEvent event) { - - if(frozen) - return; - - enableMoveToLeftButtons(selectionModelRight.getSelectedSet()); - } - }); - - // set the cell list into the provider - dataProviderRight.addDataDisplay(cellListRight); - - // manage showMorePanelRight - showMorePanelRight.setDisplay(cellListRight); - showMorePanelRight.setHeight(PANEL_HEIGHT); - showMorePanelRight.getElement().getStyle().setBorderStyle(BorderStyle.SOLID); - showMorePanelRight.getElement().getStyle().setBorderWidth(2, Unit.PX); - showMorePanelRight.getElement().getStyle().setBorderColor(PANEL_BORDER_COLOR); - - // add the list to the leftContainerPanel - rightContainer.add(showMorePanelRight); - - } - - /** - * Enable/disable the buttons to move objects from left to right properly. - * @param setselectedItemsLeft - */ - private void enableMoveToRightButtons(Set setselectedItemsLeft){ - - if(setselectedItemsLeft == null || setselectedItemsLeft.isEmpty()){ - allToRightButton.setEnabled(false); - toRightButton.setEnabled(false); - } - else if(setselectedItemsLeft.size() > 1){ - allToRightButton.setEnabled(true); - toRightButton.setEnabled(false); - } - else{ - allToRightButton.setEnabled(false); - toRightButton.setEnabled(true); - } - } - - /** - * Enable/disable the buttons to move objects from right to left properly. - * @param setselectedItemsRight - */ - private void enableMoveToLeftButtons(Set setselectedItemsRight){ - - if(setselectedItemsRight == null || setselectedItemsRight.isEmpty()){ - allToLeftButton.setEnabled(false); - allToLeftButton.setEnabled(false); - } - else if(setselectedItemsRight.size() > 1){ - allToLeftButton.setEnabled(true); - toLeftButton.setEnabled(false); - } - else{ - allToLeftButton.setEnabled(false); - toLeftButton.setEnabled(true); - } - } - - /** - * Prepare the buttons' handlers - */ - private void prepareHandlers() { - - allToRightButton.addClickHandler(new ClickHandler() { - @Override - public void onClick(ClickEvent event) { - moveToRight(selectionModelLeft.getSelectedSet()); - } - }); - - toRightButton.addClickHandler(new ClickHandler() { - @Override - public void onClick(ClickEvent event) { - moveToRight(selectionModelLeft.getSelectedSet()); - } - }); - - allToLeftButton.addClickHandler(new ClickHandler() { - @Override - public void onClick(ClickEvent event) { - moveToLeft(selectionModelRight.getSelectedSet()); - } - }); - - toLeftButton.addClickHandler(new ClickHandler() { - @Override - public void onClick(ClickEvent event) { - moveToLeft(selectionModelRight.getSelectedSet()); - } - }); - } - - /** - * Move to right elements - * @param set the elements to move - */ - private void moveToRight(Set setSelected){ - - if(setSelected == null || setSelected.isEmpty()) - return; - - Iterator iterator = setSelected.iterator(); - while (iterator.hasNext()) { - ResourceElementBean resourceElementBean = iterator - .next(); - resourceElementBean.setToBeAdded(true); - - int indexRight = dataProviderRight.getList().indexOf(resourceElementBean); - if(indexRight >= 0) - dataProviderRight.getList().set(indexRight, resourceElementBean); - else{ - dataProviderRight.getList().add(resourceElementBean); - Collections.sort(dataProviderRight.getList()); - dataProviderRight.refresh(); - } - - int indexLeft = dataProviderLeft.getList().indexOf(resourceElementBean); - dataProviderLeft.getList().set(indexLeft, resourceElementBean); - } - } - - /** - * Move to left elements - * @param setSelected the elements to move - */ - private void moveToLeft(Set setSelected){ - - if(setSelected == null || setSelected.isEmpty()) - return; - - Iterator iterator = setSelected.iterator(); - while (iterator.hasNext()) { - ResourceElementBean resourceElementBean = iterator.next(); - resourceElementBean.setToBeAdded(false); - } - - Collections.sort(dataProviderLeft.getList()); - dataProviderLeft.refresh(); - dataProviderRight.refresh(); - } - - /** - * Freeze the panel - */ - public void freeze() { - - frozen = true; - - Iterator iteratorOverPath = breadcrumbs.iterator(); - while (iteratorOverPath.hasNext()) { - Widget widget = iteratorOverPath.next(); - if(widget instanceof NavLink) - ((NavLink)widget).setActive(false); - } - - allToRightButton.setEnabled(false); - toRightButton.setEnabled(false); - allToLeftButton.setEnabled(false); - toLeftButton.setEnabled(false); - } - - /** - * Returns the root parent with the children as files to save - * @return the resources to save - */ - public ResourceElementBean getResourcesToPublish(){ - - List current = dataProviderRight.getList(); - - ResourceElementBean toReturn = new ResourceElementBean(); - List children = new ArrayList(); - - for (ResourceElementBean resource : current) { - if(resource.isToBeAdded() && !resource.isFolder()){ // be sure ... - ResourceElementBean beanWithoutChildren = new ResourceElementBean(resource); - beanWithoutChildren.setName(resource.getEditableName()); - children.add(beanWithoutChildren); - } - } - - /*toReturn.setChildren(children);*/ - return toReturn; - } - - - /** - * @return the freezed - */ - public static boolean isFroozen() { - - return frozen; - } - - // @UiHandler("getResources") - // void getResources(ClickEvent ce){ - // getResourcesToPublish(); - // } - // - // /** - // * Short the current path if needed - // */ - // private void breadcrumbsUpdater(){ - // - // // ignore first and last elem - // boolean reduce = (pathListBeans.size() - 2) > PATH_THRESHOLD; - // - // GWT.log("Is to reduce? " + reduce); - // - // GWT.log("Full size is " + pathListBeans.size()); - // - // if(!reduce){ - // GWT.log("Restore"); - // for(int i = 0; i < pathListBeans.size(); i++){ - // PathBean bean = pathListBeans.get(i); - // GWT.log("Elem is " + bean.resourceFolder); - // bean.link.setText(bean.resourceFolder.getName()); - // bean.link.setVisible(true); - // } - // }else{ - // for(int i = 1; i < pathListBeans.size(); i++){ - // PathBean bean = pathListBeans.get(i); - // - // if(i == (pathListBeans.size() - 1)){ - // bean.link.setText(bean.resourceFolder.getName()); - // bean.link.setVisible(true); - // }else if(i == (pathListBeans.size() - 2)){ - // GWT.log("The last to modify ****" + bean.resourceFolder.getName()); - // bean.link.setText("..."); - // bean.link.setVisible(true); - // }else{ - // bean.link.setText(bean.resourceFolder.getName()); - // bean.link.setVisible(false); - // } - // } - // } - // GWT.log("Updated list is " + pathListBeans.toString()); - // } -} \ No newline at end of file diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/TwinColumnSelection/TwinColumnSelectionMainPanel.ui.xml b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/TwinColumnSelection/TwinColumnSelectionMainPanel.ui.xml deleted file mode 100644 index 0fbe728..0000000 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/TwinColumnSelection/TwinColumnSelectionMainPanel.ui.xml +++ /dev/null @@ -1,58 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/form/CreateDatasetForm.ui.xml b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/form/CreateDatasetForm.ui.xml index a952ea0..f578000 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/form/CreateDatasetForm.ui.xml +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/form/CreateDatasetForm.ui.xml @@ -9,16 +9,16 @@ } .fieldset-border-style { - border: 1px groove #444; - -webkit-box-shadow: 0px 0px 0px 0px #000; - box-shadow: 0px 0px 0px 0px #000; - padding: 10px; + border: 1px groove #444 !important; + box-shadow: 0px 0px 0px 0px #000 !important; + padding: 10px !important; } .legend-style { - width: auto; - padding: 10px; - margin-bottom: 0px; + width: auto !important; + padding: 10px !important; + margin-bottom: 0 !important; + border-bottom: 0 !important; } @external .form-horizontal .input-large; diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/utils/GcubeDialogExtended.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/utils/GcubeDialogExtended.java index 43b0d7b..cdb67e7 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/utils/GcubeDialogExtended.java +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/utils/GcubeDialogExtended.java @@ -1,7 +1,7 @@ package org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.utils; import org.gcube.portlets.user.gcubewidgets.client.popup.GCubeDialog; -import org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.TwinColumnSelection.ResourceInfoForm; +import org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.workspace.ResourceInfoForm; import com.github.gwtbootstrap.client.ui.Paragraph; import com.google.gwt.core.shared.GWT; diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/SelectResourceByWEMainPanel.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/SelectResourceByWEMainPanel.java index 36efd7c..6a0c5a5 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/SelectResourceByWEMainPanel.java +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/SelectResourceByWEMainPanel.java @@ -92,30 +92,30 @@ public class SelectResourceByWEMainPanel extends Composite { this.initialBean = initialBean; this.labelNothing.setType(LabelType.INFO); - try { - String wsRootId = null; - String rootName = null; + String wsFolderId = null; + + //remove this? if(initialBean.isFolder()) { - wsRootId = initialBean.getOriginalIdInWorkspace(); - rootName = initialBean.getName(); + wsFolderId = initialBean.getOriginalIdInWorkspace(); }else { //is file - if(initialBean.getParent()!=null) { - wsRootId = initialBean.getParent().getOriginalIdInWorkspace(); - rootName = initialBean.getParent().getName(); + wsFolderId = initialBean.getParent().getOriginalIdInWorkspace(); + } } + + wsFolderId = initialBean.getRootIdInWorkspace()!=null?initialBean.getRootIdInWorkspace():wsFolderId; //loads the WE only if the root is not null - if(wsRootId!=null) { + if(wsFolderId!=null) { DISPLAY_FIELD[] displayFields = new DISPLAY_FIELD[] { DISPLAY_FIELD.ICON, DISPLAY_FIELD.NAME, DISPLAY_FIELD.OWNER, DISPLAY_FIELD.CREATION_DATE}; - WorkspaceResourcesExplorerPanel workspaceExplorerPanel = new WorkspaceResourcesExplorerPanel(wsRootId,false,null, null,false,null,displayFields); + WorkspaceResourcesExplorerPanel workspaceExplorerPanel = new WorkspaceResourcesExplorerPanel(wsFolderId,false,null, null,false,null,displayFields); WorskpaceExplorerSelectNotificationListener wsResourceExplorerListener = new WorskpaceExplorerSelectNotificationListener() { @Override diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/SelectResourceByWEMainPanel.ui.xml b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/SelectResourceByWEMainPanel.ui.xml index c345b3a..54fb234 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/SelectResourceByWEMainPanel.ui.xml +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/SelectResourceByWEMainPanel.ui.xml @@ -8,9 +8,9 @@ } .custom-header { - margin: 0; + margin: 0 !important; font-size: 18px !important; - color: #222; + color: #222 !important; } .max-height-250 { diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/public/CKanMetadataPublisher.css b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/public/CKanMetadataPublisher.css index 9b14018..2715ccd 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/public/CKanMetadataPublisher.css +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/public/CKanMetadataPublisher.css @@ -51,10 +51,14 @@ width: 100% !important; } -.accordion-no-border-inner .accordion-inner { - border: 0px; +.accordion-no-border-inner { + border: 1px solid #e5e5e5 !important; + border-radius: 4px !important; } +.accordion-no-border-inner .accordion-inner { + border-top: 0 !important; +} /* WIZARD-CREATOR CLASSES */ diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/utils/WorkspaceUtils.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/utils/WorkspaceUtils.java index 82ec1b6..964d22f 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/utils/WorkspaceUtils.java +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/utils/WorkspaceUtils.java @@ -128,6 +128,7 @@ public class WorkspaceUtils { resourceEB.setDescription(originalFolderOrFile.getDescription()); resourceEB.setFolder(originalFolderOrFile.isFolder()); resourceEB.setEditableName(originalFolderOrFile.getName()); + resourceEB.setRootIdInWorkspace(workspace.getRoot().getId()); //in case of folder if(originalFolderOrFile.isFolder()) { diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/shared/ResourceElementBean.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/shared/ResourceElementBean.java index f840530..6c2cb5a 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/shared/ResourceElementBean.java +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/shared/ResourceElementBean.java @@ -36,6 +36,8 @@ public class ResourceElementBean implements Comparable, Ser /** The original id in workspace. */ private String originalIdInWorkspace; + private String rootIdInWorkspace; + /** The mime type. */ private String mimeType; @@ -423,12 +425,16 @@ public class ResourceElementBean implements Comparable, Ser int toReturn = (o == null || o.fullPath == null) ? -1 : -o.fullPath.compareTo(fullPath); return toReturn; } + + + public String getRootIdInWorkspace() { + return rootIdInWorkspace; + } + + public void setRootIdInWorkspace(String rootIdInWorkspace) { + this.rootIdInWorkspace = rootIdInWorkspace; + } - /** - * To string. - * - * @return the string - */ @Override public String toString() { StringBuilder builder = new StringBuilder(); @@ -444,6 +450,8 @@ public class ResourceElementBean implements Comparable, Ser builder.append(fullPath); builder.append(", originalIdInWorkspace="); builder.append(originalIdInWorkspace); + builder.append(", rootIdInWorkspace="); + builder.append(rootIdInWorkspace); builder.append(", mimeType="); builder.append(mimeType); builder.append(", url="); @@ -452,14 +460,16 @@ public class ResourceElementBean implements Comparable, Ser builder.append(description); builder.append(", organizationNameDatasetParent="); builder.append(organizationNameDatasetParent); - builder.append(", parent="); - builder.append(parent); builder.append(", childrenSize="); builder.append(childrenSize); - builder.append(", identifierGWT="); - builder.append(identifierGWT); + builder.append(", toPublish="); + builder.append(toPublish); builder.append("]"); return builder.toString(); } + + + + } From a93ff1404813b9f1ec5fed9372beed5f55107d48 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Tue, 23 Mar 2021 12:07:03 +0100 Subject: [PATCH 36/44] added !important attribute in oder to avoid css portal overriding --- .../ckandatapublisherwidget/public/CKanMetadataPublisher.css | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/public/CKanMetadataPublisher.css b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/public/CKanMetadataPublisher.css index 2715ccd..d8b6db0 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/public/CKanMetadataPublisher.css +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/public/CKanMetadataPublisher.css @@ -54,10 +54,12 @@ .accordion-no-border-inner { border: 1px solid #e5e5e5 !important; border-radius: 4px !important; + padding: 6px 12px !important; } .accordion-no-border-inner .accordion-inner { border-top: 0 !important; + padding: 4px 4px !important; } /* WIZARD-CREATOR CLASSES */ From 41a287ee1f6cb64d306af9443ccbc5a32ebc4cca Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Tue, 23 Mar 2021 14:33:22 +0100 Subject: [PATCH 37/44] only indentation --- .../public/CKanMetadataPublisher.css | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/public/CKanMetadataPublisher.css b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/public/CKanMetadataPublisher.css index d8b6db0..9e2bd22 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/public/CKanMetadataPublisher.css +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/public/CKanMetadataPublisher.css @@ -51,19 +51,18 @@ width: 100% !important; } -.accordion-no-border-inner { - border: 1px solid #e5e5e5 !important; +.accordion-no-border-inner { + border: 1px solid #e5e5e5 !important; border-radius: 4px !important; - padding: 6px 12px !important; + padding: 6px 12px !important; } .accordion-no-border-inner .accordion-inner { - border-top: 0 !important; - padding: 4px 4px !important; + border-top: 0 !important; + padding: 4px 4px !important; } /* WIZARD-CREATOR CLASSES */ - .wizard-creator { width: 100%; border-spacing: 6px; From 0dbd890dda6e96876c4846fcde717ded69151f2c Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Thu, 25 Mar 2021 17:59:49 +0100 Subject: [PATCH 38/44] bug fixes. Starting integration with new Workspace Explorer constructor --- .../ui/workspace/SelectResourceByWEMainPanel.java | 5 +++-- .../server/CKANPublisherServicesImpl.java | 9 +++++++-- .../server/utils/WorkspaceUtils.java | 12 +++++++----- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/SelectResourceByWEMainPanel.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/SelectResourceByWEMainPanel.java index 6a0c5a5..7cb8af3 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/SelectResourceByWEMainPanel.java +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/SelectResourceByWEMainPanel.java @@ -6,6 +6,7 @@ import java.util.List; import java.util.Map; import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.ResourceElementBean; +import org.gcube.portlets.widgets.wsexplorer.client.explore.WorkspaceResourcesEnhancedExplorerPanel; import org.gcube.portlets.widgets.wsexplorer.client.explore.WorkspaceResourcesExplorerPanel; import org.gcube.portlets.widgets.wsexplorer.client.notification.WorkspaceExplorerSelectNotification.WorskpaceExplorerSelectNotificationListener; import org.gcube.portlets.widgets.wsexplorer.client.view.grid.ItemsTable.DISPLAY_FIELD; @@ -107,7 +108,7 @@ public class SelectResourceByWEMainPanel extends Composite { } } - wsFolderId = initialBean.getRootIdInWorkspace()!=null?initialBean.getRootIdInWorkspace():wsFolderId; + //wsFolderId = initialBean.getRootIdInWorkspace()!=null?initialBean.getRootIdInWorkspace():wsFolderId; //loads the WE only if the root is not null if(wsFolderId!=null) { @@ -115,7 +116,7 @@ public class SelectResourceByWEMainPanel extends Composite { DISPLAY_FIELD[] displayFields = new DISPLAY_FIELD[] { DISPLAY_FIELD.ICON, DISPLAY_FIELD.NAME, DISPLAY_FIELD.OWNER, DISPLAY_FIELD.CREATION_DATE}; - WorkspaceResourcesExplorerPanel workspaceExplorerPanel = new WorkspaceResourcesExplorerPanel(wsFolderId,false,null, null,false,null,displayFields); + WorkspaceResourcesEnhancedExplorerPanel workspaceExplorerPanel = new WorkspaceResourcesEnhancedExplorerPanel(wsFolderId,false,null, null,false,null,displayFields); WorskpaceExplorerSelectNotificationListener wsResourceExplorerListener = new WorskpaceExplorerSelectNotificationListener() { @Override diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/CKANPublisherServicesImpl.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/CKANPublisherServicesImpl.java index f89303f..bb2bb6b 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/CKANPublisherServicesImpl.java +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/CKANPublisherServicesImpl.java @@ -51,8 +51,6 @@ import com.liferay.portal.kernel.log.LogFactoryUtil; import com.liferay.portal.service.UserLocalServiceUtil; - - /** * Server side of the data publisher. * @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it) @@ -192,6 +190,13 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C String scope = GenericUtils.getScopeFromClientUrl(getThreadLocalRequest()); logger.info("Request for CKAN licenses for scope " + scope); String keyPerScope = CatalogueUtilMethods.concatenateSessionKeyScope(SessionCatalogueAttributes.CKAN_LICENSES_KEY, scope); + +// if(!isWithinPortal()){ +// logger.info("DEV MODE returning funny licenses..."); +// List licenses = new ArrayList(); +// licenses.add(new LicenseBean("AFL-3.0", "https://opensource.org/licenses/AFL-3.0")); +// return licenses; +// } List licensesBean = null; if(httpSession.getAttribute(keyPerScope) != null){ diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/utils/WorkspaceUtils.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/utils/WorkspaceUtils.java index 964d22f..554dff9 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/utils/WorkspaceUtils.java +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/utils/WorkspaceUtils.java @@ -153,11 +153,13 @@ public class WorkspaceUtils { }else { //it is a file, removing extension int indexOfDot = title.lastIndexOf("."); - String suffix = title.substring(indexOfDot, title.length()); - if(suffix.length()>=1 && suffix.length()<=4) { - //I'm considering last .suffix as an file extension so removing it. - title = title.substring(0,indexOfDot); - bean.setTitle(title); + if(indexOfDot>=0) { + String suffix = title.substring(indexOfDot, title.length()); + if(suffix.length()>=1 && suffix.length()<=4) { + //I'm considering last .suffix as an file extension so removing it. + title = title.substring(0,indexOfDot); + bean.setTitle(title); + } } } From 5ebfb47db1a48775229c147012849458c71f4b47 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Fri, 26 Mar 2021 12:42:56 +0100 Subject: [PATCH 39/44] Replaced com.liferay.portal.kernel.log.Log with org.slf4j.Logger; --- .../client/ui/form/CreateDatasetForm.java | 7 +++++++ .../client/ui/workspace/SelectResourceByWEMainPanel.java | 1 - .../server/CKANPublisherServicesImpl.java | 7 ++++--- .../server/utils/CatalogueRoleManager.java | 7 ++++--- .../server/utils/DiscoverTagsList.java | 7 +++---- .../server/utils/GCoreEndPointReaderSocial.java | 7 +++---- .../server/utils/GenericUtils.java | 7 +++---- .../server/utils/MetadataDiscovery.java | 7 +++---- .../server/utils/WorkspaceUtils.java | 8 ++++---- 9 files changed, 31 insertions(+), 27 deletions(-) diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/form/CreateDatasetForm.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/form/CreateDatasetForm.java index ac843c2..4fccdda 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/form/CreateDatasetForm.java +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/form/CreateDatasetForm.java @@ -448,6 +448,13 @@ public class CreateDatasetForm extends Composite{ setAlertBlock("An unknow error occurred while retrieving types, sorry", AlertType.ERROR, true); } else{ + + GWT.log("Profile returned are: "+profiles.size()); + if(!GWT.isProdMode()) { + for (MetaDataProfileBean profile : profiles) { + GWT.log("Profile title: "+profile.getTitle() + ", type: "+profile.getType()); + } + } receivedBean.setMetadataList(profiles); prepareMetadataList(receivedBean); diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/SelectResourceByWEMainPanel.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/SelectResourceByWEMainPanel.java index 7cb8af3..36adcbf 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/SelectResourceByWEMainPanel.java +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/workspace/SelectResourceByWEMainPanel.java @@ -7,7 +7,6 @@ import java.util.Map; import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.ResourceElementBean; import org.gcube.portlets.widgets.wsexplorer.client.explore.WorkspaceResourcesEnhancedExplorerPanel; -import org.gcube.portlets.widgets.wsexplorer.client.explore.WorkspaceResourcesExplorerPanel; import org.gcube.portlets.widgets.wsexplorer.client.notification.WorkspaceExplorerSelectNotification.WorskpaceExplorerSelectNotificationListener; import org.gcube.portlets.widgets.wsexplorer.client.view.grid.ItemsTable.DISPLAY_FIELD; import org.gcube.portlets.widgets.wsexplorer.shared.Item; diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/CKANPublisherServicesImpl.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/CKANPublisherServicesImpl.java index bb2bb6b..6fc5fa2 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/CKANPublisherServicesImpl.java +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/CKANPublisherServicesImpl.java @@ -43,14 +43,15 @@ import org.gcube.vomanagement.usermanagement.impl.LiferayGroupManager; import org.gcube.vomanagement.usermanagement.impl.LiferayUserManager; import org.gcube.vomanagement.usermanagement.model.GCubeUser; import org.geojson.GeoJsonObject; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import com.fasterxml.jackson.databind.ObjectMapper; import com.google.gwt.user.server.rpc.RemoteServiceServlet; -import com.liferay.portal.kernel.log.Log; -import com.liferay.portal.kernel.log.LogFactoryUtil; import com.liferay.portal.service.UserLocalServiceUtil; + /** * Server side of the data publisher. * @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it) @@ -61,7 +62,7 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C // Logger //private static final org.slf4j.Logger logger = LoggerFactory.getLogger(CKANPublisherServicesImpl.class); - private static final Log logger = LogFactoryUtil.getLog(CKANPublisherServicesImpl.class); + private static final Logger logger = LoggerFactory.getLogger(CKANPublisherServicesImpl.class); private static final String ITEM_URL_FIELD = "Item URL"; private static final String SYS_TYPE = "system:type"; private static final String TAGS_VOCABULARY_KEY = "TAGS_VOCABULARY"; diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/utils/CatalogueRoleManager.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/utils/CatalogueRoleManager.java index 42278fc..da8ff78 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/utils/CatalogueRoleManager.java +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/utils/CatalogueRoleManager.java @@ -20,16 +20,17 @@ import org.gcube.vomanagement.usermanagement.impl.LiferayUserManager; import org.gcube.vomanagement.usermanagement.model.GCubeGroup; import org.gcube.vomanagement.usermanagement.model.GCubeRole; import org.gcube.vomanagement.usermanagement.model.GatewayRolesNames; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + -import com.liferay.portal.kernel.log.Log; -import com.liferay.portal.kernel.log.LogFactoryUtil; /** * Facilities to check roles into the catalogue. */ public class CatalogueRoleManager { - private static final Log logger = LogFactoryUtil.getLog(CatalogueRoleManager.class); + private static final Logger logger = LoggerFactory.getLogger(CatalogueRoleManager.class); /** * Retrieve the highest ckan role the user has and also retrieve the list of organizations (scopes) in which the user has the ckan-admin or ckan-editor role diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/utils/DiscoverTagsList.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/utils/DiscoverTagsList.java index 8d6e52a..c1e6176 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/utils/DiscoverTagsList.java +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/utils/DiscoverTagsList.java @@ -15,19 +15,18 @@ import org.gcube.portlets.widgets.ckandatapublisherwidget.server.CKANPublisherSe import org.gcube.resources.discovery.client.api.DiscoveryClient; import org.gcube.resources.discovery.client.queries.api.Query; import org.gcube.resources.discovery.client.queries.impl.QueryBox; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.w3c.dom.Node; import org.xml.sax.InputSource; -import com.liferay.portal.kernel.log.Log; -import com.liferay.portal.kernel.log.LogFactoryUtil; - /** * Discover in a given context if there is a Generic Resource containing the list of tags to be used within the widget. * @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it) */ public class DiscoverTagsList { - private static final Log logger = LogFactoryUtil.getLog(CKANPublisherServicesImpl.class); + private static final Logger logger = LoggerFactory.getLogger(CKANPublisherServicesImpl.class); private final static String APPLICATION_PROFILE_NAME = "Tags"; private final static String QUERY = "for $profile in collection('/db/Profiles/GenericResource')//Resource " + diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/utils/GCoreEndPointReaderSocial.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/utils/GCoreEndPointReaderSocial.java index 17d3454..81c314c 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/utils/GCoreEndPointReaderSocial.java +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/utils/GCoreEndPointReaderSocial.java @@ -9,9 +9,8 @@ import org.gcube.common.resources.gcore.GCoreEndpoint; import org.gcube.common.scope.api.ScopeProvider; import org.gcube.resources.discovery.client.api.DiscoveryClient; import org.gcube.resources.discovery.client.queries.api.SimpleQuery; - -import com.liferay.portal.kernel.log.Log; -import com.liferay.portal.kernel.log.LogFactoryUtil; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * Retrieves the base url of the social-networking service in the scope provided @@ -20,7 +19,7 @@ import com.liferay.portal.kernel.log.LogFactoryUtil; public class GCoreEndPointReaderSocial { private String basePath = null; - private static final Log logger = LogFactoryUtil.getLog(GCoreEndPointReaderSocial.class); + private static final Logger logger = LoggerFactory.getLogger(GCoreEndPointReaderSocial.class); private static final String resource = "jersey-servlet"; private static final String serviceName = "SocialNetworking"; private static final String serviceClass = "Portal"; diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/utils/GenericUtils.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/utils/GenericUtils.java index 9e8cb19..babf567 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/utils/GenericUtils.java +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/utils/GenericUtils.java @@ -22,9 +22,8 @@ import org.gcube.vomanagement.usermanagement.exception.UserManagementSystemExcep import org.gcube.vomanagement.usermanagement.impl.LiferayGroupManager; import org.gcube.vomanagement.usermanagement.model.GCubeGroup; import org.gcube.vomanagement.usermanagement.model.GCubeUser; - -import com.liferay.portal.kernel.log.Log; -import com.liferay.portal.kernel.log.LogFactoryUtil; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * Util class with static methods. @@ -35,7 +34,7 @@ public class GenericUtils { // Logger //private static final org.slf4j.Logger logger = LoggerFactory.getLogger(Utils.class); - private static final Log logger = LogFactoryUtil.getLog(GenericUtils.class); + private static final Logger logger = LoggerFactory.getLogger(GenericUtils.class); public static final String GCUBE_REQUEST_URL = "gcube-request-url"; /** diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/utils/MetadataDiscovery.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/utils/MetadataDiscovery.java index ac2641f..1830ebf 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/utils/MetadataDiscovery.java +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/utils/MetadataDiscovery.java @@ -28,9 +28,8 @@ import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.metadata.FieldA import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.metadata.MetaDataProfileBean; import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.metadata.MetadataFieldWrapper; import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.metadata.TaggingGroupingValue; - -import com.liferay.portal.kernel.log.Log; -import com.liferay.portal.kernel.log.LogFactoryUtil; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * Metadatadiscovery facility. @@ -38,7 +37,7 @@ import com.liferay.portal.kernel.log.LogFactoryUtil; */ public class MetadataDiscovery { - private static final Log logger = LogFactoryUtil.getLog(MetadataDiscovery.class); + private static final Logger logger = LoggerFactory.getLogger(MetadataDiscovery.class); /** * Returns the names of the metadata profiles in a given context diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/utils/WorkspaceUtils.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/utils/WorkspaceUtils.java index 554dff9..12a410c 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/utils/WorkspaceUtils.java +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/utils/WorkspaceUtils.java @@ -23,9 +23,9 @@ import org.gcube.datacatalogue.utillibrary.shared.ResourceBean; import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.DatasetBean; import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.ResourceElementBean; import org.gcube.vomanagement.usermanagement.model.GCubeUser; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; -import com.liferay.portal.kernel.log.Log; -import com.liferay.portal.kernel.log.LogFactoryUtil; import com.liferay.portal.service.UserLocalServiceUtil; @@ -39,7 +39,7 @@ import com.liferay.portal.service.UserLocalServiceUtil; public class WorkspaceUtils { //private static final org.slf4j.Logger logger = LoggerFactory.getLogger(WorkspaceUtils.class); - private static final Log logger = LogFactoryUtil.getLog(WorkspaceUtils.class); + private static final Logger logger = LoggerFactory.getLogger(WorkspaceUtils.class); private static final String RESOURCES_NAME_SEPARATOR = "_"; private static final String STRIP_NOT_ALPHANUMERIC = "[^A-Za-z0-9.-_]"; @@ -153,7 +153,7 @@ public class WorkspaceUtils { }else { //it is a file, removing extension int indexOfDot = title.lastIndexOf("."); - if(indexOfDot>=0) { + if(indexOfDot>0) { String suffix = title.substring(indexOfDot, title.length()); if(suffix.length()>=1 && suffix.length()<=4) { //I'm considering last .suffix as an file extension so removing it. From b4bfc08cfaf80004ff41aa4f20fbe8ce0223e903 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Mon, 29 Mar 2021 15:11:45 +0200 Subject: [PATCH 40/44] Implemented some feedback reported under #20868#note-11 --- CHANGELOG.md | 1 + .../client/ui/form/CreateDatasetForm.java | 6 +++--- .../ui/resources/AddResourceToDataset.java | 8 +++++++- .../ui/resources/AddResourceToDataset.ui.xml | 2 +- .../public/CKanMetadataPublisher.css | 1 - .../server/CKANPublisherServicesImpl.java | 20 +++++++------------ 6 files changed, 19 insertions(+), 19 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 16cc007..6b9928e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm [#19568] Unify and extend the tags allowed values [#20828] Revisited title size and format [#20868] Redesigned the "Manage Resources" user experience +[##21068] Add Resources facility: only HTTPS URLs must be allowed ## [v1.6.2] - 2021-02-08 diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/form/CreateDatasetForm.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/form/CreateDatasetForm.java index 4fccdda..40c6023 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/form/CreateDatasetForm.java +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/form/CreateDatasetForm.java @@ -277,9 +277,9 @@ public class CreateDatasetForm extends Composite{ List listOfSteps = null; if(isWorkspaceRequest) { - listOfSteps = Arrays.asList("Insert Base Information","Select Item Resources", "Insert Profile Information and Publish"); + listOfSteps = Arrays.asList("Edit Common Metadata","Select Item Resources", "Edit Item Specific Metadata & Publish"); }else { - listOfSteps = Arrays.asList("Insert Base Information", "Insert Profile Information and Publish"); + listOfSteps = Arrays.asList("Edit Common Metadata", "Edit Item Specific Metadata & Publish"); } this.wizCreator = new WizardCreator(listOfSteps); @@ -1419,7 +1419,7 @@ public class CreateDatasetForm extends Composite{ } }; - t.schedule(10000); + t.schedule(15000); } } diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/resources/AddResourceToDataset.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/resources/AddResourceToDataset.java index 5347002..8b161a1 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/resources/AddResourceToDataset.java +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/resources/AddResourceToDataset.java @@ -88,7 +88,13 @@ public class AddResourceToDataset extends Composite{ showAlert("Url and name fields cannot be empty", AlertType.ERROR); return; - + } + + //THE URL must be HTTPS, see #21068 + if(!(resourceNameTextBox.getText().toLowerCase().startsWith("https://"))){ + showAlert("The URL must be HTTPS and starts with \"https://\" (e.g. https://your-resource.com)", AlertType.ERROR); + return; + } // collect data and build up the bean diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/resources/AddResourceToDataset.ui.xml b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/resources/AddResourceToDataset.ui.xml index 41b149b..600bf46 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/resources/AddResourceToDataset.ui.xml +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/resources/AddResourceToDataset.ui.xml @@ -63,7 +63,7 @@ URL: - diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/public/CKanMetadataPublisher.css b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/public/CKanMetadataPublisher.css index 9e2bd22..76dd3b1 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/public/CKanMetadataPublisher.css +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/public/CKanMetadataPublisher.css @@ -65,7 +65,6 @@ /* WIZARD-CREATOR CLASSES */ .wizard-creator { width: 100%; - border-spacing: 6px; border-collapse: separate; display: table; } diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/CKANPublisherServicesImpl.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/CKANPublisherServicesImpl.java index 6fc5fa2..c1f3732 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/CKANPublisherServicesImpl.java +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/CKANPublisherServicesImpl.java @@ -388,11 +388,6 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C // get the list of resources and convert to ResourceBean List resources = null; ResourceElementBean resourcesToAdd = toCreate.getResourceRoot(); - - // we need to copy such resource in the .catalogue area of the user's ws -// if(resourcesToAdd != null){ -// resources = WorkspaceUtils.copyResourcesToUserCatalogueArea(toCreate.getId(), userName, toCreate); -// } //converting to resources to be added if(resourcesToAdd != null){ @@ -404,6 +399,13 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C String scope = getScopeFromOrgName(organizationNameOrId); DataCatalogue utils = getCatalogue(scope); + if (!isWithinPortal()) { + logger.debug("Should be added:"); + for (String key : customFields.keySet()) { + logger.debug("Custom field with key: "+key+", value: "+customFields.get(key)); + } + } + String datasetId = utils.createCkanDatasetMultipleCustomFields(userName, title, null, @@ -422,15 +424,7 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C true, true); - /** - * OLD CODE - - String userApiKey = utils.getApiKeyFromUsername(userName); - String datasetId = utils.createCKanDatasetMultipleCustomFields - (userApiKey, title, null, organizationNameOrId, author, authorMail, maintainer, - maintainerMail, version, description, licenseId, listOfTags, customFields, resources, setPublic); - */ if(datasetId != null){ logger.info("Dataset created!"); From bc20c501479246c6853827b18b1eb07e974aecfa Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Mon, 29 Mar 2021 15:32:09 +0200 Subject: [PATCH 41/44] fixed comment --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6b9928e..fe29816 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,7 +14,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm [#19568] Unify and extend the tags allowed values [#20828] Revisited title size and format [#20868] Redesigned the "Manage Resources" user experience -[##21068] Add Resources facility: only HTTPS URLs must be allowed +[#21068] Add Resources facility: only HTTPS URLs must be allowed ## [v1.6.2] - 2021-02-08 From a0087573031c98fac151e21617c0b153aa5420d4 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Mon, 29 Mar 2021 17:37:34 +0200 Subject: [PATCH 42/44] added vertical resize for description area --- .../client/ui/form/CreateDatasetForm.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/form/CreateDatasetForm.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/form/CreateDatasetForm.java index 40c6023..f45be57 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/form/CreateDatasetForm.java +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/form/CreateDatasetForm.java @@ -47,6 +47,7 @@ import com.github.gwtbootstrap.client.ui.TextArea; import com.github.gwtbootstrap.client.ui.TextBox; import com.github.gwtbootstrap.client.ui.constants.AlertType; import com.github.gwtbootstrap.client.ui.constants.ControlGroupType; +import com.github.gwtbootstrap.client.ui.constants.ResizeType; import com.github.gwtbootstrap.client.ui.resources.Bootstrap.Tabs; import com.google.gwt.core.client.GWT; import com.google.gwt.dom.client.SelectElement; @@ -285,7 +286,7 @@ public class CreateDatasetForm extends Composite{ this.wizCreator = new WizardCreator(listOfSteps); wizardCreatorPanel.add(wizCreator); - + this.descriptionTextarea.setResize(ResizeType.VERTICAL); bind(); prepareInfoIcons(); From f0fcf09b0eff76e647e221d1d886bc205b21824b Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Tue, 30 Mar 2021 12:24:44 +0200 Subject: [PATCH 43/44] fixed css. Improved Add Resources --- .../client/ui/form/CreateDatasetForm.ui.xml | 7 +++-- .../ui/metadata/MetaDataFieldSkeleton.java | 3 +- .../ui/resources/AddResourceToDataset.java | 28 +++++++++++++++---- .../ui/resources/AddResourceToDataset.ui.xml | 26 +++++++++++------ .../public/CKanMetadataPublisher.css | 1 + 5 files changed, 47 insertions(+), 18 deletions(-) diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/form/CreateDatasetForm.ui.xml b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/form/CreateDatasetForm.ui.xml index f578000..f047f41 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/form/CreateDatasetForm.ui.xml +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/form/CreateDatasetForm.ui.xml @@ -12,6 +12,7 @@ border: 1px groove #444 !important; box-shadow: 0px 0px 0px 0px #000 !important; padding: 10px !important; + margin: 5px !important; } .legend-style { @@ -46,8 +47,10 @@ font-weight: bold; } - .the-margin-left { + .the-margin-gotoitem { margin-left: 5px; + margin-top: 10px; + margin-bottom: 10px; } @@ -419,7 +422,7 @@ Go to the Item + styleName="{style.the-margin-gotoitem}">
vocabulary = field.getVocabulary(); - + GWT.log("Vocabulary: "+field.getFieldName()); for (String term : vocabulary) { + GWT.log("Adding term: "+term); tempListBox.addItem(term); } diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/resources/AddResourceToDataset.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/resources/AddResourceToDataset.java index 8b161a1..9f64db7 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/resources/AddResourceToDataset.java +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/resources/AddResourceToDataset.java @@ -7,9 +7,11 @@ import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.ResourceElement import com.github.gwtbootstrap.client.ui.AlertBlock; import com.github.gwtbootstrap.client.ui.Button; +import com.github.gwtbootstrap.client.ui.ControlGroup; import com.github.gwtbootstrap.client.ui.TextArea; import com.github.gwtbootstrap.client.ui.TextBox; import com.github.gwtbootstrap.client.ui.constants.AlertType; +import com.github.gwtbootstrap.client.ui.constants.ControlGroupType; import com.google.gwt.core.client.GWT; import com.google.gwt.event.dom.client.ClickEvent; import com.google.gwt.event.dom.client.ClickHandler; @@ -53,6 +55,8 @@ public class AddResourceToDataset extends Composite{ @UiField Button addResourceButton; @UiField AlertBlock infoBlock; @UiField Button goToDatasetButton; + @UiField ControlGroup urlControlGroup; + @UiField ControlGroup nameControlGroup; public AddResourceToDataset(HandlerManager eventBus, String datasetId, String datasetOrg, String owner, final String datasetUrl) { initWidget(uiBinder.createAndBindUi(this)); @@ -80,19 +84,31 @@ public class AddResourceToDataset extends Composite{ @UiHandler("addResourceButton") void onAddButtonClick(ClickEvent e){ - + infoBlock.setVisible(false); + urlControlGroup.setType(ControlGroupType.NONE); + nameControlGroup.setType(ControlGroupType.NONE); // validation - if(resourceUrlTextBox.getText().isEmpty() || resourceNameTextBox.getText().isEmpty()){ + if (resourceUrlTextBox.getText().isEmpty()) { - showAlert("Url and name fields cannot be empty", AlertType.ERROR); + showAlert("'URL' field cannot be empty", AlertType.ERROR); + urlControlGroup.setType(ControlGroupType.ERROR); + return; + } + + // validation + if (resourceNameTextBox.getText().isEmpty() || resourceNameTextBox.getText().isEmpty()) { + + showAlert("'Name' field cannot be empty", AlertType.ERROR); + nameControlGroup.setType(ControlGroupType.ERROR); return; } //THE URL must be HTTPS, see #21068 - if(!(resourceNameTextBox.getText().toLowerCase().startsWith("https://"))){ - showAlert("The URL must be HTTPS and starts with \"https://\" (e.g. https://your-resource.com)", AlertType.ERROR); + if(!(resourceUrlTextBox.getText().toLowerCase().startsWith("https://"))){ + showAlert("The URL must be HTTPS, so start with \"https://\" (e.g. https://your-resource.com)", AlertType.ERROR); + urlControlGroup.setType(ControlGroupType.ERROR); return; } @@ -169,6 +185,6 @@ public class AddResourceToDataset extends Composite{ } }; - t.schedule(4000); + t.schedule(8000); } } diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/resources/AddResourceToDataset.ui.xml b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/resources/AddResourceToDataset.ui.xml index 600bf46..419665c 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/resources/AddResourceToDataset.ui.xml +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/resources/AddResourceToDataset.ui.xml @@ -1,6 +1,7 @@ + xmlns:b="urn:import:com.github.gwtbootstrap.client.ui" + xmlns:g="urn:import:com.google.gwt.user.client.ui"> .form-main-style { margin-left: 10px; @@ -56,19 +57,23 @@ is required + + Only HTTPS URLs are allowed. + If you have a desktop file upload it to Workspace and use the 'Public Link' facility to get its HTTPS URL - + * URL: - + - + * Name: @@ -80,19 +85,22 @@ - + Description: + title="Resource description" + ui:field="resourceDescriptionTextArea" /> - + Date: Tue, 30 Mar 2021 12:48:11 +0200 Subject: [PATCH 44/44] implemented feedback #20868#note-10 --- .../client/ui/resources/AddResourceToDataset.ui.xml | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/resources/AddResourceToDataset.ui.xml b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/resources/AddResourceToDataset.ui.xml index 419665c..108e98c 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/resources/AddResourceToDataset.ui.xml +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/resources/AddResourceToDataset.ui.xml @@ -57,9 +57,11 @@ is required - - Only HTTPS URLs are allowed. - If you have a desktop file upload it to Workspace and use the 'Public Link' facility to get its HTTPS URL + + The URL of the resource you are + publishing (only HTTPS URLs are allowed). If your resource is a file that you own on your + desktop, please upload that file to your workspace and generate a + public URL for that file. @@ -67,7 +69,7 @@ URL: -