head	1.12;
access;
symbols
	TIGRIS_0_9_2_4:1.3.2.1
	TIGRIS_0_9_2_3:1.3
	HELM_PEER_PORT_BRANCH:1.9.0.2
	TURBINE_PEER:1.9
	TIGRIS_0_9_2_1:1.9
	TIGRIS_0_9_2:1.3.0.2;
locks; strict;
comment	@# @;


1.12
date	2001.02.21.03.23.56;	author edk;	state dead;
branches;
next	1.11;

1.11
date	2001.02.08.02.41.05;	author elicia;	state Exp;
branches;
next	1.10;

1.10
date	2001.01.30.02.36.22;	author elicia;	state Exp;
branches;
next	1.9;

1.9
date	2001.01.26.18.29.00;	author edk;	state Exp;
branches
	1.9.2.1;
next	1.8;

1.8
date	2001.01.26.05.24.05;	author edk;	state dead;
branches;
next	1.7;

1.7
date	2001.01.25.01.38.06;	author leonardr;	state Exp;
branches;
next	1.6;

1.6
date	2001.01.24.22.24.36;	author leonardr;	state Exp;
branches;
next	1.5;

1.5
date	2001.01.24.20.42.46;	author dlr;	state Exp;
branches;
next	1.4;

1.4
date	2001.01.23.02.29.19;	author elicia;	state Exp;
branches;
next	1.3;

1.3
date	2001.01.16.23.04.29;	author elicia;	state Exp;
branches
	1.3.2.1;
next	1.2;

1.2
date	2001.01.12.22.12.13;	author elicia;	state Exp;
branches;
next	1.1;

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

1.3.2.1
date	2001.02.01.18.49.23;	author jrobbins;	state Exp;
branches;
next	;

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


desc
@@


1.12
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.io.*;
import java.util.*;
import java.sql.*;

import org.webmacro.util.Log;

import com.workingdogs.village.*;

import org.joist.database.*;

import org.tigris.helm.security.AccessControlList;
import org.tigris.helm.tool.*;
import org.tigris.helm.project.Document;

/**
 * Project documents.
 *
 * @@author <a href="mailto:elicia@@collab.net">Elicia David</a>
 * @@version $Id: ProjectDocumentManager.java,v 1.11 2001/02/08 02:41:05 elicia Exp $
 *
 * Copyright (c) 2000 CollabNet, Inc.
 */
public class ProjectDocumentManager extends TableManager
{
    /**
     * The name of the database table that this <code>TableManager</code> 
     * manages.
     */
    public static final String TABLE_NAME = "HELM_PROJECTDOCUMENT";

    /**
     * The name of the database table that this <code>TableManager</code> 
     * manages.
     */
    public static final String JOIN_TABLE = "HELM_PROJECT_DOCUMENT_SECTION";

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

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

    /**
     * The name of the document.
     */
    public static final String NAME = "NAME";

    /**
     * Indicates whether the document was uploaded, or 
     * saved at a remote URL, or saved into the database.
     */
    public static final String TYPE = "TYPE";

    /**
     * The directory structure to the file.
     */
    public static final String LOCATION = "LOCATION";

    /**
     * The name of the uploaded file.
     */
    public static final String FILE_NAME = "FILE_NAME";

    /**
     * The url to the file location.
     */
    public static final String URL = "URL";

    /**
     * The text of the document.
     */
    public static final String TEXT = "TEXT";

    /**
     * Description of the file.
     */
    public static final String DESCRIPTION = "DESCRIPTION";

    /**
     * User ID of the person who approved this upload.
     */
    public static final String APPROVED_BY = "APPROVED_BY";

    /**
     * User ID of the person who uploaded.
     */
    public static final String SUGGESTED_BY = "SUGGESTED_BY";

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

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

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

    /**
     * Retrieves document by ID
     *
     * @@param    conn    A JDBC database connection
     * @@return           a Record
     * @@exception    SQLException
     * @@exception    DataSetException
     */
    public Record getDocumentForID (Connection conn,
                                    String documentID)
        throws SQLException, DataSetException
    {
        TableDataSet document = null;

        try
        {
            document = new TableDataSet (conn, TABLE_NAME);
            document.where(DOCUMENT_ID + '=' + documentID);
            document.fetchRecords();
        }
        finally
        {
            registerToClose (document);
        }

        return document.getRecord(0);
    }

