Search in sources :

Example 71 with DataSet

use of org.hisp.dhis.dataset.DataSet in project dhis2-core by dhis2.

the class DefaultMessageService method sendCompletenessMessage.

@Override
public int sendCompletenessMessage(CompleteDataSetRegistration registration) {
    DataSet dataSet = registration.getDataSet();
    if (dataSet == null) {
        return 0;
    }
    UserGroup userGroup = dataSet.getNotificationRecipients();
    User sender = currentUserService.getCurrentUser();
    Set<User> recipients = new HashSet<>();
    if (userGroup != null) {
        recipients.addAll(new HashSet<>(userGroup.getMembers()));
    }
    if (dataSet.isNotifyCompletingUser()) {
        recipients.add(sender);
    }
    if (recipients.isEmpty()) {
        return 0;
    }
    String text = new VelocityManager().render(registration, COMPLETE_TEMPLATE);
    MessageConversation conversation = new MessageConversation(COMPLETE_SUBJECT, sender, MessageType.SYSTEM);
    conversation.addMessage(new Message(text, null, sender));
    for (User user : recipients) {
        conversation.addUserMessage(new UserMessage(user));
    }
    if (!conversation.getUserMessages().isEmpty()) {
        int id = saveMessageConversation(conversation);
        invokeMessageSenders(COMPLETE_SUBJECT, text, null, sender, new HashSet<>(conversation.getUsers()), false);
        return id;
    }
    return 0;
}
Also used : DataSet(org.hisp.dhis.dataset.DataSet) VelocityManager(org.hisp.dhis.system.velocity.VelocityManager)

Example 72 with DataSet

use of org.hisp.dhis.dataset.DataSet in project dhis2-core by dhis2.

the class LockExceptionControllerDocumentation method testGetLockException.

@Test
public void testGetLockException() throws Exception {
    MockHttpSession session = getSession("ALL");
    PeriodType periodType = periodService.getPeriodTypeByName("Monthly");
    Period period = createPeriod(periodType, getDate(2016, 12, 1), getDate(2016, 12, 31));
    manager.save(period);
    OrganisationUnit orgUnit = createOrganisationUnit('B');
    manager.save(orgUnit);
    DataSet dataSet = createDataSet('A', periodType);
    dataSet.addOrganisationUnit(orgUnit);
    manager.save(dataSet);
    LockException lockException = new LockException(period, orgUnit, dataSet);
    dataSetService.addLockException(lockException);
    String getUrl = "/lockExceptions?filter=organisationUnit.id:eq:" + orgUnit.getUid() + "&filter=period:eq:201612&filter=dataSet.id:eq:" + dataSet.getUid();
    Lists.newArrayList(fieldWithPath("period").description("Property"), fieldWithPath("organisationUnit").description("Property"), fieldWithPath("dataSet").description("Property"));
    mvc.perform(get(getUrl).session(session).accept(MediaType.APPLICATION_JSON_UTF8)).andExpect(status().is(200)).andDo(documentPrettyPrint("lockExceptions/get")).andReturn();
}
Also used : PeriodType(org.hisp.dhis.period.PeriodType) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) DataSet(org.hisp.dhis.dataset.DataSet) LockException(org.hisp.dhis.dataset.LockException) MockHttpSession(org.springframework.mock.web.MockHttpSession) Period(org.hisp.dhis.period.Period) Test(org.junit.Test) DhisWebSpringTest(org.hisp.dhis.webapi.DhisWebSpringTest)

Example 73 with DataSet

use of org.hisp.dhis.dataset.DataSet in project dhis2-core by dhis2.

the class LockExceptionControllerDocumentation method testAddLockException.

