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 com.liferay.portal.service.UserLocalServiceUtil;
|
||||||
|
|
||||||
import eu.trentorise.opendata.jackan.CheckedCkanClient;
|
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.CkanDataset;
|
||||||
import eu.trentorise.opendata.jackan.model.CkanLicense;
|
|
||||||
import eu.trentorise.opendata.jackan.model.CkanOrganization;
|
import eu.trentorise.opendata.jackan.model.CkanOrganization;
|
||||||
import eu.trentorise.opendata.jackan.model.CkanPair;
|
import eu.trentorise.opendata.jackan.model.CkanPair;
|
||||||
import eu.trentorise.opendata.jackan.model.CkanResource;
|
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");
|
logger.info("Request for user " + owner + " organizations list");
|
||||||
|
|
||||||
try{
|
try{
|
||||||
|
|
||||||
String currentScope = getCurrentScope();
|
String currentScope = getCurrentScope();
|
||||||
List<CkanOrganization> ckanOrgs = CKanUtilsFactory.getInstance().getCkanUtilsForScope(currentScope).getOrganizationsByUser(owner);
|
return CKanUtilsFactory.getInstance().getCkanUtilsForScope(currentScope).getOrganizationsNamesByUser(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;
|
|
||||||
|
|
||||||
}catch(Exception e){
|
}catch(Exception e){
|
||||||
logger.error("Failed to retrieve user's organizations", 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) {
|
private String findLicenseIdByLicense(String chosenLicense) {
|
||||||
|
|
||||||
logger.info("Requested license id");
|
String currentScope = getCurrentScope();
|
||||||
|
try {
|
||||||
String ckanPortalUrl = getCatalogueUrl();
|
return CKanUtilsFactory.getInstance().getCkanUtilsForScope(currentScope).findLicenseIdByLicense(chosenLicense);
|
||||||
CkanClient client = new CkanClient(ckanPortalUrl);
|
} catch (Exception e) {
|
||||||
|
logger.error("Failed to retrieve license id", e);
|
||||||
//retrieve the list of available licenses
|
|
||||||
List<CkanLicense> licenses = client.getLicenseList();
|
|
||||||
|
|
||||||
for (CkanLicense ckanLicense : licenses) {
|
|
||||||
if(ckanLicense.getTitle().equals(chosenLicense))
|
|
||||||
return ckanLicense.getId();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
@ -169,25 +152,16 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
|
||||||
public LicensesBean getLicenses() {
|
public LicensesBean getLicenses() {
|
||||||
|
|
||||||
logger.info("Request for CKAN licenses");
|
logger.info("Request for CKAN licenses");
|
||||||
|
try {
|
||||||
// get the url and the api key of the user
|
String currentScope = getCurrentScope();
|
||||||
String ckanPortalUrl = getCatalogueUrl();
|
List<String> titlesLicenses;
|
||||||
List<String> result = new ArrayList<String>();
|
titlesLicenses = CKanUtilsFactory.getInstance().getCkanUtilsForScope(currentScope).getLicenseTitles();
|
||||||
|
|
||||||
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());
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// return the bean
|
// return the bean
|
||||||
return new LicensesBean(result);
|
return new LicensesBean(titlesLicenses);
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("Failed to retrieve licenses", e);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in New Issue