示例#1
0
文件: Group.java 项目: sheyden/mifosx
 public boolean isChildClient(final Long clientId) {
   if (clientId != null && this.clientMembers != null && !this.clientMembers.isEmpty()) {
     for (final Client client : this.clientMembers) {
       if (client.getId().equals(clientId)) {
         return true;
       }
     }
   }
   return false;
 }
示例#2
0
文件: Group.java 项目: sheyden/mifosx
  public List<String> associateClients(final Set<Client> clientMembersSet) {
    final List<String> differences = new ArrayList<String>();
    for (final Client client : clientMembersSet) {
      if (hasClientAsMember(client)) {
        throw new ClientExistInGroupException(client.getId(), getId());
      }
      this.clientMembers.add(client);
      differences.add(client.getId().toString());
    }

    return differences;
  }
示例#3
0
文件: Group.java 项目: udgupta/mifosx
  public List<String> disassociateClients(final Set<Client> clientMembersSet) {
    List<String> differences = new ArrayList<String>();
    for (Client client : clientMembersSet) {
      if (this.hasClientAsMember(client)) {
        this.clientMembers.remove(client);
        differences.add(client.getId().toString());
      } else {
        throw new ClientNotInGroupException(client.getId(), this.getId());
      }
    }

    return differences;
  }
  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;
  }
 private void checkClientOrGroupActive(final Loan loan) {
   final Client client = loan.client();
   if (client != null) {
     if (client.isNotActive()) {
       throw new ClientNotActiveException(client.getId());
     }
   }
   final Group group = loan.group();
   if (group != null) {
     if (group.isNotActive()) {
       throw new GroupNotActiveException(group.getId());
     }
   }
 }
 private void checkClientOrGroupActive(final SavingsAccount account) {
   final Client client = account.getClient();
   if (client != null) {
     if (client.isNotActive()) {
       throw new ClientNotActiveException(client.getId());
     }
   }
   final Group group = account.group();
   if (group != null) {
     if (group.isNotActive()) {
       if (group.isCenter()) {
         throw new CenterNotActiveException(group.getId());
       }
       throw new GroupNotActiveException(group.getId());
     }
   }
 }
  @Transactional
  @Override
  public void sendPdfToEmail(
      final String printFileName, final Long clientId, final String templateName) {

    // context.authenticatedUser();
    final Client client = this.clientRepository.findOne(clientId);
    final String clientEmail = client.getEmail();
    if (clientEmail == null) {
      final String msg = "Please provide email first";
      throw new BillingOrderNoRecordsFoundException(msg, client);
    }
    final BillingMessageTemplate messageTemplate =
        this.messageTemplateRepository.findByTemplateDescription(templateName);
    if (messageTemplate != null) {
      String header =
          messageTemplate
              .getHeader()
              .replace(
                  "<PARAM1>",
                  client.getDisplayName().isEmpty()
                      ? client.getFirstname()
                      : client.getDisplayName());
      BillingMessage billingMessage =
          new BillingMessage(
              header,
              messageTemplate.getBody(),
              messageTemplate.getFooter(),
              clientEmail,
              clientEmail,
              messageTemplate.getSubject(),
              "N",
              messageTemplate,
              messageTemplate.getMessageType(),
              printFileName);
      this.messageDataRepository.save(billingMessage);
    } else {
      throw new BillingMessageTemplateNotFoundException(templateName);
    }
  }
