litesoft
@ 950
litesoft / trunk / GWT_Sandbox / Prioritizer / src / org / litesoft / prioritizer / server / boviews / podataproviders / StoryViewPoServerVoDataProvider.java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 |
package org.litesoft.prioritizer.server.boviews.podataproviders; import org.litesoft.bo.views.communication.*; import org.litesoft.bo.views.server.*; import org.litesoft.commonfoundation.base.*; import org.litesoft.commonfoundation.exceptions.*; import org.litesoft.commonfoundation.iterators.*; import org.litesoft.orsup.base.*; import org.litesoft.orsup.selection.*; import org.litesoft.orsup.transact.*; import org.litesoft.prioritizer.client.boviews.*; import org.litesoft.prioritizer.client.support.*; import org.litesoft.prioritizer.server.pos.*; import java.util.*; public class StoryViewPoServerVoDataProvider extends PoServerVoDataProvider<StoryView> implements StoryViewNames { public StoryViewPoServerVoDataProvider( MetaDataStore pMetaDataStore ) { super( StoryViewMetaData.getInstance(), pMetaDataStore ); } @Override protected void LLinitialize() { super.LLinitialize(); register( new StoryViewServerFunctionFetchReprioritizeRows() ); register( new StoryViewServerFunctionFetchInitialPrioritizeRows() ); register( new StoryViewServerFunctionReprioritizeBetween() ); register( new StoryViewServerFunctionReprioritizeToGroup() ); } @Override protected WhereClause augment_getMatchingVOs( WhereClause pWhereClause ) { return super.augment_getMatchingVOs( WCF.and( pWhereClause, Story.getLimitToCurrentRestrictedResource() ) ); // Add filter to where clause to only select based on RestrictedResource. } public SizedIterator<StoryView> getInitialPrioritizeVOs( Integer pMaxToReturn ) throws PersistenceException { return getMatchingVOs( pMaxToReturn, true, WCF.isEqual( Story.CD_Priority, 0 ), new OrderBy( Story.CD_Name ) ); } public SizedIterator<StoryView> getReprioritizeVOs( Integer pMaxToReturn ) throws PersistenceException { return getMatchingVOs( pMaxToReturn, true, WCF.isNotEqual( Story.CD_Priority, 0 ), new OrderByDescending( Story.CD_Priority ) ); } /** * Reprioritize all the pToReprioritize to the "bottom" of the pPrioritizeToGroup */ public SCresult reprioritizeToGroup( PriorityGroup pPrioritizeToGroup, StoryView[] pToReprioritize ) throws PersistenceException { try { pPrioritizeToGroup = PriorityGroup.deNull( pPrioritizeToGroup, PriorityGroup.Medium ); UnfilteringFinder zFinder = DataStoreLocator.get().getUnfilteredFinder(); WhereClause zWC_Bottom = pPrioritizeToGroup.isBottomInclusive() ? // WCF.isGreaterThanEqual( Story.CD_Priority, pPrioritizeToGroup.getRangeBottom() ) : // WCF.isGreaterThan( Story.CD_Priority, pPrioritizeToGroup.getRangeBottom() ); WhereClause zWC_Top = pPrioritizeToGroup.isTopInclusive() ? // WCF.isLessThanEqual( Story.CD_Priority, pPrioritizeToGroup.getRangeTop() ) : // WCF.isLessThan( Story.CD_Priority, pPrioritizeToGroup.getRangeTop() ); WhereClause zWhereClause = WCF.and( zWC_Bottom, zWC_Top ); List<Story> zUpperRangeStories = zFinder.findSubset( Story.class, zWhereClause, new OrderBy( Story.CD_Priority ), 0, 1 ); Float zUpperBound = zUpperRangeStories.isEmpty() ? pPrioritizeToGroup.getRangeTop() : zUpperRangeStories.get( 0 ).getPriority(); return reprioritizeBetween( zFinder, new PriorityGroup.Range( pPrioritizeToGroup.getRangeBottom(), zUpperBound ), pToReprioritize ); } catch ( ConcurrentModificationException e ) { return staleData( e.getMessage() ); } } /** * Reprioritize all the pToReprioritize between the pLowerBound & the pUpperBound. * If either (but not both) are null, then use the edges of the PriorityGroup indicated by the other. * If BOTH are null then use the bounds of PriorityGroup.Medium. */ public SCresult reprioritizeBetween( StoryView pLowerBound, StoryView pUpperBound, StoryView[] pToReprioritize ) throws PersistenceException { try { UnfilteringFinder zFinder = DataStoreLocator.get().getUnfilteredFinder(); return reprioritizeBetween( zFinder, createRange( zFinder, pLowerBound, pUpperBound ), pToReprioritize ); } catch ( ConcurrentModificationException e ) { return staleData( e.getMessage() ); } } /* * If either (but not both) are null, then use the edges of the PriorityGroup indicated by the other. * If BOTH are null then use the bounds of PriorityGroup.Medium. */ private PriorityGroup.Range createRange( UnfilteringFinder zFinder, StoryView pLowerBound, StoryView pUpperBound ) { switch ( DualNullCheck.of( pLowerBound, pUpperBound ) ) { default: case BothNull: return PriorityGroup.Medium.getRangeAssumingExclusive(); case Only1stNull: Float zUpperBound = validatePriority( zFinder, pUpperBound ); return new PriorityGroup.Range( PriorityGroup.from( zUpperBound ).getRangeBottom(), zUpperBound ); case Only2ndNull: Float zLowerBound = validatePriority( zFinder, pLowerBound ); return new PriorityGroup.Range( zLowerBound, PriorityGroup.from( zLowerBound ).getRangeTop() ); case NeitherNull: return new PriorityGroup.Range( validatePriority( zFinder, pLowerBound ), validatePriority( zFinder, pUpperBound ) ); } } private Float validatePriority( UnfilteringFinder zFinder, StoryView pStoryView ) { return validatePriority( (Story) getExistingPO( zFinder, pStoryView ), pStoryView ).getPriority(); } private Story validatePriority( Story pStory, StoryView pStoryView ) { if ( pStory == null ) { throw new ConcurrentModificationException( "Story deleted: " + pStoryView ); } if ( pStory.getIsDone() ) { throw new ConcurrentModificationException( "Story 'Done': " + pStoryView ); } if ( Currently.areEqual( pStory.getPriority(), pStoryView.getPriority() ) ) { return pStory; } throw new ConcurrentModificationException( "Priority Changed, Story: " + pStoryView ); } private SCresult staleData( String pMessage ) { return VOSC.result( "Your View is Stale - Data Changed\n\n" + pMessage ); } private SCresult reprioritizeBetween( UnfilteringFinder pFinder, PriorityGroup.Range pRange, StoryView[] pToReprioritize ) throws PersistenceException { if ( Currently.isNullOrEmpty( pToReprioritize ) ) { return VOSC.result( "Nothing to Reprioritize" ); } Transaction zTransaction = pFinder.createUnaugmentedTransaction(); List<Story> zStories = validate( pToReprioritize, zTransaction.findAllByKeys( Story.class, getKeysFor( pToReprioritize ) ) ); updatePriorities( zStories, pRange.rePrioritizeBetween( extractPriorities( zStories ) ) ); zTransaction.commit(); return VOSC.result( "" ); } private void updatePriorities( List<Story> pStories, float[] pPriorities ) { for ( int i = 0; i < pStories.size(); i++ ) { pStories.get( i ).setPriority( pPriorities[i] ); } } private Float[] extractPriorities( List<Story> pStories ) { Float[] zPriorities = new Float[pStories.size()]; for ( int i = 0; i < pStories.size(); i++ ) { zPriorities[i] = pStories.get( i ).getPriority(); } return zPriorities; } private List<Story> validate( StoryView[] pToReprioritize, List<Story> pStories ) { List<Story> zStories = new ArrayList<Story>( pToReprioritize.length ); for ( StoryView zStoryView : pToReprioritize ) { zStories.add( validatePriority( getStory( pStories, zStoryView.getID() ), zStoryView ) ); } return zStories; } private Story getStory( List<Story> pStories, Long pID ) { for ( Story zStory : pStories ) { if ( Currently.areEqual( pID, zStory.getID() ) ) { return zStory; } } return null; } private Collection getKeysFor( StoryView[] pToReprioritize ) { List<Long> keys = new ArrayList<Long>( pToReprioritize.length ); for ( StoryView zStoryView : pToReprioritize ) { keys.add( zStoryView.getID() ); } return keys; } } |
Commits for litesoft/trunk/GWT_Sandbox/Prioritizer/src/org/litesoft/prioritizer/server/boviews/podataproviders/StoryViewPoServerVoDataProvider.java
Revision | Author | Commited | Message |
---|---|---|---|
950 Diff | GeorgeS | Thu 19 Jun, 2014 17:57:04 +0000 | New Lines |
948 Diff | GeorgeS | Sat 07 Jun, 2014 23:42:39 +0000 | Jusefuls Formatter Updated to New Code Format |
947 Diff | GeorgeS | Fri 06 Jun, 2014 23:36:56 +0000 | Correct Spelling of package! |
939 Diff | GeorgeS | Mon 02 Jun, 2014 21:30:31 +0000 | Extracting commonfoundation |
922 Diff | GeorgeS | Tue 18 Feb, 2014 16:18:01 +0000 | Mini App ready for packaging... |
822 Diff | GeorgeS | Sun 19 Aug, 2012 01:03:51 +0000 | |
809 Diff | GeorgeS | Thu 16 Aug, 2012 04:10:46 +0000 | |
480 Diff | GeorgeS | Sun 04 Sep, 2011 02:38:20 +0000 | Progress on common User Support... |
476 Diff | GeorgeS | Sat 03 Sep, 2011 13:57:13 +0000 | |
398 | GeorgeS | Mon 15 Aug, 2011 19:57:47 +0000 |