|
Modified: ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/entityops/MakeNextSeqId.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/entityops/MakeNextSeqId.java?rev=1351866&r1=1351865&r2=1351866&view=diff ============================================================================== --- ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/entityops/MakeNextSeqId.java (original) +++ ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/entityops/MakeNextSeqId.java Tue Jun 19 21:36:11 2012 @@ -18,79 +18,107 @@ *******************************************************************************/ package org.ofbiz.minilang.method.entityops; -import org.ofbiz.base.util.Debug; -import org.ofbiz.base.util.UtilValidate; +import org.ofbiz.base.util.collections.FlexibleMapAccessor; +import org.ofbiz.base.util.string.FlexibleStringExpander; import org.ofbiz.entity.GenericValue; import org.ofbiz.minilang.MiniLangException; +import org.ofbiz.minilang.MiniLangRuntimeException; +import org.ofbiz.minilang.MiniLangValidate; import org.ofbiz.minilang.SimpleMethod; -import org.ofbiz.minilang.method.ContextAccessor; import org.ofbiz.minilang.method.MethodContext; import org.ofbiz.minilang.method.MethodOperation; import org.w3c.dom.Element; /** - * Look at existing values for a sub-entity with a sequenced secondary ID, and get the highest plus 1 + * Implements the <make-next-seq-id> element. */ -public class MakeNextSeqId extends MethodOperation { +public final class MakeNextSeqId extends MethodOperation { public static final String module = MakeNextSeqId.class.getName(); - String incrementByStr; - String numericPaddingStr; - String seqFieldName; - ContextAccessor<GenericValue> valueAcsr; + private final FlexibleStringExpander incrementByFse; + private final FlexibleStringExpander numericPaddingFse; + private final FlexibleStringExpander seqFieldNameFse; + private final FlexibleMapAccessor<GenericValue> valueFma; public MakeNextSeqId(Element element, SimpleMethod simpleMethod) throws MiniLangException { super(element, simpleMethod); - seqFieldName = element.getAttribute("seq-field-name"); - valueAcsr = new ContextAccessor<GenericValue>(element.getAttribute("value-field"), element.getAttribute("value-name")); - numericPaddingStr = element.getAttribute("numeric-padding"); - incrementByStr = element.getAttribute("increment-by"); + if (MiniLangValidate.validationOn()) { + MiniLangValidate.attributeNames(simpleMethod, element, "value-field", "seq-field-name", "increment-by", "numeric-padding"); + MiniLangValidate.requiredAttributes(simpleMethod, element, "value-field", "seq-field-name"); + MiniLangValidate.expressionAttributes(simpleMethod, element, "value-field"); + MiniLangValidate.noChildElements(simpleMethod, element); + } + seqFieldNameFse = FlexibleStringExpander.getInstance(element.getAttribute("seq-field-name")); + valueFma = FlexibleMapAccessor.getInstance(element.getAttribute("value-field")); + numericPaddingFse = FlexibleStringExpander.getInstance(element.getAttribute("numeric-padding")); + incrementByFse = FlexibleStringExpander.getInstance(element.getAttribute("increment-by")); } @Override public boolean exec(MethodContext methodContext) throws MiniLangException { - String seqFieldName = methodContext.expandString(this.seqFieldName); - String numericPaddingStr = methodContext.expandString(this.numericPaddingStr); - String incrementByStr = methodContext.expandString(this.incrementByStr); + GenericValue value = valueFma.get(methodContext.getEnvMap()); + if (value == null) { + throw new MiniLangRuntimeException("Entity value not found with name: " + valueFma, this); + } + String seqFieldName = seqFieldNameFse.expandString(methodContext.getEnvMap()); + String numericPaddingStr = numericPaddingFse.expandString(methodContext.getEnvMap()); + String incrementByStr = incrementByFse.expandString(methodContext.getEnvMap()); int numericPadding = 5; - int incrementBy = 1; - try { - if (UtilValidate.isNotEmpty(numericPaddingStr)) { + if (!numericPaddingStr.isEmpty()) { + try { numericPadding = Integer.parseInt(numericPaddingStr); + } catch (Exception e) { + throw new MiniLangRuntimeException("Invalid number in \"numeric-padding\" attribute", this); } - } catch (Exception e) { - Debug.logError(e, "numeric-padding format invalid for [" + numericPaddingStr + "]", module); } - try { - if (UtilValidate.isNotEmpty(incrementByStr)) { + int incrementBy = 1; + if (!incrementByStr.isEmpty()) { + try { incrementBy = Integer.parseInt(incrementByStr); + } catch (Exception e) { + throw new MiniLangRuntimeException("Invalid number in \"increment-by\" attribute", this); } - } catch (Exception e) { - Debug.logError(e, "increment-by format invalid for [" + incrementByStr + "]", module); } - GenericValue value = valueAcsr.get(methodContext); methodContext.getDelegator().setNextSubSeqId(value, seqFieldName, numericPadding, incrementBy); return true; } @Override public String expandedString(MethodContext methodContext) { - // TODO: something more than a stub/dummy - return this.rawString(); + return FlexibleStringExpander.expandString(toString(), methodContext.getEnvMap()); } @Override public String rawString() { - // TODO: something more than the empty tag - return "<make-next-seq-id/>"; + return toString(); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder("<make-next-seq-id "); + sb.append("value-field=\"").append(this.valueFma).append("\" "); + sb.append("seq-field-name=\"").append(this.seqFieldNameFse).append("\" "); + if (!incrementByFse.isEmpty()) { + sb.append("increment-by=\"").append(this.incrementByFse).append("\" "); + } + if (!numericPaddingFse.isEmpty()) { + sb.append("numeric-padding=\"").append(this.numericPaddingFse).append("\" "); + } + sb.append("/>"); + return sb.toString(); } + /** + * A factory for the <make-next-seq-id> element. + */ public static final class MakeNextSeqIdFactory implements Factory<MakeNextSeqId> { + @Override public MakeNextSeqId createMethodOperation(Element element, SimpleMethod simpleMethod) throws MiniLangException { return new MakeNextSeqId(element, simpleMethod); } + @Override public String getName() { return "make-next-seq-id"; } Modified: ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/entityops/MakeValue.java URL: http://svn.apache.org/viewvc/ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/entityops/MakeValue.java?rev=1351866&r1=1351865&r2=1351866&view=diff ============================================================================== --- ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/entityops/MakeValue.java (original) +++ ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/entityops/MakeValue.java Tue Jun 19 21:36:11 2012 @@ -20,61 +20,87 @@ package org.ofbiz.minilang.method.entity import java.util.Map; -import org.ofbiz.minilang.artifact.ArtifactInfoContext; +import org.ofbiz.base.util.collections.FlexibleMapAccessor; +import org.ofbiz.base.util.string.FlexibleStringExpander; import org.ofbiz.entity.GenericValue; import org.ofbiz.minilang.MiniLangException; +import org.ofbiz.minilang.MiniLangRuntimeException; +import org.ofbiz.minilang.MiniLangValidate; import org.ofbiz.minilang.SimpleMethod; -import org.ofbiz.minilang.method.ContextAccessor; +import org.ofbiz.minilang.artifact.ArtifactInfoContext; import org.ofbiz.minilang.method.MethodContext; import org.ofbiz.minilang.method.MethodOperation; import org.w3c.dom.Element; /** - * Uses the delegator to find entity values by anding the map fields + * Implements the <make-value> element. */ -public class MakeValue extends MethodOperation { +public final class MakeValue extends MethodOperation { - String entityName; - ContextAccessor<Map<String, ? extends Object>> mapAcsr; - ContextAccessor<GenericValue> valueAcsr; + private final FlexibleStringExpander entityNameFse; + private final FlexibleMapAccessor<Map<String, ? extends Object>> mapFma; + private final FlexibleMapAccessor<GenericValue> valueFma; public MakeValue(Element element, SimpleMethod simpleMethod) throws MiniLangException { super(element, simpleMethod); - valueAcsr = new ContextAccessor<GenericValue>(element.getAttribute("value-field"), element.getAttribute("value-name")); - entityName = element.getAttribute("entity-name"); - mapAcsr = new ContextAccessor<Map<String, ? extends Object>>(element.getAttribute("map"), element.getAttribute("map-name")); + if (MiniLangValidate.validationOn()) { + MiniLangValidate.attributeNames(simpleMethod, element, "value-field", "entity-name", "map"); + MiniLangValidate.requiredAttributes(simpleMethod, element, "value-field", "entity-name"); + MiniLangValidate.expressionAttributes(simpleMethod, element, "value-field", "map"); + MiniLangValidate.noChildElements(simpleMethod, element); + } + valueFma = FlexibleMapAccessor.getInstance(element.getAttribute("value-field")); + entityNameFse = FlexibleStringExpander.getInstance(element.getAttribute("entity-name")); + mapFma = FlexibleMapAccessor.getInstance(element.getAttribute("map")); } @Override public boolean exec(MethodContext methodContext) throws MiniLangException { - String entityName = methodContext.expandString(this.entityName); - Map<String, ? extends Object> ctxMap = (mapAcsr.isEmpty() ? null : mapAcsr.get(methodContext)); - valueAcsr.put(methodContext, methodContext.getDelegator().makeValidValue(entityName, ctxMap)); + String entityName = entityNameFse.expandString(methodContext.getEnvMap()); + if (entityName.isEmpty()) { + throw new MiniLangRuntimeException("Entity name not found: " + entityNameFse, this); + } + valueFma.put(methodContext.getEnvMap(), methodContext.getDelegator().makeValidValue(entityName, mapFma.get(methodContext.getEnvMap()))); return true; } @Override public String expandedString(MethodContext methodContext) { - // TODO: something more than a stub/dummy - return this.rawString(); + return FlexibleStringExpander.expandString(toString(), methodContext.getEnvMap()); } @Override public void gatherArtifactInfo(ArtifactInfoContext aic) { - aic.addEntityName(entityName); + aic.addEntityName(entityNameFse.toString()); } @Override public String rawString() { - // TODO: something more than the empty tag - return "<make-value/>"; + return toString(); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder("<make-value "); + sb.append("entity-name=\"").append(this.entityNameFse).append("\" "); + sb.append("value-field=\"").append(this.valueFma).append("\" "); + if (!mapFma.isEmpty()) { + sb.append("map=\"").append(this.mapFma).append("\" "); + } + sb.append("/>"); + return sb.toString(); } + /** + * A factory for the <make-value> element. + */ public static final class MakeValueFactory implements Factory<MakeValue> { + @Override public MakeValue createMethodOperation(Element element, SimpleMethod simpleMethod) throws MiniLangException { return new MakeValue(element, simpleMethod); } + @Override public String getName() { return "make-value"; } Modified: ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/entityops/OrderValueList.java URL: http://svn.apache.org/viewvc/ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/entityops/OrderValueList.java?rev=1351866&r1=1351865&r2=1351866&view=diff ============================================================================== --- ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/entityops/OrderValueList.java (original) +++ ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/entityops/OrderValueList.java Tue Jun 19 21:36:11 2012 @@ -20,61 +20,81 @@ package org.ofbiz.minilang.method.entity import java.util.List; +import org.ofbiz.base.util.collections.FlexibleMapAccessor; +import org.ofbiz.base.util.string.FlexibleStringExpander; import org.ofbiz.entity.GenericEntity; import org.ofbiz.entity.util.EntityUtil; import org.ofbiz.minilang.MiniLangException; +import org.ofbiz.minilang.MiniLangValidate; import org.ofbiz.minilang.SimpleMethod; -import org.ofbiz.minilang.method.ContextAccessor; import org.ofbiz.minilang.method.MethodContext; import org.ofbiz.minilang.method.MethodOperation; import org.w3c.dom.Element; /** - * Order the given list of GenericValue objects + * Implements the <order-value-list> element. */ -public class OrderValueList extends MethodOperation { +public final class OrderValueList extends MethodOperation { - ContextAccessor<List<? extends GenericEntity>> listAcsr; - ContextAccessor<List<String>> orderByListAcsr; - ContextAccessor<List<? extends GenericEntity>> toListAcsr; + private final FlexibleMapAccessor<List<? extends GenericEntity>> listFma; + private final FlexibleMapAccessor<List<String>> orderByListFma; + private final FlexibleMapAccessor<List<? extends GenericEntity>> toListFma; public OrderValueList(Element element, SimpleMethod simpleMethod) throws MiniLangException { super(element, simpleMethod); - listAcsr = new ContextAccessor<List<? extends GenericEntity>>(element.getAttribute("list"), element.getAttribute("list-name")); - toListAcsr = new ContextAccessor<List<? extends GenericEntity>>(element.getAttribute("to-list"), element.getAttribute("to-list-name")); - if (toListAcsr.isEmpty()) { - toListAcsr = listAcsr; + if (MiniLangValidate.validationOn()) { + MiniLangValidate.attributeNames(simpleMethod, element, "list", "order-by-list", "to-list"); + MiniLangValidate.requiredAttributes(simpleMethod, element, "list", "order-by-list"); + MiniLangValidate.expressionAttributes(simpleMethod, element, "list", "order-by-list", "to-list"); + MiniLangValidate.noChildElements(simpleMethod, element); + } + listFma = FlexibleMapAccessor.getInstance(element.getAttribute("list")); + orderByListFma = FlexibleMapAccessor.getInstance(element.getAttribute("order-by-list")); + String toListAttribute = element.getAttribute("to-list"); + if (toListAttribute.isEmpty()) { + toListFma = listFma; + } else { + toListFma = FlexibleMapAccessor.getInstance(toListAttribute); } - orderByListAcsr = new ContextAccessor<List<String>>(element.getAttribute("order-by-list"), element.getAttribute("order-by-list-name")); } @Override public boolean exec(MethodContext methodContext) throws MiniLangException { - List<String> orderByList = null; - if (!orderByListAcsr.isEmpty()) { - orderByList = orderByListAcsr.get(methodContext); - } - toListAcsr.put(methodContext, EntityUtil.orderBy(listAcsr.get(methodContext), orderByList)); + List<String> orderByList = orderByListFma.get(methodContext.getEnvMap()); + toListFma.put(methodContext.getEnvMap(), EntityUtil.orderBy(listFma.get(methodContext.getEnvMap()), orderByList)); return true; } @Override public String expandedString(MethodContext methodContext) { - // TODO: something more than a stub/dummy - return this.rawString(); + return FlexibleStringExpander.expandString(toString(), methodContext.getEnvMap()); } @Override public String rawString() { - // TODO: something more than the empty tag - return "<order-value-list/>"; + return toString(); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder("<order-value-list "); + sb.append("list=\"").append(this.listFma).append("\" "); + sb.append("order-by-list=\"").append(this.orderByListFma).append("\" "); + sb.append("to-list=\"").append(this.toListFma).append("\" "); + sb.append("/>"); + return sb.toString(); } + /** + * A factory for the <order-value-list> element. + */ public static final class OrderValueListFactory implements Factory<OrderValueList> { + @Override public OrderValueList createMethodOperation(Element element, SimpleMethod simpleMethod) throws MiniLangException { return new OrderValueList(element, simpleMethod); } + @Override public String getName() { return "order-value-list"; } Modified: ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/entityops/RefreshValue.java URL: http://svn.apache.org/viewvc/ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/entityops/RefreshValue.java?rev=1351866&r1=1351865&r2=1351866&view=diff ============================================================================== --- ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/entityops/RefreshValue.java (original) +++ ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/entityops/RefreshValue.java Tue Jun 19 21:36:11 2012 @@ -19,47 +19,53 @@ package org.ofbiz.minilang.method.entityops; import org.ofbiz.base.util.Debug; +import org.ofbiz.base.util.collections.FlexibleMapAccessor; +import org.ofbiz.base.util.string.FlexibleStringExpander; import org.ofbiz.entity.GenericEntityException; import org.ofbiz.entity.GenericValue; import org.ofbiz.minilang.MiniLangException; +import org.ofbiz.minilang.MiniLangRuntimeException; +import org.ofbiz.minilang.MiniLangValidate; import org.ofbiz.minilang.SimpleMethod; -import org.ofbiz.minilang.method.ContextAccessor; import org.ofbiz.minilang.method.MethodContext; import org.ofbiz.minilang.method.MethodOperation; import org.w3c.dom.Element; /** - * Uses the delegator to refresh the specified value object entity from the datasource + * Implements the <refresh-value> element. */ -public class RefreshValue extends MethodOperation { +public final class RefreshValue extends MethodOperation { public static final String module = RemoveValue.class.getName(); - String doCacheClearStr; - ContextAccessor<GenericValue> valueAcsr; + private final FlexibleStringExpander doCacheClearFse; + private final FlexibleMapAccessor<GenericValue> valueFma; public RefreshValue(Element element, SimpleMethod simpleMethod) throws MiniLangException { super(element, simpleMethod); - valueAcsr = new ContextAccessor<GenericValue>(element.getAttribute("value-field"), element.getAttribute("value-name")); - doCacheClearStr = element.getAttribute("do-cache-clear"); + if (MiniLangValidate.validationOn()) { + MiniLangValidate.attributeNames(simpleMethod, element, "value-field", "do-cache-clear"); + MiniLangValidate.requiredAttributes(simpleMethod, element, "value-field"); + MiniLangValidate.expressionAttributes(simpleMethod, element, "value-field"); + MiniLangValidate.noChildElements(simpleMethod, element); + } + valueFma = FlexibleMapAccessor.getInstance(element.getAttribute("value-field")); + doCacheClearFse = FlexibleStringExpander.getInstance(element.getAttribute("do-cache-clear")); } @Override public boolean exec(MethodContext methodContext) throws MiniLangException { - boolean doCacheClear = !"false".equals(methodContext.expandString(doCacheClearStr)); - GenericValue value = valueAcsr.get(methodContext); + GenericValue value = valueFma.get(methodContext.getEnvMap()); if (value == null) { - String errMsg = "In remove-value a value was not found with the specified valueAcsr: " + valueAcsr + ", not removing"; - Debug.logWarning(errMsg, module); - methodContext.setErrorReturn(errMsg, simpleMethod); - return false; + throw new MiniLangRuntimeException("Entity value not found with name: " + valueFma, this); } + boolean doCacheClear = !"false".equals(doCacheClearFse.expandString(methodContext.getEnvMap())); try { methodContext.getDelegator().refresh(value, doCacheClear); } catch (GenericEntityException e) { - String errMsg = "ERROR: Could not complete the " + simpleMethod.getShortDescription() + " process [problem removing the " + valueAcsr + " value: " + e.getMessage() + "]"; - Debug.logError(e, errMsg, module); - methodContext.setErrorReturn(errMsg, simpleMethod); + String errMsg = "Exception thrown while refreshing value: " + e.getMessage(); + Debug.logWarning(e, errMsg, module); + simpleMethod.addErrorMessage(methodContext, errMsg); return false; } return true; @@ -67,21 +73,35 @@ public class RefreshValue extends Method @Override public String expandedString(MethodContext methodContext) { - // TODO: something more than a stub/dummy - return this.rawString(); + return FlexibleStringExpander.expandString(toString(), methodContext.getEnvMap()); } @Override public String rawString() { - // TODO: something more than the empty tag - return "<refresh-value/>"; + return toString(); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder("<refresh-value "); + sb.append("value-field=\"").append(this.valueFma).append("\" "); + if (!doCacheClearFse.isEmpty()) { + sb.append("do-cache-clear=\"").append(this.doCacheClearFse).append("\" "); + } + sb.append("/>"); + return sb.toString(); } + /** + * A factory for the <refresh-value> element. + */ public static final class RefreshValueFactory implements Factory<RefreshValue> { + @Override public RefreshValue createMethodOperation(Element element, SimpleMethod simpleMethod) throws MiniLangException { return new RefreshValue(element, simpleMethod); } + @Override public String getName() { return "refresh-value"; } Modified: ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/entityops/RemoveByAnd.java URL: http://svn.apache.org/viewvc/ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/entityops/RemoveByAnd.java?rev=1351866&r1=1351865&r2=1351866&view=diff ============================================================================== --- ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/entityops/RemoveByAnd.java (original) +++ ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/entityops/RemoveByAnd.java Tue Jun 19 21:36:11 2012 @@ -21,48 +21,51 @@ package org.ofbiz.minilang.method.entity import java.util.Map; import org.ofbiz.base.util.Debug; +import org.ofbiz.base.util.collections.FlexibleMapAccessor; +import org.ofbiz.base.util.string.FlexibleStringExpander; import org.ofbiz.entity.GenericEntityException; import org.ofbiz.minilang.MiniLangException; +import org.ofbiz.minilang.MiniLangValidate; import org.ofbiz.minilang.SimpleMethod; -import org.ofbiz.minilang.method.ContextAccessor; +import org.ofbiz.minilang.artifact.ArtifactInfoContext; import org.ofbiz.minilang.method.MethodContext; import org.ofbiz.minilang.method.MethodOperation; import org.w3c.dom.Element; /** - * Uses the delegator to remove entity values constrained by anding the map fields + * Implements the <remove-by-and> element. */ -public class RemoveByAnd extends MethodOperation { +public final class RemoveByAnd extends MethodOperation { public static final String module = RemoveByAnd.class.getName(); - String doCacheClearStr; - String entityName; - ContextAccessor<Map<String, ? extends Object>> mapAcsr; + private final FlexibleStringExpander doCacheClearFse; + private final FlexibleStringExpander entityNameFse; + private final FlexibleMapAccessor<Map<String, ? extends Object>> mapFma; public RemoveByAnd(Element element, SimpleMethod simpleMethod) throws MiniLangException { super(element, simpleMethod); - entityName = element.getAttribute("entity-name"); - mapAcsr = new ContextAccessor<Map<String, ? extends Object>>(element.getAttribute("map"), element.getAttribute("map-name")); - doCacheClearStr = element.getAttribute("do-cache-clear"); + if (MiniLangValidate.validationOn()) { + MiniLangValidate.attributeNames(simpleMethod, element, "entity-name", "map", "do-cache-clear"); + MiniLangValidate.requiredAttributes(simpleMethod, element, "entity-name", "map"); + MiniLangValidate.expressionAttributes(simpleMethod, element, "map"); + MiniLangValidate.noChildElements(simpleMethod, element); + } + entityNameFse = FlexibleStringExpander.getInstance(element.getAttribute("entity-name")); + mapFma = FlexibleMapAccessor.getInstance(element.getAttribute("map")); + doCacheClearFse = FlexibleStringExpander.getInstance(element.getAttribute("do-cache-clear")); } @Override public boolean exec(MethodContext methodContext) throws MiniLangException { - boolean doCacheClear = !"false".equals(doCacheClearStr); - String entityName = methodContext.expandString(this.entityName); + boolean doCacheClear = !"false".equals(doCacheClearFse.expandString(methodContext.getEnvMap())); + String entityName = entityNameFse.expandString(methodContext.getEnvMap()); try { - methodContext.getDelegator().removeByAnd(entityName, mapAcsr.get(methodContext), doCacheClear); + methodContext.getDelegator().removeByAnd(entityName, mapFma.get(methodContext.getEnvMap()), doCacheClear); } catch (GenericEntityException e) { - Debug.logError(e, module); - String errMsg = "ERROR: Could not complete the " + simpleMethod.getShortDescription() + " process [problem removing the " + entityName + " entity by and: " + e.getMessage() + "]"; - if (methodContext.getMethodType() == MethodContext.EVENT) { - methodContext.putEnv(simpleMethod.getEventErrorMessageName(), errMsg); - methodContext.putEnv(simpleMethod.getEventResponseCodeName(), simpleMethod.getDefaultErrorCode()); - } else if (methodContext.getMethodType() == MethodContext.SERVICE) { - methodContext.putEnv(simpleMethod.getServiceErrorMessageName(), errMsg); - methodContext.putEnv(simpleMethod.getServiceResponseMessageName(), simpleMethod.getDefaultErrorCode()); - } + String errMsg = "Exception thrown while removing entities: " + e.getMessage(); + Debug.logWarning(e, errMsg, module); + simpleMethod.addErrorMessage(methodContext, errMsg); return false; } return true; @@ -70,21 +73,41 @@ public class RemoveByAnd extends MethodO @Override public String expandedString(MethodContext methodContext) { - // TODO: something more than a stub/dummy - return this.rawString(); + return FlexibleStringExpander.expandString(toString(), methodContext.getEnvMap()); + } + + @Override + public void gatherArtifactInfo(ArtifactInfoContext aic) { + aic.addEntityName(entityNameFse.toString()); } @Override public String rawString() { - // TODO: something more than the empty tag - return "<remove-by-and/>"; + return toString(); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder("<remove-by-and "); + sb.append("entity-name=\"").append(this.entityNameFse).append("\" "); + sb.append("map=\"").append(this.mapFma).append("\" "); + if (!doCacheClearFse.isEmpty()) { + sb.append("do-cache-clear=\"").append(this.doCacheClearFse).append("\" "); + } + sb.append("/>"); + return sb.toString(); } + /** + * A factory for the <remove-by-and> element. + */ public static final class RemoveByAndFactory implements Factory<RemoveByAnd> { + @Override public RemoveByAnd createMethodOperation(Element element, SimpleMethod simpleMethod) throws MiniLangException { return new RemoveByAnd(element, simpleMethod); } + @Override public String getName() { return "remove-by-and"; } Modified: ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/entityops/RemoveList.java URL: http://svn.apache.org/viewvc/ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/entityops/RemoveList.java?rev=1351866&r1=1351865&r2=1351866&view=diff ============================================================================== --- ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/entityops/RemoveList.java (original) +++ ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/entityops/RemoveList.java Tue Jun 19 21:36:11 2012 @@ -21,59 +21,53 @@ package org.ofbiz.minilang.method.entity import java.util.List; import org.ofbiz.base.util.Debug; +import org.ofbiz.base.util.collections.FlexibleMapAccessor; +import org.ofbiz.base.util.string.FlexibleStringExpander; import org.ofbiz.entity.GenericEntityException; import org.ofbiz.entity.GenericValue; import org.ofbiz.minilang.MiniLangException; +import org.ofbiz.minilang.MiniLangRuntimeException; +import org.ofbiz.minilang.MiniLangValidate; import org.ofbiz.minilang.SimpleMethod; -import org.ofbiz.minilang.method.ContextAccessor; import org.ofbiz.minilang.method.MethodContext; import org.ofbiz.minilang.method.MethodOperation; import org.w3c.dom.Element; /** - * Uses the delegator to remove the specified value object (or psuedo-pk) list from the datasource + * Implements the <remove-list> element. */ -public class RemoveList extends MethodOperation { +public final class RemoveList extends MethodOperation { public static final String module = RemoveList.class.getName(); - String doCacheClearStr; - ContextAccessor<List<GenericValue>> listAcsr; + private final FlexibleStringExpander doCacheClearFse; + private final FlexibleMapAccessor<List<GenericValue>> listFma; public RemoveList(Element element, SimpleMethod simpleMethod) throws MiniLangException { super(element, simpleMethod); - listAcsr = new ContextAccessor<List<GenericValue>>(element.getAttribute("list"), element.getAttribute("list-name")); - doCacheClearStr = element.getAttribute("do-cache-clear"); + if (MiniLangValidate.validationOn()) { + MiniLangValidate.attributeNames(simpleMethod, element, "list", "do-cache-clear"); + MiniLangValidate.requiredAttributes(simpleMethod, element, "list"); + MiniLangValidate.expressionAttributes(simpleMethod, element, "list"); + MiniLangValidate.noChildElements(simpleMethod, element); + } + listFma = FlexibleMapAccessor.getInstance(element.getAttribute("list")); + doCacheClearFse = FlexibleStringExpander.getInstance(element.getAttribute("do-cache-clear")); } @Override public boolean exec(MethodContext methodContext) throws MiniLangException { - boolean doCacheClear = !"false".equals(doCacheClearStr); - List<GenericValue> values = listAcsr.get(methodContext); + List<GenericValue> values = listFma.get(methodContext.getEnvMap()); if (values == null) { - String errMsg = "In remove-list a value list was not found with the specified listAcsr: " + listAcsr + ", not removing"; - Debug.logWarning(errMsg, module); - if (methodContext.getMethodType() == MethodContext.EVENT) { - methodContext.putEnv(simpleMethod.getEventErrorMessageName(), errMsg); - methodContext.putEnv(simpleMethod.getEventResponseCodeName(), simpleMethod.getDefaultErrorCode()); - } else if (methodContext.getMethodType() == MethodContext.SERVICE) { - methodContext.putEnv(simpleMethod.getServiceErrorMessageName(), errMsg); - methodContext.putEnv(simpleMethod.getServiceResponseMessageName(), simpleMethod.getDefaultErrorCode()); - } - return false; + throw new MiniLangRuntimeException("Entity value list not found with name: " + listFma, this); } + boolean doCacheClear = !"false".equals(doCacheClearFse.expandString(methodContext.getEnvMap())); try { methodContext.getDelegator().removeAll(values, doCacheClear); } catch (GenericEntityException e) { - Debug.logError(e, module); - String errMsg = "ERROR: Could not complete the " + simpleMethod.getShortDescription() + " process [problem removing the " + listAcsr + " value list: " + e.getMessage() + "]"; - if (methodContext.getMethodType() == MethodContext.EVENT) { - methodContext.putEnv(simpleMethod.getEventErrorMessageName(), errMsg); - methodContext.putEnv(simpleMethod.getEventResponseCodeName(), simpleMethod.getDefaultErrorCode()); - } else if (methodContext.getMethodType() == MethodContext.SERVICE) { - methodContext.putEnv(simpleMethod.getServiceErrorMessageName(), errMsg); - methodContext.putEnv(simpleMethod.getServiceResponseMessageName(), simpleMethod.getDefaultErrorCode()); - } + String errMsg = "Exception thrown while removing entities: " + e.getMessage(); + Debug.logWarning(e, errMsg, module); + simpleMethod.addErrorMessage(methodContext, errMsg); return false; } return true; @@ -81,21 +75,35 @@ public class RemoveList extends MethodOp @Override public String expandedString(MethodContext methodContext) { - // TODO: something more than a stub/dummy - return this.rawString(); + return FlexibleStringExpander.expandString(toString(), methodContext.getEnvMap()); } @Override public String rawString() { - // TODO: something more than the empty tag - return "<remove-list/>"; + return toString(); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder("<remove-list "); + sb.append("list=\"").append(this.listFma).append("\" "); + if (!doCacheClearFse.isEmpty()) { + sb.append("do-cache-clear=\"").append(this.doCacheClearFse).append("\" "); + } + sb.append("/>"); + return sb.toString(); } + /** + * A factory for the <remove-list> element. + */ public static final class RemoveListFactory implements Factory<RemoveList> { + @Override public RemoveList createMethodOperation(Element element, SimpleMethod simpleMethod) throws MiniLangException { return new RemoveList(element, simpleMethod); } + @Override public String getName() { return "remove-list"; } Modified: ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/entityops/RemoveRelated.java URL: http://svn.apache.org/viewvc/ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/entityops/RemoveRelated.java?rev=1351866&r1=1351865&r2=1351866&view=diff ============================================================================== --- ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/entityops/RemoveRelated.java (original) +++ ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/entityops/RemoveRelated.java Tue Jun 19 21:36:11 2012 @@ -19,62 +19,57 @@ package org.ofbiz.minilang.method.entityops; import org.ofbiz.base.util.Debug; +import org.ofbiz.base.util.collections.FlexibleMapAccessor; +import org.ofbiz.base.util.string.FlexibleStringExpander; import org.ofbiz.entity.GenericEntityException; import org.ofbiz.entity.GenericValue; import org.ofbiz.minilang.MiniLangException; +import org.ofbiz.minilang.MiniLangRuntimeException; +import org.ofbiz.minilang.MiniLangValidate; import org.ofbiz.minilang.SimpleMethod; -import org.ofbiz.minilang.method.ContextAccessor; +import org.ofbiz.minilang.artifact.ArtifactInfoContext; import org.ofbiz.minilang.method.MethodContext; import org.ofbiz.minilang.method.MethodOperation; import org.w3c.dom.Element; /** - * Uses the delegator to remove entities related to the specified value object from the datasource + * Implements the <remove-related> element. */ -public class RemoveRelated extends MethodOperation { +public final class RemoveRelated extends MethodOperation { public static final String module = RemoveRelated.class.getName(); - String doCacheClearStr; - String relationName; - ContextAccessor<GenericValue> valueAcsr; + private final FlexibleStringExpander doCacheClearFse; + private final FlexibleStringExpander relationNameFse; + private final FlexibleMapAccessor<GenericValue> valueFma; public RemoveRelated(Element element, SimpleMethod simpleMethod) throws MiniLangException { super(element, simpleMethod); - valueAcsr = new ContextAccessor<GenericValue>(element.getAttribute("value-field"), element.getAttribute("value-name")); - relationName = element.getAttribute("relation-name"); - doCacheClearStr = element.getAttribute("do-cache-clear"); + if (MiniLangValidate.validationOn()) { + MiniLangValidate.attributeNames(simpleMethod, element, "value-field", "relation-name", "do-cache-clear"); + MiniLangValidate.requiredAttributes(simpleMethod, element, "value-field", "relation-name"); + MiniLangValidate.expressionAttributes(simpleMethod, element, "value-field"); + MiniLangValidate.noChildElements(simpleMethod, element); + } + valueFma = FlexibleMapAccessor.getInstance(element.getAttribute("value-field")); + relationNameFse = FlexibleStringExpander.getInstance(element.getAttribute("relation-name")); + doCacheClearFse = FlexibleStringExpander.getInstance(element.getAttribute("do-cache-clear")); } @Override public boolean exec(MethodContext methodContext) throws MiniLangException { - boolean doCacheClear = !"false".equals(doCacheClearStr); - String relationName = methodContext.expandString(this.relationName); - GenericValue value = valueAcsr.get(methodContext); + GenericValue value = valueFma.get(methodContext.getEnvMap()); if (value == null) { - String errMsg = "In remove-related a value was not found with the specified valueAcsr: " + valueAcsr + ", not removing related"; - Debug.logWarning(errMsg, module); - if (methodContext.getMethodType() == MethodContext.EVENT) { - methodContext.putEnv(simpleMethod.getEventErrorMessageName(), errMsg); - methodContext.putEnv(simpleMethod.getEventResponseCodeName(), simpleMethod.getDefaultErrorCode()); - } else if (methodContext.getMethodType() == MethodContext.SERVICE) { - methodContext.putEnv(simpleMethod.getServiceErrorMessageName(), errMsg); - methodContext.putEnv(simpleMethod.getServiceResponseMessageName(), simpleMethod.getDefaultErrorCode()); - } - return false; + throw new MiniLangRuntimeException("Entity value not found with name: " + valueFma, this); } + String relationName = relationNameFse.expandString(methodContext.getEnvMap()); + boolean doCacheClear = !"false".equals(doCacheClearFse.expandString(methodContext.getEnvMap())); try { methodContext.getDelegator().removeRelated(relationName, value, doCacheClear); } catch (GenericEntityException e) { - Debug.logError(e, module); - String errMsg = "ERROR: Could not complete the " + simpleMethod.getShortDescription() + " process [problem removing the relation " + relationName + " of the value " + valueAcsr + " value: " + e.getMessage() + "]"; - if (methodContext.getMethodType() == MethodContext.EVENT) { - methodContext.putEnv(simpleMethod.getEventErrorMessageName(), errMsg); - methodContext.putEnv(simpleMethod.getEventResponseCodeName(), simpleMethod.getDefaultErrorCode()); - } else if (methodContext.getMethodType() == MethodContext.SERVICE) { - methodContext.putEnv(simpleMethod.getServiceErrorMessageName(), errMsg); - methodContext.putEnv(simpleMethod.getServiceResponseMessageName(), simpleMethod.getDefaultErrorCode()); - } + String errMsg = "Exception thrown while removing related entities: " + e.getMessage(); + Debug.logWarning(e, errMsg, module); + simpleMethod.addErrorMessage(methodContext, errMsg); return false; } return true; @@ -82,21 +77,41 @@ public class RemoveRelated extends Metho @Override public String expandedString(MethodContext methodContext) { - // TODO: something more than a stub/dummy - return this.rawString(); + return FlexibleStringExpander.expandString(toString(), methodContext.getEnvMap()); + } + + @Override + public void gatherArtifactInfo(ArtifactInfoContext aic) { + aic.addEntityName(relationNameFse.toString()); } @Override public String rawString() { - // TODO: something more than the empty tag - return "<remove-related/>"; + return toString(); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder("<remove-related "); + sb.append("value-field=\"").append(this.valueFma).append("\" "); + sb.append("relation-name=\"").append(this.relationNameFse).append("\" "); + if (!doCacheClearFse.isEmpty()) { + sb.append("do-cache-clear=\"").append(this.doCacheClearFse).append("\" "); + } + sb.append("/>"); + return sb.toString(); } + /** + * A factory for the <remove-related> element. + */ public static final class RemoveRelatedFactory implements Factory<RemoveRelated> { + @Override public RemoveRelated createMethodOperation(Element element, SimpleMethod simpleMethod) throws MiniLangException { return new RemoveRelated(element, simpleMethod); } + @Override public String getName() { return "remove-related"; } Modified: ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/entityops/RemoveValue.java URL: http://svn.apache.org/viewvc/ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/entityops/RemoveValue.java?rev=1351866&r1=1351865&r2=1351866&view=diff ============================================================================== --- ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/entityops/RemoveValue.java (original) +++ ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/entityops/RemoveValue.java Tue Jun 19 21:36:11 2012 @@ -19,47 +19,53 @@ package org.ofbiz.minilang.method.entityops; import org.ofbiz.base.util.Debug; +import org.ofbiz.base.util.collections.FlexibleMapAccessor; +import org.ofbiz.base.util.string.FlexibleStringExpander; import org.ofbiz.entity.GenericEntityException; import org.ofbiz.entity.GenericValue; import org.ofbiz.minilang.MiniLangException; +import org.ofbiz.minilang.MiniLangRuntimeException; +import org.ofbiz.minilang.MiniLangValidate; import org.ofbiz.minilang.SimpleMethod; -import org.ofbiz.minilang.method.ContextAccessor; import org.ofbiz.minilang.method.MethodContext; import org.ofbiz.minilang.method.MethodOperation; import org.w3c.dom.Element; /** - * Uses the delegator to remove the specified value object entity from the datasource + * Implements the <remove-value> element. */ public class RemoveValue extends MethodOperation { public static final String module = RemoveValue.class.getName(); - String doCacheClearStr; - ContextAccessor<GenericValue> valueAcsr; + private final FlexibleStringExpander doCacheClearFse; + private final FlexibleMapAccessor<GenericValue> valueFma; public RemoveValue(Element element, SimpleMethod simpleMethod) throws MiniLangException { super(element, simpleMethod); - valueAcsr = new ContextAccessor<GenericValue>(element.getAttribute("value-field"), element.getAttribute("value-name")); - doCacheClearStr = element.getAttribute("do-cache-clear"); + if (MiniLangValidate.validationOn()) { + MiniLangValidate.attributeNames(simpleMethod, element, "value-field", "do-cache-clear"); + MiniLangValidate.requiredAttributes(simpleMethod, element, "value-field"); + MiniLangValidate.expressionAttributes(simpleMethod, element, "value-field"); + MiniLangValidate.noChildElements(simpleMethod, element); + } + valueFma = FlexibleMapAccessor.getInstance(element.getAttribute("value-field")); + doCacheClearFse = FlexibleStringExpander.getInstance(element.getAttribute("do-cache-clear")); } @Override public boolean exec(MethodContext methodContext) throws MiniLangException { - boolean doCacheClear = !"false".equals(methodContext.expandString(doCacheClearStr)); - GenericValue value = valueAcsr.get(methodContext); + GenericValue value = valueFma.get(methodContext.getEnvMap()); if (value == null) { - String errMsg = "In remove-value a value was not found with the specified valueAcsr: " + valueAcsr + ", not removing"; - Debug.logWarning(errMsg, module); - methodContext.setErrorReturn(errMsg, simpleMethod); - return false; + throw new MiniLangRuntimeException("Entity value not found with name: " + valueFma, this); } + boolean doCacheClear = !"false".equals(doCacheClearFse.expandString(methodContext.getEnvMap())); try { methodContext.getDelegator().removeValue(value, doCacheClear); } catch (GenericEntityException e) { - String errMsg = "ERROR: Could not complete the " + simpleMethod.getShortDescription() + " process [problem removing the " + valueAcsr + " value: " + e.getMessage() + "]"; - Debug.logError(e, errMsg, module); - methodContext.setErrorReturn(errMsg, simpleMethod); + String errMsg = "Exception thrown while removing entity value: " + e.getMessage(); + Debug.logWarning(e, errMsg, module); + simpleMethod.addErrorMessage(methodContext, errMsg); return false; } return true; @@ -67,21 +73,35 @@ public class RemoveValue extends MethodO @Override public String expandedString(MethodContext methodContext) { - // TODO: something more than a stub/dummy - return this.rawString(); + return FlexibleStringExpander.expandString(toString(), methodContext.getEnvMap()); } @Override public String rawString() { - // TODO: something more than the empty tag - return "<remove-value/>"; + return toString(); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder("<remove-value "); + sb.append("value-field=\"").append(this.valueFma).append("\" "); + if (!doCacheClearFse.isEmpty()) { + sb.append("do-cache-clear=\"").append(this.doCacheClearFse).append("\" "); + } + sb.append("/>"); + return sb.toString(); } + /** + * A factory for the <remove-value> element. + */ public static final class RemoveValueFactory implements Factory<RemoveValue> { + @Override public RemoveValue createMethodOperation(Element element, SimpleMethod simpleMethod) throws MiniLangException { return new RemoveValue(element, simpleMethod); } + @Override public String getName() { return "remove-value"; } Modified: ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/entityops/SequencedIdToEnv.java URL: http://svn.apache.org/viewvc/ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/entityops/SequencedIdToEnv.java?rev=1351866&r1=1351865&r2=1351866&view=diff ============================================================================== --- ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/entityops/SequencedIdToEnv.java (original) +++ ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/entityops/SequencedIdToEnv.java Tue Jun 19 21:36:11 2012 @@ -18,82 +18,97 @@ *******************************************************************************/ package org.ofbiz.minilang.method.entityops; -import org.ofbiz.base.util.UtilValidate; +import org.ofbiz.base.util.collections.FlexibleMapAccessor; +import org.ofbiz.base.util.string.FlexibleStringExpander; import org.ofbiz.minilang.MiniLangException; +import org.ofbiz.minilang.MiniLangValidate; import org.ofbiz.minilang.SimpleMethod; -import org.ofbiz.minilang.method.ContextAccessor; import org.ofbiz.minilang.method.MethodContext; import org.ofbiz.minilang.method.MethodOperation; import org.w3c.dom.Element; /** - * Gets a sequenced ID from the delegator and puts it in the env + * Implements the <sequenced-id> element. */ -public class SequencedIdToEnv extends MethodOperation { +public final class SequencedIdToEnv extends MethodOperation { - ContextAccessor<Object> envAcsr; - boolean getLongOnly; - String seqName; - long staggerMax = 1; + private final FlexibleMapAccessor<Object> fieldFma; + private final boolean getLongOnly; + private final FlexibleStringExpander sequenceNameFse; + private final long staggerMax; public SequencedIdToEnv(Element element, SimpleMethod simpleMethod) throws MiniLangException { super(element, simpleMethod); - seqName = element.getAttribute("sequence-name"); - envAcsr = new ContextAccessor<Object>(element.getAttribute("field"), element.getAttribute("env-name")); - // default false, anything but true is false + if (MiniLangValidate.validationOn()) { + MiniLangValidate.attributeNames(simpleMethod, element, "sequence-name", "field", "get-long-only", "stagger-max"); + MiniLangValidate.requiredAttributes(simpleMethod, element, "sequence-name", "field"); + MiniLangValidate.expressionAttributes(simpleMethod, element, "field"); + MiniLangValidate.noChildElements(simpleMethod, element); + } + sequenceNameFse = FlexibleStringExpander.getInstance(element.getAttribute("sequence-name")); + fieldFma = FlexibleMapAccessor.getInstance(element.getAttribute("field")); getLongOnly = "true".equals(element.getAttribute("get-long-only")); - String staggerMaxStr = element.getAttribute("stagger-max"); - if (UtilValidate.isNotEmpty(staggerMaxStr)) { + long staggerMax = 1; + String staggerMaxAttribute = element.getAttribute("stagger-max"); + if (!staggerMaxAttribute.isEmpty()) { try { - this.staggerMax = Long.parseLong(staggerMaxStr); - if (this.staggerMax < 1) { - this.staggerMax = 1; + staggerMax = Long.parseLong(staggerMaxAttribute); + if (staggerMax < 1) { + staggerMax = 1; } } catch (NumberFormatException e) { - this.staggerMax = 1; + MiniLangValidate.handleError("Invalid stagger-max attribute value: " + e.getMessage(), simpleMethod, element); } } + this.staggerMax = staggerMax; } + @Override public boolean exec(MethodContext methodContext) throws MiniLangException { - String seqName = methodContext.expandString(this.seqName); + String seqName = sequenceNameFse.expandString(methodContext.getEnvMap()); if (getLongOnly) { - envAcsr.put(methodContext, methodContext.getDelegator().getNextSeqIdLong(seqName, staggerMax)); + fieldFma.put(methodContext.getEnvMap(), methodContext.getDelegator().getNextSeqIdLong(seqName, staggerMax)); } else { - envAcsr.put(methodContext, methodContext.getDelegator().getNextSeqId(seqName, staggerMax)); + fieldFma.put(methodContext.getEnvMap(), methodContext.getDelegator().getNextSeqId(seqName, staggerMax)); } return true; } @Override public String expandedString(MethodContext methodContext) { - // TODO: something more than a stub/dummy - return this.rawString(); + return FlexibleStringExpander.expandString(toString(), methodContext.getEnvMap()); } @Override public String rawString() { - // TODO: something more than the empty tag - return "<sequenced-id-to-env/>"; + return toString(); } - public static final class SequencedIdFactory implements Factory<SequencedIdToEnv> { - public SequencedIdToEnv createMethodOperation(Element element, SimpleMethod simpleMethod) throws MiniLangException { - return new SequencedIdToEnv(element, simpleMethod); - } - - public String getName() { - return "sequenced-id"; - } + @Override + public String toString() { + StringBuilder sb = new StringBuilder("<sequenced-id "); + sb.append("sequence-name=\"").append(this.sequenceNameFse).append("\" "); + sb.append("field=\"").append(this.fieldFma).append("\" "); + sb.append("stagger-max=\"").append(this.staggerMax).append("\" "); + if (this.getLongOnly) { + sb.append("get-long-only=\"true\" "); + } + sb.append("/>"); + return sb.toString(); } - public static final class SequencedIdToEnvFactory implements Factory<SequencedIdToEnv> { + /** + * A factory for the <sequenced-id> element. + */ + public static final class SequencedIdFactory implements Factory<SequencedIdToEnv> { + @Override public SequencedIdToEnv createMethodOperation(Element element, SimpleMethod simpleMethod) throws MiniLangException { return new SequencedIdToEnv(element, simpleMethod); } + @Override public String getName() { - return "sequenced-id-to-env"; + return "sequenced-id"; } } } Modified: ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/envops/Now.java URL: http://svn.apache.org/viewvc/ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/envops/Now.java?rev=1351866&r1=1351865&r2=1351866&view=diff ============================================================================== --- ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/envops/Now.java (original) +++ ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/envops/Now.java Tue Jun 19 21:36:11 2012 @@ -26,18 +26,37 @@ import org.ofbiz.base.util.collections.F import org.ofbiz.base.util.string.FlexibleStringExpander; import org.ofbiz.minilang.MiniLangException; import org.ofbiz.minilang.MiniLangRuntimeException; +import org.ofbiz.minilang.MiniLangUtil; import org.ofbiz.minilang.MiniLangValidate; import org.ofbiz.minilang.SimpleMethod; import org.ofbiz.minilang.ValidationException; import org.ofbiz.minilang.method.MethodContext; import org.ofbiz.minilang.method.MethodOperation; +import org.w3c.dom.Document; import org.w3c.dom.Element; /** - * Sets a field to the current system time. + * Implements the <now>, <now-date-to-env>, and <now-timestamp> elements. */ public final class Now extends MethodOperation { + // This method is needed only during the v1 to v2 transition + private static boolean autoCorrect(Element element) { + String tagName = element.getTagName(); + if ("now-date-to-env".equals(tagName) || "now-timestamp".equals(tagName)) { + Document doc = element.getOwnerDocument(); + Element newElement = doc.createElement("now"); + newElement.setAttribute("field", element.getAttribute("field")); + if ("now-date-to-env".equals(tagName)) { + element.setAttribute("type", "java.sql.Date"); + newElement.setAttribute("type", "java.sql.Date"); + } + element.getParentNode().replaceChild(newElement, element); + return true; + } + return false; + } + private final FlexibleMapAccessor<Object> fieldFma; private final String type; private final Converter<Long, ? extends Object> converter; @@ -45,17 +64,25 @@ public final class Now extends MethodOpe public Now(Element element, SimpleMethod simpleMethod) throws MiniLangException { super(element, simpleMethod); if (MiniLangValidate.validationOn()) { + String tagName = element.getTagName(); + if ("now-date-to-env".equals(tagName) || "now-timestamp".equals(tagName)) { + MiniLangValidate.handleError("Deprecated - use <now>", simpleMethod, element); + } MiniLangValidate.attributeNames(simpleMethod, element, "field", "type"); MiniLangValidate.requiredAttributes(simpleMethod, element, "field"); MiniLangValidate.expressionAttributes(simpleMethod, element, "field"); MiniLangValidate.constantAttributes(simpleMethod, element, "type"); MiniLangValidate.noChildElements(simpleMethod, element); } + boolean elementModified = autoCorrect(element); + if (elementModified && MiniLangUtil.autoCorrectOn()) { + MiniLangUtil.flagDocumentAsCorrected(element); + } this.fieldFma = FlexibleMapAccessor.getInstance(element.getAttribute("field")); this.type = element.getAttribute("type"); Class<?> targetClass = null; try { - if (this.type.length() > 0) { + if (!this.type.isEmpty()) { targetClass = ObjectType.loadClass(this.type); } if (targetClass == null) { @@ -93,7 +120,7 @@ public final class Now extends MethodOpe if (!this.fieldFma.isEmpty()) { sb.append("field=\"").append(this.fieldFma).append("\" "); } - if (this.type.length() > 0) { + if (!this.type.isEmpty()) { sb.append("type=\"").append(this.type).append("\" "); } sb.append("/>"); @@ -101,13 +128,48 @@ public final class Now extends MethodOpe } + /** + * A factory for the <now> element. + */ public static final class NowFactory implements Factory<Now> { + @Override public Now createMethodOperation(Element element, SimpleMethod simpleMethod) throws MiniLangException { return new Now(element, simpleMethod); } + @Override public String getName() { return "now"; } } + + /** + * A factory for the <now-date-to-env> element. + */ + public static final class NowDateToEnvFactory implements Factory<Now> { + @Override + public Now createMethodOperation(Element element, SimpleMethod simpleMethod) throws MiniLangException { + return new Now(element, simpleMethod); + } + + @Override + public String getName() { + return "now-date-to-env"; + } + } + + /** + * A factory for the <now-timestamp> element. + */ + public static final class NowTimestampFactory implements Factory<Now> { + @Override + public Now createMethodOperation(Element element, SimpleMethod simpleMethod) throws MiniLangException { + return new Now(element, simpleMethod); + } + + @Override + public String getName() { + return "now-timestamp"; + } + } } Modified: ofbiz/branches/20120329_portletWidget/framework/resources/templates/ofbiz-component.xml URL: http://svn.apache.org/viewvc/ofbiz/branches/20120329_portletWidget/framework/resources/templates/ofbiz-component.xml?rev=1351866&r1=1351865&r2=1351866&view=diff ============================================================================== --- ofbiz/branches/20120329_portletWidget/framework/resources/templates/ofbiz-component.xml (original) +++ ofbiz/branches/20120329_portletWidget/framework/resources/templates/ofbiz-component.xml Tue Jun 19 21:36:11 2012 @@ -17,7 +17,7 @@ <entity-resource type="model" reader-name="main" loader="main" location="entitydef/entitymodel.xml"/> <!-- <entity-resource type="eca" reader-name="main" loader="main" location="entitydef/eecas.xml"/> --> <entity-resource type="data" reader-name="seed" loader="main" location="data/@[hidden email]"/> - <entity-resource type="data" reader-name="seed" loader="main" location="data/@[hidden email]"/> + <entity-resource type="data" reader-name="seed" loader="main" location="data/@[hidden email]"/><!-- leave the type at seed because this will be used in hot-deploy where the required security files need to be loaded. --> <entity-resource type="data" reader-name="demo" loader="main" location="data/@[hidden email]"/> <!-- service resources: model(s), eca(s) and group definitions --> Propchange: ofbiz/branches/20120329_portletWidget/framework/security/data/PasswordSecurityData.xml ------------------------------------------------------------------------------ Merged /ofbiz/trunk/framework/security/data/PasswordSecurityData.xml:r1340642-1346323 Modified: ofbiz/branches/20120329_portletWidget/framework/security/ofbiz-component.xml URL: http://svn.apache.org/viewvc/ofbiz/branches/20120329_portletWidget/framework/security/ofbiz-component.xml?rev=1351866&r1=1351865&r2=1351866&view=diff ============================================================================== --- ofbiz/branches/20120329_portletWidget/framework/security/ofbiz-component.xml (original) +++ ofbiz/branches/20120329_portletWidget/framework/security/ofbiz-component.xml Tue Jun 19 21:36:11 2012 @@ -26,7 +26,7 @@ under the License. <classpath type="dir" location="dtd"/> <classpath type="jar" location="build/lib/*"/> <entity-resource type="model" reader-name="main" loader="main" location="entitydef/entitymodel.xml"/> - <entity-resource type="data" reader-name="seed" loader="main" location="data/SecurityData.xml"/> + <entity-resource type="data" reader-name="security" loader="main" location="data/SecurityData.xml"/> <!-- NOTE: comment this line out to ensure no resetting of passwords --> <entity-resource type="data" reader-name="demo" loader="main" location="data/PasswordSecurityData.xml"/> <entity-resource type="data" reader-name="demo" loader="main" location="data/SecurityDemoData.xml"/> Modified: ofbiz/branches/20120329_portletWidget/framework/security/src/org/ofbiz/security/authz/da/DynamicAccessFactory.java URL: http://svn.apache.org/viewvc/ofbiz/branches/20120329_portletWidget/framework/security/src/org/ofbiz/security/authz/da/DynamicAccessFactory.java?rev=1351866&r1=1351865&r2=1351866&view=diff ============================================================================== --- ofbiz/branches/20120329_portletWidget/framework/security/src/org/ofbiz/security/authz/da/DynamicAccessFactory.java (original) +++ ofbiz/branches/20120329_portletWidget/framework/security/src/org/ofbiz/security/authz/da/DynamicAccessFactory.java Tue Jun 19 21:36:11 2012 @@ -34,7 +34,7 @@ public class DynamicAccessFactory { /** * Cache to store the DynamicAccess implementations */ - private static UtilCache<String,DynamicAccessHandler> dynamicAccessHandlerCache = UtilCache.createUtilCache("security.DynamicAccessHandlerCache"); + private static final UtilCache<String,DynamicAccessHandler> dynamicAccessHandlerCache = UtilCache.createUtilCache("security.DynamicAccessHandlerCache"); private static final String module = DynamicAccessFactory.class.getName(); public static DynamicAccessHandler getDynamicAccessHandler(Delegator delegator, String accessString) { Modified: ofbiz/branches/20120329_portletWidget/framework/security/src/org/ofbiz/security/authz/da/ObjectDaHandler.java URL: http://svn.apache.org/viewvc/ofbiz/branches/20120329_portletWidget/framework/security/src/org/ofbiz/security/authz/da/ObjectDaHandler.java?rev=1351866&r1=1351865&r2=1351866&view=diff ============================================================================== --- ofbiz/branches/20120329_portletWidget/framework/security/src/org/ofbiz/security/authz/da/ObjectDaHandler.java (original) +++ ofbiz/branches/20120329_portletWidget/framework/security/src/org/ofbiz/security/authz/da/ObjectDaHandler.java Tue Jun 19 21:36:11 2012 @@ -25,7 +25,7 @@ import org.ofbiz.entity.Delegator; public class ObjectDaHandler implements DynamicAccessHandler { - private static UtilCache<String,DynamicAccess> dynamicAccessCache = UtilCache.createUtilCache("security.DynamicAccessCache"); + private static final UtilCache<String,DynamicAccess> dynamicAccessCache = UtilCache.createUtilCache("security.DynamicAccessCache"); protected Delegator delegator; Modified: ofbiz/branches/20120329_portletWidget/framework/service/config/serviceengine.xml URL: http://svn.apache.org/viewvc/ofbiz/branches/20120329_portletWidget/framework/service/config/serviceengine.xml?rev=1351866&r1=1351865&r2=1351866&view=diff ============================================================================== --- ofbiz/branches/20120329_portletWidget/framework/service/config/serviceengine.xml (original) +++ ofbiz/branches/20120329_portletWidget/framework/service/config/serviceengine.xml Tue Jun 19 21:36:11 2012 @@ -61,7 +61,6 @@ under the License. <engine name="rmi" class="org.ofbiz.service.rmi.RmiServiceEngine"/> <engine name="soap" class="org.ofbiz.service.engine.SOAPClientEngine"/> <engine name="ofbiz-workflow" class="org.ofbiz.workflow.WorkflowEngine"/> - <engine name="workflow" class="org.ofbiz.shark.service.SharkServiceEngine"/> <!-- The engine xml-rpc-local is only used by a test service and for this reason it is configured to run on port 8081 (see test-containers.xml); in order to use this in OFBiz change the port accordingly (for demo the default Modified: ofbiz/branches/20120329_portletWidget/framework/service/ofbiz-component.xml URL: http://svn.apache.org/viewvc/ofbiz/branches/20120329_portletWidget/framework/service/ofbiz-component.xml?rev=1351866&r1=1351865&r2=1351866&view=diff ============================================================================== --- ofbiz/branches/20120329_portletWidget/framework/service/ofbiz-component.xml (original) +++ ofbiz/branches/20120329_portletWidget/framework/service/ofbiz-component.xml Tue Jun 19 21:36:11 2012 @@ -31,7 +31,7 @@ under the License. <entity-resource type="data" reader-name="seed" loader="main" location="data/ScheduledServiceData.xml"/> <entity-resource type="data" reader-name="seed-initial" loader="main" location="data/ScheduledServices.xml"/> <entity-resource type="data" reader-name="seed" loader="main" location="data/ServiceSeedData.xml"/> - <entity-resource type="data" reader-name="seed" loader="main" location="data/ServiceSecurityData.xml"/> + <entity-resource type="data" reader-name="security" loader="main" location="data/ServiceSecurityData.xml"/> <entity-resource type="data" reader-name="demo" loader="main" location="data/ServiceDemoData.xml"/> <service-resource type="model" loader="main" location="servicedef/services.xml"/> Modified: ofbiz/branches/20120329_portletWidget/framework/service/src/org/ofbiz/service/DispatchContext.java URL: http://svn.apache.org/viewvc/ofbiz/branches/20120329_portletWidget/framework/service/src/org/ofbiz/service/DispatchContext.java?rev=1351866&r1=1351865&r2=1351866&view=diff ============================================================================== --- ofbiz/branches/20120329_portletWidget/framework/service/src/org/ofbiz/service/DispatchContext.java (original) +++ ofbiz/branches/20120329_portletWidget/framework/service/src/org/ofbiz/service/DispatchContext.java Tue Jun 19 21:36:11 2012 @@ -59,7 +59,7 @@ public class DispatchContext implements public static final String module = DispatchContext.class.getName(); protected static final String GLOBAL_KEY = "global.services"; - public static UtilCache<String, Map<String, ModelService>> modelServiceMapByDispatcher = UtilCache.createUtilCache("service.ModelServiceMapByDispatcher", 0, 0, false); + private static final UtilCache<String, Map<String, ModelService>> modelServiceMapByDispatcher = UtilCache.createUtilCache("service.ModelServiceMapByDispatcher", 0, 0, false); protected transient LocalDispatcher dispatcher; protected transient ClassLoader loader; @@ -271,24 +271,19 @@ public class DispatchContext implements private Map<String, ModelService> getLocalServiceMap() { Map<String, ModelService> serviceMap = modelServiceMapByDispatcher.get(name); if (serviceMap == null) { - synchronized (this) { - serviceMap = modelServiceMapByDispatcher.get(name); - if (serviceMap == null) { - if (this.localReaders != null) { - serviceMap = FastMap.newInstance(); - for (URL readerURL: this.localReaders) { - Map<String, ModelService> readerServiceMap = ModelServiceReader.getModelServiceMap(readerURL, this); - if (readerServiceMap != null) { - serviceMap.putAll(readerServiceMap); - } - } - serviceMap = new HashMap<String, ModelService>(serviceMap); - } - if (serviceMap != null) { - modelServiceMapByDispatcher.put(name, serviceMap); - // NOTE: the current ECA per dispatcher for local services stuff is a bit broken, so now just doing this on the global def load: ServiceEcaUtil.reloadConfig(); + if (this.localReaders != null) { + serviceMap = FastMap.newInstance(); + for (URL readerURL: this.localReaders) { + Map<String, ModelService> readerServiceMap = ModelServiceReader.getModelServiceMap(readerURL, this); + if (readerServiceMap != null) { + serviceMap.putAll(readerServiceMap); } } + serviceMap = new HashMap<String, ModelService>(serviceMap); + } + if (serviceMap != null) { + serviceMap = modelServiceMapByDispatcher.putIfAbsentAndGet(name, serviceMap); + // NOTE: the current ECA per dispatcher for local services stuff is a bit broken, so now just doing this on the global def load: ServiceEcaUtil.reloadConfig(); } } @@ -306,42 +301,39 @@ public class DispatchContext implements private Map<String, ModelService> getGlobalServiceMap() { Map<String, ModelService> serviceMap = modelServiceMapByDispatcher.get(GLOBAL_KEY); if (serviceMap == null) { - synchronized (this) { - serviceMap = modelServiceMapByDispatcher.get(GLOBAL_KEY); - if (serviceMap == null) { - serviceMap = FastMap.newInstance(); - - Element rootElement; - - try { - rootElement = ServiceConfigUtil.getXmlRootElement(); - } catch (GenericConfigException e) { - Debug.logError(e, "Error getting Service Engine XML root element", module); - return null; - } + serviceMap = FastMap.newInstance(); - List<Future<Map<String, ModelService>>> futures = FastList.newInstance(); - for (Element globalServicesElement: UtilXml.childElementList(rootElement, "global-services")) { - ResourceHandler handler = new MainResourceHandler( - ServiceConfigUtil.SERVICE_ENGINE_XML_FILENAME, globalServicesElement); + Element rootElement; - futures.add(ExecutionPool.GLOBAL_EXECUTOR.submit(createServiceReaderCallable(handler))); - } + try { + rootElement = ServiceConfigUtil.getXmlRootElement(); + } catch (GenericConfigException e) { + Debug.logError(e, "Error getting Service Engine XML root element", module); + return null; + } - // get all of the component resource model stuff, ie specified in each ofbiz-component.xml file - for (ComponentConfig.ServiceResourceInfo componentResourceInfo: ComponentConfig.getAllServiceResourceInfos("model")) { - futures.add(ExecutionPool.GLOBAL_EXECUTOR.submit(createServiceReaderCallable(componentResourceInfo.createResourceHandler()))); - } - for (Map<String, ModelService> servicesMap: ExecutionPool.getAllFutures(futures)) { - if (servicesMap != null) { - serviceMap.putAll(servicesMap); - } - } + List<Future<Map<String, ModelService>>> futures = FastList.newInstance(); + for (Element globalServicesElement: UtilXml.childElementList(rootElement, "global-services")) { + ResourceHandler handler = new MainResourceHandler( + ServiceConfigUtil.SERVICE_ENGINE_XML_FILENAME, globalServicesElement); - if (serviceMap != null) { - modelServiceMapByDispatcher.put(GLOBAL_KEY, serviceMap); - ServiceEcaUtil.reloadConfig(); - } + futures.add(ExecutionPool.GLOBAL_EXECUTOR.submit(createServiceReaderCallable(handler))); + } + + // get all of the component resource model stuff, ie specified in each ofbiz-component.xml file + for (ComponentConfig.ServiceResourceInfo componentResourceInfo: ComponentConfig.getAllServiceResourceInfos("model")) { + futures.add(ExecutionPool.GLOBAL_EXECUTOR.submit(createServiceReaderCallable(componentResourceInfo.createResourceHandler()))); + } + for (Map<String, ModelService> servicesMap: ExecutionPool.getAllFutures(futures)) { + if (servicesMap != null) { + serviceMap.putAll(servicesMap); + } + } + + if (serviceMap != null) { + Map<String, ModelService> cachedServiceMap = modelServiceMapByDispatcher.putIfAbsentAndGet(GLOBAL_KEY, serviceMap); + if (cachedServiceMap == serviceMap) { // same object: this means that the object created by this thread was actually added to the cache + ServiceEcaUtil.reloadConfig(); } } } Modified: ofbiz/branches/20120329_portletWidget/framework/service/src/org/ofbiz/service/ServiceDispatcher.java URL: http://svn.apache.org/viewvc/ofbiz/branches/20120329_portletWidget/framework/service/src/org/ofbiz/service/ServiceDispatcher.java?rev=1351866&r1=1351865&r2=1351866&view=diff ============================================================================== --- ofbiz/branches/20120329_portletWidget/framework/service/src/org/ofbiz/service/ServiceDispatcher.java (original) +++ ofbiz/branches/20120329_portletWidget/framework/service/src/org/ofbiz/service/ServiceDispatcher.java Tue Jun 19 21:36:11 2012 @@ -587,30 +587,18 @@ public class ServiceDispatcher { long timeToRun = System.currentTimeMillis() - serviceStartTime; if (Debug.timingOn() && timeToRun > 50) { + Debug.logTiming("Slow sync service execution detected: service [" + localName + "/" + modelService.name + "] finished in [" + timeToRun + "] milliseconds", module); + } else if (Debug.infoOn() && timeToRun > 200) { + Debug.logInfo("Very slow sync service execution detected: service [" + localName + "/" + modelService.name + "] finished in [" + timeToRun + "] milliseconds", module); + } + if (Debug.verboseOn() && timeToRun > 50 && !modelService.hideResultInLog) { // Sanity check - some service results can be multiple MB in size. Limit message size to 10K. String resultStr = result.toString(); if (resultStr.length() > 10240) { resultStr = resultStr.substring(0, 10226) + "...[truncated]"; } - if (!modelService.hideResultInLog) { - Debug.logTiming("Sync service [" + localName + "/" + modelService.name + "] finished in [" + timeToRun + "] milliseconds with response [" + resultStr + "]", module); - } else { - Debug.logTiming("Sync service [" + localName + "/" + modelService.name + "] finished in [" + timeToRun + "] milliseconds", module); - } - } else if (timeToRun > 200 && Debug.infoOn()) { - // Sanity check - some service results can be multiple MB in size. Limit message size to 10K. - String resultStr = result.toString(); - if (resultStr.length() > 10240) { - resultStr = resultStr.substring(0, 10226) + "...[truncated]"; - } - if (!modelService.hideResultInLog) { - Debug.logInfo("Sync service [" + localName + "/" + modelService.name + "] finished in [" + timeToRun + "] milliseconds with response [" + resultStr + "]", module); - } else { - Debug.logInfo("Sync service [" + localName + "/" + modelService.name + "] finished in [" + timeToRun + "] milliseconds", module); - - } + Debug.logVerbose("Sync service [" + localName + "/" + modelService.name + "] finished with response [" + resultStr + "]", module); } - return result; } Modified: ofbiz/branches/20120329_portletWidget/framework/service/src/org/ofbiz/service/ServiceUtil.java URL: http://svn.apache.org/viewvc/ofbiz/branches/20120329_portletWidget/framework/service/src/org/ofbiz/service/ServiceUtil.java?rev=1351866&r1=1351865&r2=1351866&view=diff ============================================================================== --- ofbiz/branches/20120329_portletWidget/framework/service/src/org/ofbiz/service/ServiceUtil.java (original) +++ ofbiz/branches/20120329_portletWidget/framework/service/src/org/ofbiz/service/ServiceUtil.java Tue Jun 19 21:36:11 2012 @@ -18,6 +18,7 @@ *******************************************************************************/ package org.ofbiz.service; +import java.math.BigDecimal; import java.sql.Timestamp; import com.ibm.icu.util.Calendar; import java.util.LinkedList; @@ -413,13 +414,12 @@ public class ServiceUtil { // begin this transaction beganTx1 = TransactionUtil.begin(); - EntityListIterator foundJobs = delegator.find("JobSandbox", mainCond, null, null, null, findOptions); + EntityListIterator foundJobs = delegator.find("JobSandbox", mainCond, null, UtilMisc.toSet("jobId"), null, findOptions); try { curList = foundJobs.getPartialList(1, 1000); } finally { foundJobs.close(); } - } catch (GenericEntityException e) { Debug.logError(e, "Cannot obtain job data from datasource", module); try { @@ -435,20 +435,14 @@ public class ServiceUtil { Debug.logWarning(e, module); } } - // remove each from the list in its own transaction if (UtilValidate.isNotEmpty(curList)) { - // list of runtime data IDs to attempt to delete - List<String> runtimeToDelete = FastList.newInstance(); - for (GenericValue job: curList) { - String runtimeId = job.getString("runtimeDataId"); String jobId = job.getString("jobId"); boolean beganTx2 = false; try { beganTx2 = TransactionUtil.begin(); job.remove(); - runtimeToDelete.add(runtimeId); } catch (GenericEntityException e) { Debug.logInfo("Cannot remove job data for ID: " + jobId, module); try { @@ -464,37 +458,51 @@ public class ServiceUtil { } } } - - // delete the runtime data - in a new transaction for each delete - // we do this so that the ones which cannot be deleted to not cause - // the entire group to rollback; some may be attached to multiple jobs. - if (runtimeToDelete.size() > 0) { - for (String runtimeId: runtimeToDelete) { - boolean beganTx3 = false; - try { - beganTx3 = TransactionUtil.begin(); - delegator.removeByAnd("RuntimeData", "runtimeDataId", runtimeId); - - } catch (GenericEntityException e) { - Debug.logInfo("Cannot remove runtime data for ID: " + runtimeId, module); - try { - TransactionUtil.rollback(beganTx3, e.getMessage(), e); - } catch (GenericTransactionException e1) { - Debug.logWarning(e1, module); - } - } finally { - try { - TransactionUtil.commit(beganTx3); - } catch (GenericTransactionException e) { - Debug.logWarning(e, module); - } - } - } - } } else { noMoreResults = true; } } + + // Now JobSandbox data is cleaned up. Now process Runtime data and remove the whole data in single shot that is of no need. + boolean beganTx3 = false; + GenericValue runtimeData = null; + EntityListIterator runTimeDataIt = null; + List<GenericValue> runtimeDataToDelete = FastList.newInstance(); + long jobsandBoxCount = 0; + try { + // begin this transaction + beganTx3 = TransactionUtil.begin(); + + runTimeDataIt = delegator.find("RuntimeData", null, null, UtilMisc.toSet("runtimeDataId"), null, null); + try { + while ((runtimeData = runTimeDataIt.next()) != null) { + EntityCondition whereCondition = EntityCondition.makeCondition(UtilMisc.toList(EntityCondition.makeCondition("runtimeDataId", EntityOperator.NOT_EQUAL, null), + EntityCondition.makeCondition("runtimeDataId", EntityOperator.EQUALS, runtimeData.getString("runtimeDataId"))), EntityOperator.AND); + jobsandBoxCount = delegator.findCountByCondition("JobSandbox", whereCondition, null, null); + if (BigDecimal.ZERO.compareTo(BigDecimal.valueOf(jobsandBoxCount)) == 0) { + runtimeDataToDelete.add(runtimeData); + } + } + } finally { + runTimeDataIt.close(); + } + // Now we are ready to delete runtimeData, we can safely delete complete list that we have recently fetched i.e runtimeDataToDelete. + delegator.removeAll(runtimeDataToDelete); + } catch (GenericEntityException e) { + Debug.logError(e, "Cannot obtain runtime data from datasource", module); + try { + TransactionUtil.rollback(beganTx3, e.getMessage(), e); + } catch (GenericTransactionException e1) { + Debug.logWarning(e1, module); + } + return ServiceUtil.returnError(e.getMessage()); + } finally { + try { + TransactionUtil.commit(beganTx3); + } catch (GenericTransactionException e) { + Debug.logWarning(e, module); + } + } } catch (GenericTransactionException e) { Debug.logError(e, "Unable to suspend transaction; cannot purge jobs!", module); return ServiceUtil.returnError(e.getMessage()); Modified: ofbiz/branches/20120329_portletWidget/framework/service/src/org/ofbiz/service/calendar/RecurrenceInfo.java URL: http://svn.apache.org/viewvc/ofbiz/branches/20120329_portletWidget/framework/service/src/org/ofbiz/service/calendar/RecurrenceInfo.java?rev=1351866&r1=1351865&r2=1351866&view=diff ============================================================================== --- ofbiz/branches/20120329_portletWidget/framework/service/src/org/ofbiz/service/calendar/RecurrenceInfo.java (original) +++ ofbiz/branches/20120329_portletWidget/framework/service/src/org/ofbiz/service/calendar/RecurrenceInfo.java Tue Jun 19 21:36:11 2012 @@ -76,7 +76,7 @@ public class RecurrenceInfo { // Get the recurrence rules objects try { rRulesList = new ArrayList<RecurrenceRule>(); - for (GenericValue value: info.getRelated("RecurrenceRule")) { + for (GenericValue value: info.getRelated("RecurrenceRule", null, null, false)) { rRulesList.add(new RecurrenceRule(value)); } } catch (GenericEntityException gee) { @@ -88,7 +88,7 @@ public class RecurrenceInfo { // Get the exception rules objects try { eRulesList = new ArrayList<RecurrenceRule>(); - for (GenericValue value: info.getRelated("ExceptionRecurrenceRule")) { + for (GenericValue value: info.getRelated("ExceptionRecurrenceRule", null, null, false)) { eRulesList.add(new RecurrenceRule(value)); } } catch (GenericEntityException gee) { |
| Free forum by Nabble | Edit this page |
