use of org.apache.ofbiz.base.util.GeneralException in project ofbiz-framework by apache.
the class VerifyPickSession method checkReservedQty.
protected void checkReservedQty(String orderId, Locale locale) throws GeneralException {
List<String> errorList = new LinkedList<String>();
for (VerifyPickSessionRow pickRow : this.getPickRows(orderId)) {
BigDecimal reservedQty = this.getReservedQty(pickRow.getOrderId(), pickRow.getOrderItemSeqId(), pickRow.getShipGroupSeqId());
BigDecimal verifiedQty = this.getReadyToVerifyQuantity(pickRow.getOrderId(), pickRow.getOrderItemSeqId());
if (verifiedQty.compareTo(reservedQty) != 0) {
errorList.add(UtilProperties.getMessage("ProductErrorUiLabels", "ProductErrorVerifiedQtyDoesNotMatchTheReservedQtyForItem", UtilMisc.toMap("productId", pickRow.getProductId(), "verifiedQty", pickRow.getReadyToVerifyQty(), "reservedQty", reservedQty), locale));
}
}
if (errorList.size() > 0) {
throw new GeneralException(UtilProperties.getMessage("OrderErrorUiLabels", "OrderErrorAttemptToVerifyOrderFailed", UtilMisc.toMap("orderId", orderId), locale), errorList);
}
}
use of org.apache.ofbiz.base.util.GeneralException 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));
}
}
}
use of org.apache.ofbiz.base.util.GeneralException in project ofbiz-framework by apache.
the class ICalConverter method invokeService.
protected static Map<String, Object> invokeService(String serviceName, Map<String, ? extends Object> serviceMap, Map<String, Object> context) {
LocalDispatcher dispatcher = (LocalDispatcher) context.get("dispatcher");
Locale locale = (Locale) context.get("locale");
Map<String, Object> localMap = new HashMap<>();
try {
ModelService modelService = null;
modelService = dispatcher.getDispatchContext().getModelService(serviceName);
for (ModelParam modelParam : modelService.getInModelParamList()) {
if (serviceMap.containsKey(modelParam.name)) {
Object value = serviceMap.get(modelParam.name);
if (UtilValidate.isNotEmpty(modelParam.type)) {
value = ObjectType.simpleTypeConvert(value, modelParam.type, null, null, null, true);
}
localMap.put(modelParam.name, value);
}
}
} catch (GeneralException e) {
String errMsg = UtilProperties.getMessage("WorkEffortUiLabels", "WorkeffortErrorWhileCreatingServiceMapForService", UtilMisc.toMap("serviceName", serviceName), locale);
Debug.logError(e, errMsg, module);
return ServiceUtil.returnError(errMsg + e);
}
if (context.get("userLogin") != null) {
localMap.put("userLogin", context.get("userLogin"));
}
localMap.put("locale", context.get("locale"));
try {
Map<String, Object> result = dispatcher.runSync(serviceName, localMap);
if (ServiceUtil.isError(result)) {
return ServiceUtil.returnError(ServiceUtil.getErrorMessage(result));
}
return result;
} catch (GenericServiceException e) {
String errMsg = UtilProperties.getMessage("WorkEffortUiLabels", "WorkeffortErrorWhileInvokingService", UtilMisc.toMap("serviceName", serviceName), locale);
Debug.logError(e, errMsg, module);
return ServiceUtil.returnError(errMsg + e);
}
}
use of org.apache.ofbiz.base.util.GeneralException in project ofbiz-framework by apache.
the class ProductConfigWrapper method init.
private void init(Delegator delegator, LocalDispatcher dispatcher, String productId, String productStoreId, String catalogId, String webSiteId, String currencyUomId, Locale locale, GenericValue autoUserLogin) throws Exception {
product = EntityQuery.use(delegator).from("Product").where("productId", productId).queryOne();
if (product == null || !"AGGREGATED".equals(product.getString("productTypeId")) && !"AGGREGATED_SERVICE".equals(product.getString("productTypeId"))) {
throw new ProductConfigWrapperException("Product " + productId + " is not an AGGREGATED product.");
}
this.dispatcher = dispatcher;
this.dispatcherName = dispatcher.getName();
this.productStoreId = productStoreId;
this.catalogId = catalogId;
this.webSiteId = webSiteId;
this.currencyUomId = currencyUomId;
this.delegator = delegator;
this.delegatorName = delegator.getDelegatorName();
this.autoUserLogin = autoUserLogin;
// get the list Price, the base Price
Map<String, Object> priceContext = UtilMisc.toMap("product", product, "prodCatalogId", catalogId, "webSiteId", webSiteId, "productStoreId", productStoreId, "currencyUomId", currencyUomId, "autoUserLogin", autoUserLogin);
Map<String, Object> priceMap = dispatcher.runSync("calculateProductPrice", priceContext);
if (ServiceUtil.isError(priceMap)) {
String errorMessage = ServiceUtil.getErrorMessage(priceMap);
throw new GeneralException(errorMessage);
}
BigDecimal originalListPrice = (BigDecimal) priceMap.get("listPrice");
BigDecimal price = (BigDecimal) priceMap.get("price");
if (originalListPrice != null) {
listPrice = originalListPrice;
}
if (price != null) {
basePrice = price;
}
questions = new LinkedList<>();
if ("AGGREGATED".equals(product.getString("productTypeId")) || "AGGREGATED_SERVICE".equals(product.getString("productTypeId"))) {
List<GenericValue> questionsValues = EntityQuery.use(delegator).from("ProductConfig").where("productId", productId).orderBy("sequenceNum").filterByDate().queryList();
Set<String> itemIds = new HashSet<>();
for (GenericValue questionsValue : questionsValues) {
ConfigItem oneQuestion = new ConfigItem(questionsValue);
// TODO: mime-type shouldn't be hardcoded
oneQuestion.setContent(locale, "text/html");
if (itemIds.contains(oneQuestion.getConfigItem().getString("configItemId"))) {
oneQuestion.setFirst(false);
} else {
itemIds.add(oneQuestion.getConfigItem().getString("configItemId"));
}
questions.add(oneQuestion);
List<GenericValue> configOptions = EntityQuery.use(delegator).from("ProductConfigOption").where("configItemId", oneQuestion.getConfigItemAssoc().getString("configItemId")).orderBy("sequenceNum").queryList();
for (GenericValue configOption : configOptions) {
ConfigOption option = new ConfigOption(delegator, dispatcher, configOption, oneQuestion, catalogId, webSiteId, currencyUomId, autoUserLogin);
oneQuestion.addOption(option);
}
}
this.setDefaultPrice();
}
}
use of org.apache.ofbiz.base.util.GeneralException in project ofbiz-framework by apache.
the class MacroScreenRenderer method renderColumnContainer.
@Override
public void renderColumnContainer(Appendable writer, Map<String, Object> context, ColumnContainer columnContainer) throws IOException {
String id = columnContainer.getId(context);
String style = columnContainer.getStyle(context);
StringBuilder sb = new StringBuilder("<@renderColumnContainerBegin");
sb.append(" id=\"");
sb.append(id);
sb.append("\" style=\"");
sb.append(style);
sb.append("\" />");
executeMacro(writer, sb.toString());
for (Column column : columnContainer.getColumns()) {
id = column.getId(context);
style = column.getStyle(context);
sb = new StringBuilder("<@renderColumnBegin");
sb.append(" id=\"");
sb.append(id);
sb.append("\" style=\"");
sb.append(style);
sb.append("\" />");
executeMacro(writer, sb.toString());
for (ModelScreenWidget subWidget : column.getSubWidgets()) {
try {
subWidget.renderWidgetString(writer, context, this);
} catch (GeneralException e) {
throw new IOException(e);
}
}
executeMacro(writer, "<@renderColumnEnd />");
}
executeMacro(writer, "<@renderColumnContainerEnd />");
}
Aggregations