MIFOSX-97: refactor into command handling logic, prepare for sql based approach for change detection.
This commit is contained in:
+4
-4
@@ -2,9 +2,9 @@ package org.mifosng.platform.api.infrastructure;
|
||||
|
||||
public class ApiConstants {
|
||||
|
||||
// TODO:Vishwas Need to move these settings to the Database
|
||||
public static final Integer MAX_FILE_UPLOAD_SIZE_IN_MB = 5;
|
||||
// TODO:Vishwas Need to move these settings to the Database
|
||||
public static final Integer MAX_FILE_UPLOAD_SIZE_IN_MB = 5;
|
||||
|
||||
// TODO:Vishwas Need to move these settings to the Database
|
||||
public static final Integer MAX_IMAGE_UPLOAD_SIZE_IN_MB = 1;
|
||||
// TODO:Vishwas Need to move these settings to the Database
|
||||
public static final Integer MAX_IMAGE_UPLOAD_SIZE_IN_MB = 1;
|
||||
}
|
||||
|
||||
+486
-695
File diff suppressed because it is too large
Load Diff
+42
-43
@@ -31,69 +31,68 @@ import org.mifosng.platform.api.commands.UserCommand;
|
||||
import org.mifosng.platform.api.data.ClientData;
|
||||
|
||||
public interface PortfolioApiDataConversionService {
|
||||
|
||||
|
||||
ChargeCommand convertJsonToChargeCommand(Long resourceIdentifier, String json);
|
||||
|
||||
FundCommand convertJsonToFundCommand(Long resourceIdentifier, String json);
|
||||
|
||||
OfficeCommand convertJsonToOfficeCommand(Long resourceIdentifier, String json);
|
||||
|
||||
RoleCommand convertJsonToRoleCommand(Long resourceIdentifier, String json);
|
||||
FundCommand convertJsonToFundCommand(Long resourceIdentifier, String json);
|
||||
|
||||
UserCommand convertJsonToUserCommand(Long resourceIdentifier, String json);
|
||||
OfficeCommand convertJsonToOfficeCommand(Long resourceIdentifier, String json);
|
||||
|
||||
BranchMoneyTransferCommand convertJsonToBranchMoneyTransferCommand(String json);
|
||||
|
||||
LoanProductCommand convertJsonToLoanProductCommand(Long resourceIdentifier, String json);
|
||||
|
||||
SavingProductCommand convertJsonToSavingProductCommand(Long resourceIdentifier, String json);
|
||||
|
||||
DepositProductCommand convertJsonToDepositProductCommand(Long resourceIdentifier, String json);
|
||||
RoleCommand convertJsonToRoleCommand(Long resourceIdentifier, String json);
|
||||
|
||||
ClientCommand convertApiRequestJsonToClientCommand(Long resourceIdentifier, String json);
|
||||
|
||||
ClientCommand convertInternalJsonFormatToClientCommand(Long resourceIdentifier, String json, boolean checkerApproved);
|
||||
|
||||
ClientData convertInternalJsonFormatToClientDataChange(Long clientId, String json);
|
||||
|
||||
ClientCommand detectChanges(Long resourceId, String baseJson, String workingJson);
|
||||
UserCommand convertJsonToUserCommand(Long resourceIdentifier, String json);
|
||||
|
||||
GroupCommand convertJsonToGroupCommand(Long resourceIdentifier, String json);
|
||||
|
||||
LoanApplicationCommand convertJsonToLoanApplicationCommand(Long resourceIdentifier, String json);
|
||||
BranchMoneyTransferCommand convertJsonToBranchMoneyTransferCommand(String json);
|
||||
|
||||
LoanProductCommand convertJsonToLoanProductCommand(Long resourceIdentifier, String json);
|
||||
|
||||
SavingProductCommand convertJsonToSavingProductCommand(Long resourceIdentifier, String json);
|
||||
|
||||
DepositProductCommand convertJsonToDepositProductCommand(Long resourceIdentifier, String json);
|
||||
|
||||
ClientCommand convertApiRequestJsonToClientCommand(Long resourceIdentifier, String json);
|
||||
|
||||
ClientCommand convertInternalJsonFormatToClientCommand(Long resourceIdentifier, String json, boolean checkerApproved);
|
||||
|
||||
ClientData convertInternalJsonFormatToClientDataChange(Long clientId, String json);
|
||||
|
||||
ClientCommand detectChanges(Long resourceId, String baseJson, String workingJson);
|
||||
|
||||
GroupCommand convertJsonToGroupCommand(Long resourceIdentifier, String json);
|
||||
|
||||
LoanApplicationCommand convertJsonToLoanApplicationCommand(Long resourceIdentifier, String json);
|
||||
|
||||
LoanChargeCommand convertJsonToLoanChargeCommand(Long loanChargeId, Long loanId, String json);
|
||||
|
||||
LoanStateTransitionCommand convertJsonToLoanStateTransitionCommand(Long resourceIdentifier, String json);
|
||||
LoanStateTransitionCommand convertJsonToLoanStateTransitionCommand(Long resourceIdentifier, String json);
|
||||
|
||||
LoanTransactionCommand convertJsonToLoanTransactionCommand(Long resourceIdentifier, String json);
|
||||
LoanTransactionCommand convertJsonToLoanTransactionCommand(Long resourceIdentifier, String json);
|
||||
|
||||
AdjustLoanTransactionCommand convertJsonToAdjustLoanTransactionCommand(
|
||||
Long loanId, Long transactionId, String json);
|
||||
AdjustLoanTransactionCommand convertJsonToAdjustLoanTransactionCommand(Long loanId, Long transactionId, String json);
|
||||
|
||||
OrganisationCurrencyCommand convertJsonToOrganisationCurrencyCommand(String json);
|
||||
OrganisationCurrencyCommand convertJsonToOrganisationCurrencyCommand(String json);
|
||||
|
||||
NoteCommand convertJsonToNoteCommand(Long resourceIdentifier, Long clientId, String json);
|
||||
NoteCommand convertJsonToNoteCommand(Long resourceIdentifier, Long clientId, String json);
|
||||
|
||||
DepositAccountCommand convertJsonToDepositAccountCommand(Long resourceIdentifier, String json);
|
||||
|
||||
DepositStateTransitionCommand convertJsonToDepositStateTransitionCommand(Long resourceIdentifier, String json);
|
||||
|
||||
DepositStateTransitionApprovalCommand convertJsonToDepositStateTransitionApprovalCommand(Long resourceIdentifier, String json);
|
||||
DepositAccountCommand convertJsonToDepositAccountCommand(Long resourceIdentifier, String json);
|
||||
|
||||
StaffCommand convertJsonToStaffCommand(Long resourceIdentifier, String json);
|
||||
DepositStateTransitionCommand convertJsonToDepositStateTransitionCommand(Long resourceIdentifier, String json);
|
||||
|
||||
DepositStateTransitionApprovalCommand convertJsonToDepositStateTransitionApprovalCommand(Long resourceIdentifier, String json);
|
||||
|
||||
StaffCommand convertJsonToStaffCommand(Long resourceIdentifier, String json);
|
||||
|
||||
LoanReassignmentCommand convertJsonToLoanReassignmentCommand(Long resourceIdentifier, String json);
|
||||
|
||||
LoanReassignmentCommand convertJsonToBulkLoanReassignmentCommand(String json);
|
||||
|
||||
DepositAccountWithdrawalCommand convertJsonToDepositWithdrawalCommand(Long resourceIdentifier, String json);
|
||||
|
||||
DepositAccountWithdrawInterestCommand convertJsonToDepositAccountWithdrawInterestCommand(Long resourceIdentifier, String json);
|
||||
|
||||
ClientIdentifierCommand convertJsonToClientIdentifierCommand(Long resourceIdentifier, Long clientId, String json);
|
||||
DepositAccountWithdrawalCommand convertJsonToDepositWithdrawalCommand(Long resourceIdentifier, String json);
|
||||
|
||||
CodeCommand convertJsonToCodeCommand(Long resourceIdentifier, String json);
|
||||
DepositAccountWithdrawInterestCommand convertJsonToDepositAccountWithdrawInterestCommand(Long resourceIdentifier, String json);
|
||||
|
||||
SavingAccountCommand convertJsonToSavingAccountCommand(Long resourceIdentifier,String json);
|
||||
ClientIdentifierCommand convertJsonToClientIdentifierCommand(Long resourceIdentifier, Long clientId, String json);
|
||||
|
||||
CodeCommand convertJsonToCodeCommand(Long resourceIdentifier, String json);
|
||||
|
||||
SavingAccountCommand convertJsonToSavingAccountCommand(Long resourceIdentifier, String json);
|
||||
}
|
||||
+1404
-1554
File diff suppressed because it is too large
Load Diff
+77
-70
@@ -42,114 +42,121 @@ import org.mifosng.platform.api.data.StaffData;
|
||||
|
||||
public interface PortfolioApiJsonSerializerService {
|
||||
|
||||
String serializeAuthenticatedUserDataToJson(boolean prettyPrint, AuthenticatedUserData authenticatedUserData);
|
||||
|
||||
String serializeGenericResultsetDataToJson(boolean prettyPrint, GenericResultsetData result);
|
||||
String serializeAuthenticatedUserDataToJson(boolean prettyPrint, AuthenticatedUserData authenticatedUserData);
|
||||
|
||||
String serializeAdditionalFieldsSetDataToJson(boolean prettyPrint, Collection<AdditionalFieldsSetData> result);
|
||||
|
||||
String serializeDatatableDataToJson(boolean prettyPrint, Collection<DatatableData> result);
|
||||
|
||||
String serializePermissionDataToJson(boolean prettyPrint, Set<String> responseParameters, Collection<PermissionData> permissions);
|
||||
String serializeGenericResultsetDataToJson(boolean prettyPrint, GenericResultsetData result);
|
||||
|
||||
String serializeRoleDataToJson(boolean prettyPrint, Set<String> responseParameters, Collection<RoleData> roles);
|
||||
String serializeAdditionalFieldsSetDataToJson(boolean prettyPrint, Collection<AdditionalFieldsSetData> result);
|
||||
|
||||
String serializeRoleDataToJson(boolean prettyPrint, Set<String> responseParameters, RoleData role);
|
||||
|
||||
String serializeRolePermissionDataToJson(boolean prettyPrint, Set<String> responseParameters, RolePermissionData rolePermissionData);
|
||||
String serializeDatatableDataToJson(boolean prettyPrint, Collection<DatatableData> result);
|
||||
|
||||
String serializeAppUserDataToJson(boolean prettyPrint, Set<String> responseParameters, Collection<AppUserData> users);
|
||||
String serializePermissionDataToJson(boolean prettyPrint, Set<String> responseParameters, Collection<PermissionData> permissions);
|
||||
|
||||
String serializeAppUserDataToJson(boolean prettyPrint, Set<String> responseParameters, AppUserData user);
|
||||
String serializeRoleDataToJson(boolean prettyPrint, Set<String> responseParameters, Collection<RoleData> roles);
|
||||
|
||||
String serializeOfficeDataToJson(boolean prettyPrint, Set<String> responseParameters, Collection<OfficeData> offices);
|
||||
String serializeRoleDataToJson(boolean prettyPrint, Set<String> responseParameters, RoleData role);
|
||||
|
||||
String serializeOfficeDataToJson(boolean prettyPrint, Set<String> responseParameters, OfficeData office);
|
||||
String serializeRolePermissionDataToJson(boolean prettyPrint, Set<String> responseParameters, RolePermissionData rolePermissionData);
|
||||
|
||||
String serializeOfficeTransactionDataToJson(boolean prettyPrint, Set<String> responseParameters, Collection<OfficeTransactionData> officeTransactions);
|
||||
|
||||
String serializeOfficeTransactionDataToJson(boolean prettyPrint, Set<String> responseParameters, OfficeTransactionData officeTransaction);
|
||||
String serializeAppUserDataToJson(boolean prettyPrint, Set<String> responseParameters, Collection<AppUserData> users);
|
||||
|
||||
String serializeConfigurationDataToJson(boolean prettyPrint, Set<String> responseParameters, ConfigurationData configuration);
|
||||
String serializeAppUserDataToJson(boolean prettyPrint, Set<String> responseParameters, AppUserData user);
|
||||
|
||||
String serializeFundDataToJson(boolean prettyPrint, Set<String> responseParameters, Collection<FundData> funds);
|
||||
String serializeOfficeDataToJson(boolean prettyPrint, Set<String> responseParameters, Collection<OfficeData> offices);
|
||||
|
||||
String serializeFundDataToJson(boolean prettyPrint, Set<String> responseParameters, FundData fund);
|
||||
String serializeOfficeDataToJson(boolean prettyPrint, Set<String> responseParameters, OfficeData office);
|
||||
|
||||
String serializeLoanProductDataToJson(boolean prettyPrint, Set<String> responseParameters, Collection<LoanProductData> products);
|
||||
|
||||
String serializeLoanProductDataToJson(boolean prettyPrint, Set<String> responseParameters, LoanProductData loanProduct);
|
||||
String serializeOfficeTransactionDataToJson(boolean prettyPrint, Set<String> responseParameters,
|
||||
Collection<OfficeTransactionData> officeTransactions);
|
||||
|
||||
String serializeSavingProductDataToJson(boolean prettyPrint, Set<String> responseParameters, Collection<SavingProductData> products);
|
||||
String serializeOfficeTransactionDataToJson(boolean prettyPrint, Set<String> responseParameters, OfficeTransactionData officeTransaction);
|
||||
|
||||
String serializeSavingProductDataToJson(boolean prettyPrint, Set<String> responseParameters, SavingProductData savingProduct);
|
||||
String serializeConfigurationDataToJson(boolean prettyPrint, Set<String> responseParameters, ConfigurationData configuration);
|
||||
|
||||
String serializeDepositProductDataToJson(boolean prettyPrint, Set<String> responseParameters, Collection<DepositProductData> products);
|
||||
String serializeFundDataToJson(boolean prettyPrint, Set<String> responseParameters, Collection<FundData> funds);
|
||||
|
||||
String serializeDepositProductDataToJson(boolean prettyPrint, Set<String> responseParameters, DepositProductData depositProduct);
|
||||
String serializeFundDataToJson(boolean prettyPrint, Set<String> responseParameters, FundData fund);
|
||||
|
||||
String serializeDepositAccountDataToJson(boolean prettyPrint, Set<String> responseParameters, Collection<DepositAccountData> accounts);
|
||||
String serializeLoanProductDataToJson(boolean prettyPrint, Set<String> responseParameters, Collection<LoanProductData> products);
|
||||
|
||||
String serializeDepositAccountDataToJson(boolean prettyPrint, Set<String> responseParameters, DepositAccountData account);
|
||||
String serializeLoanProductDataToJson(boolean prettyPrint, Set<String> responseParameters, LoanProductData loanProduct);
|
||||
|
||||
String serializeClientCommandToJson(ClientCommand command);
|
||||
|
||||
String serializeClientDataToJson(ClientData clientData);
|
||||
|
||||
String serializeClientDataToJson(boolean prettyPrint, Set<String> responseParameters, ClientData clientData);
|
||||
|
||||
String serializeClientDataToJson(boolean prettyPrint, Set<String> responseParameters, Collection<ClientData> clients);
|
||||
|
||||
String serializeClientAccountSummaryCollectionDataToJson(boolean prettyPrint, Set<String> responseParameters, ClientAccountSummaryCollectionData clientAccount);
|
||||
String serializeSavingProductDataToJson(boolean prettyPrint, Set<String> responseParameters, Collection<SavingProductData> products);
|
||||
|
||||
String serializeGroupAccountSummaryCollectionDataToJson(boolean prettyPrint, Set<String> responseParameters, GroupAccountSummaryCollectionData groupAccount);
|
||||
String serializeSavingProductDataToJson(boolean prettyPrint, Set<String> responseParameters, SavingProductData savingProduct);
|
||||
|
||||
String serializeGroupDataToJson(boolean prettyPrint, Set<String> responseParameters, Collection<GroupData> groups);
|
||||
String serializeDepositProductDataToJson(boolean prettyPrint, Set<String> responseParameters, Collection<DepositProductData> products);
|
||||
|
||||
String serializeGroupDataToJson(boolean prettyPrint, Set<String> responseParameters, GroupData group);
|
||||
String serializeDepositProductDataToJson(boolean prettyPrint, Set<String> responseParameters, DepositProductData depositProduct);
|
||||
|
||||
String serializeNoteDataToJson(boolean prettyPrint, Set<String> responseParameters, Collection<NoteData> notes);
|
||||
String serializeDepositAccountDataToJson(boolean prettyPrint, Set<String> responseParameters, Collection<DepositAccountData> accounts);
|
||||
|
||||
String serializeNoteDataToJson(boolean prettyPrint, Set<String> responseParameters, NoteData note);
|
||||
|
||||
String serializeLoanScheduleDataToJson(boolean prettyPrint, Set<String> responseParameters, LoanScheduleData loanSchedule);
|
||||
String serializeDepositAccountDataToJson(boolean prettyPrint, Set<String> responseParameters, DepositAccountData account);
|
||||
|
||||
String serializeLoanAccountDataToJson(boolean prettyPrint, Set<String> responseParameters, LoanAccountData loanAccount);
|
||||
String serializeClientCommandToJson(ClientCommand command);
|
||||
|
||||
String serializeLoanTransactionDataToJson(boolean prettyPrint, Set<String> responseParameters, LoanTransactionData newTransactionData);
|
||||
String serializeClientDataToJson(ClientData clientData);
|
||||
|
||||
String serializeLoanReassignmentDataToJson(boolean prettyPrint, Set<String> responseParameters, LoanReassignmentData loanReassignmentData);
|
||||
String serializeClientDataToJson(boolean prettyPrint, Set<String> responseParameters, ClientData clientData);
|
||||
|
||||
String serializeChargeDataToJson(boolean prettyPrint, Set<String> responseParameters, Collection<ChargeData> charges);
|
||||
String serializeClientDataToJson(boolean prettyPrint, Set<String> responseParameters, Collection<ClientData> clients);
|
||||
|
||||
String serializeChargeDataToJson(boolean prettyPrint, Set<String> responseParameters, ChargeData charge);
|
||||
String serializeClientAccountSummaryCollectionDataToJson(boolean prettyPrint, Set<String> responseParameters,
|
||||
ClientAccountSummaryCollectionData clientAccount);
|
||||
|
||||
String serializeGroupAccountSummaryCollectionDataToJson(boolean prettyPrint, Set<String> responseParameters,
|
||||
GroupAccountSummaryCollectionData groupAccount);
|
||||
|
||||
String serializeGroupDataToJson(boolean prettyPrint, Set<String> responseParameters, Collection<GroupData> groups);
|
||||
|
||||
String serializeGroupDataToJson(boolean prettyPrint, Set<String> responseParameters, GroupData group);
|
||||
|
||||
String serializeNoteDataToJson(boolean prettyPrint, Set<String> responseParameters, Collection<NoteData> notes);
|
||||
|
||||
String serializeNoteDataToJson(boolean prettyPrint, Set<String> responseParameters, NoteData note);
|
||||
|
||||
String serializeLoanScheduleDataToJson(boolean prettyPrint, Set<String> responseParameters, LoanScheduleData loanSchedule);
|
||||
|
||||
String serializeLoanAccountDataToJson(boolean prettyPrint, Set<String> responseParameters, LoanAccountData loanAccount);
|
||||
|
||||
String serializeLoanTransactionDataToJson(boolean prettyPrint, Set<String> responseParameters, LoanTransactionData newTransactionData);
|
||||
|
||||
String serializeLoanReassignmentDataToJson(boolean prettyPrint, Set<String> responseParameters,
|
||||
LoanReassignmentData loanReassignmentData);
|
||||
|
||||
String serializeChargeDataToJson(boolean prettyPrint, Set<String> responseParameters, Collection<ChargeData> charges);
|
||||
|
||||
String serializeChargeDataToJson(boolean prettyPrint, Set<String> responseParameters, ChargeData charge);
|
||||
|
||||
String serializeLoanChargeDataToJson(boolean prettyPrint, Set<String> responseParameters, LoanChargeData charge);
|
||||
|
||||
String serializeStaffDataToJson(boolean prettyPrint, Set<String> responseParameters, StaffData staff);
|
||||
|
||||
String serializeStaffDataToJson(boolean prettyPrint, Set<String> responseParameters, Collection<StaffData> staff);
|
||||
String serializeStaffDataToJson(boolean prettyPrint, Set<String> responseParameters, StaffData staff);
|
||||
|
||||
String serializeEntityIdentifier(EntityIdentifier identifier);
|
||||
|
||||
String serializeClientIdentifierDataToJson(boolean prettyPrint, Set<String> responseParameters, Collection<ClientIdentifierData> clientIdentifiers);
|
||||
String serializeStaffDataToJson(boolean prettyPrint, Set<String> responseParameters, Collection<StaffData> staff);
|
||||
|
||||
String serializeClientIdentifierDataToJson(boolean prettyPrint, Set<String> responseParameters, ClientIdentifierData clientIdentifierData);
|
||||
|
||||
String serializeDocumentDataToJson(boolean prettyPrint, Set<String> responseParameters, Collection<DocumentData> documentDatas);
|
||||
String serializeEntityIdentifier(EntityIdentifier identifier);
|
||||
|
||||
String serializeDocumentDataToJson(boolean prettyPrint, Set<String> responseParameters, DocumentData documentData);
|
||||
String serializeClientIdentifierDataToJson(boolean prettyPrint, Set<String> responseParameters,
|
||||
Collection<ClientIdentifierData> clientIdentifiers);
|
||||
|
||||
String serializeCodeDataToJson(boolean prettyPrint,Set<String> responseParameters, Collection<CodeData> codes);
|
||||
String serializeClientIdentifierDataToJson(boolean prettyPrint, Set<String> responseParameters,
|
||||
ClientIdentifierData clientIdentifierData);
|
||||
|
||||
String serializeCodeDataToJson(boolean prettyPrint,Set<String> responseParameters, CodeData code);
|
||||
|
||||
String serializeMakerCheckerDataToJson(boolean prettyPrint,Set<String> responseParameters, Collection<CommandSourceData> entries);
|
||||
String serializeDocumentDataToJson(boolean prettyPrint, Set<String> responseParameters, Collection<DocumentData> documentDatas);
|
||||
|
||||
String serializeSavingAccountsDataToJson(boolean prettyPrint, Set<String> responseParameters, SavingAccountData account);
|
||||
String serializeDocumentDataToJson(boolean prettyPrint, Set<String> responseParameters, DocumentData documentData);
|
||||
|
||||
String serializeSavingAccountsDataToJson(boolean prettyPrint, Set<String> responseParameters, Collection<SavingAccountData> accounts);
|
||||
String serializeCodeDataToJson(boolean prettyPrint, Set<String> responseParameters, Collection<CodeData> codes);
|
||||
|
||||
// TODO - KW - might devide serialize up into portfolio and account to reduce interface
|
||||
String serializeChartOfAccountDataToJson(boolean prettyPrint, Set<String> responseParameters, ChartOfAccountsData chartOfAccounts);
|
||||
String serializeCodeDataToJson(boolean prettyPrint, Set<String> responseParameters, CodeData code);
|
||||
|
||||
String serializeMakerCheckerDataToJson(boolean prettyPrint, Set<String> responseParameters, Collection<CommandSourceData> entries);
|
||||
|
||||
String serializeSavingAccountsDataToJson(boolean prettyPrint, Set<String> responseParameters, SavingAccountData account);
|
||||
|
||||
String serializeSavingAccountsDataToJson(boolean prettyPrint, Set<String> responseParameters, Collection<SavingAccountData> accounts);
|
||||
|
||||
// TODO - KW - might devide serialize up into portfolio and account to
|
||||
// reduce interface
|
||||
String serializeChartOfAccountDataToJson(boolean prettyPrint, Set<String> responseParameters, ChartOfAccountsData chartOfAccounts);
|
||||
}
|
||||
+29
-29
@@ -11,36 +11,36 @@ import org.springframework.security.access.prepost.PreAuthorize;
|
||||
|
||||
public interface ClientWritePlatformService {
|
||||
|
||||
@PreAuthorize(value = "hasAnyRole('ALL_FUNCTIONS', 'PORTFOLIO_MANAGEMENT_SUPER_USER', 'CREATE_CLIENT')")
|
||||
Long createClient(ClientCommand command);
|
||||
|
||||
@PreAuthorize(value = "hasAnyRole('ALL_FUNCTIONS', 'PORTFOLIO_MANAGEMENT_SUPER_USER', 'UPDATE_CLIENT')")
|
||||
EntityIdentifier updateClientDetails(ClientCommand command);
|
||||
|
||||
@PreAuthorize(value = "hasAnyRole('ALL_FUNCTIONS', 'PORTFOLIO_MANAGEMENT_SUPER_USER', 'DELETE_CLIENT')")
|
||||
EntityIdentifier deleteClient(ClientCommand command);
|
||||
|
||||
@PreAuthorize(value = "hasAnyRole('ALL_FUNCTIONS', 'PORTFOLIO_MANAGEMENT_SUPER_USER', 'CREATE_CLIENTIMAGE')")
|
||||
EntityIdentifier saveOrUpdateClientImage(Long clientId, String imageName, InputStream inputStream);
|
||||
|
||||
@PreAuthorize(value = "hasAnyRole('ALL_FUNCTIONS', 'PORTFOLIO_MANAGEMENT_SUPER_USER', 'CREATE_CLIENTIMAGE')")
|
||||
EntityIdentifier saveOrUpdateClientImage(Long clientId, Base64EncodedImage encodedImage);
|
||||
|
||||
@PreAuthorize(value = "hasAnyRole('ALL_FUNCTIONS', 'PORTFOLIO_MANAGEMENT_SUPER_USER', 'DELETE_CLIENTIMAGE')")
|
||||
EntityIdentifier deleteClientImage(Long clientId);
|
||||
@PreAuthorize(value = "hasAnyRole('ALL_FUNCTIONS', 'PORTFOLIO_MANAGEMENT_SUPER_USER', 'CREATE_CLIENT')")
|
||||
Long createClient(ClientCommand command);
|
||||
|
||||
@PreAuthorize(value = "hasAnyRole('ALL_FUNCTIONS', 'PORTFOLIO_MANAGEMENT_SUPER_USER', 'CREATE_CLIENTNOTE')")
|
||||
EntityIdentifier addClientNote(NoteCommand command);
|
||||
@PreAuthorize(value = "hasAnyRole('ALL_FUNCTIONS', 'PORTFOLIO_MANAGEMENT_SUPER_USER', 'UPDATE_CLIENT')")
|
||||
EntityIdentifier updateClientDetails(ClientCommand command);
|
||||
|
||||
@PreAuthorize(value = "hasAnyRole('ALL_FUNCTIONS', 'PORTFOLIO_MANAGEMENT_SUPER_USER', 'UPDATE_CLIENTNOTE')")
|
||||
EntityIdentifier updateNote(NoteCommand command);
|
||||
@PreAuthorize(value = "hasAnyRole('ALL_FUNCTIONS', 'PORTFOLIO_MANAGEMENT_SUPER_USER', 'DELETE_CLIENT')")
|
||||
EntityIdentifier deleteClient(ClientCommand command);
|
||||
|
||||
@PreAuthorize(value = "hasAnyRole('ALL_FUNCTIONS', 'PORTFOLIO_MANAGEMENT_SUPER_USER', 'CREATE_CLIENTIDENTIFIER')")
|
||||
Long addClientIdentifier(ClientIdentifierCommand clientIdentifierCommand);
|
||||
|
||||
@PreAuthorize(value = "hasAnyRole('ALL_FUNCTIONS', 'PORTFOLIO_MANAGEMENT_SUPER_USER', 'UPDATE_CLIENTIDENTIFIER')")
|
||||
EntityIdentifier updateClientIdentifier(ClientIdentifierCommand clientIdentifierCommand);
|
||||
|
||||
@PreAuthorize(value = "hasAnyRole('ALL_FUNCTIONS', 'PORTFOLIO_MANAGEMENT_SUPER_USER', 'DELETE_CLIENTIDENTIFIER')")
|
||||
EntityIdentifier deleteClientIdentifier(Long clientIdentifierId);
|
||||
@PreAuthorize(value = "hasAnyRole('ALL_FUNCTIONS', 'PORTFOLIO_MANAGEMENT_SUPER_USER', 'CREATE_CLIENTIMAGE')")
|
||||
EntityIdentifier saveOrUpdateClientImage(Long clientId, String imageName, InputStream inputStream);
|
||||
|
||||
@PreAuthorize(value = "hasAnyRole('ALL_FUNCTIONS', 'PORTFOLIO_MANAGEMENT_SUPER_USER', 'CREATE_CLIENTIMAGE')")
|
||||
EntityIdentifier saveOrUpdateClientImage(Long clientId, Base64EncodedImage encodedImage);
|
||||
|
||||
@PreAuthorize(value = "hasAnyRole('ALL_FUNCTIONS', 'PORTFOLIO_MANAGEMENT_SUPER_USER', 'DELETE_CLIENTIMAGE')")
|
||||
EntityIdentifier deleteClientImage(Long clientId);
|
||||
|
||||
@PreAuthorize(value = "hasAnyRole('ALL_FUNCTIONS', 'PORTFOLIO_MANAGEMENT_SUPER_USER', 'CREATE_CLIENTNOTE')")
|
||||
EntityIdentifier addClientNote(NoteCommand command);
|
||||
|
||||
@PreAuthorize(value = "hasAnyRole('ALL_FUNCTIONS', 'PORTFOLIO_MANAGEMENT_SUPER_USER', 'UPDATE_CLIENTNOTE')")
|
||||
EntityIdentifier updateNote(NoteCommand command);
|
||||
|
||||
@PreAuthorize(value = "hasAnyRole('ALL_FUNCTIONS', 'PORTFOLIO_MANAGEMENT_SUPER_USER', 'CREATE_CLIENTIDENTIFIER')")
|
||||
Long addClientIdentifier(ClientIdentifierCommand clientIdentifierCommand);
|
||||
|
||||
@PreAuthorize(value = "hasAnyRole('ALL_FUNCTIONS', 'PORTFOLIO_MANAGEMENT_SUPER_USER', 'UPDATE_CLIENTIDENTIFIER')")
|
||||
EntityIdentifier updateClientIdentifier(ClientIdentifierCommand clientIdentifierCommand);
|
||||
|
||||
@PreAuthorize(value = "hasAnyRole('ALL_FUNCTIONS', 'PORTFOLIO_MANAGEMENT_SUPER_USER', 'DELETE_CLIENTIDENTIFIER')")
|
||||
EntityIdentifier deleteClientIdentifier(Long clientIdentifierId);
|
||||
}
|
||||
+267
-317
@@ -40,382 +40,332 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
@Service
|
||||
public class ClientWritePlatformServiceJpaRepositoryImpl implements ClientWritePlatformService {
|
||||
|
||||
private final static Logger logger = LoggerFactory.getLogger(ClientWritePlatformServiceJpaRepositoryImpl.class);
|
||||
private final static Logger logger = LoggerFactory.getLogger(ClientWritePlatformServiceJpaRepositoryImpl.class);
|
||||
|
||||
private final PlatformSecurityContext context;
|
||||
private final ClientRepository clientRepository;
|
||||
private final ClientIdentifierRepository clientIdentifierRepository;
|
||||
private final OfficeRepository officeRepository;
|
||||
private final NoteRepository noteRepository;
|
||||
private final CodeValueRepository codeValueRepository;
|
||||
private final PlatformSecurityContext context;
|
||||
private final ClientRepository clientRepository;
|
||||
private final ClientIdentifierRepository clientIdentifierRepository;
|
||||
private final OfficeRepository officeRepository;
|
||||
private final NoteRepository noteRepository;
|
||||
private final CodeValueRepository codeValueRepository;
|
||||
|
||||
// FIXME - kw - this value is hardcoded for now but will be retrieved from configuration
|
||||
private boolean makerCheckerEnabledForTask = false;
|
||||
// FIXME - kw - this value is hardcoded for now but will be retrieved from
|
||||
// configuration
|
||||
private boolean makerCheckerEnabledForTask = false;
|
||||
|
||||
@Autowired
|
||||
public ClientWritePlatformServiceJpaRepositoryImpl(
|
||||
final PlatformSecurityContext context,
|
||||
final ClientRepository clientRepository,
|
||||
final ClientIdentifierRepository clientIdentifierRepository,
|
||||
final OfficeRepository officeRepository,
|
||||
NoteRepository noteRepository,
|
||||
final CodeValueRepository codeValueRepository) {
|
||||
this.context = context;
|
||||
this.clientRepository = clientRepository;
|
||||
this.clientIdentifierRepository = clientIdentifierRepository;
|
||||
this.officeRepository = officeRepository;
|
||||
this.noteRepository = noteRepository;
|
||||
this.codeValueRepository = codeValueRepository;
|
||||
}
|
||||
@Autowired
|
||||
public ClientWritePlatformServiceJpaRepositoryImpl(final PlatformSecurityContext context, final ClientRepository clientRepository,
|
||||
final ClientIdentifierRepository clientIdentifierRepository, final OfficeRepository officeRepository,
|
||||
NoteRepository noteRepository, final CodeValueRepository codeValueRepository) {
|
||||
this.context = context;
|
||||
this.clientRepository = clientRepository;
|
||||
this.clientIdentifierRepository = clientIdentifierRepository;
|
||||
this.officeRepository = officeRepository;
|
||||
this.noteRepository = noteRepository;
|
||||
this.codeValueRepository = codeValueRepository;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@Override
|
||||
public EntityIdentifier deleteClient(final ClientCommand command) {
|
||||
@Transactional
|
||||
@Override
|
||||
public EntityIdentifier deleteClient(final ClientCommand command) {
|
||||
|
||||
final Long clientId = command.getId();
|
||||
final Client client = this.clientRepository.findOne(clientId);
|
||||
if (client == null || client.isDeleted()) {
|
||||
throw new ClientNotFoundException(clientId);
|
||||
}
|
||||
final Long clientId = command.getId();
|
||||
final Client client = this.clientRepository.findOne(clientId);
|
||||
if (client == null || client.isDeleted()) { throw new ClientNotFoundException(clientId); }
|
||||
|
||||
client.delete();
|
||||
this.clientRepository.save(client);
|
||||
|
||||
if (this.makerCheckerEnabledForTask && !command.isApprovedByChecker()) {
|
||||
throw new RollbackTransactionAsCommandIsNotApprovedByCheckerException();
|
||||
}
|
||||
client.delete();
|
||||
this.clientRepository.save(client);
|
||||
|
||||
return new EntityIdentifier(client.getId());
|
||||
}
|
||||
if (this.makerCheckerEnabledForTask && !command.isApprovedByChecker()) { throw new RollbackTransactionAsCommandIsNotApprovedByCheckerException(); }
|
||||
|
||||
/*
|
||||
* Guaranteed to throw an exception no matter what the data integrity issue
|
||||
* is.
|
||||
*/
|
||||
private void handleDataIntegrityIssues(final ClientCommand command,
|
||||
final DataIntegrityViolationException dve) {
|
||||
return new EntityIdentifier(client.getId());
|
||||
}
|
||||
|
||||
Throwable realCause = dve.getMostSpecificCause();
|
||||
if (realCause.getMessage().contains("external_id")) {
|
||||
throw new PlatformDataIntegrityException(
|
||||
"error.msg.client.duplicate.externalId",
|
||||
"Client with externalId `" + command.getExternalId()
|
||||
+ "` already exists", "externalId",
|
||||
command.getExternalId());
|
||||
}
|
||||
/*
|
||||
* Guaranteed to throw an exception no matter what the data integrity issue
|
||||
* is.
|
||||
*/
|
||||
private void handleDataIntegrityIssues(final ClientCommand command, final DataIntegrityViolationException dve) {
|
||||
|
||||
logger.error(dve.getMessage(), dve);
|
||||
throw new PlatformDataIntegrityException(
|
||||
"error.msg.client.unknown.data.integrity.issue",
|
||||
"Unknown data integrity issue with resource.");
|
||||
}
|
||||
Throwable realCause = dve.getMostSpecificCause();
|
||||
if (realCause.getMessage().contains("external_id")) { throw new PlatformDataIntegrityException(
|
||||
"error.msg.client.duplicate.externalId", "Client with externalId `" + command.getExternalId() + "` already exists",
|
||||
"externalId", command.getExternalId()); }
|
||||
|
||||
@Transactional
|
||||
@Override
|
||||
public Long createClient(final ClientCommand command) {
|
||||
logger.error(dve.getMessage(), dve);
|
||||
throw new PlatformDataIntegrityException("error.msg.client.unknown.data.integrity.issue",
|
||||
"Unknown data integrity issue with resource.");
|
||||
}
|
||||
|
||||
try {
|
||||
context.authenticatedUser();
|
||||
@Transactional
|
||||
@Override
|
||||
public Long createClient(final ClientCommand command) {
|
||||
|
||||
final ClientCommandValidator validator = new ClientCommandValidator(command);
|
||||
validator.validateForCreate();
|
||||
try {
|
||||
context.authenticatedUser();
|
||||
|
||||
final Office clientOffice = this.officeRepository.findOne(command.getOfficeId());
|
||||
if (clientOffice == null) {
|
||||
throw new OfficeNotFoundException(command.getOfficeId());
|
||||
}
|
||||
final ClientCommandValidator validator = new ClientCommandValidator(command);
|
||||
validator.validateForCreate();
|
||||
|
||||
String firstname = command.getFirstname();
|
||||
String lastname = command.getLastname();
|
||||
if (StringUtils.isNotBlank(command.getClientOrBusinessName())) {
|
||||
lastname = command.getClientOrBusinessName();
|
||||
firstname = null;
|
||||
}
|
||||
final Office clientOffice = this.officeRepository.findOne(command.getOfficeId());
|
||||
if (clientOffice == null) { throw new OfficeNotFoundException(command.getOfficeId()); }
|
||||
|
||||
final Client newClient = Client
|
||||
.newClient(clientOffice, firstname, lastname,
|
||||
command.getJoiningDate(), command.getExternalId());
|
||||
String firstname = command.getFirstname();
|
||||
String lastname = command.getLastname();
|
||||
if (StringUtils.isNotBlank(command.getClientOrBusinessName())) {
|
||||
lastname = command.getClientOrBusinessName();
|
||||
firstname = null;
|
||||
}
|
||||
|
||||
this.clientRepository.save(newClient);
|
||||
final Client newClient = Client.newClient(clientOffice, firstname, lastname, command.getJoiningDate(), command.getExternalId());
|
||||
|
||||
if (this.makerCheckerEnabledForTask && !command.isApprovedByChecker()) {
|
||||
throw new RollbackTransactionAsCommandIsNotApprovedByCheckerException();
|
||||
}
|
||||
|
||||
return newClient.getId();
|
||||
} catch (DataIntegrityViolationException dve) {
|
||||
handleDataIntegrityIssues(command, dve);
|
||||
return Long.valueOf(-1);
|
||||
}
|
||||
}
|
||||
this.clientRepository.save(newClient);
|
||||
|
||||
@Transactional
|
||||
@Override
|
||||
public EntityIdentifier updateClientDetails(final ClientCommand command) {
|
||||
if (this.makerCheckerEnabledForTask && !command.isApprovedByChecker()) { throw new RollbackTransactionAsCommandIsNotApprovedByCheckerException(); }
|
||||
|
||||
try {
|
||||
context.authenticatedUser();
|
||||
return newClient.getId();
|
||||
} catch (DataIntegrityViolationException dve) {
|
||||
handleDataIntegrityIssues(command, dve);
|
||||
return Long.valueOf(-1);
|
||||
}
|
||||
}
|
||||
|
||||
final ClientCommandValidator validator = new ClientCommandValidator(command);
|
||||
validator.validateForUpdate();
|
||||
@Transactional
|
||||
@Override
|
||||
public EntityIdentifier updateClientDetails(final ClientCommand command) {
|
||||
|
||||
Office clientOffice = null;
|
||||
Long officeId = command.getOfficeId();
|
||||
if (command.isOfficeChanged() && officeId != null) {
|
||||
clientOffice = this.officeRepository.findOne(officeId);
|
||||
if (clientOffice == null) {
|
||||
throw new OfficeNotFoundException(command.getOfficeId());
|
||||
}
|
||||
}
|
||||
try {
|
||||
context.authenticatedUser();
|
||||
|
||||
final Client clientForUpdate = this.clientRepository.findOne(command.getId());
|
||||
if (clientForUpdate == null || clientForUpdate.isDeleted()) {
|
||||
throw new ClientNotFoundException(command.getId());
|
||||
}
|
||||
clientForUpdate.update(clientOffice, command);
|
||||
final ClientCommandValidator validator = new ClientCommandValidator(command);
|
||||
validator.validateForUpdate();
|
||||
|
||||
this.clientRepository.saveAndFlush(clientForUpdate);
|
||||
|
||||
if (this.makerCheckerEnabledForTask && !command.isApprovedByChecker()) {
|
||||
throw new RollbackTransactionAsCommandIsNotApprovedByCheckerException();
|
||||
}
|
||||
Office clientOffice = null;
|
||||
Long officeId = command.getOfficeId();
|
||||
if (command.isOfficeChanged() && officeId != null) {
|
||||
clientOffice = this.officeRepository.findOne(officeId);
|
||||
if (clientOffice == null) { throw new OfficeNotFoundException(command.getOfficeId()); }
|
||||
}
|
||||
|
||||
return new EntityIdentifier(clientForUpdate.getId());
|
||||
} catch (DataIntegrityViolationException dve) {
|
||||
handleDataIntegrityIssues(command, dve);
|
||||
return new EntityIdentifier(Long.valueOf(-1));
|
||||
}
|
||||
}
|
||||
final Client clientForUpdate = this.clientRepository.findOne(command.getId());
|
||||
if (clientForUpdate == null || clientForUpdate.isDeleted()) { throw new ClientNotFoundException(command.getId()); }
|
||||
clientForUpdate.update(clientOffice, command);
|
||||
|
||||
@Transactional
|
||||
@Override
|
||||
public EntityIdentifier addClientNote(final NoteCommand command) {
|
||||
this.clientRepository.saveAndFlush(clientForUpdate);
|
||||
|
||||
context.authenticatedUser();
|
||||
if (this.makerCheckerEnabledForTask && !command.isApprovedByChecker()) { throw new RollbackTransactionAsCommandIsNotApprovedByCheckerException(); }
|
||||
|
||||
final Client clientForUpdate = this.clientRepository.findOne(command.getClientId());
|
||||
if (clientForUpdate == null) {
|
||||
throw new ClientNotFoundException(command.getClientId());
|
||||
}
|
||||
return new EntityIdentifier(clientForUpdate.getId());
|
||||
} catch (DataIntegrityViolationException dve) {
|
||||
handleDataIntegrityIssues(command, dve);
|
||||
return new EntityIdentifier(Long.valueOf(-1));
|
||||
}
|
||||
}
|
||||
|
||||
final Note note = Note.clientNote(clientForUpdate, command.getNote());
|
||||
@Transactional
|
||||
@Override
|
||||
public EntityIdentifier addClientNote(final NoteCommand command) {
|
||||
|
||||
this.noteRepository.save(note);
|
||||
context.authenticatedUser();
|
||||
|
||||
return new EntityIdentifier(note.getId());
|
||||
}
|
||||
final Client clientForUpdate = this.clientRepository.findOne(command.getClientId());
|
||||
if (clientForUpdate == null) { throw new ClientNotFoundException(command.getClientId()); }
|
||||
|
||||
@Transactional
|
||||
@Override
|
||||
public EntityIdentifier updateNote(final NoteCommand command) {
|
||||
final Note note = Note.clientNote(clientForUpdate, command.getNote());
|
||||
|
||||
context.authenticatedUser();
|
||||
this.noteRepository.save(note);
|
||||
|
||||
final Note noteForUpdate = this.noteRepository.findOne(command.getId());
|
||||
if (noteForUpdate == null
|
||||
|| noteForUpdate.isNotAgainstClientWithIdOf(command.getClientId())) {
|
||||
throw new NoteNotFoundException(command.getId(),command.getClientId(), "client");
|
||||
}
|
||||
return new EntityIdentifier(note.getId());
|
||||
}
|
||||
|
||||
noteForUpdate.update(command.getNote());
|
||||
@Transactional
|
||||
@Override
|
||||
public EntityIdentifier updateNote(final NoteCommand command) {
|
||||
|
||||
return new EntityIdentifier(noteForUpdate.getId());
|
||||
}
|
||||
context.authenticatedUser();
|
||||
|
||||
@Transactional
|
||||
@Override
|
||||
public Long addClientIdentifier(final ClientIdentifierCommand command) {
|
||||
|
||||
String documentTypeLabel = null;
|
||||
Long documentTypeId = null;
|
||||
final String documentKey = command.getDocumentKey();
|
||||
|
||||
try {
|
||||
context.authenticatedUser();
|
||||
final Note noteForUpdate = this.noteRepository.findOne(command.getId());
|
||||
if (noteForUpdate == null || noteForUpdate.isNotAgainstClientWithIdOf(command.getClientId())) { throw new NoteNotFoundException(
|
||||
command.getId(), command.getClientId(), "client"); }
|
||||
|
||||
final ClientIdentifierCommandValidator validator = new ClientIdentifierCommandValidator(command);
|
||||
validator.validateForCreate();
|
||||
noteForUpdate.update(command.getNote());
|
||||
|
||||
final Client client = this.clientRepository.findOne(command.getClientId());
|
||||
if (client == null || client.isDeleted()) {
|
||||
throw new ClientNotFoundException(command.getClientId());
|
||||
}
|
||||
return new EntityIdentifier(noteForUpdate.getId());
|
||||
}
|
||||
|
||||
final CodeValue documentType = this.codeValueRepository.findOne(command.getDocumentTypeId());
|
||||
if (documentType == null) {
|
||||
throw new CodeValueNotFoundException(command.getDocumentTypeId());
|
||||
}
|
||||
documentTypeId = documentType.getId();
|
||||
documentTypeLabel = documentType.getLabel();
|
||||
@Transactional
|
||||
@Override
|
||||
public Long addClientIdentifier(final ClientIdentifierCommand command) {
|
||||
|
||||
final ClientIdentifier clientIdentifier = ClientIdentifier.createNew(client, documentType, documentKey, command.getDescription());
|
||||
String documentTypeLabel = null;
|
||||
Long documentTypeId = null;
|
||||
final String documentKey = command.getDocumentKey();
|
||||
|
||||
this.clientIdentifierRepository.save(clientIdentifier);
|
||||
try {
|
||||
context.authenticatedUser();
|
||||
|
||||
return clientIdentifier.getId();
|
||||
} catch (DataIntegrityViolationException dve) {
|
||||
handleClientIdentifierDataIntegrityViolation(documentTypeLabel, documentTypeId, documentKey, dve);
|
||||
return Long.valueOf(-1);
|
||||
}
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@Override
|
||||
public EntityIdentifier updateClientIdentifier(final ClientIdentifierCommand command) {
|
||||
|
||||
String documentTypeLabel = null;
|
||||
Long documentTypeId = null;
|
||||
String documentKey = command.getDocumentKey();
|
||||
|
||||
try {
|
||||
context.authenticatedUser();
|
||||
final ClientIdentifierCommandValidator validator = new ClientIdentifierCommandValidator(command);
|
||||
validator.validateForCreate();
|
||||
|
||||
final ClientIdentifierCommandValidator validator = new ClientIdentifierCommandValidator(command);
|
||||
validator.validateForUpdate();
|
||||
final Client client = this.clientRepository.findOne(command.getClientId());
|
||||
if (client == null || client.isDeleted()) { throw new ClientNotFoundException(command.getClientId()); }
|
||||
|
||||
CodeValue documentType = null;
|
||||
documentTypeId = command.getDocumentTypeId();
|
||||
if (command.isDocumentTypeChanged() && documentTypeId != null) {
|
||||
documentType = this.codeValueRepository.findOne(documentTypeId);
|
||||
if (documentType == null) {
|
||||
throw new CodeValueNotFoundException(command.getDocumentTypeId());
|
||||
}
|
||||
documentTypeId = documentType.getId();
|
||||
documentTypeLabel = documentType.getLabel();
|
||||
}
|
||||
final CodeValue documentType = this.codeValueRepository.findOne(command.getDocumentTypeId());
|
||||
if (documentType == null) { throw new CodeValueNotFoundException(command.getDocumentTypeId()); }
|
||||
documentTypeId = documentType.getId();
|
||||
documentTypeLabel = documentType.getLabel();
|
||||
|
||||
final ClientIdentifier clientIdentifierForUpdate = this.clientIdentifierRepository.findOne(command.getId());
|
||||
if (clientIdentifierForUpdate == null) {
|
||||
throw new ClientIdentifierNotFoundException(command.getId());
|
||||
}
|
||||
|
||||
// TODO - KW - why need to check what changed when integrity violation occurs?
|
||||
if (command.isDocumentTypeChanged() && command.isDocumentKeyChanged()) {
|
||||
documentTypeId = command.getDocumentTypeId();
|
||||
documentKey = command.getDocumentKey();
|
||||
} else if (command.isDocumentTypeChanged() && !command.isDocumentKeyChanged()) {
|
||||
documentTypeId = command.getDocumentTypeId();
|
||||
documentKey = clientIdentifierForUpdate.getDocumentKey();
|
||||
} else if (!command.isDocumentTypeChanged() && command.isDocumentKeyChanged()) {
|
||||
documentTypeId = clientIdentifierForUpdate.getDocumentType().getId();
|
||||
documentKey = clientIdentifierForUpdate.getDocumentKey();
|
||||
}
|
||||
|
||||
clientIdentifierForUpdate.update(command, documentType);
|
||||
final ClientIdentifier clientIdentifier = ClientIdentifier.createNew(client, documentType, documentKey,
|
||||
command.getDescription());
|
||||
|
||||
this.clientIdentifierRepository.saveAndFlush(clientIdentifierForUpdate);
|
||||
this.clientIdentifierRepository.save(clientIdentifier);
|
||||
|
||||
return new EntityIdentifier(clientIdentifierForUpdate.getId());
|
||||
} catch (DataIntegrityViolationException dve) {
|
||||
handleClientIdentifierDataIntegrityViolation(documentTypeLabel, documentTypeId, documentKey, dve);
|
||||
return new EntityIdentifier(Long.valueOf(-1));
|
||||
}
|
||||
}
|
||||
return clientIdentifier.getId();
|
||||
} catch (DataIntegrityViolationException dve) {
|
||||
handleClientIdentifierDataIntegrityViolation(documentTypeLabel, documentTypeId, documentKey, dve);
|
||||
return Long.valueOf(-1);
|
||||
}
|
||||
}
|
||||
|
||||
private void handleClientIdentifierDataIntegrityViolation(
|
||||
final String documentTypeLabel,
|
||||
final Long documentTypeId,
|
||||
final String documentKey,
|
||||
final DataIntegrityViolationException dve) {
|
||||
|
||||
if (dve.getMostSpecificCause().getMessage().contains("unique_client_identifier")) {
|
||||
throw new DuplicateClientIdentifierException(documentTypeLabel);
|
||||
} else if (dve.getMostSpecificCause().getMessage().contains("unique_identifier_key")) {
|
||||
throw new DuplicateClientIdentifierException(documentTypeId, documentTypeLabel, documentKey);
|
||||
}
|
||||
|
||||
// only log as error if unexpected data integrity violation.
|
||||
logger.error(dve.getMessage(), dve);
|
||||
throw new PlatformDataIntegrityException(
|
||||
"error.msg.clientIdentifier.unknown.data.integrity.issue",
|
||||
"Unknown data integrity issue with resource.");
|
||||
}
|
||||
@Transactional
|
||||
@Override
|
||||
public EntityIdentifier updateClientIdentifier(final ClientIdentifierCommand command) {
|
||||
|
||||
@Transactional
|
||||
@Override
|
||||
public EntityIdentifier deleteClientIdentifier(final Long clientIdentifierId) {
|
||||
final ClientIdentifier clientIdentifier = this.clientIdentifierRepository.findOne(clientIdentifierId);
|
||||
if (clientIdentifier == null) {
|
||||
throw new ClientIdentifierNotFoundException(clientIdentifierId);
|
||||
}
|
||||
this.clientIdentifierRepository.delete(clientIdentifier);
|
||||
String documentTypeLabel = null;
|
||||
Long documentTypeId = null;
|
||||
String documentKey = command.getDocumentKey();
|
||||
|
||||
return new EntityIdentifier(clientIdentifierId);
|
||||
}
|
||||
try {
|
||||
context.authenticatedUser();
|
||||
|
||||
@Transactional
|
||||
@Override
|
||||
public EntityIdentifier saveOrUpdateClientImage(Long clientId,
|
||||
String imageName, InputStream inputStream) {
|
||||
try {
|
||||
final Client client = this.clientRepository.findOne(clientId);
|
||||
String imageUploadLocation = setupForClientImageUpdate(clientId,
|
||||
client);
|
||||
final ClientIdentifierCommandValidator validator = new ClientIdentifierCommandValidator(command);
|
||||
validator.validateForUpdate();
|
||||
|
||||
String imageLocation = FileUtils.saveToFileSystem(inputStream,
|
||||
imageUploadLocation, imageName);
|
||||
CodeValue documentType = null;
|
||||
documentTypeId = command.getDocumentTypeId();
|
||||
if (command.isDocumentTypeChanged() && documentTypeId != null) {
|
||||
documentType = this.codeValueRepository.findOne(documentTypeId);
|
||||
if (documentType == null) { throw new CodeValueNotFoundException(command.getDocumentTypeId()); }
|
||||
documentTypeId = documentType.getId();
|
||||
documentTypeLabel = documentType.getLabel();
|
||||
}
|
||||
|
||||
|
||||
return updateClientImage(clientId, client, imageLocation);
|
||||
} catch (IOException ioe) {
|
||||
logger.error(ioe.getMessage(), ioe);
|
||||
throw new DocumentManagementException(imageName);
|
||||
}
|
||||
}
|
||||
final ClientIdentifier clientIdentifierForUpdate = this.clientIdentifierRepository.findOne(command.getId());
|
||||
if (clientIdentifierForUpdate == null) { throw new ClientIdentifierNotFoundException(command.getId()); }
|
||||
|
||||
@Transactional
|
||||
@Override
|
||||
public EntityIdentifier deleteClientImage(final Long clientId) {
|
||||
|
||||
final Client client = this.clientRepository.findOne(clientId);
|
||||
if (client == null || client.isDeleted()) {
|
||||
throw new ClientNotFoundException(clientId);
|
||||
}
|
||||
|
||||
// delete image from the file system
|
||||
if (StringUtils.isNotEmpty(client.getImageKey())) {
|
||||
FileUtils.deleteClientImage(clientId, client.getImageKey());
|
||||
}
|
||||
return updateClientImage(clientId, client, null);
|
||||
}
|
||||
// TODO - KW - why need to check what changed when integrity
|
||||
// violation occurs?
|
||||
if (command.isDocumentTypeChanged() && command.isDocumentKeyChanged()) {
|
||||
documentTypeId = command.getDocumentTypeId();
|
||||
documentKey = command.getDocumentKey();
|
||||
} else if (command.isDocumentTypeChanged() && !command.isDocumentKeyChanged()) {
|
||||
documentTypeId = command.getDocumentTypeId();
|
||||
documentKey = clientIdentifierForUpdate.getDocumentKey();
|
||||
} else if (!command.isDocumentTypeChanged() && command.isDocumentKeyChanged()) {
|
||||
documentTypeId = clientIdentifierForUpdate.getDocumentType().getId();
|
||||
documentKey = clientIdentifierForUpdate.getDocumentKey();
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityIdentifier saveOrUpdateClientImage(final Long clientId, final Base64EncodedImage encodedImage) {
|
||||
try {
|
||||
final Client client = this.clientRepository.findOne(clientId);
|
||||
final String imageUploadLocation = setupForClientImageUpdate(clientId, client);
|
||||
clientIdentifierForUpdate.update(command, documentType);
|
||||
|
||||
final String imageLocation = FileUtils.saveToFileSystem(encodedImage, imageUploadLocation, "image");
|
||||
|
||||
return updateClientImage(clientId, client, imageLocation);
|
||||
} catch (IOException ioe) {
|
||||
logger.error(ioe.getMessage(), ioe);
|
||||
throw new DocumentManagementException("image");
|
||||
}
|
||||
}
|
||||
this.clientIdentifierRepository.saveAndFlush(clientIdentifierForUpdate);
|
||||
|
||||
private String setupForClientImageUpdate(final Long clientId, final Client client) {
|
||||
if (client == null || client.isDeleted()) {
|
||||
throw new ClientNotFoundException(clientId);
|
||||
}
|
||||
return new EntityIdentifier(clientIdentifierForUpdate.getId());
|
||||
} catch (DataIntegrityViolationException dve) {
|
||||
handleClientIdentifierDataIntegrityViolation(documentTypeLabel, documentTypeId, documentKey, dve);
|
||||
return new EntityIdentifier(Long.valueOf(-1));
|
||||
}
|
||||
}
|
||||
|
||||
final String imageUploadLocation = FileUtils.generateClientImageParentDirectory(clientId);
|
||||
// delete previous image from the file system
|
||||
if (StringUtils.isNotEmpty(client.getImageKey())) {
|
||||
FileUtils.deleteClientImage(clientId, client.getImageKey());
|
||||
}
|
||||
private void handleClientIdentifierDataIntegrityViolation(final String documentTypeLabel, final Long documentTypeId,
|
||||
final String documentKey, final DataIntegrityViolationException dve) {
|
||||
|
||||
/** Recursively create the directory if it does not exist **/
|
||||
if (!new File(imageUploadLocation).isDirectory()) {
|
||||
new File(imageUploadLocation).mkdirs();
|
||||
}
|
||||
return imageUploadLocation;
|
||||
}
|
||||
|
||||
private EntityIdentifier updateClientImage(final Long clientId, final Client client, final String imageLocation) {
|
||||
client.setImageKey(imageLocation);
|
||||
this.clientRepository.save(client);
|
||||
if (dve.getMostSpecificCause().getMessage().contains("unique_client_identifier")) {
|
||||
throw new DuplicateClientIdentifierException(documentTypeLabel);
|
||||
} else if (dve.getMostSpecificCause().getMessage().contains("unique_identifier_key")) { throw new DuplicateClientIdentifierException(
|
||||
documentTypeId, documentTypeLabel, documentKey); }
|
||||
|
||||
return new EntityIdentifier(clientId);
|
||||
}
|
||||
// only log as error if unexpected data integrity violation.
|
||||
logger.error(dve.getMessage(), dve);
|
||||
throw new PlatformDataIntegrityException("error.msg.clientIdentifier.unknown.data.integrity.issue",
|
||||
"Unknown data integrity issue with resource.");
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@Override
|
||||
public EntityIdentifier deleteClientIdentifier(final Long clientIdentifierId) {
|
||||
final ClientIdentifier clientIdentifier = this.clientIdentifierRepository.findOne(clientIdentifierId);
|
||||
if (clientIdentifier == null) { throw new ClientIdentifierNotFoundException(clientIdentifierId); }
|
||||
this.clientIdentifierRepository.delete(clientIdentifier);
|
||||
|
||||
return new EntityIdentifier(clientIdentifierId);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@Override
|
||||
public EntityIdentifier saveOrUpdateClientImage(Long clientId, String imageName, InputStream inputStream) {
|
||||
try {
|
||||
final Client client = this.clientRepository.findOne(clientId);
|
||||
String imageUploadLocation = setupForClientImageUpdate(clientId, client);
|
||||
|
||||
String imageLocation = FileUtils.saveToFileSystem(inputStream, imageUploadLocation, imageName);
|
||||
|
||||
return updateClientImage(clientId, client, imageLocation);
|
||||
} catch (IOException ioe) {
|
||||
logger.error(ioe.getMessage(), ioe);
|
||||
throw new DocumentManagementException(imageName);
|
||||
}
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@Override
|
||||
public EntityIdentifier deleteClientImage(final Long clientId) {
|
||||
|
||||
final Client client = this.clientRepository.findOne(clientId);
|
||||
if (client == null || client.isDeleted()) { throw new ClientNotFoundException(clientId); }
|
||||
|
||||
// delete image from the file system
|
||||
if (StringUtils.isNotEmpty(client.getImageKey())) {
|
||||
FileUtils.deleteClientImage(clientId, client.getImageKey());
|
||||
}
|
||||
return updateClientImage(clientId, client, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityIdentifier saveOrUpdateClientImage(final Long clientId, final Base64EncodedImage encodedImage) {
|
||||
try {
|
||||
final Client client = this.clientRepository.findOne(clientId);
|
||||
final String imageUploadLocation = setupForClientImageUpdate(clientId, client);
|
||||
|
||||
final String imageLocation = FileUtils.saveToFileSystem(encodedImage, imageUploadLocation, "image");
|
||||
|
||||
return updateClientImage(clientId, client, imageLocation);
|
||||
} catch (IOException ioe) {
|
||||
logger.error(ioe.getMessage(), ioe);
|
||||
throw new DocumentManagementException("image");
|
||||
}
|
||||
}
|
||||
|
||||
private String setupForClientImageUpdate(final Long clientId, final Client client) {
|
||||
if (client == null || client.isDeleted()) { throw new ClientNotFoundException(clientId); }
|
||||
|
||||
final String imageUploadLocation = FileUtils.generateClientImageParentDirectory(clientId);
|
||||
// delete previous image from the file system
|
||||
if (StringUtils.isNotEmpty(client.getImageKey())) {
|
||||
FileUtils.deleteClientImage(clientId, client.getImageKey());
|
||||
}
|
||||
|
||||
/** Recursively create the directory if it does not exist **/
|
||||
if (!new File(imageUploadLocation).isDirectory()) {
|
||||
new File(imageUploadLocation).mkdirs();
|
||||
}
|
||||
return imageUploadLocation;
|
||||
}
|
||||
|
||||
private EntityIdentifier updateClientImage(final Long clientId, final Client client, final String imageLocation) {
|
||||
client.setImageKey(imageLocation);
|
||||
this.clientRepository.save(client);
|
||||
|
||||
return new EntityIdentifier(clientId);
|
||||
}
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
package org.mifosng.platform.infrastructure.errorhandling;
|
||||
|
||||
|
||||
/**
|
||||
* A {@link RuntimeException} that is thrown in the case where an invalid or unknown
|
||||
* command is attempted to be processed by platform.
|
||||
*/
|
||||
public class UnsupportedCommandException extends RuntimeException {
|
||||
|
||||
private final String unsupportedCommandName;
|
||||
|
||||
public UnsupportedCommandException(final String unsupportedCommandName) {
|
||||
this.unsupportedCommandName = unsupportedCommandName;
|
||||
}
|
||||
|
||||
public String getUnsupportedCommandName() {
|
||||
return unsupportedCommandName;
|
||||
}
|
||||
}
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
package org.mifosng.platform.infrastructure.errorhandling;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.Response;
|
||||
import javax.ws.rs.core.Response.Status;
|
||||
import javax.ws.rs.ext.ExceptionMapper;
|
||||
import javax.ws.rs.ext.Provider;
|
||||
|
||||
import org.mifosng.platform.api.data.ApiGlobalErrorResponse;
|
||||
import org.mifosng.platform.api.data.ApiParameterError;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* An {@link ExceptionMapper} to map {@link UnsupportedCommandException} thrown by platform into a HTTP API friendly format.
|
||||
*/
|
||||
@Provider
|
||||
@Component
|
||||
@Scope("singleton")
|
||||
public class UnsupportedCommandExceptionMapper implements ExceptionMapper<UnsupportedCommandException> {
|
||||
|
||||
@Override
|
||||
public Response toResponse(final UnsupportedCommandException exception) {
|
||||
|
||||
List<ApiParameterError> errors = new ArrayList<ApiParameterError>();
|
||||
|
||||
StringBuilder validationErrorCode = new StringBuilder("error.msg.command.unsupported");
|
||||
StringBuilder defaultEnglishMessage = new StringBuilder("The command ").append(exception.getUnsupportedCommandName()).append(" is not supported.");
|
||||
ApiParameterError error = ApiParameterError.parameterError(validationErrorCode.toString(), defaultEnglishMessage.toString(), exception.getUnsupportedCommandName(), exception.getUnsupportedCommandName());
|
||||
|
||||
errors.add(error);
|
||||
|
||||
ApiGlobalErrorResponse invalidParameterError = ApiGlobalErrorResponse.badClientRequest(
|
||||
"validation.msg.validation.errors.exist",
|
||||
"Validation errors exist.", errors);
|
||||
|
||||
return Response.status(Status.BAD_REQUEST).entity(invalidParameterError).type(MediaType.APPLICATION_JSON).build();
|
||||
}
|
||||
}
|
||||
+92
-83
@@ -19,99 +19,108 @@ import org.springframework.data.jpa.domain.AbstractPersistable;
|
||||
@Table(name = "m_portfolio_command_source")
|
||||
public class CommandSource extends AbstractPersistable<Long> {
|
||||
|
||||
@Column(name = "api_operation", length = 20)
|
||||
private String apiOperation;
|
||||
|
||||
@Column(name = "api_resource", length = 20)
|
||||
private String resource;
|
||||
|
||||
@Column(name = "resource_id")
|
||||
private Long resourceId;
|
||||
|
||||
@Column(name = "command_as_json", length = 1000)
|
||||
private String commandAsJson;
|
||||
@Column(name = "api_operation", length = 20)
|
||||
private String apiOperation;
|
||||
|
||||
// should maker and checker be a staff member as opposed to just any application user?
|
||||
@SuppressWarnings("unused")
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "maker_id", nullable = false)
|
||||
private AppUser maker;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@Column(name = "made_on_date", nullable = false)
|
||||
@Column(name = "api_resource", length = 20)
|
||||
private String resource;
|
||||
|
||||
@Column(name = "resource_id")
|
||||
private Long resourceId;
|
||||
|
||||
@Column(name = "command_as_json", length = 1000)
|
||||
private String commandAsJson;
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "maker_id", nullable = false)
|
||||
private AppUser maker;
|
||||
|
||||
@Column(name = "made_on_date", nullable = false)
|
||||
@Temporal(TemporalType.DATE)
|
||||
private Date madeOnDate;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "checker_id", nullable = true)
|
||||
private AppUser checker;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@Column(name = "checked_on_date", nullable = false)
|
||||
private Date madeOnDate;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "checker_id", nullable = true)
|
||||
private AppUser checker;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@Column(name = "checked_on_date", nullable = false)
|
||||
@Temporal(TemporalType.DATE)
|
||||
private Date checkedOnDate;
|
||||
private Date checkedOnDate;
|
||||
|
||||
public static CommandSource createdBy(
|
||||
final String apiOperation,
|
||||
final String resource,
|
||||
final Long resourceId,
|
||||
final AppUser maker,
|
||||
final LocalDate madeOnDate) {
|
||||
return new CommandSource(apiOperation, resource, resourceId, maker, madeOnDate);
|
||||
}
|
||||
public static CommandSource createdBy(final String apiOperation, final String resource, final Long resourceId, final AppUser maker,
|
||||
final LocalDate madeOnDate) {
|
||||
return new CommandSource(apiOperation, resource, resourceId, maker, madeOnDate);
|
||||
}
|
||||
|
||||
protected CommandSource() {
|
||||
//
|
||||
}
|
||||
protected CommandSource() {
|
||||
//
|
||||
}
|
||||
|
||||
private CommandSource(
|
||||
final String apiOperation,
|
||||
final String resource,
|
||||
final Long resourceId,
|
||||
final AppUser maker,
|
||||
final LocalDate madeOnDate) {
|
||||
this.apiOperation = StringUtils.defaultIfEmpty(apiOperation, null);
|
||||
this.resource = StringUtils.defaultIfEmpty(resource, null);
|
||||
this.resourceId = resourceId;
|
||||
this.maker = maker;
|
||||
this.madeOnDate = madeOnDate.toDate();
|
||||
}
|
||||
private CommandSource(final String apiOperation, final String resource, final Long resourceId, final AppUser maker,
|
||||
final LocalDate madeOnDate) {
|
||||
this.apiOperation = StringUtils.defaultIfEmpty(apiOperation, null);
|
||||
this.resource = StringUtils.defaultIfEmpty(resource, null);
|
||||
this.resourceId = resourceId;
|
||||
this.maker = maker;
|
||||
this.madeOnDate = madeOnDate.toDate();
|
||||
}
|
||||
|
||||
public void markAsChecked(final AppUser checker, final LocalDate checkedOnDate) {
|
||||
this.checker = checker;
|
||||
this.checkedOnDate = checkedOnDate.toDate();
|
||||
}
|
||||
|
||||
public void updateResourceId(final Long resourceId) {
|
||||
this.resourceId = resourceId;
|
||||
}
|
||||
|
||||
public void updateJsonTo(final String json) {
|
||||
this.commandAsJson = json;
|
||||
}
|
||||
|
||||
public Long resourceId() {
|
||||
return this.resourceId;
|
||||
}
|
||||
public CommandSource copy() {
|
||||
LocalDate madeOnLocalDate = null;
|
||||
if (this.madeOnDate != null) {
|
||||
madeOnLocalDate = new LocalDate(this.madeOnDate);
|
||||
}
|
||||
return new CommandSource(this.apiOperation, this.resource, this.resourceId, this.maker, madeOnLocalDate);
|
||||
}
|
||||
|
||||
public String json() {
|
||||
return this.commandAsJson;
|
||||
}
|
||||
public void markAsChecked(final AppUser checker, final LocalDate checkedOnDate) {
|
||||
this.checker = checker;
|
||||
this.checkedOnDate = checkedOnDate.toDate();
|
||||
}
|
||||
|
||||
public boolean isClientResource() {
|
||||
return this.resource.equalsIgnoreCase("CLIENTS");
|
||||
}
|
||||
public void updateResourceId(final Long resourceId) {
|
||||
this.resourceId = resourceId;
|
||||
}
|
||||
|
||||
public boolean isCreate() {
|
||||
return this.apiOperation.equalsIgnoreCase("CREATE");
|
||||
}
|
||||
public void updateJsonTo(final String json) {
|
||||
this.commandAsJson = json;
|
||||
}
|
||||
|
||||
public boolean isUpdate() {
|
||||
return this.apiOperation.equalsIgnoreCase("UPDATE") && this.resourceId != null;
|
||||
}
|
||||
public Long resourceId() {
|
||||
return this.resourceId;
|
||||
}
|
||||
|
||||
public boolean isDelete() {
|
||||
return this.apiOperation.equalsIgnoreCase("DELETE") && this.resourceId != null;
|
||||
}
|
||||
public String json() {
|
||||
return this.commandAsJson;
|
||||
}
|
||||
|
||||
public String commandName() {
|
||||
return this.apiOperation + '-' + this.resource;
|
||||
}
|
||||
|
||||
public String resourceName() {
|
||||
return this.resource;
|
||||
}
|
||||
|
||||
public String operation() {
|
||||
return this.apiOperation;
|
||||
}
|
||||
|
||||
public boolean isClientResource() {
|
||||
return this.resource.equalsIgnoreCase("CLIENTS");
|
||||
}
|
||||
|
||||
public boolean isCreate() {
|
||||
return this.apiOperation.equalsIgnoreCase("CREATE");
|
||||
}
|
||||
|
||||
public boolean isUpdate() {
|
||||
return this.apiOperation.equalsIgnoreCase("UPDATE") && this.resourceId != null;
|
||||
}
|
||||
|
||||
public boolean isDelete() {
|
||||
return this.apiOperation.equalsIgnoreCase("DELETE") && this.resourceId != null;
|
||||
}
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
package org.mifosng.platform.makerchecker.service;
|
||||
|
||||
public interface ChangeDetectionService {
|
||||
|
||||
String detectChanges(String operation, String resourceName, Long resourceId, String commandSerializedAsJson);
|
||||
|
||||
}
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
package org.mifosng.platform.makerchecker.service;
|
||||
|
||||
import org.mifosng.platform.api.commands.ClientCommand;
|
||||
import org.mifosng.platform.api.data.ClientData;
|
||||
import org.mifosng.platform.api.infrastructure.PortfolioApiDataConversionService;
|
||||
import org.mifosng.platform.api.infrastructure.PortfolioApiJsonSerializerService;
|
||||
import org.mifosng.platform.client.service.ClientReadPlatformService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class ChangeDetectionServiceJdbc implements ChangeDetectionService {
|
||||
|
||||
private final PortfolioApiDataConversionService apiDataConversionService;
|
||||
private final PortfolioApiJsonSerializerService apiJsonSerializerService;
|
||||
private final ClientReadPlatformService clientReadPlatformService;
|
||||
|
||||
@Autowired
|
||||
public ChangeDetectionServiceJdbc(final PortfolioApiDataConversionService apiDataConversionService,
|
||||
final PortfolioApiJsonSerializerService apiJsonSerializerService, final ClientReadPlatformService clientReadPlatformService) {
|
||||
this.apiDataConversionService = apiDataConversionService;
|
||||
this.apiJsonSerializerService = apiJsonSerializerService;
|
||||
this.clientReadPlatformService = clientReadPlatformService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String detectChanges(final String operation, final String resourceName, final Long resourceId,
|
||||
final String commandSerializedAsJson) {
|
||||
|
||||
String changesOnlyJson = "";
|
||||
|
||||
// FIXME - KW/JW - this change detection code for update of clients
|
||||
// using ClientCommand can re placed when more suitable sql version is
|
||||
// implemented.
|
||||
final ClientData originalClient = this.clientReadPlatformService.retrieveIndividualClient(resourceId);
|
||||
final ClientData changedClient = this.apiDataConversionService.convertInternalJsonFormatToClientDataChange(resourceId,
|
||||
commandSerializedAsJson);
|
||||
|
||||
final String baseJson = this.apiJsonSerializerService.serializeClientDataToJson(originalClient);
|
||||
final String workingJson = this.apiJsonSerializerService.serializeClientDataToJson(changedClient);
|
||||
final ClientCommand changesOnly = this.apiDataConversionService.detectChanges(resourceId, baseJson, workingJson);
|
||||
|
||||
changesOnlyJson = this.apiJsonSerializerService.serializeClientCommandToJson(changesOnly);
|
||||
|
||||
return changesOnlyJson;
|
||||
}
|
||||
|
||||
}
|
||||
+113
@@ -0,0 +1,113 @@
|
||||
package org.mifosng.platform.makerchecker.service;
|
||||
|
||||
import org.joda.time.LocalDate;
|
||||
import org.mifosng.platform.api.commands.ClientCommand;
|
||||
import org.mifosng.platform.api.data.EntityIdentifier;
|
||||
import org.mifosng.platform.api.infrastructure.PortfolioApiDataConversionService;
|
||||
import org.mifosng.platform.api.infrastructure.PortfolioApiJsonSerializerService;
|
||||
import org.mifosng.platform.client.service.ClientWritePlatformService;
|
||||
import org.mifosng.platform.client.service.RollbackTransactionAsCommandIsNotApprovedByCheckerException;
|
||||
import org.mifosng.platform.makerchecker.domain.CommandSource;
|
||||
import org.mifosng.platform.security.PlatformSecurityContext;
|
||||
import org.mifosng.platform.user.domain.AppUser;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class ClientCommandHandler implements CommandSourceHandler {
|
||||
|
||||
private final PlatformSecurityContext context;
|
||||
private final ChangeDetectionService changeDetectionService;
|
||||
private final PortfolioApiDataConversionService apiDataConversionService;
|
||||
private final PortfolioApiJsonSerializerService apiJsonSerializerService;
|
||||
private final ClientWritePlatformService clientWritePlatformService;
|
||||
|
||||
@Autowired
|
||||
public ClientCommandHandler(final PlatformSecurityContext context, final ChangeDetectionService changeDetectionService,
|
||||
final PortfolioApiDataConversionService apiDataConversionService,
|
||||
final PortfolioApiJsonSerializerService apiJsonSerializerService, final ClientWritePlatformService clientWritePlatformService) {
|
||||
this.context = context;
|
||||
this.changeDetectionService = changeDetectionService;
|
||||
this.apiDataConversionService = apiDataConversionService;
|
||||
this.apiJsonSerializerService = apiJsonSerializerService;
|
||||
this.clientWritePlatformService = clientWritePlatformService;
|
||||
}
|
||||
|
||||
public CommandSource handle(final CommandSource commandSource, final String apiRequestBodyInJson) {
|
||||
|
||||
final AppUser maker = context.authenticatedUser();
|
||||
final LocalDate asToday = new LocalDate();
|
||||
|
||||
CommandSource commandSourceResult = commandSource.copy();
|
||||
|
||||
final Long resourceId = commandSource.resourceId();
|
||||
Long newResourceId = null;
|
||||
|
||||
final ClientCommand command = this.apiDataConversionService.convertApiRequestJsonToClientCommand(resourceId, apiRequestBodyInJson);
|
||||
final String commandSerializedAsJson = this.apiJsonSerializerService.serializeClientCommandToJson(command);
|
||||
commandSourceResult.updateJsonTo(commandSerializedAsJson);
|
||||
|
||||
if (commandSource.isCreate()) {
|
||||
try {
|
||||
newResourceId = this.clientWritePlatformService.createClient(command);
|
||||
commandSourceResult.markAsChecked(maker, asToday);
|
||||
commandSourceResult.updateResourceId(newResourceId);
|
||||
} catch (RollbackTransactionAsCommandIsNotApprovedByCheckerException e) {
|
||||
// swallow this rollback transaction by design
|
||||
}
|
||||
} else if (commandSource.isUpdate()) {
|
||||
try {
|
||||
final String jsonOfChangesOnly = this.changeDetectionService.detectChanges(commandSource.operation(),
|
||||
commandSource.resourceName(), commandSource.resourceId(), commandSerializedAsJson);
|
||||
commandSourceResult.updateJsonTo(jsonOfChangesOnly);
|
||||
|
||||
final ClientCommand changesOnly = this.apiDataConversionService.convertInternalJsonFormatToClientCommand(
|
||||
commandSource.resourceId(), jsonOfChangesOnly, false);
|
||||
|
||||
EntityIdentifier result = this.clientWritePlatformService.updateClientDetails(changesOnly);
|
||||
newResourceId = result.getEntityId();
|
||||
|
||||
commandSourceResult.markAsChecked(maker, asToday);
|
||||
} catch (RollbackTransactionAsCommandIsNotApprovedByCheckerException e) {
|
||||
// swallow this rollback transaction by design
|
||||
}
|
||||
} else if (commandSource.isDelete()) {
|
||||
try {
|
||||
EntityIdentifier result = this.clientWritePlatformService.deleteClient(command);
|
||||
newResourceId = result.getEntityId();
|
||||
commandSourceResult.markAsChecked(maker, asToday);
|
||||
} catch (RollbackTransactionAsCommandIsNotApprovedByCheckerException e) {
|
||||
// swallow this rollback transaction by design
|
||||
}
|
||||
}
|
||||
|
||||
return commandSourceResult;
|
||||
}
|
||||
|
||||
public CommandSource handle(final CommandSource commandSourceResult) {
|
||||
|
||||
Long resourceId = null;
|
||||
if (commandSourceResult.isClientResource()) {
|
||||
final ClientCommand command = this.apiDataConversionService.convertInternalJsonFormatToClientCommand(
|
||||
commandSourceResult.resourceId(), commandSourceResult.json(), true);
|
||||
|
||||
if (commandSourceResult.isCreate()) {
|
||||
resourceId = this.clientWritePlatformService.createClient(command);
|
||||
} else if (commandSourceResult.isUpdate()) {
|
||||
|
||||
// TODO - is there a case for doing change detection at this
|
||||
// point also?
|
||||
|
||||
EntityIdentifier result = this.clientWritePlatformService.updateClientDetails(command);
|
||||
resourceId = result.getEntityId();
|
||||
} else if (commandSourceResult.isDelete()) {
|
||||
EntityIdentifier result = this.clientWritePlatformService.deleteClient(command);
|
||||
resourceId = result.getEntityId();
|
||||
}
|
||||
}
|
||||
|
||||
commandSourceResult.updateResourceId(resourceId);
|
||||
|
||||
return commandSourceResult;
|
||||
}
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
package org.mifosng.platform.makerchecker.service;
|
||||
|
||||
public interface CommandSourceHandler {
|
||||
|
||||
}
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
package org.mifosng.platform.makerchecker.service;
|
||||
|
||||
import org.mifosng.platform.infrastructure.errorhandling.UnsupportedCommandException;
|
||||
import org.mifosng.platform.makerchecker.domain.CommandSource;
|
||||
import org.mifosng.platform.security.PlatformSecurityContext;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* A class to delegate handling of commands to appropriate handler.
|
||||
*/
|
||||
@Service
|
||||
public class CommandSourceHandlerDelegator {
|
||||
|
||||
private final PlatformSecurityContext context;
|
||||
private final ClientCommandHandler clientCommandHandler;
|
||||
|
||||
@Autowired
|
||||
public CommandSourceHandlerDelegator(final PlatformSecurityContext context, final ClientCommandHandler clientCommandHandler) {
|
||||
this.context = context;
|
||||
this.clientCommandHandler = clientCommandHandler;
|
||||
}
|
||||
|
||||
public CommandSource handle(final CommandSource commandSource, final String apiRequestBodyInJson) {
|
||||
|
||||
context.authenticatedUser();
|
||||
CommandSource commandSourceResult = null;
|
||||
if (commandSource.isClientResource()) {
|
||||
commandSourceResult = clientCommandHandler.handle(commandSource, apiRequestBodyInJson);
|
||||
} else {
|
||||
throw new UnsupportedCommandException(commandSource.commandName());
|
||||
}
|
||||
|
||||
return commandSourceResult;
|
||||
}
|
||||
|
||||
public CommandSource handleExistingCommand(final CommandSource commandSource) {
|
||||
|
||||
CommandSource commandSourceResult = null;
|
||||
if (commandSource.isClientResource()) {
|
||||
commandSourceResult = clientCommandHandler.handle(commandSource);
|
||||
} else {
|
||||
throw new UnsupportedCommandException(commandSource.commandName());
|
||||
}
|
||||
|
||||
return commandSourceResult;
|
||||
}
|
||||
}
|
||||
+48
-125
@@ -1,14 +1,7 @@
|
||||
package org.mifosng.platform.makerchecker.service;
|
||||
|
||||
import org.joda.time.LocalDate;
|
||||
import org.mifosng.platform.api.commands.ClientCommand;
|
||||
import org.mifosng.platform.api.data.ClientData;
|
||||
import org.mifosng.platform.api.data.EntityIdentifier;
|
||||
import org.mifosng.platform.api.infrastructure.PortfolioApiDataConversionService;
|
||||
import org.mifosng.platform.api.infrastructure.PortfolioApiJsonSerializerService;
|
||||
import org.mifosng.platform.client.service.ClientReadPlatformService;
|
||||
import org.mifosng.platform.client.service.ClientWritePlatformService;
|
||||
import org.mifosng.platform.client.service.RollbackTransactionAsCommandIsNotApprovedByCheckerException;
|
||||
import org.mifosng.platform.makerchecker.domain.CommandSource;
|
||||
import org.mifosng.platform.makerchecker.domain.CommandSourceRepository;
|
||||
import org.mifosng.platform.security.PlatformSecurityContext;
|
||||
@@ -20,128 +13,58 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
@Service
|
||||
public class PortfolioCommandSourceWriteServiceImpl implements PortfolioCommandSourceWritePlatformService {
|
||||
|
||||
private final PlatformSecurityContext context;
|
||||
private final CommandSourceRepository commandSourceRepository;
|
||||
private final PortfolioApiDataConversionService apiDataConversionService;
|
||||
private final PortfolioApiJsonSerializerService apiJsonSerializerService;
|
||||
private final ClientWritePlatformService clientWritePlatformService;
|
||||
private final ClientReadPlatformService clientReadPlatformService;
|
||||
private final PlatformSecurityContext context;
|
||||
private final CommandSourceRepository commandSourceRepository;
|
||||
private final CommandSourceHandlerDelegator commandSourceHandlerDelegator;
|
||||
|
||||
@Autowired
|
||||
public PortfolioCommandSourceWriteServiceImpl(final PlatformSecurityContext context, final CommandSourceRepository makerCheckerRepository,
|
||||
final PortfolioApiDataConversionService apiDataConversionService,
|
||||
final PortfolioApiJsonSerializerService apiJsonSerializerService,
|
||||
final ClientWritePlatformService clientWritePlatformService,
|
||||
final ClientReadPlatformService clientReadPlatformService) {
|
||||
this.context = context;
|
||||
this.commandSourceRepository = makerCheckerRepository;
|
||||
this.apiDataConversionService = apiDataConversionService;
|
||||
this.apiJsonSerializerService = apiJsonSerializerService;
|
||||
this.clientWritePlatformService = clientWritePlatformService;
|
||||
this.clientReadPlatformService = clientReadPlatformService;
|
||||
}
|
||||
@Autowired
|
||||
public PortfolioCommandSourceWriteServiceImpl(final PlatformSecurityContext context,
|
||||
final CommandSourceRepository makerCheckerRepository,
|
||||
final CommandSourceHandlerDelegator commandSourceHandlerDelegator) {
|
||||
this.context = context;
|
||||
this.commandSourceRepository = makerCheckerRepository;
|
||||
this.commandSourceHandlerDelegator = commandSourceHandlerDelegator;
|
||||
}
|
||||
|
||||
// NOT TRANSACTIONAL BY DESIGN FOR NOW
|
||||
@Override
|
||||
public EntityIdentifier logCommandSource(final String apiOperation, final String resource, final Long resourceId, final String jsonRequestBody) {
|
||||
|
||||
final AppUser maker = context.authenticatedUser();
|
||||
|
||||
final LocalDate asToday = new LocalDate();
|
||||
|
||||
final CommandSource commandSource = CommandSource.createdBy(apiOperation, resource, resourceId, maker, asToday);
|
||||
|
||||
Long newResourceId = null;
|
||||
if (commandSource.isClientResource()) {
|
||||
|
||||
// translate incoming api request json into java object catering for local and dateFormat parts of api
|
||||
final ClientCommand command = this.apiDataConversionService.convertApiRequestJsonToClientCommand(resourceId, jsonRequestBody);
|
||||
// produce serialized json of internal java object representation for persistence.
|
||||
final String internalCommandSerializedAsJson = this.apiJsonSerializerService.serializeClientCommandToJson(command);
|
||||
commandSource.updateJsonTo(internalCommandSerializedAsJson);
|
||||
|
||||
if (commandSource.isCreate()) {
|
||||
try {
|
||||
newResourceId = this.clientWritePlatformService.createClient(command);
|
||||
commandSource.markAsChecked(maker, asToday);
|
||||
commandSource.updateResourceId(newResourceId);
|
||||
} catch (RollbackTransactionAsCommandIsNotApprovedByCheckerException e) {
|
||||
// swallow this rollback transaction by design
|
||||
}
|
||||
} else if (commandSource.isUpdate()) {
|
||||
try {
|
||||
// useful to employ change detection on update scenario to only store what details have changed
|
||||
final ClientData originalClient = this.clientReadPlatformService.retrieveIndividualClient(resourceId);
|
||||
final ClientData changedClient = this.apiDataConversionService.convertInternalJsonFormatToClientDataChange(resourceId, internalCommandSerializedAsJson);
|
||||
// NOT TRANSACTIONAL BY DESIGN FOR NOW
|
||||
@Override
|
||||
public EntityIdentifier logCommandSource(final String apiOperation, final String resource, final Long resourceId,
|
||||
final String apiRequestBodyInJson) {
|
||||
|
||||
final String baseJson = this.apiJsonSerializerService.serializeClientDataToJson(originalClient);
|
||||
final String workingJson = this.apiJsonSerializerService.serializeClientDataToJson(changedClient);
|
||||
final ClientCommand changesOnly = this.apiDataConversionService.detectChanges(resourceId, baseJson, workingJson);
|
||||
final AppUser maker = context.authenticatedUser();
|
||||
final LocalDate asToday = new LocalDate();
|
||||
|
||||
final String changesOnlyJson = this.apiJsonSerializerService.serializeClientCommandToJson(changesOnly);
|
||||
commandSource.updateJsonTo(changesOnlyJson);
|
||||
|
||||
EntityIdentifier result = this.clientWritePlatformService.updateClientDetails(changesOnly);
|
||||
newResourceId = result.getEntityId();
|
||||
|
||||
commandSource.markAsChecked(maker, asToday);
|
||||
} catch (RollbackTransactionAsCommandIsNotApprovedByCheckerException e) {
|
||||
// swallow this rollback transaction by design
|
||||
}
|
||||
} else if (commandSource.isDelete()) {
|
||||
try {
|
||||
EntityIdentifier result = this.clientWritePlatformService.deleteClient(command);
|
||||
newResourceId = result.getEntityId();
|
||||
commandSource.markAsChecked(maker, asToday);
|
||||
} catch (RollbackTransactionAsCommandIsNotApprovedByCheckerException e) {
|
||||
// swallow this rollback transaction by design
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
commandSourceRepository.save(commandSource);
|
||||
|
||||
return EntityIdentifier.makerChecker(newResourceId, commandSource.getId());
|
||||
}
|
||||
final CommandSource commandSourceInput = CommandSource.createdBy(apiOperation, resource, resourceId, maker, asToday);
|
||||
final CommandSource commandSourceResult = this.commandSourceHandlerDelegator.handle(commandSourceInput, apiRequestBodyInJson);
|
||||
commandSourceRepository.save(commandSourceResult);
|
||||
|
||||
@Transactional
|
||||
@Override
|
||||
public EntityIdentifier approveEntry(final Long id) {
|
||||
|
||||
final AppUser checker = context.authenticatedUser();
|
||||
|
||||
final CommandSource entity = this.commandSourceRepository.findOne(id);
|
||||
entity.markAsChecked(checker, new LocalDate());
|
||||
|
||||
Long resourceId = null;
|
||||
if (entity.isClientResource()) {
|
||||
final ClientCommand command = this.apiDataConversionService.convertInternalJsonFormatToClientCommand(entity.resourceId(), entity.json(), true);
|
||||
if (entity.isCreate()) {
|
||||
resourceId = this.clientWritePlatformService.createClient(command);
|
||||
} else if (entity.isUpdate()) {
|
||||
EntityIdentifier result = this.clientWritePlatformService.updateClientDetails(command);
|
||||
resourceId = result.getEntityId();
|
||||
} else if (entity.isDelete()) {
|
||||
EntityIdentifier result = this.clientWritePlatformService.deleteClient(command);
|
||||
resourceId = result.getEntityId();
|
||||
}
|
||||
}
|
||||
|
||||
entity.updateResourceId(resourceId);
|
||||
|
||||
commandSourceRepository.save(entity);
|
||||
|
||||
return EntityIdentifier.makerChecker(resourceId, entity.getId());
|
||||
}
|
||||
return EntityIdentifier.makerChecker(commandSourceResult.resourceId(), commandSourceResult.getId());
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@Override
|
||||
public Long deleteEntry(final Long makerCheckerId) {
|
||||
|
||||
context.authenticatedUser();
|
||||
|
||||
this.commandSourceRepository.delete(makerCheckerId);
|
||||
|
||||
return makerCheckerId;
|
||||
}
|
||||
@Transactional
|
||||
@Override
|
||||
public EntityIdentifier approveEntry(final Long id) {
|
||||
|
||||
final AppUser checker = context.authenticatedUser();
|
||||
|
||||
final CommandSource commandSourceInput = this.commandSourceRepository.findOne(id);
|
||||
commandSourceInput.markAsChecked(checker, new LocalDate());
|
||||
|
||||
final CommandSource commandSourceResult = this.commandSourceHandlerDelegator.handleExistingCommand(commandSourceInput);
|
||||
|
||||
commandSourceRepository.save(commandSourceResult);
|
||||
|
||||
return EntityIdentifier.makerChecker(commandSourceResult.resourceId(), commandSourceResult.getId());
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@Override
|
||||
public Long deleteEntry(final Long makerCheckerId) {
|
||||
|
||||
context.authenticatedUser();
|
||||
|
||||
this.commandSourceRepository.delete(makerCheckerId);
|
||||
|
||||
return makerCheckerId;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user