litesoft
@ 950
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 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 |
package org.litesoft.datt.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.commonfoundation.typeutils.*; import org.litesoft.datt.client.boviews.*; import org.litesoft.datt.client.support.*; import org.litesoft.datt.server.*; import org.litesoft.datt.server.boviews.*; import org.litesoft.datt.server.pos.*; import org.litesoft.orsup.base.*; import org.litesoft.orsup.selection.*; import org.litesoft.orsup.transact.*; 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 StoryViewServerFunctionMergeStory() ); 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 = Lists.newArrayList( 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 = Lists.newArrayList( pToReprioritize.length ); for ( StoryView zStoryView : pToReprioritize ) { keys.add( zStoryView.getID() ); } return keys; } public String mergeStory( StoryView pMergeFromStoryView, StoryView pMergeIntoStoryView ) { Long zMergeIntoID = pMergeIntoStoryView.getID(); Long zMergeFromID = pMergeFromStoryView.getID(); if ( zMergeIntoID.equals( zMergeFromID ) ) { return "Cannot merge the same Story into itself"; } while ( true ) { Transaction zTransaction = DataStoreLocator.get().getUnfilteredFinder().createTransaction(); Story zMergeIntoPO = getStoryPO( zMergeIntoID, zTransaction ); Story zMergeFromPO = getStoryPO( zMergeFromID, zTransaction ); List<Task> zTasks = zMergeFromPO.getTasks(); for ( Task zTask : zTasks ) { zMergeIntoPO.addTasks( zTask ); } zMergeIntoPO.addUpdates( new StoryUpdate( zTransaction, CurrentUserAccessor.get().getRequiredUser().freshIntoIfNotAlreadyIn( zTransaction ), "Tasks merged from story: " + zMergeFromPO.getName() ) ); zMergeFromPO.requestDelete(); try { zTransaction.commit(); return null; } catch ( ConcurrentPOModificationException e ) { // Expected } } } private Story getStoryPO( Long pMergeIntoID, Transaction pTransaction ) { Story zStory = (Story) findPO( pTransaction, pMergeIntoID ); if ( zStory == null ) { throw new DisplayableRuntimeException( "OneOfTheStoriesAppearsToHaveBeenDeleted" ); } return zStory; } } |
Commits for litesoft/trunk/Java/DATT/src/org/litesoft/datt/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 |
822 Diff | GeorgeS | Sun 19 Aug, 2012 01:03:51 +0000 | |
809 Diff | GeorgeS | Thu 16 Aug, 2012 04:10:46 +0000 | |
511 Diff | markcmarkc | Sun 18 Sep, 2011 22:42:49 +0000 | Added Restricted Resource to Story selection and fixed update of who last prioritized the story |
502 Diff | markcmarkc | Mon 12 Sep, 2011 00:46:45 +0000 | |
430 | GeorgeS | Sat 20 Aug, 2011 19:46:21 +0000 |