Skip to content

Commit

Permalink
Reports REST API improvements. Add group details endpoint and documen…
Browse files Browse the repository at this point in the history
…tation #260
  • Loading branch information
dtaimanov committed Jun 18, 2020
1 parent 591ebb4 commit 6d26a91
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 3 deletions.
50 changes: 50 additions & 0 deletions modules/web/src/com/haulmont/reports/rest-api-swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ info:
* Getting list of avaliable reports
* Getting report metadata (parameters, templates)
* Getting report group details
* Execution of report
The Reports REST API is available at the URL `/rest/reports/v1` in the web module, e.g. `http://localhost:8080/app/rest/reports/v1/report`
Expand Down Expand Up @@ -40,6 +41,13 @@ parameters:
description: Report identifier
required: true
default: ""
groupIdParam:
name: groupId
in: path
type: string
description: Report Group identifier
required: true
default: ""
entityJsonParam:
name: entityJson
description: JSON object with the entity
Expand Down Expand Up @@ -72,6 +80,9 @@ definitions:
code:
type: string
description: Report code
group:
type: string
description: Group id

reportFull:
type: object
Expand All @@ -85,6 +96,9 @@ definitions:
code:
type: string
description: Report code
group:
type: string
description: Group id
inputParameters:
type: array
items:
Expand Down Expand Up @@ -119,6 +133,10 @@ definitions:
type: string
description: |
For ENUMERATION type there will be a java class for enumeration here
defaultValue:
type: string
description: |
Default value of parameter in string form
templates:
type: array
items:
Expand Down Expand Up @@ -160,6 +178,19 @@ definitions:
items:
type: string

group:
type: object
properties:
id:
type: string
description: Group id
title:
type: string
description: Group title
code:
type: string
description: Group code

################################################################################
# Tags #
################################################################################
Expand Down Expand Up @@ -228,6 +259,25 @@ paths:
schema:
$ref: '#/definitions/error'

/group/{groupId}:
parameters:
- $ref: '#/parameters/groupIdParam'
get:
tags:
- Group
summary: Get a single group by id
description: |
Gets a single group by identifier
responses:
200:
description: Success. The group is returned in the response body.
schema:
$ref: '#/definitions/group'
403:
description: Forbidden. The user doesn't have permissions to read the report
schema:
$ref: '#/definitions/error'

/run/{reportId}:
parameters:
- $ref: '#/parameters/reportIdParam'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ public String loadReport(@PathVariable String entityId) {
return controllerManager.loadReport(entityId);
}

@GetMapping(value = "/group/{entityId}")
public String loadGroup(@PathVariable String entityId){
return controllerManager.loadGroup(entityId);
}

@PostMapping(value = "/run/{entityId}")
public void runReport(@PathVariable String entityId,
@RequestBody(required = false) String body, HttpServletResponse response) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,30 @@ public class ReportRestControllerManager {
@Inject
protected ParameterClassResolver parameterClassResolver;

public String loadGroup(String entityId) {
checkCanReadEntity(metadata.getClassNN(ReportGroup.class));

LoadContext<ReportGroup> loadContext = new LoadContext<>(ReportGroup.class);
loadContext.setView(
new View(ReportGroup.class)
.addProperty("id")
.addProperty("title")
.addProperty("code"))
.setQueryString("select g from report$ReportGroup g where g.id = :id")
.setParameter("id", getIdFromString(entityId, metadata.getClassNN(ReportGroup.class)));

ReportGroup group = dataManager.load(loadContext);
checkEntityIsNotNull(metadata.getClassNN(ReportGroup.class).getName(), entityId, group);

GroupInfo info = new GroupInfo();
//noinspection ConstantConditions
info.id = group.getId().toString();
info.code = group.getCode();
info.title = group.getTitle();

return createGson().toJson(info);
}

public String loadReportsList() {
checkCanReadEntity(metadata.getClassNN(Report.class));

Expand Down Expand Up @@ -204,7 +228,7 @@ protected Object prepareValue(ReportInputParameter inputParam, ParameterValueInf
}

protected Class resolveDatatypeActualClass(ReportInputParameter inputParam) {
switch (inputParam.getType()){
switch (inputParam.getType()) {
case DATE:
return java.sql.Date.class;
case TIME:
Expand Down Expand Up @@ -263,13 +287,13 @@ protected InputParameterInfo mapInputParameterInfo(ReportInputParameter paramete
}

if (parameter.getDefaultValue() != null) {
inputParameterInfo.defaultValue = transformDefaultValue(parameter);
inputParameterInfo.defaultValue = transformDefaultValue(parameter);
}
return inputParameterInfo;
}

protected String transformDefaultValue(ReportInputParameter parameter) {
switch (parameter.getType()){
switch (parameter.getType()) {
case ENTITY:
EntityLoadInfo info = EntityLoadInfo.parse(parameter.getDefaultValue());
if (info != null) return info.getId().toString();
Expand Down Expand Up @@ -375,6 +399,12 @@ protected class ReportInfo {
protected List<InputParameterInfo> inputParameters;
}

protected static class GroupInfo {
protected String id;
protected String title;
protected String code;
}

protected static class TemplateInfo {
protected String code;
protected String outputType;
Expand Down

0 comments on commit 6d26a91

Please sign in to comment.