<commit_before>{{ header }}

package {{ package_name }};

import {{ package_name }}.fetchers.*;

import net.nuagenetworks.vro.model.fetchers.BaseFetcher;
import net.nuagenetworks.vro.model.BaseObjectExtensions;
import net.nuagenetworks.vro.model.BaseModelHelper;
import net.nuagenetworks.bambou.RestException;
import org.springframework.web.client.HttpClientErrorException;
import java.util.ArrayList;

public class ModelHelper extends BaseModelHelper {

    public static java.util.List<Session> getAllSessions() {
        return SessionManager.getInstance().getSessions();
    }

    public static Session getSessionById(String id) {
        return SessionManager.getInstance().getSessionById(id);
    }
    
    {% for specification in specifications %}
    public static {{ specification.entity_name }} get{{ specification.entity_name }}ById(String id) {
        for (Session session : SessionManager.getInstance().getSessions()) {
            {{ specification.entity_name }} obj = null;
            {%- if specification.is_root %}
            obj = session.get{{ specification.entity_name }}();
            if (obj.getId().equals(id)) {
                return addObject(Constants.{{ specification.entity_name | upper }}, obj);
            }
            {% else %}
            obj = new {{ specification.entity_name }}();
            obj.setId(id);

            try {
                session.fetch(obj);
                return addObject(Constants.{{ specification.entity_name | upper }}, obj);
            } catch (RestException | HttpClientErrorException ex) {
                // Object not found in session
            }

            {% endif %}
        }

        return null;
    }

    {%- for child_api in specification.child_apis %}
    {%- set child_spec = specification_set[child_api.rest_name] %}
    public static {{ child_spec.entity_name_plural }}Fetcher get{{ child_spec.entity_name_plural }}FetcherFor{{ specification.entity_name }}Id(String id) throws RestException {
        {{ specification.entity_name }} obj = getObject(Constants.{{ specification.entity_name | upper }}, id);
        if (obj == null) {
            obj = get{{ specification.entity_name }}ById(id);
        }

        if (obj != null) {
            {{ child_spec.entity_name_plural }}Fetcher fetcher = obj.get{{ child_spec.entity_name_plural }}();
            return addFetcher(Constants.{{ child_spec.entity_name_plural | upper }}_FETCHER, fetcher);
        }

        return null;
    }
    {% endfor -%}

    public static java.util.List<{{ specification.entity_name }}> get{{ specification.entity_name_plural }}ForFetcherId(String id) throws RestException {
        {{ specification.entity_name_plural }}Fetcher fetcher = get{{ specification.entity_name_plural }}FetcherById(id);
        if (fetcher != null) {
            try {
                Session session = fetcher.getSession();
                session.fetch(fetcher);
                return addFetcherObjects(fetcher, Constants.{{ specification.entity_name | upper }});
            } catch (RestException | HttpClientErrorException ex) {
                // Error fetching objects
            }
        }

        return new ArrayList<{{ specification.entity_name }}>();
    }

    public static {{ specification.entity_name_plural }}Fetcher get{{ specification.entity_name_plural }}FetcherById(String id) throws RestException {
        BaseFetcher<? extends BaseObjectExtensions> fetcher = getFetcher(Constants.{{ specification.entity_name_plural | upper }}_FETCHER, id);
        if (fetcher != null) {
            return ({{ specification.entity_name_plural }}Fetcher) fetcher;
        }

        {%- for parent_api in specification.parent_apis %}
        {%- set parent_spec = specification_set[parent_api.rest_name] %}
        {%- if parent_spec is defined %}
        if ((fetcher = get{{ specification.entity_name_plural }}FetcherFor{{ parent_spec.entity_name }}Id(id)) != null) {
            return ({{ specification.entity_name_plural }}Fetcher) addFetcher(Constants.{{ specification.entity_name_plural | upper }}_FETCHER, fetcher);
        }
        {% endif -%}
        {% endfor -%}
        return null;
    }

    public static java.util.List<{{ specification.entity_name }}> getAll{{ specification.entity_name_plural }}() throws RestException {
        java.util.List<{{ specification.entity_name }}> allObjs = new ArrayList<{{ specification.entity_name }}>();
        return allObjs;
    }

    public static java.util.List<{{ specification.entity_name_plural }}Fetcher> getAll{{ specification.entity_name_plural }}Fetchers() throws RestException {
        java.util.List<{{ specification.entity_name_plural }}Fetcher> allObjs = new ArrayList<{{ specification.entity_name_plural }}Fetcher>();
        return allObjs;
    } 
<commit_msg>Added support for findAll() for objects attached to Me root object<commit_after>{{ header }}

package {{ package_name }};

import {{ package_name }}.fetchers.*;

import net.nuagenetworks.vro.model.fetchers.BaseFetcher;
import net.nuagenetworks.vro.model.BaseObjectExtensions;
import net.nuagenetworks.vro.model.BaseModelHelper;
import net.nuagenetworks.bambou.RestException;
import org.springframework.web.client.HttpClientErrorException;
import java.util.ArrayList;

public class ModelHelper extends BaseModelHelper {

