Esempio n. 1
0
 /**
  * Creates a new supplier act item.
  *
  * @param shortName the act short name
  * @param product the product
  * @param quantity the quantity
  * @param packageSize the package size
  * @param packageUnits the package units
  * @param unitPrice the unit price
  * @param listPrice the list price
  * @return a new act
  */
 protected static FinancialAct createItem(
     String shortName,
     Product product,
     BigDecimal quantity,
     int packageSize,
     String packageUnits,
     BigDecimal unitPrice,
     BigDecimal listPrice) {
   FinancialAct item = (FinancialAct) create(shortName);
   ActBean bean = new ActBean(item);
   bean.addParticipation(StockArchetypes.STOCK_PARTICIPATION, product);
   item.setQuantity(quantity);
   bean.setValue("packageSize", packageSize);
   bean.setValue("packageUnits", packageUnits);
   bean.setValue("unitPrice", unitPrice);
   bean.setValue("listPrice", listPrice);
   ArchetypeServiceHelper.getArchetypeService().deriveValues(item);
   return item;
 }
  /**
   * This method is called during the create phase of an archetype. It will check the assertion and
   * determine whether it needs to do any work.
   *
   * <p>If the node descriptor is a collection and it is not a parent child relationship then there
   * may be a need to create and associated default entries to the collection
   *
   * @param target the target object
   * @param node the node descriptor
   * @param assertion the particular assertion
   */
  public static void create(Object target, NodeDescriptor node, AssertionDescriptor assertion) {
    if ((node.isCollection()) && (!node.isParentChild())) {
      List<ArchetypeRangeInfo> atypes = getArchetypeRangeInfo(assertion);
      if (atypes.size() == 0) {
        return;
      }

      // iterate through all the archetype range and if a default value
      // has been specfied attempt to locate the entry and add it to
      // the collection
      for (ArchetypeRangeInfo type : atypes) {
        if (StringUtils.isEmpty(type.defaultValue)) {
          continue;
        }

        // okay a default value needs to be created
        ArchetypeDescriptor adesc =
            ArchetypeServiceHelper.getArchetypeService().getArchetypeDescriptor(type.shortName);
        if (adesc == null) {
          throw new AssertionRuntimeException(
              AssertionRuntimeException.ErrorCode.ArchetypeDoesNotExist,
              new Object[] {"archetypeRangeAssertion", "create", type.shortName});
        }

        try {
          ArchetypeId aid = adesc.getType();
          List<IMObject> objects =
              ArchetypeQueryHelper.get(
                      ArchetypeServiceHelper.getArchetypeService(),
                      aid.getEntityName(),
                      aid.getConcept(),
                      type.defaultValue,
                      true,
                      0,
                      ArchetypeQuery.ALL_RESULTS)
                  .getResults();

          // if can not find a matching entity
          if (objects.size() == 0) {
            throw new AssertionRuntimeException(
                AssertionRuntimeException.ErrorCode.FailedToFindArchetype,
                new Object[] {
                  "archetypeRangeAssertion", "create", type.shortName, type.defaultValue
                });
          }

          // only expect to retrieve a single object
          if (objects.size() > 1) {
            throw new AssertionRuntimeException(
                AssertionRuntimeException.ErrorCode.TooManyObjectOnCreate,
                new Object[] {
                  "archetypeRangeAssertion", "create", type.shortName, type.defaultValue
                });
          }

          // now add it to the collection
          node.addChildToCollection((IMObject) target, objects.get(0));
        } catch (Exception exception) {
          throw new AssertionRuntimeException(
              AssertionRuntimeException.ErrorCode.FailedInCreate,
              new Object[] {"archetypeRangeAssertion", "create", type.shortName},
              exception);
        }
      }
    }
  }
Esempio n. 3
0
 /**
  * Constructs a new <code>NodeSetQueryIterator</code>.
  *
  * @param query the query
  * @param nodes the nodes to query
  * @throws ArchetypeServiceException if the archetype service isn't initialised
  */
 public NodeSetQueryIterator(IArchetypeQuery query, Collection<String> nodes) {
   this(ArchetypeServiceHelper.getArchetypeService(), query, nodes);
 }