use of io.javalin.http.BadRequestResponse in project cwms-radar-api by USACE.
the class JsonV1 method buildFormatting.
private Object buildFormatting(List<? extends CwmsDTO> daoList) {
Object retval = null;
if (daoList != null && !daoList.isEmpty()) {
CwmsDTO firstObj = daoList.get(0);
if (firstObj instanceof Office) {
List<Office> officesList = daoList.stream().map(Office.class::cast).collect(Collectors.toList());
retval = new OfficeFormatV1(officesList);
} else if (dataTypesContains(firstObj.getClass())) {
// If dataType annotated with the class we can return an array of them.
// If a class needs to be handled differently an else_if branch can be added above
// here and a wrapper obj used to format the return value however is desired.
retval = daoList;
}
if (retval == null) {
String klassName = "unknown";
if (firstObj != null) {
klassName = firstObj.getClass().getName();
}
throw new BadRequestResponse(String.format("Format %s not implemented for data of class:%s", getContentType(), klassName));
}
}
return retval;
}
use of io.javalin.http.BadRequestResponse in project cwms-radar-api by USACE.
the class JsonV1 method buildFormatting.
private Object buildFormatting(CwmsDTO dao) {
Object retval = null;
if (dao instanceof Office) {
List<Office> offices = Arrays.asList((Office) dao);
retval = new OfficeFormatV1(offices);
} else if (dataTypesContains(dao.getClass())) {
// Any types that have to be handle as special cases
// should be in else if branches before this
// If the class is in the annotation assume we can just return it.
retval = dao;
}
if (retval == null) {
String klassName = "unknown";
if (dao != null) {
klassName = dao.getClass().getName();
}
throw new BadRequestResponse(String.format("Format %s not implemented for data of class:%s", getContentType(), klassName));
}
return retval;
}
Aggregations