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

Issue #80: Add enumHandler


Signed-off-by: default avatarRafael <rpd17@inf.ufpr.br>
parent 6f4d8d18
No related branches found
No related tags found
No related merge requests found
Pipeline #16886 passed
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
*/ */
import { RelationType, DataType } from "../common/types"; import { RelationType, DataType } from "../common/types";
import { EnumType } from "./enumType"; import { EnumHandler } from "../util/enumHandler";
/** Parameters used to create a Dimension object. */ /** Parameters used to create a Dimension object. */
export interface DimensionOptions { export interface DimensionOptions {
...@@ -96,14 +96,14 @@ export class Dimension { ...@@ -96,14 +96,14 @@ export class Dimension {
if (this.relation === RelationType.NONE) { if (this.relation === RelationType.NONE) {
return { return {
name: this.name, name: this.name,
dataType: (this.dataType !== DataType.NONE) ? EnumType.stringfyDataType(this.dataType) : this.enumType , dataType: EnumHandler.selectDataType(this.dataType, this.enumType),
description: this.description description: this.description
}; };
} }
else { else {
return { return {
name: this.name, name: this.name,
dataType: (this.dataType !== DataType.NONE) ? EnumType.stringfyDataType(this.dataType) : this.enumType , dataType: EnumHandler.selectDataType(this.dataType, this.enumType),
parent: this.parent.name, parent: this.parent.name,
relation: Dimension.stringifyRelationType(this.relation), relation: Dimension.stringifyRelationType(this.relation),
description: this.description description: this.description
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
import { EnumType } from "./enumType"; import { EnumType } from "./enumType";
import { DataType } from "../common/types"; import { DataType } from "../common/types";
import { EnumHandler } from "../util/enumHandler";
/** Attribute of a source. */ /** Attribute of a source. */
export interface Field { export interface Field {
...@@ -121,7 +122,7 @@ export class Source { ...@@ -121,7 +122,7 @@ export class Source {
return { return {
name : i.name, name : i.name,
description: i.description, description: i.description,
dataType: (i.dataType !== DataType.NONE) ? EnumType.stringfyDataType(i.dataType) : i.enumType dataType: EnumHandler.selectDataType(i.dataType, i.enumType)
}; };
}); });
return str; return str;
...@@ -138,7 +139,7 @@ export class Source { ...@@ -138,7 +139,7 @@ export class Source {
name : i.name, name : i.name,
description: i.description, description: i.description,
dataType: EnumType.parseDataType(i.dataType), dataType: EnumType.parseDataType(i.dataType),
enumType: (EnumType.parseDataType(i.dataType) === DataType.NONE) ? i.dataType : "" enumType: EnumHandler.selectEnumType(i.dataType)
}; };
}); });
return str; return str;
......
...@@ -22,6 +22,7 @@ import { Metric, MetricOptions, MetricStrOptions } from "../core/metric"; ...@@ -22,6 +22,7 @@ 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 } from "../core/enumType"; import { EnumType, EnumTypeOptions } from "../core/enumType";
import { EnumHandler } from "./enumHandler";
import { RelationType, DataType } from "../common/types"; import { RelationType, DataType } from "../common/types";
import { Opcode } from "../common/expression"; import { Opcode } from "../common/expression";
import { Filter } from "../core/filter"; import { Filter } from "../core/filter";
...@@ -334,7 +335,7 @@ export class ConfigParser { ...@@ -334,7 +335,7 @@ export class ConfigParser {
description: opts.description, description: opts.description,
parent: dims[i], parent: dims[i],
relation: Dimension.parseRelationType(opts.relation), relation: Dimension.parseRelationType(opts.relation),
enumType: (EnumType.parseDataType(opts.dataType) === DataType.NONE) ? opts.dataType : "" enumType: EnumHandler.selectEnumType(opts.dataType)
}; };
} }
} }
...@@ -347,7 +348,7 @@ export class ConfigParser { ...@@ -347,7 +348,7 @@ export class ConfigParser {
description: opts.description, description: opts.description,
parent: null, parent: null,
relation: RelationType.NONE, relation: RelationType.NONE,
enumType: (EnumType.parseDataType(opts.dataType) === DataType.NONE) ? opts.dataType : "" enumType: EnumHandler.selectEnumType(opts.dataType)
}; };
} }
......
import { DataType } from "../common/types";
/*
* Copyright (C) 2018 Centro de Computacao Cientifica e Software Livre
* Departamento de Informatica - Universidade Federal do Parana
*
* This file is part of blendb.
*
* blendb 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.
*
* blendb 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 blendb. If not, see <http://www.gnu.org/licenses/>.
*/
import { EnumType } from "../core/enumType";
/**
* Enum's handler. Manage changes between
* string , datatype and enumtype.
*/
export class EnumHandler {
/**
* Checks if it's a valid datatype, otherwise will be an enumtype
* @param dt datatype to compare, used as return if comparation succeed
* @param en enumtype as return if comparation fails
*/
public static selectDataType(dt: DataType , en: string): string{
return (dt !== DataType.NONE) ? EnumType.stringfyDataType(dt) : en;
}
/**
* Checks if it's a valid datatype, otherwise return an empity string
* @param data datatype to compare, used as return if comparation succeed
*/
public static selectEnumType(dt: string): string{
return (EnumType.parseDataType(dt) === DataType.NONE) ? dt : "";
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment