Skip to content

Commit

Permalink
formatted code
Browse files Browse the repository at this point in the history
  • Loading branch information
mkalema committed Sep 9, 2023
1 parent 364ad94 commit 09f82f9
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 68 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -275,17 +275,17 @@ public static SearchParameters forEmailCampaign(final String sqlSearch, final In
staffId, accountNo, loanId, savingsId, orphansOnly, isSelfUser);
}

public static SearchParameters forBanks(final Integer offset, final Integer limit,
final String orderBy, final String sortOrder, String searchText) {
public static SearchParameters forBanks(final Integer offset, final Integer limit, final String orderBy, final String sortOrder,
String searchText) {

final Integer maxLimitAllowed = getCheckedLimit(limit);
final Long staffId = null;
final String accountNo = null;
final Long loanId = null;
final Long savingsId = null;

return new SearchParameters(searchText, null, null, null, null, null, null, null, offset, maxLimitAllowed, orderBy,
sortOrder, staffId, accountNo, loanId, savingsId, null, false, null);
return new SearchParameters(searchText, null, null, null, null, null, null, null, offset, maxLimitAllowed, orderBy, sortOrder,
staffId, accountNo, loanId, savingsId, null, false, null);
}

private SearchParameters(final String sqlSearch, final Long officeId, final String externalId, final String name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@
*/
package org.apache.fineract.organisation.bank.api;

import org.apache.fineract.organisation.bank.data.BankData;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import org.apache.fineract.organisation.bank.data.BankData;

@SuppressWarnings({ "HideUtilityClassConstructor" })
public class BankApiConstants {
Expand All @@ -36,6 +35,6 @@ public class BankApiConstants {
* These parameters will match the class level parameters of {@link BankData}. Where possible, we try to get
* response parameters to match those of request parameters.
*/
protected static final Set<String> BANK_RESPONSE_DATA_PARAMETERS = new HashSet<>(Arrays.asList(idParamName, codeParamName,
nameParamName));
protected static final Set<String> BANK_RESPONSE_DATA_PARAMETERS = new HashSet<>(
Arrays.asList(idParamName, codeParamName, nameParamName));
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,18 @@
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.UriInfo;
import org.apache.fineract.commands.domain.CommandWrapper;
import org.apache.fineract.commands.service.CommandWrapperBuilder;
import org.apache.fineract.commands.service.PortfolioCommandSourceWritePlatformService;
Expand All @@ -42,19 +54,6 @@
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.UriInfo;

@Path("/banks")
@Component
@Scope("singleton")
Expand All @@ -68,10 +67,10 @@ public class BankApiResource {
private final BankReadPlatformService bankReadPlatformService;
private final ApiRequestParameterHelper apiRequestParameterHelper;


public BankApiResource(final PlatformSecurityContext platformSecurityContext, final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService,
final DefaultToApiJsonSerializer<BankData> toApiJsonSerializer, final BankReadPlatformService bankReadPlatformService,
final ApiRequestParameterHelper apiRequestParameterHelper){
public BankApiResource(final PlatformSecurityContext platformSecurityContext,
final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService,
final DefaultToApiJsonSerializer<BankData> toApiJsonSerializer, final BankReadPlatformService bankReadPlatformService,
final ApiRequestParameterHelper apiRequestParameterHelper) {
this.platformSecurityContext = platformSecurityContext;
this.commandsSourceWritePlatformService = commandsSourceWritePlatformService;
this.toApiJsonSerializer = toApiJsonSerializer;
Expand Down Expand Up @@ -105,7 +104,7 @@ public String createBank(@Parameter(hidden = true) final String apiRequestBodyAs
@ApiResponses({
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = BanksApiResourceSwagger.PutBanksBankIdResponse.class))) })
public String updateAgency(@PathParam("bankId") @Parameter(description = "bankId") final Long bankId,
@Parameter(hidden = true) final String apiRequestBodyAsJson) {
@Parameter(hidden = true) final String apiRequestBodyAsJson) {
final CommandWrapper commandRequest = new CommandWrapperBuilder() //
.updateBank(bankId) //
.withJson(apiRequestBodyAsJson) //
Expand Down Expand Up @@ -133,11 +132,11 @@ public String delete(@PathParam("bankId") @Parameter(description = "bankId") fin
@GET
@Produces({ MediaType.APPLICATION_JSON })
public String retrieveAll(@Context final UriInfo uriInfo,
@QueryParam("sqlSearch") @Parameter(description = "sqlSearch") final String sqlSearch,
@QueryParam("offset") @Parameter(description = "offset") final Integer offset,
@QueryParam("limit") @Parameter(description = "limit") final Integer limit,
@QueryParam("orderBy") @Parameter(description = "orderBy") final String orderBy,
@QueryParam("sortOrder") @Parameter(description = "sortOrder") final String sortOrder) {
@QueryParam("sqlSearch") @Parameter(description = "sqlSearch") final String sqlSearch,
@QueryParam("offset") @Parameter(description = "offset") final Integer offset,
@QueryParam("limit") @Parameter(description = "limit") final Integer limit,
@QueryParam("orderBy") @Parameter(description = "orderBy") final String orderBy,
@QueryParam("sortOrder") @Parameter(description = "sortOrder") final String sortOrder) {

this.platformSecurityContext.authenticatedUser().validateHasReadPermission(BankConstants.BANK_RESOURCE_NAME);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ public BankData(Long id, String code, String name) {
this.code = code;
this.name = name;
}
//TODO: complete

// TODO: complete
public static BankData template() {
return new BankData(null, null, null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,21 @@
*/
package org.apache.fineract.organisation.bank.domain;

import java.time.LocalDateTime;
import java.util.LinkedHashMap;
import java.util.Map;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import lombok.Getter;
import org.apache.fineract.infrastructure.core.api.JsonCommand;
import org.apache.fineract.infrastructure.core.domain.AbstractPersistableCustom;
import org.apache.fineract.infrastructure.core.service.DateUtils;
import org.apache.fineract.organisation.bank.service.BankConstants;
import org.apache.fineract.useradministration.domain.AppUser;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import java.time.LocalDateTime;
import java.util.LinkedHashMap;
import java.util.Map;

@Entity
@Getter
@Table(name = "m_bank")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class NewBankCommandHandler implements NewCommandSourceHandler {
private final BankWritePlatformService bankWritePlatformService;

@Autowired
public NewBankCommandHandler(final BankWritePlatformService bankWritePlatformService){
public NewBankCommandHandler(final BankWritePlatformService bankWritePlatformService) {
this.bankWritePlatformService = bankWritePlatformService;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@

import com.google.gson.JsonElement;
import com.google.gson.reflect.TypeToken;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.commons.lang3.StringUtils;
import org.apache.fineract.infrastructure.core.data.ApiParameterError;
import org.apache.fineract.infrastructure.core.data.DataValidatorBuilder;
Expand All @@ -30,12 +35,6 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
* Deserializer of JSON for agency API.
*/
Expand Down Expand Up @@ -69,10 +68,12 @@ public void validateForCreate(final String json) {
final JsonElement element = this.fromApiJsonHelper.parse(json);

final String code = this.fromApiJsonHelper.extractStringNamed(BankConstants.BankSupportedParameters.CODE.getValue(), element);
baseDataValidator.reset().parameter(BankConstants.BankSupportedParameters.CODE.getValue()).value(code).notBlank().notExceedingLengthOf(2);
baseDataValidator.reset().parameter(BankConstants.BankSupportedParameters.CODE.getValue()).value(code).notBlank()
.notExceedingLengthOf(2);

final String name = this.fromApiJsonHelper.extractStringNamed(BankConstants.BankSupportedParameters.NAME.getValue(), element);
baseDataValidator.reset().parameter(BankConstants.BankSupportedParameters.NAME.getValue()).value(name).notBlank().notExceedingLengthOf(100);
baseDataValidator.reset().parameter(BankConstants.BankSupportedParameters.NAME.getValue()).value(name).notBlank()
.notExceedingLengthOf(100);

throwExceptionIfValidationWarningsExist(dataValidationErrors);
}
Expand All @@ -86,15 +87,18 @@ public void validateForUpdate(final String json) {
this.fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, json, this.supportedParameters);

final List<ApiParameterError> dataValidationErrors = new ArrayList<>();
final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource(BankConstants.BANK_RESOURCE_NAME);
final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors)
.resource(BankConstants.BANK_RESOURCE_NAME);

final JsonElement element = this.fromApiJsonHelper.parse(json);

final String code = this.fromApiJsonHelper.extractStringNamed(BankConstants.BankSupportedParameters.CODE.getValue(), element);
baseDataValidator.reset().parameter(BankConstants.BankSupportedParameters.CODE.getValue()).value(code).notBlank().notExceedingLengthOf(2);
baseDataValidator.reset().parameter(BankConstants.BankSupportedParameters.CODE.getValue()).value(code).notBlank()
.notExceedingLengthOf(2);

final String name = this.fromApiJsonHelper.extractStringNamed(BankConstants.BankSupportedParameters.NAME.getValue(), element);
baseDataValidator.reset().parameter(BankConstants.BankSupportedParameters.NAME.getValue()).value(name).notBlank().notExceedingLengthOf(100);
baseDataValidator.reset().parameter(BankConstants.BankSupportedParameters.NAME.getValue()).value(name).notBlank()
.notExceedingLengthOf(100);

throwExceptionIfValidationWarningsExist(dataValidationErrors);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
*/
package org.apache.fineract.organisation.bank.service;

import java.sql.ResultSet;
import java.sql.SQLException;
import org.apache.fineract.infrastructure.core.service.Page;
import org.apache.fineract.infrastructure.core.service.PaginationHelper;
import org.apache.fineract.infrastructure.core.service.SearchParameters;
Expand All @@ -34,9 +36,6 @@
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Service;

import java.sql.ResultSet;
import java.sql.SQLException;

@Service
public class BankReadPlatformServiceImpl implements BankReadPlatformService {

Expand All @@ -51,16 +50,15 @@ public class BankReadPlatformServiceImpl implements BankReadPlatformService {

@Autowired
public BankReadPlatformServiceImpl(final PlatformSecurityContext context, final JdbcTemplate jdbcTemplate,
final ColumnValidator columnValidator, final DatabaseSpecificSQLGenerator sqlGenerator,
final AppUserReadPlatformService appUserReadPlatformService,
final OfficeReadPlatformService officeReadPlatformService,
final PaginationHelper paginationHelper) {
final ColumnValidator columnValidator, final DatabaseSpecificSQLGenerator sqlGenerator,
final AppUserReadPlatformService appUserReadPlatformService, final OfficeReadPlatformService officeReadPlatformService,
final PaginationHelper paginationHelper) {
this.context = context;
this.columnValidator = columnValidator;
this.jdbcTemplate = jdbcTemplate;
this.sqlGenerator = sqlGenerator;
this.appUserReadPlatformService = appUserReadPlatformService;
this.officeReadPlatformService = officeReadPlatformService;
this.officeReadPlatformService = officeReadPlatformService;
this.paginationHelper = paginationHelper;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
*/
package org.apache.fineract.organisation.bank.service;

import java.util.Map;
import javax.persistence.PersistenceException;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.apache.fineract.infrastructure.core.api.JsonCommand;
Expand All @@ -34,19 +36,16 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.persistence.PersistenceException;
import java.util.Map;

@Service
@Slf4j
public class BankWritePlatformServiceImpl implements BankWritePlatformService{
public class BankWritePlatformServiceImpl implements BankWritePlatformService {

private final PlatformSecurityContext context;
private final BankCommandFromApiJsonDeserializer fromApiJsonDeserializer;
private final BankRepositoryWrapper bankRepositoryWrapper;

public BankWritePlatformServiceImpl(final PlatformSecurityContext context, final BankCommandFromApiJsonDeserializer fromApiJsonDeserializer,
final BankRepositoryWrapper bankRepositoryWrapper){
public BankWritePlatformServiceImpl(final PlatformSecurityContext context,
final BankCommandFromApiJsonDeserializer fromApiJsonDeserializer, final BankRepositoryWrapper bankRepositoryWrapper) {
this.context = context;
this.fromApiJsonDeserializer = fromApiJsonDeserializer;
this.bankRepositoryWrapper = bankRepositoryWrapper;
Expand Down Expand Up @@ -115,7 +114,7 @@ public CommandProcessingResult deleteBank(Long bankId) {
return new CommandProcessingResultBuilder() //
.withEntityId(bank.getId()) //
.build();
} catch (final JpaSystemException | DataIntegrityViolationException dve) {
} catch (final JpaSystemException | DataIntegrityViolationException dve) {
Throwable throwable = ExceptionUtils.getRootCause(dve.getCause());
log.error("Error occured.", throwable);
throw new PlatformDataIntegrityException("error.msg.bank.unknown.data.integrity.issue",
Expand Down

0 comments on commit 09f82f9

Please sign in to comment.