Пример #1
0
  @Override
  public void deleteHUAssignments(
      final Object model, final Collection<I_M_HU> husToUnAssign, final String trxName) {
    Check.assumeNotNull(model, "model not null");
    Check.assumeNotNull(husToUnAssign, "husToUnAssign not null");

    final Properties ctx = InterfaceWrapperHelper.getCtx(model);
    final int adTableId = InterfaceWrapperHelper.getModelTableId(model);
    final int recordId = InterfaceWrapperHelper.getId(model);

    final Set<Integer> huIds = new HashSet<Integer>(husToUnAssign.size());
    for (final I_M_HU hu : husToUnAssign) {
      huIds.add(hu.getM_HU_ID());
    }

    if (huIds.isEmpty()) {
      return;
    }

    final IQueryBuilder<I_M_HU_Assignment> queryBuilder =
        Services.get(IQueryBL.class).createQueryBuilder(I_M_HU_Assignment.class, ctx, trxName);

    //
    // Note that here we don't want to skip anything; we want the HUAssignmentBL to do it's job, so
    // we clean everything up
    queryBuilder
        .addEqualsFilter(I_M_HU_Assignment.COLUMN_AD_Table_ID, adTableId)
        .addEqualsFilter(I_M_HU_Assignment.COLUMN_Record_ID, recordId)
        .addInArrayFilter(I_M_HU_Assignment.COLUMN_M_HU_ID, huIds)
        .create()
        .delete();
  }
Пример #2
0
  @Override
  public List<I_M_HU_Attribute> retrieveAttributesOrdered(final I_M_HU hu) {
    // NOTE: don't cache on this level. Caching is handled on upper levels

    // there are only some dozen attributes at most, so i think it'S fine to order them after
    // loading
    final List<I_M_HU_Attribute> huAttributes =
        Services.get(IQueryBL.class)
            .createQueryBuilder(I_M_HU_Attribute.class, hu)
            .filter(
                new EqualsQueryFilter<I_M_HU_Attribute>(
                    I_M_HU_Attribute.COLUMNNAME_M_HU_ID, hu.getM_HU_ID()))
            .create()
            .setOnlyActiveRecords(true)
            .list(I_M_HU_Attribute.class);

    // Optimization: set M_HU link
    for (final I_M_HU_Attribute huAttribute : huAttributes) {
      huAttribute.setM_HU(hu);
    }

    // Make sure they are sorted
    Collections.sort(huAttributes, HUAttributesBySeqNoComparator.instance);

    return huAttributes;
  }
Пример #3
0
  public HUExpectation<ParentExpectationType> assertExpected(
      final String message, final I_M_HU hu) {
    Assert.assertNotNull("hu not null", hu);

    final String prefix = (message == null ? "" : message) + "\nHU: " + hu + "\n" + "\nInvalid ";

    if (_huStatusSet) {
      Assert.assertEquals(prefix + "HUStatus", _huStatus, hu.getHUStatus());
    }

    if (_locatorSet) {
      assertModelEquals(prefix + "M_Locator", _locator, hu.getM_Locator());
    }

    if (_huPI != null) {
      final I_M_HU_PI_Version actual_huPIVersion = hu.getM_HU_PI_Version();
      final I_M_HU_PI actual_huPI =
          actual_huPIVersion == null ? null : actual_huPIVersion.getM_HU_PI();
      assertModelEquals(prefix + "HU PI", _huPI, actual_huPI);
    }

    if (huItemExpectations != null) {
      final List<I_M_HU_Item> huItems = handlingUnitsDAO.retrieveItems(hu);
      assertExpected(prefix + " HU Items", huItems);
    }

    if (_bpartner != null) {
      Assert.assertEquals(prefix + " C_BPartner", _bpartner, hu.getC_BPartner());
    }
    if (_bpartnerLocation != null) {
      Assert.assertEquals(
          prefix + " C_BPartner_Location", _bpartnerLocation, hu.getC_BPartner_Location());
    }

    //
    // Set capture
    if (_huToSetRef != null) {
      _huToSetRef.setValue(hu);
    }

    if (attributesExpectations != null) {
      attributesExpectations.assertExpected(prefix + " Attributes", hu);
    }

    return this;
  }
