Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
blendb
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
23
Issues
23
List
Boards
Labels
Service Desk
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
C3SL
blendb
Commits
f00a8a08
Commit
f00a8a08
authored
Aug 07, 2018
by
Lucas Fernandes de Oliveira
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'issue/82' into 'develop'
Issue
#82
: Add optional field for Enumtype See merge request
!71
parents
ea6ddc63
f3fc716a
Pipeline
#17086
passed with stages
in 1 minute and 8 seconds
Changes
7
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
74 additions
and
46 deletions
+74
-46
config/ci_test.yaml.example
config/ci_test.yaml.example
+2
-1
src/api/controllers/collect.ts
src/api/controllers/collect.ts
+17
-9
src/core/dimension.ts
src/core/dimension.ts
+15
-15
src/core/source.ts
src/core/source.ts
+16
-6
src/util/configParser.spec.ts
src/util/configParser.spec.ts
+5
-4
src/util/configParser.ts
src/util/configParser.ts
+15
-11
src/util/enumHandler.ts
src/util/enumHandler.ts
+4
-0
No files found.
config/ci_test.yaml.example
View file @
f00a8a08
...
...
@@ -259,7 +259,8 @@ sources:
-
name: "fields:0"
description: "first entry"
dataType: "enumtype:0"
dataType: "enumtype"
enumType: "enumtype:0"
-
name: "fields:1"
description: "second entry"
...
...
src/api/controllers/collect.ts
View file @
f00a8a08
...
...
@@ -133,15 +133,8 @@ export class CollectCtrl {
}
for
(
let
i
=
0
;
i
<
fields
.
length
;
i
++
){
if
(
fields
[
i
].
dataType
!==
DataType
.
NONE
){
if
(
!
validador
[
EnumHandler
.
stringfyDataType
(
fields
[
i
].
dataType
)](
data
[
i
])
===
true
){
throw
new
Error
(
"
The value '
"
+
data
[
i
]
+
"
' from '
"
+
fields
[
i
].
name
+
"
' isn't a type
"
+
[
EnumHandler
.
stringfyDataType
(
fields
[
i
].
dataType
)]);
}
}
else
{
// check if it's a valid enumtype
if
(
fields
[
i
].
dataType
===
DataType
.
ENUMTYPE
){
enumType
=
req
.
engine
.
getEnumTypeByName
(
fields
[
i
].
enumType
);
types
=
enumType
.
values
;
let
found
:
boolean
=
false
;
...
...
@@ -157,6 +150,21 @@ export class CollectCtrl {
"
' isn't listed on
"
+
fields
[
i
].
enumType
);
}
}
else
if
(
fields
[
i
].
dataType
!==
DataType
.
NONE
){
// check if it's a valid datatype from query
if
(
!
validador
[
EnumHandler
.
stringfyDataType
(
fields
[
i
].
dataType
)](
data
[
i
])
===
true
){
throw
new
Error
(
"
The value '
"
+
data
[
i
]
+
"
' from '
"
+
fields
[
i
].
name
+
"
' isn't a type
"
+
[
EnumHandler
.
stringfyDataType
(
fields
[
i
].
dataType
)]);
}
}
// undefined DataType
else
{
throw
new
Error
(
"
The value '
"
+
data
[
i
]
+
"
' from '
"
+
fields
[
i
].
name
+
"
' isn't listed on
"
+
fields
[
i
].
enumType
);
}
}
}
...
...
src/core/dimension.ts
View file @
f00a8a08
...
...
@@ -52,6 +52,8 @@ export interface DimensionStrOptions {
relation
?:
string
;
/** Breif description of what this dimension represents. */
description
?:
string
;
/** Dimension enum type */
enumType
?:
string
;
}
/**
...
...
@@ -85,7 +87,7 @@ export class Dimension {
this
.
relation
=
(
options
.
relation
)
?
options
.
relation
:
RelationType
.
NONE
;
this
.
parent
=
(
options
.
parent
)
?
options
.
parent
:
null
;
this
.
description
=
(
options
.
description
)
?
options
.
description
:
""
;
this
.
enumType
=
(
options
.
enumType
)
?
(
options
.
enumType
)
:
""
;
this
.
enumType
=
(
options
.
enumType
)
?
options
.
enumType
:
""
;
}
/**
...
...
@@ -93,21 +95,19 @@ export class Dimension {
* dimension as strings. Used to inform the API users.
*/
public
strOptions
():
DimensionStrOptions
{
if
(
this
.
relation
===
RelationType
.
NONE
)
{
return
{
name
:
this
.
name
,
dataType
:
(
this
.
dataType
!==
DataType
.
NONE
)
?
EnumHandler
.
stringfyDataType
(
this
.
dataType
)
:
this
.
enumType
,
description
:
this
.
description
};
let
o
:
DimensionStrOptions
=
{
name
:
this
.
name
,
dataType
:
EnumHandler
.
stringfyDataType
(
this
.
dataType
),
description
:
this
.
description
};
if
(
this
.
relation
!==
RelationType
.
NONE
){
o
.
relation
=
EnumHandler
.
stringifyRelationType
(
this
.
relation
);
o
.
parent
=
this
.
parent
.
name
;
}
else
{
return
{
name
:
this
.
name
,
dataType
:
(
this
.
dataType
!==
DataType
.
NONE
)
?
EnumHandler
.
stringfyDataType
(
this
.
dataType
)
:
this
.
enumType
,
parent
:
this
.
parent
.
name
,
relation
:
EnumHandler
.
stringifyRelationType
(
this
.
relation
),
description
:
this
.
description
};
if
(
this
.
dataType
===
DataType
.
ENUMTYPE
){
o
.
enumType
=
this
.
enumType
;
}
return
o
;
}
}
src/core/source.ts
View file @
f00a8a08
...
...
@@ -41,6 +41,8 @@ export interface FieldStr {
description
?:
string
;
/* Field data type. */
dataType
:
string
;
/* Field enum type. */
enumType
?:
string
;
}
/** Parameters used to create a source object. */
...
...
@@ -118,12 +120,17 @@ export class Source {
public
static
stringfyFieldDataType
(
opts
:
Field
[]):
FieldStr
[]
{
let
str
:
FieldStr
[];
str
=
opts
.
map
((
i
)
=>
{
return
{
name
:
i
.
name
,
let
o
:
FieldStr
=
{
name
:
i
.
name
,
description
:
i
.
description
,
dataType
:
(
i
.
dataType
!==
DataType
.
NONE
)
?
EnumHandler
.
stringfyDataType
(
i
.
dataType
)
:
i
.
enumType
dataType
:
EnumHandler
.
stringfyDataType
(
i
.
dataType
)
};
if
(
i
.
dataType
===
DataType
.
ENUMTYPE
)
{
o
.
enumType
=
i
.
enumType
;
}
return
o
;
});
return
str
;
}
...
...
@@ -134,12 +141,15 @@ export class Source {
public
static
parseFieldDataType
(
opts
:
FieldStr
[]):
Field
[]
{
let
str
:
Field
[];
str
=
opts
.
map
((
i
)
=>
{
return
{
name
:
i
.
name
,
let
o
:
Field
=
{
name
:
i
.
name
,
description
:
i
.
description
,
dataType
:
EnumHandler
.
parseDataType
(
i
.
dataType
),
enumType
:
(
EnumHandler
.
parseDataType
(
i
.
dataType
)
===
DataType
.
NONE
)
?
i
.
dataType
:
""
};
if
(
o
.
dataType
===
DataType
.
ENUMTYPE
){
o
.
enumType
=
i
.
enumType
;
}
return
o
;
});
return
str
;
}
...
...
src/util/configParser.spec.ts
View file @
f00a8a08
...
...
@@ -208,7 +208,8 @@ describe("configParser utility library", () => {
let
opts
:
DimensionStrOptions
=
{
name
:
"
dim:day
"
,
dataType
:
"
enumtype:5
"
,
dataType
:
"
enumtype
"
,
enumType
:
"
enumtype:5
"
,
parent
:
"
dim:0
"
,
relation
:
"
day
"
};
...
...
@@ -281,7 +282,8 @@ describe("configParser utility library", () => {
dataType
:
"
string
"
},
{
name
:
"
fields:1
"
,
description
:
"
second entry
"
,
dataType
:
"
enumtype:10
"
}
dataType
:
"
enumtype
"
,
enumType
:
"
enumtype:10
"
}
]
};
let
enumMap
:
{[
key
:
string
]:
EnumType
}
=
{
...
...
@@ -294,10 +296,9 @@ describe("configParser utility library", () => {
catch
(
e
)
{
error
=
true
;
expect
(
e
.
message
).
to
.
be
.
equal
(
"
[Parsing error]
DataType: '
"
+
sourc
.
fields
[
1
].
data
Type
+
"
' does not exist on Source
"
);
.
equal
(
"
[Parsing error]
EnumType: '
"
+
sourc
.
fields
[
1
].
enum
Type
+
"
' does not exist on Source
"
);
}
expect
(
error
).
to
.
be
.
true
;
});
});
src/util/configParser.ts
View file @
f00a8a08
...
...
@@ -322,8 +322,11 @@ export class ConfigParser {
public
static
parseDimOpts
(
opts
:
DimensionStrOptions
,
dims
:
Dimension
[],
map
:
EnumTypeMap
):
DimensionOptions
{
let
type
=
EnumHandler
.
parseDataType
(
opts
.
dataType
);
if
(
type
===
DataType
.
NONE
)
{
if
(
!
(
map
[
opts
.
dataType
]))
{
throw
new
Error
(
"
[Parsing error] DataType: '
"
+
opts
.
dataType
+
"
' does not exist on Dimension
"
);
}
else
if
(
type
===
DataType
.
ENUMTYPE
)
{
if
(
!
(
map
[
opts
.
enumType
]))
{
throw
new
Error
(
"
[Parsing error] EnumType: '
"
+
opts
.
enumType
+
"
' does not exist on Dimension
"
);
}
}
if
(
opts
.
parent
||
opts
.
relation
)
{
...
...
@@ -335,7 +338,7 @@ export class ConfigParser {
description
:
opts
.
description
,
parent
:
dims
[
i
],
relation
:
EnumHandler
.
parseRelationType
(
opts
.
relation
),
enumType
:
(
EnumHandler
.
parseDataType
(
opts
.
dataType
)
===
DataType
.
NONE
)
?
opts
.
dataType
:
""
enumType
:
opts
.
enumType
};
}
}
...
...
@@ -348,7 +351,7 @@ export class ConfigParser {
description
:
opts
.
description
,
parent
:
null
,
relation
:
RelationType
.
NONE
,
enumType
:
(
EnumHandler
.
parseDataType
(
opts
.
dataType
)
===
DataType
.
NONE
)
?
opts
.
dataType
:
""
enumType
:
opts
.
enumType
};
}
...
...
@@ -399,14 +402,15 @@ export class ConfigParser {
*/
public
static
parseSourceOpts
(
opts
:
SourceStrOptions
,
map
:
EnumTypeMap
):
SourceOptions
{
for
(
let
k
=
0
;
k
<
opts
.
fields
.
length
;
k
++
)
{
let
type
=
EnumHandler
.
parseDataType
(
opts
.
fields
[
k
].
dataType
);
if
(
type
===
DataType
.
NONE
)
{
if
(
!
(
map
[
opts
.
fields
[
k
].
dataType
])){
throw
new
Error
(
"
[Parsing error] DataType: '
"
+
opts
.
fields
[
k
].
dataType
+
"
' does not exist on Source
"
);
}
}
let
type
=
EnumHandler
.
parseDataType
(
opts
.
fields
[
k
].
dataType
);
if
(
type
===
DataType
.
NONE
)
{
throw
new
Error
(
"
[Parsing error] DataType: '
"
+
opts
.
fields
[
k
].
dataType
+
"
' does not exist on Source
"
);
}
else
if
(
type
===
DataType
.
ENUMTYPE
){
if
(
!
(
map
[
opts
.
fields
[
k
].
enumType
])){
throw
new
Error
(
"
[Parsing error] EnumType: '
"
+
opts
.
fields
[
k
].
enumType
+
"
' does not exist on Source
"
);
}
}
}
return
{
name
:
opts
.
name
,
...
...
src/util/enumHandler.ts
View file @
f00a8a08
...
...
@@ -41,6 +41,8 @@ export class EnumHandler {
return
"
date
"
;
case
DataType
.
BOOLEAN
:
return
"
boolean
"
;
case
DataType
.
ENUMTYPE
:
return
"
enumtype
"
;
default
:
return
""
;
}
...
...
@@ -63,6 +65,8 @@ export class EnumHandler {
return
DataType
.
DATE
;
case
"
boolean
"
:
return
DataType
.
BOOLEAN
;
case
"
enumtype
"
:
return
DataType
.
ENUMTYPE
;
default
:
return
DataType
.
NONE
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment