1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 | var LangUtils = require('@themost/common/utils').LangUtils;
|
15 | var Q = require('q');
|
16 | var _ = require('lodash');
|
17 | var HttpResult = require('./mvc').HttpResult;
|
18 | var ODataModelConventionBuilder = require('@themost/data/odata').ODataConventionModelBuilder;
|
19 | var ODataModelBuilder = require('@themost/data/odata').ODataModelBuilder;
|
20 | var DataConfiguration = require('@themost/data/data-configuration').DataConfiguration;
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 | function ODataJsonResult(data) {
|
30 | ODataJsonResult.super_.bind(this)();
|
31 | this.data = data;
|
32 | this.contentType = 'application/json;charset=utf-8';
|
33 | this.contentEncoding = 'utf8';
|
34 | }
|
35 | LangUtils.inherits(ODataJsonResult,HttpResult);
|
36 |
|
37 | ODataJsonResult.prototype.execute = function(context, callback) {
|
38 | var res = context.response;
|
39 | if (_.isNil(this.data)) {
|
40 | res.writeHead(204);
|
41 | return callback();
|
42 | }
|
43 | };
|
44 |
|
45 |
|
46 |
|
47 |
|
48 |
|
49 | function ODataModelBuilderConfiguration() {
|
50 |
|
51 | }
|
52 |
|
53 |
|
54 |
|
55 |
|
56 |
|
57 |
|
58 | ODataModelBuilderConfiguration.config = function(app) {
|
59 | if (typeof app === 'undefined' || app === null) {
|
60 | return Q.reject(new TypeError('Application may not be null'))
|
61 | }
|
62 |
|
63 | var builder = new ODataModelConventionBuilder(new DataConfiguration(app.getConfigurationPath()));
|
64 |
|
65 | return builder.initialize().then(function() {
|
66 |
|
67 | app.useStrategy(ODataModelBuilder, function() {
|
68 | return builder;
|
69 | });
|
70 |
|
71 | return Q.resolve(builder);
|
72 | });
|
73 | };
|
74 |
|
75 | ODataModelBuilderConfiguration.configSync = function(app) {
|
76 | if (typeof app === 'undefined' || app === null) {
|
77 | return Q.reject(new TypeError('Application may not be null'))
|
78 | }
|
79 |
|
80 | var builder = new ODataModelConventionBuilder(new DataConfiguration(app.getConfigurationPath()));
|
81 |
|
82 | builder.initializeSync();
|
83 |
|
84 | app.useStrategy(ODataModelBuilder, function() {
|
85 | return builder;
|
86 | });
|
87 |
|
88 | return builder;
|
89 | };
|
90 |
|
91 | if (typeof module !== 'undefined') {
|
92 | module.exports.ODataModelBuilderConfiguration = ODataModelBuilderConfiguration;
|
93 | module.exports.ODataJsonResult = ODataJsonResult;
|
94 | }
|