Skip to content
Snippets Groups Projects
Commit 0304a9d8 authored by Rafael Dias's avatar Rafael Dias
Browse files

Issue #65: Add route to enumtype


Signed-off-by: default avatarRafael <rpd17@inf.ufpr.br>
parent d85a585e
No related branches found
No related tags found
No related merge requests found
Pipeline #
...@@ -211,3 +211,26 @@ dimensions: ...@@ -211,3 +211,26 @@ dimensions:
parent: "dim:0" parent: "dim:0"
relation: "year" relation: "year"
description: "A dimension of Blendb. Has 1 possible value." description: "A dimension of Blendb. Has 1 possible value."
enumTypes:
-
name: "enumtypes:0"
values:
- "test:0"
- "test:1"
- "test:2"
- "test:3"
-
name: "enumtypes:1"
values:
- "test:4"
- "test:5"
- "test:6"
-
name: "enumtypes:2"
values:
- "test:7"
- "test:8"
-
name: "enumtypes:3"
values:
- "test:9"
...@@ -287,7 +287,12 @@ traits: ...@@ -287,7 +287,12 @@ traits:
the system and their descriptions. the system and their descriptions.
securedBy: [ null, oauth_2_0 ] securedBy: [ null, oauth_2_0 ]
get: get:
/enumtypes:
description: |
The enumtypes will serve as a filter , and are able to be used as types for datatype.
In the insertion process only those who are listed either in a type or enumtype will be insert.
get:
securedBy: [ null, oauth_2_0 ]
/data: /data:
description: | description: |
This is the main part of the API. You may query it for report This is the main part of the API. You may query it for report
......
...@@ -48,5 +48,15 @@ describe("API engine controller", () => { ...@@ -48,5 +48,15 @@ describe("API engine controller", () => {
}) })
.end(done); .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 { ...@@ -29,4 +29,8 @@ export class EngineCtrl {
public static dimensions(req: Request, res: express.Response, next: express.NextFunction) { public static dimensions(req: Request, res: express.Response, next: express.NextFunction) {
res.status(200).json(req.engine.getDimensionsDescription()); res.status(200).json(req.engine.getDimensionsDescription());
} }
public static enumTypes(req: Request, res: express.Response, next: express.NextFunction) {
res.status(200).json(req.engine.getEnumTypeDescription());
}
} }
...@@ -28,6 +28,7 @@ export function EngineMw (config: ParsedConfig): Middleware { ...@@ -28,6 +28,7 @@ export function EngineMw (config: ParsedConfig): Middleware {
config.metrics.forEach ((met) => engine.addMetric(met)); config.metrics.forEach ((met) => engine.addMetric(met));
config.dimensions.forEach ((dim) => engine.addDimension(dim)); config.dimensions.forEach ((dim) => engine.addDimension(dim));
config.views.forEach ((view) => engine.addView(view)); config.views.forEach ((view) => engine.addView(view));
config.enumTypes.forEach ((enumt) => engine.addEnumType(enumt));
return function engineMiddleware(req, res, next) { return function engineMiddleware(req, res, next) {
req.engine = engine; req.engine = engine;
......
...@@ -29,5 +29,6 @@ export const router = osprey.Router(); ...@@ -29,5 +29,6 @@ export const router = osprey.Router();
router.get("/metrics", EngineCtrl.metrics); router.get("/metrics", EngineCtrl.metrics);
router.get("/dimensions", EngineCtrl.dimensions); router.get("/dimensions", EngineCtrl.dimensions);
router.get("/enumtypes", EngineCtrl.enumTypes);
router.get("/data", DataCtrl.read); router.get("/data", DataCtrl.read);
router.post("/collect/{class}", CollectCtrl.write); router.post("/collect/{class}", CollectCtrl.write);
...@@ -25,14 +25,17 @@ import { Filter } from "./filter"; ...@@ -25,14 +25,17 @@ import { Filter } from "./filter";
import { View } from "./view"; import { View } from "./view";
import { Query } from "../common/query"; import { Query } from "../common/query";
import { Graph } from "../util/graph"; import { Graph } from "../util/graph";
import { EnumType } from "./enumType";
export class Engine { export class Engine {
private views: View[] = []; private views: View[] = [];
private metrics: Metric[] = []; private metrics: Metric[] = [];
private enumTypes: EnumType[] = [];
private dimensions: Dimension[] = []; private dimensions: Dimension[] = [];
private graph: Graph; private graph: Graph;
constructor () { constructor () {
this.enumTypes = [];
this.views = []; this.views = [];
this.metrics = []; this.metrics = [];
this.dimensions = []; this.dimensions = [];
...@@ -47,6 +50,10 @@ export class Engine { ...@@ -47,6 +50,10 @@ export class Engine {
return this.metrics.map((i) => i.strOptions()); return this.metrics.map((i) => i.strOptions());
} }
public getEnumTypeDescription() {
return this.enumTypes.map((i) => i.strOptions());
}
public getDimensionsDescription() { public getDimensionsDescription() {
return this.dimensions.map((i) => i.strOptions()); return this.dimensions.map((i) => i.strOptions());
} }
...@@ -60,6 +67,11 @@ export class Engine { ...@@ -60,6 +67,11 @@ export class Engine {
return null; return null;
} }
public addEnumType(enumType: EnumType) {
this.enumTypes.push(enumType);
return enumType;
}
public addMetric(metric: Metric) { public addMetric(metric: Metric) {
if (this.graph.addMetric(metric)) { if (this.graph.addMetric(metric)) {
this.metrics.push(metric); this.metrics.push(metric);
......
/*
* Copyright (C) 2016 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 interface EnumTypeStrOptions {
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(): EnumTypeStrOptions {
return{
name: this.name,
values: this.values
};
}
}
// values para ser uma lista de string
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
import { Metric, MetricOptions, MetricStrOptions } from "../core/metric"; import { Metric, MetricOptions, MetricStrOptions } from "../core/metric";
import { Dimension, DimensionOptions, DimensionStrOptions } from "../core/dimension"; import { Dimension, DimensionOptions, DimensionStrOptions } from "../core/dimension";
import { View, ViewOptions, LoadView } from "../core/view"; import { View, ViewOptions, LoadView } from "../core/view";
import { EnumType, EnumTypeOptions, EnumTypeStrOptions } from "../core/enumType";
import { RelationType } from "../common/types"; import { RelationType } from "../common/types";
import { Filter } from "../core/filter"; import { Filter } from "../core/filter";
import { Clause } from "../core/clause"; import { Clause } from "../core/clause";
...@@ -42,6 +43,7 @@ interface ConfigSchema { ...@@ -42,6 +43,7 @@ interface ConfigSchema {
views: ViewParsingOptions[]; views: ViewParsingOptions[];
metrics: MetricStrOptions[]; metrics: MetricStrOptions[];
dimensions: DimensionStrOptions[]; dimensions: DimensionStrOptions[];
enumTypes: EnumTypeStrOptions[];
} }
interface BuildView { interface BuildView {
...@@ -60,6 +62,7 @@ export interface ParsedConfig { ...@@ -60,6 +62,7 @@ export interface ParsedConfig {
connection: Connection; connection: Connection;
views: View[]; views: View[];
metrics: Metric[]; metrics: Metric[];
enumTypes: EnumType[];
dimensions: Dimension[]; dimensions: Dimension[];
struct: LoadStruct; struct: LoadStruct;
loadViews: LoadView[]; loadViews: LoadView[];
...@@ -82,6 +85,10 @@ interface MetricMap { ...@@ -82,6 +85,10 @@ interface MetricMap {
[key: string]: Metric; [key: string]: Metric;
} }
interface EnumTypeMap{
[key: string]: EnumType;
}
export class ConfigParser { export class ConfigParser {
public static parse(configPath: string): ParsedConfig { public static parse(configPath: string): ParsedConfig {
let config: ConfigSchema = yaml.safeLoad(fs.readFileSync(configPath, { let config: ConfigSchema = yaml.safeLoad(fs.readFileSync(configPath, {
...@@ -107,11 +114,13 @@ export class ConfigParser { ...@@ -107,11 +114,13 @@ export class ConfigParser {
let metricsOpts = config.metrics; let metricsOpts = config.metrics;
let viewsOpts = config.views; let viewsOpts = config.views;
let dimensionsOpts = config.dimensions; let dimensionsOpts = config.dimensions;
let enumTypesOpts = config.enumTypes;
let parsed: ParsedConfig = { let parsed: ParsedConfig = {
adapter: process.env.BLENDB_ADAPTER || "postgres", adapter: process.env.BLENDB_ADAPTER || "postgres",
connection: connection, connection: connection,
views: [], views: [],
metrics: [], metrics: [],
enumTypes: [],
dimensions: [], dimensions: [],
struct: struct, struct: struct,
loadViews: [], loadViews: [],
...@@ -120,12 +129,18 @@ export class ConfigParser { ...@@ -120,12 +129,18 @@ export class ConfigParser {
let metMap: MetricMap = {}; let metMap: MetricMap = {};
let dimMap: DimensionMap = {}; let dimMap: DimensionMap = {};
let enumMap: EnumTypeMap = {};
for (let i = 0; i < metricsOpts.length; ++i) { for (let i = 0; i < metricsOpts.length; ++i) {
let met = new Metric(this.parseMetOpts(metricsOpts[i])); let met = new Metric(this.parseMetOpts(metricsOpts[i]));
parsed.metrics.push(met); parsed.metrics.push(met);
metMap[met.name] = met; metMap[met.name] = met;
} }
for (let i = 0; i < enumTypesOpts.length; i++) {
let enumT = new EnumType(this.parseEnumTypeOpts(enumTypesOpts[i]));
parsed.enumTypes.push(enumT);
enumMap[enumT.name] = enumT;
}
for (let i = 0; i < dimensionsOpts.length; ++i) { for (let i = 0; i < dimensionsOpts.length; ++i) {
let dim = new Dimension(this.parseDimOpts(dimensionsOpts[i], parsed.dimensions)); let dim = new Dimension(this.parseDimOpts(dimensionsOpts[i], parsed.dimensions));
...@@ -249,6 +264,13 @@ export class ConfigParser { ...@@ -249,6 +264,13 @@ export class ConfigParser {
}; };
} }
private static parseEnumTypeOpts (opts: EnumTypeStrOptions): EnumTypeOptions {
return{
name: opts.name,
values: opts.values
};
}
private static parseClause (opts: string, metMap: MetricMap, dimMap: DimensionMap): Clause { private static parseClause (opts: string, metMap: MetricMap, dimMap: DimensionMap): Clause {
const strFilters = opts.split(","); const strFilters = opts.split(",");
const filters: Filter[] = strFilters.map((item) => { const filters: Filter[] = strFilters.map((item) => {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment