Almost all logic for dataset creation as well as resource creation/deletion has been moved into the ckan-util-library
git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/widgets/ckan-metadata-publisher-widget@129108 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
0ded532dde
commit
053daea14a
6
pom.xml
6
pom.xml
|
@ -170,12 +170,6 @@
|
||||||
<artifactId>gcube-widgets</artifactId>
|
<artifactId>gcube-widgets</artifactId>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>net.htmlparser.jericho</groupId>
|
|
||||||
<artifactId>jericho-html</artifactId>
|
|
||||||
<version>3.3</version>
|
|
||||||
<scope>compile</scope>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
|
|
@ -2,7 +2,7 @@ package org.gcube.portlets.widgets.ckandatapublisherwidget.client;
|
||||||
|
|
||||||
import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.DatasetMetadataBean;
|
import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.DatasetMetadataBean;
|
||||||
import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.LicensesBean;
|
import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.LicensesBean;
|
||||||
import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.ResourceBean;
|
import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.ResourceBeanWrapper;
|
||||||
|
|
||||||
import com.google.gwt.user.client.rpc.RemoteService;
|
import com.google.gwt.user.client.rpc.RemoteService;
|
||||||
import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;
|
import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;
|
||||||
|
@ -43,7 +43,7 @@ public interface CKanPublisherService extends RemoteService {
|
||||||
* @param datasetId
|
* @param datasetId
|
||||||
* @param owner of the dataset
|
* @param owner of the dataset
|
||||||
*/
|
*/
|
||||||
ResourceBean addResourceToDataset(ResourceBean resource, String datasetId, String owner);
|
ResourceBeanWrapper addResourceToDataset(ResourceBeanWrapper resource, String datasetId, String owner);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete this resource from the dataset with id datasetId
|
* Delete this resource from the dataset with id datasetId
|
||||||
|
@ -52,6 +52,6 @@ public interface CKanPublisherService extends RemoteService {
|
||||||
* @param owner of the dataset
|
* @param owner of the dataset
|
||||||
* @return <b>true</b> on success, false otherwise
|
* @return <b>true</b> on success, false otherwise
|
||||||
*/
|
*/
|
||||||
boolean deleteResourceFromDataset(ResourceBean resource, String owner);
|
boolean deleteResourceFromDataset(ResourceBeanWrapper resource, String owner);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@ package org.gcube.portlets.widgets.ckandatapublisherwidget.client;
|
||||||
|
|
||||||
import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.DatasetMetadataBean;
|
import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.DatasetMetadataBean;
|
||||||
import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.LicensesBean;
|
import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.LicensesBean;
|
||||||
import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.ResourceBean;
|
import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.ResourceBeanWrapper;
|
||||||
|
|
||||||
import com.google.gwt.user.client.rpc.AsyncCallback;
|
import com.google.gwt.user.client.rpc.AsyncCallback;
|
||||||
|
|
||||||
|
@ -44,8 +44,8 @@ public interface CKanPublisherServiceAsync {
|
||||||
* @param owner of the dataset
|
* @param owner of the dataset
|
||||||
* @param callback
|
* @param callback
|
||||||
*/
|
*/
|
||||||
void addResourceToDataset(ResourceBean resource, String datasetId, String owner,
|
void addResourceToDataset(ResourceBeanWrapper resource, String datasetId, String owner,
|
||||||
AsyncCallback<ResourceBean> callback);
|
AsyncCallback<ResourceBeanWrapper> callback);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete this resource from the dataset with id datasetId
|
* Delete this resource from the dataset with id datasetId
|
||||||
|
@ -53,7 +53,7 @@ public interface CKanPublisherServiceAsync {
|
||||||
* @param owner of the dataset
|
* @param owner of the dataset
|
||||||
* @return <b>true</b> on success, false otherwise
|
* @return <b>true</b> on success, false otherwise
|
||||||
*/
|
*/
|
||||||
void deleteResourceFromDataset(ResourceBean resource,
|
void deleteResourceFromDataset(ResourceBeanWrapper resource,
|
||||||
String owner, AsyncCallback<Boolean> callback);
|
String owner, AsyncCallback<Boolean> callback);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package org.gcube.portlets.widgets.ckandatapublisherwidget.client.events;
|
package org.gcube.portlets.widgets.ckandatapublisherwidget.client.events;
|
||||||
|
|
||||||
import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.ResourceBean;
|
import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.ResourceBeanWrapper;
|
||||||
|
|
||||||
import com.google.gwt.event.shared.GwtEvent;
|
import com.google.gwt.event.shared.GwtEvent;
|
||||||
|
|
||||||
|
@ -11,13 +11,13 @@ import com.google.gwt.event.shared.GwtEvent;
|
||||||
public class AddResourceEvent extends GwtEvent<AddResourceEventHandler> {
|
public class AddResourceEvent extends GwtEvent<AddResourceEventHandler> {
|
||||||
public static Type<AddResourceEventHandler> TYPE = new Type<AddResourceEventHandler>();
|
public static Type<AddResourceEventHandler> TYPE = new Type<AddResourceEventHandler>();
|
||||||
|
|
||||||
private ResourceBean resource;
|
private ResourceBeanWrapper resource;
|
||||||
|
|
||||||
public AddResourceEvent(ResourceBean resource) {
|
public AddResourceEvent(ResourceBeanWrapper resource) {
|
||||||
this.resource = resource;
|
this.resource = resource;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ResourceBean getResource() {
|
public ResourceBeanWrapper getResource() {
|
||||||
return resource;
|
return resource;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package org.gcube.portlets.widgets.ckandatapublisherwidget.client.events;
|
package org.gcube.portlets.widgets.ckandatapublisherwidget.client.events;
|
||||||
|
|
||||||
import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.ResourceBean;
|
import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.ResourceBeanWrapper;
|
||||||
|
|
||||||
import com.google.gwt.event.shared.GwtEvent;
|
import com.google.gwt.event.shared.GwtEvent;
|
||||||
|
|
||||||
|
@ -11,13 +11,13 @@ import com.google.gwt.event.shared.GwtEvent;
|
||||||
public class DeleteResourceEvent extends GwtEvent<DeleteResourceEventHandler> {
|
public class DeleteResourceEvent extends GwtEvent<DeleteResourceEventHandler> {
|
||||||
public static Type<DeleteResourceEventHandler> TYPE = new Type<DeleteResourceEventHandler>();
|
public static Type<DeleteResourceEventHandler> TYPE = new Type<DeleteResourceEventHandler>();
|
||||||
|
|
||||||
private ResourceBean resource;
|
private ResourceBeanWrapper resource;
|
||||||
|
|
||||||
public DeleteResourceEvent(ResourceBean resource) {
|
public DeleteResourceEvent(ResourceBeanWrapper resource) {
|
||||||
this.resource = resource;
|
this.resource = resource;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ResourceBean getResource() {
|
public ResourceBeanWrapper getResource() {
|
||||||
return resource;
|
return resource;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@ import org.gcube.portlets.widgets.ckandatapublisherwidget.client.CKanPublisherSe
|
||||||
import org.gcube.portlets.widgets.ckandatapublisherwidget.client.CKanPublisherServiceAsync;
|
import org.gcube.portlets.widgets.ckandatapublisherwidget.client.CKanPublisherServiceAsync;
|
||||||
import org.gcube.portlets.widgets.ckandatapublisherwidget.client.Encoder;
|
import org.gcube.portlets.widgets.ckandatapublisherwidget.client.Encoder;
|
||||||
import org.gcube.portlets.widgets.ckandatapublisherwidget.client.events.AddResourceEvent;
|
import org.gcube.portlets.widgets.ckandatapublisherwidget.client.events.AddResourceEvent;
|
||||||
import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.ResourceBean;
|
import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.ResourceBeanWrapper;
|
||||||
|
|
||||||
import com.github.gwtbootstrap.client.ui.AlertBlock;
|
import com.github.gwtbootstrap.client.ui.AlertBlock;
|
||||||
import com.github.gwtbootstrap.client.ui.Button;
|
import com.github.gwtbootstrap.client.ui.Button;
|
||||||
|
@ -98,16 +98,16 @@ public class AddResourceToDataset extends Composite{
|
||||||
}
|
}
|
||||||
|
|
||||||
// collect data and build up the bean
|
// collect data and build up the bean
|
||||||
final ResourceBean resource = new ResourceBean(resourceUrlTextBox.getText(), resourceNameTextBox.getText(), resourceDescriptionTextArea.getText());
|
final ResourceBeanWrapper resource = new ResourceBeanWrapper(resourceUrlTextBox.getText(), resourceNameTextBox.getText(), resourceDescriptionTextArea.getText());
|
||||||
|
|
||||||
// disable add button
|
// disable add button
|
||||||
addResourceButton.setEnabled(false);
|
addResourceButton.setEnabled(false);
|
||||||
|
|
||||||
// try to create
|
// try to create
|
||||||
ckanServices.addResourceToDataset(resource, datasetId, owner, new AsyncCallback<ResourceBean>() {
|
ckanServices.addResourceToDataset(resource, datasetId, owner, new AsyncCallback<ResourceBeanWrapper>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSuccess(ResourceBean result) {
|
public void onSuccess(ResourceBeanWrapper result) {
|
||||||
|
|
||||||
if(result != null){
|
if(result != null){
|
||||||
showAlert("Resource created correctly", AlertType.SUCCESS);
|
showAlert("Resource created correctly", AlertType.SUCCESS);
|
||||||
|
|
|
@ -9,7 +9,7 @@ import org.gcube.portlets.widgets.ckandatapublisherwidget.client.events.AddResou
|
||||||
import org.gcube.portlets.widgets.ckandatapublisherwidget.client.events.AddResourceEventHandler;
|
import org.gcube.portlets.widgets.ckandatapublisherwidget.client.events.AddResourceEventHandler;
|
||||||
import org.gcube.portlets.widgets.ckandatapublisherwidget.client.events.DeleteResourceEvent;
|
import org.gcube.portlets.widgets.ckandatapublisherwidget.client.events.DeleteResourceEvent;
|
||||||
import org.gcube.portlets.widgets.ckandatapublisherwidget.client.events.DeleteResourceEventHandler;
|
import org.gcube.portlets.widgets.ckandatapublisherwidget.client.events.DeleteResourceEventHandler;
|
||||||
import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.ResourceBean;
|
import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.ResourceBeanWrapper;
|
||||||
|
|
||||||
import com.github.gwtbootstrap.client.ui.Accordion;
|
import com.github.gwtbootstrap.client.ui.Accordion;
|
||||||
import com.github.gwtbootstrap.client.ui.AccordionGroup;
|
import com.github.gwtbootstrap.client.ui.AccordionGroup;
|
||||||
|
@ -46,7 +46,7 @@ public class AddedResourcesSummary extends Composite{
|
||||||
private HandlerManager eventBus;
|
private HandlerManager eventBus;
|
||||||
|
|
||||||
// list of added resources (beans)
|
// list of added resources (beans)
|
||||||
List<ResourceBean> addedResources;
|
List<ResourceBeanWrapper> addedResources;
|
||||||
|
|
||||||
// the owner
|
// the owner
|
||||||
private String owner;
|
private String owner;
|
||||||
|
@ -66,7 +66,7 @@ public class AddedResourcesSummary extends Composite{
|
||||||
bind();
|
bind();
|
||||||
|
|
||||||
// init list
|
// init list
|
||||||
addedResources = new ArrayList<ResourceBean>();
|
addedResources = new ArrayList<ResourceBeanWrapper>();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -81,7 +81,7 @@ public class AddedResourcesSummary extends Composite{
|
||||||
public void onAddedResource(AddResourceEvent addResourceEvent) {
|
public void onAddedResource(AddResourceEvent addResourceEvent) {
|
||||||
|
|
||||||
// get the resource
|
// get the resource
|
||||||
final ResourceBean justAddedResource = addResourceEvent.getResource();
|
final ResourceBeanWrapper justAddedResource = addResourceEvent.getResource();
|
||||||
|
|
||||||
// Build an accordion to show resource info
|
// Build an accordion to show resource info
|
||||||
Accordion accordion = new Accordion();
|
Accordion accordion = new Accordion();
|
||||||
|
@ -128,7 +128,7 @@ public class AddedResourcesSummary extends Composite{
|
||||||
public void onDeletedResource(DeleteResourceEvent deleteResourceEvent) {
|
public void onDeletedResource(DeleteResourceEvent deleteResourceEvent) {
|
||||||
|
|
||||||
// to delete
|
// to delete
|
||||||
ResourceBean toDelete = deleteResourceEvent.getResource();
|
ResourceBeanWrapper toDelete = deleteResourceEvent.getResource();
|
||||||
|
|
||||||
// find it
|
// find it
|
||||||
for(int i = 0; i < addedResources.size(); i++){
|
for(int i = 0; i < addedResources.size(); i++){
|
||||||
|
|
|
@ -729,6 +729,17 @@ public class CreateDatasetForm extends Composite{
|
||||||
return errorMessage;
|
return errorMessage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// better check for the title
|
||||||
|
String regexTitleSubWord = "^[a-zA-Z0-9_]+$";
|
||||||
|
String[] splittedTitle = titleTextBox.getText().split(" ");
|
||||||
|
|
||||||
|
for (String word : splittedTitle) {
|
||||||
|
|
||||||
|
if(!word.matches(regexTitleSubWord))
|
||||||
|
return "Please note that only alphanumeric characters are allowed for the title";
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
// name reg expression
|
// name reg expression
|
||||||
String regexName = "^[a-zA-Z\\s]+";
|
String regexName = "^[a-zA-Z\\s]+";
|
||||||
if(!validateByRegExpression(maintainerTextbox.getText(), regexName)){
|
if(!validateByRegExpression(maintainerTextbox.getText(), regexName)){
|
||||||
|
|
|
@ -1,18 +1,10 @@
|
||||||
package org.gcube.portlets.widgets.ckandatapublisherwidget.server;
|
package org.gcube.portlets.widgets.ckandatapublisherwidget.server;
|
||||||
|
|
||||||
import java.net.HttpURLConnection;
|
|
||||||
import java.net.URL;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
|
||||||
|
|
||||||
import net.htmlparser.jericho.Renderer;
|
|
||||||
import net.htmlparser.jericho.Segment;
|
|
||||||
import net.htmlparser.jericho.Source;
|
|
||||||
|
|
||||||
import org.gcube.common.homelibrary.home.HomeLibrary;
|
import org.gcube.common.homelibrary.home.HomeLibrary;
|
||||||
import org.gcube.common.homelibrary.home.exceptions.InternalErrorException;
|
import org.gcube.common.homelibrary.home.exceptions.InternalErrorException;
|
||||||
|
@ -22,6 +14,8 @@ import org.gcube.common.homelibrary.home.workspace.folder.FolderItem;
|
||||||
import org.gcube.common.homelibrary.home.workspace.folder.items.GCubeItem;
|
import org.gcube.common.homelibrary.home.workspace.folder.items.GCubeItem;
|
||||||
import org.gcube.common.scope.api.ScopeProvider;
|
import org.gcube.common.scope.api.ScopeProvider;
|
||||||
import org.gcube.datacatalogue.ckanutillibrary.CKanUtilsFactory;
|
import org.gcube.datacatalogue.ckanutillibrary.CKanUtilsFactory;
|
||||||
|
import org.gcube.datacatalogue.ckanutillibrary.CKanUtilsImpl;
|
||||||
|
import org.gcube.datacatalogue.ckanutillibrary.models.ResourceBean;
|
||||||
import org.gcube.datacatalogue.metadatadiscovery.DataCalogueMetadataFormatReader;
|
import org.gcube.datacatalogue.metadatadiscovery.DataCalogueMetadataFormatReader;
|
||||||
import org.gcube.datacatalogue.metadatadiscovery.bean.MetadataType;
|
import org.gcube.datacatalogue.metadatadiscovery.bean.MetadataType;
|
||||||
import org.gcube.datacatalogue.metadatadiscovery.bean.jaxb.MetadataField;
|
import org.gcube.datacatalogue.metadatadiscovery.bean.jaxb.MetadataField;
|
||||||
|
@ -34,7 +28,7 @@ import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.LicensesBean;
|
||||||
import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.MetaDataProfileBean;
|
import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.MetaDataProfileBean;
|
||||||
import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.MetaDataTypeWrapper;
|
import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.MetaDataTypeWrapper;
|
||||||
import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.MetadataFieldWrapper;
|
import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.MetadataFieldWrapper;
|
||||||
import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.ResourceBean;
|
import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.ResourceBeanWrapper;
|
||||||
import org.gcube.vomanagement.usermanagement.UserManager;
|
import org.gcube.vomanagement.usermanagement.UserManager;
|
||||||
import org.gcube.vomanagement.usermanagement.impl.liferay.LiferayUserManager;
|
import org.gcube.vomanagement.usermanagement.impl.liferay.LiferayUserManager;
|
||||||
import org.gcube.vomanagement.usermanagement.model.UserModel;
|
import org.gcube.vomanagement.usermanagement.model.UserModel;
|
||||||
|
@ -43,13 +37,6 @@ import org.slf4j.LoggerFactory;
|
||||||
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
|
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
|
||||||
import com.liferay.portal.service.UserLocalServiceUtil;
|
import com.liferay.portal.service.UserLocalServiceUtil;
|
||||||
|
|
||||||
import eu.trentorise.opendata.jackan.CheckedCkanClient;
|
|
||||||
import eu.trentorise.opendata.jackan.model.CkanDataset;
|
|
||||||
import eu.trentorise.opendata.jackan.model.CkanOrganization;
|
|
||||||
import eu.trentorise.opendata.jackan.model.CkanPair;
|
|
||||||
import eu.trentorise.opendata.jackan.model.CkanResource;
|
|
||||||
import eu.trentorise.opendata.jackan.model.CkanTag;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Server side of the data publisher.
|
* Server side of the data publisher.
|
||||||
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
|
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
|
||||||
|
@ -60,43 +47,6 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
|
||||||
// Logger
|
// Logger
|
||||||
private static final org.slf4j.Logger logger = LoggerFactory.getLogger(CKANPublisherServicesImpl.class);
|
private static final org.slf4j.Logger logger = LoggerFactory.getLogger(CKANPublisherServicesImpl.class);
|
||||||
|
|
||||||
/**
|
|
||||||
* Return the ckan catalogue url for this scope.
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
private String getCatalogueUrl(){
|
|
||||||
|
|
||||||
logger.debug("Request for catalogue url");
|
|
||||||
|
|
||||||
try{
|
|
||||||
String currentScope = ScopeProvider.instance.get();
|
|
||||||
return CKanUtilsFactory.getInstance().getCkanUtilsForScope(currentScope).getCatalogueUrl();
|
|
||||||
}catch(Exception e){
|
|
||||||
logger.error("Failed to retrieve catalogue url information", e);
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Retrieve the api key for this user
|
|
||||||
* @param owner
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
private String getCKANApikeyFromUser(String owner) {
|
|
||||||
|
|
||||||
logger.debug("Request for user api key");
|
|
||||||
|
|
||||||
try{
|
|
||||||
String currentScope = ScopeProvider.instance.get();
|
|
||||||
return CKanUtilsFactory.getInstance().getCkanUtilsForScope(currentScope).getApiKeyFromUser(owner);
|
|
||||||
}catch(Exception e){
|
|
||||||
logger.error("Failed to retrieve api key for user " + owner, e);
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve the list of organizations in which the user can publish
|
* Retrieve the list of organizations in which the user can publish
|
||||||
* @param owner
|
* @param owner
|
||||||
|
@ -230,7 +180,7 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
|
||||||
|
|
||||||
DatasetMetadataBean bean = null;
|
DatasetMetadataBean bean = null;
|
||||||
|
|
||||||
logger.info("Bean request for " + folderId + " and " + owner);
|
logger.info("DatasetBean request for " + folderId + " and " + owner);
|
||||||
|
|
||||||
if(isWithinPortal()){
|
if(isWithinPortal()){
|
||||||
try{
|
try{
|
||||||
|
@ -372,151 +322,98 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
|
||||||
@Override
|
@Override
|
||||||
public DatasetMetadataBean createCKanDataset(DatasetMetadataBean toCreate, boolean isWorkspaceRequest) {
|
public DatasetMetadataBean createCKanDataset(DatasetMetadataBean toCreate, boolean isWorkspaceRequest) {
|
||||||
|
|
||||||
// retrieve ckan's catalog url
|
logger.debug("Request for creating a dataset with these information " + toCreate);
|
||||||
String ckanPortalUrl = getCatalogueUrl();
|
|
||||||
|
|
||||||
// retrieve the owner identifier (i.e. costantino.perciante)
|
|
||||||
String owner = toCreate.getOwnerIdentifier();
|
|
||||||
|
|
||||||
// retrieve the api key for this user
|
|
||||||
String apiKey = getCKANApikeyFromUser(fromOwnerToCKanOwner(owner));
|
|
||||||
|
|
||||||
logger.info("Trying to create the dataset described by this bean " + toCreate + " into CKAN catalog at url " + ckanPortalUrl);
|
|
||||||
|
|
||||||
// Checked client
|
|
||||||
CheckedCkanClient client = new CheckedCkanClient(ckanPortalUrl, apiKey);
|
|
||||||
|
|
||||||
// create the base dataset and fill it
|
|
||||||
CkanDataset dataset = new CkanDataset();
|
|
||||||
|
|
||||||
// set dataset info (same id as the folder)
|
|
||||||
dataset.setId(toCreate.getId());
|
|
||||||
|
|
||||||
// get the name from the title
|
|
||||||
dataset.setName(nameFromTitle(toCreate.getTitle()));
|
|
||||||
dataset.setTitle(toCreate.getTitle());
|
|
||||||
|
|
||||||
CkanOrganization orgOwner = client.getOrganization(toCreate.getSelectedOrganization());
|
|
||||||
dataset.setOwnerOrg(orgOwner.getId());
|
|
||||||
dataset.setAuthor(toCreate.getAuthor());
|
|
||||||
dataset.setAuthorEmail(toCreate.getAuthorEmail());
|
|
||||||
dataset.setMaintainer(toCreate.getMaintainer());
|
|
||||||
dataset.setMaintainerEmail(toCreate.getMaintainerEmail());
|
|
||||||
dataset.setVersion(String.valueOf(toCreate.getVersion()));
|
|
||||||
|
|
||||||
// description must be escaped
|
|
||||||
Source description = new Source(toCreate.getDescription());
|
|
||||||
Segment htmlSeg = new Segment(description, 0, description.length());
|
|
||||||
Renderer htmlRend = new Renderer(htmlSeg);
|
|
||||||
dataset.setNotes(htmlRend.toString());
|
|
||||||
|
|
||||||
logger.debug("Description (escaped is ) " + htmlRend.toString());
|
|
||||||
|
|
||||||
// iterate over the licenses to find the id of the chosen one
|
|
||||||
String chosenLicense = toCreate.getLicense();
|
|
||||||
String licenseId = findLicenseIdByLicense(chosenLicense);
|
|
||||||
dataset.setLicenseId(licenseId);
|
|
||||||
|
|
||||||
// set the tags, if any
|
|
||||||
if(toCreate.getTags() != null && !toCreate.getTags().isEmpty()){
|
|
||||||
|
|
||||||
// convert to ckan tags
|
|
||||||
List<CkanTag> ckanTags = new ArrayList<CkanTag>(toCreate.getTags().size());
|
|
||||||
for (String stringTag : toCreate.getTags()) {
|
|
||||||
ckanTags.add(new CkanTag(stringTag));
|
|
||||||
}
|
|
||||||
|
|
||||||
dataset.setTags(ckanTags);
|
|
||||||
}
|
|
||||||
|
|
||||||
// set the custom fields, if any
|
|
||||||
if(toCreate.getCustomFields() != null && !toCreate.getCustomFields().isEmpty()){
|
|
||||||
|
|
||||||
// iterate and create
|
|
||||||
Iterator<Entry<String, String>> iterator = toCreate.getCustomFields().entrySet().iterator();
|
|
||||||
|
|
||||||
List<CkanPair> extras = new ArrayList<CkanPair>(toCreate.getCustomFields().entrySet().size());
|
|
||||||
|
|
||||||
while (iterator.hasNext()) {
|
|
||||||
|
|
||||||
Map.Entry<String, String> entry = (Map.Entry<String, String>) iterator.next();
|
|
||||||
extras.add(new CkanPair(entry.getKey(), entry.getValue()));
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
dataset.setExtras(extras);
|
|
||||||
}
|
|
||||||
|
|
||||||
// check if we need to add the resources
|
|
||||||
if(toCreate.isAddResources() && isWorkspaceRequest){
|
|
||||||
|
|
||||||
logger.debug("We need to add resources to the dataset");
|
|
||||||
|
|
||||||
try{
|
|
||||||
|
|
||||||
Workspace ws = HomeLibrary
|
|
||||||
.getHomeManagerFactory()
|
|
||||||
.getHomeManager()
|
|
||||||
.getHome(toCreate.getOwnerIdentifier()).getWorkspace();
|
|
||||||
|
|
||||||
List<CkanResource> resources = new ArrayList<CkanResource>();
|
|
||||||
|
|
||||||
|
|
||||||
for(String resourceId: toCreate.getResourcesIds()){
|
|
||||||
|
|
||||||
FolderItem item = (FolderItem)ws.getItem(resourceId);
|
|
||||||
CkanResource newResource = new CkanResource();
|
|
||||||
newResource.setDescription(item.getDescription());
|
|
||||||
newResource.setId(item.getId());
|
|
||||||
newResource.setUrl(item.getPublicLink(false));
|
|
||||||
newResource.setName(item.getName());
|
|
||||||
newResource.setMimetype(item.getMimeType());
|
|
||||||
newResource.setOwner(fromOwnerToCKanOwner(owner));
|
|
||||||
resources.add(newResource);
|
|
||||||
}
|
|
||||||
|
|
||||||
// add to the dataset
|
|
||||||
dataset.setResources(resources);
|
|
||||||
|
|
||||||
}catch(Exception e){
|
|
||||||
logger.error("Unable to add those resources to the dataset", e);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// try to create
|
|
||||||
CkanDataset res = null;
|
|
||||||
try{
|
try{
|
||||||
|
|
||||||
res = client.createDataset(dataset);
|
String currentScope = ScopeProvider.instance.get();
|
||||||
|
|
||||||
// add source and id to the incoming bean
|
// get the owner
|
||||||
toCreate.setId(res.getId());
|
String username = fromOwnerToCKanOwner(toCreate.getOwnerIdentifier());
|
||||||
toCreate.setSource(getCatalogueUrl() + "/dataset/" + res.getName());
|
CKanUtilsImpl utilityInstance = CKanUtilsFactory.getInstance().getCkanUtilsForScope(currentScope);
|
||||||
|
|
||||||
// set visibility
|
// set dataset info (same id as the folder, if the request comes from the workspace)
|
||||||
setVisibility(toCreate, orgOwner.getId());
|
String withId = null;
|
||||||
|
if(isWorkspaceRequest)
|
||||||
|
withId = toCreate.getId();
|
||||||
|
|
||||||
|
String title = toCreate.getTitle();
|
||||||
|
String organizationNameOrId = toCreate.getSelectedOrganization();
|
||||||
|
String author = toCreate.getAuthor();
|
||||||
|
String authorMail = toCreate.getAuthorEmail();
|
||||||
|
String maintainer = toCreate.getMaintainer();
|
||||||
|
String maintainerMail = toCreate.getMaintainerEmail();
|
||||||
|
long version = toCreate.getVersion();
|
||||||
|
String description = toCreate.getDescription();
|
||||||
|
String chosenLicense = toCreate.getLicense();
|
||||||
|
String licenseId = findLicenseIdByLicense(chosenLicense);
|
||||||
|
List<String> listOfTags = toCreate.getTags();
|
||||||
|
Map<String, String> customFields = toCreate.getCustomFields();
|
||||||
|
boolean setPublic = toCreate.getVisibility();
|
||||||
|
List<ResourceBean> resources = new ArrayList<ResourceBean>();
|
||||||
|
|
||||||
|
// build the resource (if it is a workspaceRequest type)
|
||||||
|
if(toCreate.isAddResources() && isWorkspaceRequest){
|
||||||
|
|
||||||
|
logger.debug("We need to add resources to the dataset");
|
||||||
|
|
||||||
|
try{
|
||||||
|
|
||||||
|
Workspace ws = HomeLibrary
|
||||||
|
.getHomeManagerFactory()
|
||||||
|
.getHomeManager()
|
||||||
|
.getHome(toCreate.getOwnerIdentifier()).getWorkspace();
|
||||||
|
|
||||||
|
for(String resourceId: toCreate.getResourcesIds()){
|
||||||
|
|
||||||
|
FolderItem item = (FolderItem)ws.getItem(resourceId);
|
||||||
|
ResourceBean newResource = new ResourceBean();
|
||||||
|
newResource.setDescription(item.getDescription());
|
||||||
|
newResource.setId(item.getId());
|
||||||
|
newResource.setUrl(item.getPublicLink(false));
|
||||||
|
newResource.setName(item.getName());
|
||||||
|
newResource.setMimeType(item.getMimeType());
|
||||||
|
newResource.setOwner(username);
|
||||||
|
resources.add(newResource);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}catch(Exception e){
|
||||||
|
logger.error("Unable to add those resources to the dataset", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
String datasetId = utilityInstance.createCKanDataset(username, withId, title, organizationNameOrId, author,
|
||||||
|
authorMail, maintainer, maintainerMail, version, description, licenseId,
|
||||||
|
listOfTags, customFields, resources, setPublic);
|
||||||
|
|
||||||
|
if(datasetId != null){
|
||||||
|
|
||||||
|
logger.debug("Dataset created!");
|
||||||
|
toCreate.setId(datasetId);
|
||||||
|
|
||||||
|
// retrieve the url
|
||||||
|
String datasetUrl = utilityInstance.getUrlFromDatasetIdOrName(username, datasetId);
|
||||||
|
|
||||||
|
toCreate.setSource(datasetUrl);
|
||||||
|
return toCreate;
|
||||||
|
|
||||||
|
}else{
|
||||||
|
|
||||||
|
logger.error("Failed to create the dataset");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}catch(Exception e){
|
}catch(Exception e){
|
||||||
|
logger.error("Unable to create the dataset", e);
|
||||||
// try to update
|
|
||||||
logger.error("Error while creating the dataset, probably it already exists.", e);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(res != null)
|
return null;
|
||||||
logger.debug("Dataset created/updated " + res.getId());
|
|
||||||
else{
|
|
||||||
logger.error("Dataset described by " + toCreate + " not created!");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return toCreate;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ckan username has _ instead of . (that is, costantino_perciante)
|
* Ckan username has _ instead of . (that is, costantino.perciante -> costantino_perciante)
|
||||||
* @param owner
|
* @param owner
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
|
@ -524,104 +421,41 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
|
||||||
return owner.replaceAll("\\.", "_");
|
return owner.replaceAll("\\.", "_");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the dataset visibility.
|
|
||||||
* @param created
|
|
||||||
* @param orgOwnerId
|
|
||||||
* @throws Exception
|
|
||||||
*/
|
|
||||||
private void setVisibility(DatasetMetadataBean created, String orgOwnerId) throws Exception{
|
|
||||||
|
|
||||||
logger.debug("Setting visibility of the dataset");
|
|
||||||
// set its visibility (true means public, false means private)
|
|
||||||
boolean mustbePrivate = !created.getVisibility();
|
|
||||||
String currentScope = ScopeProvider.instance.get();
|
|
||||||
|
|
||||||
CKanUtilsFactory.getInstance().
|
|
||||||
getCkanUtilsForScope(currentScope).
|
|
||||||
setDatasetPrivate(mustbePrivate, orgOwnerId, created.getId(), fromOwnerToCKanOwner(created.getOwnerIdentifier()));
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Generate the catalogue's dataset name from its title
|
|
||||||
* @param title
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
private String nameFromTitle(String title) {
|
|
||||||
String convertedName = title.replaceAll(" ", "_");
|
|
||||||
convertedName = convertedName.replaceAll("\\.", "_");
|
|
||||||
convertedName = convertedName.toLowerCase();
|
|
||||||
if(convertedName.endsWith("_"))
|
|
||||||
convertedName = convertedName.substring(0, convertedName.length() - 2);
|
|
||||||
|
|
||||||
return convertedName;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Utility methods
|
|
||||||
* @param URLName
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
private static boolean exists(String URLName){
|
|
||||||
try {
|
|
||||||
HttpURLConnection.setFollowRedirects(true);
|
|
||||||
HttpURLConnection con = (HttpURLConnection) new URL(URLName).openConnection();
|
|
||||||
con.setRequestMethod("HEAD");
|
|
||||||
logger.debug("Return code is " + con.getResponseCode());
|
|
||||||
return (con.getResponseCode() == HttpURLConnection.HTTP_OK);
|
|
||||||
}
|
|
||||||
catch (Exception e) {
|
|
||||||
logger.error("Exception while checking url", e);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ResourceBean addResourceToDataset(ResourceBean resourceBean, String datasetId, String owner) {
|
public ResourceBeanWrapper addResourceToDataset(ResourceBeanWrapper resource, String datasetId, String owner) {
|
||||||
|
|
||||||
logger.debug("Incoming request for creating new resource for dataset with id " + datasetId);
|
logger.debug("Incoming request for creating new resource for dataset with id " + datasetId);
|
||||||
logger.debug("Owner is " + owner + " and resource is " + resourceBean);
|
logger.debug("Owner is " + owner + " and resource is " + resource);
|
||||||
|
|
||||||
// of course, if it exists
|
try{
|
||||||
if(exists(resourceBean.getUrl())){
|
|
||||||
|
|
||||||
try{
|
String currentScope = ScopeProvider.instance.get();
|
||||||
// retrieve ckan's catalog url
|
|
||||||
String ckanPortalUrl = getCatalogueUrl();
|
|
||||||
|
|
||||||
// retrieve the api key for this user
|
ResourceBean resourceBean = new ResourceBean(
|
||||||
String apiKey = getCKANApikeyFromUser(fromOwnerToCKanOwner(owner));
|
resource.getUrl(),
|
||||||
|
resource.getName(),
|
||||||
|
resource.getDescription(),
|
||||||
|
null,
|
||||||
|
fromOwnerToCKanOwner(owner),
|
||||||
|
datasetId,
|
||||||
|
null);
|
||||||
|
|
||||||
CkanResource resource = new CkanResource(ckanPortalUrl, datasetId);
|
String resourceId = CKanUtilsFactory.getInstance().
|
||||||
resource.setName(resourceBean.getName());
|
getCkanUtilsForScope(currentScope).
|
||||||
|
addResourceToDataset(resourceBean);
|
||||||
|
|
||||||
// escape description
|
if(resourceId != null){
|
||||||
Source description = new Source(resourceBean.getDescription());
|
|
||||||
Segment htmlSeg = new Segment(description, 0, description.length());
|
|
||||||
Renderer htmlRend = new Renderer(htmlSeg);
|
|
||||||
|
|
||||||
resource.setDescription(htmlRend.toString());
|
logger.debug("Resource " + resource.getName() + " is now available");
|
||||||
resource.setUrl(resourceBean.getUrl());
|
|
||||||
resource.setOwner(fromOwnerToCKanOwner(owner));
|
|
||||||
|
|
||||||
// Checked client
|
// set its id and turn it to the client
|
||||||
CheckedCkanClient client = new CheckedCkanClient(ckanPortalUrl, apiKey);
|
resource.setId(resourceId);
|
||||||
CkanResource createdRes = client.createResource(resource);
|
return resource;
|
||||||
|
|
||||||
if(createdRes != null){
|
|
||||||
|
|
||||||
logger.debug("Resource " + createdRes.getName() + " is now available");
|
|
||||||
|
|
||||||
// set its id and turn it to the client
|
|
||||||
resourceBean.setId(createdRes.getId());
|
|
||||||
return resourceBean;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}catch(Exception e){
|
|
||||||
logger.error("Unable to create new resource", e);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}catch(Exception e){
|
||||||
|
logger.error("Unable to create new resource", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.debug("No resource created");
|
logger.debug("No resource created");
|
||||||
|
@ -630,29 +464,29 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean deleteResourceFromDataset(ResourceBean resource,
|
public boolean deleteResourceFromDataset(ResourceBeanWrapper resource,
|
||||||
String owner) {
|
String owner) {
|
||||||
logger.debug("Request for deleting resource " + resource);
|
logger.debug("Request for deleting resource " + resource);
|
||||||
|
|
||||||
|
boolean deleted = false;
|
||||||
|
|
||||||
try{
|
try{
|
||||||
|
String currentScope = ScopeProvider.instance.get();
|
||||||
|
|
||||||
// retrieve ckan's catalog url
|
deleted = CKanUtilsFactory.getInstance().
|
||||||
String ckanPortalUrl = getCatalogueUrl();
|
getCkanUtilsForScope(currentScope).
|
||||||
|
deleteResourceFromDataset(fromOwnerToCKanOwner(owner), resource.getId());
|
||||||
|
|
||||||
// retrieve the api key for this user
|
if(deleted){
|
||||||
String apiKey = getCKANApikeyFromUser(fromOwnerToCKanOwner(owner));
|
logger.debug("Resource described by " + resource + " deleted");
|
||||||
|
}else
|
||||||
// Checked client
|
logger.error("Resource described by " + resource + " NOT deleted");
|
||||||
CheckedCkanClient client = new CheckedCkanClient(ckanPortalUrl, apiKey);
|
|
||||||
client.deleteResource(resource.getId());
|
|
||||||
|
|
||||||
return true;
|
|
||||||
|
|
||||||
}catch(Exception e){
|
}catch(Exception e){
|
||||||
logger.error("Unable to delete such resource", e);
|
logger.error("Error while trying to delete resource described by " + resource, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return deleted;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@ import java.io.Serializable;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A MetaDataProfileBean with its children (MetaDataFormat)
|
* A MetaDataProfileBean with its children (MetaDataType and MetaDataFields)
|
||||||
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
|
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
|
||||||
*/
|
*/
|
||||||
public class MetaDataProfileBean implements Serializable{
|
public class MetaDataProfileBean implements Serializable{
|
||||||
|
|
|
@ -3,10 +3,10 @@ package org.gcube.portlets.widgets.ckandatapublisherwidget.shared;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A dataset's resource bean.
|
* A dataset's resource bean
|
||||||
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
|
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
|
||||||
*/
|
*/
|
||||||
public class ResourceBean implements Serializable{
|
public class ResourceBeanWrapper implements Serializable{
|
||||||
|
|
||||||
private static final long serialVersionUID = -6542455246456049712L;
|
private static final long serialVersionUID = -6542455246456049712L;
|
||||||
private String url;
|
private String url;
|
||||||
|
@ -14,7 +14,7 @@ public class ResourceBean implements Serializable{
|
||||||
private String description;
|
private String description;
|
||||||
private String id;
|
private String id;
|
||||||
|
|
||||||
public ResourceBean(){
|
public ResourceBeanWrapper(){
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@ public class ResourceBean implements Serializable{
|
||||||
* @param name
|
* @param name
|
||||||
* @param description
|
* @param description
|
||||||
*/
|
*/
|
||||||
public ResourceBean(String url, String name, String description) {
|
public ResourceBeanWrapper(String url, String name, String description) {
|
||||||
super();
|
super();
|
||||||
this.url = url;
|
this.url = url;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
|
@ -36,7 +36,7 @@ public class ResourceBean implements Serializable{
|
||||||
* @param description
|
* @param description
|
||||||
* @param id
|
* @param id
|
||||||
*/
|
*/
|
||||||
public ResourceBean(String url, String name, String description, String id) {
|
public ResourceBeanWrapper(String url, String name, String description, String id) {
|
||||||
super();
|
super();
|
||||||
this.url = url;
|
this.url = url;
|
||||||
this.name = name;
|
this.name = name;
|
Loading…
Reference in New Issue