Skip to content
Permalink
Browse files

REST base in admin GUI

- introduced empty constructor in SuperEntity
- introduced validation model for MVC application
- changed RPC API - ChangeableRpc: added BindingResult to specific methods
- added InputValidationException
- renamed ValidationIntegrationException -> ValidationException

Issue: OHFJIRA-63
  • Loading branch information
pjuza committed Apr 12, 2017
1 parent e0a40de commit e5a9711043d445cb7bf5f1b46329f56a8af05ea4
Showing with 561 additions and 210 deletions.
  1. +22 −8 core-api/src/main/java/org/openhubframework/openhub/api/common/Constraints.java
  2. +3 −3 core-api/src/main/java/org/openhubframework/openhub/api/common/ExchangeHelper.java
  3. +1 −1 core-api/src/main/java/org/openhubframework/openhub/api/configuration/ConfigurationItem.java
  4. +1 −2 core-api/src/main/java/org/openhubframework/openhub/api/configuration/DbConfigurationParam.java
  5. +1 −1 ...api/src/main/java/org/openhubframework/openhub/api/configuration/DbConfigurationParamService.java
  6. +0 −1 core-api/src/main/java/org/openhubframework/openhub/api/entity/ExternalCall.java
  7. +0 −1 core-api/src/main/java/org/openhubframework/openhub/api/entity/Request.java
  8. +0 −1 core-api/src/main/java/org/openhubframework/openhub/api/entity/Response.java
  9. +7 −0 core-api/src/main/java/org/openhubframework/openhub/api/entity/SuperEntity.java
  10. +5 −2 .../main/java/org/openhubframework/openhub/api/exception/{ → validation}/ConfigurationException.java
  11. +5 −2 ...rc/main/java/org/openhubframework/openhub/api/exception/{ → validation}/IllegalDataException.java
  12. +74 −0 ...src/main/java/org/openhubframework/openhub/api/exception/validation/InputValidationException.java
  13. +9 −6 ...openhub/api/exception/{ValidationIntegrationException.java → validation/ValidationException.java}
  14. +4 −0 core-api/src/main/java/org/openhubframework/openhub/api/exception/validation/package-info.java
  15. +6 −8 core-api/src/main/java/org/openhubframework/openhub/api/route/AbstractBasicRoute.java
  16. +3 −3 core-api/src/main/java/org/openhubframework/openhub/api/route/XPathValidator.java
  17. +9 −9 core/src/main/java/org/openhubframework/openhub/core/common/asynch/TraceHeaderProcessor.java
  18. +13 −25 .../main/java/org/openhubframework/openhub/core/common/ws/HeaderAndPayloadValidatingInterceptor.java
  19. +1 −1 core/src/main/java/org/openhubframework/openhub/core/confcheck/ConfCheck.java
  20. +1 −1 core/src/main/java/org/openhubframework/openhub/core/confcheck/ConfigurationChecker.java
  21. +1 −1 core/src/main/java/org/openhubframework/openhub/core/configuration/ConfigurationItemImpl.java
  22. +1 −1 ...rc/main/java/org/openhubframework/openhub/core/configuration/DbConfigurationParamServiceImpl.java
  23. +1 −1 core/src/main/java/org/openhubframework/openhub/core/node/NodeServiceImpl.java
  24. +2 −2 .../src/test/java/org/openhubframework/openhub/core/common/asynch/AsynchMessageRouteConfirmTest.java
  25. +2 −3 core/src/test/java/org/openhubframework/openhub/core/common/asynch/AsynchMessageRouteTest.java
  26. +9 −9 core/src/test/java/org/openhubframework/openhub/core/common/asynch/TraceHeaderProcessorTest.java
  27. +1 −1 core/src/test/java/org/openhubframework/openhub/core/common/exception/ExceptionTranslatorTest.java
  28. +1 −1 ...rc/test/java/org/openhubframework/openhub/core/configuration/DbConfigurationParamServiceTest.java
  29. +12 −3 web-admin/src/main/java/org/openhubframework/openhub/admin/web/common/AbstractOhfController.java
  30. +12 −89 web-admin/src/main/java/org/openhubframework/openhub/admin/web/common/rpc/BaseRpc.java
  31. +221 −0 web-admin/src/main/java/org/openhubframework/openhub/admin/web/common/rpc/ChangeableRpc.java
  32. +40 −1 web-admin/src/main/java/org/openhubframework/openhub/admin/web/common/rpc/FieldInputErrorRpc.java
  33. +3 −3 web-admin/src/main/java/org/openhubframework/openhub/admin/web/common/rpc/ValidationFaultRpc.java
  34. +10 −8 ...ain/java/org/openhubframework/openhub/admin/web/configuration/rest/DbConfigurationController.java
  35. +18 −6 ...c/main/java/org/openhubframework/openhub/admin/web/configuration/rpc/DbConfigurationParamRpc.java
  36. +18 −5 web-admin/src/main/java/org/openhubframework/openhub/web/common/ExceptionRestHandler.java
  37. +0 −1 web-admin/src/main/java/org/openhubframework/openhub/web/config/WebContextConfig.java
  38. +3 −0 web-admin/src/main/resources/messages/messages_cs.properties
  39. +3 −0 web-admin/src/main/resources/messages/messages_en.properties
  40. +38 −0 ...java/org/openhubframework/openhub/admin/web/configuration/rest/DbConfigurationControllerTest.java
