

CREATE COMPUTE MODULE WS_GENERIC_MBASE_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.XMLNSC.ns15:RequestMBASE.requestmbase.xmlns;
		--DELETE FIELD OutputRoot.SOAP.Body.*[1].xmlns;
		
		--DELETE FIELD InputRoot.XMLNSC.wsns:Fault.faultcode;
		--DELETE FIELD InputRoot.XMLNSC.wsns:Fault.faultstring;
		
		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_MBASE_MODIFY_MSG_BODY
	CREATE FUNCTION Main() RETURNS BOOLEAN
	BEGIN
		CALL CopyMessageHeaders();
		CALL CopyEntireMessage();
		SET OutputLocalEnvironment = InputLocalEnvironment;
		
		--SET OutputRoot.XMLNSC.data.body.localEnvironment = InputLocalEnvironment.Destination;
		
		SET OutputRoot.XMLNSC.data.security.ipaddress = InputRoot.HTTPInputHeader."X-Remote-Addr";
		SET OutputRoot.XMLNSC.data.security.userid = InputRoot.XMLNSC.ns15:RequestMBASE.security.userid;
		--SET OutputRoot.XMLNSC.data.labelName = InputLocalEnvironment.Destination.RouterList.DestinationData.labelName;
		SET OutputRoot.XMLNSC.data.labelName = InputLocalEnvironment.SOAP.Envelope.InRequest.ws_message_setSOAP.SOAP.Context.operation;
		SET OutputRoot.XMLNSC.data.original = InputRoot.XMLNSC.ns15:RequestMBASE.requestmbase;
		SET OutputRoot.XMLNSC.data.transactioncode = InputRoot.XMLNSC.ns15:RequestMBASE.transactioncode;
		
		--DELETE FIELD OutputRoot.XMLNSC.ns15:RequestMBASE;
		
		RETURN TRUE;
	END;
	
	CREATE PROCEDURE ConcatRequestInput() BEGIN 
		DECLARE I INTEGER 1;
		DECLARE J INTEGER;
		DECLARE field CHARACTER;
		SET J = CARDINALITY(InputRoot.XMLNSC.ns15:RequestMBASE.requestmbase.additionalFields.fieldName[]);
		WHILE I <= J DO
			SET field = FIELDVALUE(InputRoot.XMLNSC.ns15:RequestMBASE.requestmbase.additionalFields.fieldName.*[I]);
			SET OutputRoot.XMLNSC.data.body.field[I] = FIELDVALUE(InputRoot.XMLNSC.ns15:RequestMBASE.requestmbase.additionalFields.fieldValue[I]);
			SET I = I + 1;
		END WHILE;
	END;
	
	CREATE PROCEDURE CopyRequestToBody() BEGIN
		DECLARE I INTEGER 1;
		DECLARE J INTEGER;
		SET J = CARDINALITY(InputRoot.XMLNSC.ns15:RequestMBASE.requestmbase.*[]);
		WHILE I <= J DO
			SET OutputRoot.XMLNSC.data.body.*[] = InputRoot.XMLNSC.ns15:RequestMBASE.requestmbase.additionalFields.*[];
			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;


CREATE COMPUTE MODULE WS_GENERIC_MBASE_MODIFY_BODY_AFTER_MAPPING
	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 = InputLocalEnvironment.Destination.SOAP.Reply.ReplyIdentifier;
		
		SET OutputRoot.XMLNSC.data.body.localEnvironment = InputLocalEnvironment.Destination;
		
