Skip to content

Commit

Permalink
Rewrite document service:
Browse files Browse the repository at this point in the history
- Remove dependency on external document service
- Simplify support for custom fonts
- Honour permissions on subreports
- Optionally support basic auth
  • Loading branch information
manisandro committed Sep 9, 2024
1 parent a9a8ed1 commit 739eb66
Show file tree
Hide file tree
Showing 11 changed files with 629 additions and 105 deletions.
11 changes: 7 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
FROM sourcepole/qwc-uwsgi-base:alpine-v2023.10.26

ADD requirements.txt /srv/qwc_service/requirements.txt
ADD libs.txt /srv/qwc_service/libs.txt

# git: Required for pip with git repos
# postgresql-dev g++ python3-dev: Required for psycopg2
RUN \
apk add --no-cache --update --virtual runtime-deps postgresql-libs && \
apk add --no-cache --update --virtual build-deps git postgresql-dev g++ python3-dev && \
apk add --no-cache --update --virtual runtime-deps postgresql-libs openjdk17-jdk openjdk17-jre ttf-dejavu && \
apk add --no-cache --update --virtual build-deps postgresql-dev g++ python3-dev && \
pip3 install --no-cache-dir -r /srv/qwc_service/requirements.txt && \
mkdir /srv/qwc_service/libs && \
mkdir /srv/qwc_service/fonts && \
while IFS= read -r url; do if [ -n "$url" ]; then wget -P /srv/qwc_service/libs "$url"; fi; done < /srv/qwc_service/libs.txt && \
apk del build-deps

ADD src /srv/qwc_service/

ENV LD_LIBRARY_PATH=/usr/lib/jvm/java-17-openjdk/lib/server
ENV SERVICE_MOUNTPOINT=/api/v1/document
52 changes: 37 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,44 @@ Document service

The document service delivers reports from the Jasper reporting service with permission control.

Report source files (`*.jrxml`) must be placed below the `report_dir` (see config below).

Dependencies
------------
The reports are then referenced by their template name, which corresponds to their path below `report_dir`, without extension.

For instance `report_dir` is `/path/to/report/dir`, then the template name for

/path/to/report/dir/topic/myreport.jrxml

is `topic/myreport`.

The request format is

http://localhost:5018/<template>.<ext>?<key>=<value>&...

where

* `ext` is a supported report format (`pdf`, `html`, `csv`, `docx`, `ods`, `odt`, `pptx`, `rtf`, `xlsx`, `xml`). If not specified, `pdf` is assumed.
* Query KVPs are passed to the Jasper as report parameters.

Example request:

* [Jasper reporting service](https://github.com/qwc-services/jasper-reporting-service/)
http://localhost:5018/topic/myreport.pdf?FEATURE_ID=1

If your report uses a PostgresSQL data adapter, use the name of the desired PG service connection as data adapter name in the report, and the connection will be automatically looked up from the `pg_service.conf` file. Alternatively, you can set the name of the desired PG service connection as `datasource` of in the service resource configuration, see below.

If your report includes external resources (i.e. images), place these below the `report_dir` and, add a `REPORT_DIR` parameter of type `java.lang.String` in the `.jrxml` and use `$P{REPORT_DIR}` in the resource location expression, for example:

$P{REPORT_DIR} + "mysubfolder/myimage.png"

If your report requires extra fonts, place the `*.ttfs` below the `src/fonts` directory (when running locally) resp. mount them inside the `/srv/qwc_service/fonts/` when running as docker container. Font names must respect the following naming convention:

- Regular: `<FontName>.ttf` or `<FontName>-Regular.ttf`
- Bold: `<FontName>-Bold.ttf`
- Italic: `<FontName>-Italic.ttf`
- BoldItalic: `<FontName>-BoldItalic.ttf`


Set `FLASK_DEBUG=1` to get additional logging output.

Configuration
-------------
Expand All @@ -30,14 +62,13 @@ Example:
"$schema": "https://raw.githubusercontent.com/qwc-services/qwc-document-service/master/schemas/qwc-document-service.json",
"service": "document",
"config": {
"jasper_service_url": "http://localhost:8002/reports",
"jasper_timeout": 60
"report_dir": "/path/to/report/dir"
},
"resources": {
"document_templates": [
{
"template": "demo",
"report_filename": "PieChartReport"
"datasource": "<pgservice_name>"
}
]
}
Expand All @@ -48,13 +79,6 @@ Example:

Config options in the config file can be overridden by equivalent uppercase environment variables.

Environment variables:

| Variable | Description | Default value |
|----------------------|----------------------------|-------------------------------|
| `JASPER_SERVICE_URL` | Jasper Reports service URL | http://localhost:8002/reports |
| `JASPER_TIMEOUT` | Timeout (s) | 60 |

### Permissions

- [JSON schema](https://github.com/qwc-services/qwc-services-core/blob/master/schemas/qwc-services-permissions.json)
Expand Down Expand Up @@ -123,8 +147,6 @@ The format of the report is extracted from the template name, i.e.

If no extension is present in the template name, PDF is used as format.

See also jasper-reporting-service README.

Docker usage
------------

Expand Down
9 changes: 9 additions & 0 deletions libs.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
https://repo1.maven.org/maven2/commons-beanutils/commons-beanutils/1.9.4/commons-beanutils-1.9.4.jar
https://repo1.maven.org/maven2/org/apache/commons/commons-collections4/4.5.0-M2/commons-collections4-4.5.0-M2.jar
https://repo1.maven.org/maven2/commons-digester/commons-digester/2.1/commons-digester-2.1.jar
https://repo1.maven.org/maven2/commons-logging/commons-logging/1.3.4/commons-logging-1.3.4.jar
https://repo1.maven.org/maven2/net/sf/jasperreports/jasperreports/6.21.3/jasperreports-6.21.3.jar
https://jaspersoft.jfrog.io/artifactory/third-party-ce-artifacts/com/github/librepdf/openpdf/1.3.30.jaspersoft.3/openpdf-1.3.30.jaspersoft.3.jar
https://repo1.maven.org/maven2/org/postgresql/postgresql/42.7.4/postgresql-42.7.4.jar


1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ Flask-JWT-Extended==4.6.0
flask-restx==1.3.0
requests==2.32.0
qwc-services-core==1.3.30
JPype1==1.5.0
19 changes: 11 additions & 8 deletions schemas/qwc-document-service.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,17 @@
"title": "Config options",
"type": "object",
"properties": {
"jasper_service_url": {
"description": "Jasper Reporting service URL for generating reports. Example: http://localhost:8002/reports",
"type": "string"
"basic_auth_login_url": {
"description": "Login verification URL for requests with basic auth. Example: http://qwc-auth-service:9090/verify_login",
"type": "array",
"items": {
"type": "string"
}
},
"jasper_timeout": {
"description": "Timeout for requests forwarded to Jasper Reporting service",
"type": "integer",
"default": 60
"report_dir": {
"description": "Directory which contains reports.",
"type": "string",
"default": "/reports"
}
},
"required": [
Expand Down Expand Up @@ -67,4 +70,4 @@
"config",
"resources"
]
}
}
Loading

0 comments on commit 739eb66

Please sign in to comment.