DominoVagrant / demo

Apache License 2.0
0 stars 3 forks source link

Script to Import Documents from JSON #15

Open JoelProminic opened 1 year ago

JoelProminic commented 1 year ago

I would like to be able to automate importing documents into databases on the demo server. Some uses:

I did some tests with Genesis, and I was able to import documents into a database based on JSON. The template is like this:

{ 
    "title": "Import documents", 
    "versionjson": "1.0.0", 
    "steps": [ 
        { 
            "title": "--- Import Documents ---", 
            "databases": [ 
                { 
                    "action": "update", 
                    "filePath": "%databaseName%", 
                    "documents":[
                        { 
                            "action": "create", 
                            "computeWithForm": true,
                            "items": {
                                "Form":"%formName%",
                                "%fieldName%":"%value%",
                                ...
                            }
                        },
                        ...
                    ]
                }
            ]
        }
    ]
}

I want to make a script that will work roughtly like this:

  1. Create a file in /local/dominodata/JavaAddin/Genesis/json with the JSON content
  2. The file will be processed automatically if Genesis is running
  3. Check for a corresponding response file with the same name in /local/dominodata/JavaAddin/Genesis/jsonreponse
    1. "OK" - Genesis considered the operation successful. I have noficed some problems for this case if the target database doesn't exist
    2. Any other value - the operation failed - report the error
    3. No file created within X seconds - report timeout and indicate that Genesis is probably not working

For the initial version, this will process a single file. Some future improvements:

JoelProminic commented 1 year ago

Removed Comment that was supposed to be on #14

JoelProminic commented 1 year ago

I have a working script for importing JSON.

Test Expected Actual
Valid JSON Documents created Confirmed
Invalid JSON Error detected by jq. Confirmed
Error on Genesis Side Detect an report error in JSON response Confirmed
Target database doesn't exist Report error from Genesis BUG: no error triggered

I did a practical test for #14 and found some limitations:

JoelProminic commented 1 year ago

I found a DateTime format example for the appConfiguration/documents/items/"<item-name>"/"value" property here here:

  • For type "text", must be either a single string or an array of strings.
  • For type "number", must be a single number or an array of numbers.
  • For type "datetime", must be a date and/or time in one of the following ISO-8601 formats, shown via examples, or an array of such values.
    • "20210728T162308,50-04" - 4 digit year, 2 digit month, 2 digit day, "T" delimiter, 2 digit hour, 2 digit minute, 2 digit second, comma delimiter, 2 digit hundredths of seconds, "+" or "-" delimiter for offset from Greenwich Mean Time, 2 digit hour timezone offset from GMT.
    • "20210728T162308,50-0330" - as above, followed by 2 digit minute timezone offset from GMT.
    • "20210728" - date only - 4 digit year, 2 digit month, 2 digit day.
    • "T162308,50" - time only - "T" delimiter, 2 digit hour, 2 digit minute, 2 digit second, comma delimiter, 2 digit hundredths of seconds.

The main difference I see compared to Moonshine-Domino-CRUD is the addition of "hundredths of seconds". I can test to see if this is required.

JoelProminic commented 1 year ago

To make a response, we can use the Java API: https://help.hcltechsw.com/dom_designer/12.0.0/basic/H_MAKERESPONSE_METHOD_JAVA.html We'll still need a way to lookup the existing document, though.