DECLARE ns15 NAMESPACE 'http://soa.btn.co.id/ws_message_set/';


CREATE COMPUTE MODULE WS_GENERIC_ABCS_MODIFY_MSG
	CREATE FUNCTION Main() RETURNS BOOLEAN
	BEGIN
		--CALL CopyMessageHeaders();
		CALL CopyEntireMessage();
		DELETE FIELD OutputRoot.SOAP.Context."_XmlDeclaration";
		DELETE FIELD OutputRoot.HTTPInputHeader."User-Agent";
		DELETE FIELD OutputRoot.HTTPInputHeader.Vsdebuggercausalitydata;				
		DELETE FIELD OutputRoot.SOAP.Body.*[1].xmlns;
		SET OutputLocalEnvironment = InputLocalEnvironment;
		RETURN TRUE;
	END;

	CREATE PROCEDURE CopyMessageHeaders() BEGIN
		DECLARE I INTEGER 1;
		DECLARE J INTEGER;
		SET J = CARDINALITY(InputRoot.*[]);
		WHILE I < J DO
			SET OutputRoot.*[I] = InputRoot.*[I];
			SET I = I + 1;
		END WHILE;
	END;

	CREATE PROCEDURE CopyEntireMessage() BEGIN
		SET OutputRoot = InputRoot;
	END;
END MODULE;


CREATE COMPUTE MODULE WS_GENERIC_ABCS_MODIFY_DATABODY
	CREATE FUNCTION Main() RETURNS BOOLEAN
	BEGIN
		CALL CopyMessageHeaders();
		CALL CopyEntireMessage();
		SET OutputLocalEnvironment = InputLocalEnvironment;
		SET OutputRoot.XMLNSC.data.body = InputRoot.XMLNSC.ns15:RequestABCS.requestabcs;
		SET OutputRoot.XMLNSC.data.body.security.ipaddress = InputRoot.HTTPInputHeader."X-Remote-Addr";
		SET OutputRoot.XMLNSC.data.body.security.clientipaddr = InputRoot.XMLNSC.ns15:RequestABCS.security.clientipaddress;
		--SET OutputRoot.XMLNSC.data.body.localEnvironment = InputLocalEnvironment.Destination;
		
		--DELETE FIELD OutputRoot.XMLNSC.ns15:RequestABCS;

		RETURN TRUE;
	END;

	CREATE PROCEDURE CopyMessageHeaders() BEGIN
		DECLARE I INTEGER 1;
		DECLARE J INTEGER;
		SET J = CARDINALITY(InputRoot.*[]);
		WHILE I < J DO
			SET OutputRoot.*[I] = InputRoot.*[I];
			SET I = I + 1;
		END WHILE;
	END;

	CREATE PROCEDURE CopyEntireMessage() BEGIN
		SET OutputRoot = InputRoot;
	END;
END MODULE;


CREATE COMPUTE MODULE WS_GENERIC_ABCS_SET_ABCS_BODY
	CREATE FUNCTION Main() RETURNS BOOLEAN
	BEGIN
		CALL CopyMessageHeaders();
		CALL CopyEntireMessage();
		
		SET OutputLocalEnvironment = InputLocalEnvironment;
		SET OutputLocalEnvironment.Destination = InputRoot.XMLNSC.data.body.original.request.body.original.localEnvironment.SOAP;
		SET OutputLocalEnvironment.Destination.RouterList = InputRoot.XMLNSC.data.body.original.request.body.original.localEnvironment.RouterList;
		--SET OutputLocalEnvironment.Destination.SOAP.Reply.ReplyIdentifier = InputRoot.Properties.ReplyIdentifier;
		SET OutputLocalEnvironment.Destination.SOAP.Reply.ReplyIdentifier = InputLocalEnvironment.Destination.SOAP.Reply.ReplyIdentifier;
		
		SET OutputRoot.Properties.ReplyIdentifier = InputLocalEnvironment.Destination.SOAP.Reply.ReplyIdentifier;
		
		SET OutputRoot.XMLNSC.data.timestamp = InputLocalEnvironment.request_timestamp;
		SET OutputRoot.XMLNSC.data.reqtimestamp = InputLocalEnvironment.request_timestamp;
		SET OutputRoot.XMLNSC.data.time_param = InputLocalEnvironment.request_timestamp;
		SET OutputRoot.XMLNSC.data.sid = InputLocalEnvironment.request_id;

		--SET OutputRoot.XMLNSC.data.body.localEnvironment = InputLocalEnvironment.Destination;
		
		DELETE FIELD OutputRoot.XMLNSC.data.body.original;
		
		SET OutputRoot.XMLNSC.data.source_http = InputRoot.HTTPInputHeader."X-Original-HTTP-Command";
		
		SET OutputRoot.XMLNSC.data.request_timestamp = InputLocalEnvironment.request_timestamp;
		
		RETURN TRUE;
	END;

	CREATE PROCEDURE CopyMessageHeaders() BEGIN
		DECLARE I INTEGER 1;
		DECLARE J INTEGER;
		SET J = CARDINALITY(InputRoot.*[]);
		WHILE I < J DO
			SET OutputRoot.*[I] = InputRoot.*[I];
			SET I = I + 1;
		END WHILE;
	END;

	CREATE PROCEDURE CopyEntireMessage() BEGIN
		SET OutputRoot = InputRoot;
	END;
