Search in sources :

Example 6 with ObjectMapper

use of org.apache.tinkerpop.shaded.jackson.databind.ObjectMapper in project janusgraph by JanusGraph.

the class GeoshapeTest method testGeoJsonGeometry.

@Test
public void testGeoJsonGeometry() throws IOException {
    Geoshape.GeoshapeSerializer s = new Geoshape.GeoshapeSerializer();
    Map json = new ObjectMapper().readValue("{\n" + "    \"type\": \"Point\",\n" + "    \"coordinates\": [20.5, 10.5]\n" + "}", HashMap.class);
    assertEquals(Geoshape.point(10.5, 20.5), s.convert(json));
}
Also used : Geoshape(org.janusgraph.core.attribute.Geoshape) HashMap(java.util.HashMap) Map(java.util.Map) ObjectMapper(org.apache.tinkerpop.shaded.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 7 with ObjectMapper

use of org.apache.tinkerpop.shaded.jackson.databind.ObjectMapper in project janusgraph by JanusGraph.

the class GeoshapeTest method testGeoJsonInvalidBox2.

@Test(expected = IllegalArgumentException.class)
public void testGeoJsonInvalidBox2() throws IOException {
    Geoshape.GeoshapeSerializer s = new Geoshape.GeoshapeSerializer();
    Map json = new ObjectMapper().readValue("{\n" + "  \"type\": \"Feature\",\n" + "  \"geometry\": {\n" + "    \"type\": \"Polygon\",\n" + "    \"coordinates\": [[20.5, 10.5],[22.5, 10.5],[22.5, 12.5]]\n" + "  },\n" + "  \"properties\": {\n" + "    \"name\": \"Dinagat Islands\"\n" + "  }\n" + "}", HashMap.class);
    s.convert(json);
}
Also used : Geoshape(org.janusgraph.core.attribute.Geoshape) HashMap(java.util.HashMap) Map(java.util.Map) ObjectMapper(org.apache.tinkerpop.shaded.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 8 with ObjectMapper

use of org.apache.tinkerpop.shaded.jackson.databind.ObjectMapper in project unipop by unipop-graph.

the class ContextManager method reloadContexts.

private void reloadContexts() throws IOException {
    SQLDialect dialect = SQLDialect.valueOf(this.conf.getString("sqlDialect"));
    BasicDataSource ds = new BasicDataSource();
    ds.setUrl(new ObjectMapper().readValue(conf.getJSONArray("address").toString(), List.class).get(0).toString());
    ds.setDriverClassName(conf.getString("driver"));
    String user = conf.optString("user");
    String password = conf.optString("password");
    if (!user.isEmpty())
        ds.setUsername(user);
    if (!password.isEmpty())
        ds.setPassword(password);
    Settings settings = new Settings();
    settings.setRenderNameStyle(RenderNameStyle.AS_IS);
    Configuration conf = new DefaultConfiguration().set(ds).set(dialect).set(settings).set(new DefaultExecuteListenerProvider(new TimingExecuterListener()));
    this.context = DSL.using(conf);
}
Also used : DefaultConfiguration(org.jooq.impl.DefaultConfiguration) DefaultExecuteListenerProvider(org.jooq.impl.DefaultExecuteListenerProvider) List(java.util.List) DefaultConfiguration(org.jooq.impl.DefaultConfiguration) BasicDataSource(org.apache.commons.dbcp.BasicDataSource) ObjectMapper(org.apache.tinkerpop.shaded.jackson.databind.ObjectMapper) Settings(org.jooq.conf.Settings)

Example 9 with ObjectMapper

use of org.apache.tinkerpop.shaded.jackson.databind.ObjectMapper in project timbuctoo by HuygensING.

the class DatabaseLogTest method setUp.

@Before
public void setUp() throws Exception {
    objectMapper = new ObjectMapper();
    logEntryFactory = mock(LogEntryFactory.class);
    vertexLogEntry = mock(LogEntry.class);
    given(logEntryFactory.createForVertex(any(Vertex.class))).willReturn(vertexLogEntry);
    given(logEntryFactory.createForEdge(any(Edge.class))).willReturn(mock(LogEntry.class));
}
Also used : Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) VertexMatcher.likeVertex(nl.knaw.huygens.timbuctoo.util.VertexMatcher.likeVertex) LogEntryFactory(nl.knaw.huygens.timbuctoo.databaselog.entry.LogEntryFactory) EdgeMatcher.likeEdge(nl.knaw.huygens.timbuctoo.util.EdgeMatcher.likeEdge) Edge(org.apache.tinkerpop.gremlin.structure.Edge) ObjectMapper(org.apache.tinkerpop.shaded.jackson.databind.ObjectMapper) Before(org.junit.Before)

Example 10 with ObjectMapper

use of org.apache.tinkerpop.shaded.jackson.databind.ObjectMapper in project timbuctoo by HuygensING.

the class IndexAllEntityIds method execute.

@Override
public void execute(TinkerPopGraphManager graphManager) throws IOException {
    Vres vres = getVres(graphManager);
    Neo4jIndexHandler indexHandler = new Neo4jIndexHandler(graphManager);
    ObjectMapper mapper = new ObjectMapper();
    GraphTraversalSource traversalSource = graphManager.getGraph().traversal();
    traversalSource.V().has(// only valid entities
    "types").forEachRemaining(vertex -> {
        try {
            String[] types = mapper.readValue(vertex.<String>value("types"), String[].class);
            for (String type : types) {
                if (TYPES_TO_IGNORE.contains(type)) {
                    continue;
                }
                if (vres.getCollectionForType(type).isPresent()) {
                    VertexProperty<String> timIdProp = vertex.property("tim_id");
                    if (timIdProp.isPresent()) {
                        try {
                            UUID timId = UUID.fromString(timIdProp.value());
                            indexHandler.insertIntoIdIndex(timId, vertex);
                        } catch (IllegalArgumentException e) {
                            // This exception should not happen, but we do not want our migration to fail on it.
                            LOG.error("'{}' is not a valid id", timIdProp.value());
                        }
                    } else {
                        LOG.error("Vertex with id '{}' has no 'tim_id' property", vertex.id());
                    }
                } else {
                    LOG.error("'{}' is not a known entity type.", type);
                }
            }
        } catch (IOException e) {
            LOG.error("And exception occurred while indexing vertex with vertex id '{}'.", vertex.id());
        }
    });
}
Also used : GraphTraversalSource(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource) Vres(nl.knaw.huygens.timbuctoo.model.vre.Vres) TinkerPopOperationsForMigrations.getVres(nl.knaw.huygens.timbuctoo.server.databasemigration.TinkerPopOperationsForMigrations.getVres) Neo4jIndexHandler(nl.knaw.huygens.timbuctoo.database.tinkerpop.Neo4jIndexHandler) IOException(java.io.IOException) UUID(java.util.UUID) ObjectMapper(org.apache.tinkerpop.shaded.jackson.databind.ObjectMapper)

Aggregations

ObjectMapper (org.apache.tinkerpop.shaded.jackson.databind.ObjectMapper)35 HashMap (java.util.HashMap)26 Map (java.util.Map)26 Geoshape (org.janusgraph.core.attribute.Geoshape)14 Test (org.junit.Test)14 Test (org.junit.jupiter.api.Test)14 Coordinate (com.vividsolutions.jts.geom.Coordinate)4 Coordinate (org.locationtech.jts.geom.Coordinate)4 HttpHost (org.apache.http.HttpHost)3 HttpDelete (org.apache.http.client.methods.HttpDelete)3 LinearRing (com.vividsolutions.jts.geom.LinearRing)2 SimpleModule (org.apache.tinkerpop.shaded.jackson.databind.module.SimpleModule)2 Before (org.junit.Before)2 LinearRing (org.locationtech.jts.geom.LinearRing)2 JtsSpatialContext (org.locationtech.spatial4j.context.jts.JtsSpatialContext)2 IOException (java.io.IOException)1 List (java.util.List)1 UUID (java.util.UUID)1 Neo4jIndexHandler (nl.knaw.huygens.timbuctoo.database.tinkerpop.Neo4jIndexHandler)1 LogEntryFactory (nl.knaw.huygens.timbuctoo.databaselog.entry.LogEntryFactory)1