head	1.36;
access;
symbols
	TIGRIS_0_9_2_4:1.30
	TIGRIS_0_9_2_3:1.30
	HELM_PEER_PORT_BRANCH:1.33.0.2
	TURBINE_PEER:1.33
	TIGRIS_0_9_2_1:1.33
	TIGRIS_0_9_2:1.30.0.2
	TIGRIS_0_9_0:1.27.0.2
	TIGRIS_0_8_4:1.16.0.2
	NEWHELM:1.1.1.1
	TIGRIS_NOV_12_2000:1.1.1;
locks; strict;
comment	@# @;


1.36
date	2001.02.21.03.23.57;	author edk;	state dead;
branches;
next	1.35;

1.35
date	2001.02.09.01.11.33;	author elicia;	state Exp;
branches;
next	1.34;

1.34
date	2001.02.08.02.38.38;	author elicia;	state Exp;
branches;
next	1.33;

1.33
date	2001.01.26.18.29.04;	author edk;	state Exp;
branches
	1.33.2.1;
next	1.32;

1.32
date	2001.01.26.05.24.06;	author edk;	state dead;
branches;
next	1.31;

1.31
date	2001.01.25.01.11.48;	author leonardr;	state Exp;
branches;
next	1.30;

1.30
date	2000.12.29.02.40.42;	author dlr;	state Exp;
branches;
next	1.29;

1.29
date	2000.12.23.00.48.18;	author dlr;	state Exp;
branches;
next	1.28;

1.28
date	2000.12.22.03.03.00;	author dlr;	state Exp;
branches;
next	1.27;

1.27
date	2000.12.13.02.11.00;	author dlr;	state Exp;
branches;
next	1.26;

1.26
date	2000.12.13.02.02.27;	author dlr;	state Exp;
branches;
next	1.25;

1.25
date	2000.12.13.01.39.27;	author dlr;	state Exp;
branches;
next	1.24;

1.24
date	2000.12.13.01.32.42;	author dlr;	state Exp;
branches;
next	1.23;

1.23
date	2000.12.12.23.03.11;	author dlr;	state Exp;
branches;
next	1.22;

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

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

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

1.19
date	2000.12.05.23.53.30;	author leonardr;	state Exp;
branches;
next	1.18;

1.18
date	2000.12.05.23.28.59;	author leonardr;	state Exp;
branches;
next	1.17;

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

1.16
date	2000.11.21.00.08.27;	author elicia;	state Exp;
branches;
next	1.15;

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

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

1.13
date	2000.11.18.09.24.23;	author dlr;	state Exp;
branches;
next	1.12;

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

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

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

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

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

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

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

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

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

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

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

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

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

1.33.2.1
date	2001.01.28.01.02.18;	author dlr;	state dead;
branches;
next	;


desc
@@


