This is an automated email from the ASF dual-hosted git repository. myrle pushed a commit to branch develop in repository https://gitbox.apache.org/repos/asf/fineract-cn-customer.git
commit 167341d129b1413ba10a83eec20b2aa950b33397 Author: mgeiss <[email protected]> AuthorDate: Mon Sep 18 17:10:03 2017 +0200 refactored payroll into own service --- .../customer/api/v1/CustomerEventConstants.java | 3 - .../customer/api/v1/client/CustomerManager.java | 26 ----- .../PayrollDistributionValidationException.java | 19 --- .../customer/api/v1/domain/PayrollAllocation.java | 58 ---------- .../api/v1/domain/PayrollDistribution.java | 86 -------------- .../io/mifos/customer/TestPayrollDistribution.java | 115 ------------------ .../customer/listener/CustomerEventListener.java | 9 -- .../command/SetPayrollDistributionCommand.java | 38 ------ .../command/handler/CustomerAggregate.java | 63 +--------- .../internal/mapper/PayrollDistributionMapper.java | 55 --------- .../repository/PayrollAllocationEntity.java | 89 -------------- .../repository/PayrollAllocationRepository.java | 22 ---- .../repository/PayrollDistributionEntity.java | 128 --------------------- .../repository/PayrollDistributionRepository.java | 24 ---- .../service/internal/service/CustomerService.java | 13 +-- .../rest/controller/CustomerRestController.java | 34 ------ .../mariadb/V6__drop_pyroll_distributions.sql | 18 +++ 17 files changed, 20 insertions(+), 780 deletions(-) diff --git a/api/src/main/java/io/mifos/customer/api/v1/CustomerEventConstants.java b/api/src/main/java/io/mifos/customer/api/v1/CustomerEventConstants.java index 21793b6..ab5a9a3 100644 --- a/api/src/main/java/io/mifos/customer/api/v1/CustomerEventConstants.java +++ b/api/src/main/java/io/mifos/customer/api/v1/CustomerEventConstants.java @@ -46,7 +46,6 @@ public interface CustomerEventConstants { String POST_PORTRAIT = "post-portrait"; String DELETE_PORTRAIT = "delete-portrait"; - String PUT_PAYROLL_DISTRIBUTION = "put-payroll-distribution"; String SELECTOR_INITIALIZE = SELECTOR_NAME + " = '" + INITIALIZE + "'"; @@ -73,6 +72,4 @@ public interface CustomerEventConstants { String SELECTOR_PUT_PORTRAIT = SELECTOR_NAME + " = '" + POST_PORTRAIT + "'"; String SELECTOR_DELETE_PORTRAIT = SELECTOR_NAME + " = '" + DELETE_PORTRAIT + "'"; - - String SELECTOR_PUT_PAYROLL_DISTRIBUTION = SELECTOR_NAME + " = '" + PUT_PAYROLL_DISTRIBUTION + "'"; } diff --git a/api/src/main/java/io/mifos/customer/api/v1/client/CustomerManager.java b/api/src/main/java/io/mifos/customer/api/v1/client/CustomerManager.java index 024dd2c..1d56aea 100644 --- a/api/src/main/java/io/mifos/customer/api/v1/client/CustomerManager.java +++ b/api/src/main/java/io/mifos/customer/api/v1/client/CustomerManager.java @@ -26,7 +26,6 @@ import io.mifos.customer.api.v1.domain.Customer; import io.mifos.customer.api.v1.domain.CustomerPage; import io.mifos.customer.api.v1.domain.IdentificationCard; import io.mifos.customer.api.v1.domain.IdentificationCardScan; -import io.mifos.customer.api.v1.domain.PayrollDistribution; import io.mifos.customer.api.v1.domain.ProcessStep; import io.mifos.customer.api.v1.domain.TaskDefinition; import org.springframework.cloud.netflix.feign.FeignClient; @@ -39,7 +38,6 @@ import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.multipart.MultipartFile; -import javax.validation.Valid; import javax.validation.constraints.Size; import java.util.List; @@ -393,28 +391,4 @@ public interface CustomerManager { ) @ThrowsException(status = HttpStatus.NOT_FOUND, exception = CustomerNotFoundException.class) List<ProcessStep> fetchProcessSteps(@PathVariable(value = "identifier") final String customerIdentifier); - - @RequestMapping( - value = "/customers/{identifier}/payroll", - method = RequestMethod.PUT, - produces = MediaType.APPLICATION_JSON_VALUE, - consumes = MediaType.APPLICATION_JSON_VALUE - ) - @ThrowsExceptions({ - @ThrowsException(status = HttpStatus.NOT_FOUND, exception = CustomerNotFoundException.class), - @ThrowsException(status = HttpStatus.BAD_REQUEST, exception = PayrollDistributionValidationException.class) - }) - void setPayrollDistribution(@PathVariable(value = "identifier") final String customerIdentifier, - @RequestBody @Valid final PayrollDistribution payrollDistribution); - - @RequestMapping( - value = "/customers/{identifier}/payroll", - method = RequestMethod.GET, - produces = MediaType.ALL_VALUE, - consumes = MediaType.APPLICATION_JSON_VALUE - ) - @ThrowsExceptions({ - @ThrowsException(status = HttpStatus.NOT_FOUND, exception = CustomerNotFoundException.class) - }) - PayrollDistribution getPayrollDistribution(@PathVariable(value = "identifier") final String customerIdentifier); } diff --git a/api/src/main/java/io/mifos/customer/api/v1/client/PayrollDistributionValidationException.java b/api/src/main/java/io/mifos/customer/api/v1/client/PayrollDistributionValidationException.java deleted file mode 100644 index 52caca1..0000000 --- a/api/src/main/java/io/mifos/customer/api/v1/client/PayrollDistributionValidationException.java +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Copyright 2017 The Mifos Initiative. - * - * Licensed 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 io.mifos.customer.api.v1.client; - -public class PayrollDistributionValidationException extends RuntimeException { -} diff --git a/api/src/main/java/io/mifos/customer/api/v1/domain/PayrollAllocation.java b/api/src/main/java/io/mifos/customer/api/v1/domain/PayrollAllocation.java deleted file mode 100644 index 10d49cd..0000000 --- a/api/src/main/java/io/mifos/customer/api/v1/domain/PayrollAllocation.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright 2017 The Mifos Initiative. - * - * Licensed 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 io.mifos.customer.api.v1.domain; - -import io.mifos.core.lang.validation.constraints.ValidIdentifier; - -import javax.validation.constraints.DecimalMin; -import java.math.BigDecimal; - -public class PayrollAllocation { - - @ValidIdentifier - private String accountNumber; - @DecimalMin("0.001") - private BigDecimal amount; - private Boolean proportional = Boolean.FALSE; - - public PayrollAllocation() { - super(); - } - - public String getAccountNumber() { - return this.accountNumber; - } - - public void setAccountNumber(final String accountNumber) { - this.accountNumber = accountNumber; - } - - public BigDecimal getAmount() { - return this.amount; - } - - public void setAmount(final BigDecimal amount) { - this.amount = amount; - } - - public Boolean getProportional() { - return this.proportional; - } - - public void setProportional(final Boolean proportional) { - this.proportional = proportional; - } -} diff --git a/api/src/main/java/io/mifos/customer/api/v1/domain/PayrollDistribution.java b/api/src/main/java/io/mifos/customer/api/v1/domain/PayrollDistribution.java deleted file mode 100644 index d905f11..0000000 --- a/api/src/main/java/io/mifos/customer/api/v1/domain/PayrollDistribution.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright 2017 The Mifos Initiative. - * - * Licensed 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 io.mifos.customer.api.v1.domain; - -import io.mifos.core.lang.validation.constraints.ValidIdentifier; - -import javax.validation.Valid; -import java.util.HashSet; -import java.util.Set; - -public class PayrollDistribution { - - @ValidIdentifier - private String mainAccountNumber; - @Valid - private Set<PayrollAllocation> payrollAllocations = new HashSet<>(); - private String createdBy; - private String createdOn; - private String lastModifiedBy; - private String lastModifiedOn; - - public PayrollDistribution() { - super(); - } - - public String getMainAccountNumber() { - return this.mainAccountNumber; - } - - public void setMainAccountNumber(final String mainAccountNumber) { - this.mainAccountNumber = mainAccountNumber; - } - - public Set<PayrollAllocation> getPayrollAllocations() { - return this.payrollAllocations; - } - - public void setPayrollAllocations(final Set<PayrollAllocation> payrollAllocations) { - this.payrollAllocations = payrollAllocations; - } - - public String getCreatedBy() { - return this.createdBy; - } - - public void setCreatedBy(final String createdBy) { - this.createdBy = createdBy; - } - - public String getCreatedOn() { - return this.createdOn; - } - - public void setCreatedOn(final String createdOn) { - this.createdOn = createdOn; - } - - public String getLastModifiedBy() { - return this.lastModifiedBy; - } - - public void setLastModifiedBy(final String lastModifiedBy) { - this.lastModifiedBy = lastModifiedBy; - } - - public String getLastModifiedOn() { - return this.lastModifiedOn; - } - - public void setLastModifiedOn(final String lastModifiedOn) { - this.lastModifiedOn = lastModifiedOn; - } -} diff --git a/component-test/src/main/java/io/mifos/customer/TestPayrollDistribution.java b/component-test/src/main/java/io/mifos/customer/TestPayrollDistribution.java deleted file mode 100644 index 89f6da4..0000000 --- a/component-test/src/main/java/io/mifos/customer/TestPayrollDistribution.java +++ /dev/null @@ -1,115 +0,0 @@ -/* - * Copyright 2017 The Mifos Initiative. - * - * Licensed 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 io.mifos.customer; - -import com.google.common.collect.Sets; -import io.mifos.customer.api.v1.CustomerEventConstants; -import io.mifos.customer.api.v1.domain.Customer; -import io.mifos.customer.api.v1.domain.PayrollAllocation; -import io.mifos.customer.api.v1.domain.PayrollDistribution; -import io.mifos.customer.util.CustomerGenerator; -import org.junit.Assert; -import org.junit.Test; - -import java.math.BigDecimal; -import java.util.Optional; - -public class TestPayrollDistribution extends AbstractCustomerTest { - - @Test - public void shouldSetInitialPayrollDistribution() throws Exception { - final Customer customer = CustomerGenerator.createRandomCustomer(); - this.customerManager.createCustomer(customer); - - Assert.assertTrue(this.eventRecorder.wait(CustomerEventConstants.POST_CUSTOMER, customer.getIdentifier())); - - final PayrollAllocation firstPayrollAllocation = new PayrollAllocation(); - firstPayrollAllocation.setAccountNumber("08154712"); - firstPayrollAllocation.setAmount(BigDecimal.valueOf(234.56D)); - - final PayrollAllocation secondPayrollAllocation = new PayrollAllocation(); - secondPayrollAllocation.setAccountNumber("08154713"); - secondPayrollAllocation.setAmount(BigDecimal.valueOf(5.00D)); - secondPayrollAllocation.setProportional(Boolean.TRUE); - - final PayrollDistribution payrollDistribution = new PayrollDistribution(); - payrollDistribution.setMainAccountNumber("08154711"); - payrollDistribution.setPayrollAllocations(Sets.newHashSet(firstPayrollAllocation, secondPayrollAllocation)); - this.customerManager.setPayrollDistribution(customer.getIdentifier(), payrollDistribution); - - Assert.assertTrue(this.eventRecorder.wait(CustomerEventConstants.PUT_PAYROLL_DISTRIBUTION, customer.getIdentifier())); - - final PayrollDistribution fetchedPayrollDistribution = this.customerManager.getPayrollDistribution(customer.getIdentifier()); - - this.compare(payrollDistribution, fetchedPayrollDistribution); - } - - @Test - public void shouldUpdatePayrollDistribution() throws Exception { - final Customer customer = CustomerGenerator.createRandomCustomer(); - this.customerManager.createCustomer(customer); - - Assert.assertTrue(this.eventRecorder.wait(CustomerEventConstants.POST_CUSTOMER, customer.getIdentifier())); - - final PayrollAllocation firstPayrollAllocation = new PayrollAllocation(); - firstPayrollAllocation.setAccountNumber("08154712"); - firstPayrollAllocation.setAmount(BigDecimal.valueOf(234.56D)); - - final PayrollAllocation secondPayrollAllocation = new PayrollAllocation(); - secondPayrollAllocation.setAccountNumber("08154713"); - secondPayrollAllocation.setAmount(BigDecimal.valueOf(5.00D)); - secondPayrollAllocation.setProportional(Boolean.TRUE); - - final PayrollDistribution payrollDistribution = new PayrollDistribution(); - payrollDistribution.setMainAccountNumber("08154711"); - payrollDistribution.setPayrollAllocations(Sets.newHashSet(firstPayrollAllocation, secondPayrollAllocation)); - this.customerManager.setPayrollDistribution(customer.getIdentifier(), payrollDistribution); - - Assert.assertTrue(this.eventRecorder.wait(CustomerEventConstants.PUT_PAYROLL_DISTRIBUTION, customer.getIdentifier())); - this.eventRecorder.clear(); - - final PayrollDistribution fetchedPayrollDistribution = this.customerManager.getPayrollDistribution(customer.getIdentifier()); - - final PayrollAllocation replacedPayrollAllocation = new PayrollAllocation(); - replacedPayrollAllocation.setAccountNumber("08154714"); - replacedPayrollAllocation.setAmount(BigDecimal.valueOf(10.00D)); - replacedPayrollAllocation.setProportional(Boolean.TRUE); - - final PayrollDistribution replacedPayrollDistribution = new PayrollDistribution(); - replacedPayrollDistribution.setMainAccountNumber(fetchedPayrollDistribution.getMainAccountNumber()); - replacedPayrollDistribution.setPayrollAllocations(Sets.newHashSet(replacedPayrollAllocation)); - this.customerManager.setPayrollDistribution(customer.getIdentifier(), replacedPayrollDistribution); - - Assert.assertTrue(this.eventRecorder.wait(CustomerEventConstants.PUT_PAYROLL_DISTRIBUTION, customer.getIdentifier())); - - final PayrollDistribution updatedPayrollDistribution = this.customerManager.getPayrollDistribution(customer.getIdentifier()); - - this.compare(replacedPayrollDistribution, updatedPayrollDistribution); - - final Optional<PayrollAllocation> optionalPayrollAllocation = - updatedPayrollDistribution.getPayrollAllocations().stream().findFirst(); - - final PayrollAllocation payrollAllocation = optionalPayrollAllocation.orElseThrow(IllegalStateException::new); - Assert.assertEquals(replacedPayrollAllocation.getAccountNumber(), payrollAllocation.getAccountNumber()); - Assert.assertTrue(replacedPayrollAllocation.getAmount().compareTo(payrollAllocation.getAmount()) == 0); - Assert.assertEquals(replacedPayrollAllocation.getProportional(), payrollAllocation.getProportional()); - } - - private void compare(final PayrollDistribution payrollDistribution, final PayrollDistribution fetchedPayrollDistribution) { - Assert.assertEquals(payrollDistribution.getMainAccountNumber(), fetchedPayrollDistribution.getMainAccountNumber()); - Assert.assertTrue(payrollDistribution.getPayrollAllocations().size() == fetchedPayrollDistribution.getPayrollAllocations().size()); - } -} diff --git a/component-test/src/main/java/io/mifos/customer/listener/CustomerEventListener.java b/component-test/src/main/java/io/mifos/customer/listener/CustomerEventListener.java index 47ac0b5..5c1d2e1 100644 --- a/component-test/src/main/java/io/mifos/customer/listener/CustomerEventListener.java +++ b/component-test/src/main/java/io/mifos/customer/listener/CustomerEventListener.java @@ -178,13 +178,4 @@ public class CustomerEventListener { final String payload) { this.eventRecorder.event(tenant, CustomerEventConstants.DELETE_PORTRAIT, payload, String.class); } - - @JmsListener( - destination = CustomerEventConstants.DESTINATION, - selector = CustomerEventConstants.SELECTOR_PUT_PAYROLL_DISTRIBUTION - ) - public void onSetPayrollDistribution(@Header(TenantHeaderFilter.TENANT_HEADER) final String tenant, - final String payload) { - this.eventRecorder.event(tenant, CustomerEventConstants.PUT_PAYROLL_DISTRIBUTION, payload, String.class); - } } diff --git a/service/src/main/java/io/mifos/customer/service/internal/command/SetPayrollDistributionCommand.java b/service/src/main/java/io/mifos/customer/service/internal/command/SetPayrollDistributionCommand.java deleted file mode 100644 index 9d456dd..0000000 --- a/service/src/main/java/io/mifos/customer/service/internal/command/SetPayrollDistributionCommand.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright 2017 The Mifos Initiative. - * - * Licensed 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 io.mifos.customer.service.internal.command; - -import io.mifos.customer.api.v1.domain.PayrollDistribution; - -public class SetPayrollDistributionCommand { - private final String customerIdentifier; - private final PayrollDistribution payrollDistribution; - - public SetPayrollDistributionCommand(final String customerIdentifier, - final PayrollDistribution payrollDistribution) { - super(); - this.customerIdentifier = customerIdentifier; - this.payrollDistribution = payrollDistribution; - } - - public String customerIdentifier() { - return this.customerIdentifier; - } - - public PayrollDistribution payrollDistribution() { - return this.payrollDistribution; - } -} diff --git a/service/src/main/java/io/mifos/customer/service/internal/command/handler/CustomerAggregate.java b/service/src/main/java/io/mifos/customer/service/internal/command/handler/CustomerAggregate.java index b41ddfb..c20252c 100644 --- a/service/src/main/java/io/mifos/customer/service/internal/command/handler/CustomerAggregate.java +++ b/service/src/main/java/io/mifos/customer/service/internal/command/handler/CustomerAggregate.java @@ -24,7 +24,6 @@ import io.mifos.core.lang.ServiceException; import io.mifos.customer.api.v1.CustomerEventConstants; import io.mifos.customer.api.v1.domain.Command; import io.mifos.customer.api.v1.domain.Customer; -import io.mifos.customer.api.v1.domain.PayrollDistribution; import io.mifos.customer.api.v1.events.ScanEvent; import io.mifos.customer.catalog.service.internal.repository.CatalogEntity; import io.mifos.customer.catalog.service.internal.repository.CatalogRepository; @@ -44,7 +43,6 @@ import io.mifos.customer.service.internal.command.DeleteIdentificationCardScanCo import io.mifos.customer.service.internal.command.DeletePortraitCommand; import io.mifos.customer.service.internal.command.LockCustomerCommand; import io.mifos.customer.service.internal.command.ReopenCustomerCommand; -import io.mifos.customer.service.internal.command.SetPayrollDistributionCommand; import io.mifos.customer.service.internal.command.UnlockCustomerCommand; import io.mifos.customer.service.internal.command.UpdateAddressCommand; import io.mifos.customer.service.internal.command.UpdateContactDetailsCommand; @@ -69,10 +67,6 @@ import io.mifos.customer.service.internal.repository.IdentificationCardEntity; import io.mifos.customer.service.internal.repository.IdentificationCardRepository; import io.mifos.customer.service.internal.repository.IdentificationCardScanEntity; import io.mifos.customer.service.internal.repository.IdentificationCardScanRepository; -import io.mifos.customer.service.internal.repository.PayrollAllocationEntity; -import io.mifos.customer.service.internal.repository.PayrollAllocationRepository; -import io.mifos.customer.service.internal.repository.PayrollDistributionEntity; -import io.mifos.customer.service.internal.repository.PayrollDistributionRepository; import io.mifos.customer.service.internal.repository.PortraitEntity; import io.mifos.customer.service.internal.repository.PortraitRepository; import org.slf4j.Logger; @@ -106,8 +100,6 @@ public class CustomerAggregate { private final FieldRepository fieldRepository; private final CommandRepository commandRepository; private final TaskAggregate taskAggregate; - private final PayrollDistributionRepository payrollDistributionRepository; - private final PayrollAllocationRepository payrollAllocationRepository; @Autowired public CustomerAggregate(@Qualifier(ServiceConstants.LOGGER_NAME) final Logger logger, @@ -121,9 +113,7 @@ public class CustomerAggregate { final CatalogRepository catalogRepository, final FieldRepository fieldRepository, final CommandRepository commandRepository, - final TaskAggregate taskAggregate, - final PayrollDistributionRepository payrollDistributionRepository, - final PayrollAllocationRepository payrollAllocationRepository) { + final TaskAggregate taskAggregate) { super(); this.logger = logger; this.addressRepository = addressRepository; @@ -137,8 +127,6 @@ public class CustomerAggregate { this.fieldRepository = fieldRepository; this.commandRepository = commandRepository; this.taskAggregate = taskAggregate; - this.payrollDistributionRepository = payrollDistributionRepository; - this.payrollAllocationRepository = payrollAllocationRepository; } @Transactional @@ -548,55 +536,6 @@ public class CustomerAggregate { return deletePortraitCommand.identifier(); } - @Transactional - @CommandHandler - @EventEmitter(selectorName = CustomerEventConstants.SELECTOR_NAME, selectorValue = CustomerEventConstants.PUT_PAYROLL_DISTRIBUTION) - public String setPayrollDistribution(final SetPayrollDistributionCommand setPayrollDistributionCommand) { - final CustomerEntity customerEntity = - this.customerRepository.findByIdentifier(setPayrollDistributionCommand.customerIdentifier()); - - final LocalDateTime now = LocalDateTime.now(Clock.systemUTC()); - - final PayrollDistributionEntity payrollDistributionEntity = - this.payrollDistributionRepository.findByCustomer(customerEntity).orElseGet(() -> { - final PayrollDistributionEntity newPayrollDistribution = new PayrollDistributionEntity(); - newPayrollDistribution.setCustomer(customerEntity); - newPayrollDistribution.setCreatedBy(UserContextHolder.checkedGetUser()); - newPayrollDistribution.setCreatedOn(now); - return newPayrollDistribution; - }); - - if (payrollDistributionEntity.getId() != null) { - this.payrollAllocationRepository.deleteByPayrollDistribution(payrollDistributionEntity); - this.payrollAllocationRepository.flush(); - - payrollDistributionEntity.setLastModifiedBy(UserContextHolder.checkedGetUser()); - payrollDistributionEntity.setLastModifiedOn(now); - payrollDistributionEntity.setPayrollAllocationEntities(null); - } - - final PayrollDistribution payrollDistribution = setPayrollDistributionCommand.payrollDistribution(); - payrollDistributionEntity.setMainAccountNumber(payrollDistribution.getMainAccountNumber()); - - final PayrollDistributionEntity savedPayrollDistributionEntity = - this.payrollDistributionRepository.save(payrollDistributionEntity); - - this.payrollAllocationRepository.save(payrollDistribution.getPayrollAllocations() - .stream() - .map(payrollAllocation -> { - final PayrollAllocationEntity payrollAllocationEntity = new PayrollAllocationEntity(); - payrollAllocationEntity.setPayrollDistribution(savedPayrollDistributionEntity); - payrollAllocationEntity.setAccountNumber(payrollAllocation.getAccountNumber()); - payrollAllocationEntity.setAmount(payrollAllocation.getAmount()); - payrollAllocationEntity.setProportional(payrollAllocation.getProportional()); - return payrollAllocationEntity; - }) - .collect(Collectors.toList()) - ); - - return setPayrollDistributionCommand.customerIdentifier(); - } - private void setCustomValues(final Customer customer, final CustomerEntity savedCustomerEntity) { this.fieldValueRepository.save( customer.getCustomValues() diff --git a/service/src/main/java/io/mifos/customer/service/internal/mapper/PayrollDistributionMapper.java b/service/src/main/java/io/mifos/customer/service/internal/mapper/PayrollDistributionMapper.java deleted file mode 100644 index c7cc514..0000000 --- a/service/src/main/java/io/mifos/customer/service/internal/mapper/PayrollDistributionMapper.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright 2017 The Mifos Initiative. - * - * Licensed 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 io.mifos.customer.service.internal.mapper; - -import io.mifos.core.lang.DateConverter; -import io.mifos.customer.api.v1.domain.PayrollAllocation; -import io.mifos.customer.api.v1.domain.PayrollDistribution; -import io.mifos.customer.service.internal.repository.PayrollDistributionEntity; - -import java.util.stream.Collectors; - -public class PayrollDistributionMapper { - - private PayrollDistributionMapper() { - super(); - } - - public static PayrollDistribution map(final PayrollDistributionEntity payrollDistributionEntity) { - final PayrollDistribution payrollDistribution = new PayrollDistribution(); - payrollDistribution.setMainAccountNumber(payrollDistributionEntity.getMainAccountNumber()); - payrollDistribution.setCreatedBy(payrollDistributionEntity.getCreatedBy()); - payrollDistribution.setCreatedOn(DateConverter.toIsoString(payrollDistributionEntity.getCreatedOn())); - if (payrollDistributionEntity.getLastModifiedBy() != null) { - payrollDistribution.setLastModifiedBy(payrollDistributionEntity.getLastModifiedBy()); - payrollDistribution.setLastModifiedOn(DateConverter.toIsoString(payrollDistributionEntity.getLastModifiedOn())); - } - - if (payrollDistributionEntity.getPayrollAllocationEntities() != null) { - payrollDistribution.setPayrollAllocations( - payrollDistributionEntity.getPayrollAllocationEntities().stream().map(payrollAllocationEntity -> { - final PayrollAllocation payrollAllocation = new PayrollAllocation(); - payrollAllocation.setAccountNumber(payrollAllocationEntity.getAccountNumber()); - payrollAllocation.setAmount(payrollAllocationEntity.getAmount()); - payrollAllocation.setProportional(payrollAllocationEntity.getProportional()); - return payrollAllocation; - }).collect(Collectors.toSet()) - ); - } - - return payrollDistribution; - } -} diff --git a/service/src/main/java/io/mifos/customer/service/internal/repository/PayrollAllocationEntity.java b/service/src/main/java/io/mifos/customer/service/internal/repository/PayrollAllocationEntity.java deleted file mode 100644 index a08907c..0000000 --- a/service/src/main/java/io/mifos/customer/service/internal/repository/PayrollAllocationEntity.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright 2017 The Mifos Initiative. - * - * Licensed 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 io.mifos.customer.service.internal.repository; - -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.JoinColumn; -import javax.persistence.ManyToOne; -import javax.persistence.Table; -import java.math.BigDecimal; - -@Entity -@Table(name = "maat_payroll_allocations") -public class PayrollAllocationEntity { - - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - @Column(name = "id", nullable = false) - private Long id; - @ManyToOne - @JoinColumn(name = "payroll_distribution_id", nullable = false) - private PayrollDistributionEntity payrollDistribution; - @Column(name = "account_number", nullable = false, length = 34) - private String accountNumber; - @Column(name = "amount", nullable = false, precision = 15, scale = 5) - private BigDecimal amount; - @Column(name = "proportional", nullable = false) - private Boolean proportional = Boolean.FALSE; - - public PayrollAllocationEntity() { - super(); - } - - public Long getId() { - return this.id; - } - - public void setId(final Long id) { - this.id = id; - } - - public PayrollDistributionEntity getPayrollDistribution() { - return this.payrollDistribution; - } - - public void setPayrollDistribution(final PayrollDistributionEntity payrollDistribution) { - this.payrollDistribution = payrollDistribution; - } - - public String getAccountNumber() { - return this.accountNumber; - } - - public void setAccountNumber(final String accountNumber) { - this.accountNumber = accountNumber; - } - - public BigDecimal getAmount() { - return this.amount; - } - - public void setAmount(final BigDecimal amount) { - this.amount = amount; - } - - public Boolean getProportional() { - return this.proportional; - } - - public void setProportional(final Boolean proportional) { - this.proportional = proportional; - } -} diff --git a/service/src/main/java/io/mifos/customer/service/internal/repository/PayrollAllocationRepository.java b/service/src/main/java/io/mifos/customer/service/internal/repository/PayrollAllocationRepository.java deleted file mode 100644 index 9d418f3..0000000 --- a/service/src/main/java/io/mifos/customer/service/internal/repository/PayrollAllocationRepository.java +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright 2017 The Mifos Initiative. - * - * Licensed 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 io.mifos.customer.service.internal.repository; - -import org.springframework.data.jpa.repository.JpaRepository; - -public interface PayrollAllocationRepository extends JpaRepository<PayrollAllocationEntity, Long> { - void deleteByPayrollDistribution(final PayrollDistributionEntity payrollDistributionEntity); -} diff --git a/service/src/main/java/io/mifos/customer/service/internal/repository/PayrollDistributionEntity.java b/service/src/main/java/io/mifos/customer/service/internal/repository/PayrollDistributionEntity.java deleted file mode 100644 index 5cb62b9..0000000 --- a/service/src/main/java/io/mifos/customer/service/internal/repository/PayrollDistributionEntity.java +++ /dev/null @@ -1,128 +0,0 @@ -/* - * Copyright 2017 The Mifos Initiative. - * - * Licensed 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 io.mifos.customer.service.internal.repository; - -import io.mifos.core.mariadb.util.LocalDateTimeConverter; - -import javax.persistence.CascadeType; -import javax.persistence.Column; -import javax.persistence.Convert; -import javax.persistence.Entity; -import javax.persistence.FetchType; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.JoinColumn; -import javax.persistence.OneToMany; -import javax.persistence.OneToOne; -import javax.persistence.Table; -import java.time.LocalDateTime; -import java.util.List; - -@Entity -@Table(name = "maat_payroll_distributions") -public class PayrollDistributionEntity { - - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - @Column(name = "id", nullable = false) - private Long id; - @OneToOne(cascade = CascadeType.ALL) - @JoinColumn(name = "customer_id", nullable = false) - private CustomerEntity customer; - @Column(name = "main_account_number", nullable = false, length = 34) - private String mainAccountNumber; - @OneToMany(fetch = FetchType.EAGER, mappedBy = "payrollDistribution") - private List<PayrollAllocationEntity> payrollAllocationEntities; - @Column(name = "created_by") - private String createdBy; - @Column(name = "created_on") - @Convert(converter = LocalDateTimeConverter.class) - private LocalDateTime createdOn; - @Column(name = "last_modified_by") - private String lastModifiedBy; - @Column(name = "last_modified_on") - @Convert(converter = LocalDateTimeConverter.class) - private LocalDateTime lastModifiedOn; - - public PayrollDistributionEntity() { - super(); - } - - public Long getId() { - return this.id; - } - - public void setId(final Long id) { - this.id = id; - } - - public CustomerEntity getCustomer() { - return this.customer; - } - - public void setCustomer(final CustomerEntity customer) { - this.customer = customer; - } - - public String getMainAccountNumber() { - return this.mainAccountNumber; - } - - public void setMainAccountNumber(final String mainAccountNumber) { - this.mainAccountNumber = mainAccountNumber; - } - - public List<PayrollAllocationEntity> getPayrollAllocationEntities() { - return this.payrollAllocationEntities; - } - - public void setPayrollAllocationEntities(final List<PayrollAllocationEntity> payrollAllocationEntities) { - this.payrollAllocationEntities = payrollAllocationEntities; - } - - public String getCreatedBy() { - return this.createdBy; - } - - public void setCreatedBy(final String createdBy) { - this.createdBy = createdBy; - } - - public LocalDateTime getCreatedOn() { - return this.createdOn; - } - - public void setCreatedOn(final LocalDateTime createdOn) { - this.createdOn = createdOn; - } - - public String getLastModifiedBy() { - return this.lastModifiedBy; - } - - public void setLastModifiedBy(final String lastModifiedBy) { - this.lastModifiedBy = lastModifiedBy; - } - - public LocalDateTime getLastModifiedOn() { - return this.lastModifiedOn; - } - - public void setLastModifiedOn(final LocalDateTime lastModifiedOn) { - this.lastModifiedOn = lastModifiedOn; - } -} diff --git a/service/src/main/java/io/mifos/customer/service/internal/repository/PayrollDistributionRepository.java b/service/src/main/java/io/mifos/customer/service/internal/repository/PayrollDistributionRepository.java deleted file mode 100644 index f332432..0000000 --- a/service/src/main/java/io/mifos/customer/service/internal/repository/PayrollDistributionRepository.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright 2017 The Mifos Initiative. - * - * Licensed 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 io.mifos.customer.service.internal.repository; - -import org.springframework.data.jpa.repository.JpaRepository; - -import java.util.Optional; - -public interface PayrollDistributionRepository extends JpaRepository<PayrollDistributionEntity, Long> { - Optional<PayrollDistributionEntity> findByCustomer(final CustomerEntity customerEntity); -} diff --git a/service/src/main/java/io/mifos/customer/service/internal/service/CustomerService.java b/service/src/main/java/io/mifos/customer/service/internal/service/CustomerService.java index 3901f0d..cc886aa 100644 --- a/service/src/main/java/io/mifos/customer/service/internal/service/CustomerService.java +++ b/service/src/main/java/io/mifos/customer/service/internal/service/CustomerService.java @@ -20,7 +20,6 @@ import io.mifos.customer.api.v1.domain.Customer; import io.mifos.customer.api.v1.domain.CustomerPage; import io.mifos.customer.api.v1.domain.IdentificationCard; import io.mifos.customer.api.v1.domain.IdentificationCardScan; -import io.mifos.customer.api.v1.domain.PayrollDistribution; import io.mifos.customer.api.v1.domain.ProcessStep; import io.mifos.customer.api.v1.domain.TaskDefinition; import io.mifos.customer.catalog.api.v1.domain.Value; @@ -34,7 +33,6 @@ import io.mifos.customer.service.internal.mapper.ContactDetailMapper; import io.mifos.customer.service.internal.mapper.CustomerMapper; import io.mifos.customer.service.internal.mapper.IdentificationCardMapper; import io.mifos.customer.service.internal.mapper.IdentificationCardScanMapper; -import io.mifos.customer.service.internal.mapper.PayrollDistributionMapper; import io.mifos.customer.service.internal.mapper.TaskDefinitionMapper; import io.mifos.customer.service.internal.repository.CommandEntity; import io.mifos.customer.service.internal.repository.CommandRepository; @@ -46,7 +44,6 @@ import io.mifos.customer.service.internal.repository.IdentificationCardEntity; import io.mifos.customer.service.internal.repository.IdentificationCardRepository; import io.mifos.customer.service.internal.repository.IdentificationCardScanEntity; import io.mifos.customer.service.internal.repository.IdentificationCardScanRepository; -import io.mifos.customer.service.internal.repository.PayrollDistributionRepository; import io.mifos.customer.service.internal.repository.PortraitEntity; import io.mifos.customer.service.internal.repository.PortraitRepository; import io.mifos.customer.service.internal.repository.TaskDefinitionRepository; @@ -77,7 +74,6 @@ public class CustomerService { private final CommandRepository commandRepository; private final TaskDefinitionRepository taskDefinitionRepository; private final TaskInstanceRepository taskInstanceRepository; - private final PayrollDistributionRepository payrollDistributionRepository; @Autowired public CustomerService(@Qualifier(ServiceConstants.LOGGER_NAME) final Logger logger, @@ -89,8 +85,7 @@ public class CustomerService { final FieldValueRepository fieldValueRepository, final CommandRepository commandRepository, final TaskDefinitionRepository taskDefinitionRepository, - final TaskInstanceRepository taskInstanceRepository, - final PayrollDistributionRepository payrollDistributionRepository) { + final TaskInstanceRepository taskInstanceRepository) { super(); this.logger = logger; this.customerRepository = customerRepository; @@ -102,7 +97,6 @@ public class CustomerService { this.commandRepository = commandRepository; this.taskDefinitionRepository = taskDefinitionRepository; this.taskInstanceRepository = taskInstanceRepository; - this.payrollDistributionRepository = payrollDistributionRepository; } public Boolean customerExists(final String identifier) { @@ -294,9 +288,4 @@ public class CustomerService { return processStep; } - - public Optional<PayrollDistribution> getPayrollDistribution(final String customerIdentifier) { - final CustomerEntity customerEntity = this.customerRepository.findByIdentifier(customerIdentifier); - return this.payrollDistributionRepository.findByCustomer(customerEntity).map(PayrollDistributionMapper::map); - } } diff --git a/service/src/main/java/io/mifos/customer/service/rest/controller/CustomerRestController.java b/service/src/main/java/io/mifos/customer/service/rest/controller/CustomerRestController.java index d7ad048..c3c6e94 100644 --- a/service/src/main/java/io/mifos/customer/service/rest/controller/CustomerRestController.java +++ b/service/src/main/java/io/mifos/customer/service/rest/controller/CustomerRestController.java @@ -29,7 +29,6 @@ import io.mifos.customer.api.v1.domain.Customer; import io.mifos.customer.api.v1.domain.CustomerPage; import io.mifos.customer.api.v1.domain.IdentificationCard; import io.mifos.customer.api.v1.domain.IdentificationCardScan; -import io.mifos.customer.api.v1.domain.PayrollDistribution; import io.mifos.customer.api.v1.domain.ProcessStep; import io.mifos.customer.api.v1.domain.TaskDefinition; import io.mifos.customer.catalog.service.internal.service.FieldValueValidator; @@ -49,7 +48,6 @@ import io.mifos.customer.service.internal.command.ExecuteTaskForCustomerCommand; import io.mifos.customer.service.internal.command.InitializeServiceCommand; import io.mifos.customer.service.internal.command.LockCustomerCommand; import io.mifos.customer.service.internal.command.ReopenCustomerCommand; -import io.mifos.customer.service.internal.command.SetPayrollDistributionCommand; import io.mifos.customer.service.internal.command.UnlockCustomerCommand; import io.mifos.customer.service.internal.command.UpdateAddressCommand; import io.mifos.customer.service.internal.command.UpdateContactDetailsCommand; @@ -746,38 +744,6 @@ public class CustomerRestController { return ResponseEntity.ok(this.customerService.getProcessSteps(customerIdentifier)); } - @Permittable(value = AcceptedTokenType.TENANT, groupId = PermittableGroupIds.CUSTOMER) - @RequestMapping( - value = "/customers/{identifier}/payroll", - method = RequestMethod.PUT, - produces = MediaType.APPLICATION_JSON_VALUE, - consumes = MediaType.APPLICATION_JSON_VALUE - ) - public - @ResponseBody - ResponseEntity<Void> setPayrollDistribution(@PathVariable(value = "identifier") final String customerIdentifier, - @RequestBody @Valid final PayrollDistribution payrollDistribution) { - this.throwIfCustomerNotExists(customerIdentifier); - this.commandGateway.process(new SetPayrollDistributionCommand(customerIdentifier, payrollDistribution)); - return ResponseEntity.accepted().build(); - } - - @Permittable(value = AcceptedTokenType.TENANT, groupId = PermittableGroupIds.CUSTOMER) - @RequestMapping( - value = "/customers/{identifier}/payroll", - method = RequestMethod.GET, - produces = MediaType.APPLICATION_JSON_VALUE, - consumes = MediaType.ALL_VALUE - ) - public - @ResponseBody - ResponseEntity<PayrollDistribution> getPayrollDistribution(@PathVariable(value = "identifier") final String customerIdentifier) { - this.throwIfCustomerNotExists(customerIdentifier); - return ResponseEntity.ok( - this.customerService.getPayrollDistribution(customerIdentifier).orElse(null) - ); - } - private Pageable createPageRequest(final Integer pageIndex, final Integer size, final String sortColumn, final String sortDirection) { final Integer pageIndexToUse = pageIndex != null ? pageIndex : 0; final Integer sizeToUse = size != null ? size : 20; diff --git a/service/src/main/resources/db/migrations/mariadb/V6__drop_pyroll_distributions.sql b/service/src/main/resources/db/migrations/mariadb/V6__drop_pyroll_distributions.sql new file mode 100644 index 0000000..78c9690 --- /dev/null +++ b/service/src/main/resources/db/migrations/mariadb/V6__drop_pyroll_distributions.sql @@ -0,0 +1,18 @@ +-- +-- Copyright 2017 The Mifos Initiative. +-- +-- Licensed 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. +-- + +DROP TABLE maat_payroll_allocations; +DROP TABLE maat_payroll_distributions; \ No newline at end of file -- To stop receiving notification emails like this one, please contact [email protected].
