Exemplo n.º 1
0
  private File createNextCumulativePatchAddingRandomModule(
      String patchID,
      String asVersion,
      final String currentPatch,
      final String targetAsVersion,
      File targetDir)
      throws Exception {
    String layerPatchID = "layer" + patchID;
    File cpPatchDir = mkdir(tempDir, patchID);
    final String moduleName = "org.wildfly.test." + randomString();

    // Create the version module
    final String versionModuleName = ProductInfo.getVersionModule();
    final Module modifiedModule = PatchingTestUtil.createVersionModule(targetAsVersion);

    // Calculate the target hash of the currently active module
    final String currentLayerPatchID = "layer" + currentPatch;
    File originalVersionModulePath = new File(tempDir, currentPatch);
    originalVersionModulePath = new File(originalVersionModulePath, currentLayerPatchID);
    originalVersionModulePath = new File(originalVersionModulePath, Constants.MODULES);
    originalVersionModulePath = newFile(originalVersionModulePath, versionModuleName.split("\\."));
    originalVersionModulePath =
        new File(originalVersionModulePath, ProductInfo.getVersionModuleSlot());
    byte[] patchedAsVersionHash = HashUtils.hashFile(originalVersionModulePath);
    assert patchedAsVersionHash != null;

    final ResourceItem resourceItem1 = new ResourceItem("testFile1", "content1".getBytes());
    final ResourceItem resourceItem2 = new ResourceItem("testFile2", "content2".getBytes());

    Module newModule =
        new Module.Builder(moduleName).miscFile(resourceItem1).miscFile(resourceItem2).build();

    ContentModification moduleAdded =
        ContentModificationUtils.addModule(cpPatchDir, layerPatchID, newModule);
    ContentModification versionModuleModified =
        ContentModificationUtils.modifyModule(
            cpPatchDir, layerPatchID, patchedAsVersionHash, modifiedModule);

    ProductConfig productConfig = new ProductConfig(PRODUCT, asVersion, "main");
    Patch cpPatch =
        PatchBuilder.create()
            .setPatchId(patchID)
            .setDescription("A cp patch.")
            .upgradeIdentity(
                productConfig.getProductName(), productConfig.getProductVersion(), targetAsVersion)
            .getParent()
            .upgradeElement(layerPatchID, "base", false)
            .addContentModification(versionModuleModified)
            .addContentModification(moduleAdded)
            .getParent()
            .build();
    createPatchXMLFile(cpPatchDir, cpPatch);
    return createZippedPatchFile(cpPatchDir, patchID, targetDir);
  }
Exemplo n.º 2
0
  private File createNextCumulativePatchModyfyingJbossModules(
      String patchID,
      String asVersion,
      final String currentPatch,
      final String targetAsVersion,
      File targetDir)
      throws Exception {
    String layerPatchID = "layer" + patchID;
    File cpPatchDir = mkdir(tempDir, patchID);

    // Also see if we can update jboss-modules
    final File installation = new File(AS_DISTRIBUTION);
    final File patchDir = new File(cpPatchDir, patchID);
    final ContentModification jbossModulesModification =
        PatchingTestUtil.updateModulesJar(installation, patchDir);

    // Create the version module
    final String versionModuleName = ProductInfo.getVersionModule();
    final Module modifiedModule = PatchingTestUtil.createVersionModule(targetAsVersion);

    // Calculate the target hash of the currently active module
    final String currentLayerPatchID = "layer" + currentPatch;
    File originalVersionModulePath = new File(tempDir, currentPatch);
    originalVersionModulePath = new File(originalVersionModulePath, currentLayerPatchID);
    originalVersionModulePath = new File(originalVersionModulePath, Constants.MODULES);
    originalVersionModulePath = newFile(originalVersionModulePath, versionModuleName.split("\\."));
    originalVersionModulePath =
        new File(originalVersionModulePath, ProductInfo.getVersionModuleSlot());
    byte[] patchedAsVersionHash = HashUtils.hashFile(originalVersionModulePath);
    assert patchedAsVersionHash != null;

    ContentModification versionModuleModified =
        ContentModificationUtils.modifyModule(
            cpPatchDir, layerPatchID, patchedAsVersionHash, modifiedModule);

    Patch cpPatch =
        PatchBuilder.create()
            .setPatchId(patchID)
            .setDescription("A cp patch.")
            .upgradeIdentity(PRODUCT, asVersion, targetAsVersion)
            .getParent()
            .upgradeElement(layerPatchID, "base", false)
            .addContentModification(versionModuleModified)
            .getParent()
            .addContentModification(jbossModulesModification)
            .build();
    createPatchXMLFile(cpPatchDir, cpPatch);
    return createZippedPatchFile(cpPatchDir, patchID, targetDir);
  }