1.36
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 Collab.Net (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 Collab.Net.
 * 
 * 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 COLLAB.NET 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.project;

import java.util.*;
import java.io.File;
import java.io.IOException;
import java.sql.Connection;
import java.sql.SQLException;
import java.text.ParseException;

import com.workingdogs.village.*;

import org.webmacro.util.*;
import org.webmacro.servlet.*;
import com.workingdogs.village.*;

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

import org.tigris.helm.domain.BusinessObject;
import org.tigris.helm.database.*;
import org.tigris.helm.security.*;
import org.tigris.helm.tool.*;
import org.tigris.helm.DoesNotExist;
import org.tigris.helm.domain.User;

public class Download extends BusinessObject
{
    private static final int ONE_KB = 1024;

    private static final int ONE_MB = ONE_KB * 1000;

    private static final int ONE_GB = ONE_KB * 1000 * 1000;

    protected final String getTableName() 
    {
        return ProjectDownloadManager.TABLE_NAME;
    }

    private ProjectDownloadManager dlMgr;
    private ProjectManager pMgr;
    private UserUserGroupManager usrGrpMgr;

    public Download (Connection conn, DataManager dMgr, Record rec)
        throws DoesNotExist, DataSetException
    {
        super(conn, dMgr, rec);
    }


    /**
     * Constructor for a download which already exists -- accessed by
     * downloadID.
     */
    public Download(Connection conn, DataManager dMgr, String downloadID)
        throws SQLException, DataSetException, DoesNotExist
    {
        super(conn, dMgr);
        setRecord(dlMgr.getDownloadForID(conn, downloadID));
    }

    /**
     * Constructor for a download which already exists.
     */
    public Download(Connection conn, DataManager dMgr, String projectID,
                    String uploadedBy, String fileName)
        throws SQLException, DataSetException, DoesNotExist
    {
        super(conn, dMgr);
        setRecord(dlMgr.getDownloadForFile(conn, projectID, uploadedBy,
                                           fileName));
    }

    /**
     * Constructor for a new download.
     */
    public Download (Connection conn, DataManager dMgr, AccessControlList acl,
                     Project project, String descrip, File f, String isPublic,
                     String url)
        throws SQLException, DataSetException, DoesNotExist, UpdateException,
               JoistDatabaseException, ACLException, IOException
    {
        super(conn, dMgr);

        // To add a download you need either Suggest or Approve permission.
        String projectID = project.getID();
        String suggest = "Project Download - Suggest";
        String approve = "Project Download - Approve";
        if (!acl.hasPermissionForProject(suggest, projectID) && 
            !acl.hasPermissionForProject(approve, projectID))
        {
            // Assert a permission we know they don't have to cause an
            // exception.
            acl.assertPermissionForProject(suggest, projectID);
        }
        String approvedBy = (acl.hasPermissionForProject(approve, projectID) ?
                             acl.getUserID() : 
                             usrGrpMgr.getNobodyUserID(conn));
        dlMgr.addDownload(conn, projectID, f, descrip, acl.getUserID(), 
                          approvedBy, isPublic);
        project.writeHtaccessFile(extractLocation(f), url);
    }

    protected void createManagers ()
    {
        dlMgr = (ProjectDownloadManager)
            dMgr.getManager("org.tigris.helm.database.ProjectDownloadManager");
        pMgr = (ProjectManager)
            dMgr.getManager("org.tigris.helm.database.ProjectManager");
        usrGrpMgr = (UserUserGroupManager)
            dMgr.getManager("org.tigris.helm.database.UserUserGroupManager");
    }

    /**
     * Extracts the directory path to the file.
     *
     * @@param f The file to extract path information from.
     * @@return  The extracted path information.
     */
    public static final String extractLocation (File f)
    {
        return f.getParentFile().getAbsolutePath();
    }

    /**
     * Approves the download.
     */
    public void approve (AccessControlList acl)
        throws SQLException, DataSetException, JoistDatabaseException,
               UpdateException, ACLException
    {
        String action = "Project Download - Approve";
        if (acl.hasPermissionForProject(action, getProjectID()))
        {
            acl.assertPermissionForProject(action, getProjectID());
            dlMgr.approveDownload(conn, getDownloadID(), acl.getUserID());
            // HELP: Do we also need to regenerate the .htaccess file here?
        }
    }

    /**
     * Disapproves the download.
     */
    public void disapprove (AccessControlList acl, WebContext ctx)
        throws SQLException, DataSetException, JoistDatabaseException,
               JoistException, DoesNotExist, ACLException, UpdateException, 
               IOException
    {
        String action = "Project Download - Approve";
        if (acl.hasPermissionForProject(action, getProjectID()))
        {
            acl.assertPermissionForProject(action, getProjectID());

            //Send email to the owners.
            User disapprovingUser = User.getInstance(conn, dMgr, acl.getUserID());
            String subject = "Document for Project " + getProjectName() + " disapproved.";
            StringBuffer body = new StringBuffer();
            body.append("Sorry, your submission of the download '")
                .append(getName()).append("' for project ");
            body.append(getProjectName()).append(" has been disapproved.\n\n");
            body.append("For more information, please contact ")
                .append(disapprovingUser.getName()).append(" (")
                .append(disapprovingUser.getEmail()).append(").");
            HelmEmailer emailer = new HelmEmailer(conn, dMgr);
            emailer.sendEmail(getUploadedBy().getEmail(), subject, body.toString());
            delete(acl, true, ctx);
        } 
    }

    /**
     * Updates a download.
     *
     * @@param acl           The access control list of the current user.
     * @@param description   A description of the download.
     * @@param approvedBy    The database key of the approving user.
     * @@param isPublic      Whether the download is private.
     * @@param url           The URL for auth and timeout.
     *
     * @@exception SQLException
     * @@exception DataSetException
     */
    public void edit (AccessControlList acl, String description,
                      String approvedBy, String isPublic, String url)
        throws DataSetException, SQLException, ACLException, DoesNotExist,
               IOException
    {
        String projectID = getProjectID();
        acl.assertPermissionForProject("Project Download - Approve", projectID);
        dlMgr.editDownload(conn, getID(), description, approvedBy, isPublic);
        Project project = new Project(conn, dMgr, projectID);
        project.writeHtaccessFile(getLocation(), url);
    }

    /**
     * Deletes the download.  The public interface for this method is available
     * from the Project class's <code>deleteDownload()</code> method.
     *
     * @@param acl            The ACL to check for delete permission.
     * @@param fromFilesystem Whether to delete from the file system as well as 
     *                       the database.
     *
     * @@see org.tigris.helm.project.Project#deleteDownload
     */
    public void delete (AccessControlList acl, boolean fromFilesystem,
                        WebContext ctx)
        throws SQLException, DataSetException, JoistDatabaseException,
               UpdateException, ACLException, DoesNotExist, IOException
    {
        String action = "Project Download - Approve";
        acl.assertPermissionForProject(action, getProjectID());
        if (fromFilesystem)
        {
            File victim =
                new File(getLocation() + File.separatorChar + getName());
            if (victim.exists()) victim.delete();
            String htURL = URL.schemeAndServer(ctx)
                           + "/servlets/ProjectDocuments";
            Project project = new Project(conn, dMgr, getProjectID());
            project.writeHtaccessFile(getLocation(), htURL);
        }
        dlMgr.deleteDownload(conn, getID());
    }

    /**
     * Delete the download from both database and file system.
     *
     * @@see #delete
     */
    public void delete (AccessControlList acl, WebContext ctx)
        throws SQLException, DataSetException, JoistDatabaseException,
               UpdateException, ACLException, DoesNotExist, IOException
    {
        delete(acl, true, ctx);
    }

    public String getID () throws DataSetException
    {
        return rec.getValue(ProjectDownloadManager.DOWNLOAD_ID).asString();
    }

    /**
     * @@deprecated Use getID() instead.
     */
    public String getDownloadID () throws DataSetException
    {
        return getID();
    }

    /**
     * Returns the base file name of this download (i.e. no path information).
     */
    public String getName () throws DataSetException
    {
        return rec.getValue(ProjectDownloadManager.FILE_NAME).asString();
    }

    /**
     * Returns the path name to the directory in which this download resides.
     */
    public String getLocation () throws DataSetException
    {
        return rec.getValue(ProjectDownloadManager.LOCATION).asString();
    }

    /**
     * Returns a human-readable version of the file size (original is in
     * bytes).
     */
    public String getSize () throws DataSetException
    {
        String displaySize;

        int size = rec.getValue(ProjectDownloadManager.SIZE).asInt();
        if (size / ONE_GB > 0)
        {
            displaySize = String.valueOf(size / ONE_GB) + " GB";
        }
        else if (size / ONE_MB > 0)
        {
            displaySize = String.valueOf(size / ONE_MB) + " MB";
        }
        else if (size / ONE_KB > 0)
        {
            displaySize = String.valueOf(size / ONE_KB) + " kB";
        }
        else
        {
            displaySize = String.valueOf(size) + " bytes";
        }

        return displaySize;
    }

    public String getDescription () throws DataSetException
    {
        return rec.getValue(ProjectDownloadManager.DESCRIPTION).asString();
    }

    public String getUploadDate () throws DataSetException, ParseException
    {
        String uploadDate = 
            rec.getValue(ProjectDownloadManager.UPLOAD_DATE).asString();
        return FormatDate.format("yyyy-MM-dd kk:mm:ss", "MM-dd-yy", 
                                 uploadDate);
    }

    public String getProjectID() throws DataSetException
    {
        return rec.getValue(ProjectDownloadManager.PROJECT_ID).asString();
    }

    public String getProjectName() 
        throws DataSetException, SQLException, JoistDatabaseException
    {
        String projectID = getProjectID();
        String projectName = pMgr.getProjectName(conn, projectID);
        return projectName;
    }

    public User getUploadedBy()
        throws DataSetException, SQLException, JoistDatabaseException,
               DoesNotExist
    {
        String uid = 
            rec.getValue(ProjectDownloadManager.UPLOADED_BY).asString();
        return User.getInstance(conn, dMgr, uid);
    }

    public boolean isApproved()
          throws JoistDatabaseException, DataSetException, SQLException,
                 DoesNotExist
                 
      {
          return !getApprovedBy().getID().equals(usrGrpMgr.getNobodyUserID(conn));
      }

    public User getApprovedBy()
        throws DataSetException, SQLException, JoistDatabaseException,
               DoesNotExist
    {
        String uid = 
            rec.getValue(ProjectDownloadManager.APPROVED_BY).asString();
        return User.getInstance(conn, dMgr, uid);
    }

    /**
     * Returns the MD5 checksum of the download.
     */
    public String getMD5Checksum () throws DataSetException
    {
        return rec.getValue(ProjectDownloadManager.MD5_CHECKSUM).asString();
    }

    public Boolean isPublic () throws DataSetException
    {
        return DBFlag.boolValueOf
            (rec.getValue(ProjectDownloadManager.IS_PUBLIC).asString());
    }
}
@


1.35
log
@added isApproved method
@
text
@@


1.34
log
@cleanup
@
text
@d375 17
@


1.33
log
@readding all the files as part of the process of returning to the way
things were as of tuesday
@
text
@d58 4
d63 2
d87 1
d154 2
d188 29
a246 1
     * @@param url            The URL for auth and timeout.
d250 2
a251 2
    public void delete (AccessControlList acl, String url,
                        boolean fromFilesystem)
d262 4
a267 2
        Project project = new Project(conn, dMgr, getProjectID());
        project.writeHtaccessFile(getLocation(), url);
d275 1
a275 1
    public void delete (AccessControlList acl, String url)
d279 1
a279 1
        delete(acl, url, true);
d356 8
@


1.33.2.1
log
@Porting to the Turbine Peer system.  -dlr and leonardr
@
text
@@


1.32
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
@d83 2
a84 2
    public Download (DataManager dMgr, Record rec)
        throws DoesNotExist, DBException
d86 1
a86 1
        super(dMgr, rec);
d94 2
a95 2
    public Download(DataManager dMgr, String downloadID)
        throws DoesNotExist, DBException
d97 2
a98 1
        super(dMgr, dlMgr.getDownloadForID(downloadID));
d104 7
a110 5
    public Download(DataManager dMgr, String projectID, String uploadedBy,
                    String fileName)
        throws DoesNotExist, DBException
    {
        super(dMgr, dlMgr.getDownloadForFile(projectID, uploadedBy, fileName));
d116 5
a120 4
    public Download (DataManager dMgr, AccessControlList acl, Project project, 
                     String descrip, File f, String isPublic, String url)
        throws ACLException, IOException, DoesNotExist, UpdateException,
               DBException
d122 1
a122 1
        super(dMgr);
d137 2
a138 2
                             uMgr.getNobodyUserID());
        dlMgr.addDownload(projectID, f, descrip, acl.getUserID(), 
d166 2
a167 1
        throws ACLException, UpdateException, DBException
d173 1
a173 1
            dlMgr.approveDownload(getDownloadID(), acl.getUserID());
d188 1
a188 1
     * @@exception DBException
d192 2
a193 1
        throws ACLException, DoesNotExist, IOException, DBException
d197 2
a198 2
        dlMgr.editDownload(getID(), description, approvedBy, isPublic);
        Project project = new Project(dMgr, projectID);
d215 2
a216 2
        throws UpdateException, ACLException, DoesNotExist, IOException,
               DBException
d226 2
a227 2
        dlMgr.deleteDownload(getID());
        Project project = new Project(dMgr, getProjectID());
d237 2
a238 2
        throws UpdateException, ACLException, DoesNotExist, IOException,
               DBException
d243 1
a243 1
    public String getID () throws DBException
d251 1
a251 1
    public String getDownloadID () throws DBException
d259 1
a259 1
    public String getName () throws DBException
d267 1
a267 1
    public String getLocation () throws DBException
d276 1
a276 1
    public String getSize () throws DBException
d301 1
a301 1
    public String getDescription () throws DBException
d306 1
a306 1
    public String getUploadDate () throws ParseException, DBException
d314 1
a314 1
    public String getProjectID() throws DBException
d320 2
a321 1
        throws DoesNotExist, DBException
d325 1
a325 1
        return User.getInstance(dMgr, uid);
d331 1
a331 1
    public String getMD5Checksum () throws DBException
d336 1
a336 1
    public Boolean isPublic () throws DBException
@


1.31
log
@* Removed references to JDBC connections.  Connections are now pulled
  directly from the connection pool.
* Made use of DBException.
- dlr@@collab.net
@
text
@@


1.30
log
@Made use of new DBFlag class.
@
text
@d83 2
a84 2
    public Download (Connection conn, DataManager dMgr, Record rec)
        throws DoesNotExist, DataSetException
d86 1
a86 1
        super(conn, dMgr, rec);
d94 2
a95 2
    public Download(Connection conn, DataManager dMgr, String downloadID)
        throws SQLException, DataSetException, DoesNotExist
d97 1
a97 2
        super(conn, dMgr);
        setRecord(dlMgr.getDownloadForID(conn, downloadID));
d103 5
a107 7
    public Download(Connection conn, DataManager dMgr, String projectID,
                    String uploadedBy, String fileName)
        throws SQLException, DataSetException, DoesNotExist
    {
        super(conn, dMgr);
        setRecord(dlMgr.getDownloadForFile(conn, projectID, uploadedBy,
                                           fileName));
d113 4
a116 5
    public Download (Connection conn, DataManager dMgr, AccessControlList acl,
                     Project project, String descrip, File f, String isPublic,
                     String url)
        throws SQLException, DataSetException, DoesNotExist, UpdateException,
               JoistDatabaseException, ACLException, IOException
d118 1
a118 1
        super(conn, dMgr);
d133 2
a134 2
                             usrGrpMgr.getNobodyUserID(conn));
        dlMgr.addDownload(conn, projectID, f, descrip, acl.getUserID(), 
d162 1
a162 2
        throws SQLException, DataSetException, JoistDatabaseException,
               UpdateException, ACLException
d168 1
a168 1
            dlMgr.approveDownload(conn, getDownloadID(), acl.getUserID());
d183 1
a183 1
     * @@exception DataSetException
d187 1
a187 2
        throws DataSetException, SQLException, ACLException, DoesNotExist,
               IOException
d191 2
a192 2
        dlMgr.editDownload(conn, getID(), description, approvedBy, isPublic);
        Project project = new Project(conn, dMgr, projectID);
d209 2
a210 2
        throws SQLException, DataSetException, JoistDatabaseException,
               UpdateException, ACLException, DoesNotExist, IOException
d220 2
a221 2
        dlMgr.deleteDownload(conn, getID());
        Project project = new Project(conn, dMgr, getProjectID());
d231 2
a232 2
        throws SQLException, DataSetException, JoistDatabaseException,
               UpdateException, ACLException, DoesNotExist, IOException
d237 1
a237 1
    public String getID () throws DataSetException
d245 1
a245 1
    public String getDownloadID () throws DataSetException
d253 1
a253 1
    public String getName () throws DataSetException
d261 1
a261 1
    public String getLocation () throws DataSetException
d270 1
a270 1
    public String getSize () throws DataSetException
d295 1
a295 1
    public String getDescription () throws DataSetException
d300 1
a300 1
    public String getUploadDate () throws DataSetException, ParseException
d308 1
a308 1
    public String getProjectID() throws DataSetException
d314 1
a314 2
        throws DataSetException, SQLException, JoistDatabaseException,
               DoesNotExist
d318 1
a318 1
        return User.getInstance(conn, dMgr, uid);
d324 1
a324 1
    public String getMD5Checksum () throws DataSetException
d329 1
a329 1
    public Boolean isPublic () throws DataSetException
@


1.29
log
@Removed unnecessary getCache() implementations in BusinessObject subclasses and migrated to a factory method for User's primary database key ctor.
@
text
@d338 2
a339 2
        return new Boolean(rec.getValue(ProjectDownloadManager.IS_PUBLIC)
                           .asString().equals("Y"));
@


1.28
log
@Propogated object cache interface.
@
text
@a150 5
    protected Dictionary getCache ()
    {
        return null;
    }

d325 1
a325 1
        return new User(conn, dMgr, uid);
@


1.27
log
@Do deletion housekeeping in the right order.
@
text
@d151 5
@


1.26
log
@Regenerate .htaccess file on download deletion.
@
text
@d226 1
a228 1
        dlMgr.deleteDownload(conn, getID());
@


1.25
log
@obliterated eeeeeeevil tabs
@
text
@d209 1
d213 2
a214 1
    public void delete (AccessControlList acl, boolean fromFilesystem)
d216 1
a216 1
               UpdateException, ACLException
d226 3
a228 1
        dlMgr.deleteDownload(conn, getDownloadID());
d236 1
a236 1
    public void delete (AccessControlList acl)
d238 1
a238 1
               UpdateException, ACLException
d240 1
a240 1
        delete(acl, true);
@


1.24
log
@Merged duplicate download addition code into a Download ctor.  Made Download.edit() regenerate the .htaccess file.
@
text
@d120 1
a120 1
	       JoistDatabaseException, ACLException, IOException
d197 1
a197 1
	dlMgr.editDownload(conn, getID(), description, approvedBy, isPublic);
d213 2
a214 2
       throws SQLException, DataSetException, JoistDatabaseException,
              UpdateException, ACLException
d233 2
a234 2
       throws SQLException, DataSetException, JoistDatabaseException,
              UpdateException, ACLException
@


1.23
log
@Added business logic pulled from database.ProjectDownloadManager for
use by project.ProjectDownload.
@
text
@d51 1
d116 3
a118 3
    public Download(Connection conn, DataManager dMgr, AccessControlList acl,
                    String projectID, String descrip, String uploadedBy,
                    File f, String isPublic)
d120 1
a120 1
	       JoistDatabaseException, ACLException
a122 11
	
	if (!acl.hasPermissionForProject("Project Download - Suggest", 
	                                 projectID))
	{
	    throw new ACLException(acl, "Project Download - Suggest",
	                           "Project " + projectID, null);
	}

        String approvedBy = usrGrpMgr.getNobodyUserID(conn);
        setRecord(dlMgr.addDownload(conn, projectID, f, descrip,
                                    acl.getUserID(), approvedBy, isPublic));
d124 17
a140 2
	// Approve download, if user has permission
	approve(acl);
a142 1

d165 1
a165 1
    public void approve(AccessControlList acl)
d174 1
d185 1
d191 9
a199 6
                      String userID, String isPublic)
        throws DataSetException, SQLException, ACLException
    {
        acl.assertPermissionForProject("Project Download - Approve",
                                       getProjectID());
	dlMgr.editDownload(conn, getID(), description, userID, isPublic);
@


1.22
log
@Changed IS_PRIVATE to IS_PUBLIC--propogating all the way through to the UI.
@
text
@d148 11
@


1.21
log
@- Corrected compile error.
- Prefer good coding style over early return in approve().
@
text
@d117 1
a117 1
                    File f, String isPrivate)
d132 1
a132 1
                                    acl.getUserID(), approvedBy, isPrivate));
