public static EventOrder fromJson( JsonCommand command, EventMaster eventMaster, MediaDeviceData details, final Long cType, final Long eventId) { final Long clientId = command.longValueOfParameterNamed("cId"); // details.getClientId(); final LocalDate eventBookedDate = command.localDateValueOfParameterNamed("eventBookedDate"); Long clientType = command.longValueOfParameterNamed("categoryType"); // details.getClientTypeId(); if (clientType == null) { clientType = cType; } final String optType = command.stringValueOfParameterNamed("optType"); final String formatType = command.stringValueOfParameterNamed("formatType"); final Date eventValidtill = eventMaster.getEventValidity(); if (eventMaster.getEventPricings() == null || eventMaster.getEventPricings().isEmpty()) { throw new NoEventPriceFoundException(); } final Long eventPriceId = eventMaster.getEventPricings().get(0).getId(); Double bookedPrice = 0D; List<EventPricing> eventPricings = eventMaster.getEventPricings(); for (EventPricing eventPricing : eventPricings) { if (eventPricing.getClientType().longValue() == clientType.longValue() && eventPricing.getFormatType().equalsIgnoreCase(formatType) && eventPricing.getOptType().equalsIgnoreCase(optType)) { bookedPrice = eventPricing.getPrice(); } } if (bookedPrice == null) { throw new NoPricesFoundException(); } final int status = eventMaster.getStatus(); final String chargeCode = eventMaster.getChargeCode(); return new EventOrder( eventId, eventBookedDate, eventValidtill, eventPriceId, bookedPrice, clientId, status, chargeCode); }
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(); } }
@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)); } }
@Transactional @Override public CommandProcessingResult deleteEventPricing(JsonCommand command) { try { EventPricing eventPricing = this.eventPricingRepository.findOne(command.entityId()); eventPricing.setClientType(null); eventPricing.setOptType(null); eventPricing.setFormatType(null); eventPricing.setIsDeleted('y'); this.eventPricingRepository.save(eventPricing); return new CommandProcessingResultBuilder().withEntityId(eventPricing.getId()).build(); } catch (DataIntegrityViolationException dev) { return CommandProcessingResult.empty(); } }