updates to finanacial activity to account mapping api's

This commit is contained in:
Vishwas Babu A J
2014-06-11 13:36:03 -07:00
parent c2d94f2976
commit 06efcb73c9
25 changed files with 416 additions and 506 deletions
+23 -23
View File
@@ -1371,19 +1371,19 @@
</tr>
<tr>
<td><a href="#officeglaccount">Office GL Account Mappings</a></td>
<td>officeglaccounts</td>
<td><a href="#officeglaccounts_create">Create Office GL Account Mapping</a><br> </td>
<td><a href="#officeglaccounts_list">List Journal Entries</a></td>
<td>financialactivityaccounts</td>
<td><a href="#financialactivityaccounts_create">Create Office GL Account Mapping</a><br> </td>
<td><a href="#financialactivityaccounts_list">List Journal Entries</a></td>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td>officeglaccounts/{entryId}</td>
<td>financialactivityaccounts/{entryId}</td>
<td></td>
<td><a href="#officeglaccounts_retrieve">Retrieve a single Entry</a></td>
<td><a href="#officeglaccounts_update">Update Office GL Account Mapping</a></td>
<td><a href="#officeglaccounts_delete">Delete Office GL Account Mapping</a></td>
<td><a href="#financialactivityaccounts_retrieve">Retrieve a single Entry</a></td>
<td><a href="#financialactivityaccounts_update">Update Office GL Account Mapping</a></td>
<td><a href="#financialactivityaccounts_delete">Delete Office GL Account Mapping</a></td>
</tr>
@@ -28608,7 +28608,7 @@ Content-Type: application/json
</div>
</div>
<a id="officeglaccounts_list" name="officeglaccounts_list" class="old-syle-anchor">&nbsp;</a>
<a id="financialactivityaccounts_list" name="financialactivityaccounts_list" class="old-syle-anchor">&nbsp;</a>
<div class="method-section">
<div class="method-description">
<h4>List Office Level GL Account Mappings</h4>
@@ -28648,13 +28648,13 @@ Content-Type: application/json
</dl>
<p>Example Requests:</p>
<div class=apiClick>officeglaccounts</div>
<div class=apiClick>financialactivityaccounts</div>
<br>
<div class=apiClick>officeglaccounts?orderBy=id&sortOrder=DESC</div>
<div class=apiClick>financialactivityaccounts?orderBy=id&sortOrder=DESC</div>
</div>
<div class="method-example">
<code class="method-declaration">
GET https://DomainName/api/v1/officeglaccounts
GET https://DomainName/api/v1/financialactivityaccounts
</code>
<code class="method-response">
@@ -28677,7 +28677,7 @@ GET https://DomainName/api/v1/officeglaccounts
</div>
</div>
<a id="officeglaccounts_create" name="officeglaccounts_create" class="old-syle-anchor">&nbsp;</a>
<a id="financialactivityaccounts_create" name="financialactivityaccounts_create" class="old-syle-anchor">&nbsp;</a>
<div class="method-section">
<div class="method-description">
<h4>Create Office GL Account</h4>
@@ -28696,10 +28696,10 @@ GET https://DomainName/api/v1/officeglaccounts
</div>
<div class="method-example">
<code class="method-declaration">
POST https://DomainName/api/v1/officeglaccounts
POST https://DomainName/api/v1/financialactivityaccounts
</code>
<code class="method-request">
POST officeglaccounts
POST financialactivityaccounts
Content-Type: application/json
Request Body:
{
@@ -28715,7 +28715,7 @@ Request Body:
</div>
</div>
<a id="officeglaccounts_update" name="officeglaccounts_update" class="old-syle-anchor">&nbsp;</a>
<a id="financialactivityaccounts_update" name="financialactivityaccounts_update" class="old-syle-anchor">&nbsp;</a>
<div class="method-section">
<div class="method-description">
<h4>Update Office GL Account Mappings</h4>
@@ -28727,10 +28727,10 @@ Request Body:
</div>
<div class="method-example">
<code class="method-declaration">
POST https://DomainName/api/v1/officeglaccounts/1
POST https://DomainName/api/v1/financialactivityaccounts/1
</code>
<code class="method-request">
POST officeglaccounts
POST financialactivityaccounts
Content-Type: application/json
Request Body:
{
@@ -28747,18 +28747,18 @@ Request Body:
</div>
<a id="officeglaccounts_retrieve" name="officeglaccounts_retrieve"
<a id="financialactivityaccounts_retrieve" name="financialactivityaccounts_retrieve"
class="old-syle-anchor">&nbsp;</a>
<div class="method-section">
<div class="method-description">
<h4>Retrieve a single Entry</h4>
<p>Example Requests:</p>
<div class=apiClick>officeglaccounts/1</div>
<div class=apiClick>financialactivityaccounts/1</div>
<br>
</div>
<div class="method-example">
<code class="method-declaration">
GET https://DomainName/api/v1/officeglaccounts/{entryId}
GET https://DomainName/api/v1/financialactivityaccounts/{entryId}
</code>
<code class="method-response">
{
@@ -28777,7 +28777,7 @@ GET https://DomainName/api/v1/officeglaccounts/{entryId}
</div>
</div>
<a id="officeglaccounts_delete" name="officeglaccounts_delete"
<a id="financialactivityaccounts_delete" name="financialactivityaccounts_delete"
class="old-syle-anchor">&nbsp;</a>
<div class="method-section">
<div class="method-description">
@@ -28785,10 +28785,10 @@ GET https://DomainName/api/v1/officeglaccounts/{entryId}
</div>
<div class="method-example">
<code class="method-declaration">
GET https://DomainName/api/v1/officeglaccounts/{mappingId}
GET https://DomainName/api/v1/financialactivityaccounts/{mappingId}
</code>
<code class="method-request">
POST officeglaccounts/C1MAE935K0IAEYA?command=reverse
POST financialactivityaccounts/C1MAE935K0IAEYA?command=reverse
Content-Type: application/json
</code>
<code class="method-response">
@@ -0,0 +1,15 @@
ALTER TABLE acc_gl_office_mapping DROP FOREIGN KEY `FK_office_mapping_office`;
ALTER TABLE acc_gl_office_mapping DROP column office_id;
ALTER TABLE `acc_gl_office_mapping`
ALTER `financial_account_type` DROP DEFAULT;
ALTER TABLE `acc_gl_office_mapping`
CHANGE COLUMN `financial_account_type` `financial_activity_type` SMALLINT(5) NOT NULL;
ALTER TABLE `acc_gl_office_mapping`
ADD UNIQUE INDEX `financial_activity_type` (`financial_activity_type`);
RENAME TABLE `acc_gl_office_mapping` TO `acc_gl_financial_activity_account`;
@@ -7,6 +7,7 @@ package org.mifosplatform.accounting.accountmapping.api;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import javax.ws.rs.Consumes;
@@ -17,13 +18,12 @@ 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.mifosplatform.accounting.accountmapping.data.OfficeToGLAccountMappingData;
import org.mifosplatform.accounting.accountmapping.service.OfficeToGLAccountMappingReadPlatformService;
import org.mifosplatform.accounting.accountmapping.data.FinancialActivityAccountData;
import org.mifosplatform.accounting.accountmapping.service.FinancialActivityAccountReadPlatformService;
import org.mifosplatform.commands.domain.CommandWrapper;
import org.mifosplatform.commands.service.CommandWrapperBuilder;
import org.mifosplatform.commands.service.PortfolioCommandSourceWritePlatformService;
@@ -31,40 +31,38 @@ import org.mifosplatform.infrastructure.core.api.ApiRequestParameterHelper;
import org.mifosplatform.infrastructure.core.data.CommandProcessingResult;
import org.mifosplatform.infrastructure.core.serialization.ApiRequestJsonSerializationSettings;
import org.mifosplatform.infrastructure.core.serialization.DefaultToApiJsonSerializer;
import org.mifosplatform.infrastructure.core.service.Page;
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
import org.mifosplatform.portfolio.group.service.SearchParameters;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
@Path("/officeglaccounts")
@Path("/financialactivityaccounts")
@Component
@Scope("singleton")
public class OfficeGLAccountsApiResource {
public class FinancialActivityAccountsApiResource {
private static final Set<String> RESPONSE_DATA_PARAMETERS = new HashSet<String>(Arrays.asList("id", "officeData", "glAccountData",
"accountingMappingOptions", "officeOptions"));
private static final Set<String> RESPONSE_DATA_PARAMETERS = new HashSet<String>(Arrays.asList("id", "glAccountData",
"accountingMappingOptions"));
private final String resourceNameForPermission = "OFFICEGLACCOUNT";
private final OfficeToGLAccountMappingReadPlatformService officeToGLAccountMappingReadPlatformService;
private final DefaultToApiJsonSerializer<OfficeToGLAccountMappingData> apiJsonSerializerService;
private final FinancialActivityAccountReadPlatformService financialActivityAccountReadPlatformService;
private final DefaultToApiJsonSerializer<FinancialActivityAccountData> apiJsonSerializerService;
private final ApiRequestParameterHelper apiRequestParameterHelper;
private final PlatformSecurityContext context;
private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService;
@Autowired
public OfficeGLAccountsApiResource(final PlatformSecurityContext context,
final OfficeToGLAccountMappingReadPlatformService officeToGLAccountMappingReadPlatformService,
final DefaultToApiJsonSerializer<OfficeToGLAccountMappingData> toApiJsonSerializer,
public FinancialActivityAccountsApiResource(final PlatformSecurityContext context,
final FinancialActivityAccountReadPlatformService officeToGLAccountMappingReadPlatformService,
final DefaultToApiJsonSerializer<FinancialActivityAccountData> toApiJsonSerializer,
final ApiRequestParameterHelper apiRequestParameterHelper,
final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService) {
this.context = context;
this.apiRequestParameterHelper = apiRequestParameterHelper;
this.commandsSourceWritePlatformService = commandsSourceWritePlatformService;
this.apiJsonSerializerService = toApiJsonSerializer;
this.officeToGLAccountMappingReadPlatformService = officeToGLAccountMappingReadPlatformService;
this.financialActivityAccountReadPlatformService = officeToGLAccountMappingReadPlatformService;
}
@GET
@@ -75,7 +73,7 @@ public class OfficeGLAccountsApiResource {
this.context.authenticatedUser().validateHasReadPermission(this.resourceNameForPermission);
OfficeToGLAccountMappingData officeToGLAccountMappingData = this.officeToGLAccountMappingReadPlatformService.retrieveTemplate();
FinancialActivityAccountData officeToGLAccountMappingData = this.financialActivityAccountReadPlatformService.retrieveTemplate();
final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper.process(uriInfo.getQueryParameters());
return this.apiJsonSerializerService.serialize(settings, officeToGLAccountMappingData, RESPONSE_DATA_PARAMETERS);
@@ -84,18 +82,13 @@ public class OfficeGLAccountsApiResource {
@GET
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
public String retrieveAll(@Context final UriInfo uriInfo, @QueryParam("sqlSearch") final String sqlSearch,
@QueryParam("externalId") final String externalId, @QueryParam("offset") final Integer offset,
@QueryParam("limit") final Integer limit, @QueryParam("orderBy") final String orderBy,
@QueryParam("sortOrder") final String sortOrder) {
public String retrieveAll(@Context final UriInfo uriInfo) {
this.context.authenticatedUser().validateHasReadPermission(this.resourceNameForPermission);
final SearchParameters searchParameters = SearchParameters.forAccountTransfer(sqlSearch, externalId, offset, limit, orderBy,
sortOrder);
final Page<OfficeToGLAccountMappingData> mappings = this.officeToGLAccountMappingReadPlatformService.retrieveAll(searchParameters);
final List<FinancialActivityAccountData> financialActivityAccounts = this.financialActivityAccountReadPlatformService.retrieveAll();
final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper.process(uriInfo.getQueryParameters());
return this.apiJsonSerializerService.serialize(settings, mappings, RESPONSE_DATA_PARAMETERS);
return this.apiJsonSerializerService.serialize(settings, financialActivityAccounts, RESPONSE_DATA_PARAMETERS);
}
@GET
@@ -107,10 +100,10 @@ public class OfficeGLAccountsApiResource {
this.context.authenticatedUser().validateHasReadPermission(this.resourceNameForPermission);
final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper.process(uriInfo.getQueryParameters());
OfficeToGLAccountMappingData officeToGLAccountMappingData = this.officeToGLAccountMappingReadPlatformService.retrieve(mappingId);
FinancialActivityAccountData officeToGLAccountMappingData = this.financialActivityAccountReadPlatformService.retrieve(mappingId);
if (settings.isTemplate()) {
OfficeToGLAccountMappingData templateData = this.officeToGLAccountMappingReadPlatformService.retrieveTemplate();
officeToGLAccountMappingData = OfficeToGLAccountMappingData.associateTemplateData(templateData, officeToGLAccountMappingData);
FinancialActivityAccountData templateData = this.financialActivityAccountReadPlatformService.retrieveTemplate();
officeToGLAccountMappingData = FinancialActivityAccountData.associateTemplateData(templateData, officeToGLAccountMappingData);
}
return this.apiJsonSerializerService.serialize(settings, officeToGLAccountMappingData, RESPONSE_DATA_PARAMETERS);
@@ -0,0 +1,38 @@
package org.mifosplatform.accounting.accountmapping.data;
import java.util.List;
import java.util.Map;
import org.mifosplatform.accounting.glaccount.data.GLAccountData;
public class FinancialActivityAccountData {
private final Long id;
private final GLAccountData glAccountData;
private final Map<String, List<GLAccountData>> accountingMappingOptions;
public static FinancialActivityAccountData instance(final Long id, final GLAccountData glAccountData) {
final Map<String, List<GLAccountData>> accountingMappingOptions = null;
return new FinancialActivityAccountData(id, glAccountData, accountingMappingOptions);
}
public static FinancialActivityAccountData template(final Map<String, List<GLAccountData>> accountingMappingOptions) {
final Long id = null;
final GLAccountData glAccountData = null;
return new FinancialActivityAccountData(id, glAccountData, accountingMappingOptions);
}
public static FinancialActivityAccountData associateTemplateData(final FinancialActivityAccountData templateData,
final FinancialActivityAccountData accountMappingData) {
return new FinancialActivityAccountData(accountMappingData.id, accountMappingData.glAccountData,
templateData.accountingMappingOptions);
}
private FinancialActivityAccountData(final Long id, final GLAccountData glAccountData,
final Map<String, List<GLAccountData>> accountingMappingOptions) {
this.id = id;
this.glAccountData = glAccountData;
this.accountingMappingOptions = accountingMappingOptions;
}
}
@@ -1,47 +0,0 @@
package org.mifosplatform.accounting.accountmapping.data;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import org.mifosplatform.accounting.glaccount.data.GLAccountData;
import org.mifosplatform.organisation.office.data.OfficeData;
public class OfficeToGLAccountMappingData {
private final Long id;
private final OfficeData officeData;
private final GLAccountData glAccountData;
private final Map<String, List<GLAccountData>> accountingMappingOptions;
private final Collection<OfficeData> officeOptions;
public static OfficeToGLAccountMappingData instance(final Long id, final OfficeData officeData, final GLAccountData glAccountData) {
final Map<String, List<GLAccountData>> accountingMappingOptions = null;
final Collection<OfficeData> officeOptions = null;
return new OfficeToGLAccountMappingData(id, officeData, glAccountData, accountingMappingOptions, officeOptions);
}
public static OfficeToGLAccountMappingData template(final Map<String, List<GLAccountData>> accountingMappingOptions,
final Collection<OfficeData> officeOptions) {
final Long id = null;
final OfficeData officeData = null;
final GLAccountData glAccountData = null;
return new OfficeToGLAccountMappingData(id, officeData, glAccountData, accountingMappingOptions, officeOptions);
}
public static OfficeToGLAccountMappingData associateTemplateData(final OfficeToGLAccountMappingData templateData,
final OfficeToGLAccountMappingData accountMappingData) {
return new OfficeToGLAccountMappingData(accountMappingData.id, accountMappingData.officeData, accountMappingData.glAccountData,
templateData.accountingMappingOptions, templateData.officeOptions);
}
private OfficeToGLAccountMappingData(final Long id, final OfficeData officeData, final GLAccountData glAccountData,
final Map<String, List<GLAccountData>> accountingMappingOptions, final Collection<OfficeData> officeOptions) {
this.id = id;
this.officeData = officeData;
this.glAccountData = glAccountData;
this.accountingMappingOptions = accountingMappingOptions;
this.officeOptions = officeOptions;
}
}
@@ -0,0 +1,54 @@
/**
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package org.mifosplatform.accounting.accountmapping.domain;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import org.mifosplatform.accounting.glaccount.domain.GLAccount;
import org.springframework.data.jpa.domain.AbstractPersistable;
@Entity
@Table(name = "acc_gl_financial_activity_account")
public class FinancialActivityAccount extends AbstractPersistable<Long> {
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "gl_account_id")
private GLAccount glAccount;
@Column(name = "financial_activity_type", nullable = false)
private int financialActivityType;
public static FinancialActivityAccount createNew(final GLAccount glAccount, final int financialAccountType) {
return new FinancialActivityAccount(glAccount, financialAccountType);
}
protected FinancialActivityAccount() {
//
}
private FinancialActivityAccount(final GLAccount glAccount, final int financialAccountType) {
this.glAccount = glAccount;
this.financialActivityType = financialAccountType;
}
public GLAccount glAccount() {
return this.glAccount;
}
public void updateGlAccount(final GLAccount glAccount) {
this.glAccount = glAccount;
}
public int getFinancialActivityType() {
return this.financialActivityType;
}
}
@@ -0,0 +1,19 @@
/**
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package org.mifosplatform.accounting.accountmapping.domain;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
public interface FinancialActivityAccountRepository extends JpaRepository<FinancialActivityAccount, Long>,
JpaSpecificationExecutor<FinancialActivityAccount> {
@Query("from FinancialActivityAccount faa where faa.financialActivityType = :financialActivityType")
FinancialActivityAccount findByFinancialActivityType(@Param("financialActivityType") int financialAccountType);
}
@@ -0,0 +1,55 @@
/**
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package org.mifosplatform.accounting.accountmapping.domain;
import java.util.List;
import org.mifosplatform.accounting.accountmapping.exception.FinancialActivityAccountNotFoundException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
* <p>
* Wrapper for {@link FinancialActivityAccountRepository} that adds NULL
* checking and Error handling capabilities
* </p>
*/
@Service
public class FinancialActivityAccountRepositoryWrapper {
private final FinancialActivityAccountRepository repository;
@Autowired
public FinancialActivityAccountRepositoryWrapper(final FinancialActivityAccountRepository repository) {
this.repository = repository;
}
public FinancialActivityAccount findOneWithNotFoundDetection(final Long id) {
final FinancialActivityAccount financialActivityAccount = this.repository.findOne(id);
if (financialActivityAccount == null) { throw new FinancialActivityAccountNotFoundException(id); }
return financialActivityAccount;
}
public FinancialActivityAccount findByFinancialActivityType(final int financialActivityType) {
return this.repository.findByFinancialActivityType(financialActivityType);
}
public List<FinancialActivityAccount> findAll() {
return this.repository.findAll();
}
public void save(final FinancialActivityAccount entity) {
this.repository.save(entity);
}
public void saveAndFlush(final FinancialActivityAccount entity) {
this.repository.saveAndFlush(entity);
}
public void delete(final FinancialActivityAccount entity) {
this.repository.delete(entity);
}
}
@@ -1,69 +0,0 @@
/**
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package org.mifosplatform.accounting.accountmapping.domain;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import org.mifosplatform.accounting.glaccount.domain.GLAccount;
import org.mifosplatform.organisation.office.domain.Office;
import org.springframework.data.jpa.domain.AbstractPersistable;
@Entity
@Table(name = "acc_gl_office_mapping")
public class OfficeToGLAccountMapping extends AbstractPersistable<Long> {
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "gl_account_id")
private GLAccount glAccount;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "office_id")
private Office office;
@Column(name = "financial_account_type", nullable = false)
private int financialAccountType;
public static OfficeToGLAccountMapping createNew(final GLAccount glAccount, final Office office, final int financialAccountType) {
return new OfficeToGLAccountMapping(glAccount, office, financialAccountType);
}
protected OfficeToGLAccountMapping() {
//
}
private OfficeToGLAccountMapping(final GLAccount glAccount, final Office office, final int financialAccountType) {
this.glAccount = glAccount;
this.office = office;
this.financialAccountType = financialAccountType;
}
public GLAccount glAccount() {
return this.glAccount;
}
public void updateGlAccount(final GLAccount glAccount) {
this.glAccount = glAccount;
}
public Office office() {
return this.office;
}
public void updateOffice(Office office) {
this.office = office;
}
public int getFinancialAccountType() {
return this.financialAccountType;
}
}
@@ -1,23 +0,0 @@
/**
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package org.mifosplatform.accounting.accountmapping.domain;
import java.util.List;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
public interface OfficeToGLAccountMappingRepository extends JpaRepository<OfficeToGLAccountMapping, Long>,
JpaSpecificationExecutor<OfficeToGLAccountMapping> {
@Query("from OfficeToGLAccountMapping otga where otga.office.id = :officeId and otga.financialAccountType = :financialAccountType")
OfficeToGLAccountMapping findByOfficeAndFinancialAccountType(@Param("officeId")Long officeId,@Param("financialAccountType") int financialAccountType);
@Query("from OfficeToGLAccountMapping otga where otga.office.id =:officeId")
List<OfficeToGLAccountMapping> findByOffice(@Param("officeId")Long officeId);
}
@@ -1,55 +0,0 @@
/**
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package org.mifosplatform.accounting.accountmapping.domain;
import java.util.List;
import org.mifosplatform.accounting.accountmapping.exception.OfficeToGLAccountMappingNotFoundException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
* <p>
* Wrapper for {@link OfficeToGLAccountMappingRepository} that adds NULL
* checking and Error handling capabilities
* </p>
*/
@Service
public class OfficeToGLAccountMappingRepositoryWrapper {
private final OfficeToGLAccountMappingRepository repository;
@Autowired
public OfficeToGLAccountMappingRepositoryWrapper(final OfficeToGLAccountMappingRepository repository) {
this.repository = repository;
}
public OfficeToGLAccountMapping findOneWithNotFoundDetection(final Long id) {
final OfficeToGLAccountMapping officeToGLAccountMapping = this.repository.findOne(id);
if (officeToGLAccountMapping == null) { throw new OfficeToGLAccountMappingNotFoundException(id); }
return officeToGLAccountMapping;
}
public OfficeToGLAccountMapping findByOfficeAndFinancialAccountType(final Long officeId, final int financialAccountType) {
return this.repository.findByOfficeAndFinancialAccountType(officeId, financialAccountType);
}
public List<OfficeToGLAccountMapping> findByOffice(final Long officeId) {
return this.repository.findByOffice(officeId);
}
public void save(final OfficeToGLAccountMapping entity) {
this.repository.save(entity);
}
public void saveAndFlush(final OfficeToGLAccountMapping entity) {
this.repository.saveAndFlush(entity);
}
public void delete(final OfficeToGLAccountMapping entity) {
this.repository.delete(entity);
}
}
@@ -11,11 +11,11 @@ import org.mifosplatform.infrastructure.core.exception.AbstractPlatformDomainRul
* A {@link RuntimeException} thrown when product to GL account mapping are not
* found.
*/
public class DuplicateOfficeToGLAccountMappingFoundException extends AbstractPlatformDomainRuleException {
public class DuplicateFinancialActivityAccountFoundException extends AbstractPlatformDomainRuleException {
public DuplicateOfficeToGLAccountMappingFoundException(final Long officeId, final Integer accountType) {
super("error.msg.officeToAccountMapping.exists.for.office", "Mapping for office with Id " + officeId
+ " exist for an account of type " + accountType, officeId, accountType);
public DuplicateFinancialActivityAccountFoundException(final Integer financialActivityType) {
super("error.msg.officeToAccountMapping.exists.for.office", "Mapping for activity already exists " + financialActivityType,
financialActivityType);
}
}
@@ -11,14 +11,14 @@ import org.mifosplatform.infrastructure.core.exception.AbstractPlatformResourceN
* A {@link RuntimeException} thrown when product to GL account mapping are not
* found.
*/
public class OfficeToGLAccountMappingNotFoundException extends AbstractPlatformResourceNotFoundException {
public class FinancialActivityAccountNotFoundException extends AbstractPlatformResourceNotFoundException {
public OfficeToGLAccountMappingNotFoundException(final Long officeId, final String accountType) {
public FinancialActivityAccountNotFoundException(final Long officeId, final String accountType) {
super("error.msg.officeToAccountMapping.not.found", "Mapping for office with Id " + officeId
+ " does not exist for an account of type " + accountType, officeId, accountType);
}
public OfficeToGLAccountMappingNotFoundException(final Long id) {
public FinancialActivityAccountNotFoundException(final Long id) {
super("error.msg.officeToAccountMapping.not.found", "Mapping for GL Account with Id " + id + " does not exist", id);
}
}
@@ -5,7 +5,7 @@
*/
package org.mifosplatform.accounting.accountmapping.handler;
import org.mifosplatform.accounting.accountmapping.service.OfficeToGLAccountMappingWritePlatformService;
import org.mifosplatform.accounting.accountmapping.service.FinancialActivityAccountWritePlatformService;
import org.mifosplatform.commands.handler.NewCommandSourceHandler;
import org.mifosplatform.infrastructure.core.api.JsonCommand;
import org.mifosplatform.infrastructure.core.data.CommandProcessingResult;
@@ -14,12 +14,12 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@Service
public class CreateOfficeToGLAccountMappingHandler implements NewCommandSourceHandler {
public class CreateFinancialActivityAccountHandler implements NewCommandSourceHandler {
private final OfficeToGLAccountMappingWritePlatformService writePlatformService;
private final FinancialActivityAccountWritePlatformService writePlatformService;
@Autowired
public CreateOfficeToGLAccountMappingHandler(final OfficeToGLAccountMappingWritePlatformService writePlatformService) {
public CreateFinancialActivityAccountHandler(final FinancialActivityAccountWritePlatformService writePlatformService) {
this.writePlatformService = writePlatformService;
}
@@ -27,6 +27,6 @@ public class CreateOfficeToGLAccountMappingHandler implements NewCommandSourceHa
@Override
public CommandProcessingResult processCommand(final JsonCommand command) {
return this.writePlatformService.createGLAccountMapping(command);
return this.writePlatformService.createGLAccountActivityMapping(command);
}
}
@@ -5,7 +5,7 @@
*/
package org.mifosplatform.accounting.accountmapping.handler;
import org.mifosplatform.accounting.accountmapping.service.OfficeToGLAccountMappingWritePlatformService;
import org.mifosplatform.accounting.accountmapping.service.FinancialActivityAccountWritePlatformService;
import org.mifosplatform.commands.handler.NewCommandSourceHandler;
import org.mifosplatform.infrastructure.core.api.JsonCommand;
import org.mifosplatform.infrastructure.core.data.CommandProcessingResult;
@@ -14,18 +14,18 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@Service
public class DeleteOfficeToGLAccountMappingCommandHandler implements NewCommandSourceHandler {
public class DeleteFinancialActivityAccountCommandHandler implements NewCommandSourceHandler {
private final OfficeToGLAccountMappingWritePlatformService writePlatformService;
private final FinancialActivityAccountWritePlatformService writePlatformService;
@Autowired
public DeleteOfficeToGLAccountMappingCommandHandler(final OfficeToGLAccountMappingWritePlatformService writePlatformService) {
public DeleteFinancialActivityAccountCommandHandler(final FinancialActivityAccountWritePlatformService writePlatformService) {
this.writePlatformService = writePlatformService;
}
@Transactional
@Override
public CommandProcessingResult processCommand(final JsonCommand command) {
return this.writePlatformService.deleteGLAccountMapping(command.entityId(), command);
return this.writePlatformService.deleteGLAccountActivityMapping(command.entityId(), command);
}
}
@@ -5,7 +5,7 @@
*/
package org.mifosplatform.accounting.accountmapping.handler;
import org.mifosplatform.accounting.accountmapping.service.OfficeToGLAccountMappingWritePlatformService;
import org.mifosplatform.accounting.accountmapping.service.FinancialActivityAccountWritePlatformService;
import org.mifosplatform.commands.handler.NewCommandSourceHandler;
import org.mifosplatform.infrastructure.core.api.JsonCommand;
import org.mifosplatform.infrastructure.core.data.CommandProcessingResult;
@@ -14,18 +14,18 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@Service
public class UpdateOfficeToGLAccountMappingCommandHandler implements NewCommandSourceHandler {
public class UpdateFinancialActivityAccountCommandHandler implements NewCommandSourceHandler {
private final OfficeToGLAccountMappingWritePlatformService writePlatformService;
private final FinancialActivityAccountWritePlatformService writePlatformService;
@Autowired
public UpdateOfficeToGLAccountMappingCommandHandler(final OfficeToGLAccountMappingWritePlatformService writePlatformService) {
public UpdateFinancialActivityAccountCommandHandler(final FinancialActivityAccountWritePlatformService writePlatformService) {
this.writePlatformService = writePlatformService;
}
@Transactional
@Override
public CommandProcessingResult processCommand(final JsonCommand command) {
return this.writePlatformService.updateGLAccountMapping(command.entityId(), command);
return this.writePlatformService.updateGLAccountActivityMapping(command.entityId(), command);
}
}
@@ -27,18 +27,18 @@ import com.google.gson.JsonElement;
import com.google.gson.reflect.TypeToken;
@Component
public final class OfficeToGLAccountMappingDataValidator {
public final class FinancialActivityAccountDataValidator {
/**
* The parameters supported for this command.
*/
private final Set<String> supportedParameters = new HashSet<String>(Arrays.asList("locale",
ORGANIZATION_ACCOUNTING_PARAMS.LIABILITY_TRANSFER_SUSPENSE.getValue(), "officeId"));
ORGANIZATION_ACCOUNTING_PARAMS.LIABILITY_TRANSFER_SUSPENSE.getValue()));
private final FromJsonHelper fromApiJsonHelper;
@Autowired
public OfficeToGLAccountMappingDataValidator(final FromJsonHelper fromApiJsonHelper) {
public FinancialActivityAccountDataValidator(final FromJsonHelper fromApiJsonHelper) {
this.fromApiJsonHelper = fromApiJsonHelper;
}
@@ -58,9 +58,6 @@ public final class OfficeToGLAccountMappingDataValidator {
baseDataValidator.reset().parameter(ORGANIZATION_ACCOUNTING_PARAMS.LIABILITY_TRANSFER_SUSPENSE.getValue())
.value(liabilityTransferInSuspenseAccountId).notNull().integerGreaterThanZero();
final Long officeID = this.fromApiJsonHelper.extractLongNamed("officeId", element);
baseDataValidator.reset().parameter("officeId").value(officeID).notNull().integerGreaterThanZero();
throwExceptionIfValidationWarningsExist(dataValidationErrors);
}
@@ -82,11 +79,6 @@ public final class OfficeToGLAccountMappingDataValidator {
.value(liabilityTransferInSuspenseAccountId).notNull().integerGreaterThanZero();
}
if (this.fromApiJsonHelper.parameterExists("officeId", element)) {
final Long officeID = this.fromApiJsonHelper.extractLongNamed("officeId", element);
baseDataValidator.reset().parameter("officeId").value(officeID).notNull().integerGreaterThanZero();
}
throwExceptionIfValidationWarningsExist(dataValidationErrors);
}
@@ -0,0 +1,20 @@
/**
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package org.mifosplatform.accounting.accountmapping.service;
import java.util.List;
import org.mifosplatform.accounting.accountmapping.data.FinancialActivityAccountData;
public interface FinancialActivityAccountReadPlatformService {
List<FinancialActivityAccountData> retrieveAll();
FinancialActivityAccountData retrieve(Long mappingId);
FinancialActivityAccountData retrieveTemplate();
}
@@ -0,0 +1,91 @@
package org.mifosplatform.accounting.accountmapping.service;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
import java.util.Map;
import org.mifosplatform.accounting.accountmapping.data.FinancialActivityAccountData;
import org.mifosplatform.accounting.accountmapping.exception.FinancialActivityAccountNotFoundException;
import org.mifosplatform.accounting.common.AccountingDropdownReadPlatformService;
import org.mifosplatform.accounting.glaccount.data.GLAccountData;
import org.mifosplatform.infrastructure.core.domain.JdbcSupport;
import org.mifosplatform.infrastructure.core.service.RoutingDataSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Service;
@Service
public class FinancialActivityAccountReadPlatformServiceImpl implements FinancialActivityAccountReadPlatformService {
private final JdbcTemplate jdbcTemplate;
private final FinancialActivityAccountMapper financialActivityAccountMapper;
private final AccountingDropdownReadPlatformService accountingDropdownReadPlatformService;
@Autowired
public FinancialActivityAccountReadPlatformServiceImpl(final RoutingDataSource dataSource,
final AccountingDropdownReadPlatformService accountingDropdownReadPlatformService) {
financialActivityAccountMapper = new FinancialActivityAccountMapper();
this.jdbcTemplate = new JdbcTemplate(dataSource);
this.accountingDropdownReadPlatformService = accountingDropdownReadPlatformService;
}
@Override
public List<FinancialActivityAccountData> retrieveAll() {
String sql = "select " + financialActivityAccountMapper.schema();
return this.jdbcTemplate.query(sql, financialActivityAccountMapper, new Object[] {});
}
@Override
public FinancialActivityAccountData retrieve(Long mappingId) {
try {
StringBuilder sqlBuilder = new StringBuilder(200);
sqlBuilder.append("select ");
sqlBuilder.append(this.financialActivityAccountMapper.schema());
sqlBuilder.append(" where faa.id=?");
return this.jdbcTemplate.queryForObject(sqlBuilder.toString(), this.financialActivityAccountMapper, new Object[] { mappingId });
} catch (final EmptyResultDataAccessException e) {
throw new FinancialActivityAccountNotFoundException(mappingId);
}
}
@Override
public FinancialActivityAccountData retrieveTemplate() {
final Map<String, List<GLAccountData>> accountOptions = this.accountingDropdownReadPlatformService.retrieveAccountMappingOptions();
return FinancialActivityAccountData.template(accountOptions);
}
private static final class FinancialActivityAccountMapper implements RowMapper<FinancialActivityAccountData> {
private final String sql;
public FinancialActivityAccountMapper() {
StringBuilder sb = new StringBuilder(300);
sb.append(" faa.id , glaccount.id as glAccountId,glaccount.name as glAccountName,glaccount.gl_code as glCode ");
sb.append(" from acc_gl_financial_activity_account faa ");
sb.append(" join acc_gl_account glaccount on glaccount.id = faa.gl_account_id");
sql = sb.toString();
}
public String schema() {
return sql;
}
@Override
public FinancialActivityAccountData mapRow(final ResultSet rs, @SuppressWarnings("unused") final int rowNum) throws SQLException {
final Long id = JdbcSupport.getLong(rs, "id");
final Long glAccountId = JdbcSupport.getLong(rs, "glAccountId");
final String glAccountName = rs.getString("glAccountName");
final String glCode = rs.getString("glCode");
final GLAccountData gLAccountData = new GLAccountData(glAccountId, glAccountName, glCode);
final FinancialActivityAccountData accountMappingData = FinancialActivityAccountData.instance(id, gLAccountData);
return accountMappingData;
}
}
}
@@ -8,12 +8,12 @@ package org.mifosplatform.accounting.accountmapping.service;
import org.mifosplatform.infrastructure.core.api.JsonCommand;
import org.mifosplatform.infrastructure.core.data.CommandProcessingResult;
public interface OfficeToGLAccountMappingWritePlatformService {
public interface FinancialActivityAccountWritePlatformService {
CommandProcessingResult createGLAccountMapping(JsonCommand command);
CommandProcessingResult createGLAccountActivityMapping(JsonCommand command);
CommandProcessingResult updateGLAccountMapping(Long mappingId, JsonCommand command);
CommandProcessingResult updateGLAccountActivityMapping(Long mappingId, JsonCommand command);
CommandProcessingResult deleteGLAccountMapping(Long mappingId, JsonCommand command);
CommandProcessingResult deleteGLAccountActivityMapping(Long mappingId, JsonCommand command);
}
@@ -3,11 +3,10 @@ package org.mifosplatform.accounting.accountmapping.service;
import java.util.HashMap;
import java.util.Map;
import org.mifosplatform.accounting.accountmapping.domain.OfficeToGLAccountMapping;
import org.mifosplatform.accounting.accountmapping.domain.OfficeToGLAccountMappingRepositoryWrapper;
import org.mifosplatform.accounting.accountmapping.exception.DuplicateOfficeToGLAccountMappingFoundException;
import org.mifosplatform.accounting.accountmapping.exception.MappingUpdateNotSupportedException;
import org.mifosplatform.accounting.accountmapping.serialization.OfficeToGLAccountMappingDataValidator;
import org.mifosplatform.accounting.accountmapping.domain.FinancialActivityAccount;
import org.mifosplatform.accounting.accountmapping.domain.FinancialActivityAccountRepositoryWrapper;
import org.mifosplatform.accounting.accountmapping.exception.DuplicateFinancialActivityAccountFoundException;
import org.mifosplatform.accounting.accountmapping.serialization.FinancialActivityAccountDataValidator;
import org.mifosplatform.accounting.common.AccountingConstants.ORGANIZATION_ACCOUNTING_PARAMS;
import org.mifosplatform.accounting.common.AccountingConstants.ORGANIZATION_ACCOUNTS;
import org.mifosplatform.accounting.glaccount.domain.GLAccount;
@@ -18,72 +17,64 @@ import org.mifosplatform.infrastructure.core.api.JsonCommand;
import org.mifosplatform.infrastructure.core.data.CommandProcessingResult;
import org.mifosplatform.infrastructure.core.data.CommandProcessingResultBuilder;
import org.mifosplatform.infrastructure.core.serialization.FromJsonHelper;
import org.mifosplatform.organisation.office.domain.Office;
import org.mifosplatform.organisation.office.domain.OfficeRepositoryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.google.gson.JsonElement;
@Service
public class OfficeToGLAccountMappingWritePlatformServiceImpl implements OfficeToGLAccountMappingWritePlatformService {
public class FinancialActivityAccountWritePlatformServiceImpl implements FinancialActivityAccountWritePlatformService {
private final OfficeToGLAccountMappingRepositoryWrapper accountMappingRepository;
private final OfficeToGLAccountMappingDataValidator fromApiJsonDeserializer;
private final FinancialActivityAccountRepositoryWrapper financialActivityAccountRepository;
private final FinancialActivityAccountDataValidator fromApiJsonDeserializer;
private final FromJsonHelper fromApiJsonHelper;
private final GLAccountRepositoryWrapper glAccountRepositoryWrapper;
private final OfficeRepositoryWrapper officeRepositoryWrapper;
@Autowired
public OfficeToGLAccountMappingWritePlatformServiceImpl(final OfficeToGLAccountMappingRepositoryWrapper accountMappingRepository,
final OfficeToGLAccountMappingDataValidator fromApiJsonDeserializer, final FromJsonHelper fromApiJsonHelper,
final GLAccountRepositoryWrapper glAccountRepositoryWrapper, final OfficeRepositoryWrapper officeRepositoryWrapper) {
this.accountMappingRepository = accountMappingRepository;
public FinancialActivityAccountWritePlatformServiceImpl(
final FinancialActivityAccountRepositoryWrapper financialActivityAccountRepository,
final FinancialActivityAccountDataValidator fromApiJsonDeserializer, final FromJsonHelper fromApiJsonHelper,
final GLAccountRepositoryWrapper glAccountRepositoryWrapper) {
this.financialActivityAccountRepository = financialActivityAccountRepository;
this.fromApiJsonDeserializer = fromApiJsonDeserializer;
this.fromApiJsonHelper = fromApiJsonHelper;
this.glAccountRepositoryWrapper = glAccountRepositoryWrapper;
this.officeRepositoryWrapper = officeRepositoryWrapper;
}
@Override
public CommandProcessingResult createGLAccountMapping(JsonCommand command) {
public CommandProcessingResult createGLAccountActivityMapping(JsonCommand command) {
this.fromApiJsonDeserializer.validateForCreate(command.json());
final JsonElement element = this.fromApiJsonHelper.parse(command.json());
final Long officeId = this.fromApiJsonHelper.extractLongNamed("officeId", element);
final Office office = this.officeRepositoryWrapper.findOneWithNotFoundDetection(officeId);
OfficeToGLAccountMapping accountMapping = createLiabilityTrasferSuspenceMapping(office, element);
checkForExistingMapping(accountMapping);
this.accountMappingRepository.save(accountMapping);
FinancialActivityAccount financialActivityAccount = createLiabilityTrasferSuspenceMapping(element);
checkForExistingMapping(financialActivityAccount);
this.financialActivityAccountRepository.save(financialActivityAccount);
return new CommandProcessingResultBuilder() //
.withCommandId(command.commandId()) //
.withEntityId(accountMapping.getId()) //
.withEntityId(financialActivityAccount.getId()) //
.build();
}
private void checkForExistingMapping(final OfficeToGLAccountMapping accountMapping) {
OfficeToGLAccountMapping existingMapping = this.accountMappingRepository.findByOfficeAndFinancialAccountType(accountMapping
.office().getId(), accountMapping.getFinancialAccountType());
if (existingMapping != null && !existingMapping.getId().equals(accountMapping.getId())) { throw new DuplicateOfficeToGLAccountMappingFoundException(
accountMapping.office().getId(), accountMapping.getFinancialAccountType()); }
private void checkForExistingMapping(final FinancialActivityAccount financialActivityAccount) {
FinancialActivityAccount existingMapping = this.financialActivityAccountRepository
.findByFinancialActivityType(financialActivityAccount.getFinancialActivityType());
if (existingMapping != null) { throw new DuplicateFinancialActivityAccountFoundException(
financialActivityAccount.getFinancialActivityType()); }
}
@Override
public CommandProcessingResult updateGLAccountMapping(Long mappingId, JsonCommand command) {
public CommandProcessingResult updateGLAccountActivityMapping(Long mappingId, JsonCommand command) {
this.fromApiJsonDeserializer.validateForUpdate(command.json());
final OfficeToGLAccountMapping officeToGLAccountMapping = this.accountMappingRepository.findOneWithNotFoundDetection(mappingId);
Map<String, Object> changes = findChanges(command, officeToGLAccountMapping);
final FinancialActivityAccount financialActivityAccount = this.financialActivityAccountRepository
.findOneWithNotFoundDetection(mappingId);
Map<String, Object> changes = findChanges(command, financialActivityAccount);
final JsonElement element = this.fromApiJsonHelper.parse(command.json());
if (changes.containsKey(ORGANIZATION_ACCOUNTING_PARAMS.LIABILITY_TRANSFER_SUSPENSE.getValue())) {
final GLAccount glAccount = fetchGLAccount(element, ORGANIZATION_ACCOUNTING_PARAMS.LIABILITY_TRANSFER_SUSPENSE.getValue(),
GLAccountType.LIABILITY);
officeToGLAccountMapping.updateGlAccount(glAccount);
}
if (!changes.isEmpty()) {
checkForExistingMapping(officeToGLAccountMapping);
this.accountMappingRepository.save(officeToGLAccountMapping);
financialActivityAccount.updateGlAccount(glAccount);
this.financialActivityAccountRepository.save(financialActivityAccount);
}
return new CommandProcessingResultBuilder() //
.withCommandId(command.commandId()) //
@@ -93,20 +84,21 @@ public class OfficeToGLAccountMappingWritePlatformServiceImpl implements OfficeT
}
@Override
public CommandProcessingResult deleteGLAccountMapping(Long mappingId, JsonCommand command) {
final OfficeToGLAccountMapping officeToGLAccountMapping = this.accountMappingRepository.findOneWithNotFoundDetection(mappingId);
this.accountMappingRepository.delete(officeToGLAccountMapping);
public CommandProcessingResult deleteGLAccountActivityMapping(Long mappingId, JsonCommand command) {
final FinancialActivityAccount officeToGLAccountMapping = this.financialActivityAccountRepository
.findOneWithNotFoundDetection(mappingId);
this.financialActivityAccountRepository.delete(officeToGLAccountMapping);
return new CommandProcessingResultBuilder() //
.withCommandId(command.commandId()) //
.withEntityId(mappingId) //
.build();
}
private OfficeToGLAccountMapping createLiabilityTrasferSuspenceMapping(final Office office, final JsonElement element) {
private FinancialActivityAccount createLiabilityTrasferSuspenceMapping(final JsonElement element) {
final GLAccount glAccount = fetchGLAccount(element, ORGANIZATION_ACCOUNTING_PARAMS.LIABILITY_TRANSFER_SUSPENSE.getValue(),
GLAccountType.LIABILITY);
final Integer financialAccountType = ORGANIZATION_ACCOUNTS.LIABILITY_TRANSFER_SUSPENSE.getValue();
return OfficeToGLAccountMapping.createNew(glAccount, office, financialAccountType);
return FinancialActivityAccount.createNew(glAccount, financialAccountType);
}
private GLAccount fetchGLAccount(final JsonElement element, final String paramName, final GLAccountType expectedAccountType) {
@@ -133,19 +125,11 @@ public class OfficeToGLAccountMappingWritePlatformServiceImpl implements OfficeT
return glAccount;
}
public Map<String, Object> findChanges(JsonCommand command, OfficeToGLAccountMapping accountMapping) {
public Map<String, Object> findChanges(JsonCommand command, FinancialActivityAccount financialActivityAccount) {
Map<String, Object> changes = new HashMap<String, Object>();
final String officeParamName = "officeId";
Long existingOfficeId = accountMapping.office().getId();
if (command.isChangeInLongParameterNamed(officeParamName, existingOfficeId)) {
final Long newValue = command.longValueOfParameterNamed(officeParamName);
String defaultMsg = "Office updating not allowed ";
throw new MappingUpdateNotSupportedException("officeId", defaultMsg, newValue,existingOfficeId,accountMapping.getId());
}
Long existingGLAccountId = accountMapping.glAccount().getId();
Long existingGLAccountId = financialActivityAccount.glAccount().getId();
if (command
.isChangeInLongParameterNamed(ORGANIZATION_ACCOUNTING_PARAMS.LIABILITY_TRANSFER_SUSPENSE.getValue(), existingGLAccountId)) {
final Long newValue = command.longValueOfParameterNamed(ORGANIZATION_ACCOUNTING_PARAMS.LIABILITY_TRANSFER_SUSPENSE.getValue());
@@ -1,21 +0,0 @@
/**
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package org.mifosplatform.accounting.accountmapping.service;
import org.mifosplatform.accounting.accountmapping.data.OfficeToGLAccountMappingData;
import org.mifosplatform.infrastructure.core.service.Page;
import org.mifosplatform.portfolio.group.service.SearchParameters;
public interface OfficeToGLAccountMappingReadPlatformService {
Page<OfficeToGLAccountMappingData> retrieveAll(final SearchParameters searchParameters);
OfficeToGLAccountMappingData retrieve(Long mappingId);
OfficeToGLAccountMappingData retrieveTemplate();
}
@@ -1,136 +0,0 @@
package org.mifosplatform.accounting.accountmapping.service;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import org.joda.time.LocalDate;
import org.mifosplatform.accounting.accountmapping.data.OfficeToGLAccountMappingData;
import org.mifosplatform.accounting.accountmapping.exception.OfficeToGLAccountMappingNotFoundException;
import org.mifosplatform.accounting.common.AccountingDropdownReadPlatformService;
import org.mifosplatform.accounting.glaccount.data.GLAccountData;
import org.mifosplatform.infrastructure.core.domain.JdbcSupport;
import org.mifosplatform.infrastructure.core.service.Page;
import org.mifosplatform.infrastructure.core.service.PaginationHelper;
import org.mifosplatform.infrastructure.core.service.RoutingDataSource;
import org.mifosplatform.organisation.office.data.OfficeData;
import org.mifosplatform.organisation.office.service.OfficeReadPlatformService;
import org.mifosplatform.portfolio.group.service.SearchParameters;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Service;
@Service
public class OfficeToGLAccountMappingReadPlatformServiceImpl implements OfficeToGLAccountMappingReadPlatformService {
private final JdbcTemplate jdbcTemplate;
private final OfficeToGLAccountMappingMapper accountMappingMapper;
private final PaginationHelper<OfficeToGLAccountMappingData> paginationHelper = new PaginationHelper<OfficeToGLAccountMappingData>();
private final OfficeReadPlatformService officeReadPlatformService;
private final AccountingDropdownReadPlatformService accountingDropdownReadPlatformService;
@Autowired
public OfficeToGLAccountMappingReadPlatformServiceImpl(final RoutingDataSource dataSource,
final OfficeReadPlatformService officeReadPlatformService,
final AccountingDropdownReadPlatformService accountingDropdownReadPlatformService) {
accountMappingMapper = new OfficeToGLAccountMappingMapper();
this.jdbcTemplate = new JdbcTemplate(dataSource);
this.officeReadPlatformService = officeReadPlatformService;
this.accountingDropdownReadPlatformService = accountingDropdownReadPlatformService;
}
@Override
public Page<OfficeToGLAccountMappingData> retrieveAll(final SearchParameters searchParameters) {
StringBuilder sqlBuilder = new StringBuilder(300);
sqlBuilder.append("select SQL_CALC_FOUND_ROWS ");
sqlBuilder.append(this.accountMappingMapper.schema());
Object[] finalObjectArray = {};
if (searchParameters.isOrderByRequested()) {
sqlBuilder.append(" order by ").append(searchParameters.getOrderBy());
if (searchParameters.isSortOrderProvided()) {
sqlBuilder.append(' ').append(searchParameters.getSortOrder());
}
}
if (searchParameters.isLimited()) {
sqlBuilder.append(" limit ").append(searchParameters.getLimit());
if (searchParameters.isOffset()) {
sqlBuilder.append(" offset ").append(searchParameters.getOffset());
}
}
final String sqlCountRows = "SELECT FOUND_ROWS()";
return this.paginationHelper.fetchPage(this.jdbcTemplate, sqlCountRows, sqlBuilder.toString(), finalObjectArray,
this.accountMappingMapper);
}
@Override
public OfficeToGLAccountMappingData retrieve(Long mappingId) {
try {
StringBuilder sqlBuilder = new StringBuilder(200);
sqlBuilder.append("select ");
sqlBuilder.append(this.accountMappingMapper.schema());
sqlBuilder.append(" where om.id=?");
return this.jdbcTemplate.queryForObject(sqlBuilder.toString(), this.accountMappingMapper, new Object[] { mappingId });
} catch (final EmptyResultDataAccessException e) {
throw new OfficeToGLAccountMappingNotFoundException(mappingId);
}
}
@Override
public OfficeToGLAccountMappingData retrieveTemplate() {
Collection<OfficeData> officeOptions = this.officeReadPlatformService.retrieveAllOfficesForDropdown();
final Map<String, List<GLAccountData>> accountOptions = this.accountingDropdownReadPlatformService.retrieveAccountMappingOptions();
return OfficeToGLAccountMappingData.template(accountOptions, officeOptions);
}
private static final class OfficeToGLAccountMappingMapper implements RowMapper<OfficeToGLAccountMappingData> {
private final String sql;
public OfficeToGLAccountMappingMapper() {
StringBuilder sb = new StringBuilder(300);
sb.append("om.id , office.id as officeId, office.name as officeName, ");
sb.append(" glaccount.id as glAccountId,glaccount.name as glAccountName,glaccount.gl_code as glCode ");
sb.append(" from acc_gl_office_mapping om ");
sb.append("inner join m_office office on office.id = om.office_id ");
sb.append("inner join acc_gl_account glaccount on glaccount.id = om.gl_account_id");
sql = sb.toString();
}
public String schema() {
return sql;
}
@Override
public OfficeToGLAccountMappingData mapRow(final ResultSet rs, @SuppressWarnings("unused") final int rowNum) throws SQLException {
final Long id = JdbcSupport.getLong(rs, "id");
final Long officeId = JdbcSupport.getLong(rs, "officeId");
final String officeName = rs.getString("officeName");
final String nameDecorated = null;
final String externalId = null;
final LocalDate openingDate = null;
final String hierarchy = null;
final Long parentId = null;
final String parentName = null;
final Collection<OfficeData> allowedParents = null;
final OfficeData officeData = new OfficeData(officeId, officeName, nameDecorated, externalId, openingDate, hierarchy, parentId,
parentName, allowedParents);
final Long glAccountId = JdbcSupport.getLong(rs, "glAccountId");
final String glAccountName = rs.getString("glAccountName");
final String glCode = rs.getString("glCode");
final GLAccountData gLAccountData = new GLAccountData(glAccountId, glAccountName, glCode);
final OfficeToGLAccountMappingData accountMappingData = OfficeToGLAccountMappingData.instance(id, officeData, gLAccountData);
return accountMappingData;
}
}
}
@@ -14,9 +14,9 @@ import java.util.Map;
import org.apache.commons.lang.StringUtils;
import org.joda.time.LocalDate;
import org.mifosplatform.accounting.accountmapping.domain.OfficeToGLAccountMapping;
import org.mifosplatform.accounting.accountmapping.domain.OfficeToGLAccountMappingRepository;
import org.mifosplatform.accounting.accountmapping.exception.OfficeToGLAccountMappingNotFoundException;
import org.mifosplatform.accounting.accountmapping.domain.FinancialActivityAccount;
import org.mifosplatform.accounting.accountmapping.domain.FinancialActivityAccountRepository;
import org.mifosplatform.accounting.accountmapping.exception.FinancialActivityAccountNotFoundException;
import org.mifosplatform.accounting.closure.domain.GLClosure;
import org.mifosplatform.accounting.closure.domain.GLClosureRepository;
import org.mifosplatform.accounting.common.AccountingConstants.ACCRUAL_ACCOUNTS_FOR_LOAN;
@@ -61,7 +61,7 @@ public class AccountingProcessorHelper {
public static final String SAVINGS_TRANSACTION_IDENTIFIER = "S";
private final JournalEntryRepository glJournalEntryRepository;
private final ProductToGLAccountMappingRepository accountMappingRepository;
private final OfficeToGLAccountMappingRepository officeToGLAccountMappingRepository;
private final FinancialActivityAccountRepository officeToGLAccountMappingRepository;
private final GLClosureRepository closureRepository;
private final OfficeRepository officeRepository;
private final LoanTransactionRepository loanTransactionRepository;
@@ -73,7 +73,7 @@ public class AccountingProcessorHelper {
final ProductToGLAccountMappingRepository accountMappingRepository, final GLClosureRepository closureRepository,
final OfficeRepository officeRepository, final LoanTransactionRepository loanTransactionRepository,
final SavingsAccountTransactionRepository savingsAccountTransactionRepository,
final OfficeToGLAccountMappingRepository officeToGLAccountMappingRepository,
final FinancialActivityAccountRepository officeToGLAccountMappingRepository,
final AccountTransfersReadPlatformService accountTransfersReadPlatformService) {
this.glJournalEntryRepository = glJournalEntryRepository;
this.accountMappingRepository = accountMappingRepository;
@@ -572,11 +572,11 @@ public class AccountingProcessorHelper {
Long officeId) {
GLAccount glAccount = null;
if (isOrganizationAccount(accountMappingTypeId)) {
OfficeToGLAccountMapping accountMapping = this.officeToGLAccountMappingRepository.findByOfficeAndFinancialAccountType(officeId,
accountMappingTypeId);
if (accountMapping == null) { throw new OfficeToGLAccountMappingNotFoundException(officeId,
FinancialActivityAccount financialActivityAccount = this.officeToGLAccountMappingRepository
.findByFinancialActivityType(accountMappingTypeId);
if (financialActivityAccount == null) { throw new FinancialActivityAccountNotFoundException(officeId,
String.valueOf(accountMappingTypeId)); }
glAccount = accountMapping.glAccount();
glAccount = financialActivityAccount.glAccount();
} else {
ProductToGLAccountMapping accountMapping = this.accountMappingRepository.findCoreProductToFinAccountMapping(loanProductId,
PortfolioProductType.LOAN.getValue(), accountMappingTypeId);
@@ -652,11 +652,11 @@ public class AccountingProcessorHelper {
final Long paymentTypeId, Long officeId) {
GLAccount glAccount = null;
if (isOrganizationAccount(accountMappingTypeId)) {
OfficeToGLAccountMapping accountMapping = this.officeToGLAccountMappingRepository.findByOfficeAndFinancialAccountType(officeId,
accountMappingTypeId);
if (accountMapping == null) { throw new OfficeToGLAccountMappingNotFoundException(officeId,
FinancialActivityAccount financialActivityAccount = this.officeToGLAccountMappingRepository
.findByFinancialActivityType(accountMappingTypeId);
if (financialActivityAccount == null) { throw new FinancialActivityAccountNotFoundException(officeId,
String.valueOf(accountMappingTypeId)); }
glAccount = accountMapping.glAccount();
glAccount = financialActivityAccount.glAccount();
} else {
ProductToGLAccountMapping accountMapping = this.accountMappingRepository.findCoreProductToFinAccountMapping(savingsProductId,
PortfolioProductType.SAVING.getValue(), accountMappingTypeId);
@@ -790,11 +790,11 @@ public class SynchronousCommandProcessingService implements CommandProcessingSer
} else if (wrapper.isOfficeToGLAccountMapping()) {
if (wrapper.isCreate()) {
handler = this.applicationContext.getBean("createOfficeToGLAccountMappingHandler", NewCommandSourceHandler.class);
handler = this.applicationContext.getBean("createFinancialActivityAccountHandler", NewCommandSourceHandler.class);
} else if (wrapper.isUpdate()) {
handler = this.applicationContext.getBean("updateOfficeToGLAccountMappingCommandHandler", NewCommandSourceHandler.class);
handler = this.applicationContext.getBean("updateFinancialActivityAccountCommandHandler", NewCommandSourceHandler.class);
} else if (wrapper.isDelete()) {
handler = this.applicationContext.getBean("deleteOfficeToGLAccountMappingCommandHandler", NewCommandSourceHandler.class);
handler = this.applicationContext.getBean("deleteFinancialActivityAccountCommandHandler", NewCommandSourceHandler.class);
} else {
throw new UnsupportedCommandException(wrapper.commandName());
}