r374 - 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 magalie-web/src/main/webapp/WEB-INF/content
Author: bleny Date: 2013-08-26 12:09:03 +0200 (Mon, 26 Aug 2013) New Revision: 374 Url: http://forge.codelutin.com/projects/franciaflex-magalie/repository/revisions... Log: fixes #2991 show already stored quantity Added: trunk/magalie-services/src/main/java/com/franciaflex/magalie/services/service/ReceptionLocation.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/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/LocationJsonAction.java trunk/magalie-web/src/main/webapp/WEB-INF/content/receive-article-input.jsp Added: trunk/magalie-services/src/main/java/com/franciaflex/magalie/services/service/ReceptionLocation.java =================================================================== --- trunk/magalie-services/src/main/java/com/franciaflex/magalie/services/service/ReceptionLocation.java (rev 0) +++ trunk/magalie-services/src/main/java/com/franciaflex/magalie/services/service/ReceptionLocation.java 2013-08-26 10:09:03 UTC (rev 374) @@ -0,0 +1,52 @@ +package com.franciaflex.magalie.services.service; + +import com.franciaflex.magalie.persistence.entity.Location; +import com.franciaflex.magalie.persistence.entity.Warehouse; + +public class ReceptionLocation { + + protected Location location; + + protected double alreadyStoredQuantity; + + public ReceptionLocation(Location location) { + this.location = location; + } + + public String getBarcode() { + return location.getBarcode(); + } + + public String getCode() { + return location.getCode(); + } + + public boolean isRequiredCraneMan() { + return location.isRequiredCraneMan(); + } + + public Warehouse getWarehouse() { + return location.getWarehouse(); + } + + public boolean isFullLocation() { + return location.isFullLocation(); + } + + public int getRequiredAccreditationLevel() { + return location.getRequiredAccreditationLevel(); + } + + public String getId() { + return location.getId(); + } + + public double getAlreadyStoredQuantity() { + return alreadyStoredQuantity; + } + + public void setAlreadyStoredQuantity(double alreadyStoredQuantity) { + this.alreadyStoredQuantity = alreadyStoredQuantity; + } + +} 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-08-21 13:59:15 UTC (rev 373) +++ trunk/magalie-services/src/main/java/com/franciaflex/magalie/services/service/ReceptionService.java 2013-08-26 10:09:03 UTC (rev 374) @@ -52,9 +52,11 @@ import com.google.common.base.Optional; import com.google.common.base.Predicate; import com.google.common.base.Predicates; +import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Iterables; import com.google.common.collect.Lists; +import com.google.common.collect.Maps; import com.google.common.collect.Ordering; import com.google.common.collect.Sets; import org.apache.commons.lang3.StringUtils; @@ -195,6 +197,10 @@ LocationErrorsService locationErrorsService = serviceContext.newService(LocationErrorsService.class); + // a predicate to 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 + Predicate<Location> isAcceptableForReception = Predicates.and( ImmutableSet.of( @@ -204,24 +210,39 @@ ) ); + ReceptionTask receptionTask = new ReceptionTask(storedArticle, quantity); + // first step, add fixed locations for this article first - Set<Location> preferredLocations = getPreferredLocations(warehouse, article); + Set<Location> fixedLocations = article.getFixedLocationsInBuilding(warehouse.getBuilding()); - Iterable<Location> acceptablePreferredLocations = Iterables.filter(preferredLocations, isAcceptableForReception); + Iterable<Location> acceptableFixedLocations = Iterables.filter(fixedLocations, isAcceptableForReception); - // second step, add extra locations + receptionTask.setFixedLocations(acceptableFixedLocations); + // second step, add locations with already stored quantities + + Set<StoredArticle> alreadyUsedLocations = getAlreadyUsedLocations(warehouse, article); + + Iterable<StoredArticle> acceptableAlreadyUsedLocations = + Iterables.filter( + alreadyUsedLocations, + Predicates.compose(isAcceptableForReception, StoredArticles.getLocationFunction())); + + receptionTask.setAlreadyUsedLocations(acceptableAlreadyUsedLocations); + + // third step, add extra locations + Set<Location> extraLocations = getExtraLocations(warehouse); Iterable<Location> acceptableExtraLocations = Iterables.filter(extraLocations, isAcceptableForReception); - ReceptionTask receptionTask = new ReceptionTask(storedArticle, quantity, acceptablePreferredLocations, acceptableExtraLocations); + receptionTask.setExtraLocations(acceptableExtraLocations); if (log.isDebugEnabled()) { log.debug("locations to receive articles for article " + article + " in warehouse " + warehouse + " are acceptable = " - + StringUtils.join(acceptablePreferredLocations, ", ") + + + StringUtils.join(acceptableAlreadyUsedLocations, ", ") + " extra = " + StringUtils.join(acceptableExtraLocations, ", ")); } @@ -243,27 +264,15 @@ // add all locations in the same warehouse locations.addAll(locationDao.findAllWithoutReception(warehouse, LIMIT_EXTRA_LOCATIONS_TO_50)); - // 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) { + protected Set<StoredArticle> getAlreadyUsedLocations(Warehouse warehouse, Article article) { - // first step, add fixed locations for this article first + // add locations where there is already quantities stored + // we will suggest locations with highest quantities first - Set<Location> locations = Sets.newLinkedHashSet(); - - Set<Location> fixedLocationsInBuilding = - article.getFixedLocationsInBuilding(warehouse.getBuilding()); - - locations.addAll(fixedLocationsInBuilding); - - // second step, add locations where there is already quantities stored - // we will suggest locations with highest quantities first ArticleStorageService articleStorageService = serviceContext.newService(ArticleStorageService.class); @@ -280,14 +289,8 @@ Iterables.addAll(sortedStoredArticles, storedArticles); - Iterables.addAll( - locations, - Iterables.transform( - sortedStoredArticles, - StoredArticles.getLocationFunction())); + return sortedStoredArticles; - return locations; - } public ReceptionTask getReceptionTaskForPreparedArticleReception(Building building, String barcode) throws PreparedArticleReceptionAlreadyStoredException, InvalidMagalieBarcodeException { @@ -404,8 +407,12 @@ } - public Location getLocationToStoreSomething(Building building, MagalieUser magalieUser, String locationBarcode, String articleId) throws InvalidMagalieBarcodeException { + public ReceptionLocation getReceptionLocation(Building building, MagalieUser magalieUser, String locationBarcode, String articleId) throws InvalidMagalieBarcodeException { + ArticleJpaDao articleDao = serviceContext.getPersistenceContext().getArticleDao(); + + Article article = articleDao.findById(articleId); + MagalieBarcodeService magalieBarcodeService = serviceContext.newService(MagalieBarcodeService.class); @@ -420,22 +427,40 @@ LocationErrorsService locationErrorsService = serviceContext.newService(LocationErrorsService.class); - ArticleJpaDao articleDao = serviceContext.getPersistenceContext().getArticleDao(); + locationErrorsService.reportError(location, article, magalieUser); - Article article = articleDao.findById(articleId); + } - locationErrorsService.reportError(location, article, magalieUser); + ReceptionLocation receptionLocation = new ReceptionLocation(location); + // on essaie de déterminer la quantité qui se trouve dans cet emplacement + + ArticleStorageService articleStorageService = + serviceContext.newService(ArticleStorageService.class); + + Iterable<StoredArticle> storedArticles = + articleStorageService.getStoredArticles(building, article); + + ImmutableMap<Location,StoredArticle> storedArticlesByLocation = + Maps.uniqueIndex(storedArticles, StoredArticles.getLocationFunction()); + + StoredArticle storedArticle = storedArticlesByLocation.get(location); + + if (storedArticle == null) { + receptionLocation.setAlreadyStoredQuantity(0.); + } else { + receptionLocation.setAlreadyStoredQuantity(storedArticle.getQuantity()); } - return location; + return receptionLocation; } /** * On cherche à savoir si pour un storedArticle donné, il y a encore des articles à recevoir pour le même fournisseur */ - public Optional<Supplier> isSupplierHaveOtherArticlesToReceive(Building building, String storedArticleId) { + public Optional<Supplier> isSupplierHaveOtherArticlesToReceive(Building building, String + storedArticleId) { JpaMagaliePersistenceContext persistenceContext = serviceContext.getPersistenceContext(); 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-08-21 13:59:15 UTC (rev 373) +++ trunk/magalie-services/src/main/java/com/franciaflex/magalie/services/service/ReceptionTask.java 2013-08-26 10:09:03 UTC (rev 374) @@ -23,9 +23,13 @@ * #L% */ +import com.franciaflex.magalie.persistence.StoredArticles; import com.franciaflex.magalie.persistence.entity.Location; import com.franciaflex.magalie.persistence.entity.StoredArticle; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableSet; import com.google.common.collect.Iterables; +import com.google.common.collect.Maps; import com.google.common.collect.Sets; import org.apache.commons.lang3.builder.ReflectionToStringBuilder; @@ -33,36 +37,46 @@ public class ReceptionTask { - protected boolean userMustChooseExtraLocation; - protected StoredArticle storedArticle; protected double quantity; - protected Iterable<Location> preferredLocations; + protected Iterable<Location> fixedLocations; + protected Iterable<StoredArticle> alreadyUsedLocations; + protected Iterable<Location> extraLocations; - protected Set<Location> locations; - - public ReceptionTask(StoredArticle storedArticle, double quantity, Iterable<Location> preferredLocations, Iterable<Location> extraLocations) { + public ReceptionTask(StoredArticle storedArticle, double quantity) { this.storedArticle = storedArticle; this.quantity = quantity; - this.preferredLocations = preferredLocations; - this.extraLocations = extraLocations; } public StoredArticle getStoredArticle() { return storedArticle; } - public Set<Location> getLocations() { - if (locations == null) { - locations = Sets.newLinkedHashSet(); - Iterables.addAll(locations, preferredLocations); - Iterables.addAll(locations, extraLocations); + public Set<ReceptionLocation> getLocations() { + ImmutableMap<Location, StoredArticle> locationToStoredArticle = + Maps.uniqueIndex(alreadyUsedLocations, StoredArticles.getLocationFunction()); + Set<ReceptionLocation> receptionLocations = Sets.newLinkedHashSet(); + ImmutableSet<Location> allLocations = + ImmutableSet.<Location> builder() + .addAll(fixedLocations) + .addAll(Iterables.transform(alreadyUsedLocations, StoredArticles.getLocationFunction())) + .addAll(extraLocations) + .build(); + for (Location location : allLocations) { + ReceptionLocation receptionLocation = new ReceptionLocation(location); + StoredArticle storedArticleInLocation = locationToStoredArticle.get(location); + if (storedArticleInLocation == null) { + receptionLocation.setAlreadyStoredQuantity(0.); + } else { + receptionLocation.setAlreadyStoredQuantity(storedArticleInLocation.getQuantity()); + } + receptionLocations.add(receptionLocation); } - return locations; + return receptionLocations; } public double getQuantity() { @@ -70,9 +84,21 @@ } public boolean isUserMustChooseExtraLocation() { - return Iterables.isEmpty(preferredLocations); + return Iterables.isEmpty(fixedLocations) && Iterables.isEmpty(alreadyUsedLocations); } + public void setFixedLocations(Iterable<Location> fixedLocations) { + this.fixedLocations = fixedLocations; + } + + public void setAlreadyUsedLocations(Iterable<StoredArticle> alreadyUsedLocations) { + this.alreadyUsedLocations = alreadyUsedLocations; + } + + public void setExtraLocations(Iterable<Location> extraLocations) { + this.extraLocations = extraLocations; + } + @Override public String toString() { return ReflectionToStringBuilder.toString(this); 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-08-21 13:59:15 UTC (rev 373) +++ trunk/magalie-services/src/test/java/com/franciaflex/magalie/services/service/ReceptionServiceTest.java 2013-08-26 10:09:03 UTC (rev 374) @@ -363,7 +363,7 @@ Location fullLocation = fixture("locationFull1"); - service.getLocationToStoreSomething(building, magalieUser, fullLocation.getBarcode(), article.getId()); + service.getReceptionLocation(building, magalieUser, fullLocation.getBarcode(), article.getId()); EntityManager entityManager = getJpaEntityManagerRule().newEntityManager(); Modified: trunk/magalie-web/src/main/java/com/franciaflex/magalie/web/action/LocationJsonAction.java =================================================================== --- trunk/magalie-web/src/main/java/com/franciaflex/magalie/web/action/LocationJsonAction.java 2013-08-21 13:59:15 UTC (rev 373) +++ trunk/magalie-web/src/main/java/com/franciaflex/magalie/web/action/LocationJsonAction.java 2013-08-26 10:09:03 UTC (rev 374) @@ -24,9 +24,9 @@ */ import com.franciaflex.magalie.persistence.entity.Building; -import com.franciaflex.magalie.persistence.entity.Location; import com.franciaflex.magalie.persistence.entity.MagalieUser; import com.franciaflex.magalie.services.exception.InvalidMagalieBarcodeException; +import com.franciaflex.magalie.services.service.ReceptionLocation; import com.franciaflex.magalie.services.service.ReceptionService; import com.franciaflex.magalie.web.MagalieActionSupport; import com.franciaflex.magalie.web.MagalieSession; @@ -44,14 +44,14 @@ protected ReceptionService service; - protected Location location; - protected String locationBarcode; protected MagalieSession session; protected String articleId; + protected ReceptionLocation receptionLocation; + public void setSession(MagalieSession session) { this.session = session; } @@ -79,14 +79,14 @@ Building building = session.getBuilding(); - location = service.getLocationToStoreSomething(building, magalieUser, locationBarcode, articleId); + receptionLocation = service.getReceptionLocation(building, magalieUser, locationBarcode, articleId); return SUCCESS; } - public Location getLocation() { - return location; + public ReceptionLocation getReceptionLocation() { + return receptionLocation; } } Modified: trunk/magalie-web/src/main/webapp/WEB-INF/content/receive-article-input.jsp =================================================================== --- trunk/magalie-web/src/main/webapp/WEB-INF/content/receive-article-input.jsp 2013-08-21 13:59:15 UTC (rev 373) +++ trunk/magalie-web/src/main/webapp/WEB-INF/content/receive-article-input.jsp 2013-08-26 10:09:03 UTC (rev 374) @@ -66,6 +66,6 @@ <div> <span data="warehouse.code"></span> <span data="code"></span> - <span data="stored">0</span> <s:property value="receptionTask.storedArticle.article.unit" /> + <span data="stored">0</span> / <span data="alreadyStoredQuantity"></span> <s:property value="receptionTask.storedArticle.article.unit" /> </div> </div>
participants (1)
-
bleny@users.forge.codelutin.com