Search in sources :

Example 11 with GenericPK

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

the class ShoppingCartItem method confirmPromoRuleUse.

public synchronized void confirmPromoRuleUse(String productPromoId, String productPromoRuleId) {
    Iterator<Map.Entry<GenericPK, BigDecimal>> entryIter = this.quantityUsedPerPromoCandidate.entrySet().iterator();
    while (entryIter.hasNext()) {
        Map.Entry<GenericPK, BigDecimal> entry = entryIter.next();
        GenericPK productPromoCondActionPK = entry.getKey();
        BigDecimal quantityUsed = entry.getValue();
        if (productPromoId.equals(productPromoCondActionPK.getString("productPromoId")) && productPromoRuleId.equals(productPromoCondActionPK.getString("productPromoRuleId"))) {
            entryIter.remove();
            BigDecimal existingValue = this.quantityUsedPerPromoActual.get(productPromoCondActionPK);
            if (existingValue == null) {
                this.quantityUsedPerPromoActual.put(productPromoCondActionPK, quantityUsed);
            } else {
                this.quantityUsedPerPromoActual.put(productPromoCondActionPK, quantityUsed.add(existingValue));
            }
        }
    }
}
Also used : GenericPK(org.apache.ofbiz.entity.GenericPK) HashMap(java.util.HashMap) Map(java.util.Map) BigDecimal(java.math.BigDecimal)

Example 12 with GenericPK

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

the class ContentWorker method logList.

