head	1.21;
access;
symbols
	TIGRIS_1_1_0RC2:1.12.6.4
	TIGRIS_1_1_0RC1:1.12.6.4
	TIGRIS_1_1:1.12.6.4.0.2
	TIGRIS_1_0_8:1.12.6.4
	TIGRIS_1_0_8RC3:1.12.6.4
	TIGRIS_1_0_8RC2:1.12.6.4
	TIGRIS_1_0_8RC1:1.12.6.4
	TIGRIS_1_0_7:1.12.6.4
	TIGRIS_1_0_7RC3:1.12.6.4
	TIGRIS_1_0_7RC2:1.12.6.4
	TIGRIS_1_0_7RC1:1.12.6.4
	TIGRIS_1_0_6:1.12.6.4
	TIGRIS_1_0_6RC5:1.12.6.4
	TIGRIS_1_0_6RC4:1.12.6.4
	TIGRIS_1_0_6RC3:1.12.6.4
	TIGRIS_1_0_6RC2:1.12.6.4
	TIGRIS_1_0_6RC1:1.12.6.4
	TIGRIS_1_0_5:1.12.6.2
	TIGRIS_1_0_5RC6:1.12.6.2
	TIGRIS_1_0_5RC5:1.12.6.2
	TIGRIS_1_0_5RC4:1.12.6.2
	TIGRIS_1_0_5RC3:1.12.6.2
	TIGRIS_1_0_5RC2:1.12.6.2
	TIGRIS_1_0_5RC1:1.12.6.2
	TIGRIS_1_0_4:1.12.6.2
	TIGRIS_1_0_3:1.12.6.2
	TIGRIS_1_0_2:1.12.6.2
	TIGRIS_1_0_1:1.12
	TIGRIS_1_0:1.12.0.6
	TIGRIS_1_0_0:1.12
	TIGRIS_1_0_0_RC1:1.12.0.2
	dlr:1.1.1
	HELM_PEER_PORT_BRANCH:1.1.1.1;
locks; strict;
comment	@# @;


1.21
date	2001.07.16.02.23.42;	author jrobbins;	state dead;
branches;
next	1.20;

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

1.19
date	2001.06.01.00.32.53;	author elicia;	state Exp;
branches;
next	1.18;

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

1.17
date	2001.05.31.19.12.27;	author elicia;	state Exp;
branches;
next	1.16;

1.16
date	2001.05.25.16.57.15;	author leonardr;	state Exp;
branches;
next	1.15;

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

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

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

1.12
date	2001.03.08.03.30.42;	author dlr;	state Exp;
branches
	1.12.6.1;
next	1.11;

1.11
date	2001.03.07.01.53.22;	author lucas;	state Exp;
branches;
next	1.10;

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

1.9
date	2001.02.27.02.31.44;	author dlr;	state Exp;
branches;
next	1.8;

1.8
date	2001.02.27.02.27.32;	author elicia;	state Exp;
branches;
next	1.7;

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

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

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

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

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

1.2
date	2001.02.21.03.02.22;	author edk;	state Exp;
branches;
next	1.1;

1.1
date	2001.01.28.01.18.22;	author dlr;	state dead;
branches
	1.1.1.1
	1.1.2.1;
next	;

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

1.1.2.1
date	2001.01.28.01.18.22;	author dlr;	state Exp;
branches;
next	1.1.2.2;

1.1.2.2
date	2001.02.12.23.56.01;	author elicia;	state Exp;
branches;
next	1.1.2.3;

1.1.2.3
date	2001.02.13.01.14.52;	author elicia;	state Exp;
branches;
next	1.1.2.4;

1.1.2.4
date	2001.02.13.22.45.20;	author elicia;	state Exp;
branches;
next	1.1.2.5;

1.1.2.5
date	2001.02.16.03.01.27;	author dlr;	state Exp;
branches;
next	1.1.2.6;

1.1.2.6
date	2001.02.16.20.04.21;	author elicia;	state Exp;
branches;
next	1.1.2.7;

1.1.2.7
date	2001.02.16.20.31.15;	author dlr;	state Exp;
branches;
next	1.1.2.8;

1.1.2.8
date	2001.02.17.00.01.24;	author elicia;	state Exp;
branches;
next	1.1.2.9;

1.1.2.9
date	2001.02.17.00.51.32;	author elicia;	state Exp;
branches;
next	1.1.2.10;

1.1.2.10
date	2001.02.17.20.33.46;	author elicia;	state Exp;
branches;
next	1.1.2.11;

1.1.2.11
date	2001.02.18.00.51.20;	author elicia;	state Exp;
branches;
next	1.1.2.12;

1.1.2.12
date	2001.02.20.03.53.25;	author dlr;	state Exp;
branches;
next	1.1.2.13;

1.1.2.13
date	2001.02.20.03.55.16;	author dlr;	state Exp;
branches;
next	;

1.12.6.1
date	2001.04.24.22.00.08;	author dlr;	state Exp;
branches;
next	1.12.6.2;

1.12.6.2
date	2001.04.24.22.04.36;	author dlr;	state Exp;
branches;
next	1.12.6.3;

1.12.6.3
date	2001.06.07.02.31.36;	author edk;	state Exp;
branches;
next	1.12.6.4;

1.12.6.4
date	2001.06.07.03.08.39;	author dlr;	state Exp;
branches;
next	;


desc
@@


1.21
log
@factoring project documents out to project nidaba.tigris.org
@
text
@package org.tigris.helm.om;

import java.util.*;

import org.apache.velocity.context.Context;

import org.apache.turbine.om.*;
import org.apache.turbine.om.peer.BasePeer;
import org.apache.turbine.util.db.Criteria;
import org.apache.turbine.util.ObjectUtils;
import org.apache.turbine.util.StringUtils;
import org.apache.turbine.util.ParameterParser;
import org.apache.turbine.util.Log;
import org.apache.turbine.util.TurbineException;
import org.apache.turbine.util.TurbineException;
import org.apache.turbine.util.db.pool.DBConnection;
import org.apache.turbine.services.velocity.TurbineVelocity;

