Search in sources :

Example 6 with GenericPK

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

the class ContentWorker method logMap.

public static StringBuilder logMap(StringBuilder s, String lbl, Map<String, Object> map, StringBuilder indent) {
    String sep = ":";
    String eol = "\n";
    String spc = "";
    if (lbl != null) {
        s.append(lbl);
    }
    s.append("=").append(indent).append("==>").append(eol);
    for (String key : map.keySet()) {
        if ("request response session".indexOf(key) < 0) {
            Object obj = map.get(key);
            s.append(spc).append(key).append(sep);
            if (obj instanceof GenericValue) {
                GenericValue gv = (GenericValue) obj;
                GenericPK pk = gv.getPrimaryKey();
                indent.append(' ');
                logMap(s, "GMAP[" + key + " name:" + pk.getEntityName() + "]", pk, indent);
                indent.setLength(indent.length() - 1);
            } else if (obj instanceof List<?>) {
                indent.append(' ');
                logList(s, "LIST[" + ((List<?>) obj).size() + "]", UtilGenerics.checkList(obj), indent);
                indent.setLength(indent.length() - 1);
            } else if (obj instanceof Map<?, ?>) {
                indent.append(' ');
                logMap(s, "MAP[" + key + "]", UtilGenerics.<String, Object>checkMap(obj), indent);
                indent.setLength(indent.length() - 1);
            } else if (obj != null) {
                s.append(obj).append(sep).append(obj.getClass()).append(eol);
            } else {
                s.append(eol);
            }
        }
    }
    return s.append(eol).append(eol);
}
Also used : GenericValue(org.apache.ofbiz.entity.GenericValue) GenericPK(org.apache.ofbiz.entity.GenericPK) EntityConditionList(org.apache.ofbiz.entity.condition.EntityConditionList) LinkedList(java.util.LinkedList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map)

Example 7 with GenericPK

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

the class ProductionRunEvents method productionRunDeclareAndProduce.

public static String productionRunDeclareAndProduce(HttpServletRequest request, HttpServletResponse response) {
    HttpSession session = request.getSession();
    Delegator delegator = (Delegator) request.getAttribute("delegator");
    LocalDispatcher dispatcher = (LocalDispatcher) request.getAttribute("dispatcher");
    GenericValue userLogin = (GenericValue) session.getAttribute("userLogin");
    Map<String, Object> parameters = UtilHttp.getParameterMap(request);
    BigDecimal quantity = null;
    try {
        quantity = new BigDecimal((String) parameters.get("quantity"));
    } catch (NumberFormatException nfe) {
        String errMsg = "Invalid format for quantity field: " + nfe.toString();
        Debug.logError(nfe, errMsg, module);
        request.setAttribute("_ERROR_MESSAGE_", errMsg);
        return "error";
    }
    Collection<Map<String, Object>> componentRows = UtilHttp.parseMultiFormData(parameters);
    Map<GenericPK, Object> componentsLocationMap = new HashMap<GenericPK, Object>();
    for (Map<String, Object> componentRow : componentRows) {
        Timestamp fromDate = null;
        try {
            fromDate = Timestamp.valueOf((String) componentRow.get("fromDate"));
        } catch (IllegalArgumentException iae) {
            String errMsg = "Invalid format for date field: " + iae.toString();
            Debug.logError(iae, errMsg, module);
            request.setAttribute("_ERROR_MESSAGE_", errMsg);
            return "error";
        }
        GenericPK key = delegator.makePK("WorkEffortGoodStandard", UtilMisc.<String, Object>toMap("workEffortId", (String) componentRow.get("productionRunTaskId"), "productId", (String) componentRow.get("productId"), "fromDate", fromDate, "workEffortGoodStdTypeId", "PRUNT_PROD_NEEDED"));
        componentsLocationMap.put(key, UtilMisc.<String, Object>toMap("locationSeqId", (String) componentRow.get("locationSeqId"), "secondaryLocationSeqId", (String) componentRow.get("secondaryLocationSeqId"), "failIfItemsAreNotAvailable", (String) componentRow.get("failIfItemsAreNotAvailable")));
    }
    try {
        Map<String, Object> inputMap = UtilMisc.<String, Object>toMap("workEffortId", parameters.get("workEffortId"), "inventoryItemTypeId", parameters.get("inventoryItemTypeId"));
        inputMap.put("componentsLocationMap", componentsLocationMap);
        inputMap.put("quantity", quantity);
        inputMap.put("lotId", parameters.get("lotId"));
        inputMap.put("userLogin", userLogin);
        Map<String, Object> result = dispatcher.runSync("productionRunDeclareAndProduce", inputMap);
        if (ServiceUtil.isError(result)) {
            String errorMessage = ServiceUtil.getErrorMessage(result);
            request.setAttribute("_ERROR_MESSAGE_", errorMessage);
            Debug.logError(errorMessage, module);
            return "error";
        }
    } catch (GenericServiceException e) {
        String errMsg = "Error issuing materials: " + e.toString();
        Debug.logError(e, errMsg, module);
        request.setAttribute("_ERROR_MESSAGE_", errMsg);
        return "error";
    }
    return "success";
}
Also used : GenericValue(org.apache.ofbiz.entity.GenericValue) LocalDispatcher(org.apache.ofbiz.service.LocalDispatcher) GenericPK(org.apache.ofbiz.entity.GenericPK) HashMap(java.util.HashMap) HttpSession(javax.servlet.http.HttpSession) Timestamp(java.sql.Timestamp) BigDecimal(java.math.BigDecimal) Delegator(org.apache.ofbiz.entity.Delegator) GenericServiceException(org.apache.ofbiz.service.GenericServiceException) HashMap(java.util.HashMap) Map(java.util.Map)

