@Transactional
  @Override
  public CommandProcessingResult createEventOrder(JsonCommand command) {

    try {

      this.context.authenticatedUser();
      Long clientId = command.longValueOfParameterNamed("clientId");

      // Check Client Custome Validation
      this.eventValidationReadPlatformService.checkForCustomValidations(
          clientId, EventActionConstants.EVENT_EVENT_ORDER, command.json(), getUserId());
      EventOrder eventOrder = assembleEventOrderDetails(command, clientId);
      Configuration walletConfiguration =
          this.configurationRepository.findOneByName(
              ConfigurationConstants.CONFIG_PROPERTY_WALLET_ENABLE);
      boolean isBalanceAvailable =
          this.checkClientBalance(
              eventOrder.getBookedPrice(), clientId, walletConfiguration.isEnabled());
      if (!isBalanceAvailable) {
        throw new InsufficientAmountException("bookevent");
      }
      this.eventOrderRepository.save(eventOrder);

      List<OneTimeSaleData> oneTimeSaleDatas =
          eventOrderReadplatformServie.retrieveEventOrderData(eventOrder.getClientId());
      for (OneTimeSaleData oneTimeSaleData : oneTimeSaleDatas) {
        CommandProcessingResult commandProcessingResult =
            this.invoiceOneTimeSale.invoiceOneTimeSale(
                eventOrder.getClientId(), oneTimeSaleData, walletConfiguration.isEnabled());
        this.updateOneTimeSale(oneTimeSaleData);
        if (walletConfiguration.isEnabled()) {
          JournalVoucher journalVoucher =
              new JournalVoucher(
                  commandProcessingResult.resourceId(),
                  DateUtils.getDateOfTenant(),
                  "Event Sale",
                  null,
                  eventOrder.getBookedPrice(),
                  eventOrder.getClientId());
          this.journalvoucherRepository.save(journalVoucher);
        }
      }

      // Add New Action
      List<ActionDetaislData> actionDetaislDatas =
          this.actionDetailsReadPlatformService.retrieveActionDetails(
              EventActionConstants.EVENT_EVENT_ORDER);
      if (!actionDetaislDatas.isEmpty()) {
        this.actiondetailsWritePlatformService.AddNewActions(
            actionDetaislDatas, clientId, eventOrder.getId().toString(), null);
      }
      return new CommandProcessingResult(
          eventOrder.getEventOrderdetials().get(0).getMovieLink(), eventOrder.getClientId());

    } catch (DataIntegrityViolationException dve) {
      handleCodeDataIntegrityIssues(command, dve);
      return new CommandProcessingResult(Long.valueOf(-1));
    }
  }
