Skip to content

Commit

Permalink
Merge branch 'master' into RESTWS-908
Browse files Browse the repository at this point in the history
  • Loading branch information
suubi-joshua authored Jul 29, 2024
2 parents 96df47b + 70882a4 commit 4d9b8f0
Show file tree
Hide file tree
Showing 15 changed files with 354 additions and 32 deletions.
7 changes: 4 additions & 3 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@ jobs:
JAVA_VERSION: ${{ matrix.java-version }}

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Set up JDK
uses: actions/setup-java@v1
uses: actions/setup-java@v4
with:
java-version: ${{ matrix.java-version }}
distribution: 'temurin'
- name: Cache local Maven repository
uses: actions/cache@v2
uses: actions/cache@v4
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,4 +168,21 @@ public void shouldReturnTheAuditInfoForTheFullRepresentation() throws Exception

assertNotNull(PropertyUtils.getProperty(result, "auditInfo"));
}

@Test
public void shouldReturnCustomRepresentationForAuditInfo() throws Exception {
SimpleObject result = deserialize(
handle(newGetRequest(getURI() + "/" + getUuid(),
new Parameter("v", "custom:(auditInfo:(creator:(uuid),dateCreated))"))));

assertNotNull(PropertyUtils.getProperty(result, "auditInfo"));
assertNotNull(PropertyUtils.getProperty(result, "auditInfo.creator"));
assertNotNull(PropertyUtils.getProperty(result, "auditInfo.creator.uuid"));
assertNotNull(PropertyUtils.getProperty(result, "auditInfo.dateCreated"));

assertNull(PropertyUtils.getProperty(result, "name"));
assertNull(PropertyUtils.getProperty(result, "links"));
assertNull(PropertyUtils.getProperty(result, "auditInfo.creator.display"));
assertNull(PropertyUtils.getProperty(result, "auditInfo.creator.links"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public void delete(HttpServletRequest request) {
*
* @return Provider if the user is authenticated
*/
private Provider getCurrentProvider() {
protected Provider getCurrentProvider() {
Provider currentProvider = null;
User currentUser = Context.getAuthenticatedUser();
if (currentUser != null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/**
* This Source Code Form is subject to the terms of the Mozilla Public License,
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
* obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under
* the terms of the Healthcare Disclaimer located at http://openmrs.org/license.
*
* Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS
* graphic logo is a trademark of OpenMRS Inc.
*/
package org.openmrs.module.webservices.rest.web.v1_0.controller.openmrs2_0;

import java.util.Collection;
import java.util.HashSet;

import org.openmrs.Provider;
import org.openmrs.User;
import org.openmrs.api.context.Context;
import org.openmrs.module.webservices.rest.web.v1_0.controller.openmrs1_9.SessionController1_9;
import org.openmrs.util.PrivilegeConstants;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

/**
* @see SessionController1_9
*/
@Controller
@RequestMapping
public class SessionController2_0 extends SessionController1_9 {

private static final Logger log = LoggerFactory.getLogger(SessionController2_0.class);

/**
* @see SessionController1_9#getCurrentProvider()
*/
@Override
protected Provider getCurrentProvider() {
Provider currentProvider = null;
User currentUser = Context.getAuthenticatedUser();
if (currentUser != null) {
Collection<Provider> providers = new HashSet<Provider>();
try {
Context.addProxyPrivilege(PrivilegeConstants.GET_PROVIDERS);
if (currentUser.getPerson() != null) {
providers = Context.getProviderService().getProvidersByPerson(currentUser.getPerson(), false);
}
}
finally {
Context.removeProxyPrivilege(PrivilegeConstants.GET_PROVIDERS);
}
if (providers.size() > 1) {
log.warn("Can't handle users with multiple provider accounts");
} else if (providers.size() == 1) {
currentProvider = providers.iterator().next();
}
}
return currentProvider;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/**
* This Source Code Form is subject to the terms of the Mozilla Public License,
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
* obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under
* the terms of the Healthcare Disclaimer located at http://openmrs.org/license.
*
* Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS
* graphic logo is a trademark of OpenMRS Inc.
*/
package org.openmrs.module.webservices.rest.web.v1_0.controller.openmrs2_0;

import org.apache.commons.beanutils.PropertyUtils;
import org.junit.Assert;
import org.junit.Test;
import org.openmrs.api.context.Context;
import org.openmrs.web.test.BaseModuleWebContextSensitiveTest;

/**
* Tests functionality of {@link SessionController2_0}
*/
public class SessionController2_0Test extends BaseModuleWebContextSensitiveTest {

/**
* @see SessionController2_0#get()
* @verifies return the session with current provider if the user doesn't have Get Providers privilege
*/
@Test
public void get_shouldReturnCurrentProviderIfTheUserDoesNotHaveGetProvidersPrivilege() throws Exception {
executeDataSet("sessionControllerTestDataset.xml");

// authenticate new user without privileges
Context.logout();
Context.authenticate("test_user", "test");
Assert.assertTrue(Context.isAuthenticated());

SessionController2_0 controller = Context.getRegisteredComponents(SessionController2_0.class).iterator().next();

Object ret = controller.get();
Object currentProvider = PropertyUtils.getProperty(ret, "currentProvider");
Assert.assertNotNull(currentProvider);
Assert.assertTrue(currentProvider.toString().contains("Test Provider"));
}
}
19 changes: 19 additions & 0 deletions omod-2.0/src/test/resources/sessionControllerTestDataset.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version='1.0' encoding='UTF-8'?>
<!--
This Source Code Form is subject to the terms of the Mozilla Public License,
v. 2.0. If a copy of the MPL was not distributed with this file, You can
obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under
the terms of the Healthcare Disclaimer located at http://openmrs.org/license.
Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS
graphic logo is a trademark of OpenMRS Inc.
-->
<dataset>

<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"/>
<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"/>
<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" />

</dataset>
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ public String getDisplayString(Diagnosis diagnosis) {
@Override
public DelegatingResourceDescription getCreatableProperties() throws ResourceDoesNotSupportOperationException {
DelegatingResourceDescription description = new DelegatingResourceDescription();

description.addRequiredProperty("diagnosis");
description.addRequiredProperty("encounter");
description.addRequiredProperty("condition");
Expand All @@ -185,15 +185,15 @@ public DelegatingResourceDescription getCreatableProperties() throws ResourceDoe
*/
@Override
public Model getCREATEModel(Representation rep) {

return new ModelImpl()
.property("diagnosis", new StringProperty())
.property("encounter", new StringProperty())
.property("condition", new StringProperty())
.property("certainty", new StringProperty())
.property("patient", new StringProperty().example("uuid"))
.property("rank", new IntegerProperty());

}

/**
Expand All @@ -209,7 +209,7 @@ public DelegatingResourceDescription getUpdatableProperties() throws ResourceDoe
description.addRequiredProperty("voided");
description.addRequiredProperty("certainty");
description.addRequiredProperty("encounter");

return description;
}

Expand Down
42 changes: 19 additions & 23 deletions omod-2.5/pom.xml
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">

<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">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>webservices.rest</artifactId>
<groupId>org.openmrs.module</groupId>
<artifactId>webservices.rest</artifactId>
<version>2.45.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>webservices.rest-omod-2.5</artifactId>
<packaging>jar</packaging>
<name>Rest Web Services 2.5 OMOD</name>
<description>OpenMRS module project for Rest Web Services</description>

<properties>
<openmrs.version.2.5.0>2.5.0</openmrs.version.2.5.0>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>

<dependencies>
Expand Down Expand Up @@ -93,6 +95,14 @@
<version>${project.parent.version}</version>
</dependency>

<dependency>
<groupId>${project.parent.groupId}</groupId>
<artifactId>${project.parent.artifactId}-omod-2.0</artifactId>
<version>${project.parent.version}</version>
<classifier>tests</classifier>
<scope>test</scope>
</dependency>

<dependency>
<groupId>${project.parent.groupId}</groupId>
<artifactId>${project.parent.artifactId}-omod-2.2</artifactId>
Expand Down Expand Up @@ -135,14 +145,6 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>${project.parent.groupId}</groupId>
<artifactId>${project.parent.artifactId}-omod-2.0</artifactId>
<version>${project.parent.version}</version>
<classifier>tests</classifier>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.openmrs.api</groupId>
<artifactId>openmrs-api</artifactId>
Expand All @@ -160,29 +162,23 @@
<dependency>
<groupId>org.openmrs.web</groupId>
<artifactId>openmrs-web</artifactId>
<version>${openmrs.version.2.5.0}</version>
<exclusions>
<exclusion>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
</exclusion>
</exclusions>
<version>${openmrs.version.2.5.0}</version>
</dependency>

<dependency>
<groupId>org.openmrs.web</groupId>
<artifactId>openmrs-web</artifactId>
<type>test-jar</type>
<scope>test</scope>
<version>${openmrs.version.2.5.0}</version>
<version>${openmrs.version.2.5.0}</version>
</dependency>

<dependency>
<groupId>org.openmrs.test</groupId>
<artifactId>openmrs-test</artifactId>
<type>pom</type>
<scope>test</scope>
<version>${openmrs.version.2.5.0}</version>
<version>${openmrs.version.2.5.0}</version>
</dependency>

<dependency>
Expand All @@ -195,7 +191,7 @@
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>jasper</artifactId>
<version>6.0.18</version>
<version>${apacheTomcatVersion}</version>
<scope>provided</scope>
</dependency>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,20 @@
*/
package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs2_5;

import io.swagger.models.Model;
import io.swagger.models.ModelImpl;
import io.swagger.models.properties.StringProperty;

import org.openmrs.Diagnosis;
import org.openmrs.module.webservices.rest.web.RestConstants;
import org.openmrs.module.webservices.rest.web.annotation.Resource;
import org.openmrs.module.webservices.rest.web.representation.DefaultRepresentation;
import org.openmrs.module.webservices.rest.web.representation.FullRepresentation;
import org.openmrs.module.webservices.rest.web.representation.Representation;

import org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource;
import org.openmrs.module.webservices.rest.web.resource.impl.DelegatingCrudResource;

import org.openmrs.module.webservices.rest.web.resource.impl.DelegatingResourceDescription;
import org.openmrs.module.webservices.rest.web.response.ResourceDoesNotSupportOperationException;
import org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs2_2.DiagnosisResource2_2;
Expand Down Expand Up @@ -71,4 +79,5 @@ public DelegatingResourceDescription getUpdatableProperties() throws ResourceDoe

return description;
}

}
Loading

0 comments on commit 4d9b8f0

Please sign in to comment.