Search in sources :

Example 1 with OcppTagRecord

use of jooq.steve.db.tables.records.OcppTagRecord in project steve by RWTH-i5-IDSG.

the class OcppTagsController method getDetails.

@RequestMapping(value = DETAILS_PATH, method = RequestMethod.GET)
public String getDetails(@PathVariable("ocppTagPk") int ocppTagPk, Model model) {
    OcppTagRecord record = ocppTagRepository.getRecord(ocppTagPk);
    OcppTagForm form = new OcppTagForm();
    form.setOcppTagPk(record.getOcppTagPk());
    form.setIdTag(record.getIdTag());
    DateTime expiryDate = record.getExpiryDate();
    if (expiryDate != null) {
        form.setExpiration(expiryDate.toLocalDateTime());
    }
    form.setBlocked(record.getBlocked());
    form.setNote(record.getNote());
    String parentIdTag = record.getParentIdTag();
    if (parentIdTag == null) {
        parentIdTag = ControllerHelper.EMPTY_OPTION;
    }
    form.setParentIdTag(parentIdTag);
    model.addAttribute("inTransaction", record.getInTransaction());
    model.addAttribute("ocppTagForm", form);
    setTags(model);
    return "data-man/ocppTagDetails";
}
Also used : OcppTagRecord(jooq.steve.db.tables.records.OcppTagRecord) OcppTagForm(de.rwth.idsg.steve.web.dto.OcppTagForm) DateTime(org.joda.time.DateTime) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with OcppTagRecord

use of jooq.steve.db.tables.records.OcppTagRecord in project steve by RWTH-i5-IDSG.

the class OcppTagServiceImpl method getIdTagInfo.

@Override
public IdTagInfo getIdTagInfo(String idTag) {
    OcppTagRecord record = ocppTagRepository.getRecord(idTag);
    IdTagInfo idTagInfo = new IdTagInfo();
    if (record == null) {
        log.error("The user with idTag '{}' is INVALID (not present in DB).", idTag);
        idTagInfo.setStatus(AuthorizationStatus.INVALID);
        invalidOcppTagService.processNewUnidentified(idTag);
    } else {
        DateTime expiryDate = record.getExpiryDate();
        boolean isExpiryDateSet = expiryDate != null;
        if (record.getBlocked()) {
            log.error("The user with idTag '{}' is BLOCKED.", idTag);
            idTagInfo.setStatus(AuthorizationStatus.BLOCKED);
        // } else if (record.getInTransaction()) {
        // log.warn("The user with idTag '{}' is ALREADY in another transaction.", idTag);
        // idTagInfo.setStatus(ocpp.cs._2012._06.AuthorizationStatus.CONCURRENT_TX);
        } else if (isExpiryDateSet && DateTime.now().isAfter(record.getExpiryDate())) {
            log.error("The user with idTag '{}' is EXPIRED.", idTag);
            idTagInfo.setStatus(AuthorizationStatus.EXPIRED);
        } else {
            log.debug("The user with idTag '{}' is ACCEPTED.", idTag);
            idTagInfo.setStatus(AuthorizationStatus.ACCEPTED);
            // If the database contains an actual expiry, use it. Otherwise, calculate an expiry for cached info
            DateTime expiry = isExpiryDateSet ? expiryDate : DateTime.now().plusHours(settingsRepository.getHoursToExpire());
            idTagInfo.setExpiryDate(expiry);
            idTagInfo.setParentIdTag(record.getParentIdTag());
        }
    }
    return idTagInfo;
}
Also used : OcppTagRecord(jooq.steve.db.tables.records.OcppTagRecord) IdTagInfo(ocpp.cs._2015._10.IdTagInfo) DateTime(org.joda.time.DateTime)

Aggregations

OcppTagRecord (jooq.steve.db.tables.records.OcppTagRecord)2 DateTime (org.joda.time.DateTime)2 OcppTagForm (de.rwth.idsg.steve.web.dto.OcppTagForm)1 IdTagInfo (ocpp.cs._2015._10.IdTagInfo)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1