<commit_before>package com.sequenceiq.periscope.rest.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.sequenceiq.periscope.domain.MetricAlarm;
import com.sequenceiq.periscope.domain.TimeAlarm;
import com.sequenceiq.periscope.rest.converter.MetricAlarmConverter;
import com.sequenceiq.periscope.rest.converter.TimeAlarmConverter;
import com.sequenceiq.periscope.rest.json.MetricAlarmJson;
import com.sequenceiq.periscope.rest.json.MetricAlarmsJson;
import com.sequenceiq.periscope.rest.json.TimeAlarmJson;
import com.sequenceiq.periscope.rest.json.TimeAlarmsJson;
import com.sequenceiq.periscope.service.AlarmService;
import com.sequenceiq.periscope.service.ClusterNotFoundException;

@RestController
@RequestMapping("/clusters/{clusterId}/alarms")
public class AlarmController {

    @Autowired
    private AlarmService alarmService;
    @Autowired
    private MetricAlarmConverter metricAlarmConverter;
    @Autowired
    private TimeAlarmConverter timeAlarmConverter;

    @RequestMapping(method = RequestMethod.POST)
    public ResponseEntity<MetricAlarmsJson> createAlarms(@PathVariable long clusterId, @RequestBody MetricAlarmsJson json)
            throws ClusterNotFoundException {
        List<MetricAlarm> metricAlarms = metricAlarmConverter.convertAllFromJson(json.getAlarms());
        return createAlarmsResponse(alarmService.setAlarms(clusterId, metricAlarms), HttpStatus.CREATED);
    }

    @RequestMapping(method = RequestMethod.PUT)
    public ResponseEntity<MetricAlarmsJson> addAlarm(@PathVariable long clusterId, @RequestBody MetricAlarmJson json)
            throws ClusterNotFoundException {
        MetricAlarm metricAlarm = metricAlarmConverter.convert(json);
        return createAlarmsResponse(alarmService.addAlarm(clusterId, metricAlarm), HttpStatus.CREATED);
    }

    @RequestMapping(method = RequestMethod.GET)
    public ResponseEntity<MetricAlarmsJson> getAlarms(@PathVariable long clusterId) throws ClusterNotFoundException {
        return createAlarmsResponse(alarmService.getAlarms(clusterId));
    }

    @RequestMapping(value = "/{alarmId}", method = RequestMethod.DELETE)
    public ResponseEntity<MetricAlarmsJson> deleteAlarm(@PathVariable long clusterId, @PathVariable long alarmId)
            throws ClusterNotFoundException {
        return createAlarmsResponse(alarmService.deleteAlarm(clusterId, alarmId));
    }

    @RequestMapping(value = "/time", method = RequestMethod.POST)
    public ResponseEntity<TimeAlarmsJson> createTimeAlarms(@PathVariable long clusterId, @RequestBody TimeAlarmsJson json)
            throws ClusterNotFoundException {
        List<TimeAlarm> alarms = timeAlarmConverter.convertAllFromJson(json.getAlarms());
        return createTimeAlarmsResponse(alarmService.setTimeAlarms(clusterId, alarms), HttpStatus.CREATED);
    }

    private ResponseEntity<MetricAlarmsJson> createAlarmsResponse(List<MetricAlarm> metricAlarms) {
        return createAlarmsResponse(metricAlarms, HttpStatus.OK);
    }

    private ResponseEntity<MetricAlarmsJson> createAlarmsResponse(List<MetricAlarm> metricAlarms, HttpStatus status) {
        List<MetricAlarmJson> alarmResponse = metricAlarmConverter.convertAllToJson(metricAlarms);
        return new ResponseEntity<>(new MetricAlarmsJson(alarmResponse), status);
    }

    private ResponseEntity<TimeAlarmsJson> createTimeAlarmsResponse(List<TimeAlarm> alarms) {
        return createTimeAlarmsResponse(alarms, HttpStatus.OK);
    }

    private ResponseEntity<TimeAlarmsJson> createTimeAlarmsResponse(List<TimeAlarm> alarms, HttpStatus status) {
        List<TimeAlarmJson> alarmResponse = timeAlarmConverter.convertAllToJson(alarms);
        return new ResponseEntity<>(new TimeAlarmsJson(alarmResponse), status);
    }
}<commit_msg>PERI-7 extend time based alarms REST api<commit_after>package com.sequenceiq.periscope.rest.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.sequenceiq.periscope.domain.MetricAlarm;
import com.sequenceiq.periscope.domain.TimeAlarm;
import com.sequenceiq.periscope.rest.converter.MetricAlarmConverter;
import com.sequenceiq.periscope.rest.converter.TimeAlarmConverter;
import com.sequenceiq.periscope.rest.json.MetricAlarmJson;
import com.sequenceiq.periscope.rest.json.MetricAlarmsJson;
import com.sequenceiq.periscope.rest.json.TimeAlarmJson;
import com.sequenceiq.periscope.rest.json.TimeAlarmsJson;
import com.sequenceiq.periscope.service.AlarmService;
import com.sequenceiq.periscope.service.ClusterNotFoundException;

