Ejemplo n.º 1
0
  @Test
  public void setReplicationConfig() throws Exception {

    ReplicationConfiguration r = new ReplicationConfiguration();
    Operator op = new Operator();
    op.setOperatorNodeID("test_node");
    op.setSoapReplicationURL("http://localhost");
    op.setOperatorStatus(OperatorStatusType.NORMAL);

    r.getOperator().add(op);
    r.setCommunicationGraph(new CommunicationGraph());
    r.setRegistryContact(new ReplicationConfiguration.RegistryContact());
    r.getRegistryContact().setContact(new Contact());
    r.getRegistryContact().getContact().getPersonName().add(new PersonName("test", null));
    //  r.getCommunicationGraph().getEdge().add(new CommunicationGraph.Edge());
    r.getCommunicationGraph().getNode().add("test_node");

    JAXB.marshal(r, System.out);
    DispositionReport setReplicationNodes = juddi.setReplicationNodes(authInfoRoot, r);

    ReplicationConfiguration replicationNodes = juddi.getReplicationNodes(authInfoRoot);
    Assert.assertNotNull(replicationNodes.getCommunicationGraph());
    Assert.assertNotNull(replicationNodes.getCommunicationGraph().getNode());
    Assert.assertEquals("test_node", replicationNodes.getCommunicationGraph().getNode().get(0));
    Assert.assertNotNull(replicationNodes.getMaximumTimeToGetChanges());
    Assert.assertNotNull(replicationNodes.getMaximumTimeToSyncRegistry());
    Assert.assertNotNull(replicationNodes.getTimeOfConfigurationUpdate());
    Assert.assertNotNull(replicationNodes.getSerialNumber());
    long firstcommit = replicationNodes.getSerialNumber();

    r = new ReplicationConfiguration();
    r.getOperator().add(op);
    r.setCommunicationGraph(new CommunicationGraph());
    r.setRegistryContact(new ReplicationConfiguration.RegistryContact());
    r.getRegistryContact().setContact(new Contact());
    r.getRegistryContact().getContact().getPersonName().add(new PersonName("test", null));
    //  r.getCommunicationGraph().getEdge().add(new CommunicationGraph.Edge());
    r.getCommunicationGraph().getNode().add("test_node");

    JAXB.marshal(r, System.out);
    setReplicationNodes = juddi.setReplicationNodes(authInfoRoot, r);

    replicationNodes = juddi.getReplicationNodes(authInfoRoot);
    Assert.assertNotNull(replicationNodes.getCommunicationGraph());
    Assert.assertNotNull(replicationNodes.getCommunicationGraph().getNode());
    Assert.assertEquals("test_node", replicationNodes.getCommunicationGraph().getNode().get(0));
    Assert.assertNotNull(replicationNodes.getMaximumTimeToGetChanges());
    Assert.assertNotNull(replicationNodes.getMaximumTimeToSyncRegistry());
    Assert.assertNotNull(replicationNodes.getTimeOfConfigurationUpdate());
    Assert.assertNotNull(replicationNodes.getSerialNumber());
    Assert.assertTrue(firstcommit < replicationNodes.getSerialNumber());
  }
  private String marshal(Object o) {

    StringWriter w = new StringWriter();
    JAXB.marshal(o, w);
    w.flush();
    return w.getBuffer().toString();
  }
 private Exchange io(Exchange exchange) {
   StringWriter writer = new StringWriter();
   JAXB.marshal(exchange, writer);
   writer.flush();
   String xml = writer.toString();
   StringReader reader = new StringReader(xml);
   return JAXB.unmarshal(reader, Exchange.class);
 }
Ejemplo n.º 4
0
  private <T extends Event> T convertConfig(Event theInitialConfig, Class<T> theDesiredClass) {
    if (theInitialConfig.getClass().equals(theDesiredClass)) {
      return (T) theInitialConfig;
    }

    StringWriter stringWriter = new StringWriter();
    JAXB.marshal(theInitialConfig, stringWriter);

    return JAXB.unmarshal(new StringReader(stringWriter.toString()), theDesiredClass);
  }
