Search in sources :

Example 16 with GenericValue

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

the class ShipmentServices method quickScheduleShipmentRouteSegment.

/**
 * Service to call a ShipmentRouteSegment.carrierPartyId's confirm shipment method asynchronously
 */
public static Map<String, Object> quickScheduleShipmentRouteSegment(DispatchContext dctx, Map<String, ? extends Object> context) {
    Delegator delegator = dctx.getDelegator();
    LocalDispatcher dispatcher = dctx.getDispatcher();
    GenericValue userLogin = (GenericValue) context.get("userLogin");
    String shipmentId = (String) context.get("shipmentId");
    String shipmentRouteSegmentId = (String) context.get("shipmentRouteSegmentId");
    String carrierPartyId = null;
    // get the carrierPartyId
    try {
        GenericValue shipmentRouteSegment = EntityQuery.use(delegator).from("ShipmentRouteSegment").where("shipmentId", shipmentId, "shipmentRouteSegmentId", shipmentRouteSegmentId).cache(true).queryOne();
        carrierPartyId = shipmentRouteSegment.getString("carrierPartyId");
    } catch (GenericEntityException e) {
        Debug.logError(e, module);
        return ServiceUtil.returnError(e.getMessage());
    }
    // if we can't confirm a single shipment, then all shipment route segments in a multi-form are rolled back.
    try {
        Map<String, Object> input = UtilMisc.toMap("shipmentId", shipmentId, "shipmentRouteSegmentId", shipmentRouteSegmentId, "userLogin", userLogin);
        // for DHL, we just need to confirm the shipment to get the label.  Other carriers may have more elaborate requirements.
        if ("DHL".equals(carrierPartyId)) {
            dispatcher.runAsync("dhlShipmentConfirm", input);
        } else {
            Debug.logError(carrierPartyId + " is not supported at this time.  Sorry.", module);
        }
    } catch (GenericServiceException se) {
        Debug.logError(se, se.getMessage(), module);
    }
    // don't return an error
    return ServiceUtil.returnSuccess();
}
Also used : GenericValue(org.apache.ofbiz.entity.GenericValue) LocalDispatcher(org.apache.ofbiz.service.LocalDispatcher) Delegator(org.apache.ofbiz.entity.Delegator) GenericEntityException(org.apache.ofbiz.entity.GenericEntityException) GenericServiceException(org.apache.ofbiz.service.GenericServiceException)

Example 17 with GenericValue

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

the class ShipmentServices method updateShipmentsFromStaging.

