Fix for username (ckan uses name_surname format whereas liferay name.surname)

git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/widgets/ckan-metadata-publisher-widget@129067 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Costantino Perciante 2016-06-10 16:06:31 +00:00
parent 6cd048cba6
commit 549267ab1c
4 changed files with 33 additions and 16 deletions

View File

@ -5,6 +5,9 @@
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/target/generated-sources/gwt"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/resources"/>
<dependent-module archiveName="ckan-util-library-1.0.0-SNAPSHOT.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/ckan-util-library/ckan-util-library">
<dependency-type>uses</dependency-type>
</dependent-module>
<property name="context-root" value="ckan-metadata-publisher-widget"/>
<property name="java-output-path" value="/ckan-metadata-publisher-widget/target/ckan-metadata-publisher-widget-1.0.0-SNAPSHOT/WEB-INF/classes"/>
</wb-module>

View File

@ -23,7 +23,7 @@ public class CKanMetadataPublisher implements EntryPoint {
private void startExample() {
String idFolderWorkspace = "d3a37eb9-1589-4c95-a9d0-c473a02d4f0f";
String owner = "costantino_perciante";
String owner = "costantino.perciante";
RootPanel.get("ckan-metadata-publisher-div").add(new CreateDatasetForm(owner));
}

View File

@ -738,6 +738,10 @@ public class CreateDatasetForm extends Composite{
if(checkSelectedMetaDataProfile()){
errorMessage = "You must select a metadata profile different frome none";
}
if(organizationsListbox.getSelectedItemText() == null){
errorMessage = "You must select an organization in which you want to publish";
}
return errorMessage;
}

View File

@ -178,7 +178,7 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
* Retrieve the list of metadata beans
* @return
*/
public List<MetaDataProfileBean> getMetadataProfilesList() {
private List<MetaDataProfileBean> getMetadataProfilesList() {
List<MetaDataProfileBean> beans = new ArrayList<MetaDataProfileBean>();
@ -277,12 +277,11 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
bean.setAuthorEmail(userOwner.getEmail());
bean.setMaintainer(userOwner.getFullname());
bean.setMaintainerEmail(userOwner.getEmail());
bean.setOrganizationList(getUserOrganizationsList(owner));
bean.setOrganizationList(getUserOrganizationsList(fromOwnerToCKanOwner(owner)));
// if the request comes from the workspace
if(folderId != null && !folderId.isEmpty()){
Workspace ws = HomeLibrary
.getHomeManagerFactory()
.getHomeManager()
@ -330,7 +329,7 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
bean.setAuthorEmail("costantino.perciante@isti.cnr.it");
bean.setMaintainer("Costantino Perciante");
bean.setMaintainerEmail("costantino.perciante@isti.cnr.it");
bean.setOrganizationList(getUserOrganizationsList(owner));
bean.setOrganizationList(getUserOrganizationsList(fromOwnerToCKanOwner(owner)));
bean.setOwnerIdentifier(owner);
if(folderId != null && !folderId.isEmpty()){
@ -402,11 +401,11 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
// retrieve ckan's catalog url
String ckanPortalUrl = getCatalogueUrl();
// retrieve the owner identifier
// retrieve the owner identifier (i.e. costantino.perciante)
String owner = toCreate.getOwnerIdentifier();
// retrieve the api key for this user
String apiKey = getCKANApikeyFromUser(owner);
String apiKey = getCKANApikeyFromUser(fromOwnerToCKanOwner(owner));
logger.info("Trying to create the dataset described by this bean " + toCreate + " into CKAN catalog at url " + ckanPortalUrl);
@ -499,7 +498,7 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
newResource.setUrl(item.getPublicLink(false));
newResource.setName(item.getName());
newResource.setMimetype(item.getMimeType());
newResource.setOwner(fromOwnerToCKanOwner(owner));
resources.add(newResource);
}
@ -521,7 +520,7 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
// add source and id to the incoming bean
toCreate.setId(res.getId());
toCreate.setSource(getCatalogueUrl() + "/dataset/" + res.getName());
// set visibility
setVisibility(toCreate, orgOwner.getId());
@ -542,7 +541,16 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
return toCreate;
}
/**
* Ckan username has _ instead of . (that is, costantino_perciante)
* @param owner
* @return
*/
private String fromOwnerToCKanOwner(String owner){
return owner.replaceAll("\\.", "_");
}
/**
* Set the dataset visibility.
* @param created
@ -550,14 +558,16 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
* @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 = getCurrentScope();
CKanUtilsFactory.getInstance().
getCkanUtilsForScope(currentScope).setDatasetPrivate(mustbePrivate, orgOwnerId, created.getId(), created.getOwnerIdentifier());
getCkanUtilsForScope(currentScope).
setDatasetPrivate(mustbePrivate, orgOwnerId, created.getId(), fromOwnerToCKanOwner(created.getOwnerIdentifier()));
}
/**
@ -608,7 +618,7 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
String ckanPortalUrl = getCatalogueUrl();
// retrieve the api key for this user
String apiKey = getCKANApikeyFromUser(owner);
String apiKey = getCKANApikeyFromUser(fromOwnerToCKanOwner(owner));
CkanResource resource = new CkanResource(ckanPortalUrl, datasetId);
resource.setName(resourceBean.getName());
@ -620,7 +630,7 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
resource.setDescription(htmlRend.toString());
resource.setUrl(resourceBean.getUrl());
resource.setOwner(owner);
resource.setOwner(fromOwnerToCKanOwner(owner));
// Checked client
CheckedCkanClient client = new CheckedCkanClient(ckanPortalUrl, apiKey);
@ -657,7 +667,7 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
String ckanPortalUrl = getCatalogueUrl();
// retrieve the api key for this user
String apiKey = getCKANApikeyFromUser(owner);
String apiKey = getCKANApikeyFromUser(fromOwnerToCKanOwner(owner));
// Checked client
CheckedCkanClient client = new CheckedCkanClient(ckanPortalUrl, apiKey);