Search in sources :

Example 1 with GenericTransactionException

use of org.apache.ofbiz.entity.transaction.GenericTransactionException in project ofbiz-framework by apache.

the class ProductEvents method updateProductQuickAdminShipping.

public static String updateProductQuickAdminShipping(HttpServletRequest request, HttpServletResponse response) {
    Delegator delegator = (Delegator) request.getAttribute("delegator");
    Timestamp nowTimestamp = UtilDateTime.nowTimestamp();
    GenericValue userLogin = (GenericValue) request.getSession().getAttribute("userLogin");
    String variantProductId = request.getParameter("productId0");
    boolean applyToAll = (request.getParameter("applyToAll") != null);
    try {
        boolean beganTransaction = TransactionUtil.begin();
        try {
            // check for variantProductId - this will mean that we have multiple ship info to update
            if (variantProductId == null) {
                // only single product to update
                String productId = request.getParameter("productId");
                GenericValue product = EntityQuery.use(delegator).from("Product").where("productId", productId).queryOne();
                product.set("lastModifiedDate", nowTimestamp);
                product.setString("lastModifiedByUserLogin", userLogin.getString("userLoginId"));
                try {
                    product.set("productHeight", parseBigDecimalForEntity(request.getParameter("productHeight")));
                    product.set("productWidth", parseBigDecimalForEntity(request.getParameter("productWidth")));
                    product.set("productDepth", parseBigDecimalForEntity(request.getParameter("productDepth")));
                    product.set("productWeight", parseBigDecimalForEntity(request.getParameter("weight")));
                    // default unit settings for shipping parameters
                    product.set("heightUomId", "LEN_in");
                    product.set("widthUomId", "LEN_in");
                    product.set("depthUomId", "LEN_in");
                    product.set("weightUomId", "WT_oz");
                    BigDecimal floz = parseBigDecimalForEntity(request.getParameter("~floz"));
                    BigDecimal ml = parseBigDecimalForEntity(request.getParameter("~ml"));
                    BigDecimal ntwt = parseBigDecimalForEntity(request.getParameter("~ntwt"));
                    BigDecimal grams = parseBigDecimalForEntity(request.getParameter("~grams"));
                    List<GenericValue> currentProductFeatureAndAppls = EntityQuery.use(delegator).from("ProductFeatureAndAppl").where("productId", productId, "productFeatureApplTypeId", "STANDARD_FEATURE").filterByDate().queryList();
                    setOrCreateProdFeature(delegator, productId, currentProductFeatureAndAppls, "VLIQ_ozUS", "AMOUNT", floz);
                    setOrCreateProdFeature(delegator, productId, currentProductFeatureAndAppls, "VLIQ_ml", "AMOUNT", ml);
                    setOrCreateProdFeature(delegator, productId, currentProductFeatureAndAppls, "WT_g", "AMOUNT", grams);
                    setOrCreateProdFeature(delegator, productId, currentProductFeatureAndAppls, "WT_oz", "AMOUNT", ntwt);
                    product.store();
                } catch (NumberFormatException nfe) {
                    String errMsg = "Shipping Dimensions and Weights must be numbers.";
                    request.setAttribute("_ERROR_MESSAGE_", errMsg);
                    Debug.logError(nfe, errMsg, module);
                    return "error";
                }
            } else {
                // multiple products, so use a numeric suffix to get them all
                int prodIdx = 0;
                int attribIdx = 0;
                String productId = variantProductId;
                do {
                    GenericValue product = EntityQuery.use(delegator).from("Product").where("productId", productId).queryOne();
                    try {
                        product.set("productHeight", parseBigDecimalForEntity(request.getParameter("productHeight" + attribIdx)));
                        product.set("productWidth", parseBigDecimalForEntity(request.getParameter("productWidth" + attribIdx)));
                        product.set("productDepth", parseBigDecimalForEntity(request.getParameter("productDepth" + attribIdx)));
                        product.set("productWeight", parseBigDecimalForEntity(request.getParameter("weight" + attribIdx)));
                        BigDecimal floz = parseBigDecimalForEntity(request.getParameter("~floz" + attribIdx));
                        BigDecimal ml = parseBigDecimalForEntity(request.getParameter("~ml" + attribIdx));
                        BigDecimal ntwt = parseBigDecimalForEntity(request.getParameter("~ntwt" + attribIdx));
                        BigDecimal grams = parseBigDecimalForEntity(request.getParameter("~grams" + attribIdx));
                        List<GenericValue> currentProductFeatureAndAppls = EntityQuery.use(delegator).from("ProductFeatureAndAppl").where("productId", productId, "productFeatureApplTypeId", "STANDARD_FEATURE").filterByDate().queryList();
                        setOrCreateProdFeature(delegator, productId, currentProductFeatureAndAppls, "VLIQ_ozUS", "AMOUNT", floz);
                        setOrCreateProdFeature(delegator, productId, currentProductFeatureAndAppls, "VLIQ_ml", "AMOUNT", ml);
                        setOrCreateProdFeature(delegator, productId, currentProductFeatureAndAppls, "WT_g", "AMOUNT", grams);
                        setOrCreateProdFeature(delegator, productId, currentProductFeatureAndAppls, "WT_oz", "AMOUNT", ntwt);
                        product.store();
                    } catch (NumberFormatException nfe) {
                        String errMsg = "Shipping Dimensions and Weights must be numbers.";
                        request.setAttribute("_ERROR_MESSAGE_", errMsg);
                        Debug.logError(nfe, errMsg, module);
                        return "error";
                    }
                    prodIdx++;
                    if (!applyToAll) {
                        attribIdx = prodIdx;
                    }
                    productId = request.getParameter("productId" + prodIdx);
                } while (productId != null);
            }
            TransactionUtil.commit(beganTransaction);
        } catch (GenericEntityException e) {
            String errMsg = "Error updating quick admin shipping settings: " + e.toString();
            Debug.logError(e, errMsg, module);
            request.setAttribute("_ERROR_MESSAGE_", errMsg);
            TransactionUtil.rollback(beganTransaction, errMsg, e);
            return "error";
        }
    } catch (GenericTransactionException gte) {
        String errMsg = "Error updating quick admin shipping settings: " + gte.toString();
        Debug.logError(gte, errMsg, module);
        request.setAttribute("_ERROR_MESSAGE_", errMsg);
        return "error";
    }
    return "success";
}
Also used : GenericValue(org.apache.ofbiz.entity.GenericValue) Delegator(org.apache.ofbiz.entity.Delegator) GenericEntityException(org.apache.ofbiz.entity.GenericEntityException) GenericTransactionException(org.apache.ofbiz.entity.transaction.GenericTransactionException) Timestamp(java.sql.Timestamp) BigDecimal(java.math.BigDecimal)

