use of com.hp.oo.sdk.content.annotations.Param in project cloud-slang by CloudSlang.
the class ExecutableExecutionData method startExecutable.
public void startExecutable(@Param(ScoreLangConstants.EXECUTABLE_INPUTS_KEY) List<Input> executableInputs, @Param(ScoreLangConstants.RUN_ENV) RunEnvironment runEnv, @Param(ScoreLangConstants.USER_INPUTS_KEY) Map<String, ? extends Value> userInputs, @Param(EXECUTION_RUNTIME_SERVICES) ExecutionRuntimeServices executionRuntimeServices, @Param(ScoreLangConstants.NODE_NAME_KEY) String nodeName, @Param(ScoreLangConstants.NEXT_STEP_ID_KEY) Long nextStepId, @Param(ScoreLangConstants.EXECUTABLE_TYPE) ExecutableType executableType, @Param(SYSTEM_CONTEXT) SystemContext systemContext, @Param(USE_EMPTY_VALUES_FOR_PROMPTS_KEY) Boolean useEmptyValuesForPrompts) {
try {
if (runEnv.isContextModified()) {
rebindArguments(runEnv, executionRuntimeServices, nodeName);
}
Map<String, Value> callArguments = runEnv.removeCallArguments();
List<Input> mutableInputList = new ArrayList<>(executableInputs);
if (userInputs != null) {
callArguments.putAll(userInputs);
// merge is done only for flows that have extra inputs besides those defined as "flow inputs"
if (executionRuntimeServices.getMergeUserInputs()) {
Map<String, Input> executableInputsMap = mutableInputList.stream().collect(toMap(Input::getName, Function.identity()));
for (String inputName : userInputs.keySet()) {
Value inputValue = userInputs.get(inputName);
Input inputToUpdate = executableInputsMap.get(inputName);
if (inputToUpdate != null) {
Input updatedInput = new Input.InputBuilder(inputToUpdate, inputValue).build();
mutableInputList.set(mutableInputList.indexOf(inputToUpdate), updatedInput);
} else {
Input toAddInput = new Input.InputBuilder(inputName, inputValue).build();
mutableInputList.add(toAddInput);
}
}
}
}
executableInputs = Collections.unmodifiableList(mutableInputList);
// restore what was already prompted and add newly prompted values
Map<String, Value> promptedValues = runEnv.removePromptedValues();
promptedValues.putAll(missingInputHandler.applyPromptInputValues(systemContext, executableInputs));
Map<String, Prompt> promptArguments = runEnv.removePromptArguments();
List<Input> newExecutableInputs = addUserDefinedStepInputs(executableInputs, callArguments, promptArguments);
if (systemContext.get(DEBUGGER_EXECUTABLE_INPUTS) != null) {
Map<String, Value> debuggerInputs = (Map<String, Value>) systemContext.remove(DEBUGGER_EXECUTABLE_INPUTS);
List<Input> newInputs = debuggerInputs.entrySet().stream().map(entry -> new Input.InputBuilder(entry.getKey(), entry.getValue()).withRequired(false).build()).collect(toList());
List<Input> updatedExecutableInputs = new ArrayList<>(newExecutableInputs.size() + newInputs.size());
updatedExecutableInputs.addAll(executableInputs);
updatedExecutableInputs.addAll(newInputs);
newExecutableInputs = updatedExecutableInputs;
}
LanguageEventData.StepType stepType = LanguageEventData.convertExecutableType(executableType);
sendStartBindingInputsEvent(newExecutableInputs, runEnv, executionRuntimeServices, "Pre Input binding for " + stepType, stepType, nodeName, callArguments);
Map<String, Value> magicVariables = magicVariableHelper.getGlobalContext(executionRuntimeServices);
List<Input> missingInputs = new ArrayList<>();
ReadOnlyContextAccessor context = new ReadOnlyContextAccessor(callArguments, magicVariables);
Map<String, Value> boundInputValues = inputsBinding.bindInputs(newExecutableInputs, context.getMergedContexts(), promptedValues, runEnv.getSystemProperties(), missingInputs, isTrue(useEmptyValuesForPrompts), promptArguments);
boolean continueToNext = true;
if (systemContext.containsKey(ScoreLangConstants.USER_INTERRUPT)) {
Long parentRid = null;
if (systemContext.containsKey(PARENT_RUNNING_ID)) {
parentRid = (Long) systemContext.get(PARENT_RUNNING_ID);
}
continueToNext = !debuggerBreakpointsHandler.handleBreakpoints(systemContext, runEnv, executionRuntimeServices, stepType, nodeName, extractUuid(executionRuntimeServices, parentRid));
}
// try to resolve it using provided missing input handler
if (CollectionUtils.isNotEmpty(missingInputs)) {
boolean canContinue = missingInputHandler.resolveMissingInputs(missingInputs, systemContext, runEnv, executionRuntimeServices, stepType, nodeName, isTrue(useEmptyValuesForPrompts));
if (!canContinue) {
// we must keep the state unchanged}
runEnv.putCallArguments(callArguments);
runEnv.putPromptArguments(promptArguments);
// keep what was already prompted
runEnv.keepPromptedValues(promptedValues);
return;
}
}
Map<String, Value> actionArguments = new HashMap<>(boundInputValues);
// updated stored input arguments to be later used for output binding
saveStepInputsResultContext(runEnv, callArguments, promptedValues);
// done with the user inputs, don't want it to be available in next startExecutable steps..
if (userInputs != null) {
userInputs.clear();
}
updateCallArgumentsAndPushContextToStack(runEnv, new Context(boundInputValues, magicVariables), actionArguments, new HashMap<>(), continueToNext);
sendEndBindingInputsEvent(newExecutableInputs, boundInputValues, runEnv, executionRuntimeServices, "Post Input binding for " + stepType, stepType, nodeName, callArguments);
executionRuntimeServices.setShouldCheckGroup();
if (continueToNext) {
// put the next step position for the navigation
runEnv.putNextStepPosition(nextStepId);
runEnv.getExecutionPath().down();
}
} catch (RuntimeException e) {
logger.error("There was an error running the start executable execution step of: \'" + nodeName + "\'.\n\tError is: " + e.getMessage());
throw new RuntimeException("Error running: \'" + nodeName + "\'.\n\t " + e.getMessage(), e);
}
}
use of com.hp.oo.sdk.content.annotations.Param in project cs-actions by CloudSlang.
the class AddMember method execute.
@Action(name = ADD_MEMBER, description = ADD_MEMBER_DESCRIPTION, outputs = { @Output(RETURN_RESULT), @Output(STATUS_CODE), @Output(RETURN_CODE), @Output(EXCEPTION) }, responses = { @Response(text = ResponseNames.SUCCESS, field = OutputNames.RETURN_CODE, value = ReturnCodes.SUCCESS, matchType = MatchType.COMPARE_EQUAL, responseType = ResponseType.RESOLVED), @Response(text = ResponseNames.FAILURE, field = OutputNames.RETURN_CODE, value = ReturnCodes.FAILURE, matchType = MatchType.COMPARE_EQUAL, responseType = ResponseType.ERROR, isOnFail = true) })
public Map<String, String> execute(@Param(value = HOST, description = HOST_DESCRIPTION, required = true) String hostName, @Param(value = PROTOCOL, description = PROTOCOL_DESCRIPTION) String protocol, @Param(value = AUTH_TOKEN, description = AUTH_TOKEN_DESCRIPTION, required = true) String authToken, @Param(value = SAFE_URL_ID, description = SAFE_URL_ID_DESCRIPTION, required = true) String safeUrlId, @Param(value = MEMBER_NAME, description = MEMBER_NAME_DESCRIPTION, required = true) String memberName, @Param(value = SEARCH_IN, description = SEARCH_IN_DESCRIPTION) String searchIn, @Param(value = MEMBERSHIP_EXPIRATION_DATE, description = MEMBERSHIP_EXPIRATION_DATE_DESCRIPTION) String membershipExpirationDate, @Param(value = PERMISSIONS, description = PERMISSIONS_DESCRIPTION) String permissions, @Param(value = IS_READ_ONLY, description = IS_READ_ONLY_DESCRIPTION) String isReadOnly, @Param(value = MEMBER_TYPE, description = MEMBER_TYPE_DESCRIPTION) String memberType, @Param(value = PROXY_HOST, description = PROXY_HOST_DESCRIPTION) String proxyHost, @Param(value = PROXY_PORT, description = PROXY_PORT_DESCRIPTION) String proxyPort, @Param(value = PROXY_USERNAME, description = PROXY_USERNAME_DESCRIPTION) String proxyUsername, @Param(value = PROXY_PASSWORD, encrypted = true, description = PROXY_PASSWORD_DESCRIPTION) String proxyPassword, @Param(value = TLS_VERSION, description = TLS_VERSION_DESCRIPTION) String tlsVersion, @Param(value = ALLOWED_CIPHERS, description = ALLOWED_CIPHERS_DESCRIPTION) String allowedCiphers, @Param(value = TRUST_ALL_ROOTS, description = TRUST_ALL_ROOTS_DESCRIPTION) String trustAllRoots, @Param(value = X509_HOSTNAME_VERIFIER, description = X509_HOSTNAME_VERIFIER_DESCRIPTION) String x509HostnameVerifier, @Param(value = TRUST_KEYSTORE, description = TRUST_KEYSTORE_DESCRIPTION) String trustKeystore, @Param(value = TRUST_PASSWORD, encrypted = true, description = TRUST_PASSWORD_DESCRIPTION) String trustPassword, @Param(value = KEYSTORE, description = KEYSTORE_DESCRIPTION) String keystore, @Param(value = KEYSTORE_PASSWORD, encrypted = true, description = KEYSTORE_PASSWORD_DESCRIPTION) String keystorePassword, @Param(value = CONNECT_TIMEOUT, description = CONNECT_TIMEOUT_DESCRIPTION) String connectTimeout, @Param(value = EXECUTION_TIMEOUT, description = EXECUTION_TIMEOUT_DESCRIPTION) String executionTimeout, @Param(value = KEEP_ALIVE, description = KEEP_ALIVE_DESCRIPTION) String keepAlive, @Param(value = CONNECTIONS_MAX_PER_ROUTE, description = CONNECTIONS_MAX_PER_ROUTE_DESCRIPTION) String connectionsMaxPerRoute, @Param(value = CONNECTIONS_MAX_TOTAL, description = CONNECTIONS_MAX_TOTAL_DESCRIPTION) String connectionsMaxTotal, @Param(value = SESSION_COOKIES, description = SESSION_COOKIES_DESC) SerializableSessionObject sessionCookies, @Param(value = SESSION_CONNECTION_POOL, description = SESSION_CONNECTION_POOL_DESC) GlobalSessionObject sessionConnectionPool) {
try {
validateProtocol(protocol);
JSONObject body = new JSONObject();
body.put(MEMBER_NAME, memberName);
body.put(SEARCH_IN, searchIn);
if (!StringUtils.isEmpty(membershipExpirationDate))
body.put(MEMBERSHIP_EXPIRATION_DATE, membershipExpirationDate);
JSONObject permissionsJson = new JSONObject();
if (!StringUtils.isEmpty(permissions))
Arrays.stream(permissions.trim().split(SEMICOLON)).map(permission -> permission.split(EQUALS)).forEach(permission -> permissionsJson.put(permission[0], permission[1]));
body.put(PERMISSIONS, permissionsJson);
body.put(IS_READ_ONLY, isReadOnly);
body.put(MEMBER_TYPE, memberType);
Map<String, String> result = new HttpClientPostAction().execute(protocol + PROTOCOL_DELIMITER + hostName + ADD_MEMBER_ENDPOINT + safeUrlId + MEMBERS, ANONYMOUS, EMPTY, EMPTY, EMPTY, proxyHost, proxyPort, proxyUsername, proxyPassword, tlsVersion, allowedCiphers, trustAllRoots, x509HostnameVerifier, trustKeystore, trustPassword, keystore, keystorePassword, keepAlive, connectionsMaxPerRoute, connectionsMaxTotal, EMPTY, EMPTY, CONTENT_TYPE + APPLICATION_JSON + COMMA + AUTHORIZATION + authToken, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, body.toString(), APPLICATION_JSON, EMPTY, connectTimeout, EMPTY, executionTimeout, sessionCookies, sessionConnectionPool);
processHttpResult(result);
return result;
} catch (Exception exception) {
return OutputUtilities.getFailureResultsMap(exception);
}
}
use of com.hp.oo.sdk.content.annotations.Param in project cs-actions by CloudSlang.
the class Base64Encoder method execute.
/**
* This encodes in base64 a value read from a file.
*
* @param filePath - the path were the desired file is to be encoded.
* @return - a map containing the output of the operation. Keys present in the map are:
* returnResult - The encoded value.
* returnCode - the return code of the operation. 0 if the operation goes to success, -1 if the operation goes to failure.
* exception - the exception message if the operation fails.
*/
@Action(name = Descriptions.EncodeFileToStringOutput.BASE64_ENCODER_FROM_FILE, description = Descriptions.EncodeFileToStringOutput.BASE64_ENCODER_FROM_FILE_DESC, outputs = { @Output(value = OutputNames.EXCEPTION, description = Descriptions.EncodeFileToStringOutput.EXCEPTION_DESC), @Output(value = OutputNames.RETURN_CODE, description = Descriptions.EncodeFileToStringOutput.RETURN_CODE_DESC), @Output(value = OutputNames.RETURN_RESULT, description = Descriptions.EncodeFileToStringOutput.RETURN_RESULT_DESC), @Output(value = Constants.RETURN_VALUE, description = Descriptions.EncodeFileToStringOutput.RETURN_VALUE_DESC) }, responses = { @Response(text = ResponseNames.FAILURE, field = OutputNames.RETURN_CODE, value = ReturnCodes.FAILURE, matchType = MatchType.COMPARE_EQUAL, responseType = ResponseType.ERROR, description = Descriptions.EncodeFileToStringOutput.FAILURE_DESC), @Response(text = ResponseNames.SUCCESS, field = OutputNames.RETURN_CODE, value = ReturnCodes.SUCCESS, matchType = MatchType.COMPARE_EQUAL, responseType = ResponseType.RESOLVED, description = Descriptions.EncodeFileToStringOutput.SUCCESS_DESC) })
public Map<String, String> execute(@Param(value = Inputs.Base64CoderInputs.FILE_PATH, description = Descriptions.EncodeFileToStringOutput.FILE_PATH_DESC, required = true) String filePath) {
final List<String> exceptionMessages = InputsValidation.verifyBase64EncoderInputs(filePath);
if (!exceptionMessages.isEmpty()) {
final Map<String, String> result = OutputUtilities.getFailureResultsMap(StringUtilities.join(exceptionMessages, Constants.NEW_LINE));
result.put(Constants.RETURN_VALUE, Constants.ENCODE_EXCEPTION_MESSAGE);
return result;
}
try {
Base64EncoderInputs base64EncoderInputs = new Base64EncoderInputs.Base64EncoderInputsBuilder().with(builder -> builder.filePath = filePath).buildInputs();
final String resultResult = Base64EncoderToStringImpl.displayEncodedBytes(base64EncoderInputs);
final Map<String, String> result = OutputUtilities.getSuccessResultsMap(Constants.ENCODE_RETURN_VALUE + resultResult);
result.put(Constants.RETURN_VALUE, resultResult);
return result;
} catch (Exception exception) {
final Map<String, String> result = OutputUtilities.getFailureResultsMap(exception);
result.put(Constants.RETURN_VALUE, Constants.ENCODE_NO_FILE_EXCEPTION);
return result;
}
}
Aggregations