Skip to content

Commit ecff8e0

Browse files
committed
RA-429 : create a class that produces the administration notification when duplicate concepts exists and AddedUnit Test
m
1 parent a9a47b2 commit ecff8e0

5 files changed

Lines changed: 126 additions & 0 deletions

File tree

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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.referenceapplication.administrativenotification;
11+
12+
import java.util.List;
13+
import java.util.Arrays;
14+
15+
import org.openmrs.api.context.Context;
16+
import org.openmrs.module.appframework.factory.AdministrativeNotificationProducer;
17+
import org.openmrs.module.appframework.domain.AdministrativeNotification;
18+
import org.springframework.stereotype.Component;
19+
20+
@Component
21+
public class DuplicateConceptNotification implements AdministrativeNotificationProducer{
22+
23+
24+
25+
@Override
26+
public List<AdministrativeNotification> generateNotifications() {
27+
28+
29+
if (!Context.hasPrivilege("Manage Concepts")) {
30+
return null;
31+
}
32+
33+
AdministrativeNotification notification = new AdministrativeNotification();
34+
35+
36+
// checking whether concepts 1 and 2 exist in the system
37+
38+
if( Context.getConceptService().getConcept(1)==null || Context.getConceptService().getConcept(2)==null
39+
) {
40+
return null;
41+
}
42+
43+
notification.setId("DuplicateConcepts.id");
44+
notification.setIcon("icon-info-sign");
45+
notification.setCssClass("success");
46+
notification.setLabel("DuplicateConcepts.label");
47+
notification.setRequiredPrivilege("Manage Concepts");
48+
49+
50+
51+
return Arrays.asList(notification);
52+
}
53+
}

api/src/main/resources/messages.properties

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,3 +107,6 @@ referenceapplication.formentryapp.manageforms.label=Manage Forms
107107

108108
general.auditInfo=Audit Info
109109

110+
DuplicateConcepts.label= Duplicate concepts exist. Please Upgrade to the latest version of reference Metadata Module
111+
DuplicateConcepts.id = Duplicate
112+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package org.openmrs.module.referenceapplication.administrativenotification;
2+
3+
import static org.junit.Assert.assertEquals;
4+
import static org.junit.Assert.assertNull;
5+
6+
import java.util.List;
7+
8+
import org.junit.Before;
9+
import org.junit.Test;
10+
import org.openmrs.module.appframework.domain.AdministrativeNotification;
11+
import org.openmrs.test.BaseModuleContextSensitiveTest;
12+
import org.springframework.beans.factory.annotation.Autowired;
13+
14+
public class DuplicateConceptNotificationTest extends BaseModuleContextSensitiveTest {
15+
16+
@Autowired
17+
DuplicateConceptNotification producer;
18+
19+
@Before
20+
public void setUp() throws Exception {
21+
initializeInMemoryDatabase();
22+
}
23+
24+
@Test
25+
public void shouldNotProduceNotificationWhenDuplicateConceptsDoesNotExist() throws Exception {
26+
executeDataSet("NoConceptsDuplicates.xml");
27+
authenticate();
28+
assertNull(producer.generateNotifications());
29+
}
30+
31+
32+
@Test
33+
public void shouldProduceNotificationWhenDuplicateConceptsExist() throws Exception {
34+
35+
executeDataSet("ConceptsDuplicates.xml");
36+
authenticate();
37+
38+
List<AdministrativeNotification> notifications = producer.generateNotifications();
39+
assertEquals(notifications.size(), 1);
40+
assertEquals(notifications.get(0).getId(), "DuplicateConcepts.id");
41+
42+
}
43+
44+
;
45+
46+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<dataset>
3+
4+
<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"/>
5+
<concept_numeric concept_id="1" units="" precise="0"/>
6+
<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"/>
7+
8+
<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"/>
9+
<concept_numeric concept_id="2" units="" precise="0"/>
10+
<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"/>
11+
12+
</dataset>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<dataset>
3+
4+
<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"/>
5+
<concept_numeric concept_id="3" units="" precise="0"/>
6+
<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"/>
7+
8+
<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"/>
9+
<concept_numeric concept_id="4" units="" precise="0"/>
10+
<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"/>
11+
12+
</dataset>

0 commit comments

Comments
 (0)