<commit_before>package istic.gla.groupeb.flerjeco.springRest;

import android.util.Log;

import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.web.client.HttpStatusCodeException;
import org.springframework.web.client.RestTemplate;

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

import entity.IncidentCode;
import entity.Intervention;
import entity.ResourceType;
import entity.StaticData;

/**
 * Created by amhachi on 08/04/15.
 */
public class SpringService {
    private static final String TAG = SpringService.class.getSimpleName();
    private static final String URL = "http://ns3002211.ip-37-59-58.eu:8080/nivimoju/rest/";

    boolean test = true;

    /**
     * get resource by id
     * @param idRes id of the resource to get
     * @return the resource type retrieved
     */
    public ResourceType getResourceTypeById(Long idRes){

        final String url = URL + "resource/"+idRes;

        RestTemplate restTemplate = new RestTemplate();

        MappingJackson2HttpMessageConverter mappingJackson2HttpMessageConverter = new MappingJackson2HttpMessageConverter();

        restTemplate.getMessageConverters().add(mappingJackson2HttpMessageConverter);

        ResponseEntity<ResourceType> resourcetype = restTemplate.getForEntity(url, ResourceType.class);

        ResourceType rt = resourcetype.getBody();
        return rt;
    }

    /**
     * Get incident codes
     * @return array of IncidentCode
     * @throws HttpStatusCodeException throw exception if status code is bad
     */
    public IncidentCode[] codeSinistreClient() throws HttpStatusCodeException {

        final String url = URL + "incidentcode";

        RestTemplate restTemplate = new RestTemplate();

        MappingJackson2HttpMessageConverter mappingJackson2HttpMessageConverter = new MappingJackson2HttpMessageConverter();

        restTemplate.getMessageConverters().add(mappingJackson2HttpMessageConverter);

        ResponseEntity<IncidentCode[]> incidentCode = restTemplate.getForEntity(url, IncidentCode[].class);

        IncidentCode[] codes = incidentCode.getBody();
        return codes;


    }

    /**
     * Create intervention
     * @param intervention intervention to be created
     * @return id of the intervention created
     */
    public Intervention postIntervention(Intervention intervention) {
        try {

            intervention.updateDate();

            final String url = URL + "intervention/create";

            RestTemplate restTemplate = new RestTemplate();
            restTemplate.getMessageConverters().add(new MappingJackson2HttpMessageConverter());

            ResponseEntity<Intervention> intervetionResult = restTemplate.postForEntity(url, intervention, Intervention.class);

            if (intervetionResult == null) {
                Log.i("MAMH", "intervetionResult = null");
            } else
                return intervetionResult.getBody();
        } catch (HttpStatusCodeException e) {
            Log.i("MAMH", "Problème de la création de l'intervention : " + e.getMessage());
        }
        return null;
    }

    public Intervention updateIntervention(Intervention intervention) {
        try {
            intervention.updateDate();
            final String url = URL + "intervention/update";

            RestTemplate restTemplate = new RestTemplate();
            restTemplate.getMessageConverters().add(new MappingJackson2HttpMessageConverter());

            ResponseEntity<Intervention> intervetionResult = restTemplate.postForEntity(url, intervention, Intervention.class);

            if (intervetionResult == null) {
                Log.i("MAMH", "intervetionResult = null");
            } else
                Log.i(TAG, intervetionResult.toString());
                return intervetionResult.getBody();
        } catch (HttpStatusCodeException e) {
            Log.i("MAMH", "Problème de l'update de l'intervention : " + e.getMessage());
        }
        return null;
    }

    /**
     *
     * @param id
     * @param password
     * @return
     */
    public String login(String id, String password) {
        Log.i(TAG, "login start");
        final String url = URL + "authentication/connected/" + id + "/" + password;
        String httpResult = "";

        RestTemplate restTemplate = new RestTemplate();
        restTemplate.getMessageConverters().add(new MappingJackson2HttpMessageConverter());

        try {
            ResponseEntity<String> entity = restTemplate.getForEntity(url, String.class);
            httpResult = entity.getStatusCode().toString();
        } catch (HttpStatusCodeException e) {
            httpResult = "400";
        }
        Log.i(TAG, "httpResult : " + httpResult);
        Log.i(TAG, "login end");
        return httpResult;
    }

