Skip to content

Commit

Permalink
error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
cbellone committed Feb 24, 2015
1 parent 7776894 commit 7fff80a
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 18 deletions.
5 changes: 5 additions & 0 deletions src/main/java/alfio/controller/api/EventApiController.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -47,6 +48,7 @@

@RestController
@RequestMapping("/admin/api")
@Log4j2
public class EventApiController {

private static final String OK = "OK";
Expand All @@ -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();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
Expand All @@ -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() {
Expand All @@ -69,6 +72,6 @@ public static TicketCategoryModification fromTicketCategory(TicketCategory tc, Z
DateTimeModification.fromZonedDateTime(tc.getExpiration(zoneId)),
tc.getDescription(),
tc.getPrice(),
tc.isAccessRestricted());
tc.isAccessRestricted(), "");
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<div class="col-sm-12">
<div class="row">
<div class="col-sm-12 col-md-4">
<label for="{{$index}}-name">Name</label>
<input type="text" data-ng-model="ticketCategory.name" name="{{$index}}-name" id="{{$index}}-name" class="form-control" required />
<label for="{{buildPrefix($index, 'name')}}">Name</label>
<input type="text" data-ng-model="ticketCategory.name" name="{{buildPrefix($index, 'name')}}" id="{{buildPrefix($index, 'name')}}" class="form-control" required />
<field-error data-form-obj="ticketCategory" data-field-obj="ticketCategory.name" data-show-existing-errors="showExistingErrors"></field-error>
</div>

Expand All @@ -11,43 +11,43 @@
<div class="form-group">
<div class="radio-inline">
<label>
<input type="radio" name="{{$index}}-tokenGenerationRequested" data-ng-model="ticketCategory.tokenGenerationRequested" data-ng-value="false" required="">
<input type="radio" name="{{buildPrefix($index, 'tokenGenerationRequested')}}" data-ng-model="ticketCategory.tokenGenerationRequested" data-ng-value="false" required="">
Public
</label>
</div>
<div class="radio-inline">
<label>
<input type="radio" name="{{$index}}-tokenGenerationRequested" data-ng-model="ticketCategory.tokenGenerationRequested" data-ng-value="true" required="">
<input type="radio" name="{{buildPrefix($index, 'tokenGenerationRequested')}}" data-ng-model="ticketCategory.tokenGenerationRequested" data-ng-value="true" required="">
Restricted
</label>
</div>
</div>
</div>

<div class="col-sm-12 col-md-5">
<label for="{{$index}}-maxTickets">Max Tickets</label>
<input type="number" data-ng-model="ticketCategory.maxTickets" name="{{$index}}-maxTickets" id="{{$index}}-maxTickets" class="form-control" required />
<label for="{{buildPrefix($index, 'maxTickets')}}">Max Tickets</label>
<input type="number" data-ng-model="ticketCategory.maxTickets" name="{{buildPrefix($index, 'maxTickets')}}" id="{{buildPrefix($index, 'maxTickets')}}" class="form-control" required />
<field-error data-form-obj="ticketCategory" data-field-obj="ticketCategory.maxTickets" data-show-existing-errors="showExistingErrors"></field-error>
</div>

</div>
<div class="row">

<div class="col-sm-12 col-md-4">
<label for="{{$index}}-date">Validity range</label>
<input type="text" data-date-range data-start-model="ticketCategory.inception" data-end-model="ticketCategory.expiration" data-start-date="ticketCategory.notBefore" data-ng-model="ticketCategory.dateString" name="{{$index}}-date" id="{{$index}}-date" class="form-control" required />
<label for="{{buildPrefix($index, 'dateString')}}">Validity range</label>
<input type="text" data-date-range data-start-model="ticketCategory.inception" data-end-model="ticketCategory.expiration" data-start-date="ticketCategory.notBefore" data-ng-model="ticketCategory.dateString" name="{{buildPrefix($index, 'dateString')}}" id="{{buildPrefix($index, 'dateString')}}" class="form-control" required />
<field-error data-form-obj="ticketCategory" data-field-obj="ticketCategory.dateString" data-show-existing-errors="showExistingErrors"></field-error>
</div>

<div class="col-sm-12 col-md-3" data-ng-if="!event.freeOfCharge">
<label for="{{$index}}-price">Price <span data-ng-if="ticketCategory.price">({{calcCategoryPricePercent(ticketCategory, event, editMode)}}%)</span></label>
<input type="number" data-ng-model="ticketCategory.price" name="{{$index}}-price" id="{{$index}}-price" class="form-control" required />
<label for="{{buildPrefix($index, 'price')}}">Price <span data-ng-if="ticketCategory.price">({{calcCategoryPricePercent(ticketCategory, event, editMode)}}%)</span></label>
<input type="number" data-ng-model="ticketCategory.price" name="{{buildPrefix($index, 'price')}}" id="{{buildPrefix($index, 'price')}}" class="form-control" required />
<field-error data-form-obj="ticketCategory" data-field-obj="ticketCategory.price" data-show-existing-errors="showExistingErrors"></field-error>
</div>

<div class="col-sm-12 col-md-5">
<label for="{{$index}}-description">Description</label>
<textarea data-ng-model="ticketCategory.description" name="{{$index}}-description" id="{{$index}}-description" class="form-control" placeholder="Description of {{ticketCategory.name}} category"></textarea>
<label for="{{buildPrefix($index, 'description')}}">Description</label>
<textarea data-ng-model="ticketCategory.description" name="{{buildPrefix($index, 'description')}}" id="{{buildPrefix($index, 'description')}}" class="form-control" placeholder="Description of {{ticketCategory.name}} category"></textarea>
</div>

</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
};
});

Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 7fff80a

Please sign in to comment.