OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
baseline api: adding api documentation
Sebastian Fiedlschusterf4585baa3f71
diff --git a/docs/api/apiv3/openapi-spec.yml b/docs/api/apiv3/openapi-spec.ymlindex c06bee43470..c0c7260152b 100644--- a/docs/api/apiv3/openapi-spec.yml+++ b/docs/api/apiv3/openapi-spec.yml@@ -840,6 +840,7 @@ tags:- "$ref": "./tags/basic_objects.yml"- "$ref": "./tags/collections.yml"- "$ref": "./tags/filters.yml"+ - "$ref": "./tags/baseline_comparisons.yml"- "$ref": "./tags/forms.yml"- "$ref": "./tags/signaling.yml"- "$ref": "./tags/actions_and_capabilities.yml"diff --git a/docs/api/apiv3/paths/work_package.yml b/docs/api/apiv3/paths/work_package.ymlindex 29f41efb00e..64e5b06451a 100644--- a/docs/api/apiv3/paths/work_package.yml+++ b/docs/api/apiv3/paths/work_package.yml@@ -71,6 +71,17 @@ get:schema:type: integerexample: 1+ - description: |-+ In order to perform a [baseline comparison](/docs/api/baseline_comparisons) of the work-package attributes, you may+ provide one or several timestamps in ISO-8601 format as comma-separated list. The timestamps may be absolute or relative.+ Usually, the first timestamp is the baseline date, the last timestamp is the current date.+ in: path+ name: timestamps+ required: false+ schema:+ default: PT0S+ type: string+ example: '2022-01-01T00:00:00Z,PT0S'responses:'200':content:diff --git a/docs/api/apiv3/paths/work_packages.yml b/docs/api/apiv3/paths/work_packages.ymlindex f45f79f1821..c5542bc4cb1 100644--- a/docs/api/apiv3/paths/work_packages.yml+++ b/docs/api/apiv3/paths/work_packages.yml@@ -124,6 +124,17 @@ get:required: falseschema:type: string+ - description: |-+ In order to perform a [baseline comparison](/docs/api/baseline_comparisons), you may provide one or several timestamps+ in ISO-8601 format as comma-separated list. The timestamps may be absolute or relative. Usually, the first timestamp+ is the baseline date, the last timestamp is the current date.+ example: '2022-01-01T00:00:00Z,PT0S'+ in: query+ name: timestamps+ required: false+ schema:+ default: PT0S+ type: stringresponses:'200':description: OKdiff --git a/docs/api/apiv3/tags/baseline_comparisons.yml b/docs/api/apiv3/tags/baseline_comparisons.ymlnew file mode 100644index 00000000000..a3a34dfe971--- /dev/null+++ b/docs/api/apiv3/tags/baseline_comparisons.yml@@ -0,0 +1,245 @@+---+description: |-+ Baseline comparisons allow to compare work packages or collections of work packages with respect to different points in time.++ This helps to answer questions like:++ - Which work packages match a certain set of filters today, which work packages match this set of filters at a certain earlier point in time?+ - Which properties of these work packages have changed with respect to these points in time?++ This tool can be used to analyze how a project plan has changed with respect to a certain baseline date.++ ## Retrieve Work Packages for Different Timestamps++ The work-packages API supports a `timestamps` parameter to gather information about a single work package or a collection work packages for several points in time.++ ```+ GET /api/v3/work_packages?timestamps=2022-01-01T00:00:00Z,PT0S++ GET /api/v3/work_packages/123?timestamps=2022-01-01T00:00:00Z,PT0S+ ```++ Each timestamp should be given as [ISO-8601](https://en.wikipedia.org/wiki/ISO_8601) string, either as absolute date and time with timezone, e.g. `"2022-01-01T00:00:00Z"`, or as relative timestamp utilizing the [ISO-8601-Duration](https://en.wikipedia.org/wiki/ISO_8601#Durations) format, e.g. `"P-1Y"`, which is composed of an initial `"P"` for "Period", and a duration. `"P-1Y"` is interpreted as the relative timestamp "1 year ago".++ Several timestamps should be passed as comma-separated list of these ISO-8601 strings to the `timestamps` parameter.++ The timestamps should be given in ascending temporal order, such that the first timestamp is the **baseline** timestamp, and the last timestamp is the **current** timestamp.++ The information of the work packages at the different `timestamps` is returned in the `"_embedded"` section `"attributesByTimestamp"`.++ ```json+ // /api/v3/work_packages?timestamps=2022-01-01T00:00:00Z,PT0S+ {+ "_type": "WorkPackageCollection",+ "total": 1,+ "_embedded": {+ "elements": [+ {+ "_type": "WorkPackage",+ "id": 1528,+ "subject": "Current subject of the work package",+ // other attributes ...,+ "_links": {+ "self": {+ "href": "/api/v3/work_packages/1528?timestamps=2022-01-01T00:00:00Z,PT0S"+ }+ },+ "_meta": {+ "matchesFilters": true,+ "exists": true,+ "timestamp": "PT0S"+ },+ "_embedded": {+ "attributesByTimestamp": [+ {+ "subject": "Original subject of the work package",+ "_meta": {+ "matchesFilters": true,+ "exists": true,+ "timestamp": "2022-01-01T00:00:00Z"+ },+ "_links": {+ "self": {+ "href": "/api/v3/work_packages/1528?timestamps=2022-01-01T00:00:00Z"+ }+ },+ },+ {+ "_meta": {+ "matchesFilters": true,+ "exists": true,+ "timestamp": "PT0S"+ },+ "_links": {+ "self": {+ "href": "/api/v3/work_packages/1528?timestamps=PT0S"+ }+ }+ }+ ],+ }+ }+ ]+ },+ "_links": {+ "self": {+ "href": "/api/v3/work_packages?timestamps=2022-01-01T00:00:00Z,PT0S"+ }+ }+ }+ ```++ ## Filter Matching++ The work-packages API supports filtering the query results by one or several search criteria. See: [Filters](../filters)++ To find out whether a work package matches the given set of filter criteria, check `"matchesFilters"` in the `"_meta"` section for each timestamp:++ ```json+ // /api/v3/work_packages?filters=...×tamps=2022-01-01T00:00:00Z,PT0S+ {+ "_type": "WorkPackageCollection",+ "_embedded": {+ "elements": [+ {+ "_type": "WorkPackage",+ "_embedded": {+ "attributesByTimestamp": [+ {+ "_meta": {+ "matchesFilters": false,+ "timestamp": "2022-01-01T00:00:00Z"+ }+ },+ {+ "_meta": {+ "matchesFilters": true,+ "timestamp": "PT0S"+ }+ }+ ],+ }+ }+ ]+ }+ }+ ```++ In the above example, the work package matches the filter criteria at the timestamp `"PT0S"`, but does not match the filter criteria at the timestamp `"2022-01-01T00:00:00Z"`. The work package is included in the returned collection because it matches the filter criteria at least at one of the given timestamps.++ ## Existence++ To find out whether a work package has existed at the given timestamps, check `"exists"` in the `"_meta"` section for each timestamp:++ ```json+ // /api/v3/work_packages?timestamps=2022-01-01T00:00:00Z,PT0S+ {+ "_type": "WorkPackageCollection",+ "_embedded": {+ "elements": [+ {+ "_type": "WorkPackage",+ "_embedded": {+ "attributesByTimestamp": [+ {+ "_meta": {+ "exists": false,+ "timestamp": "2022-01-01T00:00:00Z"+ }+ },+ {+ "_meta": {+ "exists": true,+ "timestamp": "PT0S"+ }+ }+ ],+ }+ }+ ]+ }+ }+ ```++ In the above example, the work package exists at the timestamp `"PT0S"`, but has not existed at the timestamp `"2022-01-01T00:00:00Z"`. The work package is included in the returned collection because it has existed at least at one of the given timestamps.++ ## Attributes++ To read out the attributes of the work packages at the current timestamp (the last of the given `timestamps`), check the attributes of the work-package objects. To read out the attributes of the work packages at the other given timestamps, check the attributes within `"_embedded"` section `"attributesAtTimestamp"`.++ To save bandwidth, only attributes that differ from the ones in the main work-package object are included in the `"attributesByTimestamp"`. Attributes with the same value as in the main work-package object are not included in the `"attributesByTimestamp"` section.++ ```json+ // /api/v3/work_packages?timestamps=2022-01-01T00:00:00Z,PT0S+ {+ "_type": "WorkPackageCollection",+ "_embedded": {+ "elements": [+ {+ "_type": "WorkPackage",+ "subject": "Current subject of the work package",+ "_meta": {+ "timestamp": "PT0S"+ },+ "_embedded": {+ "attributesByTimestamp": [+ {+ "subject": "Original subject of the work package",+ "_meta": {+ "timestamp": "2022-01-01T00:00:00Z"+ }+ },+ {+ "_meta": {+ "timestamp": "PT0S"+ }+ }+ ],+ }+ }+ ]+ }+ }+ ```++ In the above example, the last of the given `timestamps` is `"PT0S"` (which means 0 seconds ago, i.e. now). The work-package attributes at this time are included in the main work-package object. The `"subject"` of the work package at the timestamp `"PT0S"` (now) is `"Current subject of the work package"`.++ The `"_embedded"` section `"attributesByTimestamp"` has an array entry for the timestamp `"PT0S"`, which is the last array entry. Because the value of the `"subject"` is the same as up in the main work-package object, the `"subject"` attribute is left out in the `"attributesByTimestamp"` for the timestamp `"PT0S"`. The `"subject"` of the work package at the timestamp `"PT0S"` (now) is `"Current subject of the work package"`.++ The `"_embedded"` section `"attributesByTimestamp"` has an array entry for the baseline timestamp `"2022-01-01T00:00:00Z"`, which is the first array entry. The `"subject"` of the work package at the timestamp `"2022-01-01T00:00:00Z"` is `"Original subject of the work package"`. It is included in the `"attributesByTimestamp"` for the timestamp `"2022-01-01T00:00:00Z"` because it differs from the `"subject"` in the main work-package object, which is `"Current subject of the work package"`.++ ## Usage Example++ In this example ruby script, the work packages are retrieved at a baseline date and in their current state. Then the subject of the first work package is compared with respect to the baseline date and the current state.++ ```ruby+ # Define timestamps+ baseline_timestamp = "2022-01-01T00:00:00Z"+ current_timestamp = "PT0S"+ timestamps = [baseline_timestamp, current_timestamp]++ # Retrieve work packages+ url = "https://community.openproject.org/api/v3/work_packages?timestamps=#{timestamps.join(',')}"+ response = JSON.parse(RestClient.get(url), object_class: OpenStruct)+ work_packages = response.dig("_embedded", "elements")++ # Extract differing baseline attributes+ work_package = work_packages.first+ baseline_attributes = work_package.dig("_embedded", "attributesByTimestamp").first++ # Compare baseline state to current state of the work package+ if baseline_attributes.subject.present? and baseline_attributes.subject != work_package.subject+ puts "The subject of the work package has changed."+ puts "Subject at the baseline time: #{baseline_attributes.subject}"+ puts "Current subject: #{work_package.subject}"+ end++ # Check existence+ puts "The work package did exist at the baseline time." if baseline_attributes.dig("_meta", "exists")+ puts "The work package exists at the current time." if work_package.dig("_meta", "exists")++ # Check filter matching+ puts "The work package matches the query filters at the baseline time." if baseline_attributes.dig("_meta", "matchesFilters")+ puts "The work package matches the query filters at the current time." if work_package.dig("_meta", "matchesFilters")+ ```+name: Baseline Comparisons