Ejemplo n.º 5
0
  @Test
  public void testGetFlightsXml()
      throws AirlineException, DatatypeConfigurationException, TransformerException {
    GetFlightsRequest request = JAXB.unmarshal(getStream("request1.xml"), GetFlightsRequest.class);

    GetFlightsResponse response = endpoint.getFlights(request);

    DOMResult domResponse = new DOMResult();
    JAXB.marshal(response, domResponse);

    XMLUnit.setIgnoreWhitespace(true);
    XMLAssert.assertXMLEqual(getDocument("response1.xml"), (Document) domResponse.getNode());
  }
Ejemplo n.º 6
0
  @Override
  public void execute() throws MojoExecutionException {
    try {
      Configuration configuration = new Configuration();
      configuration.setJdbc(jdbc);
      configuration.setGenerator(generator);

      StringWriter writer = new StringWriter();
      JAXB.marshal(configuration, writer);

      getLog().info("Using this configuration:\n" + writer.toString());
      GenerationTool.main(configuration);
    } catch (Exception ex) {
      throw new MojoExecutionException("Error running jOOQ code generation tool", ex);
    }
    project.addCompileSourceRoot(generator.getTarget().getDirectory());
  }
Ejemplo n.º 7
0
 private void flush(File file, Users users) {
   BufferedOutputStream bos = null;
   try {
     bos = new BufferedOutputStream(new FileOutputStream(file));
     JAXB.marshal(users, bos);
     lastFlushDate = new Date();
   } catch (FileNotFoundException ex) {
     Logger.getLogger(OfflineServerImpl.class.getName()).log(Level.SEVERE, null, ex);
   } finally {
     if (bos != null) {
       try {
         bos.close();
       } catch (IOException ex) {
         Logger.getLogger(OfflineServerImpl.class.getName()).log(Level.SEVERE, null, ex);
       }
     }
   }
 }
Ejemplo n.º 8
0
  public void build(File output, File template, DocumentModel model) throws IOException {
    File temporal;

    temporal = File.createTempFile(this.getClass().getName() + '.', ".xml");
    try {
      int result;

      JAXB.marshal(model, temporal);
      result =
          this.launch(
              "-build",
              template.getAbsolutePath(),
              output.getAbsolutePath(),
              temporal.getAbsolutePath());
      if (result != 0)
        throw new IOException(
            String.format("failed on build document" + " (process exit with %d)", result));
    } finally {
      temporal.delete();
    }
  }
  @Override
  public void save() {
    List<WrappedVertex> vertices = new ArrayList<WrappedVertex>();
    for (Vertex vertex : getVertices()) {
      if (vertex.isGroup()) {
        vertices.add(new WrappedGroup(vertex));
      } else {
        vertices.add(new WrappedLeafVertex(vertex));
      }
    }
    List<WrappedEdge> edges = new ArrayList<WrappedEdge>();
    for (Edge edge : getEdges()) {
      WrappedEdge newEdge =
          new WrappedEdge(
              edge,
              new WrappedLeafVertex(m_vertexProvider.getVertex(edge.getSource().getVertex())),
              new WrappedLeafVertex(m_vertexProvider.getVertex(edge.getTarget().getVertex())));
      edges.add(newEdge);
    }

    WrappedGraph graph = new WrappedGraph(getEdgeNamespace(), vertices, edges);

    JAXB.marshal(graph, new File(getConfigurationFile()));
  }
Ejemplo n.º 10
0
 public static String marshal(Object anyObject) {
   StringWriter stringWriter = new StringWriter();
   JAXB.marshal(anyObject, stringWriter);
   return stringWriter.getBuffer().toString();
 }
Ejemplo n.º 11
0
 @Override
 void marshal(Object output, File outputFile) {
   javax.xml.bind.JAXB.marshal(castJaxbObject(output), outputFile);
 }
 @Override
 public String exportConfigToXml() {
   StringWriter writer = new StringWriter();
   JAXB.marshal(this, writer);
   return writer.toString();
 }
