r351 - 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/js
Author: bleny Date: 2013-07-31 17:31:58 +0200 (Wed, 31 Jul 2013) New Revision: 351 Url: http://forge.codelutin.com/projects/franciaflex-magalie/repository/revisions... Log: fixes #2995 report error if user scan a location known as full Modified: 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 trunk/magalie-web/src/main/java/com/franciaflex/magalie/web/action/LocationJsonAction.java trunk/magalie-web/src/main/webapp/js/receive-article-input.js 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-31 14:11:50 UTC (rev 350) +++ trunk/magalie-services/src/main/java/com/franciaflex/magalie/services/service/ReceptionService.java 2013-07-31 15:31:58 UTC (rev 351) @@ -26,6 +26,7 @@ import com.franciaflex.magalie.persistence.JpaMagaliePersistenceContext; import com.franciaflex.magalie.persistence.Locations; import com.franciaflex.magalie.persistence.StoredArticles; +import com.franciaflex.magalie.persistence.dao.ArticleJpaDao; import com.franciaflex.magalie.persistence.dao.LocationDao; import com.franciaflex.magalie.persistence.dao.LocationJpaDao; import com.franciaflex.magalie.persistence.dao.PreparedArticleReceptionJpaDao; @@ -403,4 +404,32 @@ } + public Location getLocationToStoreSomething(Building building, MagalieUser magalieUser, String locationBarcode, String articleId) throws InvalidMagalieBarcodeException { + + MagalieBarcodeService magalieBarcodeService = + serviceContext.newService(MagalieBarcodeService.class); + + Location location = magalieBarcodeService.getLocation(locationBarcode, building); + + if (location.isFullLocation()) { + + if (log.isInfoEnabled()) { + log.info(magalieUser + " scanned barcode " + locationBarcode + " for reception but location " + location + " is full, reporting error"); + } + + LocationErrorsService locationErrorsService = + serviceContext.newService(LocationErrorsService.class); + + ArticleJpaDao articleDao = serviceContext.getPersistenceContext().getArticleDao(); + + Article article = articleDao.findById(articleId); + + locationErrorsService.reportError(location, article, magalieUser); + + } + + return location; + + } + } 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-31 14:11:50 UTC (rev 350) +++ trunk/magalie-services/src/test/java/com/franciaflex/magalie/services/service/ReceptionServiceTest.java 2013-07-31 15:31:58 UTC (rev 351) @@ -24,6 +24,7 @@ */ import com.franciaflex.magalie.persistence.Locations; +import com.franciaflex.magalie.persistence.dao.LocationErrorJpaDao; import com.franciaflex.magalie.persistence.dao.ReceivedPreparedArticleReceptionJpaDao; import com.franciaflex.magalie.persistence.dao.StorageMovementJpaDao; import com.franciaflex.magalie.persistence.entity.Article; @@ -354,4 +355,19 @@ } + @Test + public void testGetLocationToStoreSomethingReportErrorIfFullLocation() throws InvalidMagalieBarcodeException { + + Location fullLocation = fixture("locationFull1"); + + service.getLocationToStoreSomething(building, magalieUser, fullLocation.getBarcode(), article.getId()); + + EntityManager entityManager = getJpaEntityManagerRule().newEntityManager(); + + LocationErrorJpaDao locationErrorJpaDao = new LocationErrorJpaDao(entityManager); + + Assert.assertFalse(locationErrorJpaDao.findAll().isEmpty()); + + } + } 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-07-31 14:11:50 UTC (rev 350) +++ trunk/magalie-web/src/main/java/com/franciaflex/magalie/web/action/LocationJsonAction.java 2013-07-31 15:31:58 UTC (rev 351) @@ -25,10 +25,13 @@ 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.MagalieBarcodeService; +import com.franciaflex.magalie.services.service.ReceptionService; import com.franciaflex.magalie.web.MagalieActionSupport; import com.franciaflex.magalie.web.MagalieSession; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.apache.struts2.convention.annotation.Result; import org.apache.struts2.convention.annotation.Results; @@ -37,19 +40,23 @@ }) public class LocationJsonAction extends MagalieActionSupport{ - protected MagalieBarcodeService service; + private static final Log log = LogFactory.getLog(LocationJsonAction.class); + protected ReceptionService service; + protected Location location; protected String locationBarcode; protected MagalieSession session; + protected String articleId; + public void setSession(MagalieSession session) { this.session = session; } - public void setService(MagalieBarcodeService service) { + public void setService(ReceptionService service) { this.service = service; } @@ -57,12 +64,22 @@ this.locationBarcode = locationBarcode; } + public void setArticleId(String articleId) { + this.articleId = articleId; + } + @Override public String execute() throws InvalidMagalieBarcodeException { + MagalieUser magalieUser = session.getMagalieUser(); + + if (log.isInfoEnabled()) { + log.info(magalieUser + " scanned " + locationBarcode + " to store something"); + } + Building building = session.getBuilding(); - location = service.getLocation(locationBarcode, building); + location = service.getLocationToStoreSomething(building, magalieUser, locationBarcode, articleId); return SUCCESS; Modified: trunk/magalie-web/src/main/webapp/js/receive-article-input.js =================================================================== --- trunk/magalie-web/src/main/webapp/js/receive-article-input.js 2013-07-31 14:11:50 UTC (rev 350) +++ trunk/magalie-web/src/main/webapp/js/receive-article-input.js 2013-07-31 15:31:58 UTC (rev 351) @@ -55,7 +55,10 @@ $.ajax({ dataType: "json", url: locationJsonUrl, - data: { locationBarcode: barcode }, + data: { + locationBarcode: barcode, + articleId: model.storedArticle.article.id + }, async: false, success: function(data) { location = data.location; @@ -66,6 +69,9 @@ if (location == null) { throw new ValidationError(barcode + " n'est pas le code barre d'un emplacement valide"); } + if (location.fullLocation) { + throw new ValidationError("Emplt " + barcode + " en erreur - choisir un autre"); + } return location; };
participants (1)
-
bleny@users.forge.codelutin.com