Beispiel #2
0
  // rounding amount
  public String roundingDecimal() {

    final Configuration property =
        this.globalConfigurationRepository.findOneByName(
            ConfigurationConstants.CONFIG_PROPERTY_ROUNDING);

    if (property != null && property.isEnabled()) {

      return property.getValue();
    } else {
      return String.valueOf(2);
    }
  }
  private EventOrder assembleEventOrderDetails(JsonCommand command, Long clientId) {

    Configuration configuration =
        this.configurationRepository.findOneByName(
            ConfigurationConstants.CONFIR_PROPERTY_REGISTRATION_DEVICE);
    this.apiJsonDeserializer.validateForCreate(command.json(), configuration.isEnabled());
    final Long eventId = command.longValueOfParameterNamed("eventId");
    final String deviceId = command.stringValueOfParameterNamed("deviceId");
    Long clientType = Long.valueOf(0);

    if (configuration != null && configuration.isEnabled()) {
      MediaDeviceData deviceData = this.deviceReadPlatformService.retrieveDeviceDetails(deviceId);
      if (deviceData == null) {
        throw new NoMediaDeviceFoundException();
      }
      clientId = deviceData.getClientId();
      clientType = deviceData.getClientTypeId();

    } else if (clientId != null) {
      Client client = this.clientRepository.findOne(clientId);
      clientType = client.getCategoryType();
    }

    final String formatType = command.stringValueOfParameterNamed("formatType");
    final String optType = command.stringValueOfParameterNamed("optType");
    EventMaster eventMaster = this.eventMasterRepository.findOne(eventId);
    if (eventMaster == null) {
      throw new NoEventMasterFoundException();
    }
    List<EventDetails> eventDetails = eventMaster.getEventDetails();
    EventOrder eventOrder = EventOrder.fromJson(command, eventMaster, clientType);
    for (EventDetails detail : eventDetails) {
      EventDetails eventDetail = this.eventDetailsRepository.findOne(detail.getId());
      MediaAsset mediaAsset = this.mediaAssetRepository.findOne(eventDetail.getMediaId());
      List<MediaassetLocation> mediaassetLocations = mediaAsset.getMediaassetLocations();
      String movieLink = "";
      for (MediaassetLocation location : mediaassetLocations) {
        if (location.getFormatType().equalsIgnoreCase(formatType)) {
          movieLink = location.getLocation();
        }
      }
      EventOrderdetials eventOrderdetials =
          new EventOrderdetials(eventDetail, movieLink, formatType, optType);
      eventOrder.addEventOrderDetails(eventOrderdetials);
      if (movieLink.isEmpty()) {
        throw new NoMoviesFoundException();
      }
    }
    return eventOrder;
  }
  // @SuppressWarnings("unused")
  @Override
  public CommandProcessingResult selfRegistrationProcess(JsonCommand command) {

    try {

      context.authenticatedUser();
      Configuration deviceStatusConfiguration =
          configurationRepository.findOneByName(
              ConfigurationConstants.CONFIR_PROPERTY_REGISTRATION_DEVICE);

      commandFromApiJsonDeserializer.validateForCreate(
          command.json(), deviceStatusConfiguration.isEnabled());
      Long id = new Long(1);
      CommandProcessingResult resultClient = null;
      CommandProcessingResult resultSale = null;
      CommandProcessingResult resultOrder = null;
      String device = null;
      String dateFormat = "dd MMMM yyyy";
      String activationDate = new SimpleDateFormat(dateFormat).format(DateUtils.getDateOfTenant());

      String fullname = command.stringValueOfParameterNamed("fullname");
      String firstName = command.stringValueOfParameterNamed("firstname");
      String city = command.stringValueOfParameterNamed("city");
      String address = command.stringValueOfParameterNamed("address");
      Long phone = command.longValueOfParameterNamed("phone");
      Long homePhoneNumber = command.longValueOfParameterNamed("homePhoneNumber");
      String email = command.stringValueOfParameterNamed("email");
      String nationalId = command.stringValueOfParameterNamed("nationalId");
      String deviceId = command.stringValueOfParameterNamed("device");
      String deviceAgreementType = command.stringValueOfParameterNamed("deviceAgreementType");
      String password = command.stringValueOfParameterNamed("password");
      String isMailCheck = command.stringValueOfParameterNamed("isMailCheck");
      String passport = command.stringValueOfParameterNamed("passport");
      SelfCareTemporary temporary = null;

      if (isMailCheck == null || isMailCheck.isEmpty()) {
        temporary = selfCareTemporaryRepository.findOneByEmailId(email);

        if (temporary == null) {
          throw new SelfCareTemporaryEmailIdNotFoundException(email);

        } else if (temporary.getStatus().equalsIgnoreCase("ACTIVE")) {
          throw new ClientAlreadyCreatedException();

        } else if (temporary.getStatus().equalsIgnoreCase("INACTIVE")) {
          throw new SelfCareNotVerifiedException(email);
        }
      }

      //	if (temporary.getStatus().equalsIgnoreCase("PENDING")){

      String zipCode = command.stringValueOfParameterNamed("zipCode");
      // client creation
      AddressData addressData = this.addressReadPlatformService.retrieveAdressBy(city);
      CodeValue codeValue = this.codeValueRepository.findOneByCodeValue("Normal");
      JSONObject clientcreation = new JSONObject();
      clientcreation.put("officeId", new Long(1));
      clientcreation.put("clientCategory", codeValue.getId());
      clientcreation.put("firstname", firstName);
      clientcreation.put("lastname", fullname);
      clientcreation.put("phone", phone);
      clientcreation.put("homePhoneNumber", homePhoneNumber);
      clientcreation.put("entryType", "IND"); // new Long(1));
      clientcreation.put("addressNo", address);
      clientcreation.put("city", addressData.getCity());
      clientcreation.put("state", addressData.getState());
      clientcreation.put("country", addressData.getCountry());
      clientcreation.put("email", email);
      clientcreation.put("locale", "en");
      clientcreation.put("active", true);
      clientcreation.put("dateFormat", dateFormat);
      clientcreation.put("activationDate", activationDate);
      clientcreation.put("flag", false);
      clientcreation.put("zipCode", zipCode);
      clientcreation.put("device", deviceId);
      clientcreation.put("password", password);

      if (nationalId != null && !nationalId.equalsIgnoreCase("")) {
        clientcreation.put("externalId", nationalId);
      }

      final JsonElement element = fromJsonHelper.parse(clientcreation.toString());
      JsonCommand clientCommand =
          new JsonCommand(
              null,
              clientcreation.toString(),
              element,
              fromJsonHelper,
              null,
              null,
              null,
              null,
              null,
              null,
              null,
              null,
              null,
              null,
              null,
              null);
      resultClient = this.clientWritePlatformService.createClient(clientCommand);

      if (resultClient == null) {
        throw new PlatformDataIntegrityException(
            "error.msg.client.creation.failed", "Client Creation Failed", "Client Creation Failed");
      }

      if (passport != null && !passport.equalsIgnoreCase("")) {
        CodeValue passportcodeValue = this.codeValueRepository.findOneByCodeValue("Passport");
        JSONObject clientIdentifierJson = new JSONObject();
        clientIdentifierJson.put("documentTypeId", passportcodeValue.getId());
        clientIdentifierJson.put("documentKey", passport);
        final JsonElement idenfierJsonEement =
            fromJsonHelper.parse(clientIdentifierJson.toString());
        JsonCommand idenfierJsonCommand =
            new JsonCommand(
                null,
                clientIdentifierJson.toString(),
                idenfierJsonEement,
                fromJsonHelper,
                null,
                null,
                null,
                null,
                null,
                null,
                null,
                null,
                null,
                null,
                null,
                null);
        this.clientIdentifierWritePlatformService.addClientIdentifier(
            resultClient.getClientId(), idenfierJsonCommand);
      }

      if (temporary != null) {
        temporary.setStatus("ACTIVE");
        this.selfCareTemporaryRepository.saveAndFlush(temporary);
      }

      // book device
      if (deviceStatusConfiguration != null) {

        if (deviceStatusConfiguration.isEnabled()) {

          JSONObject bookDevice = new JSONObject();
          /*deviceStatusConfiguration = configurationRepository
          .findOneByName(ConfigurationConstants.CONFIG_PROPERTY_DEVICE_AGREMENT_TYPE);*/

          /*if (deviceStatusConfiguration != null&& deviceStatusConfiguration.isEnabled()
          && deviceStatusConfiguration.getValue().equalsIgnoreCase(ConfigurationConstants.CONFIR_PROPERTY_SALE)) {*/
          if (deviceAgreementType.equalsIgnoreCase(ConfigurationConstants.CONFIR_PROPERTY_SALE)) {

            device = command.stringValueOfParameterNamed("device");
            ItemDetails detail = itemDetailsRepository.getInventoryItemDetailBySerialNum(device);

            if (detail == null) {
              throw new SerialNumberNotFoundException(device);
            }

            ItemMaster itemMaster = this.itemRepository.findOne(detail.getItemMasterId());

            if (itemMaster == null) {
              throw new ItemNotFoundException(deviceId);
            }

            if (detail != null && detail.getStatus().equalsIgnoreCase("Used")) {
              throw new SerialNumberAlreadyExistException(device);
            }

            JSONObject serialNumberObject = new JSONObject();
            serialNumberObject.put("serialNumber", device);
            serialNumberObject.put("clientId", resultClient.getClientId());
            serialNumberObject.put("status", "allocated");
            serialNumberObject.put("itemMasterId", detail.getItemMasterId());
            serialNumberObject.put("isNewHw", "Y");
            JSONArray serialNumber = new JSONArray();
            serialNumber.put(0, serialNumberObject);

            bookDevice.put("chargeCode", itemMaster.getChargeCode());
            bookDevice.put("unitPrice", itemMaster.getUnitPrice());
            bookDevice.put("itemId", itemMaster.getId());
            bookDevice.put("discountId", id);
            bookDevice.put("officeId", detail.getOfficeId());
            bookDevice.put("totalPrice", itemMaster.getUnitPrice());

            bookDevice.put("quantity", id);
            bookDevice.put("locale", "en");
            bookDevice.put("dateFormat", dateFormat);
            bookDevice.put("saleType", "NEWSALE");
            bookDevice.put("saleDate", activationDate);
            bookDevice.put("serialNumber", serialNumber);

            final JsonElement deviceElement = fromJsonHelper.parse(bookDevice.toString());
            JsonCommand comm =
                new JsonCommand(
                    null,
                    bookDevice.toString(),
                    deviceElement,
                    fromJsonHelper,
                    null,
                    null,
                    null,
                    null,
                    null,
                    null,
                    null,
                    null,
                    null,
                    null,
                    null,
                    null);

            resultSale =
                this.oneTimeSaleWritePlatformService.createOneTimeSale(
                    comm, resultClient.getClientId());

            if (resultSale == null) {
              throw new PlatformDataIntegrityException(
                  "error.msg.client.device.assign.failed",
                  "Device Assign Failed for ClientId :" + resultClient.getClientId(),
                  "Device Assign Failed");
            }

          } else if (deviceAgreementType.equalsIgnoreCase(
              ConfigurationConstants.CONFIR_PROPERTY_OWN)) {

            List<ItemMaster> itemMaster = this.itemRepository.findAll();
            bookDevice.put("locale", "en");
            bookDevice.put("dateFormat", dateFormat);
            bookDevice.put("allocationDate", activationDate);
            bookDevice.put("provisioningSerialNumber", deviceId);
            bookDevice.put("itemType", itemMaster.get(0).getId());
            bookDevice.put("serialNumber", deviceId);
            bookDevice.put("status", "ACTIVE");
            CommandWrapper commandWrapper =
                new CommandWrapperBuilder()
                    .createOwnedHardware(resultClient.getClientId())
                    .withJson(bookDevice.toString())
                    .build();
            final CommandProcessingResult result =
                portfolioCommandSourceWritePlatformService.logCommandSource(commandWrapper);

            if (result == null) {
              throw new PlatformDataIntegrityException(
                  "error.msg.client.device.assign.failed",
                  "Device Assign Failed for ClientId :" + resultClient.getClientId(),
                  "Device Assign Failed");
            }
          } else {

          }
        }
      }

      // book order
      Configuration selfregistrationconfiguration =
          configurationRepository.findOneByName(
              ConfigurationConstants.CONFIR_PROPERTY_SELF_REGISTRATION);

      if (selfregistrationconfiguration != null && selfregistrationconfiguration.isEnabled()) {

        if (selfregistrationconfiguration.getValue() != null) {

          JSONObject ordeJson = new JSONObject(selfregistrationconfiguration.getValue());
          ordeJson.put("locale", "en");
          ordeJson.put("isNewplan", true);
          ordeJson.put("dateFormat", dateFormat);
          ordeJson.put("start_date", activationDate);

          CommandWrapper commandRequest =
              new CommandWrapperBuilder()
                  .createOrder(resultClient.getClientId())
                  .withJson(ordeJson.toString())
                  .build();
          resultOrder =
              this.portfolioCommandSourceWritePlatformService.logCommandSource(commandRequest);

          if (resultOrder == null) {
            throw new PlatformDataIntegrityException(
                "error.msg.client.order.creation",
                "Book Order Failed for ClientId:" + resultClient.getClientId(),
                "Book Order Failed");
          }

        } else {

          String paytermCode = command.stringValueOfParameterNamed("paytermCode");
          Long contractPeriod = command.longValueOfParameterNamed("contractPeriod");
          Long planCode = command.longValueOfParameterNamed("planCode");

          JSONObject ordeJson = new JSONObject();

          ordeJson.put("planCode", planCode);
          ordeJson.put("contractPeriod", contractPeriod);
          ordeJson.put("paytermCode", paytermCode);
          ordeJson.put("billAlign", false);
          ordeJson.put("locale", "en");
          ordeJson.put("isNewplan", true);
          ordeJson.put("dateFormat", dateFormat);
          ordeJson.put("start_date", activationDate);

          CommandWrapper commandRequest =
              new CommandWrapperBuilder()
                  .createOrder(resultClient.getClientId())
                  .withJson(ordeJson.toString())
                  .build();
          resultOrder =
              this.portfolioCommandSourceWritePlatformService.logCommandSource(commandRequest);

          if (resultOrder == null) {
            throw new PlatformDataIntegrityException(
                "error.msg.client.order.creation",
                "Book Order Failed for ClientId:" + resultClient.getClientId(),
                "Book Order Failed");
          }
        }
      }

      return resultClient;

      /*}  else {
      	return new CommandProcessingResult(Long.valueOf(-1));
      }*/

    } catch (DataIntegrityViolationException dve) {
      handleDataIntegrityIssues(command, dve);
      return new CommandProcessingResult(Long.valueOf(-1));
    } catch (JSONException e) {
      return new CommandProcessingResult(Long.valueOf(-1));
    }
  }