END MODULE;


CREATE COMPUTE MODULE WS_GENERIC_ABCS_SET_ABCS_RESPONSE
	CREATE FUNCTION Main() RETURNS BOOLEAN
	BEGIN
		CALL CopyMessageHeaders();
		--CALL CopyEntireMessage();
		
		SET OutputRoot.HTTPInputHeader."X-Original-HTTP-Command" = InputRoot.XMLNSC.data.request.data.source_http;
		
		SET OutputLocalEnvironment.request_timestamp = InputRoot.XMLNSC.data.request.data.request_timestamp;

		IF InputRoot.XMLNSC.data.body.dspMessageStatus = '/-------' THEN
			SET OutputRoot.XMLNSC.ns15:RequestABCSResponse.return.isError = 'false';
		ELSE
			SET OutputRoot.XMLNSC.ns15:RequestABCSResponse.return.isError = 'true';
		END IF;
		
		SET OutputRoot.XMLNSC.ns15:RequestABCSResponse.return.responseCode = InputRoot.XMLNSC.data.body.responseCode;
		SET OutputRoot.XMLNSC.ns15:RequestABCSResponse.return.responseDescription = InputRoot.data.body.ERROR_F2;
		CALL DisplayMessageOutput();

		SET OutputRoot.Properties = InputRoot.Properties;
		SET OutputRoot.Properties.MessageSet = 'WS_MESSAGE_SET';
		SET OutputRoot.Properties.ReplyProtocol = 'SOAP_AXIS2';
		
		SET OutputLocalEnvironment.Destination = InputRoot.XMLNSC.data.request.data.body.localEnvironment.SOAP;
		SET OutputLocalEnvironment.Destination.RouterList = InputRoot.XMLNSC.data.request.data.body.localEnvironment.RouterList;
		SET OutputLocalEnvironment.Destination.SOAP.Reply.ReplyIdentifier = InputRoot.Properties.ReplyIdentifier;
		 		
		RETURN TRUE;
	END;
	
	CREATE PROCEDURE DisplayMessageOutput() BEGIN
		DECLARE I INTEGER 1;
		DECLARE J INTEGER;
		SET J = CARDINALITY(InputRoot.XMLNSC.data.body.*[]);
		WHILE I <= J DO
			SET OutputRoot.XMLNSC.ns15:RequestABCSResponse.return.additionalFields[I].fieldName = FIELDNAME(InputRoot.XMLNSC.data.body.*[I]);
			SET OutputRoot.XMLNSC.ns15:RequestABCSResponse.return.additionalFields[I].fieldValue = FIELDVALUE(InputRoot.XMLNSC.data.body.*[I]);
			SET I = I + 1;
		END WHILE;
	END;
	
	CREATE PROCEDURE CopyMessageHeaders() BEGIN
		DECLARE I INTEGER 1;
		DECLARE J INTEGER;
		SET J = CARDINALITY(InputRoot.*[]);
		WHILE I < J DO
			SET OutputRoot.*[I] = InputRoot.*[I];
			SET I = I + 1;
		END WHILE;
	END;

	CREATE PROCEDURE CopyEntireMessage() BEGIN
		SET OutputRoot = InputRoot;
	END;
END MODULE;