Example 2 with GenericTransactionException

use of org.apache.ofbiz.entity.transaction.GenericTransactionException in project ofbiz-framework by apache.

the class ProductEvents method updateAllKeywords.

/**
 * Updates/adds keywords for all products
 *
 * @param request HTTPRequest object for the current request
 * @param response HTTPResponse object for the current request
 * @return String specifying the exit status of this event
 */
public static String updateAllKeywords(HttpServletRequest request, HttpServletResponse response) {
    Delegator delegator = (Delegator) request.getAttribute("delegator");
    Security security = (Security) request.getAttribute("security");
    Timestamp nowTimestamp = UtilDateTime.nowTimestamp();
    String updateMode = "CREATE";
    String errMsg = null;
    String doAll = request.getParameter("doAll");
    // check permissions before moving on...
    if (!security.hasEntityPermission("CATALOG", "_" + updateMode, request.getSession())) {
        Map<String, String> messageMap = UtilMisc.toMap("updateMode", updateMode);
        errMsg = UtilProperties.getMessage(resource, "productevents.not_sufficient_permissions", messageMap, UtilHttp.getLocale(request));
        request.setAttribute("_ERROR_MESSAGE_", errMsg);
        return "error";
    }
    EntityCondition condition = null;
    if (!"Y".equals(doAll)) {
        List<EntityCondition> condList = new LinkedList<>();
        condList.add(EntityCondition.makeCondition(EntityCondition.makeCondition("autoCreateKeywords", EntityOperator.EQUALS, null), EntityOperator.OR, EntityCondition.makeCondition("autoCreateKeywords", EntityOperator.NOT_EQUAL, "N")));
        if ("true".equals(EntityUtilProperties.getPropertyValue("prodsearch", "index.ignore.variants", delegator))) {
            condList.add(EntityCondition.makeCondition(EntityCondition.makeCondition("isVariant", EntityOperator.EQUALS, null), EntityOperator.OR, EntityCondition.makeCondition("isVariant", EntityOperator.NOT_EQUAL, "Y")));
        }
        if ("true".equals(EntityUtilProperties.getPropertyValue("prodsearch", "index.ignore.discontinued.sales", delegator))) {
            condList.add(EntityCondition.makeCondition(EntityCondition.makeCondition("salesDiscontinuationDate", EntityOperator.EQUALS, null), EntityOperator.OR, EntityCondition.makeCondition("salesDiscontinuationDate", EntityOperator.GREATER_THAN_EQUAL_TO, nowTimestamp)));
        }
        condition = EntityCondition.makeCondition(condList, EntityOperator.AND);
    } else {
        condition = EntityCondition.makeCondition(EntityCondition.makeCondition("autoCreateKeywords", EntityOperator.EQUALS, null), EntityOperator.OR, EntityCondition.makeCondition("autoCreateKeywords", EntityOperator.NOT_EQUAL, "N"));
    }
    int numProds = 0;
    int errProds = 0;
    boolean beganTx = false;
    try {
        // begin the transaction
        beganTx = TransactionUtil.begin(7200);
    } catch (GenericTransactionException gte) {
        Debug.logError(gte, "Unable to begin transaction", module);
    }
    try (EntityListIterator entityListIterator = EntityQuery.use(delegator).from("Product").where(condition).queryIterator()) {
        try {
            if (Debug.infoOn()) {
                long count = EntityQuery.use(delegator).from("Product").where(condition).queryCount();
                Debug.logInfo("========== Found " + count + " products to index ==========", module);
            }
        } catch (GenericEntityException gee) {
            Debug.logWarning(gee, gee.getMessage(), module);
            Map<String, String> messageMap = UtilMisc.toMap("gee", gee.toString());
            errMsg = UtilProperties.getMessage(resource, "productevents.error_getting_product_list", messageMap, UtilHttp.getLocale(request));
            request.setAttribute("_ERROR_MESSAGE_", errMsg);
            return "error";
        }
        GenericValue product;
        while ((product = entityListIterator.next()) != null) {
            try {
                KeywordIndex.indexKeywords(product, "Y".equals(doAll));
            } catch (GenericEntityException e) {
                Debug.logWarning("[ProductEvents.updateAllKeywords] Could not create product-keyword (write error); message: " + e.getMessage(), module);
                errProds++;
            }
            numProds++;
            if (numProds % 500 == 0) {
                Debug.logInfo("Keywords indexed for " + numProds + " so far", module);
            }
        }
    } catch (GenericEntityException e) {
        try {
            TransactionUtil.rollback(beganTx, e.getMessage(), e);
        } catch (GenericTransactionException e1) {
            Debug.logError(e1, module);
        }
        return "error";
    } catch (Throwable t) {
        Debug.logError(t, module);
        request.setAttribute("_ERROR_MESSAGE_", t.getMessage());
        try {
            TransactionUtil.rollback(beganTx, t.getMessage(), t);
        } catch (GenericTransactionException e2) {
            Debug.logError(e2, module);
        }
        return "error";
    }
    // commit the transaction
    try {
        TransactionUtil.commit(beganTx);
    } catch (GenericTransactionException e) {
        Debug.logError(e, module);
    }
    if (errProds == 0) {
        Map<String, String> messageMap = UtilMisc.toMap("numProds", Integer.toString(numProds));
        errMsg = UtilProperties.getMessage(resource, "productevents.keyword_creation_complete_for_products", messageMap, UtilHttp.getLocale(request));
        request.setAttribute("_EVENT_MESSAGE_", errMsg);
        return "success";
    } else {
        Map<String, String> messageMap = UtilMisc.toMap("numProds", Integer.toString(numProds));
        messageMap.put("errProds", Integer.toString(errProds));
        errMsg = UtilProperties.getMessage(resource, "productevents.keyword_creation_complete_for_products_with_errors", messageMap, UtilHttp.getLocale(request));
        request.setAttribute("_ERROR_MESSAGE_", errMsg);
        return "error";
    }
}
Also used : GenericValue(org.apache.ofbiz.entity.GenericValue) EntityCondition(org.apache.ofbiz.entity.condition.EntityCondition) Security(org.apache.ofbiz.security.Security) Timestamp(java.sql.Timestamp) LinkedList(java.util.LinkedList) Delegator(org.apache.ofbiz.entity.Delegator) GenericEntityException(org.apache.ofbiz.entity.GenericEntityException) GenericTransactionException(org.apache.ofbiz.entity.transaction.GenericTransactionException) EntityListIterator(org.apache.ofbiz.entity.util.EntityListIterator) HashMap(java.util.HashMap) Map(java.util.Map)

