<commit_before>/******************************************************************************
 * TestEGProviderProducer.java - created by aaronz on 12 Mar 2007
 * 
 * Copyright (c) 2008 Centre for Applied Research in Educational Technologies, University of Cambridge
 * Licensed under the Educational Community License version 1.0
 * 
 * A copy of the Educational Community License has been included in this 
 * distribution and is available at: http://www.opensource.org/licenses/ecl1.php
 * 
 * Contributors:
 * <NAME> (<EMAIL>) - primary
 * 
 *****************************************************************************/

package org.sakaiproject.evaluation.tool.producers;

import java.util.Collection;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

import org.sakaiproject.evaluation.logic.EvalCommonLogic;
import org.sakaiproject.evaluation.logic.model.EvalGroup;
import org.sakaiproject.evaluation.providers.EvalGroupsProvider;
import org.sakaiproject.evaluation.tool.renderers.NavBarRenderer;
import org.sakaiproject.evaluation.tool.viewparams.AdminTestEGViewParameters;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

import uk.org.ponder.rsf.components.UIBranchContainer;
import uk.org.ponder.rsf.components.UIContainer;
import uk.org.ponder.rsf.components.UIForm;
import uk.org.ponder.rsf.components.UIInput;
import uk.org.ponder.rsf.components.UIInternalLink;
import uk.org.ponder.rsf.components.UIMessage;
import uk.org.ponder.rsf.components.UIOutput;
import uk.org.ponder.rsf.view.ComponentChecker;
import uk.org.ponder.rsf.view.ViewComponentProducer;
import uk.org.ponder.rsf.viewstate.SimpleViewParameters;
import uk.org.ponder.rsf.viewstate.ViewParameters;
import uk.org.ponder.rsf.viewstate.ViewParamsReporter;

/**
 * Handles the choose existing items view
 * 
 * @author <NAME> (<EMAIL>)
 */
public class AdminTestEGProviderProducer implements ViewComponentProducer, ViewParamsReporter, ApplicationContextAware {

    /**
     * Used for navigation within the system, this must match with the template name
     */
    public static final String VIEW_ID = "admin_test_evalgroup_provider";
    public String getViewID() {
        return VIEW_ID;
    }

    private EvalCommonLogic commonLogic;
    public void setCommonLogic(EvalCommonLogic commonLogic) {
        this.commonLogic = commonLogic;
    }

    // pulling the spring app context, bad bad -AZ
    private ApplicationContext applicationContext;
    public void setApplicationContext(ApplicationContext applicationContext) {
        this.applicationContext = applicationContext;
    }

    private NavBarRenderer navBarRenderer;
    public void setNavBarRenderer(NavBarRenderer navBarRenderer) {
		this.navBarRenderer = navBarRenderer;
	}

