<commit_before>package org.flymine.dataloader;

import java.util.Iterator;
import java.util.Collection;
import java.util.Set;
import java.util.HashSet;

import org.acedb.Ace;
import org.acedb.AceException;
import org.acedb.AceURL;
import org.acedb.AceUtils;
import org.acedb.AceSet;
import org.acedb.AceNode;
import org.acedb.AceObject;
import org.acedb.StringValue;
import org.acedb.IntValue;
import org.acedb.FloatValue;
import org.acedb.Reference;

import org.acedb.staticobj.StaticAceObject;

import java.lang.reflect.Field;

import org.flymine.FlyMineException;
import org.flymine.metadata.Model;
import org.flymine.util.TypeUtil;

/**
 * DataLoader for AceDB data
 * @author <NAME>
 */
public class AceDataLoader extends DataLoader
{
    /**
     * No-arg constructor for testing purposes
     */
    protected AceDataLoader() {
    }

    /**
     * @see AbstractDataLoader#Constructor
     */
    public AceDataLoader(Model model, IntegrationWriter iw) {
        super(model, iw);
    }
    
    /**
     * Static method to unmarshall business objects from a given xml file and call
     * store on each.
     *
     * @param source access to AceDb
     * @throws FlyMineException if anything goes wrong with xml or storing
     */
    public void processAce(AceURL source) throws FlyMineException {
        try {
            Ace.registerDriver(new org.acedb.socket.SocketDriver());

            // Go through each class in the model and get a dump of the objects of
            // that class

            Collection clazzNames = model.getClassNames();
            Iterator clazzIter = clazzNames.iterator();
            while (clazzIter.hasNext()) {
                String clazzName = (String) clazzIter.next();

                AceURL objURL = source.relativeURL(clazzName);
                AceSet fetchedAceObjects = (AceSet) Ace.fetch(objURL);

                Collection objects = processAceObjects(fetchedAceObjects);
                Iterator objIter = objects.iterator();
                while (objIter.hasNext()) {
                    // Now store that object
                    store(objIter.next());
                }
            }

        } catch (Exception e) {
            throw new FlyMineException(e);
        }
    }

    /**
     * Process a set of Ace objects
     *
     * @param set the set of Ace objects to process
     * @return a set of Java objects
     *
     * @throws AceException if an error occurs with the Ace data
     * @throws FlyMineException if an object cannot be instantiated
     */
    protected  Set processAceObjects(AceSet set)
        throws AceException, FlyMineException {
        HashSet ret = new HashSet();
        Iterator aceObjIter = set.iterator();
        while (aceObjIter.hasNext()) {
            // Convert to Java object
            Object obj = processAceObject((AceObject) aceObjIter.next());
            ret.add(obj);
        }
        return ret;
    }

    /**
     * Process an AceObject. This will create a new instance of the
     * object and set the identifier.
     *
     * @param aceObject the AceObject to process
     * @return an instance of the object
     *
     * @throws AceException if an error occurs with the Ace data
     * @throws FlyMineException if object cannot be instantiated
     */
    protected Object processAceObject(AceObject aceObject)
        throws AceException, FlyMineException {
        Object currentObject = null;
        try {
            String clazzName = ((AceObject) aceObject).getClassName();
            if (model != null) {
                clazzName = model.getName() + "." + clazzName;
            }
            currentObject = Class.forName(clazzName).newInstance();
            setField(currentObject, "identifier", AceUtils.decode(aceObject.getName()));
        } catch (ClassNotFoundException e) {
            throw new FlyMineException(e);
        } catch (InstantiationException e) {
            throw new FlyMineException(e);
        } catch (IllegalAccessException e) {
            throw new FlyMineException(e);
        }

        processAceNode(aceObject, currentObject);<commit_msg>Throw NullPointerExceptions if null objects passed in to processAceObject() or processAceObjects()<commit_after>package org.flymine.dataloader;

import java.util.Iterator;
import java.util.Collection;
import java.util.Set;
import java.util.HashSet;

import org.acedb.Ace;
import org.acedb.AceException;
import org.acedb.AceURL;
import org.acedb.AceUtils;
import org.acedb.AceSet;
import org.acedb.AceNode;
import org.acedb.AceObject;
import org.acedb.StringValue;
import org.acedb.IntValue;
import org.acedb.FloatValue;
import org.acedb.Reference;

import org.acedb.staticobj.StaticAceObject;

import java.lang.reflect.Field;

import org.flymine.FlyMineException;
import org.flymine.metadata.Model;
import org.flymine.util.TypeUtil;

/**
 * DataLoader for AceDB data
 * @author <NAME>
 */
public class AceDataLoader extends DataLoader
{
    /**
     * No-arg constructor for testing purposes
     */
    protected AceDataLoader() {
    }

    /**
     * @see AbstractDataLoader#Constructor
     */
    public AceDataLoader(Model model, IntegrationWriter iw) {
        super(model, iw);
    }

    /**
     * Static method to unmarshall business objects from a given Ace server and call
     * store on each.
     *
     * @param source access to AceDb
     * @throws FlyMineException if anything goes wrong with ace or storing
     */
    public void processAce(AceURL source) throws FlyMineException {
        try {
            Ace.registerDriver(new org.acedb.socket.SocketDriver());

            // Go through each class in the model and get a dump of the objects of
            // that class

            Collection clazzNames = model.getClassNames();
            Iterator clazzIter = clazzNames.iterator();
            while (clazzIter.hasNext()) {
                String clazzName = (String) clazzIter.next();

                AceURL objURL = source.relativeURL(clazzName);
                AceSet fetchedAceObjects = (AceSet) Ace.fetch(objURL);

                Collection objects = processAceObjects(fetchedAceObjects);
                Iterator objIter = objects.iterator();
                while (objIter.hasNext()) {
                    // Now store that object
                    store(objIter.next());
                }
            }

        } catch (Exception e) {
            throw new FlyMineException(e);
        }
    }

    /**
     * Process a set of Ace objects
     *
     * @param set the set of Ace objects to process
     * @return a set of Java objects
     *
     * @throws AceException if an error occurs with the Ace data
     * @throws FlyMineException if an object cannot be instantiated
     */
    protected Set processAceObjects(AceSet set)
        throws AceException, FlyMineException {
        if (set == null) {
            throw new NullPointerException("set must not be null");
        }

        HashSet ret = new HashSet();
        Iterator aceObjIter = set.iterator();
        while (aceObjIter.hasNext()) {
            // Convert to Java object
            Object obj = processAceObject((AceObject) aceObjIter.next());
            ret.add(obj);
        }
        return ret;
    }

    /**
     * Process an AceObject. This will create a new instance of the
     * object and set the identifier.
     *
     * @param aceObject the AceObject to process
     * @return an instance of the object
     *
     * @throws AceException if an error occurs with the Ace data
     * @throws FlyMineException if object cannot be instantiated
     */
    protected Object processAceObject(AceObject aceObject)
        throws AceException, FlyMineException {
        if (aceObject == null) {
            throw new NullPointerException("aceObject must not be null");
        }
        Object currentObject = null;
        try {
            String clazzName = ((AceObject) aceObject).getClassName();
            if (model != null) {
                clazzName = model.getName() + "." + clazzName;
            }
            currentObject = Class.forName(clazzName).newInstance();
            setField(currentObject, "identifier", AceUtils.decode(aceObject.getName()));
        } catch (ClassNotFoundException e) {
            throw new FlyMineException(e);
        } catch (InstantiationException e) {
            throw new FlyMineException(e);
        } catch (IllegalAccessException e) {
            throw new FlyMineException(e);
        }

        processAceNode(aceObject, currentObject);
{'fraction_non_alphanumeric': 0.08719090589476151, 'fraction_numerical': 0.0, 'mean_word_length': 2.2785247791010375, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '677062', 'n_tokens_mistral': 2402, 'n_tokens_neox': 2304, 'n_words': 675}