Search in sources :

Example 1 with LockException

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

the class GetLockExceptionListAction method execute.

// -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
@Override
public String execute() {
    if (usePaging) {
        paging = createPaging(dataSetService.getLockExceptionCount());
        lockExceptions = new ArrayList<>(dataSetService.getLockExceptionsBetween(paging.getStartPos(), paging.getEndPos()));
    } else {
        lockExceptions = new ArrayList<>(dataSetService.getAllLockExceptions());
    }
    Collections.sort(lockExceptions, new LockExceptionNameComparator());
    for (LockException lockException : lockExceptions) {
        lockException.getPeriod().setName(format.formatPeriod(lockException.getPeriod()));
    }
    return SUCCESS;
}
Also used : LockExceptionNameComparator(org.hisp.dhis.dataset.comparator.LockExceptionNameComparator) LockException(org.hisp.dhis.dataset.LockException)

Example 2 with LockException

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

the class PrepareBatchRemovalAction method execute.

// -------------------------------------------------------------------------
// Action Implementation
// -------------------------------------------------------------------------
@Override
public String execute() throws Exception {
    lockExceptions = new ArrayList<>(dataSetService.getLockExceptionCombinations());
    for (LockException lockException : lockExceptions) {
        lockException.getPeriod().setName(format.formatPeriod(lockException.getPeriod()));
    }
    Collections.sort(lockExceptions, new LockExceptionNameComparator());
    return SUCCESS;
}
Also used : LockExceptionNameComparator(org.hisp.dhis.dataset.comparator.LockExceptionNameComparator) LockException(org.hisp.dhis.dataset.LockException)

Example 3 with LockException

use of org.hisp.dhis.dataset.LockException 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 4 with LockException

use of org.hisp.dhis.dataset.LockException 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 5 with LockException

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

the class LockExceptionController method addLockException.

@RequestMapping(method = RequestMethod.POST)
public void addLockException(@RequestParam("ou") String organisationUnitId, @RequestParam("pe") String periodId, @RequestParam("ds") String dataSetId, HttpServletRequest request, HttpServletResponse response) throws WebMessageException {
    User user = userService.getCurrentUser();
    DataSet dataSet = dataSetService.getDataSet(dataSetId);
    Period period = periodService.reloadPeriod(PeriodType.getPeriodFromIsoString(periodId));
    if (dataSet == null || period == null) {
        throw new WebMessageException(WebMessageUtils.conflict(" DataSet or Period is invalid"));
    }
    if (!aclService.canUpdate(user, dataSet)) {
        throw new ReadAccessDeniedException("You don't have the proper permissions to update this object");
    }
    boolean created = false;
    List<String> listOrgUnitIds = new ArrayList<>();
    if (organisationUnitId.startsWith("[") && organisationUnitId.endsWith("]")) {
        String[] arrOrgUnitIds = organisationUnitId.substring(1, organisationUnitId.length() - 1).split(",");
        Collections.addAll(listOrgUnitIds, arrOrgUnitIds);
    } else {
        listOrgUnitIds.add(organisationUnitId);
    }
    if (listOrgUnitIds.size() == 0) {
        throw new WebMessageException(WebMessageUtils.conflict(" OrganisationUnit ID is invalid."));
    }
    for (String id : listOrgUnitIds) {
        OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit(id);
        if (organisationUnit == null) {
            throw new WebMessageException(WebMessageUtils.conflict("Can't find OrganisationUnit with id =" + id));
        }
        if (organisationUnit.getDataSets().contains(dataSet)) {
            LockException lockException = new LockException();
            lockException.setOrganisationUnit(organisationUnit);
            lockException.setDataSet(dataSet);
            lockException.setPeriod(period);
            dataSetService.addLockException(lockException);
            created = true;
        }
    }
    if (created) {
        webMessageService.send(WebMessageUtils.created("LockException created successfully."), response, request);
    }
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) User(org.hisp.dhis.user.User) DataSet(org.hisp.dhis.dataset.DataSet) WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) LockException(org.hisp.dhis.dataset.LockException) ArrayList(java.util.ArrayList) Period(org.hisp.dhis.period.Period) ReadAccessDeniedException(org.hisp.dhis.hibernate.exception.ReadAccessDeniedException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

LockException (org.hisp.dhis.dataset.LockException)10 DataSet (org.hisp.dhis.dataset.DataSet)6 Period (org.hisp.dhis.period.Period)6 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)5 ArrayList (java.util.ArrayList)4 LockExceptionNameComparator (org.hisp.dhis.dataset.comparator.LockExceptionNameComparator)3 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)3 WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)2 FieldFilterParams (org.hisp.dhis.fieldfilter.FieldFilterParams)2 ReadAccessDeniedException (org.hisp.dhis.hibernate.exception.ReadAccessDeniedException)2 I18nFormat (org.hisp.dhis.i18n.I18nFormat)2 RootNode (org.hisp.dhis.node.types.RootNode)2 PeriodType (org.hisp.dhis.period.PeriodType)2 User (org.hisp.dhis.user.User)2 DhisWebSpringTest (org.hisp.dhis.webapi.DhisWebSpringTest)2 Test (org.junit.Test)2 MockHttpSession (org.springframework.mock.web.MockHttpSession)2 GetMapping (org.springframework.web.bind.annotation.GetMapping)2 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1