Пример #4
0
  @Override
  public <T> List<T> retrieveModelsForHU(
      final I_M_HU hu, final Class<T> clazz, final boolean topLevel) {
    final IQueryBL queryBL = Services.get(IQueryBL.class);

    final int tableId = InterfaceWrapperHelper.getTableId(clazz);
    final String keyColumnName = InterfaceWrapperHelper.getKeyColumnName(clazz);

    final IQueryBuilder<I_M_HU_Assignment> huAssigmentQueryBuilder =
        queryBL
            .createQueryBuilder(I_M_HU_Assignment.class, hu)
            .addOnlyContextClientOrSystem()
            .addOnlyActiveRecordsFilter()
            .addEqualsFilter(I_M_HU_Assignment.COLUMN_AD_Table_ID, tableId);
    if (topLevel) {
      huAssigmentQueryBuilder.addEqualsFilter(I_M_HU_Assignment.COLUMN_M_HU_ID, hu.getM_HU_ID());
      applyCommonTopLevelFilters(huAssigmentQueryBuilder, tableId);
    } else {
      final ICompositeQueryFilter<I_M_HU_Assignment> filter =
          queryBL
              .createCompositeQueryFilter(I_M_HU_Assignment.class)
              .setJoinOr()
              .addEqualsFilter(I_M_HU_Assignment.COLUMN_M_LU_HU_ID, hu.getM_HU_ID())
              .addEqualsFilter(I_M_HU_Assignment.COLUMN_M_TU_HU_ID, hu.getM_HU_ID())
              .addEqualsFilter(I_M_HU_Assignment.COLUMN_VHU_ID, hu.getM_HU_ID());
      huAssigmentQueryBuilder.filter(filter);
    }

    final IQuery<I_M_HU_Assignment> huAssigmentQuery = huAssigmentQueryBuilder.create();

    // @formatter:off
    return queryBL
        .createQueryBuilder(clazz, hu)
        .addOnlyContextClientOrSystem()
        .addOnlyActiveRecordsFilter()
        .addInSubQueryFilter(
            keyColumnName, I_M_HU_Assignment.COLUMNNAME_Record_ID, huAssigmentQuery)
        .orderBy()
        .addColumn(InterfaceWrapperHelper.getKeyColumnName(clazz))
        .endOrderBy()
        .create()
        .list(clazz);
    // @formatter:on
  }
Пример #5
0
  private final I_M_HU createHU_InTrx(final I_M_HU_Item parentHUItem) {
    //
    // Get HUStatus to set
    final String huStatus;
    if (isHUStatusSet()) {
      huStatus = getHUStatus();
    } else if (parentHUItem != null) {
      huStatus = parentHUItem.getM_HU().getHUStatus();
    } else {
      huStatus = null;
    }

    //
    // Get M_Locator to set
    final I_M_Locator locator;
    if (_locatorSet) {
      locator = _locator;
    } else if (parentHUItem != null) {
      locator = parentHUItem.getM_HU().getM_Locator();
    } else {
      locator = null;
    }

    //
    // Create and save HU
    final I_M_HU hu = InterfaceWrapperHelper.newInstance(I_M_HU.class, getContext());
    POJOWrapper.setInstanceName(hu, _instanceName);
    hu.setM_HU_PI_Version(getM_HU_PI_Version());
    hu.setM_HU_Item_Parent(parentHUItem);
    hu.setC_BPartner(_bpartner);
    hu.setC_BPartner_Location(_bpartnerLocation);
    hu.setHUStatus(huStatus);
    hu.setM_Locator(locator);
    InterfaceWrapperHelper.save(hu);

    //
    // Create HU Attributes
    if (attributesExpectations != null) {
      attributesExpectations.createHUAttributes(hu);
    }

    //
    // Create HU Items
    if (huItemExpectations != null) {
      for (final HUItemExpectation<HUExpectation<ParentExpectationType>> huItemExpectation :
          huItemExpectations) {
        huItemExpectation.createHUItem(hu);
      }
    }

    // Capture the HU if required
    if (_huToSetRef != null) {
      _huToSetRef.setValue(hu);
    }

    return hu;
  }