Example 3 with GenericTransactionException

use of org.apache.ofbiz.entity.transaction.GenericTransactionException in project ofbiz-framework by apache.

the class ProductEvents method updateProductQuickAdminSelFeat.

public static String updateProductQuickAdminSelFeat(HttpServletRequest request, HttpServletResponse response) {
    Delegator delegator = (Delegator) request.getAttribute("delegator");
    Timestamp nowTimestamp = UtilDateTime.nowTimestamp();
    String productId = request.getParameter("productId");
    String variantProductId = request.getParameter("productId0");
    String useImagesProdId = request.getParameter("useImages");
    String productFeatureTypeId = request.getParameter("productFeatureTypeId");
    if (UtilValidate.isEmpty(productFeatureTypeId)) {
        String errMsg = "Error: please select a ProductFeature Type to add or update variant features.";
        request.setAttribute("_ERROR_MESSAGE_", errMsg);
        return "error";
    }
    try {
        boolean beganTransaction = TransactionUtil.begin();
        try {
            GenericValue productFeatureType = EntityQuery.use(delegator).from("ProductFeatureType").where("productFeatureTypeId", productFeatureTypeId).queryOne();
            if (productFeatureType == null) {
                String errMsg = "Error: the ProductFeature Type specified was not valid and one is require to add or update variant features.";
                request.setAttribute("_ERROR_MESSAGE_", errMsg);
                return "error";
            }
            // check for variantProductId - this will mean that we have multiple variants to update
            if (variantProductId != null) {
                // multiple products, so use a numeric suffix to get them all
                int attribIdx = 0;
                GenericValue product = EntityQuery.use(delegator).from("Product").where("productId", productId).queryOne();
                do {
                    GenericValue variantProduct = EntityQuery.use(delegator).from("Product").where("productId", variantProductId).queryOne();
                    String description = request.getParameter("description" + attribIdx);
                    // blank means null, which means delete the feature application
                    if ((description != null) && (description.trim().length() < 1)) {
                        description = null;
                    }
                    Set<String> variantDescRemoveToRemoveOnVirtual = new HashSet<>();
                    checkUpdateFeatureApplByDescription(variantProductId, variantProduct, description, productFeatureTypeId, productFeatureType, "STANDARD_FEATURE", nowTimestamp, delegator, null, variantDescRemoveToRemoveOnVirtual);
                    checkUpdateFeatureApplByDescription(productId, product, description, productFeatureTypeId, productFeatureType, "SELECTABLE_FEATURE", nowTimestamp, delegator, variantDescRemoveToRemoveOnVirtual, null);
                    // update image urls
                    if ((useImagesProdId != null) && (useImagesProdId.equals(variantProductId))) {
                        product.set("smallImageUrl", variantProduct.getString("smallImageUrl"));
                        product.set("mediumImageUrl", variantProduct.getString("mediumImageUrl"));
                        product.set("largeImageUrl", null);
                        product.set("detailImageUrl", null);
                        product.store();
                    }
                    attribIdx++;
                    variantProductId = request.getParameter("productId" + attribIdx);
                } while (variantProductId != null);
            }
            TransactionUtil.commit(beganTransaction);
        } catch (GenericEntityException e) {
            String errMsg = "Error updating quick admin selectable feature settings: " + e.toString();
            Debug.logError(e, errMsg, module);
            request.setAttribute("_ERROR_MESSAGE_", errMsg);
            TransactionUtil.rollback(beganTransaction, errMsg, e);
            return "error";
        }
    } catch (GenericTransactionException gte) {
        String errMsg = "Error updating quick admin selectable feature settings: " + gte.toString();
        Debug.logError(gte, errMsg, module);
        request.setAttribute("_ERROR_MESSAGE_", errMsg);
        return "error";
    }
    return "success";
}
Also used : GenericValue(org.apache.ofbiz.entity.GenericValue) Delegator(org.apache.ofbiz.entity.Delegator) GenericEntityException(org.apache.ofbiz.entity.GenericEntityException) GenericTransactionException(org.apache.ofbiz.entity.transaction.GenericTransactionException) Timestamp(java.sql.Timestamp) HashSet(java.util.HashSet)

