return ServiceUtil.returnSuccess();
}
public static Map<String, Object> updateShipmentsFromStaging(DispatchContext dctx, Map<String, ? extends Object> context) {
LocalDispatcher dispatcher = dctx.getDispatcher();
GenericDelegator delegator = dctx.getDelegator();
GenericValue userLogin = (GenericValue) context.get("userLogin");
List<String> orderBy = UtilMisc.toList("shipmentId", "shipmentPackageSeqId", "voidIndicator");
Map<String, String> shipmentMap = FastMap.newInstance();
EntityListIterator eli = null;
try {
eli = delegator.find("OdbcPackageIn", null, null, null, orderBy, null);
GenericValue pkgInfo;
while ((pkgInfo = eli.next()) != null) {
String packageSeqId = pkgInfo.getString("shipmentPackageSeqId");
String shipmentId = pkgInfo.getString("shipmentId");
// locate the shipment package
GenericValue shipmentPackage = delegator.findByPrimaryKey("ShipmentPackage",
UtilMisc.toMap("shipmentId", shipmentId, "shipmentPackageSeqId", packageSeqId));
if (shipmentPackage != null) {
if ("00001".equals(packageSeqId)) {
// only need to do this for the first package
GenericValue rtSeg = null;
try {
rtSeg = delegator.findByPrimaryKey("ShipmentRouteSegment", UtilMisc.toMap("shipmentId", shipmentId, "shipmentRouteSegmentId", "00001"));
} catch (GenericEntityException e) {
Debug.logError(e, module);
return ServiceUtil.returnError(e.getMessage());
}
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"));
try {
delegator.store(rtSeg);
} catch (GenericEntityException e) {
Debug.logError(e, module);
return ServiceUtil.returnError(e.getMessage());
}
}
Map<String, Object> pkgCtx = FastMap.newInstance();
pkgCtx.put("shipmentId", shipmentId);
pkgCtx.put("shipmentPackageSeqId", packageSeqId);
// first update the weight of the package
GenericValue pkg = null;
try {
pkg = delegator.findByPrimaryKey("ShipmentPackage", pkgCtx);
} catch (GenericEntityException e) {
Debug.logError(e, module);
return ServiceUtil.returnError(e.getMessage());
}
if (pkg == null) {
return ServiceUtil.returnError("Package not found! - " + pkgCtx);
}
pkg.set("weight", pkgInfo.get("packageWeight"));
try {
delegator.store(pkg);
} catch (GenericEntityException e) {
Debug.logError(e, module);
return ServiceUtil.returnError(e.getMessage());
}
// need if we are the first package (only) update the route seg info
pkgCtx.put("shipmentRouteSegmentId", "00001");
GenericValue pkgRtSeg = null;
try {
pkgRtSeg = delegator.findByPrimaryKey("ShipmentPackageRouteSeg", pkgCtx);
} catch (GenericEntityException e) {
Debug.logError(e, module);
return ServiceUtil.returnError(e.getMessage());
}
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"));
try {
delegator.store(pkgRtSeg);
} catch (GenericEntityException e) {
Debug.logError(e, module);
return ServiceUtil.returnError(e.getMessage());
}
shipmentMap.put(shipmentId, pkgInfo.getString("voidIndicator"));