Example 8 with GenericPK

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

the class LayoutEvents method copyToClip.

public static String copyToClip(HttpServletRequest request, HttpServletResponse response) {
    Delegator delegator = (Delegator) request.getAttribute("delegator");
    Map<String, Object> paramMap = UtilHttp.getParameterMap(request);
    String entityName = (String) paramMap.get("entityName");
    Locale locale = UtilHttp.getLocale(request);
    if (UtilValidate.isEmpty(entityName)) {
        String errMsg = UtilProperties.getMessage(LayoutEvents.err_resource, "layoutEvents.entityname_empty", locale);
        request.setAttribute("_ERROR_MESSAGE_", errMsg);
        return "error";
    }
    GenericValue v = delegator.makeValue(entityName);
    GenericPK passedPK = v.getPrimaryKey();
    Collection<String> keyColl = passedPK.getAllKeys();
    for (String attrName : keyColl) {
        String attrVal = (String) request.getAttribute(attrName);
        if (attrVal == null) {
            attrVal = (String) paramMap.get(attrName);
        }
        if (Debug.verboseOn())
            Debug.logVerbose("in copyToClip, attrName:" + attrName, "");
        if (Debug.verboseOn())
            Debug.logVerbose("in copyToClip, attrVal:" + attrVal, "");
        if (UtilValidate.isNotEmpty(attrVal)) {
            passedPK.put(attrName, attrVal);
        } else {
            String errMsg = UtilProperties.getMessage(LayoutEvents.err_resource, "layoutEvents.empty", locale);
            request.setAttribute("_ERROR_MESSAGE_", attrName + " " + errMsg);
            return "error";
        }
    }
    ContentManagementWorker.mruAdd(request, passedPK);
    return "success";
}
Also used : Locale(java.util.Locale) GenericValue(org.apache.ofbiz.entity.GenericValue) GenericPK(org.apache.ofbiz.entity.GenericPK) Delegator(org.apache.ofbiz.entity.Delegator)

Example 9 with GenericPK

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

the class ShoppingCartEvents method setDesiredAlternateGwpProductId.

/**
 * For GWP Promotions with multiple alternatives, selects an alternative to the current GWP
 */