    /**
     * Retrieves documents for a project.
     *
     * @@param conn      The JDBC database connection to use.
     * @@param projectID The project to retrieve documents for.
     * @@return          The any documents for the project.
     *
     * @@exception DataSetException
     * @@exception SQLException
     */
    public DataSet getDocumentsForProject (Connection conn, String projectID)
        throws SQLException, DataSetException
    {
        TableDataSet documents = null;
        try
        {
            documents = new TableDataSet(conn, TABLE_NAME);
            documents.where(PROJECT_ID + '=' + projectID);
            documents.fetchRecords();
        }
        finally
        {
            registerToClose(documents);
        }
        return documents;
    }

    public DataSet getUnapprovedDocumentsForProject (Connection conn, 
                                                     String projectID)
        throws SQLException, DataSetException, JoistDatabaseException
    {
        TableDataSet documents = null;
        try
        {
            documents = new TableDataSet(conn, TABLE_NAME);
            UserUserGroupManager usrGrpMgr = 
               (UserUserGroupManager)getDataManager().getManager
               ("org.tigris.helm.database.UserUserGroupManager");
            String nobodyID = usrGrpMgr.getNobodyUserID(conn);
            documents.where(APPROVED_BY + '=' + nobodyID 
                            + " and " + PROJECT_ID + '=' + projectID);
            documents.fetchRecords();
        }
        finally
        {
            registerToClose(documents);
        }
        return documents;
    }

    public String getDocumentsQuery()
    {
        return "SELECT * FROM " + TABLE_NAME;
    }

    public String getDocumentsForProjectQuery(Connection conn,
                                              String projectID)
        throws SQLException, DataSetException, JoistDatabaseException
    {
        Criterion c = new Criterion(PROJECT_ID, projectID);
        return getDocumentsQuery() + " WHERE " + c.toString();
    }

    
    /**
     * Approves the document in the name of the given userID.
     *
     * @@param conn         The JDBC database connection to use.
     * @@param documentID   The document to approve.
     * @@param userID      The user approving the project.
     *
     * @@exception SQLException
     * @@exception DataSetException 
     */
    public void approveDocument(Connection conn,
                                String documentID, String userID)
        throws SQLException, DataSetException, JoistDatabaseException,
               UpdateException              
    {
        Record dc = null;
        TableDataSet documents = null;

        try
        {
            documents = new TableDataSet(conn, TABLE_NAME,
                                         new KeyDef().addAttrib(DOCUMENT_ID));
            if (documentID != null)
            {
                documents.where(DOCUMENT_ID + '=' + documentID);
                documents.fetchRecords();
                dc = documents.getRecord(0);
            }
            setField(dc, APPROVED_BY, userID);
            dc.save();

        }
        finally
        {
            registerToClose(documents);
        }
    }

    /**
     * Adds a document.
     *
     * @@param conn       The JDBC database connection to use.
     * @@param projectID  The database key of the project to do the add for.
     * @@param name             The name of the document.
     * @@param descrip    The document's description.
     * @@param suggestedBy The database key of the user doing the upload.
     * @@param approvedBy The database key of the user approving the upload.
     */
    public Record addDocument (Connection conn, String projectID,
                               String name, String descrip, String type,
                               String url, String text,  
                               String suggestedBy, String approvedBy, 
                               String sectionID, File f)
        throws SQLException, DataSetException, JoistDatabaseException
    {
        return updateDocument(conn, null, projectID, name, descrip, type,
                              url, text, suggestedBy, 
                              approvedBy, sectionID, f);
    }

