Skip to content

Generate text from an Accord Clause template when given data as input #1

@contractpendev

Description

@contractpendev

Hi ! Please read and understand what this file does before starting any task https://github.com/contractpendev/contractpen_node_client/blob/master/src/services/SetupClient.coffee and also better to read and understand the existing code base.
Refer to Accord Project https://www.accordproject.org/
Ergo API https://docs.accordproject.org/docs/ergo-api.html
Cicero API https://docs.accordproject.org/docs/cicero-api.html


If you are interested in the following technologies then there will be a series of tasks like this one. If your interested in Coffeescript, Legal Contracts on Accord Project https://www.accordproject.org/, eventually deployment to Blockchain. The first task starts small.

This project contractpen_node_client needs to be adjusted to add the function of generating text from a Accord Cicero template when given the data as input. This is done by using the Accord Cicero javascript API.

The task here is to create a new command so that when the following is typed at the dos prompt (or Linux or MacOSX prompt), it should then output the text of the Cicero template as filled with the input json files data. We assume a cicero project directory already exists with all the files downloaded.

What is a cicero project directory? It is for example the hello world template https://github.com/accordproject/cicero-template-library/tree/master/src/helloworld

run template <input json file> <directory of cicero project>

Let me given you an example.

run template datafile.json clauseprojectdirectoryforhelloworld

If in the above, datafile.json contains the data and clauseprojectdirectoryforhelloworld is a folder containing the NodeJS cicero project, then it should output the text of the template correctly with the data inserted into the template by using the Accord Project API's.

An example in coffeescript is given here. To explain, testLatePenaltyInput is the JSON input which you should read from , the directory is the and clause.generateText() generates the text which should then be outputted to the console.

Comedy = require 'comedy'
Awilix = require 'awilix'
Setup = require './Setup'

Template = require('@accordproject/cicero-core').Template
Clause = require('@accordproject/cicero-core').Clause
Engine = require('@accordproject/cicero-engine').Engine

# This function is NOT in use, just here for demonstration purpose
testClauseTemplate = ->
  testLatePenaltyInput = {
    "$class": "org.accordproject.latedeliveryandpenalty.LateDeliveryAndPenaltyClause",
    "forceMajeure": true,
    "penaltyDuration": {
        "$class": "org.accordproject.time.Duration",
        "amount": 537704789,
        "unit": "hours"
    },
    "penaltyPercentage": 160.789,
    "capPercentage": 63.475,
    "termination": {
        "$class": "org.accordproject.time.Duration",
        "amount": 4149649232,
        "unit": "minutes"
    },
    "fractionalPart": "seconds",
    "clauseId": "427c99b0-6df4-11e8-bb3b-67a2e79acc24"
  }

  template = await Template.fromDirectory('C:\\home\\projects\\ContractPen\\cicero-template-library\\src\\latedeliveryandpenalty')
  clause = new Clause(template)
  clause.setData testLatePenaltyInput
  n1 = clause.generateText()
  console.log n1

For example if this above example was adjusted for the Accord Cicero hello world template, it would be as follows. Note the clauseId is required.

testClauseTemplate = ->
  testLatePenaltyInput = {
    "$class": "org.accordproject.helloworld.HelloWorldClause",
    "name": "Philip",
    "clauseId": "427c99b0-6df4-11e8-bb3b-67a2e79acc24"
  }

  template = await Template.fromDirectory('C:\\home\\projects\\contractpen_node_client\\testcicerofolder')
  clause = new Clause(template)
  clause.setData testLatePenaltyInput
  n1 = clause.generateText()
  console.log n1

For me, this outputs the following which is what I expected, the template was filled with the data from the JSON.

C:\home\projects\contractpen_node_client>call npm run compile

> contractpen_node_client@1.0.0 compile C:\home\projects\contractpen_node_client
> coffee --compile src/

6:05:04 PM - info: Compiling Ergo logic
Name of the person to greet: "Philip". Thank you!

C:\home\projects\contractpen_node_client>

The task is to add a new command so that this text can be outputted to the console when the program is run from command line with parameters. You can see existing commands for example in

https://github.com/contractpendev/contractpen_node_client/blob/master/src/services/SetupClient.coffee

    program.usage('deploy <guid> <dir>').command('deploy <guid> <dir>').action (guid, directoryToCreate, cmd) =>

Check that the following are true.

  • 1. New command added so that can run from command line like
run template <input json file> <directory of cicero project>
  • 2. Given the input json data file and the template generates the text to console.

  • 3. Make sure that async await is used correctly so that all is done asynchronously without blocking.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requesthelp wantedExtra attention is needed

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions