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

import org.commcare.cases.instance.CaseDataInstance;
import org.commcare.util.mocks.CommCareInstanceInitializer;
import org.javarosa.core.model.instance.DataInstance;
import org.javarosa.core.model.instance.ExternalDataInstance;
import org.javarosa.core.model.instance.ExternalDataInstanceFactory;
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.ExtWrapNullable;
import org.javarosa.core.util.externalizable.ExtWrapTagged;
import org.javarosa.core.util.externalizable.Externalizable;
import org.javarosa.core.util.externalizable.PrototypeFactory;

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

/**
 * <p>An Entry definition describes a user
 * initiated form entry action, what information
 * needs to be collected before that action can
 * begin, and what the User Interface should
 * present to the user regarding these actions</p>
 *
 * @author ctsims
 */
public class Entry implements Externalizable, MenuDisplayable {

    private String xFormNamespace;
    Vector<SessionDatum> data;
    DisplayUnit display;
    private String commandId;
    Hashtable<String, DataInstance> instances;
    Vector<StackOperation> stackOperations;
    AssertionSet assertions;

    /**
     * Serialization only!
     */
    public Entry() {

    }

    public Entry(String commandId, DisplayUnit display, Vector<SessionDatum> data, String formNamespace, Hashtable<String, DataInstance> instances,
                 Vector<StackOperation> stackOperations, AssertionSet assertions) {
        this.commandId = commandId == null ? "" : commandId;
        this.display = display;
        this.data = data;
        xFormNamespace = formNamespace;
        this.instances = instances;
        this.stackOperations = stackOperations;
        this.assertions = assertions;
    }

    /**
     * @return the ID of this entry command. Used by Menus to determine
     * where the command should be located.
     */
    public String getCommandId() {
        return commandId;
    }

    /**
     * @return A text whose evaluated string should be presented to the
     * user as the entry point for this operation
     */
    public Text getText() {
        return display.getText();
    }

    /**
     * @return The XForm Namespce of the form which should be filled out in
     * the form entry session triggered by this action. null if no entry
     * should occur [HACK].
     */
    public String getXFormNamespace() {
        return xFormNamespace;
    }


    public String getImageURI() {
        if (display.getImageURI() == null) {
            return null;
        }
        return display.getImageURI().evaluate();
    }

    public String getAudioURI() {
        if (display.getAudioURI() == null) {
            return null;
        }
        return display.getAudioURI().evaluate();
    }

    public String getDisplayText() {
        if (display.getText() == null) {
            return null;
        }
        return display.getText().evaluate();
    }

    public Vector<SessionDatum> getSessionDataReqs() {
        return data;
    }

    public Hashtable<String, DataInstance> getInstances() {
        //return instances;

        Hashtable<String, DataInstance> copy = new Hashtable<String, DataInstance>();
        ExternalDataInstanceFactory instanceFactory = CommCareInstanceInitializer.getExternalDataInstanceFactory();
        for (Enumeration en = instances.keys(); en.hasMoreElements(); ) {
            String key = (String)en.nextElement();

            //This is silly, all of these are externaldata instances. TODO: save their
            //construction details instead.
            DataInstance cur = instances.get(key);
            if (cur instanceof ExternalDataInstance) {
                //Copy the EDI so when it gets populated we don't keep it dependent on this object's lifecycle!!
                copy.put(key, instanceFactory.getDataInstance(cur.getInstanceId(), ((ExternalDataInstance)cur).getReference()));
            } else {
                copy.put(key, cur);
            }<commit_msg>Fix Entry to not need ExternalDataInstanceFactory<commit_after>package org.commcare.suite.model;

import org.javarosa.core.model.instance.DataInstance;
import org.javarosa.core.model.instance.DataInstanceBuilder;
import org.javarosa.core.model.instance.ExternalDataInstance;
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.ExtWrapNullable;
import org.javarosa.core.util.externalizable.ExtWrapTagged;
import org.javarosa.core.util.externalizable.Externalizable;
import org.javarosa.core.util.externalizable.PrototypeFactory;

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

/**
 * <p>An Entry definition describes a user
 * initiated form entry action, what information
 * needs to be collected before that action can
 * begin, and what the User Interface should
 * present to the user regarding these actions</p>
 *
 * @author ctsims
 */
public class Entry implements Externalizable, MenuDisplayable {

    private String xFormNamespace;
    Vector<SessionDatum> data;
    DisplayUnit display;
    private String commandId;
    Hashtable<String, DataInstance> instances;
    Vector<StackOperation> stackOperations;
    AssertionSet assertions;

    /**
     * Serialization only!
     */
    public Entry() {

    }

    public Entry(String commandId, DisplayUnit display, Vector<SessionDatum> data, String formNamespace, Hashtable<String, DataInstance> instances,
                 Vector<StackOperation> stackOperations, AssertionSet assertions) {
        this.commandId = commandId == null ? "" : commandId;
        this.display = display;
        this.data = data;
        xFormNamespace = formNamespace;
        this.instances = instances;
        this.stackOperations = stackOperations;
        this.assertions = assertions;
    }

    /**
     * @return the ID of this entry command. Used by Menus to determine
     * where the command should be located.
     */
    public String getCommandId() {
        return commandId;
    }

    /**
     * @return A text whose evaluated string should be presented to the
     * user as the entry point for this operation
     */
    public Text getText() {
        return display.getText();
    }

    /**
     * @return The XForm Namespce of the form which should be filled out in
     * the form entry session triggered by this action. null if no entry
     * should occur [HACK].
     */
    public String getXFormNamespace() {
        return xFormNamespace;
    }


    public String getImageURI() {
        if (display.getImageURI() == null) {
            return null;
        }
        return display.getImageURI().evaluate();
    }

    public String getAudioURI() {
        if (display.getAudioURI() == null) {
            return null;
        }
        return display.getAudioURI().evaluate();
    }

    public String getDisplayText() {
        if (display.getText() == null) {
            return null;
        }
        return display.getText().evaluate();
    }

    public Vector<SessionDatum> getSessionDataReqs() {
        return data;
    }

    public Hashtable<String, DataInstance> getInstances() {
        Hashtable<String, DataInstance> copy = new Hashtable<String, DataInstance>();
        for (Enumeration en = instances.keys(); en.hasMoreElements(); ) {
            String key = (String)en.nextElement();

            //This is silly, all of these are externaldata instances. TODO: save their
            //construction details instead.
            DataInstance cur = instances.get(key);
            if (cur instanceof DataInstanceBuilder && cur instanceof ExternalDataInstance) {
                //Copy the EDI so when it gets populated we don't keep it dependent on this object's lifecycle!!
                // TODO PLM: check that this works if cur is CaseDataInstance!
                copy.put(key, ((DataInstanceBuilder)cur).buildDataInstance(((ExternalDataInstance)cur).getReference(), cur.getInstanceId()));
            } else {
                copy.put(key, cur);
            }
{'fraction_non_alphanumeric': 0.09162572832171827, 'fraction_numerical': 0.0, 'mean_word_length': 2.946798917944094, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 27, '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': '6880576', 'n_tokens_mistral': 2338, 'n_tokens_neox': 2283, 'n_words': 646}