Search in sources :

Example 1 with TransactionManager

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;
}
Also used : TransactionManager(org.cristalise.kernel.persistency.TransactionManager) AgentPath(org.cristalise.kernel.lookup.AgentPath) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) ProxyManager(org.cristalise.kernel.entity.proxy.ProxyManager) AgentProxy(org.cristalise.kernel.entity.proxy.AgentProxy) Authenticator(org.cristalise.kernel.process.auth.Authenticator)

Example 2 with TransactionManager

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;
}
Also used : TransactionManager(org.cristalise.kernel.persistency.TransactionManager) Outcome(org.cristalise.kernel.persistency.outcome.Outcome) Viewpoint(org.cristalise.kernel.persistency.outcome.Viewpoint) Schema(org.cristalise.kernel.persistency.outcome.Schema) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) Event(org.cristalise.kernel.events.Event) PersistencyException(org.cristalise.kernel.common.PersistencyException) History(org.cristalise.kernel.events.History) Viewpoint(org.cristalise.kernel.persistency.outcome.Viewpoint)

Example 3 with TransactionManager

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.");
    }
}
Also used : TransactionManager(org.cristalise.kernel.persistency.TransactionManager) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) ProxyManager(org.cristalise.kernel.entity.proxy.ProxyManager) Authenticator(org.cristalise.kernel.process.auth.Authenticator)

Aggregations

InvalidDataException (org.cristalise.kernel.common.InvalidDataException)3 TransactionManager (org.cristalise.kernel.persistency.TransactionManager)3 ProxyManager (org.cristalise.kernel.entity.proxy.ProxyManager)2 Authenticator (org.cristalise.kernel.process.auth.Authenticator)2 PersistencyException (org.cristalise.kernel.common.PersistencyException)1 AgentProxy (org.cristalise.kernel.entity.proxy.AgentProxy)1 Event (org.cristalise.kernel.events.Event)1 History (org.cristalise.kernel.events.History)1 AgentPath (org.cristalise.kernel.lookup.AgentPath)1 Outcome (org.cristalise.kernel.persistency.outcome.Outcome)1 Schema (org.cristalise.kernel.persistency.outcome.Schema)1 Viewpoint (org.cristalise.kernel.persistency.outcome.Viewpoint)1