import org.tigris.helm.AlreadyExists;
import org.tigris.helm.DoesNotExist;
import org.tigris.helm.om.profile.*;
import org.tigris.helm.security.*;
import org.tigris.helm.tool.*;

/** 
 * Documentation section business object.
 *
 * @@author <a href="mailto:elicia@@collab.net">Elicia David</a>
 * @@author <a href="mailto:dlr@@collab.net">Daniel Rall</a>
 */
public class ProjectSection extends BaseProjectSection
    implements ProjectArtifact
{
    /**
     * The section approval permission.
     */
    private static final String APPROVE_PERM = "Project Document - Approve";

    /**
     * The name of the template used to create the body of the section 
     * creation announcement email.
     */
    private static final String CREATED_TMPL = "ProjectCreated.vm";

    /**
     * The name of the template used to create the body of the section 
     * disapproval email.
     */
    private static final String DISAPPROVE_TMPL = 
        TemplateTool.getPathToMessageTemplate("ProjectSectionDisapprove.vm");

    /**
     * A mutex for the addition of new project sections.
     * <p>
     * TODO: Handle this via database table locking.
     */
    private static Object addLock = new Object();

    public String getParentID()
    {
        return getParentId().toString();
    }

    public List getParentSections()
        throws Exception
    {
        ArrayList temp = new ArrayList();
        ArrayList parentList = new ArrayList();
        ProjectSection section = new ProjectSection();
        String parentID = getParentID();
        while (!parentID.equals("0"))
        {
            section = (ProjectSection)ProjectSectionPeer
                                                     .getInstance(parentID);
            temp.add(section); 
            parentID = section.getParentID();
        }
        for (int i = temp.size()-1; i >=0; i--)
        {
            section = (ProjectSection)temp.get(i); 
            parentList.add(section);
        }

        return parentList;
    }

    /**
     * Determines whether a section has been approved
     */
    public boolean isApproved()
        throws Exception
    {
        return !getApprovedBy().equals(UserPeer.getNobodyUser().getUserId());
    }

    /**
     * Gets user that proposed the document.
     */
    public final User getProposedByUser()
        throws Exception
    {
        return getUserRelatedByProposedBy();
    }

    /**
     * Returns all subsections associated with this section.
     */
    public List getSubsections()
        throws Exception
    {        
        Criteria base = new Criteria()
            .add(ProjectSectionPeer.PARENT_ID, getID());
        base.add(ProjectSectionPeer.PROJECT_ID, getProjectId());
        return ProjectSectionPeer.doSelect(base);
    }

    /**
     * Returns all documents associated with this section.
     */
    public List getDocuments()
        throws Exception
    {        
        Criteria base = new Criteria()
            .addJoin(ProjectDocumentSectionPeer.DOCUMENT_ID, 
                     ProjectDocumentPeer.DOCUMENT_ID)
            .add(ProjectDocumentSectionPeer.SECTION_ID, 
                     getSectionId());
        base.add(ProjectDocumentPeer.PROJECT_ID, getProjectId());
        return ProjectDocumentPeer.doSelect(base);
    }

    /**
     * Returns all documents associated with this section which are viewable
     * by the ACL supplied.
     */
    public List getDocuments(AccessControlList acl)
        throws Exception
    {        
        List documents = getDocuments();
        List toRemove = new ArrayList();
        Iterator i = documents.iterator();
        while (i.hasNext())
        {
            ProjectDocument doc = (ProjectDocument) i.next();
            if (!doc.isViewableBy(acl))
            {
                toRemove.add(doc);
            }
        }
        documents.removeAll(toRemove);
        return documents;
    }

    /**
     * Adds a project section.
     *
     * @@param acl               The ACL of the user.
     * @@param project           Project in which the section resides.
     * @@param name              Name of the section.
     * @@param parentID          The id of the parent section.
     * @@param description       A description of the section.
     * @@return                  The database record for the section.
     *
     * @@exception AlreadyExists A project in this domain with this name exists.
     */
    public static ProjectSection add
        (AccessControlList acl, Project project, String parentID,
         String name, String description)
        throws ACLException, AlreadyExists, Exception
    {
        ProjectSection section = null;
        synchronized (addLock)
        {
            section = new ProjectSection();
            section.setProject(project);
            section.assertAddPermission(acl);
            section.setName(name);
            section.setDescription(description);
            section.setParentId(new NumberKey(parentID));
            User proposedBy = acl.getUser();
            section.setUserRelatedByProposedBy(proposedBy);
            User approvedBy = (acl.hasPermission(APPROVE_PERM, project) ?
                               proposedBy : 
                               UserPeer.getNobodyUser());
            section.setUserRelatedByApprovedBy(approvedBy);

            // Add the project to the database.            
            section.save();
        }

        //Approve the section, if user has the right permission.
        if (acl.hasPermission(APPROVE_PERM, project))
        {
            section.approve(acl);
        }
        else
        {
            /*
            // TODO
            //Send a message to the project admin(s) informing them of
            //the newly requested section.
            User createdUser = acl.getUser();
            String subject = "New unapproved section: ";
            WebMacroService wmSrvc = (WebMacroService)
            TurbineServices.getInstance().getService(WebMacroService.SERVICE_NAME);
            ctx.put("section", section);
            ctx.put("createdUser", createdUser);
            String body = TemplateInterpolator.interpolate
                (CREATED_TMPL, ctx, project.getClass());
            HelmEmailer emailer = new HelmEmailer();
            try 
            {
                emailer.messageUsersWithDomainOwnership
                    (domain, subject, body);
            }
            catch (Exception e)
            {
                Log.error
                    ("Unable to mail domain owners about new project.", e);
            }
            */
        }

        return section;
    }

    /**
     * Updates a section.
     *
     * @@param acl           The access control list of the current user.
     * @@param description   A description of the section.
     * @@param approvedBy    The database key of the approving user.
     * @@param isPrivate     Whether the section is private.
     *
     * @@exception ACLException
     */
    public void edit (AccessControlList acl, String parentID, 
                      String name, String description)
        throws ACLException, Exception
    {
        assertEditPermission(acl);

        if (parentID != null) setParentId(new NumberKey(parentID));
        if (name != null) setName(name);
        if (description != null) setDescription(description);
        save();
    }

    /**
     * Approves the section in the name of the approving user..
     *
     * @@param acl The ACL of the user approving the section.
     *
     * @@exception ACLException The ACL does not have approval permission.
     * @@exception DoesNotExist If the specified project is invalid.
     * @@exception Exception    If a database error occurs.
     */
    public void approve(AccessControlList acl)
        throws ACLException, DoesNotExist, Exception
    {
        if (acl != null) {
            acl.assertPermission(APPROVE_PERM, getProject());
                                          
            setApprovedBy(acl.getUser().getUserId());
            save();
        }
    }

    /**
     * Deletes an unapproved section, sending email to the owners
     * about it.  
     */
    public void disapprove(AccessControlList acl, String rationale)
        throws ACLException, DoesNotExist, Exception
    {
        acl.assertPermission(APPROVE_PERM, getProject());
        delete(acl);

        String subject = "Document section for Project " +
            getProject().getName() + " disapproved.";
        Context ctx = TurbineVelocity.getContext();
        ctx.put("disapprovingUser", acl.getUser());
        ctx.put("section", this);
        ctx.put("rationale", rationale);
        String body = TurbineVelocity.handleRequest(ctx, DISAPPROVE_TMPL);
        HelmEmailer emailer = new HelmEmailer();
        emailer.sendEmail(getProposedByUser().getEmail(), subject, body);
    }
    
    /**
     * Deletes the section.
     *
     * @@param acl The ACL of the user deleting the section.
     *
     * @@exception ACLException The ACL does not have approval permission.
     * @@exception Exception    If a database error occurs.
     */
    public void delete(AccessControlList acl)
        throws ACLException, Exception
    {
        if (acl == null) 
        {
            throw new Exception("No ACL provided.");
        }
        assertDeletePermission(acl);
        delete();
    }

    /**
     * Deletes the section without no ACL check.
     */
    private void delete()
        throws Exception
    {
        Criteria c = new Criteria()
            .add(ProjectSectionPeer.SECTION_ID, getSectionId());
        ProjectSectionPeer.doDelete(c);
    }

    //
    // Permission methods
    //

    /**
     * Asserts addition and/or approval permission for this section.
     *
     * @@param acl The ACL to check for permission.
     */
    public void assertAddPermission(AccessControlList acl)
        throws ACLException, Exception
    {
        acl.assertPermission("Project Document - Suggest", getProject());
    }

    /**
     * Asserts edit permission for this section.
     *
     * @@param acl The ACL to check for permission.
     */
    public void assertEditPermission(AccessControlList acl)
        throws ACLException, Exception
    {
        if (getProposedBy().equals(acl.getUser().getUserId())) {
            acl.assertPermission("Project Document - View", getProject());
        }
        else {
            acl.assertPermission("Project Document - Edit", getProject());
        }
    }

    /**
     * Asserts deletion and/or disapproval permission for this section.
     *
     * @@param acl The ACL to check for permission.
     */
    public void assertDeletePermission(AccessControlList acl)
        throws ACLException, Exception
    {
        if (getProposedBy().equals(acl.getUser().getUserId())) {
            acl.assertPermission("Project Document - View", getProject());
        }
        else {
            acl.assertPermission("Project Document - Delete", getProject());
        }
    }

    /**
     * Returns true if the given ACL can see this section.
     */
    public boolean isViewableBy(AccessControlList acl)
        throws Exception
    {
        return (acl.hasPermission(requiredViewPermission(acl), getProject()));
    }

    /**
     * Returns the appropriate permission needed 
     */
    public String requiredViewPermission(AccessControlList acl)
        throws Exception
    {
        String permission = "Project Document - View";
        if ((!isApproved()) && (getProposedBy() != acl.getUser().getUserId()))
        {
            permission = "Project Document - Approve";
        }
        return permission;
    }

    /**
     * @@see {@@link org.tigris.helm.om.ProjectArtifact#isPublic}
     */
    public final boolean isPublic()
    {
        return true;
    }
}
@


