diff --git a/pom.xml b/pom.xml index 62660d9..9e965d2 100644 --- a/pom.xml +++ b/pom.xml @@ -1,16 +1,17 @@ - 4.0.0 maven-parent org.gcube.tools - 1.1.0-SNAPSHOT + 1.1.0 org.gcube.data.access ckan-connector - 1.1.2-SNAPSHOT + 1.2.0-SNAPSHOT war ckan connector a ckan connector for automatic login @@ -80,6 +81,12 @@ 3.0.1 + + org.gcube.data-publishing + gcat-client + [1.0.0-SNAPSHOT, 2.0.0-SNAPSHOT) + + org.slf4j slf4j-api diff --git a/src/main/.gitignore b/src/main/.gitignore index 85393fc..6bb99d3 100644 --- a/src/main/.gitignore +++ b/src/main/.gitignore @@ -1 +1,5 @@ +<<<<<<< HEAD webapp/ +======= +webapp +>>>>>>> refs/remotes/origin/feature/16359 diff --git a/src/main/java/org/gcube/data/access/ckanconnector/ConnectorManager.java b/src/main/java/org/gcube/data/access/ckanconnector/ConnectorManager.java index 00bedbf..b22cd2f 100644 --- a/src/main/java/org/gcube/data/access/ckanconnector/ConnectorManager.java +++ b/src/main/java/org/gcube/data/access/ckanconnector/ConnectorManager.java @@ -20,6 +20,7 @@ import lombok.extern.slf4j.Slf4j; import org.gcube.common.authorization.library.provider.AuthorizationProvider; import org.gcube.common.scope.api.ScopeProvider; +import org.gcube.gcat.client.User; import org.python.core.PyLong; import org.python.core.PyObject; import org.python.core.PyString; @@ -82,22 +83,34 @@ public class ConnectorManager { String ckanKey = context.getInitParameter("ckanKey"); String originalUserName = AuthorizationProvider.instance.get().getClient().getId(); String changedUserName = originalUserName.replace(".", "_"); + + + int internalPort = Integer.parseInt(context.getInitParameter("internalPort")); String localhostName = "http://127.0.0.1:"+internalPort; long startCheckUser = System.currentTimeMillis(); CkanClient ckanClient = new CkanClient(localhostName, ckanKey); - CkanUser user = null; - try{ - user = ckanClient.getUser(changedUserName); - }catch(Exception e){ - log.warn("user {} doesn't exist, the system will create it",originalUserName, e); - } - log.info("checking user took {}",(System.currentTimeMillis()-startCheckUser)); - if (user==null){ - long startCreateUser = System.currentTimeMillis(); - user = ckanClient.createUser(new CkanUser(changedUserName, originalUserName+"@gcube.ckan.org" , randomString.nextString() )); - log.info("create user took {}",(System.currentTimeMillis()-startCreateUser)); + + + try { + User user = new User(); + user.read(changedUserName); + }catch (Throwable tr) { + log.error("Error while contacting gCat. The old code will made the work", tr); + CkanUser user = null; + try{ + user = ckanClient.getUser(changedUserName); + }catch(Exception e){ + log.warn("user {} doesn't exist, the system will create it",originalUserName, e); + } + log.info("checking user took {}",(System.currentTimeMillis()-startCheckUser)); + if (user==null){ + long startCreateUser = System.currentTimeMillis(); + user = ckanClient.createUser(new CkanUser(changedUserName, originalUserName+"@gcube.ckan.org" , randomString.nextString() )); + log.info("create user took {}",(System.currentTimeMillis()-startCreateUser)); + } } + addUserToVres(vres, changedUserName, ckanClient, ckanKey, localhostName); log.info("logging {} in scope {}",originalUserName, ScopeProvider.instance.get());