<commit_before><%@ page import="com.imcode.entities.Person,
                 com.imcode.entities.Application" pageEncoding="UTF-8" %>
<%@ page import="com.imcode.entities.enums.StatementStatus" %>
<%@ page import="com.imcode.services.ApplicationService" %>
<%@ page import="imcode.server.Imcms" %>
<%@ page import="imcode.services.IvisServiceFactory" %>
<%@ page import="imcode.services.utils.IvisOAuth2Utils" %>
<%@ page import="org.apache.commons.lang3.StringUtils" %>
<%@ page import="org.springframework.security.oauth2.client.resource.UserRedirectRequiredException" %>
<%@ page import="java.util.LinkedList" %>
<%@ page import="java.util.List" %>

<%@taglib prefix="imcms" uri="imcms" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt" %>
<imcms:variables/>
<jsp:include page="ivis_header.jsp"/>

<%
    request.setAttribute("statementStatusEnum", StatementStatus.values());
    //    DefaultIvisServiceFactory factory = IvisOAuth2Utils.getServiceFactory(request);
//
    if (IvisOAuth2Utils.isTokenGood(request)) {
//        request.setAttribute("isAuthorized");
//    if (factory != null) {
//        ApplicationService service = factory.getStatementService();
        IvisServiceFactory factory = IvisOAuth2Utils.getServiceFactory(request);
        ApplicationService service = factory.getService(ApplicationService.class);
//    List<Application> statements = null;
//    try {
//        statements = service.findAll();
////    } catch (UserRedirectRequiredException e) {
//    } catch (Exception e) {
//        IvisOAuth2Utils.setAccessToken(session, null);
//        response.sendRedirect(Imcms.getServerProperties().getProperty("StatementsAddress"));
//        return;
//    }
//    request.setAttribute("statements", statement);
        String searchText = request.getParameter("searchText");
        StatementStatus statusFilter = null;
        try {
            statusFilter = StatementStatus.valueOf(request.getParameter("statusFilter"));
        } catch (Exception ignore) { }

        List<Application> applicationList = null;
        try {
            List<Application> applications = service.findAll();
            applicationList = new LinkedList<Application>();

            for (Application statement : applications) {
                if (statusFilter != null && statement.getStatus() != statusFilter)
                    continue;

                if (searchText != null && StringUtils.isNoneEmpty(searchText)) {
                    Person pupilPerson = statement.getPupil() != null ? statement.getPupil().getPerson():null;
                    Person submittedPerson = statement.getSubmittedPerson();
                    if (!IvisOAuth2Utils.personContainsString(pupilPerson, searchText) && !IvisOAuth2Utils.personContainsString(submittedPerson, searchText))
                        continue;
                }

                applicationList.add(statement);
            }


        } catch (UserRedirectRequiredException e) {
            IvisOAuth2Utils.setAccessToken(session, null);
            response.sendRedirect(Imcms.getServerProperties().getProperty("ClientAddress") + "/servlet/StartDoc?meta_id=" + viewing.getTextDocument().getId());
            return;
        }
        request.setAttribute("statements", applicationList);
    }
%>
<c:if test="${isAuthorized}">
<h1>Applications</h1>
<commit_msg>commit<commit_after><%@ page import="com.imcode.entities.Person,
                 com.imcode.entities.Application" pageEncoding="UTF-8" %>
<%@ page import="com.imcode.entities.enums.StatementStatus" %>
<%@ page import="com.imcode.services.ApplicationService" %>
<%@ page import="imcode.server.Imcms" %>
<%@ page import="imcode.services.IvisServiceFactory" %>
<%@ page import="imcode.services.utils.IvisOAuth2Utils" %>
<%@ page import="org.apache.commons.lang3.StringUtils" %>
<%@ page import="org.springframework.security.oauth2.client.resource.UserRedirectRequiredException" %>
<%@ page import="java.util.LinkedList" %>
<%@ page import="java.util.List" %>
<%@ page import="java.util.Collections" %>
<%@ page import="java.util.Comparator" %>

<%@taglib prefix="imcms" uri="imcms" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt" %>
<imcms:variables/>
<jsp:include page="ivis_header.jsp"/>

<%
    request.setAttribute("statementStatusEnum", StatementStatus.values());
    //    DefaultIvisServiceFactory factory = IvisOAuth2Utils.getServiceFactory(request);
//
    if (IvisOAuth2Utils.isTokenGood(request)) {
//        request.setAttribute("isAuthorized");
//    if (factory != null) {
//        ApplicationService service = factory.getStatementService();
        IvisServiceFactory factory = IvisOAuth2Utils.getServiceFactory(request);
        ApplicationService service = factory.getService(ApplicationService.class);
//    List<Application> statements = null;
//    try {
//        statements = service.findAll();
////    } catch (UserRedirectRequiredException e) {
//    } catch (Exception e) {
//        IvisOAuth2Utils.setAccessToken(session, null);
//        response.sendRedirect(Imcms.getServerProperties().getProperty("StatementsAddress"));
//        return;
//    }
//    request.setAttribute("statements", statement);
        String searchText = request.getParameter("searchText");
        StatementStatus statusFilter = null;
        try {
            statusFilter = StatementStatus.valueOf(request.getParameter("statusFilter"));
        } catch (Exception ignore) { }

        List<Application> applicationList = null;
        try {
            List<Application> applications = service.findAll();
            applicationList = new LinkedList<Application>();

            for (Application statement : applications) {
                if (statusFilter != null && statement.getStatus() != statusFilter)
                    continue;

                if (searchText != null && StringUtils.isNoneEmpty(searchText)) {
                    Person pupilPerson = statement.getPupil() != null ? statement.getPupil().getPerson():null;
                    Person submittedPerson = statement.getSubmittedPerson();
                    if (!IvisOAuth2Utils.personContainsString(pupilPerson, searchText) && !IvisOAuth2Utils.personContainsString(submittedPerson, searchText))
                        continue;
                }

                applicationList.add(statement);
            }
            Collections.sort(applicationList, new Comparator<Application>() {
                @Override
                public int compare(Application o1, Application o2) {
                    return -Long.compare(o1.getId(), o2.getId());
                }
            });

        } catch (UserRedirectRequiredException e) {
            IvisOAuth2Utils.setAccessToken(session, null);
            response.sendRedirect(Imcms.getServerProperties().getProperty("ClientAddress") + "/servlet/StartDoc?meta_id=" + viewing.getTextDocument().getId());
            return;
        }
        request.setAttribute("statements", applicationList);
    }
%>
<c:if test="${isAuthorized}">
<h1>Applications</h1>

{'fraction_non_alphanumeric': 0.14048549107142858, 'fraction_numerical': 0.004185267857142857, 'mean_word_length': 3.1343713956170705, 'pattern_counts': {'":': 0, '<': 52, '<?xml version=': 0, '>': 52, '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': '5045663', 'n_tokens_mistral': 1993, 'n_tokens_neox': 1904, 'n_words': 293}