    /**
     * Updates or adds a document.
     *
     * @@param conn       The JDBC database connection to use.
     * @@param documentID The database key of the document to update, or
     *                   <code>null</code> if the document is new.
     * @@param name       The name of the document.
     * @@param descrip    The document's description.
     * @@param suggestedBy The database key of the user doing the upload.
     * @@param approvedBy The database key of the user approving the upload.
     * @@return           The database key of the document.
     *
     * @@exception SQLException
     * @@exception DataSetException
     */
    private Record updateDocument (Connection conn, String documentID, 
                                   String projectID, String name,  
                                   String descrip, String type,
                                   String url, String text,
                                   String suggestedBy, String approvedBy,
                                   String sectionID, File f)
        throws SQLException, DataSetException, JoistDatabaseException
    {
        Record dc = null;

        TableDataSet documents = null;
        try
        {
            documents = new TableDataSet(conn, TABLE_NAME,
                                         new KeyDef().addAttrib(DOCUMENT_ID));
            if (documentID != null)
            {
                // Updating existing document.
                documents.where(DOCUMENT_ID + '=' + documentID);
                documents.fetchRecords();
                dc = documents.getRecord(0);
            }
            else
            {
                // Adding new document.
                dc = documents.addRecord();
                setField(dc, SUGGESTED_BY, suggestedBy);
            }
            setField(dc, PROJECT_ID, projectID);
            setField(dc, DESCRIPTION, descrip);
            setField(dc, TYPE, type);
            if (f != null)
            {
                setField(dc, LOCATION, Document.extractLocation(f));
                setField(dc, FILE_NAME, f.getName());
            }
            setField(dc, URL, url);
            setField(dc, TEXT, text);
            setField(dc, NAME, name);
            setField(dc, APPROVED_BY, approvedBy);
            dc.save();
            if (documentID == null)
            {
                documentID = getLastInsertedID(conn).toString();
            }

            ProjectDocumentSectionManager pdsMgr = 
               (ProjectDocumentSectionManager)getDataManager().getManager
               ("org.tigris.helm.database.ProjectDocumentSectionManager");

            // Update record in document-section join table
            if (sectionID.equals("0"))
            {
                pdsMgr.deleteRecord(conn, documentID);
            } else {
                pdsMgr.updateRecord(conn, documentID, sectionID);
            }
        }
        finally
        {
            registerToClose(documents);
        }
        return dc;

    }


    /**
     * Updates the specified document.
     *
     * @@param conn        The JDBC database connection to use.
     * @@param documentID  The database key of the document to update, or
     *                    <code>null</code> if the document is new.
     * @@param descrip     The document's description.
     * @@param approvedBy  The database key of the approving user.
     *
     * @@exception SQLException
     * @@exception DataSetException
     */
    public void editDocument (Connection conn, String documentID, 
                              String name, String descrip, String type,
                              String url, String text, 
                              String sectionID, File f)
        throws SQLException, DataSetException, JoistDatabaseException
    {
        updateDocument(conn, documentID, null, name, descrip, type, 
                       url, text, null, null, sectionID, f);
    }

    /**
     * Deletes an existing document from the database
     *
     * @@param      conn the JDBC database connection
     * @@param      documentID       the ID of the document to delete
     * @@exception SQLException
     */
    public void deleteDocument (Connection conn, String documentID)
        throws SQLException, DataSetException, JoistDatabaseException
    {
        TableDataSet documents = null;
        try
        {
            
            documents = new TableDataSet (conn, TABLE_NAME,
                                          new KeyDef().addAttrib(DOCUMENT_ID));
            documents.where (DOCUMENT_ID + '=' + documentID);
            documents.fetchRecords();
            if (documents.containsRecord(0)) 
            {
                Record r = documents.getRecord(0);
                r.markToBeDeleted();
                r.save();
                // Delete record in document section join table
                ProjectDocumentSectionManager pdsMgr = 
                   (ProjectDocumentSectionManager)getDataManager().getManager
                   ("org.tigris.helm.database.ProjectDocumentSectionManager");
                pdsMgr.deleteRecord(conn, documentID);
            }
        }
        finally
        {
            registerToClose(documents);
        }
    }
}
@


1.11
log
@fixed bug in SQL statement
@
text
@d67 1
a67 1
 * @@version $Id: ProjectDocumentManager.java,v 1.10 2001/01/30 02:36:22 elicia Exp $
@


1.10
log
@fixed bug in updating a document-section record
@
text
@d67 1
a67 1
 * @@version $Id: ProjectDocumentManager.java,v 1.9 2001/01/26 18:29:00 edk Exp $
a223 1
            documents.where(PROJECT_ID + '=' + projectID);
d228 2
a229 1
            documents.where(APPROVED_BY + '=' + nobodyID);
@


1.9
log
@readding all the files as part of the process of returning to the way
things were as of tuesday
@
text
@d67 1
a67 1
 * @@version $Id: ProjectDocumentManager.java,v 1.4 2001/01/23 02:29:19 elicia Exp $
