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