-
Notifications
You must be signed in to change notification settings - Fork 1
/
GruntOrientDB.js
215 lines (182 loc) · 8.03 KB
/
GruntOrientDB.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
'use strict';
module.exports = function (grunt) {
grunt.loadNpmTasks('grunt-shell');
// Time how long tasks take. Can help when optimizing build times
require('time-grunt')(grunt);
// Configurable paths for the application
var appConfig = {
app: require('./bower.json').appPath || 'app',
// NKF is intended to be a plugin for OrientDB.
// Copy the (dist/)nkf subdirectory into the plugins dicretory of OrientDB.
// Call nkf app with: http://localhost:2480/nkf/index.html#/
dist: 'dist/nkf/www'
};
// Get OrientDB Parameters and Command parts
var orient = require('./orientdb.config');
var
// OrientDB Home directory
orientHome = process.env.ORIENTDB_HOME;
// Define the configuration for all the tasks
grunt.initConfig({
// Project settings
yeoman: appConfig,
// Shell tasks to drop, create, create classes and load OrientDB
shell: {
options: {
execOptions: {
maxBuffer: Infinity
}
},
createDB: {
//command: orient.Console + '"create database ' + orient.Remote + orient.SUserPassword + '"'
command: orient.Console + '"create database ' + orient.Remote + orient.SUserPassword + 'plocal"'
},
dropDB: {
command: orient.Console + '"drop database ' + orient.Remote + orient.SUserPassword + '"'
},
generateTimeline: {
command: function () {
return orient.Console + '"' + orient.Connect + ';INSERT INTO Timeline (bookingYear) VALUES (2009),(2010),(2011),(2012),(2013),(2014),(2015),(2016),(2017),(2018)"'
}
},
importServersideFunctions: {
command: function (importfile) {
return orient.Console + '"' + orient.Connect + ';delete from OFunction;IMPORT DATABASE ' + orient.ImportPath + importfile + ' -merge=true"'
}
},
exportServersideFunctions: {
command: function (exportfile) {
return orient.Console + '"' + orient.Connect + ';EXPORT DATABASE ' + orient.ImportPath + exportfile + ' -includeClass=OFunction -includeInfo=false -includeClusterDefinitions=false -includeSchema=false -includeIndexDefinitions=false -includeManualIndexes=false"'
}
},
execSQLfile: {
command: function (sqlfile) {
return orient.Console + '"' + orient.Connect + ';' + grunt.file.read(sqlfile) + '"'
}
},
loadData: {
command: function(etlConfigFile) {
return orient.Etl + orient.ImportPath + etlConfigFile
}
}
},
// Empties folders to start fresh
clean: {
orientPlugin: {
options: {force: true},
src: [orientHome + '/plugins/nkf']
}
},
// Copies remaining files to places other tasks can use
copy: {
orientPlugin: {
expand: true,
cwd: 'dist',
dest: orientHome + '/plugins',
src: ['nkf/**/*.*']
}
},
compress: {
plugin: {
options: {
archive: 'dist/nkf.zip'
},
files: [
// {src: ['path/*'], dest: 'internal_folder/', filter: 'isFile'}, // includes files in path
{
expand: true,
cwd: 'dist/nkf/',
src: ['**','!*.zip']
} // includes files in path and its subdirs
// {expand: true, cwd: 'path/', src: ['**'], dest: 'internal_folder3/'}, // makes all src relative to cwd
// {flatten: true, src: ['path/**'], dest: 'internal_folder4/', filter: 'isFile'} // flattens results to a single level
]
},
database: {
options: {
archive: 'dist/nkfDatabase.zip'
},
files: [
{
expand: true,
cwd: orient.Home + '/databases/' + orient.DB + '/',
src: ['*'],
dest: 'nkf/'
}
]
}
}
});
grunt.registerTask('orientDBCreateAndLoad', [
'orientDBCreate',
'orientDBLoadData',
'importServersideFunctions',
'generateTimeline'
]);
grunt.registerTask('orientPlugin', 'Copy app into plugin directory of OrientDB', function () {
grunt.task.run([
//'clean:orientPlugin',
'copy:orientPlugin'
]);
});
grunt.registerTask('orientDBCreate', 'Drop and create OrientDB database and classes.', function () {
grunt.task.run([
'shell:dropDB',
'shell:createDB',
'shell:execSQLfile:./import/persons/createPersonClasses.sql',
'shell:execSQLfile:./import/products/createProductTypesClass.sql',
'shell:execSQLfile:./import/hierarchies/createHierarchiesClass.sql',
'shell:execSQLfile:./import/accounting/createFrameworkClass.sql',
'shell:execSQLfile:./import/accounting/createBookingsClass.sql',
'shell:execSQLfile:./import/accounting/createTimelineClasses.sql'
]);
});
grunt.registerTask('orientDBLoadData', 'Load data into OrientDB database.', function () {
grunt.task.run([
'orientLoadData:/persons/persontypes.json:/persons/persontypes.csv',
'orientLoadData:/persons/persons.json:/persons/persons.csv',
'orientLoadData:/products/producttypes.json:/products/producttypes.csv',
'orientLoadData:/accounting/framework.json:/accounting/financial_accounts.csv'
]);
});
/**
* Change variable parameters in orient-etl config JSON-file.
* @param {string} etlConfigFile = Path to etl JSON config file. Import path will be added.
* @param {string} dataFile = Path to csv file containing the data to import. Import path will be added.
* @param {string} orientURL = URL to destination OrientDB
*/
grunt.registerTask('changeEtlConfig', 'Change variable parameters in orient-ETL config JSON-file.', function (etlConfigFile, dataFile) {
var apJsonFile = orient.ImportPath + etlConfigFile;
if (!grunt.file.exists(apJsonFile)) {
grunt.log.error("file " + apJsonFile + " not found");
return false;//return false to abort the execution
}
var etlJsonFile = grunt.file.readJSON(apJsonFile); //get file as json object
etlJsonFile.source.file.path = orient.ImportPath + dataFile;
etlJsonFile.loader.orientdb.dbURL = orient.Remote;
etlJsonFile.loader.orientdb.dbUser = orient.SUser;
etlJsonFile.loader.orientdb.dbPassword = orient.SPassword;
grunt.file.write(apJsonFile, JSON.stringify(etlJsonFile, null, 2)); //serialize it back to file
});
grunt.registerTask('orientLoadData', 'Load Data into Orient Database with ETL tool.', function (etlConfigFile, dataFile) {
grunt.task.run([
'changeEtlConfig:' + etlConfigFile + ':' + dataFile,
'shell:loadData:' + etlConfigFile
]);
});
grunt.registerTask('generateTimeline', 'Generate timeline data 2009 - 2018', function () {
grunt.task.run([
'shell:generateTimeline'
]);
});
grunt.registerTask('importServersideFunctions', 'Import all serverside js functions', function () {
grunt.task.run([
'shell:importServersideFunctions:/functions/functions.json.gz'
]);
});
grunt.registerTask('exportServersideFunctions', 'Export all serverside js functions', function () {
grunt.task.run([
'shell:exportServersideFunctions:/functions/functions.json.gz'
]);
});
};