Merge pull request #833 from lingalamadhukar/MIFOSX-1027

MIFOSX-1027 Fixing issues with maker checker
This commit is contained in:
Vishwas Babu A J
2014-04-02 09:40:47 -07:00
21 changed files with 322 additions and 190 deletions
@@ -0,0 +1,2 @@
ALTER TABLE `m_portfolio_command_source`
ADD COLUMN `transaction_id` VARCHAR(100) NULL DEFAULT NULL AFTER `product_id`;
@@ -79,6 +79,9 @@ public class CommandSource extends AbstractPersistable<Long> {
@Column(name = "product_id")
private Long productId;
@Column(name = "transaction_id", length = 100)
private String transactionId;
public static CommandSource fullEntryFrom(final CommandWrapper wrapper, final JsonCommand command, final AppUser maker) {
return new CommandSource(wrapper.actionName(), wrapper.entityName(), wrapper.getHref(), command.entityId(), command.subentityId(),
@@ -167,13 +170,14 @@ public class CommandSource extends AbstractPersistable<Long> {
}
public void updateForAudit(final Long officeId, final Long groupId, final Long clientId, final Long loanId, final Long savingsId,
final Long productId) {
final Long productId, final String transactionId) {
this.officeId = officeId;
this.groupId = groupId;
this.clientId = clientId;
this.loanId = loanId;
this.savingsId = savingsId;
this.productId = productId;
this.transactionId = transactionId;
}
public String getResourceGetUrl() {
@@ -218,6 +222,16 @@ public class CommandSource extends AbstractPersistable<Long> {
public Long getSavingsId() {
return savingsId;
}
/**
* @return the transactionId
*/
public String getTransactionId() {
return this.transactionId;
}
public void updateTransaction(final String transactionId) {
this.transactionId = transactionId;
}
}
@@ -21,12 +21,8 @@ public class CommandWrapper {
private final Long subentityId;
private final String href;
private final String json;
private final Long codeId;
private final String transactionId;
private final String supportedEntityType;
private final Long supportedEntityId;
private final Long productId;
private Long templateId;
public static CommandWrapper wrap(final String actionName, final String entityName, final Long resourceId, final Long subresourceId) {
return new CommandWrapper(null, actionName, entityName, resourceId, subresourceId, null, null);
@@ -39,9 +35,9 @@ public class CommandWrapper {
public static CommandWrapper fromExistingCommand(final Long commandId, final String actionName, final String entityName,
final Long resourceId, final Long subresourceId, final String resourceGetUrl, final Long productId, final Long officeId,
final Long groupId, final Long clientId, final Long loanId, final Long savingsId) {
final Long groupId, final Long clientId, final Long loanId, final Long savingsId, final String transactionId) {
return new CommandWrapper(commandId, actionName, entityName, resourceId, subresourceId, resourceGetUrl, productId, officeId,
groupId, clientId, loanId, savingsId);
groupId, clientId, loanId, savingsId, transactionId);
}
private CommandWrapper(final Long commandId, final String actionName, final String entityName, final Long resourceId,
@@ -57,9 +53,6 @@ public class CommandWrapper {
this.taskPermissionName = actionName + "_" + entityName;
this.entityId = resourceId;
this.subentityId = subresourceId;
this.codeId = null;
this.supportedEntityType = null;
this.supportedEntityId = null;
this.href = resourceGetUrl;
this.json = null;
this.transactionId = null;
@@ -67,9 +60,8 @@ public class CommandWrapper {
}
public CommandWrapper(final Long officeId, final Long groupId, final Long clientId, final Long loanId, final Long savingsId,
final String actionName, final String entityName, final Long entityId, final Long subentityId, final Long codeId,
final String supportedEntityType, final Long supportedEntityId, final String href, final String json,
final String transactionId, final Long productId, final Long templateId) {
final String actionName, final String entityName, final Long entityId, final Long subentityId, final String href,
final String json, final String transactionId, final Long productId) {
this.commandId = null;
this.officeId = officeId;
this.groupId = groupId;
@@ -81,19 +73,15 @@ public class CommandWrapper {
this.taskPermissionName = actionName + "_" + entityName;
this.entityId = entityId;
this.subentityId = subentityId;
this.codeId = codeId;
this.supportedEntityType = supportedEntityType;
this.supportedEntityId = supportedEntityId;
this.href = href;
this.json = json;
this.transactionId = transactionId;
this.productId = productId;
this.templateId = templateId;
}
private CommandWrapper(final Long commandId, final String actionName, final String entityName, final Long resourceId,
final Long subresourceId, final String resourceGetUrl, final Long productId, final Long officeId, final Long groupId,
final Long clientId, final Long loanId, final Long savingsId) {
final Long clientId, final Long loanId, final Long savingsId, final String transactionId) {
this.commandId = commandId;
this.officeId = officeId;
@@ -106,12 +94,9 @@ public class CommandWrapper {
this.taskPermissionName = actionName + "_" + entityName;
this.entityId = resourceId;
this.subentityId = subresourceId;
this.codeId = null;
this.supportedEntityType = null;
this.supportedEntityId = null;
this.href = resourceGetUrl;
this.json = null;
this.transactionId = null;
this.transactionId = transactionId;
this.productId = productId;
}
@@ -159,10 +144,6 @@ public class CommandWrapper {
return this.taskPermissionName;
}
public Long getCodeId() {
return this.codeId;
}
public String getHref() {
return this.href;
}
@@ -175,10 +156,6 @@ public class CommandWrapper {
return this.transactionId;
}
public Long getTemplateId() {
return this.templateId;
}
public String getEntityName() {
return this.entityName;
}
@@ -207,14 +184,6 @@ public class CommandWrapper {
return this.savingsId;
}
public Long getSupportedEntityId() {
return this.supportedEntityId;
}
public String getSupportedEntityType() {
return this.supportedEntityType;
}
public Long getProductId() {
return this.productId;
}
@@ -6,7 +6,6 @@
package org.mifosplatform.commands.service;
import org.mifosplatform.commands.domain.CommandWrapper;
import org.mifosplatform.portfolio.calendar.domain.CalendarEntityType;
public class CommandWrapperBuilder {
@@ -21,28 +20,43 @@ public class CommandWrapperBuilder {
private Long subentityId;
private String href;
private String json = "{}";
private Long codeId;
private String transactionId;
private String supportedEntityType;
private Long supportedEntityId;
private Long productId;
private Long templateId;
public CommandWrapper build() {
return new CommandWrapper(this.officeId, this.groupId, this.clientId, this.loanId, this.savingsId, this.actionName,
this.entityName, this.entityId, this.subentityId, this.codeId, this.supportedEntityType, this.supportedEntityId, this.href,
this.json, this.transactionId, this.productId, this.templateId);
this.entityName, this.entityId, this.subentityId, this.href, this.json, this.transactionId, this.productId);
}
public CommandWrapperBuilder withLoanId(final Long withLoanId) {
this.loanId = withLoanId;
return this;
}
public CommandWrapperBuilder withSavingsId(final Long withSavingsId) {
this.savingsId = withSavingsId;
return this;
}
public CommandWrapperBuilder withClientId(final Long withClientId) {
this.clientId = withClientId;
return this;
}
public CommandWrapperBuilder withGroupId(final Long withGroupId) {
this.groupId = withGroupId;
return this;
}
public CommandWrapperBuilder withEntityName(final String withEntityName) {
this.entityName = withEntityName;
return this;
}
public CommandWrapperBuilder withSubEntityId(final Long withSubEntityId) {
this.subentityId = withSubEntityId;
return this;
}
public CommandWrapperBuilder withJson(final String withJson) {
this.json = withJson;
@@ -729,7 +743,7 @@ public class CommandWrapperBuilder {
public CommandWrapperBuilder createCodeValue(final Long codeId) {
this.actionName = "CREATE";
this.entityName = "CODEVALUE";
this.codeId = codeId;
this.entityId = codeId;
this.href = "/codes/" + codeId + "/codevalues/template";
return this;
}
@@ -737,8 +751,8 @@ public class CommandWrapperBuilder {
public CommandWrapperBuilder updateCodeValue(final Long codeId, final Long codeValueId) {
this.actionName = "UPDATE";
this.entityName = "CODEVALUE";
this.entityId = codeValueId;
this.codeId = codeId;
this.subentityId = codeValueId;
this.entityId = codeId;
this.href = "/codes/" + codeId + "/codevalues/" + codeValueId;
return this;
}
@@ -746,8 +760,8 @@ public class CommandWrapperBuilder {
public CommandWrapperBuilder deleteCodeValue(final Long codeId, final Long codeValueId) {
this.actionName = "DELETE";
this.entityName = "CODEVALUE";
this.entityId = codeValueId;
this.codeId = codeId;
this.subentityId = codeValueId;
this.entityId = codeId;
this.href = "/codes/" + codeId + "/codevalues/" + codeValueId;
return this;
}
@@ -1048,11 +1062,13 @@ public class CommandWrapperBuilder {
return this;
}
public CommandWrapperBuilder createCalendar(final String supportedEntityType, final Long supportedEntityId) {
public CommandWrapperBuilder createCalendar(final CommandWrapper resourceDetails, final String supportedEntityType,
final Long supportedEntityId) {
this.actionName = "CREATE";
this.entityName = "CALENDAR";
this.supportedEntityType = supportedEntityType;
this.supportedEntityId = supportedEntityId;
this.clientId = resourceDetails.getClientId();
this.loanId = resourceDetails.getLoanId();
this.groupId = resourceDetails.getGroupId();
this.href = "/" + supportedEntityType + "/" + supportedEntityId + "/calendars/template";
return this;
}
@@ -1073,34 +1089,51 @@ public class CommandWrapperBuilder {
return this;
}
public CommandWrapperBuilder createNote(final String entityName, final String resourceType, final Long resourceId) {
public CommandWrapperBuilder createNote(final CommandWrapper resourceDetails, final String resourceType, final Long resourceId) {
this.actionName = "CREATE";
this.entityName = entityName;// Note supports multiple resources. Note
// Permissions are set for each resource.
this.supportedEntityType = resourceType;
this.supportedEntityId = resourceId;
this.entityName = resourceDetails.entityName();// Note supports multiple
// resources. Note
// Permissions are set
// for each resource.
this.clientId = resourceDetails.getClientId();
this.loanId = resourceDetails.getLoanId();
this.savingsId = resourceDetails.getSavingsId();
this.groupId = resourceDetails.getGroupId();
this.subentityId = resourceDetails.subresourceId();
this.href = "/" + resourceType + "/" + resourceId + "/notes/template";
return this;
}
public CommandWrapperBuilder updateNote(final String entityName, final String resourceType, final Long resourceId, final Long noteId) {
public CommandWrapperBuilder updateNote(final CommandWrapper resourceDetails, final String resourceType, final Long resourceId,
final Long noteId) {
this.actionName = "UPDATE";
this.entityName = entityName;// Note supports multiple resources. Note
// Permissions are set for each resource.
this.entityName = resourceDetails.entityName();// Note supports multiple
// resources. Note
// Permissions are set
// for each resource.
this.entityId = noteId;
this.supportedEntityType = resourceType;
this.supportedEntityId = resourceId;
this.clientId = resourceDetails.getClientId();
this.loanId = resourceDetails.getLoanId();
this.savingsId = resourceDetails.getSavingsId();
this.groupId = resourceDetails.getGroupId();
this.subentityId = resourceDetails.subresourceId();
this.href = "/" + resourceType + "/" + resourceId + "/notes";
return this;
}
public CommandWrapperBuilder deleteNote(final String entityName, final String resourceType, final Long resourceId, final Long noteId) {
public CommandWrapperBuilder deleteNote(final CommandWrapper resourceDetails, final String resourceType, final Long resourceId,
final Long noteId) {
this.actionName = "DELETE";
this.entityName = entityName;// Note supports multiple resources. Note
// Permissions are set for each resource.
this.entityName = resourceDetails.entityName();// Note supports multiple
// resources. Note
// Permissions are set
// for each resource.
this.entityId = noteId;
this.supportedEntityType = resourceType;
this.supportedEntityId = resourceId;
this.clientId = resourceDetails.getClientId();
this.loanId = resourceDetails.getLoanId();
this.savingsId = resourceDetails.getSavingsId();
this.groupId = resourceDetails.getGroupId();
this.subentityId = resourceDetails.subresourceId();
this.href = "/" + resourceType + "/" + resourceId + "/calendars/" + noteId;
return this;
}
@@ -1135,8 +1168,6 @@ public class CommandWrapperBuilder {
this.entityName = "GROUP";
this.entityId = groupId;
this.groupId = groupId;
this.supportedEntityId = groupId;
this.supportedEntityType = CalendarEntityType.GROUPS.name();
this.href = "/groups/" + groupId + "?command=saveCollectionSheet";
return this;
}
@@ -1275,8 +1306,7 @@ public class CommandWrapperBuilder {
this.actionName = "SAVECOLLECTIONSHEET";
this.entityName = "CENTER";
this.entityId = centerId;
this.supportedEntityId = centerId;
this.supportedEntityType = CalendarEntityType.CENTERS.name();
this.groupId = centerId;
this.href = "/centers/" + centerId + "?command=saveCollectionSheet";
return this;
}
@@ -1394,7 +1424,6 @@ public class CommandWrapperBuilder {
this.actionName = "CREATE";
this.entityName = "TEMPLATE";
this.entityId = null;
this.templateId = null;
this.href = "/templates";
return this;
}
@@ -1403,7 +1432,6 @@ public class CommandWrapperBuilder {
this.actionName = "UPDATE";
this.entityName = "TEMPLATE";
this.entityId = templateId;
this.templateId = templateId;
this.href = "/templates/" + templateId;
return this;
}
@@ -1412,7 +1440,6 @@ public class CommandWrapperBuilder {
this.actionName = "DELETE";
this.entityName = "TEMPLATE";
this.entityId = templateId;
this.templateId = templateId;
this.href = "/templates/" + templateId;
return this;
}
@@ -1476,11 +1503,13 @@ public class CommandWrapperBuilder {
return this;
}
public CommandWrapperBuilder createMeeting(final String supportedEntityType, final Long supportedEntityId) {
public CommandWrapperBuilder createMeeting(final CommandWrapper resourceDetails, final String supportedEntityType,
final Long supportedEntityId) {
this.actionName = "CREATE";
this.entityName = "MEETING";
this.supportedEntityType = supportedEntityType;
this.supportedEntityId = supportedEntityId;
this.clientId = resourceDetails.getClientId();
this.loanId = resourceDetails.getLoanId();
this.groupId = resourceDetails.getGroupId();
this.href = "/" + supportedEntityType + "/" + supportedEntityId + "/meetings";
return this;
}
@@ -1505,8 +1534,6 @@ public class CommandWrapperBuilder {
this.actionName = "SAVEORUPDATEATTENDANCE";
this.entityName = "MEETING";
this.entityId = entityId;
this.supportedEntityType = supportedEntityType;
this.supportedEntityId = supportedEntityId;
this.href = "/" + supportedEntityType + "/" + supportedEntityId + "/meetings/" + entityId + "?command=saveOrUpdateAttendance";
return this;
}
@@ -66,8 +66,7 @@ public class PortfolioCommandSourceWritePlatformServiceImpl implements Portfolio
final JsonElement parsedCommand = this.fromApiJsonHelper.parse(json);
final JsonCommand command = JsonCommand.from(json, parsedCommand, this.fromApiJsonHelper, wrapper.getEntityName(),
wrapper.getEntityId(), wrapper.getSubentityId(), wrapper.getGroupId(), wrapper.getClientId(), wrapper.getLoanId(),
wrapper.getSavingsId(), wrapper.getCodeId(), wrapper.getSupportedEntityType(), wrapper.getSupportedEntityId(),
wrapper.getTransactionId(), wrapper.getHref(), wrapper.getProductId());
wrapper.getSavingsId(), wrapper.getTransactionId(), wrapper.getHref(), wrapper.getProductId());
result = this.processAndLogCommandService.processAndLogCommand(wrapper, command, isApprovedByChecker);
} catch (final RollbackTransactionAsCommandIsNotApprovedByCheckerException e) {
@@ -88,13 +87,13 @@ public class PortfolioCommandSourceWritePlatformServiceImpl implements Portfolio
commandSourceInput.getEntityName(), commandSourceInput.resourceId(), commandSourceInput.subresourceId(),
commandSourceInput.getResourceGetUrl(), commandSourceInput.getProductId(), commandSourceInput.getOfficeId(),
commandSourceInput.getGroupId(), commandSourceInput.getClientId(), commandSourceInput.getLoanId(),
commandSourceInput.getSavingsId());
commandSourceInput.getSavingsId(), commandSourceInput.getTransactionId());
final JsonElement parsedCommand = this.fromApiJsonHelper.parse(commandSourceInput.json());
final JsonCommand command = JsonCommand.fromExistingCommand(makerCheckerId, commandSourceInput.json(), parsedCommand,
this.fromApiJsonHelper, commandSourceInput.getEntityName(), commandSourceInput.resourceId(),
commandSourceInput.subresourceId(), commandSourceInput.getGroupId(), commandSourceInput.getClientId(),
commandSourceInput.getLoanId(), commandSourceInput.getSavingsId(), commandSourceInput.getResourceGetUrl(),
commandSourceInput.getProductId());
commandSourceInput.getLoanId(), commandSourceInput.getSavingsId(), commandSourceInput.getTransactionId(),
commandSourceInput.getResourceGetUrl(), commandSourceInput.getProductId());
final boolean makerCheckerApproval = true;
return this.processAndLogCommandService.processAndLogCommand(wrapper, command, makerCheckerApproval);
@@ -69,7 +69,7 @@ public class SynchronousCommandProcessingService implements CommandProcessingSer
}
commandSourceResult.updateResourceId(result.resourceId());
commandSourceResult.updateForAudit(result.getOfficeId(), result.getGroupId(), result.getClientId(), result.getLoanId(),
result.getSavingsId(), result.getProductId());
result.getSavingsId(), result.getProductId(), result.getTransactionId());
String changesOnlyJson = null;
if (result.hasChanges()) {
@@ -85,7 +85,21 @@ public class SynchronousCommandProcessingService implements CommandProcessingSer
this.commandSourceRepository.save(commandSourceResult);
}
if ((rollbackTransaction || result.isRollbackTransaction()) && !isApprovedByChecker) { throw new RollbackTransactionAsCommandIsNotApprovedByCheckerException(commandSourceResult); }
if ((rollbackTransaction || result.isRollbackTransaction()) && !isApprovedByChecker) {
/*
* JournalEntry will generate a new transactionId every time.
* Updating the transactionId with old transactionId, because as
* there are no entries are created with new transactionId, will
* throw an error when checker approves the transaction
*/
commandSourceResult.updateTransaction(command.getTransactionId());
/*
* Update CommandSource json data with JsonCommand json data, line
* 77 and 81 may update the json data
*/
commandSourceResult.updateJsonTo(command.json());
throw new RollbackTransactionAsCommandIsNotApprovedByCheckerException(commandSourceResult);
}
result.setRollbackTransaction(null);
return result;
}
@@ -27,6 +27,6 @@ public class DeleteCodeValueCommandHandler implements NewCommandSourceHandler {
@Override
public CommandProcessingResult processCommand(final JsonCommand command) {
return this.writePlatformService.deleteCodeValue(command.getCodeId(), command.entityId());
return this.writePlatformService.deleteCodeValue(command.entityId(), command.subentityId());
}
}
@@ -27,6 +27,6 @@ public class UpdateCodeValueCommandHandler implements NewCommandSourceHandler {
@Override
public CommandProcessingResult processCommand(final JsonCommand command) {
return this.writePlatformService.updateCodeValue(command.entityId(), command);
return this.writePlatformService.updateCodeValue(command.subentityId(), command);
}
}
@@ -59,7 +59,7 @@ public class CodeValueWritePlatformServiceJpaRepositoryImpl implements CodeValue
this.fromApiJsonDeserializer.validateForCreate(command.json());
final Long codeId = command.getCodeId();
final Long codeId = command.entityId();
final Code code = this.codeRepository.findOne(codeId);
final CodeValue codeValue = CodeValue.fromJson(code, command);
this.codeValueRepository.save(codeValue);
@@ -45,44 +45,35 @@ public final class JsonCommand {
private final Long loanId;
private final Long savingsId;
private final String entityName;
private final Long codeId;
private final String supportedEntityType;
private final Long supportedEntityId;
private final String transactionId;
private final String url;
private final Long productId;
public static JsonCommand from(final String jsonCommand, final JsonElement parsedCommand, final FromJsonHelper fromApiJsonHelper,
final String entityName, final Long resourceId, final Long subresourceId, final Long groupId, final Long clientId,
final Long loanId, final Long savingsId, final Long codeId, final String supportedEntityType, final Long supportedEntityId,
final String transactionId, final String url, final Long productId) {
final Long loanId, final Long savingsId, final String transactionId, final String url, final Long productId) {
return new JsonCommand(null, jsonCommand, parsedCommand, fromApiJsonHelper, entityName, resourceId, subresourceId, groupId,
clientId, loanId, savingsId, codeId, supportedEntityType, supportedEntityId, transactionId, url, productId);
clientId, loanId, savingsId, transactionId, url, productId);
}
public static JsonCommand fromExistingCommand(final Long commandId, final String jsonCommand, final JsonElement parsedCommand,
final FromJsonHelper fromApiJsonHelper, final String entityName, final Long resourceId, final Long subresourceId,
final String url, final Long productId) {
return new JsonCommand(commandId, jsonCommand, parsedCommand, fromApiJsonHelper, entityName, resourceId, subresourceId, null, null,
null, null, null, null, null, null, url, productId);
null, null, null, url, productId);
}
/***
* Vishwas TODO: If we are recreating this command from the database, all
* properties should be set. Presence of NULL properties means we can expect
* errors!
***/
public static JsonCommand fromExistingCommand(final Long commandId, final String jsonCommand, final JsonElement parsedCommand,
final FromJsonHelper fromApiJsonHelper, final String entityName, final Long resourceId, final Long subresourceId,
final Long groupId, final Long clientId, final Long loanId, final Long savingsId, final String url, final Long productId) {
final Long groupId, final Long clientId, final Long loanId, final Long savingsId, final String transactionId, final String url,
final Long productId) {
return new JsonCommand(commandId, jsonCommand, parsedCommand, fromApiJsonHelper, entityName, resourceId, subresourceId, groupId,
clientId, loanId, savingsId, null, null, null, null, url, productId);
clientId, loanId, savingsId, transactionId, url, productId);
}
public JsonCommand(final Long commandId, final String jsonCommand, final JsonElement parsedCommand,
final FromJsonHelper fromApiJsonHelper, final String entityName, final Long resourceId, final Long subresourceId,
final Long groupId, final Long clientId, final Long loanId, final Long savingsId, final Long codeId,
final String supportedEntityType, final Long supportedEntityId, final String transactionId, final String url,
final Long groupId, final Long clientId, final Long loanId, final Long savingsId, final String transactionId, final String url,
final Long productId) {
this.commandId = commandId;
this.jsonCommand = jsonCommand;
@@ -95,9 +86,6 @@ public final class JsonCommand {
this.clientId = clientId;
this.loanId = loanId;
this.savingsId = savingsId;
this.codeId = codeId;
this.supportedEntityType = supportedEntityType;
this.supportedEntityId = supportedEntityId;
this.transactionId = transactionId;
this.url = url;
this.productId = productId;
@@ -152,18 +140,6 @@ public final class JsonCommand {
return this.savingsId;
}
public Long getCodeId() {
return this.codeId;
}
public Long getSupportedEntityId() {
return this.supportedEntityId;
}
public String getSupportedEntityType() {
return this.supportedEntityType;
}
public String getTransactionId() {
return this.transactionId;
}
@@ -40,6 +40,7 @@ import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext
import org.mifosplatform.portfolio.calendar.data.CalendarData;
import org.mifosplatform.portfolio.calendar.domain.Calendar;
import org.mifosplatform.portfolio.calendar.domain.CalendarEntityType;
import org.mifosplatform.portfolio.calendar.exception.CalendarEntityTypeNotSupportedException;
import org.mifosplatform.portfolio.calendar.service.CalendarDropdownReadPlatformService;
import org.mifosplatform.portfolio.calendar.service.CalendarReadPlatformService;
import org.mifosplatform.portfolio.calendar.service.CalendarUtils;
@@ -167,8 +168,12 @@ public class CalendarsApiResource {
@Produces({ MediaType.APPLICATION_JSON })
public String createCalendar(@PathParam("entityType") final String entityType, @PathParam("entityId") final Long entityId,
final String apiRequestBodyAsJson) {
final CalendarEntityType calendarEntityType = CalendarEntityType.getEntityType(entityType);
if (calendarEntityType == null) { throw new CalendarEntityTypeNotSupportedException(entityType); }
final CommandWrapper commandRequest = new CommandWrapperBuilder().createCalendar(entityType, entityId)
final CommandWrapper resourceDetails = getResourceDetails(calendarEntityType, entityId);
final CommandWrapper commandRequest = new CommandWrapperBuilder().createCalendar(resourceDetails, entityType, entityId)
.withJson(apiRequestBodyAsJson).build();
final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest);
@@ -216,4 +221,25 @@ public class CalendarsApiResource {
repeatsOnDayOptions);
}
private CommandWrapper getResourceDetails(final CalendarEntityType type, final Long entityId) {
CommandWrapperBuilder resourceDetails = new CommandWrapperBuilder();
switch (type) {
case CENTERS:
resourceDetails.withGroupId(entityId);
break;
case CLIENTS:
resourceDetails.withClientId(entityId);
break;
case GROUPS:
resourceDetails.withGroupId(entityId);
break;
case LOANS:
resourceDetails.withLoanId(entityId);
break;
case INVALID:
break;
}
return resourceDetails.build();
}
}
@@ -10,8 +10,8 @@ import java.util.Map;
public enum CalendarEntityType {
CLIENTS(1, "calendarEntityType.clients"), GROUPS(2, "calendarEntityType.groups"), LOANS(3, "calendarEntityType.loans"), CENTERS(4,
"calendarEntityType.centers");
INVALID(0, "calendarEntityType.invalid"), CLIENTS(1, "calendarEntityType.clients"), GROUPS(2, "calendarEntityType.groups"), LOANS(3,
"calendarEntityType.loans"), CENTERS(4, "calendarEntityType.centers");
private final Integer value;
private final String code;
@@ -114,4 +114,17 @@ public enum CalendarEntityType {
public boolean isClient() {
return this.value.equals(CalendarEntityType.CLIENTS.getValue());
}
private static final Map<String, CalendarEntityType> entityNameToEnumMap = new HashMap<String, CalendarEntityType>();
static {
for (final CalendarEntityType entityType : CalendarEntityType.values()) {
entityNameToEnumMap.put(entityType.name().toLowerCase(), entityType);
}
}
public static CalendarEntityType getEntityType(String entityType) {
return entityNameToEnumMap.get(entityType.toLowerCase());
}
}
@@ -11,7 +11,6 @@ import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import org.mifosplatform.infrastructure.core.api.JsonCommand;
import org.springframework.data.jpa.domain.AbstractPersistable;
@Entity
@@ -38,9 +37,7 @@ public class CalendarInstance extends AbstractPersistable<Long> {
}
public static CalendarInstance fromJson(final Calendar calendar, final JsonCommand command) {
final Long entityId = command.getSupportedEntityId();
final Integer entityTypeId = CalendarEntityType.valueOf(command.getSupportedEntityType().toUpperCase()).getValue();
public static CalendarInstance fromJson(final Calendar calendar, final Long entityId, final Integer entityTypeId) {
return new CalendarInstance(calendar, entityId, entityTypeId);
}
@@ -0,0 +1,11 @@
package org.mifosplatform.portfolio.calendar.exception;
import org.mifosplatform.infrastructure.core.exception.AbstractPlatformResourceNotFoundException;
public class CalendarEntityTypeNotSupportedException extends AbstractPlatformResourceNotFoundException {
public CalendarEntityTypeNotSupportedException(final String resource) {
super("calendar.entitytype.not.supported", "Calendar does not support resource "+ resource);
}
}
@@ -79,21 +79,28 @@ public class CalendarWritePlatformServiceJpaRepositoryImpl implements CalendarWr
public CommandProcessingResult createCalendar(final JsonCommand command) {
this.fromApiJsonDeserializer.validateForCreate(command.json());
final Long entityId = command.getSupportedEntityId();
final CalendarEntityType entityType = CalendarEntityType.valueOf(command.getSupportedEntityType().toUpperCase());
Long entityId = null;
CalendarEntityType entityType = CalendarEntityType.INVALID;
LocalDate entityActivationDate = null;
Group centerOrGroup = null;
if (entityType.isCenter() || entityType.isGroup()) {
centerOrGroup = this.groupRepository.findOneWithNotFoundDetection(entityId);
if (command.getGroupId() != null) {
centerOrGroup = this.groupRepository.findOneWithNotFoundDetection(command.getGroupId());
entityActivationDate = centerOrGroup.getActivationLocalDate();
} else if (entityType.isLoan()) {
final Loan loan = this.loanRepository.findOne(entityId);
entityType = centerOrGroup.isCenter() ? CalendarEntityType.CENTERS : CalendarEntityType.GROUPS;
entityId = command.getGroupId();
} else if (command.getLoanId() != null) {
final Loan loan = this.loanRepository.findOne(command.getLoanId());
entityActivationDate = (loan.getApprovedOnDate() == null) ? loan.getSubmittedOnDate() : loan.getApprovedOnDate();
} else if (entityType.isLoan()) {
final Client client = this.clientRepository.findOneWithNotFoundDetection(entityId);
entityType = CalendarEntityType.LOANS;
entityId = command.getLoanId();
} else if (command.getClientId() != null) {
final Client client = this.clientRepository.findOneWithNotFoundDetection(command.getClientId());
entityActivationDate = client.getActivationLocalDate();
entityType = CalendarEntityType.CLIENTS;
entityId = command.getClientId();
}
final Integer entityTypeId = entityType.getValue();
final Calendar newCalendar = Calendar.fromJson(command);
final List<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>();
@@ -108,17 +115,14 @@ public class CalendarWritePlatformServiceJpaRepositoryImpl implements CalendarWr
.failWithCodeNoParameterAddedToErrorCode(errorMessage);
}
if (entityType.isCenter() || entityType.isGroup()) {
Long centerOrGroupId = entityId;
if (centerOrGroup != null) {
Long centerOrGroupId = centerOrGroup.getId();
Integer centerOrGroupEntityTypeId = entityType.getValue();
if (entityType.isGroup()) {
@SuppressWarnings("null")
final Group parent = centerOrGroup.getParent();
if (parent != null) {
centerOrGroupId = parent.getId();
centerOrGroupEntityTypeId = CalendarEntityType.CENTERS.getValue();
}
final Group parent = centerOrGroup.getParent();
if (parent != null) {
centerOrGroupId = parent.getId();
centerOrGroupEntityTypeId = CalendarEntityType.CENTERS.getValue();
}
final CalendarInstance collectionCalendarInstance = this.calendarInstanceRepository
@@ -134,12 +138,15 @@ public class CalendarWritePlatformServiceJpaRepositoryImpl implements CalendarWr
this.calendarRepository.save(newCalendar);
final CalendarInstance newCalendarInstance = CalendarInstance.fromJson(newCalendar, command);
final CalendarInstance newCalendarInstance = CalendarInstance.fromJson(newCalendar, entityId, entityTypeId);
this.calendarInstanceRepository.save(newCalendarInstance);
return new CommandProcessingResultBuilder() //
.withCommandId(command.commandId()) //
.withEntityId(newCalendar.getId()) //
.withClientId(command.getClientId()) //
.withGroupId(command.getGroupId()) //
.withLoanId(command.getLoanId()) //
.build();
}
@@ -1739,7 +1739,7 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf
final JsonElement parsedCommand = this.fromApiJsonHelper.parse(overdueInstallment.toString());
final JsonCommand command = JsonCommand.from(overdueInstallment.toString(), parsedCommand, this.fromApiJsonHelper,
null, null, null, null, null, overdueInstallment.getLoanId(), null, null, null, null, null, null, null);
null, null, null, null, null, overdueInstallment.getLoanId(), null, null, null, null);
applyChargeToOverdueLoanInstallment(overdueInstallment.getLoanId(), overdueInstallment.getChargeId(),
overdueInstallment.getPeriodNumber(), command);
@@ -37,6 +37,7 @@ import org.mifosplatform.infrastructure.core.service.DateUtils;
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
import org.mifosplatform.portfolio.calendar.data.CalendarData;
import org.mifosplatform.portfolio.calendar.domain.CalendarEntityType;
import org.mifosplatform.portfolio.calendar.exception.CalendarEntityTypeNotSupportedException;
import org.mifosplatform.portfolio.calendar.service.CalendarReadPlatformService;
import org.mifosplatform.portfolio.client.data.ClientData;
import org.mifosplatform.portfolio.client.service.ClientReadPlatformService;
@@ -163,7 +164,11 @@ public class MeetingsApiResource {
public String createMeeting(@PathParam("entityType") final String entityType, @PathParam("entityId") final Long entityId,
final String apiRequestBodyAsJson) {
final CommandWrapper commandRequest = new CommandWrapperBuilder().createMeeting(entityType, entityId)
final CalendarEntityType calendarEntityType = CalendarEntityType.getEntityType(entityType);
if (calendarEntityType == null) { throw new CalendarEntityTypeNotSupportedException(entityType); }
final CommandWrapper resourceDetails = getResourceDetails(calendarEntityType, entityId);
final CommandWrapper commandRequest = new CommandWrapperBuilder().createMeeting(resourceDetails, entityType, entityId)
.withJson(apiRequestBodyAsJson).build();
final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest);
@@ -226,4 +231,26 @@ public class MeetingsApiResource {
private boolean is(final String commandParam, final String commandValue) {
return StringUtils.isNotBlank(commandParam) && commandParam.trim().equalsIgnoreCase(commandValue);
}
private CommandWrapper getResourceDetails(final CalendarEntityType type, final Long entityId) {
CommandWrapperBuilder resourceDetails = new CommandWrapperBuilder();
switch (type) {
case CENTERS:
resourceDetails.withGroupId(entityId);
break;
case CLIENTS:
resourceDetails.withClientId(entityId);
break;
case GROUPS:
resourceDetails.withGroupId(entityId);
break;
case LOANS:
resourceDetails.withLoanId(entityId);
break;
case INVALID:
break;
}
return resourceDetails.build();
}
}
@@ -106,16 +106,30 @@ public class MeetingWritePlatformServiceJpaRepositoryImpl implements MeetingWrit
}
private CalendarInstance getCalendarInstance(final JsonCommand command) {
final Long calendarId = command.longValueOfParameterNamed(calendarIdParamName);
Long entityId = command.getSupportedEntityId();
final Calendar calendarForUpdate = this.calendarRepository.findOne(calendarId);
if (calendarForUpdate == null) { throw new CalendarNotFoundException(calendarId); }
CalendarEntityType entityType = CalendarEntityType.valueOf(command.getSupportedEntityType().toUpperCase());
// If group is within a center then center entityType should be passed
// for retrieving CalendarInstance.
if (CalendarEntityType.isGroup(command.getSupportedEntityType().toUpperCase())) {
Long entityId = null;// command.getSupportedEntityId();
CalendarEntityType entityType = CalendarEntityType.INVALID;// CalendarEntityType.valueOf(command.getSupportedEntityType().toUpperCase());
if (command.getLoanId() != null) {
entityId = command.getLoanId();
entityType = CalendarEntityType.LOANS;
} else if (command.getClientId() != null) {
entityId = command.getClientId();
entityType = CalendarEntityType.CLIENTS;
} else if (command.getGroupId() != null) {
entityId = command.getGroupId();
entityType = CalendarEntityType.GROUPS;
/*
* If group is within a center then center entityType should be
* passed for retrieving CalendarInstance.
*/
final Group group = this.groupRepository.findOne(entityId);
if (group.isChildGroup()) {
if (group.isCenter()) {
entityType = CalendarEntityType.CENTERS;
} else if (group.isChildGroup()) {
entityType = CalendarEntityType.CENTERS;
entityId = group.getParent().getId();
}
@@ -124,7 +138,7 @@ public class MeetingWritePlatformServiceJpaRepositoryImpl implements MeetingWrit
final CalendarInstance calendarInstance = this.calendarInstanceRepository.findByCalendarIdAndEntityIdAndEntityTypeId(
calendarForUpdate.getId(), entityId, entityType.getValue());
if (calendarInstance == null) {
final String postFix = "for." + command.getSupportedEntityType() + "not.found";
final String postFix = "for." + entityType.name().toLowerCase() + "not.found";
final String defaultUserMessage = "No Calendar Instance details found for group with identifier " + entityId
+ " and calendar with identifier " + calendarId;
throw new CalendarInstanceNotFoundException(postFix, defaultUserMessage, entityId, calendarId);
@@ -74,7 +74,7 @@ public class NotesApiResource {
if (noteType == null) { throw new NoteResourceNotSupportedException(resourceType); }
this.context.authenticatedUser().validateHasReadPermission(getResourceNameForPermissions(noteType));
this.context.authenticatedUser().validateHasReadPermission(getResourceDetails(noteType, resourceId).entityName());
final Integer noteTypeId = noteType.getValue();
@@ -95,7 +95,7 @@ public class NotesApiResource {
if (noteType == null) { throw new NoteResourceNotSupportedException(resourceType); }
this.context.authenticatedUser().validateHasReadPermission(getResourceNameForPermissions(noteType));
this.context.authenticatedUser().validateHasReadPermission(getResourceDetails(noteType, resourceId).entityName());
final Integer noteTypeId = noteType.getValue();
@@ -115,8 +115,8 @@ public class NotesApiResource {
if (noteType == null) { throw new NoteResourceNotSupportedException(resourceType); }
final String resourceNameForPermissions = getResourceNameForPermissions(noteType);
final CommandWrapper commandRequest = new CommandWrapperBuilder().createNote(resourceNameForPermissions, resourceType, resourceId)
final CommandWrapper resourceDetails = getResourceDetails(noteType, resourceId);
final CommandWrapper commandRequest = new CommandWrapperBuilder().createNote(resourceDetails, resourceType, resourceId)
.withJson(apiRequestBodyAsJson).build();
final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest);
@@ -135,10 +135,10 @@ public class NotesApiResource {
if (noteType == null) { throw new NoteResourceNotSupportedException(resourceType); }
final String resourceNameForPermissions = getResourceNameForPermissions(noteType);
final CommandWrapper resourceDetails = getResourceDetails(noteType, resourceId);
final CommandWrapper commandRequest = new CommandWrapperBuilder()
.updateNote(resourceNameForPermissions, resourceType, resourceId, noteId).withJson(apiRequestBodyAsJson).build();
final CommandWrapper commandRequest = new CommandWrapperBuilder().updateNote(resourceDetails, resourceType, resourceId, noteId)
.withJson(apiRequestBodyAsJson).build();
final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest);
@@ -156,38 +156,46 @@ public class NotesApiResource {
if (noteType == null) { throw new NoteResourceNotSupportedException(resourceType); }
final String resourceNameForPermissions = getResourceNameForPermissions(noteType);
final CommandWrapper resourceDetails = getResourceDetails(noteType, resourceId);
final CommandWrapper commandRequest = new CommandWrapperBuilder().deleteNote(resourceNameForPermissions, resourceType, resourceId,
noteId).build();
final CommandWrapper commandRequest = new CommandWrapperBuilder().deleteNote(resourceDetails, resourceType, resourceId, noteId)
.build();
final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest);
return this.toApiJsonSerializer.serialize(result);
}
private String getResourceNameForPermissions(final NoteType type) {
private CommandWrapper getResourceDetails(final NoteType type, final Long resourceId) {
CommandWrapperBuilder resourceDetails = new CommandWrapperBuilder();
String resourceNameForPermissions = "INVALIDNOTE";
switch (type) {
case CLIENT:
resourceNameForPermissions = "CLIENTNOTE";
resourceDetails.withClientId(resourceId);
break;
case LOAN:
resourceNameForPermissions = "LOANNOTE";
resourceDetails.withLoanId(resourceId);
break;
case LOAN_TRANSACTION:
resourceNameForPermissions = "LOANTRANSACTIONNOTE";
// updating loanId, to distinguish saving transaction note and loan transaction note as we are using subEntityId for both.
resourceDetails.withLoanId(resourceId);
resourceDetails.withSubEntityId(resourceId);
break;
case SAVING_ACCOUNT:
resourceNameForPermissions = "SAVINGNOTE";
resourceDetails.withSavingsId(resourceId);
break;
case GROUP:
resourceNameForPermissions = "GROUPNOTE";
resourceDetails.withGroupId(resourceId);
break;
}
return resourceNameForPermissions;
return resourceDetails.withEntityName(resourceNameForPermissions).build();
}
}
@@ -34,6 +34,10 @@ public enum NoteType {
return this.code;
}
public String getApiUrl() {
return this.apiUrl;
}
private static final Map<Integer, NoteType> intToEnumMap = new HashMap<Integer, NoteType>();
private static int minValue;
private static int maxValue;
@@ -57,7 +57,7 @@ public class NoteWritePlatformServiceJpaRepositoryImpl implements NoteWritePlatf
private CommandProcessingResult createClientNote(final JsonCommand command) {
final Long resourceId = command.getSupportedEntityId();
final Long resourceId = command.getClientId();
final Client client = this.clientRepository.findOneWithNotFoundDetection(resourceId);
if (client == null) { throw new ClientNotFoundException(resourceId); }
@@ -85,7 +85,7 @@ public class NoteWritePlatformServiceJpaRepositoryImpl implements NoteWritePlatf
private CommandProcessingResult createGroupNote(final JsonCommand command) {
final Long resourceId = command.getSupportedEntityId();
final Long resourceId = command.getGroupId();
final Group group = this.groupRepository.findOne(resourceId);
if (group == null) { throw new GroupNotFoundException(resourceId); }
@@ -103,7 +103,7 @@ public class NoteWritePlatformServiceJpaRepositoryImpl implements NoteWritePlatf
private CommandProcessingResult createLoanNote(final JsonCommand command) {
final Long resourceId = command.getSupportedEntityId();
final Long resourceId = command.getLoanId();
final Loan loan = this.loanRepository.findOne(resourceId);
if (loan == null) { throw new LoanNotFoundException(resourceId); }
@@ -125,7 +125,7 @@ public class NoteWritePlatformServiceJpaRepositoryImpl implements NoteWritePlatf
private CommandProcessingResult createLoanTransactionNote(final JsonCommand command) {
final Long resourceId = command.getSupportedEntityId();
final Long resourceId = command.subentityId();
final LoanTransaction loanTransaction = this.loanTransactionRepository.findOne(resourceId);
if (loanTransaction == null) { throw new LoanTransactionNotFoundException(resourceId); }
@@ -173,7 +173,7 @@ public class NoteWritePlatformServiceJpaRepositoryImpl implements NoteWritePlatf
this.fromApiJsonDeserializer.validateNote(command.json());
final String resourceUrl = command.getSupportedEntityType();
final String resourceUrl = getResourceUrlFromCommand(command); //command.getSupportedEntityType();
final NoteType type = NoteType.fromApiUrl(resourceUrl);
switch (type) {
case CLIENT: {
@@ -197,13 +197,36 @@ public class NoteWritePlatformServiceJpaRepositoryImpl implements NoteWritePlatf
}
private String getResourceUrlFromCommand(JsonCommand command) {
final String resourceUrl;
if (command.getClientId() != null) {
resourceUrl = NoteType.CLIENT.getApiUrl();
} else if (command.getGroupId() != null) {
resourceUrl = NoteType.GROUP.getApiUrl();
} else if (command.getLoanId() != null) {
if (command.subentityId() != null) {
resourceUrl = NoteType.LOAN_TRANSACTION.getApiUrl();
} else {
resourceUrl = NoteType.LOAN.getApiUrl();
}
} else if (command.getSavingsId() != null) {
//TODO: SAVING_TRANSACTION type need to be add.
resourceUrl = NoteType.SAVING_ACCOUNT.getApiUrl();
} else {
resourceUrl = "";
}
return resourceUrl;
}
private CommandProcessingResult updateClientNote(final JsonCommand command) {
final Long resourceId = command.getSupportedEntityId();
final Long resourceId = command.getClientId();
final Long noteId = command.entityId();
final String resourceUrl = command.getSupportedEntityType();
final NoteType type = NoteType.fromApiUrl(resourceUrl);
final NoteType type = NoteType.CLIENT;
final Client client = this.clientRepository.findOneWithNotFoundDetection(resourceId);
@@ -227,11 +250,10 @@ public class NoteWritePlatformServiceJpaRepositoryImpl implements NoteWritePlatf
private CommandProcessingResult updateGroupNote(final JsonCommand command) {
final Long resourceId = command.getSupportedEntityId();
final Long resourceId = command.getGroupId();
final Long noteId = command.entityId();
final String resourceUrl = command.getSupportedEntityType();
final NoteType type = NoteType.fromApiUrl(resourceUrl);
final NoteType type = NoteType.GROUP;
final Group group = this.groupRepository.findOne(resourceId);
if (group == null) { throw new GroupNotFoundException(resourceId); }
@@ -255,11 +277,10 @@ public class NoteWritePlatformServiceJpaRepositoryImpl implements NoteWritePlatf
private CommandProcessingResult updateLoanNote(final JsonCommand command) {
final Long resourceId = command.getSupportedEntityId();
final Long resourceId = command.getLoanId();
final Long noteId = command.entityId();
final String resourceUrl = command.getSupportedEntityType();
final NoteType type = NoteType.fromApiUrl(resourceUrl);
final NoteType type = NoteType.LOAN;
final Loan loan = this.loanRepository.findOne(resourceId);
if (loan == null) { throw new LoanNotFoundException(resourceId); }
@@ -280,11 +301,10 @@ public class NoteWritePlatformServiceJpaRepositoryImpl implements NoteWritePlatf
private CommandProcessingResult updateLoanTransactionNote(final JsonCommand command) {
final Long resourceId = command.getSupportedEntityId();
final Long resourceId = command.subentityId();
final Long noteId = command.entityId();
final String resourceUrl = command.getSupportedEntityType();
final NoteType type = NoteType.fromApiUrl(resourceUrl);
final NoteType type = NoteType.LOAN_TRANSACTION;
final LoanTransaction loanTransaction = this.loanTransactionRepository.findOne(resourceId);
if (loanTransaction == null) { throw new LoanTransactionNotFoundException(resourceId); }
@@ -346,7 +366,7 @@ public class NoteWritePlatformServiceJpaRepositoryImpl implements NoteWritePlatf
this.fromApiJsonDeserializer.validateNote(command.json());
final String resourceUrl = command.getSupportedEntityType();
final String resourceUrl = getResourceUrlFromCommand(command); //command.getSupportedEntityType();
final NoteType type = NoteType.fromApiUrl(resourceUrl);
switch (type) {
@@ -383,25 +403,29 @@ public class NoteWritePlatformServiceJpaRepositoryImpl implements NoteWritePlatf
}
private Note getNoteForDelete(final JsonCommand command) {
final String resourceUrl = command.getSupportedEntityType();
final Long resourceId = command.getSupportedEntityId();
final String resourceUrl = getResourceUrlFromCommand(command);// command.getSupportedEntityType();
final Long noteId = command.entityId();
final NoteType type = NoteType.fromApiUrl(resourceUrl);
Long resourceId = null;
Note noteForUpdate = null;
switch (type) {
case CLIENT: {
resourceId = command.getClientId();
noteForUpdate = this.noteRepository.findByClientIdAndId(resourceId, noteId);
}
break;
case GROUP: {
resourceId = command.getGroupId();
noteForUpdate = this.noteRepository.findByGroupIdAndId(resourceId, noteId);
}
break;
case LOAN: {
resourceId = command.getLoanId();
noteForUpdate = this.noteRepository.findByLoanIdAndId(resourceId, noteId);
}
break;
case LOAN_TRANSACTION: {
resourceId = command.subentityId();
noteForUpdate = this.noteRepository.findByLoanTransactionIdAndId(resourceId, noteId);
}
break;