From 7fff80ae2e30e5c7725fdc4d76c931396b71919f Mon Sep 17 00:00:00 2001 From: Celestino Bellone Date: Tue, 24 Feb 2015 23:51:35 +0100 Subject: [PATCH] error handling --- .../controller/api/EventApiController.java | 5 ++++ .../TicketCategoryModification.java | 7 ++++-- .../event/fragment/edit-category.html | 24 +++++++++---------- .../js/admin/directive/admin-directive.js | 9 +++++-- .../js/admin/ng-app/admin-application.js | 3 +-- 5 files changed, 30 insertions(+), 18 deletions(-) diff --git a/src/main/java/alfio/controller/api/EventApiController.java b/src/main/java/alfio/controller/api/EventApiController.java index dc354cb4bd..1b7984c8aa 100644 --- a/src/main/java/alfio/controller/api/EventApiController.java +++ b/src/main/java/alfio/controller/api/EventApiController.java @@ -27,6 +27,7 @@ import alfio.util.ValidationResult; import alfio.util.Validator; import com.opencsv.CSVReader; +import lombok.extern.log4j.Log4j2; import org.apache.commons.lang3.Validate; import org.apache.commons.lang3.tuple.Pair; import org.apache.commons.lang3.tuple.Triple; @@ -47,6 +48,7 @@ @RestController @RequestMapping("/admin/api") +@Log4j2 public class EventApiController { private static final String OK = "OK"; @@ -60,6 +62,9 @@ public EventApiController(EventManager eventManager) { @ExceptionHandler(Exception.class) @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR) public String unhandledException(Exception e) { + if(!IllegalArgumentException.class.isInstance(e)) { + log.warn("unhandled exception", e); + } return e.getMessage(); } diff --git a/src/main/java/alfio/model/modification/TicketCategoryModification.java b/src/main/java/alfio/model/modification/TicketCategoryModification.java index 98e3299783..b2f129113d 100644 --- a/src/main/java/alfio/model/modification/TicketCategoryModification.java +++ b/src/main/java/alfio/model/modification/TicketCategoryModification.java @@ -37,6 +37,7 @@ public class TicketCategoryModification { private final String description; private final BigDecimal price; private final boolean tokenGenerationRequested; + private final String dateString; @JsonCreator public TicketCategoryModification(@JsonProperty("id") Integer id, @@ -46,7 +47,8 @@ public TicketCategoryModification(@JsonProperty("id") Integer id, @JsonProperty("expiration") DateTimeModification expiration, @JsonProperty("description") String description, @JsonProperty("price") BigDecimal price, - @JsonProperty("tokenGenerationRequested") boolean tokenGenerationRequested) { + @JsonProperty("tokenGenerationRequested") boolean tokenGenerationRequested, + @JsonProperty("dateString") String dateString) { this.id = id; this.name = name; this.maxTickets = maxTickets; @@ -55,6 +57,7 @@ public TicketCategoryModification(@JsonProperty("id") Integer id, this.description = description; this.price = price; this.tokenGenerationRequested = tokenGenerationRequested; + this.dateString = dateString; } public int getPriceInCents() { @@ -69,6 +72,6 @@ public static TicketCategoryModification fromTicketCategory(TicketCategory tc, Z DateTimeModification.fromZonedDateTime(tc.getExpiration(zoneId)), tc.getDescription(), tc.getPrice(), - tc.isAccessRestricted()); + tc.isAccessRestricted(), ""); } } diff --git a/src/main/webapp/resources/angular-templates/admin/partials/event/fragment/edit-category.html b/src/main/webapp/resources/angular-templates/admin/partials/event/fragment/edit-category.html index 11f51a6221..59d5e895fa 100644 --- a/src/main/webapp/resources/angular-templates/admin/partials/event/fragment/edit-category.html +++ b/src/main/webapp/resources/angular-templates/admin/partials/event/fragment/edit-category.html @@ -1,8 +1,8 @@
- - + +
@@ -11,13 +11,13 @@
@@ -25,8 +25,8 @@
- - + +
@@ -34,20 +34,20 @@
- - + +
- - + +
- - + +
diff --git a/src/main/webapp/resources/js/admin/directive/admin-directive.js b/src/main/webapp/resources/js/admin/directive/admin-directive.js index 874fdf0f49..76fc64e6c5 100644 --- a/src/main/webapp/resources/js/admin/directive/admin-directive.js +++ b/src/main/webapp/resources/js/admin/directive/admin-directive.js @@ -306,7 +306,12 @@ directives.directive('editCategory', function() { return { restrict: 'E', - templateUrl: '/resources/angular-templates/admin/partials/event/fragment/edit-category.html' + templateUrl: '/resources/angular-templates/admin/partials/event/fragment/edit-category.html', + controller: function($scope) { + $scope.buildPrefix = function(index, name) { + return angular.isDefined(index) ? index + "-" + name : name; + } + } }; }); @@ -364,7 +369,7 @@ _.chain(element.find(':input')) .filter(function(e) { return prefixes.length > 0 && _.filter(prefixes, function(p) { - return angular.isDefined(formController[p][e.name]); + return angular.isDefined(formController[p]) && angular.isDefined(formController[p][e.name]); }).length > 0; }).forEach(function(el) { _.forEach(prefixes, function(prefix) { diff --git a/src/main/webapp/resources/js/admin/ng-app/admin-application.js b/src/main/webapp/resources/js/admin/ng-app/admin-application.js index d44e41dd2a..dae315c9af 100644 --- a/src/main/webapp/resources/js/admin/ng-app/admin-application.js +++ b/src/main/webapp/resources/js/admin/ng-app/admin-application.js @@ -462,7 +462,6 @@ if(result.data['errorCount'] == 0) { resolve(result); } else { - form.$setValidity(false); _.forEach(result.data.validationErrors, function(error) { var field = fieldsContainer[error.fieldName]; if(angular.isDefined(field)) { @@ -523,7 +522,7 @@ return; } EventService.saveTicketCategory(event, category).then(function(result) { - validationErrorHandler(result, form, form.ticketCategory).then(function() { + validationErrorHandler(result, form, form).then(function() { $scope.$close(true); }); }, errorHandler);