@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 #2
0
  public final <T>
      IQueryBuilder<I_M_Material_Tracking_Ref> createMaterialTrackingRefQueryBuilderForModels(
          final IQueryBuilder<T> modelsQuery) {
    final IQueryBL queryBL = Services.get(IQueryBL.class);

    final Class<T> modelClass = modelsQuery.getModelClass();
    final int modelTableId = InterfaceWrapperHelper.getTableId(modelClass);
    final String modelKeyColumnName = InterfaceWrapperHelper.getKeyColumnName(modelClass);

    //
    // Create M_Material_Tracking_Ref query
    final IQueryBuilder<I_M_Material_Tracking_Ref> materialTrackingRefQueryBuilder =
        queryBL
            .createQueryBuilder(I_M_Material_Tracking_Ref.class)
            .setContext(getCtx(), getTrxName())
            .addEqualsFilter(I_M_Material_Tracking_Ref.COLUMN_AD_Table_ID, modelTableId)
            .addInSubQueryFilter(
                I_M_Material_Tracking_Ref.COLUMNNAME_Record_ID,
                modelKeyColumnName,
                modelsQuery.create());

    return materialTrackingRefQueryBuilder;
  }
  @Override
  public I_AD_Note createMRPNote() {
    final Properties ctx = getCtx();
    final I_AD_Org org = getAD_Org_ToUse();
    final int AD_Org_ID = org == null ? 0 : org.getAD_Org_ID();
    final I_M_Warehouse warehouse = getM_Warehouse_ToUse();
    final I_S_Resource plant = getPlant_ToUse();
    final I_M_Product product = getM_Product_ToUse();
    final int productPlanningId = getPP_Product_Planning_ID_ToUse();
    final int panner_AD_User_ID = getPlanner_AD_Use_ID_ToUse();

    //
    // Note's TextMsg
    final I_AD_Message adMessageToUse = getMRPCode_AD_Message_ToUse();
    final StringBuilder noteTextMsg = new StringBuilder();
    noteTextMsg
        .append(adMessageToUse.getValue())
        .append(" - ")
        .append(messagesBL.getMsg(ctx, adMessageToUse.getValue()));

    //
    // Note's Reference text
    final String noteReference;
    if (product != null) {
      noteReference =
          messagesBL.translate(ctx, "M_Product_ID")
              + ": "
              + product.getValue()
              + " "
              + product.getName();
    } else {
      noteReference = "";
    }

    //
    // Append DocumentNos to note's TextMsg
    final Set<String> documentNos = getDocumentNos_ToUse();
    if (documentNos != null && !documentNos.isEmpty()) {
      final String documentNoPropertyName =
          messagesBL.translate(ctx, I_PP_Order.COLUMNNAME_DocumentNo);
      for (final String documentNo : documentNos) {
        noteTextMsg.append("\n" + documentNoPropertyName + ":" + documentNo);
      }
    }

    //
    // Append additional parameters to TextMsg
    final String parametersStr = getParametersAsString();
    if (!Check.isEmpty(parametersStr, true)) {
      noteTextMsg.append("\n").append(parametersStr);
    }

    //
    // Apppend Comment (if any) to note's TextMsg
    final String comment = getComment_ToUse();
    if (!Check.isEmpty(comment, true)) {
      noteTextMsg.append("\n").append(comment);
    }

    //
    // Append Exception (if any)
    final Exception exception = getException_ToUse();
    if (exception != null) {
      String exceptionStr = exception.getLocalizedMessage();
      if (exceptionStr == null || exceptionStr.length() <= 5) {
        // comment to small, better use whole exception string
        exceptionStr = exception.toString();
      }

      noteTextMsg.append("\nException: ").append(exceptionStr);

      // NOTE: since the exception is not logged anywhere, we are printing here to console
      // FIXME: create an AD_Issue and link it to create AD_Note.
      logger.log(Level.WARNING, exception.getLocalizedMessage(), exception);
    }

    //
    // Create AD_Note and return it
    {
      final I_PP_MRP mrp = getPP_MRP_ToUse();
      final int mrpId = mrp == null ? 0 : mrp.getPP_MRP_ID();

      final I_AD_Note note =
          InterfaceWrapperHelper.create(ctx, I_AD_Note.class, ITrx.TRXNAME_ThreadInherited);
      note.setAD_Org_ID(AD_Org_ID);
      note.setAD_Message_ID(adMessageToUse.getAD_Message_ID());
      note.setAD_User_ID(panner_AD_User_ID);

      // NOTE: we always shall set the AD_Table_ID=PP_MRP because else the MRP cleanup won't delete
      // this note (see org.eevolution.mrp.api.impl.MRPNoteDAO.deleteMRPNotes(IMRPContext))
      note.setAD_Table_ID(InterfaceWrapperHelper.getTableId(I_PP_MRP.class));

      if (mrpId > 0) {
        note.setRecord_ID(mrpId);
      }
      note.setM_Warehouse(warehouse);
      note.setPP_Plant(plant);
      note.setM_Product(product);
      note.setPP_Product_Planning_ID(productPlanningId);
      note.setReference(noteReference);
      note.setTextMsg(noteTextMsg.toString());
      InterfaceWrapperHelper.save(note);
      return note;
    }
  }