diff --git a/fineract-provider/src/main/java/org/apache/fineract/batch/exception/ClientDetailsNotFoundException.java b/fineract-provider/src/main/java/org/apache/fineract/batch/exception/ClientDetailsNotFoundException.java new file mode 100644 index 000000000..9d13c163f --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/batch/exception/ClientDetailsNotFoundException.java @@ -0,0 +1,29 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.fineract.batch.exception; + +import org.apache.fineract.infrastructure.core.exception.AbstractPlatformDomainRuleException; + +public class ClientDetailsNotFoundException extends AbstractPlatformDomainRuleException{ + + public ClientDetailsNotFoundException() { + super("validation.msg.batch.jlg.no.clients.defined", "No Client details found", ""); + } + +} diff --git a/fineract-provider/src/main/java/org/apache/fineract/batch/exception/ErrorHandler.java b/fineract-provider/src/main/java/org/apache/fineract/batch/exception/ErrorHandler.java index 76b373ca7..f88d955f0 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/batch/exception/ErrorHandler.java +++ b/fineract-provider/src/main/java/org/apache/fineract/batch/exception/ErrorHandler.java @@ -18,6 +18,7 @@ */ package org.apache.fineract.batch.exception; +import org.apache.fineract.infrastructure.core.exception.AbstractPlatformDomainRuleException; import org.apache.fineract.infrastructure.core.exception.AbstractPlatformResourceNotFoundException; import org.apache.fineract.infrastructure.core.exception.PlatformApiDataValidationException; import org.apache.fineract.infrastructure.core.exception.PlatformDataIntegrityException; @@ -69,7 +70,12 @@ public class ErrorHandler extends RuntimeException { */ public static ErrorInfo handler(final RuntimeException exception) { - if (exception instanceof AbstractPlatformResourceNotFoundException) { + if(exception instanceof AbstractPlatformDomainRuleException) { + PlatformDomainRuleExceptionMapper mapper = new PlatformDomainRuleExceptionMapper() ; + final String errorBody = jsonHelper + .toJson(mapper.toResponse((AbstractPlatformDomainRuleException) exception).getEntity()); + return new ErrorInfo(500, 9999, errorBody); + }else if (exception instanceof AbstractPlatformResourceNotFoundException) { final PlatformResourceNotFoundExceptionMapper mapper = new PlatformResourceNotFoundExceptionMapper(); final String errorBody = jsonHelper diff --git a/fineract-provider/src/main/java/org/apache/fineract/batch/service/BatchApiServiceImpl.java b/fineract-provider/src/main/java/org/apache/fineract/batch/service/BatchApiServiceImpl.java index d6261dbb5..6e61ee459 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/batch/service/BatchApiServiceImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/batch/service/BatchApiServiceImpl.java @@ -32,6 +32,7 @@ import org.apache.fineract.batch.command.CommandStrategy; import org.apache.fineract.batch.command.CommandStrategyProvider; import org.apache.fineract.batch.domain.BatchRequest; import org.apache.fineract.batch.domain.BatchResponse; +import org.apache.fineract.batch.exception.ClientDetailsNotFoundException; import org.apache.fineract.batch.exception.ErrorHandler; import org.apache.fineract.batch.exception.ErrorInfo; import org.apache.fineract.batch.service.ResolutionHelper.BatchRequestNode; @@ -95,7 +96,14 @@ public class BatchApiServiceImpl implements BatchApiService { final List batchRequestNodes = this.resolutionHelper.getDependingRequests(requestList); checkList.clear(); - + if(batchRequestNodes.isEmpty()) { + final BatchResponse response = new BatchResponse(); + ErrorInfo ex = ErrorHandler.handler(new ClientDetailsNotFoundException()); + response.setStatusCode(500); + response.setBody(ex.getMessage()); + responseList.add(response) ; + return responseList ; + } for (BatchRequestNode rootNode : batchRequestNodes) { final BatchRequest rootRequest = rootNode.getRequest(); final CommandStrategy commandStrategy = this.strategyProvider.getCommandStrategy(CommandContext