use of cwms.radar.data.dto.Office in project cwms-radar-api by USACE.
the class OfficeDao method getOffices.
public List<Office> getOffices() {
List<Office> retval;
AV_OFFICE view = AV_OFFICE.AV_OFFICE;
// The .as snippets lets it map directly into the Office ctor fields.
retval = dsl.select(view.OFFICE_ID.as("name"), view.LONG_NAME, view.OFFICE_TYPE.as("type"), view.REPORT_TO_OFFICE_ID.as("reportsTo")).from(view).fetch().into(Office.class);
return retval;
}
use of cwms.radar.data.dto.Office in project cwms-radar-api by USACE.
the class TabV1Office method format.
@Override
public String format(CwmsDTO dto) {
Office office = (Office) dto;
StringBuilder builder = new StringBuilder();
builder.append(getOfficeTabHeader()).append("\r\n");
builder.append(officeRow(office));
return builder.toString();
}
use of cwms.radar.data.dto.Office in project cwms-radar-api by USACE.
the class XMLv1 method format.
@Override
public String format(CwmsDTO dto) {
try {
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
if (dto instanceof Office) {
mar.marshal(new XMLv1Office(Arrays.asList((Office) dto)), pw);
return sw.toString();
} else {
mar.marshal(dto, pw);
return sw.toString();
}
} catch (JAXBException jaxb) {
String msg = dto != null ? "Error rendering '" + dto.toString() + "' to XML" : "Null element passed to formatter";
logger.log(Level.WARNING, msg, jaxb);
throw new InternalServerErrorResponse("Invalid Parameters");
}
}
use of cwms.radar.data.dto.Office in project cwms-radar-api by USACE.
the class ClobDao method getAll.
// Yikes, I hate this method - it retrieves all the clobs? That could be gigabytes of data.
// Not returning Value or Desc fields until a useful way of working with this method is figured out.
@Override
public List<Clob> getAll(Optional<String> limitToOffice) {
AV_CLOB ac = AV_CLOB.AV_CLOB;
AV_OFFICE ao = AV_OFFICE.AV_OFFICE;
SelectJoinStep<Record2<String, String>> joinStep = dsl.select(ac.ID, ao.OFFICE_ID).from(ac.join(ao).on(ac.OFFICE_CODE.eq(ao.OFFICE_CODE)));
Select<Record2<String, String>> select = joinStep;
if (limitToOffice.isPresent()) {
String office = limitToOffice.get();
if (office != null && !office.isEmpty()) {
SelectConditionStep<Record2<String, String>> conditionStep = joinStep.where(ao.OFFICE_ID.eq(office));
select = conditionStep;
}
}
RecordMapper<Record2<String, String>, Clob> mapper = joinRecord -> new Clob(joinRecord.get(ao.OFFICE_ID), joinRecord.get(ac.ID), null, null);
return select.fetch(mapper);
}
use of cwms.radar.data.dto.Office 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