/**
  * Verifies that the editor returned by {@link IMObjectEditorFactory#create} matches that
  * expected.
  *
  * @param shortName name the archetype short name
  * @param parentShortName the parent archetype short name
  * @param type the expected editor class
  */
 private void checkCreate(String shortName, String parentShortName, Class type) {
   LayoutContext context =
       new DefaultLayoutContext(new LocalContext(), new HelpContext("foo", null));
   context.getContext().setPractice(TestHelper.getPractice());
   IMObject object = service.create(shortName);
   assertNotNull("Failed to create object with shortname=" + shortName, object);
   IMObject parent = service.create(parentShortName);
   assertNotNull("Failed to create object with shortname=" + parentShortName, parent);
   IMObjectEditor editor =
       ServiceHelper.getBean(IMObjectEditorFactory.class).create(object, parent, context);
   assertNotNull("Failed to create editor", editor);
   assertEquals(type, editor.getClass());
 }
Ejemplo n.º 2
0
 /**
  * Resolve a reference.
  *
  * @param parent the parent object
  * @param descriptor the reference descriptor
  */
 private IMObject getObject(IMObject parent, NodeDescriptor descriptor) {
   IMObjectReference ref = (IMObjectReference) descriptor.getValue(parent);
   if (ref != null) {
     try {
       return service.get(ref);
     } catch (OpenVPMSException exception) {
       log.warn(exception, exception);
     }
   }
   return null;
 }
Ejemplo n.º 3
0
 /**
  * Credits a supplier from an <em>act.supplierReturn</em> act.
  *
  * <p>The credit is saved.
  *
  * @param supplierReturn the supplier return act
  * @return the credit corresponding to the return
  * @throws ArchetypeServiceException for any archetype service error
  * @throws IllegalStateException if the return is already associated with a credit
  */
 public FinancialAct creditSupplier(Act supplierReturn) {
   if (isCredited(supplierReturn)) {
     throw new IllegalStateException("The return is already linked to a credit");
   }
   ActBean bean = new ActBean(supplierReturn, service);
   List<IMObject> objects = copy(supplierReturn, RETURN, new ReturnHandler(), new Date(), false);
   FinancialAct credit = (FinancialAct) objects.get(0);
   bean.addNodeRelationship("returnCredit", credit);
   objects.add(supplierReturn);
   service.save(objects);
   return (FinancialAct) objects.get(0);
 }
Ejemplo n.º 4
0
 /**
  * Invoices a supplier from an <em>act.supplierDelivery</em> act.
  *
  * <p>Both the invoice and delivery are saved.
  *
  * @param delivery the supplier delivery act
  * @return the invoice corresponding to the delivery
  * @throws ArchetypeServiceException for any archetype service error
  * @throws IllegalStateException if the delivery is already associated with a charge
  */
 public FinancialAct invoiceSupplier(Act delivery) {
   if (isInvoiced(delivery)) {
     throw new IllegalStateException("The delivery has already been invoiced");
   }
   ActBean bean = new ActBean(delivery, service);
   List<IMObject> objects = copy(delivery, DELIVERY, new DeliveryHandler(), new Date(), false);
   FinancialAct invoice = (FinancialAct) objects.get(0);
   bean.addNodeRelationship("invoice", invoice);
   objects.add(delivery);
   service.save(objects);
   return invoice;
 }
Ejemplo n.º 5
0
 /**
  * Processes an invoice.
  *
  * @param document the document to process
  * @param supplier the supplier submitting the invoice
  * @param stockLocation the stock location
  * @param accountId the supplier account identifier
  */
 public void process(
     InboxDocument document, Party supplier, Party stockLocation, String accountId) {
   InvoiceType invoice = (InvoiceType) document.getContent();
   try {
     Delivery delivery = mapper.map(invoice, supplier, stockLocation, accountId);
     service.save(delivery.getActs());
     notifyListener(delivery.getDelivery());
   } catch (Throwable exception) {
     String invoiceId = (invoice.getID() != null) ? invoice.getID().getValue() : null;
     Message message =
         ESCIAdapterMessages.failedToProcessInvoice(
             invoiceId, supplier, stockLocation, exception.getMessage());
     throw new ESCIAdapterException(message, exception);
   }
 }
Ejemplo n.º 6
0
 /**
  * Copies an order.
  *
  * <p>The copied order will have an <em>IN_PROGRESS</em> status and <em>PENDING</em> delivery
  * status.
  *
  * <p>The copy is saved.
  *
  * @param order the order to copy
  * @param title a title to assign to the copy. May be {@code null}
  * @return the copy of the order
  * @throws ArchetypeServiceException for any archetype service error
  */
 public FinancialAct copyOrder(FinancialAct order, String title) {
   List<IMObject> objects = copy(order, ORDER, new DefaultActCopyHandler(), new Date(), false);
   FinancialAct copy = (FinancialAct) objects.get(0);
   IMObjectBean bean = new IMObjectBean(copy, service);
   bean.setValue("deliveryStatus", DeliveryStatus.PENDING);
   copy.setTitle(title);
   for (IMObject object : objects) {
     if (TypeHelper.isA(object, SupplierArchetypes.ORDER_ITEM)) {
       IMObjectBean itemBean = new IMObjectBean(object, service);
       itemBean.setValue("receivedQuantity", BigDecimal.ZERO);
       itemBean.setValue("cancelledQuantity", BigDecimal.ZERO);
     }
   }
   service.save(objects);
   return copy;
 }
