Search in sources :

Example 21 with GlobalSessionObject

use of com.hp.oo.sdk.content.plugin.GlobalSessionObject in project cs-actions by CloudSlang.

the class CounterProcessor method init.

public void init(String to, String from, String by, boolean reset, GlobalSessionObject<Map<String, Object>> session) throws CounterImplException {
    /*
         * If the session resource is not ini
         */
    if (session.get() == null) {
        session.setResource(new CounterSessionResource(new HashMap<String, Object>()));
    }
    Map<String, Object> sessionMap = session.get();
    try {
        start = Long.parseLong(from.trim());
        end = Long.parseLong(to.trim());
        if (by == null || by.length() == 0)
            increment = 1;
        else
            try {
                increment = Integer.parseInt(by);
            } catch (Exception e) {
                increment = 1;
            }
    } catch (Exception e) {
        throw new CounterImplException("Start or end is not a long integer, or by is not an integer.\nfrom: " + from + "\nto: " + to + "\nby:" + by);
    }
    try {
        index = (Integer) sessionMap.get(INDEX);
    } catch (Exception e) {
        index = 0;
    }
    if (index == 0 && initialized(session)) {
        sessionMap.put(INDEX, 0);
    }
    // ok, now push data into context
    if (!initialized(session)) {
        sessionMap.put(INDEX, 0);
    }
    // pull data from context
    this.index = (Integer) sessionMap.get(INDEX);
}
Also used : HashMap(java.util.HashMap) GlobalSessionObject(com.hp.oo.sdk.content.plugin.GlobalSessionObject) CounterImplException(io.cloudslang.content.azure.exceptions.CounterImplException) CounterImplException(io.cloudslang.content.azure.exceptions.CounterImplException)

Aggregations

GlobalSessionObject (com.hp.oo.sdk.content.plugin.GlobalSessionObject)21 HashMap (java.util.HashMap)16 Map (java.util.Map)10 Test (org.junit.Test)8 SerializableSessionObject (com.hp.oo.sdk.content.plugin.SerializableSessionObject)6 SQLInputs (io.cloudslang.content.database.utils.SQLInputs)6 SQLSessionResource (io.cloudslang.content.database.utils.SQLSessionResource)6 Action (com.hp.oo.sdk.content.annotations.Action)5 SQLUtils.getRowsFromGlobalSessionMap (io.cloudslang.content.database.utils.SQLUtils.getRowsFromGlobalSessionMap)3 OutputUtilities.getFailureResultsMap (io.cloudslang.content.utils.OutputUtilities.getFailureResultsMap)3 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)3 OutputUtilities.getSuccessResultsMap (io.cloudslang.content.utils.OutputUtilities.getSuccessResultsMap)2 Value (io.cloudslang.lang.entities.bindings.values.Value)2 RunEnvironment (io.cloudslang.lang.runtime.env.RunEnvironment)2 NonSerializableObject (io.cloudslang.lang.runtime.steps.ContentTestActions.NonSerializableObject)2 Output (com.hp.oo.sdk.content.annotations.Output)1 Param (com.hp.oo.sdk.content.annotations.Param)1 Response (com.hp.oo.sdk.content.annotations.Response)1 MatchType (com.hp.oo.sdk.content.plugin.ActionMetadata.MatchType)1 ResponseType (com.hp.oo.sdk.content.plugin.ActionMetadata.ResponseType)1