Search in sources :

Example 81 with GenericValue

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

the class SupplierProductServices method getSuppliersForProduct.

/*
     * Parameters: productId, partyId, currencyUomId, quantity
     * Result: a List of SupplierProduct entities for productId,
     *         filtered by date and optionally by partyId, ordered with lowest price first
     */
public static Map<String, Object> getSuppliersForProduct(DispatchContext dctx, Map<String, ? extends Object> context) {
    Map<String, Object> results;
    Delegator delegator = dctx.getDelegator();
    GenericValue product = null;
    String productId = (String) context.get("productId");
    String partyId = (String) context.get("partyId");
    String currencyUomId = (String) context.get("currencyUomId");
    BigDecimal quantity = (BigDecimal) context.get("quantity");
    String canDropShip = (String) context.get("canDropShip");
    try {
        product = EntityQuery.use(delegator).from("Product").where("productId", productId).cache().queryOne();
        if (product == null) {
            results = ServiceUtil.returnSuccess();
            results.put("supplierProducts", null);
            return results;
        }
        List<GenericValue> supplierProducts = product.getRelated("SupplierProduct", null, null, true);
        // if there were no related SupplierProduct entities and the item is a variant, then get the SupplierProducts of the virtual parent product
        if (supplierProducts.size() == 0 && product.getString("isVariant") != null && "Y".equals(product.getString("isVariant"))) {
            String virtualProductId = ProductWorker.getVariantVirtualId(product);
            GenericValue virtualProduct = EntityQuery.use(delegator).from("Product").where("productId", virtualProductId).cache().queryOne();
            if (virtualProduct != null) {
                supplierProducts = virtualProduct.getRelated("SupplierProduct", null, null, true);
            }
        }
        // filter the list by date
        supplierProducts = EntityUtil.filterByDate(supplierProducts, UtilDateTime.nowTimestamp(), "availableFromDate", "availableThruDate", true);
        // filter the list down by the partyId if one is provided
        if (partyId != null) {
            supplierProducts = EntityUtil.filterByAnd(supplierProducts, UtilMisc.toMap("partyId", partyId));
        }
        // filter the list down by the currencyUomId if one is provided
        if (currencyUomId != null) {
            supplierProducts = EntityUtil.filterByAnd(supplierProducts, UtilMisc.toMap("currencyUomId", currencyUomId));
        }
        // filter the list down by the minimumOrderQuantity if one is provided
        if (quantity != null) {
            // minimumOrderQuantity
            supplierProducts = EntityUtil.filterByCondition(supplierProducts, EntityCondition.makeCondition("minimumOrderQuantity", EntityOperator.LESS_THAN_EQUAL_TO, quantity));
        }
        // filter the list down by the canDropShip if one is provided
        if (canDropShip != null) {
            supplierProducts = EntityUtil.filterByAnd(supplierProducts, UtilMisc.toMap("canDropShip", canDropShip));
        }
        // sort resulting list of SupplierProduct entities by price in ASCENDING order
        supplierProducts = EntityUtil.orderBy(supplierProducts, UtilMisc.toList("lastPrice ASC"));
        results = ServiceUtil.returnSuccess();
        results.put("supplierProducts", supplierProducts);
    } catch (GenericEntityException ex) {
        Debug.logError(ex, ex.getMessage(), module);
        return ServiceUtil.returnError(ex.getMessage());
    }
    return results;
}
Also used : GenericValue(org.apache.ofbiz.entity.GenericValue) Delegator(org.apache.ofbiz.entity.Delegator) GenericEntityException(org.apache.ofbiz.entity.GenericEntityException) BigDecimal(java.math.BigDecimal)

Example 82 with GenericValue

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

the class VerifyPickSession method checkVerifiedQty.

protected void checkVerifiedQty(String orderId, Locale locale) throws GeneralException {
    BigDecimal verifiedQty = BigDecimal.ZERO;
    BigDecimal orderedQty = BigDecimal.ZERO;
    List<GenericValue> orderItems = this.getDelegator().findByAnd("OrderItem", UtilMisc.toMap("orderId", orderId, "statusId", "ITEM_APPROVED"), null, false);
    for (GenericValue orderItem : orderItems) {
        orderedQty = orderedQty.add(orderItem.getBigDecimal("quantity"));
    }
    for (VerifyPickSessionRow pickRow : this.getPickRows(orderId)) {
        verifiedQty = verifiedQty.add(pickRow.getReadyToVerifyQty());
    }
    if (orderedQty.compareTo(verifiedQty) != 0) {
        throw new GeneralException(UtilProperties.getMessage("ProductErrorUiLabels", "ProductErrorAllOrderItemsAreNotVerified", locale));
    }
}
Also used : GenericValue(org.apache.ofbiz.entity.GenericValue) GeneralException(org.apache.ofbiz.base.util.GeneralException) BigDecimal(java.math.BigDecimal)

Example 83 with GenericValue

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

the class VerifyPickSession method createRow.