Ejemplo n.º 7
0
 /**
  * Resolves the state corresponding to a property.
  *
  * @param name the property name
  * @return the resolved state
  * @throws PropertyResolverException if the name is invalid
  */
 @Override
 @SuppressWarnings({"deprecation"})
 public PropertyState resolve(String name) {
   PropertyState state;
   IMObject object = root;
   ArchetypeDescriptor archetype = this.archetype;
   int index;
   while ((index = name.indexOf(".")) != -1) {
     String nodeName = name.substring(0, index);
     NodeDescriptor node = archetype.getNodeDescriptor(nodeName);
     if (node == null) {
       throw new NodeResolverException(InvalidProperty, name);
     }
     Object value = getValue(object, node);
     if (value == null) {
       // object missing.
       object = null;
       break;
     } else if (!(value instanceof IMObject)) {
       throw new NodeResolverException(InvalidObject, name);
     }
     object = (IMObject) value;
     archetype = service.getArchetypeDescriptor(object.getArchetypeId());
     name = name.substring(index + 1);
   }
   if (object != null) {
     NodeDescriptor leafNode = archetype.getNodeDescriptor(name);
     Object value;
     if (leafNode == null) {
       if ("displayName".equals(name)) {
         value = archetype.getDisplayName();
       } else if ("shortName".equals(name)) {
         value = object.getArchetypeId().getShortName();
       } else if ("uid".equals(name)) {
         value = object.getId();
       } else {
         throw new NodeResolverException(InvalidProperty, name);
       }
     } else {
       value = getValue(object, leafNode);
     }
     state = new PropertyState(object, archetype, name, leafNode, value);
   } else {
     state = new PropertyState();
   }
   return state;
 }
Ejemplo n.º 8
0
  /**
   * Constructs a {@link SessionMonitorConfigurer}.
   *
   * @param monitor the monitor to configure
   * @param service the archetype service
   * @param rules the practice rules
   */
  public SessionMonitorConfigurer(
      SessionMonitor monitor, IArchetypeService service, PracticeRules rules) {
    this.monitor = monitor;
    this.service = service;
    Party practice = rules.getPractice();
    if (practice != null) {
      configure(practice);
    }
    listener =
        new AbstractArchetypeServiceListener() {

          @Override
          public void saved(IMObject object) {
            configure(object);
          }
        };
    service.addListener(PracticeArchetypes.PRACTICE, listener);
  }
Ejemplo n.º 9
0
 /**
  * Helper to copy an act.
  *
  * @param object the object to copy
  * @param type the expected type of the object
  * @param handler the copy handler
  * @param startTime the start time of the copied object
  * @param save if <tt>true</tt>, save the copied objects
  * @return the copied objects
  */
 private List<IMObject> copy(
     Act object, String type, IMObjectCopyHandler handler, Date startTime, boolean save) {
   if (!TypeHelper.isA(object, type)) {
     throw new IllegalArgumentException(
         "Expected a "
             + type
             + " for argument 'object'"
             + ", but got a"
             + object.getArchetypeId().getShortName());
   }
   IMObjectCopier copier = new IMObjectCopier(handler, service);
   List<IMObject> objects = copier.apply(object);
   Act act = (Act) objects.get(0);
   act.setActivityStartTime(startTime);
   if (save) {
     service.save(objects);
   }
   return objects;
 }
Ejemplo n.º 10
0
 /**
  * Invoked by a BeanFactory on destruction of a singleton.
  *
  * @throws Exception in case of shutdown errors. Exceptions will get logged but not rethrown to
  *     allow other beans to release their resources too.
  */
 @Override
 public void destroy() throws Exception {
   service.removeListener(PracticeArchetypes.PRACTICE, listener);
 }
Ejemplo n.º 11
0
 /**
  * Returns the next page.
  *
  * @return the next page
  * @throws ArchetypeServiceException if the query fails
  */
 protected IPage<NodeSet> getPage(IArchetypeService service, IArchetypeQuery query) {
   return service.getNodes(query, nodes);
 }
Ejemplo n.º 12
0
 /**
  * Constructs a {@link NodeResolver}.
  *
  * @param root the root object
  * @param service the archetype service
  */
 public NodeResolver(IMObject root, IArchetypeService service) {
   this.root = root;
   archetype = service.getArchetypeDescriptor(root.getArchetypeId());
   this.service = service;
 }