d374 4
d379 1
a379 1
            if (!sectionID.equals("0"))
d381 2
a382 3
                ProjectDocumentSectionManager pdsMgr = 
                   (ProjectDocumentSectionManager)getDataManager().getManager
                   ("org.tigris.helm.database.ProjectDocumentSectionManager");
@


1.9.2.1
log
@Porting to the Turbine Peer system.  -dlr and leonardr
@
text
@d67 1
a67 1
 * @@version $Id: ProjectDocumentManager.java,v 1.9 2001/01/26 18:29:00 edk Exp $
@


1.8
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
@d67 1
a67 1
 * @@version $Id: ProjectDocumentManager.java,v 1.7 2001/01/25 01:38:06 leonardr Exp $
d158 1
a158 1
        super (dataMgr, new KeyDef().addAttrib(DOCUMENT_ID));
a160 9
    public String getDocumentsQuery()
    {
        return "SELECT * FROM " + TABLE_NAME;
    }

    ////////////////////////////////////////////////////////////////
    // Accessor methods.
    ////////////////////////////////////////////////////////////////

d164 8
a171 6
     * @@return       a Record
     * @@exception    DBException if a database problem occurs.
     * @@exception    DoesNotExist if the documentID is invalid.
     */
    public Record getDocumentForID (String documentID)
        throws DBException, DoesNotExist
d173 3
a175 3
        Criterion c = new Criterion(DOCUMENT_ID, documentID);
        Record r = getFirstMatchingDocument(c);
        if (r == null)
d177 3
a179 1
            throw new DoesNotExist("Document with ID " + documentID);