Ejemplo n.º 13
0
 /**
  * Serializes the {@link Wiseml} instance.
  *
  * @param wiseML the {@link Wiseml} instance to serialize
  * @return the serialized WiseML document
  */
 @SuppressWarnings("unused")
 public static String serialize(final Wiseml wiseML) {
   StringWriter writer = new StringWriter();
   JAXB.marshal(wiseML, writer);
   return writer.toString();
 }
    private Message doProcess(Message theArg0) throws HL7Exception, ApplicationException {
      String encodedMessage = theArg0.encode();

      Terser terser = new Terser(theArg0);
      String msgType = terser.get("/MSH-9-1");
      String msgTrigger = terser.get("/MSH-9-2");
      MSH msh = (MSH) theArg0.get("MSH");

      ourLog.info("Message is of type " + msgType + "^" + msgTrigger);
      List<Failure> failures;

      try {
        String msgSourceOrg = terser.get("/MSH-3-1");
        String sourceOrg =
            myContributorConfig.getContributorConfig().getNameOfHspId9004(msgSourceOrg);
        ourLog.info("Sending organization from message is {} - {}", msgSourceOrg, sourceOrg);
      } catch (Exception e) {
        // ignore
      }

      Converter converter;
      try {
        converter = new Converter(true);
      } catch (JAXBException e2) {
        ourLog.error("Failed to convert message: Could not initialize converter", e2);
        throw new HL7Exception(e2);
      }

      String outcome = null;
      if ("ORU".equals(msgType) && "R01".equals(msgTrigger)) {
        final ORU_R01 oru = (ORU_R01) theArg0;
        final List<ClinicalDocumentGroup> documents = converter.convertClinicalDocument(oru);
        try {
          outcome =
              "ORU^R01 message evaluated (containing " + documents.size() + " documents/results)";
          //					outcome = Persister.persist(documents);
        } catch (final Exception e1) {
          throw new HL7Exception(e1);
        }
      } else if ("ADT".equals(msgType)) {
        ADT_A01 adt = new ADT_A01();
        adt.setParser(myParser);
        adt.parse(encodedMessage);
        PatientWithVisits pwv = converter.convertPatientWithVisits(adt);
        try {
          if (pwv != null) {
            outcome = "ADT^" + msgTrigger + " message evaluated";
            //						outcome = Persister.persist(pwv);
          } else {
            outcome = PROCESSING_FAILED_OUTCOME;
          }
        } catch (final Exception e1) {
          throw new HL7Exception(e1);
        }
      } else if ("RDE".equals(msgType) && "O11".equals(msgTrigger)) {
        RDE_O11 rde = new RDE_O11();
        rde.setParser(myParser);
        rde.parse(encodedMessage);
        List<MedicationOrder> medOrders = converter.convertMedicationOrder(rde);
        try {
          outcome =
              "RDE^O11 message evaluated (containing " + medOrders.size() + " medication orders)";
          //					outcome = Persister.persistMedicationOrders(medOrders);
        } catch (final Exception e1) {
          throw new HL7Exception(e1);
        }
      } else if ("RAS".equals(msgType) && "O17".equals(msgTrigger)) {
        RAS_O17 ras = new RAS_O17();
        ras.setParser(myParser);
        ras.parse(encodedMessage);
        List<MedicationOrderWithAdmins> medOrdersWithAdmins = converter.convertMedicationAdmin(ras);
        try {
          outcome =
              "RAS^O17 message evaluated (containing administration data for "
                  + medOrdersWithAdmins.size()
                  + " medication orders)";
          //					outcome = Persister.persistMedicationAdmins(medOrdersWithAdmins);
        } catch (final Exception e1) {
          throw new HL7Exception(e1);
        }
      } else {

        /*
         * Note: If adding processors for additional message types, make
         * sure to update the description for F098!!
         */

        converter.validateMsh(msh);
        converter.addFailure("/MSH-9", FailureCode.F098, msgType + "^" + msgTrigger);
        outcome = PROCESSING_FAILED_OUTCOME;
      }

      if (StringUtils.isBlank(outcome)) {
        outcome = PROCESSING_FAILED_OUTCOME;
      }

      // These are determined from the IDs in the message
      SendingSystem sendingSystem = converter.getSendingSystem();
      Contributor contributor = converter.getContributorConfig();

      //			if (contributor == null) {
      //				contributor = myContributor;
      //			} else if (contributor != myContributor) {
      //				converter.addFailure("MSH-3-1", FailureCode.F112,
      // msh.getMsh3_SendingApplication().getHd1_NamespaceID().getValue());
      //				contributor = myContributor;
      //			}

      if (sendingSystem == null) {
        throw new ApplicationException(
            "Failed to determine sender from message. Please check MSH-3 value");
      }

      //			if (sendingSystem == null ||
      // contributor.getSendingSystem9008WithOid(sendingSystem.getCode()) == null) {
      //				converter.addFailure("MSH-3-2", FailureCode.F113,
      // msh.getMsh3_SendingApplication().getHd2_UniversalID().getValue());
      //				sendingSystem = contributor.getSendingSystem().get(0);
      //				ourLog.info("Defaulting to first sending system {} because MSH-3-2 was {}",
      // sendingSystem.getDescription(),
      // msh.getMsh3_SendingApplication().getHd2_UniversalID().getValue());
      //			}

      ourLog.info(
          "Converted message from {} - {}", contributor.getName(), sendingSystem.getDescription());

      String orgId = sendingSystem.getManagementConsoleOrgId();
      if (StringUtils.isBlank(orgId)) {
        orgId = contributor.getManagementConsoleOrgId();
      }

      final CanonicalHl7V2Message canon =
          AbstractPojo.createNewCanonicalMessageHl7V2(
              encodedMessage,
              orgId,
              sendingSystem.getManagementConsoleSystemId(),
              Listener.INTERFACE_ID,
              MessagePhase.INCOMING,
              Listener.class,
              java.util.logging.Logger.getLogger(Listener.class.getName()));
      failures = converter.getFailures();
      if (failures.size() > 0) {

        String problemDescription = createHtmlProblemDescription(converter);

        if (problemDescription.length() > 0) {
          canon.setValidationOutcomeDescription(problemDescription);
        }

        ourLog.info("Message has {} failures", converter.getFailures().size());

      } else {

        ourLog.info("Message has no validation failures! Outstanding.");
        canon.setValidationOutcomeDescription("No issues");
      }

      if (outcome != null) {
        canon.setValidationOutcomeDescription(
            canon.getValidationOutcomeDescription() + "<br>Outcome: " + outcome);
      } else {
        canon.setValidationOutcomeDescription(canon.getValidationOutcomeDescription());
      }

      // Journal for the source
      ourLog.info("Journalling message");
      final JournalMessageRequest request = new JournalMessageRequest();
      request.setCanonicalHl7V2Message(canon);
      try {
        AbstractPojo.tryToJournalMessage(myJournalSvc, request);
      } catch (InvalidInputException e) {
        ourLog.error("Failed to send message to journal", e);
        throw new HL7Exception("Failed to process message");
      } catch (final sail.wsdl.infrastructure.journalling.UnexpectedErrorException e) {
        ourLog.error("Failed to send message to dead letter", e);
        throw new HL7Exception("Failed to process message");
      } catch (Exception e) {
        ourLog.error("Failed to journal message. Moving on", e);
        StringWriter w = new StringWriter();
        JAXB.marshal(request, w);
        ourLog.error("Request was: " + w.toString());
      }

      // // Journal again for the destination
      // canon.setDestination(new OutboundInterface());
      // canon.getDestination().setBoxId(canon.getSource().getBoxId());
      // canon.getDestination().setDomainId(canon.getSource().getDomainId());
      // canon.getDestination().setInterfaceDirection("O");
      // canon.getDestination().setOrgId("SIMS");
      // canon.getDestination().setSystemId("CGTA_Interim_CDR");
      // canon.getDestination().setInterfaceId("All");
      // canon.setCurrentMessagePhase(MessagePhase.OUTGOING);
      // try {
      // myJournalSvc.journalMessage(request);
      // } catch (final InvalidInputException e) {
      // ourLog.error("Failed to send message to journal", e);
      // } catch (final
      // sail.wsdl.infrastructure.journalling.UnexpectedErrorException e)
      // {
      // ourLog.error("Failed to send message to dead letter", e);
      // }

      try {
        ACK ack = (ACK) theArg0.generateACK();

        for (final Failure next : converter.getFailures()) {
          ERR err = ack.getERR(ack.getERRReps());
          err.getErr1_ErrorCodeAndLocation(0).getEld1_SegmentID().setValue(next.getTerserPath());
          err.getErr3_HL7ErrorCode().getCwe1_Identifier().setValue(next.getFailureCode().name());
          err.getErr6_ApplicationErrorParameter(0).setValue(next.getFieldVal());
          err.getErr7_DiagnosticInformation().setValue(next.getMessage());
        }

        return ack;
      } catch (final IOException e) {
        throw new HL7Exception(e);
      }
    }