Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added admin point to delete templates #299

Merged
merged 1 commit into from
Jan 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Note: version releases in the 0.x.y range may introduce breaking changes.

- Flat : added more test and devise fixes ( see https://github.com/ehrbase/openEHR_SDK/pull/291)
- Upgrade to Archie 1.0.4 ([#292](https://github.com/ehrbase/openEHR_SDK/pull/292))
- cleanup created templates (https://github.com/ehrbase/openEHR_SDK/issues/298)

### Fixed

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package org.ehrbase.client.openehrclient;

public interface AdminTemplateEndpoint {
int delete(String templateId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ public interface OpenEhrClient {
*/
AdminEhrEndpoint adminEhrEndpoint();

AdminTemplateEndpoint adminTemplateEndpoint();

/**
* Get the {@link VersionedCompositionEndpoint}.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Copyright (c) 2020 Christian Chevalley (Hannover Medical School) and Vitasystems GmbH
*
* This file is part of project EHRbase
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and limitations under the License.
*/

package org.ehrbase.client.openehrclient.defaultrestclient;

import org.apache.http.HttpResponse;
import org.ehrbase.client.openehrclient.AdminTemplateEndpoint;

import java.net.URI;

/**
* Requires that the Admin endpoint is active.
*
* Parameters in .yml configuration matching the runtime context as:
*
* admin-api:
* active: true
* allowDeleteAll: true
*/
public class DefaultRestAdminTemplateEndpoint implements AdminTemplateEndpoint {

public static final String ADMIN_TEMPLATE_PATH = "rest/admin/template/";

private final DefaultRestClient defaultRestClient;

public DefaultRestAdminTemplateEndpoint(DefaultRestClient defaultRestClient) {
this.defaultRestClient = defaultRestClient;
}


@Override
public int delete(String templateId) {
if (templateId == null)
return 0;

URI uri = defaultRestClient.getConfig().getBaseUri().resolve(ADMIN_TEMPLATE_PATH + templateId);

HttpResponse response =
defaultRestClient.internalDelete(
uri,
null);

return response.getStatusLine().getStatusCode();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,11 @@ public AdminEhrEndpoint adminEhrEndpoint() {
return new DefaultRestAdminEhrEndpoint(this);
}

@Override
public AdminTemplateEndpoint adminTemplateEndpoint() {
return new DefaultRestAdminTemplateEndpoint(this);
}

@Override
public VersionedCompositionEndpoint versionedCompositionEndpoint(UUID ehrId) {
return new DefaultRestVersionedCompositionEndpoint(this, ehrId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.ehrbase.response.ehrscape.TemplateMetaDataDto;
import org.ehrbase.response.openehr.TemplatesResponseData;
import org.ehrbase.test_data.operationaltemplate.OperationalTemplateTestData;
import org.junit.After;
import org.junit.BeforeClass;
import org.junit.Test;
import org.openehr.schemas.v1.OPERATIONALTEMPLATE;
Expand All @@ -45,12 +46,20 @@ public class DefaultRestTemplateEndpointIT {

private static final String TEMPLATE_NAME_PREFIX = "ehrbase_blood_pressure_simple.de.v";

private String templateId = null; //global used for teardown

@BeforeClass
public static void setup() throws URISyntaxException {
restClient = DefaultRestClientTestHelper.setupDefaultRestClient();
restClientWithDefaultTemplateProvider = DefaultRestClientTestHelper.setupRestClientWithDefaultTemplateProvider();
}

@After
public void tearDown(){
//delete template with random version id (mostly)
restClient.adminTemplateEndpoint().delete(templateId);
}

@Test
public void testFindTemplate() {
Optional<OPERATIONALTEMPLATE> operationalTemplate = restClient.templateEndpoint()
Expand Down Expand Up @@ -82,7 +91,7 @@ public void testCreateTemplate() throws IOException, XmlException {

OPERATIONALTEMPLATE template = TemplateDocument.Factory.parse(OperationalTemplateTestData.BLOOD_PRESSURE_SIMPLE.getStream()).getTemplate();

String templateId = String.format("%s%s", TEMPLATE_NAME_PREFIX, RandomStringUtils.randomNumeric(10));
templateId = String.format("%s%s", TEMPLATE_NAME_PREFIX, RandomStringUtils.randomNumeric(10));
template.getTemplateId().setValue(templateId);
template.getUid().setValue(UUID.randomUUID().toString());

Expand All @@ -95,7 +104,7 @@ public void testCreateTemplateWithDefaultTemplateProvider() throws IOException,

OPERATIONALTEMPLATE template = TemplateDocument.Factory.parse(OperationalTemplateTestData.BLOOD_PRESSURE_SIMPLE.getStream()).getTemplate();

String templateId = String.format("%s%s", TEMPLATE_NAME_PREFIX, RandomStringUtils.randomNumeric(10));
templateId = String.format("%s%s", TEMPLATE_NAME_PREFIX, RandomStringUtils.randomNumeric(10));
template.getTemplateId().setValue(templateId);
template.getUid().setValue(UUID.randomUUID().toString());

Expand All @@ -106,7 +115,7 @@ public void testCreateTemplateWithDefaultTemplateProvider() throws IOException,
@Test
public void testFindAllTemplates() throws IOException, XmlException {

String templateId = String.format("%s%s", TEMPLATE_NAME_PREFIX, RandomStringUtils.randomNumeric(10));
templateId = String.format("%s%s", TEMPLATE_NAME_PREFIX, RandomStringUtils.randomNumeric(10));
String savedTemplateId = uploadTemplate(restClient,OperationalTemplateTestData.BLOOD_PRESSURE_SIMPLE, templateId);

assertThat(savedTemplateId).isEqualTo(templateId);
Expand All @@ -121,7 +130,7 @@ public void testFindAllTemplates() throws IOException, XmlException {

@Test
public void testFindAllTemplatesWithDefaultTemplateProvider() throws IOException, XmlException {
String templateId = String.format("%s%s", TEMPLATE_NAME_PREFIX, RandomStringUtils.randomNumeric(10));
templateId = String.format("%s%s", TEMPLATE_NAME_PREFIX, RandomStringUtils.randomNumeric(10));
String savedTemplateId = uploadTemplate(restClientWithDefaultTemplateProvider,OperationalTemplateTestData.BLOOD_PRESSURE_SIMPLE, templateId);

assertThat(savedTemplateId).isEqualTo(templateId);
Expand Down