@Test
public void testAddLockException() throws Exception {
    MockHttpSession session = getSession("ALL");
    PeriodType periodType = periodService.getPeriodTypeByName("Monthly");
    Period period = createPeriod(periodType, getDate(2016, 12, 1), getDate(2016, 12, 31));
    manager.save(period);
    OrganisationUnit orgUnit = createOrganisationUnit('B');
    manager.save(orgUnit);
    DataSet dataSet = createDataSet('A', periodType);
    dataSet.addOrganisationUnit(orgUnit);
    manager.save(dataSet);
    String postUrl = "/lockExceptions?ou=" + orgUnit.getUid() + "&pe=201612&ds=" + dataSet.getUid();
    mvc.perform(post(postUrl).session(session).accept(TestUtils.APPLICATION_JSON_UTF8)).andExpect(status().is(201)).andExpect(content().contentTypeCompatibleWith(TestUtils.APPLICATION_JSON_UTF8)).andDo(documentPrettyPrint("lockExceptions/add"));
}
Also used : PeriodType(org.hisp.dhis.period.PeriodType) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) DataSet(org.hisp.dhis.dataset.DataSet) MockHttpSession(org.springframework.mock.web.MockHttpSession) Period(org.hisp.dhis.period.Period) Test(org.junit.Test) DhisWebSpringTest(org.hisp.dhis.webapi.DhisWebSpringTest)

Example 74 with DataSet

use of org.hisp.dhis.dataset.DataSet in project dhis2-core by dhis2.

the class LockExceptionControllerDocumentation method testDeleteLockException.

@Test
public void testDeleteLockException() throws Exception {
    MockHttpSession session = getSession("ALL");
    PeriodType periodType = periodService.getPeriodTypeByName("Monthly");
    Period period = createPeriod(periodType, getDate(2016, 12, 1), getDate(2016, 12, 31));
    manager.save(period);
    OrganisationUnit orgUnit = createOrganisationUnit('B');
    manager.save(orgUnit);
    DataSet dataSet = createDataSet('A', periodType);
    dataSet.addOrganisationUnit(orgUnit);
    manager.save(dataSet);
    LockException lockException = new LockException(period, orgUnit, dataSet);
    dataSetService.addLockException(lockException);
    String deleteUrl = "/lockExceptions?ou=" + orgUnit.getUid() + "&pe=201612&ds=" + dataSet.getUid();
    mvc.perform(delete(deleteUrl).session(session).accept(TestUtils.APPLICATION_JSON_UTF8)).andExpect(status().isNoContent()).andDo(documentPrettyPrint("lockExceptions/delete"));
}
Also used : PeriodType(org.hisp.dhis.period.PeriodType) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) DataSet(org.hisp.dhis.dataset.DataSet) LockException(org.hisp.dhis.dataset.LockException) MockHttpSession(org.springframework.mock.web.MockHttpSession) Period(org.hisp.dhis.period.Period) Test(org.junit.Test) DhisWebSpringTest(org.hisp.dhis.webapi.DhisWebSpringTest)

Example 75 with DataSet

use of org.hisp.dhis.dataset.DataSet in project dhis2-core by dhis2.

the class DataEntryFormServiceTest method testGetDataEntryFormByName.

@Test
public void testGetDataEntryFormByName() {
    DataSet dataSetA = createDataSet('A', periodType);
    dataSetService.addDataSet(dataSetA);
    DataEntryForm dataEntryForm = createDataEntryForm('A');
    int id = dataEntryFormService.addDataEntryForm(dataEntryForm);
    dataEntryForm = dataEntryFormService.getDataEntryForm(id);
    assertEquals(dataEntryFormService.getDataEntryFormByName("DataEntryFormA"), dataEntryForm);
    assertNull(dataEntryFormService.getDataEntryFormByName("DataEntryFormX"));
}
Also used : DataSet(org.hisp.dhis.dataset.DataSet) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Aggregations

DataSet (org.hisp.dhis.dataset.DataSet)118 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)52 Period (org.hisp.dhis.period.Period)40 Test (org.junit.Test)39 DataElement (org.hisp.dhis.dataelement.DataElement)34 ArrayList (java.util.ArrayList)29 DhisSpringTest (org.hisp.dhis.DhisSpringTest)21 WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)21 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)21 List (java.util.List)20 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)17 User (org.hisp.dhis.user.User)17 DataElementCategoryOptionCombo (org.hisp.dhis.dataelement.DataElementCategoryOptionCombo)16 HashSet (java.util.HashSet)14 DataElementCategoryCombo (org.hisp.dhis.dataelement.DataElementCategoryCombo)14 ClassPathResource (org.springframework.core.io.ClassPathResource)14 UserAuthorityGroup (org.hisp.dhis.user.UserAuthorityGroup)13 ObjectBundleValidationReport (org.hisp.dhis.dxf2.metadata.objectbundle.feedback.ObjectBundleValidationReport)11 PeriodType (org.hisp.dhis.period.PeriodType)11 Date (java.util.Date)9