text:
package org.dspace.content.authority;

import org.apache.log4j.Logger;
import org.dspace.authorize.AuthorizeException;
import org.dspace.authorize.AuthorizeManager;
import org.dspace.content.DSpaceObject;
import org.dspace.core.ConfigurationManager;
import org.dspace.core.Constants;
import org.dspace.core.Context;
import org.dspace.core.LogManager;
import org.dspace.event.Event;
import org.dspace.storage.rdbms.DatabaseManager;
import org.dspace.storage.rdbms.TableRow;
import org.dspace.storage.rdbms.TableRowIterator;

import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * Class representing a DSpace Concept, that acts as
 * a container of DSpace Terms.
 *
 * @author Lantian Gai, Mark Diggory
 */
public class Concept extends AuthorityObject
{

    public enum Status {
        CANDIDATE,
        ACCEPTED,
        WITHDRAWN;
    }

    /** log4j logger */
    private static Logger log = Logger.getLogger(Concept.class);

    /**
     * Construct a Concept from a given context and tablerow
     *
     * @param context
     * @param row
     */
    Concept(Context context, TableRow row) throws SQLException
    {
        super(context,row);

    }

    public Date getCreated()
    {
        Date myDate = myRow.getDateColumn("created");

        if (myDate == null)
        {
            myDate = new Date();
        }

        return myDate;
    }
    public void setCreated(Date date)
    {
        Date myDate = myRow.getDateColumn("created");

        if (date != null)
        {
            myRow.setColumn("created", date);
            modified = true;
        }
    }

    public String getStatus()
    {
        return myRow.getStringColumn("status");

    }

    public void setStatus(String status)
    {
        try
        {
            Status c = Status.valueOf(status);
            if (!c.name().equals(getStatus()) ) {
                myRow.setColumn("status", c.name());
                modified = true;
            }
        }
        catch(Exception e)
        {
            if(status == null && getStatus() != null)
            {
                myRow.setColumnNull("status");
                modified = true;
            }
        }

    }

    public void setStatus(Status status)
    {
        if(status == null)
        {
            if(getStatus() != null)
            {
                myRow.setColumnNull("status");
                modified = true;
            }
        }
        else if (!status.name().equals(getStatus()))
        {
            myRow.setColumn("status", status.name());
            modified = true;
        }
    }

    public String getSource()
    {
        return myRow.getStringColumn("source");

    }
    public void setSource(String source)
    {
        myRow.setColumn("source", source);
        modified = true;
    }

    public String getLang()
    {
        return myRow.getStringColumn("lang");

    }
    public void setLang(String lang)
    {
        myRow.setColumn("lang", lang);
        modified = true;
    }

    public Boolean getTopConcept()
    {
        return myRow.getBooleanColumn("topConcept");

    }
    public void setTopConcept(Boolean topConcept)
    {
        myRow.setColumn("topConcept", topConcept);
        modified = true;
    }
    /**
     * Create a new concept
     *
     * @param context
     *            DSpace context object
     */
    public static Concept create(Context context) throws SQLException,
            AuthorizeException
    {
        // authorized?
        if (!AuthorizeManager.isAdmin(context))
        {
            throw new AuthorizeException(
                    "You must be an admin to create an Concept");
        }

        return create(context, AuthorityObject.createIdentifier());
    }

    public static Concept create(Context context, String identifier) throws SQLException,
            AuthorizeException
    {
        // authorized?
        if (!AuthorizeManager.isAdmin(context))
        {
            throw new AuthorizeException(
                    "You must be an admin to create an Concept");
        }

        // Create a table row
        TableRow row = DatabaseManager.create(context, "concept");

        Concept e = new Concept(context, row);

        e.setIdentifier(identifier);

        log.info(LogManager.getHeader(context, "create_concept", "metadata_concept_id="
                + e.getID()));

        context.addEvent(new Event(Event.CREATE, Constants.CONCEPT, e.getID(), null));

        return e;
    }
    /**
     * get the ID of the concept object
     *
     * @return id
     */
    public int getID()
    {
        return myRow.getIntColumn("id");
    }

    /**
     * add an term member
     *
     * @param t
     *            term
     */
    public void addPreferredTerm(Term t)
    {

        addTermByType(t,1);

    }
    /**
     * add an term member
     *
     * @param t
     *            term
     */
    public void addAltTerm(Term t)
    {

        addTermByType(t,2);

    }
    /**
     * remove an term from a concept
     *
     * @param t
     *            term
     */
    public void removePreferredTerm(Term t)throws SQLException,
            AuthorizeException, IOException
    {

        // Check authorisation
        AuthorizeManager.isAdmin(myContext);
        log.info(LogManager.getHeader(myContext, "remove_preferredTerm",
                "concept_id=" + getID() + ",term_id=" + t.getID()));

        TableRow trow = DatabaseManager.querySingle(myContext,
                "SELECT COUNT(DISTINCT concept_id) AS num FROM concept2term WHERE term_id= ? AND role_id=1",
                t.getID());
        DatabaseManager.setConstraintDeferred(myContext, "concept2term_term_id_fkey");

        if (trow.getLongColumn("num") == 1)
        {
            // Orphan; delete it
            t.delete();
        }

        log.info(LogManager.getHeader(myContext, "remove_term",
                "concept_id=" + getID() + ",term_id=" + t.getID()));

        // Remove any mappings
        DatabaseManager.updateQuery(myContext,
                "DELETE FROM concept2term WHERE concept_id= ? "+
                        "AND term_id= ? AND role_id=1", getID(), t.getID());

        DatabaseManager.setConstraintImmediate(myContext, "concept2term_term_id_fkey");
        myContext.addEvent(new Event(Event.REMOVE, Constants.TERM, t.getID(), null));
    }

    /**
     * remove an term from a concept
     *
     * @param t
     *            term
     */
    public void removeAltTerm(Term t)throws SQLException,
            AuthorizeException, IOException
    {
        // Check authorisation
        AuthorizeManager.isAdmin(myContext);
        log.info(LogManager.getHeader(myContext, "remove_altTerm",
                "concept_id=" + getID() + ",term_id=" + t.getID()));

        TableRow trow = DatabaseManager.querySingle(myContext,
                "SELECT COUNT(DISTINCT concept_id) AS num FROM concept2term WHERE term_id= ? AND role_id=2",
                t.getID());
        DatabaseManager.setConstraintDeferred(myContext, "concept2term_term_id_fkey");

        if (trow.getLongColumn("num") == 1)
        {
            // Orphan; delete it
            t.delete();
        }

        log.info(LogManager.getHeader(myContext, "remove_term",
                "concept_id=" + getID() + ",term_id=" + t.getID()));

        // Remove any mappings
        DatabaseManager.updateQuery(myContext,
                "DELETE FROM concept2term WHERE concept_id= ? "+
                        "AND term_id= ? AND role_id=2", getID(), t.getID());

        DatabaseManager.setConstraintImmediate(myContext, "concept2term_term_id_fkey");
        myContext.addEvent(new Event(Event.REMOVE, Constants.TERM, t.getID(), null));
    }
    /**
     * remove concept from this concept
     *
     * @param c
     */
    public void removeParentConcept(Concept c)throws SQLException,
            AuthorizeException, IOException
    {
        // Check authorisation
        AuthorizeManager.isAdmin(myContext);
        log.info(LogManager.getHeader(myContext, "remove_parentConcept",
                "concept_id=" + getID() + ",parent_concept_id=" + c.getID()));

        DatabaseManager.setConstraintDeferred(myContext, "Concept2Concept_incoming_id_fkey ");

        log.info(LogManager.getHeader(myContext, "remove_term",
                "concept_id=" + getID() + ",parent_concept_id=" + c.getID()));

        // Remove any mappings
        DatabaseManager.updateQuery(myContext,
                "DELETE FROM concept2term WHERE imcoming_id= ? "+
                        "AND outgoing_id= ? AND role_id=1", getID(), c.getID());

        DatabaseManager.setConstraintImmediate(myContext, "Concept2Concept_incoming_id_fkey ");
        myContext.addEvent(new Event(Event.REMOVE, Constants.CONCEPT, c.getID(), null));
    }

    /**
     * remove concept from this concept
     *
     * @param c
     */
    public void removeChildConcept(Concept c)throws SQLException,
            AuthorizeException, IOException
    {
        // Check authorisation
        AuthorizeManager.isAdmin(myContext);
        log.info(LogManager.getHeader(myContext, "remove_parentConcept",
                "concept_id=" + getID() + ",child_concept_id=" + c.getID()));

        DatabaseManager.setConstraintDeferred(myContext, "Concept2Concept_outgoing_id_fkey ");

        log.info(LogManager.getHeader(myContext, "remove_term",
                "concept_id=" + getID() + ",child_concept_id=" + c.getID()));

        // Remove any mappings
        DatabaseManager.updateQuery(myContext,
                "DELETE FROM concept2term WHERE outgoing_id= ? "+
                        "AND incoming_id= ? AND role_id=1", getID(), c.getID());

        DatabaseManager.setConstraintImmediate(myContext, "Concept2Concept_outgoing_id_fkey ");
        myContext.addEvent(new Event(Event.REMOVE, Constants.CONCEPT, c.getID(), null));
    }

    /**
     * fast check to see if an term is a member called with term id, does
     * database lookup without instantiating all of the term objects and is
     * thus a static method
     *
     * @param c
     *            context
     * @param conceptid
     *            concept ID to check
     */

    /**
     * find the concept by its ID
     *
     * @param context
     * @param id
     */
    public static Concept find(Context context, int id) throws SQLException
    {
        // First check the cache
        Concept fromCache = (Concept) context.fromCache(Concept.class, id);

        if (fromCache != null)
        {
            return fromCache;
        }

        TableRow row = DatabaseManager.find(context, "concept", id);

        if (row == null)
        {
            return null;
        }
        else
        {
            return new Concept(context, row);
        }
    }

    /**
     * Find the concept by its name - assumes name is unique
     *
     * @param context
     * @param identifier
     *
     * @return the named Concept, or null if not found
     */

    public static ArrayList<Concept> findByIdentifier(Context context, String identifier)
            throws SQLException
    {
        ArrayList<Concept> concepts = new ArrayList<Concept>();
        TableRowIterator row = DatabaseManager.query(context,"select * from concept where LOWER(identifier) like '"+identifier+"'");

        if (row == null)
        {
            return null;
        }
        else
        {

            while(row.hasNext())
            {
                concepts.add(new Concept(context,row.next()));

            }
        }
        return concepts;
    }

    /**
     * Find the concept by its name - assumes name is unique
     *
     * @param context
     * @param journalID
     *
     * @return the named Concept, or null if not found
     */

    public static ArrayList<Concept> findByJournalID(Context context, String journalID)
            throws SQLException
    {
        ArrayList<Concept> concepts = new ArrayList<Concept>();
        TableRowIterator row = DatabaseManager.query(context,"select c.* from concept as c, conceptmetadatavalue as cmv where cmv.text_value = '"+journalID+"' and cmv.parent_id=c.id;");

        if (row == null)
        {
            return null;
        }
        else
        {

            while(row.hasNext())
            {
                concepts.add(new Concept(context,row.next()));

            }
        }
        return concepts;
    }

    /**
     * Finds all concepts in the site
     *
     * @param context
     *            DSpace context
     * @param sortField
     *            field to sort by -- Concept.ID or Concept.NAME
     *
     * @return array of all concepts in the site
     */
    public static Concept[] findAll(Context context, int sortField)
            throws SQLException
    {
        String s;

        switch (sortField)
        {
            case ID:
                s = "id";

                break;

            case NAME:
                s = "name";

                break;

            default:
                s = "name";
        }

        // NOTE: The use of 's' in the order by clause can not cause an SQL
        // injection because the string is derived from constant values above.
        TableRowIterator rows = DatabaseManager.queryTable(
                context, "concept",
                "SELECT * FROM concept ORDER BY "+s);

        try
        {
            List<TableRow> gRows = rows.toList();

            Concept[] concepts = new Concept[gRows.size()];

            for (int i = 0; i < gRows.size(); i++)
            {
                TableRow row = gRows.get(i);

                // First check the cache
                Concept fromCache = (Concept) context.fromCache(Concept.class, row
                        .getIntColumn("id"));

                if (fromCache != null)
                {
                    concepts[i] = fromCache;
                }
                else
                {
                    concepts[i] = new Concept(context, row);
                }
            }

            return concepts;
        }
        finally
        {
            if (rows != null)
            {
                rows.close();
            }
        }
    }

    /**
     * Find the concepts that match the search query across term_concept_id or name
     *
     * @param context
     *            DSpace context
     * @param query
     *            The search string
     *
     * @return array of Concept objects
     */
    public static Concept[] search(Context context, String query)
            throws SQLException
    {
        return search(context, query, -1, -1,null);
    }

    /**
     * Find the concepts that match the search query across term_concept_id or name
     *
     * @param context
     *            DSpace context
     * @param query
     *            The search string
     * @param offset
     *            Inclusive offset
     * @param limit
     *            Maximum number of matches returned
     *
     * @return array of Concept objects
     */
    public static Concept[] search(Context context, String query, int offset, int limit,String schemeId)
            throws SQLException
    {
        String params = "%"+query.toLowerCase()+"%";
        StringBuffer queryBuf = new StringBuffer();

        if(schemeId==null){
            queryBuf.append("SELECT distinct(concept.*) FROM concept LEFT JOIN concept2term ON concept.id=concept2term.concept_id LEFT JOIN term on concept2term.concept_id = term.id WHERE concept.id = ? OR " +
                    "LOWER(concept.identifier) like ? OR LOWER(term.literalform) like ? ORDER BY concept.id, concept.created ASC");
        }
        else
        {
            queryBuf.append("SELECT distinct(concept.*) FROM concept LEFT JOIN scheme2concept ON concept.id=scheme2concept.concept_id LEFT JOIN concept2term ON concept.id=concept2term.concept_id LEFT JOIN term on concept2term.term_id = term.id WHERE scheme2concept.scheme_id = "+schemeId+" AND (concept.id = ? OR LOWER(concept.identifier) like ? OR LOWER(term.literalform) like ? ) ORDER BY concept.id ASC");
        }

        // Add offset and limit restrictions - Oracle requires special code
        if ("oracle".equals(ConfigurationManager.getProperty("db.name")))
        {
            // First prepare the query to generate row numbers
            if (limit > 0 || offset > 0)
            {
                queryBuf.insert(0, "SELECT /*+ FIRST_ROWS(n) */ rec.*, ROWNUM rnum  FROM (");
                queryBuf.append(") ");
            }

            // Restrict the number of rows returned based on the limit
            if (limit > 0)
            {
                queryBuf.append("rec WHERE rownum<=? ");
                // If we also have an offset, then convert the limit into the maximum row number
                if (offset > 0)
                {
                    limit += offset;
                }
            }

            // Return only the records after the specified offset (row number)
            if (offset > 0)
            {
                queryBuf.insert(0, "SELECT * FROM (");
                queryBuf.append(") WHERE rnum>?");
            }
        }
        else
        {
            if (limit > 0)
            {
                queryBuf.append(" LIMIT ? ");
            }

            if (offset > 0)
            {
                queryBuf.append(" OFFSET ? ");
            }
        }

        String dbquery = queryBuf.toString();

        // When checking against the term-id, make sure the query can be made into a number
        Integer int_param;
        try {
            int_param = Integer.valueOf(query);
        }
        catch (NumberFormatException e) {
            int_param = Integer.valueOf(-1);
        }

        // Create the parameter array, including limit and offset if part of the query
        Object[] paramArr = new Object[] {int_param,params,params};
        if (limit > 0 && offset > 0)
        {
            paramArr = new Object[]{int_param, params,params,limit, offset};
        }
        else if (limit > 0)
        {
            paramArr = new Object[]{int_param,params,params,  limit};
        }
        else if (offset > 0)
        {
            paramArr = new Object[]{int_param,params, params, offset};
        }

        TableRowIterator rows =
                DatabaseManager.query(context, dbquery, paramArr);

        try
        {
            List<TableRow> conceptRows = rows.toList();
            Concept[] concepts = new Concept[conceptRows.size()];

            for (int i = 0; i < conceptRows.size(); i++)
            {
                TableRow row = conceptRows.get(i);

                // First check the cache
                Concept fromCache = (Concept) context.fromCache(Concept.class, row
                        .getIntColumn("id"));

                if (fromCache != null)
                {
                    concepts[i] = fromCache;
                }
                else
                {
                    concepts[i] = new Concept(context, row);
                }
            }
            return concepts;
        }
        finally
        {
            if (rows != null)
            {
                rows.close();
            }
        }
    }

