@things-factory/dataset 7.0.0-alpha.0 → 7.0.0-alpha.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (187) hide show
  1. package/client/activities/activity-data-collect-edit.ts +1 -7
  2. package/client/activities/activity-data-collect-view.ts +7 -0
  3. package/client/activities/activity-data-review-edit.ts +66 -32
  4. package/client/activities/activity-data-review-view.ts +75 -29
  5. package/client/activities/activity-ooc-resolve-edit.ts +44 -48
  6. package/client/activities/activity-ooc-resolve-view.ts +25 -35
  7. package/client/activities/activity-ooc-review-edit.ts +36 -29
  8. package/client/activities/activity-ooc-review-view.ts +9 -19
  9. package/client/bootstrap.ts +5 -9
  10. package/client/pages/data-entry/data-entry-list-page.ts +8 -23
  11. package/client/pages/data-ooc/data-ooc-list-page.ts +71 -27
  12. package/client/pages/data-ooc/{data-ooc-view-page.ts → data-ooc-page.ts} +45 -1
  13. package/client/pages/data-ooc/data-ooc-view.ts +198 -41
  14. package/client/pages/data-ooc/data-oocs-page.ts +200 -0
  15. package/client/pages/data-sample/data-sample-list-page.ts +53 -31
  16. package/client/pages/data-sample/{data-sample-view-page.ts → data-sample-page.ts} +8 -1
  17. package/client/pages/data-sample/data-sample-search-page.ts +30 -25
  18. package/client/pages/data-sample/data-sample-view.ts +192 -21
  19. package/client/pages/data-sample/data-samples-page.ts +249 -0
  20. package/client/pages/data-sensor/data-sensor-list-page.ts +28 -6
  21. package/client/pages/data-set/data-item-list.ts +14 -8
  22. package/client/pages/data-set/data-set-list-page.ts +11 -21
  23. package/client/pages/data-summary/data-summary-list-page.ts +12 -24
  24. package/client/route.ts +10 -2
  25. package/dist-client/activities/activity-data-collect-edit.js +1 -7
  26. package/dist-client/activities/activity-data-collect-edit.js.map +1 -1
  27. package/dist-client/activities/activity-data-collect-view.js +7 -0
  28. package/dist-client/activities/activity-data-collect-view.js.map +1 -1
  29. package/dist-client/activities/activity-data-review-edit.d.ts +1 -1
  30. package/dist-client/activities/activity-data-review-edit.js +63 -33
  31. package/dist-client/activities/activity-data-review-edit.js.map +1 -1
  32. package/dist-client/activities/activity-data-review-view.d.ts +1 -1
  33. package/dist-client/activities/activity-data-review-view.js +72 -30
  34. package/dist-client/activities/activity-data-review-view.js.map +1 -1
  35. package/dist-client/activities/activity-ooc-resolve-edit.d.ts +1 -1
  36. package/dist-client/activities/activity-ooc-resolve-edit.js +44 -48
  37. package/dist-client/activities/activity-ooc-resolve-edit.js.map +1 -1
  38. package/dist-client/activities/activity-ooc-resolve-view.d.ts +13 -0
  39. package/dist-client/activities/activity-ooc-resolve-view.js +24 -34
  40. package/dist-client/activities/activity-ooc-resolve-view.js.map +1 -1
  41. package/dist-client/activities/activity-ooc-review-edit.js +39 -29
  42. package/dist-client/activities/activity-ooc-review-edit.js.map +1 -1
  43. package/dist-client/activities/activity-ooc-review-view.js +9 -19
  44. package/dist-client/activities/activity-ooc-review-view.js.map +1 -1
  45. package/dist-client/bootstrap.d.ts +4 -4
  46. package/dist-client/bootstrap.js +4 -4
  47. package/dist-client/bootstrap.js.map +1 -1
  48. package/dist-client/pages/data-entry/data-entry-list-page.js +3 -15
  49. package/dist-client/pages/data-entry/data-entry-list-page.js.map +1 -1
  50. package/dist-client/pages/data-ooc/data-ooc-list-page.d.ts +6 -0
  51. package/dist-client/pages/data-ooc/data-ooc-list-page.js +67 -24
  52. package/dist-client/pages/data-ooc/data-ooc-list-page.js.map +1 -1
  53. package/dist-client/pages/data-ooc/{data-ooc-view-page.js → data-ooc-page.js} +46 -2
  54. package/dist-client/pages/data-ooc/data-ooc-page.js.map +1 -0
  55. package/dist-client/pages/data-ooc/data-ooc-view.d.ts +11 -4
  56. package/dist-client/pages/data-ooc/data-ooc-view.js +193 -48
  57. package/dist-client/pages/data-ooc/data-ooc-view.js.map +1 -1
  58. package/dist-client/pages/data-ooc/data-oocs-page.d.ts +18 -0
  59. package/dist-client/pages/data-ooc/data-oocs-page.js +200 -0
  60. package/dist-client/pages/data-ooc/data-oocs-page.js.map +1 -0
  61. package/dist-client/pages/data-sample/data-sample-list-page.d.ts +6 -1
  62. package/dist-client/pages/data-sample/data-sample-list-page.js +51 -28
  63. package/dist-client/pages/data-sample/data-sample-list-page.js.map +1 -1
  64. package/dist-client/pages/data-sample/{data-sample-view-page.js → data-sample-page.js} +9 -2
  65. package/dist-client/pages/data-sample/data-sample-page.js.map +1 -0
  66. package/dist-client/pages/data-sample/data-sample-search-page.d.ts +6 -1
  67. package/dist-client/pages/data-sample/data-sample-search-page.js +28 -22
  68. package/dist-client/pages/data-sample/data-sample-search-page.js.map +1 -1
  69. package/dist-client/pages/data-sample/data-sample-view.d.ts +18 -0
  70. package/dist-client/pages/data-sample/data-sample-view.js +186 -19
  71. package/dist-client/pages/data-sample/data-sample-view.js.map +1 -1
  72. package/dist-client/pages/data-sample/data-samples-page.d.ts +21 -0
  73. package/dist-client/pages/data-sample/data-samples-page.js +249 -0
  74. package/dist-client/pages/data-sample/data-samples-page.js.map +1 -0
  75. package/dist-client/pages/data-sensor/data-sensor-list-page.js +28 -6
  76. package/dist-client/pages/data-sensor/data-sensor-list-page.js.map +1 -1
  77. package/dist-client/pages/data-set/data-item-list.js +14 -8
  78. package/dist-client/pages/data-set/data-item-list.js.map +1 -1
  79. package/dist-client/pages/data-set/data-set-list-page.js +3 -10
  80. package/dist-client/pages/data-set/data-set-list-page.js.map +1 -1
  81. package/dist-client/pages/data-summary/data-summary-list-page.js +12 -21
  82. package/dist-client/pages/data-summary/data-summary-list-page.js.map +1 -1
  83. package/dist-client/route.js +8 -2
  84. package/dist-client/route.js.map +1 -1
  85. package/dist-client/tsconfig.tsbuildinfo +1 -1
  86. package/dist-server/activities/activity-data-collect.js.map +1 -1
  87. package/dist-server/activities/activity-data-review.js.map +1 -1
  88. package/dist-server/activities/activity-ooc-review.js +3 -2
  89. package/dist-server/activities/activity-ooc-review.js.map +1 -1
  90. package/dist-server/controllers/create-data-sample.js +27 -29
  91. package/dist-server/controllers/create-data-sample.js.map +1 -1
  92. package/dist-server/controllers/{generate-data-summary.js → finalize-data-collection.js} +10 -30
  93. package/dist-server/controllers/finalize-data-collection.js.map +1 -0
  94. package/dist-server/controllers/issue-collect-data.js +55 -0
  95. package/dist-server/controllers/issue-collect-data.js.map +1 -0
  96. package/dist-server/controllers/query-data-summary-by-period.js +4 -9
  97. package/dist-server/controllers/query-data-summary-by-period.js.map +1 -1
  98. package/dist-server/engine/index.js +4 -0
  99. package/dist-server/engine/index.js.map +1 -0
  100. package/dist-server/engine/task/create-data-sample.js +80 -0
  101. package/dist-server/engine/task/create-data-sample.js.map +1 -0
  102. package/dist-server/engine/task/index.js +5 -0
  103. package/dist-server/engine/task/index.js.map +1 -0
  104. package/dist-server/engine/task/issue-collect-data.js +40 -0
  105. package/dist-server/engine/task/issue-collect-data.js.map +1 -0
  106. package/dist-server/index.js +1 -0
  107. package/dist-server/index.js.map +1 -1
  108. package/dist-server/routes.js +36 -65
  109. package/dist-server/routes.js.map +1 -1
  110. package/dist-server/service/data-ooc/data-ooc-query.js +32 -0
  111. package/dist-server/service/data-ooc/data-ooc-query.js.map +1 -1
  112. package/dist-server/service/data-ooc/data-ooc-subscription.js +4 -4
  113. package/dist-server/service/data-ooc/data-ooc-subscription.js.map +1 -1
  114. package/dist-server/service/data-ooc/data-ooc.js +44 -37
  115. package/dist-server/service/data-ooc/data-ooc.js.map +1 -1
  116. package/dist-server/service/data-sample/data-sample-query.js +24 -0
  117. package/dist-server/service/data-sample/data-sample-query.js.map +1 -1
  118. package/dist-server/service/data-sample/data-sample.js +30 -31
  119. package/dist-server/service/data-sample/data-sample.js.map +1 -1
  120. package/dist-server/service/data-sensor/data-sensor-query.js +16 -1
  121. package/dist-server/service/data-sensor/data-sensor-query.js.map +1 -1
  122. package/dist-server/service/data-sensor/data-sensor-type.js +8 -0
  123. package/dist-server/service/data-sensor/data-sensor-type.js.map +1 -1
  124. package/dist-server/service/data-sensor/data-sensor.js +15 -1
  125. package/dist-server/service/data-sensor/data-sensor.js.map +1 -1
  126. package/dist-server/service/data-set/data-item-type.js +17 -2
  127. package/dist-server/service/data-set/data-item-type.js.map +1 -1
  128. package/dist-server/service/data-set/data-set-mutation.js +2 -2
  129. package/dist-server/service/data-set/data-set-mutation.js.map +1 -1
  130. package/dist-server/service/data-set/data-set-query.js +2 -2
  131. package/dist-server/service/data-set/data-set-query.js.map +1 -1
  132. package/dist-server/service/data-summary/data-summary-mutation.js +34 -5
  133. package/dist-server/service/data-summary/data-summary-mutation.js.map +1 -1
  134. package/dist-server/service/data-summary/data-summary.js +8 -8
  135. package/dist-server/service/data-summary/data-summary.js.map +1 -1
  136. package/dist-server/tsconfig.tsbuildinfo +1 -1
  137. package/helps/config/dataArchive.md +21 -0
  138. package/helps/config/dataReport.md +34 -0
  139. package/helps/dataset/task/create-data-sample.ja.md +28 -0
  140. package/helps/dataset/task/create-data-sample.ko.md +28 -0
  141. package/helps/dataset/task/create-data-sample.md +28 -0
  142. package/helps/dataset/task/create-data-sample.ms.md +30 -0
  143. package/helps/dataset/task/create-data-sample.zh.md +28 -0
  144. package/helps/dataset/task/issue-collect-data.ja.md +35 -0
  145. package/helps/dataset/task/issue-collect-data.ko.md +32 -0
  146. package/helps/dataset/task/issue-collect-data.md +32 -0
  147. package/helps/dataset/task/issue-collect-data.ms.md +34 -0
  148. package/helps/dataset/task/issue-collect-data.zh.md +32 -0
  149. package/helps/dataset/ui/data-item-list.ko.md +17 -2
  150. package/package.json +14 -11
  151. package/server/activities/activity-data-collect.ts +3 -11
  152. package/server/activities/activity-data-review.ts +1 -5
  153. package/server/activities/activity-ooc-review.ts +6 -16
  154. package/server/controllers/create-data-sample.ts +31 -38
  155. package/server/controllers/{generate-data-summary.ts → finalize-data-collection.ts} +7 -39
  156. package/server/controllers/issue-collect-data.ts +61 -0
  157. package/server/controllers/query-data-summary-by-period.ts +5 -18
  158. package/server/engine/index.ts +1 -0
  159. package/server/engine/task/create-data-sample.ts +92 -0
  160. package/server/engine/task/index.ts +2 -0
  161. package/server/engine/task/issue-collect-data.ts +45 -0
  162. package/server/index.ts +1 -0
  163. package/server/routes.ts +47 -76
  164. package/server/service/data-ooc/data-ooc-query.ts +17 -0
  165. package/server/service/data-ooc/data-ooc-subscription.ts +7 -7
  166. package/server/service/data-ooc/data-ooc.ts +39 -51
  167. package/server/service/data-sample/data-sample-query.ts +17 -17
  168. package/server/service/data-sample/data-sample.ts +29 -52
  169. package/server/service/data-sensor/data-sensor-query.ts +13 -1
  170. package/server/service/data-sensor/data-sensor-type.ts +6 -0
  171. package/server/service/data-sensor/data-sensor.ts +13 -11
  172. package/server/service/data-set/data-item-type.ts +19 -10
  173. package/server/service/data-set/data-set-mutation.ts +9 -31
  174. package/server/service/data-set/data-set-query.ts +7 -7
  175. package/server/service/data-summary/data-summary-mutation.ts +24 -7
  176. package/server/service/data-summary/data-summary.ts +10 -23
  177. package/things-factory.config.js +10 -2
  178. package/translations/en.json +17 -3
  179. package/translations/ja.json +14 -2
  180. package/translations/ko.json +16 -2
  181. package/translations/ms.json +13 -1
  182. package/translations/zh.json +14 -2
  183. package/dist-client/pages/data-ooc/data-ooc-view-page.js.map +0 -1
  184. package/dist-client/pages/data-sample/data-sample-view-page.js.map +0 -1
  185. package/dist-server/controllers/generate-data-summary.js.map +0 -1
  186. /package/dist-client/pages/data-ooc/{data-ooc-view-page.d.ts → data-ooc-page.d.ts} +0 -0
  187. /package/dist-client/pages/data-sample/{data-sample-view-page.d.ts → data-sample-page.d.ts} +0 -0