d181 1
a181 16
        return r;
    }

    /**
     * Retrieves document by ID
     *
     * @@return       a Record
     * @@exception    DBException if a database problem occurs.
     * @@exception    DoesNotExist if the documentID is invalid.
     */
    public Record getDocumentForID (String documentID)
        throws DBException, DoesNotExist
    {
        Criterion c = new Criterion(DOCUMENT_ID, documentID);
        Record r = getFirstMatchingDocument(c);
        if (r == null)
d183 1
a183 1
            throw new DoesNotExist("Document with ID " + documentID);
d185 2
a186 1
        return r;
d192 1
d196 2
a197 1
     * @@exception    DBException if a database problem occurs.
d199 20
a218 2
    public DataSet getDocumentsForProject (String projectID)
        throws DBException
d220 17
a236 1
        return getDocuments(new Criterion(PROJECT_ID, projectID));
d239 8
a246 2
    public DataSet getUnapprovedDocumentsForProject (String projectID)
        throws DBException
a247 3
        UserManager uMgr = (UserManager)getDataManager().getManager
            ("org.tigris.helm.database.UserManager");
        String nobodyID = uMgr.getNobodyUserID();
d249 1
a249 2
        c.and(new Criterion(APPROVED_BY, nobodyID));
        return getDocuments(c);
d252 1
d254 1
a254 1
     * Returns the first document matching a given Criterion. 
d256 3
a258 3
     * @@param criterion Criterion to use in select.
     *
     * @@exception DBException if a database error occurs.
d260 2
a261 2
     * @@return Null if no matching document, first document in
     * recordset otherwise.  
d263 4
a266 2
    private Record getFirstMatchingDocument(Criterion criterion)
        throws DBException
d268 8
a275 4
        Record r = null;
        try {
            DataSet s = getDocuments(criterion);
            if (s != null && s.containsRecord(0))
d277 3
a279 1
                r = s.getRecord(0);
d281 3
a283 2
        } catch (DataSetException e) {
            throw new DBException(e);
d285 3
a287 19

        return r;
    }

    /**
     * Returns documents matching a given criterion, sorted by real name.
     *
     * @@param criterion Criterion to use in select.
     *
     * @@exception DBException if a database error occurs.
     */
    public DataSet getDocuments(Criterion criterion)
        throws DBException
    {
        DataSet s = null;
        try {
            s = runSelect(TABLE_NAME, criterion);
        } catch (Exception e) {
            throw new DBException(e);
a288 1
        return s;
a290 4
    ////////////////////////////////////////////////////////////////
    // Mutator methods.
    ////////////////////////////////////////////////////////////////
    
d294 1
d300 7
a306 10
     *
     * @@exception DBException if a database error occurs.
     * @@exception AlreadyExists if a document with the given name already
     *            exists in the given project.
     */
    public synchronized Record addDocument 
        (String projectID, String name, String descrip, String type, 
         String url, String text, String suggestedBy, String approvedBy, 
         String sectionID, File f)
        throws DBException, AlreadyExists
d308 3
a310 14
        Criterion c = new Criterion(PROJECT_ID, projectID);
        c.and(new Criterion(NAME, name));
        Record r = getFirstMatchingDocument(c);
        if (c != null)
        {
            throw new AlreadyExists("Document " + name + " in project " + projectID);
        }              
        
        Record r = null;
        try {
            updateDocument(null, projectID, name, descrip, type,
                           url, text, suggestedBy, approvedBy, sectionID, 
                           f);
        } catch (DoesNotExist ignore) {}
d314 1
a314 2
     * Updates or adds a document, depending on whether or not a null
     * <code>documentID</code> is specified.    
d316 1
a318 1
     * @@param projectID  The project associated with the documnet.
d325 2
a326 2
     * @@exception DBException if a database error occurs.  
     * @@exception DoesNotExist if the documentID specified is invalid.
d328 1
a328 1
    private Record updateDocument (String documentID, 
d334 1
a334 1
        throws DBException, DoesNotExist
d336 1
a337 2
        DBConnection dbConn = null;
        Record dc = null;
a338 1

d341 2
d345 8
a352 5
                dc = getDocument(downloadID);
            } else {
                dbConn = TurbineDB.getConnection();
                documents = new TableDataSet(dbconn.getConnection(), 
                                             TABLE_NAME, keydef);
a355 1

a368 1

a370 2
                // NOTE: There is no way to refresh a Village Record which has
                // been created using TableDataSet.addRecord().
d380 1
a380 9
                pdsMgr.mapDocumentToSection(documentID, sectionID);
            }
        } catch (Exception e) {
            throw new DBException(e);
        } finally {
            try {
                TurbineDB.releaseConnection(dbConn);
            } catch (Exception e) {
                throw new DBException(e);
d382 3
a386 1

d391 1
d401 2
a402 2
     * @@exception DBException if a database error occurs.
     * @@exception DoesNotExist if the specified documentID is invalid.
d404 3
a406 2
    public void editDocument (String documentID, String name, String descrip, 
                              String type, String url, String text, 
d408 1
a408 1
        throws DBException, DoesNotExist
a414 23
     * Approves the document in the name of the given userID.
     *
     * @@param documentID   The document to approve.
     * @@param userID       The user approving the project.
     *
     * @@exception DBException if a database error occurs.
     * @@exception DoesNotExist if the specified documentID is invalid.
     */
    public void approveDocument(String documentID, String userID)
        throws DBException, DoesNotExist
    {
        Record dc = getDocument(documentID);
        try {
            setField(dc, APPROVED_BY, userID);
            dc.save();
        } catch (SQLException e) {
            throw new DBException(e);
        } catch (DataSetException e) {
            throw new DBException(e);
        }
    }

    /**
d417 1
d419 1
a419 1
     * @@exception DBException if a database error occurs.
d421 2
a422 2
    public void deleteDocument (String documentID)
        throws DBException
d424 2
a425 6
        Record dc = null;
        try {
            dc = getDocument(documentID);
        } catch (DoesNotExist ignore) {}
        
        if (dc != null)
d427 8
a434 1
            try {
d439 3
a441 5
                    (ProjectDocumentSectionManager)getDataManager().getManager
                    ("org.tigris.helm.database.ProjectDocumentSectionManager");
                pdsMgr.deleteRecord(documentID);
            } catch (DataSetException e) {
                throw new DBException(e);
d443 4
@


1.7
log
@More TableManagers de-connectionified.
@
text
@d67 1
a67 1
 * @@version $Id: ProjectDocumentManager.java,v 1.6 2001/01/24 22:24:36 leonardr Exp $
@


1.6
log
@Moved TableManagers to new keydef constructor and keydef-less runSelect.
@
text
@d67 1
a67 1
 * @@version $Id: ProjectDocumentManager.java,v 1.5 2001/01/24 20:42:46 dlr Exp $
d161 9
d173 3
a175 4
     * @@param    conn    A JDBC database connection
     * @@return           a Record
     * @@exception    SQLException
     * @@exception    DataSetException
d177 2
a178 3
    public Record getDocumentForID (Connection conn,
                                    String documentID)
        throws DBException
d180 3
a182 3
        TableDataSet document = null;

        try
d184 1
a184 3
            document = new TableDataSet (conn, TABLE_NAME);
            document.where(DOCUMENT_ID + '=' + documentID);
            document.fetchRecords();
d186 16
a201 1
        finally
d203 1
a203 1
            registerToClose (document);
d205 1
a205 2

        return document.getRecord(0);
a210 1
     * @@param conn      The JDBC database connection to use.
d214 1
a214 2
     * @@exception DataSetException
     * @@exception SQLException
d216 1
a216 1
    public DataSet getDocumentsForProject (Connection conn, String projectID)
d219 1
a219 16
        TableDataSet documents = null;
        try
        {
            documents = new TableDataSet(conn, TABLE_NAME);
            documents.where(PROJECT_ID + '=' + projectID);
            documents.fetchRecords();
        }
        catch (DataSetException e)
        {
            throw new DBException(e);
        }
        finally
        {
            registerToClose(documents);
        }
        return documents;
d222 1
a222 2
    public DataSet getUnapprovedDocumentsForProject (Connection conn, 
                                                     String projectID)
d225 6
a230 17
        TableDataSet documents = null;
        try
        {
            documents = new TableDataSet(conn, TABLE_NAME);
            documents.where(PROJECT_ID + '=' + projectID);
            UserUserGroupManager usrGrpMgr = 
               (UserUserGroupManager)getDataManager().getManager
               ("org.tigris.helm.database.UserUserGroupManager");
            String nobodyID = usrGrpMgr.getNobodyUserID(conn);
            documents.where(APPROVED_BY + '=' + nobodyID);
            documents.fetchRecords();
        }
        finally
        {
            registerToClose(documents);
        }
        return documents;
d233 12
a244 1
    public String getDocumentsQuery()
d246 10
a255 2
        return "SELECT * FROM " + TABLE_NAME;
    }
d257 1
a257 6
    public String getDocumentsForProjectQuery(Connection conn,
                                              String projectID)
        throws DBException
    {
        Criterion c = new Criterion(PROJECT_ID, projectID);
        return getDocumentsQuery() + " WHERE " + c.toString();
a259 1
    
d261 1
a261 1
     * Approves the document in the name of the given userID.
d263 1
a263 3
     * @@param conn         The JDBC database connection to use.
     * @@param documentID   The document to approve.
     * @@param userID      The user approving the project.
d265 1
a265 2
     * @@exception SQLException
     * @@exception DataSetException 
d267 2
a268 4
    public void approveDocument(Connection conn,
                                String documentID, String userID)
        throws DBException,
               UpdateException              
d270 5
a274 19
        Record dc = null;
        TableDataSet documents = null;

        try
        {
            documents = new TableDataSet(conn, TABLE_NAME, keydef);
            if (documentID != null)
            {
                documents.where(DOCUMENT_ID + '=' + documentID);
                documents.fetchRecords();
                dc = documents.getRecord(0);
            }
            setField(dc, APPROVED_BY, userID);
            dc.save();

        }
        finally
        {
            registerToClose(documents);
d276 1
d279 4
a285 1
     * @@param conn       The JDBC database connection to use.
d291 10
a300 7
     */
    public Record addDocument (Connection conn, String projectID,
                               String name, String descrip, String type,
                               String url, String text,  
                               String suggestedBy, String approvedBy, 
                               String sectionID, File f)
        throws DBException
d302 14
a315 3
        return updateDocument(conn, null, projectID, name, descrip, type,
                              url, text, suggestedBy, 
                              approvedBy, sectionID, f);
d319 2
a320 1
     * Updates or adds a document.
a321 1
     * @@param conn       The JDBC database connection to use.
d324 1
d331 2
a332 2
     * @@exception SQLException
     * @@exception DataSetException
d334 1
a334 1
    private Record updateDocument (Connection conn, String documentID, 
d340 1
a340 1
        throws DBException
d342 2
d345 1
a346 1
        TableDataSet documents = null;
a348 1
            documents = new TableDataSet(conn, TABLE_NAME, keydef));
d351 5
a355 8
                // Updating existing document.
                documents.where(DOCUMENT_ID + '=' + documentID);
                documents.fetchRecords();
                dc = documents.getRecord(0);
            }
            else
            {
                // Adding new document.
d359 1
d373 1
d376 2
d387 9
a395 1
                pdsMgr.updateRecord(conn, documentID, sectionID);
a396 3
        }
        finally
        {
d399 1
a403 1

d413 2
a414 2
     * @@exception SQLException
     * @@exception DataSetException
d416 2
a417 3
    public void editDocument (Connection conn, String documentID, 
                              String name, String descrip, String type,
                              String url, String text, 
d419 1
a419 1
        throws DBException
d426 23
a450 1
     * @@param      conn the JDBC database connection
d452 1
a452 1
     * @@exception SQLException
d454 1
a454 1
    public void deleteDocument (Connection conn, String documentID)
d457 6
a462 2
        TableDataSet documents = null;
        try
d464 1
a464 7
            
            documents = new TableDataSet (conn, TABLE_NAME, keydef);
            documents.where (DOCUMENT_ID + '=' + documentID);
            documents.fetchRecords();
            if (documents.containsRecord(0)) 
            {
                Record r = documents.getRecord(0);
d469 5
a473 3
                   (ProjectDocumentSectionManager)getDataManager().getManager
                   ("org.tigris.helm.database.ProjectDocumentSectionManager");
                pdsMgr.deleteRecord(conn, documentID);
a474 8
        }
        catch (DataSetException e)
        {
            throw new DBException(e);
        }
        finally
        {
            registerToClose(documents);
@


1.5
log
@Making use of DBException.
@
text
@d67 1
a67 1
 * @@version $Id: ProjectDocumentManager.java,v 1.4 2001/01/23 02:29:19 elicia Exp $
d158 1
a158 1
        super (dataMgr);
d277 1
a277 2
            documents = new TableDataSet(conn, TABLE_NAME,
                                         new KeyDef().addAttrib(DOCUMENT_ID));
d344 1
a344 2
            documents = new TableDataSet(conn, TABLE_NAME,
                                         new KeyDef().addAttrib(DOCUMENT_ID));
d430 1
a430 2
            documents = new TableDataSet (conn, TABLE_NAME,
                                          new KeyDef().addAttrib(DOCUMENT_ID));
@


1.4
log
@added filename and file arguments
@
text
@d67 1
a67 1
 * @@version $Id: ProjectDocumentManager.java,v 1.3 2001/01/16 23:04:29 elicia Exp $
d171 1
a171 1
        throws SQLException, DataSetException
d200 1
a200 1
        throws SQLException, DataSetException
d209 4
d222 1
a222 1
        throws SQLException, DataSetException, JoistDatabaseException
d250 1
a250 1
        throws SQLException, DataSetException, JoistDatabaseException
d269 1
a269 1
        throws SQLException, DataSetException, JoistDatabaseException,
d310 1
a310 1
        throws SQLException, DataSetException, JoistDatabaseException
d338 1
a338 1
        throws SQLException, DataSetException, JoistDatabaseException
d412 1
a412 1
        throws SQLException, DataSetException, JoistDatabaseException
d426 1
a426 1
        throws SQLException, DataSetException, JoistDatabaseException
d447 4
@


1.3
log
@added arguments (new fields)

added getUnapprovedDocumentsForProject method
@
text
@d67 1
a67 1
 * @@version $Id: ProjectDocumentManager.java,v 1.2 2001/01/12 22:12:13 elicia Exp $
d101 6
d112 5
d238 1
d302 4
a305 4
                               String name, String descrip,
                               String location, String url, 
                               String text,  String suggestedBy,
                               String approvedBy, String sectionID)
d308 3
a310 3
        return updateDocument(conn, null, projectID, name, descrip,
                              location, url, text, suggestedBy, 
                              approvedBy, sectionID);
d330 1
a330 1
                                   String descrip, String location, 
d333 1
a333 1
                                   String sectionID)
d358 6
a363 1
            setField(dc, LOCATION, location);
d405 3
a407 3
                              String name, String descrip,
                              String location, String url, 
                              String text, String sectionID)
d410 2
a411 2
        updateDocument(conn, documentID, null, name, descrip, location,
                       url, text, null, null, sectionID);
@


1.3.2.1
log
@moved changed from HEAD for ProjectDocuments and ProjectDownloads
@
text
@d67 1
a67 1
 * @@version $Id: ProjectDocumentManager.java,v 1.10 2001/01/30 02:36:22 elicia Exp $
a100 6
     * Indicates whether the document was uploaded, or 
     * saved at a remote URL, or saved into the database.
     */
    public static final String TYPE = "TYPE";

    /**
a105 5
     * The name of the uploaded file.
     */
    public static final String FILE_NAME = "FILE_NAME";

    /**
a226 1

d290 4
a293 4
                               String name, String descrip, String type,
                               String url, String text,  
                               String suggestedBy, String approvedBy, 
                               String sectionID, File f)
d296 3
a298 3
        return updateDocument(conn, null, projectID, name, descrip, type,
                              url, text, suggestedBy, 
                              approvedBy, sectionID, f);
d318 1
a318 1
                                   String descrip, String type,
d321 1
a321 1
                                   String sectionID, File f)
d346 1
a346 6
            setField(dc, TYPE, type);
            if (f != null)
            {
                setField(dc, LOCATION, Document.extractLocation(f));
                setField(dc, FILE_NAME, f.getName());
            }
a356 4
            ProjectDocumentSectionManager pdsMgr = 
               (ProjectDocumentSectionManager)getDataManager().getManager
               ("org.tigris.helm.database.ProjectDocumentSectionManager");

d358 1
a358 1
            if (sectionID.equals("0"))
d360 3
a362 2
                pdsMgr.deleteRecord(conn, documentID);
            } else {
d388 3
a390 3
                              String name, String descrip, String type,
                              String url, String text, 
                              String sectionID, File f)
d393 2
a394 2
        updateDocument(conn, documentID, null, name, descrip, type, 
                       url, text, null, null, sectionID, f);
@


1.2
log
@added getQuery methods
@
text
@d67 1
a67 1
 * @@version $Id: ProjectDocumentManager.java,v 1.1 2000/12/30 05:04:53 elicia Exp $
d106 10
d205 22
d240 1
a240 13
    public String getUnapprovedDocumentsForProjectQuery(Connection conn,
                                                       String projectID)
        throws SQLException, DataSetException, JoistDatabaseException
    {
        UserUserGroupManager usrGrpMgr = 
            (UserUserGroupManager)getDataManager().getManager
            ("org.tigris.helm.database.UserUserGroupManager");
        String nobodyID = usrGrpMgr.getNobodyUserID(conn);
        Criterion c = new Criterion(APPROVED_BY, Criterion.EXACT_MATCH, 
                                    nobodyID);
        return getDocumentsForProjectQuery(conn, projectID) + " AND " + c.toString();
    }

d256 21
a276 3
        Record document = getDocumentForID(conn, documentID);
        document.setValue(APPROVED_BY, userID);
        document.save();
d290 3
a292 2
                               String name, String location, 
                               String descrip, String suggestedBy,
d296 3
a298 2
        return updateDocument(conn, null, projectID, name, location,
                              descrip, suggestedBy, approvedBy, sectionID);
d318 2
a319 1
                                   String location, String descrip, 
d347 2
d360 4
a363 4
               ProjectDocumentSectionManager pdsMgr = 
                  (ProjectDocumentSectionManager)getDataManager().getManager
                  ("org.tigris.helm.database.ProjectDocumentSectionManager");
               pdsMgr.updateRecord(conn, documentID, sectionID);
d388 3
a390 2
                              String name, String location,
                              String descrip, String sectionID)
d393 2
a394 2
        updateDocument(conn, documentID, null, name, location, descrip,
                       null, null, sectionID);
@


1.1
log
@initial revision
@
text
@a57 1
//import org.joist.util.*;
d67 1
a67 1
 * @@version $Id: ProjectDocumentManager.java,v 1.21 2000/12/12 23:03:48 dlr Exp $
d93 1
a93 1
    public static final String DOCUMENT_PROJECT_ID = "PROJECT_ID";
d185 1
a185 1
            documents.where(DOCUMENT_PROJECT_ID + '=' + projectID);
d195 26
d303 1
a303 1
            setField(dc, DOCUMENT_PROJECT_ID, projectID);
@

