Duplicating items is a very common development requirement. For some service artefacts, it is as simple as copy-and-paste; but for many it is not because they are associated and referenced via GUIDs and duplicating them would mean generation and right associations of the new GUIDs, or else they would override the source (from where the copy is created) artefacts.
Business Rules is an SAP Cloud Platform service falls under latter category – where each model of Enterprise Rules Model family has a unique ID assigned to them and these models are associated with each other, in their respective hierarchy, via these IDs. Every time you create a business rules project, or data object, rule-service, decision-table/text rule or ruleset – a new ID is generated and assigned to these models and then the respective ID is used for any reference like rule-service association with ruleset etc. When you delete the model, the reference is also deleted via these IDs.
In my day-to-day work, I have several requirements where I need to duplicate the template project for my workshops, or for creating different projects for different platforms with same base project, or for developing business rules for different use cases of same industry with changes in data objects or rules etc.
To avoid the need of creating the new business rules project every time, you now have a facility to copy the business rules project and make desired changes. Be it the changes to the attributes of data object or extending the existing business rules or upgrading business policies under new set of labels etc. This can be all be achieved from Copy APIs. The API is available in API Business Hub.
Few things to note:
- Copy API copies the entire project. It is not available of individual models
- Copy functionality is available only via APIs, not with tool (though it is in roadmap)
Let us now see how the copy API works:
In this example I have used API Business Hub, you can try the same with any other rest client or embed in your application. I will show you the API from the Neo environment but the same is valid for Cloud Foundry environment as well.
- Open SAP API Business Hub (api.sap.com)
- Navigate into Rule Authoring API for Neo environment
- Under the Projects category, you will see /copy/projects API
- Before we use this APIs, ensure that you have logged in and selected the API Environment where you want to run the API
- To select the API Environment, click on the Configure Environments
- Select the Starting URL which is nothing but the data center
- Enter any name of your choice for Display Name
- Set the provider and consumer account names (learn more)
- Finally give the Authentication (either Basic or OAuth 2.0)
- Don’t forget to Save the changes
- This API needs an XSRF Token if you are using Basic Authentication.
- Click on the XSRF Handling category on the left
- Click on the Try out link of the API
- Click on the Execute button to run the API
- If the call is successful, you will get the token. Copy the XSRF-token(hint: If the call in unsuccessful, check the provider or consumer name in the environment settings or confirm your username and password once again)
- Go back to the Copy API and click on the Try out link
- Enter the project ID – which is the ID of the business rules project you want to copy (hint: you can get the project ID from the business rules editor URL when you go into the project details)
- Enter the XSRF-Token copied from the previous API call
- Click on the Execute button
- You will see the response.
note: the response is a project JSON of the copied project. All the rule model IDs and their references have changed – which makes it’s a completely new project with a default project name as : <source-project-name><random-number>
For Example: BonusPlanExtensibilityTemplate1555988808534000
note: Copy API does not create the project in the repository. It just gives you the response of the duplicate project. You need to explicitly call an Import API (see next steps) to import the duplicate project into the repository.
- As mentioned earlier, the Copy API does not create or import the project. For this we need to next call the Import API. For that, carefully copy the entire JSON structure inside “Project”: tag (note: If you are coding, then you need to extract the element of the Project node)
(warning: do not copy ObjectMapping node)
- Open Export/Import category
- Click on /import/projects
- Click on Try out link
- Paste the project JSON in the body (warning: ensure that the JSON is valid)
- As this API also needs XSRF-Token if you have used Basic Authentication. So, call XSRF-Handling API to get the token and paste here.
- Click on the Execute button
- You will get the successful message in form the response body if the API call was executed without any issues.
- If you now open your Manage Rules Application aka Business Rules Editor, then you will see this new duplicate project
That’s it! That is how you duplicate business rules project in Neo and CF environments.