<commit_before>/*
 * Copyright 2006-2008 The Kuali Foundation
 * 
 * Licensed under the Educational Community License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 * http://www.opensource.org/licenses/ecl1.php
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.kuali.kra.questionnaire.question;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.apache.commons.collections.CollectionUtils;
import org.kuali.rice.kns.bo.BusinessObject;
import org.kuali.rice.kns.lookup.HtmlData;
import org.kuali.rice.kns.lookup.KualiLookupableHelperServiceImpl;
import org.kuali.rice.kns.lookup.HtmlData.AnchorHtmlData;
import org.kuali.rice.kns.util.KNSConstants;

import edu.emory.mathcs.backport.java.util.Collections;

public class QuestionLookupableHelperServiceImpl extends KualiLookupableHelperServiceImpl {

    private static final long serialVersionUID = 7936563894902841571L;

    /**
     * Since Question is being versioned, the lookup should only return active versions of the question
     * (the one with the highest sequenceNumber).
     * 
     * @see org.kuali.rice.kns.lookup.KualiLookupableHelperServiceImpl#getSearchResults(java.util.Map)
     */
//    // TODO: cniesen - Code has been temporarily disabled as it does not work correctly.  Until we actually
//    //       version the Question the default getSearchResults() works fine.
//    @Override
//    public List<? extends BusinessObject> getSearchResults(Map<String, String> fieldValues) {
//        
//        return getActiveQuestions(super.getSearchResults(fieldValues));
//    }
    
    @SuppressWarnings("unchecked")
    private List<? extends BusinessObject> getActiveQuestions(List<? extends BusinessObject> searchResults) {

        List<Question> activeQuestions = new ArrayList<Question>();
        List<Integer> questionIds = new ArrayList<Integer>();
        if (CollectionUtils.isNotEmpty(searchResults)) {
            Collections.sort((List<Question>) searchResults, Collections.reverseOrder());
            for (Question question : (List<Question>) searchResults) {
                if (!questionIds.contains(question.getQuestionId())) {
                    activeQuestions.add(question);
                    questionIds.add(question.getQuestionId());
                }
            }
        }
        return activeQuestions;
    }<commit_msg>KCIRB-354<commit_after>/*
 * Copyright 2006-2008 The Kuali Foundation
 * 
 * Licensed under the Educational Community License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 * http://www.opensource.org/licenses/ecl1.php
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.kuali.kra.questionnaire.question;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.apache.commons.collections.CollectionUtils;
import org.kuali.rice.kns.bo.BusinessObject;
import org.kuali.rice.kns.lookup.HtmlData;
import org.kuali.rice.kns.lookup.KualiLookupableHelperServiceImpl;
import org.kuali.rice.kns.lookup.HtmlData.AnchorHtmlData;
import org.kuali.rice.kns.util.KNSConstants;

import edu.emory.mathcs.backport.java.util.Collections;

public class QuestionLookupableHelperServiceImpl extends KualiLookupableHelperServiceImpl {

    private static final long serialVersionUID = 7936563894902841571L;

    /**
     * Since Question is being versioned, the lookup should only return active versions of the question
     * (the one with the highest sequenceNumber).
     * 
     * @see org.kuali.rice.kns.lookup.KualiLookupableHelperServiceImpl#getSearchResults(java.util.Map)
     */
    @Override
    public List<? extends BusinessObject> getSearchResults(Map<String, String> fieldValues) {
        
        return getActiveQuestions(super.getSearchResults(fieldValues));
    }
    
    @SuppressWarnings("unchecked")
    private List<? extends BusinessObject> getActiveQuestions(List<? extends BusinessObject> searchResults) {

        List<Question> activeQuestions = new ArrayList<Question>();
        List<Integer> questionIds = new ArrayList<Integer>();
        if (CollectionUtils.isNotEmpty(searchResults)) {
            Collections.sort((List<Question>) searchResults, Collections.reverseOrder());
            for (Question question : (List<Question>) searchResults) {
                if (!questionIds.contains(question.getQuestionId())) {
                    activeQuestions.add(question);
                    questionIds.add(question.getQuestionId());
                }
            }
        }
        return activeQuestions;
    }
{'fraction_non_alphanumeric': 0.09056532425789374, 'fraction_numerical': 0.01191151446398185, 'mean_word_length': 3.5485812553740326, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 23, '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': '684533', 'n_tokens_mistral': 1463, 'n_tokens_neox': 1386, 'n_words': 392}