public static Map<String, Object> updateShipmentsFromStaging(DispatchContext dctx, Map<String, ? extends Object> context) {
    LocalDispatcher dispatcher = dctx.getDispatcher();
    Delegator delegator = dctx.getDelegator();
    GenericValue userLogin = (GenericValue) context.get("userLogin");
    Locale locale = (Locale) context.get("locale");
    Map<String, String> shipmentMap = new HashMap<String, String>();
    EntityQuery eq = EntityQuery.use(delegator).from("OdbcPackageIn").orderBy("shipmentId", "shipmentPackageSeqId", "voidIndicator");
    try (EntityListIterator eli = eq.queryIterator()) {
        GenericValue pkgInfo;
        while ((pkgInfo = eli.next()) != null) {
            String packageSeqId = pkgInfo.getString("shipmentPackageSeqId");
            String shipmentId = pkgInfo.getString("shipmentId");
            // locate the shipment package
            GenericValue shipmentPackage = EntityQuery.use(delegator).from("ShipmentPackage").where("shipmentId", shipmentId, "shipmentPackageSeqId", packageSeqId).queryOne();
            if (shipmentPackage != null) {
                if ("00001".equals(packageSeqId)) {
                    // only need to do this for the first package
                    GenericValue rtSeg = null;
                    rtSeg = EntityQuery.use(delegator).from("ShipmentRouteSegment").where("shipmentId", shipmentId, "shipmentRouteSegmentId", "00001").queryOne();
                    if (rtSeg == null) {
                        rtSeg = delegator.makeValue("ShipmentRouteSegment", UtilMisc.toMap("shipmentId", shipmentId, "shipmentRouteSegmentId", "00001"));
                        try {
                            delegator.create(rtSeg);
                        } catch (GenericEntityException e) {
                            Debug.logError(e, module);
                            return ServiceUtil.returnError(e.getMessage());
                        }
                    }
                    rtSeg.set("actualStartDate", pkgInfo.get("shippedDate"));
                    rtSeg.set("billingWeight", pkgInfo.get("billingWeight"));
                    rtSeg.set("actualCost", pkgInfo.get("shippingTotal"));
                    rtSeg.set("trackingIdNumber", pkgInfo.get("trackingNumber"));
                    delegator.store(rtSeg);
                }
                Map<String, Object> pkgCtx = new HashMap<String, Object>();
                pkgCtx.put("shipmentId", shipmentId);
                pkgCtx.put("shipmentPackageSeqId", packageSeqId);
                // first update the weight of the package
                GenericValue pkg = null;
                pkg = EntityQuery.use(delegator).from("ShipmentPackage").where(pkgCtx).queryOne();
                if (pkg == null) {
                    return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ProductShipmentPackageNotFound", UtilMisc.toMap("shipmentPackageSeqId", packageSeqId, "shipmentId", shipmentId), locale));
                }
                pkg.set("weight", pkgInfo.get("packageWeight"));
                delegator.store(pkg);
                // need if we are the first package (only) update the route seg info
                pkgCtx.put("shipmentRouteSegmentId", "00001");
                GenericValue pkgRtSeg = null;
                pkgRtSeg = EntityQuery.use(delegator).from("ShipmentPackageRouteSeg").where(pkgCtx).queryOne();
                if (pkgRtSeg == null) {
                    pkgRtSeg = delegator.makeValue("ShipmentPackageRouteSeg", pkgCtx);
                    try {
                        delegator.create(pkgRtSeg);
                    } catch (GenericEntityException e) {
                        Debug.logError(e, module);
                        return ServiceUtil.returnError(e.getMessage());
                    }
                }
                pkgRtSeg.set("trackingCode", pkgInfo.get("trackingNumber"));
                pkgRtSeg.set("boxNumber", pkgInfo.get("shipmentPackageSeqId"));
                pkgRtSeg.set("packageServiceCost", pkgInfo.get("packageTotal"));
                delegator.store(pkgRtSeg);
                shipmentMap.put(shipmentId, pkgInfo.getString("voidIndicator"));
            }
        }
    } catch (GenericEntityException e) {
        Debug.logError(e, module);
        return ServiceUtil.returnError(e.getMessage());
    }
    // update the status of each shipment
    for (Map.Entry<String, String> entry : shipmentMap.entrySet()) {
        String shipmentId = entry.getKey();
        String voidInd = entry.getValue();
        Map<String, Object> shipCtx = new HashMap<String, Object>();
        shipCtx.put("shipmentId", shipmentId);
        if ("Y".equals(voidInd)) {
            shipCtx.put("statusId", "SHIPMENT_CANCELLED");
        } else {
            shipCtx.put("statusId", "SHIPMENT_SHIPPED");
        }
        shipCtx.put("userLogin", userLogin);
        Map<String, Object> shipResp = null;
        try {
            shipResp = dispatcher.runSync("updateShipment", shipCtx);
        } catch (GenericServiceException e) {
            Debug.logError(e, module);
            return ServiceUtil.returnError(e.getMessage());
        }
        if (ServiceUtil.isError(shipResp)) {
            return ServiceUtil.returnError(ServiceUtil.getErrorMessage(shipResp));
        }
        // remove the shipment info
        Map<String, Object> clearResp = null;
        try {
            clearResp = dispatcher.runSync("clearShipmentStaging", UtilMisc.<String, Object>toMap("shipmentId", shipmentId, "userLogin", userLogin));
        } catch (GenericServiceException e) {
            Debug.logError(e, module);
            return ServiceUtil.returnError(e.getMessage());
        }
        if (ServiceUtil.isError(clearResp)) {
            return ServiceUtil.returnError(ServiceUtil.getErrorMessage(clearResp));
        }
    }
    return ServiceUtil.returnSuccess();
}
Also used : Locale(java.util.Locale) GenericValue(org.apache.ofbiz.entity.GenericValue) LocalDispatcher(org.apache.ofbiz.service.LocalDispatcher) HashMap(java.util.HashMap) EntityQuery(org.apache.ofbiz.entity.util.EntityQuery) Delegator(org.apache.ofbiz.entity.Delegator) GenericEntityException(org.apache.ofbiz.entity.GenericEntityException) GenericServiceException(org.apache.ofbiz.service.GenericServiceException) EntityListIterator(org.apache.ofbiz.entity.util.EntityListIterator) HashMap(java.util.HashMap) Map(java.util.Map) TreeMap(java.util.TreeMap)

