Java tutorial
/* * Copyright (c) 2006-2014 Massachusetts General Hospital * All rights reserved. This program and the accompanying materials * are made available under the terms of the i2b2 Software License v2.1 * which accompanies this distribution. * * Contributors: * Lori Phillips */ package fileMapper.ws; import java.util.List; 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 fileMapper.fileMapperUtil.FileMapperJAXBUtil; import fileMapper.data.datavo.i2b2message.BodyType; import fileMapper.data.datavo.i2b2message.ResponseHeaderType; import fileMapper.data.datavo.i2b2message.ResponseMessageType; import fileMapper.data.datavo.i2b2message.StatusType; import fileMapper.data.datavo.i2b2result.DataType; import fileMapper.data.datavo.i2b2result.ResultEnvelopeType; import fileMapper.data.datavo.i2b2result.ResultType; import fileMapper.data.datavo.psm.query.AnalysisPluginMetadataResponseType; import fileMapper.data.datavo.psm.query.AnalysisPluginMetadataTypeType; import fileMapper.data.datavo.psm.query.CrcXmlResultResponseType; import fileMapper.data.datavo.psm.query.MasterInstanceResultResponseType; import fileMapper.data.datavo.psm.query.QueryMasterType; import fileMapper.data.datavo.psm.query.QueryResultInstanceType; import fileMapper.data.datavo.psm.query.XmlValueType; /** * @author Lori Phillips * */ public class GetPsmResponseMessage { public static final String THIS_CLASS_NAME = GetPsmResponseMessage.class.getName(); private Log log = LogFactory.getLog(THIS_CLASS_NAME); private ResponseMessageType respMessageType = null; public GetPsmResponseMessage() { } public StatusType processResult(String response) { StatusType status = null; try { JAXBElement jaxbElement = FileMapperJAXBUtil.getJAXBUtil().unMashallFromString(response); respMessageType = (ResponseMessageType) jaxbElement.getValue(); // Get response message status ResponseHeaderType responseHeader = respMessageType.getResponseHeader(); status = responseHeader.getResultStatus().getStatus(); String procStatus = status.getType(); String procMessage = status.getValue(); if (procStatus.equals("ERROR")) { log.info("Error reported by Crc web Service " + procMessage); } else if (procStatus.equals("WARNING")) { log.info("Warning reported by Crc web Service" + procMessage); } } catch (JAXBUtilException e) { // TODO Auto-generated catch block log.error(e.getMessage()); } return status; } public QueryResultInstanceType extractResultInstance(String response) { QueryResultInstanceType resultInstance = null; try { JAXBElement jaxbElement = FileMapperJAXBUtil.getJAXBUtil().unMashallFromString(response); respMessageType = (ResponseMessageType) jaxbElement.getValue(); // Get response message status BodyType body = respMessageType.getMessageBody(); JAXBUnWrapHelper helper = new JAXBUnWrapHelper(); MasterInstanceResultResponseType responseType = (MasterInstanceResultResponseType) helper .getObjectByClass(body.getAny(), MasterInstanceResultResponseType.class); resultInstance = responseType.getQueryResultInstance().get(0); } catch (JAXBUtilException e) { // TODO Auto-generated catch block log.error(e.getMessage()); return null; } return resultInstance; } public List extractXMLResult(String response) { List<DataType> counts = null; try { JAXBElement jaxbElement = FileMapperJAXBUtil.getJAXBUtil().unMashallFromString(response); respMessageType = (ResponseMessageType) jaxbElement.getValue(); // Get response message status BodyType body = respMessageType.getMessageBody(); JAXBUnWrapHelper helper = new JAXBUnWrapHelper(); CrcXmlResultResponseType responseType = (CrcXmlResultResponseType) helper .getObjectByClass(body.getAny(), CrcXmlResultResponseType.class); XmlValueType xml = responseType.getCrcXmlResult().getXmlValue(); String xmlString = (String) xml.getContent().get(0); jaxbElement = FileMapperJAXBUtil.getJAXBUtil().unMashallFromString(xmlString); ResultEnvelopeType resultEnvelopeType1 = (ResultEnvelopeType) jaxbElement.getValue(); ResultType resultType = (ResultType) helper.getObjectByClass(resultEnvelopeType1.getBody().getAny(), ResultType.class); counts = resultType.getData(); } catch (JAXBUtilException e) { // TODO Auto-generated catch block log.error(e.getMessage()); return null; } return counts; } public QueryMasterType extractQueryMaster(String response) { QueryMasterType queryMaster = null; try { JAXBElement jaxbElement = FileMapperJAXBUtil.getJAXBUtil().unMashallFromString(response); respMessageType = (ResponseMessageType) jaxbElement.getValue(); // Get response message status BodyType body = respMessageType.getMessageBody(); JAXBUnWrapHelper helper = new JAXBUnWrapHelper(); MasterInstanceResultResponseType responseType = (MasterInstanceResultResponseType) helper .getObjectByClass(body.getAny(), MasterInstanceResultResponseType.class); queryMaster = responseType.getQueryMaster(); } catch (JAXBUtilException e) { // TODO Auto-generated catch block log.error(e.getMessage()); return null; } return queryMaster; } public AnalysisPluginMetadataTypeType extractAnalysisPluginMetadata(String response) { try { JAXBElement jaxbElement = FileMapperJAXBUtil.getJAXBUtil().unMashallFromString(response); respMessageType = (ResponseMessageType) jaxbElement.getValue(); // Get response message status BodyType body = respMessageType.getMessageBody(); JAXBUnWrapHelper helper = new JAXBUnWrapHelper(); AnalysisPluginMetadataResponseType responseType = (AnalysisPluginMetadataResponseType) helper .getObjectByClass(body.getAny(), AnalysisPluginMetadataResponseType.class); List<AnalysisPluginMetadataTypeType> plugins = responseType.getAnalysisPluginMetadataType(); if (plugins.isEmpty()) return null; AnalysisPluginMetadataTypeType pluginMetadata = (AnalysisPluginMetadataTypeType) plugins.get(0); return pluginMetadata; } catch (JAXBUtilException e) { // TODO Auto-generated catch block log.error(e.getMessage()); return null; } } }