Skip to content

Commit 2e350f0

Browse files
committed
12.8.4 Release
1 parent 58e6a57 commit 2e350f0

File tree

1 file changed

+101
-0
lines changed

1 file changed

+101
-0
lines changed

darest/get_vstdata.p

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
/*************************************************************/
2+
/* Copyright (c) 2024 by progress Software Corporation */
3+
/* all rights reserved. no part of this program or document */
4+
/* may be reproduced in any form or by any means without */
5+
/* permission in writing from progress Software Corporation. */
6+
/*************************************************************/
7+
/*------------------------------------------------------------------------
8+
File : get_vstdata.p
9+
10+
Description : Dump VST table(s) data into a JSON
11+
12+
Author(s) : tmasood
13+
Created : Tue Aug 13 10:34:45 IST 2024
14+
Notes :
15+
----------------------------------------------------------------------*/
16+
17+
routine-level on error undo, throw.
18+
19+
using Progress.Lang.*.
20+
using OpenEdge.DataAdmin.Rest.RestService from propath.
21+
using OpenEdge.DataAdmin.Rest.IRestRequest from propath.
22+
using OpenEdge.DataAdmin.Error.NotFoundError from propath.
23+
using OpenEdge.DataAdmin.Error.DataAdminErrorHandler from propath.
24+
using OpenEdge.DataAdmin.Error.UnsupportedOperationError from propath.
25+
26+
{darest/restbase.i get vstdata}
27+
28+
procedure Execute:
29+
define input parameter restRequest as IRestRequest no-undo.
30+
/* *************************** Definitions ************************** */
31+
32+
define variable service as RestService no-undo.
33+
define variable errorHandler as DataAdminErrorHandler no-undo.
34+
define variable tthdl as handle no-undo.
35+
define variable bConnecthdl as handle no-undo.
36+
define variable btthdl as handle no-undo.
37+
define variable cTableName as character no-undo.
38+
define variable lRetVal as logical no-undo.
39+
define variable cOutputFile as character no-undo.
40+
/* *************************** Main Block *************************** */
41+
restRequest:Validate().
42+
service = new RestService(restRequest:ConnectionName).
43+
service:URL = restRequest:ConnectionUrl.
44+
cTableName = if restRequest:KeyValue[1] > "" then restRequest:KeyValue[1] else "" .
45+
46+
case cTableName:
47+
// Moving forward we can add more tables under the CASE statement
48+
when "_Connect" then do:
49+
/* Get VST table handle */
50+
bConnecthdl = BUFFER _Connect:HANDLE.
51+
/* Create an empty, undefined TEMP-TABLE */
52+
CREATE TEMP-TABLE tthdl.
53+
/* Give it _Connect table's fields & indexes */
54+
tthdl:CREATE-LIKE(bConnecthdl).
55+
tthdl:SERIALIZE-NAME = "_Connect".
56+
tthdl:TEMP-TABLE-PREPARE("ttConnect").
57+
/* Get the buffer handle for the temp-table */
58+
btthdl = tthdl:DEFAULT-BUFFER-HANDLE.
59+
60+
// Populate the temp-table buffer with data
61+
for each _connect no-lock:
62+
btthdl:BUFFER-CREATE.
63+
btthdl:BUFFER-COPY(bConnecthdl).
64+
end.
65+
// make sure the output filename is provided
66+
if INDEX(restRequest:OutFileName, ".json") = 0 then
67+
cOutputFile = cTableName + ".json".
68+
else
69+
cOutputFile = restRequest:OutFileName.
70+
// Write the temp-table to JSON and capture any error, if occured
71+
lRetVal = btthdl:WRITE-JSON("file", cOutputFile, TRUE) NO-ERROR.
72+
if ERROR-STATUS:ERROR and ERROR-STATUS:NUM-MESSAGES > 0 then
73+
undo, throw new NotFoundError("Error occurred: '" + ERROR-STATUS:GET-MESSAGE(1)).
74+
75+
if not lRetVal then
76+
undo, throw new NotFoundError(substitute("Unable to write JSON output file: &1", cOutputFile)).
77+
end.
78+
otherwise do:
79+
if cTableName = "" then
80+
undo, throw new NotFoundError("VST name cannot be blank. Please enter valid VST name in URL.").
81+
else
82+
undo, throw new NotFoundError("VST name not found. Please enter valid VST name in URL.").
83+
end.
84+
85+
end case.
86+
87+
catch e as Progress.Lang.Error :
88+
if session:batch-mode then
89+
errorHandler = new DataAdminErrorHandler(restRequest:ErrorFileName).
90+
else
91+
errorHandler = new DataAdminErrorHandler().
92+
errorHandler:Error(e).
93+
end catch.
94+
finally:
95+
delete object service no-error.
96+
if valid-handle(btthdl) then
97+
btthdl:BUFFER-RELEASE().
98+
delete object tthdl no-error.
99+
end finally.
100+
101+
end.

0 commit comments

Comments
 (0)