Example 18 with GenericValue

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

the class ShipmentServices method duplicateShipmentRouteSegment.

public static Map<String, Object> duplicateShipmentRouteSegment(DispatchContext dctx, Map<String, ? extends Object> context) {
    Delegator delegator = dctx.getDelegator();
    LocalDispatcher dispatcher = dctx.getDispatcher();
    GenericValue userLogin = (GenericValue) context.get("userLogin");
    String shipmentId = (String) context.get("shipmentId");
    String shipmentRouteSegmentId = (String) context.get("shipmentRouteSegmentId");
    Locale locale = (Locale) context.get("locale");
    Map<String, Object> results = ServiceUtil.returnSuccess();
    try {
        GenericValue shipmentRouteSeg = EntityQuery.use(delegator).from("ShipmentRouteSegment").where("shipmentId", shipmentId, "shipmentRouteSegmentId", shipmentRouteSegmentId).queryOne();
        if (shipmentRouteSeg == null) {
            return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ProductShipmentRouteSegmentNotFound", UtilMisc.toMap("shipmentId", shipmentId, "shipmentRouteSegmentId", shipmentRouteSegmentId), locale));
        }
        Map<String, Object> params = UtilMisc.<String, Object>toMap("shipmentId", shipmentId, "carrierPartyId", shipmentRouteSeg.getString("carrierPartyId"), "shipmentMethodTypeId", shipmentRouteSeg.getString("shipmentMethodTypeId"), "originFacilityId", shipmentRouteSeg.getString("originFacilityId"), "originContactMechId", shipmentRouteSeg.getString("originContactMechId"), "originTelecomNumberId", shipmentRouteSeg.getString("originTelecomNumberId"));
        params.put("destFacilityId", shipmentRouteSeg.getString("destFacilityId"));
        params.put("destContactMechId", shipmentRouteSeg.getString("destContactMechId"));
        params.put("destTelecomNumberId", shipmentRouteSeg.getString("destTelecomNumberId"));
        params.put("billingWeight", shipmentRouteSeg.get("billingWeight"));
        params.put("billingWeightUomId", shipmentRouteSeg.get("billingWeightUomId"));
        params.put("userLogin", userLogin);
        Map<String, Object> tmpResult = dispatcher.runSync("createShipmentRouteSegment", params);
        if (ServiceUtil.isError(tmpResult)) {
            return ServiceUtil.returnError(ServiceUtil.getErrorMessage(tmpResult));
        } else {
            results.put("newShipmentRouteSegmentId", tmpResult.get("shipmentRouteSegmentId"));
            return results;
        }
    } catch (GenericEntityException ex) {
        return ServiceUtil.returnError(ex.getMessage());
    } catch (GenericServiceException ex) {
        return ServiceUtil.returnError(ex.getMessage());
    }
}
Also used : Locale(java.util.Locale) GenericValue(org.apache.ofbiz.entity.GenericValue) LocalDispatcher(org.apache.ofbiz.service.LocalDispatcher) Delegator(org.apache.ofbiz.entity.Delegator) GenericEntityException(org.apache.ofbiz.entity.GenericEntityException) GenericServiceException(org.apache.ofbiz.service.GenericServiceException)

