add ability to delete office transactions based on chat with dick.

This commit is contained in:
Keith Woodlock
2013-01-28 16:54:37 +00:00
parent 0bc06f9215
commit a99da667fb
9 changed files with 96 additions and 12 deletions
@@ -0,0 +1 @@
INSERT INTO `m_permission` (`grouping`, `code`, `entity_name`, `action_name`, `can_maker_checker`) VALUES ('organisation', 'DELETE_OFFICETRANSACTION', 'OFFICETRANSACTION', 'DELETE', 1);
@@ -126,6 +126,14 @@ public class CommandWrapperBuilder {
this.href = "/officetransactions/template";
return this;
}
public CommandWrapperBuilder deleteOfficeTransaction(final Long transactionId) {
this.actionName = "DELETE";
this.entityName = "OFFICETRANSACTION";
this.entityId = transactionId;
this.href = "/officetransactions/" + transactionId;
return this;
}
public CommandWrapperBuilder createStaff() {
this.actionName = "CREATE";
@@ -45,10 +45,12 @@ public class SynchronousCommandProcessingService implements CommandProcessingSer
@Transactional
@Override
public CommandProcessingResult processAndLogCommand(final CommandWrapper wrapper, final JsonCommand command, final boolean isApprovedByChecker) {
public CommandProcessingResult processAndLogCommand(final CommandWrapper wrapper, final JsonCommand command,
final boolean isApprovedByChecker) {
final boolean rollbackTransaction = this.configurationDomainService.isMakerCheckerEnabledForTask(wrapper.taskPermissionName())
&& !isApprovedByChecker;
final boolean rollbackTransaction = this.configurationDomainService.isMakerCheckerEnabledForTask(wrapper.taskPermissionName()) && !isApprovedByChecker;
final NewCommandSourceHandler handler = findCommandHandler(wrapper);
final CommandProcessingResult result = handler.processCommand(command);
@@ -95,7 +97,8 @@ public class SynchronousCommandProcessingService implements CommandProcessingSer
commandSourceRepository.save(commandSourceResult);
}
return new CommandProcessingResultBuilder().withCommandId(command.commandId()).withEntityId(commandSourceResult.resourceId()).build();
return new CommandProcessingResultBuilder().withCommandId(command.commandId()).withEntityId(commandSourceResult.resourceId())
.build();
}
private NewCommandSourceHandler findCommandHandler(final CommandWrapper wrapper) {
@@ -103,8 +106,7 @@ public class SynchronousCommandProcessingService implements CommandProcessingSer
if (wrapper.isConfigurationResource()) {
handler = applicationContext.getBean("updateGlobalConfigurationCommandHandler", NewCommandSourceHandler.class);
}
else if (wrapper.isDatatableResource()) {
} else if (wrapper.isDatatableResource()) {
if (wrapper.isCreate()) {
handler = applicationContext.getBean("createDatatableEntryCommandHandler", NewCommandSourceHandler.class);
} else if (wrapper.isUpdateMultiple()) {
@@ -209,6 +211,8 @@ public class SynchronousCommandProcessingService implements CommandProcessingSer
} else if (wrapper.isOfficeTransactionResource()) {
if (wrapper.isCreate()) {
handler = applicationContext.getBean("createOfficeTransactionCommandHandler", NewCommandSourceHandler.class);
} else if (wrapper.isDelete()) {
handler = applicationContext.getBean("deleteOfficeTransactionCommandHandler", NewCommandSourceHandler.class);
} else {
throw new UnsupportedCommandException(wrapper.commandName());
}
@@ -6,9 +6,11 @@ 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.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
@@ -95,4 +97,17 @@ public class OfficeTransactionsApiResource {
return this.toApiJsonSerializer.serialize(result);
}
@DELETE
@Path("{transactionId}")
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
public String delete(@PathParam("transactionId") final Long transactionId) {
final CommandWrapper commandRequest = new CommandWrapperBuilder().deleteOfficeTransaction(transactionId).build();
final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest);
return this.toApiJsonSerializer.serialize(result);
}
}
@@ -7,7 +7,7 @@ import org.mifosplatform.infrastructure.core.exception.AbstractPlatformResourceN
*/
public class OfficeNotFoundException extends AbstractPlatformResourceNotFoundException {
public OfficeNotFoundException(final Long id) {
super("error.msg.office.id.invalid", "Office with identifier " + id + " does not exist", id);
}
public OfficeNotFoundException(final Long id) {
super("error.msg.office.id.invalid", "Office with identifier " + id + " does not exist", id);
}
}
@@ -0,0 +1,13 @@
package org.mifosplatform.organisation.office.exception;
import org.mifosplatform.infrastructure.core.exception.AbstractPlatformResourceNotFoundException;
/**
* A {@link RuntimeException} thrown when office transaction resources are not found.
*/
public class OfficeTransactionNotFoundException extends AbstractPlatformResourceNotFoundException {
public OfficeTransactionNotFoundException(final Long id) {
super("error.msg.officetransaction.id.invalid", "Office transaction with identifier " + id + " does not exist", id);
}
}
@@ -0,0 +1,27 @@
package org.mifosplatform.organisation.office.handler;
import org.mifosplatform.commands.handler.NewCommandSourceHandler;
import org.mifosplatform.infrastructure.core.api.JsonCommand;
import org.mifosplatform.infrastructure.core.data.CommandProcessingResult;
import org.mifosplatform.organisation.office.service.OfficeWritePlatformService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@Service
public class DeleteOfficeTransactionCommandHandler implements NewCommandSourceHandler {
private final OfficeWritePlatformService writePlatformService;
@Autowired
public DeleteOfficeTransactionCommandHandler(final OfficeWritePlatformService writePlatformService) {
this.writePlatformService = writePlatformService;
}
@Transactional
@Override
public CommandProcessingResult processCommand(final JsonCommand command) {
return this.writePlatformService.deleteOfficeTransaction(command.entityId(), command);
}
}
@@ -10,4 +10,6 @@ public interface OfficeWritePlatformService {
CommandProcessingResult updateOffice(Long officeId, JsonCommand command);
CommandProcessingResult externalBranchMoneyTransfer(JsonCommand command);
CommandProcessingResult deleteOfficeTransaction(Long id, JsonCommand command);
}
@@ -38,7 +38,7 @@ public class OfficeWritePlatformServiceJpaRepositoryImpl implements OfficeWriteP
private final OfficeCommandFromApiJsonDeserializer fromApiJsonDeserializer;
private final BranchMoneyTransferCommandFromApiJsonDeserializer moneyTransferCommandFromApiJsonDeserializer;
private final OfficeRepository officeRepository;
private final OfficeTransactionRepository officeMonetaryTransferRepository;
private final OfficeTransactionRepository officeTransactionRepository;
private final ApplicationCurrencyRepository applicationCurrencyRepository;
@Autowired
@@ -51,7 +51,7 @@ public class OfficeWritePlatformServiceJpaRepositoryImpl implements OfficeWriteP
this.fromApiJsonDeserializer = fromApiJsonDeserializer;
this.moneyTransferCommandFromApiJsonDeserializer = moneyTransferCommandFromApiJsonDeserializer;
this.officeRepository = officeRepository;
this.officeMonetaryTransferRepository = officeMonetaryTransferRepository;
this.officeTransactionRepository = officeMonetaryTransferRepository;
this.applicationCurrencyRepository = applicationCurrencyRepository;
}
@@ -155,12 +155,26 @@ public class OfficeWritePlatformServiceJpaRepositoryImpl implements OfficeWriteP
final OfficeTransaction entity = OfficeTransaction.fromJson(fromOffice, toOffice, amount, command);
this.officeMonetaryTransferRepository.save(entity);
this.officeTransactionRepository.save(entity);
return new CommandProcessingResultBuilder().withCommandId(command.commandId()).withEntityId(entity.getId()).withOfficeId(officeId)
.build();
}
@Transactional
@Override
public CommandProcessingResult deleteOfficeTransaction(final Long transactionId, JsonCommand command) {
context.authenticatedUser();
this.officeTransactionRepository.delete(transactionId);
return new CommandProcessingResultBuilder() //
.withCommandId(command.commandId()) //
.withEntityId(transactionId) //
.build();
}
/*
* Guaranteed to throw an exception no matter what the data integrity issue
* is.