1.20
log
@Forward porting Ed's addition of a ACL-filtered document retrieval
method from the 1.0 branch.  This method should be used in templates.
@
text
@@


1.19
log
@added methods to return the date fields in shortened, String form
@
text
@d133 22
@


1.18
log
@Implement declared interface.
@
text
@d337 1
a337 1
        if (getProposedBy() == acl.getUser().getUserId()) {
@


1.17
log
@Many changes to the Project Documents component.  It is now replacing ProjectDownloads (will remove it from cvs after a while). Took out the "type" variable so that a Document can have a file upload attachment and/or a remote URL and/or pasted text, instead of only one of the three. Added fields for modified by and modified date. Also added isPublic field for file uploads, and a status field.

Document file uploads are now being saved in helm/data/fileserv/documents/[document_id]. Refactored htAccess file code to reflect that and to fix other bugs.
Dropped $type parameter from URL arguments."

UI has changed: ProjectDocumentList now has a 2-pane UI with a folder tree on the left pane and the document list on the right.  When in the list you have a "root folder" that is the root of the tree.  Folders can now be infinitely nested instead of just two levels deep.  You add a document or subfolder directly to the root section.
@
text
@d367 8
@


1.16
log
@.wm is now .vm
@
text
@d64 23
@


1.15
log
@Ported Helm from WebMacro to Velocity.
@
text
@d43 1
a43 1
    private static final String CREATED_TMPL = "ProjectCreated.wm";
d50 1
a50 1
        TemplateTool.getPathToMessageTemplate("ProjectSectionDisapprove.wm");
@


1.14
log
@Corrected header JavaDoc.
@
text
@d5 1
a5 1
import org.webmacro.servlet.WebContext;
d14 2
d17 1
a17 1
import org.apache.turbine.services.webmacro.TurbineWebMacro;
d236 1
a236 1
        WebContext ctx = TurbineWebMacro.getContext();
d240 1
a240 1
        String body = TurbineWebMacro.handleRequest(ctx, DISAPPROVE_TMPL);
@


1.13
log
@Cleaned up and implemented ProjectArtifact.
@
text
@d24 1
a24 1
 * Project business object.
@


1.12
log
@Pushed getID() method into base class as a final method.
@
text
@a6 4
import org.tigris.helm.AlreadyExists;
import org.tigris.helm.DoesNotExist;
import org.tigris.helm.tool.*;

a8 2
import org.tigris.helm.om.*;import org.tigris.helm.om.profile.*;
import org.tigris.helm.security.*;
d17 6
d24 5
a28 5
    The skeleton for this class was autogenerated by Torque on: Fri Jan 26 17:54:39 PST 2001. 
    You should add additional methods to this class to meet the
    application requirements.  This class will only be generated as
    long as the firstTime file does not exist in the build directory.
*/
d30 1
a31 1

a79 1

a106 1

a179 1

a341 1

@


1.12.6.1
log
@A ProjectSection is also an artifact.
@
text
@d24 5
a28 5
 * Project business object.
 *
 * @@author <a href="mailto:elicia@@collab.net">Elicia David</a>
 * @@author <a href="mailto:dlr@@collab.net">Daniel Rall</a>
 */
a29 1
    implements ProjectArtifact
d31 1
d80 1
d108 1
d345 1
@


1.12.6.2
log
@Cleaned up imports.
@
text
@d7 4
d13 2
a21 6

import org.tigris.helm.AlreadyExists;
import org.tigris.helm.DoesNotExist;
import org.tigris.helm.om.profile.*;
import org.tigris.helm.security.*;
import org.tigris.helm.tool.*;
@


1.12.6.3
log
@port dlr's changes to support private documents and sections
@
text
@a107 23
     * Returns all documents associated with this section which are viewable
     * by the ACL supplied.
     */
    public List getDocuments(AccessControlList acl)
        throws Exception
    {        
        List documents = getDocuments();
        List toRemove = new ArrayList();
        Iterator i = documents.iterator();
        while (i.hasNext())
        {
            ProjectDocument pd = (ProjectDocument)i.next();
            if (!pd.isViewableBy(acl))
            {
                Log.error("removing project document " + pd);
                toRemove.add(pd);
            }
        }
        documents.removeAll(toRemove);
        return documents;
    }

    /**
@


1.12.6.4
log
@Removed extraneous error logging.
@
text
@d122 1
@


1.11
log
@Corrected regex madness for Torque upgrade.  -dlr
@
text
@a56 10

    //
    // Accessor methods for particular project sections.
    //

    public String getID()
    {
        return getPrimaryKey().toString();
    }

@


1.10
log
@changed equality test for getProposedBy to use .equals instead of =
@
text
@d13 1
a13 3
import org.tigris.helm.om.peer.*;
import org.tigris.helm.om.base.*;
import org.tigris.helm.om.profile.*;
@


1.9
log
@Don't send the disapproval email until the project section has actually been
disapproved.
@
text
@d311 1
a311 1
        if (getProposedBy() == acl.getUser().getUserId()) {
@


1.8
log
@fixed error in disapproval method (putting wrong object in context for disapproval email template)
@
text
@d245 1
d247 2
a248 2
        String subject = "Document section for Project " + getProject().getName() +
            " disapproved.";
a255 2

        delete(acl);
@


1.7
log
@updated disapprove method to send emails
@
text
@d250 1
a250 1
        ctx.put("download", this);
@


1.6
log
@Changes to keep in step with the latest Torque-generated code.
@
text
@d23 1
d49 2
a50 1
    private static final String DISAPPROVE_TMPL = "ProjectDisapprove.wm";
d80 10
a89 1
        return getApprovedBy() != UserPeer.getNobodyUser().getUserId();
d241 1
a241 1
    public void disapprove(AccessControlList acl)
d244 12
a256 19
        /*
        //Send email to the owners.
        User disapproving = acl.getUser();
        String subject = "Section " + getName() + " disapproved.";
        WebMacroService wmSrvc = (WebMacroService)
            TurbineServices.getInstance().getService(WebMacroService.SERVICE_NAME);
        ctx.put("section", this);
        ctx.put("disapprovingUser", disapproving);
        String body = TemplateInterpolator.interpolate(DISAPPROVE_TMPL, ctx,
                                                       getClass());
        HelmEmailer emailer = new HelmEmailer();
         try {
             emailer.messageUsersWithProjectOwnership(getProject(), subject, body);
         }
         catch (Exception e) {
             Log.error
                 ("Unable to mail project owner about section disapproval", e);
         }
         */
@


1.5
log
@Sync'd with latest Turbine changes.  Mostly this consists of the use of the new SimpleKey class to handle primary database keys.
@
text
@d135 1
a135 1
            section.setParentId(new SimpleKey(parentID));
d200 1
a200 1
        if (parentID != null) setParentId(new SimpleKey(parentID));
@


1.4
log
@Removed getProject() duplicated in super class.
@
text
@d69 1
a69 1
        return Integer.toString(getParentId());
d131 1
a131 1
            section.setProjectId(project.getPrimaryKeyAsInt());
d135 7
a141 7
            section.setParentId(Integer.parseInt(parentID));
            int proposedBy = acl.getUser().getUserId();
            section.setProposedBy(proposedBy);
            int approvedBy = (acl.hasPermission(APPROVE_PERM, project) ?
                              proposedBy : 
                              UserPeer.getNobodyUser().getUserId());
            section.setApprovedBy(approvedBy);
d200 1
a200 1
        if (parentID != null) setParentId(Integer.parseInt(parentID));
@


1.3
log
@Now using TurbineWebMacroService instead of TemplateInterpolator.
@
text
@d11 1
a11 1
import org.apache.turbine.om.BaseObject;
d64 1
a64 1
        return (String)getPrimaryKey();
a69 6
    }

    public Project getProject()
         throws Exception
    {
        return ProjectPeer.getInstance(Integer.toString(getProjectId()));
@


1.2
log
@adding files from the branch to the head
@
text
@d5 1
a5 1
import org.webmacro.engine.BuildContext;
d166 2
a167 1
            BuildContext ctx = TemplateInterpolator.createContext();
d244 2
a245 1
        BuildContext ctx = TemplateInterpolator.createContext();
@


1.1
log
@file ProjectSection.java was initially added on branch HELM_PEER_PORT_BRANCH.
@
text
@d1 359
@


1.1.1.1
log
@Replacing the HEAD with the HELM_PEER_PORT_BRANCH.
@
text
@a0 359
package org.tigris.helm.om;

import java.util.*;

import org.webmacro.engine.BuildContext;

import org.tigris.helm.AlreadyExists;
import org.tigris.helm.DoesNotExist;
import org.tigris.helm.tool.*;

import org.apache.turbine.om.BaseObject;
import org.apache.turbine.om.peer.BasePeer;
import org.tigris.helm.om.peer.*;
import org.tigris.helm.om.base.*;
import org.tigris.helm.om.profile.*;
import org.tigris.helm.security.*;
import org.apache.turbine.util.db.Criteria;
import org.apache.turbine.util.ObjectUtils;
import org.apache.turbine.util.StringUtils;
import org.apache.turbine.util.ParameterParser;
import org.apache.turbine.util.Log;
import org.apache.turbine.util.db.pool.DBConnection;

/** 
    The skeleton for this class was autogenerated by Torque on: Fri Jan 26 17:54:39 PST 2001. 
    You should add additional methods to this class to meet the
    application requirements.  This class will only be generated as
    long as the firstTime file does not exist in the build directory.
*/
public class ProjectSection extends BaseProjectSection
{

    /**
     * The section approval permission.
     */
    private static final String APPROVE_PERM = "Project Document - Approve";

    /**
     * The name of the template used to create the body of the section 
     * creation announcement email.
     */
    private static final String CREATED_TMPL = "ProjectCreated.wm";

    /**
     * The name of the template used to create the body of the section 
     * disapproval email.
     */
    private static final String DISAPPROVE_TMPL = "ProjectDisapprove.wm";

    /**
     * A mutex for the addition of new project sections.
     * <p>
     * TODO: Handle this via database table locking.
     */
    private static Object addLock = new Object();


    //
    // Accessor methods for particular project sections.
    //

    public String getID()
    {
        return (String)getPrimaryKey();
    }

    public String getParentID()
    {
        return Integer.toString(getParentId());
    }

    public Project getProject()
         throws Exception
    {
        return ProjectPeer.getInstance(Integer.toString(getProjectId()));
    }

    /**
     * Determines whether a section has been approved
     */
    public boolean isApproved()
        throws Exception
    {
        return getApprovedBy() != UserPeer.getNobodyUser().getUserId();
    }


    /**
     * Returns all subsections associated with this section.
     */
    public List getSubsections()
        throws Exception
    {        
        Criteria base = new Criteria()
            .add(ProjectSectionPeer.PARENT_ID, getID());
        base.add(ProjectSectionPeer.PROJECT_ID, getProjectId());
        return ProjectSectionPeer.doSelect(base);
    }

    /**
     * Returns all documents associated with this section.
     */
    public List getDocuments()
        throws Exception
    {        
        Criteria base = new Criteria()
            .addJoin(ProjectDocumentSectionPeer.DOCUMENT_ID, 
                     ProjectDocumentPeer.DOCUMENT_ID)
            .add(ProjectDocumentSectionPeer.SECTION_ID, 
                     getSectionId());
        base.add(ProjectDocumentPeer.PROJECT_ID, getProjectId());
        return ProjectDocumentPeer.doSelect(base);
    }


    /**
     * Adds a project section.
     *
     * @@param acl               The ACL of the user.
     * @@param project           Project in which the section resides.
     * @@param name              Name of the section.
     * @@param parentID          The id of the parent section.
     * @@param description       A description of the section.
     * @@return                  The database record for the section.
     *
     * @@exception AlreadyExists A project in this domain with this name exists.
     */
    public static ProjectSection add
        (AccessControlList acl, Project project, String parentID,
         String name, String description)
        throws ACLException, AlreadyExists, Exception
    {
        ProjectSection section = null;
        synchronized (addLock)
        {
            section = new ProjectSection();
            section.setProjectId(project.getPrimaryKeyAsInt());
            section.assertAddPermission(acl);
            section.setName(name);
            section.setDescription(description);
            section.setParentId(Integer.parseInt(parentID));
            int proposedBy = acl.getUser().getUserId();
            section.setProposedBy(proposedBy);
            int approvedBy = (acl.hasPermission(APPROVE_PERM, project) ?
                              proposedBy : 
                              UserPeer.getNobodyUser().getUserId());
            section.setApprovedBy(approvedBy);

            // Add the project to the database.            
            section.save();
        }

        //Approve the section, if user has the right permission.
        if (acl.hasPermission(APPROVE_PERM, project))
        {
            section.approve(acl);
        }
        else
        {
            /*
            // TODO
            //Send a message to the project admin(s) informing them of
            //the newly requested section.
            User createdUser = acl.getUser();
            String subject = "New unapproved section: ";
            BuildContext ctx = TemplateInterpolator.createContext();
            ctx.put("section", section);
            ctx.put("createdUser", createdUser);
            String body = TemplateInterpolator.interpolate
                (CREATED_TMPL, ctx, project.getClass());
            HelmEmailer emailer = new HelmEmailer();
            try 
            {
                emailer.messageUsersWithDomainOwnership
                    (domain, subject, body);
            }
            catch (Exception e)
            {
                Log.error
                    ("Unable to mail domain owners about new project.", e);
            }
            */
        }

        return section;
    }


    /**
     * Updates a section.
     *
     * @@param acl           The access control list of the current user.
     * @@param description   A description of the section.
     * @@param approvedBy    The database key of the approving user.
     * @@param isPrivate     Whether the section is private.
     *
     * @@exception ACLException
     */
    public void edit (AccessControlList acl, String parentID, 
                      String name, String description)
        throws ACLException, Exception
    {
        assertEditPermission(acl);

        if (parentID != null) setParentId(Integer.parseInt(parentID));
        if (name != null) setName(name);
        if (description != null) setDescription(description);
        save();
    }

    /**
     * Approves the section in the name of the approving user..
     *
     * @@param acl The ACL of the user approving the section.
     *
     * @@exception ACLException The ACL does not have approval permission.
     * @@exception DoesNotExist If the specified project is invalid.
     * @@exception Exception    If a database error occurs.
     */
    public void approve(AccessControlList acl)
        throws ACLException, DoesNotExist, Exception
    {
        if (acl != null) {
            acl.assertPermission(APPROVE_PERM, getProject());
                                          
            setApprovedBy(acl.getUser().getUserId());
            save();
        }
    }

    /**
     * Deletes an unapproved section, sending email to the owners
     * about it.  
     */
    public void disapprove(AccessControlList acl)
        throws ACLException, DoesNotExist, Exception
    {
        delete(acl);
        /*
        //Send email to the owners.
        User disapproving = acl.getUser();
        String subject = "Section " + getName() + " disapproved.";
        BuildContext ctx = TemplateInterpolator.createContext();
        ctx.put("section", this);
        ctx.put("disapprovingUser", disapproving);
        String body = TemplateInterpolator.interpolate(DISAPPROVE_TMPL, ctx,
                                                       getClass());
        HelmEmailer emailer = new HelmEmailer();
         try {
             emailer.messageUsersWithProjectOwnership(getProject(), subject, body);
         }
         catch (Exception e) {
             Log.error
                 ("Unable to mail project owner about section disapproval", e);
         }
         */
    }
    
    /**
     * Deletes the section.
     *
     * @@param acl The ACL of the user deleting the section.
     *
     * @@exception ACLException The ACL does not have approval permission.
     * @@exception Exception    If a database error occurs.
     */
    public void delete(AccessControlList acl)
        throws ACLException, Exception
    {
        if (acl == null) 
        {
            throw new Exception("No ACL provided.");
        }
        assertDeletePermission(acl);
        delete();
    }

    /**
     * Deletes the section without no ACL check.
     */
    private void delete()
        throws Exception
    {
        Criteria c = new Criteria()
            .add(ProjectSectionPeer.SECTION_ID, getSectionId());
        ProjectSectionPeer.doDelete(c);
    }

    //
    // Permission methods
    //

    /**
     * Asserts addition and/or approval permission for this section.
     *
     * @@param acl The ACL to check for permission.
     */
    public void assertAddPermission(AccessControlList acl)
        throws ACLException, Exception
    {
        acl.assertPermission("Project Document - Suggest", getProject());
    }

    /**
     * Asserts edit permission for this section.
     *
     * @@param acl The ACL to check for permission.
     */
    public void assertEditPermission(AccessControlList acl)
        throws ACLException, Exception
    {
        if (getProposedBy() == acl.getUser().getUserId()) {
            acl.assertPermission("Project Document - View", getProject());
        }
        else {
            acl.assertPermission("Project Document - Edit", getProject());
        }
    }

    /**
     * Asserts deletion and/or disapproval permission for this section.
     *
     * @@param acl The ACL to check for permission.
     */
    public void assertDeletePermission(AccessControlList acl)
        throws ACLException, Exception
    {
        if (getProposedBy() == acl.getUser().getUserId()) {
            acl.assertPermission("Project Document - View", getProject());
        }
        else {
            acl.assertPermission("Project Document - Delete", getProject());
        }
    }

    /**
     * Returns true if the given ACL can see this section.
     */
    public boolean isViewableBy(AccessControlList acl)
        throws Exception
    {
        return (acl.hasPermission(requiredViewPermission(acl), getProject()));
    }

    /**
     * Returns the appropriate permission needed 
     */
    public String requiredViewPermission(AccessControlList acl)
        throws Exception
    {
        String permission = "Project Document - View";
        if ((!isApproved()) && (getProposedBy() != acl.getUser().getUserId()))
        {
            permission = "Project Document - Approve";
        }
        return permission;
    }

}
@


1.1.2.1
log
@Classes ported to the Turbine Peer system. -dlr and leonardr
@
text
@a0 23
package org.tigris.helm.om;

import java.util.*;

import org.apache.turbine.om.BaseObject;
import org.apache.turbine.om.peer.BasePeer;
import org.tigris.helm.om.peer.*;
import org.apache.turbine.util.db.Criteria;
import org.apache.turbine.util.ObjectUtils;
import org.apache.turbine.util.StringUtils;
import org.apache.turbine.util.ParameterParser;
import org.apache.turbine.util.Log;
import org.apache.turbine.util.db.pool.DBConnection;

/** 
    The skeleton for this class was autogenerated by Torque on: Fri Jan 26 17:54:39 PST 2001. 
    You should add additional methods to this class to meet the
    application requirements.  This class will only be generated as
    long as the firstTime file does not exist in the build directory.
*/
public class ProjectSection extends BaseProjectSection
{
}
@


1.1.2.2
log
@added add, approve, and auth methods
@
text
@a4 5
import org.webmacro.engine.BuildContext;

import org.tigris.helm.AlreadyExists;
import org.tigris.helm.DoesNotExist;

a7 2
import org.tigris.helm.om.profile.*;
import org.tigris.helm.security.*;
a22 168

    /**
     * A mutex for the addition of new project sections.
     * <p>
     * TODO: Handle this via database table locking.
     */
    private static Object addLock = new Object();


    //
    // Accessor methods for particular project sections.
    //

    public String getID()
    {
        return (String)getPrimaryKey();
    }

    public Project getProject()
         throws Exception
    {
        return ProjectPeer.getInstance(Integer.toString(getProjectId()));
    }

    /**
     * Determines whether a section has been approved
     */
    public boolean isApproved()
        throws Exception
    {
        return getApprovedBy() != UserPeer.getNobodyUser().getUserId();
    }

    /**
     * Adds a project section.
     *
     * @@param acl               The ACL of the user.
     * @@param project           Project in which the section resides.
     * @@param name              Name of the section.
     * @@param parentID          The id of the parent section.
     * @@param description       A description of the section.
     * @@return                  The database record for the section.
     *
     * @@exception AlreadyExists A project in this domain with this name exists.
     */
    public static ProjectSection add
        (AccessControlList acl, Project project, String parentID,
         String name, String description)
        throws ACLException, AlreadyExists, Exception
    {

        ProjectSection section = null;
        synchronized (addLock)
        {
            section = new ProjectSection();
            section.setProjectId(project.getPrimaryKeyAsInt());
            section.setName(name);
            section.setDescription(description);
            section.assertAddPermission(acl);

            // Add the project to the database.            
            section.save();
        }

        //Approve the section, if user has the right permission.
        if (acl.hasPermission("Project Document - Approve", project))
        {
            section.approve(acl);
        }
            else
            {
                /*
                //Send a message to the project admin(s) informing them of
                //the newly requested section.
                User createdUser = acl.getUser();
                String subject = "New unapproved section: ";
                BuildContext ctx = TemplateInterpolator.createContext();
                ctx.put("section", section);
                ctx.put("createdUser", createdUser);
                String body = TemplateInterpolator.interpolate
                    (CREATED_TMPL, ctx, project.getClass());
                HelmEmailer emailer = new HelmEmailer();
                try 
                {
                    emailer.messageUsersWithDomainOwnership
                        (domain, subject, body);
                }
                catch (Exception e)
                {
                    Log.error
                        ("Unable to mail domain owners about new project.", e);
                }
                */
            }

        return section;
    }


    /**
     * Approves the section in the name of the approving user..
     *
     * @@param acl The ACL of the user approving the project.
     *
     * @@exception ACLException The ACL does not have approval permission.
     * @@exception DoesNotExist If the specified project is invalid.
     * @@exception Exception    If a database error occurs.
     */
    public void approve(AccessControlList acl)
        throws ACLException, DoesNotExist, Exception
    {
        if (acl != null) {
            acl.assertPermission("Project Document - Approve", getProject());
                                          
            setApprovedBy(acl.getUser().getUserId());
            save();
        }
    }


    /**
     * Asserts addition and/or approval permission for this section.
     *
     * @@param acl The ACL to check for permission.
     */
    public void assertAddPermission(AccessControlList acl)
        throws ACLException, Exception
    {
        Project project = getProject();
        if (!acl.hasPermission("Project Document - Suggest", project) &&
            !acl.hasPermission("Project Document - Approve", project))
        {
                throw new ACLException(acl, "Project Document - Suggest or Project Document - Approve", "Project  " + project.getName(), null);
        }
    }

    public void assertEditPermission(AccessControlList acl)
        throws ACLException, Exception
    {
        acl.assertPermission("Project Document - Edit", getProject());
    }

    /**
     * Asserts deletion and/or disapproval permission for this project.
     *
     * @@param acl The ACL to check for permission.
     */
    public void assertDeletePermission(AccessControlList acl)
        throws ACLException, Exception
    {
        acl.assertPermission("Project Document - Delete", getProject());
    }

    public boolean isViewableBy(AccessControlList acl)
        throws Exception
    {
        boolean ok = true;
        if (!acl.hasPermission("Project Document - View", getProject())) {
            ok = false;
        }
        else if (!isApproved()) {
            if (!acl.hasPermission("Project Document - Approve", 
                                    getProject())) {
                ok = false;       
            }
        }
        return ok;
    }
@


1.1.2.3
log
@added delete and edit methods
@
text
@a129 23
     * Updates a section.
     *
     * @@param acl           The access control list of the current user.
     * @@param description   A description of the news item.
     * @@param approvedBy    The database key of the approving user.
     * @@param isPrivate     Whether the news item is private.
     *
     * @@exception SQLException
     * @@exception DataSetException
     */
    public void edit (AccessControlList acl, String parentID, 
                      String name, String description)
        throws ACLException, Exception
    {
        assertEditPermission(acl);

        if (parentID != null) setParentId(Integer.parseInt(parentID));
        if (name != null) setName(name);
        if (description != null) setDescription(description);
        save();
    }

    /**
a148 28
    /**
     * Deletes the section.
     *
     * @@param acl The ACL of the user deleting the section.
     *
     * @@exception ACLException The ACL does not have approval permission.
     * @@exception Exception    If a database error occurs.
     */
    public void delete(AccessControlList acl)
        throws ACLException, Exception
    {
        if (acl == null) 
        {
            throw new Exception("No ACL provided.");
        }
        acl.assertPermission("Project Document - Delete",
                                       getProject());
        deleteNC();
    }

    private void deleteNC()
        throws Exception
    {
        Criteria c = new Criteria()
            .add(ProjectSectionPeer.SECTION_ID, getSectionId());
        ProjectSectionPeer.doDelete(c);
    }

a192 2
                ok = false;       
            } else if (Integer.parseInt(acl.getUserID()) != getProposedBy()) {
@


1.1.2.4
log
@added permission methods
@
text
@a31 5
     * The section approval permission.
     */
    private static final String APPROVE_PERM = "Project Section - Approve";

    /**
d80 1
d95 1
a95 1
        if (acl.hasPermission(APPROVE_PERM, project))
d99 1
a99 20
        else
        {
            /*
            // TODO: HELP how does this work
            //Send a message to the project admin(s) informing them of
            //the newly requested section.
            User createdUser = acl.getUser();
            String subject = "New unapproved section: ";
            BuildContext ctx = TemplateInterpolator.createContext();
            ctx.put("section", section);
            ctx.put("createdUser", createdUser);
            String body = TemplateInterpolator.interpolate
                (CREATED_TMPL, ctx, project.getClass());
            HelmEmailer emailer = new HelmEmailer();
            try 
            {
                emailer.messageUsersWithDomainOwnership
                    (domain, subject, body);
            }
            catch (Exception e)
d101 22
a122 2
                Log.error
                    ("Unable to mail domain owners about new project.", e);
a123 2
            */
        }