Example 4 with GenericTransactionException

use of org.apache.ofbiz.entity.transaction.GenericTransactionException in project ofbiz-framework by apache.

the class ProductSearchEvents method searchAddToCategory.

/**
 *  Adds the results of a search to the specified catogory
 *@param request The HTTPRequest object for the current request
 *@param response The HTTPResponse object for the current request
 *@return String specifying the exit status of this event
 */
public static String searchAddToCategory(HttpServletRequest request, HttpServletResponse response) {
    Delegator delegator = (Delegator) request.getAttribute("delegator");
    String productCategoryId = request.getParameter("SE_SEARCH_CATEGORY_ID");
    String fromDateStr = request.getParameter("fromDate");
    Timestamp fromDate = null;
    String errMsg = null;
    try {
        fromDate = Timestamp.valueOf(fromDateStr);
    } catch (RuntimeException e) {
        Map<String, String> messageMap = UtilMisc.toMap("errDateFormat", e.toString());
        errMsg = UtilProperties.getMessage(resource, "productsearchevents.fromDate_not_formatted_properly", messageMap, UtilHttp.getLocale(request));
        request.setAttribute("_ERROR_MESSAGE_", errMsg);
        return "error";
    }
    try {
        boolean beganTransaction = TransactionUtil.begin(DEFAULT_TX_TIMEOUT);
        try (EntityListIterator eli = getProductSearchResults(request)) {
            if (eli == null) {
                errMsg = UtilProperties.getMessage(resource, "productsearchevents.no_results_found_probably_error_constraints", UtilHttp.getLocale(request));
                request.setAttribute("_ERROR_MESSAGE_", errMsg);
                return "error";
            }
            GenericValue searchResultView = null;
            int numAdded = 0;
            while ((searchResultView = eli.next()) != null) {
                String productId = searchResultView.getString("mainProductId");
                GenericValue pcm = delegator.makeValue("ProductCategoryMember");
                pcm.set("productCategoryId", productCategoryId);
                pcm.set("productId", productId);
                pcm.set("fromDate", fromDate);
                pcm.create();
                numAdded++;
            }
            Map<String, String> messageMap = UtilMisc.toMap("numAdded", Integer.toString(numAdded));
            errMsg = UtilProperties.getMessage(resource, "productsearchevents.added_x_product_category_members", messageMap, UtilHttp.getLocale(request));
            request.setAttribute("_EVENT_MESSAGE_", errMsg);
        } catch (GenericEntityException e) {
            Map<String, String> messageMap = UtilMisc.toMap("errSearchResult", e.toString());
            errMsg = UtilProperties.getMessage(resource, "productsearchevents.error_getting_search_results", messageMap, UtilHttp.getLocale(request));
            Debug.logError(e, errMsg, module);
            request.setAttribute("_ERROR_MESSAGE_", errMsg);
            TransactionUtil.rollback(beganTransaction, errMsg, e);
            return "error";
        } finally {
            TransactionUtil.commit(beganTransaction);
        }
    } catch (GenericTransactionException e) {
        Map<String, String> messageMap = UtilMisc.toMap("errSearchResult", e.toString());
        errMsg = UtilProperties.getMessage(resource, "productsearchevents.error_getting_search_results", messageMap, UtilHttp.getLocale(request));
        Debug.logError(e, errMsg, module);
        request.setAttribute("_ERROR_MESSAGE_", errMsg);
        return "error";
    }
    return "success";
}
Also used : GenericValue(org.apache.ofbiz.entity.GenericValue) Delegator(org.apache.ofbiz.entity.Delegator) GenericEntityException(org.apache.ofbiz.entity.GenericEntityException) GenericTransactionException(org.apache.ofbiz.entity.transaction.GenericTransactionException) EntityListIterator(org.apache.ofbiz.entity.util.EntityListIterator) Timestamp(java.sql.Timestamp) HashMap(java.util.HashMap) Map(java.util.Map)

