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;
}
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;
}
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();
}
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"));
}
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);
}
}
Aggregations