@@ -18,14 +18,13 @@


import org.openhubframework.openhub.api.exception.ErrorExtEnum;
import org.openhubframework.openhub.api.exception.IllegalDataException;
import org.openhubframework.openhub.api.exception.InternalErrorEnum;
import org.openhubframework.openhub.api.exception.ValidationIntegrationException;
import org.openhubframework.openhub.api.exception.validation.IllegalDataException;
import org.openhubframework.openhub.api.exception.validation.ValidationException;


/**
* Assertion utility class that assists in validating arguments by throwing specific
* {@link ValidationIntegrationException} exceptions.
* {@link ValidationException} exceptions.
*
* <p>Useful for identifying data integration errors early and clearly at runtime.
*
@@ -50,7 +49,7 @@
public static void hasText(String text, String message) throws IllegalDataException {
notNull(text, message);
if (!org.springframework.util.StringUtils.hasText(text)) {
throw new IllegalDataException(InternalErrorEnum.E109, message);
throw new IllegalDataException(message);
}
}

@@ -80,7 +79,7 @@ public static void hasText(String text, String message, ErrorExtEnum errorCode)
*/
public static void notNull(Object object, String message) {
if (object == null) {
throw new IllegalDataException(InternalErrorEnum.E109, message);
throw new IllegalDataException(message);
}
}

@@ -107,7 +106,7 @@ public static void notNull(Object object, String message, ErrorExtEnum errorCode
*/
public static void isNull(Object object, String message) {
if (object != null) {
throw new IllegalDataException(InternalErrorEnum.E109, message);
throw new IllegalDataException(message);
}
}

@@ -135,7 +134,7 @@ public static void isNull(Object object, String message, ErrorExtEnum errorCode)
public static void isTrue(Boolean expression, String message) {
notNull(expression, message);
if (expression.booleanValue() != Boolean.TRUE) {
throw new IllegalDataException(InternalErrorEnum.E109, message);
throw new IllegalDataException(message);
}
}

@@ -154,6 +153,21 @@ public static void isTrue(Boolean expression, String message, ErrorExtEnum error
}
}

/**
* Assert a boolean expression, throwing {@code IllegalStateException}
* if the test result is {@code false}. Call isTrue if you wish to
* throw IllegalArgumentException on an assertion failure.
* <pre class="code">Assert.state(id == null, "The id property must not already be initialized");</pre>
* @param expression a boolean expression
* @param message the exception message to use if the assertion fails
* @throws IllegalStateException if expression is {@code false}
*/
public static void state(boolean expression, String message) {
if (!expression) {
throw new IllegalDataException(message);
}
}

private Constraints() {
}
}
@@ -20,13 +20,13 @@

import javax.annotation.Nullable;

import org.openhubframework.openhub.api.asynch.model.TraceHeader;
import org.openhubframework.openhub.api.exception.IllegalDataException;

import org.apache.camel.Exchange;
import org.apache.camel.Message;
import org.springframework.util.Assert;

import org.openhubframework.openhub.api.asynch.model.TraceHeader;
import org.openhubframework.openhub.api.exception.validation.IllegalDataException;

/**
* Some helper methods for working with {@link Exchange} objects.
*
@@ -16,7 +16,7 @@

package org.openhubframework.openhub.api.configuration;

import org.openhubframework.openhub.api.exception.ConfigurationException;
import org.openhubframework.openhub.api.exception.validation.ConfigurationException;


/**
@@ -27,7 +27,7 @@

import org.openhubframework.openhub.api.common.Constraints;
import org.openhubframework.openhub.api.entity.SuperEntity;
import org.openhubframework.openhub.api.exception.ConfigurationException;
import org.openhubframework.openhub.api.exception.validation.ConfigurationException;
import org.openhubframework.openhub.common.Tools;


@@ -75,7 +75,6 @@

/** Default public constructor. */
public DbConfigurationParam() {
super(null);
}

/**
@@ -19,7 +19,7 @@
import java.util.List;
import java.util.Optional;

import org.openhubframework.openhub.api.exception.ConfigurationException;
import org.openhubframework.openhub.api.exception.validation.ConfigurationException;


/**
@@ -82,7 +82,6 @@

/** Default public constructor. */
public ExternalCall() {
super(null);
}

/**
@@ -80,7 +80,6 @@

/** Default public constructor. */
public Request() {
super(null);
}

/**
@@ -66,7 +66,6 @@

/** Default public constructor. */
public Response() {
super(null);
}

/**
@@ -50,6 +50,13 @@ protected SuperEntity(@Nullable ID id) {
this.id = id;
}

/**
* Creates new entity with null identifier.
*/
protected SuperEntity() {
this(null);
}

