diff --git a/api/src/main/java/org/openmrs/module/referenceapplication/administrativenotification/DuplicateConceptNotification.java b/api/src/main/java/org/openmrs/module/referenceapplication/administrativenotification/DuplicateConceptNotification.java new file mode 100644 index 00000000..a8de90cb --- /dev/null +++ b/api/src/main/java/org/openmrs/module/referenceapplication/administrativenotification/DuplicateConceptNotification.java @@ -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 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; + } + + notification.setId("DuplicateConcepts.id"); + notification.setIcon("icon-info-sign"); + notification.setCssClass("success"); + notification.setLabel("DuplicateConcepts.label"); + notification.setRequiredPrivilege("Manage Concepts"); + + + + return Arrays.asList(notification); + } +} \ No newline at end of file diff --git a/api/src/main/resources/messages.properties b/api/src/main/resources/messages.properties index 2997abf3..dca5f70b 100644 --- a/api/src/main/resources/messages.properties +++ b/api/src/main/resources/messages.properties @@ -107,3 +107,6 @@ referenceapplication.formentryapp.manageforms.label=Manage Forms general.auditInfo=Audit Info +DuplicateConcepts.label= Duplicate concepts exist. Please Upgrade to the latest version of reference Metadata Module +DuplicateConcepts.id = Duplicate + diff --git a/api/src/test/java/org/openmrs/module/referenceapplication/administrativenotification/DuplicateConceptNotificationTest.java b/api/src/test/java/org/openmrs/module/referenceapplication/administrativenotification/DuplicateConceptNotificationTest.java new file mode 100644 index 00000000..6f6a3bcd --- /dev/null +++ b/api/src/test/java/org/openmrs/module/referenceapplication/administrativenotification/DuplicateConceptNotificationTest.java @@ -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 notifications = producer.generateNotifications(); + assertEquals(notifications.size(), 1); + assertEquals(notifications.get(0).getId(), "DuplicateConcepts.id"); + + } + + ; + +} diff --git a/api/src/test/resources/ConceptsDuplicates.xml b/api/src/test/resources/ConceptsDuplicates.xml new file mode 100644 index 00000000..37afcf6a --- /dev/null +++ b/api/src/test/resources/ConceptsDuplicates.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/api/src/test/resources/NoConceptsDuplicates.xml b/api/src/test/resources/NoConceptsDuplicates.xml new file mode 100644 index 00000000..c156aed1 --- /dev/null +++ b/api/src/test/resources/NoConceptsDuplicates.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file