You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by jo...@apache.org on 2008/07/24 10:24:43 UTC
svn commit: r679301 - in /ofbiz/trunk/framework: common/config/
example/config/ example/script/org/ofbiz/example/example/
example/servicedef/ service/src/org/ofbiz/service/engine/
Author: jonesde
Date: Thu Jul 24 01:24:43 2008
New Revision: 679301
URL: http://svn.apache.org/viewvc?rev=679301&view=rev
Log:
One more enhancement to entity-auto to automatically handle the oldStatusId OUT population and checking StatusValidChange for status changes; note that this does nothing to keep a status history, that should be done in a custom service called by SECA rule
Modified:
ofbiz/trunk/framework/common/config/CommonUiLabels.xml
ofbiz/trunk/framework/example/config/ExampleUiLabels.xml
ofbiz/trunk/framework/example/script/org/ofbiz/example/example/ExampleServices.xml
ofbiz/trunk/framework/example/servicedef/services.xml
ofbiz/trunk/framework/service/src/org/ofbiz/service/engine/EntityAutoEngine.java
Modified: ofbiz/trunk/framework/common/config/CommonUiLabels.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/common/config/CommonUiLabels.xml?rev=679301&r1=679300&r2=679301&view=diff
==============================================================================
--- ofbiz/trunk/framework/common/config/CommonUiLabels.xml (original)
+++ ofbiz/trunk/framework/common/config/CommonUiLabels.xml Thu Jul 24 01:24:43 2008
@@ -1955,8 +1955,11 @@
<value xml:lang="de">Fehler: Statuswechsel von [${lookedUpValue.statusId}] nach [${parameters.statusId}] ist nicht erlaubt.</value>
<value xml:lang="en">Error: status change from [${lookedUpValue.statusId}] to [${parameters.statusId}] is not allowed.</value>
<value xml:lang="fr">Erreur le changement de status depuis [${lookedUpValue.statusId}] vers [${parameters.statusId}] n'est pas autorisé.</value>
- <value xml:lang="th">Error: à¸à¹à¸à¸à¸´à¸à¸à¸¥à¸²à¸ ! à¹à¸¡à¹à¸à¸à¸¸à¸à¸²à¸à¸´à¹à¸à¸¥à¸µà¹à¸¢à¸à¸ªà¸à¸²à¸à¸°à¸à¸²à¸ [${lookedUpValue.statusId}] à¹à¸à¹à¸ [${parameters.statusId}]
-</value>
+ <value xml:lang="it">Errore: stato cambiato da [${lookedUpValue.statusId}] a [${parameters.statusId}] non è permesso</value>
+ <value xml:lang="ro">Eroare: stato schimbat de la [${lookedUpValue.statusId}] la [${parameters.statusId}] nu este permis</value>
+ <value xml:lang="ru">ÐÑибка: изменение ÑÑаÑÑÑа Ñ [${lookedUpValue.statusId}] на [${parameters.statusId}] запÑеÑено.</value>
+ <value xml:lang="th">Error: à¸à¹à¸à¸à¸´à¸à¸à¸¥à¸²à¸ ! à¹à¸¡à¹à¸à¸à¸¸à¸à¸²à¸à¸´à¹à¸à¸¥à¸µà¹à¸¢à¸à¸ªà¸à¸²à¸à¸°à¸à¸²à¸ [${lookedUpValue.statusId}] à¹à¸à¹à¸ [${parameters.statusId}]</value>
+ <value xml:lang="zh">é误: ä¸å
许æç¶æä»[${lookedUpValue.statusId}]å为[${parameters.statusId}]ã</value>
</property>
<property key="CommonEventDate">
<value xml:lang="ar">تارÙØ® اÙØدث</value>
Modified: ofbiz/trunk/framework/example/config/ExampleUiLabels.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/example/config/ExampleUiLabels.xml?rev=679301&r1=679300&r2=679301&view=diff
==============================================================================
--- ofbiz/trunk/framework/example/config/ExampleUiLabels.xml (original)
+++ ofbiz/trunk/framework/example/config/ExampleUiLabels.xml Thu Jul 24 01:24:43 2008
@@ -151,14 +151,6 @@
<value xml:lang="ru">ÐÑигиналÑнÑй пÑимеÑ</value>
<value xml:lang="th">à¸à¸±à¸§à¸à¸¢à¹à¸²à¸à¹à¸à¸´à¸¡</value>
</property>
- <property key="ExampleErrorNoExampleStatusValidChange">
- <value xml:lang="en">Error: status change from [${lookedUpValue.statusId}] to [${parameters.statusId}] is not allowed.</value>
- <value xml:lang="it">Errore: stato cambiato da [${lookedUpValue.statusId}] a [${parameters.statusId}] non è permesso</value>
- <value xml:lang="ro">Eroare: stato schimbat de la [${lookedUpValue.statusId}] la [${parameters.statusId}] nu este permis</value>
- <value xml:lang="ru">ÐÑибка: изменение ÑÑаÑÑÑа Ñ [${lookedUpValue.statusId}] на [${parameters.statusId}] запÑеÑено.</value>
- <value xml:lang="th">Error: à¹à¸¡à¹à¸ªà¸²à¸¡à¸²à¸£à¸à¹à¸à¸¥à¸µà¹à¸à¹à¸à¸¥à¸à¸ªà¸à¸²à¸à¸°à¸à¸²à¸ [${lookedUpValue.statusId}] à¹à¸à¹à¸ [${parameters.statusId}] à¹à¸à¹</value>
- <value xml:lang="zh">é误: ä¸å
许æç¶æä»[${lookedUpValue.statusId}]å为[${parameters.statusId}]ã</value>
- </property>
<property key="ExamplePermissionError">
<value xml:lang="en">Security Error: to run ${resourceDescription} you must have the EXAMPLE_${mainAction} or EXAMPLE_ADMIN permission</value>
<value xml:lang="it">Errore Sicurezza: per eseguire ${resourceDescription} tu devi avere il permesso EXAMPLE${mainAction} o EXAMPLE_ADMIN</value>
Modified: ofbiz/trunk/framework/example/script/org/ofbiz/example/example/ExampleServices.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/example/script/org/ofbiz/example/example/ExampleServices.xml?rev=679301&r1=679300&r2=679301&view=diff
==============================================================================
--- ofbiz/trunk/framework/example/script/org/ofbiz/example/example/ExampleServices.xml (original)
+++ ofbiz/trunk/framework/example/script/org/ofbiz/example/example/ExampleServices.xml Thu Jul 24 01:24:43 2008
@@ -20,31 +20,7 @@
<simple-methods xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://ofbiz.apache.org/dtds/simple-methods.xsd">
- <!-- Example methods -->
- <simple-method method-name="updateExample" short-description="update a Example">
- <entity-one entity-name="Example" value-name="lookedUpValue"/>
-
- <!-- handle statusId change stuff; first put the current statusId in the oldStatusId result -->
- <field-to-result field-name="lookedUpValue.statusId" result-name="oldStatusId"/>
- <if-compare-field field="lookedUpValue.statusId" operator="not-equals" to-field="parameters.statusId">
- <!-- if the record exists there should be a statusId, but just in case make it so it won't blow up -->
- <if-not-empty field="lookedUpValue.statusId">
- <!-- if statusId change is not in the StatusValidChange list, complain... -->
- <entity-one entity-name="StatusValidChange" value-name="statusValidChange" auto-field-map="false">
- <field-map field-name="statusId" env-name="lookedUpValue.statusId"/>
- <field-map field-name="statusIdTo" env-name="parameters.statusId"/>
- </entity-one>
- <if-empty field="statusValidChange">
- <!-- no valid change record found? return an error... -->
- <add-error><fail-property resource="ExampleUiLabels" property="ExampleErrorNoExampleStatusValidChange"/></add-error>
- <check-errors/>
- </if-empty>
- </if-not-empty>
- </if-compare-field>
-
- <set-nonpk-fields map-name="parameters" value-name="lookedUpValue"/>
- <store-value value-name="lookedUpValue"/>
- </simple-method>
+ <!-- ExampleStatus methods -->
<simple-method method-name="createExampleStatus" short-description="create a ExampleItem">
<now-timestamp-to-env env-name="nowTimestamp"/>
Modified: ofbiz/trunk/framework/example/servicedef/services.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/example/servicedef/services.xml?rev=679301&r1=679300&r2=679301&view=diff
==============================================================================
--- ofbiz/trunk/framework/example/servicedef/services.xml (original)
+++ ofbiz/trunk/framework/example/servicedef/services.xml Thu Jul 24 01:24:43 2008
@@ -34,8 +34,7 @@
<override name="statusId" optional="false"/>
<override name="exampleName" optional="false"/>
</service>
- <service name="updateExample" default-entity-name="Example" engine="simple"
- location="component://example/script/org/ofbiz/example/example/ExampleServices.xml" invoke="updateExample" auth="true">
+ <service name="updateExample" default-entity-name="Example" engine="entity-auto" invoke="update" auth="true">
<description>Update a Example</description>
<permission-service service-name="exampleGenericPermission" main-action="UPDATE"/>
<auto-attributes include="pk" mode="IN" optional="false"/>
Modified: ofbiz/trunk/framework/service/src/org/ofbiz/service/engine/EntityAutoEngine.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/service/src/org/ofbiz/service/engine/EntityAutoEngine.java?rev=679301&r1=679300&r2=679301&view=diff
==============================================================================
--- ofbiz/trunk/framework/service/src/org/ofbiz/service/engine/EntityAutoEngine.java (original)
+++ ofbiz/trunk/framework/service/src/org/ofbiz/service/engine/EntityAutoEngine.java Thu Jul 24 01:24:43 2008
@@ -19,11 +19,15 @@
package org.ofbiz.service.engine;
import java.util.Iterator;
+import java.util.Locale;
import java.util.Map;
+import javolution.util.FastMap;
+
import org.ofbiz.base.util.Debug;
import org.ofbiz.base.util.GeneralException;
import org.ofbiz.base.util.UtilDateTime;
+import org.ofbiz.base.util.UtilProperties;
import org.ofbiz.base.util.UtilValidate;
import org.ofbiz.entity.GenericValue;
import org.ofbiz.entity.finder.PrimaryKeyFinder;
@@ -57,10 +61,12 @@
/**
* @see org.ofbiz.service.engine.GenericEngine#runSync(java.lang.String, org.ofbiz.service.ModelService, java.util.Map)
*/
- public Map<String, Object> runSync(String localName, ModelService modelService, Map<String, Object> context) throws GenericServiceException {
+ public Map<String, Object> runSync(String localName, ModelService modelService, Map<String, Object> parameters) throws GenericServiceException {
// static java service methods should be: public Map<String, Object> methodName(DispatchContext dctx, Map<String, Object> context)
DispatchContext dctx = dispatcher.getLocalContext(localName);
+ Map<String, Object> localContext = FastMap.newInstance();
+ localContext.put("parameters", parameters);
Map<String, Object> result = ServiceUtil.returnSuccess();
// check the package and method names
@@ -158,7 +164,7 @@
*
*/
- Object pkValue = context.get(singlePkModelParam.name);
+ Object pkValue = parameters.get(singlePkModelParam.name);
if (UtilValidate.isEmpty(pkValue)) {
pkValue = dctx.getDelegator().getNextSeqId(modelEntity.getEntityName());
} else {
@@ -188,7 +194,7 @@
<create-value value-name="newEntity"/>
*/
- newEntity.setPKFields(context, true);
+ newEntity.setPKFields(parameters, true);
dctx.getDelegator().setNextSubSeqId(newEntity, doublePkSecondaryOutField.getName(), 5, 1);
result.put(doublePkSecondaryOutParam.name, newEntity.get(doublePkSecondaryOutField.getName()));
} else if (allPksInOnly) {
@@ -203,7 +209,7 @@
<create-value value-name="newEntity"/>
*
*/
- newEntity.setPKFields(context, true);
+ newEntity.setPKFields(parameters, true);
} else {
throw new GenericServiceException("In Service [" + modelService.name + "] which uses the entity-auto engine with the create invoke option: " +
"could not find a valid combination of primary key settings to do a known create operation; options include: " +
@@ -217,12 +223,12 @@
ModelField fromDateField = modelEntity.getField("fromDate");
if (fromDateField != null && fromDateField.getIsPk()) {
ModelParam fromDateParam = modelService.getParam("fromDate");
- if (fromDateParam == null || (fromDateParam.isOptional() && context.get("fromDate") == null)) {
+ if (fromDateParam == null || (fromDateParam.isOptional() && parameters.get("fromDate") == null)) {
newEntity.set("fromDate", UtilDateTime.nowTimestamp());
}
}
- newEntity.setNonPKFields(context, true);
+ newEntity.setNonPKFields(parameters, true);
newEntity.create();
} else if ("update".equals(modelService.invoke)) {
/*
@@ -238,8 +244,61 @@
throw new GenericServiceException("In Service [" + modelService.name + "] which uses the entity-auto engine with the update invoke option not all pk fields have the mode IN");
}
- GenericValue lookedUpValue = PrimaryKeyFinder.runFind(modelEntity, context, dctx.getDelegator(), false, true, null, null);
- lookedUpValue.setNonPKFields(context, true);
+ GenericValue lookedUpValue = PrimaryKeyFinder.runFind(modelEntity, parameters, dctx.getDelegator(), false, true, null, null);
+ if (lookedUpValue == null) {
+ return ServiceUtil.returnError("Value not found, cannot update");
+ }
+
+ localContext.put("lookedUpValue", lookedUpValue);
+
+ // populate the oldStatusId out if there is a service parameter for it, and before we do the set non-pk fields
+ /*
+ <auto-attributes include="pk" mode="IN" optional="false"/>
+ <attribute name="oldStatusId" type="String" mode="OUT" optional="false"/>
+ *
+ <field-to-result field-name="lookedUpValue.statusId" result-name="oldStatusId"/>
+ */
+ ModelParam statusIdParam = modelService.getParam("statusId");
+ ModelField statusIdField = modelEntity.getField("statusId");
+ ModelParam oldStatusIdParam = modelService.getParam("oldStatusId");
+ if (statusIdParam != null && statusIdParam.isIn() && oldStatusIdParam != null && oldStatusIdParam.isOut() && statusIdField != null) {
+ result.put("oldStatusId", lookedUpValue.get("statusId"));
+ }
+
+ // do the StatusValidChange check
+ /*
+ <if-compare-field field="lookedUpValue.statusId" operator="not-equals" to-field="parameters.statusId">
+ <!-- if the record exists there should be a statusId, but just in case make it so it won't blow up -->
+ <if-not-empty field="lookedUpValue.statusId">
+ <!-- if statusId change is not in the StatusValidChange list, complain... -->
+ <entity-one entity-name="StatusValidChange" value-name="statusValidChange" auto-field-map="false">
+ <field-map field-name="statusId" env-name="lookedUpValue.statusId"/>
+ <field-map field-name="statusIdTo" env-name="parameters.statusId"/>
+ </entity-one>
+ <if-empty field="statusValidChange">
+ <!-- no valid change record found? return an error... -->
+ <add-error><fail-property resource="CommonUiLabels" property="CommonErrorNoStatusValidChange"/></add-error>
+ <check-errors/>
+ </if-empty>
+ </if-not-empty>
+ </if-compare-field>
+ */
+ String parameterStatusId = (String) parameters.get("statusId");
+ if (statusIdParam != null && statusIdParam.isIn() && UtilValidate.isNotEmpty(parameterStatusId) && statusIdField != null) {
+ String lookedUpStatusId = (String) lookedUpValue.get("statusId");
+ if (UtilValidate.isNotEmpty(lookedUpStatusId) && !parameterStatusId.equals(lookedUpStatusId)) {
+ // there was an old status, and in this call we are trying to change it, so do the StatusValidChange check
+ GenericValue statusValidChange = dctx.getDelegator().findOne("StatusValidChange", true, "statusId", lookedUpStatusId, "statusIdTo", parameterStatusId);
+ if (statusValidChange == null) {
+ // uh-oh, no valid change...
+ return ServiceUtil.returnError(UtilProperties.getMessage("CommonUiLabels", "CommonErrorNoStatusValidChange", localContext, (Locale) parameters.get("locale")));
+ }
+ }
+ }
+
+ // NOTE: nothing here to maintain the status history, that should be done with a custom service called by SECA rule
+
+ lookedUpValue.setNonPKFields(parameters, true);
lookedUpValue.store();
} else if ("delete".equals(modelService.invoke)) {
/*
@@ -254,7 +313,7 @@
throw new GenericServiceException("In Service [" + modelService.name + "] which uses the entity-auto engine with the delete invoke option not all pk fields have the mode IN");
}
- GenericValue lookedUpValue = PrimaryKeyFinder.runFind(modelEntity, context, dctx.getDelegator(), false, true, null, null);
+ GenericValue lookedUpValue = PrimaryKeyFinder.runFind(modelEntity, parameters, dctx.getDelegator(), false, true, null, null);
if (lookedUpValue != null) {
lookedUpValue.remove();
}
Re: svn commit: r679301 - in /ofbiz/trunk/framework: common/config/ example/config/ example/script/org/ofbiz/example/example/ example/servicedef/ service/src/org/ofbiz/service/engine/
Posted by Jacques Le Roux <ja...@les7arts.com>.
Nice features (all of them I mean), thanks David !
Jacques
> Author: jonesde
> Date: Thu Jul 24 01:24:43 2008
> New Revision: 679301
>
> URL: http://svn.apache.org/viewvc?rev=679301&view=rev
> Log:
> One more enhancement to entity-auto to automatically handle the oldStatusId OUT population and checking StatusValidChange for
> status changes; note that this does nothing to keep a status history, that should be done in a custom service called by SECA rule
>
> Modified:
> ofbiz/trunk/framework/common/config/CommonUiLabels.xml
> ofbiz/trunk/framework/example/config/ExampleUiLabels.xml
> ofbiz/trunk/framework/example/script/org/ofbiz/example/example/ExampleServices.xml
> ofbiz/trunk/framework/example/servicedef/services.xml
> ofbiz/trunk/framework/service/src/org/ofbiz/service/engine/EntityAutoEngine.java
>
> Modified: ofbiz/trunk/framework/common/config/CommonUiLabels.xml
> URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/common/config/CommonUiLabels.xml?rev=679301&r1=679300&r2=679301&view=diff
> ==============================================================================
> --- ofbiz/trunk/framework/common/config/CommonUiLabels.xml (original)
> +++ ofbiz/trunk/framework/common/config/CommonUiLabels.xml Thu Jul 24 01:24:43 2008
> @@ -1955,8 +1955,11 @@
> <value xml:lang="de">Fehler: Statuswechsel von [${lookedUpValue.statusId}] nach [${parameters.statusId}] ist nicht
> erlaubt.</value>
> <value xml:lang="en">Error: status change from [${lookedUpValue.statusId}] to [${parameters.statusId}] is not
> allowed.</value>
> <value xml:lang="fr">Erreur le changement de status depuis [${lookedUpValue.statusId}] vers [${parameters.statusId}] n'est
> pas autorisé.</value>
> - <value xml:lang="th">Error: à¸à¹à¸à¸à¸´à¸à¸à¸¥à¸²à¸ !
> à¹à¸¡à¹à¸à¸à¸¸à¸à¸²à¸à¸´à¹à¸à¸¥à¸µà¹à¸¢à¸à¸ªà¸à¸²à¸à¸°à¸à¸²à¸ [${lookedUpValue.statusId}] à¹à¸à¹à¸
> [${parameters.statusId}]
> -</value>
> + <value xml:lang="it">Errore: stato cambiato da [${lookedUpValue.statusId}] a [${parameters.statusId}] non è
> permesso</value>
> + <value xml:lang="ro">Eroare: stato schimbat de la [${lookedUpValue.statusId}] la [${parameters.statusId}] nu este
> permis</value>
> + <value xml:lang="ru">ÐÑибка: изменение ÑÑаÑÑÑа Ñ [${lookedUpValue.statusId}] на
> [${parameters.statusId}] запÑеÑено.</value>
> + <value xml:lang="th">Error: à¸à¹à¸à¸à¸´à¸à¸à¸¥à¸²à¸ !
> à¹à¸¡à¹à¸à¸à¸¸à¸à¸²à¸à¸´à¹à¸à¸¥à¸µà¹à¸¢à¸à¸ªà¸à¸²à¸à¸°à¸à¸²à¸ [${lookedUpValue.statusId}] à¹à¸à¹à¸
> [${parameters.statusId}]</value>
> + <value xml:lang="zh">é误: ä¸å
许æç¶æä»[${lookedUpValue.statusId}]å为[${parameters.statusId}]ã</value>
> </property>
> <property key="CommonEventDate">
> <value xml:lang="ar">تارÙØ® اÙØدث</value>
>
> Modified: ofbiz/trunk/framework/example/config/ExampleUiLabels.xml
> URL:
> http://svn.apache.org/viewvc/ofbiz/trunk/framework/example/config/ExampleUiLabels.xml?rev=679301&r1=679300&r2=679301&view=diff
> ==============================================================================
> --- ofbiz/trunk/framework/example/config/ExampleUiLabels.xml (original)
> +++ ofbiz/trunk/framework/example/config/ExampleUiLabels.xml Thu Jul 24 01:24:43 2008
> @@ -151,14 +151,6 @@
> <value xml:lang="ru">ÐÑигиналÑнÑй пÑимеÑ</value>
> <value xml:lang="th">à¸à¸±à¸§à¸à¸¢à¹à¸²à¸à¹à¸à¸´à¸¡</value>
> </property>
> - <property key="ExampleErrorNoExampleStatusValidChange">
> - <value xml:lang="en">Error: status change from [${lookedUpValue.statusId}] to [${parameters.statusId}] is not
> allowed.</value>
> - <value xml:lang="it">Errore: stato cambiato da [${lookedUpValue.statusId}] a [${parameters.statusId}] non è
> permesso</value>
> - <value xml:lang="ro">Eroare: stato schimbat de la [${lookedUpValue.statusId}] la [${parameters.statusId}] nu este
> permis</value>
> - <value xml:lang="ru">ÐÑибка: изменение ÑÑаÑÑÑа Ñ [${lookedUpValue.statusId}] на
> [${parameters.statusId}] запÑеÑено.</value>
> - <value xml:lang="th">Error: à¹à¸¡à¹à¸ªà¸²à¸¡à¸²à¸£à¸à¹à¸à¸¥à¸µà¹à¸à¹à¸à¸¥à¸à¸ªà¸à¸²à¸à¸°à¸à¸²à¸
> [${lookedUpValue.statusId}] à¹à¸à¹à¸ [${parameters.statusId}] à¹à¸à¹</value>
> - <value xml:lang="zh">é误: ä¸å
许æç¶æä»[${lookedUpValue.statusId}]å为[${parameters.statusId}]ã</value>
> - </property>
> <property key="ExamplePermissionError">
> <value xml:lang="en">Security Error: to run ${resourceDescription} you must have the EXAMPLE_${mainAction} or
> EXAMPLE_ADMIN permission</value>
> <value xml:lang="it">Errore Sicurezza: per eseguire ${resourceDescription} tu devi avere il permesso EXAMPLE${mainAction}
> o EXAMPLE_ADMIN</value>
>
> Modified: ofbiz/trunk/framework/example/script/org/ofbiz/example/example/ExampleServices.xml
> URL:
> http://svn.apache.org/viewvc/ofbiz/trunk/framework/example/script/org/ofbiz/example/example/ExampleServices.xml?rev=679301&r1=679300&r2=679301&view=diff
> ==============================================================================
> --- ofbiz/trunk/framework/example/script/org/ofbiz/example/example/ExampleServices.xml (original)
> +++ ofbiz/trunk/framework/example/script/org/ofbiz/example/example/ExampleServices.xml Thu Jul 24 01:24:43 2008
> @@ -20,31 +20,7 @@
>
> <simple-methods xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xsi:noNamespaceSchemaLocation="http://ofbiz.apache.org/dtds/simple-methods.xsd">
> - <!-- Example methods -->
> - <simple-method method-name="updateExample" short-description="update a Example">
> - <entity-one entity-name="Example" value-name="lookedUpValue"/>
> -
> - <!-- handle statusId change stuff; first put the current statusId in the oldStatusId result -->
> - <field-to-result field-name="lookedUpValue.statusId" result-name="oldStatusId"/>
> - <if-compare-field field="lookedUpValue.statusId" operator="not-equals" to-field="parameters.statusId">
> - <!-- if the record exists there should be a statusId, but just in case make it so it won't blow up -->
> - <if-not-empty field="lookedUpValue.statusId">
> - <!-- if statusId change is not in the StatusValidChange list, complain... -->
> - <entity-one entity-name="StatusValidChange" value-name="statusValidChange" auto-field-map="false">
> - <field-map field-name="statusId" env-name="lookedUpValue.statusId"/>
> - <field-map field-name="statusIdTo" env-name="parameters.statusId"/>
> - </entity-one>
> - <if-empty field="statusValidChange">
> - <!-- no valid change record found? return an error... -->
> - <add-error><fail-property resource="ExampleUiLabels"
> property="ExampleErrorNoExampleStatusValidChange"/></add-error>
> - <check-errors/>
> - </if-empty>
> - </if-not-empty>
> - </if-compare-field>
> -
> - <set-nonpk-fields map-name="parameters" value-name="lookedUpValue"/>
> - <store-value value-name="lookedUpValue"/>
> - </simple-method>
> + <!-- ExampleStatus methods -->
> <simple-method method-name="createExampleStatus" short-description="create a ExampleItem">
> <now-timestamp-to-env env-name="nowTimestamp"/>
>
>
> Modified: ofbiz/trunk/framework/example/servicedef/services.xml
> URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/example/servicedef/services.xml?rev=679301&r1=679300&r2=679301&view=diff
> ==============================================================================
> --- ofbiz/trunk/framework/example/servicedef/services.xml (original)
> +++ ofbiz/trunk/framework/example/servicedef/services.xml Thu Jul 24 01:24:43 2008
> @@ -34,8 +34,7 @@
> <override name="statusId" optional="false"/>
> <override name="exampleName" optional="false"/>
> </service>
> - <service name="updateExample" default-entity-name="Example" engine="simple"
> - location="component://example/script/org/ofbiz/example/example/ExampleServices.xml" invoke="updateExample"
> auth="true">
> + <service name="updateExample" default-entity-name="Example" engine="entity-auto" invoke="update" auth="true">
> <description>Update a Example</description>
> <permission-service service-name="exampleGenericPermission" main-action="UPDATE"/>
> <auto-attributes include="pk" mode="IN" optional="false"/>
>
> Modified: ofbiz/trunk/framework/service/src/org/ofbiz/service/engine/EntityAutoEngine.java
> URL:
> http://svn.apache.org/viewvc/ofbiz/trunk/framework/service/src/org/ofbiz/service/engine/EntityAutoEngine.java?rev=679301&r1=679300&r2=679301&view=diff
> ==============================================================================
> --- ofbiz/trunk/framework/service/src/org/ofbiz/service/engine/EntityAutoEngine.java (original)
> +++ ofbiz/trunk/framework/service/src/org/ofbiz/service/engine/EntityAutoEngine.java Thu Jul 24 01:24:43 2008
> @@ -19,11 +19,15 @@
> package org.ofbiz.service.engine;
>
> import java.util.Iterator;
> +import java.util.Locale;
> import java.util.Map;
>
> +import javolution.util.FastMap;
> +
> import org.ofbiz.base.util.Debug;
> import org.ofbiz.base.util.GeneralException;
> import org.ofbiz.base.util.UtilDateTime;
> +import org.ofbiz.base.util.UtilProperties;
> import org.ofbiz.base.util.UtilValidate;
> import org.ofbiz.entity.GenericValue;
> import org.ofbiz.entity.finder.PrimaryKeyFinder;
> @@ -57,10 +61,12 @@
> /**
> * @see org.ofbiz.service.engine.GenericEngine#runSync(java.lang.String, org.ofbiz.service.ModelService, java.util.Map)
> */
> - public Map<String, Object> runSync(String localName, ModelService modelService, Map<String, Object> context) throws
> GenericServiceException {
> + public Map<String, Object> runSync(String localName, ModelService modelService, Map<String, Object> parameters) throws
> GenericServiceException {
> // static java service methods should be: public Map<String, Object> methodName(DispatchContext dctx, Map<String, Object>
> context)
> DispatchContext dctx = dispatcher.getLocalContext(localName);
>
> + Map<String, Object> localContext = FastMap.newInstance();
> + localContext.put("parameters", parameters);
> Map<String, Object> result = ServiceUtil.returnSuccess();
>
> // check the package and method names
> @@ -158,7 +164,7 @@
> *
> */
>
> - Object pkValue = context.get(singlePkModelParam.name);
> + Object pkValue = parameters.get(singlePkModelParam.name);
> if (UtilValidate.isEmpty(pkValue)) {
> pkValue = dctx.getDelegator().getNextSeqId(modelEntity.getEntityName());
> } else {
> @@ -188,7 +194,7 @@
> <create-value value-name="newEntity"/>
> */
>
> - newEntity.setPKFields(context, true);
> + newEntity.setPKFields(parameters, true);
> dctx.getDelegator().setNextSubSeqId(newEntity, doublePkSecondaryOutField.getName(), 5, 1);
> result.put(doublePkSecondaryOutParam.name, newEntity.get(doublePkSecondaryOutField.getName()));
> } else if (allPksInOnly) {
> @@ -203,7 +209,7 @@
> <create-value value-name="newEntity"/>
> *
> */
> - newEntity.setPKFields(context, true);
> + newEntity.setPKFields(parameters, true);
> } else {
> throw new GenericServiceException("In Service [" + modelService.name + "] which uses the entity-auto engine
> with the create invoke option: " +
> "could not find a valid combination of primary key settings to do a known create operation; options include: "
> +
> @@ -217,12 +223,12 @@
> ModelField fromDateField = modelEntity.getField("fromDate");
> if (fromDateField != null && fromDateField.getIsPk()) {
> ModelParam fromDateParam = modelService.getParam("fromDate");
> - if (fromDateParam == null || (fromDateParam.isOptional() && context.get("fromDate") == null)) {
> + if (fromDateParam == null || (fromDateParam.isOptional() && parameters.get("fromDate") == null)) {
> newEntity.set("fromDate", UtilDateTime.nowTimestamp());
> }
> }
>
> - newEntity.setNonPKFields(context, true);
> + newEntity.setNonPKFields(parameters, true);
> newEntity.create();
> } else if ("update".equals(modelService.invoke)) {
> /*
> @@ -238,8 +244,61 @@
> throw new GenericServiceException("In Service [" + modelService.name + "] which uses the entity-auto engine
> with the update invoke option not all pk fields have the mode IN");
> }
>
> - GenericValue lookedUpValue = PrimaryKeyFinder.runFind(modelEntity, context, dctx.getDelegator(), false, true,
> null, null);
> - lookedUpValue.setNonPKFields(context, true);
> + GenericValue lookedUpValue = PrimaryKeyFinder.runFind(modelEntity, parameters, dctx.getDelegator(), false, true,
> null, null);
> + if (lookedUpValue == null) {
> + return ServiceUtil.returnError("Value not found, cannot update");
> + }
> +
> + localContext.put("lookedUpValue", lookedUpValue);
> +
> + // populate the oldStatusId out if there is a service parameter for it, and before we do the set non-pk fields
> + /*
> + <auto-attributes include="pk" mode="IN" optional="false"/>
> + <attribute name="oldStatusId" type="String" mode="OUT" optional="false"/>
> + *
> + <field-to-result field-name="lookedUpValue.statusId" result-name="oldStatusId"/>
> + */
> + ModelParam statusIdParam = modelService.getParam("statusId");
> + ModelField statusIdField = modelEntity.getField("statusId");
> + ModelParam oldStatusIdParam = modelService.getParam("oldStatusId");
> + if (statusIdParam != null && statusIdParam.isIn() && oldStatusIdParam != null && oldStatusIdParam.isOut() &&
> statusIdField != null) {
> + result.put("oldStatusId", lookedUpValue.get("statusId"));
> + }
> +
> + // do the StatusValidChange check
> + /*
> + <if-compare-field field="lookedUpValue.statusId" operator="not-equals" to-field="parameters.statusId">
> + <!-- if the record exists there should be a statusId, but just in case make it so it won't blow up -->
> + <if-not-empty field="lookedUpValue.statusId">
> + <!-- if statusId change is not in the StatusValidChange list, complain... -->
> + <entity-one entity-name="StatusValidChange" value-name="statusValidChange" auto-field-map="false">
> + <field-map field-name="statusId" env-name="lookedUpValue.statusId"/>
> + <field-map field-name="statusIdTo" env-name="parameters.statusId"/>
> + </entity-one>
> + <if-empty field="statusValidChange">
> + <!-- no valid change record found? return an error... -->
> + <add-error><fail-property resource="CommonUiLabels"
> property="CommonErrorNoStatusValidChange"/></add-error>
> + <check-errors/>
> + </if-empty>
> + </if-not-empty>
> + </if-compare-field>
> + */
> + String parameterStatusId = (String) parameters.get("statusId");
> + if (statusIdParam != null && statusIdParam.isIn() && UtilValidate.isNotEmpty(parameterStatusId) && statusIdField
> != null) {
> + String lookedUpStatusId = (String) lookedUpValue.get("statusId");
> + if (UtilValidate.isNotEmpty(lookedUpStatusId) && !parameterStatusId.equals(lookedUpStatusId)) {
> + // there was an old status, and in this call we are trying to change it, so do the StatusValidChange
> check
> + GenericValue statusValidChange = dctx.getDelegator().findOne("StatusValidChange", true, "statusId",
> lookedUpStatusId, "statusIdTo", parameterStatusId);
> + if (statusValidChange == null) {
> + // uh-oh, no valid change...
> + return ServiceUtil.returnError(UtilProperties.getMessage("CommonUiLabels",
> "CommonErrorNoStatusValidChange", localContext, (Locale) parameters.get("locale")));
> + }
> + }
> + }
> +
> + // NOTE: nothing here to maintain the status history, that should be done with a custom service called by SECA
> rule
> +
> + lookedUpValue.setNonPKFields(parameters, true);
> lookedUpValue.store();
> } else if ("delete".equals(modelService.invoke)) {
> /*
> @@ -254,7 +313,7 @@
> throw new GenericServiceException("In Service [" + modelService.name + "] which uses the entity-auto engine
> with the delete invoke option not all pk fields have the mode IN");
> }
>
> - GenericValue lookedUpValue = PrimaryKeyFinder.runFind(modelEntity, context, dctx.getDelegator(), false, true,
> null, null);
> + GenericValue lookedUpValue = PrimaryKeyFinder.runFind(modelEntity, parameters, dctx.getDelegator(), false, true,
> null, null);
> if (lookedUpValue != null) {
> lookedUpValue.remove();
> }
>
>