Search in sources :

Example 96 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 97 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 98 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 99 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)

Example 100 with DataSet

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

the class UserRoleObjectBundleHook method postCommit.

@Override
@SuppressWarnings("unchecked")
public void postCommit(ObjectBundle bundle) {
    if (!bundle.getObjectMap().containsKey(UserAuthorityGroup.class))
        return;
    List<IdentifiableObject> objects = bundle.getObjectMap().get(UserAuthorityGroup.class);
    Map<String, Map<String, Object>> userRoleReferences = bundle.getObjectReferences(UserAuthorityGroup.class);
    if (userRoleReferences == null || userRoleReferences.isEmpty()) {
        return;
    }
    for (IdentifiableObject object : objects) {
        object = bundle.getPreheat().get(bundle.getPreheatIdentifier(), object);
        Map<String, Object> userRoleReferenceMap = userRoleReferences.get(object.getUid());
        if (userRoleReferenceMap == null || userRoleReferenceMap.isEmpty()) {
            continue;
        }
        UserAuthorityGroup userRole = (UserAuthorityGroup) object;
        userRole.setDataSets((Set<DataSet>) userRoleReferenceMap.get("dataSets"));
        userRole.setPrograms((Set<Program>) userRoleReferenceMap.get("programs"));
        preheatService.connectReferences(userRole, bundle.getPreheat(), bundle.getPreheatIdentifier());
        sessionFactory.getCurrentSession().update(userRole);
    }
}
Also used : Program(org.hisp.dhis.program.Program) UserAuthorityGroup(org.hisp.dhis.user.UserAuthorityGroup) DataSet(org.hisp.dhis.dataset.DataSet) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject) Map(java.util.Map) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject)

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