DECLARE ns NAMESPACE 'http://soa.btn.co.id/ws_generic/';


CREATE COMPUTE MODULE WS_GENERIC_RPG_MODIFY_MSG
	CREATE FUNCTION Main() RETURNS BOOLEAN
	BEGIN
		DECLARE soapenv NAMESPACE 'http://schemas.xmlsoap.org/soap/envelope/';
		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;		
		
		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_RPG_SET_SECURE_PASSWORD
	CREATE FUNCTION Main() RETURNS BOOLEAN
	BEGIN
		-- CALL CopyMessageHeaders();
		CALL CopyEntireMessage();
		
		DELETE FIELD OutputRoot.HTTPInputHeader.Expect;
		DELETE FIELD OutputRoot.HTTPInputHeader.Expect;
		DELETE FIELD OutputRoot.HTTPInputHeader.Connection;
		
		SET OutputRoot.HTTPInputHeader."Accept-Encoding" = 'gzip,deflate';
		--SET OutputRoot.SOAP.Body.ns15:RequestRPGCall.requestrpg.password.secure__ = 'true';
		SET OutputRoot.XMLNSC.ns15:RequestRPGCall.requestrpg.password.secure__ = 'true';
		
		
		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_RPG_REMOVE_XMLNS_REQUEST_RPGCALL
	CREATE FUNCTION Main() RETURNS BOOLEAN
	BEGIN
		CALL CopyMessageHeaders();
		CALL CopyEntireMessage();
		DELETE FIELD OutputRoot.XMLNSC.ns:RequestRPG.request.requestrpg.eof.xmlns;
		DELETE FIELD OutputRoot.XMLNSC.ns:RequestRPG.request.requestrpg.input.xmlns;
		DELETE FIELD OutputRoot.XMLNSC.ns:RequestRPG.request.requestrpg.password.xmlns;
		DELETE FIELD OutputRoot.XMLNSC.ns:RequestRPG.request.requestrpg.progname.xmlns;
		DELETE FIELD OutputRoot.XMLNSC.ns:RequestRPG.request.requestrpg.reqfrom.xmlns;
		DELETE FIELD OutputRoot.XMLNSC.ns:RequestRPG.request.requestrpg.reqto.xmlns;
		DELETE FIELD OutputRoot.XMLNSC.ns:RequestRPG.request.requestrpg.sequence.xmlns;
		DELETE FIELD OutputRoot.XMLNSC.ns:RequestRPG.request.requestrpg.type.xmlns;
		DELETE FIELD OutputRoot.XMLNSC.ns:RequestRPG.request.requestrpg.userid.xmlns;
		DELETE FIELD OutputRoot.XMLNSC.ns:RequestRPG.request.requestrpg.password.xmlns;	
					
		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_RPG_BEFORE_MAPPING_REQUEST
	CREATE FUNCTION Main() RETURNS BOOLEAN
	BEGIN
		CALL CopyMessageHeaders();
		-- CALL CopyEntireMessage();
		
		SET OutputRoot.XMLNSC.data.body = InputRoot.XMLNSC.ns15:RequestRPGCall.requestrpg;

		SET OutputRoot.XMLNSC.data.userid = InputRoot.XMLNSC.ns15:RequestRPGCall.requestrpg.userid;
		SET OutputRoot.XMLNSC.data.password = InputRoot.XMLNSC.ns15:RequestRPGCall.requestrpg.password;
		
		SET OutputRoot.XMLNSC.data.type = 'rpg';
		SET OutputRoot.XMLNSC.data.dir = 'O';
		SET OutputRoot.XMLNSC.data.source = 'GenericService';
		SET OutputRoot.XMLNSC.data.code = 'WS_GENERIC';
		
		SET OutputRoot.XMLNSC.data.reqtimestamp = InputLocalEnvironment.request_timestamp;
		
		--SET OutputRoot.MQMD.CorrelId = InputRoot.MQMD.MsgId;
		--SET OutputRoot.XMLNSC.data.CorrelId = InputLocalEnvironment.request_id;
		
		--SET OutputRoot.XMLNSC.data.userid = 'BTN99998';
		--SET OutputRoot.XMLNSC.data.password = 'B#n99899';
		
		--SET OutputRoot.XMLNSC.data.userid = 'DTI0009959';
		--SET OutputRoot.XMLNSC.data.password = 'irma123';
		
		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_RPG_SET_WS_RESPONSE
	CREATE FUNCTION Main() RETURNS BOOLEAN
	BEGIN
		CALL CopyMessageHeaders();
		-- CALL CopyEntireMessage();
		
		--SET OutputRoot.XMLNSC.data.body.source = InputRoot.XMLNSC.data.source;
		--SET OutputRoot.XMLNSC.data.body.code = InputRoot.XMLNSC.data.code;
		
		SET OutputLocalEnvironment.request_timestamp = InputRoot.XMLNSC.data.reqtimestamp;
		
		SET OutputRoot.XMLNSC.ns15:RequestRPGCallResponse.return.recfrom = InputRoot.XMLNSC.data.body.recfrom;
		SET OutputRoot.XMLNSC.ns15:RequestRPGCallResponse.return.recto = InputRoot.XMLNSC.data.body.recto;
		SET OutputRoot.XMLNSC.ns15:RequestRPGCallResponse.return.eof = InputRoot.XMLNSC.data.body.eof;
		SET OutputRoot.XMLNSC.ns15:RequestRPGCallResponse.return.err = InputRoot.XMLNSC.data.body.err;
		SET OutputRoot.XMLNSC.ns15:RequestRPGCallResponse.return.errdesc = InputRoot.XMLNSC.data.body.errdesc;
		SET OutputRoot.XMLNSC.ns15:RequestRPGCallResponse.return.output = InputRoot.XMLNSC.data.body.output;
		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_RPG_SET_RPG_IN_TYPE
	CREATE FUNCTION Main() RETURNS BOOLEAN
	BEGIN
		-- CALL CopyMessageHeaders();
		CALL CopyEntireMessage();
		SET OutputRoot.XMLNSC.data.type = 'rpg';
		SET OutputRoot.XMLNSC.data.dir = 'I';
		RETURN TRUE;
	END;

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


CREATE COMPUTE MODULE WS_GENERIC_RPG_SET_RPG_OUT_TYPE
	CREATE FUNCTION Main() RETURNS BOOLEAN
	BEGIN
		SET OutputRoot = InputRoot;
		SET OutputRoot.XMLNSC.data.type = 'rpg';
		SET OutputRoot.XMLNSC.data.dir = 'I';
		
		--SET OutputRoot.XMLNSC.data.timestamp = InputRoot.XMLNSC.data.reqtimestamp;
		
		RETURN TRUE;
	END;
END MODULE;
