Skip to content
Snippets Groups Projects
Commit 08c1f03f 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 #16761 passed
......@@ -19,7 +19,7 @@
*/
import { RelationType, DataType } from "../common/types";
import { EnumType } from "./enumType";
import { EnumHandler } from "../util/enumHandler";
/** Parameters used to create a Dimension object. */
export interface DimensionOptions {
......@@ -96,14 +96,14 @@ export class Dimension {
if (this.relation === RelationType.NONE) {
return {
name: this.name,
dataType: (this.dataType !== DataType.NONE) ? EnumType.stringfyDataType(this.dataType) : this.enumType ,
dataType: EnumHandler.selectDataType(this.dataType, this.enumType),
description: this.description
};
}
else {
return {
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,
relation: Dimension.stringifyRelationType(this.relation),
description: this.description
......
......@@ -20,6 +20,7 @@
import { EnumType } from "./enumType";
import { DataType } from "../common/types";
import { EnumHandler } from "../util/enumHandler";
/** Attribute of a source. */
export interface Field {
......@@ -121,7 +122,7 @@ export class Source {
return {
name : i.name,
description: i.description,
dataType: (i.dataType !== DataType.NONE) ? EnumType.stringfyDataType(i.dataType) : i.enumType
dataType: EnumHandler.selectDataType(i.dataType, i.enumType)
};
});
return str;
......@@ -138,7 +139,7 @@ export class Source {
name : i.name,
description: i.description,
dataType: EnumType.parseDataType(i.dataType),
enumType: (EnumType.parseDataType(i.dataType) === DataType.NONE) ? i.dataType : ""
enumType: EnumHandler.selectEnumType(i.dataType)
};
});
return str;
......
......@@ -22,6 +22,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 { EnumHandler } from "./enumHandler";
import { RelationType, DataType } from "../common/types";
import { Opcode } from "../common/expression";
import { Filter } from "../core/filter";
......@@ -334,7 +335,7 @@ export class ConfigParser {
description: opts.description,
parent: dims[i],
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 {
description: opts.description,
parent: null,
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/>.
*/
/**
* Enum's handler. Manage changes between
* string and enumtype.
*/
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(data: string): string{
return (EnumType.parseDataType(data) === DataType.NONE) ? data : "";
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment