Filtering data with D2W

582 views

Published on

Published in: Technology, Travel
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
582
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
9
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Filtering data with D2W

  1. 1. Filtering data with D2WPhilippe Rabier - twitter.com/prabierSophiacom
  2. 2. What is the problem to solve?
  3. 3. CompanyEOEntityAEOEntityBUserEOEntityC
  4. 4. • Use D2W• Limit the visibility of the data• Use conventions to name relationships (for example, any toOnerelationship to Company entity, is called company)• Minimize the code• Be magic!The Requirements
  5. 5. Feedback fromYou ’N Push
  6. 6. First SolutionWorking at the editingContext level
  7. 7. modified fetchspecnotificationec factoryeccompanyobjectsWithFetchSpecification()createsbusinessFPfetchspec
  8. 8. How the qualifier is modified? public void alterFetchSpecification(final NSNotification aNotification) { EOEditingContext ec = (EOEditingContext) aNotification.object(); if (shouldAddRestrictionQualifier) { Company aCompany = (NOClient) ec.userInfoForKey(NBEditingContextFactory.COMPANY_KEY); final EOFetchSpecification fs = (EOFetchSpecification) aNotification.userInfo().valueForKey(COEditingContext.FETCH_SPEC_KEY); if (aCompany != null && fs != null) { EOEntity aEntity = EOUtilities.entityNamed(ec, fs.entityName()); EOQualifier fsQualifier = fs.qualifier(); if (fsQualifier != null) { NSSet<String> keys = fsQualifier.allQualifierKeys(); for (String aKey : keys) { if (aKey.contains("company")) { shouldAddRestrictionQualifier = false; break; } } } if (shouldAddRestrictionQualifier) { EOQualifier aRestrictionQualifier = clientRestrictionQualifier(aEntity, aClient); if (aRestrictionQualifier != null) { if (fsQualifier != null) fsQualifier = new EOAndQualifier(new NSArray<EOQualifier>(new EOQualifier[] {fsQualifier, aRestrictionQualifier})); else fsQualifier = aRestrictionQualifier; fs.setQualifier(fsQualifier); } } } } }
  9. 9. How the qualifier is modified? public EOQualifier companyRestrictionQualifier(final EOEntity entity, final Company company) { EOQualifier aQualifier = null; if (entity.name().equals(Company.Keys.ENTITY_NAME)) aQualifier = new EOKeyValueQualifier(Company.Keys.NAME, EOQualifier.QualifierOperatorEqual, company.name()); else if (entity.relationshipNamed("company") != null) aQualifier = new EOKeyValueQualifier("company", EOQualifier.QualifierOperatorEqual, company); else if (entity.relationshipNamed("entityB") != null) aQualifier = new EOKeyValueQualifier("entityB.company", EOQualifier.QualifierOperatorEqual, client); else if (entity.relationshipNamed("entityC") != null) ...; if (log.isDebugEnabled()) log.debug("method: qualifier: " + aQualifier); return aQualifier; }
  10. 10. It works greatbut there is a little problemit’s too low level
  11. 11. An Example of Problem public void validateForSave() throws ValidationException { super.validateForSave(); ERXEOControlUtilities.validateUniquenessOf(this, NOUser.Keys.LOGIN); ERXEOControlUtilities.validateUniquenessOf(this, NOUser.Keys.EMAIL); } public void validateForSave() throws ValidationException { super.validateForSave(); editingContext().setUserInfoForKey(Boolean.FALSE, NBEditingContextFactory.NO_RESTRICTION_QUAL_KEY); ERXEOControlUtilities.validateUniquenessOf(this, NOUser.Keys.LOGIN); ERXEOControlUtilities.validateUniquenessOf(this, NOUser.Keys.EMAIL); editingContext().setUserInfoForKey(Boolean.TRUE, NBEditingContextFactory.NO_RESTRICTION_QUAL_KEY); }
  12. 12. Second Solution
  13. 13. • Displaying a list• Using a query component• Using ERD2WEditToManyRelationship component• Using ERD2WEditToOneRelationship componentWhen should we filter?
  14. 14. • Modify the NavigationController object• Change the data sourceDisplaying a list public WOComponent listPageForEntityName(final String entityName) { ListPageInterface newListPageInterface = D2W.factory().listPageForEntityNamed(entityName, session()); EODatabaseDataSource dataSource = new EODatabaseDataSource(ERXEC.newEditingContext(), entityName); EOEntity entity = ERXEOAccessUtilities.entityNamed(null, entityName); EOQualifier auxQual = NBBusinessLogicPrincipal.getSharedInstance().clientRestrictionQualifier(entity, ((Session)session()).getCompany()); dataSource.setAuxiliaryQualifier(auxQual); newListPageInterface.setDataSource(dataSource); return (WOComponent) newListPageInterface; }
  15. 15. • Use a query delegate• Override the method queryDataSource(ERD2WQueryPage sender)Using a query component{author = 100;class = "com.webobjects.directtoweb.Rule";lhs = {class = "com.webobjects.eocontrol.EOKeyValueQualifier";key = pageConfiguration;selectorName = isEqualTo;value = QueryMyEntity;};rhs = {class = "er.directtoweb.ERDDelayedObjectCreationAssignment";keyPath = queryDataSourceDelegate;value = "ca.wowodc.very.util.pascal.delegate.SomeOneElse";};}
  16. 16. • Maybe subclass the 2 component is the best solution• Use restrictingFetchSpecification key. If all fetchspec have thesame name, it’s possible to build a generic rule.• Need to be modified to add the possibility to set a binding tothe fetchspec• Maybe a lot of pain to create many fetchspec in the EOModelEditRelationship components
  17. 17. How the qualifier is modified?public Object restrictedChoiceList() {String restrictedChoiceKey=(String)d2wContext().valueForKey("restrictedChoiceKey");if( restrictedChoiceKey!=null && restrictedChoiceKey.length()>0 )return valueForKeyPath(restrictedChoiceKey);String fetchSpecName=(String)d2wContext().valueForKey("restrictingFetchSpecification");if(fetchSpecName != null) {EORelationship relationship = ERXUtilities.relationshipWithObjectAndKeyPath(object(),(String)d2wContext().valueForKey("propertyKey"));if(relationship != null)return EOUtilities.objectsWithFetchSpecificationAndBindings(object().editingContext(),relationship.destinationEntity().name(),fetchSpecName,null);}return null;}
  18. 18. @prabierFollow me!
  19. 19. Q&ATBD

×