@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));
   }
 }
Пример #2
0
  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);
  }