<commit_before>package de.rwth.idsg.bikeman.psinterface.rest;

import com.google.common.base.Optional;
import de.rwth.idsg.bikeman.psinterface.Utils;
import de.rwth.idsg.bikeman.psinterface.dto.request.*;
import de.rwth.idsg.bikeman.psinterface.dto.response.AuthorizeConfirmationDTO;
import de.rwth.idsg.bikeman.psinterface.dto.response.BootConfirmationDTO;
import de.rwth.idsg.bikeman.psinterface.dto.response.HeartbeatDTO;
import de.rwth.idsg.bikeman.service.CardAccountService;
import de.rwth.idsg.bikeman.web.rest.exception.DatabaseException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import javax.inject.Inject;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * Created by swam on 31/07/14.
 */

@RestController
@RequestMapping(value = "/psi", produces = MediaType.APPLICATION_JSON_VALUE)
@Slf4j
public class PsiResource {

    @Inject private PsiService psiService;
    @Inject private CardAccountService cardAccountService;

    private static final String BOOT_NOTIFICATION_PATH = "/boot";
    private static final String AUTHORIZE_PATH = "/authorize";
    private static final String HEARTBEAT_PATH = "/heartbeat";
    private static final String ACTIVATE_CARD_PATH = "/activate-card";
    private static final String AVAIL_PEDELECS_PATH = "/available-pedelecs";

    private static final String STATION_STATUS_PATH = "/status/station";
    private static final String PEDELEC_STATUS_PATH = "/status/pedelec";
    private static final String CHARGING_STATUS_PATH = "/status/charging";
    private static final String FIRMWARE_STATUS_PATH = "/status/firmware";
    private static final String LOGS_STATUS_PATH = "/status/logs";

    private static final String TRANSACTION_START_PATH = "/transaction/start";
    private static final String TRANSACTION_STOP_PATH = "/transaction/stop";

    // -------------------------------------------------------------------------
    // Station
    // -------------------------------------------------------------------------

    @RequestMapping(value = BOOT_NOTIFICATION_PATH, method = RequestMethod.POST)
    public BootConfirmationDTO bootNotification(@RequestBody BootNotificationDTO bootNotificationDTO,
                                                HttpServletRequest request) throws DatabaseException {
        String endpointAddress = Utils.getFrom(request);
        log.debug("[From: {}] Received bootNotification {}", endpointAddress, bootNotificationDTO);
        BootConfirmationDTO dto = psiService.handleBootNotification(bootNotificationDTO, endpointAddress);
        log.debug("bootNotification returns {}", dto);
        return dto;
    }

    @RequestMapping(value = HEARTBEAT_PATH, method = RequestMethod.GET)
    public HeartbeatDTO heartbeat(HttpServletRequest request) {
        log.debug("[From: {}] Received heartbeat", Utils.getFrom(request));

        HeartbeatDTO heartbeatDTO = new HeartbeatDTO();
        heartbeatDTO.setTimestamp(Utils.nowInSeconds());
        return heartbeatDTO;
    }

    @RequestMapping(value = AVAIL_PEDELECS_PATH, method = RequestMethod.GET)
    public List<String> getAvailablePedelecs(@RequestParam(value = "cardId", required = false) String cardId, HttpServletRequest request) throws DatabaseException {
        String endpointAddress = Utils.getFrom(request);
        log.debug("[From: {}] Received getAvailablePedelecs", endpointAddress);
        List<String> list = psiService.getAvailablePedelecs(endpointAddress, cardId);
        log.debug("getAvailablePedelecs returns {}", list);
        return list;
    }

    // -------------------------------------------------------------------------
    // User
    // -------------------------------------------------------------------------

    @RequestMapping(value = ACTIVATE_CARD_PATH, method = RequestMethod.POST)
    public AuthorizeConfirmationDTO activateCard(@RequestBody CardActivationDTO cardActivationDTO,
                                                 HttpServletRequest request, HttpServletResponse response) {
        log.info("[From: {}] Received activateCard {}", Utils.getFrom(request), cardActivationDTO);

        Optional<AuthorizeConfirmationDTO> optional = cardAccountService.activateCardAccount(cardActivationDTO);
        if (optional.isPresent()) {
            return optional.get();
        } else {
            response.setStatus(HttpServletResponse.SC_NOT_ACCEPTABLE);
            return null;
        }
    }
<commit_msg>log the cardid<commit_after>package de.rwth.idsg.bikeman.psinterface.rest;

import com.google.common.base.Optional;
import de.rwth.idsg.bikeman.psinterface.Utils;
import de.rwth.idsg.bikeman.psinterface.dto.request.*;
import de.rwth.idsg.bikeman.psinterface.dto.response.AuthorizeConfirmationDTO;
import de.rwth.idsg.bikeman.psinterface.dto.response.BootConfirmationDTO;
import de.rwth.idsg.bikeman.psinterface.dto.response.HeartbeatDTO;
import de.rwth.idsg.bikeman.service.CardAccountService;
import de.rwth.idsg.bikeman.web.rest.exception.DatabaseException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import javax.inject.Inject;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * Created by swam on 31/07/14.
 */

@RestController
@RequestMapping(value = "/psi", produces = MediaType.APPLICATION_JSON_VALUE)
@Slf4j
public class PsiResource {