Exemplo n.º 3
0
  private File createCumulativePatchAddingARandomModule(
      String patchID, String asVersion, final String targetAsVersion, File targetDir)
      throws Exception {
    String layerPatchID = "layer" + patchID;
    File cpPatchDir = mkdir(tempDir, patchID);

    final String moduleName = "org.wildfly.test." + randomString();

    final ResourceItem resourceItem1 = new ResourceItem("testFile1", "content1".getBytes());
    final ResourceItem resourceItem2 = new ResourceItem("testFile2", "content2".getBytes());

    Module newModule =
        new Module.Builder(moduleName).miscFile(resourceItem1).miscFile(resourceItem2).build();

    // Create the version module
    final String versionModuleName = ProductInfo.getVersionModule();
    final String slot = ProductInfo.getVersionModuleSlot();
    final String originalVersionModulePath =
        MODULES_PATH
            + FILE_SEPARATOR
            + versionModuleName.replace(".", FILE_SEPARATOR)
            + FILE_SEPARATOR
            + slot;
    final Module modifiedModule = PatchingTestUtil.createVersionModule(targetAsVersion);

    ContentModification moduleAdded =
        ContentModificationUtils.addModule(cpPatchDir, layerPatchID, newModule);
    ContentModification versionModuleModified =
        ContentModificationUtils.modifyModule(
            cpPatchDir,
            layerPatchID,
            HashUtils.hashFile(new File(originalVersionModulePath)),
            modifiedModule);

    Patch cpPatch =
        PatchBuilder.create()
            .setPatchId(patchID)
            .setDescription("A cp patch.")
            .upgradeIdentity(PRODUCT, asVersion, targetAsVersion)
            .getParent()
            .upgradeElement(layerPatchID, "base", false)
            .addContentModification(moduleAdded)
            .addContentModification(versionModuleModified)
            .getParent()
            .build();
    createPatchXMLFile(cpPatchDir, cpPatch);
    return createZippedPatchFile(cpPatchDir, patchID, targetDir);
  }