Example 19 with GenericValue

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

the class ShipmentServices method sendShipmentCompleteNotification.

public static Map<String, Object> sendShipmentCompleteNotification(DispatchContext dctx, Map<String, ? extends Object> context) {
    LocalDispatcher dispatcher = dctx.getDispatcher();
    Delegator delegator = dctx.getDelegator();
    GenericValue userLogin = (GenericValue) context.get("userLogin");
    String shipmentId = (String) context.get("shipmentId");
    String sendTo = (String) context.get("sendTo");
    String screenUri = (String) context.get("screenUri");
    Locale localePar = (Locale) context.get("locale");
    // prepare the shipment information
    Map<String, Object> sendMap = new HashMap<String, Object>();
    GenericValue shipment = null;
    GenericValue orderHeader = null;
    try {
        shipment = EntityQuery.use(delegator).from("Shipment").where("shipmentId", shipmentId).queryOne();
        orderHeader = EntityQuery.use(delegator).from("OrderHeader").where("orderId", shipment.getString("primaryOrderId")).queryOne();
    } catch (GenericEntityException e) {
        Debug.logError(e, "Problem getting info from database", module);
    }
    GenericValue productStoreEmail = null;
    try {
        productStoreEmail = EntityQuery.use(delegator).from("ProductStoreEmailSetting").where("productStoreId", orderHeader.get("productStoreId"), "emailType", "PRDS_ODR_SHIP_COMPLT").queryOne();
    } catch (GenericEntityException e) {
        Debug.logError(e, "Problem getting the ProductStoreEmailSetting for productStoreId =" + orderHeader.get("productStoreId") + " and emailType = PRDS_ODR_SHIP_COMPLT", module);
    }
    if (productStoreEmail == null) {
        return ServiceUtil.returnFailure(UtilProperties.getMessage(resource, "ProductProductStoreEmailSettingsNotValid", UtilMisc.toMap("productStoreId", orderHeader.get("productStoreId"), "emailType", "PRDS_ODR_SHIP_COMPLT"), localePar));
    }
    // the override screenUri
    if (UtilValidate.isEmpty(screenUri)) {
        String bodyScreenLocation = productStoreEmail.getString("bodyScreenLocation");
        sendMap.put("bodyScreenUri", bodyScreenLocation);
    } else {
        sendMap.put("bodyScreenUri", screenUri);
    }
    String partyId = shipment.getString("partyIdTo");
    // get the email address
    String emailString = null;
    GenericValue email = PartyWorker.findPartyLatestContactMech(partyId, "EMAIL_ADDRESS", delegator);
    if (UtilValidate.isNotEmpty(email)) {
        emailString = email.getString("infoString");
    }
    if (UtilValidate.isEmpty(emailString)) {
        return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ProductProductStoreEmailSettingsNoSendToFound", localePar));
    }
    Locale locale = PartyWorker.findPartyLastLocale(partyId, delegator);
    if (locale == null) {
        locale = Locale.getDefault();
    }
    Map<String, Object> bodyParameters = UtilMisc.<String, Object>toMap("partyId", partyId, "shipmentId", shipmentId, "orderId", shipment.getString("primaryOrderId"), "userLogin", userLogin, "locale", locale);
    sendMap.put("bodyParameters", bodyParameters);
    sendMap.put("userLogin", userLogin);
    sendMap.put("subject", productStoreEmail.getString("subject"));
    sendMap.put("contentType", productStoreEmail.get("contentType"));
    sendMap.put("sendFrom", productStoreEmail.get("fromAddress"));
    sendMap.put("sendCc", productStoreEmail.get("ccAddress"));
    sendMap.put("sendBcc", productStoreEmail.get("bccAddress"));
    if ((sendTo != null) && UtilValidate.isEmail(sendTo)) {
        sendMap.put("sendTo", sendTo);
    } else {
        sendMap.put("sendTo", emailString);
    }
    // send the notification
    Map<String, Object> sendResp = null;
    try {
        sendResp = dispatcher.runSync("sendMailFromScreen", sendMap);
    } catch (GenericServiceException gse) {
        Debug.logError(gse, "Problem sending mail", module);
        return ServiceUtil.returnError(UtilProperties.getMessage(resource_error, "OrderProblemSendingEmail", localePar));
    } catch (Exception e) {
        Debug.logError(e, "Problem sending mail", module);
        return ServiceUtil.returnError(UtilProperties.getMessage(resource_error, "OrderProblemSendingEmail", localePar));
    }
    // check for errors
    if (sendResp != null && ServiceUtil.isError(sendResp)) {
        sendResp.put("emailType", "PRDS_ODR_SHIP_COMPLT");
        return ServiceUtil.returnError(UtilProperties.getMessage(resource_error, "OrderProblemSendingEmail", localePar), null, null, sendResp);
    }
    return sendResp;
}
Also used : Locale(java.util.Locale) GenericValue(org.apache.ofbiz.entity.GenericValue) LocalDispatcher(org.apache.ofbiz.service.LocalDispatcher) Delegator(org.apache.ofbiz.entity.Delegator) HashMap(java.util.HashMap) GenericEntityException(org.apache.ofbiz.entity.GenericEntityException) GenericServiceException(org.apache.ofbiz.service.GenericServiceException) GenericServiceException(org.apache.ofbiz.service.GenericServiceException) GenericEntityException(org.apache.ofbiz.entity.GenericEntityException)