    /**
     * Returns the total number of concepts returned by a specific query, without the overhead
     * of creating the Concept objects to store the results.
     *
     * @param context
     *            DSpace context
     * @param query
     *            The search string
     *
     * @return the number of concepts matching the query
     */
    public static int searchResultCount(Context context, String query,String schemeId)
            throws SQLException
    {
        String dbquery = "%"+query.toLowerCase()+"%";
        Long count;

        // When checking against the concept-id, make sure the query can be made into a number
        Integer int_param;
        try {
            int_param = Integer.valueOf(query);
        }
        catch (NumberFormatException e) {
            int_param = Integer.valueOf(-1);
        }
        TableRow row = null;
        if(schemeId==null){
            // Get all the epeople that match the query
            row = DatabaseManager.querySingle(context,
                    "SELECT count(distinct(concept.*)) as conceptcount FROM concept LEFT JOIN concept2term ON concept.id=concept2term.concept_id LEFT JOIN term on concept2term.concept_id = term.id WHERE concept.id = ? OR " +
                            "LOWER(concept.identifier) like ? OR (concept2term.concept_id = concept.id AND concept2term.term_id=term.id AND term.literalform like ?)",
                    new Object[] {int_param,dbquery,dbquery});
        }
        else
        {
            // Get all the epeople that match the query
            row = DatabaseManager.querySingle(context,
                    "SELECT count(distinct(concept.*)) as conceptcount FROM concept LEFT JOIN scheme2concept ON concept.id=scheme2concept.concept_id LEFT JOIN concept2term ON concept.id=concept2term.concept_id LEFT JOIN term on concept2term.term_id = term.id WHERE concept.id = scheme2concept.concept_id AND scheme2concept.scheme_id = "+schemeId+" AND (concept.id = ? OR LOWER(concept.identifier) like ? OR (concept2term.concept_id = concept.id AND concept2term.term_id=term.id AND term.literalform like ?) )",
                    new Object[] {int_param,dbquery,dbquery});
        }

        // use getIntColumn for Oracle count data
        if ("oracle".equals(ConfigurationManager.getProperty("db.name")))
        {
            count = Long.valueOf(row.getIntColumn("conceptcount"));
        }
        else  //getLongColumn works for postgres
        {
            count = Long.valueOf(row.getLongColumn("conceptcount"));
        }

        return count.intValue();
    }

    /**
     * Delete a concept
     *
     */
    public void delete() throws SQLException
    {
        // FIXME: authorizations

        // Remove from cache
        myContext.removeCached(this, getID());

        // Remove all metadata
        DatabaseManager.updateQuery(myContext,
                "DELETE FROM ConceptMetadataValue WHERE parent_id= ? ",
                getID());

        //delete term
        Term[] terms = getTerms();
        for(Term term : terms)
        {
            try{
                term.delete();
            }catch (Exception e)
            {
                log.error("can't delete term :" +term.getID()+" for concept :"+getID());
            }
        }
        //remove concept from scheme
        DatabaseManager.updateQuery(myContext,
                "DELETE FROM Scheme2Concept WHERE concept_id= ? ",
                getID());
        //remove relationships
        DatabaseManager.updateQuery(myContext,
                "DELETE FROM Concept2Concept WHERE incoming_id= ?",
                getID());
        DatabaseManager.updateQuery(myContext,
                "DELETE FROM Concept2Concept WHERE outgoing_id= ?",
                getID());
        //delete concept
        DatabaseManager.delete(myContext, myRow);

        myContext.addEvent(new Event(Event.DELETE, Constants.CONCEPT, getID(), getIdentifier()));

        log.info(LogManager.getHeader(myContext, "delete_concept", "concept_id="
                + getID()));
    }

    /**
     * Return Concept members of a Concept.
     */
    public Concept[] getParentConcepts() throws SQLException
    {
        List<Concept> concepts = new ArrayList<Concept>();

        // Get the table rows
        TableRowIterator tri = DatabaseManager.queryTable(
                myContext,"concept",
                "SELECT concept.* FROM concept, Concept2Concept WHERE " +
                        "Concept2Concept.incoming_id=concept.id " +
                        "AND Concept2Concept.outgoing_id= ? ORDER BY concept.id",
                getID());

        // Make Collection objects
        try
        {
            while (tri.hasNext())
            {
                TableRow row = tri.next();

                // First check the cache
                Concept fromCache = (Concept) myContext.fromCache(
                        Concept.class, row.getIntColumn("id"));

                if (fromCache != null)
                {
                    concepts.add(fromCache);
                }
                else
                {
                    concepts.add(new Concept(myContext, row));
                }
            }
        }
        finally
        {
            // close the TableRowIterator to free up resources
            if (tri != null)
            {
                tri.close();
            }
        }

        // Put them in an array
        Concept[] conceptArray = new Concept[concepts.size()];
        conceptArray = (Concept[]) concepts.toArray(conceptArray);

        return conceptArray;
    }

    /**
     * Return Concept members of a Concept.
     */
    public Concept[] getRelatedConcepts(String relation,String direction,String scheme) throws SQLException
    {
        List<Concept> concepts = new ArrayList<Concept>();
        String query = "SELECT concept.* FROM concept, Concept2Concept, Scheme2Concept,concept2conceptrole,scheme WHERE concept.id = scheme2concept.concept_id ";
        if(direction.equals(Concept2ConceptRole.relation_incoming))
        {
            query = query + " AND Concept2Concept.incoming_id=concept.id " +
                    "AND Concept2Concept.outgoing_id= ? ";
        }
        else if(direction.equals(Concept2ConceptRole.relation_outgoing))
        {
            query = query+" AND Concept2Concept.outgoing_id=concept.id " +
                    "AND Concept2Concept.incoming_id= ? ";
        }
        else
        {
            //find all relationships
            query = query+" AND Concept2Concept.incoming_id = ? " +
                    "OR Concept2Concept.outgoing_id= ? ";
        }

        if(relation!=null&&relation.length()>0)

        {
            query = query + " AND Concept2Concept.role_id=concept2conceptrole.id AND concept2conceptrole.role='" + relation + "' ";
        }

        if(scheme!=null&&scheme.length()>0)

        {
            query = query + " AND scheme.id=scheme2concept.scheme_id AND LOWER(scheme.identifier) = '" + scheme + "' ";
        }

        // Get the table rows
        TableRowIterator tri = DatabaseManager.queryTable(
                myContext, "concept",
                query,
                getID());

        // Make Collection objects
        try
        {
            while (tri.hasNext())
            {
                TableRow row = tri.next();

                // First check the cache
                Concept fromCache = (Concept) myContext.fromCache(
                        Concept.class, row.getIntColumn("id"));

                if (fromCache != null)
                {
                    concepts.add(fromCache);
                }
                else
                {
                    concepts.add(new Concept(myContext, row));
                }
            }
        }
        finally
        {
            // close the TableRowIterator to free up resources
            if (tri != null)
            {
                tri.close();
            }
        }

        // Put them in an array
        Concept[] conceptArray = new Concept[concepts.size()];
        conceptArray = (Concept[]) concepts.toArray(conceptArray);

        return conceptArray;
    }

