From a42de79292d9541db7865b54e93be2d0b6e6a094 Mon Sep 17 00:00:00 2001 From: "serena.spinoso" Date: Thu, 7 Sep 2017 10:22:39 +0200 Subject: update verigraph JIRA: PARSER-154 code optimizations about graph manipulation and formula generation. Change-Id: Idebef19b128281aa2bc40d1aeab6e208c7ddd93d Signed-off-by: serena.spinoso --- .../verify/service/JsonValidationService.java | 136 --------------------- 1 file changed, 136 deletions(-) delete mode 100644 verigraph/src/main/java/it/polito/escape/verify/service/JsonValidationService.java (limited to 'verigraph/src/main/java/it/polito/escape/verify/service/JsonValidationService.java') diff --git a/verigraph/src/main/java/it/polito/escape/verify/service/JsonValidationService.java b/verigraph/src/main/java/it/polito/escape/verify/service/JsonValidationService.java deleted file mode 100644 index 1ac6c1f..0000000 --- a/verigraph/src/main/java/it/polito/escape/verify/service/JsonValidationService.java +++ /dev/null @@ -1,136 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2017 Politecnico di Torino and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Apache License, Version 2.0 - * which accompanies this distribution, and is available at - * http://www.apache.org/licenses/LICENSE-2.0 - *******************************************************************************/ - -package it.polito.escape.verify.service; - -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.util.Iterator; -import java.util.Map.Entry; - -import org.apache.commons.lang3.text.WordUtils; - -import com.fasterxml.jackson.databind.JsonNode; - -import it.polito.escape.verify.exception.BadRequestException; -import it.polito.escape.verify.model.Graph; -import it.polito.escape.verify.model.Node; - -public class JsonValidationService { - - private Graph graph = new Graph(); - - private Node node = new Node(); - - public JsonValidationService() { - - } - - public JsonValidationService(Graph graph, Node node) { - this.graph = graph; - this.node = node; - } - - public boolean validateFieldAgainstNodeNames(String value) { - for (Node node : this.graph.getNodes().values()) { - if (node.getName().equals(value)) - return true; - } - return false; - } - - public void validateFieldsAgainstNodeNames(JsonNode node) { - if (node.isTextual()) { - boolean isValid = validateFieldAgainstNodeNames(node.asText()); - if (!isValid) { - System.out.println(node.asText() + " is not a valid string!"); - throw new BadRequestException("String '" + node.asText() - + "' is not valid for the configuration of node '" + this.node.getName() - + "'"); - } - } - if (node.isArray()) { - for (JsonNode object : node) { - validateFieldsAgainstNodeNames(object); - } - } - if (node.isObject()) { - Iterator> iter = node.fields(); - - while (iter.hasNext()) { - Entry item = iter.next(); - validateFieldsAgainstNodeNames(item.getValue()); - } - } - - } - - public boolean validateNodeConfiguration() { - String className = WordUtils.capitalize(node.getFunctional_type()) + "Validator"; - - Class validator; - try { - validator = Class.forName("it.polito.escape.verify.validation." + className); - } - catch (ClassNotFoundException e) { - System.out.println(className + " not found, configuration properties of node '" + node.getName() - + "' will be validated against node names"); - return false; - } - - Class graphClass; - Class nodeClass; - Class configurationClass; - try { - graphClass = Class.forName("it.polito.escape.verify.model.Graph"); - nodeClass = Class.forName("it.polito.escape.verify.model.Node"); - configurationClass = Class.forName("it.polito.escape.verify.model.Configuration"); - } - catch (ClassNotFoundException e) { - throw new RuntimeException("Model classes not found"); - } - - Class[] paramTypes = new Class[3]; - paramTypes[0] = graphClass; - paramTypes[1] = nodeClass; - paramTypes[2] = configurationClass; - - String methodName = "validate"; - - Object instance; - try { - instance = validator.newInstance(); - } - catch (InstantiationException e) { - throw new RuntimeException("'" + className + "' cannot be instantiated"); - } - catch (IllegalAccessException e) { - throw new RuntimeException("Illegal access to '" + className + "' instantiation"); - } - - Method myMethod; - try { - myMethod = validator.getDeclaredMethod(methodName, paramTypes); - } - catch (NoSuchMethodException e) { - throw new RuntimeException("'" + methodName + "' method has to be implemented in " + className + " class"); - } - try { - myMethod.invoke(instance, graph, node, node.getConfiguration()); - } - catch (IllegalAccessException e) { - throw new RuntimeException("Illegal access to '" + methodName + "' method in " + className + " instance"); - } - catch (InvocationTargetException e) { - throw new BadRequestException("Validation failed for node '" + node.getName() + "': " - + e.getTargetException().getMessage()); - } - return true; - } -} -- cgit 1.2.3-korg