head	1.28;
access;
symbols
	TIGRIS_0_9_2_4:1.21
	TIGRIS_0_9_2_3:1.21
	HELM_PEER_PORT_BRANCH:1.26.0.2
	TURBINE_PEER:1.26
	TIGRIS_0_9_2_1:1.26
	TIGRIS_0_9_2:1.21.0.4
	TIGRIS_0_9_0:1.21.0.2
	TIGRIS_0_8_4:1.14.0.2
	NEWHELM:1.1.1.1
	TIGRIS_NOV_12_2000:1.1.1;
locks; strict;
comment	@# @;


1.28
date	2001.02.21.03.23.56;	author edk;	state dead;
branches;
next	1.27;

1.27
date	2001.02.08.02.41.28;	author elicia;	state Exp;
branches;
next	1.26;

1.26
date	2001.01.26.18.29.00;	author edk;	state Exp;
branches
	1.26.2.1;
next	1.25;

1.25
date	2001.01.26.05.24.05;	author edk;	state dead;
branches;
next	1.24;

1.24
date	2001.01.25.01.38.06;	author leonardr;	state Exp;
branches;
next	1.23;

1.23
date	2001.01.24.22.24.36;	author leonardr;	state Exp;
branches;
next	1.22;

1.22
date	2001.01.24.20.42.46;	author dlr;	state Exp;
branches;
next	1.21;

1.21
date	2000.12.12.23.03.48;	author dlr;	state Exp;
branches;
next	1.20;

1.20
date	2000.12.12.20.04.34;	author dlr;	state Exp;
branches;
next	1.19;

1.19
date	2000.12.12.02.34.34;	author dlr;	state Exp;
branches;
next	1.18;

1.18
date	2000.12.12.01.20.37;	author dlr;	state Exp;
branches;
next	1.17;

1.17
date	2000.12.11.23.39.07;	author dlr;	state Exp;
branches;
next	1.16;

1.16
date	2000.12.05.05.05.17;	author dlr;	state Exp;
branches;
next	1.15;

1.15
date	2000.12.05.00.22.04;	author dlr;	state Exp;
branches;
next	1.14;

1.14
date	2000.11.22.01.31.47;	author dlr;	state Exp;
branches;
next	1.13;

1.13
date	2000.11.21.00.10.22;	author elicia;	state Exp;
branches;
next	1.12;

1.12
date	2000.11.17.22.21.38;	author dlr;	state Exp;
branches;
next	1.11;

1.11
date	2000.11.17.19.48.23;	author dlr;	state Exp;
branches;
next	1.10;

1.10
date	2000.11.16.01.44.11;	author dlr;	state Exp;
branches;
next	1.9;

1.9
date	2000.11.15.23.13.13;	author elicia;	state Exp;
branches;
next	1.8;

1.8
date	2000.11.15.21.31.30;	author dlr;	state Exp;
branches;
next	1.7;

1.7
date	2000.11.15.21.13.03;	author elicia;	state Exp;
branches;
next	1.6;

1.6
date	2000.11.15.03.34.18;	author dlr;	state Exp;
branches;
next	1.5;

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

1.4
date	2000.11.15.00.13.25;	author dlr;	state Exp;
branches;
next	1.3;

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

1.2
date	2000.11.14.03.44.34;	author dlr;	state Exp;
branches;
next	1.1;

1.1
date	2000.11.12.21.15.00;	author dlr;	state Exp;
branches
	1.1.1.1;
next	;

1.1.1.1
date	2000.11.12.21.15.00;	author dlr;	state Exp;
branches;
next	;

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


desc
@@


1.28
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.text.SimpleDateFormat;
import java.security.MessageDigest;
import java.sql.*;

import org.webmacro.util.Log;

import com.workingdogs.village.*;

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

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

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

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

    /**
     * The name of the file itself (includes no path information).
     */
    public static final String FILE_NAME = "FILE_NAME";

    /**
     * The directory structure to the file (minus the actual file name).
     */
    public static final String LOCATION = "LOCATION";

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

    /**
     * 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 UPLOADED_BY = "UPLOADED_BY";

    /**
     * Date file was uploaded.
     */
    public static final String UPLOAD_DATE = "UPLOAD_DATE";
    
    /**
     * Description of the file.
     */
    public static final String DESCRIPTION = "DESCRIPTION";
    
    /**
     * Whether the download is private.
     */
    public static final String IS_PUBLIC = "IS_PUBLIC";

    /**
     * File size.
     */
    public static final String SIZE = "SIZE";

    /**
     * The MD5 checksum field.
     */
    public static final String MD5_CHECKSUM = "MD5";

    /**
     * The buffer size used when computing the MD5 checksum of a file.
     */
    private static final int MD5_BUF_SIZE = 4096;

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

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

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

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

        try
        {
            download = new TableDataSet (conn, TABLE_NAME);
            download.where(DOWNLOAD_ID + '=' + downloadID);
            download.fetchRecords();
        }
        finally
        {
            registerToClose (download);
        }

        return download.getRecord(0);
    }

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

    /**
     * Retrieves unapproved downloads for a project.
     *
     * @@param conn      The JDBC database connection to use.
     * @@param projectID The project to retrieve downloads for.
     * @@return          The any downloads for the project.
     *
     * @@exception DataSetException
     * @@exception SQLException
     */
    public DataSet getUnapprovedDownloadsForProject
                        (Connection conn, String projectID)
        throws SQLException, DataSetException, JoistDatabaseException
    {
        TableDataSet downloads = null;
        try
        {
            downloads = new TableDataSet(conn, TABLE_NAME);
            UserUserGroupManager usrGrpMgr = 
               (UserUserGroupManager)getDataManager().getManager
               ("org.tigris.helm.database.UserUserGroupManager");
            String nobodyID = usrGrpMgr.getNobodyUserID(conn);
            downloads.where(APPROVED_BY + '=' + nobodyID 
                            + " and " + PROJECT_ID + '=' + projectID);
            downloads.fetchRecords();
        }
        finally
        {
            registerToClose(downloads);
        }
        return downloads;
    }

    /**
     * Retrieves the specified download.
     *
     * @@exception DataSetException
     * @@exception SQLException
     */
    public Record getDownloadForFile(Connection conn, String projectID,
                                     String uploadedBy, String fileName)
        throws DataSetException, SQLException
    {
        Record dl = null;
        TableDataSet downloads = null;
        try
        {
            downloads = new TableDataSet(conn, TABLE_NAME);
            String where = PROJECT_ID + '=' + projectID + " AND " +
                UPLOADED_BY + '=' + uploadedBy + " AND " + FILE_NAME + '=' +
                fileName;
            if (debug) log.info("where=" + where);
            downloads.where(where);
            if (downloads.fetchRecords(1).containsRecord(0))
            {
                dl = downloads.getRecord(0);
            }
        }
        finally
        {
            if (downloads != null) downloads.close();
        }
        return dl;
    }

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

        try
        {
            downloads = new TableDataSet(conn, TABLE_NAME,
                                         new KeyDef().addAttrib(DOWNLOAD_ID));
            if (downloadID != null)
            {
                downloads.where(DOWNLOAD_ID + '=' + downloadID);
                downloads.fetchRecords();
                dl = downloads.getRecord(0);
            }
            setField(dl, APPROVED_BY, userID);
            dl.save();

        }
        finally
        {
            registerToClose(downloads);
        }
    }

    /**
     * Adds a download.
     *
     * @@param conn       The JDBC database connection to use.
     * @@param projectID  The database key of the project to do the add for.
     * @@param descrip    The download's description.
     * @@param uploadedBy The database key of the user doing the upload.
     * @@param approvedBy The database key of the user approving the upload.
     * @@param isPublic   Whether the download is public.
     */
    public Record addDownload (Connection conn, String projectID,
                               File f, String descrip, String uploadedBy,
                               String approvedBy, String isPublic)
        throws SQLException, DataSetException
    {
        return updateDownload(conn, null, projectID, f, descrip, uploadedBy,
                              approvedBy, isPublic);
    }

    /**
     * Updates or adds a download.
     *
     * @@param conn       The JDBC database connection to use.
     * @@param downloadID The database key of the download to update, or
     *                   <code>null</code> if the download is new.
     * @@param f          The file to add.
     * @@param descrip    The download's description.
     * @@param isPublic   Whether the download is public.
     * @@return           The database key of the download.
     *
     * @@exception SQLException
     * @@exception DataSetException
     */
    private Record updateDownload (Connection conn, String downloadID, 
                                   String projectID, File f, String descrip, 
                                   String uploadedBy, String approvedBy,
                                   String isPublic)
        throws SQLException, DataSetException
    {
        Record dl = null;

        TableDataSet downloads = null;
        try
        {
            downloads = new TableDataSet(conn, TABLE_NAME,
                                         new KeyDef().addAttrib(DOWNLOAD_ID));
            if (downloadID != null)
            {
                // Updating existing download.
                downloads.where(DOWNLOAD_ID + '=' + downloadID);
                downloads.fetchRecords();
                dl = downloads.getRecord(0);
            }
            else
            {
                // Adding new download.
                dl = downloads.addRecord();
                setField(dl, UPLOADED_BY, uploadedBy);
                SimpleDateFormat dateFmt =
                    new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                dl.setValue(UPLOAD_DATE, dateFmt.format(new java.util.Date()));
            }
            setField(dl, PROJECT_ID, projectID);
            setField(dl, DESCRIPTION, descrip);
            setField(dl, IS_PUBLIC, isPublic);
            setField(dl, APPROVED_BY, approvedBy);
            if (f != null && f.exists())
            {
                // Handle fields inferred from the File.
                setField(dl, FILE_NAME, f.getName());
                setField(dl, LOCATION, Download.extractLocation(f));

                // Compute the file MD5 checksum and size.
                int size = -1;
                String md5Checksum = null;
                try
                {
                    if (f.canRead())
                    {
                        FileInputStream in = new FileInputStream(f);
                        MessageDigest md5 = MessageDigest.getInstance
                            (CryptoProviderService.MD5,
                             CryptoProviderService.CRYPTIX_PROVIDER);
                        byte[] buf = new byte[MD5_BUF_SIZE];
                        int read = 0;
                        while ((read = in.read(buf)) != -1)
                        {
                            size += read;
                            md5.update(buf, 0, read);
                        }
                        in.close();
                        md5Checksum = ByteToHex.transform(md5.digest());
                    }
                }
                catch (Exception e)
                {
                    log.error("Couldn't determine file MD5 checksum or " + 
                              "size: " + f.getAbsolutePath());
                }
                setField(dl, MD5_CHECKSUM, md5Checksum);
                if (size != -1) dl.setValue(SIZE, size);
            }
            dl.save();
        }
        finally
        {
            registerToClose(downloads);
        }

        return dl;
    }

    /**
     * Updates the specified download.
     *
     * @@param conn        The JDBC database connection to use.
     * @@param downloadID  The database key of the download to update, or
     *                    <code>null</code> if the download is new.
     * @@param description The download's description.
     * @@param approvedBy  The database key of the approving user.
     * @@param isPublic    Whether the download is public.
     *
     * @@exception SQLException
     * @@exception DataSetException
     */
    public void editDownload (Connection conn, String downloadID, 
                              String description, String approvedBy, 
                              String isPublic)
        throws SQLException, DataSetException
    {
        updateDownload(conn, downloadID, null, null, description, null,
                              approvedBy, isPublic);
    }

    /**
     * Deletes an existing download from the database
     *
     * @@param      connection    the JDBC database connection
     * @@param      downloadID       the ID of the download to delete
     * @@exception SQLException
     */
    public void deleteDownload (Connection conn, String downloadID)
        throws SQLException, DataSetException
    {
        TableDataSet downloads = null;
        try
        {
            
            downloads = new TableDataSet (conn, TABLE_NAME,
                                          new KeyDef().addAttrib(DOWNLOAD_ID));
            downloads.where (DOWNLOAD_ID + '=' + downloadID);
            downloads.fetchRecords();
            if (downloads.containsRecord(0)) 
            {
                Record r = downloads.getRecord(0);
                r.markToBeDeleted();
                r.save();
            }
        }
        finally
        {
            registerToClose(downloads);
        }
    }
}
@