    /**
     * Return Concept members of a Concept.
     */
    public Concept[] getChildConcepts() throws SQLException
    {

        List<Concept> concepts = new ArrayList<Concept>();

        // Get the table rows
        TableRowIterator tri = DatabaseManager.queryTable(
                myContext,"concept",
                "SELECT concept.* FROM concept, Concept2Concept WHERE " +
                        "Concept2Concept.outgoing_id=concept.id " +
                        "AND Concept2Concept.incoming_id= ? ORDER BY concept.id",
                getID());

        // Make Collection objects
        try
        {
            while (tri.hasNext())
            {
                TableRow row = tri.next();

                // First check the cache
                Concept fromCache = (Concept) myContext.fromCache(
                        Concept.class, row.getIntColumn("id"));

                if (fromCache != null)
                {
                    concepts.add(fromCache);
                }
                else
                {
                    concepts.add(new Concept(myContext, row));
                }
            }
        }
        finally
        {
            // close the TableRowIterator to free up resources
            if (tri != null)
            {
                tri.close();
            }
        }

        // Put them in an array
        Concept[] conceptArray = new Concept[concepts.size()];
        conceptArray = (Concept[]) concepts.toArray(conceptArray);

        return conceptArray;
    }

    /**
     * Return <code>true</code> if <code>other</code> is the same Concept as
     * this object, <code>false</code> otherwise
     *
     * @param obj
     *            object to compare to
     *
     * @return <code>true</code> if object passed in represents the same concept
     *         as this object
     */
    @Override
    public boolean equals(Object obj)
    {
        if (obj == null)
        {
            return false;
        }
        if (getClass() != obj.getClass())
        {
            return false;
        }
        final Concept other = (Concept) obj;
        if(this.getID() != other.getID())
        {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode()
    {
        int hash = 7;
        hash = 59 * hash + (this.myRow != null ? this.myRow.hashCode() : 0);
        return hash;
    }

    public int getType()
    {
        return Constants.CONCEPT;
    }

    public String getHandle()
    {
        return null;
    }

    @Override
    public String getName() {
        try {
            return this.getPreferredLabel() + "(" + this.getIdentifier() + ")";
        } catch (SQLException e) {
            log.error(e.getMessage(), e);
        }
        return this.getIdentifier();
    }

    public Scheme getScheme() throws SQLException
    {
        // Get the bundle table rows
        TableRowIterator tri = DatabaseManager.queryTable(myContext,"scheme",
                "SELECT scheme.* FROM scheme, scheme2concept WHERE " +
                        "scheme.id=scheme2concept.scheme_id " +
                        "AND scheme2concept.concept_id= ? ",
                getID());

        // Build a list of Scheme objects
        List<Scheme> schemes = new ArrayList<Scheme>();

        try
        {
            while (tri.hasNext())
            {
                TableRow row = tri.next();

                // First check the cache
                Scheme owner = (Scheme) myContext.fromCache(Scheme.class,
                        row.getIntColumn("id"));

                if (owner == null)
                {
                    owner = new Scheme(myContext, row);
                }

                schemes.add(owner);
            }
        }
        finally
        {
            // close the TableRowIterator to free up resources
            if (tri != null)
            {
                tri.close();
            }
        }

        if(schemes==null||schemes.size() ==0)
        {
            return null;
        }
        return schemes.get(0);
    }

    public Date getLastModified()
    {
        Date myDate = myRow.getDateColumn("modified");

        if (myDate == null)
        {
            myDate = new Date();
        }

        return myDate;
    }
    public void setLastModified(Date date)
    {
        Date myDate = myRow.getDateColumn("modified");

        if (date != null)
        {
            myRow.setColumn("modified", date);
            modified = true;
        }
    }
    /**
     * Method that updates the last modified date of the item
     */
    public void updateLastModified()
    {
        try {
            Date lastModified = new java.sql.Timestamp(new Date().getTime());
            myRow.setColumn("modified", lastModified);
            DatabaseManager.updateQuery(myContext, "UPDATE concept SET modified = ? WHERE id= ? ", lastModified, getID());
            //Also fire a modified event since the item HAS been modified
            //ourContext.addEvent(new Event(Event.MODIFY, Constants.ITEM, getID(), null));
        } catch (SQLException e) {
            log.error(LogManager.getHeader(myContext, "Error while updating modified timestamp", "Concept: " + getID()));
        }
    }

    @Override
    public String getMetadataTable() {
        return "ConceptMetadataValue";
    }

    public Term[] getPreferredTerms() throws SQLException
    {
        List<Term> terms = new ArrayList<Term>();

        // Get the table rows
        TableRowIterator tri = DatabaseManager.queryTable(
                myContext,"term",
                "SELECT term.* FROM term, concept2term WHERE " +
                        "concept2term.term_id=term.id " +
                        "AND concept2term.concept_id= ?  AND role_id = 1 ORDER BY term.identifier",
                getID());

        // Make Concept objects
        try
        {
            while (tri.hasNext())
            {
                TableRow row = tri.next();

                // First check the cache
                Term fromCache = (Term) myContext.fromCache(
                        Term.class, row.getIntColumn("id"));

                if (fromCache != null)
                {
                    terms.add(fromCache);
                }
                else
                {
                    terms.add(new Term(myContext, row));
                }
            }
        }
        finally
        {
            // close the TableRowIterator to free up resources
            if (tri != null)
            {
                tri.close();
            }
        }

        // Put them in an array
        Term[] termArray = new Term[terms.size()];
        termArray = (Term[]) terms.toArray(termArray);

        return termArray;
    }

    public Term[] getAltTerms() throws SQLException
    {
        List<Term> terms = new ArrayList<Term>();

        // Get the table rows
        TableRowIterator tri = DatabaseManager.queryTable(
                myContext,"term",
                "SELECT term.* FROM term, concept2term WHERE " +
                        "concept2term.term_id=term.id " +
                        "AND concept2term.concept_id= ? AND role_id = 2 ORDER BY term.identifier",
                getID());

        // Make Concept objects
        try
        {
            while (tri.hasNext())
            {
                TableRow row = tri.next();

                // First check the cache
                Term fromCache = (Term) myContext.fromCache(
                        Term.class, row.getIntColumn("id"));

                if (fromCache != null)
                {
                    terms.add(fromCache);
                }
                else
                {
                    terms.add(new Term(myContext, row));
                }
            }
        }
        finally
        {
            // close the TableRowIterator to free up resources
            if (tri != null)
            {
                tri.close();
            }
        }

        // Put them in an array
        Term[] conceptArray = new Term[terms.size()];
        conceptArray = (Term[]) terms.toArray(conceptArray);

        return conceptArray;
    }

    public void addParentConcept(Concept incoming,int roleId) throws SQLException,
            AuthorizeException
    {

        // Check authorisation
        AuthorizeManager.isAdmin(myContext);

        log.info(LogManager.getHeader(myContext, "add_parentConcept",
                "concept_id=" + getID() + ",parent_concept_id=" + incoming.getID()));

        // Find out if mapping exists
        TableRowIterator tri = DatabaseManager.queryTable(myContext,
                "Concept2Concept",
                "SELECT * FROM Concept2Concept WHERE " +
                        "outgoing_id= ? AND incoming_id= ? ", getID(), incoming.getID());

        try
        {
            if (!tri.hasNext())
            {
                // No existing mapping, so add one
                TableRow mappingRow = DatabaseManager.row("Concept2Concept");

                mappingRow.setColumn("outgoing_id", getID());
                mappingRow.setColumn("incoming_id", incoming.getID());
                mappingRow.setColumn("role_id", roleId);
                DatabaseManager.insert(myContext, mappingRow);
                myContext.addEvent(new Event(Event.ADD, Constants.CONCEPT, incoming.getID(), null));
            }
        }
        finally
        {
            // close the TableRowIterator to free up resources
            if (tri != null)
            {
                tri.close();
            }
        }
    }

    public void addChildConcept(Concept outgoing, int roleId) throws SQLException,
            AuthorizeException
    {
        // Check authorisation
        AuthorizeManager.isAdmin(myContext);

        log.info(LogManager.getHeader(myContext, "add_childConcept",
                "concept_id=" + getID() + ",child_concept_id=" + outgoing.getID()));

        // Find out if mapping exists
        TableRowIterator tri = DatabaseManager.queryTable(myContext,
                "Concept2Concept",
                "SELECT * FROM Concept2Concept WHERE " +
                        "incoming_id= ? AND outgoing_id= ? ", getID(), outgoing.getID());

        try
        {
            if (!tri.hasNext())
            {
                // No existing mapping, so add one
                TableRow mappingRow = DatabaseManager.row("Concept2Concept");

                mappingRow.setColumn("outgoing_id", outgoing.getID());
                mappingRow.setColumn("incoming_id", getID());
                mappingRow.setColumn("role_id", roleId);
                DatabaseManager.insert(myContext, mappingRow);
                myContext.addEvent(new Event(Event.ADD, Constants.CONCEPT, outgoing.getID(), null));
            }
        }
        finally
        {
            // close the TableRowIterator to free up resources
            if (tri != null)
            {
                tri.close();
            }
        }
    }
    public String getPreferredLabel() throws SQLException
    {

        Term[] preferTerms = getPreferredTerms();
        if(preferTerms!=null&&preferTerms.length>0)
        {
            return preferTerms[0].getLiteralForm();
        }
        else
        {
            return null;
        }
    }

    //guarentee return a label for concept
    public String getLabel() throws SQLException
    {

        String label = getPreferredLabel();
        if(label==null)
        {
            Term [] terms =getAltTerms();

            if(terms!=null&&terms.length>0)
            {
                label = terms[0].getLiteralForm();
            }

        }
        if(label==null)
        {
            label = getIdentifier();
        }
        return label;
    }

    public void addTerm(Term t,int role_id) throws SQLException,
            AuthorizeException
    {
        // Check authorisation
        AuthorizeManager.isAdmin(myContext);

        log.info(LogManager.getHeader(myContext, "add_term",
                "concept_id=" + getID() + ",term_id=" + t.getID()));

        // Find out if mapping exists
        TableRowIterator tri = DatabaseManager.queryTable(myContext,
                "concept2term",
                "SELECT * FROM concept2term WHERE " +
                        "concept_id= ? AND term_id= ? ",getID(),t.getID());

        try
        {
            if (!tri.hasNext())
            {
                // No existing mapping, so add one
                TableRow mappingRow = DatabaseManager.row("concept2term");

                mappingRow.setColumn("concept_id", getID());
                mappingRow.setColumn("term_id", t.getID());
                mappingRow.setColumn("role_id", role_id);
                DatabaseManager.insert(myContext, mappingRow);
                myContext.addEvent(new Event(Event.ADD, Constants.TERM,t.getID(), null));
            }
        }
        finally
        {
            // close the TableRowIterator to free up resources
            if (tri != null)
            {
                tri.close();
            }
        }
    }

    public static Concept[] findByPreferredLabel(Context context,String query,int schemeId){
        //make schemeId == -1 to get all match preferred label
        ArrayList<Concept> concepts = new ArrayList<Concept>();
        String dbquery = "SELECT concept.* FROM concept,concept2term,term where concept.id=concept2term.concept_id and concept2term.term_id=term.id and LOWER(term.literalform) = LOWER(?) order by term.literalform";
        try
        {

            TableRowIterator rows = DatabaseManager.queryTable(context,"Concept", dbquery, query);

            List<TableRow> conceptRows = rows.toList();

            for (int i = 0; i < conceptRows.size(); i++)
            {
                TableRow row = conceptRows.get(i);
                Concept concept = new Concept(context,row);
                if(schemeId==-1||concept.getScheme().getID()==schemeId){
                    concepts.add(new Concept(context, row));
                }

            }
            if (rows != null)
            {
                rows.close();
            }

            // Put them in an array
            Concept[] conceptArray = new Concept[concepts.size()];
            conceptArray = (Concept[]) concepts.toArray(conceptArray);
            return conceptArray;

        }
        catch (Exception e)
        {

            return null;
        }

    }

    public Term[] getTerms() throws SQLException{
        List<Term> terms = new ArrayList<Term>();

        // Get the table rows
        TableRowIterator tri = DatabaseManager.queryTable(
                myContext,"term",
                "SELECT term.* FROM term, concept2term WHERE " +
                        "concept2term.term_id=term.id " +
                        "AND concept2term.concept_id= ?",
                getID());

        // Make Concept objects
        try
        {
            while (tri.hasNext())
            {
                TableRow row = tri.next();

                // First check the cache
                Term fromCache = (Term) myContext.fromCache(
                        Term.class, row.getIntColumn("id"));

                if (fromCache != null)
                {
                    terms.add(fromCache);
                }
                else
                {
                    terms.add(new Term(myContext, row));
                }
            }
        }
        finally
        {
            // close the TableRowIterator to free up resources
            if (tri != null)
            {
                tri.close();
            }
        }

        // Put them in an array
        Term[] termArray = new Term[terms.size()];
        termArray = (Term[]) terms.toArray(termArray);

        return termArray;
    }
    public Term createTerm(String literalForm,int relationType)throws SQLException,AuthorizeException{
        Term term = Term.create(this.myContext);
        term.setLiteralForm(literalForm);
        term.setCreated(getCreated());
        term.setLang(getLang());
        term.setSource(getSource());
        term.setLastModified(getLastModified());
        addTermByType(term,relationType);
        return term;

    }

    /**
     * add an term member
     *
     * @param t
     *            term
     */
    public void addTermByType(Term t,int type)
    {

        log.info(LogManager.getHeader(myContext, "add_Term_by_type",
                "concept_id=" + getID() + ",term_id=" + t.getID())+",type="+type);
        TableRowIterator tri = null;
        try
        {
            // Find out if mapping exists
            tri = DatabaseManager.queryTable(myContext,
                    "concept2term",
                    "SELECT * FROM concept2term WHERE " +
                            "concept_id= ? AND term_id= ? AND role_id= ?",getID(),t.getID(),type);

            if (!tri.hasNext())
            {
                // No existing mapping, so add one
                TableRow mappingRow = DatabaseManager.row("concept2term");

                mappingRow.setColumn("concept_id", getID());
                mappingRow.setColumn("term_id", t.getID());
                mappingRow.setColumn("role_id", type);
                DatabaseManager.insert(myContext, mappingRow);
                myContext.addEvent(new Event(Event.ADD, Constants.TERM, t.getID(), null));
            }
        }        catch (Exception e)
        {
            // close the TableRowIterator to free up resources
            if (tri != null)
            {
                tri.close();
            }
            log.error("error when add preferred term");
        }
        finally
        {
            // close the TableRowIterator to free up resources
            if (tri != null)
            {
                tri.close();
            }
        }

    }

    @Override
    public DSpaceObject getParentObject() throws SQLException
    {
        return this.getScheme();
    }
}


text:
from django.db import migrations, models

class Migration(migrations.Migration):

    dependencies = [
        ('core', '0013_auto_20170116_2236'),
    ]

    operations = [
        migrations.AlterField(
            model_name='provider',
            name='status',
            field=models.CharField(choices=[('N', 'Aguardando moderação'), ('D', 'Em discussão'), ('P', 'Publicado'), ('R', 'Recusado'), ('E', 'Edição aguardando moderação'), ('O', 'Substituído por versão atualizada')], default='N', max_length=1, verbose_name='Status'),
        ),
    ]

redpajama_set_name: RedPajamaGithub


text:
package net.onrc.onos.core.configmanager;

import java.util.concurrent.ConcurrentHashMap;

import net.onrc.onos.core.configmanager.NetworkConfig.SwitchConfig;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class SwitchOF10Config extends SwitchConfig {
    protected static final Logger log = LoggerFactory
            .getLogger(RoadmConfig.class);

    public SwitchOF10Config(SwitchConfig swc) {
        this.setName(swc.getName());
        this.setDpid(swc.getDpid());
        this.setType(swc.getType());
        this.setLatitude(swc.getLatitude());
        this.setLongitude(swc.getLongitude());
        this.setParams(swc.getParams());
        this.setAllowed(swc.isAllowed());
        publishAttributes = new ConcurrentHashMap<String, String>();
        parseParams();
        validateParams();
        setPublishAttributes();
    }

    private void parseParams() {
        // TODO
    }

    private void validateParams() {
        // TODO
    }

    private void setPublishAttributes() {
        // TODO
    }
}


text:
using System;
using FeatureToggle;
using Xunit;

namespace FeatureToggle.Tests
{
    public class CompositeAndDecoratorShould
    {
        [Fact]
        public void ReturnFalseWhenOneWrappedToggleIsDisabled()
        {
            var sut = new CompositeAndDecorator(new AnEnabledFeature(), new ADisabledFeature());

            Assert.False(sut.FeatureEnabled);
        }

        [Fact]
        public void ReturnFalseWhenAllWrappedTogglesAreDisabled()
        {
            var sut = new CompositeAndDecorator(new ADisabledFeature(), new AnotherDisabledFeature());

            Assert.False(sut.FeatureEnabled);
        }

        [Fact]
        public void ReturnTrueWhenAllWrappedTogglesAreEnabled()
        {
            var sut = new CompositeAndDecorator(new AnEnabledFeature(), new AnotherEnabledFeature());

            Assert.True(sut.FeatureEnabled);
        }

        [Fact]
        public void ErrorWhenNullWrappedTogglesSupplied()
        {
            Assert.Throws<ArgumentNullException>(() => new CompositeAndDecorator(null));
        }

        [Fact]
        public void ErrorWhenNoWrappedTogglesSupplied()
        {
            Assert.Throws<ArgumentOutOfRangeException>(() => new CompositeAndDecorator());
        }

        private class AnEnabledFeature : AlwaysOnFeatureToggle {}
        private class AnotherEnabledFeature : AlwaysOnFeatureToggle {}
        private class ADisabledFeature : AlwaysOffFeatureToggle {}
        private class AnotherDisabledFeature : AlwaysOffFeatureToggle {}

    }
}


text:
/*
 * DO NOT EDIT THIS FILE!
 *
 * Automatically generated by SCons
 */

#ifndef __DEBUG_ExecFaulting_HH__
#define __DEBUG_ExecFaulting_HH__

namespace Debug {
class SimpleFlag;
extern SimpleFlag ExecFaulting;
}

#endif // __DEBUG_ExecFaulting_HH__


text:
require 'colored'
require 'credentials_manager/appfile_config'
require 'yaml'

require_relative 'tunes/tunes_client'

module Spaceship
  class SpaceauthRunner
    def initialize(username: nil)
      @username = username
      @username ||= CredentialsManager::AppfileConfig.try_fetch_value(:apple_id)
      @username ||= ask("Username: ")
    end

    def run
      begin
        puts("Logging into to App Store Connect (#{@username})...")
        Spaceship::Tunes.login(@username)
        puts("Successfully logged in to App Store Connect".green)
        puts("")
      rescue => ex
        puts("Could not login to App Store Connect".red)
        puts("Please check your credentials and try again.".yellow)
        puts("This could be an issue with App Store Connect,".yellow)
        puts("Please try unsetting the FASTLANE_SESSION environment variable".yellow)
        puts("(if it is set) and re-run `fastlane spaceauth`".yellow)
        puts("")
        puts("Exception type: #{ex.class}")
        raise ex
      end

      itc_cookie_content = Spaceship::Tunes.client.store_cookie

      # The only value we actually need is the "DES5c148586daa451e55afb017aa62418f91" cookie
      # We're not sure if the key changes
      #
      # Example:
      # name: DES5c148586daa451e55afb017aa62418f91
      # value: HSARMTKNSRVTWFlaF/ek8asaa9lymMA0dN8JQ6pY7B3F5kdqTxJvMT19EVEFX8EQudB/uNwBHOHzaa30KYTU/eCP/UF7vGTgxs6PAnlVWKscWssOVHfP2IKWUPaa4Dn+I6ilA7eAFQsiaaVT
      cookies = YAML.safe_load(
        itc_cookie_content,
        [HTTP::Cookie, Time], # classes whitelist
        [],                   # symbols whitelist
        true                  # allow YAML aliases
      )

      # We remove all the un-needed cookies
      cookies.select! do |cookie|
        cookie.name.start_with?("myacinfo") || cookie.name == "dqsid" || cookie.name.start_with?("DES")
      end

      yaml = cookies.to_yaml.gsub("\n", "\\n")

      puts("---")
      puts("")
      puts("Pass the following via the FASTLANE_SESSION environment variable:")
      puts(yaml.cyan.underline)
      puts("")
      puts("")
      puts("Example:")
      puts("export FASTLANE_SESSION='#{yaml}'".cyan.underline)

      if mac? && Spaceship::Client::UserInterface.interactive? && agree("🙄 Should fastlane copy the cookie into your clipboard, so you can easily paste it? (y/n)", true)
        require 'open3'
        Open3.popen3('pbcopy') { |input, _, _| input << yaml }
        puts("Successfully copied text into your clipboard 🎨".green)
      end
    end

    def mac?
      (/darwin/ =~ RUBY_PLATFORM) != nil
    end
  end
end


text:
using System;

namespace AvalonAssets.Rojy.Grid.Hex
{
    /// <summary>
    ///     Initializes <see cref="IHexCoordinate" /> and <see cref="IRingHexCoordinate" />.
    /// </summary>
    public static class HexCoordinates
    {
        /// <summary>
        ///     <para>
        ///         Initializes a new instance of <see cref="IHexCoordinate" /> with cube coordinate.
        ///     </para>
        /// </summary>
        /// <param name="x">X.</param>
        /// <param name="y">Y.</param>
        /// <param name="z">Z.</param>
        /// <returns>New <see cref="IHexCoordinate" />.</returns>
        /// <exception cref="ArgumentException"><paramref name="x" /> + <paramref name="y" /> + <paramref name="z" /> != 0</exception>
        public static IHexCoordinate Cube(int x, int y, int z)
        {
            return new HexCoordinate(x, y, z);
        }

        /// <summary>
        ///     <para>
        ///         Initializes a new instance of <see cref="IHexCoordinate" /> with axial coordinate.
        ///     </para>
        /// </summary>
        /// <param name="q">Q.</param>
        /// <param name="r">R.</param>
        /// <returns>New <see cref="IHexCoordinate" />.</returns>
        public static IHexCoordinate Axial(int q, int r)
        {
            return new HexCoordinate(q, r);
        }

        /// <summary>
        ///     <para>
        ///         Initializes a new instance of <see cref="IRingHexCoordinate" />.
        ///     </para>
        /// </summary>
        /// <param name="center">Center of <see cref="IRingHexCoordinate" />.</param>
        /// <param name="radius">Radius from <paramref name="center" />.</param>
        /// <param name="index">
        ///     Index start from 0. Count from the top of <paramref name="center" />.
        ///     If there are two, take the one on right.
        /// </param>
        /// <returns>New <see cref="IRingHexCoordinate" />.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="center" /> is null</exception>
        /// <exception cref="ArgumentOutOfRangeException"><paramref name="radius" /> or <paramref name="index" /> < 0</exception>
        public static IRingHexCoordinate Ring(IHexCoordinate center, int radius, int index)
        {
            return new RingHexCoordinate(center, radius, index);
        }
    }
}


text:
import { expect } from 'chai';
import { describe, it } from 'mocha';
import { setupTest } from '<%= modulePrefix %>/tests/helpers';

describe('<%= friendlyTestDescription %>', function () {
  setupTest();

  // TODO: Replace this with your real tests.
  it('exists', function () {
    let service = this.owner.lookup('service:<%= dasherizedModuleName %>');
    expect(service).to.be.ok;
  });
});


text:
<?php

class User_model extends CI_Model {
  public $username, $fullname, $email, $pass, $role, $activation_key, $forgot_key, $registered_on;

  public function __construct() {
    parent::__construct();
  }

  public function get_username() {
    return $this->username;
  }

  public function get_fullname() {
    return $this->fullname;
  }

  public function is_activated() {
    return empty($this->activation_key) || is_null($this->activation_key) ? FALSE : TRUE;
  }

  public function fill_model($username) {
    // Query will be created by Query Builder, which is a bit nice.
    if(! empty($username)) {
      $query = $this->db->get_where('users',[ 'username' => $username, ]);
      if($query->num_rows() > 0) {
          $result = $query->result()[0];
          $this->username = $result->username;
          $this->fullname = $result->fullname;
          $this->pass = $result->pass;
          $this->role = $result->role;
          $this->activation_key = $result->activation_key;
          $this->forgot_key = $result->forgot_key;
          $this->registered_on = $result->registered_on;
          return TRUE;
      }
    }
    return FALSE;
  }

  public function verify_password($password) {
    $password = $this->db->escape($password);
    if(! is_null($this->pass)) {
      var_dump($password);
      return password_verify($password, $this->pass);
    }
    return FALSE;
  }

  public function generate_password($password) {
    $password = $this->db->escape($password);
    return password_hash($password, PASSWORD_BCRYPT, ['cost' => 9]);
  }

  // Code for activation key are acquired
  // from http://stackoverflow.com/questions/3290283/what-is-a-good-way-to-produce-a-random-site-salt-to-be-used-in-creating-passwo/3291689#3291689
  public function generate_activation_key() {
    $charset = '12345987ABCEFHKLMNQOPSTVWXYZabthefoxyesabcdghijklmnpqrzuvr';
    $token = "";
    for($i = 0; $i < 62; $i++) {
      $token .= $charset[$this->randomize_key(0, strlen($charset))];
    }
    return $token;
  }

  private function randomize_key($min, $max) {
    if($max - $min < 0) return $min;
    $log = log($max-$min, 2);
    $bytes = (int) $log / 8 + 1;
    $filter = (int) (1 << (intval($log) + 1)) - 1;
    do {
      $rnd = hexdec(bin2hex(openssl_random_pseudo_bytes($bytes)));
      $rnd = $rnd & $filter;
    } while($rnd >= ($max - $min));
    return $min + $rnd;
  }

  public function save_new_user() {
    $old = $this->db->db_debug;
    $this->db->db_debug = FALSE;
    // TODO AUTO_INCREMENT always return last user id + sign up attemp, fix this.
    $this->db->trans_start();
    $this->db->simple_query("ALTER TABLE users SET AUTO_INCREMENT = 1");
    $query = $this->db->insert('users', [
        'username' => $this->username,
        'fullname' => $this->fullname,
        'email'    => $this->email,
        'pass'     => $this->password,
        'role'     => $this->role,
        'activation_key' => $this->activation_key,
    ]);
    $this->db->db_debug = $old;
    if($this->db->affected_rows() > 0 && $this->db->error()['code'] == 0 && $this->db->trans_status() == TRUE) {
      $this->db->trans_commit();
      return true;
    } else {
      $this->db->trans_rollback();
      return $this->db->error();
    }
  }

  public function get_role_name() {
    if(!(is_null($this->role) || empty($this->role))) {
      $query = $this->db->get_where('role',[ 'id' => $this->role, ]);
      if($query->num_rows() > 0)
        return $query->result()[0]->name;
    }
    return FALSE;
  }

  // public function init_admin() {
    // An example for trying bcrypt password

    // $query = $this->db->insert('users', [
    //     'username' => 'matt',
    //     'fullname' => 'Matthew Wu',
    //     'email'    => 'Ruswan.Wu@outlook.com',
    //     'pass'     => password_hash('passwordmusayangku', PASSWORD_BCRYPT, [ 'cost' => 12]),
    //     'role'     => 1,
    //   ]);
  // }
}


text:
<?php
// Setting Array of cookies
setcookie("setArraycookie[three]", "cookiethree");
setcookie("setArraycookie[two]", "cookietwo");
setcookie("setArraycookie[one]", "cookieone");
header('Location: setArraycookies-result.php');
?>


text:
require 'git-process/github_configuration'
require 'json'
require 'github_test_helper'
# require 'vcr'

describe GitHubService::Configuration, :git_repo_helper do
  include GitHubTestHelper

  def test_token
    'hfgkdjfgksjhdfkls'
  end

  def ghc
    @ghc ||= GitHubService::Configuration.new(gitlib.config, :user => 'tu', :password => 'dfsdf')
  end

  describe 'create_authorization' do

    it 'should return an auth_token for a good request' do
      gitlib.remote.add('origin', 'git@github.com:jdigger/git-process.git')
      stub_post('https://tu:dfsdf@api.github.com/authorizations', :send => auth_json,
                :body => JSON({:token => test_token}).to_s)

      ghc.create_authorization().should == test_token
    end

    it 'should 401 for bad password' do
      gitlib.remote.add('origin', 'git@github.com:jdigger/git-process.git')
      stub_post('https://tu:dfsdf@api.github.com/authorizations', :send => auth_json,
                :status => 401)

      expect { ghc.create_authorization() }.to raise_error Octokit::Unauthorized
    end

    it 'should 401 for needing two-factor authentication' do
      gitlib.remote.add('origin', 'git@github.com:jdigger/git-process.git')

      stub_request(:post, 'https://tu:dfsdf@api.github.com/authorizations').to_return do |request|
        # noinspection RubyStringKeysInHashInspection
        if request.headers.has_key? 'x-github-otp'
          {
              :body => JSON({:token => test_token}).to_s,
              :headers => {'Content-Type' => 'application/json'},
              :status => 200
          }
        else
          {
              :body => '',
              :status => 401,
              :headers => {'X-GitHub-OTP' => 'required; app'}
          }
        end
      end
      GitHubService::Configuration.stub(:ask_for_two_factor).and_return('572269')

      ghc.create_authorization().should == test_token
    end

    it 'should 422 if two-factor authorization already exists' do
      gitlib.remote.add('origin', 'git@github.com:jdigger/git-process.git')

      stub_request(:post, 'https://tu:dfsdf@api.github.com/authorizations').to_return do |request|
        # noinspection RubyStringKeysInHashInspection
        if request.headers.has_key? 'x-github-otp'
          {
              :body => JSON({errors: [{:resource => 'OauthAccess', :code => 'already_exists'}]}).to_s,
              :headers => {'Content-Type' => 'application/json'},
              :status => 422
          }
        else
          {
              :body => '',
              :status => 401,
              :headers => {'X-GitHub-OTP' => 'required; app'}
          }
        end
      end
      GitHubService::Configuration.stub(:ask_for_two_factor).and_return('572269')

      expect { ghc.create_authorization() }.to raise_error GitHubService::TokenAlreadyExists
    end

  end

  describe 'auth_token no username or password' do

    it 'should get the token from config if it exists' do
      gitlib.config['github.user'] = 'test_user'
      gitlib.config['gitProcess.github.authToken'] = test_token

      ghc.auth_token.should == test_token
    end

  end

  describe 'auth_token with password but no username' do

    def ghc
      @ghc ||= GitHubService::Configuration.new(gitlib.config, :user => nil, :password => 'dfsdf')
    end

    it 'should get the token from the server if it does not exist in config' do
      gitlib.remote.add('origin', 'git@github.com:jdigger/git-process.git')
      gitlib.config['github.user'] = 'test_user'
      gitlib.config['gitProcess.github.authToken'] = ''

      stub_post('https://test_user:dfsdf@api.github.com/authorizations', :send => auth_json,
                :body => JSON({:token => test_token}).to_s)

      ghc.auth_token.should == test_token
    end

  end

  describe "user" do

    def ghc
      @ghc ||= GitHubService::Configuration.new(gitlib.config, :user => nil, :password => 'dfsdf')
    end

    it "should get the value from config" do
      gitlib.config['github.user'] = 'test_user'

      ghc.user.should == 'test_user'
    end

    it 'should prompt the user and store it in the config' do
      gitlib.config['github.user'] = ''

      GitHubService::Configuration.stub(:ask_for_user).and_return('test_user')
      ghc.user.should == 'test_user'
    end

  end

  describe 'using GHE instead of GitHub.com' do

    it 'should use the correct server and path for a non-GitHub.com site' do
      gitlib.remote.add('origin', 'git@myco.com:jdigger/git-process.git')

      stub_post('https://tu:dfsdf@myco.com/api/v3/authorizations',
                :send => auth_json,
                :body => JSON({:token => test_token}).to_s)

      ghc.create_authorization().should == test_token
    end

    it 'site should raise an error if remote.origin.url not set' do
      gitlib.config['remote.origin.url'] = ''

      expect { ghc.base_github_api_url_for_remote }.to raise_error GitHubService::NoRemoteRepository
    end

    it 'site should not work for a garbage url address' do
      gitlib.remote.add('origin', 'garbage')

      expect { ghc.base_github_api_url_for_remote }.to raise_error URI::InvalidURIError
    end

    it 'site should work for an ssh-configured url address' do
      gitlib.remote.add('origin', 'git@github.myco.com:fooble')

      ghc.base_github_api_url_for_remote.should == 'https://github.myco.com'
    end

  end

  it '#url_to_base_github_api_url' do
    c = GitHubService::Configuration

    c.url_to_base_github_api_url('ssh://git@github.myco.com/fooble').should == 'https://github.myco.com'
    c.url_to_base_github_api_url('git://myco.com/jdigger/git-process.git').should == 'https://myco.com'
    c.url_to_base_github_api_url('http://github.myco.com/fooble').should == 'http://github.myco.com'
    c.url_to_base_github_api_url('http://tu@github.myco.com/fooble').should == 'http://github.myco.com'
    c.url_to_base_github_api_url('https://github.myco.com/fooble').should == 'https://github.myco.com'
    c.url_to_base_github_api_url('https://github.com/fooble').should == 'https://api.github.com'
  end

  def auth_json
    JSON({:scopes => %w(repo user gist),
          :note => 'Git-Process',
          :note_url => 'http://jdigger.github.com/git-process'}).to_s
  end

end


text:
package life

import com.badlogic.gdx.backends.lwjgl._

object Main extends App {
    val cfg = new LwjglApplicationConfiguration
    cfg.title = "life"
    cfg.width = 1420
    cfg.height = 880
    cfg.forceExit = false
    new LwjglApplication(new Life, cfg)
}


text:
extends: base.j2
title: Summer Camp Home
keywords: youth, child, kids, children, camp, all ages
description: Overview of the different summer camps available to all ages offered at Mt. Cross.
---
{% block HTMLheadExtended %}<link rel="stylesheet" href="/CSS/summer_table.css" type="text/css" media="screen">{%endblock%}
{% block mainContainerContents %}

Summer Camp

Summer Theme: {{summer.info.theme}}

      {% if summer.info.verse %}

{{summer.info.verse}}

      {% endif %}

View Full Summer Schedule

      {{register_button}}

Camps include activities such as swimming, hiking, campfire cookouts,  Bible encounters and campfire devotions, and the Challenge Course (high ropes and low ropes elements).

Cabin groups create their activity schedule from a list of age appropriate activities, participate in all camp activities, spend time at the Trading Post and feast on quality camp food including a main entree', and a salad bar with fresh vegetable and fruit selections.

Campers can invite friends, select cabinmates or come alone to meet new friends. Combine several camps with Connections or use Connections for a Saturday or Sunday pick-up.

      <object id="vp1G4v0w" width="299" height="219" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000">
         <param name="movie" value="http://static.animoto.com/swf/w.swf?w=swf/vp1&e=1330387430&f=G4v0wZxKnMW9RkIHGEWddg&d=106&m=p&r=240p+480p&volume=100&start_res=480p&i=m&ct=&cu=&options=">
         <param name="allowFullScreen" value="true">
         <param name="allowscriptaccess" value="always">
         <embed id="vp1G4v0w" src="http://static.animoto.com/swf/w.swf?w=swf/vp1&e=1330387430&f=G4v0wZxKnMW9RkIHGEWddg&d=106&m=p&r=240p+480p&volume=100&start_res=480p&i=m&ct=&cu=&options=" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="400" height="293"></embed>
      </object>

Residential Camps

Family Camp

Confirmation Camp

		SHALOM

3rd Graders

        Explorers

 Connections Weekend Option

4th-6th Graders

        Pathfinders

        Tree Toppers

 Connections Weekend Option

7th-9th Graders

        Trailblazers

        Beach Camp

        Tree Toppers with High Ropes

 Connections Weekend Option

9th-12th Graders

        CIT (1st year)

        aCIT (2nd year)

        Junior Counselor (3rd year)

Adults with Special Needs

      Special Friends Week

Servant Opportunities

      Adventures on the Coast

      Special Friends Servants

Adult Staff Positions

Summer Staff & Counselors

    Pastor in Residence for the week

    Certified Nurse for a week of camp

Offsite Camps

Day Camps

Experience a taste of Mt. Cross at a location in Northern California.

To find a day camp in your area, please click here to see the churches already signed up for Day Camp.

{{current_year}} Summer Schedule

Youth are categorized by the grade they will enter Fall {{current_year}}.

{{macros.create_summer_calendar()}}

{% endblock %} {# closes mainContainerContents #}