Search in sources :

Example 16 with GraphObjectMap

use of org.structr.core.GraphObjectMap in project structr by structr.

the class GeoTest method testGPXImport.

@Test
public void testGPXImport() {
    try {
        final ImportGPXFunction func = new ImportGPXFunction();
        final StringBuilder gpx = new StringBuilder();
        gpx.append("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\" ?>");
        gpx.append("<gpx xmlns=\"http://www.topografix.com/GPX/1/1\" version=\"1.1\" creator=\"Wikipedia\"");
        gpx.append("    xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"");
        gpx.append("    xsi:schemaLocation=\"http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd\">");
        gpx.append(" <!-- Kommentare sehen so aus -->");
        gpx.append(" <metadata>");
        gpx.append("  <name>Dateiname</name>");
        gpx.append("  <desc>Validiertes GPX-Beispiel ohne Sonderzeichen</desc>");
        gpx.append("  <author>");
        gpx.append("   <name>Autorenname</name>");
        gpx.append("  </author>");
        gpx.append(" </metadata>");
        gpx.append(" <wpt lat=\"52.518611\" lon=\"13.376111\">");
        gpx.append("  <ele>35.0</ele>");
        gpx.append("  <time>2011-12-31T23:59:59Z</time>");
        gpx.append("  <name>Reichstag (Berlin)</name>");
        gpx.append("  <sym>City</sym>");
        gpx.append(" </wpt>");
        gpx.append(" <wpt lat=\"48.208031\" lon=\"16.358128\">");
        gpx.append("  <ele>179</ele>");
        gpx.append("  <time>2011-12-31T23:59:59Z</time>");
        gpx.append("  <name>Parlament (Wien)</name>");
        gpx.append("  <sym>City</sym>");
        gpx.append(" </wpt>");
        gpx.append(" <wpt lat=\"46.9466\" lon=\"7.44412\">");
        gpx.append("  <time>2011-12-31T23:59:59Z</time>");
        gpx.append("  <name>Bundeshaus (Bern)</name>");
        gpx.append("  <sym>City</sym>");
        gpx.append(" </wpt>");
        gpx.append(" <rte>");
        gpx.append("  <name>Routenname</name>");
        gpx.append("  <desc>Routenbeschreibung</desc>");
        gpx.append("  <rtept lat=\"52.0\" lon=\"13.5\">");
        gpx.append("   <ele>33.0</ele>");
        gpx.append("   <time>2011-12-13T23:59:59Z</time>");
        gpx.append("   <name>rtept 1</name>");
        gpx.append("  </rtept>");
        gpx.append("  <rtept lat=\"49\" lon=\"12\">");
        gpx.append("   <name>rtept 2</name>");
        gpx.append("  </rtept>");
        gpx.append("  <rtept lat=\"47.0\" lon=\"7.5\">");
        gpx.append("  </rtept>");
        gpx.append(" </rte>");
        gpx.append(" <trk>");
        gpx.append("  <name>Trackname1</name>");
        gpx.append("  <desc>Trackbeschreibung</desc>");
        gpx.append("  <trkseg>");
        gpx.append("   <trkpt lat=\"52.520000\" lon=\"13.380000\">");
        gpx.append("    <ele>36.0</ele>");
        gpx.append("    <time>2011-01-13T01:01:01Z</time>");
        gpx.append("   </trkpt>");
        gpx.append("   <trkpt lat=\"48.200000\" lon=\"16.260000\">");
        gpx.append("    <ele>180</ele>");
        gpx.append("    <time>2011-01-14T01:59:01Z</time>");
        gpx.append("   </trkpt>");
        gpx.append("   <trkpt lat=\"46.95\" lon=\"7.4\">");
        gpx.append("    <ele>987.654</ele>");
        gpx.append("    <time>2011-01-15T23:59:01Z</time>");
        gpx.append("   </trkpt>");
        gpx.append("  </trkseg>");
        gpx.append(" </trk>");
        gpx.append(" <trk>");
        gpx.append("  <name>Trackname2</name>");
        gpx.append("  <trkseg>");
        gpx.append("   <trkpt lat=\"47.2\" lon=\"7.41\">");
        gpx.append("    <time>2011-01-16T23:59:01Z</time>");
        gpx.append("   </trkpt>");
        gpx.append("   <trkpt lat=\"52.53\" lon=\"13.0\">");
        gpx.append("   </trkpt>");
        gpx.append("  </trkseg>");
        gpx.append(" </trk>");
        gpx.append("</gpx>");
        final GraphObjectMap obj = (GraphObjectMap) func.apply(null, null, new Object[] { gpx.toString() });
        System.out.println(obj);
    } catch (FrameworkException fex) {
        logger.warn("", fex);
        fail("Unexpected exception");
    }
}
Also used : FrameworkException(org.structr.common.error.FrameworkException) GraphObjectMap(org.structr.core.GraphObjectMap) Test(org.junit.Test)

Example 17 with GraphObjectMap

use of org.structr.core.GraphObjectMap in project structr by structr.

the class GeoTest method testUTMLatLonRoundTrip.

@Test
public void testUTMLatLonRoundTrip() {
    final LatLonToUTMFunction latLonUtm = new LatLonToUTMFunction();
    final UTMToLatLonFunction utmLatLon = new UTMToLatLonFunction();
    final String sourceUTM = "32U 439596 5967780";
    try {
        final GraphObjectMap result1 = (GraphObjectMap) utmLatLon.apply(null, null, new Object[] { sourceUTM });
        final String result2 = (String) latLonUtm.apply(null, null, new Object[] { result1.getProperty(UTMToLatLonFunction.latitudeProperty), result1.getProperty(UTMToLatLonFunction.longitudeProperty) });
        Assert.assertEquals("Invalid UTM to lat/lon roundtrip result", sourceUTM, result2);
    } catch (FrameworkException fex) {
        logger.warn("", fex);
        fail("Unexpected exception");
    }
}
Also used : FrameworkException(org.structr.common.error.FrameworkException) GraphObjectMap(org.structr.core.GraphObjectMap) Test(org.junit.Test)

Example 18 with GraphObjectMap

use of org.structr.core.GraphObjectMap in project structr by structr.

the class Function method toGraphObjectMap.

public static GraphObjectMap toGraphObjectMap(final Map<String, Object> src) {
    final GraphObjectMap dest = new GraphObjectMap();
    recursivelyConvertMapToGraphObjectMap(dest, src, 0);
    return dest;
}
Also used : GraphObjectMap(org.structr.core.GraphObjectMap)

Example 19 with GraphObjectMap

use of org.structr.core.GraphObjectMap in project structr by structr.

the class Function method toGraphObject.

public static Object toGraphObject(final Object sourceObject, final Integer outputDepth) {
    if (sourceObject instanceof GraphObject) {
        return sourceObject;
    } else if (sourceObject instanceof List) {
        final List list = (List) sourceObject;
        final List<GraphObject> res = new ArrayList<>();
        for (final Object o : list) {
            if (o instanceof Map) {
                final GraphObjectMap newObj = new GraphObjectMap();
                Function.recursivelyConvertMapToGraphObjectMap(newObj, (Map) o, outputDepth);
                res.add(newObj);
            } else if (o instanceof GraphObject) {
                res.add((GraphObject) o);
            } else if (o instanceof String) {
                res.add(Function.wrapStringInGraphObjectMap((String) o));
            }
        }
        return res;
    } else if (sourceObject instanceof Map) {
        final GraphObjectMap map = new GraphObjectMap();
        Function.recursivelyConvertMapToGraphObjectMap(map, (Map) sourceObject, outputDepth);
        return map;
    } else if (sourceObject instanceof String[]) {
        final List<GraphObject> res = new ArrayList<>();
        for (final String s : (String[]) sourceObject) {
            res.add(Function.wrapStringInGraphObjectMap(s));
        }
        return res;
    } else if (sourceObject instanceof String) {
        return Function.wrapStringInGraphObjectMap((String) sourceObject);
    }
    return null;
}
Also used : GraphObjectMap(org.structr.core.GraphObjectMap) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) GraphObject(org.structr.core.GraphObject) GraphObject(org.structr.core.GraphObject) Map(java.util.Map) GraphObjectMap(org.structr.core.GraphObjectMap)