1.27
log
@added approveDownload and getUnapprovedDownloadsForProject methods
@
text
@d71 1
a71 1
 * @@version $Id: ProjectDownloadManager.java,v 1.26 2001/01/26 18:29:00 edk Exp $
@


1.26
log
@readding all the files as part of the process of returning to the way
things were as of tuesday
@
text
@d71 1
a71 1
 * @@version $Id: ProjectDownloadManager.java,v 1.21 2000/12/12 23:03:48 dlr Exp $
d171 1
a171 1
    public Record getDownloadForID (Connection connection,
d179 1
a179 1
            download = new TableDataSet (connection, TABLE_NAME);
d219 33
d286 1
a286 1
     * @@param connection  The JDBC database connection to use.
d293 1
a293 1
    public void approveDownload(Connection connection,
d298 21
a318 3
        Record download = getDownloadForID(connection, downloadID);
        download.setValue(APPROVED_BY, userID);
        download.save();
d462 1
a462 1
    public void deleteDownload (Connection connection, String downloadID)
d469 1
a469 1
            downloads = new TableDataSet (connection, TABLE_NAME,
@


1.26.2.1
log
@Porting to the Turbine Peer system.  -dlr and leonardr
@
text
@d71 1
a71 1
 * @@version $Id: ProjectDownloadManager.java,v 1.26 2001/01/26 18:29:00 edk Exp $
@


1.25
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
@d71 1
a71 1
 * @@version $Id: ProjectDownloadManager.java,v 1.24 2001/01/25 01:38:06 leonardr Exp $
d160 1
a160 1
        super (dataMgr, new KeyDef().addAttrib(DOWNLOAD_ID));
a162 4
    ////////////////////////////////////////////////////////////////
    // Accessor methods.
    ////////////////////////////////////////////////////////////////

d168 2
a169 2
     * @@exception DBException if a database error occurs.
     * @@exception DoesNotExist if the downloadID is invalid.
d171 3
a173 2
    public Record getDownloadForID (String downloadID)
        throws DBException, DoesNotExist
d175 3
a177 3
        Criterion c = new Criterion(DOWNLOAD_ID, downloadID);
        Record r = getFirstMatchingRecord(c);
        if (r == null)
d179 3
a181 1
            throw DoesNotExist("Download with ID " + downloadID);
d183 1
a183 19
    }

    /**
     * Retrieves the specified download.
     *
     * @@exception DataSetException
     * @@exception SQLException
     */
    public Record getDownloadForFile(String projectID, String uploadedBy, 
                                     String fileName)
        throws DBException, DoesNotExist
    {
        Criterion c = new Criterion(FILE_NAME, fileName);
        c.and(new Criterion(UPLOADED_BY, uploadedBy));
        c.and(new Criterion(FILE_NAME, fileName));
        Record r = null;

        r = getFirstMatchingRecord(c);
        if (r == null)
d185 1
a185 2
            throw new DoesNotExist("Download " + fileName + " uploaded by " 
                                   + uploadedBy + " to project " + projectID);
d187 2
a188 1
        return r;
d198 2
a199 1
     * @@exception DBException if a problem with the database occurs.
d201 2
a202 2
    public DataSet getDownloadsForProject (String projectID)
        throws DBException
d204 12
a215 2
        Criterion c = new Criterion(PROJECT_ID, projectID);
        return getMatchingRecords(c);
d219 1
a219 1
     * Returns the first record matching a given Criterion. 
d221 2
a222 6
     * @@param criterion Criterion to use in select.
     *
     * @@exception DBException if a database error occurs.
     *
     * @@return Null if no matching record, first record in recordset
     * otherwise.  
d224 3
a226 2
    private Record getFirstMatchingRecord(Criterion criterion)
        throws DBException
d228 11
a238 4
        Record r = null;
        try {
            DataSet s = getRecords(criterion);
            if (s != null && s.containsRecord(0))
d240 1
a240 1
                r = s.getRecord(0);
a241 2
        } catch (DataSetException e) {
            throw new DBException(e);
d243 3
a245 19

        return r;
    }

    /**
     * Returns records matching a given Criterion.
     *
     * @@param criterion Criterion to use in select.
     *
     * @@exception DBException if a database error occurs.
     */
    public DataSet getRecords(Criterion criterion)
    throws DBException
    {
        DataSet s = null;
        try {
            s = runSelect(tableName, criterion);
        } catch (Exception e) {
            throw new DBException(e);
d247 1
a247 1
        return s;
a249 4
    ////////////////////////////////////////////////////////////////
    // Mutator methods.
    ////////////////////////////////////////////////////////////////

d253 1
d257 2
a258 1
     * @@exception DBException
d260 8
a267 11
    public void approveDownload(String downloadID, String userID)
        throws DBException
    {
        try
        {
            Record download = getDownloadForID(downloadID);
            download.setValue(APPROVED_BY, userID);
            download.save();
        } catch (DataSetException e) {
            throw new DBException(e);
        }
d280 4
a283 4
    public synchronized Record addDownload 
        (Connection conn, String projectID, File f, String descrip, 
         String uploadedBy, String approvedBy, String isPublic)
        throws DBException, AlreadyExists
d285 2
a286 7
        //TODO: Check for existance and throw AlreadyExists.
        Record r = null;
        try {
            r = updateDownload(conn, null, projectID, f, descrip, 
                               uploadedBy, approvedBy, isPublic);
        } catch (DoesNotExist ignore) {}
        return r;
d300 2
a301 2
     * @@exception DBException if a database error occurs.
     * @@exception DoesNotExist if the downloadID is invalid.
d303 5
a307 4
    private Record updateDownload (String downloadID, String projectID, 
                                   File f, String descrip, String uploadedBy, 
                                   String approvedBy, String isPublic)
        throws DBException, DoesNotExist
a308 1
        DBConnection dbConn = null;
d310 1
a311 1
        
d314 2
d319 6
a324 6
                dl = getDownloadForID(downloadID);
                if (dl == null)
                {
                    throw new DoesNotExist("Download with ID " + downloadID);
                }
            } else {
a325 7
                try {
                    dbConn = TurbineDB.getConnection();
                } catch (Exception e) {
                    throw new DBException(e);
                }
                downloads = new TableDataSet(dbconn.getConnection(), 
                                             TABLE_NAME, keydef);
a330 1
                
a331 1

a335 1

d341 1
a341 1
                
a372 4
        } catch (DataSetException e) {
            throw new DBException(e);
        } catch (SQLException e) {
            throw new DBException(e);
a375 5
            try {
                TurbineDB.releaseConnection(dbConn);
            } catch (Exception e) {
                throw new DBException(e);
            }
d385 1
d392 2
a393 2
     * @@exception DBException if a database error occurs.
     * @@exception DoesNotExist if the downloadID is invalid.
d395 4
a398 3
    public void editDownload (String downloadID, String description, 
                              String approvedBy, String isPublic)
        throws DBException
d407 1
d409 1
a409 1
     * @@exception DBException if a database error occurs.
d411 2
a412 2
    public void deleteDownload (String downloadID)
        throws DBException
d414 2
a415 2
        Record download = getDownloadForID(downloadID);
        if (download != null)
d417 10
a426 7
            try {
                download.markToBeDeleted();
                download.save();
            } catch (DataSetException e) {
                throw new DBException(e);
            } catch (SQLException e) {
                throw new DBException(e);
d429 5
a433 1
    }           
@


1.24
log
@More TableManagers de-connectionified.
@
text
@d71 1
a71 1
 * @@version $Id: ProjectDownloadManager.java,v 1.23 2001/01/24 22:24:36 leonardr Exp $
@


1.23
log
@Moved TableManagers to new keydef constructor and keydef-less runSelect.
@
text
@d71 1
a71 1
 * @@version $Id: ProjectDownloadManager.java,v 1.22 2001/01/24 20:42:46 dlr Exp $
d163 4
d172 2
a173 2
     * @@exception    SQLException
     * @@exception    DataSetException
d175 2
a176 3
    public Record getDownloadForID (Connection connection,
                                    String downloadID)
        throws DBException
d178 3
a180 3
        TableDataSet download = null;

        try
d182 1
a182 3
            download = new TableDataSet (connection, TABLE_NAME);
            download.where(DOWNLOAD_ID + '=' + downloadID);
            download.fetchRecords();
d184 19
a202 1
        finally
d204 2
a205 1
            registerToClose (download);
d207 1
a207 2

        return download.getRecord(0);
d217 1
a217 2
     * @@exception DataSetException
     * @@exception SQLException
d219 1
a219 1
    public DataSet getDownloadsForProject (Connection conn, String projectID)
d222 2
a223 12
        TableDataSet downloads = null;
        try
        {
            downloads = new TableDataSet(conn, TABLE_NAME);
            downloads.where(PROJECT_ID + '=' + projectID);
            downloads.fetchRecords();
        }
        finally
        {
            registerToClose(downloads);
        }
        return downloads;
d227 5
a231 1
     * Retrieves the specified download.
d233 2
a234 2
     * @@exception DataSetException
     * @@exception SQLException
d236 2
a237 3
    public Record getDownloadForFile(Connection conn, String projectID,
                                     String uploadedBy, String fileName)
        throws DataSetException, SQLException
d239 4
a242 11
        Record dl = null;
        TableDataSet downloads = null;
        try
        {
            downloads = new TableDataSet(conn, TABLE_NAME);
            String where = PROJECT_ID + '=' + projectID + " AND " +
                UPLOADED_BY + '=' + uploadedBy + " AND " + FILE_NAME + '=' +
                fileName;
            if (debug) log.info("where=" + where);
            downloads.where(where);
            if (downloads.fetchRecords(1).containsRecord(0))
d244 1
a244 1
                dl = downloads.getRecord(0);
d246 2
d249 19
a267 3
        finally
        {
            if (downloads != null) downloads.close();
d269 1
a269 1
        return dl;
d272 4
a278 1
     * @@param connection  The JDBC database connection to use.
d284 1
a284 2
    public void approveDownload(Connection connection,
                                String downloadID, String userID)
d289 1
a289 1
            Record download = getDownloadForID(connection, downloadID);
d292 1
a292 3
        }
        catch (DataSetException e)
        {
d307 4
a310 4
    public Record addDownload (Connection conn, String projectID,
                               File f, String descrip, String uploadedBy,
                               String approvedBy, String isPublic)
        throws DBException
d312 7
a318 2
        return updateDownload(conn, null, projectID, f, descrip, uploadedBy,
                              approvedBy, isPublic);
d332 2
a333 2
     * @@exception SQLException
     * @@exception DataSetException
d335 4
a338 5
    private Record updateDownload (Connection conn, String downloadID, 
                                   String projectID, File f, String descrip, 
                                   String uploadedBy, String approvedBy,
                                   String isPublic)
        throws DBException
d340 1
a341 1

d343 1
a345 1
            downloads = new TableDataSet(conn, TABLE_NAME, keydef);
d349 6
a354 6
                downloads.where(DOWNLOAD_ID + '=' + downloadID);
                downloads.fetchRecords();
                dl = downloads.getRecord(0);
            }
            else
            {
d356 7
d368 1
d370 1
d375 1
d381 1
a381 1

d413 3
a415 3
        }
        catch (DataSetException e)
        {
d420 5
a433 1
     * @@param conn        The JDBC database connection to use.
d440 2
a441 2
     * @@exception SQLException
     * @@exception DataSetException
d443 2
a444 3
    public void editDownload (Connection conn, String downloadID, 
                              String description, String approvedBy, 
                              String isPublic)
a453 1
     * @@param      connection    the JDBC database connection
d455 1
a455 1
     * @@exception SQLException
d457 1
a457 1
    public void deleteDownload (Connection connection, String downloadID)
d460 2
a461 2
        TableDataSet downloads = null;
        try
d463 7
a469 9
            
            downloads = new TableDataSet (connection, TABLE_NAME, keydef);
            downloads.where (DOWNLOAD_ID + '=' + downloadID);
            downloads.fetchRecords();
            if (downloads.containsRecord(0)) 
            {
                Record r = downloads.getRecord(0);
                r.markToBeDeleted();
                r.save();
d472 1
a472 9
        catch (DataSetException e)
        {
            throw new DBException(e);
        }
        finally
        {
            registerToClose(downloads);
        }
    }
@


1.22
log
@Making use of DBException.
@
text
@d71 1
a71 1
 * @@version $Id: ProjectDownloadManager.java,v 1.21 2000/12/12 23:03:48 dlr Exp $
d160 1
a160 1
        super (dataMgr);
d319 1
a319 2
            downloads = new TableDataSet(conn, TABLE_NAME,
                                         new KeyDef().addAttrib(DOWNLOAD_ID));
d426 1
a426 2
            downloads = new TableDataSet (connection, TABLE_NAME,
                                          new KeyDef().addAttrib(DOWNLOAD_ID));
@


1.21
log
@Moved some business logic into the corresponding business object.
@
text
@d71 1
a71 1
 * @@version $Id: ProjectDownloadManager.java,v 1.20 2000/12/12 20:04:34 dlr Exp $
d173 1
a173 1
        throws SQLException, DataSetException
d202 1
a202 1
        throws SQLException, DataSetException
d257 1
a257 2
     * @@exception SQLException
     * @@exception DataSetException 
d261 1
a261 2
        throws SQLException, DataSetException, JoistDatabaseException,
               UpdateException              
d263 10
a272 3
        Record download = getDownloadForID(connection, downloadID);
        download.setValue(APPROVED_BY, userID);
        download.save();
d288 1
a288 1
        throws SQLException, DataSetException
d312 1
a312 1
        throws SQLException, DataSetException
d379 4
d407 1
a407 1
        throws SQLException, DataSetException
d421 1
a421 1
        throws SQLException, DataSetException
d437 4
@


1.20
log
@Changed IS_PRIVATE to IS_PUBLIC--propogating all the way through to the UI.
@
text
@d64 1
d71 1
a71 1
 * @@version $Id: ProjectDownloadManager.java,v 1.19 2000/12/12 02:34:34 dlr Exp $
d340 1
a340 1
                setField(dl, LOCATION, f.getParentFile().getAbsolutePath());
@


1.19
log
@MD5 checksums are now set correctly (i.e. as hex strings).
@
text
@d70 1
a70 1
 * @@version $Id: ProjectDownloadManager.java,v 1.18 2000/12/12 01:20:37 dlr Exp $
d125 1
a125 1
    public static final String IS_PRIVATE = "IS_PRIVATE";
d277 1
a277 1
     * @@param isPrivate  Whether the download is private.
d281 1
a281 1
                               String approvedBy, String isPrivate)
d285 1
a285 1
                              approvedBy, isPrivate);
d296 1
d305 1
a305 1
                                   String isPrivate)
d333 1
a333 1
            setField(dl, IS_PRIVATE, isPrivate);
d388 2
d396 1
a396 1
                              String isPrivate)
d400 1
a400 1
                              approvedBy, isPrivate);
@


1.18
log
@Properly update the MD5 checksum.
@
text
@d70 1
a70 1
 * @@version $Id: ProjectDownloadManager.java,v 1.17 2000/12/11 23:39:07 dlr Exp $
d342 1
a342 1
                byte[] md5Checksum = null;
d359 1
a359 1
                        md5Checksum = md5.digest();
d367 1
a367 1
                if (md5Checksum != null) dl.setValue(MD5_CHECKSUM, md5Checksum);
@


1.17
log
@No point in creating an extra String object--it may have been screwing
up the MD5 anyhow.
@
text
@d70 1
a70 1
 * @@version $Id: ProjectDownloadManager.java,v 1.16 2000/12/05 05:05:17 dlr Exp $
d356 1
a356 1
                            md5.update(buf);
@


1.16
log
@Indicated more serious.
@
text
@d70 1
a70 1
 * @@version $Id: ProjectDownloadManager.java,v 1.15 2000/12/05 00:22:04 dlr Exp $
d342 1
a342 1
                String md5Checksum = null;
d359 1
a359 1
                        md5Checksum = new String(md5.digest());
d367 1
a367 1
                setField(dl, MD5_CHECKSUM, md5Checksum);
@


1.15
log
@Compute MD5 checksums for uploaded files.
@
text
@d70 1
a70 1
 * @@version $Id: ProjectDownloadManager.java,v 1.14 2000/11/22 01:31:47 dlr Exp $
d362 1
a362 1
                catch (Exception ignored)
d364 2
a365 2
                    log.warning("Couldn't determine file MD5 checksum or " + 
                                "size: " + f.getAbsolutePath());
@


1.14
log
@Pushed method into super class (Joist's TableManger).
@
text
@d52 1
d66 1
a66 1
 * Manages the User-Role-Project three-way join table.
d70 1
a70 1
 * @@version $Id: ProjectDownloadManager.java,v 1.13 2000/11/21 00:10:22 elicia Exp $
d133 10
d339 2
d342 1
d345 1
a345 2
                    FileInputStream in = new FileInputStream(f);
                    if (in.getFD().valid())
d347 13
a359 1
                        size = in.available();
a360 1
                    in.close();
d362 1
a362 1
                catch (IOException ignored)
d364 2
a365 2
                    log.warning("Couldn't determine file size: " +
                                f.getAbsolutePath());
d367 1
@


1.13
log
@changed order of argument list editDownload passes to updateDownload; looks like updateDownload may have changed
@
text
@d69 1
a69 1
 * @@version $Id: ProjectDownloadManager.java,v 1.12 2000/11/17 22:21:38 dlr Exp $
a375 9
     * Sets the field's value if provided value is not null.
     */
    private static final void setField (Record r, String name, String value)
        throws DataSetException
    {
        if (value != null) r.setValue(name, value);
    }

    /**
d382 1
a382 1
    public void  deleteDownload (Connection connection, String downloadID)
a384 1
        String action = "Deleting Download";
d390 1
a390 1
                                          new KeyDef ().addAttrib (DOWNLOAD_ID));
a398 15
            
        }
        catch (DataSetException e)
        {
            log.exception(e);
            if (debug) log.debug(action + ": " + downloadID + ": " + 
                                 e.getMessage());
            throw e;
        }
        catch (SQLException e)
        {
            log.exception(e);
            if (debug) log.debug(action + ": " + downloadID + ": " + 
                                 e.getMessage());
            throw e;
@


1.12
log
@- Added IS_PRIVATE.
- Tweaked interfaces.
- Added JavaDoc.
@
text
@d69 1
a69 1
 * @@version $Id: ProjectDownloadManager.java,v 1.11 2000/11/17 19:48:23 dlr Exp $
d371 2
a372 2
        updateDownload(conn, downloadID, description, null, null, null,
                       approvedBy, isPrivate);
@


1.11
log
@Now setting the datetime field of a new upload.
@
text
@d69 1
a69 1
 * @@version $Id: ProjectDownloadManager.java,v 1.10 2000/11/16 01:44:11 dlr Exp $
d122 5
d262 1
d264 3
d269 2
a270 2
                               String descrip, File f, String uploadedBy,
                               String approvedBy)
d273 2
a274 2
        return updateDownload(conn, null, projectID, descrip, f, uploadedBy,
                              approvedBy);
d283 1
d291 3
a293 2
                                   String projectID, String descrip, File f,
                                   String uploadedBy, String approvedBy)
d321 1
d367 2
a368 1
                              String description, String approvedBy)
d371 2
a372 2
        updateDownload(conn, downloadID, null, description, null, null,
                       approvedBy);
@


1.10
log
@Removed some debugging information.
@
text
@d51 1
d69 1
a69 1
 * @@version $Id: ProjectDownloadManager.java,v 1.9 2000/11/15 23:13:13 elicia Exp $
d304 3
a306 1
                // NOTE: UPLOAD_DATE defaults to NOW().
@


1.9
log
@added approve method
@
text
@d68 1
a68 1
 * @@version $Id: ProjectDownloadManager.java,v 1.8 2000/11/15 21:31:30 dlr Exp $
d215 5
a219 1
            downloads.where(PROJECT_ID + '=' + projectID);
a305 1
            if (debug) log.info("descrip=" + descrip);
@


1.8
log
@Added new getDownloadForFile() method.
@
text
@d68 1
a68 1
 * @@version $Id: ProjectDownloadManager.java,v 1.7 2000/11/15 21:13:03 elicia Exp $
d226 20
@


1.7
log
@added getDownloadForID method
@
text
@d67 2
a68 1
 * @@version $Id: ProjectDownloadManager.java,v 1.6 2000/11/15 03:34:18 dlr Exp $
d172 1
d174 5
a178 1
     * Retrieves roles and projects for a user.
d180 2
a181 5
     * @@param    connection    A JDBC database connection
     * @@param    userID        The userID to obtain roles and projects for.
     * @@return     a DataSet
     * @@exception    SQLException
     * @@exception    DataSetException
d183 1
a183 2
    public DataSet getDownloadsForProject (Connection connection,
                                           String projectID)
d187 12
d200 12
d214 1
a214 1
            downloads = new TableDataSet (connection, TABLE_NAME);
d216 4
a219 1
            return downloads.fetchRecords();
a220 15
	catch (DataSetException e)
	{
	    log.exception(e);
	    if (debug) log.debug("Getting Downloads: " +
	                         e.getMessage());
	    throw e;
	}
	catch (SQLException e)
	{
	    log.exception(e);
	    if (debug) log.debug("Getting Downloads : " +
	                         e.getMessage());
	    throw e;
	}

d223 1
a223 1
            if (downloads != null) registerToClose (downloads);
d225 1
@


1.6
log
@Save the path name--rather than the absolute path of the file--in the
LOCATION field.
@
text
@d67 1
a67 1
 * @@version $Id: ProjectDownloadManager.java,v 1.5 2000/11/15 03:01:59 dlr Exp $
d145 27
d190 1
a190 1
            downloads.fetchRecords();
d192 15
d209 1
a209 1
            registerToClose (downloads);
a210 2

        return downloads;
@


1.5
log
@minor cleanup
@
text
@d67 1
a67 1
 * @@version $Id: ProjectDownloadManager.java,v 1.4 2000/11/15 00:13:25 dlr Exp $
d227 1
a229 1

d232 1
d234 1
a234 1
                setField(dl, LOCATION, f.getPath());
@


1.4
log
@Upload addition code now beginning to be functional.
@
text
@d67 1
a67 1
 * @@version $Id: ProjectDownloadManager.java,v 1.3 2000/11/14 03:51:38 dlr Exp $
d224 1
a224 2
                // 0000-00-00 00:00:00
                //setField(dl, UPLOAD_DATE, new java.util.Date().toString());
a226 1
            // TODO: Pass in and set other db field values.
d234 1
a234 1
                String size = null;
d240 1
a240 1
                        size = String.valueOf(in.available());
d244 6
a249 2
                catch (IOException ignored) {}
                setField(dl, SIZE, size);
@


1.3
log
@Corrected JavaDoc and added additional stub.
@
text
@d49 2
a51 2
//import java.util.*;
import java.util.Date;
d53 1
a53 2
import org.webmacro.util.*;
import org.webmacro.servlet.*;
d67 1
a67 1
 * @@version $Id: ProjectDownloadManager.java,v 1.2 2000/11/14 03:44:34 dlr Exp $
d85 6
a90 1
     * A database key field.
d92 1
a92 1
    public static final String NAME = "NAME";
a119 5
     * File location.
     */
    public static final String LOCATION = "LOCATION";

    /**
d162 2
a163 2
            downloads.where (PROJECT_ID + '=' + projectID);
            downloads.fetchRecords ();
d179 3
a181 1
    public Record addDownload (Connection conn, String descrip)
d184 2
a185 1
        return updateDownload(conn, null, descrip);
d201 2
a202 1
                                   String descrip)
d223 25
a248 2
            // TODO: Pass in and set other values.
            dl.setValue(DESCRIPTION, descrip);
d271 1
a271 1
                              String description)
d274 11
a284 1
        updateDownload(conn, downloadID, description);
@


1.2
log
@Adding stub for more functionality.
@
text
@d68 1
a68 1
 * @@version $Id: ProjectDownloadManager.java,v 1.1.1.1 2000/11/12 21:15:00 dlr Exp $
d175 13
a187 1
     * Updates the description field of a given download.
d192 1
d199 1
a199 1
                                   String description)
d222 1
a222 1
            dl.setValue(DESCRIPTION, description);
d234 1
a234 1
     * Updates the description field of a given download.
@


1.1
log
@Initial revision
@
text
@d68 1
a68 1
 * @@version $Id: ProjectDownloadManager.java,v 1.3 2000/11/11 04:34:59 dlr Exp $
d158 1
a158 1
       TableDataSet downloads = null;
d160 10
a169 25
       String action = "Getting downloads for projectID=" + projectID;
       try
       {
          downloads = new TableDataSet (connection, TABLE_NAME);
          downloads.where (PROJECT_ID + "=" + projectID);
          downloads.fetchRecords ();
       }
       catch (DataSetException e)
       {
          log.exception (e);
          if (debug)
	     log.debug (action + ": " + e.getMessage ());
          throw e;
       }
       catch (SQLException e)
       {
         log.exception (e);
         if (debug)
	 log.debug (action + ": " + e.getMessage ());
         throw e;
       }
       finally
       {
          registerToClose (downloads);
       }
d171 1
a171 1
       return downloads;
d177 13
a189 14
     * @@param connection The JDBC database connection to use.
     * @@param downloadID    The database key of the download to update 
     * @@return	         The system-assigned download ID for the download updated.
     *
     * @@exception	SQLException
     * @@exception	DataSetException
     */
  public void editDownload (Connection connection, 
                               String downloadID, 
			       String description)
    throws SQLException, DataSetException
  {
    Record download = null;
    TableDataSet downloads = null;
d191 27
a217 9
    try
    {
      downloads = new TableDataSet (connection, TABLE_NAME,
				    new KeyDef ().addAttrib (DOWNLOAD_ID));
      downloads.where (DOWNLOAD_ID + '=' + downloadID);
      downloads.fetchRecords();
      download = downloads.getRecord (0);
      download.setValue (DESCRIPTION, description);
      download.save ();
d219 15
a233 9
    catch (DataSetException e)
    {
      log.exception (e);
      String message = "Editing download : " + e.getMessage ();
      if (debug)
	log.debug (message);
      throw e;
    }
    catch (SQLException e)
d235 1
a235 5
      log.exception (e);
      String message = "Editing download: " + e.getMessage ();
      if (debug)
	log.debug (message);
      throw e;
a236 7
    finally
    {
      registerToClose (downloads);
    }

  }

d254 3
a256 3
				        new KeyDef ().addAttrib (DOWNLOAD_ID));
	    downloads.where (DOWNLOAD_ID + '=' + downloadID);
	    downloads.fetchRecords();
@


1.1.1.1
log
@Merging newhelm tree into helm, as per IZ issue #557.  Previous major version of helm is tagged TIGRIS_NOV_11_2000.
@
text
@@