示例#8
0
  public LoanScheduleModel assembleLoanScheduleFrom(final JsonElement element) {
    // This method is getting called from calculate loan schedule.
    final LoanApplicationTerms loanApplicationTerms = assembleLoanTerms(element);
    // Get holiday details
    final boolean isHolidayEnabled =
        this.configurationDomainService.isRescheduleRepaymentsOnHolidaysEnabled();

    final Long clientId = fromApiJsonHelper.extractLongNamed("clientId", element);
    final Long groupId = fromApiJsonHelper.extractLongNamed("groupId", element);

    Client client = null;
    Group group = null;
    Long officeId = null;
    if (clientId != null) {
      client = this.clientRepository.findOneWithNotFoundDetection(clientId);
      officeId = client.getOffice().getId();
    } else if (groupId != null) {
      group = this.groupRepository.findOneWithNotFoundDetection(groupId);
      officeId = group.getOffice().getId();
    }

    final LocalDate expectedDisbursementDate =
        this.fromApiJsonHelper.extractLocalDateNamed("expectedDisbursementDate", element);
    final List<Holiday> holidays =
        this.holidayRepository.findByOfficeIdAndGreaterThanDate(
            officeId, expectedDisbursementDate.toDate());
    final WorkingDays workingDays = this.workingDaysRepository.findOne();

    validateDisbursementDateIsOnNonWorkingDay(
        loanApplicationTerms.getExpectedDisbursementDate(), workingDays);
    validateDisbursementDateIsOnHoliday(
        loanApplicationTerms.getExpectedDisbursementDate(), isHolidayEnabled, holidays);

    return assembleLoanScheduleFrom(
        loanApplicationTerms, isHolidayEnabled, holidays, workingDays, element);
  }
  @Transactional
  @Override
  public CommandProcessingResult modifyApplication(
      final Long savingsId, final JsonCommand command) {
    try {
      this.savingsAccountDataValidator.validateForUpdate(command.json());

      final Map<String, Object> changes = new LinkedHashMap<String, Object>(20);

      final SavingsAccount account = this.savingAccountAssembler.assembleFrom(savingsId);
      checkClientOrGroupActive(account);
      account.modifyApplication(command, changes);
      account.validateNewApplicationState(DateUtils.getLocalDateOfTenant());
      account.validateAccountValuesWithProduct();

      if (!changes.isEmpty()) {

        if (changes.containsKey(SavingsApiConstants.clientIdParamName)) {
          final Long clientId =
              command.longValueOfParameterNamed(SavingsApiConstants.clientIdParamName);
          if (clientId != null) {
            final Client client = this.clientRepository.findOneWithNotFoundDetection(clientId);
            if (client.isNotActive()) {
              throw new ClientNotActiveException(clientId);
            }
            account.update(client);
          } else {
            final Client client = null;
            account.update(client);
          }
        }

        if (changes.containsKey(SavingsApiConstants.groupIdParamName)) {
          final Long groupId =
              command.longValueOfParameterNamed(SavingsApiConstants.groupIdParamName);
          if (groupId != null) {
            final Group group = this.groupRepository.findOne(groupId);
            if (group == null) {
              throw new GroupNotFoundException(groupId);
            }
            if (group.isNotActive()) {
              if (group.isCenter()) {
                throw new CenterNotActiveException(groupId);
              }
              throw new GroupNotActiveException(groupId);
            }
            account.update(group);
          } else {
            final Group group = null;
            account.update(group);
          }
        }

        if (changes.containsKey(SavingsApiConstants.productIdParamName)) {
          final Long productId =
              command.longValueOfParameterNamed(SavingsApiConstants.productIdParamName);
          final SavingsProduct product = this.savingsProductRepository.findOne(productId);
          if (product == null) {
            throw new SavingsProductNotFoundException(productId);
          }

          account.update(product);
        }

        if (changes.containsKey(SavingsApiConstants.fieldOfficerIdParamName)) {
          final Long fieldOfficerId =
              command.longValueOfParameterNamed(SavingsApiConstants.fieldOfficerIdParamName);
          Staff fieldOfficer = null;
          if (fieldOfficerId != null) {
            fieldOfficer = this.staffRepository.findOneWithNotFoundDetection(fieldOfficerId);
          } else {
            changes.put(SavingsApiConstants.fieldOfficerIdParamName, "");
          }
          account.update(fieldOfficer);
        }

        if (changes.containsKey("charges")) {
          final Set<SavingsAccountCharge> charges =
              this.savingsAccountChargeAssembler.fromParsedJson(
                  command.parsedJson(), account.getCurrency().getCode());
          final boolean updated = account.update(charges);
          if (!updated) {
            changes.remove("charges");
          }
        }

        this.savingAccountRepository.saveAndFlush(account);
      }

      return new CommandProcessingResultBuilder() //
          .withCommandId(command.commandId()) //
          .withEntityId(savingsId) //
          .withOfficeId(account.officeId()) //
          .withClientId(account.clientId()) //
          .withGroupId(account.groupId()) //
          .withSavingsId(savingsId) //
          .with(changes) //
          .build();
    } catch (final DataAccessException dve) {
      handleDataIntegrityIssues(command, dve);
      return new CommandProcessingResult(Long.valueOf(-1));
    }
  }
  @Transactional
  @Override
  public EntityIdentifier modifyLoanApplication(final Long loanId, final JsonCommand command) {

    context.authenticatedUser();

    LoanApplicationCommand loanApplicationCommand =
        this.fromApiJsonDeserializer.commandFromApiJson(command.json());
    loanApplicationCommand.validate();

    CalculateLoanScheduleQuery calculateLoanScheduleQuery =
        this.calculateLoanScheduleQueryFromApiJsonDeserializer.commandFromApiJson(command.json());
    calculateLoanScheduleQuery.validate();

    final Loan existingLoanApplication = retrieveLoanBy(loanId);

    final Map<String, Object> changes =
        existingLoanApplication.modifyLoanApplication(
            command, loanApplicationCommand.getCharges(), this.aprCalculator);

    final String clientIdParamName = "clientId";
    if (changes.containsKey(clientIdParamName)) {
      final Long clientId = command.longValueOfParameterNamed(clientIdParamName);
      final Client client = this.clientRepository.findOne(clientId);
      if (client == null || client.isDeleted()) {
        throw new ClientNotFoundException(clientId);
      }

      existingLoanApplication.updateClient(client);
    }

    final String productIdParamName = "productId";
    if (changes.containsKey(productIdParamName)) {
      final Long productId = command.longValueOfParameterNamed(productIdParamName);
      final LoanProduct loanProduct = this.loanProductRepository.findOne(productId);
      if (loanProduct == null) {
        throw new LoanProductNotFoundException(productId);
      }

      existingLoanApplication.updateLoanProduct(loanProduct);
    }

    final String fundIdParamName = "fundId";
    if (changes.containsKey(fundIdParamName)) {
      final Long fundId = command.longValueOfParameterNamed(fundIdParamName);
      final Fund fund = this.loanAssembler.findFundByIdIfProvided(fundId);

      existingLoanApplication.updateFund(fund);
    }

    final String strategyIdParamName = "transactionProcessingStrategyId";
    if (changes.containsKey(strategyIdParamName)) {
      final Long strategyId = command.longValueOfParameterNamed(strategyIdParamName);
      final LoanTransactionProcessingStrategy strategy =
          this.loanAssembler.findStrategyByIdIfProvided(strategyId);

      existingLoanApplication.updateTransactionProcessingStrategy(strategy);
    }

    final String chargesParamName = "charges";
    if (changes.containsKey(chargesParamName)) {
      final Set<LoanCharge> loanCharges =
          this.loanChargeAssembler.fromParsedJson(command.parsedJson());
      existingLoanApplication.updateLoanCharges(loanCharges);
    }

    if (changes.containsKey("recalculateLoanSchedule")) {
      changes.remove("recalculateLoanSchedule");

      final JsonElement parsedQuery = this.fromJsonHelper.parse(command.json());
      final JsonQuery query = JsonQuery.from(command.json(), parsedQuery, this.fromJsonHelper);

      final LoanScheduleData loanSchedule =
          this.calculationPlatformService.calculateLoanSchedule(query);
      existingLoanApplication.updateLoanSchedule(loanSchedule);
      existingLoanApplication.updateLoanScheduleDependentDerivedFields();
    }

    this.loanRepository.save(existingLoanApplication);

    final String submittedOnNote = command.stringValueOfParameterNamed("submittedOnNote");
    if (StringUtils.isNotBlank(submittedOnNote)) {
      Note note = Note.loanNote(existingLoanApplication, submittedOnNote);
      this.noteRepository.save(note);
    }

    return EntityIdentifier.resourceResult(loanId, command.commandId(), changes);
  }