$darkmode

| Qore ServiceNowRestDataProvider Module Reference 1.2

ServiceNowTableDataProvider.qc.dox.h
1// -*- mode: c++; indent-tabs-mode: nil -*-
3
26 namespace ServiceNowRestDataProvider {
28hashdecl ServiceNowRestRecordInfo {
30 hash<string, AbstractDataField> record_type;
31
32 #! The original field type names
33 hash<string, string> field_types;
34
35 #! Hash of date/time fields for this record
36 hash<string, bool> date_time_fields;
37
38 #! Hash of boolean fields for this record
39 hash<string, bool> bool_fields;
40
41 #! Hash of integer fields for this record
42 hash<string, bool> int_fields;
43}
44
46 class ServiceNowTableDataProvider : public DataProvider::AbstractDataProvider {
47
48 public:
50 ServiceNowRestClient::ServiceNowRestClient rest;
51
53 string name;
54
56 hash<auto> access;
57
59 hash<auto> meta;
60
62 const SysColumns = {
63 "sys_created_by": {
64 "internal_type": {
65 "value": "string",
66 }
67 },
68 "sys_created_on": {
69 "internal_type": {
70 "value": "glide_date_time",
71 }
72 },
73 "sys_updated_by": {
74 "internal_type": {
75 "value": "string",
76 }
77 },
78 "sys_updated_on": {
79 "internal_type": {
80 "value": "glide_date_time",
81 }
82 },
83 };
84
86 const Expressions = {
87 DP_OP_AND: {
88 "exp": AbstractDataProvider::GenericExpressions{DP_OP_AND},
89 "impl": string sub (string cn, auto arg) {
90 throw "WHERE-ERROR", "ServiceNow does not support nested boolean logic in queries";
91 },
92 },
93 QUERY_OP_EQ: {
94 "exp": sym(AbstractDataProvider::GenericExpressions{DP_SEARCH_OP_EQ}, QUERY_OP_EQ),
95 "impl": string sub (string cn, auto arg) {
96 return sprintf("%s=%s", cn, arg);
97 },
98 },
99 QUERY_OP_NE: {
100 "exp": sym(AbstractDataProvider::GenericExpressions{DP_SEARCH_OP_NE}, QUERY_OP_NE),
101 "impl": string sub (string cn, auto arg) {
102 return sprintf("%s!=%s", cn, arg);
103 },
104 },
105 QUERY_OP_LT: {
106 "exp": sym(AbstractDataProvider::GenericExpressions{DP_SEARCH_OP_LT}, QUERY_OP_LT),
107 "impl": string sub (string cn, auto arg) {
108 return sprintf("%s<%s", cn, arg);
109 },
110 },
111 QUERY_OP_LE: {
112 "exp": sym(AbstractDataProvider::GenericExpressions{DP_SEARCH_OP_LE}, QUERY_OP_LE),
113 "impl": string sub (string cn, auto arg) {
114 return sprintf("%s<=%s", cn, arg);
115 },
116 },
117 QUERY_OP_GT: {
118 "exp": sym(AbstractDataProvider::GenericExpressions{DP_SEARCH_OP_GT}, QUERY_OP_GT),
119 "impl": string sub (string cn, auto arg) {
120 return sprintf("%s>%s", cn, arg);
121 },
122 },
123 QUERY_OP_GE: {
124 "exp": sym(AbstractDataProvider::GenericExpressions{DP_SEARCH_OP_GE}, QUERY_OP_GE),
125 "impl": string sub (string cn, auto arg) {
126 return sprintf("%s>=%s", cn, arg);
127 },
128 },
129 QUERY_OP_IN: {
130 "exp": sym(AbstractDataProvider::GenericExpressions{DP_SEARCH_OP_IN}, QUERY_OP_IN),
131 "impl": string sub (string cn, auto arg) {
132 return sprintf("%sIN%s", cn, (foldl $1 + "," + $2, arg));
133 },
134 },
135 QUERY_OP_NOTIN: {
136 "exp": <DataProviderExpressionInfo>{
137 "type": DET_Operator,
138 "label": QUERY_OP_NOTIN,
139 "name": "notin",
140 "desc": "An expression with the ServiceNow 'notin' operator",
141 "symbol": "NOTIN",
142 "args": (DataProviderSignatureFieldType, DataProviderSignatureStringValueType),
143 "return_type": AbstractDataProviderTypeMap."bool",
144 },
145 "impl": string sub (string cn, auto arg) {
146 return sprintf("%sNOTIN%s", cn, (foldl $1 + "," + $2, arg));
147 },
148 },
149 QUERY_OP_LIKE: {
150 "exp": <DataProviderExpressionInfo>{
151 "type": DET_Operator,
152 "label": QUERY_OP_LIKE,
153 "name": "like",
154 "desc": "An expression with the ServiceNow 'like' operator",
155 "symbol": "LIKE",
156 "args": (DataProviderSignatureFieldType, DataProviderSignatureStringValueType),
157 "return_type": AbstractDataProviderTypeMap."bool",
158 },
159 "impl": string sub (string cn, auto arg) {
160 return sprintf("%sLIKE%s", cn, arg);
161 },
162 },
163 QUERY_OP_NOTLIKE: {
164 "exp": <DataProviderExpressionInfo>{
165 "type": DET_Operator,
166 "label": QUERY_OP_NOTLIKE,
167 "name": "notlike",
168 "desc": "An expression with the ServiceNow 'notlike' operator",
169 "symbol": "NOTLIKE",
170 "args": (DataProviderSignatureFieldType, DataProviderSignatureStringValueType),
171 "return_type": AbstractDataProviderTypeMap."bool",
172 },
173 "impl": string sub (string cn, auto arg) {
174 return sprintf("%sNOTLIKE%s", cn, arg);
175 },
176 },
177 QUERY_OP_STARTSWITH: {
178 "exp": <DataProviderExpressionInfo>{
179 "type": DET_Operator,
180 "label": QUERY_OP_STARTSWITH,
181 "name": "like",
182 "desc": "An expression with the ServiceNow 'startswith' operator",
183 "symbol": "STARTSWITH",
184 "args": (DataProviderSignatureFieldType, DataProviderSignatureStringValueType),
185 "return_type": AbstractDataProviderTypeMap."bool",
186 },
187 "impl": string sub (string cn, auto arg) {
188 return sprintf("%sSTARTSWITH%s", cn, arg);
189 },
190 },
191 QUERY_OP_ENDSWITH: {
192 "exp": <DataProviderExpressionInfo>{
193 "type": DET_Operator,
194 "label": QUERY_OP_ENDSWITH,
195 "name": "like",
196 "desc": "An expression with the ServiceNow 'endswith' operator",
197 "symbol": "ENDSWITH",
198 "args": (DataProviderSignatureFieldType, DataProviderSignatureStringValueType),
199 "return_type": AbstractDataProviderTypeMap."bool",
200 },
201 "impl": string sub (string cn, auto arg) {
202 return sprintf("%sISEMPTY", cn);
203 },
204 },
205 QUERY_OP_ISNOTEMPTY: {
206 "exp": <DataProviderExpressionInfo>{
207 "type": DET_Operator,
208 "label": QUERY_OP_ISNOTEMPTY,
209 "name": "notlike",
210 "desc": "An expression with the ServiceNow 'isnotempty' operator",
211 "symbol": "ISNOTEMPTY",
212 "args": (DataProviderSignatureFieldType,),
213 "return_type": AbstractDataProviderTypeMap."bool",
214 },
215 "impl": string sub (string cn, auto arg) {
216 return sprintf("%sISNOTEMPTY", cn);
217 },
218 },
219 };
220
221 protected:
223 hash<ServiceNowRestRecordInfo> record_info();
224
226 string uri_path = "table/";
227
228 public:
229
231 constructor(ServiceNowRestClient rest, string name, hash<auto> access, hash<auto> meta);
232
233
235 string getName();
236
237
239 string getDesc();
240
241
242 protected:
243 *hash<string, DataProvider::AbstractDataField> getRecordTypeImpl(*hash<auto> search_options);
244 public:
245
246
248
253 private DataProvider::AbstractDataProviderRecordIterator searchRecordsImpl(*hash<auto> where_cond,
254 *hash<auto> search_options) {
255 return new ServiceNowRestRecordIterator(rest, name, record_info, where_cond, search_options);
256 }
257
259 protected:
260 hash<DataProvider::DataProviderInfo> getStaticInfoImpl();
261 public:
262
263
265
273 protected:
274 *hash<auto> createRecordImpl(hash<auto> rec, *hash<auto> create_options);
275 public:
276
277
279
285 private int updateRecordsImpl(hash<auto> set, hash<DataProviderExpression> where_cond,
286 *hash<auto> search_options) {
287 /*
288 if (where_cond.sys_id && where_cond.size() == 1) {
289 updateSingleRecord(where_cond.sys_id, set);
290 return 1;
291 }
292 */
293
294 AbstractDataProviderRecordIterator i = searchRecords(where_cond, search_options + {"columns": "sys_id"});
295 int count = 0;
296 map (updateSingleRecord(i.getValue().sys_id, set), ++count), i;
297 return count;
298 }
299
301
307 protected:
308 int deleteRecordsImpl(*hash<DataProviderExpression> where_cond, *hash<auto> search_options);
309 public:
310
311
313 protected:
314 updateSingleRecord(string id, hash<auto> set);
315 public:
316
317
319 protected:
320 deleteSingleRecord(string id);
321 public:
322
323
325 protected:
326 getRecordInfoIntern();
327 public:
328
329
331 private hash<DataProviderExpression> getEqualityComparisonExpression(int role, hash<DataProviderInfo> info, string key,
332 auto value) {
333 return <DataProviderExpression>{
334 "exp": info.expressions.eq,
335 "args": (<DataProviderFieldReference>{"field": key},) + value,
336 };
337 }
338};
339};
340
341 namespace Priv {
342hash<DataProviderExpressionInfo> sym(hash<DataProviderExpressionInfo> exp, string label);
343
344};
ServiceNowRestDataProvider::ServiceNowRestRecordIterator
Defines the record iterator class for Table-based iterators.
Definition: ServiceNowRestRecordIterator.qc.dox.h:28
ServiceNowRestDataProvider::ServiceNowTableDataProvider
The ServiceNowTableDataProvider data provider class.
Definition: ServiceNowTableDataProvider.qc.dox.h:46
ServiceNowRestDataProvider::ServiceNowTableDataProvider::SysColumns
const SysColumns
System columns.
Definition: ServiceNowTableDataProvider.qc.dox.h:62
ServiceNowRestDataProvider::ServiceNowTableDataProvider::getRecordInfoIntern
getRecordInfoIntern()
Retrieves the record type.
ServiceNowRestDataProvider::ServiceNowTableDataProvider::createRecordImpl
*hash< auto > createRecordImpl(hash< auto > rec, *hash< auto > create_options)
Creates the given record to the data provider.
ServiceNowRestDataProvider::ServiceNowTableDataProvider::meta
hash< auto > meta
Metadata description.
Definition: ServiceNowTableDataProvider.qc.dox.h:59
ServiceNowRestDataProvider::ServiceNowTableDataProvider::access
hash< auto > access
Access description.
Definition: ServiceNowTableDataProvider.qc.dox.h:56
ServiceNowRestDataProvider::ServiceNowTableDataProvider::deleteSingleRecord
deleteSingleRecord(string id)
deletes a single record
ServiceNowRestDataProvider::ServiceNowTableDataProvider::getEqualityComparisonExpression
private hash< DataProviderExpression > getEqualityComparisonExpression(int role, hash< DataProviderInfo > info, string key, auto value)
Returns an equality comparison expression.
Definition: ServiceNowTableDataProvider.qc.dox.h:331
ServiceNowRestDataProvider::ServiceNowTableDataProvider::updateSingleRecord
updateSingleRecord(string id, hash< auto > set)
updates a single record
ServiceNowRestDataProvider::ServiceNowTableDataProvider::uri_path
string uri_path
URI path prefix.
Definition: ServiceNowTableDataProvider.qc.dox.h:226
ServiceNowRestDataProvider::ServiceNowTableDataProvider::constructor
constructor(ServiceNowRestClient rest, string name, hash< auto > access, hash< auto > meta)
Creates the object from the arguments.
ServiceNowRestDataProvider::ServiceNowTableDataProvider::Expressions
const Expressions
Supported expressions.
Definition: ServiceNowTableDataProvider.qc.dox.h:86
ServiceNowRestDataProvider::ServiceNowTableDataProvider::name
string name
Current object name.
Definition: ServiceNowTableDataProvider.qc.dox.h:53
ServiceNowRestDataProvider::ServiceNowTableDataProvider::record_info
hash< ServiceNowRestRecordInfo > record_info()
Record info for the table.
ServiceNowRestDataProvider::ServiceNowTableDataProvider::searchRecordsImpl
private DataProvider::AbstractDataProviderRecordIterator searchRecordsImpl(*hash< auto > where_cond, *hash< auto > search_options)
Returns an iterator for zero or more records matching the search options.
Definition: ServiceNowTableDataProvider.qc.dox.h:253
ServiceNowRestDataProvider::ServiceNowTableDataProvider::getStaticInfoImpl
hash< DataProvider::DataProviderInfo > getStaticInfoImpl()
Returns data provider static info.
ServiceNowRestDataProvider::ServiceNowTableDataProvider::deleteRecordsImpl
int deleteRecordsImpl(*hash< DataProviderExpression > where_cond, *hash< auto > search_options)
Deletes zero or more records.
ServiceNowRestDataProvider::ServiceNowTableDataProvider::getName
string getName()
Returns the data provider name.
ServiceNowRestDataProvider::ServiceNowTableDataProvider::rest
ServiceNowRestClient::ServiceNowRestClient rest
The REST client object for API calls.
Definition: ServiceNowTableDataProvider.qc.dox.h:50
ServiceNowRestDataProvider::ServiceNowTableDataProvider::updateRecordsImpl
private int updateRecordsImpl(hash< auto > set, hash< DataProviderExpression > where_cond, *hash< auto > search_options)
Updates zero or more records matching the search options.
Definition: ServiceNowTableDataProvider.qc.dox.h:285
ServiceNowRestDataProvider::ServiceNowTableDataProvider::getDesc
string getDesc()
Returns the data provider description.
exp
number exp(number n)
ServiceNowRestDataProvider::QUERY_OP_ENDSWITH
const QUERY_OP_ENDSWITH
ends with operator
Definition: ServiceNowRestDataProviderDefs.qc.dox.h:50
ServiceNowRestDataProvider::QUERY_OP_STARTSWITH
const QUERY_OP_STARTSWITH
starts with operator
Definition: ServiceNowRestDataProviderDefs.qc.dox.h:55
ServiceNowRestDataProvider::QUERY_OP_IN
const QUERY_OP_IN
the Query "IN" operator for use in queries
Definition: ServiceNowRestDataProviderDefs.qc.dox.h:100
ServiceNowRestDataProvider::QUERY_OP_GE
const QUERY_OP_GE
the Query greater than or equals operator (>=) for use in queries
Definition: ServiceNowRestDataProviderDefs.qc.dox.h:75
ServiceNowRestDataProvider::QUERY_OP_NE
const QUERY_OP_NE
the Query not equals operator (!= or <>) for use in queries
Definition: ServiceNowRestDataProviderDefs.qc.dox.h:80
ServiceNowRestDataProvider::QUERY_OP_GT
const QUERY_OP_GT
the Query greater than operator (>) for use in queries
Definition: ServiceNowRestDataProviderDefs.qc.dox.h:70
ServiceNowRestDataProvider::QUERY_OP_LT
const QUERY_OP_LT
the Query less than (<) operator for use in queries
Definition: ServiceNowRestDataProviderDefs.qc.dox.h:60
ServiceNowRestDataProvider::QUERY_OP_LIKE
const QUERY_OP_LIKE
Definition: ServiceNowRestDataProviderDefs.qc.dox.h:40
ServiceNowRestDataProvider::QUERY_OP_LE
const QUERY_OP_LE
the Query less than or equals (<=) operator for use in queries
Definition: ServiceNowRestDataProviderDefs.qc.dox.h:65
ServiceNowRestDataProvider::QUERY_OP_EQ
const QUERY_OP_EQ
the Query equals operator (=) for use in queries
Definition: ServiceNowRestDataProviderDefs.qc.dox.h:85
ServiceNowRestDataProvider::QUERY_OP_ISNOTEMPTY
const QUERY_OP_ISNOTEMPTY
the Query "is not empty string" operator (ISNOTEMPTY) for use in queries
Definition: ServiceNowRestDataProviderDefs.qc.dox.h:95
ServiceNowRestDataProvider::QUERY_OP_NOTIN
const QUERY_OP_NOTIN
the Query "NOTIN" operator for use in queries
Definition: ServiceNowRestDataProviderDefs.qc.dox.h:105
ServiceNowRestDataProvider::QUERY_OP_NOTLIKE
const QUERY_OP_NOTLIKE
not like operator
Definition: ServiceNowRestDataProviderDefs.qc.dox.h:45
sprintf
string sprintf(string fmt,...)
ServiceNowRestDataProvider
Qore ServiceNowRestDataProvider module definition.
Definition: ServiceNowRestDataProvider.qc.dox.h:26
ServiceNowRestDataProvider::ServiceNowRestRecordInfo
hashdecl ServiceNowRestRecordInfo
contains ServiceNow object record information
Definition: ServiceNowTableDataProvider.qc.dox.h:28