http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/08c553f9/fineract-provider/src/main/java/org/apache/fineract/portfolio/shares/constants/ShareProductApiConstants.java ---------------------------------------------------------------------- diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/shares/constants/ShareProductApiConstants.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/shares/constants/ShareProductApiConstants.java deleted file mode 100644 index ae384f8..0000000 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/shares/constants/ShareProductApiConstants.java +++ /dev/null @@ -1,52 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.fineract.portfolio.shares.constants; - -public interface ShareProductApiConstants { - - //Command Strings - public final String PREIEW_DIVIDENDS_COMMAND_STRING = "previewdividends" ; - public final String POST_DIVIDENdS_COMMAND_STRING = "postdividends" ; - - String id_paramname = "id"; - String name_paramname = "name"; - String shortname_paramname = "shortName"; - String description_paramname = "description"; - String externalid_paramname = "externalId"; - String totalshares_paramname = "totalShares"; - String currency_paramname = "currencyCode"; - String digitsafterdecimal_paramname = "digitsAfterDecimal"; - String inmultiplesof_paramname = "inMultiplesOf"; - String totalsharesissued_paramname = "totalSharesIssued"; - String unitprice_paramname = "unitPrice"; - String sharecapital_paramname = "shareCapital"; - String suspenseaccount_paramname = "suspenseAccount"; - String equityaccount_paramname = "equityAccount"; - String minimumshares_paramname = "minimumShares"; - String nominaltshares_paramname = "nominaltShares"; - String maximumshares_paramname = "maximumShares"; - String marketprice_paramname = "marketPrice"; - String charges_paramname = "charges"; - String allowdividendcalculationforinactiveclients_paramname = "allowDividendCalculationForInactiveClients"; - String lockperiod_paramname = "lockPeriod"; - String minimumactiveperiodfordividends_paramname = "minimumActivePeriodForDividends"; - - String startdate_paramname = "startDate"; - String sharevalue_paramname = "shareValue"; -}
http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/08c553f9/fineract-provider/src/main/java/org/apache/fineract/portfolio/shares/data/DividendsData.java ---------------------------------------------------------------------- diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/shares/data/DividendsData.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/shares/data/DividendsData.java deleted file mode 100644 index 9bba515..0000000 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/shares/data/DividendsData.java +++ /dev/null @@ -1,49 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.fineract.portfolio.shares.data; - -import java.math.BigDecimal; -import java.util.Date; - -public class DividendsData { - - private Long clientId; - - private String clientName; - - private String shareAccountNo; - - private String savingsAccountNo; - - private Long numberOfShares; - - private BigDecimal dividendAmount; - - private Date dividendIssuedDate; - - public DividendsData(final Long clientId, final String clientName, final String savingsAccountNo, final Long numberOfShares, - final BigDecimal dividendAmount, final Date dividendIssuedDate) { - this.clientId = clientId; - this.clientName = clientName; - this.savingsAccountNo = savingsAccountNo; - this.numberOfShares = numberOfShares; - this.dividendAmount = dividendAmount; - this.dividendIssuedDate = dividendIssuedDate; - } -} http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/08c553f9/fineract-provider/src/main/java/org/apache/fineract/portfolio/shares/data/ProductDividendsData.java ---------------------------------------------------------------------- diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/shares/data/ProductDividendsData.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/shares/data/ProductDividendsData.java deleted file mode 100644 index f48dc8f..0000000 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/shares/data/ProductDividendsData.java +++ /dev/null @@ -1,65 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.fineract.portfolio.shares.data; - -import java.math.BigDecimal; -import java.util.Collection; -import java.util.Date; - -import org.apache.fineract.organisation.monetary.data.CurrencyData; - - -public class ProductDividendsData { - - private Long id ; - - private Long productId ; - - private String productName ; - - private Date dividendsIssuedDate ; - - private BigDecimal dividendAmount ; - - private CurrencyData currency ; - - Collection<DividendsData> dividendsData ; - - public ProductDividendsData(final Long productId, final String productName, final Date dividendsIssuedDate, - final BigDecimal dividendAmount, final CurrencyData currency, final Collection<DividendsData> dividendsData) { - this.productId = productId ; - this.productName = productName ; - this.dividendsIssuedDate = dividendsIssuedDate ; - this.dividendAmount = dividendAmount ; - this.dividendsData = dividendsData ; - this.currency = currency ; - } - - public void setId(Long id) { - this.id = id ; - } - - public Long getId() { - return this.id ; - } - - public Long getProductId() { - return productId ; - } -} http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/08c553f9/fineract-provider/src/main/java/org/apache/fineract/portfolio/shares/data/ShareMarketPriceData.java ---------------------------------------------------------------------- diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/shares/data/ShareMarketPriceData.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/shares/data/ShareMarketPriceData.java deleted file mode 100644 index 90fb3fd..0000000 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/shares/data/ShareMarketPriceData.java +++ /dev/null @@ -1,42 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.fineract.portfolio.shares.data; - -import java.math.BigDecimal; -import java.util.Date; - -public class ShareMarketPriceData { - - private final Date startDate; - - private final BigDecimal shareValue; - - public ShareMarketPriceData(final Date startDate, final BigDecimal shareValue) { - this.startDate = startDate ; - this.shareValue = shareValue ; - } - - public Date getStartDate() { - return this.startDate; - } - - public BigDecimal getShareValue() { - return this.shareValue; - } -} http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/08c553f9/fineract-provider/src/main/java/org/apache/fineract/portfolio/shares/data/ShareProductData.java ---------------------------------------------------------------------- diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/shares/data/ShareProductData.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/shares/data/ShareProductData.java deleted file mode 100644 index 60b744f..0000000 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/shares/data/ShareProductData.java +++ /dev/null @@ -1,160 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.fineract.portfolio.shares.data; - -import java.math.BigDecimal; -import java.util.List; - -import org.apache.fineract.accounting.glaccount.data.GLAccountData; -import org.apache.fineract.infrastructure.core.data.EnumOptionData; -import org.apache.fineract.organisation.monetary.data.CurrencyData; -import org.apache.fineract.portfolio.charge.data.ChargeData; -import org.apache.fineract.portfolio.products.data.ProductData; - -public class ShareProductData implements ProductData{ - - private final Long id; - private final String name; - private final String shortName; - private final String description; - private final String externalId; - private final CurrencyData currency; - private final Long totalShares; - private final Long totalSharesIssued; - private final BigDecimal unitPrice; - private final BigDecimal shareCapital; - private final GLAccountData suspenseAccount; - private final GLAccountData equityAccount; - private final Long minimumShares; - private final Long nominaltShares; - private final Long maximumShares; - private final List<ShareMarketPriceData> marketPrice; - private final List<ChargeData> charges; - private Boolean allowDividendCalculationForInactiveClients; - private final EnumOptionData lockPeriod; - private final EnumOptionData minimumActivePeriodForDividends; - - public ShareProductData(final Long id, final String name, final String shortName, final String description, final String externalId, - final CurrencyData currency, final Long totalShares, final Long totalSharesIssued, final BigDecimal unitPrice, - final BigDecimal shareCapital, final GLAccountData suspenseAccount, final GLAccountData equityAccount, - final Long minimumShares, final Long nominaltShares, final Long maximumShares, List<ShareMarketPriceData> marketPrice, - final List<ChargeData> charges, final Boolean allowDividendCalculationForInactiveClients, final EnumOptionData lockPeriod, - final EnumOptionData minimumActivePeriodForDividends) { - this.id = id; - this.name = name; - this.shortName = shortName; - this.description = description; - this.externalId = externalId; - this.currency = currency; - this.totalShares = totalShares; - this.totalSharesIssued = totalSharesIssued; - this.unitPrice = unitPrice; - this.shareCapital = shareCapital; - this.suspenseAccount = suspenseAccount; - this.equityAccount = equityAccount; - this.minimumShares = minimumShares; - this.nominaltShares = nominaltShares; - this.maximumShares = maximumShares; - this.marketPrice = marketPrice; - this.charges = charges; - this.allowDividendCalculationForInactiveClients = allowDividendCalculationForInactiveClients; - this.lockPeriod = lockPeriod; - this.minimumActivePeriodForDividends = minimumActivePeriodForDividends; - } - - public Long getId() { - return this.id; - } - - public String getName() { - return this.name; - } - - public String getShortName() { - return this.shortName; - } - - public String getDescription() { - return this.description; - } - - public String getExternalId() { - return this.externalId; - } - - public CurrencyData getCurrency() { - return this.currency; - } - - public Long getTotalShares() { - return this.totalShares; - } - - public Long getTotalSharesIssued() { - return this.totalSharesIssued; - } - - public BigDecimal getUnitPrice() { - return this.unitPrice; - } - - public BigDecimal getShareCapital() { - return this.shareCapital; - } - - public GLAccountData getSuspenseAccount() { - return this.suspenseAccount; - } - - public GLAccountData getEquityAccount() { - return this.equityAccount; - } - - public Long getMinimumShares() { - return this.minimumShares; - } - - public Long getNominaltShares() { - return this.nominaltShares; - } - - public Long getMaximumShares() { - return this.maximumShares; - } - - public List<ShareMarketPriceData> getMarketPrice() { - return this.marketPrice; - } - - public List<ChargeData> getCharges() { - return this.charges; - } - - public Boolean getAllowDividendCalculationForInactiveClients() { - return this.allowDividendCalculationForInactiveClients; - } - - public EnumOptionData getLockPeriod() { - return this.lockPeriod; - } - - public EnumOptionData getMinimumActivePeriodForDividends() { - return this.minimumActivePeriodForDividends; - } -} http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/08c553f9/fineract-provider/src/main/java/org/apache/fineract/portfolio/shares/domain/ShareMarketPrice.java ---------------------------------------------------------------------- diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/shares/domain/ShareMarketPrice.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/shares/domain/ShareMarketPrice.java deleted file mode 100644 index 8b84c55..0000000 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/shares/domain/ShareMarketPrice.java +++ /dev/null @@ -1,65 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.fineract.portfolio.shares.domain; - -import java.math.BigDecimal; -import java.util.Date; - -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.JoinColumn; -import javax.persistence.ManyToOne; -import javax.persistence.Table; -import javax.persistence.Temporal; -import javax.persistence.TemporalType; - -import org.springframework.data.jpa.domain.AbstractPersistable; - -@Entity -@Table(name = "m_share_marketprice") -public class ShareMarketPrice extends AbstractPersistable<Long> { - - @ManyToOne(optional = false) - @JoinColumn(name = "product_id", referencedColumnName = "id", nullable = false) - private ShareProduct product; - - @Column(name = "start_date") - @Temporal(TemporalType.DATE) - private Date startDate; - - @Column(name = "share_value", nullable = false) - private BigDecimal shareValue ; - - public ShareMarketPrice(final Date startDate, final BigDecimal shareValue) { - this.startDate = startDate ; - this.shareValue = shareValue ; - } - - public void setShareProduct(final ShareProduct product) { - this.product = product ; - } - - public Date getStartDate() { - return this.startDate ; - } - - public BigDecimal getPrice() { - return this.shareValue ; - } -} http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/08c553f9/fineract-provider/src/main/java/org/apache/fineract/portfolio/shares/domain/ShareProduct.java ---------------------------------------------------------------------- diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/shares/domain/ShareProduct.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/shares/domain/ShareProduct.java deleted file mode 100644 index 2c50648..0000000 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/shares/domain/ShareProduct.java +++ /dev/null @@ -1,363 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.fineract.portfolio.shares.domain; - -import java.math.BigDecimal; -import java.util.ArrayList; -import java.util.Date; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -import javax.persistence.CascadeType; -import javax.persistence.Column; -import javax.persistence.Embedded; -import javax.persistence.Entity; -import javax.persistence.EnumType; -import javax.persistence.Enumerated; -import javax.persistence.FetchType; -import javax.persistence.JoinColumn; -import javax.persistence.JoinTable; -import javax.persistence.ManyToMany; -import javax.persistence.ManyToOne; -import javax.persistence.OneToMany; -import javax.persistence.Table; -import javax.persistence.Temporal; -import javax.persistence.TemporalType; - -import org.apache.fineract.accounting.glaccount.data.GLAccountData; -import org.apache.fineract.accounting.glaccount.domain.GLAccount; -import org.apache.fineract.infrastructure.core.data.EnumOptionData; -import org.apache.fineract.infrastructure.core.domain.AbstractAuditableCustom; -import org.apache.fineract.organisation.monetary.data.CurrencyData; -import org.apache.fineract.organisation.monetary.domain.MonetaryCurrency; -import org.apache.fineract.portfolio.charge.data.ChargeData; -import org.apache.fineract.portfolio.charge.domain.Charge; -import org.apache.fineract.portfolio.common.domain.PeriodFrequencyType; -import org.apache.fineract.portfolio.shares.data.ShareMarketPriceData; -import org.apache.fineract.portfolio.shares.data.ShareProductData; -import org.apache.fineract.useradministration.domain.AppUser; -import org.hibernate.annotations.LazyCollection; -import org.hibernate.annotations.LazyCollectionOption; -import org.joda.time.DateTime; - -@Entity -@Table(name = "m_shareproducts") -public class ShareProduct extends AbstractAuditableCustom<AppUser, Long> { - - @Column(name = "name", nullable = false, unique = true) - private String name; - - @Column(name = "short_name", nullable = false, unique = true) - private String shortName; - - @Column(name = "description") - private String description; - - @Column(name = "start_date") - @Temporal(TemporalType.DATE) - private Date startDate; - - @Column(name = "end_date") - @Temporal(TemporalType.DATE) - private Date endDate; - - @Column(name = "external_id", length = 100, nullable = true, unique = true) - private String externalId; - - @Embedded - private MonetaryCurrency currency; - - @Column(name = "total_shares", nullable = false) - private Long totalShares; - - @Column(name = "total_shares_issued", nullable = false) - private Long totalSharesIssued; - - @Column(name = "unit_price", nullable = false) - private BigDecimal unitPrice; - - @Column(name = "share_capital", nullable = false) - private BigDecimal shareCapital; - - @ManyToOne - @JoinColumn(name = "suspence_account", nullable = false) - private GLAccount suspenseAccount; - - @ManyToOne - @JoinColumn(name = "equity_account", nullable = false) - private GLAccount equityAccount; - - @Column(name = "minimum_client_shares") - private Long minimumShares; - - @Column(name = "default_client_shares", nullable = false) - private Long nominalShares; - - @Column(name = "maximum_client_shares") - private Long maximumShares; - - @LazyCollection(LazyCollectionOption.FALSE) - @OneToMany(cascade = CascadeType.ALL, mappedBy = "product", orphanRemoval = true) - Set<ShareMarketPrice> marketPrice = new HashSet<>(); - - @ManyToMany(fetch = FetchType.EAGER) - @JoinTable(name = "m_product_charges", joinColumns = @JoinColumn(name = "product_id"), inverseJoinColumns = @JoinColumn(name = "charge_id")) - private Set<Charge> charges; - - @Column(name = "allow_dividends_inactive_clients") - private Boolean allowDividendCalculationForInactiveClients; - - @Enumerated(EnumType.ORDINAL) - @Column(name = "lock_period", nullable = true) - private PeriodFrequencyType lockPeriod; - - @Enumerated(EnumType.ORDINAL) - @Column(name = "dividend_active_period", nullable = true) - private PeriodFrequencyType minimumActivePeriodForDividends; - - protected ShareProduct() { - - } - // FIXME Remove this method - public void setTempId(Long id) { - super.setId(id); - } - - public ShareProduct(final String name, final String shortName, final String description, final String externalId, - final MonetaryCurrency currency, final Long totalShares, final Long totalSharesIssued, final BigDecimal unitPrice, - final BigDecimal shareCapital, final GLAccount suspenseAccount, final GLAccount equityAccount, final Long minimumShares, - final Long nominalShares, final Long maximumShares, Set<ShareMarketPrice> marketPrice, Set<Charge> charges, - final Boolean allowDividendCalculationForInactiveClients, final PeriodFrequencyType lockPeriod, - final PeriodFrequencyType minimumActivePeriodForDividends, - AppUser createdBy, DateTime createdDate, AppUser lastModifiedBy, DateTime lastModifiedDate) { - this.name = name; - this.shortName = shortName; - this.description = description; - this.externalId = externalId; - this.currency = currency; - this.totalShares = totalShares; - this.totalSharesIssued = totalSharesIssued; - this.unitPrice = unitPrice; - this.shareCapital = shareCapital; - this.suspenseAccount = suspenseAccount; - this.equityAccount = equityAccount; - this.minimumShares = minimumShares; - this.nominalShares = nominalShares; - this.maximumShares = maximumShares; - this.marketPrice = marketPrice; - this.charges = charges; - this.allowDividendCalculationForInactiveClients = allowDividendCalculationForInactiveClients; - this.lockPeriod = lockPeriod; - this.minimumActivePeriodForDividends = minimumActivePeriodForDividends; - setCreatedBy(createdBy) ; - setCreatedDate(createdDate) ; - setLastModifiedBy(lastModifiedBy) ; - setLastModifiedDate(lastModifiedDate) ; - } - - public ShareProductData toData() { - GLAccountData suspenseAccount1 = new GLAccountData(suspenseAccount.getId(), suspenseAccount.getName(), suspenseAccount.getGlCode()); - GLAccountData equityAccount1 = new GLAccountData(equityAccount.getId(), equityAccount.getName(), equityAccount.getGlCode()); - List<ChargeData> chargeData = new ArrayList<>(); - for(Charge charge: this.charges) { - chargeData.add(ChargeData.lookup(charge.getId(), charge.getName(), charge.isPenalty())) ; - } - List<ShareMarketPriceData> marketData = new ArrayList<>() ; - for(ShareMarketPrice pri: marketPrice) { - marketData.add(new ShareMarketPriceData(pri.getStartDate(), pri.getPrice())) ; - } - EnumOptionData lock = new EnumOptionData(this.lockPeriod.getValue().longValue(), this.lockPeriod.getCode(), - this.lockPeriod.toString()); - EnumOptionData mini = new EnumOptionData(this.minimumActivePeriodForDividends.getValue().longValue(), this.minimumActivePeriodForDividends.getCode(), - this.minimumActivePeriodForDividends.toString());; - CurrencyData curr = new CurrencyData(currency.getCode(), "", currency.getDigitsAfterDecimal(), currency.getCurrencyInMultiplesOf(), - "", ""); - return new ShareProductData(getId(), name, shortName, description, externalId, curr, totalShares, totalSharesIssued, unitPrice, - shareCapital, suspenseAccount1, equityAccount1, minimumShares, nominalShares, maximumShares, marketData, chargeData, - allowDividendCalculationForInactiveClients, lock, mini); - } - - public boolean setProductName(String productName) { - boolean returnValue = false; - if (!this.name.equals(productName)) { - this.name = productName; - returnValue = true; - } - return returnValue; - } - - public String getProductName() { - return this.name ; - } - - public boolean setShortName(String shortName) { - boolean returnValue = false; - if (!this.shortName.equals(shortName)) { - this.shortName = shortName; - returnValue = true; - } - return returnValue; - } - - public boolean setDescription(String description) { - boolean returnValue = false; - if (!this.description.equals(description)) { - this.description = description; - returnValue = true; - } - return returnValue; - } - - public boolean setExternalId(String externalId) { - boolean returnValue = false; - if (!this.externalId.equals(externalId)) { - this.externalId = externalId; - returnValue = true; - } - return returnValue; - } - - public boolean setTotalShares(Long totalShares) { - boolean returnValue = false; - if (!this.totalShares.equals(totalShares)) { - this.totalShares = totalShares; - returnValue = true; - } - return returnValue; - - } - - public Long getTotalShares() { - return this.totalShares ; - } - - public boolean setTotalIssuedShares(Long totalSharesIssued) { - boolean returnValue = false; - if (!this.totalSharesIssued.equals(totalSharesIssued)) { - this.totalSharesIssued = totalSharesIssued; - returnValue = true; - } - return returnValue; - } - - public boolean setMonetaryCurrency(MonetaryCurrency currency) { - boolean returnValue = false; - if (!this.currency.equals(currency)) { - this.currency = currency; - returnValue = true; - } - return returnValue; - } - - public MonetaryCurrency getCurrency() { - return this.currency ; - } - - public boolean setUnitPrice(BigDecimal unitPrice) { - boolean returnValue = false; - if (!this.unitPrice.equals(unitPrice)) { - this.unitPrice = unitPrice; - returnValue = true; - } - return returnValue; - } - - public boolean setSuspenseAccount(GLAccount suspenseAccount) { - boolean returnValue = false; - if (!this.suspenseAccount.getId().equals(suspenseAccount.getId())) { - this.suspenseAccount = suspenseAccount; - returnValue = true; - } - return returnValue; - } - - public boolean setEquityAccount(GLAccount equityAccount) { - boolean returnValue = false; - if (!this.equityAccount.getId().equals(equityAccount.getId())) { - this.equityAccount = equityAccount; - returnValue = true; - } - return returnValue; - } - - public boolean setMinimumShares(final Long minimumShares) { - boolean returnValue = false; - if (!this.minimumShares.equals(minimumShares)) { - this.minimumShares = minimumShares; - returnValue = true; - } - return returnValue; - } - - public boolean setNominalShares(final Long nominalShares) { - boolean returnValue = false; - if (!this.nominalShares.equals(nominalShares)) { - this.nominalShares = nominalShares; - returnValue = true; - } - return returnValue; - } - - public boolean setMaximumShares(final Long maximumShares) { - boolean returnValue = false; - if (!this.maximumShares.equals(maximumShares)) { - this.maximumShares = maximumShares; - returnValue = true; - } - return returnValue; - } - - public boolean setMarketPrice(Set<ShareMarketPrice> marketPrice) { - this.marketPrice = marketPrice; - return true; - } - - public boolean setCharges(Set<Charge> charges) { - this.charges = charges; - return true; - } - - public boolean setAllowDividendCalculationForInactiveClients(Boolean allowDividendCalculationForInactiveClients) { - boolean returnValue = false; - if (!this.allowDividendCalculationForInactiveClients.equals(allowDividendCalculationForInactiveClients)) { - this.allowDividendCalculationForInactiveClients = allowDividendCalculationForInactiveClients; - returnValue = true; - } - return returnValue; - } - - public boolean setLockPeriod(final PeriodFrequencyType lockPeriod) { - boolean returnValue = false; - if (!this.lockPeriod.equals(lockPeriod)) { - this.lockPeriod = lockPeriod; - returnValue = true; - } - return returnValue; - } - - public boolean setminimumActivePeriodForDividends(final PeriodFrequencyType minimumActivePeriodForDividends) { - boolean returnValue = false; - if (!this.minimumActivePeriodForDividends.equals(minimumActivePeriodForDividends)) { - this.minimumActivePeriodForDividends = minimumActivePeriodForDividends; - returnValue = true; - } - return returnValue; - } -} http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/08c553f9/fineract-provider/src/main/java/org/apache/fineract/portfolio/shares/domain/ShareProductRepository.java ---------------------------------------------------------------------- diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/shares/domain/ShareProductRepository.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/shares/domain/ShareProductRepository.java deleted file mode 100644 index e6a3693..0000000 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/shares/domain/ShareProductRepository.java +++ /dev/null @@ -1,27 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.fineract.portfolio.shares.domain; - -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.JpaSpecificationExecutor; - - -public interface ShareProductRepository extends JpaRepository<ShareProduct, Long>, JpaSpecificationExecutor<ShareProduct> { - -} http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/08c553f9/fineract-provider/src/main/java/org/apache/fineract/portfolio/shares/domain/ShareProductTempRepository.java ---------------------------------------------------------------------- diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/shares/domain/ShareProductTempRepository.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/shares/domain/ShareProductTempRepository.java deleted file mode 100644 index f6c0fac..0000000 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/shares/domain/ShareProductTempRepository.java +++ /dev/null @@ -1,79 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.fineract.portfolio.shares.domain; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.Map; - -import org.apache.fineract.portfolio.accounts.domain.ShareAccount; -import org.apache.fineract.portfolio.shares.data.ProductDividendsData; - - -public class ShareProductTempRepository { - - Map<Long, ShareProduct> cache = new HashMap<>() ; - Map<Long, ArrayList<ShareAccount>> accountsCache = new HashMap<>() ; - Map<Long, ProductDividendsData> dividendsCahe = new HashMap<>() ; - - private final static ShareProductTempRepository instance = new ShareProductTempRepository() ; - - private ShareProductTempRepository() { - - } - - public final static ShareProductTempRepository getInstance() { - return instance ; - } - - public ShareProduct fineOne(Long productId) { - return this.cache.get(productId) ; - } - - public Collection<ShareProduct> findAll() { - return this.cache.values() ; - } - public void save(ShareProduct product) { - Long id = new Long(cache.size() + 1) ; - product.setTempId(id) ; - this.cache.put(id, product) ; - } - - public void addAccount(Long productId, ShareAccount account) { - if(accountsCache.containsKey(productId)) { - ArrayList<ShareAccount> list = accountsCache.get(productId) ; - list.add(account) ; - }else { - ArrayList<ShareAccount> list = new ArrayList<>() ; - list.add(account) ; - accountsCache.put(productId, list) ; - } - } - - public ArrayList<ShareAccount> getAllAccounts(Long productId) { - return accountsCache.get(productId) ; - } - - public void saveDividends(ProductDividendsData data) { - Long id = new Long(dividendsCahe.size()+1) ; - data.setId(id) ; - dividendsCahe.put(data.getProductId(), data) ; - } -} http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/08c553f9/fineract-provider/src/main/java/org/apache/fineract/portfolio/shares/handler/CreateShareProductCommandHandler.java ---------------------------------------------------------------------- diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/shares/handler/CreateShareProductCommandHandler.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/shares/handler/CreateShareProductCommandHandler.java deleted file mode 100644 index 4ba6023..0000000 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/shares/handler/CreateShareProductCommandHandler.java +++ /dev/null @@ -1,47 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.fineract.portfolio.shares.handler; - -import org.apache.fineract.commands.annotation.CommandType; -import org.apache.fineract.commands.handler.NewCommandSourceHandler; -import org.apache.fineract.infrastructure.core.api.JsonCommand; -import org.apache.fineract.infrastructure.core.data.CommandProcessingResult; -import org.apache.fineract.portfolio.shares.service.ShareProductWritePlatformService; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -@Service -@CommandType(entity = "SHAREPRODUCT", action = "CREATE") -public class CreateShareProductCommandHandler implements NewCommandSourceHandler { - - private final ShareProductWritePlatformService shareProductWritePlatformService ; - - @Autowired - public CreateShareProductCommandHandler(final ShareProductWritePlatformService shareProductWritePlatformService) { - this.shareProductWritePlatformService = shareProductWritePlatformService ; - } - - @Transactional - @Override - public CommandProcessingResult processCommand(JsonCommand jsonCommand) { - return this.shareProductWritePlatformService.createShareProduct(jsonCommand); - } - -} http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/08c553f9/fineract-provider/src/main/java/org/apache/fineract/portfolio/shares/handler/UpdateShareProductCommandHandler.java ---------------------------------------------------------------------- diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/shares/handler/UpdateShareProductCommandHandler.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/shares/handler/UpdateShareProductCommandHandler.java deleted file mode 100644 index c2003fa..0000000 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/shares/handler/UpdateShareProductCommandHandler.java +++ /dev/null @@ -1,47 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.fineract.portfolio.shares.handler; - -import org.apache.fineract.commands.annotation.CommandType; -import org.apache.fineract.commands.handler.NewCommandSourceHandler; -import org.apache.fineract.infrastructure.core.api.JsonCommand; -import org.apache.fineract.infrastructure.core.data.CommandProcessingResult; -import org.apache.fineract.portfolio.shares.service.ShareProductWritePlatformService; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -@Service -@CommandType(entity = "SHAREPRODUCT", action = "UPDATE") -public class UpdateShareProductCommandHandler implements NewCommandSourceHandler { - - private final ShareProductWritePlatformService shareProductWritePlatformService ; - - @Autowired - public UpdateShareProductCommandHandler(final ShareProductWritePlatformService shareProductWritePlatformService) { - this.shareProductWritePlatformService = shareProductWritePlatformService ; - } - - @Transactional - @Override - public CommandProcessingResult processCommand(JsonCommand jsonCommand) { - return this.shareProductWritePlatformService.updateProduct(jsonCommand.entityId(), jsonCommand); - } - -} http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/08c553f9/fineract-provider/src/main/java/org/apache/fineract/portfolio/shares/serialization/ShareProductDataSerializer.java ---------------------------------------------------------------------- diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/shares/serialization/ShareProductDataSerializer.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/shares/serialization/ShareProductDataSerializer.java deleted file mode 100644 index 59c65d8..0000000 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/shares/serialization/ShareProductDataSerializer.java +++ /dev/null @@ -1,341 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.fineract.portfolio.shares.serialization; - -import java.lang.reflect.Type; -import java.math.BigDecimal; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Locale; -import java.util.Map; -import java.util.Set; - -import org.apache.commons.lang.StringUtils; -import org.apache.fineract.accounting.glaccount.domain.GLAccount; -import org.apache.fineract.accounting.glaccount.domain.GLAccountRepositoryWrapper; -import org.apache.fineract.infrastructure.core.api.JsonCommand; -import org.apache.fineract.infrastructure.core.data.ApiParameterError; -import org.apache.fineract.infrastructure.core.data.DataValidatorBuilder; -import org.apache.fineract.infrastructure.core.exception.InvalidJsonException; -import org.apache.fineract.infrastructure.core.serialization.FromJsonHelper; -import org.apache.fineract.infrastructure.core.service.DateUtils; -import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext; -import org.apache.fineract.organisation.monetary.domain.MonetaryCurrency; -import org.apache.fineract.portfolio.charge.domain.Charge; -import org.apache.fineract.portfolio.charge.domain.ChargeRepositoryWrapper; -import org.apache.fineract.portfolio.common.domain.PeriodFrequencyType; -import org.apache.fineract.portfolio.loanproduct.exception.InvalidCurrencyException; -import org.apache.fineract.portfolio.shares.constants.ShareProductApiConstants; -import org.apache.fineract.portfolio.shares.domain.ShareMarketPrice; -import org.apache.fineract.portfolio.shares.domain.ShareProduct; -import org.apache.fineract.useradministration.domain.AppUser; -import org.joda.time.DateTime; -import org.joda.time.LocalDate; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; - -import com.google.gson.JsonArray; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.google.gson.reflect.TypeToken; - -//This class responsibility is to validate data and serialize to entity and return object to the caller -@Service -public class ShareProductDataSerializer { - - private final Set<String> supportedParameters = new HashSet<>(Arrays.asList("")); - - private final FromJsonHelper fromApiJsonHelper; - - private final ChargeRepositoryWrapper chargeRepository; - - private final GLAccountRepositoryWrapper glAccountRepository; - - private final PlatformSecurityContext platformSecurityContext ; - - @Autowired - public ShareProductDataSerializer(final FromJsonHelper fromApiJsonHelper, final ChargeRepositoryWrapper chargeRepository, - final GLAccountRepositoryWrapper glAccountRepository, - final PlatformSecurityContext platformSecurityContext) { - this.fromApiJsonHelper = fromApiJsonHelper; - this.chargeRepository = chargeRepository; - this.glAccountRepository = glAccountRepository; - this.platformSecurityContext = platformSecurityContext ; - } - - public ShareProduct validateAndCreate(JsonCommand jsonCommand) { - if (StringUtils.isBlank(jsonCommand.json())) { throw new InvalidJsonException(); } - final Type typeOfMap = new TypeToken<Map<String, Object>>() {}.getType(); - //this.fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, jsonCommand.json(), supportedParameters); - - final List<ApiParameterError> dataValidationErrors = new ArrayList<>(); - final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("sharesproduct"); - JsonElement element = jsonCommand.parsedJson(); - final Locale locale = this.fromApiJsonHelper.extractLocaleParameter(element.getAsJsonObject()); - final String productName = this.fromApiJsonHelper.extractStringNamed(ShareProductApiConstants.name_paramname, element); - baseDataValidator.reset().parameter(ShareProductApiConstants.name_paramname).value(productName).notBlank() - .notExceedingLengthOf(200); - final String shortName = this.fromApiJsonHelper.extractStringNamed(ShareProductApiConstants.shortname_paramname, element); - baseDataValidator.reset().parameter(ShareProductApiConstants.shortname_paramname).value(shortName).notBlank() - .notExceedingLengthOf(10); - String description = null; - if (this.fromApiJsonHelper.parameterExists(ShareProductApiConstants.description_paramname, element)) { - description = this.fromApiJsonHelper.extractStringNamed(ShareProductApiConstants.description_paramname, element); - } - - String externalId = this.fromApiJsonHelper.extractStringNamed(ShareProductApiConstants.externalid_paramname, element); - Long totalNumberOfShares = this.fromApiJsonHelper.extractLongNamed(ShareProductApiConstants.totalshares_paramname, element); - final String currencyCode = this.fromApiJsonHelper.extractStringNamed(ShareProductApiConstants.currency_paramname, element); - final Integer digitsAfterDecimal = this.fromApiJsonHelper.extractIntegerWithLocaleNamed( - ShareProductApiConstants.digitsafterdecimal_paramname, element); - final Integer inMultiplesOf = this.fromApiJsonHelper.extractIntegerWithLocaleNamed( - ShareProductApiConstants.inmultiplesof_paramname, element); - final MonetaryCurrency currency = new MonetaryCurrency(currencyCode, digitsAfterDecimal, inMultiplesOf); - final Long sharesIssued = this.fromApiJsonHelper.extractLongNamed(ShareProductApiConstants.totalsharesissued_paramname, element); - final BigDecimal unitPrice = this.fromApiJsonHelper.extractBigDecimalNamed(ShareProductApiConstants.unitprice_paramname, element, - locale); - final BigDecimal shareCapitalValue = null; - Long suspenseAccountId = this.fromApiJsonHelper.extractLongNamed(ShareProductApiConstants.suspenseaccount_paramname, element); - Long equityAccountId = this.fromApiJsonHelper.extractLongNamed(ShareProductApiConstants.equityaccount_paramname, element); - Long minimumClientShares = this.fromApiJsonHelper.extractLongNamed(ShareProductApiConstants.minimumshares_paramname, element); - Long nominalClientShares = this.fromApiJsonHelper.extractLongNamed(ShareProductApiConstants.nominaltshares_paramname, element); - Long maximumClientShares = this.fromApiJsonHelper.extractLongNamed(ShareProductApiConstants.maximumshares_paramname, element); - Set<ShareMarketPrice> marketPriceSet = asembleShareMarketPrice(element); - Set<Charge> charges = assembleListOfProductCharges(element, currencyCode); - Boolean allowdividendsForInactiveClients = this.fromApiJsonHelper.extractBooleanNamed( - ShareProductApiConstants.allowdividendcalculationforinactiveclients_paramname, element); - PeriodFrequencyType lockPeriod = extractPeriodType(ShareProductApiConstants.lockperiod_paramname, element); - PeriodFrequencyType minimumActivePeriod = extractPeriodType(ShareProductApiConstants.minimumactiveperiodfordividends_paramname, - element); - GLAccount suspenseAccount = glAccountRepository.findOneWithNotFoundDetection(suspenseAccountId); - GLAccount equityAccount = glAccountRepository.findOneWithNotFoundDetection(equityAccountId); - AppUser modifiedBy = null; - DateTime modifiedOn = null; - AppUser createdBy = platformSecurityContext.authenticatedUser() ; - DateTime createdDate = DateUtils.getLocalDateTimeOfTenant().toDateTime() ; - ShareProduct product = new ShareProduct(productName, shortName, description, externalId, currency, totalNumberOfShares, - sharesIssued, unitPrice, shareCapitalValue, suspenseAccount, equityAccount, minimumClientShares, nominalClientShares, - maximumClientShares, marketPriceSet, charges, allowdividendsForInactiveClients, lockPeriod, minimumActivePeriod, - createdBy, createdDate, modifiedBy, modifiedOn); - return product; - } - - private PeriodFrequencyType extractPeriodType(String paramName, final JsonElement element) { - PeriodFrequencyType frequencyType = PeriodFrequencyType.INVALID; - frequencyType = PeriodFrequencyType.fromInt(this.fromApiJsonHelper.extractIntegerWithLocaleNamed(paramName, element)); - return frequencyType; - } - - private Set<ShareMarketPrice> asembleShareMarketPrice(final JsonElement element) { - Set<ShareMarketPrice> set = null; - if (this.fromApiJsonHelper.parameterExists(ShareProductApiConstants.marketprice_paramname, element)) { - set = new HashSet<>(); - JsonArray array = this.fromApiJsonHelper.extractJsonArrayNamed(ShareProductApiConstants.marketprice_paramname, element); - for (JsonElement arrayElement : array) { - LocalDate localDate = this.fromApiJsonHelper.extractLocalDateNamed(ShareProductApiConstants.startdate_paramname, - arrayElement); - final BigDecimal shareValue = this.fromApiJsonHelper.extractBigDecimalWithLocaleNamed( - ShareProductApiConstants.sharevalue_paramname, arrayElement); - ShareMarketPrice obj = new ShareMarketPrice(localDate.toDate(), shareValue); - set.add(obj); - } - } - return set; - } - - private Set<Charge> assembleListOfProductCharges(final JsonElement element, final String currencyCode) { - final Set<Charge> charges = new HashSet<>(); - if (this.fromApiJsonHelper.parameterExists(ShareProductApiConstants.charges_paramname, element)) { - JsonArray chargesArray = this.fromApiJsonHelper.extractJsonArrayNamed(ShareProductApiConstants.charges_paramname, element); - if (chargesArray != null) { - for (int i = 0; i < chargesArray.size(); i++) { - final JsonObject jsonObject = chargesArray.get(i).getAsJsonObject(); - if (jsonObject.has("id")) { - final Long id = jsonObject.get("id").getAsLong(); - final Charge charge = this.chargeRepository.findOneWithNotFoundDetection(id); - if (!currencyCode.equals(charge.getCurrencyCode())) { - final String errorMessage = "Charge and Loan Product must have the same currency."; - throw new InvalidCurrencyException("charge", "attach.to.loan.product", errorMessage); - } - charges.add(charge); - } - } - } - } - return charges; - } - - public Map<String, Object> validateAndUpdate(JsonCommand jsonCommand, ShareProduct product) { - Map<String, Object> actualChanges = new HashMap<>(); - - if (StringUtils.isBlank(jsonCommand.json())) { throw new InvalidJsonException(); } - final Type typeOfMap = new TypeToken<Map<String, Object>>() {}.getType(); - //this.fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, jsonCommand.json(), supportedParameters); - - final List<ApiParameterError> dataValidationErrors = new ArrayList<>(); - final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("sharesproduct"); - - JsonElement element = jsonCommand.parsedJson(); - final Locale locale = this.fromApiJsonHelper.extractLocaleParameter(element.getAsJsonObject()); - if (this.fromApiJsonHelper.parameterExists(ShareProductApiConstants.name_paramname, element)) { - final String productName = this.fromApiJsonHelper.extractStringNamed(ShareProductApiConstants.name_paramname, element); - if (product.setProductName(productName)) { - actualChanges.put(ShareProductApiConstants.name_paramname, productName); - } - } - - if (this.fromApiJsonHelper.parameterExists(ShareProductApiConstants.shortname_paramname, element)) { - final String shortName = this.fromApiJsonHelper.extractStringNamed(ShareProductApiConstants.shortname_paramname, element); - if (product.setShortName(shortName)) { - actualChanges.put(ShareProductApiConstants.shortname_paramname, shortName); - } - } - if (this.fromApiJsonHelper.parameterExists(ShareProductApiConstants.description_paramname, element)) { - String description = this.fromApiJsonHelper.extractStringNamed(ShareProductApiConstants.description_paramname, element); - if (product.setDescription(description)) { - actualChanges.put(ShareProductApiConstants.description_paramname, description); - } - } - - if (this.fromApiJsonHelper.parameterExists(ShareProductApiConstants.externalid_paramname, element)) { - String externalId = this.fromApiJsonHelper.extractStringNamed(ShareProductApiConstants.externalid_paramname, element); - if (product.setExternalId(externalId)) { - actualChanges.put(ShareProductApiConstants.externalid_paramname, externalId); - } - } - - if (this.fromApiJsonHelper.parameterExists(ShareProductApiConstants.totalshares_paramname, element)) { - Long totalShares = this.fromApiJsonHelper.extractLongNamed(ShareProductApiConstants.totalshares_paramname, element); - if (product.setTotalShares(totalShares)) { - actualChanges.put(ShareProductApiConstants.totalshares_paramname, totalShares); - } - } - - if (this.fromApiJsonHelper.parameterExists(ShareProductApiConstants.totalsharesissued_paramname, element)) { - final Long sharesIssued = this.fromApiJsonHelper - .extractLongNamed(ShareProductApiConstants.totalsharesissued_paramname, element); - if (product.setTotalIssuedShares(sharesIssued)) { - actualChanges.put(ShareProductApiConstants.totalsharesissued_paramname, sharesIssued); - } - } - - if (this.fromApiJsonHelper.parameterExists(ShareProductApiConstants.currency_paramname, element) - && this.fromApiJsonHelper.parameterExists(ShareProductApiConstants.digitsafterdecimal_paramname, element) - && this.fromApiJsonHelper.parameterExists(ShareProductApiConstants.inmultiplesof_paramname, element)) { - final String currencyCode = this.fromApiJsonHelper.extractStringNamed(ShareProductApiConstants.currency_paramname, element); - final Integer digitsAfterDecimal = this.fromApiJsonHelper.extractIntegerWithLocaleNamed( - ShareProductApiConstants.digitsafterdecimal_paramname, element); - final Integer inMultiplesOf = this.fromApiJsonHelper.extractIntegerWithLocaleNamed( - ShareProductApiConstants.inmultiplesof_paramname, element); - final MonetaryCurrency currency = new MonetaryCurrency(currencyCode, digitsAfterDecimal, inMultiplesOf); - if (product.setMonetaryCurrency(currency)) { - actualChanges.put(ShareProductApiConstants.currency_paramname, currency); - } - } - - if (this.fromApiJsonHelper.parameterExists(ShareProductApiConstants.unitprice_paramname, element)) { - final BigDecimal unitPrice = this.fromApiJsonHelper.extractBigDecimalNamed(ShareProductApiConstants.unitprice_paramname, - element, locale); - if (product.setUnitPrice(unitPrice)) { - actualChanges.put(ShareProductApiConstants.unitprice_paramname, unitPrice); - } - } - - if (this.fromApiJsonHelper.parameterExists(ShareProductApiConstants.suspenseaccount_paramname, element)) { - Long suspenseAccountId = this.fromApiJsonHelper.extractLongNamed(ShareProductApiConstants.suspenseaccount_paramname, element); - GLAccount suspenseAccount = glAccountRepository.findOneWithNotFoundDetection(suspenseAccountId); - if (product.setSuspenseAccount(suspenseAccount)) { - actualChanges.put(ShareProductApiConstants.suspenseaccount_paramname, suspenseAccount); - } - } - - if (this.fromApiJsonHelper.parameterExists(ShareProductApiConstants.equityaccount_paramname, element)) { - Long equityAccountId = this.fromApiJsonHelper.extractLongNamed(ShareProductApiConstants.equityaccount_paramname, element); - GLAccount equityAccount = glAccountRepository.findOneWithNotFoundDetection(equityAccountId); - if (product.setEquityAccount(equityAccount)) { - actualChanges.put(ShareProductApiConstants.equityaccount_paramname, equityAccount); - } - } - - if (this.fromApiJsonHelper.parameterExists(ShareProductApiConstants.minimumshares_paramname, element)) { - Long minimumClientShares = this.fromApiJsonHelper.extractLongNamed(ShareProductApiConstants.minimumshares_paramname, element); - if (product.setMinimumShares(minimumClientShares)) { - actualChanges.put(ShareProductApiConstants.minimumshares_paramname, minimumClientShares); - } - } - - if (this.fromApiJsonHelper.parameterExists(ShareProductApiConstants.nominaltshares_paramname, element)) { - Long nominalClientShares = this.fromApiJsonHelper.extractLongNamed(ShareProductApiConstants.nominaltshares_paramname, element); - if (product.setNominalShares(nominalClientShares)) { - actualChanges.put(ShareProductApiConstants.nominaltshares_paramname, nominalClientShares); - } - } - - if (this.fromApiJsonHelper.parameterExists(ShareProductApiConstants.maximumshares_paramname, element)) { - Long maximumClientShares = this.fromApiJsonHelper.extractLongNamed(ShareProductApiConstants.maximumshares_paramname, element); - if (product.setMaximumShares(maximumClientShares)) { - actualChanges.put(ShareProductApiConstants.maximumshares_paramname, maximumClientShares); - } - } - - if (this.fromApiJsonHelper.parameterExists(ShareProductApiConstants.marketprice_paramname, element)) { - Set<ShareMarketPrice> marketPrice = asembleShareMarketPrice(element); - if (product.setMarketPrice(marketPrice)) { - actualChanges.put(ShareProductApiConstants.marketprice_paramname, marketPrice); - } - } - - if (this.fromApiJsonHelper.parameterExists(ShareProductApiConstants.charges_paramname, element)) { - final String currencyCode = this.fromApiJsonHelper.extractStringNamed(ShareProductApiConstants.currency_paramname, element); - Set<Charge> charges = assembleListOfProductCharges(element, currencyCode); - if (product.setCharges(charges)) { - actualChanges.put(ShareProductApiConstants.charges_paramname, charges); - } - } - - if (this.fromApiJsonHelper.parameterExists(ShareProductApiConstants.allowdividendcalculationforinactiveclients_paramname, element)) { - Boolean allowdividendsForInactiveClients = this.fromApiJsonHelper.extractBooleanNamed( - ShareProductApiConstants.allowdividendcalculationforinactiveclients_paramname, element); - if (product.setAllowDividendCalculationForInactiveClients(allowdividendsForInactiveClients)) { - actualChanges.put(ShareProductApiConstants.allowdividendcalculationforinactiveclients_paramname, - allowdividendsForInactiveClients); - } - } - - if (this.fromApiJsonHelper.parameterExists(ShareProductApiConstants.lockperiod_paramname, element)) { - PeriodFrequencyType lockPeriod = extractPeriodType(ShareProductApiConstants.lockperiod_paramname, element); - if (product.setLockPeriod(lockPeriod)) { - actualChanges.put(ShareProductApiConstants.lockperiod_paramname, lockPeriod); - } - } - - if (this.fromApiJsonHelper.parameterExists(ShareProductApiConstants.minimumactiveperiodfordividends_paramname, element)) { - PeriodFrequencyType minimumActivePeriod = extractPeriodType(ShareProductApiConstants.minimumactiveperiodfordividends_paramname, - element); - if (product.setminimumActivePeriodForDividends(minimumActivePeriod)) { - actualChanges.put(ShareProductApiConstants.minimumactiveperiodfordividends_paramname, minimumActivePeriod); - } - } - return actualChanges; - } - -} http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/08c553f9/fineract-provider/src/main/java/org/apache/fineract/portfolio/shares/service/ShareProductCommandsServiceImpl.java ---------------------------------------------------------------------- diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/shares/service/ShareProductCommandsServiceImpl.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/shares/service/ShareProductCommandsServiceImpl.java deleted file mode 100644 index 3257adf..0000000 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/shares/service/ShareProductCommandsServiceImpl.java +++ /dev/null @@ -1,105 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.fineract.portfolio.shares.service; - -import java.math.BigDecimal; -import java.util.ArrayList; -import java.util.Date; - -import org.apache.fineract.infrastructure.core.api.JsonCommand; -import org.apache.fineract.infrastructure.core.data.CommandProcessingResult; -import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder; -import org.apache.fineract.infrastructure.core.serialization.FromJsonHelper; -import org.apache.fineract.organisation.monetary.data.CurrencyData; -import org.apache.fineract.organisation.monetary.domain.MonetaryCurrency; -import org.apache.fineract.portfolio.accounts.domain.ShareAccount; -import org.apache.fineract.portfolio.products.service.ProductCommandsService; -import org.apache.fineract.portfolio.shares.constants.ShareProductApiConstants; -import org.apache.fineract.portfolio.shares.data.DividendsData; -import org.apache.fineract.portfolio.shares.data.ProductDividendsData; -import org.apache.fineract.portfolio.shares.domain.ShareProduct; -import org.apache.fineract.portfolio.shares.domain.ShareProductTempRepository; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.dao.DataIntegrityViolationException; -import org.springframework.stereotype.Service; - -import com.google.gson.JsonElement; - -@Service(value = "SHAREPRODUCT_COMMANDSERVICE") -public class ShareProductCommandsServiceImpl implements ProductCommandsService { - - private final FromJsonHelper fromApiJsonHelper; - - @Autowired - public ShareProductCommandsServiceImpl(final FromJsonHelper fromApiJsonHelper) { - this.fromApiJsonHelper = fromApiJsonHelper; - } - - public ProductDividendsData previewDividends(Long productId, JsonCommand jsonCommand) { - ArrayList<ShareAccount> accounts = ShareProductTempRepository.getInstance().getAllAccounts(productId); - ShareProduct product = ShareProductTempRepository.getInstance().fineOne(productId); - Long total = product.getTotalShares(); - JsonElement element = jsonCommand.parsedJson(); - final BigDecimal totalDividendAmount = this.fromApiJsonHelper.extractBigDecimalWithLocaleNamed("dividendAmount", element); - BigDecimal perShareValue = totalDividendAmount.divide(new BigDecimal(total)); - Date date = new Date(); - ArrayList<DividendsData> dividends = new ArrayList<>(); - for (ShareAccount account : accounts) { - if(account.getStatus().equals("Approved")) { - BigDecimal val = perShareValue.multiply(new BigDecimal(account.getTotalShares())); - DividendsData data = new DividendsData(account.getClientId(), account.getClientName(), account.getSavingsAccountNo(), - account.getTotalShares(), val, date); - dividends.add(data); - } - } - - MonetaryCurrency currency = product.getCurrency() ; - CurrencyData cur = new CurrencyData(currency.getCode(), "", currency.getDigitsAfterDecimal(), currency.getCurrencyInMultiplesOf(), - "", ""); - ProductDividendsData toReturn = new ProductDividendsData(productId, product.getProductName(), date, totalDividendAmount, cur, dividends); - return toReturn; - } - - public CommandProcessingResult postDividends(Long productId, JsonCommand jsonCommand) { - try { - ProductDividendsData data = previewDividends(productId, jsonCommand); - ShareProductTempRepository.getInstance().saveDividends(data); - return new CommandProcessingResultBuilder() // - .withCommandId(jsonCommand.commandId()) // - .withEntityId(data.getId()) // - .build(); - } catch (final DataIntegrityViolationException dve) { - return CommandProcessingResult.empty(); - } - } - - @Override - public Object handleCommand(Long productId, String command, String jsonBody) { - final JsonElement parsedCommand = this.fromApiJsonHelper.parse(jsonBody); - final JsonCommand jsonCommand = JsonCommand.from(jsonBody, parsedCommand, this.fromApiJsonHelper, null, null, null, null, null, - null, null, null, null, null); - if (ShareProductApiConstants.PREIEW_DIVIDENDS_COMMAND_STRING.equals(command)) { - return previewDividends(productId, jsonCommand); - } else if (ShareProductApiConstants.POST_DIVIDENdS_COMMAND_STRING.equals(command)) { return postDividends(productId, - jsonCommand); } - // throw unknow commandexception - return CommandProcessingResult.empty(); - } - -} http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/08c553f9/fineract-provider/src/main/java/org/apache/fineract/portfolio/shares/service/ShareProductReadPlatformServiceImpl.java ---------------------------------------------------------------------- diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/shares/service/ShareProductReadPlatformServiceImpl.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/shares/service/ShareProductReadPlatformServiceImpl.java deleted file mode 100644 index 0158d06..0000000 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/shares/service/ShareProductReadPlatformServiceImpl.java +++ /dev/null @@ -1,64 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.fineract.portfolio.shares.service; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.Set; - -import org.apache.fineract.portfolio.products.data.ProductData; -import org.apache.fineract.portfolio.products.service.ProductReadPlatformService; -import org.apache.fineract.portfolio.shares.domain.ShareProduct; -import org.apache.fineract.portfolio.shares.domain.ShareProductTempRepository; -import org.springframework.stereotype.Service; - - -@Service(value = "shareReadPlatformService") -public class ShareProductReadPlatformServiceImpl implements ProductReadPlatformService{ - - ShareProductTempRepository repo = ShareProductTempRepository.getInstance() ; - - @Override - public Collection<ProductData> retrieveAllProducts() { - Collection<ShareProduct> entities = repo.findAll() ; - List<ProductData> toReturn = new ArrayList<>() ; - for(ShareProduct entity: entities) { - toReturn.add(entity.toData()) ; - } - return toReturn; - } - - @Override - public ProductData retrieveOne(Long productId) { - ShareProduct product = repo.fineOne(productId) ; - return product.toData() ; - } - - @Override - public ProductData retrieveTemplate() { - return null; - } - - @Override - public Set<String> getResponseDataParams() { - return null; - } - -} http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/08c553f9/fineract-provider/src/main/java/org/apache/fineract/portfolio/shares/service/ShareProductWritePlatformService.java ---------------------------------------------------------------------- diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/shares/service/ShareProductWritePlatformService.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/shares/service/ShareProductWritePlatformService.java deleted file mode 100644 index 23a2051..0000000 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/shares/service/ShareProductWritePlatformService.java +++ /dev/null @@ -1,30 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.fineract.portfolio.shares.service; - -import org.apache.fineract.infrastructure.core.api.JsonCommand; -import org.apache.fineract.infrastructure.core.data.CommandProcessingResult; - - -public interface ShareProductWritePlatformService { - - CommandProcessingResult createShareProduct(JsonCommand jsonCommand) ; - - CommandProcessingResult updateProduct(Long productId, JsonCommand command); -} http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/08c553f9/fineract-provider/src/main/java/org/apache/fineract/portfolio/shares/service/ShareProductWritePlatformServiceJpaRepositoryImpl.java ---------------------------------------------------------------------- diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/shares/service/ShareProductWritePlatformServiceJpaRepositoryImpl.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/shares/service/ShareProductWritePlatformServiceJpaRepositoryImpl.java deleted file mode 100644 index f245c2b..0000000 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/shares/service/ShareProductWritePlatformServiceJpaRepositoryImpl.java +++ /dev/null @@ -1,90 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.fineract.portfolio.shares.service; - -import java.util.Map; - -import org.apache.fineract.infrastructure.core.api.JsonCommand; -import org.apache.fineract.infrastructure.core.data.CommandProcessingResult; -import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder; -import org.apache.fineract.portfolio.products.exception.ProductNotFoundException; -import org.apache.fineract.portfolio.shares.domain.ShareProduct; -import org.apache.fineract.portfolio.shares.domain.ShareProductRepository; -import org.apache.fineract.portfolio.shares.domain.ShareProductTempRepository; -import org.apache.fineract.portfolio.shares.serialization.ShareProductDataSerializer; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.dao.DataIntegrityViolationException; -import org.springframework.stereotype.Service; - -@Service -public class ShareProductWritePlatformServiceJpaRepositoryImpl implements ShareProductWritePlatformService { - - private final ShareProductRepository repository; - private final ShareProductDataSerializer serializer; - - @Autowired - public ShareProductWritePlatformServiceJpaRepositoryImpl(final ShareProductRepository repository, - final ShareProductDataSerializer serializer) { - this.repository = repository; - this.serializer = serializer; - } - - @Override - public CommandProcessingResult createShareProduct(JsonCommand jsonCommand) { - try { - ShareProduct product = this.serializer.validateAndCreate(jsonCommand); - //this.repository.save(product); - ShareProductTempRepository.getInstance().save(product) ; - return new CommandProcessingResultBuilder() // - .withCommandId(jsonCommand.commandId()) // - .withEntityId(product.getId()) // - .build(); - } catch (final DataIntegrityViolationException dve) { - handleDataIntegrityIssues(jsonCommand, dve); - return CommandProcessingResult.empty(); - } - - } - - @Override - public CommandProcessingResult updateProduct(Long productId, JsonCommand jsonCommand) { - try { - //ShareProduct product = this.repository.findOne(productId); - ShareProduct product = ShareProductTempRepository.getInstance().fineOne(productId) ; - if (product == null) { throw new ProductNotFoundException(productId, "share"); } - final Map<String, Object> changes = this.serializer.validateAndUpdate(jsonCommand, product); - if(!changes.isEmpty()) { - //this.repository.saveAndFlush(product) ; - } - return new CommandProcessingResultBuilder() // - .withCommandId(jsonCommand.commandId()) // - .withEntityId(productId) // - .with(changes) // - .build(); - } catch (DataIntegrityViolationException dve) { - handleDataIntegrityIssues(jsonCommand, dve); - return CommandProcessingResult.empty(); - } - } - - private void handleDataIntegrityIssues(final JsonCommand command, final DataIntegrityViolationException dve) { - - } - -} http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/08c553f9/fineract-provider/src/main/java/org/apache/fineract/scheduledjobs/service/ScheduledJobRunnerService.java ---------------------------------------------------------------------- diff --git a/fineract-provider/src/main/java/org/apache/fineract/scheduledjobs/service/ScheduledJobRunnerService.java b/fineract-provider/src/main/java/org/apache/fineract/scheduledjobs/service/ScheduledJobRunnerService.java index 6d3a8f9..6be117e 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/scheduledjobs/service/ScheduledJobRunnerService.java +++ b/fineract-provider/src/main/java/org/apache/fineract/scheduledjobs/service/ScheduledJobRunnerService.java @@ -35,4 +35,6 @@ public interface ScheduledJobRunnerService { void updateMaturityDetailsOfDepositAccounts(); void generateRDSchedule(); + + void postDividends() throws JobExecutionException; } http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/08c553f9/fineract-provider/src/main/java/org/apache/fineract/scheduledjobs/service/ScheduledJobRunnerServiceImpl.java ---------------------------------------------------------------------- diff --git a/fineract-provider/src/main/java/org/apache/fineract/scheduledjobs/service/ScheduledJobRunnerServiceImpl.java b/fineract-provider/src/main/java/org/apache/fineract/scheduledjobs/service/ScheduledJobRunnerServiceImpl.java index ea28f53..d68efb1 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/scheduledjobs/service/ScheduledJobRunnerServiceImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/scheduledjobs/service/ScheduledJobRunnerServiceImpl.java @@ -19,6 +19,7 @@ package org.apache.fineract.scheduledjobs.service; import java.math.BigDecimal; +import java.math.BigInteger; import java.util.Collection; import java.util.Date; import java.util.List; @@ -40,6 +41,8 @@ import org.apache.fineract.portfolio.savings.service.DepositAccountReadPlatformS import org.apache.fineract.portfolio.savings.service.DepositAccountWritePlatformService; import org.apache.fineract.portfolio.savings.service.SavingsAccountChargeReadPlatformService; import org.apache.fineract.portfolio.savings.service.SavingsAccountWritePlatformService; +import org.apache.fineract.portfolio.shareaccounts.service.ShareAccountDividendReadPlatformService; +import org.apache.fineract.portfolio.shareaccounts.service.ShareAccountSchedularService; import org.joda.time.LocalDate; import org.joda.time.format.DateTimeFormat; import org.joda.time.format.DateTimeFormatter; @@ -62,18 +65,24 @@ public class ScheduledJobRunnerServiceImpl implements ScheduledJobRunnerService private final SavingsAccountChargeReadPlatformService savingsAccountChargeReadPlatformService; private final DepositAccountReadPlatformService depositAccountReadPlatformService; private final DepositAccountWritePlatformService depositAccountWritePlatformService; + private final ShareAccountDividendReadPlatformService shareAccountDividendReadPlatformService; + private final ShareAccountSchedularService shareAccountSchedularService; @Autowired public ScheduledJobRunnerServiceImpl(final RoutingDataSourceServiceFactory dataSourceServiceFactory, final SavingsAccountWritePlatformService savingsAccountWritePlatformService, final SavingsAccountChargeReadPlatformService savingsAccountChargeReadPlatformService, final DepositAccountReadPlatformService depositAccountReadPlatformService, - final DepositAccountWritePlatformService depositAccountWritePlatformService) { + final DepositAccountWritePlatformService depositAccountWritePlatformService, + final ShareAccountDividendReadPlatformService shareAccountDividendReadPlatformService, + final ShareAccountSchedularService shareAccountSchedularService) { this.dataSourceServiceFactory = dataSourceServiceFactory; this.savingsAccountWritePlatformService = savingsAccountWritePlatformService; this.savingsAccountChargeReadPlatformService = savingsAccountChargeReadPlatformService; this.depositAccountReadPlatformService = depositAccountReadPlatformService; this.depositAccountWritePlatformService = depositAccountWritePlatformService; + this.shareAccountDividendReadPlatformService = shareAccountDividendReadPlatformService; + this.shareAccountSchedularService = shareAccountSchedularService; } @Transactional @@ -364,4 +373,33 @@ public class ScheduledJobRunnerServiceImpl implements ScheduledJobRunnerService } + @Override + @CronTarget(jobName = JobName.POST_DIVIDENTS_FOR_SHARES) + public void postDividends() throws JobExecutionException { + List<Map<String, Object>> dividendDetails = this.shareAccountDividendReadPlatformService.retriveDividendDetailsForPostDividents(); + StringBuilder errorMsg = new StringBuilder(); + for (Map<String, Object> dividendMap : dividendDetails) { + final Long id = ((BigInteger) dividendMap.get("id")).longValue(); + final Long savingsId = ((BigInteger) dividendMap.get("savingsAccountId")).longValue(); + try { + this.shareAccountSchedularService.postDividend(id, savingsId); + } catch (final PlatformApiDataValidationException e) { + final List<ApiParameterError> errors = e.getErrors(); + for (final ApiParameterError error : errors) { + logger.error("Post Dividends to savings failed for Divident detail Id:" + id + " and savings Id: " + savingsId + + " with message " + error.getDeveloperMessage()); + errorMsg.append("Post Dividends to savings failed for Divident detail Id:").append(id).append(" and savings Id:") + .append(savingsId).append(" with message ").append(error.getDeveloperMessage()); + } + } catch (final Exception e) { + logger.error("Post Dividends to savings failed for Divident detail Id:" + id + " and savings Id: " + savingsId + + " with message " + e.getLocalizedMessage()); + errorMsg.append("Post Dividends to savings failed for Divident detail Id:").append(id).append(" and savings Id:") + .append(savingsId).append(" with message ").append(e.getLocalizedMessage()); + } + } + + if (errorMsg.length() > 0) { throw new JobExecutionException(errorMsg.toString()); } + } + }