--		SET OutputRoot.XMLNSC.data.timestamp = InputLocalEnvironment.request_timestamp;
--		SET OutputRoot.XMLNSC.data.replyToQueue = 'WS_REPLY_MBASE';
--		SET OutputRoot.XMLNSC.data.time_total = InputLocalEnvironment.request_timestamp;
--		SET OutputRoot.XMLNSC.data.replyToManager = 'WSBROKER';
--		SET OutputRoot.XMLNSC.data.current_timestamp = InputLocalEnvironment.request_timestamp;
--		SET OutputRoot.XMLNSC.data.ReplyIdentifier = InputLocalEnvironment.Destination.SOAP.Reply.ReplyIdentifier;
--		SET OutputRoot.XMLNSC.data.reqtimestamp = InputLocalEnvironment.request_timestamp;
--		SET OutputRoot.XMLNSC.data.time_param = InputLocalEnvironment.request_timestamp;
--		SET OutputRoot.XMLNSC.data.source = 'core-ws';
--		SET OutputRoot.XMLNSC.data.adaptor = 'core-ws';
--		SET OutputRoot.XMLNSC.data.dir = 'O';
		
--		DELETE FIELD OutputRoot.XMLNSC;
--		SET OutputRoot.Properties.ReplyIdentifier = InputLocalEnvironment.Destination.SOAP.Reply.ReplyIdentifier;
--		SET OutputRoot.XMLNSC.data.ReplyIdentifier = InputLocalEnvironment.Destination.SOAP.Reply.ReplyIdentifier;
--		SET OutputRoot.XMLNSC.data.CorrelId = InputRoot.MQMD.CorrelId;
--		
--		SET OutputRoot.XMLNSC.data.timestamp = InputLocalEnvironment.request_timestamp;
--		SET OutputRoot.XMLNSC.data.time_param = InputLocalEnvironment.request_timestamp;
--		SET OutputRoot.XMLNSC.data.sid = InputLocalEnvironment.request_id; 

		--DELETE FIELD OutputRoot.XMLNSC.data.body.original;
		
		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.request_timestamp = InputLocalEnvironment.request_timestamp;
		SET OutputRoot.XMLNSC.data.source_http = InputRoot.HTTPInputHeader."X-Original-HTTP-Command";
				
		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_MBASE_SET_MBASE_RESPONSE
	CREATE FUNCTION Main() RETURNS BOOLEAN
	BEGIN
		CALL CopyMessageHeaders();
		CALL CopyEntireMessage();
		
		DELETE FIELD OutputRoot.XMLNSC;
		
		--IF InputRoot.XMLNSC.data.body.dspMessageStatus = '/-------' THEN
		--	SET OutputRoot.XMLNSC.ns15:RequestMBASEResponse.return.isError = 'false';
		--ELSE
		--	SET OutputRoot.XMLNSC.ns15:RequestMBASEResponse.return.isError = 'true';
		--END IF;
		
		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.RIND = 'AA' THEN
			SET OutputRoot.XMLNSC.ns15:RequestMBASEResponse.return.isError = 'false';
		ELSE
			SET OutputRoot.XMLNSC.ns15:RequestMBASEResponse.return.isError = 'true';
		END IF;
		
		SET OutputRoot.XMLNSC.ns15:RequestMBASEResponse.return.responseCode = InputRoot.XMLNSC.data.body.responseCode;
		SET OutputRoot.XMLNSC.ns15:RequestMBASEResponse.return.responseDesciption = 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;
		SET OutputLocalEnvironment.Destination.SOAP.Reply.ReplyIdentifier = InputRoot.MQMD.CorrelId;
		
		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:RequestMBASEResponse.return.additionalFields[I].fieldName = FIELDNAME(InputRoot.XMLNSC.data.body.*[I]);
			SET OutputRoot.XMLNSC.ns15:RequestMBASEResponse.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;


CREATE COMPUTE MODULE WS_GENERIC_MBASE_SET_HEAD_FOR_MAPPING
	CREATE FUNCTION Main() RETURNS BOOLEAN
	BEGIN
		CALL CopyMessageHeaders();
		CALL CopyEntireMessage();
		--SET OutputRoot.XMLNSC.data.CorrelId = InputLocalEnvironment.Destination.SOAP.Reply.ReplyIdentifier;
		--SET OutputRoot.XMLNSC.data.labelName = InputLocalEnvironment.Destination.RouterList.DestinationData.labelName;
		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;

