예제 #1
0
  public SyncProduct createSyncProduct(final I_PMM_Product pmmProduct) {
    final String product_uuid = SyncUUIDs.toUUIDString(pmmProduct);
    try {
      final SyncProduct syncProduct =
          syncProductsCache.get(
              product_uuid,
              new Callable<SyncProduct>() {

                @Override
                public SyncProduct call() throws Exception {
                  return createSyncProductNoCache(pmmProduct);
                }
              });
      return syncProduct.copy();
    } catch (final ExecutionException ex) {
      throw new RuntimeException(
          "Failed creating " + SyncProduct.class + " for " + pmmProduct, ex.getCause());
    }
  }
예제 #2
0
  private final SyncProduct createSyncProductNoCache(final I_PMM_Product pmmProduct) {
    final String product_uuid = SyncUUIDs.toUUIDString(pmmProduct);

    final I_M_Product product = pmmProduct.getM_Product();

    String productName = pmmProduct.getProductName();
    // Fallback to M_Product.Name (shall not happen)
    if (Check.isEmpty(productName, true)) {
      productName = product == null ? null : product.getName();
    }

    final SyncProduct syncProduct = new SyncProduct();

    final boolean valid =
        pmmProduct.isActive()
            && pmmProduct.getM_Warehouse_ID() > 0
            && pmmProduct.getM_Product_ID() > 0
            && pmmProduct.getM_HU_PI_Item_Product_ID() > 0;

    syncProduct.setUuid(product_uuid);
    syncProduct.setName(productName);
    syncProduct.setPackingInfo(pmmProduct.getPackDescription());

    syncProduct.setShared(
        pmmProduct.getC_BPartner_ID()
            <= 0); // share, unless it is assigned to a particular BPartner
    syncProduct.setDeleted(!valid);

    //
    // Translations
    {
      final Map<String, String> syncProductNamesTrl = syncProduct.getNamesTrl();
      final IModelTranslationMap productTrls =
          InterfaceWrapperHelper.getModelTranslationMap(product);
      final PMMProductNameBuilder productNameTrlBuilder =
          PMMProductNameBuilder.newBuilder().setPMM_Product(pmmProduct);
      for (final IModelTranslation productLanguageTrl : productTrls.getAllTranslations().values()) {
        final String adLanguage = productLanguageTrl.getAD_Language();

        final String productNamePartTrl =
            productLanguageTrl.getTranslation(I_M_Product.COLUMNNAME_Name);
        if (Check.isEmpty(productNamePartTrl, true)) {
          continue;
        }

        final String productNameTrl =
            productNameTrlBuilder.setProductNamePartIfUsingMProduct(productNamePartTrl).build();
        if (Check.isEmpty(productNameTrl, true)) {
          continue;
        }

        syncProductNamesTrl.put(adLanguage, productNameTrl.trim());
      }
    }

    return syncProduct;
  }