head	1.9;
access;
symbols
	TIGRIS_0_9_2_4:1.2.2.1
	TIGRIS_0_9_2_3:1.2
	HELM_PEER_PORT_BRANCH:1.7.0.2
	TURBINE_PEER:1.7
	TIGRIS_0_9_2_1:1.7
	TIGRIS_0_9_2:1.2.0.2;
locks; strict;
comment	@# @;


1.9
date	2001.02.21.03.23.56;	author edk;	state dead;
branches;
next	1.8;

1.8
date	2001.01.30.02.36.50;	author elicia;	state Exp;
branches;
next	1.7;

1.7
date	2001.01.26.18.29.00;	author edk;	state Exp;
branches
	1.7.2.1;
next	1.6;

1.6
date	2001.01.26.05.24.05;	author edk;	state dead;
branches;
next	1.5;

1.5
date	2001.01.25.01.38.06;	author leonardr;	state Exp;
branches;
next	1.4;

1.4
date	2001.01.24.22.24.36;	author leonardr;	state Exp;
branches;
next	1.3;

1.3
date	2001.01.24.20.42.46;	author dlr;	state Exp;
branches;
next	1.2;

1.2
date	2001.01.12.22.12.52;	author elicia;	state Exp;
branches
	1.2.2.1;
next	1.1;

1.1
date	2000.12.30.05.04.53;	author elicia;	state Exp;
branches;
next	;

1.2.2.1
date	2001.02.01.18.49.24;	author jrobbins;	state Exp;
branches;
next	;

1.7.2.1
date	2001.01.28.01.02.17;	author dlr;	state dead;
branches;
next	;


desc
@@


1.9
log
@delete stuff from the head which is obsolete in the branch (more changes
are still needed for a clean compile)
@
text
@/* ================================================================
 * Copyright (c) 2000 CollabNet.  All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are
 * met:
 * 
 * 1. Redistributions of source code must retain the above copyright
 * notice, this list of conditions and the following disclaimer.
 * 
 * 2. Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 * 
 * 3. The end-user documentation included with the redistribution, if
 * any, must include the following acknowlegement: "This product includes
 * software developed by CollabNet (http://www.collab.net/)."
 * Alternately, this acknowlegement may appear in the software itself, if
 * and wherever such third-party acknowlegements normally appear.
 * 
 * 4. The hosted project names must not be used to endorse or promote
 * products derived from this software without prior written
 * permission. For written permission, please contact info@@collab.net.
 * 
 * 5. Products derived from this software may not use the "Tigris" name
 * nor may "Tigris" appear in their names without prior written
 * permission of CollabNet.
 * 
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 * IN NO EVENT SHALL COLLABNET OR ITS CONTRIBUTORS BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * ====================================================================
 * 
 * This software consists of voluntary contributions made by many
 * individuals on behalf of CollabNet.
 */

package org.tigris.helm.database;

import java.sql.*;
import java.util.*;

import org.webmacro.util.*;
import org.webmacro.servlet.*;

import com.workingdogs.village.*;

import org.joist.database.*;
import org.joist.util.*;

import org.tigris.helm.DoesNotExist;
import org.tigris.helm.domain.User;
import org.tigris.helm.project.Project;
import org.tigris.helm.security.AccessControlList;
import org.tigris.helm.tool.*;

/**
 * Manages the Document-Section two way join table.
 *
 * @@author <a href="mailto:leonardr@@collab.net">Elicia David</a>
 * @@version $Id: ProjectDocumentSectionManager.java,v 1.8 2001/01/30 02:36:50 elicia Exp $
 *
 * Copyright (c) 2000 CollabNet, Inc.
 */
public class ProjectDocumentSectionManager extends TableManager
{
    /**
     * The name of the database table that this <code>TableManager</code> 
     * manages.
     */
    public static final String TABLE_NAME = "HELM_PROJECT_DOCUMENT_SECTION";

    /**
     * A database key field.
     */
    public static final String DOCUMENT_ID = "DOCUMENT_ID";

    /**
     * A database key field.
     */
    public static final String SECTION_ID = "SECTION_ID";


    /**
     * The logger instance for all instances of this class.
     */
    private static Log log = new Log ("pdsMgr", "ProjectDocumentSectionMgr");

    /**
     * Whether we want debugging information.
     */
    private static final boolean debug = true;

    /**
     * Creates a new instance.
     *
     * @@param dataMgr The manager of this instance.
     */
    public ProjectDocumentSectionManager (DataManager dataMgr)
    {
        super (dataMgr);
    }

    /**
     * Retrieves the documents in a section.
     *
     * @@param    conn    A JDBC database connection
     * @@param    sectionID   The sectionID to obtain documents for
     * @@return     a DataSet
     * @@exception    SQLException
     * @@exception    DataSetException
     */
    public DataSet getDocumentsForSection (Connection conn,
                                           String sectionID)
        throws SQLException, DataSetException
    {
        TableDataSet documents = null; 

        try
        {
            documents = new TableDataSet (conn, TABLE_NAME);
            documents.where(SECTION_ID + "=" + sectionID);
            documents.fetchRecords ();
        }
        catch (DataSetException e)
        {
            log.exception (e);
            if (debug)
                log.info ("Getting Documents: " + e.getMessage());
            throw e;
        }
        catch (SQLException e)
        {
            log.exception (e);
            if (debug)
                log.info ("Getting Documents " + e.getMessage ());
            throw e;
        }
        finally
        {
            registerToClose (documents);
        }
        return documents;
    }

    /**
     * Gets the sectionID of the section the document is associated with
     *
     * @@param    conn    A JDBC database connection
     * @@param    documentID   The database key of the document
     * @@return     a String; if there no section, return 0
     * @@exception    SQLException
     * @@exception    DataSetException
     */
    public String getSectionIDForDocument (Connection conn,
                                           String documentID)
        throws SQLException, DataSetException
    {
        TableDataSet documents = null; 
        String sectionID = "0";

        try
        {
            documents = new TableDataSet (conn, TABLE_NAME);
            documents.where(DOCUMENT_ID + "=" + documentID);
            documents.fetchRecords ();
            if (documents.containsRecord (0))
            {
                Record r = documents.getRecord (0);
                sectionID = r.getValue(SECTION_ID).asString();
            }
        }
        catch (DataSetException e)
        {
            log.exception (e);
            if (debug)
                log.info ("Getting SectionID: " + e.getMessage());
            throw e;
        }
        catch (SQLException e)
        {
            log.exception (e);
            if (debug)
                log.info ("Getting SectionID " + e.getMessage ());
            throw e;
        }
        finally
        {
            registerToClose (documents);
        }
        return sectionID;
    }

    /**
     * Updates a record in the table
     *
     *
     * @@param connection          The JDBC database connection to use.
     * @@param documentID          The database key of the document to update 
     * @@param sectionID           The id of the section (or null, if
     *                                document is to be top level)
     * @@return  nothing
     *
     * @@exception SQLException
     * @@exception DataSetException 
     */
    public void updateRecord (Connection connection, String documentID,
                              String sectionID)
        throws SQLException, DataSetException, JoistDatabaseException
    {
        TableDataSet documents = null;
        Record r;

        try
        {
            KeyDef kd = new KeyDef ().addAttrib (DOCUMENT_ID);
            documents = new TableDataSet (connection, TABLE_NAME, kd);
            documents.where(DOCUMENT_ID + "=" +  documentID);
            documents.fetchRecords ();

            // If a record exists, delete it 
            if (documents.containsRecord (0))
            {
                r = documents.getRecord (0);
                r.markToBeDeleted();
            }

            r = documents.addRecord();
            r.setValue(DOCUMENT_ID, documentID);
            r.setValue(SECTION_ID, sectionID);

            documents.save();
        }
        catch (DataSetException e)
        {
            log.exception (e);
            String message = "Updating ProjectDocumentSection: " + e.getMessage ();
            if (debug) log.info (message);
            throw e;
        }
        catch (SQLException e)
        {
            log.exception (e);
            String message = "Updating ProjectDocumentSection: " + e.getMessage ();
            if (debug) log.info (message);
            throw e;
        }
        finally
        {
            registerToClose (documents);
        }
    }

    /**
     * Deletes a record in the table
     *
     *
     * @@param connection          The JDBC database connection to use.
     * @@param documentID          The database key of the document to update 
     * @@return  nothing
     *
     * @@exception SQLException
     * @@exception DataSetException 
     */
    public void deleteRecord (Connection connection, String documentID)
        throws SQLException, DataSetException
    {
        TableDataSet documents = null;
        Record r;

        try
        {
            KeyDef kd = new KeyDef ().addAttrib (DOCUMENT_ID);
            documents = new TableDataSet (connection, TABLE_NAME, kd);
            documents.where(DOCUMENT_ID + "=" + documentID);
            documents.fetchRecords ();

            // If a record exists, delete it 
            if (documents.containsRecord (0))
            {
                r = documents.getRecord (0);
                r.markToBeDeleted();
            }
            documents.save();
        }
        catch (DataSetException e)
        {
            log.exception (e);
            String message = "Deleting ProjectDocumentSection: " + e.getMessage ();
            if (debug) log.info (message);
            throw e;
        }
        catch (SQLException e)
        {
            log.exception (e);
            String message = "Deleting ProjectDocumentSection: " + e.getMessage ();
            if (debug) log.info (message);
            throw e;
        }
        finally
        {
            registerToClose (documents);
        }
    }
}
@


1.8
log
@cleanup
@
text
@d70 1
a70 1
 * @@version $Id: ProjectDocumentSectionManager.java,v 1.7 2001/01/26 18:29:00 edk Exp $
@


1.7
log
@readding all the files as part of the process of returning to the way
things were as of tuesday
@
text
@d70 1
a70 1
 * @@version $Id: ProjectDocumentSectionManager.java,v 1.2 2001/01/12 22:12:52 elicia Exp $
d160 1
a160 1
     * @@return     a String
d169 1
a169 1
        String sectionID = null;
a178 1
                log.info("record=" + r);
a179 1
                log.info("sectionID" + sectionID);
d236 4
a239 6
            else
            {
                r = documents.addRecord();
                r.setValue(DOCUMENT_ID, documentID);
                r.setValue(SECTION_ID, sectionID);
            }
@


1.7.2.1
log
@Porting to the Turbine Peer system.  -dlr and leonardr
@
text
@d70 1
a70 1
 * @@version $Id: ProjectDocumentSectionManager.java,v 1.7 2001/01/26 18:29:00 edk Exp $
@


1.6
log
@revert this stuff to its state as of 2001/01/24 12:42:00 GMT -- with
the following exceptions, which have some different modifications so
they'll work with changes which have happened in joist:

ProjectNewsEdit.java
SkinManager.java
SkinStyleElementValueManager.java
StyleElementManager.java
StyleManager.java

it compiles.  i dunno if it works, though.
@
text
@d70 1
a70 1
 * @@version $Id: ProjectDocumentSectionManager.java,v 1.5 2001/01/25 01:38:06 leonardr Exp $
d110 1
a110 1
        super (dataMgrm, KeyDef kd = new KeyDef().addAttrib(DOCUMENT_ID).addAttrib(SECTION_ID));
a112 4
    ////////////////////////////////////////////////////////////////
    // Mutator methods.
    ////////////////////////////////////////////////////////////////

d116 1
d119 2
a120 1
     * @@exception    DBException if a database error occurs.
d122 31
a152 5
    public DataSet getDocumentsForSection (String sectionID)
        throws DBException
    {        
        Criterion c = new Criterion(SECTION_ID, sectionID);
        return getMappings(c);
d161 2
a162 1
     * @@exception    DBException if a database error occurs.
d164 3
a166 2
    public String getSectionIDForDocument (String documentID)
        throws DBException
d168 1
d171 1
a171 4
        Criterion c = new Criterion(DOCUMENT_ID, documentID);
        Record r = getFirstMatchingMapping(c);

        if (r != null)
d173 4
a176 24
            sectionID = r.getValue(SECTION_ID).asString();
        } catch (DataSetException e) {
            throw new DBException(e);
        }
        return sectionID;
    }

    /**
     * Returns the first mapping matching a given Criterion. 
     *
     * @@param criterion Criterion to use in select.
     *
     * @@exception DBException if a database error occurs.
     *
     * @@return Null if no matching mapping, first mapping in recordset
     * otherwise.  
     */
    private Record getFirstMatchingMapping(Criterion criterion)
        throws DBException
    {
        Record r = null;
        try {
            DataSet s = getMappings(criterion);
            if (s != null && s.containsRecord(0))
d178 4
a181 1
                r = s.getRecord(0);
a182 2
        } catch (DataSetException e) {
            throw new DBException(e);
d184 19
a202 2

        return r;
d206 1
a206 3
     * Returns mappings matching a given criterion.
     *
     * @@param criterion Criterion to use in select.
a207 20
     * @@exception DBException if a database error occurs.
     */
    public DataSet getMappings(Criterion criterion)
    throws DBException
    {
        DataSet s = null;
        try {
            s = runSelect(TABLE_NAME, criterion);
        } catch (Exception e) {
            throw new DBException(e);
        }
        return s;
    }

    ////////////////////////////////////////////////////////////////
    // Mutator methods.
    ////////////////////////////////////////////////////////////////

    /**
     * Map a document to a section. 
d209 1
d211 1
a211 1
     * @@param sectionID           The id of the new section (or null, if
d215 2
a216 2
     * @@exception DBException if a database error occurs.
     * @@exception DoesNotExist if the documentID is invalid.
d218 3
a220 2
    public void mapDocumentToSection (String documentID, String sectionID)
        throws DBException
d222 12
a233 5
        Criterion c = new Criterion(DOCUMENT_ID, documentID);
        Record r = null;
        try {
            DataSet d = getMappings(c);
            if (d.hasRecord(0))
d235 2
a236 1
                r = d.getRecord(0);
d238 1
a238 2
            
            if (r != null && sectionID == null)
d240 1
a240 8
                //There's a record, which we should be deleting
                r.markToBeDeleted();
            } else if (r != null) {
                //There's a record, which we should be modifying.
                r.setValue(SECTION_ID, sectionID);
            } else if (documentID != null) {
                //There's no record, and we should be adding one.
                r = d.addRecord();
d244 20
a263 9
            
            if (r != null)
            {
                r.save();
            }
        } catch (SQLException e) {
            throw new DBException(e);
        } catch (DataSetException e) {
            throw new DBException(e);
d270 2
d275 2
a276 1
     * @@exception DBException
d278 2
a279 2
    public void deleteRecord (String documentID)
        throws DBException
d281 4
a284 6
        Record r = null;
        try {
            r = getDocument(documentID);
        } catch (DoesNotExist ignore) {}
        
        if (r != null)
d286 9
a294 1
            try {
a295 5
                r.save();
            } catch (SQLException e) {
                throw new DBException(e);
            } catch (DataSetException e) {
                throw new DBException(e);
d297 19
a316 1
        
@


1.5
log
@More TableManagers de-connectionified.
@
text
@d70 1
a70 1
 * @@version $Id: ProjectDocumentSectionManager.java,v 1.4 2001/01/24 22:24:36 leonardr Exp $
@


1.4
log
@Moved TableManagers to new keydef constructor and keydef-less runSelect.
@
text
@d70 1
a70 1
 * @@version $Id: ProjectDocumentSectionManager.java,v 1.3 2001/01/24 20:42:46 dlr Exp $
d113 4
a119 1
     * @@param    conn    A JDBC database connection
d122 1
a122 2
     * @@exception    SQLException
     * @@exception    DataSetException
d124 1
a124 2
    public DataSet getDocumentsForSection (Connection conn,
                                           String sectionID)
d126 3
a128 22
    {
        TableDataSet documents = null; 

        try
        {
            documents = new TableDataSet (conn, TABLE_NAME);
            documents.where(SECTION_ID + "=" + sectionID);
            documents.fetchRecords ();
        }
        catch (DataSetException e)
        {
            throw new DBException(e);
        }
        catch (SQLException e)
        {
            throw new DBException(e);
        }
        finally
        {
            registerToClose (documents);
        }
        return documents;
d137 1
a137 2
     * @@exception    SQLException
     * @@exception    DataSetException
d139 1
a139 2
    public String getSectionIDForDocument (Connection conn,
                                           String documentID)
a141 1
        TableDataSet documents = null; 
d144 4
a147 1
        try
d149 24
a172 4
            documents = new TableDataSet (conn, TABLE_NAME);
            documents.where(DOCUMENT_ID + "=" + documentID);
            documents.fetchRecords ();
            if (documents.containsRecord (0))
d174 1
a174 4
                Record r = documents.getRecord (0);
                log.info("record=" + r);
                sectionID = r.getValue(SECTION_ID).asString();
                log.info("sectionID" + sectionID);
d176 1
a176 3
        }
        catch (DataSetException e)
        {
d179 18
a196 2
        catch (SQLException e)
        {
d199 1
a199 5
        finally
        {
            registerToClose (documents);
        }
        return sectionID;
d202 4
d207 1
a207 1
     * Updates a record in the table
a208 2
     *
     * @@param connection          The JDBC database connection to use.
d210 1
a210 1
     * @@param sectionID           The id of the section (or null, if
d214 2
a215 2
     * @@exception SQLException
     * @@exception DataSetException 
d217 1
a217 2
    public void updateRecord (Connection connection, String documentID,
                              String sectionID)
d220 5
a224 11
        TableDataSet documents = null;
        Record r;

        try
        {
            documents = new TableDataSet (connection, TABLE_NAME, keydef);
            documents.where(DOCUMENT_ID + "=" +  documentID);
            documents.fetchRecords ();

            // If a record exists, delete it 
            if (documents.containsRecord (0))
d226 1
a226 2
                r = documents.getRecord (0);
                r.markToBeDeleted();
d228 2
a229 1
            else
d231 8
a238 1
                r = documents.addRecord();
d242 6
a247 5

            documents.save();
        }
        catch (DataSetException e)
        {
d249 1
a249 3
        }
        catch (SQLException e)
        {
a251 4
        finally
        {
            registerToClose (documents);
        }
a256 2
     *
     * @@param connection          The JDBC database connection to use.
d262 1
a262 1
    public void deleteRecord (Connection connection, String documentID)
d265 6
a270 4
        TableDataSet documents = null;
        Record r;

        try
d272 1
a272 8
            documents = new TableDataSet (connection, TABLE_NAME, keydef);
            documents.where(DOCUMENT_ID + "=" + documentID);
            documents.fetchRecords ();

            // If a record exists, delete it 
            if (documents.containsRecord (0))
            {
                r = documents.getRecord (0);
d274 5
a279 13
            documents.save();
        }
        catch (DataSetException e)
        {
            throw new DBException(e);
        }
        catch (SQLException e)
        {
            throw new DBException(e);
        }
        finally
        {
            registerToClose (documents);
d281 1
@


1.3
log
@Making use of DBException.
@
text
@d70 1
a70 1
 * @@version $Id: ProjectDocumentSectionManager.java,v 1.2 2001/01/12 22:12:52 elicia Exp $
d110 1
a110 1
        super (dataMgr);
d215 1
a215 2
            KeyDef kd = new KeyDef ().addAttrib (DOCUMENT_ID);
            documents = new TableDataSet (connection, TABLE_NAME, kd);
d266 1
a266 2
            KeyDef kd = new KeyDef ().addAttrib (DOCUMENT_ID);
            documents = new TableDataSet (connection, TABLE_NAME, kd);
@


1.2
log
@added getSectionIDForDocument method
@
text
@d70 1
a70 1
 * @@version $Id: ProjectDocumentSectionManager.java,v 1.1 2000/12/30 05:04:53 elicia Exp $
d124 1
a124 1
        throws SQLException, DataSetException
d136 1
a136 4
            log.exception (e);
            if (debug)
                log.info ("Getting Documents: " + e.getMessage());
            throw e;
d140 1
a140 4
            log.exception (e);
            if (debug)
                log.info ("Getting Documents " + e.getMessage ());
            throw e;
d160 1
a160 1
        throws SQLException, DataSetException
d180 1
a180 4
            log.exception (e);
            if (debug)
                log.info ("Getting SectionID: " + e.getMessage());
            throw e;
d184 1
a184 4
            log.exception (e);
            if (debug)
                log.info ("Getting SectionID " + e.getMessage ());
            throw e;
d208 1
a208 1
        throws SQLException, DataSetException, JoistDatabaseException
d237 1
a237 4
            log.exception (e);
            String message = "Updating ProjectDocumentSection: " + e.getMessage ();
            if (debug) log.info (message);
            throw e;
d241 1
a241 4
            log.exception (e);
            String message = "Updating ProjectDocumentSection: " + e.getMessage ();
            if (debug) log.info (message);
            throw e;
d257 1
a257 2
     * @@exception SQLException
     * @@exception DataSetException 
d260 1
a260 1
        throws SQLException, DataSetException
d282 1
a282 4
            log.exception (e);
            String message = "Deleting ProjectDocumentSection: " + e.getMessage ();
            if (debug) log.info (message);
            throw e;
d286 1
a286 4
            log.exception (e);
            String message = "Deleting ProjectDocumentSection: " + e.getMessage ();
            if (debug) log.info (message);
            throw e;
@


1.2.2.1
log
@moved changed from HEAD for ProjectDocuments and ProjectDownloads
@
text
@d70 1
a70 1
 * @@version $Id: ProjectDocumentSectionManager.java,v 1.8 2001/01/30 02:36:50 elicia Exp $
d160 1
a160 1
     * @@return     a String; if there no section, return 0
d169 1
a169 1
        String sectionID = "0";
d179 1
d181 1
d238 6
a243 4

            r = documents.addRecord();
            r.setValue(DOCUMENT_ID, documentID);
            r.setValue(SECTION_ID, sectionID);
@


1.1
log
@initial revision
@
text
@d70 1
a70 1
 * @@version $Id: UserRoleProjectManager.java,v 1.11 2000/12/01 22:14:50 elicia Exp $
d156 1
a156 2
     * Determines whether a document is top-level; i.e., 
     * Whether or not it is associated with a section
d160 1
a160 1
     * @@return     a DataSet
d164 2
a165 2
    public boolean isTopLevelDocument (Connection conn,
                                       String documentID)
d169 1
a169 1
        boolean isTopLevel = true;
a175 1

d178 4
a181 1
                isTopLevel = false;
d188 1
a188 1
                log.info ("Getting Documents: " + e.getMessage());
d195 1
a195 1
                log.info ("Getting Documents " + e.getMessage ());
d202 1
a202 1
        return isTopLevel;
@