    @Inject private PsiService psiService;
    @Inject private CardAccountService cardAccountService;

    private static final String BOOT_NOTIFICATION_PATH = "/boot";
    private static final String AUTHORIZE_PATH = "/authorize";
    private static final String HEARTBEAT_PATH = "/heartbeat";
    private static final String ACTIVATE_CARD_PATH = "/activate-card";
    private static final String AVAIL_PEDELECS_PATH = "/available-pedelecs";

    private static final String STATION_STATUS_PATH = "/status/station";
    private static final String PEDELEC_STATUS_PATH = "/status/pedelec";
    private static final String CHARGING_STATUS_PATH = "/status/charging";
    private static final String FIRMWARE_STATUS_PATH = "/status/firmware";
    private static final String LOGS_STATUS_PATH = "/status/logs";

    private static final String TRANSACTION_START_PATH = "/transaction/start";
    private static final String TRANSACTION_STOP_PATH = "/transaction/stop";

    // -------------------------------------------------------------------------
    // Station
    // -------------------------------------------------------------------------

    @RequestMapping(value = BOOT_NOTIFICATION_PATH, method = RequestMethod.POST)
    public BootConfirmationDTO bootNotification(@RequestBody BootNotificationDTO bootNotificationDTO,
                                                HttpServletRequest request) throws DatabaseException {
        String endpointAddress = Utils.getFrom(request);
        log.debug("[From: {}] Received bootNotification {}", endpointAddress, bootNotificationDTO);
        BootConfirmationDTO dto = psiService.handleBootNotification(bootNotificationDTO, endpointAddress);
        log.debug("bootNotification returns {}", dto);
        return dto;
    }

    @RequestMapping(value = HEARTBEAT_PATH, method = RequestMethod.GET)
    public HeartbeatDTO heartbeat(HttpServletRequest request) {
        log.debug("[From: {}] Received heartbeat", Utils.getFrom(request));

        HeartbeatDTO heartbeatDTO = new HeartbeatDTO();
        heartbeatDTO.setTimestamp(Utils.nowInSeconds());
        return heartbeatDTO;
    }

    @RequestMapping(value = AVAIL_PEDELECS_PATH, method = RequestMethod.GET)
    public List<String> getAvailablePedelecs(@RequestParam(value = "cardId", required = false) String cardId,
                                             HttpServletRequest request) throws DatabaseException {
        String endpointAddress = Utils.getFrom(request);
        log.debug("[From: {}] Received getAvailablePedelecs for cardId '{}'", endpointAddress, cardId);
        List<String> list = psiService.getAvailablePedelecs(endpointAddress, cardId);
        log.debug("getAvailablePedelecs returns {}", list);
        return list;
    }

    // -------------------------------------------------------------------------
    // User
    // -------------------------------------------------------------------------

    @RequestMapping(value = ACTIVATE_CARD_PATH, method = RequestMethod.POST)
    public AuthorizeConfirmationDTO activateCard(@RequestBody CardActivationDTO cardActivationDTO,
                                                 HttpServletRequest request, HttpServletResponse response) {
        log.info("[From: {}] Received activateCard {}", Utils.getFrom(request), cardActivationDTO);

        Optional<AuthorizeConfirmationDTO> optional = cardAccountService.activateCardAccount(cardActivationDTO);
        if (optional.isPresent()) {
            return optional.get();
        } else {
            response.setStatus(HttpServletResponse.SC_NOT_ACCEPTABLE);
            return null;
        }
    }

{'fraction_non_alphanumeric': 0.15206521739130435, 'fraction_numerical': 0.001956521739130435, 'mean_word_length': 2.8692178301093354, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1219583', 'n_tokens_mistral': 2393, 'n_tokens_neox': 2391, 'n_words': 481}