use of org.apache.ofbiz.entity.GenericPK in project ofbiz-framework by apache.
the class ShoppingCartItem method getPromoQuantityCandidateUseActionAndAllConds.
public BigDecimal getPromoQuantityCandidateUseActionAndAllConds(GenericValue productPromoAction) {
BigDecimal totalUse = BigDecimal.ZERO;
String productPromoId = productPromoAction.getString("productPromoId");
String productPromoRuleId = productPromoAction.getString("productPromoRuleId");
GenericPK productPromoActionPK = productPromoAction.getPrimaryKey();
BigDecimal existingValue = this.quantityUsedPerPromoCandidate.get(productPromoActionPK);
if (existingValue != null) {
totalUse = existingValue;
}
for (Map.Entry<GenericPK, BigDecimal> entry : this.quantityUsedPerPromoCandidate.entrySet()) {
GenericPK productPromoCondActionPK = entry.getKey();
BigDecimal quantityUsed = entry.getValue();
if (quantityUsed != null) {
// must be in the same rule and be a condition
if (productPromoId.equals(productPromoCondActionPK.getString("productPromoId")) && productPromoRuleId.equals(productPromoCondActionPK.getString("productPromoRuleId")) && productPromoCondActionPK.containsKey("productPromoCondSeqId")) {
totalUse = totalUse.add(quantityUsed);
}
}
}
return totalUse;
}
use of org.apache.ofbiz.entity.GenericPK in project ofbiz-framework by apache.
the class ShoppingCartItem method resetPromoRuleUse.
public synchronized void resetPromoRuleUse(String productPromoId, String productPromoRuleId) {
Iterator<Map.Entry<GenericPK, BigDecimal>> entryIter = this.quantityUsedPerPromoCandidate.entrySet().iterator();
while (entryIter.hasNext()) {
Map.Entry<GenericPK, BigDecimal> entry = entryIter.next();
GenericPK productPromoCondActionPK = entry.getKey();
BigDecimal quantityUsed = entry.getValue();
if (productPromoId.equals(productPromoCondActionPK.getString("productPromoId")) && productPromoRuleId.equals(productPromoCondActionPK.getString("productPromoRuleId"))) {
entryIter.remove();
BigDecimal existingValue = this.quantityUsedPerPromoFailed.get(productPromoCondActionPK);
if (existingValue == null) {
this.quantityUsedPerPromoFailed.put(productPromoCondActionPK, quantityUsed);
} else {
this.quantityUsedPerPromoFailed.put(productPromoCondActionPK, quantityUsed.add(existingValue));
}
this.promoQuantityUsed = this.promoQuantityUsed.subtract(quantityUsed);
}
}
}
use of org.apache.ofbiz.entity.GenericPK in project ofbiz-framework by apache.
the class ScriptHelperImpl method runFindByPrimaryKey.
private static GenericValue runFindByPrimaryKey(ModelEntity modelEntity, ContextHelper ctxHelper, boolean useCache, boolean autoFieldMap, Map<String, ? extends Object> fieldMap, List<String> selectFieldList) throws ScriptException {
Map<String, Object> entityContext = new HashMap<String, Object>();
Delegator delegator = ctxHelper.getDelegator();
Map<String, Object> context = ctxHelper.getBindings();
if (autoFieldMap) {
GenericValue tempVal = delegator.makeValue(modelEntity.getEntityName());
Object parametersObj = context.get("parameters");
if (parametersObj != null && parametersObj instanceof Map<?, ?>) {
tempVal.setAllFields(UtilGenerics.checkMap(parametersObj), true, null, Boolean.TRUE);
}
tempVal.setAllFields(context, true, null, Boolean.TRUE);
entityContext.putAll(tempVal);
}
if (fieldMap != null) {
entityContext.putAll(fieldMap);
}
entityContext.put("locale", context.get("locale"));
entityContext.put("timeZone", context.get("timeZone"));
modelEntity.convertFieldMapInPlace(entityContext, delegator);
entityContext.remove("locale");
entityContext.remove("timeZone");
Set<String> fieldsToSelect = null;
if (selectFieldList != null) {
fieldsToSelect = new HashSet<String>(selectFieldList);
}
if (fieldsToSelect != null && useCache) {
String errMsg = "Error running script " + ctxHelper.getScriptName() + ": Problem invoking the findOne method: Cannot specify selectFieldList argument when useCache is set to true ";
Debug.logWarning(errMsg, module);
throw new ScriptException(errMsg);
}
GenericValue valueOut = null;
GenericPK entityPK = delegator.makePK(modelEntity.getEntityName(), entityContext);
if (entityPK.containsPrimaryKey(true)) {
try {
if (useCache) {
valueOut = EntityQuery.use(delegator).from(entityPK.getEntityName()).where(entityPK).cache(true).queryOne();
} else {
if (fieldsToSelect != null) {
valueOut = delegator.findByPrimaryKeyPartial(entityPK, fieldsToSelect);
} else {
valueOut = EntityQuery.use(delegator).from(entityPK.getEntityName()).where(entityPK).queryOne();
}
}
} catch (GenericEntityException e) {
String errMsg = "Error running script " + ctxHelper.getScriptName() + ": Problem invoking the findOne method: " + e.getMessage();
Debug.logWarning(e, errMsg, module);
throw new ScriptException(errMsg);
}
} else {
if (Debug.warningOn()) {
Debug.logWarning("Error running script " + ctxHelper.getScriptName() + ": Returning null because found incomplete primary key in find: " + entityPK, module);
}
}
return valueOut;
}
use of org.apache.ofbiz.entity.GenericPK in project ofbiz-framework by apache.
the class EntityCache method remove.
public GenericValue remove(GenericPK pk) {
UtilCache<GenericPK, GenericValue> entityCache = getCache(pk.getEntityName());
if (Debug.verboseOn()) {
Debug.logVerbose("Removing from EntityCache with PK [" + pk + "], will remove from this cache: " + (entityCache == null ? "[No cache found to remove from]" : entityCache.getName()), module);
}
if (entityCache == null) {
return null;
}
GenericValue retVal = entityCache.remove(pk);
ModelEntity model = pk.getModelEntity();
if (model != null) {
Iterator<String> it = model.getViewConvertorsIterator();
while (it.hasNext()) {
String targetEntityName = it.next();
UtilCache.clearCache(getCacheName(targetEntityName));
}
}
if (Debug.verboseOn()) {
Debug.logVerbose("Removing from EntityCache with PK [" + pk + "], found this in the cache: " + retVal, module);
}
return retVal;
}
Aggregations