d133 1
a133 1
     * @@param description   A description of the section.
d135 1
a135 1
     * @@param isPrivate     Whether the section is private.
d165 1
a165 1
            acl.assertPermission(APPROVE_PERM, getProject());
d187 2
a188 1
        assertDeletePermission(acl);
a199 3
    //
    // Permission methods
    //
d209 6
a214 1
        acl.assertPermission("Project Document - Suggest", getProject());
a216 5
    /**
     * Asserts edit permission for this section.
     *
     * @@param acl The ACL to check for permission.
     */
d220 1
a220 6
        if (getProposedBy() == acl.getUser().getUserId())
        {
            acl.assertPermission("Project Document - View", getProject());
        } else {
            acl.assertPermission("Project Document - Edit", getProject());
        }
d224 1
a224 1
     * Asserts deletion and/or disapproval permission for this section.
d231 1
a231 6
        if (getProposedBy() == acl.getUser().getUserId())
        {
            acl.assertPermission("Project Document - View", getProject());
        } else {
            acl.assertPermission("Project Document - Delete", getProject());
        }
a233 3
    /**
     * Returns true if the given ACL can see this section.
     */
d237 11
a247 13
        return (acl.hasPermission(requiredViewPermission(acl), getProject()));
    }

    /**
     * Returns the appropriate permission needed 
     */
    public String requiredViewPermission(AccessControlList acl)
        throws Exception
    {
        String permission = "Project Document - View";
        if ((!isApproved()) && (getProposedBy() != acl.getUser().getUserId()))
        {
            permission = "Project Document - Approve";
d249 1
a249 1
        return permission;
a250 1

@


1.1.2.5
log
@Added new imports necessitated by Torque.
@
text
@a12 1
import org.tigris.helm.om.base.*;
@


1.1.2.6
log
@added getSubsections() and getDocuments() methods
@
text
@d35 1
a35 1
    private static final String APPROVE_PERM = "Project Document - Approve";
a53 5
    public String getParentID()
    {
        return Integer.toString(getParentId());
    }

a67 27


    /**
     * Returns all subsections associated with this section.
     */
    public List getSubsections()
        throws Exception
    {        
        Criteria base = new Criteria()
            .add(ProjectSectionPeer.PARENT_ID, getID());
        base.add(ProjectSectionPeer.PROJECT_ID, getProjectId());
        return ProjectSectionPeer.doSelect(base);
    }

    /**
     * Returns all documents associated with this section.
     */
    public List getDocuments()
        throws Exception
    {        
        Criteria base = new Criteria()
            .addJoin(ProjectDocumentSectionPeer.DOCUMENT_ID, 
                     ProjectDocumentPeer.DOCUMENT_ID);
        base.add(ProjectDocumentPeer.PROJECT_ID, getProjectId());
        return ProjectDocumentPeer.doSelect(base);
    }

@


1.1.2.7
log
@String the calls to Criteria.add() together for consistancy throughout
the source code.
@
text
@d82 2
a83 2
            .add(ProjectSectionPeer.PARENT_ID, getID())
            .add(ProjectSectionPeer.PROJECT_ID, getProjectId());
d95 2
a96 2
                     ProjectDocumentPeer.DOCUMENT_ID)
            .add(ProjectDocumentPeer.PROJECT_ID, getProjectId());
@


1.1.2.8
log
@added disapprove and approve methods
@
text
@a8 1
import org.tigris.helm.tool.*;
a37 12
     * The name of the template used to create the body of the section 
     * creation announcement email.
     */
    private static final String CREATED_TMPL = "ProjectCreated.wm";

    /**
     * The name of the template used to create the body of the section 
     * disapproval email.
     */
    private static final String DISAPPROVE_TMPL = "ProjectDisapprove.wm";

    /**
d82 2
a83 2
            .add(ProjectSectionPeer.PARENT_ID, getID());
        base.add(ProjectSectionPeer.PROJECT_ID, getProjectId());
d95 2
a96 2
                     ProjectDocumentPeer.DOCUMENT_ID);
        base.add(ProjectDocumentPeer.PROJECT_ID, getProjectId());
d193 1
a193 1
     * @@param acl The ACL of the user approving the section.
a209 28
    /**
     * Deletes an unapproved section, sending email to the owners
     * about it.  
     */
    public void disapprove(AccessControlList acl)
        throws ACLException, DoesNotExist, Exception
    {
        delete(acl);
        /*
        //Send email to the owners.
        User disapproving = acl.getUser();
        String subject = "Section " + getName() + " disapproved.";
        BuildContext ctx = TemplateInterpolator.createContext();
        ctx.put("section", this);
        ctx.put("disapprovingUser", disapproving);
        String body = TemplateInterpolator.interpolate(DISAPPROVE_TMPL, ctx,
                                                       getClass());
        HelmEmailer emailer = new HelmEmailer();
         try {
             emailer.messageUsersWithProjectOwnership(getProject(), subject, body);
         }
         catch (Exception e) {
             Log.error
                 ("Unable to mail project owner about section disapproval", e);
         }
         */
    }
    
@


1.1.2.9
log
@added fields to add method
@
text
@a135 1
            section.assertAddPermission(acl);
d138 1
a138 7
            section.setParentId(Integer.parseInt(parentID));
            int proposedBy = acl.getUser().getUserId();
            section.setProposedBy(proposedBy);
            int approvedBy = (acl.hasPermission(APPROVE_PERM, project) ?
                              proposedBy : 
                              UserPeer.getNobodyUser().getUserId());
            section.setApprovedBy(approvedBy);
d152 1
a152 1
            // TODO
@


1.1.2.10
log
@minor cleanup
@
text
@d195 2
a196 1
     * @@exception ACLException
@


1.1.2.11
log
@added additional criteria to getDocuments method
@
text
@d108 1
a108 3
                     ProjectDocumentPeer.DOCUMENT_ID)
            .add(ProjectDocumentSectionPeer.SECTION_ID, 
                     getSectionId());
@


1.1.2.12
log
@Corrected formatting.
@
text
@d309 2
a310 1
        if (getProposedBy() == acl.getUser().getUserId()) {
d312 1
a312 2
        }
        else {
d325 2
a326 1
        if (getProposedBy() == acl.getUser().getUserId()) {
d328 1
a328 2
        }
        else {
@


1.1.2.13
log
@* deleteNC --> delete
* JavaDoc
@
text
@d275 1
a275 1
        delete();
d278 1
a278 4
    /**
     * Deletes the section without no ACL check.
     */
    private void delete()
@


