@Override
  public I_C_DocLine_Sort find() {
    //
    // BPartner query builder
    final IQueryBuilder<I_C_BP_DocLine_Sort> bpQueryBuilder =
        queryBL
            .createQueryBuilder(I_C_BP_DocLine_Sort.class, getCtx(), ITrx.TRXNAME_None)
            .addOnlyActiveRecordsFilter();

    bpQueryBuilder.addEqualsFilter(I_C_BP_DocLine_Sort.COLUMN_C_BPartner_ID, getC_BPartner_ID());

    //
    // Collect header
    final IQueryBuilder<I_C_DocLine_Sort> docLineQueryBuilder =
        bpQueryBuilder
            .andCollect(I_C_BP_DocLine_Sort.COLUMN_C_DocLine_Sort_ID, I_C_DocLine_Sort.class)
            .addOnlyActiveRecordsFilter();

    //
    // IsDefault
    docLineQueryBuilder.addEqualsFilter(I_C_DocLine_Sort.COLUMN_IsDefault, false);

    //
    // DocBaseType
    docLineQueryBuilder.addEqualsFilter(I_C_DocLine_Sort.COLUMN_DocBaseType, getDocBaseType());

    final boolean existsBPDocLineSortConfig = docLineQueryBuilder.create().match();
    if (existsBPDocLineSortConfig) {
      return docLineQueryBuilder.create().firstOnly(I_C_DocLine_Sort.class);
    }

    //
    // Retrieve default if no match was found
    final IQueryBuilder<I_C_DocLine_Sort> docLineDefaultQueryBuilder =
        queryBL
            .createQueryBuilder(I_C_DocLine_Sort.class, getCtx(), ITrx.TRXNAME_None)
            .addOnlyActiveRecordsFilter();

    //
    // IsDefault
    docLineDefaultQueryBuilder.addEqualsFilter(I_C_DocLine_Sort.COLUMN_IsDefault, true);

    //
    // DocBaseType
    docLineDefaultQueryBuilder.addEqualsFilter(
        I_C_DocLine_Sort.COLUMN_DocBaseType, getDocBaseType());

    //
    // Return default (if any)
    return docLineDefaultQueryBuilder.create().firstOnly(I_C_DocLine_Sort.class);
  }
Beispiel #2
0
  public IQueryBuilder<I_M_Material_Tracking> createQueryBuilder(
      final IMaterialTrackingQuery queryVO) {
    Check.assumeNotNull(queryVO, "queryVO not null");

    final IQueryBuilder<I_M_Material_Tracking> queryBuilder =
        queryBL
            .createQueryBuilder(I_M_Material_Tracking.class)
            .setContext(getCtx(), getTrxName())
            .addOnlyContextClient()
            .addOnlyActiveRecordsFilter();

    final IQueryOrderByBuilder<I_M_Material_Tracking> orderBy = queryBuilder.orderBy();

    //
    // M_Product_ID
    final int productId = queryVO.getM_Product_ID();
    Check.assume(productId > 0, "productId > 0");
    queryBuilder.addEqualsFilter(I_M_Material_Tracking.COLUMN_M_Product_ID, productId);

    //
    // C_BPartner_ID
    final int bpartnerId = queryVO.getC_BPartner_ID();
    queryBuilder.addInArrayFilter(I_M_Material_Tracking.COLUMN_C_BPartner_ID, null, bpartnerId);
    orderBy.addColumn(I_M_Material_Tracking.COLUMN_C_BPartner_ID, Direction.Descending, Nulls.Last);

    // TODO: ValidFrom, ValidTo

    //
    // Processed
    final Boolean processed = queryVO.getProcessed();
    if (processed != null) {
      queryBuilder.addEqualsFilter(I_M_Material_Tracking.COLUMN_Processed, processed);
    }

    //
    // Linked documents
    final List<?> linkedModels = queryVO.getWithLinkedDocuments();
    if (linkedModels != null && !linkedModels.isEmpty()) {
      final IQuery<I_M_Material_Tracking_Ref> materialTrackingRefQuery =
          createMaterialTrackingRefQueryForModels(linkedModels);
      if (materialTrackingRefQuery != null) {
        queryBuilder.addInSubQueryFilter(
            I_M_Material_Tracking.COLUMN_M_Material_Tracking_ID,
            I_M_Material_Tracking_Ref.COLUMN_M_Material_Tracking_ID,
            materialTrackingRefQuery);
      }
      // TODO
    }

    return queryBuilder;
  }
  @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_Assignment> retrieveIncludedHUAssignments(final I_M_HU_Assignment assignment) {
    final IQueryBL queryBL = Services.get(IQueryBL.class);
    final IQueryBuilder<I_M_HU_Assignment> queryBuilder =
        queryBL.createQueryBuilder(I_M_HU_Assignment.class, assignment);

    queryBuilder
        // references same record..
        .addEqualsFilter(I_M_HU_Assignment.COLUMN_AD_Table_ID, assignment.getAD_Table_ID())
        .addEqualsFilter(I_M_HU_Assignment.COLUMN_Record_ID, assignment.getRecord_ID())
        // ..and same toplevel-HU..
        .addEqualsFilter(I_M_HU_Assignment.COLUMN_M_HU_ID, assignment.getM_HU_ID());

    // ..but additionally references one of the HU's components (TU or LU)
    final ICompositeQueryFilter<I_M_HU_Assignment> subFilter =
        queryBL.createCompositeQueryFilter(I_M_HU_Assignment.class);
    subFilter
        .setJoinOr()
        .addNotEqualsFilter(I_M_HU_Assignment.COLUMN_M_LU_HU_ID, null)
        .addNotEqualsFilter(I_M_HU_Assignment.COLUMN_M_TU_HU_ID, null);

    queryBuilder.filter(subFilter);

    //
    return queryBuilder.create().list(I_M_HU_Assignment.class);
  }
Beispiel #5
0
  private IQueryBuilder<I_AD_Column> retrieveColumnQueryBuilder(
      final String tableName, final String columnName) {
    //
    // Create queryBuilder with default context (not needed for tables)
    final IQueryBuilder<I_AD_Column> queryBuilder =
        Services.get(IQueryBL.class)
            .createQueryBuilder(I_AD_Column.class, Env.getCtx(), ITrx.TRXNAME_None);

    //
    // Filter by tableName
    queryBuilder.addEqualsFilter(I_AD_Column.COLUMNNAME_AD_Table_ID, retrieveTableId(tableName));
    //
    // Filter by columnName
    queryBuilder.addEqualsFilter(
        I_AD_Column.COLUMNNAME_ColumnName, columnName, UpperCaseQueryFilterModifier.instance);

    return queryBuilder;
  }
 /**
  * Adds a filter that makes sure only <b>top level-HU</b> records with the given <code>AD_Table_ID
  * </code> and in addition with <code>M_LU_HU_ID</code>, <code>M_TU_HU_ID</code> and <code>VHU_ID
  * </code> being <code>null</code> will be selected.
  *
  * @param queryBuilder the builder that is augmented by this method
  * @param adTableId
  * @return
  */
 private IQueryBuilder<I_M_HU_Assignment> applyCommonTopLevelFilters(
     final IQueryBuilder<I_M_HU_Assignment> queryBuilder, final int adTableId) {
   queryBuilder
       .addEqualsFilter(I_M_HU_Assignment.COLUMN_AD_Table_ID, adTableId)
       //
       // Filter out entries which are specifically for other levels
       //
       .addEqualsFilter(I_M_HU_Assignment.COLUMN_M_LU_HU_ID, null)
       .addEqualsFilter(I_M_HU_Assignment.COLUMN_M_TU_HU_ID, null);
   return queryBuilder;
 }
  @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
  }
Beispiel #8
0
  @Override
  protected String doIt() throws Exception {
    if (p_Target_Directory == null) throw new FillMandatoryException("Target_Directory");
    if (p_EntityType == null) throw new FillMandatoryException("EntityType");

    final IQueryBuilder<I_EXP_Format> queryBuilder =
        Services.get(IQueryBL.class).createQueryBuilder(I_EXP_Format.class).setContext(this);

    if (p_FilterBy_AD_Client_ID) {
      queryBuilder.addInArrayFilter(I_EXP_Format.COLUMNNAME_AD_Client_ID, 0, getAD_Client_ID());
    }
    if (p_EntityType != null) {
      queryBuilder.addEqualsFilter(I_EXP_Format.COLUMNNAME_EntityType, p_EntityType);
    }

    queryBuilder
        .orderBy()
        .addColumn(I_EXP_Format.COLUMNNAME_EXP_Format_ID) // to have a predictible order
    ;

    final List<I_EXP_Format> expFormats = queryBuilder.create().list();

    final CanonicalXSDGenerator engine = new CanonicalXSDGenerator();
    for (final I_EXP_Format format : expFormats) {
      if (!format.isActive()) continue;
      engine.addEXPFormat(format);
      // metas-ts: commenting out for now, because taskes very long when there are many export
      // formats and it never helped me so far (mainly because it doesn't export embedded formats)
      // createTestModel(format);
    }
    createTestModelsIndex(expFormats);

    final String schemaFile = getSchemaFile().getAbsolutePath();
    engine.saveToFile(schemaFile);
    addLog("Created schema file: " + schemaFile);

    return "OK";
  }