edu.harvard.i2b2.fr.delegate.pm.PMResponseMessage.java Source code

Java tutorial

Introduction

Here is the source code for edu.harvard.i2b2.fr.delegate.pm.PMResponseMessage.java

Source

/*
 * Copyright (c) 2006-2012 Massachusetts General Hospital 
 * All rights reserved. This program and the accompanying materials 
 * are made available under the terms of the i2b2 Software License v1.0 
 * which accompanies this distribution. 
 * 
 * Contributors: 
 *     Rajesh Kuttan
 */
package edu.harvard.i2b2.fr.delegate.pm;

import javax.xml.bind.JAXBElement;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import edu.harvard.i2b2.common.util.jaxb.JAXBUnWrapHelper;
import edu.harvard.i2b2.common.util.jaxb.JAXBUtilException;
import edu.harvard.i2b2.fr.datavo.FRJAXBUtil;
import edu.harvard.i2b2.fr.datavo.i2b2message.BodyType;
import edu.harvard.i2b2.fr.datavo.i2b2message.ResponseHeaderType;
import edu.harvard.i2b2.fr.datavo.i2b2message.ResponseMessageType;
import edu.harvard.i2b2.fr.datavo.i2b2message.StatusType;
import edu.harvard.i2b2.fr.datavo.pm.ConfigureType;

public class PMResponseMessage {

    public static final String THIS_CLASS_NAME = PMResponseMessage.class.getName();
    private Log log = LogFactory.getLog(THIS_CLASS_NAME);
    private ResponseMessageType pmRespMessageType = null;

    public PMResponseMessage() {
    }

    public StatusType processResult(String response) throws JAXBUtilException {
        StatusType status = null;
        try {

            JAXBElement jaxbElement = FRJAXBUtil.getJAXBUtil().unMashallFromString(response);
            pmRespMessageType = (ResponseMessageType) jaxbElement.getValue();

            // Get response message status 
            ResponseHeaderType responseHeader = pmRespMessageType.getResponseHeader();
            status = responseHeader.getResultStatus().getStatus();
            String procStatus = status.getType();
            String procMessage = status.getValue();

            if (procStatus.equals("ERROR")) {
                log.error("Error reported by CRC web Service " + procMessage);
            } else if (procStatus.equals("WARNING")) {
                log.debug("Warning reported by CRC web Service" + procMessage);
            }

        } catch (JAXBUtilException e) {
            log.error(e);
            throw e;
        }
        return status;
    }

    public ConfigureType readUserInfo() throws JAXBUtilException {
        ConfigureType pmResponse = null;

        BodyType bodyType = pmRespMessageType.getMessageBody();
        JAXBUnWrapHelper helper = new JAXBUnWrapHelper();
        pmResponse = (ConfigureType) helper.getObjectByClass(bodyType.getAny(), ConfigureType.class);

        return pmResponse;
    }

}