<commit_before>package factories;

import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.JsonNode;
import com.mashape.unirest.http.Unirest;
import com.mashape.unirest.http.exceptions.UnirestException;
import org.json.JSONException;
import org.json.JSONObject;
import pojos.LoggedUser;

import static factories.FactoryConfig.API_VERSION;
import static factories.FactoryConfig.REQUEST_ADDRESS;
import static factories.FactoryConfig.REQUEST_PORT;

/**
 * Created by Bogdanel on 06.06.2017.
 */
public class BidirectionalLoggedUserFactory {

    private static final String FIELD_ID = "id";
    private static final String FIELD_USER_NAME = "userName";

    /**
     * Gets the attributes of a loggedUser from de db service.
     * @param name identifies this loggedUser.
     * @return A new loggedUser instance.
     * @throws UnirestException
     */
    // TODO: Lacks security
    // overload may be added
    public static LoggedUser newInstance(String name) throws UnirestException {
        String url = String.format("http://%s:%s/%s/loggeduser/%s",
                REQUEST_ADDRESS, REQUEST_PORT, API_VERSION, name);

        HttpResponse<JsonNode> response = Unirest.get(url).asJson();
        JSONObject jsonObject = response.getBody().getObject();

        LoggedUser loggedUser = null;
        try {

            loggedUser = new LoggedUser();

            loggedUser.setId(jsonObject.getLong(FIELD_ID));
            loggedUser.setUserName(jsonObject.getString(FIELD_USER_NAME));

        } catch (JSONException e) {
            e.printStackTrace();
        }

        return loggedUser;
    }

    public static void main(String[] args) {

    }

    public static Boolean persist( LoggedUser loggedUser) throws UnirestException {
        String url = String.format("http://%s:%s/%s/loggeduser/",
                REQUEST_ADDRESS, REQUEST_PORT, API_VERSION);

        JSONObject jsonObject = null;
        try {<commit_msg>Added remove method to LoggedUserFactory<commit_after>package factories;

import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.JsonNode;
import com.mashape.unirest.http.Unirest;
import com.mashape.unirest.http.exceptions.UnirestException;
import org.json.JSONException;
import org.json.JSONObject;
import pojos.LoggedUser;

import static factories.FactoryConfig.API_VERSION;
import static factories.FactoryConfig.REQUEST_ADDRESS;
import static factories.FactoryConfig.REQUEST_PORT;

/**
 * Created by Bogdanel on 06.06.2017.
 */
public class BidirectionalLoggedUserFactory {

    private static final String FIELD_ID = "id";
    private static final String FIELD_USER_NAME = "userName";

    /**
     * Gets the attributes of a loggedUser from de db service.
     * @param name identifies this loggedUser.
     * @return A new loggedUser instance.
     * @throws UnirestException
     */
    // TODO: Lacks security
    // overload may be added
    public static LoggedUser newInstance(String name) throws UnirestException {
        String url = String.format("http://%s:%s/%s/loggeduser/%s",
                REQUEST_ADDRESS, REQUEST_PORT, API_VERSION, name);

        HttpResponse<JsonNode> response = Unirest.get(url).asJson();
        JSONObject jsonObject = response.getBody().getObject();

        LoggedUser loggedUser = null;
        try {

            loggedUser = new LoggedUser();

            loggedUser.setId(jsonObject.getLong(FIELD_ID));
            loggedUser.setUserName(jsonObject.getString(FIELD_USER_NAME));

        } catch (JSONException e) {
            e.printStackTrace();
        }

        return loggedUser;
    }

    public static void main(String[] args) {
        LoggedUser user = new LoggedUser(1L, "Cristi");

        try {
            remove(user);
        } catch (UnirestException e) {
            e.printStackTrace();
        }
    }

    public static Boolean remove(LoggedUser loggedUser) throws UnirestException{
        String url = String.format("http://%s:%s/%s/loggeduser/%s",
                REQUEST_ADDRESS, REQUEST_PORT, API_VERSION, loggedUser.getUserName());
        HttpResponse<JsonNode> response = Unirest.delete(url).asJson();

        if(response.getStatus() == 200)
            return Boolean.TRUE;
        return Boolean.FALSE;
    }

    public static Boolean persist( LoggedUser loggedUser) throws UnirestException {
        String url = String.format("http://%s:%s/%s/loggeduser/",
                REQUEST_ADDRESS, REQUEST_PORT, API_VERSION);

        JSONObject jsonObject = null;
        try {
{'fraction_non_alphanumeric': 0.09788359788359788, 'fraction_numerical': 0.004409171075837742, 'mean_word_length': 2.990325417766051, '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': '376864', 'n_tokens_mistral': 1349, 'n_tokens_neox': 1277, 'n_words': 302}