fix for name translation

git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/widgets/ckan-metadata-publisher-widget@129062 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Costantino Perciante 2016-06-10 14:59:55 +00:00
parent 51c3fb40b1
commit 9a95392ea1
2 changed files with 42 additions and 13 deletions

View File

@ -73,13 +73,24 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
}
/**
* Get the scope in which we look for metadata
* @return
*/
private String getMetadataScope(){
if(isWithinPortal())
return ScopeProvider.instance.get();
else
return "/gcube/devsec/devVRE"; // Development
}
/**
* Return the ckan catalogue url for this scope.
* @return
*/
private String getCatalogueUrl(){
logger.info("Request for catalogue url");
logger.debug("Request for catalogue url");
try{
String currentScope = getCurrentScope();
@ -98,7 +109,7 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
*/
private String getCKANApikeyFromUser(String owner) {
logger.info("Request for user api key");
logger.debug("Request for user api key");
try{
String currentScope = getCurrentScope();
@ -117,7 +128,7 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
*/
private List<String> getUserOrganizationsList(String owner) {
logger.info("Request for user " + owner + " organizations list");
logger.debug("Request for user " + owner + " organizations list");
try{
@ -173,7 +184,7 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
try {
ScopeProvider.instance.set("/gcube/devsec/devVRE"); // TODO remove
ScopeProvider.instance.set(getMetadataScope()); // TODO remove
DataCalogueMetadataFormatReader reader = new DataCalogueMetadataFormatReader();
for (MetadataType mt : reader.getListOfMetadataTypes()) {
@ -203,7 +214,7 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
wrapperList.add(wrapperObj);
}
// wrap the mt as well
MetaDataTypeWrapper typeWrapper = new MetaDataTypeWrapper();
typeWrapper.setDescription(mt.getDescription());
@ -412,8 +423,8 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
dataset.setName(nameFromTitle(toCreate.getTitle()));
dataset.setTitle(toCreate.getTitle());
CkanOrganization orgTest = client.getOrganization(toCreate.getSelectedOrganization());
dataset.setOwnerOrg(orgTest.getId());
CkanOrganization orgOwner = client.getOrganization(toCreate.getSelectedOrganization());
dataset.setOwnerOrg(orgOwner.getId());
dataset.setAuthor(toCreate.getAuthor());
dataset.setAuthorEmail(toCreate.getAuthorEmail());
dataset.setMaintainer(toCreate.getMaintainer());
@ -428,9 +439,6 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
logger.debug("Description (escaped is ) " + htmlRend.toString());
// visibility TODO
dataset.setOpen(toCreate.getVisibility());
// iterate over the licenses to find the id of the chosen one
String chosenLicense = toCreate.getLicense();
String licenseId = findLicenseIdByLicense(chosenLicense);
@ -509,10 +517,14 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
try{
res = client.createDataset(dataset);
// add source and id to the incoming bean
toCreate.setId(res.getId());
toCreate.setSource(getCatalogueUrl() + "/dataset/" + res.getName());
// set visibility
setVisibility(toCreate, orgOwner.getId());
}catch(Exception e){
@ -530,6 +542,22 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
return toCreate;
}
/**
* Set the dataset visibility.
* @param created
* @param orgOwnerId
* @throws Exception
*/
private void setVisibility(DatasetMetadataBean created, String orgOwnerId) throws Exception{
// 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(), getCKANApikeyFromUser(created.getOwnerIdentifier()));
}
/**
* Generate the catalogue's dataset name from its title
@ -537,7 +565,8 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
* @return
*/
private String nameFromTitle(String title) {
String convertedName = title.replaceAll(" ", "_").replaceAll(".", "_");
String convertedName = title.replaceAll(" ", "_");
convertedName = convertedName.replaceAll("\\.", "_");
convertedName = convertedName.toLowerCase();
if(convertedName.endsWith("_"))
convertedName = convertedName.substring(0, convertedName.length() - 2);

View File

@ -1,5 +1,6 @@
package org.gcube.portlets.widgets.ckandatapublisherwidget.client;
/**
*
* @author Costantino Perciante at ISTI-CNR
@ -8,5 +9,4 @@ package org.gcube.portlets.widgets.ckandatapublisherwidget.client;
*/
public class Tests {
}