Search in sources :

Example 11 with GenericEntityException

use of org.apache.ofbiz.entity.GenericEntityException 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 12 with GenericEntityException

use of org.apache.ofbiz.entity.GenericEntityException 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 13 with GenericEntityException

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

the class ShipmentServices method fillShipmentStagingTables.

public static Map<String, Object> fillShipmentStagingTables(DispatchContext dctx, Map<String, ? extends Object> context) {
    Delegator delegator = dctx.getDelegator();
    String shipmentId = (String) context.get("shipmentId");
    Locale locale = (Locale) context.get("locale");
    GenericValue shipment = null;
    if (shipmentId != null) {
        try {
            shipment = EntityQuery.use(delegator).from("Shipment").where("shipmentId", shipmentId).queryOne();
        } catch (GenericEntityException e) {
            Debug.logError(e, module);
            return ServiceUtil.returnError(e.getMessage());
        }
    }
    if (shipment == null) {
        return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ProductShipmentNotFoundId", locale));
    }
    String shipmentStatusId = shipment.getString("statusId");
    if ("SHIPMENT_PACKED".equals(shipmentStatusId)) {
        GenericValue address = null;
        try {
            address = shipment.getRelatedOne("DestinationPostalAddress", false);
        } catch (GenericEntityException e) {
            Debug.logError(e, module);
            return ServiceUtil.returnError(e.getMessage());
        }
        if (address == null) {
            return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ProductShipmentNoAddressFound", locale));
        }
        List<GenericValue> packages = null;
        try {
            packages = shipment.getRelated("ShipmentPackage", null, null, false);
        } catch (GenericEntityException e) {
            Debug.logError(e, module);
            return ServiceUtil.returnError(e.getMessage());
        }
        if (UtilValidate.isEmpty(packages)) {
            return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ProductShipmentNoPackagesAvailable", locale));
        }
        List<GenericValue> routeSegs = null;
        try {
            routeSegs = shipment.getRelated("ShipmentRouteSegment", null, null, false);
        } catch (GenericEntityException e) {
            Debug.logError(e, module);
            return ServiceUtil.returnError(e.getMessage());
        }
        GenericValue routeSeg = EntityUtil.getFirst(routeSegs);
        // to store list
        List<GenericValue> toStore = new LinkedList<GenericValue>();
        // make the staging records
        GenericValue stageShip = delegator.makeValue("OdbcShipmentOut");
        stageShip.set("shipmentId", shipment.get("shipmentId"));
        stageShip.set("partyId", shipment.get("partyIdTo"));
        stageShip.set("carrierPartyId", routeSeg.get("carrierPartyId"));
        stageShip.set("shipmentMethodTypeId", routeSeg.get("shipmentMethodTypeId"));
        stageShip.set("toName", address.get("toName"));
        stageShip.set("attnName", address.get("attnName"));
        stageShip.set("address1", address.get("address1"));
        stageShip.set("address2", address.get("address2"));
        stageShip.set("directions", address.get("directions"));
        stageShip.set("city", address.get("city"));
        stageShip.set("postalCode", address.get("postalCode"));
        stageShip.set("postalCodeExt", address.get("postalCodeExt"));
        stageShip.set("countryGeoId", address.get("countryGeoId"));
        stageShip.set("stateProvinceGeoId", address.get("stateProvinceGeoId"));
        stageShip.set("numberOfPackages", Long.valueOf(packages.size()));
        stageShip.set("handlingInstructions", shipment.get("handlingInstructions"));
        toStore.add(stageShip);
        for (GenericValue shipmentPkg : packages) {
            GenericValue stagePkg = delegator.makeValue("OdbcPackageOut");
            stagePkg.set("shipmentId", shipmentPkg.get("shipmentId"));
            stagePkg.set("shipmentPackageSeqId", shipmentPkg.get("shipmentPackageSeqId"));
            stagePkg.set("orderId", shipment.get("primaryOrderId"));
            stagePkg.set("shipGroupSeqId", shipment.get("primaryShipGroupSeqId"));
            stagePkg.set("shipmentBoxTypeId", shipmentPkg.get("shipmentBoxTypeId"));
            stagePkg.set("weight", shipmentPkg.get("weight"));
            toStore.add(stagePkg);
        }
        try {
            delegator.storeAll(toStore);
        } catch (GenericEntityException e) {
            Debug.logError(e, module);
            return ServiceUtil.returnError(e.getMessage());
        }
    } else {
        Debug.logWarning("Shipment #" + shipmentId + " is not available for shipment; not setting in staging tables.", module);
    }
    return ServiceUtil.returnSuccess();
}
Also used : Locale(java.util.Locale) GenericValue(org.apache.ofbiz.entity.GenericValue) Delegator(org.apache.ofbiz.entity.Delegator) GenericEntityException(org.apache.ofbiz.entity.GenericEntityException) LinkedList(java.util.LinkedList)

Example 14 with GenericEntityException

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

the class ShipmentServices method removeShipmentEstimate.

public static Map<String, Object> removeShipmentEstimate(DispatchContext dctx, Map<String, ? extends Object> context) {
    Delegator delegator = dctx.getDelegator();
    String shipmentCostEstimateId = (String) context.get("shipmentCostEstimateId");
    Locale locale = (Locale) context.get("locale");
    GenericValue estimate = null;
    try {
        estimate = EntityQuery.use(delegator).from("ShipmentCostEstimate").where("shipmentCostEstimateId", shipmentCostEstimateId).queryOne();
        estimate.remove();
    } catch (GenericEntityException e) {
        Debug.logError(e, module);
        return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ProductShipmentCostEstimateRemoveError", UtilMisc.toMap("errorString", e.toString()), locale));
    }
    return ServiceUtil.returnSuccess();
}
Also used : Locale(java.util.Locale) GenericValue(org.apache.ofbiz.entity.GenericValue) Delegator(org.apache.ofbiz.entity.Delegator) GenericEntityException(org.apache.ofbiz.entity.GenericEntityException)

