diff options
author | julien zhang <zhang.jun3g@zte.com.cn> | 2017-09-12 14:47:37 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@opnfv.org> | 2017-09-12 14:47:37 +0000 |
commit | 8153ff1bac0ec3664c777302396698e4fb5f34b9 (patch) | |
tree | 2b97892774e3ced5f0c10e400657d28f9222749b /verigraph/src/main/java/it/polito/escape/verify/deserializer | |
parent | 96de9387460091e7cf0dc5fde1afaa637a8b2b79 (diff) | |
parent | a42de79292d9541db7865b54e93be2d0b6e6a094 (diff) |
Merge "update verigraph"
Diffstat (limited to 'verigraph/src/main/java/it/polito/escape/verify/deserializer')
4 files changed, 0 insertions, 273 deletions
diff --git a/verigraph/src/main/java/it/polito/escape/verify/deserializer/ConfigurationCustomDeserializer.java b/verigraph/src/main/java/it/polito/escape/verify/deserializer/ConfigurationCustomDeserializer.java deleted file mode 100644 index 5cdd084..0000000 --- a/verigraph/src/main/java/it/polito/escape/verify/deserializer/ConfigurationCustomDeserializer.java +++ /dev/null @@ -1,42 +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.deserializer; - -import java.io.IOException; - -import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.DeserializationContext; -import com.fasterxml.jackson.databind.JsonDeserializer; -import com.fasterxml.jackson.databind.JsonNode; - -import it.polito.escape.verify.exception.InternalServerErrorException; -import it.polito.escape.verify.model.Configuration; - -public class ConfigurationCustomDeserializer extends JsonDeserializer<Configuration> { - - @Override - public Configuration deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, - JsonProcessingException { - try { - JsonNode root = jp.getCodec().readTree(jp); - - return new Configuration("", "", root); - } - catch (JsonProcessingException e) { - throw new InternalServerErrorException("Error parsing configuration: " + e.getMessage()); - } - catch (IOException e) { - throw new InternalServerErrorException("I/O error parsing configuration: " + e.getMessage()); - } - - } - -} diff --git a/verigraph/src/main/java/it/polito/escape/verify/deserializer/GraphCustomDeserializer.java b/verigraph/src/main/java/it/polito/escape/verify/deserializer/GraphCustomDeserializer.java deleted file mode 100644 index f71c996..0000000 --- a/verigraph/src/main/java/it/polito/escape/verify/deserializer/GraphCustomDeserializer.java +++ /dev/null @@ -1,87 +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.deserializer; - -import java.io.IOException; -import java.util.List; -import java.util.Map; - -import com.fasterxml.jackson.core.JsonParseException; -import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.DeserializationContext; -import com.fasterxml.jackson.databind.JsonDeserializer; -import com.fasterxml.jackson.databind.JsonMappingException; -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.type.TypeFactory; - -import it.polito.escape.verify.exception.BadRequestException; -import it.polito.escape.verify.exception.InternalServerErrorException; -import it.polito.escape.verify.model.Graph; -import it.polito.escape.verify.model.Node; - - -/** - * The Class GraphCustomDeserializer is a custom deserializer for a Graph object - */ -public class GraphCustomDeserializer extends JsonDeserializer<Graph>{ - - /* (non-Javadoc) - * @see com.fasterxml.jackson.databind.JsonDeserializer#deserialize(com.fasterxml.jackson.core.JsonParser, com.fasterxml.jackson.databind.DeserializationContext) - */ - @Override - public Graph deserialize(JsonParser jp, DeserializationContext context){ - JsonNode root = null; - try { - root = jp.getCodec().readTree(jp); - } - catch (JsonProcessingException e) { - throw new InternalServerErrorException("Error parsing a graph: " + e.getMessage()); - } - catch (IOException e) { - throw new InternalServerErrorException("I/O error parsing a graph: " + e.getMessage()); - } - - JsonNode nodesJson = root.get("nodes"); - - if(nodesJson == null) - throw new BadRequestException("Invalid graph"); - - List<Node> nodeList = null; - try { - nodeList = new ObjectMapper().readValue(nodesJson.toString(), TypeFactory.defaultInstance().constructCollectionType(List.class, Node.class)); - } - catch (JsonParseException e) { - throw new BadRequestException("Invalid content for a graph: " + e.getMessage()); - } - catch (JsonMappingException e) { - throw new BadRequestException("Invalid input json structure for a graph: " + e.getMessage()); - } - catch (IOException e) { - throw new InternalServerErrorException("I/O error parsing a graph: " + e.getMessage()); - } - - Graph graph = new Graph(); - if(root.get("id") != null){ - long graphId = root.get("id").asLong(); - graph.setId(graphId); - } - Map<Long, Node> nodes = graph.getNodes(); - - long numberOfNodes = 0; - for (Node node : nodeList){ - nodes.put(++numberOfNodes, node); - } - return graph; - - } - -} diff --git a/verigraph/src/main/java/it/polito/escape/verify/deserializer/NodeCustomDeserializer.java b/verigraph/src/main/java/it/polito/escape/verify/deserializer/NodeCustomDeserializer.java deleted file mode 100644 index fb451db..0000000 --- a/verigraph/src/main/java/it/polito/escape/verify/deserializer/NodeCustomDeserializer.java +++ /dev/null @@ -1,92 +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.deserializer; - -import java.io.IOException; -import java.util.List; -import java.util.Map; - -import com.fasterxml.jackson.core.JsonParseException; -import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.DeserializationContext; -import com.fasterxml.jackson.databind.JsonDeserializer; -import com.fasterxml.jackson.databind.JsonMappingException; -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.type.TypeFactory; - -import it.polito.escape.verify.exception.BadRequestException; -import it.polito.escape.verify.exception.InternalServerErrorException; -import it.polito.escape.verify.model.Configuration; -import it.polito.escape.verify.model.Neighbour; -import it.polito.escape.verify.model.Node; - -public class NodeCustomDeserializer extends JsonDeserializer<Node> { - - @Override - public Node deserialize(JsonParser jp, DeserializationContext context) { - - try { - JsonNode root = jp.getCodec().readTree(jp); - JsonNode neighboursJson = root.get("neighbours"); - JsonNode configurationJson = root.get("configuration"); - - String nodeName = root.get("name").asText(); - String functionalType = root.get("functional_type").asText(); - - Node node = new Node(); - if(root.get("id") != null){ - long nodeId = root.get("id").asLong(); - node.setId(nodeId); - } - node.setName(nodeName); - node.setFunctional_type(functionalType); - - if (configurationJson == null) - node.setConfiguration(new Configuration(node.getName(), "", new ObjectMapper().createArrayNode())); - else { - Configuration conf = node.getConfiguration(); - conf.setId(node.getName()); - conf.setDescription(""); - conf.setConfiguration(configurationJson); - } - - try { - List<Neighbour> neighbourList = new ObjectMapper().readValue( neighboursJson.toString(), - TypeFactory .defaultInstance() - .constructCollectionType( List.class, - Neighbour.class)); - Map<Long, Neighbour> neighbours = node.getNeighbours(); - - long numberOfNeighbours = 0; - for (Neighbour neighbour : neighbourList) { - neighbours.put(++numberOfNeighbours, neighbour); - } - - return node; - } - catch (JsonParseException e) { - throw new BadRequestException("Invalid content for a node: " + e.getMessage()); - } - catch (JsonMappingException e) { - throw new BadRequestException("Invalid input json structure for a node: " + e.getMessage()); - } - } - catch (JsonProcessingException e) { - throw new InternalServerErrorException("Error parsing a node: " + e.getMessage()); - } - catch (IOException e) { - throw new InternalServerErrorException("I/O error parsing a node: " + e.getMessage()); - } - - } - -} diff --git a/verigraph/src/main/java/it/polito/escape/verify/deserializer/PathsMessageBodyReader.java b/verigraph/src/main/java/it/polito/escape/verify/deserializer/PathsMessageBodyReader.java deleted file mode 100644 index 3b54503..0000000 --- a/verigraph/src/main/java/it/polito/escape/verify/deserializer/PathsMessageBodyReader.java +++ /dev/null @@ -1,52 +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.deserializer; - -import java.io.IOException; -import java.io.InputStream; -import java.lang.annotation.Annotation; -import java.lang.reflect.Type; -import javax.ws.rs.Consumes; -import javax.ws.rs.ProcessingException; -import javax.ws.rs.WebApplicationException; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.MultivaluedMap; -import javax.ws.rs.ext.MessageBodyReader; -import javax.ws.rs.ext.Provider; -import javax.xml.bind.JAXBContext; -import javax.xml.bind.JAXBException; - -import it.polito.nffg.neo4j.jaxb.Paths; - -@Provider -@Consumes(MediaType.APPLICATION_XML) -public class PathsMessageBodyReader implements MessageBodyReader<Paths>{ - - @Override - public boolean isReadable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) { - return type == Paths.class; - } - - @Override - public Paths readFrom(Class<Paths> type, Type genericType, Annotation[] annotations, MediaType mediaType, - MultivaluedMap<String, String> httpHeaders, InputStream entityStream) - throws IOException, WebApplicationException { - try { - JAXBContext jaxbContext = JAXBContext.newInstance(Paths.class); - Paths paths = (Paths) jaxbContext.createUnmarshaller() - .unmarshal(entityStream); - return paths; - } catch (JAXBException jaxbException) { - throw new ProcessingException("Error deserializing a Paths object.", - jaxbException); - } - } - -} |