<commit_before>package com.telekom.m2m.cot.restsdk.event;

import com.google.gson.Gson;
import com.telekom.m2m.cot.restsdk.CloudOfThingsRestClient;
import com.telekom.m2m.cot.restsdk.util.ExtensibleObject;
import com.telekom.m2m.cot.restsdk.util.Filter;
import com.telekom.m2m.cot.restsdk.util.GsonUtils;

/**
 * Use the Event to work with Events.
 *
 * Created by <NAME> on 04.02.16.
 */
public class EventApi {

    private static final String CONTENT_TYPE = "application/vnd.com.nsn.cumulocity.event+json;charset=UTF-8;ver=0.9";
    private static final String ACCEPT = "application/vnd.com.nsn.cumulocity.event+json;charset=UTF-8;ver=0.9";
    private static final String RELATIVE_API_URL = "event/events/";

    private final Gson gson = GsonUtils.createGson();
    private final CloudOfThingsRestClient cloudOfThingsRestClient;

    /**
     * Internal Constructor.
     *
     * @param cloudOfThingsRestClient the configured rest client.
     */
    public EventApi(CloudOfThingsRestClient cloudOfThingsRestClient) {
        this.cloudOfThingsRestClient = cloudOfThingsRestClient;
    }

    /**
     * Retrieves a specific Event.
     *
     * @param eventId the unique identifier of the desired Event.
     * @return the Event (or null if not found).
     */
    public Event getEvent(String eventId) {
        String response = cloudOfThingsRestClient.getResponse(eventId, RELATIVE_API_URL, CONTENT_TYPE);
        if (response == null) {
            return null;
        }

        return new Event(gson.fromJson(response, ExtensibleObject.class));
    }

    /**
     * Stores an Event.
     *
     * @param event the event to create.
     * @return the created event with the assigned unique identifier.
     */
    public Event createEvent(Event event) {
        String json = gson.toJson(event);

        String id = cloudOfThingsRestClient.doRequestWithIdResponse(json, RELATIVE_API_URL, CONTENT_TYPE, ACCEPT);
        event.setId(id);

        return event;
    }

    /**
     * Deletes an Event.
     *
     * @param event the Event to delete
     */
    public void deleteEvent(Event event) {
        cloudOfThingsRestClient.delete(event.getId(), RELATIVE_API_URL);
    }

    /**
     * Retrieves Events.
     *
     * @return the found Events.
     */
    public EventCollection getEvents() {
        return new EventCollection(
                cloudOfThingsRestClient,
                RELATIVE_API_URL,
                gson,
                null);
    }

    /**
     * Retrieves Events filtered by criteria.
     *
     * @param filters filters of event attributes.
     * @return the EventCollections to navigate through the results.
     * @since 0.2.0
     */
    public EventCollection getEvents(Filter.FilterBuilder filters) {
        return new EventCollection(
                cloudOfThingsRestClient,
                RELATIVE_API_URL,
                gson,
                filters);
    }

    /**
     * Deletes a collection of Events by criteria.
     *
     * @param filters filters of Event attributes.
     */
    public void deleteEvents(Filter.FilterBuilder filters) {
        cloudOfThingsRestClient.delete("", RELATIVE_API_URL + "?" + filters.buildFilter() + "&x=");
    }
}<commit_msg>add support for checking accepted filters in EventApi<commit_after>package com.telekom.m2m.cot.restsdk.event;

import com.google.gson.Gson;
import com.telekom.m2m.cot.restsdk.CloudOfThingsRestClient;
import com.telekom.m2m.cot.restsdk.util.ExtensibleObject;
import com.telekom.m2m.cot.restsdk.util.Filter;
import com.telekom.m2m.cot.restsdk.util.FilterBy;
import com.telekom.m2m.cot.restsdk.util.GsonUtils;

import java.util.Arrays;
import java.util.List;

/**
 * Use the Event to work with Events.
 *
 * Created by <NAME> on 04.02.16.
 */
public class EventApi {

    private static final String CONTENT_TYPE = "application/vnd.com.nsn.cumulocity.event+json;charset=UTF-8;ver=0.9";
    private static final String ACCEPT = "application/vnd.com.nsn.cumulocity.event+json;charset=UTF-8;ver=0.9";
    private static final String RELATIVE_API_URL = "event/events/";
    private static final List<FilterBy> acceptedFilters = Arrays.asList(FilterBy.BYTYPE, FilterBy.BYSOURCE, FilterBy.BYDATETO, FilterBy.BYDATEFROM, FilterBy.BYFRAGMENTTYPE);

    private final Gson gson = GsonUtils.createGson();
    private final CloudOfThingsRestClient cloudOfThingsRestClient;

    /**
     * Internal Constructor.
     *
     * @param cloudOfThingsRestClient the configured rest client.
     */
    public EventApi(CloudOfThingsRestClient cloudOfThingsRestClient) {
        this.cloudOfThingsRestClient = cloudOfThingsRestClient;
    }

    /**
     * Retrieves a specific Event.
     *
     * @param eventId the unique identifier of the desired Event.
     * @return the Event (or null if not found).
     */
    public Event getEvent(String eventId) {
        String response = cloudOfThingsRestClient.getResponse(eventId, RELATIVE_API_URL, CONTENT_TYPE);
        if (response == null) {
            return null;
        }

        return new Event(gson.fromJson(response, ExtensibleObject.class));
    }

    /**
     * Stores an Event.
     *
     * @param event the event to create.
     * @return the created event with the assigned unique identifier.
     */
    public Event createEvent(Event event) {
        String json = gson.toJson(event);

        String id = cloudOfThingsRestClient.doRequestWithIdResponse(json, RELATIVE_API_URL, CONTENT_TYPE, ACCEPT);
        event.setId(id);

        return event;
    }

    /**
     * Deletes an Event.
     *
     * @param event the Event to delete
     */
    public void deleteEvent(Event event) {
        cloudOfThingsRestClient.delete(event.getId(), RELATIVE_API_URL);
    }

    /**
     * Retrieves Events.
     *
     * @return the found Events.
     */
    public EventCollection getEvents() {
        return new EventCollection(
                cloudOfThingsRestClient,
                RELATIVE_API_URL,
                gson,
                null);
    }

    /**
     * Retrieves Events filtered by criteria.
     *
     * @param filters filters of event attributes.
     * @return the EventCollections to navigate through the results.
     * @since 0.2.0
     */
    public EventCollection getEvents(Filter.FilterBuilder filters) {
        if(filters != null)
            filters.testSupportedFilter(acceptedFilters);
        return new EventCollection(
                cloudOfThingsRestClient,
                RELATIVE_API_URL,
                gson,
                filters);
    }

    /**
     * Deletes a collection of Events by criteria.
     *
     * @param filters filters of Event attributes.
     */
    public void deleteEvents(Filter.FilterBuilder filters) {
        if(filters != null)
            filters.testSupportedFilter(acceptedFilters);
        cloudOfThingsRestClient.delete("", RELATIVE_API_URL + "?" + filters.buildFilter() + "&x=");
    }
}
{'fraction_non_alphanumeric': 0.0941329104800346, 'fraction_numerical': 0.005910335880063428, 'mean_word_length': 2.572605561277034, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, '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': '7319630', 'n_tokens_mistral': 2141, 'n_tokens_neox': 2019, 'n_words': 477}