@RestController
@RequestMapping("/clusters/{clusterId}/alarms")
public class AlarmController {

    @Autowired
    private AlarmService alarmService;
    @Autowired
    private MetricAlarmConverter metricAlarmConverter;
    @Autowired
    private TimeAlarmConverter timeAlarmConverter;

    @RequestMapping(method = RequestMethod.POST)
    public ResponseEntity<MetricAlarmsJson> createAlarms(@PathVariable long clusterId, @RequestBody MetricAlarmsJson json)
            throws ClusterNotFoundException {
        List<MetricAlarm> metricAlarms = metricAlarmConverter.convertAllFromJson(json.getAlarms());
        return createAlarmsResponse(alarmService.setAlarms(clusterId, metricAlarms), HttpStatus.CREATED);
    }

    @RequestMapping(method = RequestMethod.PUT)
    public ResponseEntity<MetricAlarmsJson> addAlarm(@PathVariable long clusterId, @RequestBody MetricAlarmJson json)
            throws ClusterNotFoundException {
        MetricAlarm metricAlarm = metricAlarmConverter.convert(json);
        return createAlarmsResponse(alarmService.addAlarm(clusterId, metricAlarm), HttpStatus.CREATED);
    }

    @RequestMapping(method = RequestMethod.GET)
    public ResponseEntity<MetricAlarmsJson> getAlarms(@PathVariable long clusterId) throws ClusterNotFoundException {
        return createAlarmsResponse(alarmService.getAlarms(clusterId));
    }

    @RequestMapping(value = "/{alarmId}", method = RequestMethod.DELETE)
    public ResponseEntity<MetricAlarmsJson> deleteAlarm(@PathVariable long clusterId, @PathVariable long alarmId)
            throws ClusterNotFoundException {
        return createAlarmsResponse(alarmService.deleteAlarm(clusterId, alarmId));
    }

    @RequestMapping(value = "/time", method = RequestMethod.POST)
    public ResponseEntity<TimeAlarmsJson> createTimeAlarms(@PathVariable long clusterId, @RequestBody TimeAlarmsJson json)
            throws ClusterNotFoundException {
        List<TimeAlarm> alarms = timeAlarmConverter.convertAllFromJson(json.getAlarms());
        return createTimeAlarmsResponse(alarmService.setTimeAlarms(clusterId, alarms), HttpStatus.CREATED);
    }

    @RequestMapping(value = "/time", method = RequestMethod.GET)
    public ResponseEntity<TimeAlarmsJson> getTimeAlarms(@PathVariable long clusterId) throws ClusterNotFoundException {
        return createTimeAlarmsResponse(alarmService.getTimeAlarms(clusterId));
    }

    @RequestMapping(value = "/time/{alarmId}", method = RequestMethod.DELETE)
    public ResponseEntity<TimeAlarmsJson> deleteTimeAlarm(@PathVariable long clusterId, @PathVariable long alarmId)
            throws ClusterNotFoundException {
        return createTimeAlarmsResponse(alarmService.deleteTimeAlarm(clusterId, alarmId));
    }

    @RequestMapping(value = "/time", method = RequestMethod.PUT)
    public ResponseEntity<TimeAlarmsJson> addTimeAlarm(@PathVariable long clusterId, @RequestBody TimeAlarmJson json)
            throws ClusterNotFoundException {
        TimeAlarm timeAlarm = timeAlarmConverter.convert(json);
        return createTimeAlarmsResponse(alarmService.addTimeAlarm(clusterId, timeAlarm), HttpStatus.CREATED);
    }

    private ResponseEntity<MetricAlarmsJson> createAlarmsResponse(List<MetricAlarm> metricAlarms) {
        return createAlarmsResponse(metricAlarms, HttpStatus.OK);
    }

    private ResponseEntity<MetricAlarmsJson> createAlarmsResponse(List<MetricAlarm> metricAlarms, HttpStatus status) {
        List<MetricAlarmJson> alarmResponse = metricAlarmConverter.convertAllToJson(metricAlarms);
        return new ResponseEntity<>(new MetricAlarmsJson(alarmResponse), status);
    }

    private ResponseEntity<TimeAlarmsJson> createTimeAlarmsResponse(List<TimeAlarm> alarms) {
        return createTimeAlarmsResponse(alarms, HttpStatus.OK);
    }

    private ResponseEntity<TimeAlarmsJson> createTimeAlarmsResponse(List<TimeAlarm> alarms, HttpStatus status) {
        List<TimeAlarmJson> alarmResponse = timeAlarmConverter.convertAllToJson(alarms);
        return new ResponseEntity<>(new TimeAlarmsJson(alarmResponse), status);
    }
}
{'fraction_non_alphanumeric': 0.08276153277736725, 'fraction_numerical': 0.00010556317956296844, 'mean_word_length': 5.657765284609979, 'pattern_counts': {'":': 0, '<': 44, '<?xml version=': 0, '>': 44, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1921068', 'n_tokens_mistral': 2572, 'n_tokens_neox': 2542, 'n_words': 429}