@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(); }
@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; }
@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 }
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); }
@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; }
@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); } }
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; }