Skip to content

Commit 3856b48

Browse files
committed
export all last features
1 parent 20214ae commit 3856b48

File tree

9 files changed

+15194
-115
lines changed

9 files changed

+15194
-115
lines changed
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1-
The OpenShift `nodejs` cartridge documentation can be found at:
1+
HOSTING DOCUMENTATION
22

33
http://openshift.github.io/documentation/oo_cartridge_guide.html#nodejs
4+
5+
TESTS
6+
7+
https://github.com/dimik/ymaps/blob/master/remote-object-manager-server/test/express.spec.js

remote-object-manager-server/app-worker.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ var bodyParser = require('body-parser');
88
var app = express();
99
var api = require('./routes/api');
1010

11-
app.use(bodyParser.json());
11+
app.use(bodyParser.json({ limit: 100000000 }));
1212
app.use(uncaughtExceptionHandler);
13-
app.use('/api', api);
13+
app.use('/api/v1', api);
1414
app.use(errorHandler);
1515

1616
var host = config.get('server:hostname');
@@ -22,9 +22,8 @@ var server = app.listen(port, host, function () {
2222
// Expressjs middleware for handling errors.
2323
function errorHandler(err, req, res, next) {
2424
console.error('Express error', err);
25-
res.status(500).json({
26-
"error": err.message,
27-
"stack": err.stack
25+
res.status(400).json({
26+
"error": err
2827
});
2928
// next(err);
3029
}
@@ -52,8 +51,7 @@ function uncaughtExceptionHandler(req, res, next) {
5251
// Try to send an error to the request that triggered the problem.
5352
try {
5453
res.status(500).json({
55-
"error": err.message,
56-
"stack": err.stack
54+
"error": err
5755
});
5856
}
5957
catch (err) {
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
'use strict';
2+
3+
var StorageFacade = require('../../lib/storage/facade');
4+
var storage = new StorageFacade();
5+
6+
/**
7+
* Find features.
8+
*/
9+
exports['get'] = function (req, res) {
10+
storage.findFeatures()
11+
.then(function (data) {
12+
_send(res, {
13+
"error": null,
14+
"data": data.getData()
15+
});
16+
})
17+
.fail(function (err) {
18+
res.status(400);
19+
_send(res, {
20+
"error": err
21+
});
22+
});
23+
};
24+
25+
/**
26+
* Add feautures.
27+
*/
28+
exports['put'] = function (req, res) {
29+
var inspector = require('schema-inspector');
30+
var schema = require('../../schema/geojson.js');
31+
var FeatureIds = require('../../lib/serializer/feature-ids');
32+
var fIds = new FeatureIds();
33+
var result = inspector.validate(schema['FeatureCollection'], req.body);
34+
35+
if(result.valid) {
36+
storage.addFeatures(req.body.features)
37+
.then(function (data) {
38+
var ids = data.serialize(fIds).getData();
39+
40+
_send(res, {
41+
"error": null,
42+
"data": {
43+
"total": ids.length,
44+
"ids": ids
45+
}
46+
});
47+
})
48+
.fail(function (err) {
49+
res.status(400);
50+
_send(res, {
51+
"error": err
52+
});
53+
});
54+
}
55+
else {
56+
res.status(400);
57+
_send(res, {
58+
"error": new Error(result.format())
59+
});
60+
}
61+
};
62+
63+
/**
64+
* TODO
65+
* Update features.
66+
*/
67+
exports['post'] = function (req, res) {
68+
};
69+
70+
/**
71+
* TODO
72+
* Remove features.
73+
*/
74+
exports['delete'] = function (req, res) {
75+
};
76+
77+
/**
78+
* Find features inside bbox.
79+
*/
80+
exports['get-within-bbox'] = function (req, res) {
81+
var FeatureClusterer = require('../../lib/serializer/feature-clusterer');
82+
var fc = new FeatureClusterer();
83+
var YMapsCluster = require('../../lib/serializer/ymaps-cluster');
84+
var yc = new YMapsCluster();
85+
86+
var zoom = +req.param('zoom');
87+
var bbox = req.param('bbox').split(',').map(Number);
88+
89+
storage.findFeaturesInBounds([ bbox.slice(0, 2), bbox.slice(2, 4) ])
90+
.then(function (data) {
91+
return req.param('clusterize')?
92+
data.serialize(fc, { zoom: zoom }).serialize(yc) : data;
93+
})
94+
.then(function (data) {
95+
_send(res, {
96+
"error": null,
97+
"data": data.getData()
98+
});
99+
})
100+
.fail(function (err) {
101+
res.status(400);
102+
_send(res, {
103+
"error": err
104+
});
105+
});
106+
};
107+
108+
/**
109+
* TODO
110+
* Find features inside polygon.
111+
*/
112+
exports['get-within-polygon'] = function (req, res) {
113+
};
114+
115+
/**
116+
* TODO
117+
* Find features near coordinates.
118+
*/
119+
exports['get-near'] = function (req, res) {
120+
};
121+
122+
function _send(res, data) {
123+
res.format({
124+
"application/jsonp": function () {
125+
res.jsonp(data);
126+
},
127+
"application/json": function () {
128+
res.json(data);
129+
},
130+
"default": function () {
131+
res.status(406).send('Not Acceptable');
132+
}
133+
});
134+
}

remote-object-manager-server/routes/api/get-features.js

Lines changed: 0 additions & 59 deletions
This file was deleted.

remote-object-manager-server/routes/api/index.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,21 @@
22

33
var express = require('express');
44
var router = express.Router();
5+
var features = require('./features');
56

67
module.exports = router;
78

8-
router.route('/v1/features')
9-
.get(require('./get-features'))
10-
.put(require('./put-features'));
9+
router.route('/features')
10+
.get(features['get'])
11+
.put(features['put'])
12+
.post(features['post'])
13+
.delete(features['delete']);
14+
15+
router.route('/features/within/bbox/:bbox')
16+
.get(features['get-within-bbox'])
17+
18+
router.route('/features/within/polygon/:coordinates')
19+
.get(features['get-within-polygon'])
20+
21+
router.route('/features/near/:coordinates')
22+
.get(features['get-near'])

remote-object-manager-server/routes/api/put-features.js

Lines changed: 0 additions & 38 deletions
This file was deleted.

0 commit comments

Comments
 (0)