Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

problem with execute <entity-find-one/> on ViewEntity #101

Closed
locnguyenx opened this issue Sep 3, 2016 · 3 comments
Closed

problem with execute <entity-find-one/> on ViewEntity #101

locnguyenx opened this issue Sep 3, 2016 · 3 comments

Comments

@locnguyenx
Copy link

Scenario 1:
In screen: component/SimpleScreens/User/EditUser (call via url /apps/PopcAdmin/User/EditUser)
record ID is existing, but record value is empty (checked via debug)

After checking following code:

<actions>
        <entity-find-one entity-name="mantle.party.PersonAndUserAccount" value-field="personAndUserAccount"/>
...

into new one:

<actions>
       <entity-find-one entity-name="mantle.party.PersonAndUserAccount" value-field="personAndUserAccount">
            <field-map field-name="partyId"/>
        </entity-find-one>
...

it works as expected

Scenario 2:
In screen: component/SimpleScreens/Supplier/

  1. Create New Supplier & submit
  2. System complete creating new Supplier and redirect to /EditSupplier with new partyId
  3. all fields of new record is blank (although no error occurred, no problem with new ID)
  4. I navigate back to FindSupplier screen, error message occurred due to party.pseudoId is null
  5. If I use Tool/AutoScreen to find the viewentity PartyDetail, the find result list display new ID together with pseudoId (AutoFind screen). However, if I select to edit the problematic record, the pseudoId is blank in AutoEditMaster screen.

I got problem with scenario 2 once and I can't replicate it.

I guess there's something wrong with entity-find-one with viewentity with cache.

@locnguyenx
Copy link
Author

For case 1, after scrutinize the EntityFindBase I find that:

  • if in XMLAction we use entity-find-one without any field-map, then moqui will call .condition(context), then create simpleAndMap with only 1 key. Due to the viewentity PersonAndUserAccount has more than 1 PKs, the oneInternal method will return null.
  • if we use entity-find-one with a field-map. i.e 'partyId', then moqui will call .condition(field, value), then create a pair of singleCondField/singleCondValue. Later on, the oneInternal method will form a whereCondition with this field/value and return result as expected.

I've tried to change the method EntityFind condition(Map<String, Object> fields) to force using singleCondField/singleCondValue instead of simpleAndMap if it has only 1 field:

if (fieldsSize == 1 && noSam && noScf) {
            // just set the singleCondField
            Map.Entry<String, Object> onlyEntry = fields.entrySet().iterator().next()
            singleCondField = (String) onlyEntry.key
            singleCondValue = onlyEntry.value
        } else {
            if (noSam) simpleAndMap = new LinkedHashMap<String, Object>()
            if (!noScf) {
                simpleAndMap.put(singleCondField, singleCondValue)
                singleCondField = (String) null
                singleCondValue = null
            }
            getEntityDef().setFields(fields, simpleAndMap, true, null, null)

            // My Code: use singleCond to avoid checking PKs in .oneInternal()
            if (simpleAndMap?.size() == 1 && noScf) {
                // just set the singleCondField
                Map.Entry<String, Object> onlyEntry = simpleAndMap.entrySet().iterator().next()
                singleCondField = (String) onlyEntry.key
                singleCondValue = onlyEntry.value
                simpleAndMap = null
            }
        }

This fixed the issue that use entity-find-one without any field-map. However, I don't know if this change will have any side-effect or not.

About the case 2, I can't reproduce the issue.

@jonesde
Copy link
Member

jonesde commented Sep 4, 2016

Would you pull the latest code and try this again? I am unable to reproduce the error.

If I understand correctly this error should be seen by just going to:

http://localhost:8080/apps/hmadmin/User/EditUser?partyId=EX_JOHN_DOE

That screen and the populated form are rendering fine for me now with the single PK for the view-entity entity-find-one. Let me know if there is something different that needs to be done to reproduce this issue.

The EntityFindBase code, and lots of code related to it, has been reviewed and updated quite a bit (mostly for performance/efficiency), and while it is somewhat complex and messy to run faster it should all be working now.

@locnguyenx
Copy link
Author

This issue not happen with newest code. It has been fixed in commit 2e6eaff.
In this commit, system don't change simpleAndMap in case its size = 1

acetousk pushed a commit that referenced this issue Jan 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants