head	1.26;
access;
symbols
	TIGRIS_0_9_2_4:1.18
	TIGRIS_0_9_2_3:1.18
	HELM_PEER_PORT_BRANCH:1.22.0.2
	TURBINE_PEER:1.22
	TIGRIS_0_9_2_1:1.22
	TIGRIS_0_9_2:1.18.0.2
	TIGRIS_0_9_0:1.11.0.2
	TIGRIS_0_8_4:1.6.0.2
	NEWHELM:1.1.1.1
	TIGRIS_NOV_12_2000:1.1.1;
locks; strict;
comment	@# @;


1.26
date	2001.02.21.02.19.01;	author dlr;	state dead;
branches;
next	1.25;

1.25
date	2001.02.06.20.01.32;	author elicia;	state Exp;
branches;
next	1.24;

1.24
date	2001.02.02.04.03.34;	author elicia;	state Exp;
branches;
next	1.23;

1.23
date	2001.02.02.01.10.21;	author elicia;	state Exp;
branches;
next	1.22;

1.22
date	2001.01.26.18.29.02;	author edk;	state Exp;
branches
	1.22.2.1;
next	1.21;

1.21
date	2001.01.26.05.24.05;	author edk;	state dead;
branches;
next	1.20;

1.20
date	2001.01.24.23.41.04;	author leonardr;	state Exp;
branches;
next	1.19;

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

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

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

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

1.15
date	2001.01.12.22.13.38;	author elicia;	state Exp;
branches;
next	1.14;

1.14
date	2000.12.29.17.11.53;	author leonardr;	state Exp;
branches;
next	1.13;

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

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

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

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

1.9
date	2000.12.15.01.34.38;	author jrobbins;	state Exp;
branches;
next	1.8;

1.8
date	2000.12.05.23.53.30;	author leonardr;	state Exp;
branches;
next	1.7;

1.7
date	2000.12.05.23.28.58;	author leonardr;	state Exp;
branches;
next	1.6;

1.6
date	2000.11.23.04.07.12;	author elicia;	state Exp;
branches
	1.6.2.1;
next	1.5;

1.5
date	2000.11.22.03.28.22;	author elicia;	state Exp;
branches;
next	1.4;

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

1.3
date	2000.11.22.02.19.37;	author elicia;	state Exp;
branches;
next	1.2;

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

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

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

1.6.2.1
date	2000.12.15.06.20.19;	author jrobbins;	state Exp;
branches;
next	;

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


desc
@@


1.26
log
@Moved to om package by Peer port.
@
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.domain;

import java.util.Date;
import java.util.Dictionary;
import java.sql.*;
import java.text.ParseException;

import com.workingdogs.village.*;

import org.webmacro.engine.BuildContext;

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

import org.tigris.helm.DoesNotExist;
import org.tigris.helm.database.*;
import org.tigris.helm.security.*;
import org.tigris.helm.tool.*;
import org.tigris.helm.DoesNotExist;
import org.tigris.helm.project.Project;
import org.tigris.helm.tool.*;

public class NewsItem extends BusinessObject
{
    /**
     * The name of the template used to create the body of the news item
     * disapproval email.
     */
    private static final String DISAPPROVE_TMPL = "NewsItemDisapprove.wm";

    private ProjectNewsManager newsMgr;
    private ProjectManager pMgr;
    private UserUserGroupManager usrGrpMgr;
    private UserManager uMgr;
    private Project project;

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

    public NewsItem (Connection c, DataManager dMgr, Record r)
        throws DoesNotExist, DataSetException
    {
        super(c, dMgr, r);
    }

    /**
     * Constructor for a news item which already exists -- accessed by
     * newsID.
     */
    public NewsItem(Connection conn, DataManager dMgr, String newsID)
        throws SQLException, DataSetException, DoesNotExist
    {
        super(conn, dMgr);
        setRecord(newsMgr.getNewsItemForID(conn, newsID));
    }

    /**
     * Constructor for a new news item.
     */
    public NewsItem(Connection conn, DataManager dMgr, AccessControlList acl,
                    Project project, Date eventDate, String headline,
                    String body, Date publishOn, Date removeOn, String priority)
        throws SQLException, DataSetException, DoesNotExist, UpdateException,
               JoistDatabaseException, ACLException
    {
        super(conn, dMgr);

        // To add a news item you need either Suggest or Approve permission.
        String projectID = project.getID();
        String userID = acl.getUserID();
        String suggest = "Project News - Suggest";
        String approve = "Project News - 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) ?
                             userID : 
                             usrGrpMgr.getNobodyUserID(conn));

        setRecord(newsMgr.updateNews(conn, null, projectID, eventDate,
                            headline, body, approvedBy, 
                            publishOn, removeOn, priority, userID));
    }

    protected void createManagers ()
    {
        newsMgr = (ProjectNewsManager)
            dMgr.getManager ("org.tigris.helm.database.ProjectNewsManager");
        pMgr = (ProjectManager)
            dMgr.getManager ("org.tigris.helm.database.ProjectManager");
        usrGrpMgr = (UserUserGroupManager)
            dMgr.getManager ("org.tigris.helm.database.UserUserGroupManager");
        uMgr = (UserManager)
            dMgr.getManager ("org.joist.database.UserManager");
    }

    /**
     * Updates a news item.
     *
     * @@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, Date eventDate,
                      String headline, String body, Date publishOn,
                      Date removeOn, String priority)
        throws DataSetException, SQLException, ACLException
    {
        String action;
        if (acl.getUserID().equals(getProposedBy()))
        {
            action = "Project News - View";
            acl.assertPermissionForProject("Project News - View", getProjectID());
        } else {
            action = "Project News - Edit";
        }
        acl.assertPermissionForProject(action, getProjectID());
        newsMgr.updateNews(conn, getID(), null, eventDate, headline, 
                           body, null, publishOn, removeOn, priority, null);
    }

    /**
     * Deletes the news item.  
     *
     * @@param acl The ACL to check for delete permission.
     */
    public void delete (AccessControlList acl)
        throws SQLException, DataSetException, JoistDatabaseException,
               UpdateException, ACLException
    {
        String action;
        if (acl.getUserID().equals(getProposedBy()))
        {
            action = "Project News - View";
        } else {
            action = "Project News - Approve";
        }
        acl.assertPermissionForProject(action, getProjectID());
        newsMgr.deleteNewsItem(conn, getID());
    }

    /**
     * Approves the news item.
     *
     * @@param acl The ACL to check for approve permission.
     */
    public void approve(AccessControlList acl)
        throws SQLException, DataSetException, JoistDatabaseException,
               DoesNotExist, ACLException
    {
        String action = "Project News - Approve";
        if (!acl.hasPermissionForProject(action, getProjectID()))
        {
            return;
        }
        acl.assertPermissionForProject(action, getProjectID());
        newsMgr.approveNewsItem(conn, getID(), acl.getUserID());
    }

    /**
     * Sends email and deletes the news item.
     *
     * @@param acl The ACL to check for disapprove permission.
     */
    public void disapprove(AccessControlList acl)
        throws SQLException, DataSetException, JoistDatabaseException,
               JoistException, DoesNotExist, ACLException, UpdateException,
               DBException
    {
        String action = "Project News - Approve";
        if (!acl.hasPermissionForProject(action, getProjectID()))
        {
            return;
        }
        acl.assertPermissionForProject(action, getProjectID());

        //Send email to the owners.
        User disapprovingUser = new User(conn, dMgr, acl.getUserID());
        String subject = "News item for Project " + getProjectName() +
            " disapproved.";
        BuildContext ctx = TemplateInterpolator.createContext();
        ctx.put("disapprovingUser", disapprovingUser);
        ctx.put("news", this);
        String body = TemplateInterpolator.interpolate(DISAPPROVE_TMPL, ctx,
                                                       getClass());
        HelmEmailer emailer = new HelmEmailer(conn, dMgr);
        emailer.sendEmail(getProposedByUser().getEmail(), subject, body);
        delete(acl);
    }

    public String getID () throws DataSetException
    {
        return rec.getValue(newsMgr.NEWS_ID).asString();
    }

    public String getHeadline () throws DataSetException
    {
        return rec.getValue(newsMgr.HEADLINE).asString();
    }

    public String getBody () throws DataSetException
    {
        return rec.getValue(newsMgr.BODY).asString();
    }

    public String getEventDate () throws DataSetException, ParseException
    {
        String eventDate = rec.getValue(newsMgr.EVENT_DATE).asString();
        return FormatDate.format("yyyy-MM-dd kk:mm:ss", "MM-dd-yyyy", eventDate);
    }

    public String getPublishOn () throws DataSetException, ParseException
    {
        String publishOn = rec.getValue (newsMgr.PUBLISH_ON).asString ();
        return FormatDate.format("yyyy-MM-dd kk:mm:ss", "MM-dd-yyyy", publishOn);
    }

    public String getRemoveOn () throws DataSetException, ParseException
    {
        String removeOn = rec.getValue (newsMgr.REMOVE_ON).asString ();
        return FormatDate.format("yyyy-MM-dd kk:mm:ss", "MM-dd-yyyy", removeOn);
    }
  
    public Date getRemoveOnAsDate () throws DataSetException, ParseException
    {
        return rec.getValue (newsMgr.REMOVE_ON).asDate();
    }

    public Date getPublishOnAsDate () throws DataSetException, ParseException
    {
        return rec.getValue (newsMgr.PUBLISH_ON).asDate();
    }

    public Date getEventAsDate () throws DataSetException, ParseException
    {
        return rec.getValue (newsMgr.EVENT_DATE).asDate();
    }

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

    public User getProposedByUser()
        throws DBException, JoistDatabaseException, SQLException,
               DataSetException, DoesNotExist
    {
        String userID = rec.getValue(newsMgr.PROPOSED_BY).asString();
        return new User(conn, dMgr, userID);
    }

    public String getApprovedBy() throws DataSetException
    {
        return rec.getValue(newsMgr.APPROVED_BY).asString ();
    }

    public String getProposedBy() throws DataSetException
    {
        return rec.getValue(newsMgr.PROPOSED_BY).asString ();
    }

    public String getProjectName()
        throws DataSetException, SQLException, JoistDatabaseException,
               DoesNotExist
    {
        return getProject().getName();
    }

    public String getProjectHome()
        throws DataSetException, SQLException, JoistDatabaseException,
               DoesNotExist
    {
        return getProject().getProjectHome();
    }

    public Project getProject()
        throws DataSetException, SQLException, JoistDatabaseException,
               DoesNotExist
    {
        if (project == null)
        {
            String projectID = rec.getValue(newsMgr.PROJECT_ID).asString();
            project = new Project(conn, dMgr, projectID);
        }
        return project;
    }

    /**
     * Determines whether a news item should be posted now
     * Or at a later date 
     *
     */
    public boolean isPosted()
        throws DataSetException, ParseException
    {
        boolean isPosted = true;
        if  (getPublishOnAsDate().compareTo(new Date()) > 0)
        {
            isPosted = false;
        }

        return isPosted;
    }

    /**
     * Determines whether a news item should be posted now
     * Or if it has already passed the removeOn() date
     *
     */
    public boolean isRemoved()
        throws DataSetException, ParseException
    {
        boolean isRemoved = false;
        if (getRemoveOnAsDate() != null)
        {
            if (getRemoveOnAsDate().compareTo(new Date()) < 0)
                isRemoved = true;
        }
        return isRemoved;
    }

    /**
     * Determines whether a news item has been approved
     *
     */
    public boolean isApproved()
        throws JoistDatabaseException, DataSetException, SQLException
    {
        return !getApprovedBy().equals(usrGrpMgr.getNobodyUserID(conn));
    }

    public String requiredViewPermission(AccessControlList acl)
        throws JoistDatabaseException, DataSetException, SQLException,
               ParseException
    {
        String permission = "Project News - Edit";
        if (isPosted() && !isRemoved() && isApproved())
        {
            permission = "Project News - View";
        } else if (!isApproved()) {
            if (acl.getUserID().equals(getProposedBy()))
            {
                permission = "Project News - View";
            }
            else {
                permission = "Project News - Approve";
            }
        }
        return permission;
    }

}
@


1.25
log
@changed constructor to do the work of adding new news items
@
text
@@


1.24
log
@get proposed by user for template
@
text
@d116 7
a122 2
        if (!acl.hasPermissionForProject("Project News - Suggest", 
                                         project.getID()))
d124 3
a126 2
            throw new ACLException(acl, "Project News - Suggest",
                                   "Project " + project.getID(), null);
d128 3
d132 3
a134 8
        String action = "Project News - Approve";
        String approvedBy =
            (acl.hasPermissionForProject(action, project.getID()) ?
             acl.getUserID() : 
             usrGrpMgr.getNobodyUserID(conn));
        setRecord(newsMgr.updateNews(conn, null, project.getID(), eventDate,
                                     headline, body, approvedBy, 
                                     publishOn, removeOn, priority, null));
d160 1
a160 1
    public void edit (AccessControlList acl, String newsID, Date eventDate,
@


1.23
log
@now the user who proposed the news item can edit and delete it
@
text
@d219 2
a220 1
               JoistException, DoesNotExist, ACLException, UpdateException
a237 1
        User user = new User(conn, dMgr, getProposedBy());
d239 1
a239 1
        emailer.sendEmail(user.getEmail(), subject, body);
d297 3
a299 2
    public String getProposedBy()
        throws DataSetException
d301 2
a302 1
        return rec.getValue(newsMgr.PROPOSED_BY).asString();
d305 1
a305 3
    public String getProposedByName()
        throws DataSetException, JoistDatabaseException, SQLException,
               DoesNotExist
d307 1
a307 9
        String userID = getProposedBy();
        if (userID != null) 
        {
            Record r = uMgr.getUser(conn, userID);
            User u = new User(conn, dMgr, r);
            return u.getName();
        } else {
            return null;
        }
d310 1
a310 1
    public String getApprovedBy() throws DataSetException
d312 1
a312 1
        return rec.getValue(newsMgr.APPROVED_BY).asString ();
@


1.22
log
@readding all the files as part of the process of returning to the way
things were as of tuesday
@
text
@d161 9
a169 1
        acl.assertPermissionForProject("Project News - Edit", getProjectID());
d183 7
a189 1
        String action = "Project News - Approve";
d393 1
a393 1
    public String requiredViewPermission()
d402 7
a408 1
            permission = "Project News - Approve";
@


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


1.21
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
@d59 1
a59 3
import org.joist.database.UserManager;
import org.joist.database.DataManager;
import org.joist.database.JoistDatabaseException;
d88 2
a89 2
    public NewsItem (DataManager dMgr, Record r)
        throws DoesNotExist, DBException
d91 1
a91 1
        super(dMgr, r);
d98 2
a99 2
    public NewsItem(DataManager dMgr, String newsID)
        throws DoesNotExist, DBException
d101 2
a102 1
        super(dMgr, newsMgr.getNewsItemForID(conn, newsID));
d108 1
a108 1
    public NewsItem(DataManager dMgr, AccessControlList acl,
d111 2
a112 1
        throws ACLException, DoesNotExist, UpdateException, DBException
d114 1
a114 1
        super(dMgr);
d127 2
a128 2
             uMgr.getNobodyUserID());
        setRecord(newsMgr.updateNews(null, project.getID(), eventDate,
d142 1
a142 1
            dMgr.getManager ("org.tigris.helm.database.UserManager");
d159 1
a159 1
        throws ACLException, DBException
d162 1
a162 1
        newsMgr.updateNews(getID(), null, eventDate, headline, 
d172 2
a173 1
        throws ACLException, UpdateException, DBException
d177 1
a177 1
        newsMgr.deleteNewsItem(getID());
d186 2
a187 1
        throws ACLException, DoesNotExist, DBException
d195 1
a195 1
        newsMgr.approveNewsItem(getID(), acl.getUserID());
d204 2
a205 2
        throws ACLException, JoistException, DoesNotExist, UpdateException,
               DBException
d215 1
a215 1
        User disapprovingUser = new User(dMgr, acl.getUserID());
d223 2
a224 2
        User user = new User(dMgr, getProposedBy());
        HelmEmailer emailer = new HelmEmailer(dMgr);
d229 1
a229 1
    public String getID () throws DBException
d234 1
a234 1
    public String getHeadline () throws DBException
d239 1
a239 1
    public String getBody () throws DBException
d244 1
a244 1
    public String getEventDate () throws DBException, ParseException
d250 1
a250 1
    public String getPublishOn () throws DBException, ParseException
d256 1
a256 1
    public String getRemoveOn () throws DBException, ParseException
d262 1
a262 1
    public Date getRemoveOnAsDate () throws DBException, ParseException
d267 1
a267 1
    public Date getPublishOnAsDate () throws DBException, ParseException
d272 1
a272 1
    public Date getEventAsDate () throws DBException, ParseException
d277 1
a277 1
    public String getProjectID() throws DBException
d284 1
a284 1
        throws DBException
d290 2
a291 1
        throws DoesNotExist, DBException
d296 2
a297 2
            Record r = uMgr.getUser(userID);
            User u = new User(dMgr, r);
d304 1
a304 1
    public String getApprovedBy() throws DBException
d310 2
a311 1
        throws DoesNotExist, DBException
d317 2
a318 1
        throws DoesNotExist, DBException
d324 2
a325 1
        throws DoesNotExist, DBException
d330 1
a330 1
            project = new Project(dMgr, projectID);
d341 1
a341 1
        throws DBException, ParseException
d358 1
a358 1
        throws DBException, ParseException
d374 1
a374 1
        throws DBException
d376 1
a376 1
        return !getApprovedBy().equals(uMgr.getNobodyUserID());
d380 2
a381 1
        throws DBException, ParseException
@


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


1.19
log
@Ported UserManager and RoleManager to Helm. Started moving other TableManagers toward a grab-connection-on-demand model. Massive breakage ensues. dlr and I are working on it.
@
text
@d90 2
a91 2
    public NewsItem (Connection c, DataManager dMgr, Record r)
        throws DoesNotExist, DataSetException
d93 1
a93 1
        super(c, dMgr, r);
d100 2
a101 2
    public NewsItem(Connection conn, DataManager dMgr, String newsID)
        throws SQLException, DataSetException, DoesNotExist
d103 1
a103 2
        super(conn, dMgr);
        setRecord(newsMgr.getNewsItemForID(conn, newsID));
d109 1
a109 1
    public NewsItem(Connection conn, DataManager dMgr, AccessControlList acl,
d112 1
a112 2
        throws SQLException, DataSetException, DoesNotExist, UpdateException,
               JoistDatabaseException, ACLException
d114 1
a114 1
        super(conn, dMgr);
d128 1
a128 1
        setRecord(newsMgr.updateNews(conn, null, project.getID(), eventDate,
d159 1
a159 1
        throws DataSetException, SQLException, ACLException
d162 1
a162 1
        newsMgr.updateNews(conn, getID(), null, eventDate, headline, 
d172 1
a172 2
        throws SQLException, DataSetException, JoistDatabaseException,
               UpdateException, ACLException
d176 1
a176 1
        newsMgr.deleteNewsItem(conn, getID());
d185 1
a185 2
        throws SQLException, DataSetException, JoistDatabaseException,
               DoesNotExist, ACLException
d193 1
a193 1
        newsMgr.approveNewsItem(conn, getID(), acl.getUserID());
d202 2
a203 2
        throws DBException, SQLException, DataSetException, JoistDatabaseException,
               JoistException, DoesNotExist, ACLException, UpdateException
d213 1
a213 1
        User disapprovingUser = new User(conn, dMgr, acl.getUserID());
d221 2
a222 2
        User user = new User(conn, dMgr, getProposedBy());
        HelmEmailer emailer = new HelmEmailer(conn, dMgr);
d227 1
a227 1
    public String getID () throws DataSetException
d232 1
a232 1
    public String getHeadline () throws DataSetException
d237 1
a237 1
    public String getBody () throws DataSetException
d242 1
a242 1
    public String getEventDate () throws DataSetException, ParseException
d248 1
a248 1
    public String getPublishOn () throws DataSetException, ParseException
d254 1
a254 1
    public String getRemoveOn () throws DataSetException, ParseException
d260 1
a260 1
    public Date getRemoveOnAsDate () throws DataSetException, ParseException
d265 1
a265 1
    public Date getPublishOnAsDate () throws DataSetException, ParseException
d270 1
a270 1
    public Date getEventAsDate () throws DataSetException, ParseException
d275 1
a275 1
    public String getProjectID() throws DataSetException
d282 1
a282 1
        throws DataSetException
d288 1
a288 2
        throws DataSetException, JoistDatabaseException, SQLException,
               DoesNotExist
d293 2
a294 2
            Record r = uMgr.getUser(conn, userID);
            User u = new User(conn, dMgr, r);
d301 1
a301 1
    public String getApprovedBy() throws DataSetException
d307 1
a307 2
        throws DataSetException, SQLException, JoistDatabaseException,
               DoesNotExist
d313 1
a313 2
        throws DataSetException, SQLException, JoistDatabaseException,
               DoesNotExist
d319 1
a319 2
        throws DataSetException, SQLException, JoistDatabaseException,
               DoesNotExist
d324 1
a324 1
            project = new Project(conn, dMgr, projectID);
d335 1
a335 1
        throws DataSetException, ParseException
d352 1
a352 1
        throws DataSetException, ParseException
d374 1
a374 2
        throws DBException, JoistDatabaseException, DataSetException, SQLException,
               ParseException
@


1.18
log
@Improved JavaDoc wording.
@
text
@d59 3
a61 1
import org.joist.database.*;
d129 1
a129 1
             usrGrpMgr.getNobodyUserID(conn));
d144 1
a144 1
            dMgr.getManager ("org.joist.database.UserManager");
d206 1
a206 1
        throws SQLException, DataSetException, JoistDatabaseException,
d376 1
a376 1
        throws JoistDatabaseException, DataSetException, SQLException
d378 1
a378 1
        return !getApprovedBy().equals(usrGrpMgr.getNobodyUserID(conn));
d382 1
a382 1
        throws JoistDatabaseException, DataSetException, SQLException,
@


1.17
log
@Use a template to generate the message body.
@
text
@d72 1
a72 1
     * The name of the template to use to create the body of the news item
@


1.16
log
@Corrected indentation.
@
text
@d56 2
d71 6
d81 2
a82 1
    
d124 4
a127 3
        String approvedBy = (acl.hasPermissionForProject(action, 
                                                         project.getID()) ?  acl.getUserID() : 
                             usrGrpMgr.getNobodyUserID(conn));
d169 1
a169 2
     * @@param acl            The ACL to check for delete permission.
     *
d182 2
d200 2
d216 7
a222 8
        String subject = "News item for Project " + getProjectName() + " disapproved.";
        StringBuffer body = new StringBuffer();
        body.append("Sorry, your submission of the news item '")
            .append(getHeadline()).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(")");
d225 1
a225 1
        emailer.sendEmail(user.getEmail(), subject, body.toString());
d231 1
a231 1
        return rec.getValue (newsMgr.NEWS_ID).asString ();
d236 1
a236 1
        return rec.getValue (newsMgr.HEADLINE).asString ();
d241 1
a241 1
        return rec.getValue (newsMgr.BODY).asString ();
d246 1
a246 1
        String eventDate = rec.getValue (newsMgr.EVENT_DATE).asString ();
d306 1
a306 1
        return rec.getValue (newsMgr.APPROVED_BY).asString ();
d309 3
a311 2
    public String getProjectName() throws DataSetException, SQLException,
    JoistDatabaseException
d313 1
a313 3
        String projectID = rec.getValue (newsMgr.PROJECT_ID).asString ();
        String projectName = pMgr.getProjectName(conn, projectID);
        return projectName;
d317 2
a318 1
        throws DataSetException, SQLException, JoistDatabaseException, DoesNotExist
d320 1
a320 2
        Project p = getProject();
        return p.getProjectHome();
d324 2
a325 1
        throws DataSetException, SQLException, JoistDatabaseException, DoesNotExist
d327 6
a332 3
        String projectID = rec.getValue(newsMgr.PROJECT_ID).asString();
        Project p = new Project(conn, dMgr, projectID);
        return p;
@


1.15
log
@cleanup
@
text
@d96 6
a101 6
  /**
   * Constructor for a new news item.
   */
  public NewsItem(Connection conn, DataManager dMgr, AccessControlList acl,
                  Project project, Date eventDate, String headline,
		          String body, Date publishOn, Date removeOn, String priority)
d103 59
a161 59
	           JoistDatabaseException, ACLException
  {
      super(conn, dMgr);
	
      if (!acl.hasPermissionForProject("Project News - Suggest", 
	                                   project.getID()))
	  {
	      throw new ACLException(acl, "Project News - Suggest",
	                             "Project " + project.getID(), null);
	  }

      String action = "Project News - Approve";
      String approvedBy = (acl.hasPermissionForProject(action, 
                           project.getID()) ?  acl.getUserID() : 
                           usrGrpMgr.getNobodyUserID(conn));
      setRecord(newsMgr.updateNews(conn, null, project.getID(), eventDate,
	                               headline, body, approvedBy, 
	                               publishOn, removeOn, priority, null));
  }

  protected void createManagers ()
  {
    newsMgr = (ProjectNewsManager)
      dMgr.getManager ("org.tigris.helm.database.ProjectNewsManager");
    pMgr = (ProjectManager)
      dMgr.getManager ("org.tigris.helm.database.ProjectManager");
    usrGrpMgr = (UserUserGroupManager)
      dMgr.getManager ("org.tigris.helm.database.UserUserGroupManager");
    uMgr = (UserManager)
      dMgr.getManager ("org.joist.database.UserManager");
  }

  /**
   * Updates a news item.
   *
   * @@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 newsID, Date eventDate,
                    String headline, String body, Date publishOn,
		    Date removeOn, String priority)
      throws DataSetException, SQLException, ACLException
  {
      acl.assertPermissionForProject("Project News - Edit", getProjectID());
      newsMgr.updateNews(conn, getID(), null, eventDate, headline, 
                         body, null, publishOn, removeOn, priority, null);
  }

  /**
   * Deletes the news item.  
   *
   * @@param acl            The ACL to check for delete permission.
   *
   */
d163 2
a164 2
       throws SQLException, DataSetException, JoistDatabaseException,
              UpdateException, ACLException
d171 3
a173 3
  /**
    * Approves the news item.
    */
d187 3
a189 3
  /**
    * Sends email and deletes the news item.
    */
d217 32
a248 32
  public String getID () throws DataSetException
  {
    return rec.getValue (newsMgr.NEWS_ID).asString ();
  }

  public String getHeadline () throws DataSetException
  {
    return rec.getValue (newsMgr.HEADLINE).asString ();
  }

  public String getBody () throws DataSetException
  {
    return rec.getValue (newsMgr.BODY).asString ();
  }

  public String getEventDate () throws DataSetException, ParseException
  {
    String eventDate = rec.getValue (newsMgr.EVENT_DATE).asString ();
    return FormatDate.format("yyyy-MM-dd kk:mm:ss", "MM-dd-yyyy", eventDate);
  }

  public String getPublishOn () throws DataSetException, ParseException
  {
    String publishOn = rec.getValue (newsMgr.PUBLISH_ON).asString ();
    return FormatDate.format("yyyy-MM-dd kk:mm:ss", "MM-dd-yyyy", publishOn);
  }

  public String getRemoveOn () throws DataSetException, ParseException
  {
    String removeOn = rec.getValue (newsMgr.REMOVE_ON).asString ();
    return FormatDate.format("yyyy-MM-dd kk:mm:ss", "MM-dd-yyyy", removeOn);
  }
d250 9
a258 20
  public Date getRemoveOnAsDate () throws DataSetException, ParseException
  {
    return rec.getValue (newsMgr.REMOVE_ON).asDate();
  }

  public Date getPublishOnAsDate () throws DataSetException, ParseException
  {
    return rec.getValue (newsMgr.PUBLISH_ON).asDate();
  }

  public Date getEventAsDate () throws DataSetException, ParseException
  {
    return rec.getValue (newsMgr.EVENT_DATE).asDate();
  }

  public String getProjectID() throws DataSetException
  {
    String projectID = rec.getValue (newsMgr.PROJECT_ID).asString ();
    return projectID;
  }
d260 12
a271 1
  public String getProposedBy()
d273 86
a358 86
  {
    return rec.getValue(newsMgr.PROPOSED_BY).asString();
  }

  public String getProposedByName()
     throws DataSetException, JoistDatabaseException, SQLException,
            DoesNotExist
  {
    String userID = getProposedBy();
    if (userID != null) 
    {
       Record r = uMgr.getUser(conn, userID);
       User u = new User(conn, dMgr, r);
       return u.getName();
    } else {
       return null;
    }
  }

  public String getApprovedBy() throws DataSetException
  {
    return rec.getValue (newsMgr.APPROVED_BY).asString ();
  }

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

  public String getProjectHome()
    throws DataSetException, SQLException, JoistDatabaseException, DoesNotExist
  {
    Project p = getProject();
    return p.getProjectHome();
  }

  public Project getProject()
    throws DataSetException, SQLException, JoistDatabaseException, DoesNotExist
  {
    String projectID = rec.getValue(newsMgr.PROJECT_ID).asString();
    Project p = new Project(conn, dMgr, projectID);
    return p;
  }

  /**
   * Determines whether a news item should be posted now
   * Or at a later date 
   *
   */
  public boolean isPosted()
    throws DataSetException, ParseException
  {
    boolean isPosted = true;
    if  (getPublishOnAsDate().compareTo(new Date()) > 0)
    {
        isPosted = false;
    }

    return isPosted;
  }

  /**
   * Determines whether a news item should be posted now
   * Or if it has already passed the removeOn() date
   *
   */
  public boolean isRemoved()
    throws DataSetException, ParseException
  {
    boolean isRemoved = false;
    if (getRemoveOnAsDate() != null)
    {
       if (getRemoveOnAsDate().compareTo(new Date()) < 0)
          isRemoved = true;
    }
    return isRemoved;
  }

  /**
   * Determines whether a news item has been approved
   *
   */
  public boolean isApproved()
@


1.14
log
@Many, many pagination changes.
@
text
@d100 1
a100 1
                  String projectID, Date eventDate, String headline,
d108 1
a108 1
	                                   projectID))
d111 1
a111 1
	                             "Project " + projectID, null);
d115 2
a116 2
      String approvedBy = (acl.hasPermissionForProject(action, projectID) ?
                           acl.getUserID() : 
d118 1
a118 1
      setRecord(newsMgr.updateNews(conn, null, projectID, eventDate,
@


1.13
log
@Removed unnecessary getCache() implementations in BusinessObject subclasses and migrated to a factory method for User's primary database key ctor.
@
text
@d363 15
@


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

@


1.11
log
@fixed permission problem in approve and disapprove methods
@
text
@d50 1
d123 4
@


1.10
log
@added news item approval methods
@
text
@d179 1
a179 1
        if (!acl.hasPermissionForProject(action, getID()))
d183 1
a183 1
        acl.assertPermissionForProject(action, getID());
d195 1
a195 1
        if (!acl.hasPermissionForProject(action, getID()))
d199 1
a199 1
        acl.assertPermissionForProject(action, getID());
@


1.9
log
@added a way to get the Project object, so that we can get any project page URL more easily
@
text
@d55 1
d64 1
a64 1
import org.tigris.helm.tool.FormatDate;
d70 2
d99 2
a100 3
                    String projectID, Date eventDate, String headline,
		    String body, String approvedBy, Date publishOn, 
		    Date removeOn, String priority)
d102 1
a102 1
	       JoistDatabaseException, ACLException
d104 1
a104 1
        super(conn, dMgr);
d106 14
a119 16
	if (!acl.hasPermissionForProject("Project News - Add", 
	                                 projectID))
	{
	    throw new ACLException(acl, "Project News - Add",
	                           "Project " + projectID, null);
	}

        //String approvedBy = usrGrpMgr.getNobodyUserID(conn);
        setRecord(newsMgr.updateNews(conn, null, projectID, eventDate,
	                              headline, body, acl.getUserID(), 
				      publishOn, removeOn, priority));

        /* TODO : approval step
	// Approve news item, if user has permission
	approve(acl);
	*/
d129 4
d153 1
a153 1
                         body, null, publishOn, removeOn, priority);
d171 46
d260 5
d271 26
d353 10
@


1.8
log
@Enabled security check of records passed into business objects.
@
text
@d227 7
d236 1
a236 1
    return p.getProjectHome();
@


1.7
log
@Added a check so that business objects cannot be created with records from the wrong table. Also added some new business objects.
@
text
@d67 7
a73 2
  private ProjectNewsManager newsMgr;
  private ProjectManager pMgr;
d75 5
a79 5
  public NewsItem (Connection c, DataManager dMgr, Record r)
      throws DoesNotExist, DataSetException
  {
    super(c, dMgr, r);
  }
@


1.6
log
@changed years for dates to "2000" format instead of "00"
@
text
@d71 1
a71 1
    throws DoesNotExist
@


1.6.2.1
log
@added method to make links easier
@
text
@a226 8
  public Project getProject()
    throws DataSetException, SQLException, JoistDatabaseException, DoesNotExist
  {
    String projectID = rec.getValue(newsMgr.PROJECT_ID).asString();
    Project p = new Project(conn, dMgr, projectID);
    return p;
  }

@


1.5
log
@added isRemoved() method to check whether news item is past its removeOn date
@
text
@d180 1
a180 1
    return FormatDate.format("yyyy-MM-dd kk:mm:ss", "MM-dd-yy", eventDate);
d186 1
a186 1
    return FormatDate.format("yyyy-MM-dd kk:mm:ss", "MM-dd-yy", publishOn);
d192 1
a192 1
    return FormatDate.format("yyyy-MM-dd kk:mm:ss", "MM-dd-yy", removeOn);
d236 1
a236 2
    if ( (getPublishOnAsDate().compareTo(new Date()) > 0)
       && (getRemoveOnAsDate().compareTo(new Date()) >= 0))
d252 2
a253 2
    boolean isRemoved = true;
    if (getRemoveOnAsDate().compareTo(new Date()) >= 0)
d255 2
a256 1
        isRemoved = false;
a257 1

@


1.4
log
@added comments for isPosted method
@
text
@d195 10
a234 2
    String dateToday = FormatDate.format("EEE MMM dd kk:mm:ss z yyyy",
                                  "MM-dd-yy", new Date().toString());
d236 2
a237 2
    if ( (getPublishOn().compareTo(dateToday) > 0)
       && (getRemoveOn().compareTo(dateToday) >= 0))
d243 17
@


1.3
log
@modernized -- added constructor for new news item, edit and delete methods, isPosted method to determine whether the news item should be posted now or at a later date
@
text
@d217 5
@


1.2
log
@provide a method required by the StartPage template
@
text
@d49 1
a49 1
import java.util.*;
d59 3
d76 42
d126 37
a162 1
  public String getNewsID () throws DataSetException
d183 12
d215 15
@


1.1
log
@Initial revision
@
text
@d59 1
d116 7
@


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