Skip to content

Commit 4d9b8f0

Browse files
authored
Merge branch 'master' into RESTWS-908
2 parents 96df47b + 70882a4 commit 4d9b8f0

File tree

15 files changed

+354
-32
lines changed

15 files changed

+354
-32
lines changed

.github/workflows/maven.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,14 @@ jobs:
2121
JAVA_VERSION: ${{ matrix.java-version }}
2222

2323
steps:
24-
- uses: actions/checkout@v2
24+
- uses: actions/checkout@v4
2525
- name: Set up JDK
26-
uses: actions/setup-java@v1
26+
uses: actions/setup-java@v4
2727
with:
2828
java-version: ${{ matrix.java-version }}
29+
distribution: 'temurin'
2930
- name: Cache local Maven repository
30-
uses: actions/cache@v2
31+
uses: actions/cache@v4
3132
with:
3233
path: ~/.m2/repository
3334
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}

omod-1.8/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_8/PatientIdentifierTypeController1_8Test.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,4 +168,21 @@ public void shouldReturnTheAuditInfoForTheFullRepresentation() throws Exception
168168

169169
assertNotNull(PropertyUtils.getProperty(result, "auditInfo"));
170170
}
171+
172+
@Test
173+
public void shouldReturnCustomRepresentationForAuditInfo() throws Exception {
174+
SimpleObject result = deserialize(
175+
handle(newGetRequest(getURI() + "/" + getUuid(),
176+
new Parameter("v", "custom:(auditInfo:(creator:(uuid),dateCreated))"))));
177+
178+
assertNotNull(PropertyUtils.getProperty(result, "auditInfo"));
179+
assertNotNull(PropertyUtils.getProperty(result, "auditInfo.creator"));
180+
assertNotNull(PropertyUtils.getProperty(result, "auditInfo.creator.uuid"));
181+
assertNotNull(PropertyUtils.getProperty(result, "auditInfo.dateCreated"));
182+
183+
assertNull(PropertyUtils.getProperty(result, "name"));
184+
assertNull(PropertyUtils.getProperty(result, "links"));
185+
assertNull(PropertyUtils.getProperty(result, "auditInfo.creator.display"));
186+
assertNull(PropertyUtils.getProperty(result, "auditInfo.creator.links"));
187+
}
171188
}

omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_9/SessionController1_9.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ public void delete(HttpServletRequest request) {
132132
*
133133
* @return Provider if the user is authenticated
134134
*/
135-
private Provider getCurrentProvider() {
135+
protected Provider getCurrentProvider() {
136136
Provider currentProvider = null;
137137
User currentUser = Context.getAuthenticatedUser();
138138
if (currentUser != null) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/**
2+
* This Source Code Form is subject to the terms of the Mozilla Public License,
3+
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
4+
* obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under
5+
* the terms of the Healthcare Disclaimer located at http://openmrs.org/license.
6+
*
7+
* Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS
8+
* graphic logo is a trademark of OpenMRS Inc.
9+
*/
10+
package org.openmrs.module.webservices.rest.web.v1_0.controller.openmrs2_0;
11+
12+
import java.util.Collection;
13+
import java.util.HashSet;
14+
15+
import org.openmrs.Provider;
16+
import org.openmrs.User;
17+
import org.openmrs.api.context.Context;
18+
import org.openmrs.module.webservices.rest.web.v1_0.controller.openmrs1_9.SessionController1_9;
19+
import org.openmrs.util.PrivilegeConstants;
20+
import org.slf4j.Logger;
21+
import org.slf4j.LoggerFactory;
22+
import org.springframework.stereotype.Controller;
23+
import org.springframework.web.bind.annotation.RequestMapping;
24+
25+
/**
26+
* @see SessionController1_9
27+
*/
28+
@Controller
29+
@RequestMapping
30+
public class SessionController2_0 extends SessionController1_9 {
31+
32+
private static final Logger log = LoggerFactory.getLogger(SessionController2_0.class);
33+
34+
/**
35+
* @see SessionController1_9#getCurrentProvider()
36+
*/
37+
@Override
38+
protected Provider getCurrentProvider() {
39+
Provider currentProvider = null;
40+
User currentUser = Context.getAuthenticatedUser();
41+
if (currentUser != null) {
42+
Collection<Provider> providers = new HashSet<Provider>();
43+
try {
44+
Context.addProxyPrivilege(PrivilegeConstants.GET_PROVIDERS);
45+
if (currentUser.getPerson() != null) {
46+
providers = Context.getProviderService().getProvidersByPerson(currentUser.getPerson(), false);
47+
}
48+
}
49+
finally {
50+
Context.removeProxyPrivilege(PrivilegeConstants.GET_PROVIDERS);
51+
}
52+
if (providers.size() > 1) {
53+
log.warn("Can't handle users with multiple provider accounts");
54+
} else if (providers.size() == 1) {
55+
currentProvider = providers.iterator().next();
56+
}
57+
}
58+
return currentProvider;
59+
}
60+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/**
2+
* This Source Code Form is subject to the terms of the Mozilla Public License,
3+
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
4+
* obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under
5+
* the terms of the Healthcare Disclaimer located at http://openmrs.org/license.
6+
*
7+
* Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS
8+
* graphic logo is a trademark of OpenMRS Inc.
9+
*/
10+
package org.openmrs.module.webservices.rest.web.v1_0.controller.openmrs2_0;
11+
12+
import org.apache.commons.beanutils.PropertyUtils;
13+
import org.junit.Assert;
14+
import org.junit.Test;
15+
import org.openmrs.api.context.Context;
16+
import org.openmrs.web.test.BaseModuleWebContextSensitiveTest;
17+
18+
/**
19+
* Tests functionality of {@link SessionController2_0}
20+
*/
21+
public class SessionController2_0Test extends BaseModuleWebContextSensitiveTest {
22+
23+
/**
24+
* @see SessionController2_0#get()
25+
* @verifies return the session with current provider if the user doesn't have Get Providers privilege
26+
*/
27+
@Test
28+
public void get_shouldReturnCurrentProviderIfTheUserDoesNotHaveGetProvidersPrivilege() throws Exception {
29+
executeDataSet("sessionControllerTestDataset.xml");
30+
31+
// authenticate new user without privileges
32+
Context.logout();
33+
Context.authenticate("test_user", "test");
34+
Assert.assertTrue(Context.isAuthenticated());
35+
36+
SessionController2_0 controller = Context.getRegisteredComponents(SessionController2_0.class).iterator().next();
37+
38+
Object ret = controller.get();
39+
Object currentProvider = PropertyUtils.getProperty(ret, "currentProvider");
40+
Assert.assertNotNull(currentProvider);
41+
Assert.assertTrue(currentProvider.toString().contains("Test Provider"));
42+
}
43+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version='1.0' encoding='UTF-8'?>
2+
<!--
3+
4+
This Source Code Form is subject to the terms of the Mozilla Public License,
5+
v. 2.0. If a copy of the MPL was not distributed with this file, You can
6+
obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under
7+
the terms of the Healthcare Disclaimer located at http://openmrs.org/license.
8+
9+
Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS
10+
graphic logo is a trademark of OpenMRS Inc.
11+
12+
-->
13+
<dataset>
14+
15+
<person person_id="601" gender="M" dead="false" birthdate_estimated="0" creator="1" date_created="2008-08-15 15:57:09.0" voided="false" uuid="hy6b4e41-790c-484f-b6ed-71dc3e4222de"/>
16+
<users user_id="601" person_id="601" system_id="7-5" username="test_user" password="4a1750c8607d0fa237de36c6305715c223415189" salt="c788c6ad82a157b712392ca695dfcf2eed193d7f" creator="1" date_created="2008-08-15 15:57:09.0" retired="false" uuid="06d05314-e132-11de-babe-001e37123456"/>
17+
<provider provider_id="601" person_id="601" name="Mr. Test Provider" identifier="Test Provider" creator="1" date_created="2008-08-15 15:57:09.0" retired="false" uuid="e1009293-c561-47ae-b112-214052c17888" />
18+
19+
</dataset>

omod-2.2/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_2/DiagnosisResource2_2.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ public String getDisplayString(Diagnosis diagnosis) {
169169
@Override
170170
public DelegatingResourceDescription getCreatableProperties() throws ResourceDoesNotSupportOperationException {
171171
DelegatingResourceDescription description = new DelegatingResourceDescription();
172-
172+
173173
description.addRequiredProperty("diagnosis");
174174
description.addRequiredProperty("encounter");
175175
description.addRequiredProperty("condition");
@@ -185,15 +185,15 @@ public DelegatingResourceDescription getCreatableProperties() throws ResourceDoe
185185
*/
186186
@Override
187187
public Model getCREATEModel(Representation rep) {
188-
188+
189189
return new ModelImpl()
190190
.property("diagnosis", new StringProperty())
191191
.property("encounter", new StringProperty())
192192
.property("condition", new StringProperty())
193193
.property("certainty", new StringProperty())
194194
.property("patient", new StringProperty().example("uuid"))
195195
.property("rank", new IntegerProperty());
196-
196+
197197
}
198198

199199
/**
@@ -209,7 +209,7 @@ public DelegatingResourceDescription getUpdatableProperties() throws ResourceDoe
209209
description.addRequiredProperty("voided");
210210
description.addRequiredProperty("certainty");
211211
description.addRequiredProperty("encounter");
212-
212+
213213
return description;
214214
}
215215

omod-2.5/pom.xml

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<project xmlns="http://maven.apache.org/POM/4.0.0"
3-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
4-
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
54
<parent>
6-
<artifactId>webservices.rest</artifactId>
75
<groupId>org.openmrs.module</groupId>
6+
<artifactId>webservices.rest</artifactId>
87
<version>2.45.0-SNAPSHOT</version>
98
</parent>
10-
<modelVersion>4.0.0</modelVersion>
119

1210
<artifactId>webservices.rest-omod-2.5</artifactId>
11+
<packaging>jar</packaging>
1312
<name>Rest Web Services 2.5 OMOD</name>
13+
<description>OpenMRS module project for Rest Web Services</description>
1414

1515
<properties>
1616
<openmrs.version.2.5.0>2.5.0</openmrs.version.2.5.0>
17+
<maven.compiler.source>1.8</maven.compiler.source>
18+
<maven.compiler.target>1.8</maven.compiler.target>
1719
</properties>
1820

1921
<dependencies>
@@ -93,6 +95,14 @@
9395
<version>${project.parent.version}</version>
9496
</dependency>
9597

98+
<dependency>
99+
<groupId>${project.parent.groupId}</groupId>
100+
<artifactId>${project.parent.artifactId}-omod-2.0</artifactId>
101+
<version>${project.parent.version}</version>
102+
<classifier>tests</classifier>
103+
<scope>test</scope>
104+
</dependency>
105+
96106
<dependency>
97107
<groupId>${project.parent.groupId}</groupId>
98108
<artifactId>${project.parent.artifactId}-omod-2.2</artifactId>
@@ -135,14 +145,6 @@
135145
<scope>test</scope>
136146
</dependency>
137147

138-
<dependency>
139-
<groupId>${project.parent.groupId}</groupId>
140-
<artifactId>${project.parent.artifactId}-omod-2.0</artifactId>
141-
<version>${project.parent.version}</version>
142-
<classifier>tests</classifier>
143-
<scope>test</scope>
144-
</dependency>
145-
146148
<dependency>
147149
<groupId>org.openmrs.api</groupId>
148150
<artifactId>openmrs-api</artifactId>
@@ -160,29 +162,23 @@
160162
<dependency>
161163
<groupId>org.openmrs.web</groupId>
162164
<artifactId>openmrs-web</artifactId>
163-
<version>${openmrs.version.2.5.0}</version>
164-
<exclusions>
165-
<exclusion>
166-
<groupId>javax.servlet</groupId>
167-
<artifactId>servlet-api</artifactId>
168-
</exclusion>
169-
</exclusions>
165+
<version>${openmrs.version.2.5.0}</version>
170166
</dependency>
171167

172168
<dependency>
173169
<groupId>org.openmrs.web</groupId>
174170
<artifactId>openmrs-web</artifactId>
175171
<type>test-jar</type>
176172
<scope>test</scope>
177-
<version>${openmrs.version.2.5.0}</version>
173+
<version>${openmrs.version.2.5.0}</version>
178174
</dependency>
179175

180176
<dependency>
181177
<groupId>org.openmrs.test</groupId>
182178
<artifactId>openmrs-test</artifactId>
183179
<type>pom</type>
184180
<scope>test</scope>
185-
<version>${openmrs.version.2.5.0}</version>
181+
<version>${openmrs.version.2.5.0}</version>
186182
</dependency>
187183

188184
<dependency>
@@ -195,7 +191,7 @@
195191
<dependency>
196192
<groupId>org.apache.tomcat</groupId>
197193
<artifactId>jasper</artifactId>
198-
<version>6.0.18</version>
194+
<version>${apacheTomcatVersion}</version>
199195
<scope>provided</scope>
200196
</dependency>
201197

omod-2.5/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_5/DiagnosisResource2_5.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,20 @@
99
*/
1010
package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs2_5;
1111

12+
import io.swagger.models.Model;
13+
import io.swagger.models.ModelImpl;
14+
import io.swagger.models.properties.StringProperty;
15+
1216
import org.openmrs.Diagnosis;
1317
import org.openmrs.module.webservices.rest.web.RestConstants;
1418
import org.openmrs.module.webservices.rest.web.annotation.Resource;
1519
import org.openmrs.module.webservices.rest.web.representation.DefaultRepresentation;
1620
import org.openmrs.module.webservices.rest.web.representation.FullRepresentation;
1721
import org.openmrs.module.webservices.rest.web.representation.Representation;
22+
23+
import org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource;
24+
import org.openmrs.module.webservices.rest.web.resource.impl.DelegatingCrudResource;
25+
1826
import org.openmrs.module.webservices.rest.web.resource.impl.DelegatingResourceDescription;
1927
import org.openmrs.module.webservices.rest.web.response.ResourceDoesNotSupportOperationException;
2028
import org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs2_2.DiagnosisResource2_2;
@@ -71,4 +79,5 @@ public DelegatingResourceDescription getUpdatableProperties() throws ResourceDoe
7179

7280
return description;
7381
}
82+
7483
}

0 commit comments

Comments
 (0)