Search in sources :

Example 41 with GraphObjectMap

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

the class ImportGPXFunction method apply.

@Override
public Object apply(final ActionContext ctx, final Object caller, final Object[] sources) throws FrameworkException {
    if (arrayHasLengthAndAllElementsNotNull(sources, 1)) {
        if (sources[0] instanceof String) {
            final String source = (String) sources[0];
            if (source != null) {
                // parse source, create a list of points
                final GraphObjectMap result = new GraphObjectMap();
                final XmlFunction xmlParser = new XmlFunction();
                final Document doc = (Document) xmlParser.apply(ctx, caller, sources);
                final List<GraphObjectMap> waypoints = new LinkedList<>();
                final List<GraphObjectMap> routes = new LinkedList<>();
                final List<GraphObjectMap> tracks = new LinkedList<>();
                if (doc != null) {
                    final Element root = doc.getDocumentElement();
                    final List<Element> children = getChildren(root);
                    for (final Element child : children) {
                        switch(child.getTagName()) {
                            case "metadata":
                                final GraphObjectMap metadata = readPoint(child);
                                if (metadata != null) {
                                    result.put(metadataProperty, metadata);
                                }
                                break;
                            case "rte":
                                readRoute(child, routes);
                                break;
                            case "wpt":
                                readWaypoint(child, waypoints);
                                break;
                            case "trk":
                                readTrack(child, tracks);
                                break;
                        }
                    }
                    if (!waypoints.isEmpty()) {
                        result.put(waypointsProperty, waypoints);
                    }
                    if (!routes.isEmpty()) {
                        result.put(routesProperty, routes);
                    }
                    if (!tracks.isEmpty()) {
                        result.put(tracksProperty, tracks);
                    }
                }
                return result;
            }
        } else {
            logger.warn("Invalid parameter for GPX import, expected string, got {}", sources[0].getClass().getSimpleName());
        }
        return "Invalid parameters";
    }
    return usage(ctx != null ? ctx.isJavaScriptContext() : false);
}
Also used : XmlFunction(org.structr.core.function.XmlFunction) GraphObjectMap(org.structr.core.GraphObjectMap) Element(org.w3c.dom.Element) Document(org.w3c.dom.Document) LinkedList(java.util.LinkedList)

Example 42 with GraphObjectMap

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

the class ImportGPXFunction method readPoint.

private GraphObjectMap readPoint(final Element point) {
    final GraphObjectMap item = new GraphObjectMap();
    // latitude and longitude are the only node attributes
    final Double latitude = getDoubleAttribute(point, "lat");
    if (latitude != null) {
        item.put(latitudeProperty, latitude);
    }
    // latitude and longitude are the only node attributes
    final Double longitude = getDoubleAttribute(point, "lon");
    if (longitude != null) {
        item.put(longitudeProperty, longitude);
    }
    // all other attributes are stored in child nodes
    for (final Element child : getChildren(point)) {
        readProperties(child, item);
    }
    return item;
}
Also used : GraphObjectMap(org.structr.core.GraphObjectMap) Element(org.w3c.dom.Element)

Example 43 with GraphObjectMap

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

the class UTMToLatLonFunction method utmToLatLon.

private GraphObjectMap utmToLatLon(final String zone, final String hemisphere, final String east, final String north) {
    final GraphObjectMap obj = new GraphObjectMap();
    // clean zone string (remove all non-digits)
    final String cleanedZone = zone.replaceAll("[\\D]+", "");
    final StringBuilder epsg = new StringBuilder("EPSG:32");
    switch(hemisphere) {
        case "N":
            epsg.append("6");
            break;
        case "S":
            epsg.append("7");
            break;
    }
    // append "0" to zone number of single-digit
    if (cleanedZone.length() == 1) {
        epsg.append("0");
    }
    // append zone number
    epsg.append(cleanedZone);
    try {
        final CoordinateReferenceSystem src = CRS.decode(epsg.toString());
        final CoordinateReferenceSystem dst = CRS.decode("EPSG:4326");
        final MathTransform transform = CRS.findMathTransform(src, dst, true);
        final DirectPosition sourcePt = new DirectPosition2D(getDoubleOrNull(east), getDoubleOrNull(north));
        final DirectPosition targetPt = transform.transform(sourcePt, null);
        obj.put(latitudeProperty, targetPt.getOrdinate(0));
        obj.put(longitudeProperty, targetPt.getOrdinate(1));
    } catch (Throwable t) {
        logger.warn("", t);
    }
    return obj;
}
Also used : DirectPosition(org.opengis.geometry.DirectPosition) MathTransform(org.opengis.referencing.operation.MathTransform) GraphObjectMap(org.structr.core.GraphObjectMap) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) DirectPosition2D(org.geotools.geometry.DirectPosition2D)

