Skip to content

Commit

Permalink
Merge pull request #216 from WorldBank-Transport/feature/wbcatalog
Browse files Browse the repository at this point in the history
Add support for wbcatalog source
  • Loading branch information
olafveerman authored Oct 3, 2018
2 parents c2b441d + 38a6931 commit 40ca7c7
Show file tree
Hide file tree
Showing 57 changed files with 6,498 additions and 2,462 deletions.
7 changes: 6 additions & 1 deletion .babelrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
{
"presets": [ "es2015" ]
"presets": [ "es2015" ],
"plugins": [
["transform-object-rest-spread", { "useBuiltIns": true }]
],
"sourceMaps": "inline",
"retainLines": true
}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ dist
.nyc_output
ecs-task-definition-generated.yml
*.pyc
.vscode

# OSM P2P db
osm-p2p-dbs
osm-p2p-dbs-test
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ module.exports = {
service: 'docker',
hyperAccess: null,
hyperSecret: null,
container: 'wbtransport/ram-analysis:latest-stable',
container: 'wbtransport/ram-analysis:latest-dev',
db: 'postgresql://ram:ram@ram-postgis:5432/ram',
storageHost: 'ram-minio',
storagePort: 9000
Expand All @@ -143,7 +143,7 @@ module.exports = {
service: 'docker',
hyperAccess: null,
hyperSecret: null,
container: 'wbtransport/ram-vt:latest-stable',
container: 'wbtransport/ram-vt:latest-dev',
storageHost: 'ram-minio',
storagePort: 9000
},
Expand Down
22 changes: 21 additions & 1 deletion app/db/structure.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ export function dropScenariosSourceData () {
return db.schema.dropTableIfExists('scenarios_source_data');
}

export function dropWbCatalogResources () {
DEBUG && console.log('Dropping table: wbcatalog_resources');
return db.schema.dropTableIfExists('wbcatalog_resources');
}

export function createProjectsTable () {
DEBUG && console.log('Creating table: projects');
return db.schema.createTable('projects', table => {
Expand Down Expand Up @@ -300,6 +305,19 @@ export function createScenariosSourceData () {
});
}

export function createWbCatalogResources () {
DEBUG && console.log('Creating table: wbcatalog_resources');
return db.schema.createTable('wbcatalog_resources', table => {
table.increments('id').primary();
table.string('type');
table.string('name');
table.timestamp('created_at').defaultTo(db.fn.now());
table.string('resource_id');
table.string('resource_url');
table.json('data');
});
}

export function setupStructure () {
return dropScenariosFiles()
.then(() => dropProjectsFiles())
Expand All @@ -315,6 +333,7 @@ export function setupStructure () {
.then(() => dropProjectsOriginsIndicators())
.then(() => dropProjectsOrigins())
.then(() => dropProjects())
.then(() => dropWbCatalogResources())
.then(() => createProjectsTable())
.then(() => createProjectsAATable())
.then(() => createScenariosTable())
Expand All @@ -328,5 +347,6 @@ export function setupStructure () {
.then(() => createResultsTable())
.then(() => createResultsPoiTable())
.then(() => createScenariosSourceData())
.then(() => createProjectsSourceData());
.then(() => createProjectsSourceData())
.then(() => createWbCatalogResources());
}
9 changes: 2 additions & 7 deletions app/routes/projects--delete.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
'use strict';
import Joi from 'joi';
import Boom from 'boom';

import db from '../db/';
import { removeDir as removeS3Dir } from '../s3/utils';
import { ProjectNotFoundError } from '../utils/errors';
import { ProjectNotFoundError, getBoomResponseForError } from '../utils/errors';

module.exports = [
{
Expand Down Expand Up @@ -48,11 +47,7 @@ module.exports = [
});
})
.then(() => reply({statusCode: 200, message: 'Project deleted'}))
.catch(ProjectNotFoundError, () => reply(Boom.notFound('Project not found')))
.catch(err => {
console.log('err', err);
reply(Boom.badImplementation(err));
});
.catch(err => reply(getBoomResponseForError(err)));
}
}
];
11 changes: 2 additions & 9 deletions app/routes/projects--files-delete.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
'use strict';
import Joi from 'joi';
import Boom from 'boom';

