-
Notifications
You must be signed in to change notification settings - Fork 145
RA-429 : create a class that produces the administration notification… #50
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| /** | ||
| * 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.referenceapplication.administrativenotification; | ||
|
|
||
| import java.util.List; | ||
| import java.util.Arrays; | ||
|
|
||
| import org.openmrs.api.context.Context; | ||
| import org.openmrs.module.appframework.factory.AdministrativeNotificationProducer; | ||
| import org.openmrs.module.appframework.domain.AdministrativeNotification; | ||
| import org.springframework.stereotype.Component; | ||
|
|
||
| @Component | ||
| public class DuplicateConceptNotification implements AdministrativeNotificationProducer{ | ||
|
|
||
|
|
||
|
|
||
| @Override | ||
| public List<AdministrativeNotification> generateNotifications() { | ||
|
|
||
|
|
||
| if (!Context.hasPrivilege("Manage Concepts")) { | ||
| return null; | ||
| } | ||
|
|
||
| AdministrativeNotification notification = new AdministrativeNotification(); | ||
|
|
||
|
|
||
| // checking whether concepts 1 and 2 exist in the system | ||
|
|
||
| if( Context.getConceptService().getConcept(1)==null || Context.getConceptService().getConcept(2)==null | ||
| ) { | ||
| return null; | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. condition on line 29 and line 38 can me merged into a single if statement instead of using two if statements
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mozzy11 could respond to @haripriya999 comment please |
||
|
|
||
| notification.setId("DuplicateConcepts.id"); | ||
| notification.setIcon("icon-info-sign"); | ||
| notification.setCssClass("success"); | ||
| notification.setLabel("DuplicateConcepts.label"); | ||
| notification.setRequiredPrivilege("Manage Concepts"); | ||
|
|
||
|
|
||
|
|
||
| return Arrays.asList(notification); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| package org.openmrs.module.referenceapplication.administrativenotification; | ||
|
|
||
| import static org.junit.Assert.assertEquals; | ||
| import static org.junit.Assert.assertNull; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| import org.junit.Before; | ||
| import org.junit.Test; | ||
| import org.openmrs.module.appframework.domain.AdministrativeNotification; | ||
| import org.openmrs.test.BaseModuleContextSensitiveTest; | ||
| import org.springframework.beans.factory.annotation.Autowired; | ||
|
|
||
| public class DuplicateConceptNotificationTest extends BaseModuleContextSensitiveTest { | ||
|
|
||
| @Autowired | ||
| DuplicateConceptNotification producer; | ||
|
|
||
| @Before | ||
| public void setUp() throws Exception { | ||
| initializeInMemoryDatabase(); | ||
| } | ||
|
|
||
| @Test | ||
| public void shouldNotProduceNotificationWhenDuplicateConceptsDoesNotExist() throws Exception { | ||
| executeDataSet("NoConceptsDuplicates.xml"); | ||
| authenticate(); | ||
| assertNull(producer.generateNotifications()); | ||
| } | ||
|
|
||
|
|
||
| @Test | ||
| public void shouldProduceNotificationWhenDuplicateConceptsExist() throws Exception { | ||
|
|
||
| executeDataSet("ConceptsDuplicates.xml"); | ||
| authenticate(); | ||
|
|
||
| List<AdministrativeNotification> notifications = producer.generateNotifications(); | ||
| assertEquals(notifications.size(), 1); | ||
| assertEquals(notifications.get(0).getId(), "DuplicateConcepts.id"); | ||
|
|
||
| } | ||
|
|
||
| ; | ||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <dataset> | ||
|
|
||
| <concept concept_id="1" retired="0" datatype_id="1" class_id="7" is_set="0" creator="1" date_created="2013-04-26 14:32:16.0" version="" changed_by="1" retired_by="1" uuid="161655AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"/> | ||
| <concept_numeric concept_id="1" units="" precise="0"/> | ||
| <concept_name concept_id="1" name="ANC ID" locale="en" creator="1" date_created="2013-04-26 14:32:16.0" concept_name_id="123687" voided="0" voided_by="1" uuid="123687BBBBBBBBBBBBBBBBBBBBBBBBBBBBBB" concept_name_type="SHORT" locale_preferred="false"/> | ||
|
|
||
| <concept concept_id="2" retired="0" datatype_id="2" class_id="7" is_set="0" creator="1" date_created="2013-04-26 14:32:16.0" version="" changed_by="1" retired_by="1" uuid="161655AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA2"/> | ||
| <concept_numeric concept_id="2" units="" precise="0"/> | ||
| <concept_name concept_id="2" name="ANC ID" locale="en" creator="1" date_created="2013-04-26 14:32:16.0" concept_name_id="123687" voided="0" voided_by="1" uuid="123687BBBBBBBBBBBBBBBBBBBBBBBBBBBBBB2" concept_name_type="SHORT" locale_preferred="false"/> | ||
|
|
||
| </dataset> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <dataset> | ||
|
|
||
| <concept concept_id="3" retired="0" datatype_id="1" class_id="7" is_set="0" creator="1" date_created="2013-04-26 14:32:16.0" version="" changed_by="1" retired_by="1" uuid="161655AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"/> | ||
| <concept_numeric concept_id="3" units="" precise="0"/> | ||
| <concept_name concept_id="3" name="ANC ID" locale="en" creator="1" date_created="2013-04-26 14:32:16.0" concept_name_id="123687" voided="0" voided_by="1" uuid="123687BBBBBBBBBBBBBBBBBBBBBBBBBBBBBB" concept_name_type="SHORT" locale_preferred="false"/> | ||
|
|
||
| <concept concept_id="4" retired="0" datatype_id="2" class_id="7" is_set="0" creator="1" date_created="2013-04-26 14:32:16.0" version="" changed_by="1" retired_by="1" uuid="161655AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA2"/> | ||
| <concept_numeric concept_id="4" units="" precise="0"/> | ||
| <concept_name concept_id="4" name="ANC ID" locale="en" creator="1" date_created="2013-04-26 14:32:16.0" concept_name_id="123687" voided="0" voided_by="1" uuid="123687BBBBBBBBBBBBBBBBBBBBBBBBBBBBBB2" concept_name_type="SHORT" locale_preferred="false"/> | ||
|
|
||
| </dataset> |
Uh oh!
There was an error while loading. Please reload this page.