public static String setDesiredAlternateGwpProductId(HttpServletRequest request, HttpServletResponse response) {
    ShoppingCart cart = getCartObject(request);
    Delegator delegator = (Delegator) request.getAttribute("delegator");
    LocalDispatcher dispatcher = (LocalDispatcher) request.getAttribute("dispatcher");
    String alternateGwpProductId = request.getParameter("alternateGwpProductId");
    String alternateGwpLineStr = request.getParameter("alternateGwpLine");
    Locale locale = UtilHttp.getLocale(request);
    if (UtilValidate.isEmpty(alternateGwpProductId)) {
        request.setAttribute("_ERROR_MESSAGE_", UtilProperties.getMessage(resource_error, "OrderCouldNotSelectAlternateGiftNoAlternateGwpProductIdPassed", locale));
        return "error";
    }
    if (UtilValidate.isEmpty(alternateGwpLineStr)) {
        request.setAttribute("_ERROR_MESSAGE_", UtilProperties.getMessage(resource_error, "OrderCouldNotSelectAlternateGiftNoAlternateGwpLinePassed", locale));
        return "error";
    }
    int alternateGwpLine = 0;
    try {
        alternateGwpLine = Integer.parseInt(alternateGwpLineStr);
    } catch (Exception e) {
        request.setAttribute("_ERROR_MESSAGE_", UtilProperties.getMessage(resource_error, "OrderCouldNotSelectAlternateGiftAlternateGwpLineIsNotAValidNumber", locale));
        return "error";
    }
    ShoppingCartItem cartLine = cart.findCartItem(alternateGwpLine);
    if (cartLine == null) {
        request.setAttribute("_ERROR_MESSAGE_", "Could not select alternate gift, no cart line item found for #" + alternateGwpLine + ".");
        return "error";
    }
    if (cartLine.getIsPromo()) {
        // note that there should just be one promo adjustment, the reversal of the GWP, so use that to get the promo action key
        Iterator<GenericValue> checkOrderAdjustments = UtilMisc.toIterator(cartLine.getAdjustments());
        while (checkOrderAdjustments != null && checkOrderAdjustments.hasNext()) {
            GenericValue checkOrderAdjustment = checkOrderAdjustments.next();
            if (UtilValidate.isNotEmpty(checkOrderAdjustment.getString("productPromoId")) && UtilValidate.isNotEmpty(checkOrderAdjustment.getString("productPromoRuleId")) && UtilValidate.isNotEmpty(checkOrderAdjustment.getString("productPromoActionSeqId"))) {
                GenericPK productPromoActionPk = delegator.makeValidValue("ProductPromoAction", checkOrderAdjustment).getPrimaryKey();
                cart.setDesiredAlternateGiftByAction(productPromoActionPk, alternateGwpProductId);
                if ("SALES_ORDER".equals(cart.getOrderType())) {
                    org.apache.ofbiz.order.shoppingcart.product.ProductPromoWorker.doPromotions(cart, dispatcher);
                }
                return "success";
            }
        }
    }
    request.setAttribute("_ERROR_MESSAGE_", "Could not select alternate gift, cart line item found for #" + alternateGwpLine + " does not appear to be a valid promotional gift.");
    return "error";
}
Also used : Locale(java.util.Locale) GenericValue(org.apache.ofbiz.entity.GenericValue) LocalDispatcher(org.apache.ofbiz.service.LocalDispatcher) GenericPK(org.apache.ofbiz.entity.GenericPK) Delegator(org.apache.ofbiz.entity.Delegator) GenericServiceException(org.apache.ofbiz.service.GenericServiceException) GenericEntityException(org.apache.ofbiz.entity.GenericEntityException)

Example 10 with GenericPK

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

the class ShoppingCartItem method getPromoQuantityCandidateUse.

public BigDecimal getPromoQuantityCandidateUse(GenericValue productPromoCondAction) {
    GenericPK productPromoCondActionPK = productPromoCondAction.getPrimaryKey();
    BigDecimal existingValue = this.quantityUsedPerPromoCandidate.get(productPromoCondActionPK);
    if (existingValue == null) {
        return BigDecimal.ZERO;
    }
    return existingValue;
}
Also used : GenericPK(org.apache.ofbiz.entity.GenericPK) BigDecimal(java.math.BigDecimal)

Aggregations

GenericPK (org.apache.ofbiz.entity.GenericPK)24 GenericValue (org.apache.ofbiz.entity.GenericValue)17 HashMap (java.util.HashMap)11 BigDecimal (java.math.BigDecimal)9 Delegator (org.apache.ofbiz.entity.Delegator)8 Map (java.util.Map)7 GenericEntityException (org.apache.ofbiz.entity.GenericEntityException)7 Locale (java.util.Locale)5 GenericServiceException (org.apache.ofbiz.service.GenericServiceException)4 LocalDispatcher (org.apache.ofbiz.service.LocalDispatcher)4 ModelEntity (org.apache.ofbiz.entity.model.ModelEntity)3 Timestamp (java.sql.Timestamp)2 LinkedList (java.util.LinkedList)2 List (java.util.List)2 HttpSession (javax.servlet.http.HttpSession)2 GeneralException (org.apache.ofbiz.base.util.GeneralException)2 EntityCondition (org.apache.ofbiz.entity.condition.EntityCondition)2 EntityConditionList (org.apache.ofbiz.entity.condition.EntityConditionList)2 DateFormat (java.text.DateFormat)1 SimpleDateFormat (java.text.SimpleDateFormat)1