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/escape/verify/deserializer/GraphCustomDeserializer.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/escape/verify/deserializer/GraphCustomDeserializer.java')
-rw-r--r-- | verigraph/src/main/java/it/polito/escape/verify/deserializer/GraphCustomDeserializer.java | 87 |
1 files changed, 0 insertions, 87 deletions
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; - - } - -} |