Author: bleny Date: 2013-07-31 17:49:10 +0200 (Wed, 31 Jul 2013) New Revision: 352 Url: http://forge.codelutin.com/projects/franciaflex-magalie/repository/revisions... Log: fixes #3001 urgent field was considered but shortest list was priorized, now list size is ignored Modified: trunk/magalie-persistence/src/main/java/com/franciaflex/magalie/persistence/RequestedArticles.java trunk/magalie-persistence/src/main/java/com/franciaflex/magalie/persistence/RequestedLists.java trunk/magalie-services/src/main/java/com/franciaflex/magalie/services/service/RequestedArticleService.java trunk/magalie-services/src/test/java/com/franciaflex/magalie/services/service/RequestedArticleServiceTest.java Modified: trunk/magalie-persistence/src/main/java/com/franciaflex/magalie/persistence/RequestedArticles.java =================================================================== --- trunk/magalie-persistence/src/main/java/com/franciaflex/magalie/persistence/RequestedArticles.java 2013-07-31 15:31:58 UTC (rev 351) +++ trunk/magalie-persistence/src/main/java/com/franciaflex/magalie/persistence/RequestedArticles.java 2013-07-31 15:49:10 UTC (rev 352) @@ -31,7 +31,6 @@ import org.nuiton.jpa.api.JpaEntities; import java.util.Comparator; -import java.util.List; public class RequestedArticles { @@ -49,12 +48,12 @@ } } - public static Comparator<RequestedArticle> comparator(List<RequestedArticle> requests, RequestedList affectedRequestedList) { + public static Comparator<RequestedArticle> comparator(RequestedList affectedRequestedList) { Comparator<RequestedArticle> comparator = Ordering.compound( Lists.newArrayList( - new RequestedListComparator(RequestedLists.comparator(requests, affectedRequestedList)), + new RequestedListComparator(RequestedLists.comparator(affectedRequestedList)), // we can still have ambiguous or priorities, so to be deterministic, use arbitrary order JpaEntities.<RequestedArticle>arbitraryComparator() Modified: trunk/magalie-persistence/src/main/java/com/franciaflex/magalie/persistence/RequestedLists.java =================================================================== --- trunk/magalie-persistence/src/main/java/com/franciaflex/magalie/persistence/RequestedLists.java 2013-07-31 15:31:58 UTC (rev 351) +++ trunk/magalie-persistence/src/main/java/com/franciaflex/magalie/persistence/RequestedLists.java 2013-07-31 15:49:10 UTC (rev 352) @@ -23,21 +23,14 @@ * #L% */ -import com.franciaflex.magalie.persistence.entity.RequestedArticle; import com.franciaflex.magalie.persistence.entity.RequestedList; -import com.google.common.collect.ImmutableListMultimap; import com.google.common.collect.Lists; -import com.google.common.collect.Maps; -import com.google.common.collect.Multimaps; import com.google.common.collect.Ordering; import org.apache.commons.collections.comparators.BooleanComparator; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import java.util.Collection; import java.util.Comparator; -import java.util.List; -import java.util.Map; public class RequestedLists { @@ -77,40 +70,6 @@ } - protected static class FinishEarlyFirstComparator implements Comparator<RequestedList> { - - protected Map<RequestedList, Integer> requestListToArticleRemainingCount; - - public FinishEarlyFirstComparator(Map<RequestedList, Integer> requestListToArticleRemainingCount) { - this.requestListToArticleRemainingCount = requestListToArticleRemainingCount; - } - - protected int getRemainingCount(RequestedList requestedList) { - Integer remainingCount = requestListToArticleRemainingCount.get(requestedList); - return remainingCount; - } - - @Override - public int compare(RequestedList x, RequestedList y) { - int xRemainingCount = getRemainingCount(x); - int yRemainingCount = getRemainingCount(y); - int compare = xRemainingCount - yRemainingCount; - if (log.isTraceEnabled()) { - if (compare < 0) { - log.trace(x.getId() + " is before " + y.getId()); - } - if (compare == 0 && ! x.equals(y)) { - log.trace(x.getId() + " is same position as " + y.getId()); - } - if (compare > 0) { - log.trace(y.getId() + " is before " + x.getId()); - } - } - return compare; - } - - } - public static Comparator<RequestedList> urgentFirstComparator() { return new UrgentFirstComparator(); } @@ -119,41 +78,15 @@ return new RequestDateFistComparator(); } - public static Comparator<RequestedList> finishEarlyFirstComparator(List<RequestedArticle> requests) { - - ImmutableListMultimap<RequestedList, RequestedArticle> index = - Multimaps.index(requests, RequestedArticles.getRequestList()); - - Map<RequestedList, Integer> requestListToArticleRemainingCount = Maps.newHashMap(); - - for (Map.Entry<RequestedList, Collection<RequestedArticle>> requestedListCollectionEntry : index.asMap().entrySet()) { - - RequestedList requestedList = requestedListCollectionEntry.getKey(); - - int remainingCount = requestedListCollectionEntry.getValue().size(); - - requestListToArticleRemainingCount.put(requestedList, remainingCount); - - } - - if (log.isDebugEnabled()) { - log.debug("number of remaining articles per list: " + requestListToArticleRemainingCount); - } - - return new FinishEarlyFirstComparator(requestListToArticleRemainingCount); - - } - public static Comparator<RequestedList> givenRequestListFirst(RequestedList requestedList) { return new GivenRequestListFirst(requestedList); } - public static Comparator<RequestedList> comparator(List<RequestedArticle> requests, RequestedList affectedRequestedList) { + public static Comparator<RequestedList> comparator(RequestedList affectedRequestedList) { Ordering<RequestedList> comparator = Ordering.compound( Lists.newArrayList( givenRequestListFirst(affectedRequestedList), - finishEarlyFirstComparator(requests), urgentFirstComparator(), requestDateFirstComparator() ) Modified: trunk/magalie-services/src/main/java/com/franciaflex/magalie/services/service/RequestedArticleService.java =================================================================== --- trunk/magalie-services/src/main/java/com/franciaflex/magalie/services/service/RequestedArticleService.java 2013-07-31 15:31:58 UTC (rev 351) +++ trunk/magalie-services/src/main/java/com/franciaflex/magalie/services/service/RequestedArticleService.java 2013-07-31 15:49:10 UTC (rev 352) @@ -286,7 +286,7 @@ } Comparator<RequestedArticle> priorityComparator = - RequestedArticles.comparator(requests, affectedRequestedList); + RequestedArticles.comparator(affectedRequestedList); Set<RequestedArticle> requestedArticles = Sets.newTreeSet(priorityComparator); Modified: trunk/magalie-services/src/test/java/com/franciaflex/magalie/services/service/RequestedArticleServiceTest.java =================================================================== --- trunk/magalie-services/src/test/java/com/franciaflex/magalie/services/service/RequestedArticleServiceTest.java 2013-07-31 15:31:58 UTC (rev 351) +++ trunk/magalie-services/src/test/java/com/franciaflex/magalie/services/service/RequestedArticleServiceTest.java 2013-07-31 15:49:10 UTC (rev 352) @@ -93,12 +93,12 @@ Assert.assertEquals(requestedArticles.size(), requestedArticlesByPriority.size()); - Assert.assertEquals("requestedArticle5", Iterables.get(requestedArticlesByPriority, 0).getId()); - Assert.assertEquals("requestedArticle6", Iterables.get(requestedArticlesByPriority, 1).getId()); - Assert.assertEquals("requestedArticle1", Iterables.get(requestedArticlesByPriority, 2).getId()); - Assert.assertEquals("requestedArticle2", Iterables.get(requestedArticlesByPriority, 3).getId()); - Assert.assertEquals("requestedArticle3", Iterables.get(requestedArticlesByPriority, 4).getId()); - Assert.assertEquals("requestedArticle4", Iterables.get(requestedArticlesByPriority, 5).getId()); + Assert.assertEquals("requestedArticle1", Iterables.get(requestedArticlesByPriority, 0).getId()); + Assert.assertEquals("requestedArticle2", Iterables.get(requestedArticlesByPriority, 1).getId()); + Assert.assertEquals("requestedArticle3", Iterables.get(requestedArticlesByPriority, 2).getId()); + Assert.assertEquals("requestedArticle4", Iterables.get(requestedArticlesByPriority, 3).getId()); + Assert.assertEquals("requestedArticle5", Iterables.get(requestedArticlesByPriority, 4).getId()); + Assert.assertEquals("requestedArticle6", Iterables.get(requestedArticlesByPriority, 5).getId()); } @@ -212,6 +212,20 @@ } + // continuing first list, user affectation not changed + { + orderToExecute = service.findOrderToExecute(magalieUser, building, LIST_TYPE); + Preconditions.checkState(orderToExecute.isSuccess()); + + Assert.assertNull(orderToExecute.getOldAffectation()); + Assert.assertNull(orderToExecute.getNewAffectation()); + + StorageMovementConfirmation confirmation = new StorageMovementConfirmation(); + confirmation.setRequestedArticleId(orderToExecute.getRequestedArticle().getId()); + service.onStorageMovementConfirmation(confirmation, emptySet); + + } + // first list is finished, must know old affectation and new affectation { orderToExecute = service.findOrderToExecute(magalieUser, building, LIST_TYPE);