import db from '../db/';
import { removeFile } from '../s3/utils';
import { ProjectNotFoundError, FileNotFoundError, ProjectStatusError } from '../utils/errors';
import { ProjectNotFoundError, FileNotFoundError, ProjectStatusError, getBoomResponseForError } from '../utils/errors';

module.exports = [
{
Expand Down Expand Up @@ -41,13 +40,7 @@ module.exports = [
.then(() => removeFile(data.file_path));
})
.then(() => reply({statusCode: 200, message: 'File deleted'}))
.catch(ProjectNotFoundError, e => reply(Boom.notFound(e.message)))
.catch(ProjectStatusError, e => reply(Boom.badRequest(e.message)))
.catch(FileNotFoundError, e => reply(Boom.notFound(e.message)))
.catch(err => {
console.log('err', err);
reply(Boom.badImplementation(err));
});
.catch(err => reply(getBoomResponseForError(err)));
}
}
];
11 changes: 2 additions & 9 deletions app/routes/projects--files-download.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Boom from 'boom';

import db from '../db/';
import { getFile } from '../s3/utils';
import { FileNotFoundError } from '../utils/errors';
import { FileNotFoundError, getBoomResponseForError } from '../utils/errors';

module.exports = [
{
Expand Down Expand Up @@ -53,14 +53,7 @@ module.exports = [
.header('Content-Disposition', `attachment; filename=${file.name}`);
});
})
.catch(FileNotFoundError, e => reply(Boom.notFound(e.message)))
.catch(err => {
if (err.code === 'NoSuchKey') {
return reply(Boom.notFound('File not found in storage bucket'));
}
console.log('err', err);
reply(Boom.badImplementation(err));
});
.catch(err => reply(getBoomResponseForError(err)));
}
}
];
13 changes: 3 additions & 10 deletions app/routes/projects--finish-setup.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
'use strict';
import Joi from 'joi';
import Boom from 'boom';
import Promise from 'bluebird';

import db from '../db/';
import { ProjectNotFoundError, DataConflictError } from '../utils/errors';
import { DataConflictError, getBoomResponseForError } from '../utils/errors';
import { getProject } from './projects--get';
import Operation from '../utils/operation';
import ServiceRunner from '../utils/service-runner';
Expand Down Expand Up @@ -67,12 +66,7 @@ module.exports = [
);
})
.then(() => reply({statusCode: 200, message: 'Project setup finish started'}))
.catch(ProjectNotFoundError, e => reply(Boom.notFound(e.message)))
.catch(DataConflictError, e => reply(Boom.conflict(e.message)))
.catch(err => {
console.log('err', err);
reply(Boom.badImplementation(err));
});
.catch(err => reply(getBoomResponseForError(err)));
}
}
];
Expand Down Expand Up @@ -114,8 +108,7 @@ function concludeProjectSetup (projId, scId, opId, cb) {
op.loadById(opId)
.then(op => {
if (!op.isCompleted()) {
return op.log('error', {error: err.message})
.then(op => op.finish());
return op.finish('error', {error: err.message});
}
});
}
Expand Down
11 changes: 3 additions & 8 deletions app/routes/projects--get.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
'use strict';
import Joi from 'joi';
import Boom from 'boom';
import Promise from 'bluebird';

import db from '../db/';
import { ProjectNotFoundError } from '../utils/errors';
import { ProjectNotFoundError, getBoomResponseForError } from '../utils/errors';
import { getSourceData, getOperationData } from '../utils/utils';

module.exports = [
Expand Down Expand Up @@ -41,11 +40,7 @@ module.exports = [
handler: (request, reply) => {
getProject(request.params.projId)
.then(project => reply(project))
.catch(ProjectNotFoundError, e => reply(Boom.notFound(e.message)))
.catch(err => {
console.log('err', err);
reply(Boom.badImplementation(err));
});
.catch(err => reply(getBoomResponseForError(err)));
}
}
];
Expand Down Expand Up @@ -113,7 +108,7 @@ function attachFinishSetupOperation (project) {
.where('project_id', project.id)
.where('master', true)
.first()
.then(scenario => getOperationData(db, 'project-setup-finish', 'finish_setup', scenario.id))
.then(scenario => getOperationData(db, 'project-setup-finish', scenario.id))
.then(opData => {
project.finish_setup = opData;
return project;
Expand Down
Loading

0 comments on commit 40ca7c7

Please sign in to comment.