r102 - in trunk: magalie-persistence/src/main/java/com/franciaflex/magalie/persistence magalie-persistence/src/main/java/com/franciaflex/magalie/persistence/entity magalie-services/src/main/java/com/franciaflex/magalie/services/service
Author: bleny Date: 2013-04-17 11:46:14 +0200 (Wed, 17 Apr 2013) New Revision: 102 Url: http://forge.codelutin.com/projects/franciaflex-magalie/repository/revisions... Log: on confirmation, when adding a storage movement set destination location Modified: trunk/magalie-persistence/src/main/java/com/franciaflex/magalie/persistence/StorageMovements.java trunk/magalie-persistence/src/main/java/com/franciaflex/magalie/persistence/entity/StorageMovementOrder.java trunk/magalie-services/src/main/java/com/franciaflex/magalie/services/service/ArticleStorageService.java Modified: trunk/magalie-persistence/src/main/java/com/franciaflex/magalie/persistence/StorageMovements.java =================================================================== --- trunk/magalie-persistence/src/main/java/com/franciaflex/magalie/persistence/StorageMovements.java 2013-04-17 09:37:50 UTC (rev 101) +++ trunk/magalie-persistence/src/main/java/com/franciaflex/magalie/persistence/StorageMovements.java 2013-04-17 09:46:14 UTC (rev 102) @@ -25,6 +25,14 @@ } } + protected static class GetDestinationFunction implements Function<StorageMovement, Location> { + + @Override + public Location apply(StorageMovement storageMovement) { + return storageMovement.getDestinationLocation(); + } + } + protected static class StorageMovementIsConfirmedPredicate implements Predicate<StorageMovement> { @Override @@ -41,6 +49,10 @@ return new GetOriginFunction(); } + public static Function<StorageMovement, Location> getDestinationFunction() { + return new GetDestinationFunction(); + } + public static Predicate<StorageMovement> storageMovementIsConfirmed() { return new StorageMovementIsConfirmedPredicate(); } Modified: trunk/magalie-persistence/src/main/java/com/franciaflex/magalie/persistence/entity/StorageMovementOrder.java =================================================================== --- trunk/magalie-persistence/src/main/java/com/franciaflex/magalie/persistence/entity/StorageMovementOrder.java 2013-04-17 09:37:50 UTC (rev 101) +++ trunk/magalie-persistence/src/main/java/com/franciaflex/magalie/persistence/entity/StorageMovementOrder.java 2013-04-17 09:46:14 UTC (rev 102) @@ -127,4 +127,20 @@ public String toString() { return ToStringBuilder.reflectionToString(this); } + + protected Set<Location> getDestinationLocations() { + Set<Location> locations = + Sets.newHashSet( + Iterables.transform( + getStorageMovements(), + StorageMovements.getDestinationFunction() + ) + ); + return locations; + } + + public Location getDestinationLocation() { + Location onlyElement = Iterables.getOnlyElement(getDestinationLocations()); + return onlyElement; + } } 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-04-17 09:37:50 UTC (rev 101) +++ trunk/magalie-services/src/main/java/com/franciaflex/magalie/services/service/ArticleStorageService.java 2013-04-17 09:46:14 UTC (rev 102) @@ -306,21 +306,24 @@ public void confirmStorageMovement(StorageMovementConfirmation confirmation, MagalieUser magalieUser) { - String storageMovementOrderId = confirmation.getStorageMovementOrderId(); + MagaliePersistenceContext persistenceContext = serviceContext.getPersistenceContext(); StorageMovementOrderDao storageMovementOrderDao = - serviceContext.getPersistenceContext().getStorageMovementOrderDao(); + persistenceContext.getStorageMovementOrderDao(); - LocationDao locationDao = serviceContext.getPersistenceContext().getLocationDao(); + LocationDao locationDao = persistenceContext.getLocationDao(); StorageMovementOrder storageMovementOrder = - storageMovementOrderDao.findById(storageMovementOrderId); + storageMovementOrderDao.findById( + confirmation.getStorageMovementOrderId()); Date confirmDate = serviceContext.getNow(); LocationErrorsService locationErrorsService = serviceContext.newService(LocationErrorsService.class); + Location destinationLocation = storageMovementOrder.getDestinationLocation(); + for (Map.Entry<String, Double> locationIdToActualQuantity : confirmation.getLocationsIdsToActualQuantities().entrySet()) { String locationId = locationIdToActualQuantity.getKey(); @@ -339,7 +342,7 @@ storageMovement.setOriginLocation(originLocation); - // TODO brendan 28/03/13 what about destination location + storageMovement.setDestinationLocation(destinationLocation); storageMovement.setMagalieUser(magalieUser); @@ -367,7 +370,7 @@ storageMovementOrderDao.merge(storageMovementOrder); - serviceContext.getPersistenceContext().commit(); + persistenceContext.commit(); } }
participants (1)
-
bleny@users.forge.codelutin.com