Example 20 with GenericValue

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

the class ShipmentServices method applyQuantityBreak.

private static boolean applyQuantityBreak(Map<String, ? extends Object> context, Map<String, Object> result, List<GenericValue> storeAll, Delegator delegator, GenericValue estimate, String prefix, String breakType, String breakTypeString) {
    BigDecimal min = (BigDecimal) context.get(prefix + "min");
    BigDecimal max = (BigDecimal) context.get(prefix + "max");
    if (min != null || max != null) {
        if (min != null && max != null) {
            if (min.compareTo(max) <= 0 || max.compareTo(BigDecimal.ZERO) == 0) {
                try {
                    String newSeqId = delegator.getNextSeqId("QuantityBreak");
                    GenericValue weightBreak = delegator.makeValue("QuantityBreak");
                    weightBreak.set("quantityBreakId", newSeqId);
                    weightBreak.set("quantityBreakTypeId", "SHIP_" + breakType.toUpperCase(Locale.getDefault()));
                    weightBreak.set("fromQuantity", min);
                    weightBreak.set("thruQuantity", max);
                    estimate.set(breakType + "BreakId", newSeqId);
                    estimate.set(breakType + "UnitPrice", context.get(prefix + "price"));
                    if (context.containsKey(prefix + "uom")) {
                        estimate.set(breakType + "UomId", context.get(prefix + "uom"));
                    }
                    storeAll.add(0, weightBreak);
                } catch (Exception e) {
                    Debug.logError(e, module);
                }
            } else {
                result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_ERROR);
                result.put(ModelService.ERROR_MESSAGE, "Max " + breakTypeString + " must not be less than Min " + breakTypeString + ".");
                return false;
            }
        } else {
            result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_ERROR);
            result.put(ModelService.ERROR_MESSAGE, breakTypeString + " Span Requires BOTH Fields.");
            return false;
        }
    }
    return true;
}
Also used : GenericValue(org.apache.ofbiz.entity.GenericValue) BigDecimal(java.math.BigDecimal) GenericServiceException(org.apache.ofbiz.service.GenericServiceException) GenericEntityException(org.apache.ofbiz.entity.GenericEntityException)

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