Example 44 with GraphObjectMap

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

the class VideoFile method getMetadata.

static RestMethodResult getMetadata(final VideoFile thisVideo) throws FrameworkException {
    final SecurityContext securityContext = thisVideo.getSecurityContext();
    final Map<String, String> metadata = AVConv.newInstance(securityContext, thisVideo).getMetadata();
    final RestMethodResult result = new RestMethodResult(200);
    final GraphObjectMap map = new GraphObjectMap();
    for (final Entry<String, String> entry : metadata.entrySet()) {
        map.setProperty(new StringProperty(entry.getKey()), entry.getValue());
    }
    result.addContent(map);
    return result;
}
Also used : GraphObjectMap(org.structr.core.GraphObjectMap) SecurityContext(org.structr.common.SecurityContext) StringProperty(org.structr.core.property.StringProperty) RestMethodResult(org.structr.rest.RestMethodResult)

Example 45 with GraphObjectMap

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

the class SchemaResource method getSchemaOverviewResult.

// ----- public static methods -----
public static Result getSchemaOverviewResult() throws FrameworkException {
    final List<GraphObjectMap> resultList = new LinkedList<>();
    final ConfigurationProvider config = StructrApp.getConfiguration();
    // extract types from ModuleService
    final Set<String> nodeEntityKeys = config.getNodeEntities().keySet();
    final Set<String> relEntityKeys = config.getRelationshipEntities().keySet();
    Set<String> entityKeys = new HashSet<>();
    entityKeys.addAll(nodeEntityKeys);
    entityKeys.addAll(relEntityKeys);
    for (String rawType : entityKeys) {
        // create & add schema information
        Class type = SchemaHelper.getEntityClassForRawType(rawType);
        GraphObjectMap schema = new GraphObjectMap();
        resultList.add(schema);
        if (type != null) {
            String url = "/".concat(rawType);
            final boolean isRel = AbstractRelationship.class.isAssignableFrom(type);
            schema.setProperty(urlProperty, url);
            schema.setProperty(typeProperty, type.getSimpleName());
            schema.setProperty(nameProperty, type.getSimpleName());
            schema.setProperty(classNameProperty, type.getName());
            schema.setProperty(extendsClassNameProperty, type.getSuperclass().getName());
            schema.setProperty(isRelProperty, isRel);
            schema.setProperty(flagsProperty, SecurityContext.getResourceFlags(rawType));
            if (!isRel) {
                final List<GraphObjectMap> relatedTo = new LinkedList<>();
                final List<GraphObjectMap> relatedFrom = new LinkedList<>();
                for (final PropertyKey key : config.getPropertySet(type, PropertyView.All)) {
                    if (key instanceof RelationProperty) {
                        final RelationProperty relationProperty = (RelationProperty) key;
                        final Relation relation = relationProperty.getRelation();
                        if (!relation.isHidden()) {
                            switch(relation.getDirectionForType(type)) {
                                case OUTGOING:
                                    relatedTo.add(relationPropertyToMap(config, relationProperty));
                                    break;
                                case INCOMING:
                                    relatedFrom.add(relationPropertyToMap(config, relationProperty));
                                    break;
                                case BOTH:
                                    relatedTo.add(relationPropertyToMap(config, relationProperty));
                                    relatedFrom.add(relationPropertyToMap(config, relationProperty));
                                    break;
                            }
                        }
                    }
                }
                if (!relatedTo.isEmpty()) {
                    schema.setProperty(relatedToProperty, relatedTo);
                }
                if (!relatedFrom.isEmpty()) {
                    schema.setProperty(relatedFromProperty, relatedFrom);
                }
            }
        }
    }
    return new Result(resultList, resultList.size(), false, false);
}
Also used : RelationProperty(org.structr.core.property.RelationProperty) ConfigurationProvider(org.structr.schema.ConfigurationProvider) LinkedList(java.util.LinkedList) Result(org.structr.core.Result) RestMethodResult(org.structr.rest.RestMethodResult) Relation(org.structr.core.entity.Relation) GraphObjectMap(org.structr.core.GraphObjectMap) PropertyKey(org.structr.core.property.PropertyKey) HashSet(java.util.HashSet)

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