update docs on funds api
This commit is contained in:
@@ -231,6 +231,21 @@ function getBaseURL(docURL)
|
||||
<td><a href="#configs_code_update">Update a Code</a></td>
|
||||
<td><a href="#configs_code_delete">Delete a Code</a></td>
|
||||
</tr>
|
||||
<tr class="alt">
|
||||
<td><a href="#funds">FUNDS</a></td><td>funds</td>
|
||||
<td><a href="#funds_create">Create a Fund</a></td>
|
||||
<td><a href="#funds_retrieve">List Funds</a></td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
</tr>
|
||||
<tr class="alt">
|
||||
<td></td>
|
||||
<td>funds/{fundId}</td>
|
||||
<td></td>
|
||||
<td><a href="#fund_retrieve">Retrieve a Fund</a></td>
|
||||
<td><a href="#fund_update">Update a Fund</a></td>
|
||||
<td></td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
@@ -2470,6 +2485,100 @@ Content-Type: application/json
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<a id="funds" name="funds" class="old-syle-anchor"> </a>
|
||||
<div class="method-section">
|
||||
<div class="method-description">
|
||||
<h3>Funds</h3>
|
||||
<p>Simple implementation of funds. At present funds can optionally be associated with a Loan.</p>
|
||||
<p>This information can then be used to produce reports on loans/loan amounts drawn from a fund.</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<a id="funds_create" name="funds_create" class="old-syle-anchor"> </a>
|
||||
<div class="method-section">
|
||||
<div class="method-description">
|
||||
<h4>Create a Fund</h4>
|
||||
<p>Creates a fund.</p>
|
||||
</div>
|
||||
<div class="method-example">
|
||||
<code class="method-declaration">POST https://Domain Name/api/v1/funds</code>
|
||||
<code class="method-request">POST funds
|
||||
Content-Type: application/json
|
||||
Request Body:
|
||||
{
|
||||
"name": "EU Agri Fund"
|
||||
}
|
||||
</code>
|
||||
<code class="method-response">{
|
||||
"resourceId": 1
|
||||
}
|
||||
</code>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<a id="funds_retrieve" name="funds_retrieve" class="old-syle-anchor"> </a>
|
||||
<div class="method-section">
|
||||
<div class="method-description">
|
||||
<h4>Retrieve Funds</h4>
|
||||
<p>Returns the list of funds.</p>
|
||||
<p>Example Requests: </p>
|
||||
<div class=apiClick>funds</div>
|
||||
</div>
|
||||
<div class="method-example">
|
||||
<code class="method-declaration">GET https://Domain Name/api/v1/funds</code>
|
||||
<code class="method-response">[
|
||||
{
|
||||
"id": 1,
|
||||
"name": "EU Agri Fund"
|
||||
}
|
||||
]
|
||||
</code>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<a id="fund_retrieve" name="fund_retrieve" class="old-syle-anchor"> </a>
|
||||
<div class="method-section">
|
||||
<div class="method-description">
|
||||
<h4>Retrieve a Fund</h4>
|
||||
<p>Returns the details of a Fund.</p>
|
||||
<p>Example Requests: </p>
|
||||
<div class=apiClick>funds/1</div>
|
||||
</div>
|
||||
<div class="method-example">
|
||||
<code class="method-declaration">GET https://Domain Name/api/v1/funds/1</code>
|
||||
<code class="method-response">{
|
||||
"id": 1,
|
||||
"name": "EU Agri Fund"
|
||||
}
|
||||
</code>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<a id="fund_update" name="fund_update" class="old-syle-anchor"> </a>
|
||||
<div class="method-section">
|
||||
<div class="method-description">
|
||||
<h4>Update a Fund</h4>
|
||||
<p>Updates the details of a fund.</p>
|
||||
</div>
|
||||
<div class="method-example">
|
||||
<code class="method-declaration">PUT https://Domain Name/api/v1/funds/1</code>
|
||||
<code class="method-request">PUT funds/1
|
||||
Content-Type: application/json
|
||||
Request Body:
|
||||
{
|
||||
"name": "EU Agri Fund (2010-2020)"
|
||||
}
|
||||
</code>
|
||||
<code class="method-response">{
|
||||
"resourceId": 1,
|
||||
"changes": {
|
||||
"name": "EU Agri Fund (2010-2020)"
|
||||
}
|
||||
}
|
||||
</code>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- start of datatables api docs -->
|
||||
<a id="datatables" name="datatables" class="old-syle-anchor"> </a>
|
||||
<div class="method-section">
|
||||
@@ -3576,6 +3685,21 @@ Request body:
|
||||
<td><a href="#configs_code_update">Update a Code</a></td>
|
||||
<td><a href="#configs_code_delete">Delete a Code</a></td>
|
||||
</tr>
|
||||
<tr class="alt">
|
||||
<td><a href="#funds">FUNDS</a></td><td>funds</td>
|
||||
<td><a href="#funds_create">Create a Fund</a></td>
|
||||
<td><a href="#funds_retrieve">List Funds</a></td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
</tr>
|
||||
<tr class="alt">
|
||||
<td></td>
|
||||
<td>funds/{fundId}</td>
|
||||
<td></td>
|
||||
<td><a href="#fund_retrieve">Retrieve a Fund</a></td>
|
||||
<td><a href="#fund_update">Update a Fund</a></td>
|
||||
<td></td>
|
||||
</tr>
|
||||
<tr><td><a href="#datatables">DATA TABLE</a></td><td>datatables</td><td></td><td><a href="#datatables_list">List Data Tables</a></td><td></td><td></td></tr>
|
||||
<tr class="alt"><td></td><td>datatables/register/{datatable}/{apptable}</td><td><a href="#datatables_register">Register Data Table</a></td><td></td><td></td><td></td></tr>
|
||||
<tr><td></td><td>datatables/deregister/{datatable}</td><td><a href="#datatables_deregister">Deregister Data Table</a></td><td></td><td></td><td></td></tr>
|
||||
|
||||
-5
@@ -10,19 +10,14 @@ import java.util.Set;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.mifosplatform.infrastructure.core.exception.InvalidJsonException;
|
||||
import org.mifosplatform.infrastructure.core.serialization.AbstractFromApiJsonDeserializer;
|
||||
import org.mifosplatform.infrastructure.core.serialization.FromApiJsonDeserializer;
|
||||
import org.mifosplatform.infrastructure.core.serialization.FromJsonHelper;
|
||||
import org.mifosplatform.portfolio.charge.command.ChargeDefinitionCommand;
|
||||
import org.mifosplatform.portfolio.fund.command.FundCommand;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
|
||||
/**
|
||||
* Implementation of {@link FromApiJsonDeserializer} for {@link FundCommand}'s.
|
||||
*/
|
||||
@Component
|
||||
public final class ChargeDefinitionCommandFromApiJsonDeserializer extends AbstractFromApiJsonDeserializer<ChargeDefinitionCommand> {
|
||||
|
||||
|
||||
-48
@@ -1,48 +0,0 @@
|
||||
package org.mifosplatform.portfolio.fund.command;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.mifosplatform.infrastructure.core.data.ApiParameterError;
|
||||
import org.mifosplatform.infrastructure.core.data.DataValidatorBuilder;
|
||||
import org.mifosplatform.infrastructure.core.exception.PlatformApiDataValidationException;
|
||||
|
||||
/**
|
||||
* Immutable command for creating or updating details of a fund.
|
||||
*/
|
||||
public class FundCommand {
|
||||
|
||||
private final String name;
|
||||
private final String externalId;
|
||||
|
||||
public FundCommand(final String fundName, final String externalId) {
|
||||
this.name = fundName;
|
||||
this.externalId = externalId;
|
||||
}
|
||||
|
||||
public void validateForCreate() {
|
||||
List<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>();
|
||||
|
||||
DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("fund");
|
||||
|
||||
baseDataValidator.reset().parameter("name").value(this.name).notBlank();
|
||||
baseDataValidator.reset().parameter("externalId").value(this.externalId).notExceedingLengthOf(100);
|
||||
|
||||
if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist",
|
||||
"Validation errors exist.", dataValidationErrors); }
|
||||
}
|
||||
|
||||
public void validateForUpdate() {
|
||||
List<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>();
|
||||
|
||||
DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("fund");
|
||||
|
||||
baseDataValidator.reset().parameter("name").value(this.name).ignoreIfNull().notBlank();
|
||||
baseDataValidator.reset().parameter("externalId").value(this.externalId).ignoreIfNull().notExceedingLengthOf(100);
|
||||
|
||||
baseDataValidator.reset().anyOfNotNull(this.name, this.externalId);
|
||||
|
||||
if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist",
|
||||
"Validation errors exist.", dataValidationErrors); }
|
||||
}
|
||||
}
|
||||
+46
-14
@@ -1,28 +1,27 @@
|
||||
package org.mifosplatform.portfolio.fund.serialization;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.mifosplatform.infrastructure.core.data.ApiParameterError;
|
||||
import org.mifosplatform.infrastructure.core.data.DataValidatorBuilder;
|
||||
import org.mifosplatform.infrastructure.core.exception.InvalidJsonException;
|
||||
import org.mifosplatform.infrastructure.core.serialization.AbstractFromApiJsonDeserializer;
|
||||
import org.mifosplatform.infrastructure.core.serialization.FromApiJsonDeserializer;
|
||||
import org.mifosplatform.infrastructure.core.exception.PlatformApiDataValidationException;
|
||||
import org.mifosplatform.infrastructure.core.serialization.FromJsonHelper;
|
||||
import org.mifosplatform.portfolio.fund.command.FundCommand;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
|
||||
/**
|
||||
* Implementation of {@link FromApiJsonDeserializer} for {@link FundCommand}'s.
|
||||
*/
|
||||
@Component
|
||||
public final class FundCommandFromApiJsonDeserializer extends AbstractFromApiJsonDeserializer<FundCommand> {
|
||||
public final class FundCommandFromApiJsonDeserializer {
|
||||
|
||||
/**
|
||||
* The parameters supported for this command.
|
||||
@@ -36,18 +35,51 @@ public final class FundCommandFromApiJsonDeserializer extends AbstractFromApiJso
|
||||
this.fromApiJsonHelper = fromApiJsonHelper;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FundCommand commandFromApiJson(final String json) {
|
||||
|
||||
public void validateForCreate(final String json) {
|
||||
if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); }
|
||||
|
||||
final Type typeOfMap = new TypeToken<Map<String, Object>>() {}.getType();
|
||||
fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, json, supportedParameters);
|
||||
|
||||
final JsonElement element = fromApiJsonHelper.parse(json);
|
||||
final String name = fromApiJsonHelper.extractStringNamed("name", element);
|
||||
final String externalId = fromApiJsonHelper.extractStringNamed("externalId", element);
|
||||
final List<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>();
|
||||
final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("code");
|
||||
|
||||
return new FundCommand(name, externalId);
|
||||
final JsonElement element = fromApiJsonHelper.parse(json);
|
||||
|
||||
final String name = fromApiJsonHelper.extractStringNamed("name", element);
|
||||
baseDataValidator.reset().parameter("name").value(name).notBlank().notExceedingLengthOf(255);
|
||||
|
||||
final String externalId = fromApiJsonHelper.extractStringNamed("externalId", element);
|
||||
baseDataValidator.reset().parameter("externalId").value(externalId).notExceedingLengthOf(255);
|
||||
|
||||
throwExceptionIfValidationWarningsExist(dataValidationErrors);
|
||||
}
|
||||
|
||||
public void validateForUpdate(final String json) {
|
||||
if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); }
|
||||
|
||||
final Type typeOfMap = new TypeToken<Map<String, Object>>() {}.getType();
|
||||
fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, json, supportedParameters);
|
||||
|
||||
final List<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>();
|
||||
final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("code");
|
||||
|
||||
final JsonElement element = fromApiJsonHelper.parse(json);
|
||||
if (fromApiJsonHelper.parameterExists("name", element)) {
|
||||
final String name = fromApiJsonHelper.extractStringNamed("name", element);
|
||||
baseDataValidator.reset().parameter("name").value(name).notBlank().notExceedingLengthOf(255);
|
||||
}
|
||||
|
||||
if (fromApiJsonHelper.parameterExists("externalId", element)) {
|
||||
final String externalId = fromApiJsonHelper.extractStringNamed("externalId", element);
|
||||
baseDataValidator.reset().parameter("externalId").value(externalId).notExceedingLengthOf(100);
|
||||
}
|
||||
|
||||
throwExceptionIfValidationWarningsExist(dataValidationErrors);
|
||||
}
|
||||
|
||||
private void throwExceptionIfValidationWarningsExist(final List<ApiParameterError> dataValidationErrors) {
|
||||
if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist",
|
||||
"Validation errors exist.", dataValidationErrors); }
|
||||
}
|
||||
}
|
||||
+7
-11
@@ -7,7 +7,6 @@ import org.mifosplatform.infrastructure.core.data.CommandProcessingResult;
|
||||
import org.mifosplatform.infrastructure.core.data.CommandProcessingResultBuilder;
|
||||
import org.mifosplatform.infrastructure.core.exception.PlatformDataIntegrityException;
|
||||
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
|
||||
import org.mifosplatform.portfolio.fund.command.FundCommand;
|
||||
import org.mifosplatform.portfolio.fund.domain.Fund;
|
||||
import org.mifosplatform.portfolio.fund.domain.FundRepository;
|
||||
import org.mifosplatform.portfolio.fund.exception.FundNotFoundException;
|
||||
@@ -30,8 +29,7 @@ public class FundWritePlatformServiceJpaRepositoryImpl implements FundWritePlatf
|
||||
|
||||
@Autowired
|
||||
public FundWritePlatformServiceJpaRepositoryImpl(final PlatformSecurityContext context,
|
||||
final FundCommandFromApiJsonDeserializer fromApiJsonDeserializer,
|
||||
final FundRepository fundRepository) {
|
||||
final FundCommandFromApiJsonDeserializer fromApiJsonDeserializer, final FundRepository fundRepository) {
|
||||
this.context = context;
|
||||
this.fromApiJsonDeserializer = fromApiJsonDeserializer;
|
||||
this.fundRepository = fundRepository;
|
||||
@@ -43,11 +41,10 @@ public class FundWritePlatformServiceJpaRepositoryImpl implements FundWritePlatf
|
||||
|
||||
try {
|
||||
context.authenticatedUser();
|
||||
|
||||
final FundCommand fundCommand = this.fromApiJsonDeserializer.commandFromApiJson(command.json());
|
||||
fundCommand.validateForCreate();
|
||||
|
||||
Fund fund = Fund.fromJson(command);
|
||||
this.fromApiJsonDeserializer.validateForCreate(command.json());
|
||||
|
||||
final Fund fund = Fund.fromJson(command);
|
||||
|
||||
this.fundRepository.save(fund);
|
||||
|
||||
@@ -64,13 +61,12 @@ public class FundWritePlatformServiceJpaRepositoryImpl implements FundWritePlatf
|
||||
|
||||
try {
|
||||
context.authenticatedUser();
|
||||
|
||||
final FundCommand fundCommand = this.fromApiJsonDeserializer.commandFromApiJson(command.json());
|
||||
fundCommand.validateForUpdate();
|
||||
|
||||
this.fromApiJsonDeserializer.validateForUpdate(command.json());
|
||||
|
||||
final Fund fund = this.fundRepository.findOne(fundId);
|
||||
if (fund == null) { throw new FundNotFoundException(fundId); }
|
||||
|
||||
|
||||
final Map<String, Object> changes = fund.update(command);
|
||||
if (!changes.isEmpty()) {
|
||||
this.fundRepository.saveAndFlush(fund);
|
||||
|
||||
Reference in New Issue
Block a user