@Override
public void setId(@Nullable ID id) {
this.id = id;
@@ -14,15 +14,18 @@
* limitations under the License.
*/

package org.openhubframework.openhub.api.exception;
package org.openhubframework.openhub.api.exception.validation;

import org.openhubframework.openhub.api.exception.InternalErrorEnum;


/**
* Configuration exception that reflects error state of configuration item.
*
* @author Tomas Hanus
* @since 2.0
*/
public class ConfigurationException extends ValidationIntegrationException {
public class ConfigurationException extends ValidationException {

private static final long serialVersionUID = 1L;

@@ -14,17 +14,20 @@
* limitations under the License.
*/

package org.openhubframework.openhub.api.exception;
package org.openhubframework.openhub.api.exception.validation;

import javax.annotation.Nullable;

import org.openhubframework.openhub.api.exception.ErrorExtEnum;
import org.openhubframework.openhub.api.exception.InternalErrorEnum;


/**
* Exception indicates non-valid, illegal data.
*
* @author Petr Juza
*/
public class IllegalDataException extends ValidationIntegrationException {
public class IllegalDataException extends ValidationException {

/**
* Creates exception with the message and {@link InternalErrorEnum#E109} error code.
@@ -0,0 +1,74 @@
/*
* Copyright 2002-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.openhubframework.openhub.api.exception.validation;

import javax.annotation.Nullable;

import org.springframework.http.HttpStatus;
import org.springframework.util.Assert;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ResponseStatus;

import org.openhubframework.openhub.api.exception.ErrorExtEnum;
import org.openhubframework.openhub.api.exception.InternalErrorEnum;
import org.openhubframework.openhub.common.Tools;


/**
* Validation exception indicates error(s) in input data.
* Exception encapsulates {@link BindingResult input errors}.
*
* @author Petr Juza
* @since 2.0
*/
@ResponseStatus(HttpStatus.BAD_REQUEST)
public class InputValidationException extends ValidationException {

private BindingResult bindingResult;

/**
* Creates exception with binding errors.
*
* @param bindingResult Binding errors
*/
public InputValidationException(BindingResult bindingResult) {
this(bindingResult, InternalErrorEnum.E109);
}

/**
* Creates exception with binding errors and specific error code.
*
* @param bindingResult Binding errors
* @param error The error code
*/
public InputValidationException(BindingResult bindingResult, @Nullable ErrorExtEnum error) {
super(error, null, null);

Assert.notNull(bindingResult, "bindingResult must not be null");

this.bindingResult = bindingResult;
}

public BindingResult getBindingResult() {
return bindingResult;
}

@Override
public String getMessage() {
return Tools.fm("Input validation error in object '{}'", bindingResult.getObjectName());
}
}
@@ -14,11 +14,14 @@
* limitations under the License.
*/

package org.openhubframework.openhub.api.exception;
package org.openhubframework.openhub.api.exception.validation;

import javax.annotation.Nullable;

import org.openhubframework.openhub.api.entity.MsgStateEnum;
import org.openhubframework.openhub.api.exception.ErrorExtEnum;
import org.openhubframework.openhub.api.exception.IntegrationException;
import org.openhubframework.openhub.api.exception.InternalErrorEnum;


/**
@@ -28,14 +31,14 @@
*
* @author Petr Juza
*/
public class ValidationIntegrationException extends IntegrationException {
public class ValidationException extends IntegrationException {

/**
* Creates validation exception with the message and {@link InternalErrorEnum#E102} error code.
*
* @param msg the message
*/
public ValidationIntegrationException(String msg) {
public ValidationException(String msg) {
super(InternalErrorEnum.E102, msg);
}

@@ -44,7 +47,7 @@ public ValidationIntegrationException(String msg) {
*
* @param error the error code
*/
public ValidationIntegrationException(ErrorExtEnum error) {
public ValidationException(ErrorExtEnum error) {
super(error);
}

@@ -54,7 +57,7 @@ public ValidationIntegrationException(ErrorExtEnum error) {
* @param error the error code
* @param msg the message
*/
public ValidationIntegrationException(ErrorExtEnum error, String msg) {
public ValidationException(ErrorExtEnum error, String msg) {
super(error, msg);
}

@@ -65,7 +68,7 @@ public ValidationIntegrationException(ErrorExtEnum error, String msg) {
* @param msg the message
* @param cause the throwable that caused this exception
*/
public ValidationIntegrationException(ErrorExtEnum error, @Nullable String msg, @Nullable Throwable cause) {
public ValidationException(ErrorExtEnum error, @Nullable String msg, @Nullable Throwable cause) {
super(error, msg, cause);
}
}
@@ -0,0 +1,4 @@
/**
* Validation exceptions.
*/
package org.openhubframework.openhub.api.exception.validation;
@@ -24,7 +24,6 @@
import org.apache.camel.Handler;
import org.apache.camel.Header;
import org.apache.camel.LoggingLevel;
import org.apache.camel.ValidationException;
import org.apache.camel.processor.DefaultExchangeFormatter;
import org.apache.camel.spi.EventNotifier;
import org.apache.camel.spring.SpringRouteBuilder;
@@ -33,18 +32,17 @@
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.openhubframework.openhub.api.asynch.AsynchConstants;
import org.openhubframework.openhub.api.entity.ExternalSystemExtEnum;
import org.openhubframework.openhub.api.entity.ServiceExtEnum;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.Assert;

import org.openhubframework.openhub.api.asynch.AsynchConstants;
import org.openhubframework.openhub.api.entity.ExternalSystemExtEnum;
import org.openhubframework.openhub.api.entity.ServiceExtEnum;
import org.openhubframework.openhub.api.exception.BusinessException;
import org.openhubframework.openhub.api.exception.LockFailureException;
import org.openhubframework.openhub.api.exception.MultipleDataFoundException;
import org.openhubframework.openhub.api.exception.NoDataFoundException;
import org.openhubframework.openhub.api.exception.ValidationIntegrationException;
import org.openhubframework.openhub.api.exception.validation.ValidationException;


/**
@@ -160,8 +158,8 @@ public String exceptionHandling(Exception ex, @Header(AsynchConstants.ASYNCH_MSG

String nextUri;

if (ExceptionUtils.indexOfThrowable(ex, ValidationException.class) >= 0
|| ExceptionUtils.indexOfThrowable(ex, ValidationIntegrationException.class) >= 0) {
if (ExceptionUtils.indexOfThrowable(ex, org.apache.camel.ValidationException.class) >= 0
|| ExceptionUtils.indexOfThrowable(ex, ValidationException.class) >= 0) {
LOG.warn("Validation error, no further processing - " + ex.getMessage());
nextUri = AsynchConstants.URI_ERROR_FATAL;

0 comments on commit e5a9711

Please sign in to comment.
You can’t perform that action at this time.