MIFOSX-97: global configuration to enable disable maker checker support on tasks. hardcoded to disabled by default for now.

This commit is contained in:
Keith Woodlock
2012-11-30 13:12:57 +00:00
parent d2c751f2eb
commit f58f211664
52 changed files with 929 additions and 718 deletions
@@ -23,6 +23,7 @@ import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo; import javax.ws.rs.core.UriInfo;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.mifosng.platform.api.commands.ClientCommand;
import org.mifosng.platform.api.commands.NoteCommand; import org.mifosng.platform.api.commands.NoteCommand;
import org.mifosng.platform.api.data.ClientAccountSummaryCollectionData; import org.mifosng.platform.api.data.ClientAccountSummaryCollectionData;
import org.mifosng.platform.api.data.ClientData; import org.mifosng.platform.api.data.ClientData;
@@ -31,6 +32,7 @@ import org.mifosng.platform.api.data.NoteData;
import org.mifosng.platform.api.infrastructure.ApiConstants; import org.mifosng.platform.api.infrastructure.ApiConstants;
import org.mifosng.platform.api.infrastructure.PortfolioApiDataConversionService; import org.mifosng.platform.api.infrastructure.PortfolioApiDataConversionService;
import org.mifosng.platform.api.infrastructure.PortfolioApiJsonSerializerService; import org.mifosng.platform.api.infrastructure.PortfolioApiJsonSerializerService;
import org.mifosng.platform.api.infrastructure.PortfolioCommandSerializerService;
import org.mifosng.platform.client.service.ClientReadPlatformService; import org.mifosng.platform.client.service.ClientReadPlatformService;
import org.mifosng.platform.client.service.ClientWritePlatformService; import org.mifosng.platform.client.service.ClientWritePlatformService;
import org.mifosng.platform.exceptions.ImageNotFoundException; import org.mifosng.platform.exceptions.ImageNotFoundException;
@@ -61,33 +63,38 @@ public class ClientsApiResource {
private final static Logger logger = LoggerFactory.getLogger(ClientsApiResource.class); private final static Logger logger = LoggerFactory.getLogger(ClientsApiResource.class);
@Autowired private final PlatformSecurityContext context;
private ClientReadPlatformService clientReadPlatformService; private final ClientReadPlatformService clientReadPlatformService;
private final ClientWritePlatformService clientWritePlatformService;
private final OfficeReadPlatformService officeReadPlatformService;
private final PortfolioApiDataConversionService apiDataConversionService;
private final PortfolioCommandSerializerService commandSerializerService;
private final PortfolioApiJsonSerializerService apiJsonSerializerService;
private final PortfolioCommandsReadPlatformService commandSourceReadPlatformService;
private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService;
@Autowired @Autowired
private ClientWritePlatformService clientWritePlatformService; public ClientsApiResource(final PlatformSecurityContext context, final ClientReadPlatformService readPlatformService,
final ClientWritePlatformService clientWritePlatformService, final OfficeReadPlatformService officeReadPlatformService,
@Autowired final PortfolioApiDataConversionService apiDataConversionService,
private PortfolioCommandsReadPlatformService commandSourceReadPlatformService; final PortfolioCommandSerializerService commandSerializerService,
final PortfolioApiJsonSerializerService apiJsonSerializerService,
@Autowired final PortfolioCommandsReadPlatformService commandsReadPlatformService,
private PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService; final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService) {
this.context = context;
@Autowired this.clientReadPlatformService = readPlatformService;
private OfficeReadPlatformService officeReadPlatformService; this.clientWritePlatformService = clientWritePlatformService;
this.officeReadPlatformService = officeReadPlatformService;
@Autowired this.apiDataConversionService = apiDataConversionService;
private PortfolioApiDataConversionService apiDataConversionService; this.commandSerializerService = commandSerializerService;
this.apiJsonSerializerService = apiJsonSerializerService;
@Autowired this.commandSourceReadPlatformService = commandsReadPlatformService;
private PortfolioApiJsonSerializerService apiJsonSerializerService; this.commandsSourceWritePlatformService = commandsSourceWritePlatformService;
}
@Autowired
private PlatformSecurityContext context;
@GET @GET
@Consumes({MediaType.APPLICATION_JSON}) @Consumes({ MediaType.APPLICATION_JSON })
@Produces({MediaType.APPLICATION_JSON}) @Produces({ MediaType.APPLICATION_JSON })
public String retrieveAllIndividualClients(@Context final UriInfo uriInfo, @QueryParam("sqlSearch") final String sqlSearch, public String retrieveAllIndividualClients(@Context final UriInfo uriInfo, @QueryParam("sqlSearch") final String sqlSearch,
@QueryParam("officeId") final Integer officeId, @QueryParam("externalId") final String externalId, @QueryParam("officeId") final Integer officeId, @QueryParam("externalId") final String externalId,
@QueryParam("displayName") final String displayName, @QueryParam("firstName") final String firstName, @QueryParam("displayName") final String displayName, @QueryParam("firstName") final String firstName,
@@ -150,8 +157,8 @@ public class ClientsApiResource {
@GET @GET
@Path("{clientId}") @Path("{clientId}")
@Consumes({MediaType.APPLICATION_JSON}) @Consumes({ MediaType.APPLICATION_JSON })
@Produces({MediaType.APPLICATION_JSON}) @Produces({ MediaType.APPLICATION_JSON })
public String retrieveClient(@PathParam("clientId") final Long clientId, @Context final UriInfo uriInfo) { public String retrieveClient(@PathParam("clientId") final Long clientId, @Context final UriInfo uriInfo) {
context.authenticatedUser().validateHasReadPermission("CLIENT"); context.authenticatedUser().validateHasReadPermission("CLIENT");
@@ -170,14 +177,16 @@ public class ClientsApiResource {
clientData = handleRequestToIntegrateProposedChangesFromCommand(clientId, commandId, clientData); clientData = handleRequestToIntegrateProposedChangesFromCommand(clientId, commandId, clientData);
} }
// pick up possibility of changes by default - might push down a layer into the retrieve client method // pick up possibility of changes by default - might push down a layer
// into the retrieve client method
final Collection<ClientData> dataChanges = retrieveAllUnprocessedDataChanges(clientId); final Collection<ClientData> dataChanges = retrieveAllUnprocessedDataChanges(clientId);
clientData = ClientData.integrateChanges(clientData, clientData.currentChange(), dataChanges); clientData = ClientData.integrateChanges(clientData, clientData.currentChange(), dataChanges);
return this.apiJsonSerializerService.serializeClientDataToJson(prettyPrint, responseParameters, clientData); return this.apiJsonSerializerService.serializeClientDataToJson(prettyPrint, responseParameters, clientData);
} }
private ClientData handleRequestToIntegrateProposedChangesFromCommand(final Long clientId, final Long commandId, final ClientData clientData) { private ClientData handleRequestToIntegrateProposedChangesFromCommand(final Long clientId, final Long commandId,
final ClientData clientData) {
final CommandSourceData entry = this.commandSourceReadPlatformService.retrieveById(commandId); final CommandSourceData entry = this.commandSourceReadPlatformService.retrieveById(commandId);
final ClientData currentChange = this.apiDataConversionService.convertInternalJsonFormatToClientDataChange(clientId, entry.json()); final ClientData currentChange = this.apiDataConversionService.convertInternalJsonFormatToClientDataChange(clientId, entry.json());
@@ -205,8 +214,8 @@ public class ClientsApiResource {
@GET @GET
@Path("template") @Path("template")
@Consumes({MediaType.APPLICATION_JSON}) @Consumes({ MediaType.APPLICATION_JSON })
@Produces({MediaType.APPLICATION_JSON}) @Produces({ MediaType.APPLICATION_JSON })
public String newClientDetails(@Context final UriInfo uriInfo) { public String newClientDetails(@Context final UriInfo uriInfo) {
context.authenticatedUser().validateHasReadPermission("CLIENT"); context.authenticatedUser().validateHasReadPermission("CLIENT");
@@ -224,43 +233,49 @@ public class ClientsApiResource {
} }
@POST @POST
@Consumes({MediaType.APPLICATION_JSON}) @Consumes({ MediaType.APPLICATION_JSON })
@Produces({MediaType.APPLICATION_JSON}) @Produces({ MediaType.APPLICATION_JSON })
public String createClient(final String jsonRequestBody) { public String createClient(final String apiRequestBodyAsJson) {
final List<String> allowedPermissions = Arrays.asList("ALL_FUNCTIONS", "PORTFOLIO_MANAGEMENT_SUPER_USER", "CREATE_CLIENT"); final List<String> allowedPermissions = Arrays.asList("ALL_FUNCTIONS", "PORTFOLIO_MANAGEMENT_SUPER_USER", "CREATE_CLIENT");
context.authenticatedUser().validateHasPermissionTo("CREATE_CLIENT", allowedPermissions); context.authenticatedUser().validateHasPermissionTo("CREATE_CLIENT", allowedPermissions);
final EntityIdentifier result = this.commandsSourceWritePlatformService final ClientCommand command = this.apiDataConversionService.convertApiRequestJsonToClientCommand(null, apiRequestBodyAsJson);
.logCommandSource("CREATE", "clients", null, jsonRequestBody); final String commandSerializedAsJson = this.commandSerializerService.serializeCommandToJson(command);
final EntityIdentifier result = this.commandsSourceWritePlatformService.logCommandSource("CREATE", "clients", null,
commandSerializedAsJson);
return this.apiJsonSerializerService.serializeEntityIdentifier(result); return this.apiJsonSerializerService.serializeEntityIdentifier(result);
} }
@PUT @PUT
@Path("{clientId}") @Path("{clientId}")
@Consumes({MediaType.APPLICATION_JSON}) @Consumes({ MediaType.APPLICATION_JSON })
@Produces({MediaType.APPLICATION_JSON}) @Produces({ MediaType.APPLICATION_JSON })
public String updateClient(@PathParam("clientId") final Long clientId, final String jsonRequestBody) { public String updateClient(@PathParam("clientId") final Long clientId, final String apiRequestBodyAsJson) {
final List<String> allowedPermissions = Arrays.asList("ALL_FUNCTIONS", "PORTFOLIO_MANAGEMENT_SUPER_USER", "UPDATE_CLIENT"); final List<String> allowedPermissions = Arrays.asList("ALL_FUNCTIONS", "PORTFOLIO_MANAGEMENT_SUPER_USER", "UPDATE_CLIENT");
context.authenticatedUser().validateHasPermissionTo("UPDATE_CLIENT", allowedPermissions); context.authenticatedUser().validateHasPermissionTo("UPDATE_CLIENT", allowedPermissions);
final ClientCommand command = this.apiDataConversionService.convertApiRequestJsonToClientCommand(clientId, apiRequestBodyAsJson);
final String commandSerializedAsJson = this.commandSerializerService.serializeCommandToJson(command);
final EntityIdentifier result = this.commandsSourceWritePlatformService.logCommandSource("UPDATE", "clients", clientId, final EntityIdentifier result = this.commandsSourceWritePlatformService.logCommandSource("UPDATE", "clients", clientId,
jsonRequestBody); commandSerializedAsJson);
return this.apiJsonSerializerService.serializeEntityIdentifier(result); return this.apiJsonSerializerService.serializeEntityIdentifier(result);
} }
@DELETE @DELETE
@Path("{clientId}") @Path("{clientId}")
@Consumes({MediaType.APPLICATION_JSON}) @Consumes({ MediaType.APPLICATION_JSON })
@Produces({MediaType.APPLICATION_JSON}) @Produces({ MediaType.APPLICATION_JSON })
public String deleteClient(@PathParam("clientId") final Long clientId) { public String deleteClient(@PathParam("clientId") final Long clientId) {
final List<String> allowedPermissions = Arrays.asList("ALL_FUNCTIONS", "PORTFOLIO_MANAGEMENT_SUPER_USER", "DELETE_CLIENT"); final List<String> allowedPermissions = Arrays.asList("ALL_FUNCTIONS", "PORTFOLIO_MANAGEMENT_SUPER_USER", "DELETE_CLIENT");
context.authenticatedUser().validateHasPermissionTo("DELETE_CLIENT", allowedPermissions); context.authenticatedUser().validateHasPermissionTo("DELETE_CLIENT", allowedPermissions);
final EntityIdentifier result = this.commandsSourceWritePlatformService.logCommandSource("DELETE", "clients", clientId, "{}"); final EntityIdentifier result = this.commandsSourceWritePlatformService.logCommandSource("DELETE", "clients", clientId, "{}");
return this.apiJsonSerializerService.serializeEntityIdentifier(result); return this.apiJsonSerializerService.serializeEntityIdentifier(result);
@@ -268,8 +283,8 @@ public class ClientsApiResource {
@GET @GET
@Path("{clientId}/loans") @Path("{clientId}/loans")
@Consumes({MediaType.APPLICATION_JSON}) @Consumes({ MediaType.APPLICATION_JSON })
@Produces({MediaType.APPLICATION_JSON}) @Produces({ MediaType.APPLICATION_JSON })
public String retrieveClientAccount(@PathParam("clientId") final Long clientId, @Context final UriInfo uriInfo) { public String retrieveClientAccount(@PathParam("clientId") final Long clientId, @Context final UriInfo uriInfo) {
context.authenticatedUser().validateHasReadPermission("CLIENT"); context.authenticatedUser().validateHasReadPermission("CLIENT");
@@ -285,8 +300,8 @@ public class ClientsApiResource {
@GET @GET
@Path("{clientId}/notes") @Path("{clientId}/notes")
@Consumes({MediaType.APPLICATION_JSON}) @Consumes({ MediaType.APPLICATION_JSON })
@Produces({MediaType.APPLICATION_JSON}) @Produces({ MediaType.APPLICATION_JSON })
public String retrieveAllClientNotes(@PathParam("clientId") final Long clientId, @Context final UriInfo uriInfo) { public String retrieveAllClientNotes(@PathParam("clientId") final Long clientId, @Context final UriInfo uriInfo) {
context.authenticatedUser().validateHasReadPermission("CLIENTNOTE"); context.authenticatedUser().validateHasReadPermission("CLIENTNOTE");
@@ -301,8 +316,8 @@ public class ClientsApiResource {
@POST @POST
@Path("{clientId}/notes") @Path("{clientId}/notes")
@Consumes({MediaType.APPLICATION_JSON}) @Consumes({ MediaType.APPLICATION_JSON })
@Produces({MediaType.APPLICATION_JSON}) @Produces({ MediaType.APPLICATION_JSON })
public Response addNewClientNote(@PathParam("clientId") final Long clientId, final String jsonRequestBody) { public Response addNewClientNote(@PathParam("clientId") final Long clientId, final String jsonRequestBody) {
final NoteCommand command = this.apiDataConversionService.convertJsonToNoteCommand(null, clientId, jsonRequestBody); final NoteCommand command = this.apiDataConversionService.convertJsonToNoteCommand(null, clientId, jsonRequestBody);
@@ -314,8 +329,8 @@ public class ClientsApiResource {
@GET @GET
@Path("{clientId}/notes/{noteId}") @Path("{clientId}/notes/{noteId}")
@Consumes({MediaType.APPLICATION_JSON}) @Consumes({ MediaType.APPLICATION_JSON })
@Produces({MediaType.APPLICATION_JSON}) @Produces({ MediaType.APPLICATION_JSON })
public String retrieveClientNote(@PathParam("clientId") final Long clientId, @PathParam("noteId") final Long noteId, public String retrieveClientNote(@PathParam("clientId") final Long clientId, @PathParam("noteId") final Long noteId,
@Context final UriInfo uriInfo) { @Context final UriInfo uriInfo) {
@@ -331,8 +346,8 @@ public class ClientsApiResource {
@PUT @PUT
@Path("{clientId}/notes/{noteId}") @Path("{clientId}/notes/{noteId}")
@Consumes({MediaType.APPLICATION_JSON}) @Consumes({ MediaType.APPLICATION_JSON })
@Produces({MediaType.APPLICATION_JSON}) @Produces({ MediaType.APPLICATION_JSON })
public Response updateClientNote(@PathParam("clientId") final Long clientId, @PathParam("noteId") final Long noteId, public Response updateClientNote(@PathParam("clientId") final Long clientId, @PathParam("noteId") final Long noteId,
final String jsonRequestBody) { final String jsonRequestBody) {
@@ -348,8 +363,8 @@ public class ClientsApiResource {
*/ */
@POST @POST
@Path("{clientId}/image") @Path("{clientId}/image")
@Consumes({MediaType.MULTIPART_FORM_DATA}) @Consumes({ MediaType.MULTIPART_FORM_DATA })
@Produces({MediaType.APPLICATION_JSON}) @Produces({ MediaType.APPLICATION_JSON })
public Response addNewClientImage(@PathParam("clientId") final Long clientId, @HeaderParam("Content-Length") Long fileSize, public Response addNewClientImage(@PathParam("clientId") final Long clientId, @HeaderParam("Content-Length") Long fileSize,
@FormDataParam("file") InputStream inputStream, @FormDataParam("file") FormDataContentDisposition fileDetails, @FormDataParam("file") InputStream inputStream, @FormDataParam("file") FormDataContentDisposition fileDetails,
@FormDataParam("file") FormDataBodyPart bodyPart) { @FormDataParam("file") FormDataBodyPart bodyPart) {
@@ -361,10 +376,10 @@ public class ClientsApiResource {
FileUtils.validateImageMimeType(bodyPart.getMediaType().toString()); FileUtils.validateImageMimeType(bodyPart.getMediaType().toString());
FileUtils.validateFileSizeWithinPermissibleRange(fileSize, fileDetails.getFileName(), ApiConstants.MAX_FILE_UPLOAD_SIZE_IN_MB); FileUtils.validateFileSizeWithinPermissibleRange(fileSize, fileDetails.getFileName(), ApiConstants.MAX_FILE_UPLOAD_SIZE_IN_MB);
// logger.debug(bodyPart.getMediaType().toString()); // logger.debug(bodyPart.getMediaType().toString());
final EntityIdentifier entityIdentifier = this.clientWritePlatformService.saveOrUpdateClientImage(clientId, fileDetails.getFileName(), final EntityIdentifier entityIdentifier = this.clientWritePlatformService.saveOrUpdateClientImage(clientId,
inputStream); fileDetails.getFileName(), inputStream);
return Response.ok().entity(entityIdentifier).build(); return Response.ok().entity(entityIdentifier).build();
} }
@@ -374,8 +389,8 @@ public class ClientsApiResource {
*/ */
@POST @POST
@Path("{clientId}/image") @Path("{clientId}/image")
@Consumes({MediaType.APPLICATION_JSON}) @Consumes({ MediaType.APPLICATION_JSON })
@Produces({MediaType.APPLICATION_JSON}) @Produces({ MediaType.APPLICATION_JSON })
public Response addNewClientImage(@PathParam("clientId") final Long clientId, final String jsonRequestBody) { public Response addNewClientImage(@PathParam("clientId") final Long clientId, final String jsonRequestBody) {
final Base64EncodedImage base64EncodedImage = FileUtils.extractImageFromDataURL(jsonRequestBody); final Base64EncodedImage base64EncodedImage = FileUtils.extractImageFromDataURL(jsonRequestBody);
@@ -390,8 +405,8 @@ public class ClientsApiResource {
*/ */
@GET @GET
@Path("{clientId}/image") @Path("{clientId}/image")
@Consumes({MediaType.APPLICATION_JSON}) @Consumes({ MediaType.APPLICATION_JSON })
@Produces({MediaType.APPLICATION_JSON}) @Produces({ MediaType.APPLICATION_JSON })
public Response retrieveClientImage(@PathParam("clientId") final Long clientId) { public Response retrieveClientImage(@PathParam("clientId") final Long clientId) {
context.authenticatedUser().validateHasReadPermission("CLIENTIMAGE"); context.authenticatedUser().validateHasReadPermission("CLIENTIMAGE");
@@ -408,8 +423,8 @@ public class ClientsApiResource {
*/ */
@PUT @PUT
@Path("{clientId}/image") @Path("{clientId}/image")
@Consumes({MediaType.MULTIPART_FORM_DATA}) @Consumes({ MediaType.MULTIPART_FORM_DATA })
@Produces({MediaType.APPLICATION_JSON}) @Produces({ MediaType.APPLICATION_JSON })
public Response updateClientImage(@PathParam("clientId") final Long clientId, @HeaderParam("Content-Length") Long fileSize, public Response updateClientImage(@PathParam("clientId") final Long clientId, @HeaderParam("Content-Length") Long fileSize,
@FormDataParam("file") InputStream inputStream, @FormDataParam("file") FormDataContentDisposition fileDetails, @FormDataParam("file") InputStream inputStream, @FormDataParam("file") FormDataContentDisposition fileDetails,
@FormDataParam("file") FormDataBodyPart bodyPart) { @FormDataParam("file") FormDataBodyPart bodyPart) {
@@ -418,8 +433,8 @@ public class ClientsApiResource {
@DELETE @DELETE
@Path("{clientId}/image") @Path("{clientId}/image")
@Consumes({MediaType.APPLICATION_JSON}) @Consumes({ MediaType.APPLICATION_JSON })
@Produces({MediaType.APPLICATION_JSON}) @Produces({ MediaType.APPLICATION_JSON })
public Response deleteClientImage(@PathParam("clientId") final Long clientId) { public Response deleteClientImage(@PathParam("clientId") final Long clientId) {
this.clientWritePlatformService.deleteClientImage(clientId); this.clientWritePlatformService.deleteClientImage(clientId);
return Response.ok(new EntityIdentifier(clientId)).build(); return Response.ok(new EntityIdentifier(clientId)).build();
@@ -433,8 +448,8 @@ public class ClientsApiResource {
*/ */
@PUT @PUT
@Path("{clientId}/image") @Path("{clientId}/image")
@Consumes({MediaType.APPLICATION_JSON}) @Consumes({ MediaType.APPLICATION_JSON })
@Produces({MediaType.APPLICATION_JSON}) @Produces({ MediaType.APPLICATION_JSON })
public Response updateClientImage(@PathParam("clientId") final Long clientId, final String jsonRequestBody) { public Response updateClientImage(@PathParam("clientId") final Long clientId, final String jsonRequestBody) {
return addNewClientImage(clientId, jsonRequestBody); return addNewClientImage(clientId, jsonRequestBody);
} }
@@ -5,7 +5,6 @@ import java.util.Collection;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
import org.mifosng.platform.api.commands.ClientCommand;
import org.mifosng.platform.api.data.ClientAccountSummaryCollectionData; import org.mifosng.platform.api.data.ClientAccountSummaryCollectionData;
import org.mifosng.platform.api.data.ClientData; import org.mifosng.platform.api.data.ClientData;
import org.mifosng.platform.api.data.ClientIdentifierData; import org.mifosng.platform.api.data.ClientIdentifierData;
@@ -358,13 +357,6 @@ public class GoogleGsonPortfolioApiJsonSerializerService implements PortfolioApi
return helper.serializedJsonFrom(gsonDeserializer, account); return helper.serializedJsonFrom(gsonDeserializer, account);
} }
@Override
public String serializeClientCommandToJson(final ClientCommand command) {
final Gson gsonDeserializer = helper.createGsonBuilderWithParameterExclusionSerializationStrategy(new HashSet<String>(), false,
new HashSet<String>());
return helper.serializedJsonFrom(gsonDeserializer, command);
}
@Override @Override
public String serializeClientDataToJson(final ClientData client) { public String serializeClientDataToJson(final ClientData client) {
return serializeClientDataToJson(false, new HashSet<String>(), client); return serializeClientDataToJson(false, new HashSet<String>(), client);
@@ -30,12 +30,12 @@ import org.mifosplatform.infrastructure.user.command.PermissionsCommand;
import org.mifosplatform.infrastructure.user.command.RoleCommand; import org.mifosplatform.infrastructure.user.command.RoleCommand;
import org.mifosplatform.infrastructure.user.command.RolePermissionCommand; import org.mifosplatform.infrastructure.user.command.RolePermissionCommand;
import org.mifosplatform.infrastructure.user.command.UserCommand; import org.mifosplatform.infrastructure.user.command.UserCommand;
import org.mifosplatform.portfolio.charge.command.ChargeCommand; import org.mifosplatform.portfolio.charge.command.ChargeDefinitionCommand;
import org.mifosplatform.portfolio.fund.command.FundCommand; import org.mifosplatform.portfolio.fund.command.FundCommand;
public interface PortfolioApiDataConversionService { public interface PortfolioApiDataConversionService {
ChargeCommand convertJsonToChargeCommand(Long resourceIdentifier, String json); ChargeDefinitionCommand convertApiRequestJsonToChargeDefinitionCommand(Long resourceIdentifier, String json);
FundCommand convertApiRequestJsonToFundCommand(Long resourceIdentifier, String json); FundCommand convertApiRequestJsonToFundCommand(Long resourceIdentifier, String json);
@@ -59,8 +59,6 @@ public interface PortfolioApiDataConversionService {
ClientCommand convertApiRequestJsonToClientCommand(Long resourceIdentifier, String json); ClientCommand convertApiRequestJsonToClientCommand(Long resourceIdentifier, String json);
ClientCommand convertInternalJsonFormatToClientCommand(Long resourceIdentifier, String json, boolean checkerApproved);
ClientData convertInternalJsonFormatToClientDataChange(Long clientId, String json); ClientData convertInternalJsonFormatToClientDataChange(Long clientId, String json);
ClientCommand detectChanges(Long resourceId, String baseJson, String workingJson); ClientCommand detectChanges(Long resourceId, String baseJson, String workingJson);
@@ -52,7 +52,7 @@ import org.mifosplatform.infrastructure.user.command.PermissionsCommand;
import org.mifosplatform.infrastructure.user.command.RoleCommand; import org.mifosplatform.infrastructure.user.command.RoleCommand;
import org.mifosplatform.infrastructure.user.command.RolePermissionCommand; import org.mifosplatform.infrastructure.user.command.RolePermissionCommand;
import org.mifosplatform.infrastructure.user.command.UserCommand; import org.mifosplatform.infrastructure.user.command.UserCommand;
import org.mifosplatform.portfolio.charge.command.ChargeCommand; import org.mifosplatform.portfolio.charge.command.ChargeDefinitionCommand;
import org.mifosplatform.portfolio.fund.command.FundCommand; import org.mifosplatform.portfolio.fund.command.FundCommand;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.number.NumberFormatter; import org.springframework.format.number.NumberFormatter;
@@ -92,7 +92,7 @@ public class PortfolioApiDataConversionServiceImpl implements PortfolioApiDataCo
} }
@Override @Override
public ChargeCommand convertJsonToChargeCommand(final Long resourceIdentifier, final String json) { public ChargeDefinitionCommand convertApiRequestJsonToChargeDefinitionCommand(final Long resourceIdentifier, final String json) {
if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); } if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); }
final Type typeOfMap = new TypeToken<Map<String, String>>() {}.getType(); final Type typeOfMap = new TypeToken<Map<String, String>>() {}.getType();
@@ -103,21 +103,25 @@ public class PortfolioApiDataConversionServiceImpl implements PortfolioApiDataCo
"active")); "active"));
checkForUnsupportedParameters(requestMap, supportedParams); checkForUnsupportedParameters(requestMap, supportedParams);
final JsonParserHelper helper = new JsonParserHelper();
JsonParser parser = new JsonParser();
final JsonElement element = parser.parse(json);
Set<String> modifiedParameters = new HashSet<String>(); final Set<String> parametersPassedInRequest = new HashSet<String>();
final String name = extractStringParameter("name", requestMap, modifiedParameters); final String name = helper.extractStringNamed("name", element, parametersPassedInRequest);
final BigDecimal amount = extractBigDecimalParameter("amount", requestMap, modifiedParameters); final String currencyCode = helper.extractStringNamed("currencyCode", element, parametersPassedInRequest);
final String currencyCode = extractStringParameter("currencyCode", requestMap, modifiedParameters); final BigDecimal amount = helper.extractBigDecimalWithLocaleNamed("amount", element.getAsJsonObject(), parametersPassedInRequest);
final Integer chargeTimeType = extractIntegerParameter("chargeTimeType", requestMap, modifiedParameters); final Integer chargeTimeType = helper.extractIntegerWithLocaleNamed("chargeTimeType", element, parametersPassedInRequest);
final Integer chargeAppliesTo = extractIntegerParameter("chargeAppliesTo", requestMap, modifiedParameters); final Integer chargeAppliesTo = helper.extractIntegerWithLocaleNamed("chargeAppliesTo", element, parametersPassedInRequest);
final Integer chargeCalculationType = extractIntegerParameter("chargeCalculationType", requestMap, modifiedParameters); final Integer chargeCalculationType = helper.extractIntegerWithLocaleNamed("chargeCalculationType", element, parametersPassedInRequest);
final boolean penalty = extractBooleanParameter("penalty", requestMap, modifiedParameters); final Boolean penalty = helper.extractBooleanNamed("penalty", element, parametersPassedInRequest);
final boolean active = extractBooleanParameter("active", requestMap, modifiedParameters); final Boolean active = helper.extractBooleanNamed("active", element, parametersPassedInRequest);
return new ChargeCommand(modifiedParameters, resourceIdentifier, name, amount, currencyCode, chargeTimeType, chargeAppliesTo, return new ChargeDefinitionCommand(parametersPassedInRequest, false, resourceIdentifier, name, amount, currencyCode, chargeTimeType, chargeAppliesTo,
chargeCalculationType, penalty, active); chargeCalculationType, penalty, active);
} }
@@ -466,39 +470,10 @@ public class PortfolioApiDataConversionServiceImpl implements PortfolioApiDataCo
officeId, joiningDate, false); officeId, joiningDate, false);
} }
@Override
public ClientCommand convertInternalJsonFormatToClientCommand(final Long resourceIdentifier, final String json,
final boolean checkerApproved) {
if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); }
final Type typeOfMap = new TypeToken<Map<String, Object>>() {}.getType();
final Map<String, Object> requestMap = gsonConverter.fromJson(json, typeOfMap);
final Set<String> supportedParams = new HashSet<String>(Arrays.asList("id", "externalId", "firstname", "lastname",
"clientOrBusinessName", "officeId", "joiningDate"));
checkForUnsupportedParameters(requestMap, supportedParams);
final JsonParser parser = new JsonParser();
final JsonElement element = parser.parse(json);
final JsonParserHelper helper = new JsonParserHelper();
final Set<String> parametersPassedInRequest = new HashSet<String>();
final Long officeId = helper.extractLongNamed("officeId", element, parametersPassedInRequest);
final String externalId = helper.extractStringNamed("externalId", element, parametersPassedInRequest);
final String firstname = helper.extractStringNamed("firstname", element, parametersPassedInRequest);
final String lastname = helper.extractStringNamed("lastname", element, parametersPassedInRequest);
final String clientOrBusinessName = helper.extractStringNamed("clientOrBusinessName", element, parametersPassedInRequest);
final LocalDate joiningDate = helper.extractLocalDateAsArrayNamed("joiningDate", element, parametersPassedInRequest);
return new ClientCommand(parametersPassedInRequest, resourceIdentifier, externalId, firstname, lastname, clientOrBusinessName,
officeId, joiningDate, checkerApproved);
}
@Override @Override
public ClientData convertInternalJsonFormatToClientDataChange(final Long resourceIdentifier, final String json) { public ClientData convertInternalJsonFormatToClientDataChange(final Long resourceIdentifier, final String json) {
final ClientCommand command = convertInternalJsonFormatToClientCommand(resourceIdentifier, json, false); final ClientCommand command = this.portfolioCommandDeserializerService.deserializeClientCommand(resourceIdentifier, json, false);
return ClientData.dataChangeInstance(resourceIdentifier, command.getOfficeId(), command.getExternalId(), command.getFirstname(), return ClientData.dataChangeInstance(resourceIdentifier, command.getOfficeId(), command.getExternalId(), command.getFirstname(),
command.getLastname(), command.getClientOrBusinessName(), command.getJoiningDate()); command.getLastname(), command.getClientOrBusinessName(), command.getJoiningDate());
@@ -570,14 +545,14 @@ public class PortfolioApiDataConversionServiceImpl implements PortfolioApiDataCo
.extractLongNamed("transactionProcessingStrategyId", element, modifiedParameters); .extractLongNamed("transactionProcessingStrategyId", element, modifiedParameters);
final String currencyCode = helper.extractStringNamed("currencyCode", element, modifiedParameters); final String currencyCode = helper.extractStringNamed("currencyCode", element, modifiedParameters);
final Integer digitsAfterDecimal = helper.extractIntegerNamed("digitsAfterDecimal", element, modifiedParameters); final Integer digitsAfterDecimal = helper.extractIntegerWithLocaleNamed("digitsAfterDecimal", element, modifiedParameters);
final BigDecimal principal = helper.extractBigDecimalNamed("principal", element, modifiedParameters); final BigDecimal principal = helper.extractBigDecimalWithLocaleNamed("principal", element, modifiedParameters);
final BigDecimal inArrearsTolerance = helper.extractBigDecimalNamed("inArrearsTolerance", element, modifiedParameters); final BigDecimal inArrearsTolerance = helper.extractBigDecimalWithLocaleNamed("inArrearsTolerance", element, modifiedParameters);
final BigDecimal interestRatePerPeriod = helper.extractBigDecimalNamed("interestRatePerPeriod", element, modifiedParameters); final BigDecimal interestRatePerPeriod = helper.extractBigDecimalWithLocaleNamed("interestRatePerPeriod", element, modifiedParameters);
final Integer repaymentEvery = helper.extractIntegerNamed("repaymentEvery", element, modifiedParameters); final Integer repaymentEvery = helper.extractIntegerWithLocaleNamed("repaymentEvery", element, modifiedParameters);
final Integer numberOfRepayments = helper.extractIntegerNamed("numberOfRepayments", element, modifiedParameters); final Integer numberOfRepayments = helper.extractIntegerWithLocaleNamed("numberOfRepayments", element, modifiedParameters);
final Integer repaymentFrequencyType = helper.extractIntegerNamed("repaymentFrequencyType", element, modifiedParameters); final Integer repaymentFrequencyType = helper.extractIntegerWithLocaleNamed("repaymentFrequencyType", element, modifiedParameters);
// FIXME - A - LoanProduct - KW - should loan term fields be part of // FIXME - A - LoanProduct - KW - should loan term fields be part of
// product also as are basic part of 'loan terms' // product also as are basic part of 'loan terms'
@@ -587,10 +562,10 @@ public class PortfolioApiDataConversionServiceImpl implements PortfolioApiDataCo
// final Integer loanTermFrequencyType = // final Integer loanTermFrequencyType =
// helper.extractIntegerNamed("loanTermFrequencyType", element, // helper.extractIntegerNamed("loanTermFrequencyType", element,
// modifiedParameters); // modifiedParameters);
final Integer interestRateFrequencyType = helper.extractIntegerNamed("interestRateFrequencyType", element, modifiedParameters); final Integer interestRateFrequencyType = helper.extractIntegerWithLocaleNamed("interestRateFrequencyType", element, modifiedParameters);
final Integer amortizationType = helper.extractIntegerNamed("amortizationType", element, modifiedParameters); final Integer amortizationType = helper.extractIntegerWithLocaleNamed("amortizationType", element, modifiedParameters);
final Integer interestType = helper.extractIntegerNamed("interestType", element, modifiedParameters); final Integer interestType = helper.extractIntegerWithLocaleNamed("interestType", element, modifiedParameters);
final Integer interestCalculationPeriodType = helper.extractIntegerNamed("interestCalculationPeriodType", element, final Integer interestCalculationPeriodType = helper.extractIntegerWithLocaleNamed("interestCalculationPeriodType", element,
modifiedParameters); modifiedParameters);
String[] charges = null; String[] charges = null;
@@ -642,20 +617,20 @@ public class PortfolioApiDataConversionServiceImpl implements PortfolioApiDataCo
final Long transactionProcessingStrategyId = helper.extractLongNamed("transactionProcessingStrategyId", element, final Long transactionProcessingStrategyId = helper.extractLongNamed("transactionProcessingStrategyId", element,
parametersPassedInCommand); parametersPassedInCommand);
final String externalId = helper.extractStringNamed("externalId", element, parametersPassedInCommand); final String externalId = helper.extractStringNamed("externalId", element, parametersPassedInCommand);
final BigDecimal principal = helper.extractBigDecimalNamed("principal", element, parametersPassedInCommand); final BigDecimal principal = helper.extractBigDecimalWithLocaleNamed("principal", element, parametersPassedInCommand);
final BigDecimal inArrearsToleranceValue = helper.extractBigDecimalNamed("inArrearsTolerance", element, parametersPassedInCommand); final BigDecimal inArrearsToleranceValue = helper.extractBigDecimalWithLocaleNamed("inArrearsTolerance", element, parametersPassedInCommand);
final BigDecimal interestRatePerPeriod = helper.extractBigDecimalNamed("interestRatePerPeriod", element, parametersPassedInCommand); final BigDecimal interestRatePerPeriod = helper.extractBigDecimalWithLocaleNamed("interestRatePerPeriod", element, parametersPassedInCommand);
final Integer repaymentEvery = helper.extractIntegerNamed("repaymentEvery", element, parametersPassedInCommand); final Integer repaymentEvery = helper.extractIntegerWithLocaleNamed("repaymentEvery", element, parametersPassedInCommand);
final Integer numberOfRepayments = helper.extractIntegerNamed("numberOfRepayments", element, parametersPassedInCommand); final Integer numberOfRepayments = helper.extractIntegerWithLocaleNamed("numberOfRepayments", element, parametersPassedInCommand);
final Integer repaymentFrequencyType = helper.extractIntegerNamed("repaymentFrequencyType", element, parametersPassedInCommand); final Integer repaymentFrequencyType = helper.extractIntegerWithLocaleNamed("repaymentFrequencyType", element, parametersPassedInCommand);
final Integer loanTermFrequency = helper.extractIntegerNamed("loanTermFrequency", element, parametersPassedInCommand); final Integer loanTermFrequency = helper.extractIntegerWithLocaleNamed("loanTermFrequency", element, parametersPassedInCommand);
final Integer loanTermFrequencyType = helper.extractIntegerNamed("loanTermFrequencyType", element, parametersPassedInCommand); final Integer loanTermFrequencyType = helper.extractIntegerWithLocaleNamed("loanTermFrequencyType", element, parametersPassedInCommand);
final Integer interestRateFrequencyType = helper.extractIntegerNamed("interestRateFrequencyType", element, final Integer interestRateFrequencyType = helper.extractIntegerWithLocaleNamed("interestRateFrequencyType", element,
parametersPassedInCommand); parametersPassedInCommand);
final Integer amortizationType = helper.extractIntegerNamed("amortizationType", element, parametersPassedInCommand); final Integer amortizationType = helper.extractIntegerWithLocaleNamed("amortizationType", element, parametersPassedInCommand);
final Integer interestType = helper.extractIntegerNamed("interestType", element, parametersPassedInCommand); final Integer interestType = helper.extractIntegerWithLocaleNamed("interestType", element, parametersPassedInCommand);
final Integer interestCalculationPeriodType = helper.extractIntegerNamed("interestCalculationPeriodType", element, final Integer interestCalculationPeriodType = helper.extractIntegerWithLocaleNamed("interestCalculationPeriodType", element,
parametersPassedInCommand); parametersPassedInCommand);
final LocalDate expectedDisbursementDate = helper.extractLocalDateNamed("expectedDisbursementDate", element, final LocalDate expectedDisbursementDate = helper.extractLocalDateNamed("expectedDisbursementDate", element,
@@ -3,7 +3,6 @@ package org.mifosng.platform.api.infrastructure;
import java.util.Collection; import java.util.Collection;
import java.util.Set; import java.util.Set;
import org.mifosng.platform.api.commands.ClientCommand;
import org.mifosng.platform.api.data.ClientAccountSummaryCollectionData; import org.mifosng.platform.api.data.ClientAccountSummaryCollectionData;
import org.mifosng.platform.api.data.ClientData; import org.mifosng.platform.api.data.ClientData;
import org.mifosng.platform.api.data.ClientIdentifierData; import org.mifosng.platform.api.data.ClientIdentifierData;
@@ -90,8 +89,6 @@ public interface PortfolioApiJsonSerializerService {
String serializeDepositAccountDataToJson(boolean prettyPrint, Set<String> responseParameters, DepositAccountData account); String serializeDepositAccountDataToJson(boolean prettyPrint, Set<String> responseParameters, DepositAccountData account);
String serializeClientCommandToJson(ClientCommand command);
String serializeClientDataToJson(ClientData clientData); String serializeClientDataToJson(ClientData clientData);
String serializeClientDataToJson(boolean prettyPrint, Set<String> responseParameters, ClientData clientData); String serializeClientDataToJson(boolean prettyPrint, Set<String> responseParameters, ClientData clientData);
@@ -7,6 +7,7 @@ import java.util.Set;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.joda.time.LocalDate; import org.joda.time.LocalDate;
import org.mifosng.platform.api.commands.ClientCommand;
import org.mifosng.platform.infrastructure.api.JsonParserHelper; import org.mifosng.platform.infrastructure.api.JsonParserHelper;
import org.mifosng.platform.infrastructure.errorhandling.InvalidJsonException; import org.mifosng.platform.infrastructure.errorhandling.InvalidJsonException;
import org.mifosplatform.infrastructure.codes.command.CodeCommand; import org.mifosplatform.infrastructure.codes.command.CodeCommand;
@@ -18,6 +19,7 @@ import org.mifosplatform.infrastructure.user.command.PermissionsCommand;
import org.mifosplatform.infrastructure.user.command.RoleCommand; import org.mifosplatform.infrastructure.user.command.RoleCommand;
import org.mifosplatform.infrastructure.user.command.RolePermissionCommand; import org.mifosplatform.infrastructure.user.command.RolePermissionCommand;
import org.mifosplatform.infrastructure.user.command.UserCommand; import org.mifosplatform.infrastructure.user.command.UserCommand;
import org.mifosplatform.portfolio.charge.command.ChargeDefinitionCommand;
import org.mifosplatform.portfolio.fund.command.FundCommand; import org.mifosplatform.portfolio.fund.command.FundCommand;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@@ -221,4 +223,51 @@ public class PortfolioCommandDeerializerServiceGoogleGson implements PortfolioCo
return new CurrencyCommand(makerCheckerApproval, currencies); return new CurrencyCommand(makerCheckerApproval, currencies);
} }
@Override
public ChargeDefinitionCommand deserializeChargeDefinitionCommand(final Long chargeDefinitionId, final String commandAsJson, final boolean makerCheckerApproval) {
if (StringUtils.isBlank(commandAsJson)) { throw new InvalidJsonException(); }
final JsonParserHelper helper = new JsonParserHelper();
final JsonElement element = parser.parse(commandAsJson);
final Set<String> parametersPassedInRequest = new HashSet<String>();
final String name = helper.extractStringNamed("name", element, parametersPassedInRequest);
final String currencyCode = helper.extractStringNamed("currencyCode", element, parametersPassedInRequest);
final BigDecimal amount = helper.extractBigDecimalNamed("amount", element.getAsJsonObject(), Locale.US, parametersPassedInRequest);
final Integer chargeTimeType = helper.extractIntegerNamed("chargeTimeType", element, Locale.US, parametersPassedInRequest);
final Integer chargeAppliesTo = helper.extractIntegerNamed("chargeAppliesTo", element, Locale.US, parametersPassedInRequest);
final Integer chargeCalculationType = helper.extractIntegerNamed("chargeCalculationType", element, Locale.US, parametersPassedInRequest);
final Boolean penalty = helper.extractBooleanNamed("penalty", element, parametersPassedInRequest);
final Boolean active = helper.extractBooleanNamed("active", element, parametersPassedInRequest);
return new ChargeDefinitionCommand(parametersPassedInRequest, makerCheckerApproval, chargeDefinitionId, name, amount, currencyCode, chargeTimeType, chargeAppliesTo,
chargeCalculationType, penalty, active);
}
@Override
public ClientCommand deserializeClientCommand(final Long clientId, final String commandAsJson, final boolean makerCheckerApproval) {
if (StringUtils.isBlank(commandAsJson)) { throw new InvalidJsonException(); }
final JsonParserHelper helper = new JsonParserHelper();
final JsonElement element = parser.parse(commandAsJson);
final Set<String> parametersPassedInRequest = new HashSet<String>();
final Long officeId = helper.extractLongNamed("officeId", element, parametersPassedInRequest);
final String externalId = helper.extractStringNamed("externalId", element, parametersPassedInRequest);
final String firstname = helper.extractStringNamed("firstname", element, parametersPassedInRequest);
final String lastname = helper.extractStringNamed("lastname", element, parametersPassedInRequest);
final String clientOrBusinessName = helper.extractStringNamed("clientOrBusinessName", element, parametersPassedInRequest);
final LocalDate joiningDate = helper.extractLocalDateAsArrayNamed("joiningDate", element, parametersPassedInRequest);
return new ClientCommand(parametersPassedInRequest, clientId, externalId, firstname, lastname, clientOrBusinessName,
officeId, joiningDate, makerCheckerApproval);
}
} }
@@ -1,5 +1,6 @@
package org.mifosng.platform.api.infrastructure; package org.mifosng.platform.api.infrastructure;
import org.mifosng.platform.api.commands.ClientCommand;
import org.mifosplatform.infrastructure.codes.command.CodeCommand; import org.mifosplatform.infrastructure.codes.command.CodeCommand;
import org.mifosplatform.infrastructure.configuration.command.CurrencyCommand; import org.mifosplatform.infrastructure.configuration.command.CurrencyCommand;
import org.mifosplatform.infrastructure.office.command.BranchMoneyTransferCommand; import org.mifosplatform.infrastructure.office.command.BranchMoneyTransferCommand;
@@ -9,6 +10,7 @@ import org.mifosplatform.infrastructure.user.command.PermissionsCommand;
import org.mifosplatform.infrastructure.user.command.RoleCommand; import org.mifosplatform.infrastructure.user.command.RoleCommand;
import org.mifosplatform.infrastructure.user.command.RolePermissionCommand; import org.mifosplatform.infrastructure.user.command.RolePermissionCommand;
import org.mifosplatform.infrastructure.user.command.UserCommand; import org.mifosplatform.infrastructure.user.command.UserCommand;
import org.mifosplatform.portfolio.charge.command.ChargeDefinitionCommand;
import org.mifosplatform.portfolio.fund.command.FundCommand; import org.mifosplatform.portfolio.fund.command.FundCommand;
/** /**
@@ -42,4 +44,8 @@ public interface PortfolioCommandDeserializerService {
BranchMoneyTransferCommand deserializeOfficeTransactionCommand(String commandAsJson, boolean makerCheckerApproval); BranchMoneyTransferCommand deserializeOfficeTransactionCommand(String commandAsJson, boolean makerCheckerApproval);
CurrencyCommand deserializeCurrencyCommand(String commandAsJson, boolean makerCheckerApproval); CurrencyCommand deserializeCurrencyCommand(String commandAsJson, boolean makerCheckerApproval);
ChargeDefinitionCommand deserializeChargeDefinitionCommand(Long chargeDefinitionId, String commandAsJson, boolean makerCheckerApproval);
ClientCommand deserializeClientCommand(Long clientId, String commandAsJson, boolean makerCheckerApproval);
} }
@@ -38,4 +38,6 @@ public interface PortfolioCommandSerializerService {
String serializeOfficeTransactionCommandToJson(BranchMoneyTransferCommand command); String serializeOfficeTransactionCommandToJson(BranchMoneyTransferCommand command);
String serializeCurrencyCommandToJson(CurrencyCommand command); String serializeCurrencyCommandToJson(CurrencyCommand command);
String serializeCommandToJson(Object command);
} }
@@ -92,4 +92,10 @@ public class PortfolioCommandSerializerServiceJson implements PortfolioCommandSe
final Gson gsonDeserializer = helper.createGsonBuilderWithParameterExclusionSerializationStrategy(new HashSet<String>(), false, new HashSet<String>()); final Gson gsonDeserializer = helper.createGsonBuilderWithParameterExclusionSerializationStrategy(new HashSet<String>(), false, new HashSet<String>());
return helper.serializedJsonFrom(gsonDeserializer, command); return helper.serializedJsonFrom(gsonDeserializer, command);
} }
@Override
public String serializeCommandToJson(Object command) {
final Gson gsonDeserializer = helper.createGsonBuilderWithParameterExclusionSerializationStrategy(new HashSet<String>(), false, new HashSet<String>());
return helper.serializedJsonFrom(gsonDeserializer, command);
}
} }
@@ -27,11 +27,10 @@ import org.mifosng.platform.infrastructure.FileUtils;
import org.mifosplatform.infrastructure.codes.domain.CodeValue; import org.mifosplatform.infrastructure.codes.domain.CodeValue;
import org.mifosplatform.infrastructure.codes.domain.CodeValueRepository; import org.mifosplatform.infrastructure.codes.domain.CodeValueRepository;
import org.mifosplatform.infrastructure.codes.exception.CodeValueNotFoundException; import org.mifosplatform.infrastructure.codes.exception.CodeValueNotFoundException;
import org.mifosplatform.infrastructure.configuration.service.ConfigurationDomainService;
import org.mifosplatform.infrastructure.office.domain.Office; import org.mifosplatform.infrastructure.office.domain.Office;
import org.mifosplatform.infrastructure.office.domain.OfficeRepository; import org.mifosplatform.infrastructure.office.domain.OfficeRepository;
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext; import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
import org.mifosplatform.infrastructure.user.domain.Permission;
import org.mifosplatform.infrastructure.user.domain.PermissionRepository;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@@ -50,19 +49,20 @@ public class ClientWritePlatformServiceJpaRepositoryImpl implements ClientWriteP
private final OfficeRepository officeRepository; private final OfficeRepository officeRepository;
private final NoteRepository noteRepository; private final NoteRepository noteRepository;
private final CodeValueRepository codeValueRepository; private final CodeValueRepository codeValueRepository;
private final PermissionRepository permissionRepository; private final ConfigurationDomainService configurationDomainService;
@Autowired @Autowired
public ClientWritePlatformServiceJpaRepositoryImpl(final PlatformSecurityContext context, final ClientRepository clientRepository, public ClientWritePlatformServiceJpaRepositoryImpl(final PlatformSecurityContext context, final ClientRepository clientRepository,
final ClientIdentifierRepository clientIdentifierRepository, final OfficeRepository officeRepository, final ClientIdentifierRepository clientIdentifierRepository, final OfficeRepository officeRepository,
NoteRepository noteRepository, final CodeValueRepository codeValueRepository, final PermissionRepository permissionRepository) { final NoteRepository noteRepository, final CodeValueRepository codeValueRepository,
final ConfigurationDomainService configurationDomainService) {
this.context = context; this.context = context;
this.clientRepository = clientRepository; this.clientRepository = clientRepository;
this.clientIdentifierRepository = clientIdentifierRepository; this.clientIdentifierRepository = clientIdentifierRepository;
this.officeRepository = officeRepository; this.officeRepository = officeRepository;
this.noteRepository = noteRepository; this.noteRepository = noteRepository;
this.codeValueRepository = codeValueRepository; this.codeValueRepository = codeValueRepository;
this.permissionRepository = permissionRepository; this.configurationDomainService = configurationDomainService;
} }
@Transactional @Transactional
@@ -76,9 +76,8 @@ public class ClientWritePlatformServiceJpaRepositoryImpl implements ClientWriteP
client.delete(); client.delete();
this.clientRepository.save(client); this.clientRepository.save(client);
final Permission thisTask = this.permissionRepository.findOneByCode("DELETE_CLIENT"); if (this.configurationDomainService.isMakerCheckerEnabledForTask("DELETE_CLIENT") && !command.isApprovedByChecker()) { throw new RollbackTransactionAsCommandIsNotApprovedByCheckerException(); }
if (thisTask.hasMakerCheckerEnabled() && !command.isApprovedByChecker()) { throw new RollbackTransactionAsCommandIsNotApprovedByCheckerException(); }
return new EntityIdentifier(client.getId()); return new EntityIdentifier(client.getId());
} }
@@ -121,9 +120,8 @@ public class ClientWritePlatformServiceJpaRepositoryImpl implements ClientWriteP
final Client newClient = Client.newClient(clientOffice, firstname, lastname, command.getJoiningDate(), command.getExternalId()); final Client newClient = Client.newClient(clientOffice, firstname, lastname, command.getJoiningDate(), command.getExternalId());
this.clientRepository.save(newClient); this.clientRepository.save(newClient);
final Permission thisTask = this.permissionRepository.findOneByCode("CREATE_CLIENT"); if (this.configurationDomainService.isMakerCheckerEnabledForTask("CREATE_CLIENT") && !command.isApprovedByChecker()) { throw new RollbackTransactionAsCommandIsNotApprovedByCheckerException(); }
if (thisTask.hasMakerCheckerEnabled() && !command.isApprovedByChecker()) { throw new RollbackTransactionAsCommandIsNotApprovedByCheckerException(); }
return newClient.getId(); return newClient.getId();
} catch (DataIntegrityViolationException dve) { } catch (DataIntegrityViolationException dve) {
@@ -155,9 +153,8 @@ public class ClientWritePlatformServiceJpaRepositoryImpl implements ClientWriteP
this.clientRepository.saveAndFlush(clientForUpdate); this.clientRepository.saveAndFlush(clientForUpdate);
final Permission thisTask = this.permissionRepository.findOneByCode("UPDATE_CLIENT"); if (this.configurationDomainService.isMakerCheckerEnabledForTask("UPDATE_CLIENT") && !command.isApprovedByChecker()) { throw new RollbackTransactionAsCommandIsNotApprovedByCheckerException(); }
if (thisTask.hasMakerCheckerEnabled() && !command.isApprovedByChecker()) { throw new RollbackTransactionAsCommandIsNotApprovedByCheckerException(); }
return new EntityIdentifier(clientForUpdate.getId()); return new EntityIdentifier(clientForUpdate.getId());
} catch (DataIntegrityViolationException dve) { } catch (DataIntegrityViolationException dve) {
handleDataIntegrityIssues(command, dve); handleDataIntegrityIssues(command, dve);
@@ -10,8 +10,8 @@ public abstract class AbstractPlatformResourceNotFoundException extends RuntimeE
private final String defaultUserMessage; private final String defaultUserMessage;
private final Object[] defaultUserMessageArgs; private final Object[] defaultUserMessageArgs;
public AbstractPlatformResourceNotFoundException(String globalisationMessageCode, String defaultUserMessage, public AbstractPlatformResourceNotFoundException(final String globalisationMessageCode, final String defaultUserMessage,
Object... defaultUserMessageArgs) { final Object... defaultUserMessageArgs) {
this.globalisationMessageCode = globalisationMessageCode; this.globalisationMessageCode = globalisationMessageCode;
this.defaultUserMessage = defaultUserMessage; this.defaultUserMessage = defaultUserMessage;
this.defaultUserMessageArgs = defaultUserMessageArgs; this.defaultUserMessageArgs = defaultUserMessageArgs;
@@ -1,13 +0,0 @@
package org.mifosng.platform.exceptions;
/**
* A {@link RuntimeException} thrown when permission resources are not found.
*/
public class PermissionCantBeMakerCheckerableException extends
AbstractPlatformResourceNotFoundException {
public PermissionCantBeMakerCheckerableException(String code) {
super("error.msg.permission.code.not.makercheckerable", "Permission with Code "
+ code + " can't be Maker Checkerable", code);
}
}
@@ -1,13 +0,0 @@
package org.mifosng.platform.exceptions;
/**
* A {@link RuntimeException} thrown when permission resources are not found.
*/
public class PermissionNotFoundException extends
AbstractPlatformResourceNotFoundException {
public PermissionNotFoundException(String code) {
super("error.msg.permission.code.invalid", "Permission with Code "
+ code + " does not exist", code);
}
}
@@ -74,7 +74,7 @@ public class JsonParserHelper {
return stringValue; return stringValue;
} }
public BigDecimal extractBigDecimalNamed(final String parameterName, final JsonElement element, final Set<String> modifiedParameters) { public BigDecimal extractBigDecimalWithLocaleNamed(final String parameterName, final JsonElement element, final Set<String> modifiedParameters) {
BigDecimal value = null; BigDecimal value = null;
if (element.isJsonObject()) { if (element.isJsonObject()) {
final JsonObject object = element.getAsJsonObject(); final JsonObject object = element.getAsJsonObject();
@@ -101,7 +101,7 @@ public class JsonParserHelper {
return value; return value;
} }
public Integer extractIntegerNamed(final String parameterName, final JsonElement element, final Set<String> modifiedParameters) { public Integer extractIntegerWithLocaleNamed(final String parameterName, final JsonElement element, final Set<String> modifiedParameters) {
Integer value = null; Integer value = null;
if (element.isJsonObject()) { if (element.isJsonObject()) {
final JsonObject object = element.getAsJsonObject(); final JsonObject object = element.getAsJsonObject();
@@ -49,20 +49,21 @@ public class CommandSource extends AbstractPersistable<Long> {
@Temporal(TemporalType.DATE) @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, public static CommandSource createdBy(final String apiOperation, final String resource, final Long resourceId,
final LocalDate madeOnDate) { final String commandSerializedAsJson, final AppUser maker, final LocalDate madeOnDate) {
return new CommandSource(apiOperation, resource, resourceId, maker, madeOnDate); return new CommandSource(apiOperation, resource, resourceId, commandSerializedAsJson, maker, madeOnDate);
} }
protected CommandSource() { protected CommandSource() {
// //
} }
private CommandSource(final String apiOperation, final String resource, final Long resourceId, final AppUser maker, private CommandSource(final String apiOperation, final String resource, final Long resourceId, final String commandSerializedAsJson, final AppUser maker,
final LocalDate madeOnDate) { final LocalDate madeOnDate) {
this.apiOperation = StringUtils.defaultIfEmpty(apiOperation, null); this.apiOperation = StringUtils.defaultIfEmpty(apiOperation, null);
this.resource = StringUtils.defaultIfEmpty(resource, null); this.resource = StringUtils.defaultIfEmpty(resource, null);
this.resourceId = resourceId; this.resourceId = resourceId;
this.commandAsJson = commandSerializedAsJson;
this.maker = maker; this.maker = maker;
this.madeOnDate = madeOnDate.toDate(); this.madeOnDate = madeOnDate.toDate();
} }
@@ -72,7 +73,7 @@ public class CommandSource extends AbstractPersistable<Long> {
if (this.madeOnDate != null) { if (this.madeOnDate != null) {
madeOnLocalDate = new LocalDate(this.madeOnDate); madeOnLocalDate = new LocalDate(this.madeOnDate);
} }
return new CommandSource(this.apiOperation, this.resource, this.resourceId, this.maker, madeOnLocalDate); return new CommandSource(this.apiOperation, this.resource, this.resourceId, this.commandAsJson, this.maker, madeOnLocalDate);
} }
public void markAsChecked(final AppUser checker, final LocalDate checkedOnDate) { public void markAsChecked(final AppUser checker, final LocalDate checkedOnDate) {
@@ -114,7 +115,8 @@ public class CommandSource extends AbstractPersistable<Long> {
public boolean isUpdate() { public boolean isUpdate() {
// permissions resource has special update which involves no resource. // permissions resource has special update which involves no resource.
return (isPermissionResource() && isUpdateOperation()) || (isCurrencyResource() && isUpdateOperation()) || (isUpdateOperation() && this.resourceId != null); return (isPermissionResource() && isUpdateOperation()) || (isCurrencyResource() && isUpdateOperation())
|| (isUpdateOperation() && this.resourceId != null);
} }
private boolean isUpdateOperation() { private boolean isUpdateOperation() {
@@ -132,7 +134,7 @@ public class CommandSource extends AbstractPersistable<Long> {
public boolean isPermissionResource() { public boolean isPermissionResource() {
return this.resource.equalsIgnoreCase("PERMISSIONS"); return this.resource.equalsIgnoreCase("PERMISSIONS");
} }
public boolean isRoleResource() { public boolean isRoleResource() {
return this.resource.equalsIgnoreCase("ROLES"); return this.resource.equalsIgnoreCase("ROLES");
} }
@@ -144,7 +146,7 @@ public class CommandSource extends AbstractPersistable<Long> {
public boolean isCurrencyResource() { public boolean isCurrencyResource() {
return this.resource.equalsIgnoreCase("CURRENCIES"); return this.resource.equalsIgnoreCase("CURRENCIES");
} }
public boolean isCodeResource() { public boolean isCodeResource() {
return this.resource.equalsIgnoreCase("CODES"); return this.resource.equalsIgnoreCase("CODES");
} }
@@ -152,11 +154,11 @@ public class CommandSource extends AbstractPersistable<Long> {
public boolean isStaffResource() { public boolean isStaffResource() {
return this.resource.equalsIgnoreCase("STAFF"); return this.resource.equalsIgnoreCase("STAFF");
} }
public boolean isFundResource() { public boolean isFundResource() {
return this.resource.equalsIgnoreCase("FUNDS"); return this.resource.equalsIgnoreCase("FUNDS");
} }
public boolean isOfficeResource() { public boolean isOfficeResource() {
return this.resource.equalsIgnoreCase("OFFICES"); return this.resource.equalsIgnoreCase("OFFICES");
} }
@@ -164,8 +166,13 @@ public class CommandSource extends AbstractPersistable<Long> {
public boolean isOfficeTransactionResource() { public boolean isOfficeTransactionResource() {
return this.resource.equalsIgnoreCase("OFFICETRANSACTIONS"); return this.resource.equalsIgnoreCase("OFFICETRANSACTIONS");
} }
public boolean isChargeDefinitionResource() {
return this.resource.equalsIgnoreCase("CHARGES");
}
public boolean isClientResource() { public boolean isClientResource() {
return this.resource.equalsIgnoreCase("CLIENTS"); return this.resource.equalsIgnoreCase("CLIENTS");
} }
} }
@@ -0,0 +1,120 @@
package org.mifosplatform.commands.handler;
import java.util.Arrays;
import java.util.List;
import org.joda.time.LocalDate;
import org.mifosng.platform.api.infrastructure.PortfolioCommandDeserializerService;
import org.mifosng.platform.client.service.RollbackTransactionAsCommandIsNotApprovedByCheckerException;
import org.mifosplatform.commands.domain.CommandSource;
import org.mifosplatform.commands.service.ChangeDetectionService;
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
import org.mifosplatform.infrastructure.user.domain.AppUser;
import org.mifosplatform.portfolio.charge.command.ChargeDefinitionCommand;
import org.mifosplatform.portfolio.charge.service.ChargeWritePlatformService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class ChargeDefinitionCommandHandler implements CommandSourceHandler {
private final PlatformSecurityContext context;
private final ChangeDetectionService changeDetectionService;
private final PortfolioCommandDeserializerService commandDeserializerService;
private final ChargeWritePlatformService writePlatformService;
@Autowired
public ChargeDefinitionCommandHandler(final PlatformSecurityContext context, final ChangeDetectionService changeDetectionService,
final PortfolioCommandDeserializerService commandDeserializerService,
final ChargeWritePlatformService writePlatformService) {
this.context = context;
this.changeDetectionService = changeDetectionService;
this.commandDeserializerService = commandDeserializerService;
this.writePlatformService = writePlatformService;
}
/*
* Used when users with 'create' capability create a command. If 'maker-checker' is not
* enabled for this specific command then the 'creator' is also marked 'as the checker' and command
* automatically is processed and changes state of system.
*/
public CommandSource handle(final CommandSource commandSource, final String commandSerializedAsJson) {
final AppUser maker = context.authenticatedUser();
final LocalDate asToday = new LocalDate();
CommandSource commandSourceResult = commandSource.copy();
final Long resourceId = commandSource.resourceId();
final ChargeDefinitionCommand command = this.commandDeserializerService.deserializeChargeDefinitionCommand(resourceId, commandSourceResult.json(), true);
if (commandSource.isCreate()) {
try {
Long newResourceId = this.writePlatformService.createCharge(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.detectChangesOnUpdate(commandSource.resourceName(), commandSource.resourceId(), commandSource.json());
commandSourceResult.updateJsonTo(jsonOfChangesOnly);
final ChargeDefinitionCommand changesOnly = this.commandDeserializerService.deserializeChargeDefinitionCommand(resourceId, jsonOfChangesOnly, false);
this.writePlatformService.updateCharge(changesOnly);
commandSourceResult.markAsChecked(maker, asToday);
} catch (RollbackTransactionAsCommandIsNotApprovedByCheckerException e) {
// swallow this rollback transaction by design
}
} else if (commandSource.isDelete()) {
try {
this.writePlatformService.deleteCharge(command);
commandSourceResult.markAsChecked(maker, asToday);
} catch (RollbackTransactionAsCommandIsNotApprovedByCheckerException e) {
// swallow this rollback transaction by design
}
}
return commandSourceResult;
}
/*
* Used when users with 'checker' capability approve a command.
*/
public CommandSource handle(final CommandSource commandSourceResult) {
final AppUser checker = context.authenticatedUser();
Long resourceId = commandSourceResult.resourceId();
final ChargeDefinitionCommand command = this.commandDeserializerService.deserializeChargeDefinitionCommand(resourceId, commandSourceResult.json(), true);
if (commandSourceResult.isUserResource()) {
if (commandSourceResult.isCreate()) {
final List<String> allowedPermissions = Arrays.asList("ALL_FUNCTIONS", "ORGANISATION_ADMINISTRATION_SUPER_USER", "CREATE_CHARGE_MAKER");
context.authenticatedUser().validateHasPermissionTo("CREATE_CHARGE_MAKER", allowedPermissions);
resourceId = this.writePlatformService.createCharge(command);
commandSourceResult.updateResourceId(resourceId);
commandSourceResult.markAsChecked(checker, new LocalDate());
} else if (commandSourceResult.isUpdate()) {
final List<String> allowedPermissions = Arrays.asList("ALL_FUNCTIONS", "ORGANISATION_ADMINISTRATION_SUPER_USER", "UPDATE_CHARGE_MAKER");
context.authenticatedUser().validateHasPermissionTo("UPDATE_CHARGE_MAKER", allowedPermissions);
this.writePlatformService.updateCharge(command);
commandSourceResult.markAsChecked(checker, new LocalDate());
} else if (commandSourceResult.isDelete()) {
final List<String> allowedPermissions = Arrays.asList("ALL_FUNCTIONS", "ORGANISATION_ADMINISTRATION_SUPER_USER", "DELETE_CHARGE_MAKER");
context.authenticatedUser().validateHasPermissionTo("DELETE_CHARGE_MAKER", allowedPermissions);
this.writePlatformService.deleteCharge(command);
commandSourceResult.markAsChecked(checker, new LocalDate());
}
}
return commandSourceResult;
}
}
@@ -6,8 +6,7 @@ import java.util.List;
import org.joda.time.LocalDate; import org.joda.time.LocalDate;
import org.mifosng.platform.api.commands.ClientCommand; import org.mifosng.platform.api.commands.ClientCommand;
import org.mifosng.platform.api.data.EntityIdentifier; import org.mifosng.platform.api.data.EntityIdentifier;
import org.mifosng.platform.api.infrastructure.PortfolioApiDataConversionService; import org.mifosng.platform.api.infrastructure.PortfolioCommandDeserializerService;
import org.mifosng.platform.api.infrastructure.PortfolioApiJsonSerializerService;
import org.mifosng.platform.client.service.ClientWritePlatformService; import org.mifosng.platform.client.service.ClientWritePlatformService;
import org.mifosng.platform.client.service.RollbackTransactionAsCommandIsNotApprovedByCheckerException; import org.mifosng.platform.client.service.RollbackTransactionAsCommandIsNotApprovedByCheckerException;
import org.mifosplatform.commands.domain.CommandSource; import org.mifosplatform.commands.domain.CommandSource;
@@ -22,35 +21,30 @@ public class ClientCommandHandler implements CommandSourceHandler {
private final PlatformSecurityContext context; private final PlatformSecurityContext context;
private final ChangeDetectionService changeDetectionService; private final ChangeDetectionService changeDetectionService;
private final PortfolioApiDataConversionService apiDataConversionService;
private final PortfolioApiJsonSerializerService apiJsonSerializerService;
private final ClientWritePlatformService clientWritePlatformService; private final ClientWritePlatformService clientWritePlatformService;
private final PortfolioCommandDeserializerService commandDeserializerService;
@Autowired @Autowired
public ClientCommandHandler(final PlatformSecurityContext context, final ChangeDetectionService changeDetectionService, public ClientCommandHandler(final PlatformSecurityContext context, final ChangeDetectionService changeDetectionService,
final PortfolioApiDataConversionService apiDataConversionService, final PortfolioCommandDeserializerService commandDeserializerService,
final PortfolioApiJsonSerializerService apiJsonSerializerService, final ClientWritePlatformService clientWritePlatformService) { final ClientWritePlatformService clientWritePlatformService) {
this.context = context; this.context = context;
this.changeDetectionService = changeDetectionService; this.changeDetectionService = changeDetectionService;
this.apiDataConversionService = apiDataConversionService; this.commandDeserializerService = commandDeserializerService;
this.apiJsonSerializerService = apiJsonSerializerService;
this.clientWritePlatformService = clientWritePlatformService; this.clientWritePlatformService = clientWritePlatformService;
} }
public CommandSource handle(final CommandSource commandSource, final String apiRequestBodyInJson) { public CommandSource handle(final CommandSource commandSource, final String commandSerializedAsJson) {
final AppUser maker = context.authenticatedUser(); final AppUser maker = context.authenticatedUser();
final LocalDate asToday = new LocalDate(); final LocalDate asToday = new LocalDate();
final ClientCommand command = this.commandDeserializerService.deserializeClientCommand(commandSource.resourceId(),
commandSource.json(), false);
CommandSource commandSourceResult = commandSource.copy(); CommandSource commandSourceResult = commandSource.copy();
final Long resourceId = commandSource.resourceId();
Long newResourceId = null; Long newResourceId = null;
final ClientCommand command = this.apiDataConversionService.convertApiRequestJsonToClientCommand(resourceId, apiRequestBodyInJson);
final String commandSerializedAsJson = this.apiJsonSerializerService.serializeClientCommandToJson(command);
commandSourceResult.updateJsonTo(commandSerializedAsJson);
if (commandSource.isCreate()) { if (commandSource.isCreate()) {
try { try {
newResourceId = this.clientWritePlatformService.createClient(command); newResourceId = this.clientWritePlatformService.createClient(command);
@@ -61,11 +55,12 @@ public class ClientCommandHandler implements CommandSourceHandler {
} }
} else if (commandSource.isUpdate()) { } else if (commandSource.isUpdate()) {
try { try {
final String jsonOfChangesOnly = this.changeDetectionService.detectChangesOnUpdate(commandSource.resourceName(), commandSource.resourceId(), commandSerializedAsJson); final String jsonOfChangesOnly = this.changeDetectionService.detectChangesOnUpdate(commandSource.resourceName(),
commandSource.resourceId(), commandSource.json());
commandSourceResult.updateJsonTo(jsonOfChangesOnly); commandSourceResult.updateJsonTo(jsonOfChangesOnly);
final ClientCommand changesOnly = this.apiDataConversionService.convertInternalJsonFormatToClientCommand( final ClientCommand changesOnly = this.commandDeserializerService.deserializeClientCommand(commandSource.resourceId(),
commandSource.resourceId(), jsonOfChangesOnly, false); jsonOfChangesOnly, false);
EntityIdentifier result = this.clientWritePlatformService.updateClientDetails(changesOnly); EntityIdentifier result = this.clientWritePlatformService.updateClientDetails(changesOnly);
newResourceId = result.getEntityId(); newResourceId = result.getEntityId();
@@ -90,34 +85,35 @@ public class ClientCommandHandler implements CommandSourceHandler {
public CommandSource handle(final CommandSource commandSourceResult) { public CommandSource handle(final CommandSource commandSourceResult) {
final AppUser checker = context.authenticatedUser(); final AppUser checker = context.authenticatedUser();
Long resourceId = null;
if (commandSourceResult.isClientResource()) {
final ClientCommand command = this.apiDataConversionService.convertInternalJsonFormatToClientCommand(
commandSourceResult.resourceId(), commandSourceResult.json(), true);
if (commandSourceResult.isCreate()) { Long resourceId = null;
final List<String> allowedPermissions = Arrays.asList("ALL_FUNCTIONS", "PORTFOLIO_MANAGEMENT_SUPER_USER", "CREATE_CLIENT_CHECKER"); final ClientCommand command = this.commandDeserializerService.deserializeClientCommand(commandSourceResult.resourceId(),
context.authenticatedUser().validateHasPermissionTo("CREATE_CLIENT_CHECKER", allowedPermissions); commandSourceResult.json(), true);
resourceId = this.clientWritePlatformService.createClient(command); if (commandSourceResult.isCreate()) {
commandSourceResult.updateResourceId(resourceId); final List<String> allowedPermissions = Arrays.asList("ALL_FUNCTIONS", "PORTFOLIO_MANAGEMENT_SUPER_USER",
commandSourceResult.markAsChecked(checker, new LocalDate()); "CREATE_CLIENT_CHECKER");
} else if (commandSourceResult.isUpdate()) { context.authenticatedUser().validateHasPermissionTo("CREATE_CLIENT_CHECKER", allowedPermissions);
final List<String> allowedPermissions = Arrays.asList("ALL_FUNCTIONS", "PORTFOLIO_MANAGEMENT_SUPER_USER", "UPDATE_CLIENT_CHECKER");
context.authenticatedUser().validateHasPermissionTo("UPDATE_CLIENT_CHECKER", allowedPermissions); resourceId = this.clientWritePlatformService.createClient(command);
commandSourceResult.updateResourceId(resourceId);
EntityIdentifier result = this.clientWritePlatformService.updateClientDetails(command); commandSourceResult.markAsChecked(checker, new LocalDate());
resourceId = result.getEntityId(); } else if (commandSourceResult.isUpdate()) {
commandSourceResult.markAsChecked(checker, new LocalDate()); final List<String> allowedPermissions = Arrays.asList("ALL_FUNCTIONS", "PORTFOLIO_MANAGEMENT_SUPER_USER",
} else if (commandSourceResult.isDelete()) { "UPDATE_CLIENT_CHECKER");
final List<String> allowedPermissions = Arrays.asList("ALL_FUNCTIONS", "PORTFOLIO_MANAGEMENT_SUPER_USER", "DELETE_CLIENT_CHECKER"); context.authenticatedUser().validateHasPermissionTo("UPDATE_CLIENT_CHECKER", allowedPermissions);
context.authenticatedUser().validateHasPermissionTo("DELETE_CLIENT_CHECKER", allowedPermissions);
EntityIdentifier result = this.clientWritePlatformService.updateClientDetails(command);
EntityIdentifier result = this.clientWritePlatformService.deleteClient(command); resourceId = result.getEntityId();
resourceId = result.getEntityId(); commandSourceResult.markAsChecked(checker, new LocalDate());
commandSourceResult.markAsChecked(checker, new LocalDate()); } else if (commandSourceResult.isDelete()) {
} final List<String> allowedPermissions = Arrays.asList("ALL_FUNCTIONS", "PORTFOLIO_MANAGEMENT_SUPER_USER",
"DELETE_CLIENT_CHECKER");
context.authenticatedUser().validateHasPermissionTo("DELETE_CLIENT_CHECKER", allowedPermissions);
EntityIdentifier result = this.clientWritePlatformService.deleteClient(command);
resourceId = result.getEntityId();
commandSourceResult.markAsChecked(checker, new LocalDate());
} }
return commandSourceResult; return commandSourceResult;
@@ -23,6 +23,7 @@ public class CommandSourceHandlerDelegator {
private final OfficeCommandHandler officeCommandHandler; private final OfficeCommandHandler officeCommandHandler;
private final OfficeTransactionCommandHandler officeTransactionCommandHandler; private final OfficeTransactionCommandHandler officeTransactionCommandHandler;
private final CurrencyCommandHandler currencyCommandHandler; private final CurrencyCommandHandler currencyCommandHandler;
private final ChargeDefinitionCommandHandler chargeDefinitionCommandHandler;
@Autowired @Autowired
public CommandSourceHandlerDelegator(final PlatformSecurityContext context, public CommandSourceHandlerDelegator(final PlatformSecurityContext context,
@@ -35,7 +36,8 @@ public class CommandSourceHandlerDelegator {
final FundCommandHandler fundCommandHandler, final FundCommandHandler fundCommandHandler,
final OfficeCommandHandler officeCommandHandler, final OfficeCommandHandler officeCommandHandler,
final OfficeTransactionCommandHandler officeTransactionCommandHandler, final OfficeTransactionCommandHandler officeTransactionCommandHandler,
final CurrencyCommandHandler currencyCommandHandler) { final CurrencyCommandHandler currencyCommandHandler,
final ChargeDefinitionCommandHandler chargeDefinitionCommandHandler) {
this.context = context; this.context = context;
this.clientCommandHandler = clientCommandHandler; this.clientCommandHandler = clientCommandHandler;
this.roleCommandHandler = roleCommandHandler; this.roleCommandHandler = roleCommandHandler;
@@ -47,6 +49,7 @@ public class CommandSourceHandlerDelegator {
this.officeCommandHandler = officeCommandHandler; this.officeCommandHandler = officeCommandHandler;
this.officeTransactionCommandHandler = officeTransactionCommandHandler; this.officeTransactionCommandHandler = officeTransactionCommandHandler;
this.currencyCommandHandler = currencyCommandHandler; this.currencyCommandHandler = currencyCommandHandler;
this.chargeDefinitionCommandHandler = chargeDefinitionCommandHandler;
} }
public CommandSource handle(final CommandSource commandSource, final String apiRequestBodyInJson) { public CommandSource handle(final CommandSource commandSource, final String apiRequestBodyInJson) {
@@ -73,6 +76,8 @@ public class CommandSourceHandlerDelegator {
commandSourceResult = officeTransactionCommandHandler.handle(commandSource, apiRequestBodyInJson); commandSourceResult = officeTransactionCommandHandler.handle(commandSource, apiRequestBodyInJson);
} else if (commandSource.isCurrencyResource()) { } else if (commandSource.isCurrencyResource()) {
commandSourceResult = currencyCommandHandler.handle(commandSource, apiRequestBodyInJson); commandSourceResult = currencyCommandHandler.handle(commandSource, apiRequestBodyInJson);
} else if (commandSource.isChargeDefinitionResource()) {
commandSourceResult = chargeDefinitionCommandHandler.handle(commandSource, apiRequestBodyInJson);
} else { } else {
throw new UnsupportedCommandException(commandSource.commandName()); throw new UnsupportedCommandException(commandSource.commandName());
} }
@@ -103,6 +108,8 @@ public class CommandSourceHandlerDelegator {
commandSourceResult = officeTransactionCommandHandler.handle(existingCommandSource); commandSourceResult = officeTransactionCommandHandler.handle(existingCommandSource);
} else if (existingCommandSource.isCurrencyResource()) { } else if (existingCommandSource.isCurrencyResource()) {
commandSourceResult = currencyCommandHandler.handle(existingCommandSource); commandSourceResult = currencyCommandHandler.handle(existingCommandSource);
} else if (existingCommandSource.isChargeDefinitionResource()) {
commandSourceResult = chargeDefinitionCommandHandler.handle(existingCommandSource);
} else { } else {
throw new UnsupportedCommandException(existingCommandSource.commandName()); throw new UnsupportedCommandException(existingCommandSource.commandName());
} }
@@ -12,7 +12,7 @@ import org.mifosng.platform.infrastructure.errorhandling.UnsupportedCommandExcep
import org.mifosplatform.commands.domain.CommandSource; import org.mifosplatform.commands.domain.CommandSource;
import org.mifosplatform.commands.service.ChangeDetectionService; import org.mifosplatform.commands.service.ChangeDetectionService;
import org.mifosplatform.infrastructure.configuration.command.CurrencyCommand; import org.mifosplatform.infrastructure.configuration.command.CurrencyCommand;
import org.mifosplatform.infrastructure.configuration.service.ConfigurationWritePlatformService; import org.mifosplatform.infrastructure.configuration.service.CurrencyWritePlatformService;
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext; import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
import org.mifosplatform.infrastructure.user.domain.AppUser; import org.mifosplatform.infrastructure.user.domain.AppUser;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@@ -26,14 +26,14 @@ public class CurrencyCommandHandler implements CommandSourceHandler {
private final PortfolioApiDataConversionService apiDataConversionService; private final PortfolioApiDataConversionService apiDataConversionService;
private final PortfolioCommandSerializerService commandSerializerService; private final PortfolioCommandSerializerService commandSerializerService;
private final PortfolioCommandDeserializerService commandDeserializerService; private final PortfolioCommandDeserializerService commandDeserializerService;
private final ConfigurationWritePlatformService writePlatformService; private final CurrencyWritePlatformService writePlatformService;
@Autowired @Autowired
public CurrencyCommandHandler(final PlatformSecurityContext context, public CurrencyCommandHandler(final PlatformSecurityContext context,
final ChangeDetectionService changeDetectionService, final ChangeDetectionService changeDetectionService,
final PortfolioApiDataConversionService apiDataConversionService, final PortfolioApiDataConversionService apiDataConversionService,
final PortfolioCommandSerializerService commandSerializerService, final PortfolioCommandSerializerService commandSerializerService,
final PortfolioCommandDeserializerService commandDeserializerService, final ConfigurationWritePlatformService writePlatformService) { final PortfolioCommandDeserializerService commandDeserializerService, final CurrencyWritePlatformService writePlatformService) {
this.context = context; this.context = context;
this.changeDetectionService = changeDetectionService; this.changeDetectionService = changeDetectionService;
this.apiDataConversionService = apiDataConversionService; this.apiDataConversionService = apiDataConversionService;
@@ -4,9 +4,7 @@ import java.util.Arrays;
import java.util.List; import java.util.List;
import org.joda.time.LocalDate; import org.joda.time.LocalDate;
import org.mifosng.platform.api.infrastructure.PortfolioApiDataConversionService;
import org.mifosng.platform.api.infrastructure.PortfolioCommandDeserializerService; import org.mifosng.platform.api.infrastructure.PortfolioCommandDeserializerService;
import org.mifosng.platform.api.infrastructure.PortfolioCommandSerializerService;
import org.mifosng.platform.client.service.RollbackTransactionAsCommandIsNotApprovedByCheckerException; import org.mifosng.platform.client.service.RollbackTransactionAsCommandIsNotApprovedByCheckerException;
import org.mifosng.platform.infrastructure.errorhandling.UnsupportedCommandException; import org.mifosng.platform.infrastructure.errorhandling.UnsupportedCommandException;
import org.mifosplatform.commands.domain.CommandSource; import org.mifosplatform.commands.domain.CommandSource;
@@ -24,20 +22,14 @@ public class RoleCommandHandler implements CommandSourceHandler {
private final PlatformSecurityContext context; private final PlatformSecurityContext context;
private final ChangeDetectionService changeDetectionService; private final ChangeDetectionService changeDetectionService;
private final PortfolioApiDataConversionService apiDataConversionService;
private final PortfolioCommandSerializerService commandSerializerService;
private final PortfolioCommandDeserializerService commandDeserializerService; private final PortfolioCommandDeserializerService commandDeserializerService;
private final RoleWritePlatformService writePlatformService; private final RoleWritePlatformService writePlatformService;
@Autowired @Autowired
public RoleCommandHandler(final PlatformSecurityContext context, final ChangeDetectionService changeDetectionService, public RoleCommandHandler(final PlatformSecurityContext context, final ChangeDetectionService changeDetectionService,
final PortfolioApiDataConversionService apiDataConversionService,
final PortfolioCommandSerializerService commandSerializerService,
final PortfolioCommandDeserializerService commandDeserializerService, final RoleWritePlatformService writePlatformService) { final PortfolioCommandDeserializerService commandDeserializerService, final RoleWritePlatformService writePlatformService) {
this.context = context; this.context = context;
this.changeDetectionService = changeDetectionService; this.changeDetectionService = changeDetectionService;
this.apiDataConversionService = apiDataConversionService;
this.commandSerializerService = commandSerializerService;
this.commandDeserializerService = commandDeserializerService; this.commandDeserializerService = commandDeserializerService;
this.writePlatformService = writePlatformService; this.writePlatformService = writePlatformService;
} }
@@ -48,7 +40,7 @@ public class RoleCommandHandler implements CommandSourceHandler {
* 'creator' is also marked 'as the checker' and command automatically is * 'creator' is also marked 'as the checker' and command automatically is
* processed and changes state of system. * processed and changes state of system.
*/ */
public CommandSource handle(final CommandSource commandSource, final String apiRequestBodyInJson) { public CommandSource handle(final CommandSource commandSource, final String commandSerializedAsJson) {
final AppUser maker = context.authenticatedUser(); final AppUser maker = context.authenticatedUser();
final LocalDate asToday = new LocalDate(); final LocalDate asToday = new LocalDate();
@@ -60,12 +52,10 @@ public class RoleCommandHandler implements CommandSourceHandler {
if (commandSource.isCreate()) { if (commandSource.isCreate()) {
try { try {
final RoleCommand command = this.apiDataConversionService.convertApiRequestJsonToRoleCommand(resourceId, final RoleCommand command = this.commandDeserializerService.deserializeRoleCommand(resourceId, commandSource.json(), false);
apiRequestBodyInJson);
final String commandSerializedAsJson = this.commandSerializerService.serializeRoleCommandToJson(command);
commandSourceResult.updateJsonTo(commandSerializedAsJson);
newResourceId = this.writePlatformService.createRole(command); newResourceId = this.writePlatformService.createRole(command);
commandSourceResult.markAsChecked(maker, asToday); commandSourceResult.markAsChecked(maker, asToday);
commandSourceResult.updateResourceId(newResourceId); commandSourceResult.updateResourceId(newResourceId);
} catch (RollbackTransactionAsCommandIsNotApprovedByCheckerException e) { } catch (RollbackTransactionAsCommandIsNotApprovedByCheckerException e) {
@@ -73,13 +63,8 @@ public class RoleCommandHandler implements CommandSourceHandler {
} }
} else if (commandSource.isUpdate()) { } else if (commandSource.isUpdate()) {
try { try {
final RoleCommand command = this.apiDataConversionService.convertApiRequestJsonToRoleCommand(resourceId,
apiRequestBodyInJson);
final String commandSerializedAsJson = this.commandSerializerService.serializeRoleCommandToJson(command);
commandSourceResult.updateJsonTo(commandSerializedAsJson);
final String jsonOfChangesOnly = this.changeDetectionService.detectChangesOnUpdate(commandSource.resourceName(), final String jsonOfChangesOnly = this.changeDetectionService.detectChangesOnUpdate(commandSource.resourceName(),
commandSource.resourceId(), commandSerializedAsJson); commandSource.resourceId(), commandSource.json());
commandSourceResult.updateJsonTo(jsonOfChangesOnly); commandSourceResult.updateJsonTo(jsonOfChangesOnly);
final RoleCommand changesOnly = this.commandDeserializerService final RoleCommand changesOnly = this.commandDeserializerService
@@ -93,13 +78,8 @@ public class RoleCommandHandler implements CommandSourceHandler {
} }
} else if (commandSource.isUpdateRolePermissions()) { } else if (commandSource.isUpdateRolePermissions()) {
try { try {
final RolePermissionCommand command = this.apiDataConversionService.convertApiRequestJsonToRolePermissionCommand(
resourceId, apiRequestBodyInJson);
final String commandSerializedAsJson = this.commandSerializerService.serializeRolePermissionCommandToJson(command);
commandSourceResult.updateJsonTo(commandSerializedAsJson);
final String jsonOfChangesOnly = this.changeDetectionService.detectChangesOnUpdate(commandSource.resourceName(), final String jsonOfChangesOnly = this.changeDetectionService.detectChangesOnUpdate(commandSource.resourceName(),
commandSource.resourceId(), commandSerializedAsJson); commandSource.resourceId(), commandSource.json());
commandSourceResult.updateJsonTo(jsonOfChangesOnly); commandSourceResult.updateJsonTo(jsonOfChangesOnly);
final RolePermissionCommand changesOnly = this.commandDeserializerService.deserializeRolePermissionCommand(resourceId, final RolePermissionCommand changesOnly = this.commandDeserializerService.deserializeRolePermissionCommand(resourceId,
@@ -124,38 +104,34 @@ public class RoleCommandHandler implements CommandSourceHandler {
final AppUser checker = context.authenticatedUser(); final AppUser checker = context.authenticatedUser();
Long resourceId = commandSourceResult.resourceId(); Long resourceId = commandSourceResult.resourceId();
if (commandSourceResult.isRoleResource()) { if (commandSourceResult.isCreate()) {
if (commandSourceResult.isCreate()) { final List<String> allowedPermissions = Arrays.asList("ALL_FUNCTIONS", "USER_ADMINISTRATION_SUPER_USER", "CREATE_ROLE_CHECKER");
final List<String> allowedPermissions = Arrays.asList("ALL_FUNCTIONS", "USER_ADMINISTRATION_SUPER_USER", context.authenticatedUser().validateHasPermissionTo("CREATE_ROLE_CHECKER", allowedPermissions);
"CREATE_ROLE_CHECKER");
context.authenticatedUser().validateHasPermissionTo("CREATE_ROLE_CHECKER", allowedPermissions);
final RoleCommand command = this.commandDeserializerService.deserializeRoleCommand(resourceId, commandSourceResult.json(), final RoleCommand command = this.commandDeserializerService
true); .deserializeRoleCommand(resourceId, commandSourceResult.json(), true);
resourceId = this.writePlatformService.createRole(command); resourceId = this.writePlatformService.createRole(command);
commandSourceResult.markAsChecked(checker, new LocalDate()); commandSourceResult.updateResourceId(resourceId);
} else if (commandSourceResult.isUpdate()) { commandSourceResult.markAsChecked(checker, new LocalDate());
final List<String> allowedPermissions = Arrays.asList("ALL_FUNCTIONS", "USER_ADMINISTRATION_SUPER_USER",
"UPDATE_ROLE_CHECKER");
context.authenticatedUser().validateHasPermissionTo("UPDATE_ROLE_CHECKER", allowedPermissions);
final RoleCommand command = this.commandDeserializerService.deserializeRoleCommand(resourceId, commandSourceResult.json(), } else if (commandSourceResult.isUpdate()) {
true); final List<String> allowedPermissions = Arrays.asList("ALL_FUNCTIONS", "USER_ADMINISTRATION_SUPER_USER", "UPDATE_ROLE_CHECKER");
resourceId = this.writePlatformService.updateRole(command); context.authenticatedUser().validateHasPermissionTo("UPDATE_ROLE_CHECKER", allowedPermissions);
commandSourceResult.markAsChecked(checker, new LocalDate());
} else if (commandSourceResult.isUpdateRolePermissions()) {
final List<String> allowedPermissions = Arrays.asList("ALL_FUNCTIONS", "USER_ADMINISTRATION_SUPER_USER",
"PERMISSIONS_ROLE_CHECKER");
context.authenticatedUser().validateHasPermissionTo("PERMISSIONS_ROLE_CHECKER", allowedPermissions);
final RolePermissionCommand command = this.commandDeserializerService.deserializeRolePermissionCommand(resourceId, final RoleCommand command = this.commandDeserializerService
commandSourceResult.json(), true); .deserializeRoleCommand(resourceId, commandSourceResult.json(), true);
resourceId = this.writePlatformService.updateRolePermissions(command); resourceId = this.writePlatformService.updateRole(command);
commandSourceResult.markAsChecked(checker, new LocalDate()); commandSourceResult.markAsChecked(checker, new LocalDate());
} else if (commandSourceResult.isDelete()) { throw new UnsupportedCommandException(commandSourceResult.commandName()); } } else if (commandSourceResult.isUpdateRolePermissions()) {
} final List<String> allowedPermissions = Arrays.asList("ALL_FUNCTIONS", "USER_ADMINISTRATION_SUPER_USER",
"PERMISSIONS_ROLE_CHECKER");
context.authenticatedUser().validateHasPermissionTo("PERMISSIONS_ROLE_CHECKER", allowedPermissions);
commandSourceResult.updateResourceId(resourceId); final RolePermissionCommand command = this.commandDeserializerService.deserializeRolePermissionCommand(resourceId,
commandSourceResult.json(), true);
resourceId = this.writePlatformService.updateRolePermissions(command);
commandSourceResult.markAsChecked(checker, new LocalDate());
} else if (commandSourceResult.isDelete()) { throw new UnsupportedCommandException(commandSourceResult.commandName()); }
return commandSourceResult; return commandSourceResult;
} }
@@ -4,6 +4,7 @@ import org.mifosng.platform.api.commands.ClientCommand;
import org.mifosng.platform.api.data.ClientData; import org.mifosng.platform.api.data.ClientData;
import org.mifosng.platform.api.infrastructure.PortfolioApiDataConversionService; import org.mifosng.platform.api.infrastructure.PortfolioApiDataConversionService;
import org.mifosng.platform.api.infrastructure.PortfolioApiJsonSerializerService; import org.mifosng.platform.api.infrastructure.PortfolioApiJsonSerializerService;
import org.mifosng.platform.api.infrastructure.PortfolioCommandSerializerService;
import org.mifosng.platform.client.service.ClientReadPlatformService; import org.mifosng.platform.client.service.ClientReadPlatformService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@@ -14,11 +15,16 @@ public class ChangeDetectionServiceJdbc implements ChangeDetectionService {
private final PortfolioApiDataConversionService apiDataConversionService; private final PortfolioApiDataConversionService apiDataConversionService;
private final PortfolioApiJsonSerializerService apiJsonSerializerService; private final PortfolioApiJsonSerializerService apiJsonSerializerService;
private final ClientReadPlatformService clientReadPlatformService; private final ClientReadPlatformService clientReadPlatformService;
private final PortfolioCommandSerializerService commandSerializerService;
@Autowired @Autowired
public ChangeDetectionServiceJdbc(final PortfolioApiDataConversionService apiDataConversionService, public ChangeDetectionServiceJdbc(
final PortfolioApiJsonSerializerService apiJsonSerializerService, final ClientReadPlatformService clientReadPlatformService) { final PortfolioApiDataConversionService apiDataConversionService,
final PortfolioCommandSerializerService commandSerializerService,
final PortfolioApiJsonSerializerService apiJsonSerializerService,
final ClientReadPlatformService clientReadPlatformService) {
this.apiDataConversionService = apiDataConversionService; this.apiDataConversionService = apiDataConversionService;
this.commandSerializerService = commandSerializerService;
this.apiJsonSerializerService = apiJsonSerializerService; this.apiJsonSerializerService = apiJsonSerializerService;
this.clientReadPlatformService = clientReadPlatformService; this.clientReadPlatformService = clientReadPlatformService;
} }
@@ -40,7 +46,7 @@ public class ChangeDetectionServiceJdbc implements ChangeDetectionService {
final String workingJson = this.apiJsonSerializerService.serializeClientDataToJson(changedClient); final String workingJson = this.apiJsonSerializerService.serializeClientDataToJson(changedClient);
final ClientCommand changesOnly = this.apiDataConversionService.detectChanges(resourceId, baseJson, workingJson); final ClientCommand changesOnly = this.apiDataConversionService.detectChanges(resourceId, baseJson, workingJson);
changesOnlyJson = this.apiJsonSerializerService.serializeClientCommandToJson(changesOnly); changesOnlyJson = this.commandSerializerService.serializeCommandToJson(changesOnly);
} else { } else {
changesOnlyJson = commandSerializedAsJson; changesOnlyJson = commandSerializedAsJson;
} }
@@ -4,7 +4,7 @@ import org.mifosng.platform.api.data.EntityIdentifier;
public interface PortfolioCommandSourceWritePlatformService { public interface PortfolioCommandSourceWritePlatformService {
EntityIdentifier logCommandSource(String apiOperation, String resource, Long resourceId, String jsonRequestBody); EntityIdentifier logCommandSource(String apiOperation, String resource, Long resourceId, String commandSerializedAsJson);
EntityIdentifier approveEntry(Long id); EntityIdentifier approveEntry(Long id);
@@ -29,13 +29,13 @@ public class PortfolioCommandSourceWritePlatformServiceImpl implements Portfolio
// NOT TRANSACTIONAL BY DESIGN FOR NOW // NOT TRANSACTIONAL BY DESIGN FOR NOW
@Override @Override
public EntityIdentifier logCommandSource(final String apiOperation, final String resource, final Long resourceId, public EntityIdentifier logCommandSource(final String apiOperation, final String resource, final Long resourceId,
final String apiRequestBodyInJson) { final String commandSerializedAsJson) {
final AppUser maker = context.authenticatedUser(); final AppUser maker = context.authenticatedUser();
final LocalDate asToday = new LocalDate(); final LocalDate asToday = new LocalDate();
final CommandSource commandSourceInput = CommandSource.createdBy(apiOperation, resource, resourceId, maker, asToday); final CommandSource commandSourceInput = CommandSource.createdBy(apiOperation, resource, resourceId, commandSerializedAsJson, maker, asToday);
final CommandSource commandSourceResult = this.commandSourceHandlerDelegator.handle(commandSourceInput, apiRequestBodyInJson); final CommandSource commandSourceResult = this.commandSourceHandlerDelegator.handle(commandSourceInput, commandSerializedAsJson);
commandSourceRepository.save(commandSourceResult); commandSourceRepository.save(commandSourceResult);
return EntityIdentifier.makerChecker(commandSourceResult.resourceId(), commandSourceResult.getId()); return EntityIdentifier.makerChecker(commandSourceResult.resourceId(), commandSourceResult.getId());
@@ -8,9 +8,8 @@ import org.mifosplatform.infrastructure.codes.domain.Code;
import org.mifosplatform.infrastructure.codes.domain.CodeRepository; import org.mifosplatform.infrastructure.codes.domain.CodeRepository;
import org.mifosplatform.infrastructure.codes.exception.CodeNotFoundException; import org.mifosplatform.infrastructure.codes.exception.CodeNotFoundException;
import org.mifosplatform.infrastructure.codes.exception.SystemDefinedCodeCannotBeChangedException; import org.mifosplatform.infrastructure.codes.exception.SystemDefinedCodeCannotBeChangedException;
import org.mifosplatform.infrastructure.configuration.service.ConfigurationDomainService;
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext; import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
import org.mifosplatform.infrastructure.user.domain.Permission;
import org.mifosplatform.infrastructure.user.domain.PermissionRepository;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@@ -25,14 +24,15 @@ public class CodeWritePlatformServiceJpaRepositoryImpl implements CodeWritePlatf
private final PlatformSecurityContext context; private final PlatformSecurityContext context;
private final CodeRepository codeRepository; private final CodeRepository codeRepository;
private final PermissionRepository permissionRepository;
private final ConfigurationDomainService configurationDomainService;
@Autowired @Autowired
public CodeWritePlatformServiceJpaRepositoryImpl(final PlatformSecurityContext context, final CodeRepository codeRepository, public CodeWritePlatformServiceJpaRepositoryImpl(final PlatformSecurityContext context, final CodeRepository codeRepository,
final PermissionRepository permissionRepository) { final ConfigurationDomainService configurationDomainService) {
this.context = context; this.context = context;
this.codeRepository = codeRepository; this.codeRepository = codeRepository;
this.permissionRepository = permissionRepository; this.configurationDomainService = configurationDomainService;
} }
@Transactional @Transactional
@@ -47,9 +47,8 @@ public class CodeWritePlatformServiceJpaRepositoryImpl implements CodeWritePlatf
this.codeRepository.save(code); this.codeRepository.save(code);
final Permission thisTask = this.permissionRepository.findOneByCode("CREATE_CODE"); if (this.configurationDomainService.isMakerCheckerEnabledForTask("CREATE_CODE") && !command.isApprovedByChecker()) { throw new RollbackTransactionAsCommandIsNotApprovedByCheckerException(); }
if (thisTask.hasMakerCheckerEnabled() && !command.isApprovedByChecker()) { throw new RollbackTransactionAsCommandIsNotApprovedByCheckerException(); }
return code.getId(); return code.getId();
} catch (DataIntegrityViolationException dve) { } catch (DataIntegrityViolationException dve) {
return Long.valueOf(-1); return Long.valueOf(-1);
@@ -69,9 +68,8 @@ public class CodeWritePlatformServiceJpaRepositoryImpl implements CodeWritePlatf
this.codeRepository.save(code); this.codeRepository.save(code);
final Permission thisTask = this.permissionRepository.findOneByCode("UPDATE_CODE"); if (this.configurationDomainService.isMakerCheckerEnabledForTask("UPDATE_CODE") && !command.isApprovedByChecker()) { throw new RollbackTransactionAsCommandIsNotApprovedByCheckerException(); }
if (thisTask.hasMakerCheckerEnabled() && !command.isApprovedByChecker()) { throw new RollbackTransactionAsCommandIsNotApprovedByCheckerException(); }
return code.getId(); return code.getId();
} catch (DataIntegrityViolationException dve) { } catch (DataIntegrityViolationException dve) {
handleCodeDataIntegrityIssues(command, dve); handleCodeDataIntegrityIssues(command, dve);
@@ -106,9 +104,8 @@ public class CodeWritePlatformServiceJpaRepositoryImpl implements CodeWritePlatf
this.codeRepository.delete(code); this.codeRepository.delete(code);
final Permission thisTask = this.permissionRepository.findOneByCode("DELETE_CODE"); if (this.configurationDomainService.isMakerCheckerEnabledForTask("DELETE_CODE") && !command.isApprovedByChecker()) { throw new RollbackTransactionAsCommandIsNotApprovedByCheckerException(); }
if (thisTask.hasMakerCheckerEnabled() && !command.isApprovedByChecker()) { throw new RollbackTransactionAsCommandIsNotApprovedByCheckerException(); }
return new EntityIdentifier(code.getId()); return new EntityIdentifier(code.getId());
} }
@@ -18,7 +18,7 @@ import org.mifosng.platform.api.infrastructure.PortfolioApiJsonSerializerService
import org.mifosng.platform.infrastructure.api.ApiParameterHelper; import org.mifosng.platform.infrastructure.api.ApiParameterHelper;
import org.mifosplatform.commands.service.PortfolioCommandSourceWritePlatformService; import org.mifosplatform.commands.service.PortfolioCommandSourceWritePlatformService;
import org.mifosplatform.infrastructure.configuration.data.ConfigurationData; import org.mifosplatform.infrastructure.configuration.data.ConfigurationData;
import org.mifosplatform.infrastructure.configuration.service.ConfigurationReadPlatformService; import org.mifosplatform.infrastructure.configuration.service.OrganisationCurrencyReadPlatformService;
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext; import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope; import org.springframework.context.annotation.Scope;
@@ -32,13 +32,13 @@ public class CurrenciesApiResource {
private final String resourceNameForPermissions = "CURRENCY"; private final String resourceNameForPermissions = "CURRENCY";
private final PlatformSecurityContext context; private final PlatformSecurityContext context;
private final ConfigurationReadPlatformService readPlatformService; private final OrganisationCurrencyReadPlatformService readPlatformService;
private final PortfolioApiJsonSerializerService apiJsonSerializerService; private final PortfolioApiJsonSerializerService apiJsonSerializerService;
private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService; private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService;
@Autowired @Autowired
public CurrenciesApiResource(final PlatformSecurityContext context, public CurrenciesApiResource(final PlatformSecurityContext context,
final ConfigurationReadPlatformService readPlatformService, final OrganisationCurrencyReadPlatformService readPlatformService,
final PortfolioApiJsonSerializerService apiJsonSerializerService, final PortfolioApiJsonSerializerService apiJsonSerializerService,
final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService) { final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService) {
this.context = context; this.context = context;
@@ -0,0 +1,7 @@
package org.mifosplatform.infrastructure.configuration.service;
public interface ConfigurationDomainService {
boolean isMakerCheckerEnabledForTask(String taskPermissionCode);
}
@@ -0,0 +1,33 @@
package org.mifosplatform.infrastructure.configuration.service;
import org.mifosplatform.infrastructure.user.domain.Permission;
import org.mifosplatform.infrastructure.user.domain.PermissionRepository;
import org.mifosplatform.infrastructure.user.exception.PermissionNotFoundException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class ConfigurationDomainServiceJpa implements ConfigurationDomainService {
private final PermissionRepository permissionRepository;
/*
* hard code to false to disable maker checker across the board.
*/
private final boolean makerCheckerGloablConfigurationEnabled = false;
@Autowired
public ConfigurationDomainServiceJpa(final PermissionRepository permissionRepository) {
this.permissionRepository = permissionRepository;
}
@Override
public boolean isMakerCheckerEnabledForTask(final String taskPermissionCode) {
final Permission thisTask = this.permissionRepository.findOneByCode(taskPermissionCode);
if (thisTask == null) {
throw new PermissionNotFoundException(taskPermissionCode);
}
return thisTask.hasMakerCheckerEnabled() && this.makerCheckerGloablConfigurationEnabled;
}
}
@@ -2,7 +2,7 @@ package org.mifosplatform.infrastructure.configuration.service;
import org.mifosplatform.infrastructure.configuration.command.CurrencyCommand; import org.mifosplatform.infrastructure.configuration.command.CurrencyCommand;
public interface ConfigurationWritePlatformService { public interface CurrencyWritePlatformService {
void updateAllowedCurrencies(CurrencyCommand command); void updateAllowedCurrencies(CurrencyCommand command);
@@ -15,29 +15,26 @@ import org.mifosplatform.infrastructure.configuration.domain.ApplicationCurrency
import org.mifosplatform.infrastructure.office.domain.OrganisationCurrency; import org.mifosplatform.infrastructure.office.domain.OrganisationCurrency;
import org.mifosplatform.infrastructure.office.domain.OrganisationCurrencyRepository; import org.mifosplatform.infrastructure.office.domain.OrganisationCurrencyRepository;
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext; import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
import org.mifosplatform.infrastructure.user.domain.Permission;
import org.mifosplatform.infrastructure.user.domain.PermissionRepository;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
@Service @Service
public class ConfigurationWritePlatformServiceJpaRepositoryImpl implements ConfigurationWritePlatformService { public class CurrencyWritePlatformServiceJpaRepositoryImpl implements CurrencyWritePlatformService {
private final PlatformSecurityContext context; private final PlatformSecurityContext context;
private final ApplicationCurrencyRepository applicationCurrencyRepository; private final ApplicationCurrencyRepository applicationCurrencyRepository;
private final OrganisationCurrencyRepository organisationCurrencyRepository; private final OrganisationCurrencyRepository organisationCurrencyRepository;
private final PermissionRepository permissionRepository; private final ConfigurationDomainService configurationDomainService;
@Autowired @Autowired
public ConfigurationWritePlatformServiceJpaRepositoryImpl(final PlatformSecurityContext context, public CurrencyWritePlatformServiceJpaRepositoryImpl(final PlatformSecurityContext context,
final ApplicationCurrencyRepository applicationCurrencyRepository, final ApplicationCurrencyRepository applicationCurrencyRepository,
final OrganisationCurrencyRepository organisationCurrencyRepository, final OrganisationCurrencyRepository organisationCurrencyRepository, final ConfigurationDomainService configurationDomainService) {
final PermissionRepository permissionRepository) {
this.context = context; this.context = context;
this.applicationCurrencyRepository = applicationCurrencyRepository; this.applicationCurrencyRepository = applicationCurrencyRepository;
this.organisationCurrencyRepository = organisationCurrencyRepository; this.organisationCurrencyRepository = organisationCurrencyRepository;
this.permissionRepository = permissionRepository; this.configurationDomainService = configurationDomainService;
} }
@Transactional @Transactional
@@ -72,9 +69,8 @@ public class ConfigurationWritePlatformServiceJpaRepositoryImpl implements Confi
this.organisationCurrencyRepository.deleteAll(); this.organisationCurrencyRepository.deleteAll();
this.organisationCurrencyRepository.save(allowedCurrencies); this.organisationCurrencyRepository.save(allowedCurrencies);
final Permission thisTask = this.permissionRepository.findOneByCode("UPDATE_CURRENCY"); if (this.configurationDomainService.isMakerCheckerEnabledForTask("UPDATE_CURRENCY") && !command.isApprovedByChecker()) { throw new RollbackTransactionAsCommandIsNotApprovedByCheckerException(); }
if (thisTask.hasMakerCheckerEnabled() && !command.isApprovedByChecker()) { throw new RollbackTransactionAsCommandIsNotApprovedByCheckerException(); }
if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist", if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist",
"Validation errors exist.", dataValidationErrors); } "Validation errors exist.", dataValidationErrors); }
@@ -2,7 +2,7 @@ package org.mifosplatform.infrastructure.configuration.service;
import org.mifosplatform.infrastructure.configuration.data.ConfigurationData; import org.mifosplatform.infrastructure.configuration.data.ConfigurationData;
public interface ConfigurationReadPlatformService { public interface OrganisationCurrencyReadPlatformService {
ConfigurationData retrieveCurrencyConfiguration(); ConfigurationData retrieveCurrencyConfiguration();
@@ -8,12 +8,12 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@Service @Service
public class ConfigurationReadPlatformServiceImpl implements ConfigurationReadPlatformService { public class OrganisationCurrencyReadPlatformServiceImpl implements OrganisationCurrencyReadPlatformService {
private final CurrencyReadPlatformService currencyReadPlatformService; private final CurrencyReadPlatformService currencyReadPlatformService;
@Autowired @Autowired
public ConfigurationReadPlatformServiceImpl(final CurrencyReadPlatformService currencyReadPlatformService) { public OrganisationCurrencyReadPlatformServiceImpl(final CurrencyReadPlatformService currencyReadPlatformService) {
this.currencyReadPlatformService = currencyReadPlatformService; this.currencyReadPlatformService = currencyReadPlatformService;
} }
@@ -9,6 +9,7 @@ import org.mifosplatform.infrastructure.configuration.domain.ApplicationCurrency
import org.mifosplatform.infrastructure.configuration.domain.ApplicationCurrencyRepository; import org.mifosplatform.infrastructure.configuration.domain.ApplicationCurrencyRepository;
import org.mifosplatform.infrastructure.configuration.domain.MonetaryCurrency; import org.mifosplatform.infrastructure.configuration.domain.MonetaryCurrency;
import org.mifosplatform.infrastructure.configuration.domain.Money; import org.mifosplatform.infrastructure.configuration.domain.Money;
import org.mifosplatform.infrastructure.configuration.service.ConfigurationDomainService;
import org.mifosplatform.infrastructure.office.command.BranchMoneyTransferCommand; import org.mifosplatform.infrastructure.office.command.BranchMoneyTransferCommand;
import org.mifosplatform.infrastructure.office.command.OfficeCommand; import org.mifosplatform.infrastructure.office.command.OfficeCommand;
import org.mifosplatform.infrastructure.office.domain.Office; import org.mifosplatform.infrastructure.office.domain.Office;
@@ -17,8 +18,6 @@ import org.mifosplatform.infrastructure.office.domain.OfficeTransaction;
import org.mifosplatform.infrastructure.office.domain.OfficeTransactionRepository; import org.mifosplatform.infrastructure.office.domain.OfficeTransactionRepository;
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext; import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
import org.mifosplatform.infrastructure.user.domain.AppUser; import org.mifosplatform.infrastructure.user.domain.AppUser;
import org.mifosplatform.infrastructure.user.domain.Permission;
import org.mifosplatform.infrastructure.user.domain.PermissionRepository;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@@ -35,17 +34,17 @@ public class OfficeWritePlatformServiceJpaRepositoryImpl implements OfficeWriteP
private final OfficeRepository officeRepository; private final OfficeRepository officeRepository;
private final OfficeTransactionRepository officeMonetaryTransferRepository; private final OfficeTransactionRepository officeMonetaryTransferRepository;
private final ApplicationCurrencyRepository applicationCurrencyRepository; private final ApplicationCurrencyRepository applicationCurrencyRepository;
private final PermissionRepository permissionRepository; private final ConfigurationDomainService configurationDomainService;
@Autowired @Autowired
public OfficeWritePlatformServiceJpaRepositoryImpl(final PlatformSecurityContext context, final OfficeRepository officeRepository, public OfficeWritePlatformServiceJpaRepositoryImpl(final PlatformSecurityContext context, final OfficeRepository officeRepository,
final OfficeTransactionRepository officeMonetaryTransferRepository, final OfficeTransactionRepository officeMonetaryTransferRepository,
final ApplicationCurrencyRepository applicationCurrencyRepository, final PermissionRepository permissionRepository) { final ApplicationCurrencyRepository applicationCurrencyRepository, final ConfigurationDomainService configurationDomainService) {
this.context = context; this.context = context;
this.officeRepository = officeRepository; this.officeRepository = officeRepository;
this.officeMonetaryTransferRepository = officeMonetaryTransferRepository; this.officeMonetaryTransferRepository = officeMonetaryTransferRepository;
this.applicationCurrencyRepository = applicationCurrencyRepository; this.applicationCurrencyRepository = applicationCurrencyRepository;
this.permissionRepository = permissionRepository; this.configurationDomainService = configurationDomainService;
} }
@Transactional @Transactional
@@ -66,9 +65,8 @@ public class OfficeWritePlatformServiceJpaRepositoryImpl implements OfficeWriteP
office.generateHierarchy(); office.generateHierarchy();
this.officeRepository.save(office); this.officeRepository.save(office);
final Permission thisTask = this.permissionRepository.findOneByCode("CREATE_OFFICE"); if (this.configurationDomainService.isMakerCheckerEnabledForTask("CREATE_OFFICE") && !command.isApprovedByChecker()) { throw new RollbackTransactionAsCommandIsNotApprovedByCheckerException(); }
if (thisTask.hasMakerCheckerEnabled() && !command.isApprovedByChecker()) { throw new RollbackTransactionAsCommandIsNotApprovedByCheckerException(); }
return office.getId(); return office.getId();
} catch (DataIntegrityViolationException dve) { } catch (DataIntegrityViolationException dve) {
@@ -95,9 +93,8 @@ public class OfficeWritePlatformServiceJpaRepositoryImpl implements OfficeWriteP
} }
this.officeRepository.save(office); this.officeRepository.save(office);
final Permission thisTask = this.permissionRepository.findOneByCode("UPDATE_OFFICE"); if (this.configurationDomainService.isMakerCheckerEnabledForTask("UPDATE_OFFICE") && !command.isApprovedByChecker()) { throw new RollbackTransactionAsCommandIsNotApprovedByCheckerException(); }
if (thisTask.hasMakerCheckerEnabled() && !command.isApprovedByChecker()) { throw new RollbackTransactionAsCommandIsNotApprovedByCheckerException(); }
return office.getId(); return office.getId();
} catch (DataIntegrityViolationException dve) { } catch (DataIntegrityViolationException dve) {
@@ -135,9 +132,8 @@ public class OfficeWritePlatformServiceJpaRepositoryImpl implements OfficeWriteP
command.getDescription()); command.getDescription());
this.officeMonetaryTransferRepository.save(entity); this.officeMonetaryTransferRepository.save(entity);
final Permission thisTask = this.permissionRepository.findOneByCode("CREATE_OFFICETRANSACTION"); if (this.configurationDomainService.isMakerCheckerEnabledForTask("CREATE_OFFICETRANSACTION") && !command.isApprovedByChecker()) { throw new RollbackTransactionAsCommandIsNotApprovedByCheckerException(); }
if (thisTask.hasMakerCheckerEnabled() && !command.isApprovedByChecker()) { throw new RollbackTransactionAsCommandIsNotApprovedByCheckerException(); }
return entity.getId(); return entity.getId();
} }
@@ -5,14 +5,13 @@ import org.mifosng.platform.client.service.RollbackTransactionAsCommandIsNotAppr
import org.mifosng.platform.exceptions.OfficeNotFoundException; import org.mifosng.platform.exceptions.OfficeNotFoundException;
import org.mifosng.platform.exceptions.PlatformDataIntegrityException; import org.mifosng.platform.exceptions.PlatformDataIntegrityException;
import org.mifosng.platform.exceptions.StaffNotFoundException; import org.mifosng.platform.exceptions.StaffNotFoundException;
import org.mifosplatform.infrastructure.configuration.service.ConfigurationDomainService;
import org.mifosplatform.infrastructure.office.domain.Office; import org.mifosplatform.infrastructure.office.domain.Office;
import org.mifosplatform.infrastructure.office.domain.OfficeRepository; import org.mifosplatform.infrastructure.office.domain.OfficeRepository;
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext; import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
import org.mifosplatform.infrastructure.staff.command.StaffCommand; import org.mifosplatform.infrastructure.staff.command.StaffCommand;
import org.mifosplatform.infrastructure.staff.domain.Staff; import org.mifosplatform.infrastructure.staff.domain.Staff;
import org.mifosplatform.infrastructure.staff.domain.StaffRepository; import org.mifosplatform.infrastructure.staff.domain.StaffRepository;
import org.mifosplatform.infrastructure.user.domain.Permission;
import org.mifosplatform.infrastructure.user.domain.PermissionRepository;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@@ -28,15 +27,15 @@ public class StaffWritePlatformServiceJpaRepositoryImpl implements StaffWritePla
private final PlatformSecurityContext context; private final PlatformSecurityContext context;
private final StaffRepository staffRepository; private final StaffRepository staffRepository;
private final OfficeRepository officeRepository; private final OfficeRepository officeRepository;
private final PermissionRepository permissionRepository; private final ConfigurationDomainService configurationDomainService;
@Autowired @Autowired
public StaffWritePlatformServiceJpaRepositoryImpl(final PlatformSecurityContext context, final StaffRepository staffRepository, public StaffWritePlatformServiceJpaRepositoryImpl(final PlatformSecurityContext context, final StaffRepository staffRepository,
final OfficeRepository officeRepository, final PermissionRepository permissionRepository) { final OfficeRepository officeRepository, final ConfigurationDomainService configurationDomainService) {
this.context = context; this.context = context;
this.staffRepository = staffRepository; this.staffRepository = staffRepository;
this.officeRepository = officeRepository; this.officeRepository = officeRepository;
this.permissionRepository = permissionRepository; this.configurationDomainService = configurationDomainService;
} }
@Transactional @Transactional
@@ -54,8 +53,7 @@ public class StaffWritePlatformServiceJpaRepositoryImpl implements StaffWritePla
this.staffRepository.save(staff); this.staffRepository.save(staff);
final Permission thisTask = this.permissionRepository.findOneByCode("CREATE_STAFF"); if (this.configurationDomainService.isMakerCheckerEnabledForTask("CREATE_STAFF") && !command.isApprovedByChecker()) { throw new RollbackTransactionAsCommandIsNotApprovedByCheckerException(); }
if (thisTask.hasMakerCheckerEnabled() && !command.isApprovedByChecker()) { throw new RollbackTransactionAsCommandIsNotApprovedByCheckerException(); }
return staff.getId(); return staff.getId();
} catch (DataIntegrityViolationException dve) { } catch (DataIntegrityViolationException dve) {
@@ -87,8 +85,7 @@ public class StaffWritePlatformServiceJpaRepositoryImpl implements StaffWritePla
this.staffRepository.save(staff); this.staffRepository.save(staff);
final Permission thisTask = this.permissionRepository.findOneByCode("UPDATE_STAFF"); if (this.configurationDomainService.isMakerCheckerEnabledForTask("UPDATE_STAFF") && !command.isApprovedByChecker()) { throw new RollbackTransactionAsCommandIsNotApprovedByCheckerException(); }
if (thisTask.hasMakerCheckerEnabled() && !command.isApprovedByChecker()) { throw new RollbackTransactionAsCommandIsNotApprovedByCheckerException(); }
return staff.getId(); return staff.getId();
} catch (DataIntegrityViolationException dve) { } catch (DataIntegrityViolationException dve) {
@@ -18,8 +18,10 @@ import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.UriInfo; import javax.ws.rs.core.UriInfo;
import org.mifosng.platform.api.data.EntityIdentifier; 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.api.infrastructure.PortfolioApiJsonSerializerService;
import org.mifosng.platform.api.infrastructure.PortfolioCommandDeserializerService; import org.mifosng.platform.api.infrastructure.PortfolioCommandDeserializerService;
import org.mifosng.platform.api.infrastructure.PortfolioCommandSerializerService;
import org.mifosng.platform.infrastructure.api.ApiParameterHelper; import org.mifosng.platform.infrastructure.api.ApiParameterHelper;
import org.mifosplatform.commands.api.data.CommandSourceData; import org.mifosplatform.commands.api.data.CommandSourceData;
import org.mifosplatform.commands.service.PortfolioCommandSourceWritePlatformService; import org.mifosplatform.commands.service.PortfolioCommandSourceWritePlatformService;
@@ -45,6 +47,8 @@ public class RolesApiResource {
private final RoleReadPlatformService roleReadPlatformService; private final RoleReadPlatformService roleReadPlatformService;
private final PermissionReadPlatformService permissionReadPlatformService; private final PermissionReadPlatformService permissionReadPlatformService;
private final PortfolioApiJsonSerializerService apiJsonSerializerService; private final PortfolioApiJsonSerializerService apiJsonSerializerService;
private final PortfolioApiDataConversionService apiDataConversionService;
private final PortfolioCommandSerializerService commandSerializerService;
private final PortfolioCommandsReadPlatformService commandSourceReadPlatformService; private final PortfolioCommandsReadPlatformService commandSourceReadPlatformService;
private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService; private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService;
private final PortfolioCommandDeserializerService commandDeserializerService; private final PortfolioCommandDeserializerService commandDeserializerService;
@@ -57,6 +61,8 @@ public class RolesApiResource {
final RoleReadPlatformService readPlatformService, final RoleReadPlatformService readPlatformService,
final PermissionReadPlatformService permissionReadPlatformService, final PermissionReadPlatformService permissionReadPlatformService,
final PortfolioApiJsonSerializerService apiJsonSerializerService, final PortfolioApiJsonSerializerService apiJsonSerializerService,
final PortfolioApiDataConversionService apiDataConversionService,
final PortfolioCommandSerializerService commandSerializerService,
final PortfolioCommandsReadPlatformService commandSourceReadPlatformService, final PortfolioCommandsReadPlatformService commandSourceReadPlatformService,
final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService, final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService,
final PortfolioCommandDeserializerService commandDeserializerService) { final PortfolioCommandDeserializerService commandDeserializerService) {
@@ -64,6 +70,8 @@ public class RolesApiResource {
this.roleReadPlatformService = readPlatformService; this.roleReadPlatformService = readPlatformService;
this.permissionReadPlatformService = permissionReadPlatformService; this.permissionReadPlatformService = permissionReadPlatformService;
this.apiJsonSerializerService = apiJsonSerializerService; this.apiJsonSerializerService = apiJsonSerializerService;
this.apiDataConversionService = apiDataConversionService;
this.commandSerializerService = commandSerializerService;
this.commandSourceReadPlatformService = commandSourceReadPlatformService; this.commandSourceReadPlatformService = commandSourceReadPlatformService;
this.commandsSourceWritePlatformService = commandsSourceWritePlatformService; this.commandsSourceWritePlatformService = commandsSourceWritePlatformService;
this.commandDeserializerService = commandDeserializerService; this.commandDeserializerService = commandDeserializerService;
@@ -91,9 +99,12 @@ public class RolesApiResource {
final List<String> allowedPermissions = Arrays.asList("ALL_FUNCTIONS", "USER_ADMINISTRATION_SUPER_USER", "CREATE_ROLE"); final List<String> allowedPermissions = Arrays.asList("ALL_FUNCTIONS", "USER_ADMINISTRATION_SUPER_USER", "CREATE_ROLE");
context.authenticatedUser().validateHasPermissionTo("CREATE_ROLE", allowedPermissions); context.authenticatedUser().validateHasPermissionTo("CREATE_ROLE", allowedPermissions);
final RoleCommand command = this.apiDataConversionService.convertApiRequestJsonToRoleCommand(null,apiRequestBodyAsJson);
final String commandSerializedAsJson = this.commandSerializerService.serializeRoleCommandToJson(command);
final EntityIdentifier result = this.commandsSourceWritePlatformService.logCommandSource("CREATE", "roles", null, final EntityIdentifier result = this.commandsSourceWritePlatformService.logCommandSource("CREATE", "roles", null,
apiRequestBodyAsJson); commandSerializedAsJson);
return this.apiJsonSerializerService.serializeEntityIdentifier(result); return this.apiJsonSerializerService.serializeEntityIdentifier(result);
} }
@@ -140,8 +151,11 @@ public class RolesApiResource {
final List<String> allowedPermissions = Arrays.asList("ALL_FUNCTIONS", "USER_ADMINISTRATION_SUPER_USER", "UPDATE_ROLE"); final List<String> allowedPermissions = Arrays.asList("ALL_FUNCTIONS", "USER_ADMINISTRATION_SUPER_USER", "UPDATE_ROLE");
context.authenticatedUser().validateHasPermissionTo("UPDATE_ROLE", allowedPermissions); context.authenticatedUser().validateHasPermissionTo("UPDATE_ROLE", allowedPermissions);
final RoleCommand command = this.apiDataConversionService.convertApiRequestJsonToRoleCommand(roleId, apiRequestBodyAsJson);
final String commandSerializedAsJson = this.commandSerializerService.serializeRoleCommandToJson(command);
final EntityIdentifier result = this.commandsSourceWritePlatformService.logCommandSource("UPDATE", "roles", roleId, final EntityIdentifier result = this.commandsSourceWritePlatformService.logCommandSource("UPDATE", "roles", roleId,
apiRequestBodyAsJson); commandSerializedAsJson);
return this.apiJsonSerializerService.serializeEntityIdentifier(result); return this.apiJsonSerializerService.serializeEntityIdentifier(result);
} }
@@ -200,8 +214,11 @@ public class RolesApiResource {
final List<String> allowedPermissions = Arrays.asList("ALL_FUNCTIONS", "USER_ADMINISTRATION_SUPER_USER", "PERMISSIONS_ROLE"); final List<String> allowedPermissions = Arrays.asList("ALL_FUNCTIONS", "USER_ADMINISTRATION_SUPER_USER", "PERMISSIONS_ROLE");
context.authenticatedUser().validateHasPermissionTo("PERMISSIONS_ROLE", allowedPermissions); context.authenticatedUser().validateHasPermissionTo("PERMISSIONS_ROLE", allowedPermissions);
final RolePermissionCommand command = this.apiDataConversionService.convertApiRequestJsonToRolePermissionCommand(roleId, apiRequestBodyAsJson);
final String commandSerializedAsJson = this.commandSerializerService.serializeRolePermissionCommandToJson(command);
final EntityIdentifier result = this.commandsSourceWritePlatformService.logCommandSource("UPDATEPERMISSIONS", "roles", roleId, final EntityIdentifier result = this.commandsSourceWritePlatformService.logCommandSource("UPDATEPERMISSIONS", "roles", roleId,
apiRequestBodyAsJson); commandSerializedAsJson);
return this.apiJsonSerializerService.serializeEntityIdentifier(result); return this.apiJsonSerializerService.serializeEntityIdentifier(result);
} }
@@ -5,6 +5,7 @@ import org.mifosng.platform.infrastructure.EmailDetail;
import org.mifosng.platform.infrastructure.PlatformEmailService; import org.mifosng.platform.infrastructure.PlatformEmailService;
import org.mifosng.platform.infrastructure.PlatformPasswordEncoder; import org.mifosng.platform.infrastructure.PlatformPasswordEncoder;
import org.mifosng.platform.infrastructure.RandomPasswordGenerator; import org.mifosng.platform.infrastructure.RandomPasswordGenerator;
import org.mifosplatform.infrastructure.configuration.service.ConfigurationDomainService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
@@ -15,21 +16,21 @@ public class JpaUserDomainService implements UserDomainService {
private final AppUserRepository userRepository; private final AppUserRepository userRepository;
private final PlatformPasswordEncoder applicationPasswordEncoder; private final PlatformPasswordEncoder applicationPasswordEncoder;
private final PlatformEmailService emailService; private final PlatformEmailService emailService;
private final PermissionRepository permissionRepository; private final ConfigurationDomainService configurationDomainService;
@Autowired @Autowired
public JpaUserDomainService(final AppUserRepository userRepository, final PlatformPasswordEncoder applicationPasswordEncoder, public JpaUserDomainService(final AppUserRepository userRepository, final PlatformPasswordEncoder applicationPasswordEncoder,
final PlatformEmailService emailService, final PermissionRepository permissionRepository) { final PlatformEmailService emailService, final ConfigurationDomainService configurationDomainService) {
this.userRepository = userRepository; this.userRepository = userRepository;
this.applicationPasswordEncoder = applicationPasswordEncoder; this.applicationPasswordEncoder = applicationPasswordEncoder;
this.emailService = emailService; this.emailService = emailService;
this.permissionRepository = permissionRepository; this.configurationDomainService = configurationDomainService;
} }
@Transactional @Transactional
@Override @Override
public void create(final AppUser appUser, final boolean isApprovedByChecker) { public void create(final AppUser appUser, final boolean isApprovedByChecker) {
generateKeyUsedForPasswordSalting(appUser); generateKeyUsedForPasswordSalting(appUser);
String unencodedPassword = appUser.getPassword(); String unencodedPassword = appUser.getPassword();
@@ -42,11 +43,11 @@ public class JpaUserDomainService implements UserDomainService {
appUser.updatePassword(encodePassword); appUser.updatePassword(encodePassword);
this.userRepository.save(appUser); this.userRepository.save(appUser);
final Permission thisTask = this.permissionRepository.findOneByCode("CREATE_USER");
if (thisTask.hasMakerCheckerEnabled() && !isApprovedByChecker) { throw new RollbackTransactionAsCommandIsNotApprovedByCheckerException(); }
final EmailDetail emailDetail = new EmailDetail(appUser.getFirstname(), appUser.getFirstname(), appUser.getEmail(), appUser.getUsername()); if (this.configurationDomainService.isMakerCheckerEnabledForTask("CREATE_USER") && !isApprovedByChecker) { throw new RollbackTransactionAsCommandIsNotApprovedByCheckerException(); }
final EmailDetail emailDetail = new EmailDetail(appUser.getFirstname(), appUser.getFirstname(), appUser.getEmail(),
appUser.getUsername());
this.emailService.sendToUserAccount(emailDetail, unencodedPassword); this.emailService.sendToUserAccount(emailDetail, unencodedPassword);
} }
@@ -0,0 +1,13 @@
package org.mifosplatform.infrastructure.user.exception;
import org.mifosng.platform.exceptions.AbstractPlatformResourceNotFoundException;
/**
* A {@link RuntimeException} thrown when permission is attempted to be set as maker-checker enabled.
*/
public class PermissionCantBeMakerCheckerableException extends AbstractPlatformResourceNotFoundException {
public PermissionCantBeMakerCheckerableException(final String code) {
super("error.msg.permission.code.not.makercheckerable", "Permission with Code " + code + " can't be maker-checkerable", code);
}
}
@@ -0,0 +1,13 @@
package org.mifosplatform.infrastructure.user.exception;
import org.mifosng.platform.exceptions.AbstractPlatformResourceNotFoundException;
/**
* A {@link RuntimeException} thrown when permission resources are not found.
*/
public class PermissionNotFoundException extends AbstractPlatformResourceNotFoundException {
public PermissionNotFoundException(final String code) {
super("error.msg.permission.code.invalid", "Permission with Code " + code + " does not exist", code);
}
}
@@ -15,6 +15,7 @@ import org.mifosng.platform.exceptions.RoleNotFoundException;
import org.mifosng.platform.exceptions.UserNotFoundException; import org.mifosng.platform.exceptions.UserNotFoundException;
import org.mifosng.platform.infrastructure.PlatformEmailSendException; import org.mifosng.platform.infrastructure.PlatformEmailSendException;
import org.mifosng.platform.infrastructure.PlatformPasswordEncoder; import org.mifosng.platform.infrastructure.PlatformPasswordEncoder;
import org.mifosplatform.infrastructure.configuration.service.ConfigurationDomainService;
import org.mifosplatform.infrastructure.office.domain.Office; import org.mifosplatform.infrastructure.office.domain.Office;
import org.mifosplatform.infrastructure.office.domain.OfficeRepository; import org.mifosplatform.infrastructure.office.domain.OfficeRepository;
import org.mifosplatform.infrastructure.security.domain.BasicPasswordEncodablePlatformUser; import org.mifosplatform.infrastructure.security.domain.BasicPasswordEncodablePlatformUser;
@@ -24,8 +25,6 @@ import org.mifosplatform.infrastructure.user.command.UserCommand;
import org.mifosplatform.infrastructure.user.command.UserCommandValidator; import org.mifosplatform.infrastructure.user.command.UserCommandValidator;
import org.mifosplatform.infrastructure.user.domain.AppUser; import org.mifosplatform.infrastructure.user.domain.AppUser;
import org.mifosplatform.infrastructure.user.domain.AppUserRepository; import org.mifosplatform.infrastructure.user.domain.AppUserRepository;
import org.mifosplatform.infrastructure.user.domain.Permission;
import org.mifosplatform.infrastructure.user.domain.PermissionRepository;
import org.mifosplatform.infrastructure.user.domain.Role; import org.mifosplatform.infrastructure.user.domain.Role;
import org.mifosplatform.infrastructure.user.domain.RoleRepository; import org.mifosplatform.infrastructure.user.domain.RoleRepository;
import org.mifosplatform.infrastructure.user.domain.UserDomainService; import org.mifosplatform.infrastructure.user.domain.UserDomainService;
@@ -48,19 +47,19 @@ public class AppUserWritePlatformServiceJpaRepositoryImpl implements AppUserWrit
private final AppUserRepository appUserRepository; private final AppUserRepository appUserRepository;
private final OfficeRepository officeRepository; private final OfficeRepository officeRepository;
private final RoleRepository roleRepository; private final RoleRepository roleRepository;
private final PermissionRepository permissionRepository; private final ConfigurationDomainService configurationDomainService;
@Autowired @Autowired
public AppUserWritePlatformServiceJpaRepositoryImpl(final PlatformSecurityContext context, final AppUserRepository appUserRepository, public AppUserWritePlatformServiceJpaRepositoryImpl(final PlatformSecurityContext context, final AppUserRepository appUserRepository,
final UserDomainService userDomainService, final OfficeRepository officeRepository, final RoleRepository roleRepository, final UserDomainService userDomainService, final OfficeRepository officeRepository, final RoleRepository roleRepository,
final PlatformPasswordEncoder platformPasswordEncoder, final PermissionRepository permissionRepository) { final PlatformPasswordEncoder platformPasswordEncoder, final ConfigurationDomainService configurationDomainService) {
this.context = context; this.context = context;
this.appUserRepository = appUserRepository; this.appUserRepository = appUserRepository;
this.userDomainService = userDomainService; this.userDomainService = userDomainService;
this.officeRepository = officeRepository; this.officeRepository = officeRepository;
this.roleRepository = roleRepository; this.roleRepository = roleRepository;
this.platformPasswordEncoder = platformPasswordEncoder; this.platformPasswordEncoder = platformPasswordEncoder;
this.permissionRepository = permissionRepository; this.configurationDomainService = configurationDomainService;
} }
@Transactional @Transactional
@@ -87,7 +86,7 @@ public class AppUserWritePlatformServiceJpaRepositoryImpl implements AppUserWrit
command.getLastname(), password); command.getLastname(), password);
this.userDomainService.create(appUser, command.isApprovedByChecker()); this.userDomainService.create(appUser, command.isApprovedByChecker());
return appUser.getId(); return appUser.getId();
} catch (DataIntegrityViolationException dve) { } catch (DataIntegrityViolationException dve) {
handleDataIntegrityIssues(command, dve); handleDataIntegrityIssues(command, dve);
@@ -109,10 +108,10 @@ public class AppUserWritePlatformServiceJpaRepositoryImpl implements AppUserWrit
try { try {
context.authenticatedUser(); context.authenticatedUser();
UserCommandValidator validator = new UserCommandValidator(command); UserCommandValidator validator = new UserCommandValidator(command);
validator.validateForUpdate(); validator.validateForUpdate();
final Set<Role> allRoles = assembleSetOfRoles(command); final Set<Role> allRoles = assembleSetOfRoles(command);
Office office = null; Office office = null;
@@ -137,8 +136,7 @@ public class AppUserWritePlatformServiceJpaRepositoryImpl implements AppUserWrit
this.appUserRepository.saveAndFlush(userToUpdate); this.appUserRepository.saveAndFlush(userToUpdate);
} }
final Permission thisTask = this.permissionRepository.findOneByCode("UPDATE_USER"); if (this.configurationDomainService.isMakerCheckerEnabledForTask("UPDATE_USER") && !command.isApprovedByChecker()) { throw new RollbackTransactionAsCommandIsNotApprovedByCheckerException(); }
if (thisTask.hasMakerCheckerEnabled() && !command.isApprovedByChecker()) { throw new RollbackTransactionAsCommandIsNotApprovedByCheckerException(); }
return userToUpdate.getId(); return userToUpdate.getId();
} catch (DataIntegrityViolationException dve) { } catch (DataIntegrityViolationException dve) {
@@ -155,10 +153,10 @@ public class AppUserWritePlatformServiceJpaRepositoryImpl implements AppUserWrit
@Transactional @Transactional
@Override @Override
public Long updateUsersOwnAccountDetails(final UserCommand command) { public Long updateUsersOwnAccountDetails(final UserCommand command) {
try { try {
context.authenticatedUser(); context.authenticatedUser();
UserCommandValidator validator = new UserCommandValidator(command); UserCommandValidator validator = new UserCommandValidator(command);
validator.validateForUpdate(); validator.validateForUpdate();
@@ -185,7 +183,7 @@ public class AppUserWritePlatformServiceJpaRepositoryImpl implements AppUserWrit
userToUpdate.updatePassword(newPasswordEncoded); userToUpdate.updatePassword(newPasswordEncoded);
this.appUserRepository.saveAndFlush(userToUpdate); this.appUserRepository.saveAndFlush(userToUpdate);
} }
return userToUpdate.getId(); return userToUpdate.getId();
} catch (DataIntegrityViolationException dve) { } catch (DataIntegrityViolationException dve) {
handleDataIntegrityIssues(command, dve); handleDataIntegrityIssues(command, dve);
@@ -213,8 +211,6 @@ public class AppUserWritePlatformServiceJpaRepositoryImpl implements AppUserWrit
@Transactional @Transactional
@Override @Override
public void deleteUser(final UserCommand command) { public void deleteUser(final UserCommand command) {
final Permission permissionForThisTask = this.permissionRepository.findOneByCode("UPDATE_USER");
final Long userId = command.getId(); final Long userId = command.getId();
AppUser user = this.appUserRepository.findOne(userId); AppUser user = this.appUserRepository.findOne(userId);
@@ -222,8 +218,8 @@ public class AppUserWritePlatformServiceJpaRepositoryImpl implements AppUserWrit
user.delete(); user.delete();
this.appUserRepository.save(user); this.appUserRepository.save(user);
if (permissionForThisTask.hasMakerCheckerEnabled() && !command.isApprovedByChecker()) { throw new RollbackTransactionAsCommandIsNotApprovedByCheckerException(); } if (this.configurationDomainService.isMakerCheckerEnabledForTask("DELETE_USER") && !command.isApprovedByChecker()) { throw new RollbackTransactionAsCommandIsNotApprovedByCheckerException(); }
} }
/* /*
@@ -3,11 +3,11 @@ package org.mifosplatform.infrastructure.user.service;
import java.util.Collection; import java.util.Collection;
import java.util.Map; import java.util.Map;
import org.mifosng.platform.exceptions.PermissionNotFoundException;
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext; import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
import org.mifosplatform.infrastructure.user.command.PermissionsCommand; import org.mifosplatform.infrastructure.user.command.PermissionsCommand;
import org.mifosplatform.infrastructure.user.domain.Permission; import org.mifosplatform.infrastructure.user.domain.Permission;
import org.mifosplatform.infrastructure.user.domain.PermissionRepository; import org.mifosplatform.infrastructure.user.domain.PermissionRepository;
import org.mifosplatform.infrastructure.user.exception.PermissionNotFoundException;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
@@ -4,8 +4,8 @@ import java.util.Collection;
import java.util.Map; import java.util.Map;
import org.mifosng.platform.client.service.RollbackTransactionAsCommandIsNotApprovedByCheckerException; import org.mifosng.platform.client.service.RollbackTransactionAsCommandIsNotApprovedByCheckerException;
import org.mifosng.platform.exceptions.PermissionNotFoundException;
import org.mifosng.platform.exceptions.RoleNotFoundException; import org.mifosng.platform.exceptions.RoleNotFoundException;
import org.mifosplatform.infrastructure.configuration.service.ConfigurationDomainService;
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext; import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
import org.mifosplatform.infrastructure.user.command.RoleCommand; import org.mifosplatform.infrastructure.user.command.RoleCommand;
import org.mifosplatform.infrastructure.user.command.RoleCommandValidator; import org.mifosplatform.infrastructure.user.command.RoleCommandValidator;
@@ -14,6 +14,7 @@ import org.mifosplatform.infrastructure.user.domain.Permission;
import org.mifosplatform.infrastructure.user.domain.PermissionRepository; import org.mifosplatform.infrastructure.user.domain.PermissionRepository;
import org.mifosplatform.infrastructure.user.domain.Role; import org.mifosplatform.infrastructure.user.domain.Role;
import org.mifosplatform.infrastructure.user.domain.RoleRepository; import org.mifosplatform.infrastructure.user.domain.RoleRepository;
import org.mifosplatform.infrastructure.user.exception.PermissionNotFoundException;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
@@ -24,13 +25,16 @@ public class RoleWritePlatformServiceJpaRepositoryImpl implements RoleWritePlatf
private final PlatformSecurityContext context; private final PlatformSecurityContext context;
private final RoleRepository roleRepository; private final RoleRepository roleRepository;
private final PermissionRepository permissionRepository; private final PermissionRepository permissionRepository;
private final ConfigurationDomainService configurationDomainService;
@Autowired @Autowired
public RoleWritePlatformServiceJpaRepositoryImpl(final PlatformSecurityContext context, final RoleRepository roleRepository, public RoleWritePlatformServiceJpaRepositoryImpl(final PlatformSecurityContext context, final RoleRepository roleRepository,
final PermissionRepository permissionRepository) { final PermissionRepository permissionRepository,
final ConfigurationDomainService configurationDomainService) {
this.context = context; this.context = context;
this.roleRepository = roleRepository; this.roleRepository = roleRepository;
this.permissionRepository = permissionRepository; this.permissionRepository = permissionRepository;
this.configurationDomainService = configurationDomainService;
} }
@Transactional @Transactional
@@ -46,8 +50,7 @@ public class RoleWritePlatformServiceJpaRepositoryImpl implements RoleWritePlatf
this.roleRepository.save(entity); this.roleRepository.save(entity);
final Permission thisTask = this.permissionRepository.findOneByCode("CREATE_ROLE"); if (this.configurationDomainService.isMakerCheckerEnabledForTask("CREATE_ROLE") && !command.isApprovedByChecker()) { throw new RollbackTransactionAsCommandIsNotApprovedByCheckerException(); }
if (thisTask.hasMakerCheckerEnabled() && !command.isApprovedByChecker()) { throw new RollbackTransactionAsCommandIsNotApprovedByCheckerException(); }
return entity.getId(); return entity.getId();
} }
@@ -67,9 +70,8 @@ public class RoleWritePlatformServiceJpaRepositoryImpl implements RoleWritePlatf
this.roleRepository.save(role); this.roleRepository.save(role);
final Permission thisTask = this.permissionRepository.findOneByCode("UPDATE_ROLE"); if (this.configurationDomainService.isMakerCheckerEnabledForTask("UPDATE_ROLE") && !command.isApprovedByChecker()) { throw new RollbackTransactionAsCommandIsNotApprovedByCheckerException(); }
if (thisTask.hasMakerCheckerEnabled() && !command.isApprovedByChecker()) { throw new RollbackTransactionAsCommandIsNotApprovedByCheckerException(); }
return role.getId(); return role.getId();
} }
@@ -97,8 +99,7 @@ public class RoleWritePlatformServiceJpaRepositoryImpl implements RoleWritePlatf
this.roleRepository.save(role); this.roleRepository.save(role);
final Permission thisTask = this.permissionRepository.findOneByCode("PERMISSIONS_ROLE"); if (this.configurationDomainService.isMakerCheckerEnabledForTask("PERMISSIONS_ROLE") && !command.isApprovedByChecker()) { throw new RollbackTransactionAsCommandIsNotApprovedByCheckerException(); }
if (thisTask.hasMakerCheckerEnabled() && !command.isApprovedByChecker()) { throw new RollbackTransactionAsCommandIsNotApprovedByCheckerException(); }
return role.getId(); return role.getId();
} }
@@ -1,6 +1,8 @@
package org.mifosplatform.portfolio.charge.api; package org.mifosplatform.portfolio.charge.api;
import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.List;
import java.util.Set; import java.util.Set;
import javax.ws.rs.Consumes; import javax.ws.rs.Consumes;
@@ -13,18 +15,18 @@ import javax.ws.rs.PathParam;
import javax.ws.rs.Produces; import javax.ws.rs.Produces;
import javax.ws.rs.core.Context; import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo; import javax.ws.rs.core.UriInfo;
import org.mifosng.platform.api.data.EntityIdentifier; import org.mifosng.platform.api.data.EntityIdentifier;
import org.mifosng.platform.api.infrastructure.PortfolioApiDataConversionService; import org.mifosng.platform.api.infrastructure.PortfolioApiDataConversionService;
import org.mifosng.platform.api.infrastructure.PortfolioApiJsonSerializerService; import org.mifosng.platform.api.infrastructure.PortfolioApiJsonSerializerService;
import org.mifosng.platform.api.infrastructure.PortfolioCommandSerializerService;
import org.mifosng.platform.infrastructure.api.ApiParameterHelper; import org.mifosng.platform.infrastructure.api.ApiParameterHelper;
import org.mifosplatform.commands.service.PortfolioCommandSourceWritePlatformService;
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext; import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
import org.mifosplatform.portfolio.charge.command.ChargeCommand; import org.mifosplatform.portfolio.charge.command.ChargeDefinitionCommand;
import org.mifosplatform.portfolio.charge.data.ChargeData; import org.mifosplatform.portfolio.charge.data.ChargeData;
import org.mifosplatform.portfolio.charge.service.ChargeReadPlatformService; import org.mifosplatform.portfolio.charge.service.ChargeReadPlatformService;
import org.mifosplatform.portfolio.charge.service.ChargeWritePlatformService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope; import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@@ -34,34 +36,41 @@ import org.springframework.stereotype.Component;
@Scope("singleton") @Scope("singleton")
public class ChargesApiResource { public class ChargesApiResource {
private final String entityType = "CHARGE"; private final String resourceNameForPermissions = "CHARGE";
private final PlatformSecurityContext context;
private final ChargeReadPlatformService readPlatformService;
private final PortfolioApiDataConversionService apiDataConversionService;
private final PortfolioCommandSerializerService commandSerializerService;
private final PortfolioApiJsonSerializerService apiJsonSerializerService;
private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService;
@Autowired @Autowired
private ChargeReadPlatformService chargeReadPlatformService; public ChargesApiResource(final PlatformSecurityContext context,
final ChargeReadPlatformService readPlatformService,
@Autowired final PortfolioApiDataConversionService apiDataConversionService,
private ChargeWritePlatformService chargeWritePlatformService; final PortfolioCommandSerializerService commandSerializerService,
final PortfolioApiJsonSerializerService apiJsonSerializerService,
@Autowired final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService) {
private PortfolioApiDataConversionService apiDataConversionService; this.context = context;
this.readPlatformService = readPlatformService;
@Autowired this.apiDataConversionService = apiDataConversionService;
private PortfolioApiJsonSerializerService apiJsonSerializerService; this.commandSerializerService = commandSerializerService;
this.apiJsonSerializerService = apiJsonSerializerService;
@Autowired this.commandsSourceWritePlatformService = commandsSourceWritePlatformService;
private PlatformSecurityContext context; }
@GET @GET
@Consumes({ MediaType.APPLICATION_JSON }) @Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_JSON })
public String retrieveAllCharges(@Context final UriInfo uriInfo) { public String retrieveAllCharges(@Context final UriInfo uriInfo) {
context.authenticatedUser().validateHasReadPermission(entityType); context.authenticatedUser().validateHasReadPermission(resourceNameForPermissions);
final Set<String> responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters()); final Set<String> responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters());
final boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters()); final boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters());
final Collection<ChargeData> charges = this.chargeReadPlatformService.retrieveAllCharges(); final Collection<ChargeData> charges = this.readPlatformService.retrieveAllCharges();
return this.apiJsonSerializerService.serializeChargeDataToJson(prettyPrint, responseParameters, charges); return this.apiJsonSerializerService.serializeChargeDataToJson(prettyPrint, responseParameters, charges);
} }
@@ -72,16 +81,16 @@ public class ChargesApiResource {
@Produces({ MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_JSON })
public String retrieveCharge(@PathParam("chargeId") final Long chargeId, @Context final UriInfo uriInfo) { public String retrieveCharge(@PathParam("chargeId") final Long chargeId, @Context final UriInfo uriInfo) {
context.authenticatedUser().validateHasReadPermission(entityType); context.authenticatedUser().validateHasReadPermission(resourceNameForPermissions);
final Set<String> responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters()); final Set<String> responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters());
final boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters()); final boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters());
final boolean template = ApiParameterHelper.template(uriInfo.getQueryParameters()); final boolean template = ApiParameterHelper.template(uriInfo.getQueryParameters());
ChargeData charge = this.chargeReadPlatformService.retrieveCharge(chargeId); ChargeData charge = this.readPlatformService.retrieveCharge(chargeId);
if (template) { if (template) {
ChargeData templateData = this.chargeReadPlatformService.retrieveNewChargeDetails(); ChargeData templateData = this.readPlatformService.retrieveNewChargeDetails();
charge = new ChargeData(charge, templateData); charge = new ChargeData(charge, templateData);
} }
@@ -94,13 +103,13 @@ public class ChargesApiResource {
@Produces({ MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_JSON })
public String retrieveNewChargeDetails(@Context final UriInfo uriInfo) { public String retrieveNewChargeDetails(@Context final UriInfo uriInfo) {
context.authenticatedUser().validateHasReadPermission(entityType); context.authenticatedUser().validateHasReadPermission(resourceNameForPermissions);
final Set<String> responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters()); final Set<String> responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters());
final boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters()); final boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters());
final ChargeData chargeData = this.chargeReadPlatformService.retrieveNewChargeDetails(); final ChargeData chargeData = this.readPlatformService.retrieveNewChargeDetails();
return this.apiJsonSerializerService.serializeChargeDataToJson(prettyPrint, responseParameters, chargeData); return this.apiJsonSerializerService.serializeChargeDataToJson(prettyPrint, responseParameters, chargeData);
} }
@@ -108,36 +117,47 @@ public class ChargesApiResource {
@POST @POST
@Consumes({ MediaType.APPLICATION_JSON }) @Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_JSON })
public Response createCharge(final String jsonRequestBody) { public String createCharge(final String apiRequestBodyAsJson) {
final List<String> allowedPermissions = Arrays.asList("ALL_FUNCTIONS", "ORGANISATION_ADMINISTRATION_SUPER_USER", "CREATE_CHARGE");
context.authenticatedUser().validateHasPermissionTo("CREATE_CHARGE", allowedPermissions);
final ChargeCommand command = this.apiDataConversionService.convertJsonToChargeCommand(null, jsonRequestBody); final ChargeDefinitionCommand command = this.apiDataConversionService.convertApiRequestJsonToChargeDefinitionCommand(null, apiRequestBodyAsJson);
final String commandSerializedAsJson = this.commandSerializerService.serializeCommandToJson(command);
final EntityIdentifier result = this.commandsSourceWritePlatformService.logCommandSource("CREATE", "charges", null, commandSerializedAsJson);
final Long chargeId = this.chargeWritePlatformService.createCharge(command); return this.apiJsonSerializerService.serializeEntityIdentifier(result);
return Response.ok().entity(new EntityIdentifier(chargeId)).build();
} }
@PUT @PUT
@Path("{chargeId}") @Path("{chargeId}")
@Consumes({ MediaType.APPLICATION_JSON }) @Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_JSON })
public Response updateCharge(@PathParam("chargeId") final Long chargeId, final String jsonRequestBody) { public String updateCharge(@PathParam("chargeId") final Long chargeId, final String apiRequestBodyAsJson) {
final List<String> allowedPermissions = Arrays.asList("ALL_FUNCTIONS", "ORGANISATION_ADMINISTRATION_SUPER_USER", "UPDATE_CHARGE");
context.authenticatedUser().validateHasPermissionTo("UPDATE_CHARGE", allowedPermissions);
final ChargeDefinitionCommand command = this.apiDataConversionService.convertApiRequestJsonToChargeDefinitionCommand(chargeId, apiRequestBodyAsJson);
final String commandSerializedAsJson = this.commandSerializerService.serializeCommandToJson(command);
final EntityIdentifier result = this.commandsSourceWritePlatformService.logCommandSource("UPDATE", "charges", chargeId, commandSerializedAsJson);
final ChargeCommand command = this.apiDataConversionService.convertJsonToChargeCommand(chargeId, jsonRequestBody); return this.apiJsonSerializerService.serializeEntityIdentifier(result);
final Long entityId = this.chargeWritePlatformService.updateCharge(command);
return Response.ok().entity(new EntityIdentifier(entityId)).build();
} }
@DELETE @DELETE
@Path("{chargeId}") @Path("{chargeId}")
@Consumes({ MediaType.APPLICATION_JSON }) @Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_JSON })
public Response deleteCharge(@PathParam("chargeId") final Long chargeId) { public String deleteCharge(@PathParam("chargeId") final Long chargeId) {
Long entityId = this.chargeWritePlatformService.deleteCharge(chargeId); final List<String> allowedPermissions = Arrays.asList("ALL_FUNCTIONS", "ORGANISATION_ADMINISTRATION_SUPER_USER", "DELETE_CHARGE");
context.authenticatedUser().validateHasPermissionTo("DELETE_CHARGE", allowedPermissions);
final EntityIdentifier result = this.commandsSourceWritePlatformService.logCommandSource("DELETE", "charges", chargeId, "{}");
return Response.ok().entity(new EntityIdentifier(entityId)).build(); return this.apiJsonSerializerService.serializeEntityIdentifier(result);
} }
} }
@@ -1,123 +0,0 @@
package org.mifosplatform.portfolio.charge.command;
import java.math.BigDecimal;
import java.util.Set;
/**
* Immutable data object for creating and modifying defined charges.
*/
public class ChargeCommand {
private final Long id;
private final String name;
private final BigDecimal amount;
private final String currencyCode;
private final Integer chargeTimeType;
private final Integer chargeAppliesTo;
private final Integer chargeCalculationType;
private final boolean penalty;
private final boolean active;
private final Set<String> modifiedParameters;
public ChargeCommand(
final Set<String> modifiedParameters,
final Long id,
final String name,
final BigDecimal amount,
final String currencyCode,
final Integer chargeTimeType,
final Integer chargeAppliesTo,
final Integer chargeCalculationType,
final boolean penalty,
final boolean active) {
this.id = id;
this.name = name;
this.amount = amount;
this.currencyCode = currencyCode;
this.chargeTimeType = chargeTimeType;
this.chargeAppliesTo = chargeAppliesTo;
this.chargeCalculationType = chargeCalculationType;
this.modifiedParameters = modifiedParameters;
this.penalty = penalty;
this.active = active;
}
public Long getId() {
return id;
}
public String getName() {
return name;
}
public BigDecimal getAmount() {
return amount;
}
public Set<String> getModifiedParameters() {
return modifiedParameters;
}
public String getCurrencyCode() {
return currencyCode;
}
public Integer getChargeCalculationType() {
return chargeCalculationType;
}
public Integer getChargeAppliesTo() {
return chargeAppliesTo;
}
public Integer getChargeTimeType() {
return chargeTimeType;
}
public boolean isPenalty() {
return penalty;
}
public boolean isFee() {
return !penalty;
}
public boolean isActive() {
return active;
}
public boolean isNameChanged(){
return this.modifiedParameters.contains("name");
}
public boolean isAmountChanged(){
return this.modifiedParameters.contains("amount");
}
public boolean isCurrencyCodeChanged(){
return this.modifiedParameters.contains("currencyCode");
}
public boolean isChargeTimeTypeChanged(){
return this.modifiedParameters.contains("chargeTimeType");
}
public boolean isChargeAppliesToChanged(){
return this.modifiedParameters.contains("chargeAppliesTo");
}
public boolean isChargeCalculationTypeChanged(){
return this.modifiedParameters.contains("chargeCalculationType");
}
public boolean isPenaltyChanged(){
return this.modifiedParameters.contains("penalty");
}
public boolean isActiveChanged(){
return this.modifiedParameters.contains("active");
}
}
@@ -1,56 +0,0 @@
package org.mifosplatform.portfolio.charge.command;
import org.mifosng.platform.DataValidatorBuilder;
import org.mifosng.platform.api.data.ApiParameterError;
import org.mifosng.platform.exceptions.PlatformApiDataValidationException;
import java.util.ArrayList;
import java.util.List;
public class ChargeCommandValidator {
private final ChargeCommand command;
public ChargeCommandValidator(final ChargeCommand command) {
this.command = command;
}
public void validateForCreate() {
List<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>();
DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("charge");
baseDataValidator.reset().parameter("name").value(command.getName()).notBlank().notExceedingLengthOf(100);
baseDataValidator.reset().parameter("amount").value(command.getAmount()).notNull().positiveAmount();
baseDataValidator.reset().parameter("currencyCode").value(command.getCurrencyCode()).notBlank();
baseDataValidator.reset().parameter("chargeAppliesTo").value(command.getChargeAppliesTo()).notNull().inMinMaxRange(1, 1);
baseDataValidator.reset().parameter("chargeTimeType").value(command.getChargeTimeType()).notNull().inMinMaxRange(1, 2);
baseDataValidator.reset().parameter("chargeCalculationType").value(command.getChargeCalculationType()).notNull().inMinMaxRange(1, 4);
if (command.isPenalty() && command.getChargeTimeType().equals(Integer.valueOf(1))) {
// FIXME - KW - cannot have penalty charge at time of disbursement
}
if (!dataValidationErrors.isEmpty()) {
throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist", "Validation errors exist.", dataValidationErrors);
}
}
public void validateForUpdate() {
List<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>();
DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("charge");
baseDataValidator.reset().parameter("id").value(command.getId()).notNull();
baseDataValidator.reset().parameter("name").value(command.getName()).ignoreIfNull().notBlank().notExceedingLengthOf(100);
baseDataValidator.reset().parameter("amount").value(command.getAmount()).ignoreIfNull().positiveAmount();
baseDataValidator.reset().parameter("currencyCode").value(command.getCurrencyCode()).ignoreIfNull().notBlank();
baseDataValidator.reset().parameter("chargeAppliesTo").value(command.getChargeAppliesTo()).ignoreIfNull().notNull().inMinMaxRange(1, 1);
baseDataValidator.reset().parameter("chargeTimeType").value(command.getChargeTimeType()).ignoreIfNull().notNull().inMinMaxRange(1, 2);
baseDataValidator.reset().parameter("chargeCalculationType").value(command.getChargeCalculationType()).ignoreIfNull().notNull().inMinMaxRange(1, 4);
if (!dataValidationErrors.isEmpty()) {
throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist", "Validation errors exist.", dataValidationErrors);
}
}
}
@@ -0,0 +1,175 @@
package org.mifosplatform.portfolio.charge.command;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import org.mifosng.platform.DataValidatorBuilder;
import org.mifosng.platform.api.data.ApiParameterError;
import org.mifosng.platform.exceptions.PlatformApiDataValidationException;
/**
* Immutable data object for creating and modifying defined charges.
*/
public class ChargeDefinitionCommand {
private final String name;
private final BigDecimal amount;
private final String currencyCode;
private final Integer chargeTimeType;
private final Integer chargeAppliesTo;
private final Integer chargeCalculationType;
private final boolean penalty;
private final boolean active;
private final transient Set<String> modifiedParameters;
private final transient boolean makerCheckerApproval;
private final transient Long id;
public ChargeDefinitionCommand(
final Set<String> modifiedParameters,
final boolean makerCheckerApproval,
final Long id,
final String name,
final BigDecimal amount,
final String currencyCode,
final Integer chargeTimeType,
final Integer chargeAppliesTo,
final Integer chargeCalculationType,
final boolean penalty,
final boolean active) {
this.makerCheckerApproval = makerCheckerApproval;
this.id = id;
this.name = name;
this.amount = amount;
this.currencyCode = currencyCode;
this.chargeTimeType = chargeTimeType;
this.chargeAppliesTo = chargeAppliesTo;
this.chargeCalculationType = chargeCalculationType;
this.modifiedParameters = modifiedParameters;
this.penalty = penalty;
this.active = active;
}
public Long getId() {
return id;
}
public String getName() {
return name;
}
public BigDecimal getAmount() {
return amount;
}
public Set<String> getModifiedParameters() {
return modifiedParameters;
}
public String getCurrencyCode() {
return currencyCode;
}
public Integer getChargeCalculationType() {
return chargeCalculationType;
}
public Integer getChargeAppliesTo() {
return chargeAppliesTo;
}
public Integer getChargeTimeType() {
return chargeTimeType;
}
public boolean isPenalty() {
return penalty;
}
public boolean isFee() {
return !penalty;
}
public boolean isActive() {
return active;
}
public boolean isNameChanged(){
return this.modifiedParameters.contains("name");
}
public boolean isAmountChanged(){
return this.modifiedParameters.contains("amount");
}
public boolean isCurrencyCodeChanged(){
return this.modifiedParameters.contains("currencyCode");
}
public boolean isChargeTimeTypeChanged(){
return this.modifiedParameters.contains("chargeTimeType");
}
public boolean isChargeAppliesToChanged(){
return this.modifiedParameters.contains("chargeAppliesTo");
}
public boolean isChargeCalculationTypeChanged(){
return this.modifiedParameters.contains("chargeCalculationType");
}
public boolean isPenaltyChanged(){
return this.modifiedParameters.contains("penalty");
}
public boolean isActiveChanged(){
return this.modifiedParameters.contains("active");
}
public boolean isApprovedByChecker() {
return this.makerCheckerApproval;
}
public void validateForCreate() {
List<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>();
DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("charge");
baseDataValidator.reset().parameter("name").value(this.name).notBlank().notExceedingLengthOf(100);
baseDataValidator.reset().parameter("amount").value(this.amount).notNull().positiveAmount();
baseDataValidator.reset().parameter("currencyCode").value(this.currencyCode).notBlank();
baseDataValidator.reset().parameter("chargeAppliesTo").value(this.chargeAppliesTo).notNull().inMinMaxRange(1, 1);
baseDataValidator.reset().parameter("chargeTimeType").value(this.chargeTimeType).notNull().inMinMaxRange(1, 2);
baseDataValidator.reset().parameter("chargeCalculationType").value(this.chargeCalculationType).notNull().inMinMaxRange(1, 4);
if (this.penalty && this.chargeTimeType.equals(Integer.valueOf(1))) {
// FIXME - KW - cannot have penalty charge at time of disbursement
}
if (!dataValidationErrors.isEmpty()) {
throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist", "Validation errors exist.", dataValidationErrors);
}
}
public void validateForUpdate() {
List<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>();
DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("charge");
baseDataValidator.reset().parameter("id").value(this.id).notNull();
baseDataValidator.reset().parameter("name").value(this.name).ignoreIfNull().notBlank().notExceedingLengthOf(100);
baseDataValidator.reset().parameter("amount").value(this.amount).ignoreIfNull().positiveAmount();
baseDataValidator.reset().parameter("currencyCode").value(this.currencyCode).ignoreIfNull().notBlank();
baseDataValidator.reset().parameter("chargeAppliesTo").value(this.chargeAppliesTo).ignoreIfNull().notNull().inMinMaxRange(1, 1);
baseDataValidator.reset().parameter("chargeTimeType").value(this.chargeTimeType).ignoreIfNull().notNull().inMinMaxRange(1, 2);
baseDataValidator.reset().parameter("chargeCalculationType").value(this.chargeCalculationType).ignoreIfNull().notNull().inMinMaxRange(1, 4);
if (!dataValidationErrors.isEmpty()) {
throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist", "Validation errors exist.", dataValidationErrors);
}
}
}
@@ -2,7 +2,7 @@ package org.mifosplatform.portfolio.charge.domain;
import org.mifosng.platform.infrastructure.AbstractAuditableCustom; import org.mifosng.platform.infrastructure.AbstractAuditableCustom;
import org.mifosplatform.infrastructure.user.domain.AppUser; import org.mifosplatform.infrastructure.user.domain.AppUser;
import org.mifosplatform.portfolio.charge.command.ChargeCommand; import org.mifosplatform.portfolio.charge.command.ChargeDefinitionCommand;
import javax.persistence.*; import javax.persistence.*;
import java.math.BigDecimal; import java.math.BigDecimal;
@@ -93,7 +93,7 @@ public class Charge extends AbstractAuditableCustom<AppUser, Long> {
return deleted; return deleted;
} }
public void update(final ChargeCommand command) { public void update(final ChargeDefinitionCommand command) {
if (command.isNameChanged()) { if (command.isNameChanged()) {
this.name = command.getName(); this.name = command.getName();
} }
@@ -6,10 +6,9 @@ import org.mifosng.platform.api.data.EnumOptionData;
public interface ChargeDropdownReadPlatformService { public interface ChargeDropdownReadPlatformService {
List<EnumOptionData> retrieveCalculationTypes(); List<EnumOptionData> retrieveCalculationTypes();
List<EnumOptionData> retrieveApplicableToTypes(); List<EnumOptionData> retrieveApplicableToTypes();
List<EnumOptionData> retrieveCollectionTimeTypes();
List<EnumOptionData> retrieveCollectionTimeTypes();
} }
@@ -16,23 +16,23 @@ import org.springframework.stereotype.Service;
@Service @Service
public class ChargeDropdownReadPlatformServiceImpl implements ChargeDropdownReadPlatformService { public class ChargeDropdownReadPlatformServiceImpl implements ChargeDropdownReadPlatformService {
@Override @Override
public List<EnumOptionData> retrieveCalculationTypes() { public List<EnumOptionData> retrieveCalculationTypes() {
return Arrays.asList(chargeCalculationType(ChargeCalculationType.FLAT), return Arrays.asList(chargeCalculationType(ChargeCalculationType.FLAT),
chargeCalculationType(ChargeCalculationType.PERCENT_OF_AMOUNT) chargeCalculationType(ChargeCalculationType.PERCENT_OF_AMOUNT)
// chargeCalculationType(ChargeCalculationType.PERCENT_OF_AMOUNT_AND_INTEREST), // chargeCalculationType(ChargeCalculationType.PERCENT_OF_AMOUNT_AND_INTEREST),
// chargeCalculationType(ChargeCalculationType.PERCENT_OF_INTEREST) // chargeCalculationType(ChargeCalculationType.PERCENT_OF_INTEREST)
); );
} }
@Override @Override
public List<EnumOptionData> retrieveApplicableToTypes() { public List<EnumOptionData> retrieveApplicableToTypes() {
return Arrays.asList(chargeAppliesTo(ChargeAppliesTo.LOAN)); return Arrays.asList(chargeAppliesTo(ChargeAppliesTo.LOAN));
} }
@Override @Override
public List<EnumOptionData> retrieveCollectionTimeTypes() { public List<EnumOptionData> retrieveCollectionTimeTypes() {
return Arrays.asList(chargeTimeType(ChargeTimeType.DISBURSEMENT), chargeTimeType(ChargeTimeType.SPECIFIED_DUE_DATE)); return Arrays.asList(chargeTimeType(ChargeTimeType.DISBURSEMENT), chargeTimeType(ChargeTimeType.SPECIFIED_DUE_DATE));
} }
} }
@@ -7,65 +7,73 @@ import org.mifosplatform.portfolio.charge.domain.ChargeTimeType;
public class ChargeEnumerations { public class ChargeEnumerations {
public static EnumOptionData chargeTimeType(final int id){ public static EnumOptionData chargeTimeType(final int id) {
return chargeTimeType(ChargeTimeType.fromInt(id)); return chargeTimeType(ChargeTimeType.fromInt(id));
} }
public static EnumOptionData chargeTimeType(final ChargeTimeType type){ public static EnumOptionData chargeTimeType(final ChargeTimeType type) {
EnumOptionData optionData = null; EnumOptionData optionData = null;
switch (type){ switch (type) {
case DISBURSEMENT: case DISBURSEMENT:
optionData = new EnumOptionData(ChargeTimeType.DISBURSEMENT.getValue().longValue(), ChargeTimeType.DISBURSEMENT.getCode(), "Disbursement"); optionData = new EnumOptionData(ChargeTimeType.DISBURSEMENT.getValue().longValue(), ChargeTimeType.DISBURSEMENT.getCode(),
break; "Disbursement");
break;
case SPECIFIED_DUE_DATE: case SPECIFIED_DUE_DATE:
optionData = new EnumOptionData(ChargeTimeType.SPECIFIED_DUE_DATE.getValue().longValue(), ChargeTimeType.SPECIFIED_DUE_DATE.getCode(), "Specified due date"); optionData = new EnumOptionData(ChargeTimeType.SPECIFIED_DUE_DATE.getValue().longValue(),
break; ChargeTimeType.SPECIFIED_DUE_DATE.getCode(), "Specified due date");
break;
default: default:
optionData = new EnumOptionData(ChargeTimeType.INVALID.getValue().longValue(), ChargeTimeType.INVALID.getCode(), "Invalid"); optionData = new EnumOptionData(ChargeTimeType.INVALID.getValue().longValue(), ChargeTimeType.INVALID.getCode(), "Invalid");
break; break;
} }
return optionData; return optionData;
} }
public static EnumOptionData chargeAppliesTo(final int id){ public static EnumOptionData chargeAppliesTo(final int id) {
return chargeAppliesTo(ChargeAppliesTo.fromInt(id)); return chargeAppliesTo(ChargeAppliesTo.fromInt(id));
} }
public static EnumOptionData chargeAppliesTo(final ChargeAppliesTo type){ public static EnumOptionData chargeAppliesTo(final ChargeAppliesTo type) {
EnumOptionData optionData = null; EnumOptionData optionData = null;
switch (type){ switch (type) {
case LOAN: case LOAN:
optionData = new EnumOptionData(ChargeAppliesTo.LOAN.getValue().longValue(), ChargeAppliesTo.LOAN.getCode(), "Loan"); optionData = new EnumOptionData(ChargeAppliesTo.LOAN.getValue().longValue(), ChargeAppliesTo.LOAN.getCode(), "Loan");
break; break;
default: default:
optionData = new EnumOptionData(ChargeAppliesTo.INVALID.getValue().longValue(), ChargeAppliesTo.INVALID.getCode(), "Invalid"); optionData = new EnumOptionData(ChargeAppliesTo.INVALID.getValue().longValue(), ChargeAppliesTo.INVALID.getCode(),
break; "Invalid");
break;
} }
return optionData; return optionData;
} }
public static EnumOptionData chargeCalculationType(final int id){ public static EnumOptionData chargeCalculationType(final int id) {
return chargeCalculationType(ChargeCalculationType.fromInt(id)); return chargeCalculationType(ChargeCalculationType.fromInt(id));
} }
public static EnumOptionData chargeCalculationType(final ChargeCalculationType type){ public static EnumOptionData chargeCalculationType(final ChargeCalculationType type) {
EnumOptionData optionData = null; EnumOptionData optionData = null;
switch (type){ switch (type) {
case FLAT: case FLAT:
optionData = new EnumOptionData(ChargeCalculationType.FLAT.getValue().longValue(), ChargeCalculationType.FLAT.getCode(), "Flat"); optionData = new EnumOptionData(ChargeCalculationType.FLAT.getValue().longValue(), ChargeCalculationType.FLAT.getCode(),
break; "Flat");
break;
case PERCENT_OF_AMOUNT: case PERCENT_OF_AMOUNT:
optionData = new EnumOptionData(ChargeCalculationType.PERCENT_OF_AMOUNT.getValue().longValue(), ChargeCalculationType.PERCENT_OF_AMOUNT.getCode(), "% Amount"); optionData = new EnumOptionData(ChargeCalculationType.PERCENT_OF_AMOUNT.getValue().longValue(),
break; ChargeCalculationType.PERCENT_OF_AMOUNT.getCode(), "% Amount");
break;
case PERCENT_OF_AMOUNT_AND_INTEREST: case PERCENT_OF_AMOUNT_AND_INTEREST:
optionData = new EnumOptionData(ChargeCalculationType.PERCENT_OF_AMOUNT_AND_INTEREST.getValue().longValue(), ChargeCalculationType.PERCENT_OF_AMOUNT_AND_INTEREST.getCode(), "% Loan Amount + Interest"); optionData = new EnumOptionData(ChargeCalculationType.PERCENT_OF_AMOUNT_AND_INTEREST.getValue().longValue(),
break; ChargeCalculationType.PERCENT_OF_AMOUNT_AND_INTEREST.getCode(), "% Loan Amount + Interest");
break;
case PERCENT_OF_INTEREST: case PERCENT_OF_INTEREST:
optionData = new EnumOptionData(ChargeCalculationType.PERCENT_OF_INTEREST.getValue().longValue(), ChargeCalculationType.PERCENT_OF_INTEREST.getCode(), "% Interest"); optionData = new EnumOptionData(ChargeCalculationType.PERCENT_OF_INTEREST.getValue().longValue(),
break; ChargeCalculationType.PERCENT_OF_INTEREST.getCode(), "% Interest");
break;
default: default:
optionData = new EnumOptionData(ChargeCalculationType.INVALID.getValue().longValue(), ChargeCalculationType.INVALID.getCode(), "Invalid"); optionData = new EnumOptionData(ChargeCalculationType.INVALID.getValue().longValue(),
break; ChargeCalculationType.INVALID.getCode(), "Invalid");
break;
} }
return optionData; return optionData;
} }
@@ -1,16 +1,12 @@
package org.mifosplatform.portfolio.charge.service; package org.mifosplatform.portfolio.charge.service;
import org.mifosplatform.portfolio.charge.command.ChargeCommand; import org.mifosplatform.portfolio.charge.command.ChargeDefinitionCommand;
import org.springframework.security.access.prepost.PreAuthorize;
public interface ChargeWritePlatformService { public interface ChargeWritePlatformService {
@PreAuthorize(value = "hasAnyRole('ALL_FUNCTIONS', 'ORGANISATION_ADMINISTRATION_SUPER_USER', 'CREATE_CHARGE')") Long createCharge(ChargeDefinitionCommand command);
Long createCharge(final ChargeCommand command);
@PreAuthorize(value = "hasAnyRole('ALL_FUNCTIONS', 'ORGANISATION_ADMINISTRATION_SUPER_USER', 'UPDATE_CHARGE')") Long updateCharge(ChargeDefinitionCommand command);
Long updateCharge(final ChargeCommand command);
@PreAuthorize(value = "hasAnyRole('ALL_FUNCTIONS', 'ORGANISATION_ADMINISTRATION_SUPER_USER', 'DELETE_CHARGE')") Long deleteCharge(ChargeDefinitionCommand command);
Long deleteCharge(final Long chargeId);
} }
@@ -1,10 +1,11 @@
package org.mifosplatform.portfolio.charge.service; package org.mifosplatform.portfolio.charge.service;
import org.mifosng.platform.client.service.RollbackTransactionAsCommandIsNotApprovedByCheckerException;
import org.mifosng.platform.exceptions.ChargeNotFoundException; import org.mifosng.platform.exceptions.ChargeNotFoundException;
import org.mifosng.platform.exceptions.PlatformDataIntegrityException; import org.mifosng.platform.exceptions.PlatformDataIntegrityException;
import org.mifosplatform.infrastructure.configuration.service.ConfigurationDomainService;
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext; import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
import org.mifosplatform.portfolio.charge.command.ChargeCommand; import org.mifosplatform.portfolio.charge.command.ChargeDefinitionCommand;
import org.mifosplatform.portfolio.charge.command.ChargeCommandValidator;
import org.mifosplatform.portfolio.charge.domain.Charge; import org.mifosplatform.portfolio.charge.domain.Charge;
import org.mifosplatform.portfolio.charge.domain.ChargeAppliesTo; import org.mifosplatform.portfolio.charge.domain.ChargeAppliesTo;
import org.mifosplatform.portfolio.charge.domain.ChargeCalculationType; import org.mifosplatform.portfolio.charge.domain.ChargeCalculationType;
@@ -24,21 +25,21 @@ public class ChargeWritePlatformServiceJpaRepositoryImpl implements ChargeWriteP
private final PlatformSecurityContext context; private final PlatformSecurityContext context;
private final ChargeRepository chargeRepository; private final ChargeRepository chargeRepository;
private final ConfigurationDomainService configurationDomainService;
@Autowired @Autowired
public ChargeWritePlatformServiceJpaRepositoryImpl(final PlatformSecurityContext context, final ChargeRepository chargeRepository) { public ChargeWritePlatformServiceJpaRepositoryImpl(final PlatformSecurityContext context, final ChargeRepository chargeRepository, final ConfigurationDomainService configurationDomainService) {
this.context = context; this.context = context;
this.chargeRepository = chargeRepository; this.chargeRepository = chargeRepository;
this.configurationDomainService = configurationDomainService;
} }
@Transactional @Transactional
@Override @Override
public Long createCharge(final ChargeCommand command) { public Long createCharge(final ChargeDefinitionCommand command) {
try { try {
this.context.authenticatedUser(); this.context.authenticatedUser();
command.validateForCreate();
final ChargeCommandValidator validator = new ChargeCommandValidator(command);
validator.validateForCreate();
final ChargeAppliesTo chargeAppliesTo = ChargeAppliesTo.fromInt(command.getChargeAppliesTo()); final ChargeAppliesTo chargeAppliesTo = ChargeAppliesTo.fromInt(command.getChargeAppliesTo());
final ChargeTimeType chargeTimeType = ChargeTimeType.fromInt(command.getChargeTimeType()); final ChargeTimeType chargeTimeType = ChargeTimeType.fromInt(command.getChargeTimeType());
@@ -47,8 +48,10 @@ public class ChargeWritePlatformServiceJpaRepositoryImpl implements ChargeWriteP
final Charge charge = Charge.createNew(command.getName(), command.getAmount(), command.getCurrencyCode(), chargeAppliesTo, final Charge charge = Charge.createNew(command.getName(), command.getAmount(), command.getCurrencyCode(), chargeAppliesTo,
chargeTimeType, chargeCalculationType, command.isPenalty(), command.isActive()); chargeTimeType, chargeCalculationType, command.isPenalty(), command.isActive());
this.chargeRepository.saveAndFlush(charge); this.chargeRepository.save(charge);
if (this.configurationDomainService.isMakerCheckerEnabledForTask("CREATE_CHARGE") && !command.isApprovedByChecker()) { throw new RollbackTransactionAsCommandIsNotApprovedByCheckerException(); }
return charge.getId(); return charge.getId();
} catch (DataIntegrityViolationException dve) { } catch (DataIntegrityViolationException dve) {
handleDataIntegrityIssues(command, dve); handleDataIntegrityIssues(command, dve);
@@ -58,22 +61,22 @@ public class ChargeWritePlatformServiceJpaRepositoryImpl implements ChargeWriteP
@Transactional @Transactional
@Override @Override
public Long updateCharge(final ChargeCommand command) { public Long updateCharge(final ChargeDefinitionCommand command) {
try { try {
this.context.authenticatedUser(); this.context.authenticatedUser();
ChargeCommandValidator validator = new ChargeCommandValidator(command); command.validateForUpdate();
validator.validateForUpdate();
final Long chargeId = command.getId(); final Long chargeId = command.getId();
final Charge chargeForUpdate = this.chargeRepository.findOne(chargeId); final Charge chargeForUpdate = this.chargeRepository.findOne(chargeId);
if (chargeForUpdate == null) { throw new ChargeNotFoundException(chargeId); } if (chargeForUpdate == null) { throw new ChargeNotFoundException(chargeId); }
chargeForUpdate.update(command); chargeForUpdate.update(command);
this.chargeRepository.saveAndFlush(chargeForUpdate); this.chargeRepository.save(chargeForUpdate);
if (this.configurationDomainService.isMakerCheckerEnabledForTask("UPDATE_CHARGE") && !command.isApprovedByChecker()) { throw new RollbackTransactionAsCommandIsNotApprovedByCheckerException(); }
return chargeForUpdate.getId(); return chargeForUpdate.getId();
} catch (DataIntegrityViolationException dve) { } catch (DataIntegrityViolationException dve) {
handleDataIntegrityIssues(command, dve); handleDataIntegrityIssues(command, dve);
@@ -83,16 +86,20 @@ public class ChargeWritePlatformServiceJpaRepositoryImpl implements ChargeWriteP
@Transactional @Transactional
@Override @Override
public Long deleteCharge(Long chargeId) { public Long deleteCharge(final ChargeDefinitionCommand command) {
this.context.authenticatedUser(); this.context.authenticatedUser();
final Long chargeId = command.getId();
final Charge chargeForDelete = this.chargeRepository.findOne(chargeId); final Charge chargeForDelete = this.chargeRepository.findOne(chargeId);
if (chargeForDelete == null || chargeForDelete.isDeleted()) { throw new ChargeNotFoundException(chargeId); } if (chargeForDelete == null || chargeForDelete.isDeleted()) { throw new ChargeNotFoundException(chargeId); }
chargeForDelete.delete(); chargeForDelete.delete();
chargeRepository.saveAndFlush(chargeForDelete); chargeRepository.save(chargeForDelete);
if (this.configurationDomainService.isMakerCheckerEnabledForTask("DELETE_CHARGE") && !command.isApprovedByChecker()) { throw new RollbackTransactionAsCommandIsNotApprovedByCheckerException(); }
return chargeForDelete.getId(); return chargeForDelete.getId();
} }
@@ -100,7 +107,7 @@ public class ChargeWritePlatformServiceJpaRepositoryImpl implements ChargeWriteP
* Guaranteed to throw an exception no matter what the data integrity issue * Guaranteed to throw an exception no matter what the data integrity issue
* is. * is.
*/ */
private void handleDataIntegrityIssues(final ChargeCommand command, final DataIntegrityViolationException dve) { private void handleDataIntegrityIssues(final ChargeDefinitionCommand command, final DataIntegrityViolationException dve) {
Throwable realCause = dve.getMostSpecificCause(); Throwable realCause = dve.getMostSpecificCause();
if (realCause.getMessage().contains("name")) { throw new PlatformDataIntegrityException("error.msg.charge.duplicate.name", if (realCause.getMessage().contains("name")) { throw new PlatformDataIntegrityException("error.msg.charge.duplicate.name",
@@ -3,9 +3,8 @@ package org.mifosplatform.portfolio.fund.service;
import org.mifosng.platform.client.service.RollbackTransactionAsCommandIsNotApprovedByCheckerException; import org.mifosng.platform.client.service.RollbackTransactionAsCommandIsNotApprovedByCheckerException;
import org.mifosng.platform.exceptions.FundNotFoundException; import org.mifosng.platform.exceptions.FundNotFoundException;
import org.mifosng.platform.exceptions.PlatformDataIntegrityException; import org.mifosng.platform.exceptions.PlatformDataIntegrityException;
import org.mifosplatform.infrastructure.configuration.service.ConfigurationDomainService;
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext; import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
import org.mifosplatform.infrastructure.user.domain.Permission;
import org.mifosplatform.infrastructure.user.domain.PermissionRepository;
import org.mifosplatform.portfolio.fund.command.FundCommand; import org.mifosplatform.portfolio.fund.command.FundCommand;
import org.mifosplatform.portfolio.fund.domain.Fund; import org.mifosplatform.portfolio.fund.domain.Fund;
import org.mifosplatform.portfolio.fund.domain.FundRepository; import org.mifosplatform.portfolio.fund.domain.FundRepository;
@@ -23,15 +22,14 @@ public class FundWritePlatformServiceJpaRepositoryImpl implements FundWritePlatf
private final PlatformSecurityContext context; private final PlatformSecurityContext context;
private final FundRepository fundRepository; private final FundRepository fundRepository;
private final ConfigurationDomainService configurationDomainService;
private final PermissionRepository permissionRepository;
@Autowired @Autowired
public FundWritePlatformServiceJpaRepositoryImpl(final PlatformSecurityContext context, final FundRepository fundRepository, public FundWritePlatformServiceJpaRepositoryImpl(final PlatformSecurityContext context, final FundRepository fundRepository,
final PermissionRepository permissionRepository) { final ConfigurationDomainService configurationDomainService) {
this.context = context; this.context = context;
this.fundRepository = fundRepository; this.fundRepository = fundRepository;
this.permissionRepository = permissionRepository; this.configurationDomainService = configurationDomainService;
} }
@Transactional @Transactional
@@ -46,8 +44,7 @@ public class FundWritePlatformServiceJpaRepositoryImpl implements FundWritePlatf
this.fundRepository.save(fund); this.fundRepository.save(fund);
final Permission thisTask = this.permissionRepository.findOneByCode("CREATE_FUND"); if (this.configurationDomainService.isMakerCheckerEnabledForTask("CREATE_FUND") && !command.isApprovedByChecker()) { throw new RollbackTransactionAsCommandIsNotApprovedByCheckerException(); }
if (thisTask.hasMakerCheckerEnabled() && !command.isApprovedByChecker()) { throw new RollbackTransactionAsCommandIsNotApprovedByCheckerException(); }
return fund.getId(); return fund.getId();
} catch (DataIntegrityViolationException dve) { } catch (DataIntegrityViolationException dve) {
@@ -71,9 +68,8 @@ public class FundWritePlatformServiceJpaRepositoryImpl implements FundWritePlatf
this.fundRepository.save(fund); this.fundRepository.save(fund);
final Permission thisTask = this.permissionRepository.findOneByCode("UPDATE_FUND"); if (this.configurationDomainService.isMakerCheckerEnabledForTask("UPDATE_FUND") && !command.isApprovedByChecker()) { throw new RollbackTransactionAsCommandIsNotApprovedByCheckerException(); }
if (thisTask.hasMakerCheckerEnabled() && !command.isApprovedByChecker()) { throw new RollbackTransactionAsCommandIsNotApprovedByCheckerException(); }
return fund.getId(); return fund.getId();
} catch (DataIntegrityViolationException dve) { } catch (DataIntegrityViolationException dve) {
handleFundDataIntegrityIssues(command, dve); handleFundDataIntegrityIssues(command, dve);
@@ -92,8 +88,7 @@ public class FundWritePlatformServiceJpaRepositoryImpl implements FundWritePlatf
throw new PlatformDataIntegrityException("error.msg.fund.duplicate.externalId", "A fund with external id '" throw new PlatformDataIntegrityException("error.msg.fund.duplicate.externalId", "A fund with external id '"
+ command.getExternalId() + "' already exists", "externalId", command.getExternalId()); + command.getExternalId() + "' already exists", "externalId", command.getExternalId());
} else if (realCause.getMessage().contains("fund_name_org")) { throw new PlatformDataIntegrityException( } else if (realCause.getMessage().contains("fund_name_org")) { throw new PlatformDataIntegrityException(
"error.msg.fund.duplicate.name", "A fund with name '" + command.getName() + "' already exists", "name", "error.msg.fund.duplicate.name", "A fund with name '" + command.getName() + "' already exists", "name", command.getName()); }
command.getName()); }
logger.error(dve.getMessage(), dve); logger.error(dve.getMessage(), dve);
throw new PlatformDataIntegrityException("error.msg.fund.unknown.data.integrity.issue", throw new PlatformDataIntegrityException("error.msg.fund.unknown.data.integrity.issue",
@@ -17,7 +17,7 @@
<context:component-scan base-package="org.mifosng.platform.security, org.mifosng.platform.infrastructure, <context:component-scan base-package="org.mifosng.platform.security, org.mifosng.platform.infrastructure,
org.mifosng.platform.*.domain, org.mifosng.platform, org.mifosng.platform.*.domain, org.mifosng.platform,
org.mifosplatform.*.*.service, org.mifosplatform.*.*.domain, org.mifosplatform, org.mifosplatform.commands"> org.mifosplatform.*.*.service, org.mifosplatform.*.*.domain, org.mifosplatform, org.mifosplatform.commands, org.mifosplatform.infrastructure.*.service">
<context:exclude-filter expression="org.springframework.stereotype.Controller" type="annotation" /> <context:exclude-filter expression="org.springframework.stereotype.Controller" type="annotation" />
</context:component-scan> </context:component-scan>