Skip to content
Snippets Groups Projects
Commit b80adcb2 authored by Lucas Fernandes de Oliveira's avatar Lucas Fernandes de Oliveira
Browse files

Merge branch 'issue/65' into 'develop'

Issue #65: Add route to enumtype

See merge request !56
parents 7b642a58 87c94112
Branches
No related tags found
1 merge request!56Issue #65: Add route to enumtype
Pipeline #
......@@ -211,3 +211,26 @@ dimensions:
parent: "dim:0"
relation: "year"
description: "A dimension of Blendb. Has 1 possible value."
enumTypes:
-
name: "enum type:0"
values:
- "test:0"
- "test:1"
- "test:2"
- "test:3"
-
name: "enum type:1"
values:
- "test:4"
- "test:5"
- "test:6"
-
name: "enum type:2"
values:
- "test:7"
- "test:8"
-
name: "enum type:3"
values:
- "test:9"
......@@ -287,7 +287,13 @@ traits:
the system and their descriptions.
securedBy: [ null, oauth_2_0 ]
get:
/enumtypes:
description: |
A EnumType is short for enumerable type. This is a special data type that only accepts a few possible values. This
collection allows the user to list all the enumerable types available in the system, their descriptions and possible
values.
get:
securedBy: [ null, oauth_2_0 ]
/data:
description: |
This is the main part of the API. You may query it for report
......
......@@ -48,5 +48,15 @@ describe("API engine controller", () => {
})
.end(done);
});
it("should respond 200 and the list of enumTypes", (done) => {
request(server)
.get("/v1/enumtypes")
.expect((res: any) => {
let result = res.body;
expect(result).to.be.an("array");
expect(result).to.have.length(4);
})
.end(done);
});
});
......@@ -29,4 +29,8 @@ export class EngineCtrl {
public static dimensions(req: Request, res: express.Response, next: express.NextFunction) {
res.status(200).json(req.engine.getDimensionsDescription());
}
public static enumTypes(req: Request, res: express.Response, next: express.NextFunction) {
res.status(200).json(req.engine.getEnumTypesDescription());
}
}
......@@ -28,6 +28,7 @@ export function EngineMw (config: ParsedConfig): Middleware {
config.metrics.forEach ((met) => engine.addMetric(met));
config.dimensions.forEach ((dim) => engine.addDimension(dim));
config.views.forEach ((view) => engine.addView(view));
config.enumTypes.forEach ((enumt) => engine.addEnumType(enumt));
return function engineMiddleware(req, res, next) {
req.engine = engine;
......
......@@ -29,5 +29,6 @@ export const router = osprey.Router();
router.get("/metrics", EngineCtrl.metrics);
router.get("/dimensions", EngineCtrl.dimensions);
router.get("/enumtypes", EngineCtrl.enumTypes);
router.get("/data", DataCtrl.read);
router.post("/collect/{class}", CollectCtrl.write);
......@@ -25,14 +25,17 @@ import { Filter } from "./filter";
import { View } from "./view";
import { Query } from "../common/query";
import { Graph } from "../util/graph";
import { EnumType, EnumTypeOptions} from "./enumType";
export class Engine {
private views: View[] = [];
private metrics: Metric[] = [];
private enumTypes: EnumType[] = [];
private dimensions: Dimension[] = [];
private graph: Graph;
constructor () {
this.enumTypes = [];
this.views = [];
this.metrics = [];
this.dimensions = [];
......@@ -47,6 +50,10 @@ export class Engine {
return this.metrics.map((i) => i.strOptions());
}
public getEnumTypesDescription(): EnumTypeOptions[] {
return this.enumTypes.map((i) => i.strOptions());
}
public getDimensionsDescription() {
return this.dimensions.map((i) => i.strOptions());
}
......@@ -60,6 +67,11 @@ export class Engine {
return null;
}
public addEnumType(enumType: EnumType) {
this.enumTypes.push(enumType);
return enumType;
}
public addMetric(metric: Metric) {
if (this.graph.addMetric(metric)) {
this.metrics.push(metric);
......
/*
* Copyright (C) 2018 Centro de Computacao Cientifica e Software Livre
* Departamento de Informatica - Universidade Federal do Parana
*
* This file is part of blend.
*
* blend is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* blend is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with blend. If not, see <http://www.gnu.org/licenses/>.
*/
export interface EnumTypeOptions {
name: string;
values: string[];
}
export class EnumType {
public name: string;
public values: string[];
constructor(options: EnumTypeOptions) {
this.name = options.name;
this.values = options.values;
}
public strOptions(): EnumTypeOptions {
return{
name: this.name,
values: this.values
};
}
}
......@@ -21,6 +21,7 @@
import { Metric, MetricOptions, MetricStrOptions } from "../core/metric";
import { Dimension, DimensionOptions, DimensionStrOptions } from "../core/dimension";
import { View, ViewOptions, LoadView } from "../core/view";
import { EnumType, EnumTypeOptions } from "../core/enumType";
import { RelationType } from "../common/types";
import { Filter } from "../core/filter";
import { Clause } from "../core/clause";
......@@ -42,6 +43,7 @@ interface ConfigSchema {
views: ViewParsingOptions[];
metrics: MetricStrOptions[];
dimensions: DimensionStrOptions[];
enumTypes: EnumTypeOptions[];
}
interface BuildView {
......@@ -60,6 +62,7 @@ export interface ParsedConfig {
connection: Connection;
views: View[];
metrics: Metric[];
enumTypes: EnumType[];
dimensions: Dimension[];
struct: LoadStruct;
loadViews: LoadView[];
......@@ -82,6 +85,10 @@ interface MetricMap {
[key: string]: Metric;
}
interface EnumTypeMap{
[key: string]: EnumType;
}
export class ConfigParser {
public static parse(configPath: string): ParsedConfig {
let config: ConfigSchema = yaml.safeLoad(fs.readFileSync(configPath, {
......@@ -107,11 +114,13 @@ export class ConfigParser {
let metricsOpts = config.metrics;
let viewsOpts = config.views;
let dimensionsOpts = config.dimensions;
let enumTypesOpts = config.enumTypes;
let parsed: ParsedConfig = {
adapter: process.env.BLENDB_ADAPTER || "postgres",
connection: connection,
views: [],
metrics: [],
enumTypes: [],
dimensions: [],
struct: struct,
loadViews: [],
......@@ -120,12 +129,18 @@ export class ConfigParser {
let metMap: MetricMap = {};
let dimMap: DimensionMap = {};
let enumMap: EnumTypeMap = {};
for (let i = 0; i < metricsOpts.length; ++i) {
let met = new Metric(this.parseMetOpts(metricsOpts[i]));
parsed.metrics.push(met);
metMap[met.name] = met;
}
for (let i = 0; i < enumTypesOpts.length; i++) {
let enumT = new EnumType((enumTypesOpts[i]));
parsed.enumTypes.push(enumT);
enumMap[enumT.name] = enumT;
}
for (let i = 0; i < dimensionsOpts.length; ++i) {
let dim = new Dimension(this.parseDimOpts(dimensionsOpts[i], parsed.dimensions));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment