add system defined checks to codes
This commit is contained in:
+39
-38
@@ -1083,9 +1083,9 @@ public class PortfolioApiDataConversionServiceImpl implements PortfolioApiDataCo
|
||||
/*
|
||||
* private LocalDate convertFrom(final String dateAsString, final String
|
||||
* parameterName, final String dateFormat) {
|
||||
*
|
||||
*
|
||||
* if (StringUtils.isBlank(dateFormat)) {
|
||||
*
|
||||
*
|
||||
* List<ApiParameterError> dataValidationErrors = new
|
||||
* ArrayList<ApiParameterError>(); String defaultMessage = new
|
||||
* StringBuilder("The parameter '" + parameterName +
|
||||
@@ -1093,11 +1093,11 @@ public class PortfolioApiDataConversionServiceImpl implements PortfolioApiDataCo
|
||||
* ApiParameterError error = ApiParameterError.parameterError(
|
||||
* "validation.msg.missing.dateFormat.parameter", defaultMessage,
|
||||
* parameterName); dataValidationErrors.add(error);
|
||||
*
|
||||
*
|
||||
* throw new PlatformApiDataValidationException(
|
||||
* "validation.msg.validation.errors.exist", "Validation errors exist.",
|
||||
* dataValidationErrors); }
|
||||
*
|
||||
*
|
||||
* LocalDate eventLocalDate = null; if
|
||||
* (StringUtils.isNotBlank(dateAsString)) { try { Locale locale =
|
||||
* LocaleContextHolder.getLocale(); eventLocalDate =
|
||||
@@ -1110,18 +1110,18 @@ public class PortfolioApiDataConversionServiceImpl implements PortfolioApiDataCo
|
||||
* " is invalid based on the dateFormat provided:" + dateFormat,
|
||||
* parameterName, dateAsString, dateFormat);
|
||||
* dataValidationErrors.add(error);
|
||||
*
|
||||
*
|
||||
* throw new PlatformApiDataValidationException(
|
||||
* "validation.msg.validation.errors.exist", "Validation errors exist.",
|
||||
* dataValidationErrors); } }
|
||||
*
|
||||
*
|
||||
* return eventLocalDate; }
|
||||
*
|
||||
*
|
||||
* private Integer convertToInteger(final String numericalValueFormatted,
|
||||
* final String parameterName, final Locale clientApplicationLocale) {
|
||||
*
|
||||
*
|
||||
* if (clientApplicationLocale == null) {
|
||||
*
|
||||
*
|
||||
* List<ApiParameterError> dataValidationErrors = new
|
||||
* ArrayList<ApiParameterError>(); String defaultMessage = new
|
||||
* StringBuilder("The parameter '" + parameterName +
|
||||
@@ -1129,41 +1129,41 @@ public class PortfolioApiDataConversionServiceImpl implements PortfolioApiDataCo
|
||||
* ApiParameterError error =
|
||||
* ApiParameterError.parameterError("validation.msg.missing.locale.parameter"
|
||||
* , defaultMessage, parameterName); dataValidationErrors.add(error);
|
||||
*
|
||||
*
|
||||
* throw new PlatformApiDataValidationException(
|
||||
* "validation.msg.validation.errors.exist", "Validation errors exist.",
|
||||
* dataValidationErrors); }
|
||||
*
|
||||
*
|
||||
* try { Integer number = null;
|
||||
*
|
||||
*
|
||||
* if (StringUtils.isNotBlank(numericalValueFormatted)) {
|
||||
*
|
||||
*
|
||||
* String source = numericalValueFormatted.trim();
|
||||
*
|
||||
*
|
||||
* NumberFormat format = NumberFormat.getInstance(clientApplicationLocale);
|
||||
* DecimalFormat df = (DecimalFormat) format; DecimalFormatSymbols symbols =
|
||||
* df.getDecimalFormatSymbols(); df.setParseBigDecimal(true);
|
||||
*
|
||||
*
|
||||
* // http://bugs.sun.com/view_bug.do?bug_id=4510618 char groupingSeparator
|
||||
* = symbols.getGroupingSeparator(); if (groupingSeparator == '\u00a0') {
|
||||
* source = source.replaceAll(" ", Character.toString('\u00a0')); }
|
||||
*
|
||||
*
|
||||
* Number parsedNumber = df.parse(source);
|
||||
*
|
||||
*
|
||||
* double parsedNumberDouble = parsedNumber.doubleValue(); int
|
||||
* parsedNumberInteger = parsedNumber.intValue();
|
||||
*
|
||||
*
|
||||
* if (source.contains(Character.toString(symbols.getDecimalSeparator()))) {
|
||||
* throw new ParseException(source, 0); }
|
||||
*
|
||||
*
|
||||
* if
|
||||
* (!Double.valueOf(parsedNumberDouble).equals(Double.valueOf(Integer.valueOf
|
||||
* (parsedNumberInteger)))) { throw new ParseException(source, 0); }
|
||||
*
|
||||
*
|
||||
* number = parsedNumber.intValue(); }
|
||||
*
|
||||
*
|
||||
* return number; } catch (ParseException e) {
|
||||
*
|
||||
*
|
||||
* List<ApiParameterError> dataValidationErrors = new
|
||||
* ArrayList<ApiParameterError>(); ApiParameterError error =
|
||||
* ApiParameterError.parameterError(
|
||||
@@ -1173,16 +1173,16 @@ public class PortfolioApiDataConversionServiceImpl implements PortfolioApiDataCo
|
||||
* clientApplicationLocale.toString() + "].", parameterName,
|
||||
* numericalValueFormatted, clientApplicationLocale);
|
||||
* dataValidationErrors.add(error);
|
||||
*
|
||||
*
|
||||
* throw new PlatformApiDataValidationException(
|
||||
* "validation.msg.validation.errors.exist", "Validation errors exist.",
|
||||
* dataValidationErrors); } }
|
||||
*
|
||||
*
|
||||
* private BigDecimal convertFrom(final String numericalValueFormatted,
|
||||
* final String parameterName, final Locale clientApplicationLocale) {
|
||||
*
|
||||
*
|
||||
* if (clientApplicationLocale == null) {
|
||||
*
|
||||
*
|
||||
* List<ApiParameterError> dataValidationErrors = new
|
||||
* ArrayList<ApiParameterError>(); String defaultMessage = new
|
||||
* StringBuilder("The parameter '" + parameterName +
|
||||
@@ -1190,17 +1190,17 @@ public class PortfolioApiDataConversionServiceImpl implements PortfolioApiDataCo
|
||||
* ApiParameterError error =
|
||||
* ApiParameterError.parameterError("validation.msg.missing.locale.parameter"
|
||||
* , defaultMessage, parameterName); dataValidationErrors.add(error);
|
||||
*
|
||||
*
|
||||
* throw new PlatformApiDataValidationException(
|
||||
* "validation.msg.validation.errors.exist", "Validation errors exist.",
|
||||
* dataValidationErrors); }
|
||||
*
|
||||
*
|
||||
* try { BigDecimal number = null;
|
||||
*
|
||||
*
|
||||
* if (StringUtils.isNotBlank(numericalValueFormatted)) {
|
||||
*
|
||||
*
|
||||
* String source = numericalValueFormatted.trim();
|
||||
*
|
||||
*
|
||||
* NumberFormat format =
|
||||
* NumberFormat.getNumberInstance(clientApplicationLocale); DecimalFormat df
|
||||
* = (DecimalFormat) format; DecimalFormatSymbols symbols =
|
||||
@@ -1208,14 +1208,14 @@ public class PortfolioApiDataConversionServiceImpl implements PortfolioApiDataCo
|
||||
* http://bugs.sun.com/view_bug.do?bug_id=4510618 char groupingSeparator =
|
||||
* symbols.getGroupingSeparator(); if (groupingSeparator == '\u00a0') {
|
||||
* source = source.replaceAll(" ", Character.toString('\u00a0')); }
|
||||
*
|
||||
*
|
||||
* NumberFormatter numberFormatter = new NumberFormatter(); Number
|
||||
* parsedNumber = numberFormatter.parse(source, clientApplicationLocale);
|
||||
* number = BigDecimal.valueOf(Double.valueOf(parsedNumber.doubleValue()));
|
||||
* }
|
||||
*
|
||||
*
|
||||
* return number; } catch (ParseException e) {
|
||||
*
|
||||
*
|
||||
* List<ApiParameterError> dataValidationErrors = new
|
||||
* ArrayList<ApiParameterError>(); ApiParameterError error =
|
||||
* ApiParameterError.parameterError(
|
||||
@@ -1225,7 +1225,7 @@ public class PortfolioApiDataConversionServiceImpl implements PortfolioApiDataCo
|
||||
* clientApplicationLocale.toString() + "].", parameterName,
|
||||
* numericalValueFormatted, clientApplicationLocale);
|
||||
* dataValidationErrors.add(error);
|
||||
*
|
||||
*
|
||||
* throw new PlatformApiDataValidationException(
|
||||
* "validation.msg.validation.errors.exist", "Validation errors exist.",
|
||||
* dataValidationErrors); } }
|
||||
@@ -1543,13 +1543,14 @@ public class PortfolioApiDataConversionServiceImpl implements PortfolioApiDataCo
|
||||
public CodeCommand convertApiRequestJsonToCodeCommand(final Long resourceIdentifier, final String json) {
|
||||
if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); }
|
||||
|
||||
Type typeOfMap = new TypeToken<Map<String, String>>() {}.getType();
|
||||
Map<String, String> requestMap = gsonConverter.fromJson(json, typeOfMap);
|
||||
Type typeOfMap = new TypeToken<Map<String, Object>>() {}.getType();
|
||||
Map<String, Object> requestMap = gsonConverter.fromJson(json, typeOfMap);
|
||||
|
||||
Set<String> supportedParams = new HashSet<String>(Arrays.asList("name"));
|
||||
Set<String> supportedParams = new HashSet<String>(Arrays.asList("name","is_system_defined"));
|
||||
|
||||
checkForUnsupportedParameters(requestMap, supportedParams);
|
||||
|
||||
|
||||
// no difference between api request json format and internal command
|
||||
// json format.
|
||||
return this.portfolioCommandDeserializerService.deserializeCodeCommand(resourceIdentifier, json, false);
|
||||
|
||||
+25
-24
@@ -41,14 +41,14 @@ public class PortfolioCommandDeerializerServiceGoogleGson implements PortfolioCo
|
||||
parser = new JsonParser();
|
||||
gsonConverter = new Gson();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public RoleCommand deserializeRoleCommand(final Long roleId, 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);
|
||||
@@ -60,16 +60,16 @@ public class PortfolioCommandDeerializerServiceGoogleGson implements PortfolioCo
|
||||
@Override
|
||||
public RolePermissionCommand deserializeRolePermissionCommand(final Long roleId, final String commandAsJson, final boolean makerCheckerApproval) {
|
||||
if (StringUtils.isBlank(commandAsJson)) { throw new InvalidJsonException(); }
|
||||
|
||||
|
||||
final RolePermissionCommand command = gsonConverter.fromJson(commandAsJson, RolePermissionCommand.class);
|
||||
|
||||
return new RolePermissionCommand(roleId, command.getPermissions(), makerCheckerApproval);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public PermissionsCommand deserializePermissionsCommand(final String commandAsJson, final boolean makerCheckerApproval) {
|
||||
if (StringUtils.isBlank(commandAsJson)) { throw new InvalidJsonException(); }
|
||||
|
||||
|
||||
final PermissionsCommand command = gsonConverter.fromJson(commandAsJson, PermissionsCommand.class);
|
||||
|
||||
return new PermissionsCommand(command.getPermissions(), makerCheckerApproval);
|
||||
@@ -81,18 +81,18 @@ public class PortfolioCommandDeerializerServiceGoogleGson implements PortfolioCo
|
||||
|
||||
final JsonParserHelper helper = new JsonParserHelper();
|
||||
final JsonElement element = parser.parse(commandAsJson);
|
||||
|
||||
|
||||
final Set<String> parametersPassedInRequest = new HashSet<String>();
|
||||
|
||||
|
||||
final String username = helper.extractStringNamed("username", element, parametersPassedInRequest);
|
||||
final String firstname = helper.extractStringNamed("firstname", element, parametersPassedInRequest);
|
||||
|
||||
|
||||
final String lastname = helper.extractStringNamed("lastname", element, parametersPassedInRequest);
|
||||
final String password = helper.extractStringNamed("password", element, parametersPassedInRequest);
|
||||
final String repeatPassword = helper.extractStringNamed("repeatPassword", element, parametersPassedInRequest);
|
||||
final String email = helper.extractStringNamed("email", element, parametersPassedInRequest);
|
||||
final Long officeId = helper.extractLongNamed("officeId", element, parametersPassedInRequest);
|
||||
|
||||
|
||||
// check array
|
||||
String[] notSelectedRoles = null;
|
||||
String[] roles = null;
|
||||
@@ -117,7 +117,7 @@ public class PortfolioCommandDeerializerServiceGoogleGson implements PortfolioCo
|
||||
}
|
||||
}
|
||||
|
||||
return new UserCommand(parametersPassedInRequest, makerCheckerApproval, userId, username, firstname, lastname,
|
||||
return new UserCommand(parametersPassedInRequest, makerCheckerApproval, userId, username, firstname, lastname,
|
||||
password, repeatPassword, email, officeId, notSelectedRoles, roles);
|
||||
}
|
||||
|
||||
@@ -127,22 +127,23 @@ public class PortfolioCommandDeerializerServiceGoogleGson implements PortfolioCo
|
||||
|
||||
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 boolean isSystemDefined = helper.extractBooleanNamed("isSystemDefined", element, parametersPassedInRequest);
|
||||
|
||||
return new CodeCommand(parametersPassedInRequest, makerCheckerApproval, codeId, name);
|
||||
return new CodeCommand(parametersPassedInRequest, makerCheckerApproval, codeId, name,isSystemDefined);
|
||||
}
|
||||
|
||||
@Override
|
||||
public StaffCommand deserializeStaffCommand(final Long staffId, 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 firstname = helper.extractStringNamed("firstname", element, parametersPassedInRequest);
|
||||
@@ -155,35 +156,35 @@ public class PortfolioCommandDeerializerServiceGoogleGson implements PortfolioCo
|
||||
|
||||
@Override
|
||||
public FundCommand deserializeFundCommand(final Long fundId, 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 externalId = helper.extractStringNamed("externalId", element, parametersPassedInRequest);
|
||||
|
||||
|
||||
return new FundCommand(parametersPassedInRequest, makerCheckerApproval, fundId, name, externalId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public OfficeCommand deserializeOfficeCommand(final Long officeId, 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 externalId = helper.extractStringNamed("externalId", element, parametersPassedInRequest);
|
||||
final Long parentId = helper.extractLongNamed("parentId", element, parametersPassedInRequest);
|
||||
final LocalDate openingLocalDate = helper.extractLocalDateAsArrayNamed("openingDate", element, parametersPassedInRequest);
|
||||
|
||||
|
||||
return new OfficeCommand(parametersPassedInRequest, makerCheckerApproval, officeId, name, externalId, parentId, openingLocalDate);
|
||||
}
|
||||
|
||||
@@ -194,7 +195,7 @@ public class PortfolioCommandDeerializerServiceGoogleGson implements PortfolioCo
|
||||
|
||||
final JsonParserHelper helper = new JsonParserHelper();
|
||||
final JsonElement element = parser.parse(commandAsJson);
|
||||
|
||||
|
||||
final Set<String> parametersPassedInRequest = new HashSet<String>();
|
||||
|
||||
final Long fromOfficeId = helper.extractLongNamed("fromOfficeId", element, parametersPassedInRequest);
|
||||
@@ -203,7 +204,7 @@ public class PortfolioCommandDeerializerServiceGoogleGson implements PortfolioCo
|
||||
final String currencyCode = helper.extractStringNamed("currencyCode", element, parametersPassedInRequest);
|
||||
final BigDecimal transactionAmount = helper.extractBigDecimalNamed("transactionAmount", element.getAsJsonObject(), Locale.US, parametersPassedInRequest);
|
||||
final String description = helper.extractStringNamed("description", element, parametersPassedInRequest);
|
||||
|
||||
|
||||
return new BranchMoneyTransferCommand(parametersPassedInRequest, makerCheckerApproval, fromOfficeId, toOfficeId, transactionLocalDate, currencyCode,
|
||||
transactionAmount, description);
|
||||
}
|
||||
@@ -214,11 +215,11 @@ public class PortfolioCommandDeerializerServiceGoogleGson implements PortfolioCo
|
||||
|
||||
final JsonParserHelper helper = new JsonParserHelper();
|
||||
final JsonElement element = parser.parse(commandAsJson);
|
||||
|
||||
|
||||
final Set<String> parametersPassedInRequest = new HashSet<String>();
|
||||
|
||||
final String[] currencies = helper.extractArrayNamed("currencies", element, parametersPassedInRequest);
|
||||
|
||||
|
||||
return new CurrencyCommand(makerCheckerApproval, currencies);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package org.mifosng.platform.exceptions;
|
||||
|
||||
public class CodeExceptionRule extends AbstractPlatformDomainRuleException
|
||||
{
|
||||
public CodeExceptionRule()
|
||||
{
|
||||
super("error.msg.code.systemdefined","This code is system defined and cannot be modified or deleted.");
|
||||
}
|
||||
}
|
||||
+12
-6
@@ -18,15 +18,21 @@ public class CodeCommand {
|
||||
private final transient Set<String> parametersPassedInRequest;
|
||||
private final transient boolean makerCheckerApproval;
|
||||
private final transient Long id;
|
||||
private final transient boolean isSystemDefined;
|
||||
|
||||
public CodeCommand(final Set<String> modifiedParameters, final boolean makerCheckerApproval, final Long id, final String name) {
|
||||
public CodeCommand(final Set<String> modifiedParameters, final boolean makerCheckerApproval, final Long id, final String name,final boolean isSystemDefined) {
|
||||
this.parametersPassedInRequest = modifiedParameters;
|
||||
this.makerCheckerApproval = makerCheckerApproval;
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.isSystemDefined = isSystemDefined;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
public boolean getisSystemDefined() {
|
||||
return isSystemDefined;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
@@ -44,10 +50,10 @@ public class CodeCommand {
|
||||
|
||||
public void validateForCreate() {
|
||||
List<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>();
|
||||
|
||||
|
||||
DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("code");
|
||||
baseDataValidator.reset().parameter("name").value(this.name).notBlank();
|
||||
|
||||
|
||||
if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist",
|
||||
"Validation errors exist.", dataValidationErrors); }
|
||||
}
|
||||
@@ -55,10 +61,10 @@ public class CodeCommand {
|
||||
public void validateForUpdate() {
|
||||
List<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>();
|
||||
DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("code");
|
||||
|
||||
|
||||
baseDataValidator.reset().parameter("id").value(this.id).notNull();
|
||||
baseDataValidator.reset().parameter("name").value(this.name).ignoreIfNull().notBlank();
|
||||
|
||||
|
||||
if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist",
|
||||
"Validation errors exist.", dataValidationErrors); }
|
||||
}
|
||||
|
||||
+9
-1
@@ -18,7 +18,15 @@ public class Code extends AbstractPersistable<Long> {
|
||||
@Column(name = "code_name", length = 100)
|
||||
private String codeName;
|
||||
|
||||
public static Code createNew(final String codeName) {
|
||||
@SuppressWarnings("unused")
|
||||
@Column(name = "is_system_defined")
|
||||
private boolean isSystemDefined;
|
||||
|
||||
public boolean getisSystemDefined() {
|
||||
return isSystemDefined;
|
||||
}
|
||||
|
||||
public static Code createNew(final String codeName) {
|
||||
return new Code(codeName);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user