r292 - in trunk: magalie-services/src/main/java/com/franciaflex/magalie/services/service magalie-services/src/test/java/com/franciaflex/magalie/services/service magalie-web/src/main/java/com/franciaflex/magalie/web/action
Author: bleny Date: 2013-07-05 12:14:21 +0200 (Fri, 05 Jul 2013) New Revision: 292 Url: http://forge.codelutin.com/projects/franciaflex-magalie/repository/revisions... Log: add a flag in receptionTask for when user must use an extra location Modified: trunk/magalie-services/src/main/java/com/franciaflex/magalie/services/service/ReceptionService.java trunk/magalie-services/src/main/java/com/franciaflex/magalie/services/service/ReceptionTask.java trunk/magalie-services/src/test/java/com/franciaflex/magalie/services/service/ReceptionServiceTest.java trunk/magalie-web/src/main/java/com/franciaflex/magalie/web/action/ReceiveArticleAction.java Modified: trunk/magalie-services/src/main/java/com/franciaflex/magalie/services/service/ReceptionService.java =================================================================== --- trunk/magalie-services/src/main/java/com/franciaflex/magalie/services/service/ReceptionService.java 2013-07-04 14:15:09 UTC (rev 291) +++ trunk/magalie-services/src/main/java/com/franciaflex/magalie/services/service/ReceptionService.java 2013-07-05 10:14:21 UTC (rev 292) @@ -183,47 +183,84 @@ Warehouse warehouse = storedArticle.getLocation().getWarehouse(); - List<Location> locations = findLocationsToReceiveArticle(warehouse, article); + if (log.isTraceEnabled()) { + log.trace("looking for locations to receive for " + article + " in " + warehouse); + } - return new ReceptionTask(storedArticle, quantity, locations); + LocationErrorsService locationErrorsService = + serviceContext.newService(LocationErrorsService.class); - } + Predicate<Location> isAcceptableForReception = + Predicates.and( + ImmutableSet.of( + Locations.isNotReceptionLocation(), + Locations.isNotFullLocation(), + locationErrorsService.getLocationNotReportedInErrorPredicate() + ) + ); - public ReceptionTask getReceptionTaskForPreparedArticleReception(Building building, String barcode) throws PreparedArticleReceptionAlreadyStoredException, InvalidMagalieBarcodeException { + // first step, add fixed locations for this article first - PreparedArticleReception preparedArticleReception = - getPreparedArticleReception(building, barcode); + Set<Location> preferredLocations = getPreferredLocations(warehouse, article); - JpaMagaliePersistenceContext persistenceContext = - serviceContext.getPersistenceContext(); + boolean userMustChooseExtraLocation = preferredLocations.isEmpty(); - StoredArticleJpaDao storedArticleDao = - persistenceContext.getStoredArticleDao(); + // second step, add extra locations - Article article = preparedArticleReception.getArticle(); + Set<Location> extraLocations = getExtraLocations(warehouse); - StoredArticle storedArticle = - storedArticleDao.findInReception(building, article); + Set<Location> locations = Sets.newLinkedHashSet(); - ReceptionTask receptionTask = buildReceptionTask( - storedArticle, - preparedArticleReception.getQuantity()); + Iterables.addAll(locations, Iterables.filter(preferredLocations, isAcceptableForReception)); - if (log.isInfoEnabled()) { - log.info("reception task for prepared article reception '" + barcode + "' is " + receptionTask); + Iterables.addAll(locations, Iterables.filter(extraLocations, isAcceptableForReception)); + + ReceptionTask receptionTask = new ReceptionTask(storedArticle, quantity, locations, userMustChooseExtraLocation); + + if (log.isDebugEnabled()) { + log.debug(locations.size() + " locations to receive articles for article " + + article + " in warehouse " + warehouse + " are " + + StringUtils.join(locations, ", ")); } return receptionTask; } - protected List<Location> findLocationsToReceiveArticle(Warehouse warehouse, Article article) { + protected Set<Location> getExtraLocations(Warehouse warehouse) { - if (log.isTraceEnabled()) { - log.trace("looking for locations to receive for " + article + " in " + warehouse); + Set<Location> locations = Sets.newLinkedHashSet(); + + // third step, add extra locations + JpaMagaliePersistenceContext persistenceContext = + serviceContext.getPersistenceContext(); + + LocationDao locationDao = + persistenceContext.getLocationDao(); + + // TODO brendan 04/07/13 probablement l'origine du problème de performance + + // add all locations in the same warehouse + locations.addAll(locationDao.findAllWithoutReception(warehouse)); + + // add all locations in the same building, other warehouses + // FIXME brendan 04/07/13 re-enable + if (false) { + locations.addAll(locationDao.findAllWithoutReception(warehouse.getBuilding())); } + // fourth step, remove reception locations because it's stupid to + // move an article from reception location to another reception location + // also, remove full locations and locations reported in error + + return locations; + + } + + protected Set<Location> getPreferredLocations(Warehouse warehouse, Article article) { + // first step, add fixed locations for this article first + Set<Location> locations = Sets.newLinkedHashSet(); if (article.getFixedLocations() != null) { @@ -256,53 +293,35 @@ sortedStoredArticles, StoredArticles.getLocationFunction())); - // third step, add extra locations - JpaMagaliePersistenceContext persistenceContext = - serviceContext.getPersistenceContext(); + return locations; - LocationDao locationDao = - persistenceContext.getLocationDao(); + } - // TODO brendan 04/07/13 probablement l'origine du problème de performance + public ReceptionTask getReceptionTaskForPreparedArticleReception(Building building, String barcode) throws PreparedArticleReceptionAlreadyStoredException, InvalidMagalieBarcodeException { - // add all locations in the same warehouse - locations.addAll(locationDao.findAllWithoutReception(warehouse)); + PreparedArticleReception preparedArticleReception = + getPreparedArticleReception(building, barcode); - // add all locations in the same building, other warehouses - // FIXME brendan 04/07/13 re-enable - // locations.addAll(locationDao.findAllWithoutReception(warehouse.getBuilding())); + JpaMagaliePersistenceContext persistenceContext = + serviceContext.getPersistenceContext(); - // fourth step, remove reception locations because it's stupid to - // move an article from reception location to another reception location - // also, remove full locations and locations reported in error + StoredArticleJpaDao storedArticleDao = + persistenceContext.getStoredArticleDao(); - LocationErrorsService locationErrorsService = - serviceContext.newService(LocationErrorsService.class); + Article article = preparedArticleReception.getArticle(); - Predicate<Location> isAcceptableForReception = - Predicates.and( - ImmutableSet.of( - Locations.isNotReceptionLocation(), - Locations.isNotFullLocation(), - locationErrorsService.getLocationNotReportedInErrorPredicate() - ) - ); + StoredArticle storedArticle = + storedArticleDao.findInReception(building, article); - List<Location> result = - Lists.newArrayList( - Iterables.filter( - locations, - isAcceptableForReception - ) - ); + ReceptionTask receptionTask = buildReceptionTask( + storedArticle, + preparedArticleReception.getQuantity()); - if (log.isDebugEnabled()) { - log.debug(result.size() + " locations to receive articles for article " - + article + " in warehouse " + warehouse + " are " - + StringUtils.join(result, ", ")); + if (log.isInfoEnabled()) { + log.info("reception task for prepared article reception '" + barcode + "' is " + receptionTask); } - return result; + return receptionTask; } Modified: trunk/magalie-services/src/main/java/com/franciaflex/magalie/services/service/ReceptionTask.java =================================================================== --- trunk/magalie-services/src/main/java/com/franciaflex/magalie/services/service/ReceptionTask.java 2013-07-04 14:15:09 UTC (rev 291) +++ trunk/magalie-services/src/main/java/com/franciaflex/magalie/services/service/ReceptionTask.java 2013-07-05 10:14:21 UTC (rev 292) @@ -26,31 +26,39 @@ import com.franciaflex.magalie.persistence.entity.Location; import com.franciaflex.magalie.persistence.entity.StoredArticle; -import java.util.List; +import java.util.Set; public class ReceptionTask { + protected boolean userMustChooseExtraLocation; + protected StoredArticle storedArticle; protected double quantity; - protected List<Location> locations; + protected Set<Location> locations; - public ReceptionTask(StoredArticle storedArticle, double quantity, List<Location> locations) { + public ReceptionTask(StoredArticle storedArticle, double quantity, Set<Location> locations, boolean userMustChooseExtraLocation) { this.storedArticle = storedArticle; this.quantity = quantity; this.locations = locations; + this.userMustChooseExtraLocation = userMustChooseExtraLocation; } public StoredArticle getStoredArticle() { return storedArticle; } - public List<Location> getLocations() { + public Set<Location> getLocations() { return locations; } public double getQuantity() { return quantity; } + + public boolean isUserMustChooseExtraLocation() { + return userMustChooseExtraLocation; + } + } Modified: trunk/magalie-services/src/test/java/com/franciaflex/magalie/services/service/ReceptionServiceTest.java =================================================================== --- trunk/magalie-services/src/test/java/com/franciaflex/magalie/services/service/ReceptionServiceTest.java 2013-07-04 14:15:09 UTC (rev 291) +++ trunk/magalie-services/src/test/java/com/franciaflex/magalie/services/service/ReceptionServiceTest.java 2013-07-05 10:14:21 UTC (rev 292) @@ -53,6 +53,7 @@ import java.util.Date; import java.util.List; import java.util.Map; +import java.util.Set; public class ReceptionServiceTest extends AbstractMagalieServiceTest { @@ -135,21 +136,21 @@ Location fixedLocation = Iterables.getOnlyElement(article.getFixedLocations()); // fixed location - Assert.assertEquals(fixedLocation, receptionTask.getLocations().get(0)); + Assert.assertEquals(fixedLocation, Iterables.get(receptionTask.getLocations(), 0)); // locations of the same warehouse - Assert.assertEquals(receivedArticle.getLocation().getWarehouse(), receptionTask.getLocations().get(1).getWarehouse()); - Assert.assertEquals(receivedArticle.getLocation().getWarehouse(), receptionTask.getLocations().get(2).getWarehouse()); - Assert.assertEquals(receivedArticle.getLocation().getWarehouse(), receptionTask.getLocations().get(3).getWarehouse()); + Assert.assertEquals(receivedArticle.getLocation().getWarehouse(), Iterables.get(receptionTask.getLocations(), 1).getWarehouse()); + Assert.assertEquals(receivedArticle.getLocation().getWarehouse(), Iterables.get(receptionTask.getLocations(), 2).getWarehouse()); + Assert.assertEquals(receivedArticle.getLocation().getWarehouse(), Iterables.get(receptionTask.getLocations(), 3).getWarehouse()); // locations in another warehouse last - Assert.assertNotEquals(receivedArticle.getLocation().getWarehouse(), receptionTask.getLocations().get(4).getWarehouse()); - Assert.assertNotEquals(receivedArticle.getLocation().getWarehouse(), receptionTask.getLocations().get(5).getWarehouse()); - Assert.assertNotEquals(receivedArticle.getLocation().getWarehouse(), receptionTask.getLocations().get(6).getWarehouse()); - Assert.assertNotEquals(receivedArticle.getLocation().getWarehouse(), receptionTask.getLocations().get(7).getWarehouse()); - Assert.assertNotEquals(receivedArticle.getLocation().getWarehouse(), receptionTask.getLocations().get(8).getWarehouse()); - Assert.assertNotEquals(receivedArticle.getLocation().getWarehouse(), receptionTask.getLocations().get(9).getWarehouse()); - Assert.assertNotEquals(receivedArticle.getLocation().getWarehouse(), receptionTask.getLocations().get(10).getWarehouse()); + Assert.assertNotEquals(receivedArticle.getLocation().getWarehouse(), Iterables.get(receptionTask.getLocations(), 4).getWarehouse()); + Assert.assertNotEquals(receivedArticle.getLocation().getWarehouse(), Iterables.get(receptionTask.getLocations(), 5).getWarehouse()); + Assert.assertNotEquals(receivedArticle.getLocation().getWarehouse(), Iterables.get(receptionTask.getLocations(), 6).getWarehouse()); + Assert.assertNotEquals(receivedArticle.getLocation().getWarehouse(), Iterables.get(receptionTask.getLocations(), 7).getWarehouse()); + Assert.assertNotEquals(receivedArticle.getLocation().getWarehouse(), Iterables.get(receptionTask.getLocations(), 8).getWarehouse()); + Assert.assertNotEquals(receivedArticle.getLocation().getWarehouse(), Iterables.get(receptionTask.getLocations(), 9).getWarehouse()); + Assert.assertNotEquals(receivedArticle.getLocation().getWarehouse(), Iterables.get(receptionTask.getLocations(), 10).getWarehouse()); for (Location location : receptionTask.getLocations()) { @@ -282,7 +283,7 @@ // just store the whole quantity in the first location given Map<String, Double> locationIdToStoredQuantities = ImmutableMap.of( - receptionTask.getLocations().get(0).getId(), + Iterables.get(receptionTask.getLocations(), 0).getId(), receptionTask.getQuantity()); receptionConfirmation.setLocationIdToStoredQuantities(locationIdToStoredQuantities); @@ -345,9 +346,15 @@ transaction.commit(); + List<StoredArticle> receivedArticles = + service.getReceivedArticles(building, supplier.getId()); + + StoredArticle receivedArticle = + Iterables.getOnlyElement(receivedArticles); + long time = System.currentTimeMillis(); - List<Location> locations = service.findLocationsToReceiveArticle(u02, article); + Set<Location> locations = service.getReceptionTask(receivedArticle.getId()).getLocations(); if (log.isTraceEnabled()) { log.trace("getting a result of " + locations.size() + Modified: trunk/magalie-web/src/main/java/com/franciaflex/magalie/web/action/ReceiveArticleAction.java =================================================================== --- trunk/magalie-web/src/main/java/com/franciaflex/magalie/web/action/ReceiveArticleAction.java 2013-07-04 14:15:09 UTC (rev 291) +++ trunk/magalie-web/src/main/java/com/franciaflex/magalie/web/action/ReceiveArticleAction.java 2013-07-05 10:14:21 UTC (rev 292) @@ -98,6 +98,12 @@ receptionTask = service.getReceptionTaskForPreparedArticleReception(building, preparedArticleReceptionBarcode); + if (receptionTask.isUserMustChooseExtraLocation()) { + + addActionMessage("Pas de stock : emplacement libre proposé"); + + } + } catch (PreparedArticleReceptionAlreadyStoredException e) { session.addMessage("Article déjà rangé");
participants (1)
-
bleny@users.forge.codelutin.com