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);
}
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;
}
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;
}
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;
}
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);
}
Aggregations