Merge pull request #7 from madhukar547/master

Deleting a Saving Product
This commit is contained in:
John Woodlock
2012-08-06 00:28:00 -07:00
7 changed files with 52 additions and 2 deletions
@@ -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();
}
}
@@ -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) {
@@ -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";
}
@@ -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);
}
@@ -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"