r301 - in trunk: magalie-persistence/src/main/java/com/franciaflex/magalie/persistence magalie-persistence/src/main/java/com/franciaflex/magalie/persistence/dao magalie-services/src/main/java/com/franciaflex/magalie/services/service magalie-services/src/test/java/com/franciaflex/magalie/services/service
Author: bleny Date: 2013-07-11 20:41:26 +0200 (Thu, 11 Jul 2013) New Revision: 301 Url: http://forge.codelutin.com/projects/franciaflex-magalie/repository/revisions... Log: fixes some locations are removed even if the article is not the same Modified: trunk/magalie-persistence/src/main/java/com/franciaflex/magalie/persistence/Locations.java trunk/magalie-persistence/src/main/java/com/franciaflex/magalie/persistence/dao/LocationErrorDao.java trunk/magalie-persistence/src/main/java/com/franciaflex/magalie/persistence/dao/LocationErrorJpaDao.java trunk/magalie-services/src/main/java/com/franciaflex/magalie/services/service/ArticleStorageService.java trunk/magalie-services/src/main/java/com/franciaflex/magalie/services/service/LocationErrorsService.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/Locations.java =================================================================== --- trunk/magalie-persistence/src/main/java/com/franciaflex/magalie/persistence/Locations.java 2013-07-11 10:56:35 UTC (rev 300) +++ trunk/magalie-persistence/src/main/java/com/franciaflex/magalie/persistence/Locations.java 2013-07-11 18:41:26 UTC (rev 301) @@ -95,10 +95,6 @@ return new LocationRequiringDriverLicenseFirstComparator(); } - public static Predicate<Location> locationIsNotReportedInError(Collection<Location> allLocationsInError) { - return Predicates.not(Predicates.in(allLocationsInError)); - } - public static String codeForWarehouseWithoutLocations() { return " SANS"; } Modified: trunk/magalie-persistence/src/main/java/com/franciaflex/magalie/persistence/dao/LocationErrorDao.java =================================================================== --- trunk/magalie-persistence/src/main/java/com/franciaflex/magalie/persistence/dao/LocationErrorDao.java 2013-07-11 10:56:35 UTC (rev 300) +++ trunk/magalie-persistence/src/main/java/com/franciaflex/magalie/persistence/dao/LocationErrorDao.java 2013-07-11 18:41:26 UTC (rev 301) @@ -23,6 +23,7 @@ * #L% */ +import com.franciaflex.magalie.persistence.entity.Article; import com.franciaflex.magalie.persistence.entity.Location; import com.franciaflex.magalie.persistence.entity.LocationError; @@ -33,7 +34,8 @@ LocationError findByLocation(Location location); - List<Location> findAllLocationsInError(); + List<Location> findAllLocationsInError(Article article); List<LocationError> findAll(); + } Modified: trunk/magalie-persistence/src/main/java/com/franciaflex/magalie/persistence/dao/LocationErrorJpaDao.java =================================================================== --- trunk/magalie-persistence/src/main/java/com/franciaflex/magalie/persistence/dao/LocationErrorJpaDao.java 2013-07-11 10:56:35 UTC (rev 300) +++ trunk/magalie-persistence/src/main/java/com/franciaflex/magalie/persistence/dao/LocationErrorJpaDao.java 2013-07-11 18:41:26 UTC (rev 301) @@ -23,12 +23,12 @@ * #L% */ +import com.franciaflex.magalie.persistence.entity.Article; import com.franciaflex.magalie.persistence.entity.Location; import com.franciaflex.magalie.persistence.entity.LocationError; import javax.persistence.EntityManager; import javax.persistence.Query; -import javax.persistence.TypedQuery; import java.util.List; public class LocationErrorJpaDao extends AbstractLocationErrorJpaDao { @@ -38,22 +38,16 @@ } @Override - public LocationError findByLocation(Location location) { - TypedQuery<LocationError> query = createQuery("from LocationError se where se.location = :location"); - query.setParameter("location", location); - return findUniqueOrNull(query); - } - - @Override - public List<Location> findAllLocationsInError() { - Query query = entityManager.createQuery("select se.location from LocationError se"); + public List<Location> findAllLocationsInError(Article article) { + Query query = entityManager.createQuery("select le.location from LocationError le where le.article = :article "); + query.setParameter("article", article); List<Location> allLocationsInError = query.getResultList(); return allLocationsInError; } @Override public List<LocationError> findAll() { - Query query = entityManager.createQuery("from LocationError se order by se.reportDate"); + Query query = entityManager.createQuery("from LocationError le order by le.reportDate"); List<LocationError> all = query.getResultList(); return all; } Modified: trunk/magalie-services/src/main/java/com/franciaflex/magalie/services/service/ArticleStorageService.java =================================================================== --- trunk/magalie-services/src/main/java/com/franciaflex/magalie/services/service/ArticleStorageService.java 2013-07-11 10:56:35 UTC (rev 300) +++ trunk/magalie-services/src/main/java/com/franciaflex/magalie/services/service/ArticleStorageService.java 2013-07-11 18:41:26 UTC (rev 301) @@ -356,9 +356,7 @@ LocationErrorsService locationErrorsService = serviceContext.newService(LocationErrorsService.class); - storedArticles = Iterables.filter( - storedArticles, - locationErrorsService.getArticleNotStoredInLocationReportedInErrorPredicate()); + storedArticles = locationErrorsService.filterLocationInError(storedArticles); return storedArticles; Modified: trunk/magalie-services/src/main/java/com/franciaflex/magalie/services/service/LocationErrorsService.java =================================================================== --- trunk/magalie-services/src/main/java/com/franciaflex/magalie/services/service/LocationErrorsService.java 2013-07-11 10:56:35 UTC (rev 300) +++ trunk/magalie-services/src/main/java/com/franciaflex/magalie/services/service/LocationErrorsService.java 2013-07-11 18:41:26 UTC (rev 301) @@ -24,8 +24,6 @@ */ import com.franciaflex.magalie.persistence.JpaMagaliePersistenceContext; -import com.franciaflex.magalie.persistence.Locations; -import com.franciaflex.magalie.persistence.StoredArticles; import com.franciaflex.magalie.persistence.dao.LocationErrorJpaDao; import com.franciaflex.magalie.persistence.dao.StoredArticleJpaDao; import com.franciaflex.magalie.persistence.entity.Article; @@ -38,6 +36,8 @@ import com.google.common.base.Preconditions; import com.google.common.base.Predicate; import com.google.common.base.Predicates; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.Lists; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -122,20 +122,54 @@ } - public Predicate<Location> getLocationNotReportedInErrorPredicate() { + protected Predicate<Location> getLocationNotReportedInErrorPredicate(Article article) { LocationErrorJpaDao locationErrorDao = serviceContext.getPersistenceContext().getLocationErrorDao(); - List<Location> allLocationsInError = locationErrorDao.findAllLocationsInError(); + List<Location> allLocationsInErrorForArticle = + locationErrorDao.findAllLocationsInError(article); - return Locations.locationIsNotReportedInError(allLocationsInError); + return Predicates.not(Predicates.in(allLocationsInErrorForArticle)); } - public Predicate<StoredArticle> getArticleNotStoredInLocationReportedInErrorPredicate() { + protected Iterable<StoredArticle> filterLocationInError(Iterable<StoredArticle> storedArticles) { - return Predicates.compose(getLocationNotReportedInErrorPredicate(), StoredArticles.getLocationFunction()); + List<StoredArticle> result = Lists.newLinkedList(); + LocationErrorJpaDao locationErrorDao = + serviceContext.getPersistenceContext().getLocationErrorDao(); + + for (StoredArticle storedArticle : storedArticles) { + + ImmutableMap properties = + ImmutableMap.of( + LocationError.PROPERTY_ARTICLE, storedArticle.getArticle(), + LocationError.PROPERTY_LOCATION, storedArticle.getLocation() + ); + + LocationError locationError = locationErrorDao.findByProperties(properties); + + if (locationError == null) { + + if (log.isTraceEnabled()) { + log.trace("no location error reported for " + storedArticle); + } + + result.add(storedArticle); + + } else { + + if (log.isDebugEnabled()) { + log.debug("removing stored article " + storedArticle + " due to location error " + locationError); + } + + } + + } + + return result; + } } 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-11 10:56:35 UTC (rev 300) +++ trunk/magalie-services/src/main/java/com/franciaflex/magalie/services/service/ReceptionService.java 2013-07-11 18:41:26 UTC (rev 301) @@ -68,6 +68,9 @@ private static final Log log = LogFactory.getLog(ReceptionService.class); + /** disabled, for a warehouse with 1000+ locations, can lead to a page of 1Mo+, now the locations are loaded on demand */ + protected static final boolean INCLUDE_ALL_BUILDING_LOCATIONS_IN_RECEPTION_TASK = false; + protected MagalieServiceContext serviceContext; @Override @@ -195,7 +198,7 @@ ImmutableSet.of( Locations.isNotReceptionLocation(), Locations.isNotFullLocation(), - locationErrorsService.getLocationNotReportedInErrorPredicate() + locationErrorsService.getLocationNotReportedInErrorPredicate(article) ) ); @@ -244,7 +247,7 @@ locations.addAll(locationDao.findAllWithoutReception(warehouse)); // add all locations in the same building, other warehouses - if (false) { // disabled, for a warehouse with 1000+ locations, can lead to a page of 1Mo+, now the locations are loaded on demand + if (INCLUDE_ALL_BUILDING_LOCATIONS_IN_RECEPTION_TASK) { locations.addAll(locationDao.findAllWithoutReception(warehouse.getBuilding())); } 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-11 10:56:35 UTC (rev 300) +++ trunk/magalie-services/src/test/java/com/franciaflex/magalie/services/service/ReceptionServiceTest.java 2013-07-11 18:41:26 UTC (rev 301) @@ -144,14 +144,18 @@ Assert.assertEquals(receivedArticle.getLocation().getWarehouse(), Iterables.get(receptionTask.getLocations(), 3).getWarehouse()); // locations in another warehouse last - 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()); + if (service.INCLUDE_ALL_BUILDING_LOCATIONS_IN_RECEPTION_TASK) { + 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()) { if (log.isDebugEnabled()) {
participants (1)
-
bleny@users.forge.codelutin.com