    public static java.util.List<Session> getAllSessions() {
        return SessionManager.getInstance().getSessions();
    }

    public static Session getSessionById(String id) {
        return SessionManager.getInstance().getSessionById(id);
    }
    
    {% for specification in specifications %}
    public static {{ specification.entity_name }} get{{ specification.entity_name }}ById(String id) {
        for (Session session : SessionManager.getInstance().getSessions()) {
            {{ specification.entity_name }} obj = null;
            {%- if specification.is_root %}
            obj = session.get{{ specification.entity_name }}();
            if (obj.getId().equals(id)) {
                return addObject(Constants.{{ specification.entity_name | upper }}, obj);
            }
            {% else %}
            obj = new {{ specification.entity_name }}();
            obj.setId(id);

            try {
                session.fetch(obj);
                return addObject(Constants.{{ specification.entity_name | upper }}, obj);
            } catch (RestException | HttpClientErrorException ex) {
                // Object not found in session
            }

            {% endif %}
        }

        return null;
    }

    {%- for child_api in specification.child_apis %}
    {%- set child_spec = specification_set[child_api.rest_name] %}
    public static {{ child_spec.entity_name_plural }}Fetcher get{{ child_spec.entity_name_plural }}FetcherFor{{ specification.entity_name }}Id(String id) throws RestException {
        {{ specification.entity_name }} obj = getObject(Constants.{{ specification.entity_name | upper }}, id);
        if (obj == null) {
            obj = get{{ specification.entity_name }}ById(id);
        }

        if (obj != null) {
            {{ child_spec.entity_name_plural }}Fetcher fetcher = obj.get{{ child_spec.entity_name_plural }}();
            return addFetcher(Constants.{{ child_spec.entity_name_plural | upper }}_FETCHER, fetcher);
        }

        return null;
    }
    {% endfor -%}

    public static java.util.List<{{ specification.entity_name }}> get{{ specification.entity_name_plural }}ForFetcherId(String id) throws RestException {
        {{ specification.entity_name_plural }}Fetcher fetcher = get{{ specification.entity_name_plural }}FetcherById(id);
        if (fetcher != null) {
            try {
                Session session = fetcher.getSession();
                session.fetch(fetcher);
                return addFetcherObjects(fetcher, Constants.{{ specification.entity_name | upper }});
            } catch (RestException | HttpClientErrorException ex) {
                // Error fetching objects
            }
        }

        return new ArrayList<{{ specification.entity_name }}>();
    }

    public static {{ specification.entity_name_plural }}Fetcher get{{ specification.entity_name_plural }}FetcherById(String id) throws RestException {
        BaseFetcher<? extends BaseObjectExtensions> fetcher = getFetcher(Constants.{{ specification.entity_name_plural | upper }}_FETCHER, id);
        if (fetcher != null) {
            return ({{ specification.entity_name_plural }}Fetcher) fetcher;
        }

        {%- for parent_api in specification.parent_apis %}
        {%- set parent_spec = specification_set[parent_api.rest_name] %}
        {%- if parent_spec is defined %}
        if ((fetcher = get{{ specification.entity_name_plural }}FetcherFor{{ parent_spec.entity_name }}Id(id)) != null) {
            return ({{ specification.entity_name_plural }}Fetcher) addFetcher(Constants.{{ specification.entity_name_plural | upper }}_FETCHER, fetcher);
        }
        {% endif -%}
        {% endfor -%}
        return null;
    }

    public static java.util.List<{{ specification.entity_name }}> getAll{{ specification.entity_name_plural }}() throws RestException {
        java.util.List<{{ specification.entity_name }}> allObjs = new ArrayList<{{ specification.entity_name }}>();

        {%- for parent_api in specification.parent_apis %}
        {%- set parent_spec = specification_set[parent_api.rest_name] %}
        {%- if parent_spec is defined and parent_spec.is_root %}
        for (Session session : SessionManager.getInstance().getSessions()) {
            {{ specification.entity_name_plural }}Fetcher fetcher = get{{ specification.entity_name_plural }}FetcherFor{{ parent_spec.entity_name }}Id(session.getId());
            java.util.List<{{ specification.entity_name }}> objs = session.fetch(fetcher);
            allObjs.addAll(objs);
        }
        {% endif -%}
        {% endfor %}

        return allObjs;
    }

    public static java.util.List<{{ specification.entity_name_plural }}Fetcher> getAll{{ specification.entity_name_plural }}Fetchers() throws RestException {
        java.util.List<{{ specification.entity_name_plural }}Fetcher> allObjs = new ArrayList<{{ specification.entity_name_plural }}Fetcher>();
        return allObjs;
    } 

{'fraction_non_alphanumeric': 0.11827119633992018, 'fraction_numerical': 0.0, 'mean_word_length': 2.9258693160106994, 'pattern_counts': {'":': 0, '<': 24, '<?xml version=': 0, '>': 24, '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': '6723017', 'n_tokens_mistral': 2941, 'n_tokens_neox': 2793, 'n_words': 588}