diff options
author | 2017-09-07 10:22:39 +0200 | |
---|---|---|
committer | 2017-09-12 08:42:03 +0200 | |
commit | a42de79292d9541db7865b54e93be2d0b6e6a094 (patch) | |
tree | cc357be8dc0030be4fa965273c4074f0dcb79345 /verigraph/src/main/java/it/polito/grpc/GrpcUtils.java | |
parent | dd361d8d9df7a69a4fc7c004db5b959440a024c2 (diff) |
update verigraph
JIRA: PARSER-154
code optimizations about graph manipulation and formula generation.
Change-Id: Idebef19b128281aa2bc40d1aeab6e208c7ddd93d
Signed-off-by: serena.spinoso <serena.spinoso@polito.it>
Diffstat (limited to 'verigraph/src/main/java/it/polito/grpc/GrpcUtils.java')
-rw-r--r-- | verigraph/src/main/java/it/polito/grpc/GrpcUtils.java | 156 |
1 files changed, 0 insertions, 156 deletions
diff --git a/verigraph/src/main/java/it/polito/grpc/GrpcUtils.java b/verigraph/src/main/java/it/polito/grpc/GrpcUtils.java deleted file mode 100644 index 0ed002c..0000000 --- a/verigraph/src/main/java/it/polito/grpc/GrpcUtils.java +++ /dev/null @@ -1,156 +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.grpc; - -import java.io.IOException; -import java.util.Map; -import java.util.logging.Level; -import java.util.logging.Logger; - -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.Splitter; - -import io.grpc.verigraph.ConfigurationGrpc; -import io.grpc.verigraph.GraphGrpc; -import io.grpc.verigraph.NeighbourGrpc; -import io.grpc.verigraph.NodeGrpc; -import io.grpc.verigraph.TestGrpc; -import io.grpc.verigraph.VerificationGrpc; -import io.grpc.verigraph.NodeGrpc.FunctionalType; -import it.polito.escape.verify.model.Configuration; -import it.polito.escape.verify.model.Graph; -import it.polito.escape.verify.model.Neighbour; -import it.polito.escape.verify.model.Node; -import it.polito.escape.verify.model.Test; -import it.polito.escape.verify.model.Verification; - -public class GrpcUtils { - private static final Logger logger = Logger.getLogger(GrpcUtils.class.getName()); - - public static NeighbourGrpc obtainNeighbour(Neighbour ne){ - return NeighbourGrpc.newBuilder() - .setId(ne.getId()) - .setName(ne.getName()) - .build(); - } - - public static Neighbour deriveNeighbour(NeighbourGrpc request) { - //id is not present - Neighbour ne = new Neighbour(); - ne.setName(request.getName()); - return ne; - } - - public static ConfigurationGrpc obtainConfiguration(Configuration conf){ - return ConfigurationGrpc.newBuilder() - .setId(conf.getId()) - .setDescription(conf.getDescription()) - .setConfiguration(conf.getConfiguration().toString()) - .build(); - } - - public static Configuration deriveConfiguration(ConfigurationGrpc request) { - Configuration conf = new Configuration(); - conf.setId(request.getId()); - conf.setDescription(request.getDescription()); - ObjectMapper mapper = new ObjectMapper(); - JsonNode rootNode = null; - try { - if ("".equals(request.getConfiguration())) - rootNode=mapper.readTree("[]"); - else - rootNode = mapper.readTree(request.getConfiguration()); - } catch (IOException e) { - logger.log(Level.WARNING, e.getMessage()); - } - conf.setConfiguration(rootNode); - return conf; - } - - public static NodeGrpc obtainNode(Node node) { - NodeGrpc.Builder nr = NodeGrpc.newBuilder(); - nr.setId(node.getId()); - nr.setName(node.getName()); - nr.setFunctionalType(FunctionalType.valueOf(node.getFunctional_type())); - for(Neighbour neighbour:node.getNeighbours().values()){ - NeighbourGrpc ng = obtainNeighbour(neighbour); - nr.addNeighbour(ng); - } - nr.setConfiguration(obtainConfiguration(node.getConfiguration())); - return nr.build(); - } - - public static Node deriveNode(NodeGrpc request) { - //id is not present - Node node = new Node(); - node.setName(request.getName()); - node.setFunctional_type(request.getFunctionalType().toString()); - Configuration conf = deriveConfiguration(request.getConfiguration()); - node.setConfiguration(conf); - - Map<Long,Neighbour> neighours = node.getNeighbours(); - long i = 1; - for(NeighbourGrpc neighbour:request.getNeighbourList()){ - Neighbour ng = deriveNeighbour(neighbour); - neighours.put(i++, ng); - } - - return node; - } - - public static GraphGrpc obtainGraph(Graph graph){ - GraphGrpc.Builder gr = GraphGrpc.newBuilder(); - gr.setId(graph.getId()); - for(Node node:graph.getNodes().values()){ - NodeGrpc ng = obtainNode(node); - gr.addNode(ng); - } - return gr.build(); - } - - public static Graph deriveGraph(GraphGrpc request) { - //id is not present - Graph graph = new Graph(); - - long i=1; - Map<Long, Node> nodes = graph.getNodes(); - for(NodeGrpc node:request.getNodeList()){ - Node ng = deriveNode(node); - nodes.put(i++, ng); - } - - return graph; - } - - public static VerificationGrpc obtainVerification(Verification verify){ - VerificationGrpc.Builder ver = VerificationGrpc.newBuilder(); - ver.setComment(verify.getComment()); - ver.setResult(verify.getResult()); - for(Test test:verify.getTests()){ - TestGrpc.Builder tst = TestGrpc.newBuilder().setResult(test.getResult()); - for(Node node:test.getPath()){ - NodeGrpc ng = obtainNode(node); - tst.addNode(ng); - } - ver.addTest(tst); - } - return ver.build(); - } - - /**Intended for string that begins with "?" - * */ - public static Map<String,String> getParamGivenString(String str){ - String string = str.substring(1); - final Map<String, String> map = Splitter.on('&').trimResults().withKeyValueSeparator("="). - split(string); - return map; - } -} |