minor fix when checking roles. Support for copying files in catalogue area almost finished
git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/widgets/ckan-metadata-publisher-widget@131766 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
58750aa80c
commit
52d3efce0c
|
@ -126,7 +126,7 @@ public class CKanMetadataPublisher implements EntryPoint {
|
||||||
|
|
||||||
String idFolderWorkspace = "d3a37eb9-1589-4c95-a9d0-c473a02d4f0f";
|
String idFolderWorkspace = "d3a37eb9-1589-4c95-a9d0-c473a02d4f0f";
|
||||||
String owner = "costantino.perciante";
|
String owner = "costantino.perciante";
|
||||||
RootPanel.get("ckan-metadata-publisher-div").add(new CreateDatasetForm(idFolderWorkspace ,owner, eventBus));
|
RootPanel.get("ckan-metadata-publisher-div").add(new CreateDatasetForm(idFolderWorkspace, eventBus));
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,4 +58,12 @@ public interface CKanPublisherService extends RemoteService {
|
||||||
* @return <b>true</b> on success, false otherwise
|
* @return <b>true</b> on success, false otherwise
|
||||||
*/
|
*/
|
||||||
boolean deleteResourceFromDataset(ResourceBeanWrapper resource);
|
boolean deleteResourceFromDataset(ResourceBeanWrapper resource);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Given the title the user wants to give to the new product to create, a check is performed
|
||||||
|
* to understand if a dataset with the proposed title (and so the id generateda at server side) already exists
|
||||||
|
* @param title
|
||||||
|
* @return true if it exists, false otherwise
|
||||||
|
*/
|
||||||
|
boolean datasetIdAlreadyExists(String title);
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,4 +60,12 @@ public interface CKanPublisherServiceAsync {
|
||||||
*/
|
*/
|
||||||
void getProfiles(String orgName, AsyncCallback<List<MetaDataProfileBean>> callback);
|
void getProfiles(String orgName, AsyncCallback<List<MetaDataProfileBean>> callback);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Given the title the user wants to give to the new product to create, a check is performed
|
||||||
|
* to understand if a dataset with the proposed title (and so the id generateda at server side) already exists
|
||||||
|
* @param title
|
||||||
|
* @return true if it exists, false otherwise
|
||||||
|
*/
|
||||||
|
void datasetIdAlreadyExists(String title, AsyncCallback<Boolean> callback);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -156,6 +156,9 @@ public class CreateDatasetForm extends Composite{
|
||||||
@UiField Icon infoIconResources;
|
@UiField Icon infoIconResources;
|
||||||
@UiField FocusPanel focusPanelResources;
|
@UiField FocusPanel focusPanelResources;
|
||||||
@UiField Popover popoverResources;
|
@UiField Popover popoverResources;
|
||||||
|
@UiField Icon infoIconTitle;
|
||||||
|
@UiField FocusPanel focusPanelTitle;
|
||||||
|
@UiField Popover popoverTitle;
|
||||||
@UiField ControlGroup metadataProfilesControlGroup;
|
@UiField ControlGroup metadataProfilesControlGroup;
|
||||||
@UiField ControlGroup productTitleGroup;
|
@UiField ControlGroup productTitleGroup;
|
||||||
@UiField ControlGroup maintainerControlGroup;
|
@UiField ControlGroup maintainerControlGroup;
|
||||||
|
@ -208,9 +211,9 @@ public class CreateDatasetForm extends Composite{
|
||||||
* Invoked in the most general case
|
* Invoked in the most general case
|
||||||
* @param owner
|
* @param owner
|
||||||
*/
|
*/
|
||||||
public CreateDatasetForm(String owner, HandlerManager eventBus) {
|
public CreateDatasetForm(HandlerManager eventBus) {
|
||||||
|
|
||||||
createDatasetFormBody(false, null, owner, eventBus);
|
createDatasetFormBody(false, null, eventBus);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -219,9 +222,9 @@ public class CreateDatasetForm extends Composite{
|
||||||
* @param idFolderWorkspace
|
* @param idFolderWorkspace
|
||||||
* @param owner
|
* @param owner
|
||||||
*/
|
*/
|
||||||
public CreateDatasetForm(String idFolderWorkspace, String owner, HandlerManager eventBus) {
|
public CreateDatasetForm(String idFolderWorkspace, HandlerManager eventBus) {
|
||||||
|
|
||||||
createDatasetFormBody(true, idFolderWorkspace, owner, eventBus);
|
createDatasetFormBody(true, idFolderWorkspace, eventBus);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -263,12 +266,10 @@ public class CreateDatasetForm extends Composite{
|
||||||
* @param owner
|
* @param owner
|
||||||
* @param eventBus
|
* @param eventBus
|
||||||
*/
|
*/
|
||||||
private void createDatasetFormBody(final boolean isWorkspaceRequest, String idFolderWorkspace, String owner, final HandlerManager eventBus){
|
private void createDatasetFormBody(final boolean isWorkspaceRequest, String idFolderWorkspace, final HandlerManager eventBus){
|
||||||
|
|
||||||
initWidget(uiBinder.createAndBindUi(this));
|
initWidget(uiBinder.createAndBindUi(this));
|
||||||
|
|
||||||
this.owner = owner;
|
|
||||||
|
|
||||||
// save event bus
|
// save event bus
|
||||||
this.eventBus = eventBus;
|
this.eventBus = eventBus;
|
||||||
|
|
||||||
|
@ -634,7 +635,6 @@ public class CreateDatasetForm extends Composite{
|
||||||
}else{
|
}else{
|
||||||
alertOnContinue("Please check inserted data [" + errorMsg + "]", AlertType.ERROR);
|
alertOnContinue("Please check inserted data [" + errorMsg + "]", AlertType.ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -958,6 +958,15 @@ public class CreateDatasetForm extends Composite{
|
||||||
focusPanelResources
|
focusPanelResources
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// title
|
||||||
|
preparePopupPanelAndPopover(
|
||||||
|
InfoIconsLabels.TITLE_INFO_ID_POPUP,
|
||||||
|
InfoIconsLabels.TITLE_INFO_TEXT,
|
||||||
|
InfoIconsLabels.TITLE_INFO_CAPTION,
|
||||||
|
infoIconTitle,
|
||||||
|
popoverTitle,
|
||||||
|
focusPanelTitle
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1040,8 +1049,6 @@ public class CreateDatasetForm extends Composite{
|
||||||
*/
|
*/
|
||||||
private String validateDataOnContinue() {
|
private String validateDataOnContinue() {
|
||||||
|
|
||||||
String errorMessage = null;
|
|
||||||
|
|
||||||
// remove errors
|
// remove errors
|
||||||
productTitleGroup.setType(ControlGroupType.NONE);
|
productTitleGroup.setType(ControlGroupType.NONE);
|
||||||
maintainerControlGroup.setType(ControlGroupType.NONE);
|
maintainerControlGroup.setType(ControlGroupType.NONE);
|
||||||
|
@ -1050,52 +1057,51 @@ public class CreateDatasetForm extends Composite{
|
||||||
organizationsGroup.setType(ControlGroupType.NONE);
|
organizationsGroup.setType(ControlGroupType.NONE);
|
||||||
|
|
||||||
if(titleTextBox.getText().isEmpty()){
|
if(titleTextBox.getText().isEmpty()){
|
||||||
errorMessage = "Missing title";
|
|
||||||
productTitleGroup.setType(ControlGroupType.ERROR);
|
productTitleGroup.setType(ControlGroupType.ERROR);
|
||||||
return errorMessage;
|
return "Missing title";
|
||||||
}
|
}
|
||||||
|
|
||||||
// better check for the title
|
// better check for the title
|
||||||
String regexTitleSubWord = "^[a-zA-Z0-9_]+$";
|
String regexTitleSubWord = "[^a-zA-Z0-9_.-]";
|
||||||
String[] splittedTitle = titleTextBox.getText().split(" ");
|
String[] splittedTitle = titleTextBox.getText().split(" ");
|
||||||
|
|
||||||
for (String word : splittedTitle) {
|
for (String word : splittedTitle) {
|
||||||
|
String replaced = word.replaceAll(regexTitleSubWord, "");
|
||||||
if(!word.matches(regexTitleSubWord)){
|
if(!replaced.equals(word)){
|
||||||
productTitleGroup.setType(ControlGroupType.ERROR);
|
productTitleGroup.setType(ControlGroupType.ERROR);
|
||||||
return "Please note that only alphanumeric characters are allowed for the title";
|
return "Please note that only alphanumeric characters are allowed for the title";
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// email reg expression
|
// email reg expression
|
||||||
String regexMail = "\\b[\\w.%-]+@[-.\\w]+\\.[A-Za-z]{2,4}\\b";
|
String regexMail = "\\b[\\w.%-]+@[-.\\w]+\\.[A-Za-z]{2,4}\\b";
|
||||||
if(!validateByRegExpression(maintainerEmailTextbox.getText(), regexMail)){
|
if(!validateByRegExpression(maintainerEmailTextbox.getText(), regexMail)){
|
||||||
errorMessage = "Not valid maintainer email";
|
|
||||||
maintainerControlGroup.setType(ControlGroupType.ERROR);
|
maintainerControlGroup.setType(ControlGroupType.ERROR);
|
||||||
return errorMessage;
|
return "Not valid maintainer email";
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if version is a number
|
// check if version is a number
|
||||||
try{
|
try{
|
||||||
Integer.valueOf(versionTextbox.getText());
|
int number = Integer.valueOf(versionTextbox.getText());
|
||||||
|
if(number <= 0)
|
||||||
|
throw new Exception();
|
||||||
}catch(Exception e){
|
}catch(Exception e){
|
||||||
versionControlGroup.setType(ControlGroupType.ERROR);
|
versionControlGroup.setType(ControlGroupType.ERROR);
|
||||||
return errorMessage = "Version must be a natural number";
|
return "Version must be a natural number greater than zero";
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if metadata profile is different from none and its mandatory fields have been fulfilled
|
// check if metadata profile is different from none and its mandatory fields have been fulfilled
|
||||||
if(checkSelectedMetaDataProfile()){
|
if(checkSelectedMetaDataProfile()){
|
||||||
errorMessage = "You must select a metadata profile different frome none";
|
|
||||||
metadataProfilesControlGroup.setType(ControlGroupType.ERROR);
|
metadataProfilesControlGroup.setType(ControlGroupType.ERROR);
|
||||||
|
return "You must select a metadata profile different frome none";
|
||||||
}
|
}
|
||||||
|
|
||||||
if(organizationsListbox.getSelectedItemText() == null){
|
if(organizationsListbox.getSelectedItemText() == null){
|
||||||
organizationsGroup.setType(ControlGroupType.ERROR);
|
organizationsGroup.setType(ControlGroupType.ERROR);
|
||||||
errorMessage = "You must select an organization in which you want to publish";
|
return "You must select an organization in which you want to publish";
|
||||||
}
|
}
|
||||||
|
|
||||||
return errorMessage;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -62,7 +62,15 @@
|
||||||
</b:ControlLabel>
|
</b:ControlLabel>
|
||||||
<b:Controls>
|
<b:Controls>
|
||||||
<b:TextBox alternateSize="LARGE" placeholder="Product title"
|
<b:TextBox alternateSize="LARGE" placeholder="Product title"
|
||||||
width="95%" b:id="title" title="Product title" ui:field="titleTextBox" />
|
width="90%" b:id="title" title="Product title" ui:field="titleTextBox" />
|
||||||
|
<span style="float:right; width:5%; color: #aaaaaa;">
|
||||||
|
<b:Popover ui:field="popoverTitle" html="true"
|
||||||
|
animation="true" placement="LEFT">
|
||||||
|
<g:FocusPanel ui:field="focusPanelTitle">
|
||||||
|
<b:Icon type="INFO_SIGN" size="TWO_TIMES" ui:field="infoIconTitle" />
|
||||||
|
</g:FocusPanel>
|
||||||
|
</b:Popover>
|
||||||
|
</span>
|
||||||
</b:Controls>
|
</b:Controls>
|
||||||
</b:ControlGroup>
|
</b:ControlGroup>
|
||||||
|
|
||||||
|
|
|
@ -317,9 +317,7 @@ public class MetaDataFieldSkeleton extends Composite{
|
||||||
List<String> vocabulary = field.getVocabulary();
|
List<String> vocabulary = field.getVocabulary();
|
||||||
|
|
||||||
for (String term : vocabulary) {
|
for (String term : vocabulary) {
|
||||||
|
|
||||||
((ListBox)holder).addItem(term);
|
((ListBox)holder).addItem(term);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// set default value
|
// set default value
|
||||||
|
@ -574,7 +572,7 @@ public class MetaDataFieldSkeleton extends Composite{
|
||||||
if(field.getValidator() == null || field.getValidator().isEmpty())
|
if(field.getValidator() == null || field.getValidator().isEmpty())
|
||||||
return null; // no further check
|
return null; // no further check
|
||||||
else return checkValidator(textBoxValue, field.getValidator()) ? null : MALFORMED_ATTRIBUTE;
|
else return checkValidator(textBoxValue, field.getValidator()) ? null : MALFORMED_ATTRIBUTE;
|
||||||
else return " a mandatory attribute cannot be empty";
|
else return MANDATORY_ATTRIBUTE_MISSING;
|
||||||
|
|
||||||
}else{
|
}else{
|
||||||
if(textBoxValue.trim().isEmpty())
|
if(textBoxValue.trim().isEmpty())
|
||||||
|
@ -582,7 +580,25 @@ public class MetaDataFieldSkeleton extends Composite{
|
||||||
else return checkValidator(textBoxValue, field.getValidator()) ? null : MALFORMED_ATTRIBUTE;
|
else return checkValidator(textBoxValue, field.getValidator()) ? null : MALFORMED_ATTRIBUTE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else return null;
|
else{
|
||||||
|
|
||||||
|
String listBoxCurrentValue = getFieldCurrentValue();
|
||||||
|
|
||||||
|
// listbox case
|
||||||
|
if(!field.getMandatory()){
|
||||||
|
|
||||||
|
if(field.getValidator() == null || field.getValidator().isEmpty())
|
||||||
|
return null;
|
||||||
|
else
|
||||||
|
return checkValidator(listBoxCurrentValue, field.getValidator()) ? null : MALFORMED_ATTRIBUTE;
|
||||||
|
|
||||||
|
}else{
|
||||||
|
|
||||||
|
return listBoxCurrentValue == null || listBoxCurrentValue.isEmpty() ? MANDATORY_ATTRIBUTE_MISSING : null;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
default: return null;
|
default: return null;
|
||||||
|
|
||||||
|
|
|
@ -59,4 +59,9 @@ public class InfoIconsLabels {
|
||||||
public static final String CUSTOM_FIELDS_INFO_CAPTION = "Product Custom Fields";
|
public static final String CUSTOM_FIELDS_INFO_CAPTION = "Product Custom Fields";
|
||||||
public static final String CUSTOM_FIELDS_INFO_TEXT = "Custom fields are customable metadata that will be added to the product. You have to choose a unique key for the field and a value for this. You can remove them at any time until you create theproduct.";
|
public static final String CUSTOM_FIELDS_INFO_TEXT = "Custom fields are customable metadata that will be added to the product. You have to choose a unique key for the field and a value for this. You can remove them at any time until you create theproduct.";
|
||||||
|
|
||||||
|
// 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.";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,7 @@ import org.gcube.application.framework.core.session.ASLSession;
|
||||||
import org.gcube.application.framework.core.session.SessionManager;
|
import org.gcube.application.framework.core.session.SessionManager;
|
||||||
import org.gcube.common.homelibrary.home.HomeLibrary;
|
import org.gcube.common.homelibrary.home.HomeLibrary;
|
||||||
import org.gcube.common.homelibrary.home.workspace.Workspace;
|
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.WorkspaceItem;
|
||||||
import org.gcube.common.homelibrary.home.workspace.catalogue.WorkspaceCatalogue;
|
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.FolderItem;
|
||||||
|
@ -346,7 +347,7 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
|
||||||
WorkspaceItem originalFolder = ws.getItem(folderId);
|
WorkspaceItem originalFolder = ws.getItem(folderId);
|
||||||
|
|
||||||
// set some info
|
// set some info
|
||||||
String onlyAlphanumeric = originalFolder.getName().replaceAll("[^A-Za-z0-9]", ""); // that is, remove characters different than A-Z,a-z,0-9
|
String onlyAlphanumeric = originalFolder.getName().replaceAll("[^A-Za-z0-9.-_]", " "); // that is, remove characters different than the ones inside
|
||||||
bean.setTitle(onlyAlphanumeric);
|
bean.setTitle(onlyAlphanumeric);
|
||||||
bean.setDescription(originalFolder.getDescription());
|
bean.setDescription(originalFolder.getDescription());
|
||||||
|
|
||||||
|
@ -359,9 +360,7 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
|
||||||
|
|
||||||
for (WorkspaceItem file : originalFolder.getChildren()) {
|
for (WorkspaceItem file : originalFolder.getChildren()) {
|
||||||
if(!file.isFolder()){
|
if(!file.isFolder()){
|
||||||
|
|
||||||
childrenIds.add(file.getId());
|
childrenIds.add(file.getId());
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -381,19 +380,29 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
|
||||||
private List<ResourceBean> copyResourcesToUserCatalogueArea(
|
private List<ResourceBean> copyResourcesToUserCatalogueArea(
|
||||||
List<ResourceBeanWrapper> resourcesToAdd, String folderId, String userName, DatasetMetadataBean bean) throws Exception{
|
List<ResourceBeanWrapper> resourcesToAdd, String folderId, String userName, DatasetMetadataBean bean) throws Exception{
|
||||||
|
|
||||||
|
logger.debug("Request to copy onto catalogue area. Parameters are resources to add" + resourcesToAdd);
|
||||||
|
logger.debug("Request to copy onto catalogue area. Folder id is " + folderId);
|
||||||
|
logger.debug("Request to copy onto catalogue area. Username is " + userName);
|
||||||
|
logger.debug("Request to copy onto catalogue area. DatasetMetadataBean is " + bean);
|
||||||
|
|
||||||
// in to the .catalogue area of the user's workspace
|
// in to the .catalogue area of the user's workspace
|
||||||
Workspace ws = HomeLibrary
|
Workspace ws = HomeLibrary
|
||||||
.getHomeManagerFactory()
|
.getHomeManagerFactory()
|
||||||
.getHomeManager()
|
.getHomeManager()
|
||||||
.getHome(userName).getWorkspace();
|
.getHome(userName)
|
||||||
|
.getWorkspace();
|
||||||
WorkspaceItem originalFolder = ws.getItem(folderId);
|
|
||||||
|
|
||||||
// Retrieve the catalogue of the user
|
// Retrieve the catalogue of the user
|
||||||
WorkspaceCatalogue userCatalogue = ws.getCatalogue();
|
WorkspaceCatalogue userCatalogue = ws.getCatalogue();
|
||||||
|
|
||||||
// Create the folder in the catalogue
|
// Create the folder in the catalogue
|
||||||
WorkspaceItem copiedFolder = userCatalogue.addWorkspaceItem(originalFolder.getPath(), null); // add to .catalogue root
|
WorkspaceItem copiedFolder = userCatalogue.addWorkspaceItem(folderId, userCatalogue.getId()); // add to .catalogue root area
|
||||||
|
|
||||||
|
// change description for the folder
|
||||||
|
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()));
|
||||||
|
|
||||||
List<ResourceBean> resources = new ArrayList<ResourceBean>();
|
List<ResourceBean> resources = new ArrayList<ResourceBean>();
|
||||||
|
|
||||||
|
@ -404,14 +413,21 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
|
||||||
|
|
||||||
// ok it is a file, so copy it into the copiedFolder
|
// ok it is a file, so copy it into the copiedFolder
|
||||||
WorkspaceItem copiedFile = userCatalogue.addWorkspaceItem(resourceBeanWrapper.getId(), copiedFolder.getId());
|
WorkspaceItem copiedFile = userCatalogue.addWorkspaceItem(resourceBeanWrapper.getId(), copiedFolder.getId());
|
||||||
|
|
||||||
|
// name and description could have been edited
|
||||||
|
copiedFile.setDescription(resourceBeanWrapper.getDescription());
|
||||||
|
|
||||||
resources.add(new ResourceBean(
|
resources.add(new ResourceBean(
|
||||||
copiedFile.getPublicLink(true),
|
copiedFile.getPublicLink(true),
|
||||||
copiedFile.getName(),
|
resourceBeanWrapper.getName(),
|
||||||
copiedFile.getDescription(),
|
copiedFile.getDescription(),
|
||||||
copiedFile.getId(),
|
copiedFile.getId(),
|
||||||
userName,
|
userName,
|
||||||
null, // to be set
|
null, // to be set
|
||||||
((FolderItem)copiedFile).getMimeType()));
|
((FolderItem)copiedFile).getMimeType()));
|
||||||
|
|
||||||
|
// postpone rename operation
|
||||||
|
copiedFile.rename(resourceBeanWrapper.getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -459,7 +475,7 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.debug("The user wants to publish in organization with name " + organizationNameOrId + " and current scope name is " + aslSession.getScopeName());
|
logger.debug("The user wants to publish in organization with name " + organizationNameOrId);
|
||||||
String scope = Utils.retrieveScopeFromOrganizationName(organizationNameOrId);
|
String scope = Utils.retrieveScopeFromOrganizationName(organizationNameOrId);
|
||||||
CKanUtils utils = getCkanUtilsObj(scope);
|
CKanUtils utils = getCkanUtilsObj(scope);
|
||||||
|
|
||||||
|
@ -594,4 +610,22 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
|
||||||
|
|
||||||
return toReturn;
|
return toReturn;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean datasetIdAlreadyExists(String title) {
|
||||||
|
|
||||||
|
if(title == null || title.isEmpty())
|
||||||
|
return true; // it's an error somehow
|
||||||
|
|
||||||
|
try{
|
||||||
|
|
||||||
|
String scope = (String)getThreadLocalRequest().getSession().getAttribute(SessionCatalogueAttributes.SCOPE_CLIENT_PORTLET_URL);
|
||||||
|
return getCkanUtilsObj(scope).existProductWithNameOrId(title);
|
||||||
|
|
||||||
|
}catch(Exception e){
|
||||||
|
logger.error("Unable to check if such a dataset id already exists", e);
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -113,7 +113,6 @@ public class Utils {
|
||||||
}
|
}
|
||||||
} catch (InternalErrorException e) {
|
} catch (InternalErrorException e) {
|
||||||
logger.error("Error in server getItemProperties: ", e);
|
logger.error("Error in server getItemProperties: ", e);
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
@ -163,10 +162,6 @@ public class Utils {
|
||||||
// get highest role according liferay
|
// get highest role according liferay
|
||||||
RolesIntoOrganization correspondentRoleToCheck = getLiferayHighestRoleInOrg(roles);
|
RolesIntoOrganization correspondentRoleToCheck = getLiferayHighestRoleInOrg(roles);
|
||||||
|
|
||||||
// if the role is member, continue
|
|
||||||
if(correspondentRoleToCheck.equals(RolesIntoOrganization.MEMBER))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
checkIfRoleIsSetInCkanInstance(username, gCubeGroupName, gCubeGroup.getGroupId(), correspondentRoleToCheck, toReturn, groupManager, ckanPublisherServicesImpl);
|
checkIfRoleIsSetInCkanInstance(username, gCubeGroupName, gCubeGroup.getGroupId(), correspondentRoleToCheck, toReturn, groupManager, ckanPublisherServicesImpl);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -184,10 +179,6 @@ public class Utils {
|
||||||
// get highest role according liferay
|
// get highest role according liferay
|
||||||
RolesIntoOrganization correspondentRoleToCheck = getLiferayHighestRoleInOrg(roles);
|
RolesIntoOrganization correspondentRoleToCheck = getLiferayHighestRoleInOrg(roles);
|
||||||
|
|
||||||
// if the role is member, continue
|
|
||||||
if(correspondentRoleToCheck.equals(RolesIntoOrganization.MEMBER))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
checkIfRoleIsSetInCkanInstance(username, gCubeGroupName, gCubeGroup.getGroupId(), correspondentRoleToCheck, toReturn, groupManager, ckanPublisherServicesImpl);
|
checkIfRoleIsSetInCkanInstance(username, gCubeGroupName, gCubeGroup.getGroupId(), correspondentRoleToCheck, toReturn, groupManager, ckanPublisherServicesImpl);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -199,10 +190,7 @@ public class Utils {
|
||||||
// get highest role according liferay
|
// get highest role according liferay
|
||||||
RolesIntoOrganization correspondentRoleToCheck = getLiferayHighestRoleInOrg(roles);
|
RolesIntoOrganization correspondentRoleToCheck = getLiferayHighestRoleInOrg(roles);
|
||||||
|
|
||||||
if(correspondentRoleToCheck.equals(RolesIntoOrganization.ADMIN)){
|
checkIfRoleIsSetInCkanInstance(username, groupName, currentGroupId, correspondentRoleToCheck, toReturn, groupManager, ckanPublisherServicesImpl);
|
||||||
|
|
||||||
checkIfRoleIsSetInCkanInstance(username, groupName, currentGroupId, correspondentRoleToCheck, toReturn, groupManager, ckanPublisherServicesImpl);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}catch(Exception e){
|
}catch(Exception e){
|
||||||
logger.error("Unable to retrieve the role information for this user. Returning member role", e);
|
logger.error("Unable to retrieve the role information for this user. Returning member role", e);
|
||||||
|
@ -235,12 +223,11 @@ public class Utils {
|
||||||
// if there is an instance of ckan in this scope..
|
// if there is an instance of ckan in this scope..
|
||||||
if(ckanUtils != null){
|
if(ckanUtils != null){
|
||||||
boolean res = ckanUtils.checkRole(username, gCubeGroupName, correspondentRoleToCheck);
|
boolean res = ckanUtils.checkRole(username, gCubeGroupName, correspondentRoleToCheck);
|
||||||
if(res){
|
if(res && !correspondentRoleToCheck.equals(RolesIntoOrganization.MEMBER)){
|
||||||
|
// get the orgs of the user and retrieve its title and name
|
||||||
// get the orgs of the user
|
|
||||||
List<CkanOrganization> ckanOrgs = ckanUtils.getOrganizationsByUser(username);
|
List<CkanOrganization> ckanOrgs = ckanUtils.getOrganizationsByUser(username);
|
||||||
for (CkanOrganization ckanOrganization : ckanOrgs) {
|
for (CkanOrganization ckanOrganization : ckanOrgs) {
|
||||||
if(ckanOrganization.getName().equals(gCubeGroupName.toLowerCase())){//|| ckanOrganization.getName().equals(CKanUtilsImpl.PRODUCTION_CKAN_ORGNAME_ROOT)){
|
if(ckanOrganization.getName().equals(gCubeGroupName.toLowerCase())){
|
||||||
orgs.add(new OrganizationBean(ckanOrganization.getTitle(), ckanOrganization.getName()));
|
orgs.add(new OrganizationBean(ckanOrganization.getTitle(), ckanOrganization.getName()));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -262,6 +249,9 @@ public class Utils {
|
||||||
if(gCubeRole.getRoleName().equalsIgnoreCase(GatewayRolesNames.CATALOGUE_ADMIN.getRoleName())){
|
if(gCubeRole.getRoleName().equalsIgnoreCase(GatewayRolesNames.CATALOGUE_ADMIN.getRoleName())){
|
||||||
return RolesIntoOrganization.ADMIN;
|
return RolesIntoOrganization.ADMIN;
|
||||||
}
|
}
|
||||||
|
if(gCubeRole.getRoleName().equalsIgnoreCase(GatewayRolesNames.CATALOGUE_EDITOR.getRoleName())){
|
||||||
|
return RolesIntoOrganization.EDITOR;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return RolesIntoOrganization.MEMBER;
|
return RolesIntoOrganization.MEMBER;
|
||||||
}
|
}
|
||||||
|
@ -296,10 +286,6 @@ public class Utils {
|
||||||
|
|
||||||
if(scope != null){
|
if(scope != null){
|
||||||
|
|
||||||
|
|
||||||
// if(scope.equals(CKanUtilsImpl.PRODUCTION_SCOPE_ROOT))
|
|
||||||
// return CKanUtilsImpl.PRODUCTION_CKAN_ORGNAME_ROOT;
|
|
||||||
|
|
||||||
GroupManager gm = new LiferayGroupManager();
|
GroupManager gm = new LiferayGroupManager();
|
||||||
return gm.getGroup(gm.getGroupIdFromInfrastructureScope(scope)).getGroupName().toLowerCase();
|
return gm.getGroup(gm.getGroupIdFromInfrastructureScope(scope)).getGroupName().toLowerCase();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,21 @@
|
||||||
package org.gcube.portlets.widgets.ckandatapublisherwidget.client;
|
package org.gcube.portlets.widgets.ckandatapublisherwidget.client;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.gcube.common.homelibrary.home.HomeLibrary;
|
||||||
|
import org.gcube.common.homelibrary.home.exceptions.HomeNotFoundException;
|
||||||
|
import org.gcube.common.homelibrary.home.exceptions.InternalErrorException;
|
||||||
|
import org.gcube.common.homelibrary.home.exceptions.UserNotFoundException;
|
||||||
|
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.exceptions.ItemNotFoundException;
|
||||||
|
import org.gcube.common.homelibrary.home.workspace.exceptions.WorkspaceFolderNotFoundException;
|
||||||
|
import org.gcube.common.scope.api.ScopeProvider;
|
||||||
import org.gcube.portlets.widgets.ckandatapublisherwidget.server.CKANPublisherServicesImpl;
|
import org.gcube.portlets.widgets.ckandatapublisherwidget.server.CKANPublisherServicesImpl;
|
||||||
|
|
||||||
|
|
||||||
public class TestClass {
|
public class TestClass {
|
||||||
|
|
||||||
//@Test
|
//@Test
|
||||||
|
@ -11,4 +25,69 @@ public class TestClass {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//@Test
|
||||||
|
public void testCopyResources() throws WorkspaceFolderNotFoundException, InternalErrorException, HomeNotFoundException, UserNotFoundException, ItemNotFoundException{
|
||||||
|
|
||||||
|
ScopeProvider.instance.set("/gcube/devNext/NextNext");
|
||||||
|
|
||||||
|
Workspace ws = HomeLibrary
|
||||||
|
.getHomeManagerFactory()
|
||||||
|
.getHomeManager()
|
||||||
|
.getHome("costantino.perciante").getWorkspace();
|
||||||
|
|
||||||
|
WorkspaceItem originalFolder = ws.getItem("d3a37eb9-1589-4c95-a9d0-c473a02d4f0f");
|
||||||
|
|
||||||
|
List<? extends WorkspaceItem> children = originalFolder.getChildren();
|
||||||
|
// System.out.println("Folder is " + originalFolder.getName());
|
||||||
|
// for (WorkspaceItem workspaceItem : children) {
|
||||||
|
// System.out.println("Child is " + workspaceItem.getName());
|
||||||
|
// }
|
||||||
|
|
||||||
|
// copy to catalogue
|
||||||
|
WorkspaceCatalogue userCatalogue = ws.getCatalogue();
|
||||||
|
|
||||||
|
WorkspaceItem copiedFolder = userCatalogue.addWorkspaceItem(originalFolder.getId(), userCatalogue.getId());
|
||||||
|
System.out.println(copiedFolder.isHidden());
|
||||||
|
// for (WorkspaceItem workspaceItem : children) {
|
||||||
|
// WorkspaceItem copiedChildren = userCatalogue.addWorkspaceItem(workspaceItem.getId(), copiedFolder.getId());
|
||||||
|
// System.out.println("****************************** Copied file has path " + copiedChildren.getPath());
|
||||||
|
// }
|
||||||
|
|
||||||
|
// look at catalogue structure
|
||||||
|
List<WorkspaceItem> catalogueChildrens = ((WorkspaceFolder)userCatalogue).getChildren(true);
|
||||||
|
if(catalogueChildrens.isEmpty())
|
||||||
|
System.out.println("****************************** Catalogue Child list is empty");
|
||||||
|
else for (WorkspaceItem catalogueItem : catalogueChildrens) {
|
||||||
|
System.out.println("****************************** Catalogue Child is " + catalogueItem.getName());
|
||||||
|
if(catalogueItem.isFolder()){
|
||||||
|
WorkspaceFolder catalogueFolder = (WorkspaceFolder) catalogueItem;
|
||||||
|
System.out.println("**************************" + catalogueFolder.getName() + " it is a folder, printing children");
|
||||||
|
List<? extends WorkspaceItem> copiedFolderChildren = catalogueFolder.getChildren(true);
|
||||||
|
for (WorkspaceItem copiedFolderChildrenItem : copiedFolderChildren) {
|
||||||
|
System.out.println("****************************** Child is " + copiedFolderChildrenItem.getName());
|
||||||
|
copiedFolderChildrenItem.getPublicLink(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//@Test
|
||||||
|
public void testTitle(){
|
||||||
|
|
||||||
|
// String regexTitleSubWord = "[^a-zA-Z0-9_.-]";
|
||||||
|
// String title = "this is a test title .";
|
||||||
|
// String[] splittedTitle = title.split(" ");
|
||||||
|
//
|
||||||
|
// for (String word : splittedTitle) {
|
||||||
|
// System.out.println("Word is " + word);
|
||||||
|
// String replaced = word.replaceAll(regexTitleSubWord, "");
|
||||||
|
// System.out.println("Replaced Word is " + replaced);
|
||||||
|
// if(!replaced.equals(word)){
|
||||||
|
// System.out.println("Please note that only alphanumeric characters are allowed for the title");
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
System.out.println("Notification_portlet".replaceAll("[^A-Za-z0-9.-_]", " "));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue