private String getXMLString(JAXBElement<?> jaxbElement) throws Exception {
    JAXBUtil jaxbUtil = new JAXBUtil(new String[] {"edu.harvard.i2b2.core.datavo.pdo"});
    StringWriter strWriter = new StringWriter();

    jaxbUtil.marshaller(jaxbElement, strWriter);

    return strWriter.toString();
  }
  public static String getAnalysisDefinitionXml(AnalysisDefinitionType analysisDefinition)
      throws JAXBUtilException {
    StringWriter queryDefWriter = new StringWriter();
    edu.harvard.i2b2.crc.datavo.setfinder.query.ObjectFactory of =
        new edu.harvard.i2b2.crc.datavo.setfinder.query.ObjectFactory();
    JAXBUtil jaxbUtil = CRCJAXBUtil.getAnalysisDefJAXBUtil();
    jaxbUtil.marshaller(of.createAnalysisDefinition(analysisDefinition), queryDefWriter);

    return queryDefWriter.toString();
  }
예제 #3
0
  public void setUserInfo(String responseXML) throws Exception {
    // log.info("PM response message: /n"+responseXML);
    UserInfoBean.pmResponse(responseXML);

    JAXBUtil jaxbUtil =
        new JAXBUtil(
            new String[] {
              "edu.harvard.i2b2.pm.datavo.pm", //$NON-NLS-1$
              "edu.harvard.i2b2.pm.datavo.i2b2message" //$NON-NLS-1$
            });
    JAXBElement jaxbElement = jaxbUtil.unMashallFromString(responseXML);
    ResponseMessageType responseMessageType = (ResponseMessageType) jaxbElement.getValue();

    String procStatus =
        responseMessageType.getResponseHeader().getResultStatus().getStatus().getType();
    String procMessage =
        responseMessageType.getResponseHeader().getResultStatus().getStatus().getValue();

    // String serverVersion = responseMessageType.getMessageHeader()
    // .getSendingApplication().getApplicationVersion();
    // System.setProperty("serverVersion", serverVersion);

    if (procStatus.equals("ERROR")) { // $NON-NLS-1$
      setMsg(procMessage);
    } else if (procStatus.equals("WARNING")) { // $NON-NLS-1$
      setMsg(procMessage);
    } else {
      BodyType bodyType = responseMessageType.getMessageBody();
      JAXBUnWrapHelper helper = new JAXBUnWrapHelper();
      ConfigureType response =
          (ConfigureType) helper.getObjectByClass(bodyType.getAny(), ConfigureType.class);

      userInfoBean.setEnvironment(response.getEnvironment());
      userInfoBean.setUserName(response.getUser().getUserName());
      userInfoBean.setUserFullName(response.getUser().getFullName());
      // userInfoBean.setUserPassword(response.getUser().getPassword());
      userInfoBean.setUserKey(response.getUser().getKey());
      userInfoBean.setUserDomain(response.getUser().getDomain());
      userInfoBean.setHelpURL(response.getHelpURL());

      // Save Global variables in properties
      if (response.getGlobalData() != null) {
        for (ParamType param : response.getGlobalData().getParam())
          userInfoBean.setGlobals(param.getName(), param.getValue());
      }
      // Save projects
      if (response.getUser().getProject() != null)
        // userInfoBean.setProjects( response.getUser().getProject());

        // Save Cell
        if (response.getCellDatas() != null) {}
      // userInfoBean.setCellDatas(response.getCellDatas());
    }
  }
예제 #4
0
  public String writeContentQueryXML(String queryName, String userId) {
    // DTOFactory dtoFactory = new DTOFactory();

    // QueryType queryType = new QueryType();

    // create header
    PsmQryHeaderType headerType = new PsmQryHeaderType();
    UserType userType = new UserType();
    userType.setLogin(userId);
    userType.setValue(userId);
    headerType.setUser(userType);
    headerType.setRequestType(PsmRequestTypeType.CRC_QRY_RUN_QUERY_INSTANCE_FROM_QUERY_DEFINITION);

    // QuerySetType querySetType = new QuerySetType();
    // querySetType.getQuery().add(queryType);

    RequestHeaderType requestHeader = new RequestHeaderType();
    requestHeader.setResultWaittimeMs(180000);
    BodyType bodyType = new BodyType();
    edu.harvard.i2b2.crcxmljaxb.datavo.psm.query.ObjectFactory psmOf =
        new edu.harvard.i2b2.crcxmljaxb.datavo.psm.query.ObjectFactory();
    bodyType.getAny().add(psmOf.createPsmheader(headerType));

    MessageHeaderType messageHeader = getMessageHeader();
    RequestMessageType requestMessageType = new RequestMessageType();
    requestMessageType.setMessageBody(bodyType);
    requestMessageType.setMessageHeader(messageHeader);
    requestMessageType.setRequestHeader(requestHeader);
    // dtoFactory.getRequestMessageType(messageHeader, requestHeader,
    // bodyType);

    JAXBUtil jaxbUtil = PreviousQueryJAXBUtil.getJAXBUtil();
    StringWriter strWriter = new StringWriter();
    try {
      edu.harvard.i2b2.crcxmljaxb.datavo.i2b2message.ObjectFactory of =
          new edu.harvard.i2b2.crcxmljaxb.datavo.i2b2message.ObjectFactory();
      jaxbUtil.marshaller(of.createRequest(requestMessageType), strWriter);
    } catch (Exception e) {
      e.printStackTrace();
    }

    System.out.println("Generated content XML request: " + strWriter.toString());
    return strWriter.toString();
  }
  public I2B2RequestMessageHelper(String requestXml) throws I2B2Exception {
    this.requestXml = requestXml;
    unWrapHelper = new JAXBUnWrapHelper();
    try {
      jaxbElement = jaxbUtil.unMashallFromString(requestXml);

      if (jaxbElement == null) {
        throw new I2B2Exception("null value in after unmarshalling request string ");
      }
      requestMessageType = (RequestMessageType) jaxbElement.getValue();
    } catch (JAXBUtilException jaxbUtilEx) {
      log.error("Error processing request xml [" + requestXml + "]", jaxbUtilEx);
      throw new I2B2Exception(jaxbUtilEx.getMessage());
    }
  }
  /** @see edu.harvard.i2b2.crc.delegate.RequestHandlerDelegate#handleRequest(java.lang.String) */
  public String handleRequest(String requestXml, RequestHandler requestHandler)
      throws I2B2Exception {
    String response = null;
    JAXBUtil jaxbUtil = CRCLoaderJAXBUtil.getJAXBUtil();

    try {
      JAXBElement jaxbElement = jaxbUtil.unMashallFromString(requestXml);
      RequestMessageType requestMessageType = (RequestMessageType) jaxbElement.getValue();
      BodyType bodyType = requestMessageType.getMessageBody();

      if (bodyType == null) {
        log.error("null value in body type");
        throw new I2B2Exception("null value in body type");
      }

      // Call PM cell to validate user
      StatusType procStatus = null;
      ProjectType projectType = null;
      String projectId = null;
      SecurityType securityType = null;
      try {

        if (requestMessageType.getMessageHeader() != null) {
          if (requestMessageType.getMessageHeader().getSecurity() != null) {
            securityType = requestMessageType.getMessageHeader().getSecurity();
          }
          projectId = requestMessageType.getMessageHeader().getProjectId();
        }
        if (securityType == null) {
          procStatus = new StatusType();
          procStatus.setType("ERROR");
          procStatus.setValue("Request message missing user/password");
          response =
              I2B2MessageResponseFactory.buildResponseMessage(requestXml, procStatus, bodyType);
          return response;
        }

        PMServiceDriver pmServiceDriver = new PMServiceDriver();
        projectType = pmServiceDriver.checkValidUser(securityType, projectId);
        if (projectType == null) {
          procStatus = new StatusType();
          procStatus.setType("ERROR");
          procStatus.setValue("Invalid user/password for the given domain");
          response =
              I2B2MessageResponseFactory.buildResponseMessage(requestXml, procStatus, bodyType);
          return response;
        }

        log.debug("project name from PM " + projectType.getName());
        log.debug("project id from PM " + projectType.getId());
        if (projectType.getRole().get(0) != null) {
          log.debug("Project role from PM " + projectType.getRole().get(0));
          this.putRoles(
              projectId,
              securityType.getUsername(),
              securityType.getDomain(),
              projectType.getRole());

          Node rootNode = CacheUtil.getCache().getRoot();
          List<String> roles =
              (List<String>)
                  rootNode.get(
                      securityType.getDomain()
                          + "/"
                          + projectId
                          + "/"
                          + securityType.getUsername());
          if (roles != null) {
            System.out.println("roles size !!1 " + roles.size());
          }

        } else {
          log.warn("project role not set for user [" + securityType.getUsername() + "]");
        }

      } catch (AxisFault e) {
        procStatus = new StatusType();
        procStatus.setType("ERROR");
        procStatus.setValue("Could not connect to server");
        response =
            I2B2MessageResponseFactory.buildResponseMessage(requestXml, procStatus, bodyType);
        return response;
      } catch (I2B2Exception e) {
        procStatus = new StatusType();
        procStatus.setType("ERROR");
        procStatus.setValue("Message error connecting Project Management cell");
        response =
            I2B2MessageResponseFactory.buildResponseMessage(requestXml, procStatus, bodyType);
        return response;
      } catch (JAXBUtilException e) {
        procStatus = new StatusType();
        procStatus.setType("ERROR");
        procStatus.setValue("Message error from Project Management cell");
        response =
            I2B2MessageResponseFactory.buildResponseMessage(requestXml, procStatus, bodyType);
        return response;
      }

      JAXBUnWrapHelper unWrapHelper = new JAXBUnWrapHelper();

      BodyType responseBodyType = null;
      if (requestHandler instanceof PublishDataRequestHandler) {

        String irodsStorageResource = null;
        for (ParamType paramType : projectType.getParam()) {

          if (paramType.getName().equalsIgnoreCase("SRBDefaultStorageResource")) {
            irodsStorageResource = paramType.getValue();
            log.debug("param value for SRBDefaultStorageResource" + paramType.getValue());
          }
        }
        ((PublishDataRequestHandler) requestHandler)
            .setIrodsDefaultStorageResource(irodsStorageResource);
      }

      responseBodyType = requestHandler.execute();

      procStatus = new StatusType();
      procStatus.setType("DONE");
      procStatus.setValue("DONE");

      response =
          I2B2MessageResponseFactory.buildResponseMessage(
              requestXml, procStatus, responseBodyType, true);

    } catch (JAXBUtilException e) {
      log.error("JAXBUtil exception", e);
      StatusType procStatus = new StatusType();
      procStatus.setType("ERROR");
      procStatus.setValue(requestXml + "\n\n" + StackTraceUtil.getStackTrace(e));
      try {
        response = I2B2MessageResponseFactory.buildResponseMessage(null, procStatus, null);
      } catch (JAXBUtilException e1) {
        e1.printStackTrace();
      }
    } catch (I2B2Exception e) {
      log.error("I2B2Exception", e);
      StatusType procStatus = new StatusType();
      procStatus.setType("ERROR");
      procStatus.setValue(StackTraceUtil.getStackTrace(e));
      try {
        response = I2B2MessageResponseFactory.buildResponseMessage(requestXml, procStatus, null);
      } catch (JAXBUtilException e1) {
        e1.printStackTrace();
      }
    } catch (Throwable e) {
      log.error("Throwable", e);
      StatusType procStatus = new StatusType();
      procStatus.setType("ERROR");
      procStatus.setValue(StackTraceUtil.getStackTrace(e));
      try {
        response = I2B2MessageResponseFactory.buildResponseMessage(requestXml, procStatus, null);
      } catch (JAXBUtilException e1) {
        e1.printStackTrace();
      }
    }
    return response;
  }
  /**
   * Function accepts parameter in Map. The patient count will be obfuscated if the user is OBFUS
   */
  public void generateResult(Map param) throws CRCTimeOutException, I2B2DAOException {

    SetFinderConnection sfConn = (SetFinderConnection) param.get("SetFinderConnection");
    SetFinderDAOFactory sfDAOFactory = (SetFinderDAOFactory) param.get("SetFinderDAOFactory");

    // String patientSetId = (String)param.get("PatientSetId");
    String queryInstanceId = (String) param.get("QueryInstanceId");
    String TEMP_DX_TABLE = (String) param.get("TEMP_DX_TABLE");
    String resultInstanceId = (String) param.get("ResultInstanceId");
    // String itemKey = (String) param.get("ItemKey");
    String resultTypeName = (String) param.get("ResultOptionName");
    String processTimingFlag = (String) param.get("ProcessTimingFlag");
    int obfuscatedRecordCount = (Integer) param.get("ObfuscatedRecordCount");
    int transactionTimeout = (Integer) param.get("TransactionTimeout");
    TransactionManager tm = (TransactionManager) param.get("TransactionManager");
    this.setDbSchemaName(sfDAOFactory.getDataSourceLookup().getFullSchema());
    Map ontologyKeyMap = (Map) param.get("setFinderResultOntologyKeyMap");
    String serverType = (String) param.get("ServerType");
    CallOntologyUtil ontologyUtil = (CallOntologyUtil) param.get("CallOntologyUtil");
    List<String> roles = (List<String>) param.get("Roles");
    String tempTableName = "";
    PreparedStatement stmt = null;
    boolean errorFlag = false, timeoutFlag = false;
    String itemKey = "";

    int actualTotal = 0, obsfcTotal = 0;
    boolean obfscDataRoleFlag = false;
    try {
      LogTimingUtil logTimingUtil = new LogTimingUtil();
      logTimingUtil.setStartTime();
      obfscDataRoleFlag = checkDataObscRole(sfDAOFactory.getOriginalDataSourceLookup(), roles);
      itemKey = getItemKeyFromResultType(sfDAOFactory, resultTypeName);

      log.debug("Result type's " + resultTypeName + " item key value " + itemKey);

      LogTimingUtil subLogTimingUtil = new LogTimingUtil();
      subLogTimingUtil.setStartTime();
      ConceptsType conceptsType = ontologyUtil.callGetChildren(itemKey);
      if (conceptsType != null && conceptsType.getConcept().size() < 1) {
        throw new I2B2DAOException(
            "Could not fetch children result type "
                + resultTypeName
                + " item key [ "
                + itemKey
                + " ]");
      }
      subLogTimingUtil.setEndTime();
      if (processTimingFlag != null) {
        if (processTimingFlag.trim().equalsIgnoreCase(ProcessTimingReportUtil.DEBUG)) {
          ProcessTimingReportUtil ptrUtil =
              new ProcessTimingReportUtil(sfDAOFactory.getDataSourceLookup());
          ptrUtil.logProcessTimingMessage(
              queryInstanceId,
              ptrUtil.buildProcessTiming(
                  subLogTimingUtil,
                  "BUILD - " + resultTypeName + " : Ontology Call(GetChildren) ",
                  ""));
        }
      }

      String itemCountSql =
          " select count(distinct PATIENT_NUM) as item_count  from "
              + this.getDbSchemaName()
              + "observation_fact obs_fact  "
              + " where obs_fact.patient_num in (select patient_num from "
              + TEMP_DX_TABLE
              + "    ) "
              + " and obs_fact.concept_cd in (select concept_cd from "
              + this.getDbSchemaName()
              + "concept_dimension  where concept_path like ?)";

      ResultType resultType = new ResultType();
      resultType.setName(resultTypeName);
      stmt = sfConn.prepareStatement(itemCountSql);

      CancelStatementRunner csr = new CancelStatementRunner(stmt, transactionTimeout);
      Thread csrThread = new Thread(csr);
      csrThread.start();

      for (ConceptType conceptType : conceptsType.getConcept()) {

        String dimCode = this.getDimCodeInSqlFormat(conceptType);

        itemCountSql =
            " select count(distinct PATIENT_NUM) as item_count  from "
                + this.getDbSchemaName()
                + " observation_fact "
                + " where "
                + " patient_num in (select patient_num from "
                + TEMP_DX_TABLE
                + " )  and "
                + conceptType.getFacttablecolumn()
                + " IN (select "
                + conceptType.getFacttablecolumn()
                + " from "
                + getDbSchemaName()
                + conceptType.getTablename()
                + "  "
                + " where "
                + conceptType.getColumnname()
                + " "
                + conceptType.getOperator()
                + " "
                + dimCode
                + ")";

        stmt = sfConn.prepareStatement(itemCountSql);

        // // smuniraju: Currently, in postgres, a timeout value > 0 will result in "setQueryTimeout
        // is not yet implemented"
        // stmt.setQueryTimeout(transactionTimeout);
        int queryTimeout =
            (serverType.equalsIgnoreCase(DAOFactoryHelper.POSTGRES)) ? 0 : transactionTimeout;
        stmt.setQueryTimeout(queryTimeout);

        log.debug("Executing count sql [" + itemCountSql + "]");

        //
        subLogTimingUtil.setStartTime();
        ResultSet resultSet = stmt.executeQuery();
        if (csr.getSqlFinishedFlag()) {
          timeoutFlag = true;
          throw new CRCTimeOutException("The query was canceled.");
        }
        resultSet.next();
        int demoCount = resultSet.getInt("item_count");
        subLogTimingUtil.setEndTime();
        if (processTimingFlag != null) {
          if (processTimingFlag.trim().equalsIgnoreCase(ProcessTimingReportUtil.DEBUG)) {
            ProcessTimingReportUtil ptrUtil =
                new ProcessTimingReportUtil(sfDAOFactory.getDataSourceLookup());
            ptrUtil.logProcessTimingMessage(
                queryInstanceId,
                ptrUtil.buildProcessTiming(
                    subLogTimingUtil,
                    "BUILD - "
                        + resultTypeName
                        + " : COUNT SQL for "
                        + conceptType.getDimcode()
                        + " ",
                    "sql=" + itemCountSql));
          }
        }
        //

        actualTotal += demoCount;
        if (obfscDataRoleFlag) {
          GaussianBoxMuller gaussianBoxMuller = new GaussianBoxMuller();
          demoCount = (int) gaussianBoxMuller.getNormalizedValueForCount(demoCount);
          obsfcTotal += demoCount;
        }
        DataType mdataType = new DataType();
        mdataType.setValue(String.valueOf(demoCount));
        mdataType.setColumn(conceptType.getName());
        mdataType.setType("int");
        resultType.getData().add(mdataType);
      }
      csr.setSqlFinishedFlag();
      csrThread.interrupt();
      stmt.close();

      edu.harvard.i2b2.crc.datavo.i2b2result.ObjectFactory of =
          new edu.harvard.i2b2.crc.datavo.i2b2result.ObjectFactory();
      BodyType bodyType = new BodyType();
      bodyType.getAny().add(of.createResult(resultType));
      ResultEnvelopeType resultEnvelop = new ResultEnvelopeType();
      resultEnvelop.setBody(bodyType);

      JAXBUtil jaxbUtil = CRCJAXBUtil.getJAXBUtil();

      StringWriter strWriter = new StringWriter();
      subLogTimingUtil.setStartTime();
      jaxbUtil.marshaller(of.createI2B2ResultEnvelope(resultEnvelop), strWriter);
      subLogTimingUtil.setEndTime();
      tm.begin();
      IXmlResultDao xmlResultDao = sfDAOFactory.getXmlResultDao();
      xmlResultDao.createQueryXmlResult(resultInstanceId, strWriter.toString());
      //
      if (processTimingFlag != null) {
        if (!processTimingFlag.trim().equalsIgnoreCase(ProcessTimingReportUtil.NONE)) {
          ProcessTimingReportUtil ptrUtil =
              new ProcessTimingReportUtil(sfDAOFactory.getDataSourceLookup());
          if (processTimingFlag.trim().equalsIgnoreCase(ProcessTimingReportUtil.DEBUG)) {
            ptrUtil.logProcessTimingMessage(
                queryInstanceId,
                ptrUtil.buildProcessTiming(subLogTimingUtil, "JAXB - " + resultTypeName, ""));
          }
          logTimingUtil.setEndTime();
          ptrUtil.logProcessTimingMessage(
              queryInstanceId,
              ptrUtil.buildProcessTiming(logTimingUtil, "BUILD - " + resultTypeName, ""));
        }
      }
      tm.commit();
    } catch (com.microsoft.sqlserver.jdbc.SQLServerException sqlServerEx) {
      // if the setQueryTimeout worked, then the message would be timed
      // out
      if (sqlServerEx.getMessage().indexOf("timed out") > -1) {
        timeoutFlag = true;
        throw new CRCTimeOutException(sqlServerEx.getMessage(), sqlServerEx);
      } else if (sqlServerEx
              .getMessage()
              .indexOf( // if the stmt.cancel()
                  // worked, then this
                  // exception is
                  // thrown
                  "The query was canceled.")
          > -1) {

        timeoutFlag = true;
        throw new CRCTimeOutException(sqlServerEx.getMessage(), sqlServerEx);
      } else {

        errorFlag = true;
        log.error("Sqlserver error while executing sql", sqlServerEx);
        throw new I2B2DAOException("Sqlserver error while executing sql", sqlServerEx);
      }

    } catch (SQLException sqlEx) {
      // catch oracle query timeout error ORA-01013
      if (sqlEx.toString().indexOf("ORA-01013") > -1) {
        timeoutFlag = true;
        throw new CRCTimeOutException(sqlEx.getMessage(), sqlEx);
      }
      if (sqlEx.getMessage().indexOf("The query was canceled.") > -1) {
        timeoutFlag = true;
        throw new CRCTimeOutException(sqlEx.getMessage(), sqlEx);
      }
      errorFlag = true;
      log.error("Error while executing sql", sqlEx);
      throw new I2B2DAOException("Error while executing sql", sqlEx);
    } catch (Exception sqlEx) {

      errorFlag = true;
      log.error("QueryResultPatientSetGenerator.generateResult:" + sqlEx.getMessage(), sqlEx);
      throw new I2B2DAOException(
          "QueryResultPatientSetGenerator.generateResult:" + sqlEx.getMessage(), sqlEx);
    } finally {

      IQueryResultInstanceDao resultInstanceDao = sfDAOFactory.getPatientSetResultDAO();

      if (errorFlag) {
        resultInstanceDao.updatePatientSet(
            resultInstanceId, QueryStatusTypeId.STATUSTYPE_ID_ERROR, 0);
      } else {
        // set the setsize and the description of the result instance if
        // the user role is obfuscated
        if (timeoutFlag == false) { // check if the query completed
          try {
            tm.begin();

            String obfusMethod = "", description = null;
            if (obfscDataRoleFlag) {
              obfusMethod = IQueryResultInstanceDao.OBSUBTOTAL;
              // add () to the result type description
              // read the description from result type

            } else {
              obfuscatedRecordCount = actualTotal;
            }
            IQueryResultTypeDao resultTypeDao = sfDAOFactory.getQueryResultTypeDao();
            List<QtQueryResultType> resultTypeList =
                resultTypeDao.getQueryResultTypeByName(resultTypeName);

            // add "(Obfuscated)" in the description
            // description = resultTypeList.get(0)
            //		.getDescription()
            //		+ " (Obfuscated) ";
            String queryName =
                sfDAOFactory
                    .getQueryMasterDAO()
                    .getQueryDefinition(
                        sfDAOFactory
                            .getQueryInstanceDAO()
                            .getQueryInstanceByInstanceId(queryInstanceId)
                            .getQtQueryMaster()
                            .getQueryMasterId())
                    .getName();

            resultInstanceDao.updatePatientSet(
                resultInstanceId,
                QueryStatusTypeId.STATUSTYPE_ID_FINISHED,
                null,
                // obsfcTotal,
                obfuscatedRecordCount,
                actualTotal,
                obfusMethod);

            description = resultTypeList.get(0).getDescription() + " for \"" + queryName + "\"";

            // set the result instance description
            resultInstanceDao.updateResultInstanceDescription(resultInstanceId, description);
            tm.commit();
          } catch (NotSupportedException e) {
            throw new I2B2DAOException(
                "Failed to write obfuscated description " + e.getMessage(), e);
          } catch (SystemException e) {
            throw new I2B2DAOException(
                "Failed to write obfuscated description " + e.getMessage(), e);
          } catch (SecurityException e) {
            throw new I2B2DAOException(
                "Failed to write obfuscated description " + e.getMessage(), e);
          } catch (IllegalStateException e) {
            throw new I2B2DAOException(
                "Failed to write obfuscated description " + e.getMessage(), e);
          } catch (RollbackException e) {
            throw new I2B2DAOException(
                "Failed to write obfuscated description " + e.getMessage(), e);
          } catch (HeuristicMixedException e) {
            throw new I2B2DAOException(
                "Failed to write obfuscated description " + e.getMessage(), e);
          } catch (HeuristicRollbackException e) {
            throw new I2B2DAOException(
                "Failed to write obfuscated description " + e.getMessage(), e);
          }
        }
      }
    }
  }
예제 #8
0
  @SuppressWarnings("unchecked")
  public void redrawPanelFromXml(String xmlstr) {
    try {
      JAXBUtil jaxbUtil = PreviousQueryJAXBUtil.getJAXBUtil();
      JAXBElement jaxbElement = jaxbUtil.unMashallFromString(xmlstr);
      ResponseMessageType messageType = (ResponseMessageType) jaxbElement.getValue();
      BodyType bt = messageType.getMessageBody();
      MasterResponseType masterResponseType =
          (MasterResponseType)
              new JAXBUnWrapHelper().getObjectByClass(bt.getAny(), MasterResponseType.class);
      RequestXmlType requestXmlType = masterResponseType.getQueryMaster().get(0).getRequestXml();
      String strRequest = (String) requestXmlType.getContent().get(0);

      jaxbElement = jaxbUtil.unMashallFromString(strRequest);
      RequestMessageType requestMessageType = (RequestMessageType) jaxbElement.getValue();
      bt = requestMessageType.getMessageBody();
      QueryDefinitionRequestType queryDefinitionRequestType =
          (QueryDefinitionRequestType)
              new JAXBUnWrapHelper()
                  .getObjectByClass(bt.getAny(), QueryDefinitionRequestType.class);
      QueryDefinitionType queryDefinitionType = queryDefinitionRequestType.getQueryDefinition();

      int numOfPanels = queryDefinitionType.getPanel().size();
      if (numOfPanels > 3) {
        for (int i = 0; i < (numOfPanels - 3); i++) {
          topPanel.addPanel();
        }
      }

      for (int i = 0; i < numOfPanels; i++) {
        PanelType panelType = queryDefinitionType.getPanel().get(i);
        final ConceptTreePanel panel = getTreePanel(i);
        ConceptTreeData panelData = new ConceptTreeData();
        panelData.setOccurrenceTimes(panelType.getTotalItemOccurrences().getValue());
        if (panelType.getInvert() == 0) {
          panelData.exclude(false);
        } else if (panelType.getInvert() == 1) {
          panelData.exclude(true);
        }

        for (int j = 0; j < panelType.getItem().size(); j++) {
          ItemType itemType = panelType.getItem().get(j);
          QueryConceptTreeNodeData nodedata = new QueryConceptTreeNodeData();

          nodedata.name(itemType.getItemName());
          nodedata.visualAttribute("FA");
          nodedata.tooltip(itemType.getTooltip());
          nodedata.fullname(itemType.getItemKey());
          // mm removed
          // nodedata.lookuptable(itemType.getItemTable());
          nodedata.hlevel(new Integer(itemType.getHlevel()).toString());
          nodedata.lookupdb("metadata");
          // nodedata.selectservice(System.getProperty("selectservice")
          // );
          // get the xml content from select service then set it as
          // node data
          nodedata.setXmlContent();

          panelData.getItems().add(nodedata);
        }

        final ConceptTreeData fpanelData = panelData;
        final String name = queryDefinitionType.getQueryName();
        java.awt.EventQueue.invokeLater(
            new Runnable() {
              public void run() {
                topPanel.setQueryName(name);
                panel.redraw(fpanelData);
              }
            });
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
예제 #9
0
  public String wirteQueryXML() {
    DTOFactory dtoFactory = new DTOFactory();
    // TimeZone pdt = TimeZone.getTimeZone("EST");
    // DatatypeFactory dataTypeFactory = null;
    // try {
    // dataTypeFactory = DatatypeFactory.newInstance();
    // XMLGregorianCalendar xmlCalendar =
    // dataTypeFactory.newXMLGregorianCalendarDate(2006, 9, 21, -5*60);
    // TimeZone pdt = xmlCalendar.getgetTimezone();
    // }
    // catch (DatatypeConfigurationException e) {
    // e.printStackTrace();
    // }

    // RequestType requestType = new RequestType();
    // requestType.setSpecificityScale(specificity());
    QueryDefinitionType queryDefinitionType = new QueryDefinitionType();
    QueryDefinitionRequestType queryDefinitionRequestType = new QueryDefinitionRequestType();
    for (int i = 0; i < panelCount; i++) {
      ConceptTreePanel panel = getTreePanel(i);
      ArrayList<QueryConceptTreeNodeData> nodelist = panel.data().getItems();
      if ((nodelist != null) && (nodelist.size() > 0)) {
        System.out.println(
            "Panel: "
                + panel.getGroupName()
                + " Excluded: "
                + ((panel.data().exclude()) ? "yes" : "no"));
        PanelType panelType = new PanelType();
        panelType.setInvert((panel.data().exclude()) ? 1 : 0);
        PanelType.TotalItemOccurrences totalItemOccurrences = new PanelType.TotalItemOccurrences();
        totalItemOccurrences.setValue(panel.getOccurrenceTimes());

        panelType.setTotalItemOccurrences(totalItemOccurrences);
        panelType.setPanelNumber(i + 1);

        // if(panel.data().startTime() != -1) {
        // panelType.setPanelDateFrom(//dataTypeFactory.
        // newXMLGregorianCalendarDate(
        // dtoFactory.getXMLGregorianCalendarDate(panel.data().startYear(
        // ),
        // panel.data().startMonth(), panel.data().startDay()));
        // }

        // if(panel.data().endTime() != -1) {
        // panelType.setPanelDateTo(//dataTypeFactory.
        // newXMLGregorianCalendarDate(
        // dtoFactory.getXMLGregorianCalendarDate(panel.data().endYear(),
        // panel.data().endMonth(), panel.data().endDay()));
        // }

        for (int j = 0; j < nodelist.size(); j++) {
          QueryConceptTreeNodeData node = nodelist.get(j);
          System.out.println("\tItem: " + node.fullname());

          // create item
          ItemType itemType = new ItemType();
          // itemType.setConstrainByDate(.setDateFrom(dtoFactory.
          // getXMLGregorianCalendarDate(2006,
          // 10, 4)));
          itemType.setItemKey(node.fullname());
          itemType.setItemName(node.name());
          // mm removed
          // itemType.setItemTable(node.lookuptable());
          itemType.setTooltip(node.tooltip());
          itemType.setHlevel(Integer.parseInt(node.hlevel()));
          itemType.setClazz("ENC");
          ConstrainByDate cDate = new ConstrainByDate();
          ConstrainDateType constrinDataType = new ConstrainDateType();
          constrinDataType.setValue(
              dtoFactory.getXMLGregorianCalendarDate(
                  node.startYear(), node.startMonth(), node.startDay()));
          if (node.startTime() != -1) {
            cDate.setDateFrom(constrinDataType);
          }
          if (node.endTime() != -1) {
            cDate.setDateTo(constrinDataType);
          }
          itemType.getConstrainByDate().add(cDate);
          panelType.getItem().add(itemType);
        }
        queryDefinitionType.getPanel().add(panelType);
      }
    }

    // create infotype
    InfoType infoType = new InfoType();
    infoType.setValue("INFO");
    infoType.setUrl("http://www.ibm.com");

    // create header
    PsmQryHeaderType headerType = new PsmQryHeaderType();
    UserType userType = new UserType();
    userType.setLogin(UserInfoBean.getInstance().getUserName());
    userType.setValue(UserInfoBean.getInstance().getUserName());
    headerType.setUser(userType);
    headerType.setRequestType(PsmRequestTypeType.CRC_QRY_RUN_QUERY_INSTANCE_FROM_QUERY_DEFINITION);
    if (queryName == null) {
      queryName =
          getTreePanel(0).data().getItems().get(0).name()
              + "_"
              + generateMessageId().substring(0, 4);
    }

    queryDefinitionType.setQueryName(queryName);
    queryDefinitionRequestType.setQueryDefinition(queryDefinitionType);

    RequestHeaderType requestHeader = new RequestHeaderType();
    requestHeader.setResultWaittimeMs(180000);

    BodyType bodyType = new BodyType();
    edu.harvard.i2b2.crcxmljaxb.datavo.psm.query.ObjectFactory psmOf =
        new edu.harvard.i2b2.crcxmljaxb.datavo.psm.query.ObjectFactory();
    bodyType.getAny().add(psmOf.createPsmheader(headerType));
    bodyType.getAny().add(psmOf.createRequest(queryDefinitionRequestType));
    // new QueryToolDTOFactory().buildBodyType(headerType,
    // queryDefinitionRequestType, null);
    MessageHeaderType messageHeader = getMessageHeader();
    RequestMessageType requestMessageType = new RequestMessageType();
    requestMessageType.setMessageBody(bodyType);
    requestMessageType.setMessageHeader(messageHeader);
    requestMessageType.setRequestHeader(requestHeader);
    // dtoFactory.getRequestMessageType(messageHeader, requestHeader,
    // bodyType);

    JAXBUtil jaxbUtil = PreviousQueryJAXBUtil.getJAXBUtil();
    StringWriter strWriter = new StringWriter();
    try {
      edu.harvard.i2b2.crcxmljaxb.datavo.i2b2message.ObjectFactory of =
          new edu.harvard.i2b2.crcxmljaxb.datavo.i2b2message.ObjectFactory();
      jaxbUtil.marshaller(of.createRequest(requestMessageType), strWriter);
    } catch (Exception e) {
      e.printStackTrace();
    }

    return strWriter.toString();
  }
 public static AnalysisDefinitionType getAnalysisDefinitionFromXml(String defXml)
     throws JAXBUtilException {
   JAXBUtil jaxbUtil = CRCJAXBUtil.getJAXBUtil();
   JAXBElement analysisDef = jaxbUtil.unMashallFromString(defXml);
   return (AnalysisDefinitionType) analysisDef.getValue();
 }