Exemplo n.º 4
0
  public static ProductInfo[] getProductInfo() {
    ProductInfo[] result = new ProductInfo[3];
    ProductInfo table = new ProductInfo();
    table.price = 1500;
    table.product = "Table";

    ProductInfo window = new ProductInfo();
    window.price = 1300;
    window.product = "Window";

    ProductInfo bed = new ProductInfo();
    bed.price = 500;
    bed.product = "Bed";

    result[0] = table;
    result[1] = window;
    result[2] = bed;

    return result;
  }
  /**
   * Create Facts (the accounting logic) for MMS, MMR.
   *
   * <pre>
   *  Shipment
   *      CoGS            DR
   *      Inventory               CR
   *  Shipment of Project Issue
   *      CoGS            DR
   *      Project                 CR
   *  Receipt
   *      Inventory       DR
   *      NotInvoicedReceipt      CR
   * </pre>
   *
   * @param as accounting schema
   * @return Fact
   */
  public Fact createFact(
      AcctSchema as, ConnectionProvider conn, Connection con, VariablesSecureApp vars)
      throws ServletException {
    // Select specific definition
    String strClassname =
        AcctServerData.selectTemplateDoc(conn, as.m_C_AcctSchema_ID, DocumentType);
    if (StringUtils.isEmpty(strClassname)) {
      strClassname = AcctServerData.selectTemplate(conn, as.m_C_AcctSchema_ID, AD_Table_ID);
    } else {
      try {
        DocCostAdjustmentTemplate newTemplate =
            (DocCostAdjustmentTemplate) Class.forName(strClassname).newInstance();
        return newTemplate.createFact(this, as, conn, con, vars);
      } catch (Exception e) {
        log4j.error("Error while creating new instance for DocCostAdjustmentTemplate - ", e);
      }
    }
    C_Currency_ID = as.getC_Currency_ID();
    // create Fact Header
    Fact fact = new Fact(this, as, Fact.POST_Actual);
    String Fact_Acct_Group_ID = SequenceIdData.getUUID();
    String amtDebit = "0";
    String amtCredit = "0";

    // Lines
    for (int i = 0; p_lines != null && i < p_lines.length; i++) {
      DocLine_CostAdjustment line = (DocLine_CostAdjustment) p_lines[i];
      String transactionType = line.getTransactionType();

      BigDecimal amount = new BigDecimal(line.getAmount());
      ProductInfo p = new ProductInfo(line.m_M_Product_ID, conn);

      log4jDocCostAdjustment.debug(
          "antes del creteline, line.getAmount(): "
              + line.getAmount()
              + " - TransactionType: "
              + transactionType);
      if (transactionType.equals(DocLine_CostAdjustment.TRXTYPE_SHIPMENT)) {
        // Cogs DR
        // Inventory Asset CR
        log4jDocCostAdjustment.debug(
            "********** DocCostAdjustment - factAcct - account - "
                + p.getAccount(ProductInfo.ACCTTYPE_P_Cogs, as, conn).C_ValidCombination_ID);

        if (line.isTransactionNegative()) {
          amtDebit = "";
          amtCredit = amount.toPlainString();
        } else {
          amtDebit = amount.toPlainString();
          amtCredit = "";
        }
        fact.createLine(
            line,
            p.getAccount(ProductInfo.ACCTTYPE_P_Cogs, as, conn),
            line.m_C_Currency_ID,
            amtDebit,
            amtCredit,
            Fact_Acct_Group_ID,
            nextSeqNo(SeqNo),
            DocumentType,
            line.m_DateAcct,
            null,
            conn);
        fact.createLine(
            line,
            p.getAccount(ProductInfo.ACCTTYPE_P_Asset, as, conn),
            line.m_C_Currency_ID,
            amtCredit,
            amtDebit,
            Fact_Acct_Group_ID,
            nextSeqNo(SeqNo),
            DocumentType,
            line.m_DateAcct,
            null,
            conn);
      } else if (transactionType.equals(DocLine_CostAdjustment.TRXTYPE_RECEIPT)) {
        Account acct = null;
        // Inventory Asset DR
        if (line.getIsSource() && ("PDC").equals(line.getSourceProcess())) { // Price Diff
          // Correction
          // Invoice Price Variance CR
          acct = p.getAccount(ProductInfo.ACCTTYPE_P_IPV, as, conn);
        } else if (line.getIsSource() && ("LC").equals(line.getSourceProcess())) {
          throw new IllegalStateException(OBMessageUtils.messageBD("LCNotAccounting"));
        } else {
          // Product Exp CR
          acct =
              getAccountByWarehouse(
                  AcctServer.ACCTTYPE_InvDifferences, as, line.getWarehouseId(), conn);
        }
        log4jDocCostAdjustment.debug(
            "********** DocCostAdjustment - factAcct - account - "
                + p.getAccount(ProductInfo.ACCTTYPE_P_Expense, as, conn).C_ValidCombination_ID);
        if (line.isTransactionNegative()) {
          amtDebit = amount.toPlainString();
          amtCredit = "";
        } else {
          amtDebit = "";
          amtCredit = amount.toPlainString();
        }
        fact.createLine(
            line,
            acct,
            line.m_C_Currency_ID,
            amtDebit,
            amtCredit,
            Fact_Acct_Group_ID,
            nextSeqNo(SeqNo),
            DocumentType,
            line.m_DateAcct,
            null,
            conn);
        fact.createLine(
            line,
            p.getAccount(ProductInfo.ACCTTYPE_P_Asset, as, conn),
            line.m_C_Currency_ID,
            amtCredit,
            amtDebit,
            Fact_Acct_Group_ID,
            nextSeqNo(SeqNo),
            DocumentType,
            line.m_DateAcct,
            null,
            conn);
      } else if (transactionType.equals(DocLine_CostAdjustment.TRXTYPE_INVENTORY)) {
        // Inventory Asset DR
        // Inventory Adjustment CR
        log4jDocCostAdjustment.debug(
            "********** DocCostAdjustment - factAcct - account - "
                + getAccountByWarehouse(
                        AcctServer.ACCTTYPE_InvDifferences, as, line.getWarehouseId(), conn)
                    .C_ValidCombination_ID);
        if (line.isTransactionNegative()) {
          amtDebit = amount.toPlainString();
          amtCredit = "";
        } else {
          amtDebit = "";
          amtCredit = amount.toPlainString();
        }
        fact.createLine(
            line,
            getAccountByWarehouse(
                AcctServer.ACCTTYPE_InvDifferences, as, line.getWarehouseId(), conn),
            line.m_C_Currency_ID,
            amtDebit,
            amtCredit,
            Fact_Acct_Group_ID,
            nextSeqNo(SeqNo),
            DocumentType,
            line.m_DateAcct,
            null,
            conn);
        fact.createLine(
            line,
            p.getAccount(ProductInfo.ACCTTYPE_P_Asset, as, conn),
            line.m_C_Currency_ID,
            amtCredit,
            amtDebit,
            Fact_Acct_Group_ID,
            nextSeqNo(SeqNo),
            DocumentType,
            line.m_DateAcct,
            null,
            conn);
      } else if (transactionType.equals(DocLine_CostAdjustment.TRXTYPE_INTERNALMOVEMENTFROM)) {
        // Inventory Asset DR
        // Inventory Adjustment CR
        M_Warehouse_ID = line.getWarehouseId();
        log4jDocCostAdjustment.debug(
            "********** DocCostAdjustment - factAcct - account - "
                + getAccountByWarehouse(
                        AcctServer.ACCTTYPE_InvDifferences, as, line.getWarehouseId(), conn)
                    .C_ValidCombination_ID);
        if (line.isTransactionNegative()) {
          amtDebit = amount.negate().toPlainString();
          amtCredit = "";
        } else {
          amtDebit = "";
          amtCredit = amount.negate().toPlainString();
        }
        fact.createLine(
            line,
            p.getAccount(ProductInfo.ACCTTYPE_P_Asset, as, conn),
            line.m_C_Currency_ID,
            amtDebit,
            amtCredit,
            Fact_Acct_Group_ID,
            nextSeqNo(SeqNo),
            DocumentType,
            line.m_DateAcct,
            null,
            conn);

        fact.createLine(
            line,
            getAccountByWarehouse(
                AcctServer.ACCTTYPE_InvDifferences, as, line.getWarehouseId(), conn),
            line.m_C_Currency_ID,
            amtCredit,
            amtDebit,
            Fact_Acct_Group_ID,
            nextSeqNo(SeqNo),
            DocumentType,
            line.m_DateAcct,
            null,
            conn);
      } else if (transactionType.equals(DocLine_CostAdjustment.TRXTYPE_INTERNALMOVEMENTTO)) {
        // Inventory Asset DR
        // Inventory Adjustment CR
        M_Warehouse_ID = line.getWarehouseId();
        log4jDocCostAdjustment.debug(
            "********** DocCostAdjustment - factAcct - account - "
                + getAccountByWarehouse(
                        AcctServer.ACCTTYPE_InvDifferences, as, line.getWarehouseId(), conn)
                    .C_ValidCombination_ID);
        if (line.isTransactionNegative()) {
          amtDebit = amount.toPlainString();
          amtCredit = "";
        } else {
          amtDebit = "";
          amtCredit = amount.toPlainString();
        }
        fact.createLine(
            line,
            getAccountByWarehouse(
                AcctServer.ACCTTYPE_InvDifferences, as, line.getWarehouseId(), conn),
            line.m_C_Currency_ID,
            amtDebit,
            amtCredit,
            Fact_Acct_Group_ID,
            nextSeqNo(SeqNo),
            DocumentType,
            line.m_DateAcct,
            null,
            conn);
        fact.createLine(
            line,
            p.getAccount(ProductInfo.ACCTTYPE_P_Asset, as, conn),
            line.m_C_Currency_ID,
            amtCredit,
            amtDebit,
            Fact_Acct_Group_ID,
            nextSeqNo(SeqNo),
            DocumentType,
            line.m_DateAcct,
            null,
            conn);
      } else if (transactionType.equals(DocLine_CostAdjustment.TRXTYPE_INTERNALCONSUMPTION)) {
        // Inventory Asset DR
        // Inventory Adjustment CR
        M_Warehouse_ID = line.getWarehouseId();
        log4jDocCostAdjustment.debug(
            "********** DocCostAdjustment - factAcct - account - "
                + getAccountByWarehouse(
                        AcctServer.ACCTTYPE_InvDifferences, as, line.getWarehouseId(), conn)
                    .C_ValidCombination_ID);
        if (line.isTransactionNegative()) {
          amtDebit = amount.toPlainString();
          amtCredit = "";
        } else {
          amtDebit = "";
          amtCredit = amount.toPlainString();
        }
        fact.createLine(
            line,
            p.getAccount(ProductInfo.ACCTTYPE_P_Asset, as, conn),
            line.m_C_Currency_ID,
            amtDebit,
            amtCredit,
            Fact_Acct_Group_ID,
            nextSeqNo(SeqNo),
            DocumentType,
            line.m_DateAcct,
            null,
            conn);

        fact.createLine(
            line,
            getAccountByWarehouse(
                AcctServer.ACCTTYPE_InvDifferences, as, line.getWarehouseId(), conn),
            line.m_C_Currency_ID,
            amtCredit,
            amtDebit,
            Fact_Acct_Group_ID,
            nextSeqNo(SeqNo),
            DocumentType,
            line.m_DateAcct,
            null,
            conn);
      } else if (transactionType.equals(DocLine_CostAdjustment.TRXTYPE_BOM)) {
        // Inventory Asset DR
        // Inventory Adjustment CR
        M_Warehouse_ID = line.getWarehouseId();
        log4jDocCostAdjustment.debug(
            "********** DocCostAdjustment - factAcct - account - "
                + getAccountByWarehouse(
                        AcctServer.ACCTTYPE_InvDifferences, as, line.getWarehouseId(), conn)
                    .C_ValidCombination_ID);
        if (line.isTransactionNegative()) {
          amtDebit = amount.toPlainString();
          amtCredit = "";
        } else {
          amtDebit = "";
          amtCredit = amount.toPlainString();
        }
        fact.createLine(
            line,
            getAccountByWarehouse(
                AcctServer.ACCTTYPE_InvDifferences, as, line.getWarehouseId(), conn),
            line.m_C_Currency_ID,
            amtDebit,
            amtCredit,
            Fact_Acct_Group_ID,
            nextSeqNo(SeqNo),
            DocumentType,
            line.m_DateAcct,
            null,
            conn);

        fact.createLine(
            line,
            p.getAccount(ProductInfo.ACCTTYPE_P_Asset, as, conn),
            line.m_C_Currency_ID,
            amtCredit,
            amtDebit,
            Fact_Acct_Group_ID,
            nextSeqNo(SeqNo),
            DocumentType,
            line.m_DateAcct,
            null,
            conn);
      } else if (transactionType.equals(DocLine_CostAdjustment.TRXTYPE_MANUFACTURING)) {
        // Inventory Asset DR
        // Inventory Adjustment CR
        M_Warehouse_ID = line.getWarehouseId();
        log4jDocCostAdjustment.debug(
            "********** DocCostAdjustment - factAcct - account - "
                + getAccountByWarehouse(
                        AcctServer.ACCTTYPE_InvDifferences, as, line.getWarehouseId(), conn)
                    .C_ValidCombination_ID);
        if (line.isTransactionNegative()) {
          amtDebit = amount.toPlainString();
          amtCredit = "";
        } else {
          amtDebit = "";
          amtCredit = amount.toPlainString();
        }
        fact.createLine(
            line,
            getAccountByWarehouse(
                AcctServer.ACCTTYPE_InvDifferences, as, line.getWarehouseId(), conn),
            line.m_C_Currency_ID,
            amtDebit,
            amtCredit,
            Fact_Acct_Group_ID,
            nextSeqNo(SeqNo),
            DocumentType,
            line.m_DateAcct,
            null,
            conn);

        fact.createLine(
            line,
            p.getAccount(ProductInfo.ACCTTYPE_P_Asset, as, conn),
            line.m_C_Currency_ID,
            amtCredit,
            amtDebit,
            Fact_Acct_Group_ID,
            nextSeqNo(SeqNo),
            DocumentType,
            line.m_DateAcct,
            null,
            conn);
      }
    } // lines

    SeqNo = "0";
    return fact;
  } // createFact
 // 测试ProductList类
 @Test
 public void test_ProductList() {
   ProductList list = ProductList.Initial();
   ProductInfo one_item_info = list.getProductItemInfo("ITEM000005");
   assertTrue(one_item_info.getName().equals("牙膏"));
 }