Enhanced version
This commit is contained in:
parent
65c2fa264a
commit
3db0d61283
2
pom.xml
2
pom.xml
|
@ -11,7 +11,7 @@
|
||||||
|
|
||||||
<groupId>org.gcube.data.access</groupId>
|
<groupId>org.gcube.data.access</groupId>
|
||||||
<artifactId>ckan-connector</artifactId>
|
<artifactId>ckan-connector</artifactId>
|
||||||
<version>1.1.2-SNAPSHOT</version>
|
<version>1.2.0-SNAPSHOT</version>
|
||||||
<packaging>war</packaging>
|
<packaging>war</packaging>
|
||||||
<name>ckan connector</name>
|
<name>ckan connector</name>
|
||||||
<description>a ckan connector for automatic login</description>
|
<description>a ckan connector for automatic login</description>
|
||||||
|
|
|
@ -20,6 +20,7 @@ import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
import org.gcube.common.authorization.library.provider.AuthorizationProvider;
|
import org.gcube.common.authorization.library.provider.AuthorizationProvider;
|
||||||
import org.gcube.common.scope.api.ScopeProvider;
|
import org.gcube.common.scope.api.ScopeProvider;
|
||||||
|
import org.gcube.gcat.client.User;
|
||||||
import org.python.core.PyLong;
|
import org.python.core.PyLong;
|
||||||
import org.python.core.PyObject;
|
import org.python.core.PyObject;
|
||||||
import org.python.core.PyString;
|
import org.python.core.PyString;
|
||||||
|
@ -82,22 +83,34 @@ public class ConnectorManager {
|
||||||
String ckanKey = context.getInitParameter("ckanKey");
|
String ckanKey = context.getInitParameter("ckanKey");
|
||||||
String originalUserName = AuthorizationProvider.instance.get().getClient().getId();
|
String originalUserName = AuthorizationProvider.instance.get().getClient().getId();
|
||||||
String changedUserName = originalUserName.replace(".", "_");
|
String changedUserName = originalUserName.replace(".", "_");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int internalPort = Integer.parseInt(context.getInitParameter("internalPort"));
|
int internalPort = Integer.parseInt(context.getInitParameter("internalPort"));
|
||||||
String localhostName = "http://127.0.0.1:"+internalPort;
|
String localhostName = "http://127.0.0.1:"+internalPort;
|
||||||
long startCheckUser = System.currentTimeMillis();
|
long startCheckUser = System.currentTimeMillis();
|
||||||
CkanClient ckanClient = new CkanClient(localhostName, ckanKey);
|
CkanClient ckanClient = new CkanClient(localhostName, ckanKey);
|
||||||
CkanUser user = null;
|
|
||||||
try{
|
|
||||||
user = ckanClient.getUser(changedUserName);
|
try {
|
||||||
}catch(Exception e){
|
User user = new User();
|
||||||
log.warn("user {} doesn't exist, the system will create it",originalUserName, e);
|
user.read(changedUserName);
|
||||||
}
|
}catch (Exception ex) {
|
||||||
log.info("checking user took {}",(System.currentTimeMillis()-startCheckUser));
|
log.error("Error while contacting gCat. The old code will made the work", ex);
|
||||||
if (user==null){
|
CkanUser user = null;
|
||||||
long startCreateUser = System.currentTimeMillis();
|
try{
|
||||||
user = ckanClient.createUser(new CkanUser(changedUserName, originalUserName+"@gcube.ckan.org" , randomString.nextString() ));
|
user = ckanClient.getUser(changedUserName);
|
||||||
log.info("create user took {}",(System.currentTimeMillis()-startCreateUser));
|
}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);
|
addUserToVres(vres, changedUserName, ckanClient, ckanKey, localhostName);
|
||||||
|
|
||||||
log.info("logging {} in scope {}",originalUserName, ScopeProvider.instance.get());
|
log.info("logging {} in scope {}",originalUserName, ScopeProvider.instance.get());
|
||||||
|
|
Loading…
Reference in New Issue