    /* (non-Javadoc)
     * @see uk.org.ponder.rsf.view.ComponentProducer#fillComponents(uk.org.ponder.rsf.components.UIContainer, uk.org.ponder.rsf.viewstate.ViewParameters, uk.org.ponder.rsf.view.ComponentChecker)
     */
    public void fillComponents(UIContainer tofill, ViewParameters viewparams, ComponentChecker checker) {

        String warningMessage = "";
        String currentUserId = commonLogic.getCurrentUserId();
        boolean userAdmin = commonLogic.isUserAdmin(currentUserId);
        if (! userAdmin) {
            // Security check and denial
            throw new SecurityException("Non-admin users may not access this page");
        }
        
        navBarRenderer.makeNavBar(tofill, NavBarRenderer.NAV_ELEMENT, this.getViewID());

        // get provider
        EvalGroupsProvider evalGroupsProvider;
        String providerBeanName = EvalGroupsProvider.class.getName();
        if (applicationContext.containsBean(providerBeanName)) {
            evalGroupsProvider = (EvalGroupsProvider) applicationContext.getBean(providerBeanName);
        } else {
            // no provider, die horribly
            UIOutput.make(tofill, "warning-message", "No EvalGroupsProvider found... cannot test...");
            return;
        }

        AdminTestEGViewParameters testViewParameters = (AdminTestEGViewParameters) viewparams;
        String username = testViewParameters.username;
        String evalGroupId = testViewParameters.evalGroupId;
        if (evalGroupId == null || evalGroupId.equals("")) {
            warningMessage += "No evalGroupId set.";
            //UIOutput.make(tofill, "warning-message", warningMessage);
        } else {
            String title = commonLogic.getDisplayTitle(evalGroupId);
            if ("--------".equals(title)) {
                warningMessage += "Invalid evalGroupId ("+evalGroupId+"): cannot find title, reset to null.";
                //UIOutput.make(tofill, "warning-message", warningMessage);
                evalGroupId = null;
            }
        }
        String userId = currentUserId;
        if (username == null || username.equals("")) {
            username = commonLogic.getUserUsername(userId);
            warningMessage += "  No username set: using current user.";
            //UIOutput.make(tofill, "warning-message", warningMessage);
        } else {
            userId = commonLogic.getUserId(username);
            if (userId == null) {
                warningMessage += "  Invalid username ("+username+"): cannot find id, setting to current user id.";
                //UIOutput.make(tofill, "warning-message", warningMessage);
                userId = currentUserId;
            }
        }
        if (warningMessage.length() > 0) {
        	UIOutput.make(tofill, "warning-message", warningMessage);
        }

        UIMessage.make(tofill, "page-title", "admintesteg.page.title");
        UIInternalLink.make(tofill, "summary-link", UIMessage.make("summary.page.title"), 
                new SimpleViewParameters(SummaryProducer.VIEW_ID));
        UIInternalLink.make(tofill, "administrate-link", UIMessage.make("administrate.page.title"), 
                new SimpleViewParameters(AdministrateProducer.VIEW_ID));

        UIMessage.make(tofill, "current_test_header", "admintesteg.current.test.header");
        UIMessage.make(tofill, "current_test_user_header", "admintesteg.current.test.user.header");
        UIOutput.make(tofill, "current_test_user", username);
        UIMessage.make(tofill, "current_test_group_header", "admintesteg.current.test.group.header");
        UIOutput.make(tofill, "current_test_group", evalGroupId);

        // create a copy of the VP (to avoid corrupting the original)
        AdminTestEGViewParameters ategvp = (AdminTestEGViewParameters) testViewParameters.copyBase();
        ategvp.username = username;
        ategvp.evalGroupId = evalGroupId;

        UIForm searchForm = UIForm.make(tofill, "current_test_form", ategvp);
        UIInput.make(searchForm, "current_test_user_input", "#{username}");
        UIInput.make(searchForm, "current_test_group_input", "#{evalGroupId}");<commit_msg>EVALSYS-1018 Test EvalGroup Provider page doesn't display<commit_after>/******************************************************************************
 * TestEGProviderProducer.java - created by aaronz on 12 Mar 2007
 * 
 * Copyright (c) 2008 Centre for Applied Research in Educational Technologies, University of Cambridge
 * Licensed under the Educational Community License version 1.0
 * 
 * A copy of the Educational Community License has been included in this 
 * distribution and is available at: http://www.opensource.org/licenses/ecl1.php
 * 
 * Contributors:
 * <NAME> (<EMAIL>) - primary
 * 
 *****************************************************************************/

package org.sakaiproject.evaluation.tool.producers;

import java.util.Collection;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

import org.sakaiproject.evaluation.logic.EvalCommonLogic;
import org.sakaiproject.evaluation.logic.model.EvalGroup;
import org.sakaiproject.evaluation.providers.EvalGroupsProvider;
import org.sakaiproject.evaluation.tool.renderers.NavBarRenderer;
import org.sakaiproject.evaluation.tool.viewparams.AdminTestEGViewParameters;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

import uk.org.ponder.rsf.components.UIBranchContainer;
import uk.org.ponder.rsf.components.UIContainer;
import uk.org.ponder.rsf.components.UIForm;
import uk.org.ponder.rsf.components.UIInput;
import uk.org.ponder.rsf.components.UIInternalLink;
import uk.org.ponder.rsf.components.UIMessage;
import uk.org.ponder.rsf.components.UIOutput;
import uk.org.ponder.rsf.view.ComponentChecker;
import uk.org.ponder.rsf.view.ViewComponentProducer;
import uk.org.ponder.rsf.viewstate.SimpleViewParameters;
import uk.org.ponder.rsf.viewstate.ViewParameters;
import uk.org.ponder.rsf.viewstate.ViewParamsReporter;

/**
 * Handles the choose existing items view
 * 
 * @author <NAME> (<EMAIL>)
 */
public class AdminTestEGProviderProducer implements ViewComponentProducer, ViewParamsReporter, ApplicationContextAware {

    /**
     * Used for navigation within the system, this must match with the template name
     */
    public static final String VIEW_ID = "admin_test_evalgroup_provider";
    public String getViewID() {
        return VIEW_ID;
    }

    private EvalCommonLogic commonLogic;
    public void setCommonLogic(EvalCommonLogic commonLogic) {
        this.commonLogic = commonLogic;
    }

    // pulling the spring app context, bad bad -AZ
    private ApplicationContext applicationContext;
    public void setApplicationContext(ApplicationContext applicationContext) {
        this.applicationContext = applicationContext;
    }

    private NavBarRenderer navBarRenderer;
    public void setNavBarRenderer(NavBarRenderer navBarRenderer) {
		this.navBarRenderer = navBarRenderer;
	}

    /* (non-Javadoc)
     * @see uk.org.ponder.rsf.view.ComponentProducer#fillComponents(uk.org.ponder.rsf.components.UIContainer, uk.org.ponder.rsf.viewstate.ViewParameters, uk.org.ponder.rsf.view.ComponentChecker)
     */
    public void fillComponents(UIContainer tofill, ViewParameters viewparams, ComponentChecker checker) {

        String warningMessage = "";
        String currentUserId = commonLogic.getCurrentUserId();
        boolean userAdmin = commonLogic.isUserAdmin(currentUserId);
        if (! userAdmin) {
            // Security check and denial
            throw new SecurityException("Non-admin users may not access this page");
        }
        
        navBarRenderer.makeNavBar(tofill, NavBarRenderer.NAV_ELEMENT, this.getViewID());

        // get provider
        EvalGroupsProvider evalGroupsProvider;
        String providerBeanName = EvalGroupsProvider.class.getName();
        if (applicationContext.containsBean(providerBeanName)) {
            evalGroupsProvider = (EvalGroupsProvider) applicationContext.getBean(providerBeanName);
        } else {
            // no provider, die horribly
            UIOutput.make(tofill, "warning-message", "No EvalGroupsProvider found... cannot test...");
            return;
        }

        AdminTestEGViewParameters testViewParameters = (AdminTestEGViewParameters) viewparams;
        String username = testViewParameters.username;
        String evalGroupId = testViewParameters.evalGroupId;
        if (evalGroupId == null || evalGroupId.equals("")) {
            warningMessage += "No evalGroupId set.";
            //UIOutput.make(tofill, "warning-message", warningMessage);
        } else {
            String title = commonLogic.getDisplayTitle(evalGroupId);
            if ("--------".equals(title)) {
                warningMessage += "Invalid evalGroupId ("+evalGroupId+"): cannot find title, reset to null.";
                //UIOutput.make(tofill, "warning-message", warningMessage);
                evalGroupId = null;
            }
        }
        String userId = currentUserId;
        if (username == null || username.equals("")) {
            username = commonLogic.getUserUsername(userId);
            warningMessage += "  No username set: using current user.";
            //UIOutput.make(tofill, "warning-message", warningMessage);
        } else {
            userId = commonLogic.getUserId(username);
            if (userId == null) {
                warningMessage += "  Invalid username ("+username+"): cannot find id, setting to current user id.";
                //UIOutput.make(tofill, "warning-message", warningMessage);
                userId = currentUserId;
            }
        }
        if (warningMessage.length() > 0) {
        	UIOutput.make(tofill, "warning-message", warningMessage);
        }

        UIMessage.make(tofill, "page-title", "admintesteg.page.title");
        UIMessage.make(tofill, "current_test_header", "admintesteg.current.test.header");
        UIMessage.make(tofill, "current_test_user_header", "admintesteg.current.test.user.header");
        UIOutput.make(tofill, "current_test_user", username);
        UIMessage.make(tofill, "current_test_group_header", "admintesteg.current.test.group.header");
        UIOutput.make(tofill, "current_test_group", evalGroupId);

        // create a copy of the VP (to avoid corrupting the original)
        AdminTestEGViewParameters ategvp = (AdminTestEGViewParameters) testViewParameters.copyBase();
        ategvp.username = username;
        ategvp.evalGroupId = evalGroupId;

        UIForm searchForm = UIForm.make(tofill, "current_test_form", ategvp);
        UIInput.make(searchForm, "current_test_user_input", "#{username}");
        UIInput.make(searchForm, "current_test_group_input", "#{evalGroupId}");
{'fraction_non_alphanumeric': 0.12232639906240844, 'fraction_numerical': 0.0023439789041898623, 'mean_word_length': 3.504453975585615, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '3961304', 'n_tokens_mistral': 3805, 'n_tokens_neox': 3690, 'n_words': 779}