delete a saving product
This commit is contained in:
+12
@@ -6,6 +6,7 @@ import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.DELETE;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.POST;
|
||||
import javax.ws.rs.PUT;
|
||||
@@ -127,4 +128,15 @@ public class SavingProductsApiResource {
|
||||
|
||||
return this.apiDataConversionService.convertSavingProductDataToJson(prettyPrint, responseParameters, savingProduct);
|
||||
}
|
||||
|
||||
@DELETE
|
||||
@Path("{productId}")
|
||||
@Consumes({MediaType.APPLICATION_JSON})
|
||||
@Produces({MediaType.APPLICATION_JSON})
|
||||
public Response deleteProduct(@PathParam("productId") final Long productId) {
|
||||
|
||||
this.savingProductWritePlatformService.deleteSavingProduct(productId);
|
||||
|
||||
return Response.ok(new EntityIdentifier(productId)).build();
|
||||
}
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
package org.mifosng.platform.exceptions;
|
||||
|
||||
public class ProductNotFoundException extends AbstractPlatformResourceNotFoundException{
|
||||
|
||||
public ProductNotFoundException(Long id) {
|
||||
super("error.msg.product.id.invalid", "Product with identifier " + id + " does not exist", id);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -23,6 +23,9 @@ public class SavingProduct extends AbstractAuditableCustom<AppUser, Long> {
|
||||
@Column(name = "description")
|
||||
private String description;
|
||||
|
||||
@Column(name = "is_deleted", nullable=false)
|
||||
private boolean deleted = false;
|
||||
|
||||
@Embedded
|
||||
SavingProductRelatedDetail savingProductRelatedDetail;
|
||||
|
||||
@@ -57,6 +60,14 @@ public class SavingProduct extends AbstractAuditableCustom<AppUser, Long> {
|
||||
public BigDecimal getInterestRate(){
|
||||
return this.savingProductRelatedDetail.getInterestRate();
|
||||
}
|
||||
|
||||
public boolean isDeleted() {
|
||||
return deleted;
|
||||
}
|
||||
|
||||
public void delete() {
|
||||
this.deleted = true;
|
||||
}
|
||||
|
||||
public void update(final SavingProductCommand command) {
|
||||
|
||||
|
||||
+1
-1
@@ -95,7 +95,7 @@ public class SavingProductReadPlatformServiceImpl implements
|
||||
}
|
||||
|
||||
public String savingProductSchema(){
|
||||
return "sp.id as id,sp.name as name, sp.description as description,sp.currency_code as currencyCode, sp.currency_digits as currencyDigits,sp.interest_rate as interestRate,sp.created_date as createdon, sp.lastmodified_date as modifiedon,"
|
||||
return "sp.id as id,sp.name as name, sp.description as description,sp.currency_code as currencyCode, sp.currency_digits as currencyDigits,sp.interest_rate as interestRate,sp.created_date as createdon, sp.lastmodified_date as modifiedon, sp.is_deleted as isdeleted, "
|
||||
+ "curr.name as currencyName, curr.internationalized_name_code as currencyNameCode, curr.display_symbol as currencyDisplaySymbol"
|
||||
+ " from portfolio_product_savings sp join ref_currency curr on curr.code = sp.currency_code";
|
||||
}
|
||||
|
||||
+3
@@ -10,4 +10,7 @@ public interface SavingProductWritePlatformService {
|
||||
|
||||
@PreAuthorize(value = "hasRole('ORGANISATION_ADMINISTRATION_SUPER_USER_ROLE')")
|
||||
EntityIdentifier updateSavingProduct(SavingProductCommand command);
|
||||
|
||||
@PreAuthorize(value = "hasRole('ORGANISATION_ADMINISTRATION_SUPER_USER_ROLE')")
|
||||
EntityIdentifier deleteSavingProduct(Long productId);
|
||||
}
|
||||
|
||||
+15
@@ -3,6 +3,7 @@ package org.mifosng.platform.savingproduct.service;
|
||||
import org.mifosng.platform.api.commands.SavingProductCommand;
|
||||
import org.mifosng.platform.api.data.EntityIdentifier;
|
||||
import org.mifosng.platform.currency.domain.MonetaryCurrency;
|
||||
import org.mifosng.platform.exceptions.ProductNotFoundException;
|
||||
import org.mifosng.platform.exceptions.SavingProductNotFoundException;
|
||||
import org.mifosng.platform.saving.domain.SavingProduct;
|
||||
import org.mifosng.platform.saving.domain.SavingProductRepository;
|
||||
@@ -54,4 +55,18 @@ public class SavingProductWritePlatformServiceJpaRepositoryImpl implements Savin
|
||||
this.savingProductRepository.save(product);
|
||||
return new EntityIdentifier(Long.valueOf(product.getId()));
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@Override
|
||||
public EntityIdentifier deleteSavingProduct(Long productId) {
|
||||
SavingProduct product=this.savingProductRepository.findOne(productId);
|
||||
if (product==null || product.isDeleted()) {
|
||||
throw new ProductNotFoundException(productId);
|
||||
}
|
||||
product.delete();
|
||||
this.savingProductRepository.save(product);
|
||||
return new EntityIdentifier(Long.valueOf(product.getId()));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -5,7 +5,7 @@
|
||||
driverClassName="com.mysql.jdbc.Driver"
|
||||
url="jdbc:mysql://localhost:3306/mifosplatform-tenants"
|
||||
username="root"
|
||||
password="mysql"
|
||||
password="mifos"
|
||||
validationQuery="select 1"
|
||||
maxActive="10"
|
||||
maxIdle="4"
|
||||
|
||||
Reference in New Issue
Block a user