Moved utility methods into the library
git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/widgets/ckan-metadata-publisher-widget@128996 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
1e95f70f5f
commit
acd1343032
|
@ -28,9 +28,7 @@ import com.google.gwt.user.server.rpc.RemoteServiceServlet;
|
|||
import com.liferay.portal.service.UserLocalServiceUtil;
|
||||
|
||||
import eu.trentorise.opendata.jackan.CheckedCkanClient;
|
||||
import eu.trentorise.opendata.jackan.CkanClient;
|
||||
import eu.trentorise.opendata.jackan.model.CkanDataset;
|
||||
import eu.trentorise.opendata.jackan.model.CkanLicense;
|
||||
import eu.trentorise.opendata.jackan.model.CkanOrganization;
|
||||
import eu.trentorise.opendata.jackan.model.CkanPair;
|
||||
import eu.trentorise.opendata.jackan.model.CkanResource;
|
||||
|
@ -107,18 +105,9 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
|
|||
logger.info("Request for user " + owner + " organizations list");
|
||||
|
||||
try{
|
||||
|
||||
String currentScope = getCurrentScope();
|
||||
List<CkanOrganization> ckanOrgs = CKanUtilsFactory.getInstance().getCkanUtilsForScope(currentScope).getOrganizationsByUser(owner);
|
||||
|
||||
logger.debug("Organizations are " + ckanOrgs);
|
||||
|
||||
List<String> orgsName = new ArrayList<String>();
|
||||
for (CkanOrganization ckanOrganization : ckanOrgs) {
|
||||
orgsName.add(ckanOrganization.getName());
|
||||
logger.debug("Organization name is " + ckanOrganization.getName());
|
||||
}
|
||||
|
||||
return orgsName;
|
||||
return CKanUtilsFactory.getInstance().getCkanUtilsForScope(currentScope).getOrganizationsNamesByUser(owner);
|
||||
|
||||
}catch(Exception e){
|
||||
logger.error("Failed to retrieve user's organizations", e);
|
||||
|
@ -149,17 +138,11 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
|
|||
*/
|
||||
private String findLicenseIdByLicense(String chosenLicense) {
|
||||
|
||||
logger.info("Requested license id");
|
||||
|
||||
String ckanPortalUrl = getCatalogueUrl();
|
||||
CkanClient client = new CkanClient(ckanPortalUrl);
|
||||
|
||||
//retrieve the list of available licenses
|
||||
List<CkanLicense> licenses = client.getLicenseList();
|
||||
|
||||
for (CkanLicense ckanLicense : licenses) {
|
||||
if(ckanLicense.getTitle().equals(chosenLicense))
|
||||
return ckanLicense.getId();
|
||||
String currentScope = getCurrentScope();
|
||||
try {
|
||||
return CKanUtilsFactory.getInstance().getCkanUtilsForScope(currentScope).findLicenseIdByLicense(chosenLicense);
|
||||
} catch (Exception e) {
|
||||
logger.error("Failed to retrieve license id", e);
|
||||
}
|
||||
|
||||
return null;
|
||||
|
@ -169,25 +152,16 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
|
|||
public LicensesBean getLicenses() {
|
||||
|
||||
logger.info("Request for CKAN licenses");
|
||||
|
||||
// get the url and the api key of the user
|
||||
String ckanPortalUrl = getCatalogueUrl();
|
||||
List<String> result = new ArrayList<String>();
|
||||
|
||||
CkanClient client = new CkanClient(ckanPortalUrl);
|
||||
|
||||
//retrieve the list of available licenses
|
||||
List<CkanLicense> licenses = client.getLicenseList();
|
||||
|
||||
for (CkanLicense ckanLicense : licenses) {
|
||||
|
||||
result.add(ckanLicense.getTitle());
|
||||
logger.debug("License is " + ckanLicense.getTitle() + " and id " + ckanLicense.getId());
|
||||
|
||||
try {
|
||||
String currentScope = getCurrentScope();
|
||||
List<String> titlesLicenses;
|
||||
titlesLicenses = CKanUtilsFactory.getInstance().getCkanUtilsForScope(currentScope).getLicenseTitles();
|
||||
// return the bean
|
||||
return new LicensesBean(titlesLicenses);
|
||||
} catch (Exception e) {
|
||||
logger.error("Failed to retrieve licenses", e);
|
||||
}
|
||||
|
||||
// return the bean
|
||||
return new LicensesBean(result);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in New Issue