Search in sources :

Example 1 with CwmsDTO

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;
}
Also used : Office(cwms.radar.data.dto.Office) CwmsDTO(cwms.radar.data.dto.CwmsDTO) OfficeFormatV1(cwms.radar.formatters.OfficeFormatV1) BadRequestResponse(io.javalin.http.BadRequestResponse)

Aggregations

CwmsDTO (cwms.radar.data.dto.CwmsDTO)1 Office (cwms.radar.data.dto.Office)1 OfficeFormatV1 (cwms.radar.formatters.OfficeFormatV1)1 BadRequestResponse (io.javalin.http.BadRequestResponse)1