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