Пример #6
0
  private final IQueryBuilder<I_M_HU_Assignment> getDerivedTradingUnitAssignmentsQueryBuilder(
      final Properties ctx,
      final Object model,
      final I_M_HU topLevelHU,
      final I_M_HU luHU,
      final I_M_HU tuHU,
      final String trxName) {
    final int adTableId = InterfaceWrapperHelper.getModelTableId(model);

    final Integer luHUId = luHU == null ? null : luHU.getM_HU_ID();
    final Integer tuHUId = tuHU == null ? null : tuHU.getM_HU_ID();

    return Services.get(IQueryBL.class)
        .createQueryBuilder(I_M_HU_Assignment.class, ctx, trxName)
        .addEqualsFilter(I_M_HU_Assignment.COLUMN_AD_Table_ID, adTableId)
        //
        .addEqualsFilter(I_M_HU_Assignment.COLUMN_M_HU_ID, topLevelHU.getM_HU_ID())
        //
        .addEqualsFilter(I_M_HU_Assignment.COLUMN_M_LU_HU_ID, luHUId)
        .addEqualsFilter(I_M_HU_Assignment.COLUMN_M_TU_HU_ID, tuHUId);
  }
Пример #7
0
  @Override
  public final IQueryBuilder<I_M_HU_Assignment> retrieveTableHUAssignmentsQuery(
      final IContextAware contextProvider, final int adTableId, final I_M_HU hu) {
    final IQueryBuilder<I_M_HU_Assignment> queryBuilder =
        Services.get(IQueryBL.class).createQueryBuilder(I_M_HU_Assignment.class, contextProvider)
        // .addOnlyActiveRecordsFilter()
        ;

    applyCommonTopLevelFilters(queryBuilder, adTableId)
        .addEqualsFilter(I_M_HU_Assignment.COLUMN_M_HU_ID, hu.getM_HU_ID());
    return queryBuilder;
  }
Пример #8
0
 @Override
 public I_M_HU_Attribute retrieveAttribute(final I_M_HU hu, final I_M_Attribute attribute) {
   final List<I_M_HU_Attribute> huAttributes = retrieveAttributes(hu, attribute);
   if (huAttributes.isEmpty()) {
     return null;
   } else if (huAttributes.size() == 1) {
     return huAttributes.get(0);
   } else {
     throw new AdempiereException(
         "More than one HU Attributes were found for "
             + attribute.getName()
             + " on "
             + hu.getM_HU_ID()
             + ": "
             + huAttributes);
   }
 }
Пример #9
0
  private final List<I_M_HU_Attribute> retrieveAttributes(
      final I_M_HU hu, final I_M_Attribute attribute) {
    final List<I_M_HU_Attribute> huAttributes =
        Services.get(IQueryBL.class)
            .createQueryBuilder(I_M_HU_Attribute.class, hu)
            .filter(
                new EqualsQueryFilter<I_M_HU_Attribute>(
                    I_M_HU_Attribute.COLUMNNAME_M_Attribute_ID, attribute.getM_Attribute_ID()))
            .filter(
                new EqualsQueryFilter<I_M_HU_Attribute>(
                    I_M_HU_Attribute.COLUMNNAME_M_HU_ID, hu.getM_HU_ID()))
            .create()
            .setOnlyActiveRecords(true)
            .list(I_M_HU_Attribute.class);

    // Optimization: set M_HU link
    for (final I_M_HU_Attribute huAttribute : huAttributes) {
      huAttribute.setM_HU(hu);
    }

    return huAttributes;
  }
  public VirtualHUKeyWithParent(
      final IHUKeyFactory keyFactory, final I_M_HU hu, final IHUDocumentLine documentLine) {
    super(keyFactory, hu, documentLine);

    Check.assume(hu.getM_HU_Item_Parent_ID() > 0, "hu has a parent ({})", hu);
  }