d168 1
a168 1
     * @@param isPrivate     Whether the download is private.
d174 1
a174 1
                      String userID, String isPrivate)
d179 1
a179 1
	dlMgr.editDownload(conn, getID(), description, userID, isPrivate);
d312 1
a312 1
    public Boolean isPrivate () throws DataSetException
d314 1
a314 1
        return new Boolean(rec.getValue(ProjectDownloadManager.IS_PRIVATE)
@


1.20
log
@Added getMD5Checksum() method.
@
text
@d155 1
a155 1
        if (!acl.hasPermissionForProject(action, getProjectID()))
d157 2
a158 1
            return;
a159 2
        acl.assertPermissionForProject(action, getProjectID());
        dlMgr.approveDownload(conn, getDownloadID(), acl.getUserID());
d177 2
a178 1
        acl.assertPermissionForProject("Project Download - Approve", getProjectID());
d307 1
a307 1
    public String getMD5Checksum ()
@


1.19
log
@Enabled security check of records passed into business objects.
@
text
@d304 8
@


1.18
log
@Added a check so that business objects cannot be created with records from the wrong table. Also added some new business objects.
@
text
@d74 5
@


1.17
log
@Correctly indented method.
@
text
@d78 1
a78 1
        throws DoesNotExist
@


1.16
log
@changed name of edit permission
@
text
@d17 1
a17 1
 * software developed by Collab.Net (http://www.Collab.Net/)."
d145 12
a156 12
   public void approve(AccessControlList acl)
       throws SQLException, DataSetException, JoistDatabaseException,
              UpdateException, ACLException
   {
       String action = "Project Download - Approve";
       if (!acl.hasPermissionForProject(action, getProjectID()))
       {
          return;
       }
       acl.assertPermissionForProject(action, getProjectID());
       dlMgr.approveDownload(conn, getDownloadID(), acl.getUserID());
   }
@


1.15
log
@Added additional delete() interface.
@
text
@d173 1
a173 1
        acl.assertPermissionForProject("Download - Approve", getProjectID());
@


1.14
log
@I wanted to use the variable name "markedForDeath" instead of
"victim", but the longer name caused the line to wrap.  DAMN.
@
text
@d178 8
a185 1
     * Deletes the download.
d187 1
a187 1
   public void delete(AccessControlList acl)
d193 6
a198 2
        File victim = new File(getLocation() + File.separatorChar + getName());
        if (victim.exists()) victim.delete();
d200 12
@


1.13
log
@Renamed editDownload() to edit() and refactored with a vengence.
@
text
@d186 2
@


1.12
log
@- Added isPrivate flag for Download ctors.
- Now checking ACLs in editDownload(), and handling isPrivate.
@
text
@d159 19
d274 1
a274 17
    /**
     * Updates a mailing list in the project database.
     *
     * @@param connection    The JDBC database connection to use
     * @@param acl           The access control list for the current user
     * @@param projectID     The ID for the list's project
     * @@param name          The name for the list
     * @@param description   A short description of the list
     * @@param type          The type of the list
     *
     * @@exception SQLException
     * @@exception DataSetException
     */
    public void editDownload(AccessControlList acl, Download dl,
                             String description, String loginID,
                             String isPrivate)
        throws DataSetException, SQLException, ACLException
d276 2
a277 3
        acl.assertPermissionForProject("Download - Approve", 
                                       dl.getProjectID());
	dlMgr.editDownload(conn, dl.getID(), description, loginID, isPrivate);
@


1.11
log
@Sync'd w/ interface changes.
@
text
@d112 1
a112 1
                    File f)
d126 2
a127 2
        setRecord(dlMgr.addDownload (conn, projectID, f, descrip,
                                     acl.getUserID(), approvedBy));
d268 8
a275 9
    public void editDownload(Connection connection, AccessControlList acl, 
                            Download dl, String description, String loginID)
        throws DataSetException, SQLException, SecurityException
    {
        if (false && !acl.hasPermissionForProject("Download - Approve", 
                    dl.getDownloadID()))
            throw new SecurityException("No permission to edit a download");
	dlMgr.editDownload(connection, dl.getDownloadID(), 
	                   description, loginID);
@


1.10
log
@- Corrected formatting of delete() method.
- Deprecated getDownloadID() method and added getID() method for
  consistancy w/ other business objects.
@
text
@d111 2
a112 1
                    String projectID, String descrip, String uploadedBy, File f)
d126 2
a127 1
        setRecord(dlMgr.addDownload (conn, projectID, descrip, f, acl.getUserID(), approvedBy));
@


1.9
log
@added add, delete, approve methods
@
text
@d162 5
a166 5
   {
       String action = "Project Download - Approve";
       acl.assertPermissionForProject(action, getProjectID());
       dlMgr.deleteDownload(conn, getDownloadID());
   }
d168 8
d178 1
a178 1
        return rec.getValue(ProjectDownloadManager.DOWNLOAD_ID).asString();
@


1.8
log
@Added new ctor.
@
text
@d50 1
d60 1
a60 1
import org.tigris.helm.database.ProjectDownloadManager;
d62 1
a62 1
import org.tigris.helm.tool.FormatDate;
d75 1
d83 1
d107 25
d136 2
d139 28
@


1.7
log
@added edit method with ACL checking

added constructor to access Download by downloadID

TODO: add constructor for new downloads
@
text
@d92 12
@


1.6
log
@Added getLocation() method.
@
text
@d60 1
d81 11
d173 24
@


1.5
log
@use thy constants, gentle fool
@
text
@d91 3
d97 8
@


1.4
log
@Refactored methods for pretty-printing.
@
text
@d68 1
a68 1
    private static final int ONE_MB = 1024 * 1000;
d70 1
a70 1
    private static final int ONE_GB = 1024 * 1000 * 1000;
@


1.3
log
@Added a getSize() method.
@
text
@d62 1
d66 6
d96 4
d102 21
a122 1
        return rec.getValue(ProjectDownloadManager.SIZE).asString();
d143 7
a149 4
    public String getUploadedBy()
        throws DataSetException, SQLException, JoistDatabaseException
    {
        return rec.getValue(ProjectDownloadManager.UPLOADED_BY).asString();
@


1.2
log
@Cleaned up and sync'd w/ ProjectDownloadManager.
@
text
@d89 5
d112 2
a113 2
    public String getUploadedBy() throws DataSetException, SQLException,
    JoistDatabaseException
@


1.1
log
@Initial revision
@
text
@d50 2
a51 1
import java.sql.*;
d58 1
a59 1
import org.tigris.helm.domain.BusinessObject;
d65 1
a65 1
  private ProjectDownloadManager dlMgr;
d67 45
a111 43
  public Download (Connection conn, DataManager dMgr, Record rec)
      throws DoesNotExist
  {
    super(conn, dMgr, rec);
  }

  protected void createManagers ()
  {
    dlMgr = (ProjectDownloadManager)
      dMgr.getManager ("org.tigris.helm.database.ProjectDownloadManager");
  }

  public String getDownloadID () throws DataSetException
  {
    return rec.getValue (dlMgr.DOWNLOAD_ID).asString ();
  }

  public String getName () throws DataSetException
  {
    return rec.getValue (dlMgr.NAME).asString ();
  }

  public String getDescription () throws DataSetException
  {
    return rec.getValue (dlMgr.DESCRIPTION).asString ();
  }

  public String getUploadDate () throws DataSetException, ParseException
  {
    String uploadDate = rec.getValue (dlMgr.UPLOAD_DATE).asString ();
    return FormatDate.format("yyyy-MM-dd kk:mm:ss", "MM-dd-yy", uploadDate);
  }

  public String getProjectID() throws DataSetException
  {
    return rec.getValue (dlMgr.PROJECT_ID).asString ();
  }

  public String getUploadedBy() throws DataSetException, SQLException,
                                         JoistDatabaseException
  {
    return rec.getValue (dlMgr.UPLOADED_BY).asString ();
  }
@


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
@@
