Skip to content

Commit 232a235

Browse files
author
TanyaEf
committed
Fixed SettingsServiceTest
2 parents 32fe62b + 1d8d87f commit 232a235

File tree

22 files changed

+250
-386
lines changed

22 files changed

+250
-386
lines changed

README.md

Lines changed: 77 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@ Table of Contents
1010
* [Loading configuration from file](#loading-configuration-from-file).
1111
* [Creation of manual configuration](#creation-of-manual-configuration).
1212
* [HTTPS configuration](#https-configuration).
13+
* [X-HTTP-Method override](#x-http-method-override).
1314
* [Client instantiation](#client-instantiation).
1415
3. [Authentication](#authentication).
16+
* [Anonymous session](#anonymous-session).
1517
* [Invalidating session](#invalidating-session).
1618
4. [Report services](#report-services).
1719
* [Running a report](#running-a-report).
@@ -58,7 +60,7 @@ Table of Contents
5860
* [Setting Role Membership](#setting-role-membership).
5961
* [Deleting a Role](#deleting-a-role).
6062
5. [The Settings Service](#settings-service).
61-
* [Getting server specific settings](#getting-settings).
63+
* [Getting server specific settings](#getting-server-specific-settings).
6264
7. [Repository Services](#repository-services).
6365
1. [Resources Service](#resources-service).
6466
* [Searching the Repository](#searching-the-repository).
@@ -150,6 +152,12 @@ TrustManager[] trustManagers = new TrustManager[1];
150152
trustManagers[0] = x509TrustManager;
151153
configuration.setTrustManagers(trustManagers);
152154
```
155+
####X-HTTP-Method override
156+
To avoid situation, when your proxies or web services do not support arbitrary HTTP methods or newer HTTP methods, you can use “restricted mode”. In this mode `JaperserverRestClient` sends requests through POST method and set the `X-HTTP-Method-Override` header with value of intended HTTP method. To use this mode you should set flag `RestrictedHttpMethods`:
157+
```java
158+
session.getStorage().getConfiguration().setRestrictedHttpMethods(true);
159+
```
160+
If you do not use the "restricted mode", POST or GET methods and server returns the response with 411 error code, `JaperserverRestClient` resend this request through POST method with the X-HTTP-Method-Override header automatically.
153161
####Client instantiation:
154162
Here everything is easy, you need just to pass `configuration` to `JasperserverRestClient` constructor.
155163
```java
@@ -164,6 +172,11 @@ Session session = client.authenticate("jasperadmin", "jasperadmin");
164172
//authentication with multitenancy enabled
165173
Session session = client.authenticate("jasperadmin|organization_1", "jasperadmin");
166174
```
175+
###Anonymous session
176+
For some Jasperserver services authentication is not required (for example, settings service and server info service), so you can use anonymous session:
177+
```java
178+
AnonymousSession session = client.getAnonymousSession();
179+
```
167180
####Invalidating session
168181
Not to store session on server you can invalidate it with `logout()` method.
169182
```java
@@ -191,6 +204,19 @@ OperationResult<InputStream> result = client
191204
.run();
192205
InputStream report = result.getEntity();
193206
```
207+
Also you can use this method to run report with several values for the same parameter. In this case new values of the parameter are added to the previous ones (new values do not replace previous values of the parameter):
208+
```java
209+
OperationResult<InputStream> result = client
210+
.authenticate("superuser", "superuser")
211+
.reportingService()
212+
.report("/reports/samples/Cascading_multi_select_report")
213+
.prepareForRun(ReportOutputFormat.PDF, 1)
214+
.parameter("Cascading_state_multi_select", "CA")
215+
.parameter("Cascading_state_multi_select", "OR", "WA")
216+
.parameter("Cascading_name_single_select", "Adams-Steen Transportation Holdings")
217+
.parameter("Country_multi_select", "USA")
218+
.run();
219+
```
194220
In this mode you don't need to work in one session. In the above code we specified report URI, format in which we want to get a report and some report parameters. As we a result we got `InputStream` instance. In synchronous mode as a response you get a report itself while in asynchronous you get just a descriptor with report ID which you can use to download report afer it will be ready.
195221

196222
In order to run a report in asynchronous mode, you need firstly build `ReportExecutionRequest` instance and specify all the parameters needed to launch a report. The response from the server is the `ReportExecutionDescriptor` instance which contains the request ID needed to track the execution until completion and others report parameters. Here's the code to run a report:
@@ -391,7 +417,8 @@ To create an organization, put all information in an organization descriptor, an
391417
```java
392418
Organization organization = new Organization();
393419
organization.setAlias("myOrg1");
394-
420+
```
421+
``java
395422
OperationResult<Organization> result = session
396423
.organizationsService()
397424
.organizations()
@@ -831,18 +858,25 @@ Settings Service
831858

832859
It provides method that allow you to get server specific settings, required by UI to work with the server in sync. There can be formats and patterns, modes for some modules etc.
833860

834-
####Getting settings
835-
To get settings, use the `getEntity()` method and specify the group of settings in the `group()` method. The method `getEntity()` returns map of settings where the keys in the map are names of the settings and values can be any objects.
836-
861+
####Getting server specific settings
862+
To get settings, use the `getEntity()` method and specify the group of settings in the `group()` method and class of entity as shown below. The method `getEntity()` returns instance of specified class:
837863
```java
838864
final Map settings = session
839865
.settingsService()
840866
.settings()
841-
.group(group)
867+
.group(group, Map.class)
842868
.getEntity();
843869

844870
```
845-
Supported groups are:
871+
Please notice, you can get settings of user’s time zones in this way as List only:
872+
```java
873+
final List settings = session
874+
.settingsService()
875+
.settings()
876+
.group("userTimeZones", List.class)
877+
.getEntity();
878+
```
879+
Supported groups of settings are:
846880

847881
1. “request”. Settings related to current AJAX request configuration. Returned settings are: maxInactiveInterval, contextPath;
848882

@@ -866,6 +900,42 @@ Supported groups are:
866900

867901
11. “adhocview”. Different configuration dictionary values and lists for ad hoc. Configuration of settings depends on configuration of Jaspersoft server.
868902

903+
There is another way to get settings using specified methods for groups of settings that return specific object of settings:
904+
```java
905+
Final RequestSettings settings = session
906+
.settingsService()
907+
.settings()
908+
.ofRequestGroup()
909+
.getEntity();
910+
```
911+
Pleace notice, you should use List interface to get user’s time zones setting in this way:
912+
```java
913+
final List<UserTimeZone> settings = session
914+
.settingsService()
915+
.settings()
916+
.ofUserTimeZonesGroup()
917+
.getEntity();
918+
```
919+
Or you can get List of specified DTO for user’s time zones using GenericType class:
920+
```java
921+
final List<UserTimeZone> settings = session
922+
.settingsService()
923+
.settings()
924+
.group("userTimeZones", new GenericType<List<UserTimeZone>>() {})
925+
.getEntity();
926+
```
927+
Supported specified methods are:
928+
```java
929+
OperationResult<RequestSettings> ofRequestGroup();
930+
OperationResult<DataSourcePatternsSettings> ofDataSourcePatternsGroup();
931+
OperationResult<List<UserTimeZone>> ofUserTimeZonesGroup();
932+
OperationResult<AwsSettings> ofAwsGroup();
933+
OperationResult<DecimalFormatSymbolsSettings> ofDecimalFormatSymbolsGroup();
934+
OperationResult<DashboardSettings> ofDashboardGroup();
935+
OperationResult<GlobalConfigurationSettings> ofGlobalConfigurationGroup();
936+
OperationResult<DateTimeSettings> ofDateTimeGroup();
937+
OperationResult<InputControlsSettings> ofInputControlsGroup();
938+
```
869939

870940
Repository Services
871941
=====================

Vagrantfile

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#
2+
# Copyright (C) 2005 - 2014 Jaspersoft Corporation. All rights reserved.
3+
# http://www.jaspersoft.com.
4+
#
5+
# Unless you have purchased a commercial license agreement from Jaspersoft,
6+
# the following license terms apply:
7+
#
8+
# This program is free software: you can redistribute it and/or modify
9+
# it under the terms of the GNU Affero General Public License as
10+
# published by the Free Software Foundation, either version 3 of the
11+
# License, or (at your option) any later version.
12+
#
13+
# This program is distributed in the hope that it will be useful,
14+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
# GNU Affero General Public License for more details.
17+
#
18+
# You should have received a copy of the GNU Affero General Public License
19+
# along with this program.&nbsp; If not, see <http://www.gnu.org/licenses/>.
20+
#
21+
22+
Vagrant.configure(2) do |config|
23+
24+
config.vm.box = "JasperSoft/JasperServer6.1.0"
25+
config.vm.box_check_update = false
26+
config.ssh.pty = true
27+
28+
config.vm.network "forwarded_port", guest: 8080, host: 8090
29+
config.vm.network "forwarded_port", guest: 5432, host: 5430
30+
31+
config.vm.provision "shell", inline: "su vagrant -l -c '/bin/sh /home/vagrant/jasperreports-server-cp-6.1.0/ctlscript.sh start'"
32+
33+
end

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,8 @@
153153
<artifactId>maven-compiler-plugin</artifactId>
154154
<version>3.1</version>
155155
<configuration>
156-
<source>1.7</source>
157-
<target>1.7</target>
156+
<source>1.6</source>
157+
<target>1.6</target>
158158
</configuration>
159159
</plugin>
160160
<plugin>

src/integration-test/java/com/jaspersoft/jasperserver/jaxrs/client/apiadapters/authority/users/UsersServiceIT.java

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
package com.jaspersoft.jasperserver.jaxrs.client.apiadapters.authority.users;
22

33
import com.jaspersoft.jasperserver.dto.authority.ClientUser;
4-
import com.jaspersoft.jasperserver.jaxrs.client.core.*;
4+
import com.jaspersoft.jasperserver.jaxrs.client.core.JasperserverRestClient;
5+
import com.jaspersoft.jasperserver.jaxrs.client.core.RestClientConfiguration;
6+
import com.jaspersoft.jasperserver.jaxrs.client.core.Session;
7+
import java.util.List;
58
import org.testng.Assert;
69
import org.testng.annotations.AfterMethod;
710
import org.testng.annotations.BeforeMethod;
811
import org.testng.annotations.Test;
912

10-
import java.util.List;
11-
1213
/**
1314
* @author Alexander Krasnyanskiy
1415
*/
@@ -20,18 +21,19 @@ public class UsersServiceIT {
2021

2122
@BeforeMethod
2223
public void before() {
23-
config = new RestClientConfiguration("http://localhost:4444/jasperserver-pro");
24-
config.setAcceptMimeType(MimeType.JSON);
25-
config.setContentMimeType(MimeType.JSON);
26-
config.setJrsVersion(JRSVersion.v6_0_1);
27-
client = new JasperserverRestClient(config);
24+
25+
RestClientConfiguration cfg = new RestClientConfiguration("http://localhost:4444/jasperserver-pro");
26+
JasperserverRestClient client = new JasperserverRestClient(cfg);
27+
2828
session = client.authenticate("superuser", "superuser");
2929
}
3030

3131
@Test
3232
public void shouldReturnAllUsers() {
3333

34+
3435
//When
36+
3537
List<ClientUser> users = session
3638
.usersService()
3739
.allUsers()
@@ -55,6 +57,7 @@ public void should_return_list_users_by_role() {
5557
.getUserList();
5658

5759
//Then
60+
5861
Assert.assertTrue(users.size() > 3);
5962
}
6063

src/integration-test/java/com/jaspersoft/jasperserver/jaxrs/client/apiadapters/reporting/ReportingServiceIT.java

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,16 @@
33
import com.jaspersoft.jasperserver.jaxrs.client.core.JasperserverRestClient;
44
import com.jaspersoft.jasperserver.jaxrs.client.core.RestClientConfiguration;
55
import com.jaspersoft.jasperserver.jaxrs.client.core.operationresult.OperationResult;
6+
import java.io.InputStream;
67
import junit.framework.Assert;
78
import org.testng.annotations.AfterMethod;
89
import org.testng.annotations.BeforeMethod;
910
import org.testng.annotations.Test;
10-
import sun.org.mozilla.javascript.internal.ast.WhileLoop;
11-
12-
import java.io.*;
1311

12+
/**
13+
* @author Alex Krasnyanskiy
14+
* @author Tetiana Iefimenko
15+
*/
1416
public class ReportingServiceIT {
1517

1618
private RestClientConfiguration configuration;
@@ -41,28 +43,6 @@ public void should_return_proper_entity_if_pass_jrprint_report_output_format() {
4143
/** Then **/
4244
Assert.assertNotNull(entity);
4345

44-
// OutputStream output = null;
45-
// try {
46-
// output = new FileOutputStream("file.pdf");
47-
// int i = 0;
48-
// while (i != -1) {
49-
// i = entity.read();
50-
// output.write(i);
51-
// output.flush();
52-
//
53-
// }
54-
// } catch (IOException e) {
55-
// e.printStackTrace();
56-
// } finally {
57-
//
58-
// try {
59-
// entity.close();
60-
// output.close();
61-
// } catch (IOException e) {
62-
// e.printStackTrace();
63-
// }
64-
// }
65-
6646
}
6747

6848
@AfterMethod

src/integration-test/java/com/jaspersoft/jasperserver/jaxrs/client/apiadapters/resources/ResourcesServiceIT.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
package com.jaspersoft.jasperserver.jaxrs.client.apiadapters.resources;
22

3-
import com.jaspersoft.jasperserver.dto.resources.ClientFolder;
4-
import com.jaspersoft.jasperserver.dto.resources.ClientResource;
5-
import com.jaspersoft.jasperserver.jaxrs.client.core.*;
6-
import junit.framework.Assert;
3+
import com.jaspersoft.jasperserver.jaxrs.client.core.JRSVersion;
4+
import com.jaspersoft.jasperserver.jaxrs.client.core.JasperserverRestClient;
5+
import com.jaspersoft.jasperserver.jaxrs.client.core.MimeType;
6+
import com.jaspersoft.jasperserver.jaxrs.client.core.RestClientConfiguration;
7+
import com.jaspersoft.jasperserver.jaxrs.client.core.Session;
8+
import java.io.ByteArrayInputStream;
9+
import java.util.concurrent.TimeUnit;
10+
import javax.ws.rs.core.Response;
11+
import org.testng.Assert;
712
import org.testng.annotations.AfterMethod;
813
import org.testng.annotations.BeforeMethod;
914
import org.testng.annotations.Test;
1015

11-
import javax.ws.rs.core.Response;
12-
import java.io.ByteArrayInputStream;
13-
import java.util.concurrent.TimeUnit;
14-
1516
/**
1617
* @author Alexander Krasnyanskiy
18+
* @author tetiana Iefimenko
1719
*/
1820
public class ResourcesServiceIT {
1921

src/integration-test/java/com/jaspersoft/jasperserver/jaxrs/client/apiadapters/settings/SettingsServiceIT.java

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,26 @@
11
package com.jaspersoft.jasperserver.jaxrs.client.apiadapters.settings;
22

3-
import com.jaspersoft.jasperserver.jaxrs.client.core.*;
4-
import com.jaspersoft.jasperserver.jaxrs.client.dto.settings.*;
3+
import com.jaspersoft.jasperserver.jaxrs.client.core.AnonymousSession;
4+
import com.jaspersoft.jasperserver.jaxrs.client.core.JRSVersion;
5+
import com.jaspersoft.jasperserver.jaxrs.client.core.JasperserverRestClient;
6+
import com.jaspersoft.jasperserver.jaxrs.client.core.MimeType;
7+
import com.jaspersoft.jasperserver.jaxrs.client.core.RestClientConfiguration;
8+
import com.jaspersoft.jasperserver.jaxrs.client.dto.settings.AwsSettings;
9+
import com.jaspersoft.jasperserver.jaxrs.client.dto.settings.DashboardSettings;
10+
import com.jaspersoft.jasperserver.jaxrs.client.dto.settings.DataSourcePatternsSettings;
11+
import com.jaspersoft.jasperserver.jaxrs.client.dto.settings.DateTimeSettings;
12+
import com.jaspersoft.jasperserver.jaxrs.client.dto.settings.DecimalFormatSymbolsSettings;
13+
import com.jaspersoft.jasperserver.jaxrs.client.dto.settings.GlobalConfigurationSettings;
14+
import com.jaspersoft.jasperserver.jaxrs.client.dto.settings.InputControlsSettings;
15+
import com.jaspersoft.jasperserver.jaxrs.client.dto.settings.RequestSettings;
16+
import com.jaspersoft.jasperserver.jaxrs.client.dto.settings.UserTimeZone;
17+
import java.util.List;
18+
import java.util.Map;
19+
import javax.ws.rs.core.GenericType;
520
import org.testng.annotations.AfterMethod;
621
import org.testng.annotations.BeforeMethod;
722
import org.testng.annotations.Test;
823

9-
import javax.ws.rs.core.GenericType;
10-
import java.util.List;
11-
import java.util.Map;
12-
1324
import static junit.framework.Assert.assertFalse;
1425
import static junit.framework.Assert.assertNotNull;
1526
import static junit.framework.Assert.assertSame;

src/integration-test/resoursec/daracouese_resp.json

Lines changed: 0 additions & 12 deletions
This file was deleted.

0 commit comments

Comments
 (0)