Group creation and management are now supported. Moved resources classes onto another package.
git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/widgets/ckan-metadata-publisher-widget@131994 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
baddb2e8cb
commit
c8df6dea6a
2
pom.xml
2
pom.xml
|
@ -152,7 +152,7 @@
|
|||
<dependency>
|
||||
<groupId>org.gcube.data-catalogue</groupId>
|
||||
<artifactId>ckan-util-library</artifactId>
|
||||
<version>[1.0.0-SNAPSHOT, 2.0.0-SNAPSHOT)</version>
|
||||
<version>[2.0.0-SNAPSHOT, 3.0.0-SNAPSHOT)</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
|
|
@ -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<MetaDataProfileBean> 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){
|
||||
|
||||
|
|
|
@ -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;
|
|
@ -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;
|
|
@ -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;
|
|
@ -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<ResourceBeanWrapper, String> descColumn = new Column<ResourceBeanWrapper, String>(new EditTextCell()) {
|
|
@ -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";
|
||||
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -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<CkanLicense> titlesLicenses = getCkanUtilsObj(scope).getLicenses();
|
||||
List<CkanLicense> titlesLicenses = getCatalogue(scope).getLicenses();
|
||||
List<String> titles = new ArrayList<String>();
|
||||
List<String> urls = new ArrayList<String>();
|
||||
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<ResourceBean> resources = new ArrayList<ResourceBean>();
|
||||
|
||||
|
@ -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);
|
||||
|
|
|
@ -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<OrganizationBean> getUserOrganizationsListAdmin(String currentScope, String username, String groupName, CKANPublisherServicesImpl ckanPublisherServicesImpl){
|
||||
public static List<OrganizationBean> getUserOrganizationsListAdminEditor(String currentScope, String username, String groupName, CKANPublisherServicesImpl ckanPublisherServicesImpl){
|
||||
|
||||
List<OrganizationBean> toReturn = new ArrayList<OrganizationBean>();
|
||||
|
||||
|
@ -160,7 +160,7 @@ public class Utils {
|
|||
List<GCubeRole> 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<GCubeRole> 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<OrganizationBean> 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<CkanOrganization> ckanOrgs = ckanUtils.getOrganizationsByUser(username);
|
||||
List<CkanOrganization> 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<GCubeRole> 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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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)
|
||||
* <ul>
|
||||
* <li> id -> the id of the workspace folder
|
||||
* <li> id -> the id that will be assigned by ckan
|
||||
* <li> Title -> folder's name
|
||||
* <li> Description -> folders' description
|
||||
* <li> tags -> folder's custom fields keys' names
|
||||
|
@ -20,9 +20,9 @@ import java.util.Map;
|
|||
* <li> organizationsList -> list of organizations to which the user belong (and in which
|
||||
* he wants to publish)
|
||||
* <li> list of metadata, that is custom fields per vre
|
||||
* <li> the name of the chosen profile used
|
||||
* </ul>
|
||||
* @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<ResourceBeanWrapper> resources; // in case of workspace, this is the list of children
|
||||
private List<MetaDataProfileBean> 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 + "]";
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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<MetadataFieldWrapper> wrapperList = new ArrayList<MetadataFieldWrapper>();
|
||||
List<MetadataField> 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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue