Author: bleny Date: 2013-05-21 15:12:25 +0200 (Tue, 21 May 2013) New Revision: 171 Url: http://forge.codelutin.com/projects/franciaflex-magalie/repository/revisions... Log: refs #2165 suggest locations of the same warehouse first Modified: trunk/magalie-persistence/src/main/java/com/franciaflex/magalie/persistence/dao/LocationDao.java trunk/magalie-persistence/src/main/java/com/franciaflex/magalie/persistence/dao/jpa/LocationJpaDao.java trunk/magalie-services/src/main/java/com/franciaflex/magalie/services/service/ReceptionService.java trunk/magalie-services/src/test/java/com/franciaflex/magalie/services/service/ReceptionServiceTest.java Modified: trunk/magalie-persistence/src/main/java/com/franciaflex/magalie/persistence/dao/LocationDao.java =================================================================== --- trunk/magalie-persistence/src/main/java/com/franciaflex/magalie/persistence/dao/LocationDao.java 2013-05-21 10:28:31 UTC (rev 170) +++ trunk/magalie-persistence/src/main/java/com/franciaflex/magalie/persistence/dao/LocationDao.java 2013-05-21 13:12:25 UTC (rev 171) @@ -35,4 +35,5 @@ List<Location> findAllWithoutReception(Building building); + List<Location> findAllWithoutReception(Warehouse warehouse); } Modified: trunk/magalie-persistence/src/main/java/com/franciaflex/magalie/persistence/dao/jpa/LocationJpaDao.java =================================================================== --- trunk/magalie-persistence/src/main/java/com/franciaflex/magalie/persistence/dao/jpa/LocationJpaDao.java 2013-05-21 10:28:31 UTC (rev 170) +++ trunk/magalie-persistence/src/main/java/com/franciaflex/magalie/persistence/dao/jpa/LocationJpaDao.java 2013-05-21 13:12:25 UTC (rev 171) @@ -52,18 +52,39 @@ return findUnique(query); } - @Override - public List<Location> findAllWithoutReception(Building building) { - TypedQuery<Location> query = createQuery( - " from Location l where" - + " l.warehouse.building = :building and " - + " l.code != :codeForReceptionLocations and " - + " l.code != :codeForWarehouseWithoutLocations and " - + " l.fullLocation = false " - + " order by l.warehouse.building.code, l.warehouse.code, l.code"); - query.setParameter("building", building); + protected List<Location> findAllWithoutReception(Building building, Warehouse warehouse) { + boolean filterOnBuilding = building != null; + boolean filterOnWarehouse = warehouse != null; + String hql = " from Location l where"; + if (filterOnBuilding) { + hql += " l.warehouse.building = :building and "; + } + if (filterOnWarehouse) { + hql += " l.warehouse = :warehouse and "; + } + hql += " l.code != :codeForReceptionLocations and " + + " l.code != :codeForWarehouseWithoutLocations and " + + " l.fullLocation = false " + + " order by l.warehouse.building.code, l.warehouse.code, l.code"; + TypedQuery <Location> query = createQuery(hql); + if (filterOnBuilding) { + query.setParameter("building", building); + } + if (filterOnWarehouse) { + query.setParameter("warehouse", warehouse); + } query.setParameter("codeForReceptionLocations", Locations.codeForReceptionLocations()); query.setParameter("codeForWarehouseWithoutLocations", Locations.codeForWarehouseWithoutLocations()); return findAll(query); } + + @Override + public List<Location> findAllWithoutReception(Building building) { + return findAllWithoutReception(building, null); + } + + @Override + public List<Location> findAllWithoutReception(Warehouse warehouse) { + return findAllWithoutReception(null, warehouse); + } } 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-05-21 10:28:31 UTC (rev 170) +++ trunk/magalie-services/src/main/java/com/franciaflex/magalie/services/service/ReceptionService.java 2013-05-21 13:12:25 UTC (rev 171) @@ -37,6 +37,7 @@ import com.franciaflex.magalie.persistence.entity.StorageMovement; import com.franciaflex.magalie.persistence.entity.StoredArticle; import com.franciaflex.magalie.persistence.entity.Supplier; +import com.franciaflex.magalie.persistence.entity.Warehouse; import com.franciaflex.magalie.services.MagalieService; import com.franciaflex.magalie.services.MagalieServiceContext; import com.google.common.collect.Iterables; @@ -152,9 +153,9 @@ Article article = storedArticle.getArticle(); - Building building = storedArticle.getLocation().getWarehouse().getBuilding(); + Warehouse warehouse = storedArticle.getLocation().getWarehouse(); - List<Location> locations = findLocationsToReceiveArticle(building, article); + List<Location> locations = findLocationsToReceiveArticle(warehouse, article); ReceptionTask receptionTask = new ReceptionTask(storedArticle, locations); @@ -162,7 +163,7 @@ } - protected List<Location> findLocationsToReceiveArticle(Building building, Article article) { + protected List<Location> findLocationsToReceiveArticle(Warehouse warehouse, Article article) { // first step, add fixed locations for this article first Set<Location> locations = Sets.newLinkedHashSet(); @@ -179,7 +180,7 @@ serviceContext.newService(ArticleStorageService.class); Iterable<StoredArticle> storedArticles = - articleStorageService.getStoredArticles(building, article); + articleStorageService.getStoredArticles(warehouse.getBuilding(), article); Ordering<StoredArticle> comparator = Ordering.compound( Lists.newArrayList( @@ -204,8 +205,12 @@ LocationDao locationDao = persistenceContext.getLocationDao(); - locations.addAll(locationDao.findAllWithoutReception(building)); + // add all locations in the same warehouse + locations.addAll(locationDao.findAllWithoutReception(warehouse)); + // add all locations in the same building, other warehouses + 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 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-05-21 10:28:31 UTC (rev 170) +++ trunk/magalie-services/src/test/java/com/franciaflex/magalie/services/service/ReceptionServiceTest.java 2013-05-21 13:12:25 UTC (rev 171) @@ -125,8 +125,23 @@ Location fixedLocation = Iterables.getOnlyElement(article.getFixedLocations()); + // fixed location Assert.assertEquals(fixedLocation, receptionTask.getLocations().get(0)); + // locations of the same warehouse + Assert.assertEquals(onlyElement.getLocation().getWarehouse(), receptionTask.getLocations().get(1).getWarehouse()); + Assert.assertEquals(onlyElement.getLocation().getWarehouse(), receptionTask.getLocations().get(2).getWarehouse()); + Assert.assertEquals(onlyElement.getLocation().getWarehouse(), receptionTask.getLocations().get(3).getWarehouse()); + + // locations in another warehouse last + Assert.assertNotEquals(onlyElement.getLocation().getWarehouse(), receptionTask.getLocations().get(4).getWarehouse()); + Assert.assertNotEquals(onlyElement.getLocation().getWarehouse(), receptionTask.getLocations().get(5).getWarehouse()); + Assert.assertNotEquals(onlyElement.getLocation().getWarehouse(), receptionTask.getLocations().get(6).getWarehouse()); + Assert.assertNotEquals(onlyElement.getLocation().getWarehouse(), receptionTask.getLocations().get(7).getWarehouse()); + Assert.assertNotEquals(onlyElement.getLocation().getWarehouse(), receptionTask.getLocations().get(8).getWarehouse()); + Assert.assertNotEquals(onlyElement.getLocation().getWarehouse(), receptionTask.getLocations().get(9).getWarehouse()); + Assert.assertNotEquals(onlyElement.getLocation().getWarehouse(), receptionTask.getLocations().get(10).getWarehouse()); + for (Location location : receptionTask.getLocations()) { if (log.isDebugEnabled()) { @@ -147,6 +162,12 @@ "we should never suggest someone to store something in a full location", location.isFullLocation()); + Assert.assertEquals( + "we shoud only suggest locations in the same building", + building, + location.getWarehouse().getBuilding() + ); + } }