head	1.14;
access;
symbols
	TIGRIS_0_9_2_4:1.3.2.1
	TIGRIS_0_9_2_3:1.3
	HELM_PEER_PORT_BRANCH:1.8.0.2
	TURBINE_PEER:1.8
	TIGRIS_0_9_2_1:1.8
	TIGRIS_0_9_2:1.3.0.2;
locks; strict;
comment	@# @;


1.14
date	2001.02.21.03.23.57;	author edk;	state dead;
branches;
next	1.13;

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

1.12
date	2001.02.02.00.14.50;	author elicia;	state Exp;
branches;
next	1.11;

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

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

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

1.8
date	2001.01.27.02.18.50;	author elicia;	state Exp;
branches
	1.8.2.1;
next	1.7;

1.7
date	2001.01.26.18.29.04;	author edk;	state Exp;
branches;
next	1.6;

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

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

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

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

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

1.1
date	2000.12.31.23.09.07;	author jrobbins;	state Exp;
branches;
next	;

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

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


desc
@@


1.14
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.*;
import java.text.ParseException;

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 Document extends BusinessObject
{

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

    private ProjectManager pMgr;
    private ProjectDocumentManager docMgr;
    private ProjectDocumentSectionManager pdsMgr;
    private UserUserGroupManager usrGrpMgr;

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


    /**
     * Constructor for a document which already exists -- accessed by
     * documentID.
     */
    public Document(Connection conn, DataManager dMgr, String documentID)
        throws SQLException, DataSetException, DoesNotExist
    {
        super(conn, dMgr);
        setRecord(docMgr.getDocumentForID(conn, documentID));
    }

    /**
     * Constructor for a new document.
     */
    public Document (Connection conn, DataManager dMgr, AccessControlList acl,
                     Project project, String name, String descrip, 
                     String type, String url, String text,
                     String sectionID, File f, String htURL)
        throws SQLException, DataSetException, DoesNotExist, UpdateException,
               JoistDatabaseException, ACLException, IOException
    {
        super(conn, dMgr);

        // To type a document you need either Suggest or Approve permission.
        String projectID = project.getID();
        String suggest = "Project Document - Suggest";
        String approve = "Project Document - 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 nobody = usrGrpMgr.getNobodyUserID(conn);
        String approvedBy = (acl.hasPermissionForProject(approve, projectID) ?
                             acl.getUserID() : 
                             usrGrpMgr.getNobodyUserID(conn));
        docMgr.addDocument(conn, projectID, name, descrip, type,
                           url, text, acl.getUserID(), approvedBy, sectionID, f);
        if (f != null)
            project.writeHtaccessFile(extractLocation(f), htURL);
    }

    protected void createManagers ()
    {
        pMgr = (ProjectManager)
            dMgr.getManager("org.tigris.helm.database.ProjectManager");
        docMgr = (ProjectDocumentManager)
            dMgr.getManager("org.tigris.helm.database.ProjectDocumentManager");
        pdsMgr = (ProjectDocumentSectionManager)
            dMgr.getManager("org.tigris.helm.database.ProjectDocumentSectionManager");
        usrGrpMgr = (UserUserGroupManager)
            dMgr.getManager("org.tigris.helm.database.UserUserGroupManager");
    }


    /**
     * Approves the document.
     */
    public void approve (AccessControlList acl)
        throws SQLException, DataSetException, JoistDatabaseException,
               UpdateException, ACLException
    {
        String action = "Project Document - Approve";
        if (acl.hasPermissionForProject(action, getProjectID()))
        {
            acl.assertPermissionForProject(action, getProjectID());
            docMgr.approveDocument(conn, getID(), acl.getUserID());
        }
    }

    /**
     * Disapproves the document.
     */
    public void disapprove (AccessControlList acl, WebContext ctx)
        throws SQLException, DataSetException, JoistDatabaseException,
               JoistException, DoesNotExist, ACLException, UpdateException, 
               IOException
    {
        String action = "Project Document - Approve";
        if (!acl.hasPermissionForProject(action, getProjectID()))
        {
            return;
        }
        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 document '")
            .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(getSuggestedBy().getEmail(), subject, body.toString());
        delete(acl, true, ctx);
    }

    /**
     * Updates a document.
     *
     * @@param acl           The access control list of the current user.
     * @@param name          The name of the document.
     * @@param type          How the document got saved.
     * @@param description   A description of the document.
     *
     * @@exception SQLException
     * @@exception DataSetException
     */
    public void edit (AccessControlList acl, String name, String description,
                      String type, String url, String text,
                      String sectionID, File f, WebContext ctx)
        throws DataSetException, SQLException, ACLException, DoesNotExist,
               IOException, JoistDatabaseException
    {
        String action = "Project Document - Edit";
        if (!acl.getUserID().equals(getSuggestedBy().getID()))
            acl.assertPermissionForProject(action, getProjectID());
        docMgr.editDocument(conn, getID(), name, description, type, 
                            url, text, sectionID, f);
        Project project = new Project(conn, dMgr, getProjectID());
        if (getType().equals("upload"))
        {
            String htURL = URL.schemeAndServer(ctx)
                           + "/servlets/ProjectDocuments";
            project.writeHtaccessFile(getLocation(), htURL);
        }
    }

    /**
     * Deletes the document.  
     * If fromFilesystem is true, deletes uploaded file
     * And updates the .htaccess file
     *
     * @@param acl            The ACL to check for delete permission.
     *                       the database.
     * @@param fromFilesystem If true, delete uploaded file 
     *                       and update the .htaccess file
     * @@param ctx            WebContext.
     */
    public void delete (AccessControlList acl, boolean fromFilesystem,
                        WebContext ctx)
        throws SQLException, DataSetException, JoistDatabaseException,
               UpdateException, ACLException, DoesNotExist, IOException
    {
        String action = "Project Document - Delete";
        if (!acl.getUserID().equals(getSuggestedBy().getID()))
        {
            acl.assertPermissionForProject(action, getProjectID());
        }
        if (fromFilesystem)
        {
            File victim =
                new File(getLocation() + File.separatorChar + getFilename());
            if (victim.exists()) victim.delete();
            String htURL = URL.schemeAndServer(ctx)
                           + "/servlets/ProjectDocuments";
            Project project = new Project(conn, dMgr, getProjectID());
            project.writeHtaccessFile(getLocation(), htURL);
        }
        docMgr.deleteDocument(conn, getID());
    }

    /**
     * Moves the document to the top level.
     */
    public void moveToTop ()
        throws SQLException, DataSetException, JoistDatabaseException,
               UpdateException, ACLException, DoesNotExist, IOException
    {
        pdsMgr.deleteRecord(conn, getID());
    }

    /**
     * Returns the id of the section of this document 
     */
    public String getID () throws DataSetException
    {
        return rec.getValue(ProjectDocumentManager.DOCUMENT_ID).asString();
    }

    /**
     * Returns the id of this document 
     */
    public String getSectionID() throws DataSetException, SQLException
    {
        return pdsMgr.getSectionIDForDocument(conn, getID());
    }
        
    /**
     * Returns the name of this document 
     */
    public String getName () throws DataSetException
    {
        return rec.getValue(ProjectDocumentManager.NAME).asString();
    }

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

    /**
     * Returns the way the document was saved--uploaded, as a remote URL,
     * Or in the database.
     */
    public String getType () throws DataSetException
    {
        return rec.getValue(ProjectDocumentManager.TYPE).asString();
    }

    /**
     * Returns the name of the uploaded file
     */
    public String getFilename () throws DataSetException
    {
        return rec.getValue(ProjectDocumentManager.FILE_NAME).asString();
    }
    /**
     * Returns the link to the file.
     */
    public String getLink (Project currentProject) throws DataSetException
    {
        String link = null;
        StringBuffer argBuffer = null;
        String arg = null;
        String type = getType();

        if (type.equals("url"))
        {
           link = getUrl();
        } 
        else if (type.equals("text"))
        {
           argBuffer = new StringBuffer("documentID=");
           argBuffer.append(getID());
           arg = argBuffer.toString();
           link = currentProject.getProjectPageURL("ProjectDocumentView", 
                                                   arg);
        }
        else
        {
           argBuffer = new StringBuffer("dcID=");
           argBuffer.append(getID()).append("&action=download");
           arg = argBuffer.toString();
           link = currentProject.getProjectPageURL("ProjectDocuments", 
                                                   arg);
        }
   
        return link;
     }
          

    /**
     * Returns the url where this document resides.
     */
    public String getUrl () throws DataSetException
    {
        return rec.getValue(ProjectDocumentManager.URL).asString();
    }

    /**
     * Returns the text of the document.
     */
    public String getText () throws DataSetException
    {
        return rec.getValue(ProjectDocumentManager.TEXT).asString();
    }

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


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

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

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

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

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

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

    /**
     * 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();
    }
}
@


1.13
log
@cleanup
@
text
@@


1.12
log
@added formatting to email message
@
text
@d380 1
a380 1
        String projectID = rec.getValue (ProjectDocumentManager.PROJECT_ID).asString ();
@


1.11
log
@passing context to Document to determine url for .htaccess file
@
text
@d183 1
a183 1
        body.append(getProjectName()).append(" has been disapproved.\n");
d186 1
a186 1
            .append(disapprovingUser.getEmail()).append(")");
@


1.10
log
@added moveToTop method
@
text
@d60 1
d165 1
a165 1
    public void disapprove (AccessControlList acl, String htURL)
d189 1
a189 1
        delete(acl, true, htURL);
d205 1
a205 1
                      String sectionID, File f, String htURL)
d215 6
a220 1
        project.writeHtaccessFile(getLocation(), htURL);
d225 2
d230 3
d235 1
a235 1
                        String htURL)
d241 1
d243 1
d249 4
a254 2
        Project project = new Project(conn, dMgr, getProjectID());
        project.writeHtaccessFile(getLocation(), htURL);
@


1.9
log
@added editing of .htaccess file on edit and deleting of a file
@
text
@d243 10
@


1.8
log
@changed permission checking so that the user that suggested a document can edit and delete it
@
text
@d164 1
a164 1
    public void disapprove (AccessControlList acl)
d188 1
a188 1
        delete(acl,true);
d203 2
a204 2
                      String type, String url, 
                      String text, String sectionID, File f)
d213 2
d223 2
a224 1
    public void delete (AccessControlList acl, boolean fromFilesystem)
d238 2
@


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


1.7
log
@readding all the files as part of the process of returning to the way
things were as of tuesday
@
text
@d208 3
a210 2
        String projectID = getProjectID();
        acl.assertPermissionForProject("Project Document - Edit", projectID);
d226 2
a227 1
        acl.assertPermissionForProject(action, getProjectID());
a234 14
    }

    public String requiredViewPermission()
        throws JoistDatabaseException, DataSetException, SQLException,
               ParseException, DoesNotExist
    {
        String permission = "Project Document - Edit";
        if (isApproved())
        {
            permission = "Project Document - View";
        } else {
            permission = "Project Document - Approve";
        }
        return permission;
@


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

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

it compiles.  i dunno if it works, though.
@
text
@d82 2
a83 2
    public Document (DataManager dMgr, Record rec)
        throws DBException
d85 1
a85 1
        super(dMgr, rec);
d93 2
a94 2
    public Document(DataManager dMgr, String documentID)
        throws DoesNotExist, DBException
d96 2
a97 1
        super(dMgr, docMgr.getDocumentForID(documentID));
d103 1
a103 1
    public Document (DataManager dMgr, AccessControlList acl,
d107 2
a108 2
        throws ACLException, IOException, DoesNotExist, UpdateException,
               DBException
d110 1
a110 1
        super(dMgr);
d123 1
a123 1
        String nobody = uMgr.getNobodyUserID();
d126 3
a128 4
                             uMgr.getNobodyUserID());
        docMgr.addDocument(projectID, name, descrip, type, url, text,
                           acl.getUserID(), approvedBy, sectionID, f);
                           
d150 2
a151 1
        throws ACLException, UpdateException, DBException
d157 1
a157 1
            docMgr.approveDocument(getID(), acl.getUserID());
d165 1
a165 1
        throws DBException,
d177 2
a178 3
        User disapprovingUser = User.getInstance(dMgr, acl.getUserID());
        String subject = "Document for Project " + getProjectName() +
            " disapproved.";
d186 1
a186 1
        HelmEmailer emailer = new HelmEmailer(dMgr);
d205 2
a206 1
        throws ACLException, DoesNotExist, IOException, DBException
d210 2
a211 2
        docMgr.editDocument(getID(), name, description, type, url, text,
                            sectionID, f);
d221 2
a222 2
        throws ACLException, DoesNotExist, UpdateException, IOException,
               DBException
d232 1
a232 1
        docMgr.deleteDocument(getID());
d236 2
a237 1
        throws DoesNotExist, ParseException, DBException
d252 1
a252 1
    public String getID () throws DBException
d260 1
a260 1
    public String getSectionID() throws DBException, SQLException
d262 1
a262 1
        return pdsMgr.getSectionIDForDocument(getID());
d268 1
a268 1
    public String getName () throws DBException
d276 1
a276 1
    public String getLocation () throws DBException
d285 1
a285 1
    public String getType () throws DBException
d293 1
a293 1
    public String getFilename () throws DBException
d300 1
a300 1
    public String getLink (Project currentProject) throws DBException
d335 1
a335 1
    public String getUrl () throws DBException
d343 1
a343 1
    public String getText () throws DBException
d348 1
a348 1
    public String getDescription () throws DBException
d354 1
a354 1
    public String getProjectID() throws DBException
d360 1
a360 1
        throws DBException, SQLException, JoistDatabaseException
d362 2
a363 3
        String projectID =
            rec.getValue(ProjectDocumentManager.PROJECT_ID).asString();
        String projectName = pMgr.getProjectName(projectID);
d368 2
a369 1
        throws DoesNotExist, DBException
d373 1
a373 1
        return User.getInstance(dMgr, uid);
d377 2
a378 1
        throws DoesNotExist, DBException
d382 1
a382 1
        return User.getInstance(dMgr, uid);
d386 2
a387 1
          throws DoesNotExist, DBException
d390 1
a390 1
          return !getApprovedBy().getID().equals(uMgr.getNobodyUserID());
d393 1
a393 1
    public Boolean isPublic () throws DBException
@


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


1.4
log
@added getLink, isPublic, extractLocation, getType methods
@
text
@d82 2
a83 2
    public Document (Connection conn, DataManager dMgr, Record rec)
        throws DoesNotExist, DataSetException
d85 1
a85 1
        super(conn, dMgr, rec);
d93 2
a94 2
    public Document(Connection conn, DataManager dMgr, String documentID)
        throws SQLException, DataSetException, DoesNotExist
d96 1
a96 2
        super(conn, dMgr);
        setRecord(docMgr.getDocumentForID(conn, documentID));
d102 1
a102 1
    public Document (Connection conn, DataManager dMgr, AccessControlList acl,
d106 2
a107 2
        throws SQLException, DataSetException, DoesNotExist, UpdateException,
               JoistDatabaseException, ACLException, IOException
d109 1
a109 1
        super(conn, dMgr);
d122 1
a122 1
        String nobody = usrGrpMgr.getNobodyUserID(conn);
d125 4
a128 3
                             usrGrpMgr.getNobodyUserID(conn));
        docMgr.addDocument(conn, projectID, name, descrip, type,
                           url, text, acl.getUserID(), approvedBy, sectionID, f);
d150 1
a150 2
        throws SQLException, DataSetException, JoistDatabaseException,
               UpdateException, ACLException
d156 1
a156 1
            docMgr.approveDocument(conn, getID(), acl.getUserID());
d164 1
a164 1
        throws SQLException, DataSetException, JoistDatabaseException,
d176 3
a178 2
        User disapprovingUser = User.getInstance(conn, dMgr, acl.getUserID());
        String subject = "Document for Project " + getProjectName() + " disapproved.";
d186 1
a186 1
        HelmEmailer emailer = new HelmEmailer(conn, dMgr);
d205 1
a205 2
        throws DataSetException, SQLException, ACLException, DoesNotExist,
               IOException, JoistDatabaseException
d209 2
a210 2
        docMgr.editDocument(conn, getID(), name, description, type, 
                            url, text, sectionID, f);
d220 2
a221 2
        throws SQLException, DataSetException, JoistDatabaseException,
               UpdateException, ACLException, DoesNotExist, IOException
d231 1
a231 1
        docMgr.deleteDocument(conn, getID());
d235 1
a235 2
        throws JoistDatabaseException, DataSetException, SQLException,
               ParseException, DoesNotExist
d250 1
a250 1
    public String getID () throws DataSetException
d258 1
a258 1
    public String getSectionID() throws DataSetException, SQLException
d260 1
a260 1
        return pdsMgr.getSectionIDForDocument(conn, getID());
d266 1
a266 1
    public String getName () throws DataSetException
d274 1
a274 1
    public String getLocation () throws DataSetException
d283 1
a283 1
    public String getType () throws DataSetException
d291 1
a291 1
    public String getFilename () throws DataSetException
d298 1
a298 1
    public String getLink (Project currentProject) throws DataSetException
d333 1
a333 1
    public String getUrl () throws DataSetException
d341 1
a341 1
    public String getText () throws DataSetException
d346 1
a346 1
    public String getDescription () throws DataSetException
d352 1
a352 1
    public String getProjectID() throws DataSetException
d358 1
a358 1
        throws DataSetException, SQLException, JoistDatabaseException
d360 3
a362 2
        String projectID = rec.getValue (ProjectDocumentManager.PROJECT_ID).asString ();
        String projectName = pMgr.getProjectName(conn, projectID);
d367 1
a367 2
        throws DataSetException, SQLException, JoistDatabaseException,
               DoesNotExist
d371 1
a371 1
        return User.getInstance(conn, dMgr, uid);
d375 1
a375 2
        throws DataSetException, SQLException, JoistDatabaseException,
               DoesNotExist
d379 1
a379 1
        return User.getInstance(conn, dMgr, uid);
d383 1
a383 2
          throws JoistDatabaseException, DataSetException, SQLException,
                 DoesNotExist
d386 1
a386 1
          return !getApprovedBy().getID().equals(usrGrpMgr.getNobodyUserID(conn));
d389 1
a389 1
    public Boolean isPublic () throws DataSetException
@


1.3
log
@added URL and TEXT fields

added getProjectName method
@
text
@d105 2
a106 2
                     String location, String url, String text,
                     String sectionID)
d112 1
a112 1
        // To add a document you need either Suggest or Approve permission.
d127 4
a130 2
        docMgr.addDocument(conn, projectID, name, descrip, location,
                           url, text, acl.getUserID(), approvedBy, sectionID);
d188 1
a188 1
        delete(acl);
d196 1
a196 1
     * @@param location      The location of the document.
d203 2
a204 1
                      String location, String url, String text, String sectionID)
d210 2
a211 2
        docMgr.editDocument(conn, getID(), name, description, location, url,
                            text, sectionID);
d220 1
a220 1
    public void delete (AccessControlList acl)
d226 6
d282 51
d393 16
@


1.3.2.1
log
@moved changed from HEAD for ProjectDocuments and ProjectDownloads
@
text
@a59 1
import org.joist.util.*;
d105 2
a106 2
                     String type, String url, String text,
                     String sectionID, File f, String htURL)
d112 1
a112 1
        // To type a document you need either Suggest or Approve permission.
d127 2
a128 4
        docMgr.addDocument(conn, projectID, name, descrip, type,
                           url, text, acl.getUserID(), approvedBy, sectionID, f);
        if (f != null)
            project.writeHtaccessFile(extractLocation(f), htURL);
d162 1
a162 1
    public void disapprove (AccessControlList acl, WebContext ctx)
d186 1
a186 1
        delete(acl, true, ctx);
d194 1
a194 1
     * @@param type          How the document got saved.
d201 1
a201 2
                      String type, String url, String text,
                      String sectionID, File f, WebContext ctx)
d205 4
a208 12
        String action = "Project Document - Edit";
        if (!acl.getUserID().equals(getSuggestedBy().getID()))
            acl.assertPermissionForProject(action, getProjectID());
        docMgr.editDocument(conn, getID(), name, description, type, 
                            url, text, sectionID, f);
        Project project = new Project(conn, dMgr, getProjectID());
        if (getType().equals("upload"))
        {
            String htURL = URL.schemeAndServer(ctx)
                           + "/servlets/ProjectDocuments";
            project.writeHtaccessFile(getLocation(), htURL);
        }
a212 2
     * If fromFilesystem is true, deletes uploaded file
     * And updates the .htaccess file
a215 3
     * @@param fromFilesystem If true, delete uploaded file 
     *                       and update the .htaccess file
     * @@param ctx            WebContext.
d217 1
a217 2
    public void delete (AccessControlList acl, boolean fromFilesystem,
                        WebContext ctx)
d222 1
a222 14
        if (!acl.getUserID().equals(getSuggestedBy().getID()))
        {
            acl.assertPermissionForProject(action, getProjectID());
        }
        if (fromFilesystem)
        {
            File victim =
                new File(getLocation() + File.separatorChar + getFilename());
            if (victim.exists()) victim.delete();
            String htURL = URL.schemeAndServer(ctx)
                           + "/servlets/ProjectDocuments";
            Project project = new Project(conn, dMgr, getProjectID());
            project.writeHtaccessFile(getLocation(), htURL);
        }
d226 3
a228 6
    /**
     * Moves the document to the top level.
     */
    public void moveToTop ()
        throws SQLException, DataSetException, JoistDatabaseException,
               UpdateException, ACLException, DoesNotExist, IOException
d230 8
a237 1
        pdsMgr.deleteRecord(conn, getID());
a272 51
     * Returns the way the document was saved--uploaded, as a remote URL,
     * Or in the database.
     */
    public String getType () throws DataSetException
    {
        return rec.getValue(ProjectDocumentManager.TYPE).asString();
    }

    /**
     * Returns the name of the uploaded file
     */
    public String getFilename () throws DataSetException
    {
        return rec.getValue(ProjectDocumentManager.FILE_NAME).asString();
    }
    /**
     * Returns the link to the file.
     */
    public String getLink (Project currentProject) throws DataSetException
    {
        String link = null;
        StringBuffer argBuffer = null;
        String arg = null;
        String type = getType();

        if (type.equals("url"))
        {
           link = getUrl();
        } 
        else if (type.equals("text"))
        {
           argBuffer = new StringBuffer("documentID=");
           argBuffer.append(getID());
           arg = argBuffer.toString();
           link = currentProject.getProjectPageURL("ProjectDocumentView", 
                                                   arg);
        }
        else
        {
           argBuffer = new StringBuffer("dcID=");
           argBuffer.append(getID()).append("&action=download");
           arg = argBuffer.toString();
           link = currentProject.getProjectPageURL("ProjectDocuments", 
                                                   arg);
        }
   
        return link;
     }
          

    /**
a332 16
    public Boolean isPublic () throws DataSetException
    {
        return DBFlag.boolValueOf
            (rec.getValue(ProjectDownloadManager.IS_PUBLIC).asString());
    }

    /**
     * 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();
    }
@


1.2
log
@added isApproved, getSectionID, getRequiredView permission methods
@
text
@d60 1
d77 1
d104 3
a106 2
                     Project project, String name, String location, 
                     String descrip, String sectionID)
d127 2
a128 2
        docMgr.addDocument(conn, projectID, name, location, descrip, 
                          acl.getUserID(), approvedBy, sectionID);
d133 2
d160 30
d200 2
a201 2
    public void edit (AccessControlList acl, String name, String location,
                      String description, String sectionID)
d207 2
a208 2
        docMgr.editDocument(conn, getID(), name, location, description, 
                            sectionID);
d217 1
a217 1
    public void delete (AccessControlList acl, String downloadID)
d221 1
a221 1
        String action = "Project Document - Approve";
d272 16
d299 8
d330 1
a330 1
          return !getApprovedBy().equals(usrGrpMgr.getNobodyUserID(conn));
@


1.1
log
@added files needed for ProjectDocuments
@
text
@d55 2
d77 1
d120 1
d132 4
d171 1
a171 1
        acl.assertPermissionForProject("Project Document - Approve", projectID);
d191 13
d205 3
d214 8
d245 1
a245 1
        return rec.getValue(ProjectDocumentManager.DOCUMENT_PROJECT_ID).asString();
d265 9
@

