use of com.hp.oo.sdk.content.annotations.Output 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.Output 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