Example 15 with GenericEntityException

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

the class ShipmentServices method updatePurchaseShipmentFromReceipt.

/**
 * Whenever a ShipmentReceipt is generated, check the Shipment associated
 * with it to see if all items were received. If so, change its status to
 * PURCH_SHIP_RECEIVED. The check is accomplished by counting the
 * products shipped (from ShipmentAndItem) and matching them with the
 * products received (from ShipmentReceipt).
 */
public static Map<String, Object> updatePurchaseShipmentFromReceipt(DispatchContext dctx, Map<String, ? extends Object> context) {
    Delegator delegator = dctx.getDelegator();
    LocalDispatcher dispatcher = dctx.getDispatcher();
    String shipmentId = (String) context.get("shipmentId");
    GenericValue userLogin = (GenericValue) context.get("userLogin");
    try {
        List<GenericValue> shipmentReceipts = EntityQuery.use(delegator).from("ShipmentReceipt").where("shipmentId", shipmentId).queryList();
        if (shipmentReceipts.size() == 0)
            return ServiceUtil.returnSuccess();
        // If there are shipment receipts, the shipment must have been shipped, so set the shipment status to PURCH_SHIP_SHIPPED if it's only PURCH_SHIP_CREATED
        GenericValue shipment = EntityQuery.use(delegator).from("Shipment").where("shipmentId", shipmentId).queryOne();
        if ((!UtilValidate.isEmpty(shipment)) && "PURCH_SHIP_CREATED".equals(shipment.getString("statusId"))) {
            Map<String, Object> updateShipmentMap = dispatcher.runSync("updateShipment", UtilMisc.<String, Object>toMap("shipmentId", shipmentId, "statusId", "PURCH_SHIP_SHIPPED", "userLogin", userLogin));
            if (ServiceUtil.isError(updateShipmentMap)) {
                return updateShipmentMap;
            }
        }
        List<GenericValue> shipmentAndItems = EntityQuery.use(delegator).from("ShipmentAndItem").where("shipmentId", shipmentId, "statusId", "PURCH_SHIP_SHIPPED").queryList();
        if (shipmentAndItems.size() == 0) {
            return ServiceUtil.returnSuccess();
        }
        // store the quantity of each product shipped in a hashmap keyed to productId
        Map<String, BigDecimal> shippedCountMap = new HashMap<String, BigDecimal>();
        for (GenericValue item : shipmentAndItems) {
            BigDecimal shippedQuantity = item.getBigDecimal("quantity");
            BigDecimal quantity = shippedCountMap.get(item.getString("productId"));
            quantity = quantity == null ? shippedQuantity : shippedQuantity.add(quantity);
            shippedCountMap.put(item.getString("productId"), quantity);
        }
        // store the quantity of each product received in a hashmap keyed to productId
        Map<String, BigDecimal> receivedCountMap = new HashMap<String, BigDecimal>();
        for (GenericValue item : shipmentReceipts) {
            BigDecimal receivedQuantity = item.getBigDecimal("quantityAccepted");
            BigDecimal quantity = receivedCountMap.get(item.getString("productId"));
            quantity = quantity == null ? receivedQuantity : receivedQuantity.add(quantity);
            receivedCountMap.put(item.getString("productId"), quantity);
        }
        // let Map.equals do all the hard comparison work
        if (!shippedCountMap.equals(receivedCountMap)) {
            return ServiceUtil.returnSuccess();
        }
        // now update the shipment
        Map<String, Object> serviceResult = dispatcher.runSync("updateShipment", UtilMisc.<String, Object>toMap("shipmentId", shipmentId, "statusId", "PURCH_SHIP_RECEIVED", "userLogin", userLogin));
        if (ServiceUtil.isError(serviceResult)) {
            return ServiceUtil.returnError(ServiceUtil.getErrorMessage(serviceResult));
        }
    } catch (GenericEntityException e) {
        Debug.logError(e, module);
        return ServiceUtil.returnError(e.getMessage());
    } catch (GenericServiceException se) {
        Debug.logError(se, module);
        return ServiceUtil.returnError(se.getMessage());
    }
    return ServiceUtil.returnSuccess();
}
Also used : 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) BigDecimal(java.math.BigDecimal)

Aggregations

GenericEntityException (org.apache.ofbiz.entity.GenericEntityException)913 GenericValue (org.apache.ofbiz.entity.GenericValue)847 Delegator (org.apache.ofbiz.entity.Delegator)599 Locale (java.util.Locale)384 HashMap (java.util.HashMap)336 GenericServiceException (org.apache.ofbiz.service.GenericServiceException)270 LocalDispatcher (org.apache.ofbiz.service.LocalDispatcher)259 LinkedList (java.util.LinkedList)231 BigDecimal (java.math.BigDecimal)213 Timestamp (java.sql.Timestamp)171 Map (java.util.Map)109 GeneralException (org.apache.ofbiz.base.util.GeneralException)95 EntityCondition (org.apache.ofbiz.entity.condition.EntityCondition)78 IOException (java.io.IOException)75 EntityListIterator (org.apache.ofbiz.entity.util.EntityListIterator)57 Security (org.apache.ofbiz.security.Security)54 ArrayList (java.util.ArrayList)48 EntityExpr (org.apache.ofbiz.entity.condition.EntityExpr)47 GenericTransactionException (org.apache.ofbiz.entity.transaction.GenericTransactionException)39 LinkedHashMap (java.util.LinkedHashMap)37