public void createRow(String orderId, String orderItemSeqId, String shipGroupSeqId, String productId, String originGeoId, BigDecimal quantity, Locale locale) throws GeneralException {
    if (orderItemSeqId == null && productId != null) {
        orderItemSeqId = this.findOrderItemSeqId(productId, orderId, shipGroupSeqId, quantity, locale);
    }
    // get the reservations for the item
    Map<String, Object> inventoryLookupMap = new HashMap<String, Object>();
    inventoryLookupMap.put("orderId", orderId);
    inventoryLookupMap.put("orderItemSeqId", orderItemSeqId);
    inventoryLookupMap.put("shipGroupSeqId", shipGroupSeqId);
    List<GenericValue> reservations = this.getDelegator().findByAnd("OrderItemShipGrpInvRes", inventoryLookupMap, UtilMisc.toList("quantity DESC"), false);
    // no reservations we cannot add this item
    if (UtilValidate.isEmpty(reservations)) {
        throw new GeneralException(UtilProperties.getMessage("ProductErrorUiLabels", "ProductErrorNoInventoryReservationsAvailableCannotVerifyThisItem", locale));
    }
    if (reservations.size() == 1) {
        GenericValue reservation = EntityUtil.getFirst(reservations);
        int checkCode = this.checkRowForAdd(reservation, orderId, orderItemSeqId, shipGroupSeqId, productId, quantity);
        this.createVerifyPickRow(checkCode, reservation, orderId, orderItemSeqId, shipGroupSeqId, productId, originGeoId, quantity, locale);
    } else {
        // more than one reservation found
        Map<GenericValue, BigDecimal> reserveQtyMap = new HashMap<GenericValue, BigDecimal>();
        BigDecimal qtyRemain = quantity;
        for (GenericValue reservation : reservations) {
            if (qtyRemain.compareTo(BigDecimal.ZERO) > 0) {
                if (!productId.equals(reservation.getRelatedOne("InventoryItem", false).getString("productId"))) {
                    continue;
                }
                BigDecimal reservedQty = reservation.getBigDecimal("quantity");
                BigDecimal resVerifiedQty = this.getVerifiedQuantity(orderId, orderItemSeqId, shipGroupSeqId, productId, reservation.getString("inventoryItemId"));
                if (resVerifiedQty.compareTo(reservedQty) >= 0) {
                    continue;
                } else {
                    reservedQty = reservedQty.subtract(resVerifiedQty);
                }
                BigDecimal thisQty = reservedQty.compareTo(qtyRemain) > 0 ? qtyRemain : reservedQty;
                int thisCheck = this.checkRowForAdd(reservation, orderId, orderItemSeqId, shipGroupSeqId, productId, thisQty);
                switch(thisCheck) {
                    case 2:
                        // new verify pick row will be created
                        reserveQtyMap.put(reservation, thisQty);
                        qtyRemain = qtyRemain.subtract(thisQty);
                        break;
                    case 1:
                        // existing verify pick row has been updated
                        qtyRemain = qtyRemain.subtract(thisQty);
                        break;
                    case 0:
                        // doing nothing
                        break;
                }
            }
        }
        if (qtyRemain.compareTo(BigDecimal.ZERO) == 0) {
            for (Map.Entry<GenericValue, BigDecimal> entry : reserveQtyMap.entrySet()) {
                GenericValue reservation = entry.getKey();
                BigDecimal qty = entry.getValue();
                this.createVerifyPickRow(2, reservation, orderId, orderItemSeqId, shipGroupSeqId, productId, originGeoId, qty, locale);
            }
        } else {
            throw new GeneralException(UtilProperties.getMessage("ProductErrorUiLabels", "ProductErrorNotEnoughInventoryReservationAvailableCannotVerifyTheItem", locale));
        }
    }
}
Also used : GenericValue(org.apache.ofbiz.entity.GenericValue) GeneralException(org.apache.ofbiz.base.util.GeneralException) HashMap(java.util.HashMap) HashMap(java.util.HashMap) Map(java.util.Map) BigDecimal(java.math.BigDecimal)

Example 84 with GenericValue

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

the class CertificateServices method importIssuerCertificate.