Example 5 with GenericTransactionException

use of org.apache.ofbiz.entity.transaction.GenericTransactionException in project ofbiz-framework by apache.

the class VariantEvents method quickAddChosenVariant.

/**
 * Creates variant products from a virtual product and a combination of selectable features
 *@param request The HTTPRequest object for the current request
 *@param response The HTTPResponse object for the current request
 *@return String specifying the exit status of this event
 */
public static String quickAddChosenVariant(HttpServletRequest request, HttpServletResponse response) {
    String errMsg = "";
    Delegator delegator = (Delegator) request.getAttribute("delegator");
    String productId = request.getParameter("productId");
    String variantProductId = request.getParameter("variantProductId");
    String featureTypeSizeStr = request.getParameter("featureTypeSize");
    if (UtilValidate.isEmpty(productId)) {
        errMsg = UtilProperties.getMessage(resource, "variantevents.productId_required_but_missing", UtilHttp.getLocale(request));
        request.setAttribute("_ERROR_MESSAGE_", errMsg);
        return "error";
    }
    if (UtilValidate.isEmpty(variantProductId)) {
        errMsg = UtilProperties.getMessage(resource, "variantevents.variantProductId_required_but_missing_enter_an_id", UtilHttp.getLocale(request));
        request.setAttribute("_ERROR_MESSAGE_", errMsg);
        return "error";
    }
    int featureTypeSize = 0;
    try {
        featureTypeSize = Integer.parseInt(featureTypeSizeStr);
    } catch (NumberFormatException e) {
        Map<String, String> messageMap = UtilMisc.toMap("featureTypeSizeStr", featureTypeSizeStr);
        errMsg = UtilProperties.getMessage(resource, "variantevents.featureTypeSize_not_number", messageMap, UtilHttp.getLocale(request));
        request.setAttribute("_ERROR_MESSAGE_", errMsg);
        return "error";
    }
    try {
        boolean beganTransacton = TransactionUtil.begin();
        try {
            // read the product, duplicate it with the given id
            GenericValue product = EntityQuery.use(delegator).from("Product").where("productId", productId).queryOne();
            if (product == null) {
                Map<String, String> messageMap = UtilMisc.toMap("productId", productId);
                errMsg = UtilProperties.getMessage(resource, "variantevents.product_not_found_with_ID", messageMap, UtilHttp.getLocale(request));
                TransactionUtil.rollback(beganTransacton, errMsg, null);
                request.setAttribute("_ERROR_MESSAGE_", errMsg);
                return "error";
            }
            // check if product exists
            GenericValue variantProduct = EntityQuery.use(delegator).from("Product").where("productId", variantProductId).queryOne();
            if (variantProduct == null) {
                // if product does not exist
                variantProduct = GenericValue.create(product);
                variantProduct.set("productId", variantProductId);
                variantProduct.set("isVirtual", "N");
                variantProduct.set("isVariant", "Y");
                variantProduct.set("primaryProductCategoryId", null);
                // create new
                variantProduct.create();
            } else {
                // if product does exist
                variantProduct.set("isVirtual", "N");
                variantProduct.set("isVariant", "Y");
                variantProduct.set("primaryProductCategoryId", null);
                // update entry
                variantProduct.store();
            }
            // add an association from productId to variantProductId of the PRODUCT_VARIANT
            GenericValue productAssoc = delegator.makeValue("ProductAssoc", UtilMisc.toMap("productId", productId, "productIdTo", variantProductId, "productAssocTypeId", "PRODUCT_VARIANT", "fromDate", UtilDateTime.nowTimestamp()));
            productAssoc.create();
            // add the selected standard features to the new product given the productFeatureIds
            for (int i = 0; i < featureTypeSize; i++) {
                String productFeatureId = request.getParameter("feature_" + i);
                if (productFeatureId == null) {
                    Map<String, String> messageMap = UtilMisc.toMap("i", Integer.toString(i));
                    errMsg = UtilProperties.getMessage(resource, "variantevents.productFeatureId_for_feature_type_number_not_found", messageMap, UtilHttp.getLocale(request));
                    TransactionUtil.rollback(beganTransacton, errMsg, null);
                    request.setAttribute("_ERROR_MESSAGE_", errMsg);
                    return "error";
                }
                GenericValue productFeature = EntityQuery.use(delegator).from("ProductFeature").where("productFeatureId", productFeatureId).queryOne();
                GenericValue productFeatureAppl = delegator.makeValue("ProductFeatureAppl", UtilMisc.toMap("productId", variantProductId, "productFeatureId", productFeatureId, "productFeatureApplTypeId", "STANDARD_FEATURE", "fromDate", UtilDateTime.nowTimestamp()));
                // set the default seq num if it's there...
                if (productFeature != null) {
                    productFeatureAppl.set("sequenceNum", productFeature.get("defaultSequenceNum"));
                }
                productFeatureAppl.create();
            }
            TransactionUtil.commit(beganTransacton);
        } catch (GenericEntityException e) {
            Map<String, String> messageMap = UtilMisc.toMap("errMessage", e.toString());
            errMsg = UtilProperties.getMessage(resource, "variantevents.entity_error_quick_add_variant_data", messageMap, UtilHttp.getLocale(request));
            TransactionUtil.rollback(beganTransacton, errMsg, null);
            Debug.logError(e, "Entity error creating quick add variant data", module);
            request.setAttribute("_ERROR_MESSAGE_", errMsg);
            return "error";
        }
    } catch (GenericTransactionException e) {
        Debug.logError(e, "Transaction error creating quick add variant data", module);
        Map<String, String> messageMap = UtilMisc.toMap("errMessage", e.toString());
        errMsg = UtilProperties.getMessage(resource, "variantevents.transaction_error_quick_add_variant_data", messageMap, UtilHttp.getLocale(request));
        request.setAttribute("_ERROR_MESSAGE_", errMsg);
        return "error";
    }
    Map<String, String> messageMap = UtilMisc.toMap("variantProductId", variantProductId);
    String sucMsg = UtilProperties.getMessage(resource, "variantevents.successfully_created_variant_product_with_id", messageMap, UtilHttp.getLocale(request));
    request.setAttribute("_EVENT_MESSAGE_", sucMsg);
    return "success";
}
Also used : GenericValue(org.apache.ofbiz.entity.GenericValue) Delegator(org.apache.ofbiz.entity.Delegator) GenericEntityException(org.apache.ofbiz.entity.GenericEntityException) GenericTransactionException(org.apache.ofbiz.entity.transaction.GenericTransactionException) Map(java.util.Map)

Aggregations

GenericTransactionException (org.apache.ofbiz.entity.transaction.GenericTransactionException)49 GenericValue (org.apache.ofbiz.entity.GenericValue)37 GenericEntityException (org.apache.ofbiz.entity.GenericEntityException)35 Delegator (org.apache.ofbiz.entity.Delegator)24 Locale (java.util.Locale)18 EntityListIterator (org.apache.ofbiz.entity.util.EntityListIterator)18 HashMap (java.util.HashMap)14 Timestamp (java.sql.Timestamp)13 GenericServiceException (org.apache.ofbiz.service.GenericServiceException)12 LocalDispatcher (org.apache.ofbiz.service.LocalDispatcher)12 Transaction (javax.transaction.Transaction)11 Map (java.util.Map)10 IOException (java.io.IOException)9 LinkedList (java.util.LinkedList)9 GeneralException (org.apache.ofbiz.base.util.GeneralException)6 EntityCondition (org.apache.ofbiz.entity.condition.EntityCondition)5 ModelEntity (org.apache.ofbiz.entity.model.ModelEntity)5 EntityQuery (org.apache.ofbiz.entity.util.EntityQuery)5 HttpSession (javax.servlet.http.HttpSession)4 List (java.util.List)3