Example 20 with GraphObjectMap

use of org.structr.core.GraphObjectMap in project structr by structr.

the class Function method wrapStringInGraphObjectMap.

public static GraphObjectMap wrapStringInGraphObjectMap(final String str) {
    final GraphObjectMap stringWrapperObject = new GraphObjectMap();
    stringWrapperObject.put(new StringProperty("value"), str);
    return stringWrapperObject;
}
Also used : GraphObjectMap(org.structr.core.GraphObjectMap) StringProperty(org.structr.core.property.StringProperty)

Aggregations

GraphObjectMap (org.structr.core.GraphObjectMap)60 LinkedList (java.util.LinkedList)27 GraphObject (org.structr.core.GraphObject)24 Map (java.util.Map)18 FrameworkException (org.structr.common.error.FrameworkException)16 StringProperty (org.structr.core.property.StringProperty)15 GenericProperty (org.structr.core.property.GenericProperty)13 PropertyKey (org.structr.core.property.PropertyKey)12 List (java.util.List)11 Result (org.structr.core.Result)10 SecurityContext (org.structr.common.SecurityContext)8 IntProperty (org.structr.core.property.IntProperty)8 RestMethodResult (org.structr.rest.RestMethodResult)8 ArrayList (java.util.ArrayList)6 Collection (java.util.Collection)6 Test (org.junit.Test)6 ConfigurationProvider (org.structr.schema.ConfigurationProvider)6 HashMap (java.util.HashMap)5 LinkedHashSet (java.util.LinkedHashSet)5 Tx (org.structr.core.graph.Tx)5