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") @Column(name = "product_id")
private Long productId; 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) { 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(), 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, 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.officeId = officeId;
this.groupId = groupId; this.groupId = groupId;
this.clientId = clientId; this.clientId = clientId;
this.loanId = loanId; this.loanId = loanId;
this.savingsId = savingsId; this.savingsId = savingsId;
this.productId = productId; this.productId = productId;
this.transactionId = transactionId;
} }
public String getResourceGetUrl() { public String getResourceGetUrl() {
@@ -218,6 +222,16 @@ public class CommandSource extends AbstractPersistable<Long> {
public Long getSavingsId() { public Long getSavingsId() {
return savingsId; 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 Long subentityId;
private final String href; private final String href;
private final String json; private final String json;
private final Long codeId;
private final String transactionId; private final String transactionId;
private final String supportedEntityType;
private final Long supportedEntityId;
private final Long productId; private final Long productId;
private Long templateId;
public static CommandWrapper wrap(final String actionName, final String entityName, final Long resourceId, final Long subresourceId) { 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); 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, 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 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, 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, 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.taskPermissionName = actionName + "_" + entityName;
this.entityId = resourceId; this.entityId = resourceId;
this.subentityId = subresourceId; this.subentityId = subresourceId;
this.codeId = null;
this.supportedEntityType = null;
this.supportedEntityId = null;
this.href = resourceGetUrl; this.href = resourceGetUrl;
this.json = null; this.json = null;
this.transactionId = 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, 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 actionName, final String entityName, final Long entityId, final Long subentityId, final String href,
final String supportedEntityType, final Long supportedEntityId, final String href, final String json, final String json, final String transactionId, final Long productId) {
final String transactionId, final Long productId, final Long templateId) {
this.commandId = null; this.commandId = null;
this.officeId = officeId; this.officeId = officeId;
this.groupId = groupId; this.groupId = groupId;
@@ -81,19 +73,15 @@ public class CommandWrapper {
this.taskPermissionName = actionName + "_" + entityName; this.taskPermissionName = actionName + "_" + entityName;
this.entityId = entityId; this.entityId = entityId;
this.subentityId = subentityId; this.subentityId = subentityId;
this.codeId = codeId;
this.supportedEntityType = supportedEntityType;
this.supportedEntityId = supportedEntityId;
this.href = href; this.href = href;
this.json = json; this.json = json;
this.transactionId = transactionId; this.transactionId = transactionId;
this.productId = productId; this.productId = productId;
this.templateId = templateId;
} }
private CommandWrapper(final Long commandId, final String actionName, final String entityName, final Long resourceId, 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 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.commandId = commandId;
this.officeId = officeId; this.officeId = officeId;
@@ -106,12 +94,9 @@ public class CommandWrapper {
this.taskPermissionName = actionName + "_" + entityName; this.taskPermissionName = actionName + "_" + entityName;
this.entityId = resourceId; this.entityId = resourceId;
this.subentityId = subresourceId; this.subentityId = subresourceId;
this.codeId = null;
this.supportedEntityType = null;
this.supportedEntityId = null;
this.href = resourceGetUrl; this.href = resourceGetUrl;
this.json = null; this.json = null;
this.transactionId = null; this.transactionId = transactionId;
this.productId = productId; this.productId = productId;
} }
@@ -159,10 +144,6 @@ public class CommandWrapper {
return this.taskPermissionName; return this.taskPermissionName;
} }
public Long getCodeId() {
return this.codeId;
}
public String getHref() { public String getHref() {
return this.href; return this.href;
} }
@@ -175,10 +156,6 @@ public class CommandWrapper {
return this.transactionId; return this.transactionId;
} }
public Long getTemplateId() {
return this.templateId;
}
public String getEntityName() { public String getEntityName() {
return this.entityName; return this.entityName;
} }
@@ -207,14 +184,6 @@ public class CommandWrapper {
return this.savingsId; return this.savingsId;
} }
public Long getSupportedEntityId() {
return this.supportedEntityId;
}
public String getSupportedEntityType() {
return this.supportedEntityType;
}
public Long getProductId() { public Long getProductId() {
return this.productId; return this.productId;
} }
@@ -6,7 +6,6 @@
package org.mifosplatform.commands.service; package org.mifosplatform.commands.service;
import org.mifosplatform.commands.domain.CommandWrapper; import org.mifosplatform.commands.domain.CommandWrapper;
import org.mifosplatform.portfolio.calendar.domain.CalendarEntityType;
public class CommandWrapperBuilder { public class CommandWrapperBuilder {
@@ -21,28 +20,43 @@ public class CommandWrapperBuilder {
private Long subentityId; private Long subentityId;
private String href; private String href;
private String json = "{}"; private String json = "{}";
private Long codeId;
private String transactionId; private String transactionId;
private String supportedEntityType;
private Long supportedEntityId;
private Long productId; private Long productId;
private Long templateId;
public CommandWrapper build() { public CommandWrapper build() {
return new CommandWrapper(this.officeId, this.groupId, this.clientId, this.loanId, this.savingsId, this.actionName, 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.entityName, this.entityId, this.subentityId, this.href, this.json, this.transactionId, this.productId);
this.json, this.transactionId, this.productId, this.templateId);
} }
public CommandWrapperBuilder withLoanId(final Long withLoanId) { public CommandWrapperBuilder withLoanId(final Long withLoanId) {
this.loanId = withLoanId; this.loanId = withLoanId;
return this; return this;
} }
public CommandWrapperBuilder withSavingsId(final Long withSavingsId) {
this.savingsId = withSavingsId;
return this;
}
public CommandWrapperBuilder withClientId(final Long withClientId) { public CommandWrapperBuilder withClientId(final Long withClientId) {
this.clientId = withClientId; this.clientId = withClientId;
return this; 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) { public CommandWrapperBuilder withJson(final String withJson) {
this.json = withJson; this.json = withJson;
@@ -729,7 +743,7 @@ public class CommandWrapperBuilder {
public CommandWrapperBuilder createCodeValue(final Long codeId) { public CommandWrapperBuilder createCodeValue(final Long codeId) {
this.actionName = "CREATE"; this.actionName = "CREATE";
this.entityName = "CODEVALUE"; this.entityName = "CODEVALUE";
this.codeId = codeId; this.entityId = codeId;
this.href = "/codes/" + codeId + "/codevalues/template"; this.href = "/codes/" + codeId + "/codevalues/template";
return this; return this;
} }
@@ -737,8 +751,8 @@ public class CommandWrapperBuilder {
public CommandWrapperBuilder updateCodeValue(final Long codeId, final Long codeValueId) { public CommandWrapperBuilder updateCodeValue(final Long codeId, final Long codeValueId) {
this.actionName = "UPDATE"; this.actionName = "UPDATE";
this.entityName = "CODEVALUE"; this.entityName = "CODEVALUE";
this.entityId = codeValueId; this.subentityId = codeValueId;
this.codeId = codeId; this.entityId = codeId;
this.href = "/codes/" + codeId + "/codevalues/" + codeValueId; this.href = "/codes/" + codeId + "/codevalues/" + codeValueId;
return this; return this;
} }
@@ -746,8 +760,8 @@ public class CommandWrapperBuilder {
public CommandWrapperBuilder deleteCodeValue(final Long codeId, final Long codeValueId) { public CommandWrapperBuilder deleteCodeValue(final Long codeId, final Long codeValueId) {
this.actionName = "DELETE"; this.actionName = "DELETE";
this.entityName = "CODEVALUE"; this.entityName = "CODEVALUE";
this.entityId = codeValueId; this.subentityId = codeValueId;
this.codeId = codeId; this.entityId = codeId;
this.href = "/codes/" + codeId + "/codevalues/" + codeValueId; this.href = "/codes/" + codeId + "/codevalues/" + codeValueId;
return this; return this;
} }
@@ -1048,11 +1062,13 @@ public class CommandWrapperBuilder {
return this; 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.actionName = "CREATE";
this.entityName = "CALENDAR"; this.entityName = "CALENDAR";
this.supportedEntityType = supportedEntityType; this.clientId = resourceDetails.getClientId();
this.supportedEntityId = supportedEntityId; this.loanId = resourceDetails.getLoanId();
this.groupId = resourceDetails.getGroupId();
this.href = "/" + supportedEntityType + "/" + supportedEntityId + "/calendars/template"; this.href = "/" + supportedEntityType + "/" + supportedEntityId + "/calendars/template";
return this; return this;
} }
@@ -1073,34 +1089,51 @@ public class CommandWrapperBuilder {
return this; 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.actionName = "CREATE";
this.entityName = entityName;// Note supports multiple resources. Note this.entityName = resourceDetails.entityName();// Note supports multiple
// Permissions are set for each resource. // resources. Note
this.supportedEntityType = resourceType; // Permissions are set
this.supportedEntityId = resourceId; // 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"; this.href = "/" + resourceType + "/" + resourceId + "/notes/template";
return this; 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.actionName = "UPDATE";
this.entityName = entityName;// Note supports multiple resources. Note this.entityName = resourceDetails.entityName();// Note supports multiple
// Permissions are set for each resource. // resources. Note
// Permissions are set
// for each resource.
this.entityId = noteId; this.entityId = noteId;
this.supportedEntityType = resourceType; this.clientId = resourceDetails.getClientId();
this.supportedEntityId = resourceId; this.loanId = resourceDetails.getLoanId();
this.savingsId = resourceDetails.getSavingsId();
this.groupId = resourceDetails.getGroupId();
this.subentityId = resourceDetails.subresourceId();
this.href = "/" + resourceType + "/" + resourceId + "/notes"; this.href = "/" + resourceType + "/" + resourceId + "/notes";
return this; 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.actionName = "DELETE";
this.entityName = entityName;// Note supports multiple resources. Note this.entityName = resourceDetails.entityName();// Note supports multiple
// Permissions are set for each resource. // resources. Note
// Permissions are set
// for each resource.
this.entityId = noteId; this.entityId = noteId;
this.supportedEntityType = resourceType; this.clientId = resourceDetails.getClientId();
this.supportedEntityId = resourceId; this.loanId = resourceDetails.getLoanId();
this.savingsId = resourceDetails.getSavingsId();
this.groupId = resourceDetails.getGroupId();
this.subentityId = resourceDetails.subresourceId();
this.href = "/" + resourceType + "/" + resourceId + "/calendars/" + noteId; this.href = "/" + resourceType + "/" + resourceId + "/calendars/" + noteId;
return this; return this;
} }
@@ -1135,8 +1168,6 @@ public class CommandWrapperBuilder {
this.entityName = "GROUP"; this.entityName = "GROUP";
this.entityId = groupId; this.entityId = groupId;
this.groupId = groupId; this.groupId = groupId;
this.supportedEntityId = groupId;
this.supportedEntityType = CalendarEntityType.GROUPS.name();
this.href = "/groups/" + groupId + "?command=saveCollectionSheet"; this.href = "/groups/" + groupId + "?command=saveCollectionSheet";
return this; return this;
} }
@@ -1275,8 +1306,7 @@ public class CommandWrapperBuilder {
this.actionName = "SAVECOLLECTIONSHEET"; this.actionName = "SAVECOLLECTIONSHEET";
this.entityName = "CENTER"; this.entityName = "CENTER";
this.entityId = centerId; this.entityId = centerId;
this.supportedEntityId = centerId; this.groupId = centerId;
this.supportedEntityType = CalendarEntityType.CENTERS.name();
this.href = "/centers/" + centerId + "?command=saveCollectionSheet"; this.href = "/centers/" + centerId + "?command=saveCollectionSheet";
return this; return this;
} }
@@ -1394,7 +1424,6 @@ public class CommandWrapperBuilder {
this.actionName = "CREATE"; this.actionName = "CREATE";
this.entityName = "TEMPLATE"; this.entityName = "TEMPLATE";
this.entityId = null; this.entityId = null;
this.templateId = null;
this.href = "/templates"; this.href = "/templates";
return this; return this;
} }
@@ -1403,7 +1432,6 @@ public class CommandWrapperBuilder {
this.actionName = "UPDATE"; this.actionName = "UPDATE";
this.entityName = "TEMPLATE"; this.entityName = "TEMPLATE";
this.entityId = templateId; this.entityId = templateId;
this.templateId = templateId;
this.href = "/templates/" + templateId; this.href = "/templates/" + templateId;
return this; return this;
} }
@@ -1412,7 +1440,6 @@ public class CommandWrapperBuilder {
this.actionName = "DELETE"; this.actionName = "DELETE";
this.entityName = "TEMPLATE"; this.entityName = "TEMPLATE";
this.entityId = templateId; this.entityId = templateId;
this.templateId = templateId;
this.href = "/templates/" + templateId; this.href = "/templates/" + templateId;
return this; return this;
} }
@@ -1476,11 +1503,13 @@ public class CommandWrapperBuilder {
return this; 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.actionName = "CREATE";
this.entityName = "MEETING"; this.entityName = "MEETING";
this.supportedEntityType = supportedEntityType; this.clientId = resourceDetails.getClientId();
this.supportedEntityId = supportedEntityId; this.loanId = resourceDetails.getLoanId();
this.groupId = resourceDetails.getGroupId();
this.href = "/" + supportedEntityType + "/" + supportedEntityId + "/meetings"; this.href = "/" + supportedEntityType + "/" + supportedEntityId + "/meetings";
return this; return this;
} }
@@ -1505,8 +1534,6 @@ public class CommandWrapperBuilder {
this.actionName = "SAVEORUPDATEATTENDANCE"; this.actionName = "SAVEORUPDATEATTENDANCE";
this.entityName = "MEETING"; this.entityName = "MEETING";
this.entityId = entityId; this.entityId = entityId;
this.supportedEntityType = supportedEntityType;
this.supportedEntityId = supportedEntityId;
this.href = "/" + supportedEntityType + "/" + supportedEntityId + "/meetings/" + entityId + "?command=saveOrUpdateAttendance"; this.href = "/" + supportedEntityType + "/" + supportedEntityId + "/meetings/" + entityId + "?command=saveOrUpdateAttendance";
return this; return this;
} }
@@ -66,8 +66,7 @@ public class PortfolioCommandSourceWritePlatformServiceImpl implements Portfolio
final JsonElement parsedCommand = this.fromApiJsonHelper.parse(json); final JsonElement parsedCommand = this.fromApiJsonHelper.parse(json);
final JsonCommand command = JsonCommand.from(json, parsedCommand, this.fromApiJsonHelper, wrapper.getEntityName(), final JsonCommand command = JsonCommand.from(json, parsedCommand, this.fromApiJsonHelper, wrapper.getEntityName(),
wrapper.getEntityId(), wrapper.getSubentityId(), wrapper.getGroupId(), wrapper.getClientId(), wrapper.getLoanId(), wrapper.getEntityId(), wrapper.getSubentityId(), wrapper.getGroupId(), wrapper.getClientId(), wrapper.getLoanId(),
wrapper.getSavingsId(), wrapper.getCodeId(), wrapper.getSupportedEntityType(), wrapper.getSupportedEntityId(), wrapper.getSavingsId(), wrapper.getTransactionId(), wrapper.getHref(), wrapper.getProductId());
wrapper.getTransactionId(), wrapper.getHref(), wrapper.getProductId());
result = this.processAndLogCommandService.processAndLogCommand(wrapper, command, isApprovedByChecker); result = this.processAndLogCommandService.processAndLogCommand(wrapper, command, isApprovedByChecker);
} catch (final RollbackTransactionAsCommandIsNotApprovedByCheckerException e) { } catch (final RollbackTransactionAsCommandIsNotApprovedByCheckerException e) {
@@ -88,13 +87,13 @@ public class PortfolioCommandSourceWritePlatformServiceImpl implements Portfolio
commandSourceInput.getEntityName(), commandSourceInput.resourceId(), commandSourceInput.subresourceId(), commandSourceInput.getEntityName(), commandSourceInput.resourceId(), commandSourceInput.subresourceId(),
commandSourceInput.getResourceGetUrl(), commandSourceInput.getProductId(), commandSourceInput.getOfficeId(), commandSourceInput.getResourceGetUrl(), commandSourceInput.getProductId(), commandSourceInput.getOfficeId(),
commandSourceInput.getGroupId(), commandSourceInput.getClientId(), commandSourceInput.getLoanId(), commandSourceInput.getGroupId(), commandSourceInput.getClientId(), commandSourceInput.getLoanId(),
commandSourceInput.getSavingsId()); commandSourceInput.getSavingsId(), commandSourceInput.getTransactionId());
final JsonElement parsedCommand = this.fromApiJsonHelper.parse(commandSourceInput.json()); final JsonElement parsedCommand = this.fromApiJsonHelper.parse(commandSourceInput.json());
final JsonCommand command = JsonCommand.fromExistingCommand(makerCheckerId, commandSourceInput.json(), parsedCommand, final JsonCommand command = JsonCommand.fromExistingCommand(makerCheckerId, commandSourceInput.json(), parsedCommand,
this.fromApiJsonHelper, commandSourceInput.getEntityName(), commandSourceInput.resourceId(), this.fromApiJsonHelper, commandSourceInput.getEntityName(), commandSourceInput.resourceId(),
commandSourceInput.subresourceId(), commandSourceInput.getGroupId(), commandSourceInput.getClientId(), commandSourceInput.subresourceId(), commandSourceInput.getGroupId(), commandSourceInput.getClientId(),
commandSourceInput.getLoanId(), commandSourceInput.getSavingsId(), commandSourceInput.getResourceGetUrl(), commandSourceInput.getLoanId(), commandSourceInput.getSavingsId(), commandSourceInput.getTransactionId(),
commandSourceInput.getProductId()); commandSourceInput.getResourceGetUrl(), commandSourceInput.getProductId());
final boolean makerCheckerApproval = true; final boolean makerCheckerApproval = true;
return this.processAndLogCommandService.processAndLogCommand(wrapper, command, makerCheckerApproval); return this.processAndLogCommandService.processAndLogCommand(wrapper, command, makerCheckerApproval);
@@ -69,7 +69,7 @@ public class SynchronousCommandProcessingService implements CommandProcessingSer
} }
commandSourceResult.updateResourceId(result.resourceId()); commandSourceResult.updateResourceId(result.resourceId());
commandSourceResult.updateForAudit(result.getOfficeId(), result.getGroupId(), result.getClientId(), result.getLoanId(), commandSourceResult.updateForAudit(result.getOfficeId(), result.getGroupId(), result.getClientId(), result.getLoanId(),
result.getSavingsId(), result.getProductId()); result.getSavingsId(), result.getProductId(), result.getTransactionId());
String changesOnlyJson = null; String changesOnlyJson = null;
if (result.hasChanges()) { if (result.hasChanges()) {
@@ -85,7 +85,21 @@ public class SynchronousCommandProcessingService implements CommandProcessingSer
this.commandSourceRepository.save(commandSourceResult); 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); result.setRollbackTransaction(null);
return result; return result;
} }
@@ -27,6 +27,6 @@ public class DeleteCodeValueCommandHandler implements NewCommandSourceHandler {
@Override @Override
public CommandProcessingResult processCommand(final JsonCommand command) { 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 @Override
public CommandProcessingResult processCommand(final JsonCommand command) { 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()); this.fromApiJsonDeserializer.validateForCreate(command.json());
final Long codeId = command.getCodeId(); final Long codeId = command.entityId();
final Code code = this.codeRepository.findOne(codeId); final Code code = this.codeRepository.findOne(codeId);
final CodeValue codeValue = CodeValue.fromJson(code, command); final CodeValue codeValue = CodeValue.fromJson(code, command);
this.codeValueRepository.save(codeValue); this.codeValueRepository.save(codeValue);
@@ -45,44 +45,35 @@ public final class JsonCommand {
private final Long loanId; private final Long loanId;
private final Long savingsId; private final Long savingsId;
private final String entityName; private final String entityName;
private final Long codeId;
private final String supportedEntityType;
private final Long supportedEntityId;
private final String transactionId; private final String transactionId;
private final String url; private final String url;
private final Long productId; private final Long productId;
public static JsonCommand from(final String jsonCommand, final JsonElement parsedCommand, final FromJsonHelper fromApiJsonHelper, 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 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 Long loanId, final Long savingsId, final String transactionId, final String url, final Long productId) {
final String transactionId, final String url, final Long productId) {
return new JsonCommand(null, jsonCommand, parsedCommand, fromApiJsonHelper, entityName, resourceId, subresourceId, groupId, 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, 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 FromJsonHelper fromApiJsonHelper, final String entityName, final Long resourceId, final Long subresourceId,
final String url, final Long productId) { final String url, final Long productId) {
return new JsonCommand(commandId, jsonCommand, parsedCommand, fromApiJsonHelper, entityName, resourceId, subresourceId, null, null, 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, 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 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, 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, public JsonCommand(final Long commandId, final String jsonCommand, final JsonElement parsedCommand,
final FromJsonHelper fromApiJsonHelper, final String entityName, final Long resourceId, final Long subresourceId, 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 Long groupId, final Long clientId, final Long loanId, final Long savingsId, final String transactionId, final String url,
final String supportedEntityType, final Long supportedEntityId, final String transactionId, final String url,
final Long productId) { final Long productId) {
this.commandId = commandId; this.commandId = commandId;
this.jsonCommand = jsonCommand; this.jsonCommand = jsonCommand;
@@ -95,9 +86,6 @@ public final class JsonCommand {
this.clientId = clientId; this.clientId = clientId;
this.loanId = loanId; this.loanId = loanId;
this.savingsId = savingsId; this.savingsId = savingsId;
this.codeId = codeId;
this.supportedEntityType = supportedEntityType;
this.supportedEntityId = supportedEntityId;
this.transactionId = transactionId; this.transactionId = transactionId;
this.url = url; this.url = url;
this.productId = productId; this.productId = productId;
@@ -152,18 +140,6 @@ public final class JsonCommand {
return this.savingsId; return this.savingsId;
} }
public Long getCodeId() {
return this.codeId;
}
public Long getSupportedEntityId() {
return this.supportedEntityId;
}
public String getSupportedEntityType() {
return this.supportedEntityType;
}
public String getTransactionId() { public String getTransactionId() {
return this.transactionId; 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.data.CalendarData;
import org.mifosplatform.portfolio.calendar.domain.Calendar; import org.mifosplatform.portfolio.calendar.domain.Calendar;
import org.mifosplatform.portfolio.calendar.domain.CalendarEntityType; 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.CalendarDropdownReadPlatformService;
import org.mifosplatform.portfolio.calendar.service.CalendarReadPlatformService; import org.mifosplatform.portfolio.calendar.service.CalendarReadPlatformService;
import org.mifosplatform.portfolio.calendar.service.CalendarUtils; import org.mifosplatform.portfolio.calendar.service.CalendarUtils;
@@ -167,8 +168,12 @@ public class CalendarsApiResource {
@Produces({ MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_JSON })
public String createCalendar(@PathParam("entityType") final String entityType, @PathParam("entityId") final Long entityId, public String createCalendar(@PathParam("entityType") final String entityType, @PathParam("entityId") final Long entityId,
final String apiRequestBodyAsJson) { 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(); .withJson(apiRequestBodyAsJson).build();
final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest); final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest);
@@ -216,4 +221,25 @@ public class CalendarsApiResource {
repeatsOnDayOptions); 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 { public enum CalendarEntityType {
CLIENTS(1, "calendarEntityType.clients"), GROUPS(2, "calendarEntityType.groups"), LOANS(3, "calendarEntityType.loans"), CENTERS(4, INVALID(0, "calendarEntityType.invalid"), CLIENTS(1, "calendarEntityType.clients"), GROUPS(2, "calendarEntityType.groups"), LOANS(3,
"calendarEntityType.centers"); "calendarEntityType.loans"), CENTERS(4, "calendarEntityType.centers");
private final Integer value; private final Integer value;
private final String code; private final String code;
@@ -114,4 +114,17 @@ public enum CalendarEntityType {
public boolean isClient() { public boolean isClient() {
return this.value.equals(CalendarEntityType.CLIENTS.getValue()); 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.ManyToOne;
import javax.persistence.Table; import javax.persistence.Table;
import org.mifosplatform.infrastructure.core.api.JsonCommand;
import org.springframework.data.jpa.domain.AbstractPersistable; import org.springframework.data.jpa.domain.AbstractPersistable;
@Entity @Entity
@@ -38,9 +37,7 @@ public class CalendarInstance extends AbstractPersistable<Long> {
} }
public static CalendarInstance fromJson(final Calendar calendar, final JsonCommand command) { public static CalendarInstance fromJson(final Calendar calendar, final Long entityId, final Integer entityTypeId) {
final Long entityId = command.getSupportedEntityId();
final Integer entityTypeId = CalendarEntityType.valueOf(command.getSupportedEntityType().toUpperCase()).getValue();
return new CalendarInstance(calendar, entityId, 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) { public CommandProcessingResult createCalendar(final JsonCommand command) {
this.fromApiJsonDeserializer.validateForCreate(command.json()); this.fromApiJsonDeserializer.validateForCreate(command.json());
final Long entityId = command.getSupportedEntityId(); Long entityId = null;
final CalendarEntityType entityType = CalendarEntityType.valueOf(command.getSupportedEntityType().toUpperCase()); CalendarEntityType entityType = CalendarEntityType.INVALID;
LocalDate entityActivationDate = null; LocalDate entityActivationDate = null;
Group centerOrGroup = null; Group centerOrGroup = null;
if (entityType.isCenter() || entityType.isGroup()) { if (command.getGroupId() != null) {
centerOrGroup = this.groupRepository.findOneWithNotFoundDetection(entityId); centerOrGroup = this.groupRepository.findOneWithNotFoundDetection(command.getGroupId());
entityActivationDate = centerOrGroup.getActivationLocalDate(); entityActivationDate = centerOrGroup.getActivationLocalDate();
} else if (entityType.isLoan()) { entityType = centerOrGroup.isCenter() ? CalendarEntityType.CENTERS : CalendarEntityType.GROUPS;
final Loan loan = this.loanRepository.findOne(entityId); entityId = command.getGroupId();
} else if (command.getLoanId() != null) {
final Loan loan = this.loanRepository.findOne(command.getLoanId());
entityActivationDate = (loan.getApprovedOnDate() == null) ? loan.getSubmittedOnDate() : loan.getApprovedOnDate(); entityActivationDate = (loan.getApprovedOnDate() == null) ? loan.getSubmittedOnDate() : loan.getApprovedOnDate();
} else if (entityType.isLoan()) { entityType = CalendarEntityType.LOANS;
final Client client = this.clientRepository.findOneWithNotFoundDetection(entityId); entityId = command.getLoanId();
} else if (command.getClientId() != null) {
final Client client = this.clientRepository.findOneWithNotFoundDetection(command.getClientId());
entityActivationDate = client.getActivationLocalDate(); entityActivationDate = client.getActivationLocalDate();
entityType = CalendarEntityType.CLIENTS;
entityId = command.getClientId();
} }
final Integer entityTypeId = entityType.getValue();
final Calendar newCalendar = Calendar.fromJson(command); final Calendar newCalendar = Calendar.fromJson(command);
final List<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>(); final List<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>();
@@ -108,17 +115,14 @@ public class CalendarWritePlatformServiceJpaRepositoryImpl implements CalendarWr
.failWithCodeNoParameterAddedToErrorCode(errorMessage); .failWithCodeNoParameterAddedToErrorCode(errorMessage);
} }
if (entityType.isCenter() || entityType.isGroup()) { if (centerOrGroup != null) {
Long centerOrGroupId = entityId; Long centerOrGroupId = centerOrGroup.getId();
Integer centerOrGroupEntityTypeId = entityType.getValue(); Integer centerOrGroupEntityTypeId = entityType.getValue();
if (entityType.isGroup()) { final Group parent = centerOrGroup.getParent();
@SuppressWarnings("null") if (parent != null) {
final Group parent = centerOrGroup.getParent(); centerOrGroupId = parent.getId();
if (parent != null) { centerOrGroupEntityTypeId = CalendarEntityType.CENTERS.getValue();
centerOrGroupId = parent.getId();
centerOrGroupEntityTypeId = CalendarEntityType.CENTERS.getValue();
}
} }
final CalendarInstance collectionCalendarInstance = this.calendarInstanceRepository final CalendarInstance collectionCalendarInstance = this.calendarInstanceRepository
@@ -134,12 +138,15 @@ public class CalendarWritePlatformServiceJpaRepositoryImpl implements CalendarWr
this.calendarRepository.save(newCalendar); this.calendarRepository.save(newCalendar);
final CalendarInstance newCalendarInstance = CalendarInstance.fromJson(newCalendar, command); final CalendarInstance newCalendarInstance = CalendarInstance.fromJson(newCalendar, entityId, entityTypeId);
this.calendarInstanceRepository.save(newCalendarInstance); this.calendarInstanceRepository.save(newCalendarInstance);
return new CommandProcessingResultBuilder() // return new CommandProcessingResultBuilder() //
.withCommandId(command.commandId()) // .withCommandId(command.commandId()) //
.withEntityId(newCalendar.getId()) // .withEntityId(newCalendar.getId()) //
.withClientId(command.getClientId()) //
.withGroupId(command.getGroupId()) //
.withLoanId(command.getLoanId()) //
.build(); .build();
} }
@@ -1739,7 +1739,7 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf
final JsonElement parsedCommand = this.fromApiJsonHelper.parse(overdueInstallment.toString()); final JsonElement parsedCommand = this.fromApiJsonHelper.parse(overdueInstallment.toString());
final JsonCommand command = JsonCommand.from(overdueInstallment.toString(), parsedCommand, this.fromApiJsonHelper, 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(), applyChargeToOverdueLoanInstallment(overdueInstallment.getLoanId(), overdueInstallment.getChargeId(),
overdueInstallment.getPeriodNumber(), command); overdueInstallment.getPeriodNumber(), command);
@@ -37,6 +37,7 @@ import org.mifosplatform.infrastructure.core.service.DateUtils;
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext; import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
import org.mifosplatform.portfolio.calendar.data.CalendarData; import org.mifosplatform.portfolio.calendar.data.CalendarData;
import org.mifosplatform.portfolio.calendar.domain.CalendarEntityType; 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.calendar.service.CalendarReadPlatformService;
import org.mifosplatform.portfolio.client.data.ClientData; import org.mifosplatform.portfolio.client.data.ClientData;
import org.mifosplatform.portfolio.client.service.ClientReadPlatformService; 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, public String createMeeting(@PathParam("entityType") final String entityType, @PathParam("entityId") final Long entityId,
final String apiRequestBodyAsJson) { 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(); .withJson(apiRequestBodyAsJson).build();
final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest); final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest);
@@ -226,4 +231,26 @@ public class MeetingsApiResource {
private boolean is(final String commandParam, final String commandValue) { private boolean is(final String commandParam, final String commandValue) {
return StringUtils.isNotBlank(commandParam) && commandParam.trim().equalsIgnoreCase(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) { private CalendarInstance getCalendarInstance(final JsonCommand command) {
final Long calendarId = command.longValueOfParameterNamed(calendarIdParamName); final Long calendarId = command.longValueOfParameterNamed(calendarIdParamName);
Long entityId = command.getSupportedEntityId();
final Calendar calendarForUpdate = this.calendarRepository.findOne(calendarId); final Calendar calendarForUpdate = this.calendarRepository.findOne(calendarId);
if (calendarForUpdate == null) { throw new CalendarNotFoundException(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 Long entityId = null;// command.getSupportedEntityId();
// for retrieving CalendarInstance. CalendarEntityType entityType = CalendarEntityType.INVALID;// CalendarEntityType.valueOf(command.getSupportedEntityType().toUpperCase());
if (CalendarEntityType.isGroup(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); final Group group = this.groupRepository.findOne(entityId);
if (group.isChildGroup()) { if (group.isCenter()) {
entityType = CalendarEntityType.CENTERS;
} else if (group.isChildGroup()) {
entityType = CalendarEntityType.CENTERS; entityType = CalendarEntityType.CENTERS;
entityId = group.getParent().getId(); entityId = group.getParent().getId();
} }
@@ -124,7 +138,7 @@ public class MeetingWritePlatformServiceJpaRepositoryImpl implements MeetingWrit
final CalendarInstance calendarInstance = this.calendarInstanceRepository.findByCalendarIdAndEntityIdAndEntityTypeId( final CalendarInstance calendarInstance = this.calendarInstanceRepository.findByCalendarIdAndEntityIdAndEntityTypeId(
calendarForUpdate.getId(), entityId, entityType.getValue()); calendarForUpdate.getId(), entityId, entityType.getValue());
if (calendarInstance == null) { 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 final String defaultUserMessage = "No Calendar Instance details found for group with identifier " + entityId
+ " and calendar with identifier " + calendarId; + " and calendar with identifier " + calendarId;
throw new CalendarInstanceNotFoundException(postFix, defaultUserMessage, entityId, calendarId); throw new CalendarInstanceNotFoundException(postFix, defaultUserMessage, entityId, calendarId);
@@ -74,7 +74,7 @@ public class NotesApiResource {
if (noteType == null) { throw new NoteResourceNotSupportedException(resourceType); } 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(); final Integer noteTypeId = noteType.getValue();
@@ -95,7 +95,7 @@ public class NotesApiResource {
if (noteType == null) { throw new NoteResourceNotSupportedException(resourceType); } 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(); final Integer noteTypeId = noteType.getValue();
@@ -115,8 +115,8 @@ public class NotesApiResource {
if (noteType == null) { throw new NoteResourceNotSupportedException(resourceType); } if (noteType == null) { throw new NoteResourceNotSupportedException(resourceType); }
final String resourceNameForPermissions = getResourceNameForPermissions(noteType); final CommandWrapper resourceDetails = getResourceDetails(noteType, resourceId);
final CommandWrapper commandRequest = new CommandWrapperBuilder().createNote(resourceNameForPermissions, resourceType, resourceId) final CommandWrapper commandRequest = new CommandWrapperBuilder().createNote(resourceDetails, resourceType, resourceId)
.withJson(apiRequestBodyAsJson).build(); .withJson(apiRequestBodyAsJson).build();
final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest); final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest);
@@ -135,10 +135,10 @@ public class NotesApiResource {
if (noteType == null) { throw new NoteResourceNotSupportedException(resourceType); } if (noteType == null) { throw new NoteResourceNotSupportedException(resourceType); }
final String resourceNameForPermissions = getResourceNameForPermissions(noteType); final CommandWrapper resourceDetails = getResourceDetails(noteType, resourceId);
final CommandWrapper commandRequest = new CommandWrapperBuilder() final CommandWrapper commandRequest = new CommandWrapperBuilder().updateNote(resourceDetails, resourceType, resourceId, noteId)
.updateNote(resourceNameForPermissions, resourceType, resourceId, noteId).withJson(apiRequestBodyAsJson).build(); .withJson(apiRequestBodyAsJson).build();
final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest); final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest);
@@ -156,38 +156,46 @@ public class NotesApiResource {
if (noteType == null) { throw new NoteResourceNotSupportedException(resourceType); } 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, final CommandWrapper commandRequest = new CommandWrapperBuilder().deleteNote(resourceDetails, resourceType, resourceId, noteId)
noteId).build(); .build();
final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest); final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest);
return this.toApiJsonSerializer.serialize(result); 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"; String resourceNameForPermissions = "INVALIDNOTE";
switch (type) { switch (type) {
case CLIENT: case CLIENT:
resourceNameForPermissions = "CLIENTNOTE"; resourceNameForPermissions = "CLIENTNOTE";
resourceDetails.withClientId(resourceId);
break; break;
case LOAN: case LOAN:
resourceNameForPermissions = "LOANNOTE"; resourceNameForPermissions = "LOANNOTE";
resourceDetails.withLoanId(resourceId);
break; break;
case LOAN_TRANSACTION: case LOAN_TRANSACTION:
resourceNameForPermissions = "LOANTRANSACTIONNOTE"; 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; break;
case SAVING_ACCOUNT: case SAVING_ACCOUNT:
resourceNameForPermissions = "SAVINGNOTE"; resourceNameForPermissions = "SAVINGNOTE";
resourceDetails.withSavingsId(resourceId);
break; break;
case GROUP: case GROUP:
resourceNameForPermissions = "GROUPNOTE"; resourceNameForPermissions = "GROUPNOTE";
resourceDetails.withGroupId(resourceId);
break; break;
} }
return resourceNameForPermissions; return resourceDetails.withEntityName(resourceNameForPermissions).build();
} }
} }
@@ -34,6 +34,10 @@ public enum NoteType {
return this.code; return this.code;
} }
public String getApiUrl() {
return this.apiUrl;
}
private static final Map<Integer, NoteType> intToEnumMap = new HashMap<Integer, NoteType>(); private static final Map<Integer, NoteType> intToEnumMap = new HashMap<Integer, NoteType>();
private static int minValue; private static int minValue;
private static int maxValue; private static int maxValue;
@@ -57,7 +57,7 @@ public class NoteWritePlatformServiceJpaRepositoryImpl implements NoteWritePlatf
private CommandProcessingResult createClientNote(final JsonCommand command) { private CommandProcessingResult createClientNote(final JsonCommand command) {
final Long resourceId = command.getSupportedEntityId(); final Long resourceId = command.getClientId();
final Client client = this.clientRepository.findOneWithNotFoundDetection(resourceId); final Client client = this.clientRepository.findOneWithNotFoundDetection(resourceId);
if (client == null) { throw new ClientNotFoundException(resourceId); } if (client == null) { throw new ClientNotFoundException(resourceId); }
@@ -85,7 +85,7 @@ public class NoteWritePlatformServiceJpaRepositoryImpl implements NoteWritePlatf
private CommandProcessingResult createGroupNote(final JsonCommand command) { private CommandProcessingResult createGroupNote(final JsonCommand command) {
final Long resourceId = command.getSupportedEntityId(); final Long resourceId = command.getGroupId();
final Group group = this.groupRepository.findOne(resourceId); final Group group = this.groupRepository.findOne(resourceId);
if (group == null) { throw new GroupNotFoundException(resourceId); } if (group == null) { throw new GroupNotFoundException(resourceId); }
@@ -103,7 +103,7 @@ public class NoteWritePlatformServiceJpaRepositoryImpl implements NoteWritePlatf
private CommandProcessingResult createLoanNote(final JsonCommand command) { private CommandProcessingResult createLoanNote(final JsonCommand command) {
final Long resourceId = command.getSupportedEntityId(); final Long resourceId = command.getLoanId();
final Loan loan = this.loanRepository.findOne(resourceId); final Loan loan = this.loanRepository.findOne(resourceId);
if (loan == null) { throw new LoanNotFoundException(resourceId); } if (loan == null) { throw new LoanNotFoundException(resourceId); }
@@ -125,7 +125,7 @@ public class NoteWritePlatformServiceJpaRepositoryImpl implements NoteWritePlatf
private CommandProcessingResult createLoanTransactionNote(final JsonCommand command) { private CommandProcessingResult createLoanTransactionNote(final JsonCommand command) {
final Long resourceId = command.getSupportedEntityId(); final Long resourceId = command.subentityId();
final LoanTransaction loanTransaction = this.loanTransactionRepository.findOne(resourceId); final LoanTransaction loanTransaction = this.loanTransactionRepository.findOne(resourceId);
if (loanTransaction == null) { throw new LoanTransactionNotFoundException(resourceId); } if (loanTransaction == null) { throw new LoanTransactionNotFoundException(resourceId); }
@@ -173,7 +173,7 @@ public class NoteWritePlatformServiceJpaRepositoryImpl implements NoteWritePlatf
this.fromApiJsonDeserializer.validateNote(command.json()); this.fromApiJsonDeserializer.validateNote(command.json());
final String resourceUrl = command.getSupportedEntityType(); final String resourceUrl = getResourceUrlFromCommand(command); //command.getSupportedEntityType();
final NoteType type = NoteType.fromApiUrl(resourceUrl); final NoteType type = NoteType.fromApiUrl(resourceUrl);
switch (type) { switch (type) {
case CLIENT: { 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) { private CommandProcessingResult updateClientNote(final JsonCommand command) {
final Long resourceId = command.getSupportedEntityId(); final Long resourceId = command.getClientId();
final Long noteId = command.entityId(); 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); final Client client = this.clientRepository.findOneWithNotFoundDetection(resourceId);
@@ -227,11 +250,10 @@ public class NoteWritePlatformServiceJpaRepositoryImpl implements NoteWritePlatf
private CommandProcessingResult updateGroupNote(final JsonCommand command) { private CommandProcessingResult updateGroupNote(final JsonCommand command) {
final Long resourceId = command.getSupportedEntityId(); final Long resourceId = command.getGroupId();
final Long noteId = command.entityId(); 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); final Group group = this.groupRepository.findOne(resourceId);
if (group == null) { throw new GroupNotFoundException(resourceId); } if (group == null) { throw new GroupNotFoundException(resourceId); }
@@ -255,11 +277,10 @@ public class NoteWritePlatformServiceJpaRepositoryImpl implements NoteWritePlatf
private CommandProcessingResult updateLoanNote(final JsonCommand command) { private CommandProcessingResult updateLoanNote(final JsonCommand command) {
final Long resourceId = command.getSupportedEntityId(); final Long resourceId = command.getLoanId();
final Long noteId = command.entityId(); 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); final Loan loan = this.loanRepository.findOne(resourceId);
if (loan == null) { throw new LoanNotFoundException(resourceId); } if (loan == null) { throw new LoanNotFoundException(resourceId); }
@@ -280,11 +301,10 @@ public class NoteWritePlatformServiceJpaRepositoryImpl implements NoteWritePlatf
private CommandProcessingResult updateLoanTransactionNote(final JsonCommand command) { private CommandProcessingResult updateLoanTransactionNote(final JsonCommand command) {
final Long resourceId = command.getSupportedEntityId(); final Long resourceId = command.subentityId();
final Long noteId = command.entityId(); 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); final LoanTransaction loanTransaction = this.loanTransactionRepository.findOne(resourceId);
if (loanTransaction == null) { throw new LoanTransactionNotFoundException(resourceId); } if (loanTransaction == null) { throw new LoanTransactionNotFoundException(resourceId); }
@@ -346,7 +366,7 @@ public class NoteWritePlatformServiceJpaRepositoryImpl implements NoteWritePlatf
this.fromApiJsonDeserializer.validateNote(command.json()); this.fromApiJsonDeserializer.validateNote(command.json());
final String resourceUrl = command.getSupportedEntityType(); final String resourceUrl = getResourceUrlFromCommand(command); //command.getSupportedEntityType();
final NoteType type = NoteType.fromApiUrl(resourceUrl); final NoteType type = NoteType.fromApiUrl(resourceUrl);
switch (type) { switch (type) {
@@ -383,25 +403,29 @@ public class NoteWritePlatformServiceJpaRepositoryImpl implements NoteWritePlatf
} }
private Note getNoteForDelete(final JsonCommand command) { private Note getNoteForDelete(final JsonCommand command) {
final String resourceUrl = command.getSupportedEntityType(); final String resourceUrl = getResourceUrlFromCommand(command);// command.getSupportedEntityType();
final Long resourceId = command.getSupportedEntityId();
final Long noteId = command.entityId(); final Long noteId = command.entityId();
final NoteType type = NoteType.fromApiUrl(resourceUrl); final NoteType type = NoteType.fromApiUrl(resourceUrl);
Long resourceId = null;
Note noteForUpdate = null; Note noteForUpdate = null;
switch (type) { switch (type) {
case CLIENT: { case CLIENT: {
resourceId = command.getClientId();
noteForUpdate = this.noteRepository.findByClientIdAndId(resourceId, noteId); noteForUpdate = this.noteRepository.findByClientIdAndId(resourceId, noteId);
} }
break; break;
case GROUP: { case GROUP: {
resourceId = command.getGroupId();
noteForUpdate = this.noteRepository.findByGroupIdAndId(resourceId, noteId); noteForUpdate = this.noteRepository.findByGroupIdAndId(resourceId, noteId);
} }
break; break;
case LOAN: { case LOAN: {
resourceId = command.getLoanId();
noteForUpdate = this.noteRepository.findByLoanIdAndId(resourceId, noteId); noteForUpdate = this.noteRepository.findByLoanIdAndId(resourceId, noteId);
} }
break; break;
case LOAN_TRANSACTION: { case LOAN_TRANSACTION: {
resourceId = command.subentityId();
noteForUpdate = this.noteRepository.findByLoanTransactionIdAndId(resourceId, noteId); noteForUpdate = this.noteRepository.findByLoanTransactionIdAndId(resourceId, noteId);
} }
break; break;