use of org.cristalise.kernel.persistency.TransactionManager in project kernel by cristal-ise.
the class Gateway method connect.
/**
* Log in with the given username and password, and initialises the {@link Lookup}, {@link TransactionManager} and {@link ProxyManager}.
* It shall be uses in client processes only.
*
* @param agentName - username
* @param agentPassword - password
* @return an AgentProxy on the requested user
*
* @throws InvalidDataException - bad params
* @throws PersistencyException - error starting storages
* @throws ObjectNotFoundException - object not found
*/
public static AgentProxy connect(String agentName, String agentPassword, String resource) throws InvalidDataException, ObjectNotFoundException, PersistencyException {
Authenticator auth = getAuthenticator();
if (!auth.authenticate(agentName, agentPassword, resource))
throw new InvalidDataException("Login failed");
try {
if (mLookup != null)
mLookup.close();
mLookup = (Lookup) mC2KProps.getInstance("Lookup");
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException ex) {
Logger.error(ex);
throw new InvalidDataException("Lookup " + mC2KProps.getString("Lookup") + " could not be instantiated");
}
mLookup.open(auth);
mStorage = new TransactionManager(auth);
mProxyManager = new ProxyManager();
// find agent proxy
AgentPath agentPath = mLookup.getAgentPath(agentName);
AgentProxy agent = (AgentProxy) mProxyManager.getProxy(agentPath);
agent.setAuthObj(auth);
ScriptConsole.setUser(agent);
// Run module startup scripts. Server does this during bootstrap
mModules.setUser(agent);
mModules.runScripts("startup");
Logger.msg("Gateway.connect(agent) - DONE.");
return agent;
}
use of org.cristalise.kernel.persistency.TransactionManager in project kernel by cristal-ise.
the class Import method runActivityLogic.
/**
* Params: Schemaname_version:Viewpoint (optional), Outcome, Timestamp (optional)
*/
@Override
protected String runActivityLogic(AgentPath agent, ItemPath item, int transitionID, String requestData, Object locker) throws InvalidDataException, PersistencyException, ObjectNotFoundException {
String[] params = getDataList(requestData);
if (Logger.doLog(3))
Logger.msg(3, "Import: called by " + agent + " on " + item + " with parameters " + Arrays.toString(params));
int split1 = params[0].indexOf('_');
int split2 = params[0].indexOf(':');
if (split1 == -1)
throw new InvalidDataException("Import: Invalid parameters " + Arrays.toString(params));
requestData = params[1];
Schema schema;
String viewpoint = null;
String schemaName = params[0].substring(0, split1);
int schemaVersion;
if (split2 > -1) {
schemaVersion = Integer.parseInt(params[0].substring(split1 + 1, split2));
viewpoint = params[0].substring(split2 + 1);
} else
schemaVersion = Integer.parseInt(params[0].substring(split1 + 1));
schema = LocalObjectLoader.getSchema(schemaName, schemaVersion);
String timestamp;
if (params.length == 3)
timestamp = params[2];
else
timestamp = DateUtility.timeToString(DateUtility.getNow());
// write event, outcome and viewpoints to storage
TransactionManager storage = Gateway.getStorage();
History hist = getWf().getHistory();
Event event = hist.addEvent(agent, null, getCurrentAgentRole(), getName(), getPath(), getType(), schema, getStateMachine(), transitionID, viewpoint, timestamp);
try {
storage.put(item, new Outcome(event.getID(), requestData, schema), locker);
storage.put(item, new Viewpoint(item, schema, viewpoint, event.getID()), locker);
if (!"last".equals(viewpoint))
storage.put(item, new Viewpoint(item, schema, "last", event.getID()), locker);
} catch (PersistencyException e) {
storage.abort(locker);
throw e;
}
storage.commit(locker);
return requestData;
}
use of org.cristalise.kernel.persistency.TransactionManager in project kernel by cristal-ise.
the class Gateway method connect.
/**
* Connects to the Lookup server in an administrative context - using the admin username and
* password available in the implementation of the Authenticator. It shall be
* used in server processes only.
*
* @throws InvalidDataException - bad params
* @throws PersistencyException - error starting storages
* @throws ObjectNotFoundException - object not found
*/
public static Authenticator connect() throws InvalidDataException, PersistencyException, ObjectNotFoundException {
try {
Authenticator auth = getAuthenticator();
if (!auth.authenticate("System"))
throw new InvalidDataException("Server authentication failed");
if (mLookup != null)
mLookup.close();
mLookup = (Lookup) mC2KProps.getInstance("Lookup");
mLookup.open(auth);
mStorage = new TransactionManager(auth);
mProxyManager = new ProxyManager();
Logger.msg("Gateway.connect() - DONE.");
return auth;
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException ex) {
Logger.error(ex);
throw new InvalidDataException("Cannot connect server process. Please check config.");
}
}
Aggregations