public static Map<String, Object> importIssuerCertificate(DispatchContext dctx, Map<String, ? extends Object> context) {
    Delegator delegator = dctx.getDelegator();
    String certString = (String) context.get("certString");
    String componentName = (String) context.get("componentName");
    String keystoreName = (String) context.get("keystoreName");
    String alias = (String) context.get("alias");
    String importIssuer = (String) context.get("importIssuer");
    // load the keystore
    KeyStore ks;
    try {
        ks = KeyStoreUtil.getComponentKeyStore(componentName, keystoreName);
    } catch (Exception e) {
        return ServiceUtil.returnError(e.getMessage());
    }
    // read the certificate
    X509Certificate cert;
    try {
        cert = (X509Certificate) KeyStoreUtil.pemToCert(certString);
    } catch (CertificateException e) {
        return ServiceUtil.returnError(e.getMessage());
    } catch (IOException e) {
        return ServiceUtil.returnError(e.getMessage());
    }
    // store the cert
    try {
        ks.setCertificateEntry(alias, cert);
    } catch (Exception e) {
        return ServiceUtil.returnError(e.getMessage());
    }
    // save the keystore
    try {
        KeyStoreUtil.storeComponentKeyStore(componentName, keystoreName, ks);
    } catch (Exception e) {
        return ServiceUtil.returnError(e.getMessage());
    }
    // set the issuer provision
    Map<String, String> x500Map = KeyStoreUtil.getCertX500Map(cert);
    if (importIssuer != null && "Y".equalsIgnoreCase(importIssuer)) {
        GenericValue provision = delegator.makeValue("X509IssuerProvision");
        provision.set("commonName", x500Map.get("CN"));
        provision.set("organizationalUnit", x500Map.get("OU"));
        provision.set("organizationName", x500Map.get("O"));
        provision.set("cityLocality", x500Map.get("L"));
        provision.set("stateProvince", x500Map.get("ST"));
        provision.set("country", x500Map.get("C"));
        provision.set("serialNumber", cert.getSerialNumber().toString(16));
        try {
            delegator.createSetNextSeqId(provision);
        } catch (GenericEntityException e) {
            return ServiceUtil.returnError(e.getMessage());
        }
    }
    return ServiceUtil.returnSuccess();
}
Also used : GenericValue(org.apache.ofbiz.entity.GenericValue) Delegator(org.apache.ofbiz.entity.Delegator) GenericEntityException(org.apache.ofbiz.entity.GenericEntityException) CertificateException(java.security.cert.CertificateException) IOException(java.io.IOException) KeyStore(java.security.KeyStore) GenericEntityException(org.apache.ofbiz.entity.GenericEntityException) IOException(java.io.IOException) CertificateException(java.security.cert.CertificateException) X509Certificate(java.security.cert.X509Certificate)

Example 85 with GenericValue

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

the class LoginEvents method saveEntryParams.

/**
 * Save USERNAME and PASSWORD for use by auth pages even if we start in non-auth pages.
 *
 * @param request The HTTP request object for the current JSP or Servlet request.
 * @param response The HTTP response object for the current JSP or Servlet request.
 * @return String
 */
public static String saveEntryParams(HttpServletRequest request, HttpServletResponse response) {
    GenericValue userLogin = (GenericValue) request.getSession().getAttribute("userLogin");
    HttpSession session = request.getSession();
    Delegator delegator = (Delegator) request.getAttribute("delegator");
    // save entry login parameters if we don't have a valid login object
    if (userLogin == null) {
        String username = request.getParameter("USERNAME");
        String password = request.getParameter("PASSWORD");
        if ((username != null) && ("true".equalsIgnoreCase(EntityUtilProperties.getPropertyValue("security", "username.lowercase", delegator)))) {
            username = username.toLowerCase(Locale.getDefault());
        }
        if ((password != null) && ("true".equalsIgnoreCase(EntityUtilProperties.getPropertyValue("security", "password.lowercase", delegator)))) {
            password = password.toLowerCase(Locale.getDefault());
        }
        // save parameters into the session - so they can be used later, if needed
        if (username != null) {
            session.setAttribute("USERNAME", username);
        }
        if (password != null) {
            session.setAttribute("PASSWORD", password);
        }
    } else {
        // if the login object is valid, remove attributes
        session.removeAttribute("USERNAME");
        session.removeAttribute("PASSWORD");
    }
    return "success";
}
Also used : GenericValue(org.apache.ofbiz.entity.GenericValue) Delegator(org.apache.ofbiz.entity.Delegator) GenericDelegator(org.apache.ofbiz.entity.GenericDelegator) HttpSession(javax.servlet.http.HttpSession)

Aggregations

GenericValue (org.apache.ofbiz.entity.GenericValue)1422 GenericEntityException (org.apache.ofbiz.entity.GenericEntityException)871 Delegator (org.apache.ofbiz.entity.Delegator)721 Locale (java.util.Locale)505 HashMap (java.util.HashMap)463 GenericServiceException (org.apache.ofbiz.service.GenericServiceException)370 LocalDispatcher (org.apache.ofbiz.service.LocalDispatcher)356 BigDecimal (java.math.BigDecimal)338 LinkedList (java.util.LinkedList)312 Timestamp (java.sql.Timestamp)202 GeneralException (org.apache.ofbiz.base.util.GeneralException)168 Map (java.util.Map)155 IOException (java.io.IOException)116 EntityCondition (org.apache.ofbiz.entity.condition.EntityCondition)97 HttpSession (javax.servlet.http.HttpSession)89 ArrayList (java.util.ArrayList)69 Security (org.apache.ofbiz.security.Security)69 EntityListIterator (org.apache.ofbiz.entity.util.EntityListIterator)59 List (java.util.List)56 EntityExpr (org.apache.ofbiz.entity.condition.EntityExpr)52