use of org.hisp.dhis.feedback.ErrorMessage in project dhis2-core by dhis2.
the class EventQueryValidatorTest method validateErrorPage.
@Test
void validateErrorPage() {
EventQueryParams params = new EventQueryParams.Builder().withProgram(prA).withStartDate(new DateTime(2010, 6, 1, 0, 0).toDate()).withEndDate(new DateTime(2012, 3, 20, 0, 0).toDate()).withOrganisationUnits(Lists.newArrayList(ouB)).withPage(-2).build();
ErrorMessage error = queryValidator.validateForErrorMessage(params);
assertEquals(ErrorCode.E7207, error.getErrorCode());
}
use of org.hisp.dhis.feedback.ErrorMessage in project dhis2-core by dhis2.
the class EventQueryValidatorTest method validateDuplicateQueryItems.
@Test
void validateDuplicateQueryItems() {
EventQueryParams params = new EventQueryParams.Builder().withProgram(prA).withStartDate(new DateTime(2010, 6, 1, 0, 0).toDate()).withEndDate(new DateTime(2012, 3, 20, 0, 0).toDate()).withOrganisationUnits(Lists.newArrayList(ouA)).addItem(new QueryItem(deA, prA, null, ValueType.TEXT, AggregationType.NONE, null)).addItem(new QueryItem(deA, prA, null, ValueType.TEXT, AggregationType.NONE, null)).build();
ErrorMessage error = queryValidator.validateForErrorMessage(params);
assertEquals(ErrorCode.E7202, error.getErrorCode());
}
use of org.hisp.dhis.feedback.ErrorMessage in project dhis2-core by dhis2.
the class EventQueryValidatorTest method validateErrorMaxLimit.
@Test
void validateErrorMaxLimit() {
when(systemSettingManager.getIntSetting(SettingKey.ANALYTICS_MAX_LIMIT)).thenReturn(100);
EventQueryParams params = new EventQueryParams.Builder().withProgram(prA).withStartDate(new DateTime(2010, 6, 1, 0, 0).toDate()).withEndDate(new DateTime(2012, 3, 20, 0, 0).toDate()).withOrganisationUnits(Lists.newArrayList(ouB)).withLimit(200).build();
ErrorMessage error = queryValidator.validateForErrorMessage(params);
assertEquals(ErrorCode.E7209, error.getErrorCode());
}
use of org.hisp.dhis.feedback.ErrorMessage in project dhis2-core by dhis2.
the class DefaultDeletionManager method deleteObjects.
private <T> void deleteObjects(T object) {
Class<T> clazz = getClazz(object);
@SuppressWarnings({ "rawtypes", "unchecked" }) Queue<Function<T, DeletionVeto>> vetoHandlers = (Queue) vetoHandlersByType.getOrDefault(clazz, EMPTY);
@SuppressWarnings({ "rawtypes", "unchecked" }) Queue<Consumer<T>> deletionHandlers = (Queue) deletionHandlersByType.getOrDefault(clazz, EMPTY);
if (vetoHandlers.isEmpty() && deletionHandlers.isEmpty()) {
log.debug("No deletion handlers registered, aborting deletion handling");
return;
}
log.debug("Veto handlers detected: " + vetoHandlers.size());
log.debug("Deletion handlers detected: " + deletionHandlers.size());
String className = clazz.getSimpleName();
// ---------------------------------------------------------------------
// Verify that object is allowed to be deleted
// ---------------------------------------------------------------------
String handlerName = "";
try {
for (Function<T, DeletionVeto> handler : vetoHandlers) {
handlerName = handler.toString();
log.debug("Check if allowed using " + handlerName + " for class " + className);
DeletionVeto veto = handler.apply(object);
if (veto.isVetoed()) {
ErrorMessage errorMessage = new ErrorMessage(ErrorCode.E4030, veto.getMessage());
log.debug("Delete was not allowed by " + handlerName + ": " + errorMessage.toString());
throw new DeleteNotAllowedException(errorMessage);
}
}
} catch (DeleteNotAllowedException ex) {
throw ex;
} catch (Exception ex) {
log.error("Deletion failed, veto handler '" + handlerName + "' threw an exception: ", ex);
return;
}
// ---------------------------------------------------------------------
// Delete associated objects
// ---------------------------------------------------------------------
handlerName = "";
try {
for (Consumer<T> handler : deletionHandlers) {
handlerName = handler.toString();
log.debug("Deleting object using " + handlerName + " for class " + className);
handler.accept(object);
}
} catch (Exception ex) {
log.error("Deletion failed, deletion handler '" + handlerName + "' threw an exception: ", ex);
return;
}
log.debug("Deleted objects associated with object of type " + className);
}
use of org.hisp.dhis.feedback.ErrorMessage in project dhis2-core by dhis2.
the class ListGrid method repositionHeaders.
/**
* Re-order the GridHeaders of the given Grid based on the List headers. The
* final Grid will have the all its headers defined in the same order as the
* given List of headers.
*
* @param headers
* @return a Set of indexes that holds the holds the new order
*/
@Override
public Set<Integer> repositionHeaders(final Set<String> headers) {
verifyGridState();
final List<String> gridHeaders = getHeaders().stream().map(GridHeader::getName).collect(toList());
final List<GridHeader> orderedHeaders = new ArrayList<>();
final Set<Integer> newColumnIndexes = new LinkedHashSet<>();
for (final String header : headers) {
if (gridHeaders.contains(header)) {
final int gridHeaderIndex = getIndexOfHeader(header);
orderedHeaders.add(getHeaders().get(gridHeaderIndex));
newColumnIndexes.add(gridHeaderIndex);
} else {
throw new IllegalQueryException(new ErrorMessage(E7230, header));
}
}
replaceHeaders(orderedHeaders);
return newColumnIndexes;
}
Aggregations