@Transactional @Override @CacheEvict(value = "hooks", allEntries = true) public CommandProcessingResult createHook(final JsonCommand command) { try { this.context.authenticatedUser(); this.fromApiJsonDeserializer.validateForCreate(command.json()); final HookTemplate template = retrieveHookTemplateBy(command.stringValueOfParameterNamed(nameParamName)); final String configJson = command.jsonFragment(configParamName); final Set<HookConfiguration> config = assembleConfig(command.mapValueOfParameterNamed(configJson), template); final JsonArray events = command.arrayOfParameterNamed(eventsParamName); final Set<HookResource> allEvents = assembleSetOfEvents(events); Template ugdTemplate = null; if (command.hasParameter(templateIdParamName)) { final Long ugdTemplateId = command.longValueOfParameterNamed(templateIdParamName); ugdTemplate = this.ugdTemplateRepository.findOne(ugdTemplateId); if (ugdTemplate == null) { throw new TemplateNotFoundException(ugdTemplateId); } } final Hook hook = Hook.fromJson(command, template, config, allEvents, ugdTemplate); validateHookRules(template, config, allEvents); this.hookRepository.save(hook); return new CommandProcessingResultBuilder() .withCommandId(command.commandId()) .withEntityId(hook.getId()) .build(); } catch (final DataIntegrityViolationException dve) { handleHookDataIntegrityIssues(command, dve); return CommandProcessingResult.empty(); } }
public Map<String, Object> update( final JsonCommand command, final PlatformPasswordEncoder platformPasswordEncoder) { final Map<String, Object> actualChanges = new LinkedHashMap<String, Object>(7); // unencoded password provided final String passwordParamName = "password"; final String passwordEncodedParamName = "passwordEncoded"; if (command.hasParameter(passwordParamName)) { if (command.isChangeInPasswordParameterNamed( passwordParamName, this.password, platformPasswordEncoder, this.getId())) { final String passwordEncodedValue = command.passwordValueOfParameterNamed( passwordParamName, platformPasswordEncoder, this.getId()); actualChanges.put(passwordEncodedParamName, passwordEncodedValue); updatePassword(passwordEncodedValue); } } if (command.hasParameter(passwordEncodedParamName)) { if (command.isChangeInStringParameterNamed(passwordEncodedParamName, this.password)) { final String newValue = command.stringValueOfParameterNamed(passwordEncodedParamName); actualChanges.put(passwordEncodedParamName, newValue); updatePassword(newValue); } } final String officeIdParamName = "officeId"; if (command.isChangeInLongParameterNamed(officeIdParamName, this.office.getId())) { final Long newValue = command.longValueOfParameterNamed(officeIdParamName); actualChanges.put(officeIdParamName, newValue); } final String rolesParamName = "roles"; if (command.isChangeInArrayParameterNamed(rolesParamName, getRolesAsIdStringArray())) { final String[] newValue = command.arrayValueOfParameterNamed(rolesParamName); actualChanges.put(rolesParamName, newValue); } final String usernameParamName = "username"; if (command.isChangeInStringParameterNamed(usernameParamName, this.username)) { final String newValue = command.stringValueOfParameterNamed(usernameParamName); actualChanges.put(usernameParamName, newValue); this.username = newValue; } final String firstnameParamName = "firstname"; if (command.isChangeInStringParameterNamed(firstnameParamName, this.firstname)) { final String newValue = command.stringValueOfParameterNamed(firstnameParamName); actualChanges.put(firstnameParamName, newValue); this.firstname = newValue; } final String lastnameParamName = "lastname"; if (command.isChangeInStringParameterNamed(lastnameParamName, this.lastname)) { final String newValue = command.stringValueOfParameterNamed(lastnameParamName); actualChanges.put(lastnameParamName, newValue); this.lastname = newValue; } final String emailParamName = "email"; if (command.isChangeInStringParameterNamed(emailParamName, this.email)) { final String newValue = command.stringValueOfParameterNamed(emailParamName); actualChanges.put(emailParamName, newValue); this.email = newValue; } return actualChanges; }
public static LoanCharge createNewFromJson( final Loan loan, final Charge chargeDefinition, final JsonCommand command, final LocalDate dueDate) { final BigDecimal amount = command.bigDecimalValueOfParameterNamed("amount"); final ChargeTimeType chargeTime = null; final ChargeCalculationType chargeCalculation = null; final ChargePaymentMode chargePaymentMode = null; BigDecimal amountPercentageAppliedTo = BigDecimal.ZERO; switch (ChargeCalculationType.fromInt(chargeDefinition.getChargeCalculation())) { case PERCENT_OF_AMOUNT: if (command.hasParameter("principal")) { amountPercentageAppliedTo = command.bigDecimalValueOfParameterNamed("principal"); } else { amountPercentageAppliedTo = loan.getPrincpal().getAmount(); } break; case PERCENT_OF_AMOUNT_AND_INTEREST: if (command.hasParameter("principal") && command.hasParameter("interest")) { amountPercentageAppliedTo = command .bigDecimalValueOfParameterNamed("principal") .add(command.bigDecimalValueOfParameterNamed("interest")); } else { amountPercentageAppliedTo = loan.getPrincpal().getAmount().add(loan.getTotalInterest()); } break; case PERCENT_OF_INTEREST: if (command.hasParameter("interest")) { amountPercentageAppliedTo = command.bigDecimalValueOfParameterNamed("interest"); } else { amountPercentageAppliedTo = loan.getTotalInterest(); } break; default: break; } BigDecimal loanCharge = BigDecimal.ZERO; if (ChargeTimeType.fromInt(chargeDefinition.getChargeTime()) .equals(ChargeTimeType.INSTALMENT_FEE)) { BigDecimal percentage = amount; if (percentage == null) { percentage = chargeDefinition.getAmount(); } loanCharge = loan.calculatePerInstallmentChargeAmount( ChargeCalculationType.fromInt(chargeDefinition.getChargeCalculation()), percentage); } return new LoanCharge( loan, chargeDefinition, amountPercentageAppliedTo, amount, chargeTime, chargeCalculation, dueDate, chargePaymentMode, null, loanCharge); }