    /**
     * get a notification from server
     * @return intervention to update
     */
    public Intervention getNotify() {
        Log.i(TAG, "notify start");
        final String url = URL + "notify";


        RestTemplate restTemplate = new RestTemplate();
<commit_msg>Commit to merge<commit_after>package istic.gla.groupeb.flerjeco.springRest;

import android.util.Log;

import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.web.client.HttpStatusCodeException;
import org.springframework.web.client.RestTemplate;

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

import entity.IncidentCode;
import entity.Intervention;
import entity.ResourceType;
import entity.StaticData;

/**
 * Created by amhachi on 08/04/15.
 */
public class SpringService {
    private static final String TAG = SpringService.class.getSimpleName();
    private static final String URL = "http://ns3002211.ip-37-59-58.eu:8080/nivimoju/rest/";

    boolean test = true;

    /**
     * get resource by id
     * @param idRes id of the resource to get
     * @return the resource type retrieved
     */
    public ResourceType getResourceTypeById(Long idRes){

        final String url = URL + "resource/"+idRes;

        RestTemplate restTemplate = new RestTemplate();

        MappingJackson2HttpMessageConverter mappingJackson2HttpMessageConverter = new MappingJackson2HttpMessageConverter();

        restTemplate.getMessageConverters().add(mappingJackson2HttpMessageConverter);

        ResponseEntity<ResourceType> resourcetype = restTemplate.getForEntity(url, ResourceType.class);

        ResourceType rt = resourcetype.getBody();
        return rt;
    }

    /**
     * Get incident codes
     * @return array of IncidentCode
     * @throws HttpStatusCodeException throw exception if status code is bad
     */
    public IncidentCode[] codeSinistreClient() throws HttpStatusCodeException {

        final String url = URL + "incidentcode";

        RestTemplate restTemplate = new RestTemplate();

        MappingJackson2HttpMessageConverter mappingJackson2HttpMessageConverter = new MappingJackson2HttpMessageConverter();

        restTemplate.getMessageConverters().add(mappingJackson2HttpMessageConverter);

        ResponseEntity<IncidentCode[]> incidentCode = restTemplate.getForEntity(url, IncidentCode[].class);

        IncidentCode[] codes = incidentCode.getBody();
        return codes;


    }

    /**
     * Create intervention
     * @param intervention intervention to be created
     * @return id of the intervention created
     */
    public Intervention postIntervention(Intervention intervention) {
        try {

            intervention.updateDate();

            final String url = URL + "intervention/create";

            RestTemplate restTemplate = new RestTemplate();
            restTemplate.getMessageConverters().add(new MappingJackson2HttpMessageConverter());

            ResponseEntity<Intervention> intervetionResult = restTemplate.postForEntity(url, intervention, Intervention.class);

            if (intervetionResult == null) {
                Log.i("MAMH", "intervetionResult = null");
            } else
                return intervetionResult.getBody();
        } catch (HttpStatusCodeException e) {
            Log.i("MAMH", "Problème de la création de l'intervention : " + e.getMessage());
        }
        return null;
    }

    public Intervention updateIntervention(Intervention intervention) {
        try {
            intervention.updateDate();
            final String url = URL + "intervention/update";

            RestTemplate restTemplate = new RestTemplate();
            restTemplate.getMessageConverters().add(new MappingJackson2HttpMessageConverter());

            ResponseEntity<Intervention> intervetionResult = restTemplate.postForEntity(url, intervention, Intervention.class);

            if (intervetionResult == null) {
                Log.i("MAMH", "intervetionResult = null");
            } else
                Log.i(TAG, intervetionResult.toString());
                return intervetionResult.getBody();
        } catch (HttpStatusCodeException e) {
            Log.i("MAMH", "Problème de l'update de l'intervention : " + e.getMessage());
        }
        return null;
    }

    /**
     *
     * @param id
     * @param password
     * @return
     */
    public String login(String id, String password) {
        Log.i(TAG, "login start");
        final String url = URL + "authentication/connected/" + id + "/" + password;
        String httpResult = "";

        RestTemplate restTemplate = new RestTemplate();
        restTemplate.getMessageConverters().add(new MappingJackson2HttpMessageConverter());

        try {
            ResponseEntity<String> entity = restTemplate.getForEntity(url, String.class);
            httpResult = entity.getStatusCode().toString();
        } catch (HttpStatusCodeException e) {
            httpResult = "400";
        }
        Log.i(TAG, "httpResult : " + httpResult);
        Log.i(TAG, "login end");
        return httpResult;
    }

    /**
     * get a notification from server
     * @return intervention to update
     */
    public Intervention getNotify() {
        Log.i(TAG, "notify start");
        final String url = URL + "notify";

        RestTemplate restTemplate = new RestTemplate();

{'fraction_non_alphanumeric': 0.0952013131215603, 'fraction_numerical': 0.007338032248720672, 'mean_word_length': 2.8707025411061284, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, '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': '5541831', 'n_tokens_mistral': 2744, 'n_tokens_neox': 2617, 'n_words': 628}