<commit_before>package org.commcare.suite.model;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.util.Hashtable;
import java.util.Vector;

import org.javarosa.core.reference.RootTranslator;
import org.javarosa.core.services.PropertyManager;
import org.javarosa.core.services.storage.Persistable;
import org.javarosa.core.util.externalizable.DeserializationException;
import org.javarosa.core.util.externalizable.ExtUtil;
import org.javarosa.core.util.externalizable.ExtWrapList;
import org.javarosa.core.util.externalizable.ExtWrapMap;
import org.javarosa.core.util.externalizable.PrototypeFactory;

/**
 * <p>
 * Profile is a model which defines the operating profile
 * of a CommCare application. An applicaiton's profile
 * defines what CommCare features should be activated,
 * certain properties which should be defined, and 
 * any JavaRosa URI reference roots which should be
 * available.</p>
 * 
 * 
 * @author ctsims
 *
 */

public class Profile implements Persistable {
	
	public static final String STORAGE_KEY = "PROFILE";
	
	public static final String FEATURE_REVIEW = "checkoff";
	
	int recordId = -1;
	int version;
	String authRef;
	Vector<PropertySetter> properties;
	Vector<RootTranslator> roots;
	
	Hashtable<String,Boolean> featureStatus;
	
	/**
	 * Serialization Only!
	 */
	public Profile() {
		
	}
	
	/**
	 * Creates an application profile with the provided
	 * version and authoritative reference URI. 
	 * 
	 * @param version The version of this profile which
	 * is represented by this definition.
	 * 
	 * @param authRef A URI which represents the authoritative
	 * source of this profile's master definition. If the 
	 * profile definition read at this URI claims a higher
	 * version number than this profile's version, this profile
	 * is obsoleted by it. 
	 * 
	 */
	public Profile(int version, String authRef) {
		this.version = version;
		this.authRef = authRef;
		properties = new Vector<PropertySetter>();
		roots = new Vector<RootTranslator>();
		featureStatus = new Hashtable<String, Boolean>();
		
		//turn on default features
		featureStatus.put("users",new Boolean(true));
	}
	
	/*
	 * (non-Javadoc)
	 * @see org.javarosa.core.services.storage.Persistable#getID()
	 */
	public int getID() {
		return recordId;
	}

	/*
	 * (non-Javadoc)
	 * @see org.javarosa.core.services.storage.Persistable#setID(int)
	 */
	public void setID(int ID) {
		recordId = ID;
	}
	
	/**
	 * @return The version of this profile which
	 * is represented by this definition.
	 */
	public int getVersion() {
		return version;
	}
	
	/**
	 * @return A URI which represents the authoritative
	 * source of this profile's master definition. If the 
	 * profile definition read at this URI claims a higher
	 * version number than this profile's version, this profile
	 * is obsoleted by it. 
	 */
	public String getAuthReference() {
		return authRef;
	}
	
	
	/**
	 * Determines whether or not a specific CommCare feature should
	 * be active in the current application. 
	 *  
	 * @param feature The key of the feature being requested.
	 * @return Whether or not in the application being defined
	 * by this profile the feature requested should be made available
	 * to end users.
	 */
	public boolean isFeatureActive(String feature) {
		if(!featureStatus.contains(feature)) { return false; }
		return featureStatus.get(feature).booleanValue();
	}
	
	// The below methods should all be replaced by a model builder
	// or a change to how the profile parser works
	
	public void addRoot(RootTranslator r) {
		this.roots.addElement(r);
	}
	
	public void addPropertySetter(String key, String value) {
		this.addPropertySetter(key,value,false);<commit_msg>Fix for features all being off by default<commit_after>package org.commcare.suite.model;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.util.Hashtable;
import java.util.Vector;

import org.javarosa.core.reference.RootTranslator;
import org.javarosa.core.services.PropertyManager;
import org.javarosa.core.services.storage.Persistable;
import org.javarosa.core.util.externalizable.DeserializationException;
import org.javarosa.core.util.externalizable.ExtUtil;
import org.javarosa.core.util.externalizable.ExtWrapList;
import org.javarosa.core.util.externalizable.ExtWrapMap;
import org.javarosa.core.util.externalizable.PrototypeFactory;

/**
 * <p>
 * Profile is a model which defines the operating profile
 * of a CommCare application. An applicaiton's profile
 * defines what CommCare features should be activated,
 * certain properties which should be defined, and 
 * any JavaRosa URI reference roots which should be
 * available.</p>
 * 
 * 
 * @author ctsims
 *
 */

public class Profile implements Persistable {
	
	public static final String STORAGE_KEY = "PROFILE";
	
	public static final String FEATURE_REVIEW = "checkoff";
	
	int recordId = -1;
	int version;
	String authRef;
	Vector<PropertySetter> properties;
	Vector<RootTranslator> roots;
	
	Hashtable<String,Boolean> featureStatus;
	
	/**
	 * Serialization Only!
	 */
	public Profile() {
		
	}
	
	/**
	 * Creates an application profile with the provided
	 * version and authoritative reference URI. 
	 * 
	 * @param version The version of this profile which
	 * is represented by this definition.
	 * 
	 * @param authRef A URI which represents the authoritative
	 * source of this profile's master definition. If the 
	 * profile definition read at this URI claims a higher
	 * version number than this profile's version, this profile
	 * is obsoleted by it. 
	 * 
	 */
	public Profile(int version, String authRef) {
		this.version = version;
		this.authRef = authRef;
		properties = new Vector<PropertySetter>();
		roots = new Vector<RootTranslator>();
		featureStatus = new Hashtable<String, Boolean>();
		
		//turn on default features
		featureStatus.put("users",new Boolean(true));
	}
	
	/*
	 * (non-Javadoc)
	 * @see org.javarosa.core.services.storage.Persistable#getID()
	 */
	public int getID() {
		return recordId;
	}

	/*
	 * (non-Javadoc)
	 * @see org.javarosa.core.services.storage.Persistable#setID(int)
	 */
	public void setID(int ID) {
		recordId = ID;
	}
	
	/**
	 * @return The version of this profile which
	 * is represented by this definition.
	 */
	public int getVersion() {
		return version;
	}
	
	/**
	 * @return A URI which represents the authoritative
	 * source of this profile's master definition. If the 
	 * profile definition read at this URI claims a higher
	 * version number than this profile's version, this profile
	 * is obsoleted by it. 
	 */
	public String getAuthReference() {
		return authRef;
	}
	
	
	/**
	 * Determines whether or not a specific CommCare feature should
	 * be active in the current application. 
	 *  
	 * @param feature The key of the feature being requested.
	 * @return Whether or not in the application being defined
	 * by this profile the feature requested should be made available
	 * to end users.
	 */
	public boolean isFeatureActive(String feature) {
		if(!featureStatus.containsKey(feature)) { return false; }
		return featureStatus.get(feature).booleanValue();
	}
	
	// The below methods should all be replaced by a model builder
	// or a change to how the profile parser works
	
	public void addRoot(RootTranslator r) {
		this.roots.addElement(r);
	}
	
	public void addPropertySetter(String key, String value) {
		this.addPropertySetter(key,value,false);
{'fraction_non_alphanumeric': 0.09082384460817147, 'fraction_numerical': 0.00026791694574681847, 'mean_word_length': 3.924802110817942, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, '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': '5210284', 'n_tokens_mistral': 2317, 'n_tokens_neox': 2082, 'n_words': 712}