<commit_before>/* $This file is distributed under the terms of the license in /doc/license.txt$ */

package edu.cornell.mannlib.vitro.webapp.edit.n3editing;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.hp.hpl.jena.vocabulary.OWL;

import edu.cornell.mannlib.vitro.webapp.beans.DataProperty;
import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatement;
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
import edu.cornell.mannlib.vitro.webapp.beans.ObjectProperty;
import edu.cornell.mannlib.vitro.webapp.beans.ObjectPropertyStatement;
import edu.cornell.mannlib.vitro.webapp.beans.VClass;
import edu.cornell.mannlib.vitro.webapp.beans.VClassGroup;
import edu.cornell.mannlib.vitro.webapp.dao.DataPropertyDao;
import edu.cornell.mannlib.vitro.webapp.dao.DataPropertyStatementDao;
import edu.cornell.mannlib.vitro.webapp.dao.VClassDao;
import edu.cornell.mannlib.vitro.webapp.dao.VClassGroupDao;
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;

public class SelectListGenerator {
    
    static Log log = LogFactory.getLog(SelectListGenerator.class);
    
    public static Map<String,String> getOptions(
            EditConfiguration editConfig, 
            String fieldName, 
            WebappDaoFactory wDaoFact){
        if( editConfig == null ){
            log.error( "fieldToSelectItemList() must be called with a non-null EditConfiguration ");
            return Collections.EMPTY_MAP;
        }
        if( fieldName == null ){
            log.error( "fieldToSelectItemList() must be called with a non-null fieldName");
            return Collections.EMPTY_MAP;
        }                            
        
        Field field = editConfig.getField(fieldName);
        if (field==null) {
            log.error("no field \""+fieldName+"\" found from editConfig in SelectListGenerator.getOptions()");
            return Collections.EMPTY_MAP;
        }
        // now create an empty HashMap to populate and return
        HashMap <String,String> optionsMap = new HashMap<String,String>();
        // for debugging, keep a count of the number of options populated
        int optionsCount=0;

        Field.OptionsType optionsType = field.getOptionsType();
        String vclassUri = null;
        switch (optionsType){
            case HARDCODED_LITERALS:  // not auto-sorted, and empty values not removed or replaced
                List<List<String>> hardcodedLiteralOptions = field.getLiteralOptions();
                if (hardcodedLiteralOptions==null) {
                    log.error("no literalOptions List found for field \""+fieldName+"\" in SelectListGenerator.getOptions() when OptionsType UNSORTED_LITERALS specified");
                    return new HashMap <String,String>();
                }
                for(Object obj: ((Iterable)hardcodedLiteralOptions)){
                    List<String> literalPair = (List)obj;
                    String value=(String)literalPair.get(0);
                    if( value != null){  // allow empty string as a value
                        String label=(String)literalPair.get(1);<commit_msg>NIHVIVO-799 Use LinkedHashMap in SelectListGenerator so order of HARDCODED_LITERALS select is exactly as specified.<commit_after>/* $This file is distributed under the terms of the license in /doc/license.txt$ */

package edu.cornell.mannlib.vitro.webapp.edit.n3editing;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.ListIterator;
import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.hp.hpl.jena.vocabulary.OWL;

import edu.cornell.mannlib.vitro.webapp.beans.DataProperty;
import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatement;
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
import edu.cornell.mannlib.vitro.webapp.beans.ObjectProperty;
import edu.cornell.mannlib.vitro.webapp.beans.ObjectPropertyStatement;
import edu.cornell.mannlib.vitro.webapp.beans.VClass;
import edu.cornell.mannlib.vitro.webapp.beans.VClassGroup;
import edu.cornell.mannlib.vitro.webapp.dao.DataPropertyDao;
import edu.cornell.mannlib.vitro.webapp.dao.DataPropertyStatementDao;
import edu.cornell.mannlib.vitro.webapp.dao.VClassDao;
import edu.cornell.mannlib.vitro.webapp.dao.VClassGroupDao;
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;

public class SelectListGenerator {
    
    static Log log = LogFactory.getLog(SelectListGenerator.class);
    
    public static Map<String,String> getOptions(
            EditConfiguration editConfig, 
            String fieldName, 
            WebappDaoFactory wDaoFact){
        if( editConfig == null ){
            log.error( "fieldToSelectItemList() must be called with a non-null EditConfiguration ");
            return Collections.EMPTY_MAP;
        }
        if( fieldName == null ){
            log.error( "fieldToSelectItemList() must be called with a non-null fieldName");
            return Collections.EMPTY_MAP;
        }                            
        
        Field field = editConfig.getField(fieldName);
        if (field==null) {
            log.error("no field \""+fieldName+"\" found from editConfig in SelectListGenerator.getOptions()");
            return Collections.EMPTY_MAP;
        }
        // now create an empty HashMap to populate and return
        HashMap <String,String> optionsMap = new LinkedHashMap<String,String>();
        // for debugging, keep a count of the number of options populated
        int optionsCount=0;

        Field.OptionsType optionsType = field.getOptionsType();
        String vclassUri = null;
        switch (optionsType){
            case HARDCODED_LITERALS:  // not auto-sorted, and empty values not removed or replaced
                List<List<String>> hardcodedLiteralOptions = field.getLiteralOptions();
                if (hardcodedLiteralOptions==null) {
                    log.error("no literalOptions List found for field \""+fieldName+"\" in SelectListGenerator.getOptions() when OptionsType UNSORTED_LITERALS specified");
                    return new HashMap <String,String>();
                }
                for(Object obj: ((Iterable)hardcodedLiteralOptions)){
                    List<String> literalPair = (List)obj;
                    String value=(String)literalPair.get(0);
                    if( value != null){  // allow empty string as a value
                        String label=(String)literalPair.get(1);
{'fraction_non_alphanumeric': 0.09652453271028037, 'fraction_numerical': 0.0016063084112149532, 'mean_word_length': 2.927178899082569, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '380044', 'n_tokens_mistral': 2011, 'n_tokens_neox': 1946, 'n_words': 430}