@Transactional @Override public CommandProcessingResult createEventPricing(JsonCommand command) { try { this.context.authenticatedUser(); this.apiJsonDeserializer.validateForCreate(command.json()); Long eventId = command.longValueOfParameterNamed("eventId"); EventMaster eventMaster = this.eventMasterRepository.findOne(eventId); final EventPricing eventPricing = EventPricing.fromJson(command, eventMaster); List<EventPricingData> eventDetails = this.eventPricingReadPlatformService.retrieventPriceData(command.entityId()); for (EventPricingData eventDetail : eventDetails) { if (eventPricing.getFormatType().equalsIgnoreCase(eventDetail.getFormatType()) && eventPricing.getClientType() == eventDetail.getClientType() && eventPricing.getOptType().equalsIgnoreCase(eventDetail.getOptType())) { throw new DuplicatEventPrice(eventPricing.getFormatType()); } } this.eventPricingRepository.save(eventPricing); return new CommandProcessingResultBuilder() .withCommandId(command.commandId()) .withEntityId(eventPricing.getId()) .build(); } catch (DataIntegrityViolationException dve) { handleDataIntegrityIssues(command, dve); return new CommandProcessingResult(Long.valueOf(-1)); } }
public CommandProcessingResult updateEventPricing(JsonCommand command) { try { this.apiJsonDeserializer.validateForCreate(command.json()); EventPricing eventPrice = this.eventPricingRepository.findOne(command.entityId()); EventMaster eventMaster = eventPrice.getEventId(); EventPricing newEventPricing = EventPricing.fromJson(command, eventMaster); eventPrice = (EventPricing) UpdateCompareUtil.compare(eventPrice, newEventPricing); this.eventPricingRepository.save(eventPrice); return new CommandProcessingResultBuilder() .withEntityId(eventPrice.getId()) .withCommandId(command.commandId()) .build(); } catch (DataIntegrityViolationException dev) { return CommandProcessingResult.empty(); } }