Search in sources :

Example 1 with Office

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;
}
Also used : Office(cwms.radar.data.dto.Office) AV_OFFICE(usace.cwms.db.jooq.codegen.tables.AV_OFFICE)

Example 2 with Office

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();
}
Also used : Office(cwms.radar.data.dto.Office)

Example 3 with Office

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");
    }
}
Also used : Office(cwms.radar.data.dto.Office) StringWriter(java.io.StringWriter) JAXBException(javax.xml.bind.JAXBException) InternalServerErrorResponse(io.javalin.http.InternalServerErrorResponse) PrintWriter(java.io.PrintWriter)

Example 4 with Office

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);
}
Also used : SelectJoinStep(org.jooq.SelectJoinStep) Clob(cwms.radar.data.dto.Clob) DSL(org.jooq.impl.DSL) RecordMapper(org.jooq.RecordMapper) DSL.count(org.jooq.impl.DSL.count) Table(org.jooq.Table) Clobs(cwms.radar.data.dto.Clobs) ParamType(org.jooq.conf.ParamType) Condition(org.jooq.Condition) SelectLimitPercentStep(org.jooq.SelectLimitPercentStep) Record4(org.jooq.Record4) SelectConditionStep(org.jooq.SelectConditionStep) Record2(org.jooq.Record2) AV_OFFICE(usace.cwms.db.jooq.codegen.tables.AV_OFFICE) Record1(org.jooq.Record1) DSLContext(org.jooq.DSLContext) Select(org.jooq.Select) AV_CLOB(usace.cwms.db.jooq.codegen.tables.AV_CLOB) DSL.inline(org.jooq.impl.DSL.inline) Record(org.jooq.Record) DSL.asterisk(org.jooq.impl.DSL.asterisk) Logger(java.util.logging.Logger) List(java.util.List) Catalog(cwms.radar.data.dto.Catalog) TableField(org.jooq.TableField) SQLDataType(org.jooq.impl.SQLDataType) Optional(java.util.Optional) Office(cwms.radar.data.dto.Office) AV_CLOB(usace.cwms.db.jooq.codegen.tables.AV_CLOB) AV_OFFICE(usace.cwms.db.jooq.codegen.tables.AV_OFFICE) Clob(cwms.radar.data.dto.Clob) Record2(org.jooq.Record2)

Example 5 with Office

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;
}
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

Office (cwms.radar.data.dto.Office)19 DSLContext (org.jooq.DSLContext)7 List (java.util.List)6 Catalog (cwms.radar.data.dto.Catalog)4 AV_OFFICE (usace.cwms.db.jooq.codegen.tables.AV_OFFICE)4 Timer (com.codahale.metrics.Timer)3 Clob (cwms.radar.data.dto.Clob)3 Clobs (cwms.radar.data.dto.Clobs)3 ContentType (cwms.radar.formatters.ContentType)3 OpenApi (io.javalin.plugin.openapi.annotations.OpenApi)3 Optional (java.util.Optional)3 Logger (java.util.logging.Logger)3 Condition (org.jooq.Condition)3 Record (org.jooq.Record)3 Record1 (org.jooq.Record1)3 Record2 (org.jooq.Record2)3 Record4 (org.jooq.Record4)3 RecordMapper (org.jooq.RecordMapper)3 Select (org.jooq.Select)3 SelectConditionStep (org.jooq.SelectConditionStep)3