package/server/routes.ts CHANGED
@@ -2,13 +2,13 @@ import { In } from 'typeorm'
2
2
 
3
3
  import { Domain, getDataSource } from '@things-factory/shell'
4
4
  import { User } from '@things-factory/auth-base'
5
- import { Activity } from '@things-factory/worklist'
6
- import { issue } from '@things-factory/worklist/dist-server/controllers/activity-instance/issue'
5
+ import { runScenario } from '@things-factory/integration-base'
7
6
  import { ScheduleRegisterRequest } from '@things-factory/scheduler-client'
8
7
 
9
8
  import { createDataSample } from './controllers/create-data-sample'
10
9
  import { renderJasperReport } from './controllers/jasper-report'
11
10
  import { renderShinyReport } from './controllers/shiny-report'
11
+ import { issueCollectData } from './controllers/issue-collect-data'
12
12
  import { DataSensor } from './service/data-sensor/data-sensor'
13
13
  import { DataSet } from './service/data-set/data-set'
14
14
 
@@ -23,8 +23,8 @@ process.on('bootstrap-module-global-public-route' as any, (app, globalPublicRout
23
23
  globalPublicRouter.post('/sensor-data', async (context, next) => {
24
24
  // 데이타 검증
25
25
  const { deviceId, data, rawData, timestamp = Date.now() } = context.request.body
26
- if (!deviceId || !data) {
27
- throw new Error(`deviceId(${deviceId}) and data(${JSON.stringify(data)}) properties are mandatory`)
26
+ if (!deviceId) {
27
+ throw new Error(`The deviceId(${deviceId}) property are mandatory`)
28
28
  }
29
29
 
30
30
  // make new data-sample
@@ -32,7 +32,7 @@ process.on('bootstrap-module-global-public-route' as any, (app, globalPublicRout
32
32
  // find sensor through deviceId
33
33
  const sensor = await tx.getRepository(DataSensor).findOne({
34
34
  where: { deviceId },
35
- relations: ['domain', 'appliance', 'dataSet']
35
+ relations: ['domain', 'appliance', 'dataSet', 'decoder']
36
36
  })
37
37
 
38
38
  if (!sensor) {
@@ -47,18 +47,18 @@ process.on('bootstrap-module-global-public-route' as any, (app, globalPublicRout
47
47
  throw new Error(`Appliance of the sensor given deviceId(${deviceId}) is not set up`)
48
48
  }
49
49
 
50
- if (!sensor.dataSet) {
51
- throw new Error(`DataSet of the sensor given deviceId(${deviceId}) is not set up`)
52
- }
50
+ // if (!sensor.dataSet) {
51
+ // throw new Error(`DataSet of the sensor given deviceId(${deviceId}) is not set up`)
52
+ // }
53
53
 
54
54
  const domain = sensor.domain
55
55
  const dataSet = sensor.dataSet
56
- const user: User = await tx.getRepository(User).findOne({
57
- where: {
58
- reference: sensor.appliance.id,
59
- userType: 'appliance'
60
- }
61
- })
56
+ // const user: User = await tx.getRepository(User).findOne({
57
+ // where: {
58
+ // reference: sensor.appliance.id,
59
+ // userType: 'appliance'
60
+ // }
61
+ // })
62
62
 
63
63
  context.state = {
64
64
  ...context.state,
@@ -66,19 +66,40 @@ process.on('bootstrap-module-global-public-route' as any, (app, globalPublicRout
66
66
  tx
67
67
  }
68
68
 
69
- return await createDataSample(
70
- {
71
- dataSet,
69
+ var decoded
70
+ if (sensor.decoder) {
71
+ const { name: scenarioName } = sensor.decoder
72
+ const variables = {
73
+ dataSensor: sensor,
74
+ source: deviceId,
72
75
  data,
73
76
  rawData,
74
- source: deviceId,
75
- collectedAt: new Date(timestamp)
76
- },
77
- context
78
- )
79
- })
77
+ timestamp
78
+ }
80
79
 
81
- context.status = 200
80
+ decoded = (await runScenario(null, scenarioName, variables, context))?.result
81
+ }
82
+
83
+ if (dataSet) {
84
+ await createDataSample(
85
+ {
86
+ dataSet,
87
+ data,
88
+ rawData,
89
+ source: deviceId,
90
+ collectedAt: new Date(timestamp),
91
+ ...decoded
92
+ },
93
+ context
94
+ )
95
+ }
96
+
97
+ context.status = 200
98
+ context.body = {
99
+ data,
100
+ ...decoded
101
+ }
102
+ })
82
103
  })
83
104
 
84
105
  /* When a callback occurs from the scheduler when a scheduled dataset is on schedule, data collection task for the dataset should be issued. */
@@ -95,55 +116,7 @@ process.on('bootstrap-module-global-public-route' as any, (app, globalPublicRout
95
116
  throw new Error(`group(${domainId}) and key(${dataSetId}) properties should not be empty`)
96
117
  }
97
118
 
98
- await getDataSource().transaction(async tx => {
99
- const domain = await tx.getRepository(Domain).findOneBy({ id: domainId })
100
-
101
- if (!domain) {
102
- throw new Error(`domain(${domainId}) not found`)
103
- }
104
-
105
- const dataSet = await tx
106
- .getRepository(DataSet)
107
- .findOne({ where: { domain: { id: In([domain.id, domain.parentId].filter(Boolean)) }, id: dataSetId } })
108
-
109
- const activity = (await tx.getRepository(Activity).findOneBy({
110
- domain: { id: domainId },
111
- name: 'Collect Data'
112
- })) as Activity
113
-
114
- if (activity) {
115
- const { assignees } = dataSet
116
-
117
- /* 해당 dataset에 대한 데이타 수집 태스크를 dataset assignees에게 할당한다. */
118
- if (assignees && assignees instanceof Array && assignees.length > 0) {
119
- const activityInstance = {
120
- name: `[Data 수집] ${dataSet.name}`,
121
- description: dataSet.description,
122
- activityId: activity.id,
123
- dueAt: new Date(Date.now() + 24 * 60 * 60 * 1000),
124
- input: {
125
- dataSetId: dataSet.id,
126
- dataSetName: dataSet.name
127
- },
128
- assignees
129
- }
130
-
131
- context.state = {
132
- ...context.state,
133
- domain,
134
- tx
135
- }
136
-
137
- await issue(activityInstance, context)
138
- } else {
139
- throw new Error(
140
- `Assignees not set. So Data Collect Activity for ${dataSet.name}($dataSet.id) could not be issued.`
141
- )
142
- }
143
- } else {
144
- throw new Error(`Data Collect Activity is not installed.`)
145
- }
146
- })
119
+ await issueCollectData(domainId, dataSetId, context)
147
120
 
148
121
  context.status = 200
149
122
  })
@@ -169,9 +142,7 @@ process.on('bootstrap-module-global-public-route' as any, (app, globalPublicRout
169
142
  throw new Error(`domain(${domainId}) not found`)
170
143
  }
171
144
 
172
- const dataSet = await tx
173
- .getRepository(DataSet)
174
- .findOne({ where: { domain: { id: In([domain.id, domain.parentId].filter(Boolean)) }, id: dataSetId } })
145
+ const dataSet = await tx.getRepository(DataSet).findOne({ where: { domain: { id: In([domain.id, domain.parentId].filter(Boolean)) }, id: dataSetId } })
175
146
 
176
147
  // do what you gotta do
177
148
  })
@@ -2,10 +2,12 @@ import { Arg, Args, Ctx, Directive, FieldResolver, Query, Resolver, Root } from
2
2
 
3
3
  import { User } from '@things-factory/auth-base'
4
4
  import { Domain, getQueryBuilderFromListParams, getRepository, ListParam } from '@things-factory/shell'
5
+ import { ActivityInstance } from '@things-factory/worklist'
5
6
 
6
7
  import { DataSetHistory } from '../data-set-history/data-set-history'
7
8
  import { DataItem } from '../data-set/data-item-type'
8
9
  import { DataSet } from '../data-set/data-set'
10
+ import { DataSample } from '../data-sample/data-sample'
9
11
  import { DataOoc } from './data-ooc'
10
12
  import { DataOocList } from './data-ooc-type'
11
13
 
@@ -51,11 +53,26 @@ export class DataOocQuery {
51
53
  return dataSetHistory?.dataItems || []
52
54
  }
53
55
 
56
+ @FieldResolver(type => DataSample)
57
+ async dataSample(@Root() dataOoc: DataOoc): Promise<DataSample> {
58
+ return dataOoc.dataSampleId && (await getRepository(DataSample).findOneBy({ id: dataOoc.dataSampleId }))
59
+ }
60
+
54
61
  @FieldResolver(type => DataSet)
55
62
  async dataSet(@Root() dataOoc: DataOoc): Promise<DataSet> {
56
63
  return dataOoc.dataSetId && (await getRepository(DataSet).findOneBy({ id: dataOoc.dataSetId }))
57
64
  }
58
65
 
66
+ @FieldResolver(type => ActivityInstance)
67
+ async reviewActivityInstance(@Root() dataOoc: DataOoc): Promise<ActivityInstance> {
68
+ return dataOoc.reviewActivityInstanceId && (await getRepository(ActivityInstance).findOneBy({ id: dataOoc.reviewActivityInstanceId }))
69
+ }
70
+
71
+ @FieldResolver(type => ActivityInstance)
72
+ async resolveActivityInstance(@Root() dataOoc: DataOoc): Promise<ActivityInstance> {
73
+ return dataOoc.resolveActivityInstanceId && (await getRepository(ActivityInstance).findOneBy({ id: dataOoc.resolveActivityInstanceId }))
74
+ }
75
+
59
76
  @FieldResolver(type => User)
60
77
  async corrector(@Root() dataOoc: DataOoc): Promise<User> {
61
78
  return dataOoc.correctorId && (await getRepository(User).findOneBy({ id: dataOoc.correctorId }))
@@ -1,4 +1,4 @@
1
- import { withFilter } from 'graphql-subscriptions'
1
+ import { filter, pipe } from 'graphql-yoga'
2
2
  import { Resolver, Root, Subscription } from 'type-graphql'
3
3
 
4
4
  import { User } from '@things-factory/auth-base'
@@ -9,7 +9,7 @@ import { DataOoc } from './data-ooc'
9
9
  @Resolver(DataOoc)
10
10
  export class DataOocSubscription {
11
11
  @Subscription({
12
- subscribe: (_, args, context, info) => {
12
+ subscribe: ({ args, context, info }) => {
13
13
  const { domain, user } = context.state
14
14
  const subdomain = domain?.subdomain
15
15
 
@@ -21,9 +21,9 @@ export class DataOocSubscription {
21
21
  throw new Error(`domain(${subdomain}) is not working for user(${user.email}).`)
22
22
  }
23
23
 
24
- return withFilter(
25
- () => pubsub.asyncIterator('data-ooc'),
26
- async (payload, variables, context, info) => {
24
+ return pipe(
25
+ pubsub.subscribe('data-ooc'),
26
+ filter(async (payload: { dataOoc: DataOoc; supervisoryRoleId: string }) => {
27
27
  const { dataOoc, supervisoryRoleId } = payload
28
28
  const { domain } = dataOoc
29
29
 
@@ -38,8 +38,8 @@ export class DataOocSubscription {
38
38
  })
39
39
 
40
40
  return !!userWithRoles.roles.find(role => role.id === supervisoryRoleId)
41
- }
42
- )(_, args, context, info)
41
+ })
42
+ )
43
43
  }
44
44
  })
45
45
  dataOoc(@Root() payload: { dataOoc: DataOoc; supervisoryRoleId: string }): DataOoc {
@@ -1,21 +1,14 @@
1
1
  import { Field, ID, ObjectType, registerEnumType } from 'type-graphql'
2
- import {
3
- Column,
4
- CreateDateColumn,
5
- Entity,
6
- Index,
7
- ManyToOne,
8
- PrimaryGeneratedColumn,
9
- RelationId,
10
- UpdateDateColumn
11
- } from 'typeorm'
2
+ import { Column, CreateDateColumn, Entity, Index, JoinColumn, ManyToOne, OneToOne, PrimaryGeneratedColumn, RelationId, UpdateDateColumn } from 'typeorm'
12
3
 
13
4
  import { User } from '@things-factory/auth-base'
14
5
  import { config } from '@things-factory/env'
15
6
  import { Domain, ScalarObject } from '@things-factory/shell'
7
+ import { ActivityInstance } from '@things-factory/worklist'
16
8
 
17
9
  import { DataItem } from '../data-set/data-item-type'
18
10
  import { DataSet } from '../data-set/data-set'
11
+ import { DataSample } from '../data-sample/data-sample'
19
12
 
20
13
  const ORMCONFIG = config.get('ormconfig', {})
21
14
  const DATABASE_TYPE = ORMCONFIG.type
@@ -47,12 +40,10 @@ export class DataOoc {
47
40
  domainId?: string
48
41
 
49
42
  @Column()
50
- @Field()
51
- name: string
43
+ @Field({ nullable: true })
44
+ name?: string
52
45
 
53
- @Column({
54
- nullable: true
55
- })
46
+ @Column({ nullable: true })
56
47
  @Field({ nullable: true })
57
48
  description?: string
58
49
 
@@ -67,57 +58,37 @@ export class DataOoc {
67
58
  @Field({ nullable: true })
68
59
  dataSetVersion?: number
69
60
 
70
- @Column({
71
- nullable: true
72
- })
61
+ @Column({ nullable: true })
73
62
  @Field({ nullable: true })
74
63
  ooc?: boolean
75
64
 
76
- @Column({
77
- nullable: true
78
- })
65
+ @Column({ nullable: true })
79
66
  @Field({ nullable: true })
80
67
  oos?: boolean
81
68
 
82
- @Column({
83
- nullable: true
84
- })
69
+ @Column({ nullable: true })
85
70
  @Field({ nullable: true })
86
71
  state?: DataOocStatus
87
72
 
88
73
  @Column({
89
74
  nullable: true,
90
- type:
91
- DATABASE_TYPE == 'mysql' || DATABASE_TYPE == 'mariadb'
92
- ? 'longtext'
93
- : DATABASE_TYPE == 'oracle'
94
- ? 'clob'
95
- : 'varchar'
75
+ type: DATABASE_TYPE == 'mysql' || DATABASE_TYPE == 'mariadb' ? 'longtext' : DATABASE_TYPE == 'oracle' ? 'clob' : 'varchar'
96
76
  })
97
77
  @Field({ nullable: true })
98
78
  correctiveInstruction?: string
99
79
 
100
80
  @Column({
101
81
  nullable: true,
102
- type:
103
- DATABASE_TYPE == 'mysql' || DATABASE_TYPE == 'mariadb'
104
- ? 'longtext'
105
- : DATABASE_TYPE == 'oracle'
106
- ? 'clob'
107
- : 'varchar'
82
+ type: DATABASE_TYPE == 'mysql' || DATABASE_TYPE == 'mariadb' ? 'longtext' : DATABASE_TYPE == 'oracle' ? 'clob' : 'varchar'
108
83
  })
109
84
  @Field({ nullable: true })
110
85
  correctiveAction?: string
111
86
 
112
- @Column({
113
- nullable: true
114
- })
87
+ @Column({ nullable: true })
115
88
  @Field({ nullable: true })
116
89
  type?: string
117
90
 
118
- @Column({
119
- nullable: true
120
- })
91
+ @Column({ nullable: true })
121
92
  @Field({ nullable: true })
122
93
  useCase?: string
123
94
 
@@ -162,22 +133,39 @@ export class DataOoc {
162
133
 
163
134
  @Column({
164
135
  nullable: true,
165
- type:
166
- DATABASE_TYPE == 'mysql' || DATABASE_TYPE == 'mariadb'
167
- ? 'longtext'
168
- : DATABASE_TYPE == 'oracle'
169
- ? 'clob'
170
- : 'varchar'
136
+ type: DATABASE_TYPE == 'mysql' || DATABASE_TYPE == 'mariadb' ? 'longtext' : DATABASE_TYPE == 'oracle' ? 'clob' : 'varchar'
171
137
  })
172
138
  @Field({ nullable: true })
173
139
  rawData?: string
174
140
 
175
- @Column({
176
- nullable: true
177
- })
141
+ @Column({ nullable: true })
178
142
  @Field({ nullable: true })
179
143
  source?: string
180
144
 
145
+ @OneToOne(type => DataSample, { nullable: true })
146
+ @JoinColumn()
147
+ @Field(type => DataSample, { nullable: true })
148
+ dataSample?: DataSample
149
+
150
+ @RelationId((dataOoc: DataOoc) => dataOoc.dataSample)
151
+ dataSampleId?: string
152
+
153
+ @OneToOne(type => ActivityInstance, { nullable: true })
154
+ @JoinColumn()
155
+ @Field({ nullable: true })
156
+ reviewActivityInstance?: ActivityInstance
157
+
158
+ @RelationId((dataOoc: DataOoc) => dataOoc.reviewActivityInstance)
159
+ reviewActivityInstanceId?: string
160
+
161
+ @OneToOne(type => ActivityInstance, { nullable: true })
162
+ @JoinColumn()
163
+ @Field({ nullable: true })
164
+ resolveActivityInstance?: ActivityInstance
165
+
166
+ @RelationId((dataOoc: DataOoc) => dataOoc.resolveActivityInstance)
167
+ resolveActivityInstanceId?: string
168
+
181
169
  @Column({ nullable: true })
182
170
  @Field({ nullable: true })
183
171
  workDate?: string
@@ -2,18 +2,14 @@ import { In } from 'typeorm'
2
2
  import { Arg, Args, Ctx, Directive, FieldResolver, Query, Resolver, Root } from 'type-graphql'
3
3
 
4
4
  import { User } from '@things-factory/auth-base'
5
- import {
6
- Domain,
7
- getQueryBuilderFromListParams,
8
- getRepository,
9
- getISOStringsForPeriod,
10
- ListParam
11
- } from '@things-factory/shell'
5
+ import { Domain, getQueryBuilderFromListParams, getRepository, getISOStringsForPeriod, ListParam } from '@things-factory/shell'
6
+ import { ActivityInstance } from '@things-factory/worklist'
12
7
 
13
8
  import { DataKeySet } from '../data-key-set/data-key-set'
14
9
  import { DataSetHistory } from '../data-set-history/data-set-history'
15
10
  import { DataItem } from '../data-set/data-item-type'
16
11
  import { DataSet } from '../data-set/data-set'
12
+ import { DataOoc } from '../data-ooc/data-ooc'
17
13
  import { DataSample } from './data-sample'
18
14
  import { DataSampleList } from './data-sample-type'
19
15
 
@@ -48,11 +44,7 @@ export class DataSampleQuery {
48
44
 
49
45
  @Directive('@privilege(category: "data-sample", privilege: "query", domainOwnerGranted: true)')
50
46
  @Query(returns => DataSampleList, { description: 'To fetch multiple data samples by data set' })
51
- async dataSamplesByDataSet(
52
- @Arg('dataSetId') dataSetId: string,
53
- @Args() params: ListParam,
54
- @Ctx() context: ResolverContext
55
- ): Promise<DataSampleList> {
47
+ async dataSamplesByDataSet(@Arg('dataSetId') dataSetId: string, @Args() params: ListParam, @Ctx() context: ResolverContext): Promise<DataSampleList> {
56
48
  const { domain } = context.state
57
49
 
58
50
  const dataSet = await getRepository(DataSet).findOne({
@@ -84,11 +76,7 @@ export class DataSampleQuery {
84
76
 
85
77
  @Directive('@privilege(category: "data-sample", privilege: "query", domainOwnerGranted: true)')
86
78
  @Query(returns => DataSampleList, { description: 'To fetch multiple data samples by data key set' })
87
- async dataSamplesByDataKeySet(
88
- @Arg('dataKeySetId') dataKeySetId: string,
89
- @Args() params: ListParam,
90
- @Ctx() context: ResolverContext
91
- ): Promise<DataSampleList> {
79
+ async dataSamplesByDataKeySet(@Arg('dataKeySetId') dataKeySetId: string, @Args() params: ListParam, @Ctx() context: ResolverContext): Promise<DataSampleList> {
92
80
  const { domain } = context.state
93
81
 
94
82
  const dataKeySet = await getRepository(DataKeySet).findOneBy({ id: dataKeySetId })
@@ -178,6 +166,18 @@ export class DataSampleQuery {
178
166
  return dataSample.dataSetId && (await getRepository(DataSet).findOneBy({ id: dataSample.dataSetId }))
179
167
  }
180
168
 
169
+ @FieldResolver(type => DataOoc)
170
+ async dataOoc(@Root() dataSample: DataSample): Promise<DataOoc> {
171
+ if (dataSample.ooc || dataSample.oos) {
172
+ return await getRepository(DataOoc).findOneBy({ dataSample: { id: dataSample.id } })
173
+ }
174
+ }
175
+
176
+ @FieldResolver(type => ActivityInstance)
177
+ async reviewActivityInstance(@Root() dataSample: DataSample): Promise<ActivityInstance> {
178
+ return dataSample.reviewActivityInstanceId && (await getRepository(ActivityInstance).findOneBy({ id: dataSample.reviewActivityInstanceId }))
179
+ }
180
+
181
181
  @FieldResolver(type => Domain)
182
182
  async domain(@Root() dataSample: DataSample): Promise<Domain> {
183
183
  return dataSample.domainId && (await getRepository(Domain).findOneBy({ id: dataSample.domainId }))
@@ -1,41 +1,22 @@
1
1
  import { Field, ID, ObjectType } from 'type-graphql'
2
- import {
3
- Column,
4
- CreateDateColumn,
5
- Entity,
6
- Index,
7
- ManyToOne,
8
- PrimaryGeneratedColumn,
9
- RelationId,
10
- UpdateDateColumn
11
- } from 'typeorm'
2
+ import { Column, CreateDateColumn, Entity, Index, JoinColumn, ManyToOne, OneToOne, PrimaryGeneratedColumn, RelationId, UpdateDateColumn } from 'typeorm'
12
3
 
13
4
  import { User } from '@things-factory/auth-base'
14
5
  import { config } from '@things-factory/env'
15
- import { Domain, ScalarObject } from '@things-factory/shell'
6
+ import { Domain, ScalarObject, json5Transformer } from '@things-factory/shell'
7
+ import { ActivityInstance } from '@things-factory/worklist'
16
8
 
17
9
  import { DataItem } from '../data-set/data-item-type'
18
10
  import { DataSet } from '../data-set/data-set'
11
+ import { DataOoc } from '../data-ooc/data-ooc'
19
12
 
20
13
  const ORMCONFIG = config.get('ormconfig', {})
21
14
  const DATABASE_TYPE = ORMCONFIG.type
22
15
  @Entity()
23
- @Index(
24
- 'ix_data_sample_0',
25
- (dataSample: DataSample) => [
26
- dataSample.domain,
27
- dataSample.dataSet,
28
- dataSample.workDate,
29
- dataSample.workShift,
30
- dataSample.collectedAt
31
- ],
32
- { unique: false }
33
- )
34
- @Index(
35
- 'ix_data_sample_1',
36
- (dataSample: DataSample) => [dataSample.domain, dataSample.dataSet, dataSample.collectedAt],
37
- { unique: false }
38
- )
16
+ @Index('ix_data_sample_0', (dataSample: DataSample) => [dataSample.domain, dataSample.dataSet, dataSample.workDate, dataSample.workShift, dataSample.collectedAt], {
17
+ unique: false
18
+ })
19
+ @Index('ix_data_sample_1', (dataSample: DataSample) => [dataSample.domain, dataSample.dataSet, dataSample.collectedAt], { unique: false })
39
20
  @ObjectType({ description: 'Entity for DataSample' })
40
21
  export class DataSample {
41
22
  @PrimaryGeneratedColumn('uuid')
@@ -50,24 +31,18 @@ export class DataSample {
50
31
  domainId?: string
51
32
 
52
33
  @Column()
53
- @Field()
34
+ @Field({ nullable: true })
54
35
  name: string
55
36
 
56
- @Column({
57
- nullable: true
58
- })
37
+ @Column({ nullable: true })
59
38
  @Field({ nullable: true })
60
39
  description?: string
61
40
 
62
- @Column({
63
- nullable: true
64
- })
41
+ @Column({ nullable: true })
65
42
  @Field({ nullable: true })
66
43
  type?: string
67
44
 
68
- @Column({
69
- nullable: true
70
- })
45
+ @Column({ nullable: true })
71
46
  @Field({ nullable: true })
72
47
  useCase?: string
73
48
 
@@ -99,31 +74,21 @@ export class DataSample {
99
74
 
100
75
  @Column({
101
76
  nullable: true,
102
- type:
103
- DATABASE_TYPE == 'mysql' || DATABASE_TYPE == 'mariadb'
104
- ? 'longtext'
105
- : DATABASE_TYPE == 'oracle'
106
- ? 'clob'
107
- : 'varchar'
77
+ type: DATABASE_TYPE == 'mysql' || DATABASE_TYPE == 'mariadb' ? 'longtext' : DATABASE_TYPE == 'oracle' ? 'clob' : 'varchar',
78
+ transformer: json5Transformer
108
79
  })
109
80
  @Field({ nullable: true })
110
81
  rawData?: string
111
82
 
112
- @Column({
113
- nullable: true
114
- })
83
+ @Column({ nullable: true })
115
84
  @Field({ nullable: true })
116
85
  source?: string
117
86
 
118
- @Column({
119
- nullable: true
120
- })
87
+ @Column({ nullable: true })
121
88
  @Field({ nullable: true })
122
89
  ooc?: boolean
123
90
 
124
- @Column({
125
- nullable: true
126
- })
91
+ @Column({ nullable: true })
127
92
  @Field({ nullable: true })
128
93
  oos?: boolean
129
94
 
@@ -155,6 +120,18 @@ export class DataSample {
155
120
  @Field({ nullable: true })
156
121
  workShift?: string
157
122
 
123
+ @OneToOne(type => ActivityInstance, { nullable: true })
124
+ @JoinColumn()
125
+ @Field({ nullable: true })
126
+ reviewActivityInstance?: ActivityInstance
127
+
128
+ @RelationId((dataSample: DataSample) => dataSample.reviewActivityInstance)
129
+ reviewActivityInstanceId?: string
130
+
131
+ @OneToOne(type => DataOoc, dataOoc => dataOoc.dataSample, { nullable: true })
132
+ @Field(type => DataOoc, { nullable: true })
133
+ dataOoc?: DataOoc
134
+
158
135
  @Column({ nullable: true })
159
136
  @Field({ nullable: true })
160
137
  collectedAt?: Date
@@ -2,6 +2,7 @@ import { Arg, Args, Ctx, FieldResolver, Query, Resolver, Root } from 'type-graph
2
2
 
3
3
  import { Appliance, User } from '@things-factory/auth-base'
4
4
  import { Domain, getQueryBuilderFromListParams, getRepository, ListParam } from '@things-factory/shell'
5
+ import { Scenario } from '@things-factory/integration-base'
5
6
 
6
7
  import { DataSet } from '../data-set/data-set'
7
8
  import { DataSensor } from './data-sensor'
@@ -39,11 +40,22 @@ export class DataSensorQuery {
39
40
  return dataSensor.applianceId && (await getRepository(Appliance).findOneBy({ id: dataSensor.applianceId }))
40
41
  }
41
42
 
42
- @FieldResolver(type => Appliance)
43
+ @FieldResolver(type => DataSet)
43
44
  async dataSet(@Root() dataSensor: DataSensor): Promise<DataSet> {
44
45
  return dataSensor.dataSetId && (await getRepository(DataSet).findOneBy({ id: dataSensor.dataSetId }))
45
46
  }
46
47
 
48
+ @FieldResolver(type => Scenario)
49
+ async decoder(@Root() dataSensor: DataSensor): Promise<Scenario> {
50
+ return (
51
+ dataSensor.decoder ||
52
+ (dataSensor.decoderId &&
53
+ (await getRepository(Scenario).findOneBy({
54
+ id: dataSensor.decoderId
55
+ })))
56
+ )
57
+ }
58
+
47
59
  @FieldResolver(type => Domain)
48
60
  async domain(@Root() dataSensor: DataSensor): Promise<Domain> {
49
61
  return dataSensor.domainId && (await getRepository(Domain).findOneBy({ id: dataSensor.domainId }))
@@ -41,6 +41,9 @@ export class NewDataSensor {
41
41
 
42
42
  @Field(type => ObjectRef, { nullable: true })
43
43
  dataSet?: ObjectRef
44
+
45
+ @Field(type => ObjectRef, { nullable: true })
46
+ decoder?: ObjectRef
44
47
  }
45
48
 
46
49
  @InputType()
@@ -84,6 +87,9 @@ export class DataSensorPatch {
84
87
  @Field(type => ObjectRef, { nullable: true })
85
88
  dataSet?: ObjectRef
86
89
 
90
+ @Field(type => ObjectRef, { nullable: true })
91
+ decoder?: ObjectRef
92
+
87
93
  @Field()
88
94
  cuFlag: string
89
95
  }