Reorganizing code

This commit is contained in:
Luca Frosini 2022-06-01 09:52:30 +02:00
parent c1f283486a
commit 71f661c478
9 changed files with 48 additions and 96 deletions

View File

@ -3,6 +3,11 @@
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [v2.0.0-SNAPSHOT]
- Complete refactor of connector [#23454]
- Changed groupId
## [v1.4.0]
- Removed old code which set the user role in ckan [#23310]

View File

@ -21,6 +21,7 @@ See [Releases](https://code-repo.d4science.org/gCubeSystem/ckan-connector/releas
## Authors
* **Luca Frosini** ([ORCID](https://orcid.org/0000-0003-3183-2291)) - [ISTI-CNR Infrascience Group](http://nemis.isti.cnr.it/groups/infrascience)
* **Lucio Lelii** ([ISTI-CNR Infrascience Group](http://nemis.isti.cnr.it/groups/infrascience)

13
pom.xml
View File

@ -9,12 +9,12 @@
<version>1.1.0</version>
</parent>
<groupId>org.gcube.data.access</groupId>
<groupId>org.gcube.data-catalogue</groupId>
<artifactId>ckan-connector</artifactId>
<version>1.4.0</version>
<version>2.0.0-SNAPSHOT</version>
<packaging>war</packaging>
<name>ckan connector</name>
<description>a ckan connector for automatic login</description>
<name>Ckan connector</name>
<description>Ckan connector for automatic login</description>
<scm>
<connection>scm:git:https://code-repo.d4science.org/gCubeSystem/${project.artifactId}.git</connection>
@ -23,8 +23,9 @@
</scm>
<properties>
<webappDirectory>${project.basedir}/src/main/webapp/WEB-INF</webappDirectory>
<distroDirectory>${project.basedir}/distro</distroDirectory>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<webappDirectory>${project.basedir}${file.separator}src${file.separator}main${file.separator}webapp${file.separator}WEB-INF</webappDirectory>
<enunciate.version>2.14.0</enunciate.version>
</properties>
<dependencyManagement>

View File

@ -0,0 +1,19 @@
package org.gcube.ckanconnector;
import javax.ws.rs.ApplicationPath;
import org.gcube.ckanconnector.rest.ConnectorManager;
import org.glassfish.jersey.server.ResourceConfig;
/**
* @author Luca Frosini (ISTI - CNR)
* @author Lucio Lelii (ISTI - CNR)
*/
@ApplicationPath("/gcube/service/")
public class CKanConnector extends ResourceConfig {
public CKanConnector(){
packages(ConnectorManager.class.getPackage().toString());
}
}

View File

@ -1,4 +1,4 @@
package org.gcube.data.access.ckanconnector;
package org.gcube.ckanconnector.rest;
import java.io.File;
import java.io.FileInputStream;
@ -15,6 +15,7 @@ import javax.ws.rs.core.Context;
import javax.ws.rs.core.NewCookie;
import javax.ws.rs.core.Response;
import org.gcube.ckanconnector.utils.RandomString;
import org.gcube.common.authorization.library.provider.AuthorizationProvider;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.gcat.client.User;
@ -22,18 +23,22 @@ import org.python.core.PyLong;
import org.python.core.PyObject;
import org.python.core.PyString;
import org.python.util.PythonInterpreter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import lombok.extern.slf4j.Slf4j;
/**
* @author Luca Frosini (ISTI - CNR)
* @author Lucio Lelii (ISTI - CNR)
*/
@Path("/")
@Slf4j
public class ConnectorManager {
private static final Logger log = LoggerFactory.getLogger(ConnectorManager.class);
@Context ServletContext context;
RandomString randomString = new RandomString(12);
@Path("disconnect")
@GET
public Response disconnect(@Context HttpServletRequest req) {

View File

@ -1,7 +1,11 @@
package org.gcube.data.access.ckanconnector;
package org.gcube.ckanconnector.utils;
import java.util.Random;
/**
* @author Luca Frosini (ISTI - CNR)
* @author Lucio Lelii (ISTI - CNR)
*/
public class RandomString {
private static final char[] symbols;

View File

@ -1,14 +0,0 @@
package org.gcube.data.access.ckanconnector;
import javax.ws.rs.ApplicationPath;
import org.glassfish.jersey.server.ResourceConfig;
@ApplicationPath("/gcube/service/")
public class CKanConnector extends ResourceConfig {
public CKanConnector(){
packages("org.gcube.data.access.ckanconnector");
}
}

View File

@ -1,70 +0,0 @@
package org.gcube.data.access.ckanconnector;
import javax.servlet.ServletContext;
import javax.ws.rs.Path;
import javax.ws.rs.core.Context;
import lombok.extern.slf4j.Slf4j;
@Path("organization")
@Slf4j
public class OrganizationManager {
@Context ServletContext context;
// @PUT
// @Path("/{name}")
// public Response create(@PathParam("name") String organizationName) {
// log.info("create called");
// try{
//
//// This is done by smartgears
//// if (AuthorizationProvider.instance.get()==null || AuthorizationProvider.instance.get().getClient() == null ) return Response.status(Status.UNAUTHORIZED).build();
//
// String ckanKey = context.getInitParameter("ckanKey");
// int internalPort = Integer.parseInt(context.getInitParameter("internalPort"));
// CkanClient ckanClient = new CkanClient("http://127.0.0.1:"+internalPort, ckanKey);
//
// CkanOrganization org = new CkanOrganization(organizationName.replaceAll(" ", "_").replace(".", "_").toLowerCase());
// org.setDisplayName(organizationName);
// org.setTitle(organizationName);
// ckanClient.createOrganization(org);
//
// log.info("create organizzation {} called from user {} in scope {}",organizationName, AuthorizationProvider.instance.get().getClient().getId(), ScopeProvider.instance.get());
// return Response.ok().build();
// }catch(Exception e){
// log.error("error trying to create organization "+organizationName,e);
// return Response.serverError().entity(e.getMessage()).build();
// }
// }
//
// @GET
// @Path("/{name}")
// @Produces(MediaType.APPLICATION_JSON)
// public String get(@PathParam("name") String organizationName) {
// log.info("get called with name {}", organizationName);
//
//// This is done by smartgears
//// if (AuthorizationProvider.instance.get()==null || AuthorizationProvider.instance.get().getClient() == null ) throw new WebApplicationException("user authentication needed",Response.Status.UNAUTHORIZED);
//
// String ckanKey = context.getInitParameter("ckanKey");
// int internalPort = Integer.parseInt(context.getInitParameter("internalPort"));
//
// try{
// CkanClient ckanClient = new CkanClient("http://127.0.0.1:"+internalPort, ckanKey);
// CkanOrganization org = ckanClient.getOrganization(organizationName.replaceAll(" ", "_").replace(".", "_").toLowerCase());
// log.trace("organization {} found",organizationName);
// return new Gson().toJson(org);
// }catch(CkanNotFoundException e){
// log.error("organization {} doesn't exist",organizationName);
// throw new WebApplicationException("organization "+organizationName+" doesn't exist",Response.Status.NOT_FOUND);
// } catch (Exception e) {
// log.error("error trying to contect ckan",e);
// throw new WebApplicationException("error trying to contect ckan",Response.Status.INTERNAL_SERVER_ERROR);
// }
//
//
// }
}

View File

@ -6,6 +6,7 @@ import javax.net.ssl.HttpsURLConnection;
import javax.ws.rs.core.Application;
import javax.ws.rs.core.Response;
import org.gcube.ckanconnector.rest.ConnectorManager;
import org.glassfish.jersey.server.ResourceConfig;
import org.glassfish.jersey.test.JerseyTest;
import org.junit.Test;