All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.debugthug.transformers.HoldInventoryTransformer Maven / Gradle / Ivy

package com.github.debugthug.transformers;

import java.util.List;
import java.util.TimeZone;

import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;

import com.github.debugthug.scCryptography;
import com.github.debugthug.converters.IntConverterTest;
import com.github.debugthug.exceptions.HoldInventoryException;
import com.github.debugthug.exceptions.IncorrectRequestException;
import com.github.debugthug.validators.HoldInventoryValidator;
import com.github.debugthug.xo.Authenticate;
import com.github.debugthug.xo.Body;
import com.github.debugthug.xo.Envelope;
import com.github.debugthug.xo.holdInventory.Hold;
import com.github.debugthug.xo.holdInventory.HoldInventory;
import com.github.debugthug.xo.holdInventory.HoldInventoryRQ;
import com.github.debugthug.xo.holdInventory.HoldInventoryRS;
import com.github.debugthug.xo.holdInventory.HoldInventoryResponse;
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.converters.basic.DateConverter;
import com.thoughtworks.xstream.converters.basic.NullConverter;

public class HoldInventoryTransformer {
	final Logger logger = Logger.getLogger(HoldInventoryTransformer.class);
	public String transformRequest(Envelope envelopeHoldInvRQ) throws HoldInventoryException {

		try {
			DateConverter dateconverter = new DateConverter("yyyyMMdd", new String[] {},TimeZone.getDefault());
			
			HoldInventoryValidator holdInventoryValidator = new HoldInventoryValidator();
			holdInventoryValidator.validate(envelopeHoldInvRQ);
			
			Body body = envelopeHoldInvRQ.getBody();
			HoldInventory holdInventory = body.getHoldInventory();
			HoldInventoryRQ holdInventoryRQ = holdInventory.getStrInput().getHoldInventoryRQ();
			Authenticate authenticateHoldInventoryRQ = holdInventoryRQ.getAunthenticate();
			List holdList = holdInventoryRQ.getHoldList();
			int holdListSize = holdList.size();
			int i = 0;
			Hold hold = null;

			StringBuilder sb = new StringBuilder();
			sb.append("");
			sb.append("");

			for (i = 0; i < holdListSize; i++) {
				hold = holdList.get(i);

				sb.append("");
			}
			sb.append("");

			logger.debug("request created::" + sb.toString());
			String request = null;
			scCryptography sc = new scCryptography();
			request = sc.Encrypt(sb.toString());

			StringBuilder builder = new StringBuilder(
					"");
			builder.append("");
			builder.append("");
			builder.append("");
			builder.append(request);
			builder.append("");
			builder.append("");
			builder.append("");
			builder.append("");

			return builder.toString();
		} catch (IncorrectRequestException ire) {
			throw new HoldInventoryException(ire.getMessage(), ire);
		} catch (Exception e) {
			throw new HoldInventoryException(e);
		}

	}

	public Envelope transformResponse(String holdResponse) throws HoldInventoryException {

		Envelope envelopeHoldInvRS = null;

		try {

			XStream xstream = new XStream();
			xstream.processAnnotations(Envelope.class);

			xstream.registerLocalConverter(Hold.class, "orderNo", new IntConverterTest());
			xstream.registerLocalConverter(Hold.class, "holdID", new NullConverter());
			xstream.registerLocalConverter(Hold.class, "status", new NullConverter());

			envelopeHoldInvRS = (Envelope) xstream.fromXML(holdResponse);

			HoldInventoryResponse holdInventoryResponse = envelopeHoldInvRS.getBody().getHoldInventoryResponse();
			HoldInventoryRS holdInventoryRS = holdInventoryResponse.getHoldInventoryResult().getHoldInventoryRS();
			String status = holdInventoryRS.getErrors().getStatus();
			String errorDescription = holdInventoryRS.getErrors().getError().getDescription();
			if(StringUtils.equalsIgnoreCase("TRUE", status) || !(StringUtils.isEmpty(errorDescription)))
				throw new Exception(errorDescription);

		} catch (Exception e) {
			throw new HoldInventoryException(e.getMessage(), e);
		}

		return envelopeHoldInvRS;

	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy