diff --git a/pom.xml b/pom.xml
index 230aa61..3f0f702 100644
--- a/pom.xml
+++ b/pom.xml
@@ -152,7 +152,7 @@
org.gcube.data-catalogue
ckan-util-library
- [1.0.0-SNAPSHOT, 2.0.0-SNAPSHOT)
+ [2.0.0-SNAPSHOT, 3.0.0-SNAPSHOT)
compile
diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/CreateDatasetForm.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/CreateDatasetForm.java
index 29dc280..0e676c9 100644
--- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/CreateDatasetForm.java
+++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/CreateDatasetForm.java
@@ -15,6 +15,10 @@ 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.dataset.resources.AddResourceContainer;
+import org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.dataset.resources.AddResourceToDataset;
+import org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.dataset.resources.AddedResourcesSummary;
+import org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.dataset.resources.ResourcesTable;
import org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.utils.GcubeDialogExtended;
import org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.utils.InfoIconsLabels;
import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.DataType;
@@ -71,7 +75,7 @@ import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;
/**
- * Create metadata form for ckan dataset.
+ * Create metadata form for ckan product.
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
*/
public class CreateDatasetForm extends Composite{
@@ -212,7 +216,7 @@ public class CreateDatasetForm extends Composite{
/**
* Invoked in the most general case
- * @param owner
+ * @param eventBus the event bus
*/
public CreateDatasetForm(HandlerManager eventBus) {
@@ -223,7 +227,7 @@ public class CreateDatasetForm extends Composite{
/**
* Invoked when the workspace is used
* @param idFolderWorkspace
- * @param owner
+ * @param eventBus the event bus
*/
public CreateDatasetForm(String idFolderWorkspace, HandlerManager eventBus) {
@@ -507,7 +511,7 @@ public class CreateDatasetForm extends Composite{
metadataProfilesFormatListbox.setEnabled(true);
// everything went ok
- setAlertBlock("", AlertType.ERROR, false);
+ setAlertBlock("", AlertType.DEFAULT, false);
}else
setAlertBlock("Error while retrieving profiles, sorry", AlertType.ERROR, true);
@@ -528,7 +532,7 @@ public class CreateDatasetForm extends Composite{
* Add the items to the listbox and put data into the metadataPanel
* @param receivedBean
*/
- private void prepareMetadataList(DatasetMetadataBean receivedBean) {
+ private void prepareMetadataList(final DatasetMetadataBean receivedBean) {
List beans = receivedBean.getMetadataList();
@@ -549,8 +553,9 @@ public class CreateDatasetForm extends Composite{
// hide the panel
metadataFieldsPanel.clear();
metadataFieldsPanel.setVisible(false);
+ receivedBean.setChosenProfile(null);
}else{
-
+ receivedBean.setChosenProfile(selectedItem);
metadataFieldsPanel.clear();
addFields(selectedItem);
}
@@ -563,9 +568,14 @@ public class CreateDatasetForm extends Composite{
metadataProfilesControlGroup.setVisible(false);
metadataFieldsPanel.clear();
listOfMetadataFields.clear();
+ receivedBean.setChosenProfile(null);
}
}
+ /**
+ * Add fields of the selected metadata profile to the widget
+ * @param selectedItem
+ */
protected void addFields(String selectedItem) {
for(MetaDataProfileBean bean: receivedBean.getMetadataList()){
@@ -661,7 +671,7 @@ public class CreateDatasetForm extends Composite{
@Override
public void onFailure(Throwable caught) {
- alertOnContinue("Sorry but there was a proble while checking if the inserted data are correct", AlertType.ERROR);
+ alertOnContinue("Sorry but there was a problem while checking if the inserted data are correct", AlertType.ERROR);
}
});
@@ -1103,7 +1113,7 @@ public class CreateDatasetForm extends Composite{
}
// email reg expression
- if(!validateByRegExpression(maintainerEmailTextbox.getText(), REGEX_MAIL)){
+ if(!maintainerEmailTextbox.getText().matches(REGEX_MAIL)){
maintainerControlGroup.setType(ControlGroupType.ERROR);
return "Not valid maintainer email";
}
@@ -1140,16 +1150,6 @@ public class CreateDatasetForm extends Composite{
return metadataProfilesFormatListbox.getSelectedItemText().equals("none") && (metadataProfilesFormatListbox.getItemCount() != 1);
}
- /**
- * Validate a text against a regular expression.
- * @param textToValidate
- * @param regex
- * @return
- */
- private boolean validateByRegExpression(String textToValidate, String regex){
- return textToValidate.matches(regex);
- }
-
@UiHandler("resetButton")
void resetFormEvent(ClickEvent e){
diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/AddResourceContainer.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/dataset/resources/AddResourceContainer.java
similarity index 97%
rename from src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/AddResourceContainer.java
rename to src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/dataset/resources/AddResourceContainer.java
index 8ed70a4..8ab89a5 100644
--- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/AddResourceContainer.java
+++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/dataset/resources/AddResourceContainer.java
@@ -1,4 +1,4 @@
-package org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui;
+package org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.dataset.resources;
import com.github.gwtbootstrap.client.ui.TabPanel;
import com.google.gwt.core.client.GWT;
diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/AddResourceContainer.ui.xml b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/dataset/resources/AddResourceContainer.ui.xml
similarity index 100%
rename from src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/AddResourceContainer.ui.xml
rename to src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/dataset/resources/AddResourceContainer.ui.xml
diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/AddResourceToDataset.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/dataset/resources/AddResourceToDataset.java
similarity index 99%
rename from src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/AddResourceToDataset.java
rename to src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/dataset/resources/AddResourceToDataset.java
index 9d8d316..285c8fc 100644
--- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/AddResourceToDataset.java
+++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/dataset/resources/AddResourceToDataset.java
@@ -1,4 +1,4 @@
-package org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui;
+package org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.dataset.resources;
import org.gcube.portlets.widgets.ckandatapublisherwidget.client.CKanPublisherService;
import org.gcube.portlets.widgets.ckandatapublisherwidget.client.CKanPublisherServiceAsync;
diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/AddResourceToDataset.ui.xml b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/dataset/resources/AddResourceToDataset.ui.xml
similarity index 100%
rename from src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/AddResourceToDataset.ui.xml
rename to src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/dataset/resources/AddResourceToDataset.ui.xml
diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/AddedResourcesSummary.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/dataset/resources/AddedResourcesSummary.java
similarity index 99%
rename from src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/AddedResourcesSummary.java
rename to src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/dataset/resources/AddedResourcesSummary.java
index 3a9d7c4..1126f5e 100644
--- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/AddedResourcesSummary.java
+++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/dataset/resources/AddedResourcesSummary.java
@@ -1,4 +1,4 @@
-package org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui;
+package org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.dataset.resources;
import java.util.ArrayList;
import java.util.List;
diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/AddedResourcesSummary.ui.xml b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/dataset/resources/AddedResourcesSummary.ui.xml
similarity index 100%
rename from src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/AddedResourcesSummary.ui.xml
rename to src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/dataset/resources/AddedResourcesSummary.ui.xml
diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/ResourcesTable.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/dataset/resources/ResourcesTable.java
similarity index 99%
rename from src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/ResourcesTable.java
rename to src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/dataset/resources/ResourcesTable.java
index e92c628..6a40f28 100644
--- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/ResourcesTable.java
+++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/dataset/resources/ResourcesTable.java
@@ -1,4 +1,4 @@
-package org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui;
+package org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.dataset.resources;
import java.util.Comparator;
import java.util.List;
@@ -200,7 +200,7 @@ public class ResourcesTable extends Composite{
return object.getUrl();
}
};
- table.addColumn(urlColumn, "Url");
+ table.addColumn(urlColumn, "Url (Temporary)");
// Add a date column to show the description (and make it sortable)
Column descColumn = new Column(new EditTextCell()) {
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 8d61144..f0da701 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
@@ -61,7 +61,7 @@ public class InfoIconsLabels {
// TITLE
public static final String TITLE_INFO_ID_POPUP = "title-popup-panel-info";
- public static final String TITLE_INFO_TEXT = "Product Title";
- public static final String TITLE_INFO_CAPTION = "Product Title must contain only alphanumer characters and [. - _]. No others symbols are allowed.";
+ public static final String TITLE_INFO_TEXT = "Product Title must contain only alphanumer characters, dots, underscore or hyphen minus. No others symbols are allowed.";
+ public static final String TITLE_INFO_CAPTION = "Product Title";
}
diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/AssociationToGroupThread.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/AssociationToGroupThread.java
new file mode 100644
index 0000000..b50ea07
--- /dev/null
+++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/AssociationToGroupThread.java
@@ -0,0 +1,67 @@
+package org.gcube.portlets.widgets.ckandatapublisherwidget.server;
+
+import org.gcube.datacatalogue.ckanutillibrary.DataCatalogue;
+import org.gcube.datacatalogue.ckanutillibrary.models.RolesCkanGroupOrOrg;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import eu.trentorise.opendata.jackan.model.CkanGroup;
+
+/**
+ * Associate the dataset to a group.
+ * @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
+ */
+public class AssociationToGroupThread extends Thread {
+
+ private static final Logger logger = LoggerFactory.getLogger(AssociationToGroupThread.class);
+
+ private String groupTitle;
+ private String datasetId;
+ private String username;
+ private DataCatalogue catalogue;
+
+ /**
+ * @param groupTitle
+ * @param datasetId
+ * @param username
+ * @param catalogue
+ */
+ public AssociationToGroupThread(String groupTitle, String datasetId,
+ String username, DataCatalogue catalogue) {
+ this.groupTitle = groupTitle;
+ this.datasetId = datasetId;
+ this.username = username;
+ this.catalogue = catalogue;
+ }
+
+ @Override
+ public void run() {
+
+ logger.info("Association thread started to put the dataset with id="+ datasetId + " into group with title " + groupTitle + " for user " + username);
+
+ // create the group
+ CkanGroup group = catalogue.createGroup(groupTitle, groupTitle, "");
+
+ if(group == null){
+
+ logger.warn("The group doesn't exist!!! Unable to perform such association");
+
+ }else{
+
+ logger.debug("Group exists, going to add the user " + username + " as its admin...");
+
+ boolean assigned = catalogue.checkRoleIntoGroup(username, groupTitle, RolesCkanGroupOrOrg.ADMIN);
+
+ if(assigned){
+
+ logger.debug("Admin role was assigned for this group, going to associate the product to the group");
+
+ boolean putIntoGroup = catalogue.assignDatasetToGroup(groupTitle, datasetId, catalogue.getApiKeyFromUsername(username));
+ logger.debug("Was product put into group? " + putIntoGroup);
+
+ }
+ }
+
+ }
+
+}
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 9b0c285..396239f 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
@@ -15,8 +15,8 @@ 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.datacatalogue.ckanutillibrary.CKanUtils;
-import org.gcube.datacatalogue.ckanutillibrary.CkanUtilsFactory;
+import org.gcube.datacatalogue.ckanutillibrary.DataCatalogue;
+import org.gcube.datacatalogue.ckanutillibrary.DataCatalogueFactory;
import org.gcube.datacatalogue.ckanutillibrary.models.ResourceBean;
import org.gcube.datacatalogue.ckanutillibrary.utils.SessionCatalogueAttributes;
import org.gcube.datacatalogue.ckanutillibrary.utils.UtilMethods;
@@ -57,13 +57,13 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
* @param scope if it is null it is evaluated from the session
* @return
*/
- public CKanUtils getCkanUtilsObj(String scope){
+ public DataCatalogue getCatalogue(String scope){
- CKanUtils instance = null;
+ DataCatalogue instance = null;
try{
String scopeInWhichDiscover = (scope != null && !scope.isEmpty()) ? scope : getASLSession().getScope();
logger.debug("Discovering ckan instance into scope " + scopeInWhichDiscover);
- instance = CkanUtilsFactory.getFactory().getUtilsPerScope(scopeInWhichDiscover);
+ instance = DataCatalogueFactory.getFactory().getUtilsPerScope(scopeInWhichDiscover);
}catch(Exception e){
logger.error("Unable to retrieve ckan utils", e);
}
@@ -136,7 +136,7 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
logger.debug("Found ckan token into session");
}
else{
- token = getCkanUtilsObj(scopeInWhichDiscover).getApiKeyFromUsername(username);
+ token = getCatalogue(scopeInWhichDiscover).getApiKeyFromUsername(username);
httpSession.setAttribute(keyPerScope, token);
logger.debug("Ckan token has been set for user " + username);
}
@@ -171,7 +171,7 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
logger.info("List of organizations was into session " + orgsName);
}
else{
- orgsName = Utils.getUserOrganizationsListAdmin(scope, username, getASLSession().getGroupName(), this);
+ orgsName = Utils.getUserOrganizationsListAdminEditor(scope, username, getASLSession().getGroupName(), this);
httpSession.setAttribute(keyPerScope, orgsName);
logger.info("Organizations name for user " + username + " has been saved into session " + orgsName);
}
@@ -200,8 +200,10 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
* @return
*/
private String findLicenseIdByLicense(String chosenLicense) {
+
String scope = (String)getThreadLocalRequest().getSession().getAttribute(SessionCatalogueAttributes.SCOPE_CLIENT_PORTLET_URL);
- return getCkanUtilsObj(scope).findLicenseIdByLicenseTitle(chosenLicense);
+ return getCatalogue(scope).findLicenseIdByLicenseTitle(chosenLicense);
+
}
@Override
@@ -225,7 +227,7 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
logger.debug("List of licenses was into session");
}
else{
- List titlesLicenses = getCkanUtilsObj(scope).getLicenses();
+ List titlesLicenses = getCatalogue(scope).getLicenses();
List titles = new ArrayList();
List urls = new ArrayList();
for (CkanLicense license : titlesLicenses) {
@@ -402,7 +404,7 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
copiedFolder.setDescription(bean.getDescription());
// change name of the copied folder to match the title
- ((WorkspaceFolder)copiedFolder).rename(org.gcube.datacatalogue.ckanutillibrary.utils.UtilMethods.nameFromTitle(bean.getTitle()));
+ ((WorkspaceFolder)copiedFolder).rename(org.gcube.datacatalogue.ckanutillibrary.utils.UtilMethods.fromProductTitleToName(bean.getTitle()));
List resources = new ArrayList();
@@ -477,7 +479,7 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
logger.debug("The user wants to publish in organization with name " + organizationNameOrId);
String scope = Utils.retrieveScopeFromOrganizationName(organizationNameOrId);
- CKanUtils utils = getCkanUtilsObj(scope);
+ DataCatalogue utils = getCatalogue(scope);
String datasetId = utils.createCKanDataset(getUserCKanTokenFromSession(scope), title, organizationNameOrId, author,
authorMail, maintainer, maintainerMail, version, description, licenseId,
@@ -491,6 +493,15 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
// retrieve the url
String datasetUrl = utils.getPortletUrl() + "?path=" + utils.getUrlFromDatasetIdOrName(getUserCKanTokenFromSession(scope), datasetId, true);
toCreate.setSource(datasetUrl);
+
+ // start a thread that will associate this dataset with the group
+ if(toCreate.getChosenProfile() != null){
+
+ AssociationToGroupThread thread = new AssociationToGroupThread(toCreate.getChosenProfile(), datasetId, userName, utils);
+ thread.start();
+
+ }
+
return toCreate;
}else{
@@ -542,7 +553,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 = Utils.retrieveScopeFromOrganizationName(resource.getOrganizationNameDatasetParent());
- String resourceId = getCkanUtilsObj(scope).addResourceToDataset(resourceBean, getUserCKanTokenFromSession(scope));
+ String resourceId = getCatalogue(scope).addResourceToDataset(resourceBean, getUserCKanTokenFromSession(scope));
if(resourceId != null){
logger.debug("Resource " + resource.getName() + " is now available");
@@ -580,7 +591,7 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
try{
// get the scope in which we should discover the ckan instance given the organization name in which the dataset was created
String scope = Utils.retrieveScopeFromOrganizationName(resource.getOrganizationNameDatasetParent());
- deleted = getCkanUtilsObj(scope).
+ deleted = getCatalogue(scope).
deleteResourceFromDataset(resource.getId(), getUserCKanTokenFromSession(scope));
if(deleted){
logger.debug("Resource described by " + resource + " deleted");
@@ -620,8 +631,8 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
try{
String scope = (String)getThreadLocalRequest().getSession().getAttribute(SessionCatalogueAttributes.SCOPE_CLIENT_PORTLET_URL);
- String idFromTitle = org.gcube.datacatalogue.ckanutillibrary.utils.UtilMethods.nameFromTitle(title);
- return getCkanUtilsObj(scope).existProductWithNameOrId(idFromTitle, getUserCKanTokenFromSession(scope));
+ String idFromTitle = org.gcube.datacatalogue.ckanutillibrary.utils.UtilMethods.fromProductTitleToName(title);
+ return getCatalogue(scope).existProductWithNameOrId(idFromTitle);
}catch(Exception e){
logger.error("Unable to check if such a dataset id already exists", e);
diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/utils/Utils.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/utils/Utils.java
index 069fd68..cc3108b 100644
--- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/utils/Utils.java
+++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/utils/Utils.java
@@ -14,8 +14,8 @@ import org.gcube.common.homelibrary.home.workspace.WorkspaceItem;
import org.gcube.common.homelibrary.home.workspace.folder.FolderItem;
import org.gcube.common.homelibrary.home.workspace.folder.items.GCubeItem;
import org.gcube.common.scope.api.ScopeProvider;
-import org.gcube.datacatalogue.ckanutillibrary.CKanUtils;
-import org.gcube.datacatalogue.ckanutillibrary.models.RolesIntoOrganization;
+import org.gcube.datacatalogue.ckanutillibrary.DataCatalogue;
+import org.gcube.datacatalogue.ckanutillibrary.models.RolesCkanGroupOrOrg;
import org.gcube.datacatalogue.ckanutillibrary.utils.SessionCatalogueAttributes;
import org.gcube.datacatalogue.ckanutillibrary.utils.UtilMethods;
import org.gcube.datacatalogue.metadatadiscovery.DataCalogueMetadataFormatReader;
@@ -119,13 +119,13 @@ public class Utils {
}
/**
- * Retrieve the list of organizations in which the user has the ckan-admin role
+ * Retrieve the list of organizations in which the user has the admin/editor role
* @param currentScope the current scope
* @param username the current username
* @param groupName the current groupName
* @param ckanPublisherServicesImpl
*/
- public static List getUserOrganizationsListAdmin(String currentScope, String username, String groupName, CKANPublisherServicesImpl ckanPublisherServicesImpl){
+ public static List getUserOrganizationsListAdminEditor(String currentScope, String username, String groupName, CKANPublisherServicesImpl ckanPublisherServicesImpl){
List toReturn = new ArrayList();
@@ -160,7 +160,7 @@ public class Utils {
List roles = roleManager.listRolesByUserAndGroup(userid, groupManager.getGroupId(gCubeGroupName));
// get highest role according liferay
- RolesIntoOrganization correspondentRoleToCheck = getLiferayHighestRoleInOrg(roles);
+ RolesCkanGroupOrOrg correspondentRoleToCheck = getLiferayHighestRoleInOrg(roles);
checkIfRoleIsSetInCkanInstance(username, gCubeGroupName, gCubeGroup.getGroupId(), correspondentRoleToCheck, toReturn, groupManager, ckanPublisherServicesImpl);
}
@@ -177,7 +177,7 @@ public class Utils {
List roles = roleManager.listRolesByUserAndGroup(userid, groupManager.getGroupId(gCubeGroupName));
// get highest role according liferay
- RolesIntoOrganization correspondentRoleToCheck = getLiferayHighestRoleInOrg(roles);
+ RolesCkanGroupOrOrg correspondentRoleToCheck = getLiferayHighestRoleInOrg(roles);
checkIfRoleIsSetInCkanInstance(username, gCubeGroupName, gCubeGroup.getGroupId(), correspondentRoleToCheck, toReturn, groupManager, ckanPublisherServicesImpl);
}
@@ -188,7 +188,7 @@ public class Utils {
logger.debug("The list of roles for " + username + " into " + groupName + " is " + roles);
// get highest role according liferay
- RolesIntoOrganization correspondentRoleToCheck = getLiferayHighestRoleInOrg(roles);
+ RolesCkanGroupOrOrg correspondentRoleToCheck = getLiferayHighestRoleInOrg(roles);
checkIfRoleIsSetInCkanInstance(username, groupName, currentGroupId, correspondentRoleToCheck, toReturn, groupManager, ckanPublisherServicesImpl);
}
@@ -214,18 +214,18 @@ public class Utils {
*/
private static void checkIfRoleIsSetInCkanInstance(String username,
String gCubeGroupName, long groupId,
- RolesIntoOrganization correspondentRoleToCheck,
+ RolesCkanGroupOrOrg correspondentRoleToCheck,
List orgs, GroupManager groupManager, CKANPublisherServicesImpl ckanPublisherServicesImpl) throws UserManagementSystemException, GroupRetrievalFault {
// with this invocation, we check if the role is present in ckan and if it is not it will be added
- CKanUtils ckanUtils = ckanPublisherServicesImpl.getCkanUtilsObj(groupManager.getInfrastructureScope(groupId));
+ DataCatalogue catalogue = ckanPublisherServicesImpl.getCatalogue(groupManager.getInfrastructureScope(groupId));
// if there is an instance of ckan in this scope..
- if(ckanUtils != null){
- boolean res = ckanUtils.checkRole(username, gCubeGroupName, correspondentRoleToCheck);
- if(res && !correspondentRoleToCheck.equals(RolesIntoOrganization.MEMBER)){
+ if(catalogue != null){
+ boolean res = catalogue.checkRoleIntoOrganization(username, gCubeGroupName, correspondentRoleToCheck);
+ if(res && !correspondentRoleToCheck.equals(RolesCkanGroupOrOrg.MEMBER)){
// get the orgs of the user and retrieve its title and name
- List ckanOrgs = ckanUtils.getOrganizationsByUser(username);
+ List ckanOrgs = catalogue.getOrganizationsByUser(username);
for (CkanOrganization ckanOrganization : ckanOrgs) {
if(ckanOrganization.getName().equals(gCubeGroupName.toLowerCase())){
orgs.add(new OrganizationBean(ckanOrganization.getTitle(), ckanOrganization.getName()));
@@ -242,18 +242,18 @@ public class Utils {
* @param roles
* @return
*/
- private static RolesIntoOrganization getLiferayHighestRoleInOrg(
+ private static RolesCkanGroupOrOrg getLiferayHighestRoleInOrg(
List roles) {
// NOTE: it is supposed that there is just one role for this person correspondent to the one in the catalog
for (GCubeRole gCubeRole : roles) {
if(gCubeRole.getRoleName().equalsIgnoreCase(GatewayRolesNames.CATALOGUE_ADMIN.getRoleName())){
- return RolesIntoOrganization.ADMIN;
+ return RolesCkanGroupOrOrg.ADMIN;
}
if(gCubeRole.getRoleName().equalsIgnoreCase(GatewayRolesNames.CATALOGUE_EDITOR.getRoleName())){
- return RolesIntoOrganization.EDITOR;
+ return RolesCkanGroupOrOrg.EDITOR;
}
}
- return RolesIntoOrganization.MEMBER;
+ return RolesCkanGroupOrOrg.MEMBER;
}
/**
diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/shared/DatasetMetadataBean.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/shared/DatasetMetadataBean.java
index 104aca9..25c7af9 100644
--- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/shared/DatasetMetadataBean.java
+++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/shared/DatasetMetadataBean.java
@@ -8,7 +8,7 @@ import java.util.Map;
* This bean will contain during ckan metadata creation the following information
* (related to the workspace folder that represents a dataset)
*
- * - id -> the id of the workspace folder
+ *
- id -> the id that will be assigned by ckan
*
- Title -> folder's name
*
- Description -> folders' description
*
- tags -> folder's custom fields keys' names
@@ -20,9 +20,9 @@ import java.util.Map;
*
- organizationsList -> list of organizations to which the user belong (and in which
* he wants to publish)
*
- list of metadata, that is custom fields per vre
+ *
- the name of the chosen profile used
*
- * @author Costantino Perciante at ISTI-CNR
- * (costantino.perciante@isti.cnr.it)
+ * @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
*/
@SuppressWarnings("serial")
public class DatasetMetadataBean implements Serializable {
@@ -47,6 +47,7 @@ public class DatasetMetadataBean implements Serializable {
private String selectedOrganization;
private List resources; // in case of workspace, this is the list of children
private List metadataList;
+ private String chosenProfile; // the name of the MetaDataProfile chosen
public DatasetMetadataBean(){
super();
@@ -262,7 +263,14 @@ public class DatasetMetadataBean implements Serializable {
public void setAuthorFullName(String authorFullName) {
this.authorFullName = authorFullName;
}
+
+ public String getChosenProfile() {
+ return chosenProfile;
+ }
+ public void setChosenProfile(String chosenProfile) {
+ this.chosenProfile = chosenProfile;
+ }
@Override
public String toString() {
return "DatasetMetadataBean [id=" + id + ", title=" + title
@@ -277,6 +285,7 @@ public class DatasetMetadataBean implements Serializable {
+ ", organizationList=" + organizationList
+ ", selectedOrganization=" + selectedOrganization
+ ", resources=" + resources + ", metadataList=" + metadataList
- + "]";
+ + ", chosenProfile=" + chosenProfile + "]";
}
+
}
diff --git a/src/test/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/TestClass.java b/src/test/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/TestClass.java
index eccf995..67ffefc 100644
--- a/src/test/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/TestClass.java
+++ b/src/test/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/TestClass.java
@@ -1,5 +1,6 @@
package org.gcube.portlets.widgets.ckandatapublisherwidget.client;
+import java.util.ArrayList;
import java.util.List;
import org.gcube.common.homelibrary.home.HomeLibrary;
@@ -13,12 +14,22 @@ import org.gcube.common.homelibrary.home.workspace.catalogue.WorkspaceCatalogue;
import org.gcube.common.homelibrary.home.workspace.exceptions.ItemNotFoundException;
import org.gcube.common.homelibrary.home.workspace.exceptions.WorkspaceFolderNotFoundException;
import org.gcube.common.scope.api.ScopeProvider;
+import org.gcube.datacatalogue.metadatadiscovery.DataCalogueMetadataFormatReader;
+import org.gcube.datacatalogue.metadatadiscovery.bean.MetadataType;
+import org.gcube.datacatalogue.metadatadiscovery.bean.jaxb.MetadataField;
+import org.gcube.datacatalogue.metadatadiscovery.bean.jaxb.MetadataFormat;
+import org.gcube.datacatalogue.metadatadiscovery.bean.jaxb.MetadataValidator;
+import org.gcube.datacatalogue.metadatadiscovery.bean.jaxb.MetadataVocabulary;
import org.gcube.portlets.widgets.ckandatapublisherwidget.server.CKANPublisherServicesImpl;
+import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.DataType;
+import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.MetaDataTypeWrapper;
+import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.MetadataFieldWrapper;
+import org.junit.Test;
public class TestClass {
- //@Test
+ @Test
public void testUser() {
assert(new CKANPublisherServicesImpl().getDevelopmentUser().equals(CKANPublisherServicesImpl.TEST_USER));
@@ -26,6 +37,7 @@ public class TestClass {
}
//@Test
+ @SuppressWarnings("deprecation")
public void testCopyResources() throws WorkspaceFolderNotFoundException, InternalErrorException, HomeNotFoundException, UserNotFoundException, ItemNotFoundException{
ScopeProvider.instance.set("/gcube/devNext/NextNext");
@@ -90,4 +102,65 @@ public class TestClass {
System.out.println("Notification_portlet".replaceAll("[^A-Za-z0-9.-_]", " "));
}
+ //@Test
+ public void retrieveMetadata(){
+
+ try {
+
+ ScopeProvider.instance.set("/gcube/devNext/NextNext");
+
+ DataCalogueMetadataFormatReader reader = new DataCalogueMetadataFormatReader();
+
+ for (MetadataType mt : reader.getListOfMetadataTypes()) {
+
+ System.out.println("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" + mt.getName());
+ MetadataFormat metadata = reader.getMetadataFormatForMetadataType(mt);
+
+ // we need to wrap the list of metadata
+ List wrapperList = new ArrayList();
+ List toWrap = metadata.getMetadataFields();
+
+ for(MetadataField metadataField: toWrap){
+
+
+
+ MetadataFieldWrapper wrapperObj = new MetadataFieldWrapper();
+ wrapperObj.setDefaultValue(metadataField.getDefaultValue());
+ wrapperObj.setFieldName(metadataField.getFieldName());
+ wrapperObj.setType(DataType.valueOf(metadataField.getDataType().toString()));
+ wrapperObj.setMandatory(metadataField.getMandatory());
+ wrapperObj.setNote(metadataField.getNote());
+
+ MetadataValidator validator = metadataField.getValidator();
+ if(validator != null)
+ wrapperObj.setValidator(validator.getRegularExpression());
+
+ MetadataVocabulary vocabulary = metadataField.getVocabulary();
+
+ if(vocabulary != null){
+ wrapperObj.setVocabulary(vocabulary.getVocabularyFields());
+ wrapperObj.setMultiSelection(vocabulary.isMultiSelection());
+ }
+
+ // add to the list
+ wrapperList.add(wrapperObj);
+
+ }
+
+ // wrap the mt as well
+ MetaDataTypeWrapper typeWrapper = new MetaDataTypeWrapper();
+ typeWrapper.setDescription(mt.getDescription());
+ typeWrapper.setId(mt.getId());
+ typeWrapper.setName(mt.getName());
+
+ }
+
+ System.out.println("List of profiles has been saved into session");
+
+ } catch (Exception e) {
+ System.out.println("Error while retrieving metadata beans " + e);
+ }
+
+ }
+
}