head	1.10;
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.10
date	2001.02.21.03.23.57;	author edk;	state dead;
branches;
next	1.9;

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

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

1.7
date	2001.01.26.18.29.05;	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.18.38;	author leonardr;	state Exp;
branches;
next	1.4;

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

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

1.2
date	2001.01.12.22.10.44;	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.10
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.IOException;
import java.sql.*;

import com.workingdogs.village.*;

import org.joist.database.*;
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 Section extends BusinessObject
{

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

    private ProjectManager pMgr;
    private ProjectSectionManager secMgr;
    private UserUserGroupManager usrGrpMgr;
    private ProjectDocumentSectionManager pdsMgr;

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


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

    /**
     * Constructor for a new document section.
     */
    public Section (Connection conn, DataManager dMgr, 
                    AccessControlList acl, Project project, 
                    String parentID, String name, String descrip)
        throws SQLException, DataSetException, DoesNotExist, UpdateException,
               JoistDatabaseException, ACLException
    {
        super(conn, dMgr);

        // To add a section 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 approvedBy = (acl.hasPermissionForProject(approve, projectID) ?
                             acl.getUserID() : 
                             usrGrpMgr.getNobodyUserID(conn));
        secMgr.addSection(conn, projectID, parentID, name, descrip, 
                          acl.getUserID(), approvedBy);
    }

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


    /**
     * Moves section to top level.
     */
    public void moveToTop (AccessControlList acl)
        throws SQLException, DataSetException, JoistDatabaseException,
               UpdateException, ACLException
    {
        String action = "Project Document - Edit";
        if (acl.hasPermissionForProject(action, getProjectID()))
        {
            acl.assertPermissionForProject(action, getProjectID());
            secMgr.moveToTop(conn, getID());
        }
    }

    /**
     * Approves the document section.
     */
    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());
            secMgr.approveSection(conn, getID(), acl.getUserID());
        }
    }

    /**
     * Disapproves the document section.
     */
    public void disapprove (AccessControlList acl)
        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 Section for Project " + getProjectName() + " disapproved.";
        StringBuffer body = new StringBuffer();
        body.append("Sorry, your submission of the document section '")
            .append(getName()).append("' for project ");
        body.append(getProjectName()).append(" has been disapproved.\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);
    }

    /**
     * Updates a document section.
     *
     * @@param acl           The access control list of the current user.
     * @@param name          The name of the document.
     * @@param description   A description of the document.
     *
     * @@exception SQLException
     * @@exception DataSetException
     */
    public void edit (AccessControlList acl, String parentID,
                      String name, String description)
        throws DataSetException, SQLException, ACLException, DoesNotExist,
               JoistDatabaseException
    {
        String action = "Project Document - Edit";
        if (!acl.getUserID().equals(getSuggestedBy().getID()))
            acl.assertPermissionForProject(action, getProjectID());
        secMgr.editSection(conn, getID(), parentID, name, description);
    }

    /**
     * Deletes the document section.  
     *
     * @@param acl            The ACL to check for delete permission.
     *                       the database.
     */
    public void delete (AccessControlList acl)
        throws SQLException, DataSetException, JoistDatabaseException,
               UpdateException, ACLException, DoesNotExist 
    {
        String action = "Project Document - Delete";
        if (!acl.getUserID().equals(getSuggestedBy().getID()))
            acl.assertPermissionForProject(action, getProjectID());
        secMgr.deleteSection(conn, getID());
    }


    public String getID () throws DataSetException
    {
        return rec.getValue(ProjectSectionManager.SECTION_ID).asString();
    }

    /**
     * Returns the name of this section 
     */
    public String getName () throws DataSetException
    {
        return rec.getValue(ProjectSectionManager.NAME).asString();
    }

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

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

    public String getProjectName() 
        throws DataSetException, SQLException, JoistDatabaseException
    {
        String projectID = rec.getValue (ProjectSectionManager.PROJECT_ID).asString ();
        String projectName = pMgr.getProjectName(conn, projectID);
        return projectName;
    }

    public String getParentID() throws DataSetException
    {
        return rec.getValue(ProjectSectionManager.PARENT_ID).asString();
    }

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

    public User getApprovedBy()
        throws DataSetException, SQLException, JoistDatabaseException,
               DoesNotExist
    {
        String uid = 
            rec.getValue(ProjectSectionManager.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 List getSubsections()
        throws DataSetException, SQLException, DoesNotExist, 
               JoistDatabaseException
    {
        List sections = new ArrayList();

        DataSet sectionSet = secMgr.getSubsections
                              (conn, getID());

        for (int i = 0; i < sectionSet.size(); i++)
        {
            Record r = sectionSet.getRecord(i);
	        sections.add(new Section(conn, dMgr, r));
        }

        return sections;

    }

    public List getDocuments()
        throws DataSetException, SQLException, DoesNotExist, 
               JoistDatabaseException
    {
        List documents = new ArrayList();

        DataSet documentSet = pdsMgr.getDocumentsForSection(conn, getID());

        for (int i = 0; i < documentSet.size(); i++)
        {
            Record r = documentSet.getRecord(i);
            String documentID = (String)r.getStringValue("document_id");
	        documents.add(new Document(conn, dMgr, documentID));
        }

        return documents;

    }
}
@


1.9
log
@fixed permission problem : owners of sections can deleting their own sections
@
text
@@


1.8
log
@changed permission checking so user that suggested a section can edit and delete it
@
text
@a231 1
        acl.assertPermissionForProject(action, getProjectID());
@


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
@d210 2
a211 1
        throws DataSetException, SQLException, ACLException, DoesNotExist
d213 3
a215 2
        String projectID = getProjectID();
        acl.assertPermissionForProject("Project Document - Approve", projectID);
d230 2
@


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
@d68 5
d78 2
a79 2
    public Section (DataManager dMgr, Record rec)
        throws DoesNotExist, DBException
d81 1
a81 1
        super(dMgr, rec);
d84 1
d89 2
a90 2
    public Section(DataManager dMgr, String documentID)
        throws DoesNotExist, DBException
d92 2
a93 1
        super(dMgr, secMgr.getSectionForID(documentID));
d99 2
a100 1
    public Section (DataManager dMgr, AccessControlList acl, Project project, 
d102 2
a103 1
        throws ACLException, DoesNotExist, UpdateException, DBException
d105 1
a105 1
        super(dMgr);
d120 2
a121 2
                             uMgr.getNobodyUserID());
        secMgr.addSection(projectID, parentID, name, descrip, 
a136 4
    protected final String getTableName() 
    {
        return ProjectSectionManager.TABLE_NAME;
    }
d142 2
a143 1
        throws ACLException, UpdateException, DBException
d149 1
a149 1
            secMgr.moveToTop(getID());
d157 2
a158 1
        throws ACLException, UpdateException, DBException
d164 1
a164 1
            secMgr.approveSection(getID(), acl.getUserID());
d172 3
a174 2
        throws ACLException, JoistException, DoesNotExist, UpdateException, 
               IOException, DBException
d184 1
a184 1
        User disapprovingUser = User.getInstance(dMgr, acl.getUserID());
d193 1
a193 1
        HelmEmailer emailer = new HelmEmailer(dMgr);
d206 1
a206 1
     * @@exception DBException
d210 1
a210 1
        throws ACLException, DoesNotExist, DBException
d214 1
a214 1
        secMgr.editSection(getID(), parentID, name, description);
d224 2
a225 1
        throws ACLException, UpdateException, DoesNotExist, DBException 
d229 1
a229 1
        secMgr.deleteSection(getID());
d233 1
a233 1
    public String getID () throws DBException
d241 1
a241 1
    public String getName () throws DBException
d246 1
a246 1
    public String getDescription () throws DBException
d251 1
a251 1
    public String getProjectID() throws DBException
d257 1
a257 1
        throws DBException
d260 1
a260 1
        String projectName = pMgr.getProjectName(projectID);
d264 1
a264 1
    public String getParentID() throws DBException
d270 2
a271 1
        throws DoesNotExist, DBException
d275 1
a275 1
        return User.getInstance(dMgr, uid);
d279 2
a280 1
        throws DoesNotExist, DBException
d284 1
a284 1
        return User.getInstance(dMgr, uid);
d288 3
a290 1
          throws DoesNotExist, DBException
d292 1
a292 1
          return !getApprovedBy().getID().equals(uMgr.getNobodyUserID());
d297 2
a298 1
        throws DoesNotExist, DBException
d302 2
a303 1
        DataSet sectionSet = secMgr.getSubsections(getID());
d308 1
a308 1
	        sections.add(new Section(dMgr, r));
d316 2
a317 1
        throws DoesNotExist, DBException
d321 1
a321 1
        DataSet documentSet = pdsMgr.getDocumentsForSection(getID());
d327 1
a327 1
	        documents.add(new Document(dMgr, documentID));
d331 1
@


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 moveToTop method to make sections top level if their parent sections get deleted
@
text
@a67 5
    protected final String getTableName() 
    {
        return ProjectSectionManager.TABLE_NAME;
    }

d73 2
a74 2
    public Section (Connection conn, DataManager dMgr, Record rec)
        throws DoesNotExist, DataSetException
d76 1
a76 1
        super(conn, dMgr, rec);
a78 1

d83 2
a84 2
    public Section(Connection conn, DataManager dMgr, String documentID)
        throws SQLException, DataSetException, DoesNotExist
d86 1
a86 2
        super(conn, dMgr);
        setRecord(secMgr.getSectionForID(conn, documentID));
d92 1
a92 2
    public Section (Connection conn, DataManager dMgr, 
                    AccessControlList acl, Project project, 
d94 1
a94 2
        throws SQLException, DataSetException, DoesNotExist, UpdateException,
               JoistDatabaseException, ACLException
d96 1
a96 1
        super(conn, dMgr);
d111 2
a112 2
                             usrGrpMgr.getNobodyUserID(conn));
        secMgr.addSection(conn, projectID, parentID, name, descrip, 
d128 4
d137 1
a137 2
        throws SQLException, DataSetException, JoistDatabaseException,
               UpdateException, ACLException
d143 1
a143 1
            secMgr.moveToTop(conn, getID());
d151 1
a151 2
        throws SQLException, DataSetException, JoistDatabaseException,
               UpdateException, ACLException
d157 1
a157 1
            secMgr.approveSection(conn, getID(), acl.getUserID());
d165 2
a166 3
        throws SQLException, DataSetException, JoistDatabaseException,
               JoistException, DoesNotExist, ACLException, UpdateException, 
               IOException
d176 1
a176 1
        User disapprovingUser = User.getInstance(conn, dMgr, acl.getUserID());
d185 1
a185 1
        HelmEmailer emailer = new HelmEmailer(conn, dMgr);
d198 1
a198 1
     * @@exception DataSetException
d202 1
a202 1
        throws DataSetException, SQLException, ACLException, DoesNotExist
d206 1
a206 1
        secMgr.editSection(conn, getID(), parentID, name, description);
d216 1
a216 2
        throws SQLException, DataSetException, JoistDatabaseException,
               UpdateException, ACLException, DoesNotExist 
d220 1
a220 1
        secMgr.deleteSection(conn, getID());
d224 1
a224 1
    public String getID () throws DataSetException
d232 1
a232 1
    public String getName () throws DataSetException
d237 1
a237 1
    public String getDescription () throws DataSetException
d242 1
a242 1
    public String getProjectID() throws DataSetException
d248 1
a248 1
        throws DataSetException, SQLException, JoistDatabaseException
d251 1
a251 1
        String projectName = pMgr.getProjectName(conn, projectID);
d255 1
a255 1
    public String getParentID() throws DataSetException
d261 1
a261 2
        throws DataSetException, SQLException, JoistDatabaseException,
               DoesNotExist
d265 1
a265 1
        return User.getInstance(conn, dMgr, uid);
d269 1
a269 2
        throws DataSetException, SQLException, JoistDatabaseException,
               DoesNotExist
d273 1
a273 1
        return User.getInstance(conn, dMgr, uid);
d277 1
a277 3
          throws JoistDatabaseException, DataSetException, SQLException,
                 DoesNotExist
                 
d279 1
a279 1
          return !getApprovedBy().getID().equals(usrGrpMgr.getNobodyUserID(conn));
d284 1
a284 2
        throws DataSetException, SQLException, DoesNotExist, 
               JoistDatabaseException
d288 1
a288 2
        DataSet sectionSet = secMgr.getSubsections
                              (conn, getID());
d293 1
a293 1
	        sections.add(new Section(conn, dMgr, r));
d301 1
a301 2
        throws DataSetException, SQLException, DoesNotExist, 
               JoistDatabaseException
d305 1
a305 1
        DataSet documentSet = pdsMgr.getDocumentsForSection(conn, getID());
d311 1
a311 1
	        documents.add(new Document(conn, dMgr, documentID));
a314 1

@


1.3
log
@added disapprove method
@
text
@d139 15
@


1.3.2.1
log
@moved changed from HEAD for ProjectDocuments and ProjectDownloads
@
text
@a138 15
     * Moves section to top level.
     */
    public void moveToTop (AccessControlList acl)
        throws SQLException, DataSetException, JoistDatabaseException,
               UpdateException, ACLException
    {
        String action = "Project Document - Edit";
        if (acl.hasPermissionForProject(action, getProjectID()))
        {
            acl.assertPermissionForProject(action, getProjectID());
            secMgr.moveToTop(conn, getID());
        }
    }

    /**
d195 1
a195 2
        throws DataSetException, SQLException, ACLException, DoesNotExist,
               JoistDatabaseException
d197 2
a198 3
        String action = "Project Document - Edit";
        if (!acl.getUserID().equals(getSuggestedBy().getID()))
            acl.assertPermissionForProject(action, getProjectID());
a212 2
        if (!acl.getUserID().equals(getSuggestedBy().getID()))
            acl.assertPermissionForProject(action, getProjectID());
@


1.2
log
@added getParentID method
@
text
@d50 1
d56 1
d73 1
d127 2
d154 30
d208 1
a208 1
    public void delete (AccessControlList acl, String downloadID)
d212 1
a212 1
        String action = "Project Document - Approve";
d238 9
a246 1
        return rec.getValue(ProjectSectionManager.SECTION_PROJECT_ID).asString();
d271 9
@


1.1
log
@added files needed for ProjectDocuments
@
text
@d206 5
@

