/**
   * Verifies that when the receiving application throws an exception, the persistent message status
   * is set to {@link HL7MessageStatuses#ERROR}.
   *
   * @throws Exception for any error
   */
  @Test
  public void testExceptionInReceivingApplication() throws Exception {
    ReceivingApplication application =
        new ReceivingApplication() {
          @Override
          public Message processMessage(Message theMessage, Map<String, Object> theMetadata)
              throws ReceivingApplicationException, HL7Exception {
            assertEquals(1, acts.size());
            assertEquals(HL7MessageStatuses.PENDING, acts.get(0).getStatus());
            throw new RuntimeException("Simulated ReceivingApplication Exception");
          }

          @Override
          public boolean canProcess(Message theMessage) {
            return true;
          }
        };
    MessageReceiver receiver = new MessageReceiver(application, connector, service, user);
    Message message = createRDS(createProduct());
    assertTrue(receiver.canProcess(message));
    try {
      receiver.processMessage(message, new HashMap<String, Object>());
      fail("Expected ReceivingApplicationException");
    } catch (ReceivingApplicationException expected) {
      // do nothing
    }

    assertEquals(1, acts.size());
    DocumentAct act = get(acts.get(0)); // reload
    assertNotNull(act);
    assertEquals(HL7MessageStatuses.ERROR, act.getStatus());
    IMObjectBean bean = new IMObjectBean(act);
    assertEquals("Simulated ReceivingApplication Exception", bean.getString("error"));
  }
Пример #2
0
 /**
  * Loads the next document.
  *
  * @return {@code true} if the document was loaded successfully
  */
 public boolean loadNext() {
   boolean result = false;
   IMObjectReference ref = iterator.next();
   DocumentAct act = getDocumentAct(ref);
   if (act != null) {
     File file = new File(dir, act.getFileName());
     try {
       Document doc = createDocument(file);
       addDocument(act, doc);
       notifyLoaded(file, act.getId());
     } catch (Throwable exception) {
       notifyError(file, exception);
     }
     result = true;
   }
   return result;
 }
  /**
   * Apply the layout strategy.
   *
   * <p>This renders an object in a {@code Component}, using a factory to create the child
   * components.
   *
   * @param object the object to apply
   * @param properties the object's properties
   * @param parent the parent object. May be {@code null}
   * @param context the layout context
   * @return the component containing the rendered {@code object}
   */
  public ComponentState apply(
      IMObject object, PropertySet properties, IMObject parent, LayoutContext context) {
    Property property = properties.get("act");
    IMObjectReference ref = (IMObjectReference) property.getValue();
    final DocumentAct act = (DocumentAct) context.getCache().get(ref);
    Component component;
    if (act != null && act.getDocument() != null) {
      DocumentActDownloader downloader =
          new DocumentActDownloader(act, false, showDescription, context.getContext());

      // wrap in a row to left justify
      component = RowFactory.create(downloader.getComponent());
    } else {
      component = LabelFactory.create();
    }
    return new ComponentState(component);
  }