public static StringBuilder logList(StringBuilder s, String lbl, List<Object> lst, StringBuilder indent) {
    String sep = ":";
    String eol = "\n";
    String spc = "";
    if (lst == null) {
        return s;
    }
    int sz = lst.size();
    if (lbl != null)
        s.append(lbl);
    s.append("=").append(indent).append("==> sz:").append(sz).append(eol);
    for (Object obj : lst) {
        s.append(spc);
        if (obj instanceof GenericValue) {
            GenericValue gv = (GenericValue) obj;
            GenericPK pk = gv.getPrimaryKey();
            indent.append(' ');
            logMap(s, "MAP[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[]", 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 13 with GenericPK

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

the class ProductionRunServices method updateProductionRunTask.

public static Map<String, Object> updateProductionRunTask(DispatchContext ctx, Map<String, ? extends Object> context) {
    Map<String, Object> result = new HashMap<String, Object>();
    Delegator delegator = ctx.getDelegator();
    LocalDispatcher dispatcher = ctx.getDispatcher();
    Locale locale = (Locale) context.get("locale");
    GenericValue userLogin = (GenericValue) context.get("userLogin");
    // Mandatory input fields
    String productionRunId = (String) context.get("productionRunId");
    String workEffortId = (String) context.get("productionRunTaskId");
    String partyId = (String) context.get("partyId");
    if (UtilValidate.isEmpty(partyId)) {
        partyId = userLogin.getString("partyId");
    }
    // Optional input fields
    Timestamp fromDate = (Timestamp) context.get("fromDate");
    Timestamp toDate = (Timestamp) context.get("toDate");
    BigDecimal addQuantityProduced = (BigDecimal) context.get("addQuantityProduced");
    BigDecimal addQuantityRejected = (BigDecimal) context.get("addQuantityRejected");
    BigDecimal addSetupTime = (BigDecimal) context.get("addSetupTime");
    BigDecimal addTaskTime = (BigDecimal) context.get("addTaskTime");
    String comments = (String) context.get("comments");
    Boolean issueRequiredComponents = (Boolean) context.get("issueRequiredComponents");
    Map<GenericPK, Object> componentsLocationMap = UtilGenerics.checkMap(context.get("componentsLocationMap"));
    if (issueRequiredComponents == null) {
        issueRequiredComponents = Boolean.FALSE;
    }
    if (fromDate == null) {
        fromDate = UtilDateTime.nowTimestamp();
    }
    if (toDate == null) {
        toDate = UtilDateTime.nowTimestamp();
    }
    if (addQuantityProduced == null) {
        addQuantityProduced = BigDecimal.ZERO;
    }
    if (addQuantityRejected == null) {
        addQuantityRejected = BigDecimal.ZERO;
    }
    if (comments == null) {
        comments = "";
    }
    ProductionRun productionRun = new ProductionRun(productionRunId, delegator, dispatcher);
    if (!productionRun.exist()) {
        return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingProductionRunNotExists", locale));
    }
    List<GenericValue> tasks = productionRun.getProductionRunRoutingTasks();
    GenericValue theTask = null;
    GenericValue oneTask = null;
    for (int i = 0; i < tasks.size(); i++) {
        oneTask = tasks.get(i);
        if (oneTask.getString("workEffortId").equals(workEffortId)) {
            theTask = oneTask;
            break;
        }
    }
    if (theTask == null) {
        return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingProductionRunTaskNotExists", locale));
    }
    String currentStatusId = theTask.getString("currentStatusId");
    if (!"PRUN_RUNNING".equals(currentStatusId)) {
        return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingProductionRunTaskNotRunning", locale));
    }
    BigDecimal quantityProduced = theTask.getBigDecimal("quantityProduced");
    if (quantityProduced == null) {
        quantityProduced = BigDecimal.ZERO;
    }
    BigDecimal quantityRejected = theTask.getBigDecimal("quantityRejected");
    if (quantityRejected == null) {
        quantityRejected = BigDecimal.ZERO;
    }
    BigDecimal totalQuantityProduced = quantityProduced.add(addQuantityProduced);
    BigDecimal totalQuantityRejected = quantityRejected.add(addQuantityRejected);
    if (issueRequiredComponents.booleanValue() && addQuantityProduced.compareTo(ZERO) > 0) {
        BigDecimal quantityToProduce = theTask.getBigDecimal("quantityToProduce");
        if (quantityToProduce == null) {
            quantityToProduce = BigDecimal.ZERO;
        }
        if (quantityToProduce.compareTo(ZERO) > 0) {
            try {
                List<GenericValue> components = theTask.getRelated("WorkEffortGoodStandard", null, null, false);
                for (GenericValue component : components) {
                    BigDecimal totalRequiredMaterialQuantity = component.getBigDecimal("estimatedQuantity").multiply(totalQuantityProduced).divide(quantityToProduce, rounding);
                    // now get the units that have been already issued and subtract them
                    List<GenericValue> issuances = EntityQuery.use(delegator).from("WorkEffortAndInventoryAssign").where("workEffortId", workEffortId, "productId", component.get("productId")).queryList();
                    BigDecimal totalIssued = BigDecimal.ZERO;
                    for (GenericValue issuance : issuances) {
                        BigDecimal issued = issuance.getBigDecimal("quantity");
                        if (issued != null) {
                            totalIssued = totalIssued.add(issued);
                        }
                    }
                    BigDecimal requiredQuantity = totalRequiredMaterialQuantity.subtract(totalIssued);
                    if (requiredQuantity.compareTo(ZERO) > 0) {
                        GenericPK key = component.getPrimaryKey();
                        Map<String, Object> componentsLocation = null;
                        if (componentsLocationMap != null) {
                            componentsLocation = UtilGenerics.checkMap(componentsLocationMap.get(key));
                        }
                        Map<String, Object> serviceContext = UtilMisc.toMap("workEffortId", workEffortId, "productId", component.getString("productId"), "fromDate", component.getTimestamp("fromDate"));
                        serviceContext.put("quantity", requiredQuantity);
                        if (componentsLocation != null) {
                            serviceContext.put("locationSeqId", componentsLocation.get("locationSeqId"));
                            serviceContext.put("secondaryLocationSeqId", componentsLocation.get("secondaryLocationSeqId"));
                            serviceContext.put("failIfItemsAreNotAvailable", componentsLocation.get("failIfItemsAreNotAvailable"));
                        }
                        serviceContext.put("userLogin", userLogin);
                        Map<String, Object> serviceResult = dispatcher.runSync("issueProductionRunTaskComponent", serviceContext);
                        if (ServiceUtil.isError(serviceResult)) {
                            return ServiceUtil.returnError(ServiceUtil.getErrorMessage(serviceResult));
                        }
                    }
                }
            } catch (GenericEntityException | GenericServiceException e) {
                String errMsg = "Problem calling the updateProductionRunTaskStatus service";
                Debug.logError(e, errMsg, module);
                return ServiceUtil.returnError(errMsg);
            }
        }
    }
    // Create a new TimeEntry
    try {
        Map<String, Object> serviceContext = new HashMap<String, Object>();
        serviceContext.clear();
        serviceContext.put("workEffortId", workEffortId);
        if (addTaskTime != null) {
            Double actualMilliSeconds = theTask.getDouble("actualMilliSeconds");
            if (actualMilliSeconds == null) {
                actualMilliSeconds = Double.valueOf(0);
            }
            serviceContext.put("actualMilliSeconds", Double.valueOf(actualMilliSeconds.doubleValue() + addTaskTime.doubleValue()));
        }
        if (addSetupTime != null) {
            Double actualSetupMillis = theTask.getDouble("actualSetupMillis");
            if (actualSetupMillis == null) {
                actualSetupMillis = Double.valueOf(0);
            }
            serviceContext.put("actualSetupMillis", Double.valueOf(actualSetupMillis.doubleValue() + addSetupTime.doubleValue()));
        }
        serviceContext.put("quantityProduced", totalQuantityProduced);
        serviceContext.put("quantityRejected", totalQuantityRejected);
        serviceContext.put("userLogin", userLogin);
        Map<String, Object> serviceResult = dispatcher.runSync("updateWorkEffort", serviceContext);
        if (ServiceUtil.isError(serviceResult)) {
            return ServiceUtil.returnError(ServiceUtil.getErrorMessage(serviceResult));
        }
    } catch (GenericServiceException exc) {
        return ServiceUtil.returnError(exc.getMessage());
    } catch (Exception exc) {
        return ServiceUtil.returnError(exc.getMessage());
    }
    return result;
}
Also used : Locale(java.util.Locale) GenericValue(org.apache.ofbiz.entity.GenericValue) LocalDispatcher(org.apache.ofbiz.service.LocalDispatcher) GenericPK(org.apache.ofbiz.entity.GenericPK) HashMap(java.util.HashMap) Timestamp(java.sql.Timestamp) BigDecimal(java.math.BigDecimal) GenericServiceException(org.apache.ofbiz.service.GenericServiceException) GenericEntityException(org.apache.ofbiz.entity.GenericEntityException) GeneralException(org.apache.ofbiz.base.util.GeneralException) Delegator(org.apache.ofbiz.entity.Delegator) GenericEntityException(org.apache.ofbiz.entity.GenericEntityException) GenericServiceException(org.apache.ofbiz.service.GenericServiceException)

Example 14 with GenericPK

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

the class ContentManagementWorker method getCurrentValue.

public static void getCurrentValue(HttpServletRequest request, Delegator delegator) {
    HttpSession session = request.getSession();
    Map<String, GenericPK> currentEntityMap = UtilGenerics.checkMap(session.getAttribute("currentEntityMap"));
    if (currentEntityMap == null) {
        currentEntityMap = new HashMap<String, GenericPK>();
        session.setAttribute("currentEntityMap", currentEntityMap);
    }
    Map<String, Object> paramMap = UtilHttp.getParameterMap(request);
    String entityName = (String) paramMap.get("entityName");
    if (UtilValidate.isEmpty(entityName)) {
        entityName = (String) request.getAttribute("entityName");
    }
    GenericPK cachedPK = null;
    if (UtilValidate.isNotEmpty(entityName)) {
        cachedPK = currentEntityMap.get(entityName);
    }
    getCurrentValueWithCachedPK(request, delegator, cachedPK, entityName);
    GenericPK currentPK = (GenericPK) request.getAttribute("currentPK");
    currentEntityMap.put(entityName, currentPK);
}
Also used : GenericPK(org.apache.ofbiz.entity.GenericPK) HttpSession(javax.servlet.http.HttpSession)

Example 15 with GenericPK

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

the class XmlSerializer method serializeSingle.

public static Element serializeSingle(Object object, Document document) throws SerializeException {
    if (document == null) {
        return null;
    }
    if (object == null) {
        return makeElement("null", null, document);
    }
    // - Standard Objects -
    if (object instanceof String) {
        return makeElement("std-String", object, document);
    } else if (object instanceof Integer) {
        return makeElement("std-Integer", object, document);
    } else if (object instanceof Long) {
        return makeElement("std-Long", object, document);
    } else if (object instanceof Float) {
        return makeElement("std-Float", object, document);
    } else if (object instanceof Double) {
        return makeElement("std-Double", object, document);
    } else if (object instanceof Boolean) {
        return makeElement("std-Boolean", object, document);
    } else if (object instanceof Locale) {
        return makeElement("std-Locale", object, document);
    } else if (object instanceof BigDecimal) {
        String stringValue = ((BigDecimal) object).setScale(10, RoundingMode.HALF_UP).toString();
        return makeElement("std-BigDecimal", stringValue, document);
    // - SQL Objects -
    } else if (object instanceof java.sql.Timestamp) {
        String stringValue = object.toString().replace(' ', 'T');
        return makeElement("sql-Timestamp", stringValue, document);
    } else if (object instanceof java.sql.Date) {
        return makeElement("sql-Date", object, document);
    } else if (object instanceof java.sql.Time) {
        return makeElement("sql-Time", object, document);
    } else if (object instanceof java.util.Date) {
        // NOTE: make sure this is AFTER the java.sql date/time objects since they inherit from java.util.Date
        DateFormat formatter = getDateFormat();
        String stringValue = null;
        synchronized (formatter) {
            stringValue = formatter.format((java.util.Date) object);
        }
        return makeElement("std-Date", stringValue, document);
    // return makeElement("std-Date", object, document);
    } else if (object instanceof Collection<?>) {
        // - Collections -
        String elementName = null;
        // these ARE order sensitive; for instance Stack extends Vector, so if Vector were first we would lose the stack part
        if (object instanceof ArrayList<?>) {
            elementName = "col-ArrayList";
        } else if (object instanceof LinkedList<?>) {
            elementName = "col-LinkedList";
        } else if (object instanceof Stack<?>) {
            elementName = "col-Stack";
        } else if (object instanceof Vector<?>) {
            elementName = "col-Vector";
        } else if (object instanceof TreeSet<?>) {
            elementName = "col-TreeSet";
        } else if (object instanceof HashSet<?>) {
            elementName = "col-HashSet";
        } else {
            // no specific type found, do general Collection, will deserialize as LinkedList
            elementName = "col-Collection";
        }
        Collection<?> value = UtilGenerics.cast(object);
        Element element = document.createElement(elementName);
        Iterator<?> iter = value.iterator();
        while (iter.hasNext()) {
            element.appendChild(serializeSingle(iter.next(), document));
        }
        return element;
    } else if (object instanceof GenericPK) {
        // Do GenericEntity objects as a special case, use std XML import/export routines
        GenericPK value = (GenericPK) object;
        return value.makeXmlElement(document, "eepk-");
    } else if (object instanceof GenericValue) {
        GenericValue value = (GenericValue) object;
        return value.makeXmlElement(document, "eeval-");
    } else if (object instanceof Map<?, ?>) {
        // - Maps -
        String elementName = null;
        // these ARE order sensitive; for instance Properties extends Hashtable, so if Hashtable were first we would lose the Properties part
        if (object instanceof HashMap<?, ?>) {
            elementName = "map-HashMap";
        } else if (object instanceof Properties) {
            elementName = "map-Properties";
        } else if (object instanceof Hashtable<?, ?>) {
            elementName = "map-Hashtable";
        } else if (object instanceof WeakHashMap<?, ?>) {
            elementName = "map-WeakHashMap";
        } else if (object instanceof TreeMap<?, ?>) {
            elementName = "map-TreeMap";
        } else {
            // serialize as a simple Map implementation if nothing else applies, these will deserialize as a HashMap
            elementName = "map-Map";
        }
        Element element = document.createElement(elementName);
        Map<?, ?> value = UtilGenerics.cast(object);
        Iterator<Map.Entry<?, ?>> iter = UtilGenerics.cast(value.entrySet().iterator());
        while (iter.hasNext()) {
            Map.Entry<?, ?> entry = iter.next();
            Element entryElement = document.createElement("map-Entry");
            element.appendChild(entryElement);
            Element key = document.createElement("map-Key");
            entryElement.appendChild(key);
            key.appendChild(serializeSingle(entry.getKey(), document));
            Element mapValue = document.createElement("map-Value");
            entryElement.appendChild(mapValue);
            mapValue.appendChild(serializeSingle(entry.getValue(), document));
        }
        return element;
    }
    return serializeCustom(object, document);
}
Also used : Locale(java.util.Locale) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) Properties(java.util.Properties) TreeSet(java.util.TreeSet) Iterator(java.util.Iterator) GenericValue(org.apache.ofbiz.entity.GenericValue) GenericPK(org.apache.ofbiz.entity.GenericPK) BigDecimal(java.math.BigDecimal) Stack(java.util.Stack) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) Collection(java.util.Collection) HashMap(java.util.HashMap) Map(java.util.Map) WeakHashMap(java.util.WeakHashMap) TreeMap(java.util.TreeMap) WeakHashMap(java.util.WeakHashMap)

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