Use the APIs to clone a project and replace files
Using the Rigi APIs, you can create multiple projects that contain different files but have the same settings. This can be handy if you need to create similar Rigi projects regularly, for example, when you build a Rigi connector for one of the following systems:
E-commerce systems (ECS).
Product information management systems (PIM).
Content management systems (CMS).
The API documentation is available on <yourserver>.rigi.io/api-docs/
.
To create a new project based on a template, we will clone a project from a project named ‘Template,’ give it a new name (PROJECT_NAME), upload a new set of source files, approve the workspace, and synchronize the string list.
Make sure that no project with the name PROJECT_NAME already exists:
API:
GET /api/projects/names?name=PROJECT_NAME
.The return value of this endpoint is an object with the key "exists" of type Boolean.
Clone a template project:
Initiate the full clone of a project:
API:
POST /api/projects/clone?full-true
.After you initiate a project's clone, you must wait until its completion.
Keep it small!
If the source project is a template, ensure its size is as limited as possible.
To copy parser settings, the source project must have at least one file with the required parser settings. Use a small file in the source project, for example, with only one source string
Check the status of the cloning operation:
API:
GET api/projects/actions?name=PROJECT_NAME
.This endpoint provides insight into the project status. It returns an object with the project ID, project name, and operation status details.
{ "projectId": "12345", "name": "PROJECT_NAME", "details": { "projectCloneStatus": "1", "workspaceFilesStatus": "1", "workspaceApproveStatus": "1", "workspaceMergeStatus": "1" } }
The status values can be:
"0”: the operation is still in progress.
"1”: the operation is ready.
"2”: there is an error.
Cloning a smaller project can take about 10 seconds. Poll the
projectCloneStatus
each second and wait until the operation is ready.while (true) { wait 1 second get project status if (projectCloneStatus == "1") return READY else if (projectCloneStatus == "2") return ERROR }
Upload a new set of files to the workspace:
Create a manifest file based on files that are going to be uploaded.
The manifest file (manifest.json) is located at the root of the ZIP file that will be uploaded. The manifest contains the following fields:
Table 16.Field
Required
Description
filepath
Required
Relative file path in the ZIP file, for example,
abc\def\myfile.json
.parserId
Required
Parser ID. You can find it in the parser settings of your source project, for example,
json
. For details, see the Configure parser settings guide.targetRule
Optional
Name of the target rule that shall be applied for this file. If no target rule is specified, the rule assigned to the first file with this extension in the template project will be used.
fileId
Optional
File identifier that will be assigned to this file:
If no file ID is specified and the template project contains a file with the same name, this file ID is used.
If no file ID is specified and the template project does not contain a file with the same name, the system will auto-create a file ID.
Create a ZIP file containing the manifest file and project files.
Example 22.In this example, the manifest file is:
[ { "filepath": "en-CA.json", "parserId": "json", "targetRule": null, "fileId": null }, { "filepath": "hello.json", "parserId": "json", "targetRule": null, "fileId": null }, { "filepath": "nl-NL.json", "parserId": "json", "targetRule": null, "fileId": null } ]
The
workspaceFilesStatus
should be ready ("1") at this moment to be sure that no uploads are happening right now.Prepare the upload (set
workspaceFilesStatus
to 'in progress' ("0")):In the same way we have waited until the project cloning was completed, we must now wait until all files are processed. Some time passes between uploading the ZIP file and when the server starts processing it. We need to mark the
workspaceFilesStatus
as ‘in progress’ ("0") to detect when the server has processed the ZIP.API:
POST /api/projects/{id}/actions
Body:
{ "workspaceFilesStatus" : "0" }
Upload the ZIP file:
API:
POST api/projects/{id}/workspaces/files
.This operation uploads a ZIP file to the workspace. The Rigi server will add the files defined in the workspace to the project.
Wait until the upload is completed (e.g.,
workspaceFilesStatus == ready ("1")
):while (true) { wait 1 second get project status if (workspaceFilesStatus == "1") return READY else if (workspaceFilesStatus == "2") return ERROR }
This operation can take a while.
Approve the workspace:
API:
POST api/projects/{id}/workspaces/files/approve
.Wait until the approval is completed (e.g.,
workspaceApproveStatus== ready ("1")
):while (true) { wait 1 second get project status if (workspaceApproveStatus== "1") return READY else if (workspaceFilesStatus == "2") return ERROR }
Synchronize the string list. This will update the string list with the files uploaded and assigned to the project.
API:
PUT api/projects/{id}/workspaces/merge
.Wait until the synchronization is completed (e.g.,
workspaceMergeStatus== ready ("1")
):while (true) { wait 1 second get project status if (workspaceMergeStatus== "1") return READY else if (workspaceMergeStatus== "2") return ERROR }