use of cwms.radar.data.dto.CwmsDTO 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;
}
Aggregations