[
https://issues.apache.org/jira/browse/OFBIZ-5760?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14143915#comment-14143915
]
Nicolas Malin edited comment on OFBIZ-5760 at 9/22/14 10:07 PM:
----------------------------------------------------------------
A better way to manage all entity assoc with more than 2 primary keys
{code:java}
Index: framework/service/src/org/ofbiz/service/engine/EntityAutoEngine.java
===================================================================
--- framework/service/src/org/ofbiz/service/engine/EntityAutoEngine.java
(révision 1625001)
+++ framework/service/src/org/ofbiz/service/engine/EntityAutoEngine.java
(copie de travail)
@@ -19,6 +19,7 @@
package org.ofbiz.service.engine;
import java.util.Iterator;
+import java.util.LinkedList;
import java.util.Locale;
import java.util.Map;
@@ -89,11 +90,16 @@
try {
boolean allPksInOnly = true;
+ LinkedList<String> pkFieldNameOutOnly = null;
for (ModelField pkField: modelEntity.getPkFieldsUnmodifiable()) {
ModelParam pkParam = modelService.getParam(pkField.getName());
if (pkParam.isOut()) {
allPksInOnly = false;
}
+ if (pkParam.isOut() && !pkParam.isIn()) {
+ if (pkFieldNameOutOnly == null) pkFieldNameOutOnly = new
LinkedList();
+ pkFieldNameOutOnly.add(pkField.getName());
+ }
}
if ("create".equals(modelService.invoke)) {
@@ -215,12 +221,28 @@
*/
newEntity.setPKFields(parameters, true);
} else {
+ /* We haven't all Pk and their are 3 or more, now check if
isn't a associate entity with own sequence
+ <set-pk-fields map="parameters" value-field="newEntity"/>
+ <sequenced-id sequence-name="ExempleItemAssoc"
field="newEntity.exempleItemAsscId"/>
+ <create-value value-field="newEntity"/>
+ */
+ if (pkFieldNameOutOnly != null &&
pkFieldNameOutOnly.size() == 1) {
+ newEntity.setPKFields(parameters, true);
+ String pkFieldName = pkFieldNameOutOnly.getFirst();
+ //if it's a fromDate, don't update it now, it's will
be on next step
+ if (! "fromDate".equals(pkFieldName)) {
+ String pkValue =
dctx.getDelegator().getNextSeqId(modelEntity.getEntityName());
+ newEntity.set(pkFieldName, pkValue);
+ result.put(pkFieldName, pkValue);
+ }
+ } 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: " +
"1. a single OUT pk for primary auto-sequencing, "
+
"2. a single INOUT pk for primary auto-sequencing
with optional override, " +
"3. a 2-part pk with one part IN (existing primary
pk) and one part OUT (the secdonary pk to sub-sequence, " +
"4. all pk fields are IN for a manually specified
primary key");
+ }
}
// handle the case where there is a fromDate in the pk of the
entity, and it is optional or undefined in the service def, populate
automatically
@@ -229,6 +251,9 @@
ModelParam fromDateParam =
modelService.getParam("fromDate");
if (fromDateParam == null || (fromDateParam.isOptional()
&& parameters.get("fromDate") == null)) {
newEntity.set("fromDate", UtilDateTime.nowTimestamp());
+ if (fromDateParam.isOut()) {
+ result.put("fromDate", newEntity.get("fromDate"));
+ }
}
}
{code}
was (Author: soledad):
A better way to manage all entity assoc with more than 2 primary keys
[code:java]
Index: framework/service/src/org/ofbiz/service/engine/EntityAutoEngine.java
===================================================================
--- framework/service/src/org/ofbiz/service/engine/EntityAutoEngine.java
(révision 1625001)
+++ framework/service/src/org/ofbiz/service/engine/EntityAutoEngine.java
(copie de travail)
@@ -19,6 +19,7 @@
package org.ofbiz.service.engine;
import java.util.Iterator;
+import java.util.LinkedList;
import java.util.Locale;
import java.util.Map;
@@ -89,11 +90,16 @@
try {
boolean allPksInOnly = true;
+ LinkedList<String> pkFieldNameOutOnly = null;
for (ModelField pkField: modelEntity.getPkFieldsUnmodifiable()) {
ModelParam pkParam = modelService.getParam(pkField.getName());
if (pkParam.isOut()) {
allPksInOnly = false;
}
+ if (pkParam.isOut() && !pkParam.isIn()) {
+ if (pkFieldNameOutOnly == null) pkFieldNameOutOnly = new
LinkedList();
+ pkFieldNameOutOnly.add(pkField.getName());
+ }
}
if ("create".equals(modelService.invoke)) {
@@ -215,12 +221,28 @@
*/
newEntity.setPKFields(parameters, true);
} else {
+ /* We haven't all Pk and their are 3 or more, now check if
isn't a associate entity with own sequence
+ <set-pk-fields map="parameters" value-field="newEntity"/>
+ <sequenced-id sequence-name="ExempleItemAssoc"
field="newEntity.exempleItemAsscId"/>
+ <create-value value-field="newEntity"/>
+ */
+ if (pkFieldNameOutOnly != null &&
pkFieldNameOutOnly.size() == 1) {
+ newEntity.setPKFields(parameters, true);
+ String pkFieldName = pkFieldNameOutOnly.getFirst();
+ //if it's a fromDate, don't update it now, it's will
be on next step
+ if (! "fromDate".equals(pkFieldName)) {
+ String pkValue =
dctx.getDelegator().getNextSeqId(modelEntity.getEntityName());
+ newEntity.set(pkFieldName, pkValue);
+ result.put(pkFieldName, pkValue);
+ }
+ } 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: " +
"1. a single OUT pk for primary auto-sequencing, "
+
"2. a single INOUT pk for primary auto-sequencing
with optional override, " +
"3. a 2-part pk with one part IN (existing primary
pk) and one part OUT (the secdonary pk to sub-sequence, " +
"4. all pk fields are IN for a manually specified
primary key");
+ }
}
// handle the case where there is a fromDate in the pk of the
entity, and it is optional or undefined in the service def, populate
automatically
@@ -229,6 +251,9 @@
ModelParam fromDateParam =
modelService.getParam("fromDate");
if (fromDateParam == null || (fromDateParam.isOptional()
&& parameters.get("fromDate") == null)) {
newEntity.set("fromDate", UtilDateTime.nowTimestamp());
+ if (fromDateParam.isOut()) {
+ result.put("fromDate", newEntity.get("fromDate"));
+ }
}
}
[code]
> Convert HR entites CRUD service from simple to entity-auto
> ----------------------------------------------------------
>
> Key: OFBIZ-5760
> URL: https://issues.apache.org/jira/browse/OFBIZ-5760
> Project: OFBiz
> Issue Type: Improvement
> Components: humanres
> Affects Versions: Trunk
> Reporter: Nicolas Malin
> Priority: Trivial
> Labels: crud, entity-auto
> Attachments: OFBIZ-5760.patch, OFBIZ-5760.patch
>
>
> I converted CRUD service to entity-auto for :
> || Entity || IHM Test||
> |PartyQual | {color:red}KO{color}, wait decision |
> |PartyResume| OK |
> |PartySkill| OK |
> |PerfReview| {color:red}KO{color} |
> |PerfReviewItem| OK |
> |PerformanceNote| - |
> |Employment| OK |
> |EmploymentApp| - |
> |PartyBenefit| OK |
> |PayGrade| OK |
> |PayHistory| - |
> |PayrollPreference| - |
> |SalaryStep| OK |
> |TerminationReason| OK |
> |UnemploymentClaim| OK |
> |EmplPosition| OK |
> |EmplPositionFulfillment| OK |
> |EmplPositionReportingStruct| OK |
> |EmplPositionResponsibility| OK |
> |ValidResponsibility| - |
> |SkillType| OK |
> |ResponsibilityType| OK |
> |TerminationType| OK |
> |EmplPositionType| OK |
> |EmplPositionTypeRate| OK |
> |AgreementEmploymentAppl| - |
> |EmplLeave| OK, only on update |
> |EmplLeaveType| OK |
> |JobRequisition| OK |
> |EmploymentApp| - |
> |JobInterview| OK |
> |JobInterviewType| OK |
> |PersonTraining| - |
> |TrainingClassType| OK |
> |EmplLeaveReasonType| - |
> With this first pass I tested all entities in IHM Test = OK.
> I need to correct the failed tests and continue the untested entities.
> It's a little big, so I prefer to open this issue.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)