[ 
https://issues.apache.org/jira/browse/OFBIZ-1141?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12512880
 ] 

Wickersheimer Jeremy commented on OFBIZ-1141:
---------------------------------------------

I have the following working: the validation code is not the ugly conditions 
pyramid like before but the more readable:

       <!--we need to check that Party Id exists manually-->
        <check-primary-key entity-name="Party" ignore-empty="true">
            <primary-key field-name="partyId" env-name="parameters.partyIdFrom" 
/>
            <fail-message message="The Party '${parameters.partyIdFrom}' 
doesn't exist"/>
        </check-primary-key>
        <check-primary-key entity-name="Party" ignore-empty="true">
            <primary-key field-name="partyId" env-name="parameters.partyIdTo" />
            <fail-message message="The Party '${parameters.partyIdTo}' doesn't 
exist"/>
        </check-primary-key>
        <check-errors/>
        <!--check for product Id-->
        <check-primary-key entity-name="Product" ignore-empty="true">
            <primary-key field-name="productId" env-name="parameters.productId" 
/>
            <fail-message message="The Product '${parameters.productId}' 
doesn't exist"/>
        </check-primary-key>
        <check-errors/>
        <!--check for FK violation-->
        <check-primary-key entity-name="PartyRole" ignore-partial="true">
            <primary-key field-name="partyId" env-name="parameters.partyIdFrom" 
/>
            <primary-key field-name="roleTypeId" 
env-name="parameters.roleTypeIdFrom" />
            <fail-message message="The Party '${parameters.partyIdFrom}' 
doesn't have the Role Type '${parameters.roleTypeIdFrom}'"/>
        </check-primary-key>
        <check-primary-key entity-name="PartyRole" ignore-partial="true">
            <primary-key field-name="partyId" env-name="parameters.partyIdTo" />
            <primary-key field-name="roleTypeId" 
env-name="parameters.roleTypeIdTo" />
            <fail-message message="The Party '${parameters.partyIdTo}' doesn't 
have the Role Type '${parameters.roleTypeIdTo}'"/>
        </check-primary-key>
        <check-errors/>

There is far less code per validation now, but it is still a bit tedious to 
rewrite (or write, partyId validation wasn't working) each validation condition.
Also in that case i need to duplicate this block of code in both create and 
update.

Now this reminds me of how validation is done in Ruby On Rails, we could do 
something similar:
- validation conditions written in the model definition (entity definition), 
with localized error messages
- validation done automatically before update / create is passed to the 
database thus supplementing but not replacing the DB FK checks.

If think this would be even more elegant !


> More user friendly error messages
> ---------------------------------
>
>                 Key: OFBIZ-1141
>                 URL: https://issues.apache.org/jira/browse/OFBIZ-1141
>             Project: OFBiz
>          Issue Type: Improvement
>    Affects Versions: SVN trunk, Release Branch 4.0
>            Reporter: Wickersheimer Jeremy
>            Priority: Minor
>         Attachments: ofbiz-1141-example1.patch
>
>
> A lot of error messages in Ofbiz are "cryptic" for normal users. For example 
> sometimes a user would trigger a database foreign key violation and as a 
> result will have a quite big error message thrown at him.
> This would happen for example when you create an Agreement then gives both a 
> Party Id To and a Role Type Id To that doesn't  match. 
> In that case the error is something like:
> ERROR: Could not complete the Create an Agreement 
> [file:/home/jeremy/bertelsmann/dgerp/applications/accounting/script/org/ofbiz/accounting/agreement/AgreementServices.xml#createAgreement]
>  process [problem creating the newEntity value: Exception while inserting the 
> following entity: 
> [GenericEntity:Agreement][agreementDate,null()][agreementId,10076(java.lang.String)][agreementTypeId,null()][createdStamp,2007-07-12
>  12:33:38.285(java.sql.Timestamp)][createdTxStamp,2007-07-12 
> 12:33:38.283(java.sql.Timestamp)][defaultCurrencyUomId,null()][description,null()][fromDate,2007-07-12
>  
> 12:33:38.285(java.sql.Timestamp)][fromPartyClassGroupId,null()][lastUpdatedStamp,2007-07-12
>  12:33:38.285(java.sql.Timestamp)][lastUpdatedTxStamp,2007-07-12 
> 12:33:38.283(java.sql.Timestamp)][partyIdFrom,null()][partyIdTo,Admin(java.lang.String)][productId,null()][roleTypeIdFrom,null()][roleTypeIdTo,PERSON_ROLE(java.lang.String)][statusId,null()][textData,null()][thruDate,null()][toPartyClassGroupId,null()]
>  (while inserting: 
> [GenericEntity:Agreement][agreementDate,null()][agreementId,10076(java.lang.String)][agreementTypeId,null()][createdStamp,2007-07-12
>  12:33:38.285(java.sql.Timestamp)][createdTxStamp,2007-07-12 
> 12:33:38.283(java.sql.Timestamp)][defaultCurrencyUomId,null()][description,null()][fromDate,2007-07-12
>  
> 12:33:38.285(java.sql.Timestamp)][fromPartyClassGroupId,null()][lastUpdatedStamp,2007-07-12
>  12:33:38.285(java.sql.Timestamp)][lastUpdatedTxStamp,2007-07-12 
> 12:33:38.283(java.sql.Timestamp)][partyIdFrom,null()][partyIdTo,Admin(java.lang.String)][productId,null()][roleTypeIdFrom,null()][roleTypeIdTo,PERSON_ROLE(java.lang.String)][statusId,null()][textData,null()][thruDate,null()][toPartyClassGroupId,null()]
>  (SQL Exception while executing the following:INSERT INTO public.AGREEMENT 
> (AGREEMENT_ID, PRODUCT_ID, PARTY_ID_FROM, PARTY_ID_TO, ROLE_TYPE_ID_FROM, 
> ROLE_TYPE_ID_TO, AGREEMENT_TYPE_ID, AGREEMENT_DATE, FROM_DATE, THRU_DATE, 
> DESCRIPTION, TEXT_DATA, LAST_UPDATED_STAMP, LAST_UPDATED_TX_STAMP, 
> CREATED_STAMP, CREATED_TX_STAMP, STATUS_ID, DEFAULT_CURRENCY_UOM_ID, 
> FROM_PARTY_CLASS_GROUP_ID, TO_PARTY_CLASS_GROUP_ID) VALUES (?, ?, ?, ?, ?, ?, 
> ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) (ERROR: insert or update on table 
> "agreement" violates foreign key constraint "agrmnt_tprtyrle"
> Detail: Key (party_id_to,role_type_id_to)=(Admin,PERSON_ROLE) is not present 
> in table "party_role".)))]
> It is fine for a developer who can understand that, but not for a user.
> I agree that with some hacking or better design in the forms it would be 
> possible to avoid that kind of error, but the idea would be to be able to 
> catch that and replace the error we something more understandable, for 
> example:
> ERROR: the "Party Id To" doesn't have the "Role Type To Id" you entered.
> Or better:
> ERROR: the "Party Id To: Admin" doesn't have the "Role Type To Id: Person". 
> Possible values for the Role Type are : "..."
> I know that such a feature cannot be implemented in the framework directly 
> because errors are context sensitive, so it would have to be done in the 
> Service XML definition.
> Perhaps some new methods could be added in simple-methods to make that task 
> easier ?

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to