head	1.17;
access;
symbols
	TIGRIS_0_9_2_4:1.8
	TIGRIS_0_9_2_3:1.8
	HELM_PEER_PORT_BRANCH:1.15.0.2
	TURBINE_PEER:1.15
	TIGRIS_0_9_2_1:1.15
	TIGRIS_0_9_2:1.8.0.2
	TIGRIS_0_9_0:1.7.0.2
	TIGRIS_0_8_4:1.4.0.2
	NEWHELM:1.1.1.1
	TIGRIS_NOV_12_2000:1.1.1;
locks; strict;
comment	@# @;


1.17
date	2001.02.21.03.23.56;	author edk;	state dead;
branches;
next	1.16;

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

1.15
date	2001.01.26.18.29.00;	author edk;	state Exp;
branches
	1.15.2.1;
next	1.14;

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

1.13
date	2001.01.25.04.30.00;	author stack;	state Exp;
branches;
next	1.12;

1.12
date	2001.01.25.02.53.24;	author leonardr;	state Exp;
branches;
next	1.11;

1.11
date	2001.01.25.01.42.10;	author leonardr;	state Exp;
branches;
next	1.10;

1.10
date	2001.01.24.22.24.36;	author leonardr;	state Exp;
branches;
next	1.9;

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

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

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

1.6
date	2000.12.19.03.17.35;	author elicia;	state Exp;
branches;
next	1.5;

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

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

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

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

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

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

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


desc
@@


1.17
log
@delete stuff from the head which is obsolete in the branch (more changes
are still needed for a clean compile)
@
text
@/* ================================================================
 * Copyright (c) 2000 CollabNet.  All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are
 * met:
 * 
 * 1. Redistributions of source code must retain the above copyright
 * notice, this list of conditions and the following disclaimer.
 * 
 * 2. Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 * 
 * 3. The end-user documentation included with the redistribution, if
 * any, must include the following acknowlegement: "This product includes
 * software developed by CollabNet (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 CollabNet.
 * 
 * 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.database;

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

import org.webmacro.util.*;

import com.workingdogs.village.*;

import org.joist.util.*;
import org.joist.database.*;
import org.tigris.helm.domain.NewsItem;

/**
 * Manages the project news table.
 *
 * @@author <a href="mailto:elicia@@collab.net">Elicia David</a>
 * @@version $Id: ProjectNewsManager.java,v 1.16 2001/02/06 19:56:10 elicia Exp $
 *
 * Copyright (c) 2000 CollabNet, Inc.  
 */

public class ProjectNewsManager extends TableManager
{
    /**
     * The name of the database table that this <code>TableManager</code> 
     * manages. 
     */
  public static final String TABLE_NAME = "HELM_PROJECTNEWS";

    /**
     * The primary database key field.
     */
  public static final String NEWS_ID = "NEWS_ID";

    /**
     * The headline field.
     */
  public static final String HEADLINE = "HEADLINE";

    /**
     * The body of the news item field.
     */
  public static final String BODY = "BODY";


    /**
     * The project_id of the project the news item is for.
     */
  public static final String PROJECT_ID = "PROJECT_ID";

    /**
     * The loginID of the person who approves the item
     */
  public static final String APPROVED_BY = "APPROVED_BY";

    /**
     * The loginID of the person who suggested the item
     */
  public static final String PROPOSED_BY = "PROPOSED_BY";

    /**
     * The date the news item should be published
     */
  public static final String PUBLISH_ON = "PUBLISH_ON";

    /**
     * The date the news item should be removed
     */
  public static final String REMOVE_ON = "REMOVE_ON";

    /**
     * The priority of the news item 
     */
  public static final String PRIORITY = "PRIORITY";

    /**
     * The event date of the news item 
     */
  public static final String EVENT_DATE = "EVENT_DATE";

    /**
     * The logger instance for all instances of this class.
     */
  private static Log log = new Log ("newsMgr", "ProjectNewsManager");

    /**
     * Whether we want debugging information.
     */
  private static boolean debug = true;


    /**
     * Creates a new instance.
     *
     * @@param dataMgr The manager of this instance.
     */
  public ProjectNewsManager (DataManager dataMgr)
  {
    super (dataMgr);
  }

    /**
     * Gets a list of news items for a given project 
     * If approvedBy has not been passed, pass a null to method
     *
     * @@param conn The JDBC database conn to use.
     * @@param projectID    The database key of the project to get news for
     * @@return	         The dataset of news items
     *
     * @@exception	SQLException
     * @@exception	DataSetException
     */
  public DataSet getNewsForProject(Connection conn, String projectID)
    throws DataSetException, SQLException, JoistDatabaseException
    {
       return getNewsForProject(conn, projectID, null);
    }

    /**
     * Gets a list of news items for a given project
     *
     * @@param conn The JDBC database connection to use.
     * @@param projectID    The database key of the project to get news for
     * @@param approvedBy   Id of person who has approved news item
     * @@return	         The dataset of news items
     *
     * @@exception	SQLException
     * @@exception	DataSetException
     */
  public DataSet getNewsForProject (Connection conn, String projectID, 
                                    String approvedBy)
    throws DataSetException, SQLException, JoistDatabaseException
  {
    String action = "Getting news items for projectID=" + projectID;
    TableDataSet newsItems = null;
    try
    {
      newsItems = new TableDataSet (conn, TABLE_NAME);
      StringBuffer whereClause = new StringBuffer(PROJECT_ID + '=' + projectID);
      if (approvedBy != null)
      {
          whereClause.append(" and " + APPROVED_BY + '=' + approvedBy); 
      }
      newsItems.where(whereClause.toString());
      newsItems.order (EVENT_DATE + " desc");
      newsItems.fetchRecords ();
    }
    catch (DataSetException e)
    {
      log.exception (e);
      if (debug)
	log.debug (action + ": " + e.getMessage ());
      throw e;
    }
    catch (SQLException e)
    {
      log.exception (e);
      if (debug)
	log.debug (action + ": " + e.getMessage ());
      throw e;
    }
    finally
    {
      registerToClose (newsItems);
    }

    return newsItems;
  }

    public String getNewsQuery()
    {
        return "SELECT * FROM " + TABLE_NAME;
    }

    public String getNewsForProjectQuery(Connection conn,
                                         String projectID)
        throws SQLException, DataSetException, JoistDatabaseException
    {
        Criterion c = new Criterion(PROJECT_ID, projectID);
        return getNewsQuery() + " WHERE " + c.toString();
    }

    public String getUnapprovedNewsForProjectQuery(Connection conn,
                                                   String projectID)
        throws SQLException, DataSetException, JoistDatabaseException
    {
        UserUserGroupManager usrGrpMgr = 
            (UserUserGroupManager)getDataManager().getManager
            ("org.tigris.helm.database.UserUserGroupManager");
        String nobodyID = usrGrpMgr.getNobodyUserID(conn);
        Criterion c = new Criterion(APPROVED_BY, Criterion.EXACT_MATCH, 
                                    nobodyID);
        return getNewsForProjectQuery(conn, projectID) + " AND " + c.toString();
    }

    /**
     * Gets a list of news items for a given domain
     *
     * @@param conn The JDBC database connection to use.
     * @@param domain    The database key of the domain to get news for
     * @@return	         The dataset of news items
     *
     * @@exception	SQLException
     * @@exception	DataSetException
     */
  public DataSet getNewsForDomain (Connection conn, String domainID) 
    throws DataSetException, SQLException
  {
    String action = "Getting news items for domain " + domainID;
    DataManager dMgr = getDataManager();
    ProjectManager pMgr = (ProjectManager)
       dMgr.getManager("org.tigris.helm.database.ProjectManager");
    String otherTable =  pMgr.TABLE_NAME;
    String otherProjectID = otherTable + "." + pMgr.PROJECT_ID;
    String otherDomainID = otherTable + "." + pMgr.PROJECT_DOMAIN_ID;
    DateFormat normalFormat = new SimpleDateFormat("MMMM dd, yyyy");

    QueryDataSet newsItems = null;
    try
    {
        StringBuffer q = new StringBuffer();
        q.append("select ").append(EVENT_DATE)
	  .append(",").append(HEADLINE).append(",").append(BODY);
	q.append(",").append(NEWS_ID).append(" from ")
          .append(TABLE_NAME).append(", ").append(otherTable);
        q.append(" where ").append(TABLE_NAME)
	  .append(".").append(PROJECT_ID);
         q.append("=").append(otherProjectID);
        q.append(" and ").append(otherDomainID)
          .append("=").append(domainID);
	  
        newsItems = new QueryDataSet(conn, q.toString());
        newsItems.fetchRecords();
    }
    catch (DataSetException e)
    {
      log.exception (e);
      if (debug)
	log.debug (action + ": " + e.getMessage ());
      throw e;
    }
    catch (SQLException e)
    {
      log.exception (e);
      if (debug)
	log.debug (action + ": " + e.getMessage ());
      throw e;
    }
    finally
    {
      registerToClose (newsItems);
    }

    return newsItems;
  }

    /**
     * Gets a news item by ID
     *
     * @@param conn The JDBC database connection to use.
     * @@param newsID    The database key of the news item
     * @@return	        The news item
     *
     * @@exception	SQLException
     * @@exception	DataSetException
     */
  public Record getNewsItemForID (Connection conn, String newsID)
    throws DataSetException, SQLException
  {
    String action = "Getting news items for newsID=" + newsID;

    TableDataSet newsItem = null;
    try
    {
      newsItem = new TableDataSet(conn, TABLE_NAME);
      newsItem.where(NEWS_ID + "=" + newsID);
      newsItem.fetchRecords ();
    }
    catch (DataSetException e)
    {
      log.exception (e);
      if (debug)
	log.debug (action + ": " + e.getMessage ());
      throw e;
    }
    catch (SQLException e)
    {
      log.exception (e);
      if (debug)
	log.debug (action + ": " + e.getMessage ());
      throw e;
    }
    finally
    {
      registerToClose (newsItem);
    }

    return newsItem.getRecord(0);
  }

    /**
     * Updates an existing newsItem or adds a new newsItem to the database 
     * (depending on whether given a <code>newsID</code> or not).
     *
     * @@param conn The JDBC database connection to use.
     * @@param newsID    The database key of the news item to update, or 
     *                   <code>null</code> if the news item is new.
     * @@return	         The system-assigned news ID for the news item updated.
     *
     * @@exception	SQLException
     * @@exception	DataSetException
     */
  public Record updateNews (Connection conn,
			               String newsID, String projectID,
			               Date eventDate, String headline,
			               String body, String approvedBy, 
			               Date publishOn, Date removeOn, 
			               String priority, String proposedBy)
    throws SQLException, DataSetException
  {
    Record newsItem = null;
    TableDataSet newsItems = null;

    try
    {
      newsItems = new TableDataSet (conn, TABLE_NAME,
				    new KeyDef ().addAttrib (NEWS_ID));

      if (newsID != null)
      {
	      // Updates existing news item
	     if (debug)
	        log.info ("Updating news item news_ID=" + newsID);
	     newsItems.where (NEWS_ID + '=' + newsID);
	     newsItems.fetchRecords();
	     newsItem = newsItems.getRecord(0);
      }
      else
      {
	     // Adding new news item
	     if (debug)
	        log.debug ("Adding new news item");
	     newsItem = newsItems.addRecord();
      }

      // Do update
      setField (newsItem, PROJECT_ID, projectID);
      if (eventDate != null) newsItem.setValue (EVENT_DATE, eventDate);
      setField (newsItem, HEADLINE, headline);
      setField (newsItem, BODY, body);
      setField (newsItem, APPROVED_BY, approvedBy);
      if (publishOn != null) newsItem.setValue (PUBLISH_ON, publishOn);
      if (removeOn != null) newsItem.setValue (REMOVE_ON, removeOn);
      setField (newsItem, PRIORITY, priority);
      if (proposedBy != null) setField (newsItem, PROPOSED_BY, proposedBy);
      newsItem.save ();
      if (newsID == null)
      {
         newsID = getLastInsertedID(conn).toString();
         newsItem.setValue(NEWS_ID, newsID);
      }
    }
    catch (DataSetException e)
    {
      log.exception (e);
      String message = "Editing news item : " + e.getMessage ();
      if (debug)
	log.debug (message);
      throw e;
    }
    catch (SQLException e)
    {
      log.exception (e);
      String message = "Editing news item: " + e.getMessage ();
      if (debug) log.debug (message);
      throw e;
    }
    finally
    {
      registerToClose (newsItems);
    }

    return newsItem;
  }

    /**
     * Retrieves the most recent ten news items for the projects
     * Belonging to a User
     * @@param	conn    A JDBC database connection
     * @@param	userID        The userID to get projects for.
     * @@return	 a DataSet of fields
     * @@exception	SQLException
     * @@exception	DataSetException
     */
  public DataSet getNewsItemsForUser (Connection conn, String userID)
    throws SQLException, DataSetException, JoistDatabaseException
  {
    String action = "Getting News Items for User";
    QueryDataSet newsItems = null;
    DataManager dMgr = getDataManager();
    UserUserGroupManager usrGrpMgr = (UserUserGroupManager)
       dMgr.getManager("org.tigris.helm.database.UserUserGroupManager");
    String nobodyID = usrGrpMgr.getNobodyUserID(conn);

    StringBuffer stmt =
      new StringBuffer ("select distinct news.").append (NEWS_ID);
      stmt.append (", news.").append (EVENT_DATE);
      stmt.append (", news.").append (HEADLINE).append (", urp.");
      stmt.append (PROJECT_ID).append (", p.name FROM ");
      stmt.append (TABLE_NAME).append (" news, ");
      stmt.append ("HELM_PROJECT p, HELM_USER_ROLE_PROJECT urp WHERE ");
      stmt.append ("urp.user_id = ").append (userID);
      stmt.append (" and p.project_id = urp.project_id and news.");
      stmt.append (PROJECT_ID).append (" = p.project_id ");
      stmt.append ("and news.");
      stmt.append(APPROVED_BY).append(" !=").append(nobodyID);
      stmt.append (" ORDER BY news.").append (EVENT_DATE).append (" DESC");

    if (debug)
        log.info ("SQL=" + stmt.toString ());
    try
    {
      newsItems = new QueryDataSet (conn, stmt.toString ());
    }
    catch (DataSetException e)
    {
      log.exception (e);
      if (debug)
	  log.debug (action + e.getMessage ());
      throw e;
    }
    catch (SQLException e)
    {
      log.exception (e);
      if (debug)
	log.debug (action + e.getMessage ());
      throw e;
    }
    finally
    {
      registerToClose(newsItems);
    }
    return newsItems.fetchRecords();
  }

    /**
     * Approves the news item in the name of the given userID.
     *
     * @@param conn  The JDBC database connection to use.
     * @@param newsID   The news item to approve.
     * @@param userID      The user approving the project.
     * @@return  The system-assigned project ID for the project.
     *
     * @@exception SQLException
     * @@exception DataSetException 
     */
    public void approveNewsItem(Connection conn, String newsID, String userID)
        throws SQLException, DataSetException, JoistDatabaseException
    {
        updateNews (conn, newsID, null, null, null, null, 
                    userID, null, null, null, null);
        /*
        Record newsItem = getNewsItemForID(conn, newsID);
        newsItem.setValue(APPROVED_BY, userID);
        newsItem.save();
        */
    }

    /**
     * Deletes an existing news item from the database
     *
     * @@param      conn    the JDBC database connection
     * @@param      newsID       the ID of the news item to delete
     * @@exception SQLException
     */
    public void  deleteNewsItem (Connection conn, String newsID)
        throws SQLException, DataSetException
    {
        String action = "Deleting News";
        TableDataSet newsItems = null;
        try
        {
            newsItems = new TableDataSet (conn, TABLE_NAME,
				        new KeyDef ().addAttrib (NEWS_ID));
	    newsItems.where (NEWS_ID + '=' + newsID);
	    newsItems.fetchRecords();
            if (newsItems.containsRecord(0)) 
            {
                Record r = newsItems.getRecord(0);
                r.markToBeDeleted();
                r.save();
            }
            
        }
        catch (DataSetException e)
        {
            log.exception(e);
            if (debug) log.debug(action + ": " + newsID + ": " + 
                                 e.getMessage());
            throw e;
        }
        catch (SQLException e)
        {
            log.exception(e);
            if (debug) log.debug(action + ": " + newsID + ": " + 
                                 e.getMessage());
            throw e;
        }
        finally
        {
            registerToClose(newsItems);
        }
    }

}
@


1.16
log
@added ID to record when adding a new news item
@
text
@d64 1
a64 1
 * @@version $Id: ProjectNewsManager.java,v 1.15 2001/01/26 18:29:00 edk Exp $
@


1.15
log
@readding all the files as part of the process of returning to the way
things were as of tuesday
@
text
@d64 1
a64 1
 * @@version $Id: ProjectNewsManager.java,v 1.8 2000/12/29 17:11:52 leonardr Exp $
d404 5
d422 1
a422 2
      if (debug)
	log.debug (message);
@


1.15.2.1
log
@Porting to the Turbine Peer system.  -dlr and leonardr
@
text
@d64 1
a64 1
 * @@version $Id: ProjectNewsManager.java,v 1.15 2001/01/26 18:29:00 edk Exp $
@


1.14
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
@d64 1
a64 1
 * @@version $Id: ProjectNewsManager.java,v 1.13 2001/01/25 04:30:00 stack Exp $
d136 2
a137 1
    private static boolean debug = true;
d144 4
a147 33
    public ProjectNewsManager (DataManager dataMgr)
    {
        super (dataMgr, new KeyDef().addAttrib(NEWS_ID));
    }

    private static String DEFAULT_ORDER_BY = 
        TABLE_NAME + "." + EVENT_DATE + " desc";

    public String getNewsQuery()
    {
        return "SELECT * FROM " + TABLE_NAME;
    }

    public String getNewsForProjectQuery (String projectID)
        throws DBException
    {
        Criterion c = new Criterion(PROJECT_ID, projectID);
        return getNewsQuery() + " WHERE " + c.toString();
    }

    public String getUnapprovedNewsForProjectQuery(String projectID)
        throws DBException
    {
        UserManager uMgr = (UserManager)getDataManager().getManager
            ("org.tigris.helm.database.UserManager");
        String nobodyID = uMgr.getNobodyUserID();
        Criterion c = new Criterion(APPROVED_BY, nobodyID);
        return getNewsForProjectQuery(projectID) + " AND " + c.toString();
    }

    ////////////////////////////////////////////////////////////////
    // Accessor methods.
    ////////////////////////////////////////////////////////////////
d151 1
d153 1
d157 2
a158 1
     * @@exception DBException if a database error occurs.
d160 2
a161 2
    public DataSet getNewsForProject(String projectID)
        throws DBException
d163 1
a163 2
        Criterion c = new Criterion(PROJECT_ID, projectID);
        return getMatchingRecords(c);
d169 1
d174 2
a175 1
     * @@exception DBException if a database error occurs.
d177 48
a224 2
    public DataSet getNewsForProject (String projectID, String approvedBy)
        throws DBException
d227 14
a240 2
        c.add(new Criterion(APPROVED_BY, approvedBy));
        return getMatchingRecords(c);
d246 1
d250 2
a251 1
     * @@exception DBException if a database error occurs.
d253 46
a298 8
    public DataSet getNewsForDomain (String domainID) 
        throws DBException, DoesNotExist
    {       
        ProjectManager pMgr = (ProjectManager)
            dMgr.getManager("org.tigris.helm.database.ProjectManager");
        String domainProjectID = pMgr.getDomainProjectID(domainID);
        Criterion c = new Criterion(PROJECT_ID, domainProjectID);
        return getMatchingRecords(c);
d301 3
d311 2
a312 1
     * @@exception DBException
d314 7
a320 2
    public Record getNewsItemForID (String newsID)
        throws DBException, DoesNotExist;
d322 3
a324 6
        Criterion c = new Criterion(NEWS_ID, newsID);
        Record item = getFirstMatchingRecord(c);
        if (item == null)
        {
            throw new DoesNotExist("News item with ID " + newsID);
        }
d326 1
a326 16

    /**
     * Retrieves the most recent ten news items for the projects
     * Belonging to a User
     *
     * <b>TODO:</b> Make this use Criterion objects and have it get all
     * the news items that the user can view, as opposed to those
     * in certain projects.
     *
     * @@param	conn    A JDBC database connection
     * @@param	userID        The userID to get projects for.
     * @@return	 a DataSet of fields
     * @@exception DBException
     */
    public DataSet getNewsItemsForUser (String userID)
        throws DBException
d328 4
a331 54
        QueryDataSet newsItems = null;

        DBConnection dbConn = null;
        Connection conn = null;
        try {
            conn = dbconn.getConnection();
        } catch (Exception e) {
            throw new DBException(e);
        }
        
        DataManager dMgr = getDataManager();
        UserUserGroupManager usrGrpMgr = (UserUserGroupManager)
            dMgr.getManager("org.tigris.helm.database.UserUserGroupManager");
        String nobodyID = usrGrpMgr.getNobodyUserID(conn);

        StringBuffer stmt =
            new StringBuffer ("select distinct news.*").append (NEWS_ID);
        stmt.append (", news.").append (EVENT_DATE);
        stmt.append (", news.").append (HEADLINE).append (", urp.");
        stmt.append (PROJECT_ID).append (", p.name FROM ");
        stmt.append (TABLE_NAME).append (" news, ");
        stmt.append ("HELM_PROJECT p, HELM_USER_ROLE_PROJECT urp WHERE ");
        stmt.append ("urp.user_id = ").append (userID);
        stmt.append (" and p.project_id = urp.project_id and news.");
        stmt.append (PROJECT_ID).append (" = p.project_id ");
        stmt.append ("and news.");
        stmt.append(APPROVED_BY).append(" !=").append(nobodyID);
        stmt.append (" ORDER BY news.").append (EVENT_DATE).append (" DESC");

        if (debug)
            log.info ("SQL=" + stmt.toString ());
        try
        {
            newsItems = new QueryDataSet (conn, stmt.toString ());
            newsItems.fetchRecords();
        }
        catch (DataSetException e)
        {
            throw new DBException(e);
        }
        catch (SQLException e)
        {
            throw new DBException(e);
        }
        finally
        {
            registerToClose(newsItems);
            try {
                TurbineDB.releaseConnection(dbConn);
            } catch (Exception e) {
                throw new DBException(e);
            }
        }
        return newsitems;
d333 1
a333 13

    /**
     * Returns the first record matching a given Criterion. 
     *
     * @@param criterion Criterion to use in select.
     *
     * @@exception DBException if a database error occurs.
     *
     * @@return Null if no matching record, first record in recordset
     * otherwise.  
     */
    private Record getFirstMatchingRecord(Criterion criterion)
        throws DBException
d335 4
a338 12
        Record r = null;
        try {
            DataSet s = getRecords(criterion);
            if (s != null && s.containsRecord(0))
            {
                r = s.getRecord(0);
            }
        } catch (DataSetException e) {
            throw new DBException(e);
        }

        return r;
d340 1
a340 10

    /**
     * Returns records matching a given Criterion.
     *
     * @@param criterion Criterion to use in select.
     *
     * @@exception DBException if a database error occurs.
     */
    public DataSet getRecords(Criterion criterion)
    throws DBException
d342 1
a342 7
        DataSet s = null;
        try {
            s = runSelect(tableName, criterion, PROJECT_NAME);
        } catch (Exception e) {
            throw new DBException(e);
        }
        return s;
d345 2
a346 3
    ////////////////////////////////////////////////////////////////
    // Mutator methods.
    ////////////////////////////////////////////////////////////////
d352 1
d355 1
a355 1
     * @@return	         The updated record for the specified newsItem.
d357 2
d360 62
a421 6
    public Record updateNews (String newsID, String projectID,
                              Date eventDate, String headline,
                              String body, String approvedBy, 
                              Date publishOn, Date removeOn, 
                              String priority, String proposedBy)
        throws DoesNotExist, DBException
d423 2
a424 3
        DBConnection dbConn = null;
        TableDataSet newsItems = null;
        Record newsItem = null;
d426 2
a427 14
        try
        {
            if (newsID != null)
            {
                newsItem = getNewsItemForID(newsID);
            } else {
                try {
                    dbConn = TurbineDB.getConnection();
                } catch (Exception e) {
                    throw new DBException(e);
                }
                newsItems = new TableDataSet(conn, TABLE_NAME, keydef);
                newsItem = newsItems.addRecord();
            }
d429 56
a484 25
            // Do update
            setField (newsItem, PROJECT_ID, projectID);
            if (eventDate != null) newsItem.setValue (EVENT_DATE, eventDate);
            setField (newsItem, HEADLINE, headline);
            setField (newsItem, BODY, body);
            setField (newsItem, APPROVED_BY, approvedBy);
            if (publishOn != null) newsItem.setValue (PUBLISH_ON, publishOn);
            if (removeOn != null) newsItem.setValue (REMOVE_ON, removeOn);
            setField (newsItem, PRIORITY, priority);
            if (proposedBy != null) setField (newsItem, PROPOSED_BY, proposedBy);
            newsItem.save();
        } catch (DataSetException e) {
            throw new DBException(e);
        } catch (SQLException e) {
            throw new DBException(e);
        } finally {
            registerToClose (newsItems);
            try {
                TurbineDB.releaseConnection(dbConn);
            } catch (Exception e) {
                throw new DBException(e);
            }
        }

        return newsItem;
d486 2
d492 1
d497 2
a498 1
     * @@exception DBException
d500 2
a501 2
    public Record approveNewsItem(String newsID, String userID)
        throws DBException
d503 7
a509 10
        Record newsItem = getNewsItemForID(newsID);
        try {
            newsItem.setValue(APPROVED_BY, userID);
            newsItem.save();
        } catch (DataSetException e) {
            throw new DBException(e);
        } catch (SQLException e) {
            throw new DBException(e);
        }
        return newsItem;
d515 1
d517 1
a517 2
     *
     * @@exception DBException
d519 2
a520 2
    public void  deleteNewsItem (String newsID)
        throws DBException
d522 3
a524 2
        Record item = getItemForID(newsID);
        if (item != null)
d526 9
a534 7
            try {
                item.markToBeDeleted();
                item.save();
            } catch (DataSetException e) {
                throw new DBException(e);
            } catch (SQLException e) {
                throw new DBException(e);
d536 19
d557 1
@


1.13
log
@Syntax errors (missing semi-colon and misquoting of string concatenation)
@
text
@d64 1
a64 1
 * @@version $Id: ProjectNewsManager.java,v 1.12 2001/01/25 02:53:24 leonardr Exp $
@


1.12
log
@More converted TableManagers.
@
text
@d64 1
a64 1
 * @@version $Id: ProjectNewsManager.java,v 1.11 2001/01/25 01:42:10 leonardr Exp $
d149 1
a149 1
        TABLE_NAME + "." + EVENT_DATE + " desc"
@


1.11
log
@Added basic record obtaining methods.
@
text
@d64 1
a64 1
 * @@version $Id: ProjectNewsManager.java,v 1.10 2001/01/24 22:24:36 leonardr Exp $
d148 29
a178 1
     * If approvedBy has not been passed, pass a null to method
a179 1
     * @@param conn The JDBC database conn to use.
d183 1
a183 2
     * @@exception	SQLException
     * @@exception	DataSetException
d185 1
a185 1
    public DataSet getNewsForProject(Connection conn, String projectID)
d188 2
a189 1
        return getNewsForProject(conn, projectID, null);
a194 1
     * @@param conn The JDBC database connection to use.
d199 1
a199 2
     * @@exception	SQLException
     * @@exception	DataSetException
d201 1
a201 2
    public DataSet getNewsForProject (Connection conn, String projectID, 
                                      String approvedBy)
d204 3
a206 29
        String action = "Getting news items for projectID=" + projectID;
        TableDataSet newsItems = null;
        try
        {
            newsItems = new TableDataSet (conn, TABLE_NAME);
            StringBuffer whereClause = new StringBuffer(PROJECT_ID);
            whereClause.append('=').append(projectID);
            if (approvedBy != null)
            {
                whereClause.append(" and " + APPROVED_BY + '=' + approvedBy); 
            }
            newsItems.where(whereClause.toString());
            newsItems.order (EVENT_DATE + " desc");
            newsItems.fetchRecords ();
        }
        catch (DataSetException e)
        {
            throw new DBException(e);
        }
        catch (SQLException e)
        {
            throw new DBException(e);
        }
        finally
        {
            registerToClose (newsItems);
        }

        return newsItems;
d209 16
a224 3
    public String getNewsQuery()
    {
        return "SELECT * FROM " + TABLE_NAME;
d227 11
a237 2
    public String getNewsForProjectQuery (Connection conn, String projectID)
        throws DBException
d239 6
a244 15
        Criterion c = new Criterion(PROJECT_ID, projectID);
        return getNewsQuery() + " WHERE " + c.toString();
    }

    public String getUnapprovedNewsForProjectQuery(Connection conn,
                                                   String projectID)
        throws DBException
    {
        UserUserGroupManager usrGrpMgr = 
            (UserUserGroupManager)getDataManager().getManager
            ("org.tigris.helm.database.UserUserGroupManager");
        String nobodyID = usrGrpMgr.getNobodyUserID(conn);
        Criterion c = new Criterion(APPROVED_BY, Criterion.EXACT_MATCH, 
                                    nobodyID);
        return getNewsForProjectQuery(conn, projectID) + " AND " + c.toString();
d248 2
a249 1
     * Gets a list of news items for a given domain
d251 3
a253 3
     * @@param conn The JDBC database connection to use.
     * @@param domain    The database key of the domain to get news for
     * @@return	         The dataset of news items
d255 4
a258 2
     * @@exception	SQLException
     * @@exception	DataSetException
d260 1
a260 1
    public DataSet getNewsForDomain (Connection conn, String domainID) 
d263 10
a272 1
        String action = "Getting news items for domain " + domainID;
d274 17
a290 6
        ProjectManager pMgr = (ProjectManager)
            dMgr.getManager("org.tigris.helm.database.ProjectManager");
        String otherTable =  pMgr.TABLE_NAME;
        String otherProjectID = otherTable + "." + pMgr.PROJECT_ID;
        String otherDomainID = otherTable + "." + pMgr.PROJECT_DOMAIN_ID;
        DateFormat normalFormat = new SimpleDateFormat("MMMM dd, yyyy");
d292 2
a293 1
        QueryDataSet newsItems = null;
d296 1
a296 12
            StringBuffer q = new StringBuffer();
            q.append("select ").append(EVENT_DATE)
                .append(",").append(HEADLINE).append(",").append(BODY);
            q.append(",").append(NEWS_ID).append(" from ")
                .append(TABLE_NAME).append(", ").append(otherTable);
            q.append(" where ").append(TABLE_NAME)
                .append(".").append(PROJECT_ID);
            q.append("=").append(otherProjectID);
            q.append(" and ").append(otherDomainID)
                .append("=").append(domainID);
	  
            newsItems = new QueryDataSet(conn, q.toString());
d309 6
a314 1
            registerToClose (newsItems);
d316 1
a316 2

        return newsItems;
d320 3
a322 1
     * Gets a news item by ID
d324 1
a324 3
     * @@param conn The JDBC database connection to use.
     * @@param newsID    The database key of the news item
     * @@return	        The news item
d326 2
a327 1
     * @@exception DBException
d329 1
a329 1
    public Record getNewsItemForID (Connection conn, String newsID)
d332 8
a339 11
        String action = "Getting news items for newsID=" + newsID;

        TableDataSet newsItem = null;
        try
        {
            newsItem = new TableDataSet(conn, TABLE_NAME);
            newsItem.where(NEWS_ID + "=" + newsID);
            newsItem.fetchRecords ();
        }
        catch (DataSetException e)
        {
d342 18
a359 2
        catch (SQLException e)
        {
d362 2
a363 4
        finally
        {
            registerToClose (newsItem);
        }
d365 3
a367 2
        return newsItem.getRecord(0);
    }
a372 1
     * @@param conn The JDBC database connection to use.
d375 1
a375 1
     * @@return	         The system-assigned news ID for the news item updated.
a376 2
     * @@exception	SQLException
     * @@exception	DataSetException
d378 1
a378 2
    public Record updateNews (Connection conn,
                              String newsID, String projectID,
d383 1
a383 1
        throws DBException
d385 2
a387 1
        TableDataSet newsItems = null;
a390 2
            newsItems = new TableDataSet (conn, TABLE_NAME, keydef);

d393 8
a400 12
                // Updates existing news item
                if (debug)
                    log.info ("Updating news item news_ID=" + newsID);
                newsItems.where (NEWS_ID + '=' + newsID);
                newsItems.fetchRecords();
                newsItem = newsItems.getRecord(0);
            }
            else
            {
                // Adding new news item
                if (debug)
                    log.debug ("Adding new news item");
d414 2
a415 4
            newsItem.save ();
        }
        catch (DataSetException e)
        {
d417 1
a417 3
        }
        catch (SQLException e)
        {
d419 1
a419 3
        }
        finally
        {
d421 5
a431 54
     * Retrieves the most recent ten news items for the projects
     * Belonging to a User
     * @@param	conn    A JDBC database connection
     * @@param	userID        The userID to get projects for.
     * @@return	 a DataSet of fields
     * @@exception	SQLException
     * @@exception	DataSetException
     */
    public DataSet getNewsItemsForUser (Connection conn, String userID)
        throws DBException
    {
        String action = "Getting News Items for User";
        QueryDataSet newsItems = null;
        DataManager dMgr = getDataManager();
        UserUserGroupManager usrGrpMgr = (UserUserGroupManager)
            dMgr.getManager("org.tigris.helm.database.UserUserGroupManager");
        String nobodyID = usrGrpMgr.getNobodyUserID(conn);

        StringBuffer stmt =
            new StringBuffer ("select distinct news.").append (NEWS_ID);
        stmt.append (", news.").append (EVENT_DATE);
        stmt.append (", news.").append (HEADLINE).append (", urp.");
        stmt.append (PROJECT_ID).append (", p.name FROM ");
        stmt.append (TABLE_NAME).append (" news, ");
        stmt.append ("HELM_PROJECT p, HELM_USER_ROLE_PROJECT urp WHERE ");
        stmt.append ("urp.user_id = ").append (userID);
        stmt.append (" and p.project_id = urp.project_id and news.");
        stmt.append (PROJECT_ID).append (" = p.project_id ");
        stmt.append ("and news.");
        stmt.append(APPROVED_BY).append(" !=").append(nobodyID);
        stmt.append (" ORDER BY news.").append (EVENT_DATE).append (" DESC");

        if (debug)
            log.info ("SQL=" + stmt.toString ());
        try
        {
            newsItems = new QueryDataSet (conn, stmt.toString ());
        }
        catch (DataSetException e)
        {
            throw new DBException(e);
        }
        catch (SQLException e)
        {
            throw new DBException(e);
        }
        finally
        {
            registerToClose(newsItems);
        }
        return newsItems.fetchRecords();
    }

    /**
a433 1
     * @@param conn  The JDBC database connection to use.
d440 1
a440 1
    public void approveNewsItem(Connection conn, String newsID, String userID)
d443 10
a452 7
        updateNews (conn, newsID, null, null, null, null, 
                    userID, null, null, null, null);
        /*
        Record newsItem = getNewsItemForID(conn, newsID);
        newsItem.setValue(APPROVED_BY, userID);
        newsItem.save();
        */
a457 1
     * @@param      conn    the JDBC database connection
d462 1
a462 1
    public void  deleteNewsItem (Connection conn, String newsID)
d465 2
a466 3
        String action = "Deleting News";
        TableDataSet newsItems = null;
        try
d468 7
a474 8
            newsItems = new TableDataSet (conn, TABLE_NAME, keydef);
	    newsItems.where (NEWS_ID + '=' + newsID);
	    newsItems.fetchRecords();
            if (newsItems.containsRecord(0)) 
            {
                Record r = newsItems.getRecord(0);
                r.markToBeDeleted();
                r.save();
a475 13
            
        }
        catch (DataSetException e)
        {
            throw new DBException(e);
        }
        catch (SQLException e)
        {
            throw new DBException(e);
        }
        finally
        {
            registerToClose(newsItems);
@


1.10
log
@Moved TableManagers to new keydef constructor and keydef-less runSelect.
@
text
@d64 1
a64 1
 * @@version $Id: ProjectNewsManager.java,v 1.9 2001/01/24 20:42:46 dlr Exp $
d136 1
a136 2
  private static boolean debug = true;

@


1.9
log
@Making use of DBException.
@
text
@d64 1
a64 1
 * @@version $Id: ProjectNewsManager.java,v 1.8 2000/12/29 17:11:52 leonardr Exp $
d144 4
a147 4
  public ProjectNewsManager (DataManager dataMgr)
  {
    super (dataMgr);
  }
d354 1
a354 2
            newsItems = new TableDataSet (conn, TABLE_NAME,
                                          new KeyDef ().addAttrib (NEWS_ID));
d492 1
a492 2
            newsItems = new TableDataSet (conn, TABLE_NAME,
				        new KeyDef ().addAttrib (NEWS_ID));
@


1.8
log
@Many, many pagination changes.
@
text
@d64 1
a64 1
 * @@version $Id: ProjectNewsManager.java,v 1.7 2000/12/19 19:52:42 elicia Exp $
d160 2
a161 2
  public DataSet getNewsForProject(Connection conn, String projectID)
    throws DataSetException, SQLException, JoistDatabaseException
d163 1
a163 1
       return getNewsForProject(conn, projectID, null);
d177 3
a179 7
  public DataSet getNewsForProject (Connection conn, String projectID, 
                                    String approvedBy)
    throws DataSetException, SQLException, JoistDatabaseException
  {
    String action = "Getting news items for projectID=" + projectID;
    TableDataSet newsItems = null;
    try
d181 29
a209 27
      newsItems = new TableDataSet (conn, TABLE_NAME);
      StringBuffer whereClause = new StringBuffer(PROJECT_ID + '=' + projectID);
      if (approvedBy != null)
      {
          whereClause.append(" and " + APPROVED_BY + '=' + approvedBy); 
      }
      newsItems.where(whereClause.toString());
      newsItems.order (EVENT_DATE + " desc");
      newsItems.fetchRecords ();
    }
    catch (DataSetException e)
    {
      log.exception (e);
      if (debug)
	log.debug (action + ": " + e.getMessage ());
      throw e;
    }
    catch (SQLException e)
    {
      log.exception (e);
      if (debug)
	log.debug (action + ": " + e.getMessage ());
      throw e;
    }
    finally
    {
      registerToClose (newsItems);
a211 3
    return newsItems;
  }

d217 2
a218 3
    public String getNewsForProjectQuery(Connection conn,
                                         String projectID)
        throws SQLException, DataSetException, JoistDatabaseException
d226 1
a226 1
        throws SQLException, DataSetException, JoistDatabaseException
d247 25
a271 25
  public DataSet getNewsForDomain (Connection conn, String domainID) 
    throws DataSetException, SQLException
  {
    String action = "Getting news items for domain " + domainID;
    DataManager dMgr = getDataManager();
    ProjectManager pMgr = (ProjectManager)
       dMgr.getManager("org.tigris.helm.database.ProjectManager");
    String otherTable =  pMgr.TABLE_NAME;
    String otherProjectID = otherTable + "." + pMgr.PROJECT_ID;
    String otherDomainID = otherTable + "." + pMgr.PROJECT_DOMAIN_ID;
    DateFormat normalFormat = new SimpleDateFormat("MMMM dd, yyyy");

    QueryDataSet newsItems = null;
    try
    {
        StringBuffer q = new StringBuffer();
        q.append("select ").append(EVENT_DATE)
	  .append(",").append(HEADLINE).append(",").append(BODY);
	q.append(",").append(NEWS_ID).append(" from ")
          .append(TABLE_NAME).append(", ").append(otherTable);
        q.append(" where ").append(TABLE_NAME)
	  .append(".").append(PROJECT_ID);
         q.append("=").append(otherProjectID);
        q.append(" and ").append(otherDomainID)
          .append("=").append(domainID);
d273 17
a289 20
        newsItems = new QueryDataSet(conn, q.toString());
        newsItems.fetchRecords();
    }
    catch (DataSetException e)
    {
      log.exception (e);
      if (debug)
	log.debug (action + ": " + e.getMessage ());
      throw e;
    }
    catch (SQLException e)
    {
      log.exception (e);
      if (debug)
	log.debug (action + ": " + e.getMessage ());
      throw e;
    }
    finally
    {
      registerToClose (newsItems);
a291 3
    return newsItems;
  }

d299 1
a299 2
     * @@exception	SQLException
     * @@exception	DataSetException
d301 24
a324 4
  public Record getNewsItemForID (Connection conn, String newsID)
    throws DataSetException, SQLException
  {
    String action = "Getting news items for newsID=" + newsID;
d326 1
a326 24
    TableDataSet newsItem = null;
    try
    {
      newsItem = new TableDataSet(conn, TABLE_NAME);
      newsItem.where(NEWS_ID + "=" + newsID);
      newsItem.fetchRecords ();
    }
    catch (DataSetException e)
    {
      log.exception (e);
      if (debug)
	log.debug (action + ": " + e.getMessage ());
      throw e;
    }
    catch (SQLException e)
    {
      log.exception (e);
      if (debug)
	log.debug (action + ": " + e.getMessage ());
      throw e;
    }
    finally
    {
      registerToClose (newsItem);
a328 3
    return newsItem.getRecord(0);
  }

d341 32
a372 10
  public Record updateNews (Connection conn,
			               String newsID, String projectID,
			               Date eventDate, String headline,
			               String body, String approvedBy, 
			               Date publishOn, Date removeOn, 
			               String priority, String proposedBy)
    throws SQLException, DataSetException
  {
    Record newsItem = null;
    TableDataSet newsItems = null;
d374 24
a397 4
    try
    {
      newsItems = new TableDataSet (conn, TABLE_NAME,
				    new KeyDef ().addAttrib (NEWS_ID));
d399 1
a399 48
      if (newsID != null)
      {
	      // Updates existing news item
	     if (debug)
	        log.info ("Updating news item news_ID=" + newsID);
	     newsItems.where (NEWS_ID + '=' + newsID);
	     newsItems.fetchRecords();
	     newsItem = newsItems.getRecord(0);
      }
      else
      {
	     // Adding new news item
	     if (debug)
	        log.debug ("Adding new news item");
	     newsItem = newsItems.addRecord();
      }

      // Do update
      setField (newsItem, PROJECT_ID, projectID);
      if (eventDate != null) newsItem.setValue (EVENT_DATE, eventDate);
      setField (newsItem, HEADLINE, headline);
      setField (newsItem, BODY, body);
      setField (newsItem, APPROVED_BY, approvedBy);
      if (publishOn != null) newsItem.setValue (PUBLISH_ON, publishOn);
      if (removeOn != null) newsItem.setValue (REMOVE_ON, removeOn);
      setField (newsItem, PRIORITY, priority);
      if (proposedBy != null) setField (newsItem, PROPOSED_BY, proposedBy);
      newsItem.save ();
    }
    catch (DataSetException e)
    {
      log.exception (e);
      String message = "Editing news item : " + e.getMessage ();
      if (debug)
	log.debug (message);
      throw e;
    }
    catch (SQLException e)
    {
      log.exception (e);
      String message = "Editing news item: " + e.getMessage ();
      if (debug)
	log.debug (message);
      throw e;
    }
    finally
    {
      registerToClose (newsItems);
a401 3
    return newsItem;
  }

d411 2
a412 45
  public DataSet getNewsItemsForUser (Connection conn, String userID)
    throws SQLException, DataSetException, JoistDatabaseException
  {
    String action = "Getting News Items for User";
    QueryDataSet newsItems = null;
    DataManager dMgr = getDataManager();
    UserUserGroupManager usrGrpMgr = (UserUserGroupManager)
       dMgr.getManager("org.tigris.helm.database.UserUserGroupManager");
    String nobodyID = usrGrpMgr.getNobodyUserID(conn);

    StringBuffer stmt =
      new StringBuffer ("select distinct news.").append (NEWS_ID);
      stmt.append (", news.").append (EVENT_DATE);
      stmt.append (", news.").append (HEADLINE).append (", urp.");
      stmt.append (PROJECT_ID).append (", p.name FROM ");
      stmt.append (TABLE_NAME).append (" news, ");
      stmt.append ("HELM_PROJECT p, HELM_USER_ROLE_PROJECT urp WHERE ");
      stmt.append ("urp.user_id = ").append (userID);
      stmt.append (" and p.project_id = urp.project_id and news.");
      stmt.append (PROJECT_ID).append (" = p.project_id ");
      stmt.append ("and news.");
      stmt.append(APPROVED_BY).append(" !=").append(nobodyID);
      stmt.append (" ORDER BY news.").append (EVENT_DATE).append (" DESC");

    if (debug)
        log.info ("SQL=" + stmt.toString ());
    try
    {
      newsItems = new QueryDataSet (conn, stmt.toString ());
    }
    catch (DataSetException e)
    {
      log.exception (e);
      if (debug)
	  log.debug (action + e.getMessage ());
      throw e;
    }
    catch (SQLException e)
    {
      log.exception (e);
      if (debug)
	log.debug (action + e.getMessage ());
      throw e;
    }
    finally
d414 40
a453 1
      registerToClose(newsItems);
a454 2
    return newsItems.fetchRecords();
  }
d464 1
a464 2
     * @@exception SQLException
     * @@exception DataSetException 
d467 1
a467 1
        throws SQLException, DataSetException, JoistDatabaseException
d483 2
a484 1
     * @@exception SQLException
d487 1
a487 1
        throws SQLException, DataSetException
d507 1
a507 4
            log.exception(e);
            if (debug) log.debug(action + ": " + newsID + ": " + 
                                 e.getMessage());
            throw e;
d511 1
a511 4
            log.exception(e);
            if (debug) log.debug(action + ": " + newsID + ": " + 
                                 e.getMessage());
            throw e;
a517 1

@


1.7
log
@fixed ambiguity in select statement in getNewsForUser
@
text
@d64 1
a64 1
 * @@version $Id: ProjectNewsManager.java,v 1.6 2000/12/19 03:17:35 elicia Exp $
d216 26
@


1.6
log
@the getProjectsForUser now filtering out unapprovedProjects
@
text
@d64 1
a64 1
 * @@version $Id: ProjectNewsManager.java,v 1.5 2000/12/19 02:37:32 elicia Exp $
d432 2
a433 1
      stmt.append ("and ").append(APPROVED_BY).append(" !=").append(nobodyID);
d437 1
a437 1
        log.debug ("SQL=" + stmt.toString ());
@


1.5
log
@added method getNewsForProject that takes approvedBy as an argument
@
text
@d64 1
a64 1
 * @@version $Id: ProjectNewsManager.java,v 1.4 2000/11/30 20:20:07 elicia Exp $
d413 1
a413 1
    throws SQLException, DataSetException
d417 4
d432 2
a433 1
      stmt.append ("ORDER BY news.").append (EVENT_DATE).append (" DESC");
@


1.4
log
@ordering news items by event date descending
@
text
@d64 1
a64 1
 * @@version $Id: ProjectNewsManager.java,v 1.3 2000/11/22 01:39:17 dlr Exp $
d104 5
d150 17
d169 1
a169 1
     * @@param connection The JDBC database connection to use.
d171 1
d177 3
a179 2
  public DataSet getNewsForProject (Connection conn, String projectID)
    throws DataSetException, SQLException
d186 6
a191 1
      newsItems.where (PROJECT_ID + '=' + projectID);
d220 1
a220 1
     * @@param connection The JDBC database connection to use.
d281 1
a281 1
     * @@param connection The JDBC database connection to use.
d326 1
a326 1
     * @@param connection The JDBC database connection to use.
d334 6
a339 6
  public Record updateNews (Connection connection,
			     String newsID, String projectID,
			     Date eventDate, String headline,
			     String body, String approvedBy, 
			     Date publishOn, Date removeOn, 
			     String priority)
d347 1
a347 1
      newsItems = new TableDataSet (connection, TABLE_NAME,
d352 6
a357 6
	// Updates existing news item
	if (debug)
	  log.info ("Updating news item news_ID=" + newsID);
	newsItems.where (NEWS_ID + '=' + newsID);
	newsItems.fetchRecords();
	newsItem = newsItems.getRecord(0);
d361 4
a364 4
	// Adding new news item
	if (debug)
	  log.debug ("Adding new news item");
	newsItem = newsItems.addRecord();
d376 1
d406 1
a406 1
     * @@param	connection    A JDBC database connection
d412 1
a412 1
  public DataSet getNewsItemsForUser (Connection connection, String userID)
d434 1
a434 1
      newsItems = new QueryDataSet (connection, stmt.toString ());
d440 1
a440 1
	log.debug (action + e.getMessage ());
d458 23
d483 1
a483 1
     * @@param      connection    the JDBC database connection
d487 1
a487 1
    public void  deleteNewsItem (Connection connection, String newsID)
d494 1
a494 1
            newsItems = new TableDataSet (connection, TABLE_NAME,
@


1.3
log
@Made use of new super class method.
@
text
@d64 1
a64 1
 * @@version $Id: ProjectNewsManager.java,v 1.2 2000/11/22 01:01:27 elicia Exp $
d163 1
@


1.2
log
@cleanup
@
text
@d64 1
a64 1
 * @@version $Id: ProjectNewsManager.java,v 1.1.1.1 2000/11/12 21:15:08 dlr Exp $
d338 5
a342 5
      if (projectID != null) newsItem.setValue (PROJECT_ID, projectID);
      if (eventDate != null ) newsItem.setValue (EVENT_DATE, eventDate);
      if (headline != null) newsItem.setValue (HEADLINE, headline);
      if (body != null) newsItem.setValue (BODY, body);
      if (approvedBy != null) newsItem.setValue (APPROVED_BY, approvedBy);
d345 1
a345 1
      if (priority != null) newsItem.setValue (PRIORITY, priority);
@


1.1
log
@Initial revision
@
text
@a48 1
import java.util.*;
d58 1
a58 4
import org.joist.util.EscapedString;
import org.joist.util.QuotedString;

import org.tigris.helm.security.AccessControlList;
d61 1
a61 1
 * Manages the domain table.
d63 2
a64 3
 * @@author <a href="mailto:leonardr@@collab.net">Leonard Richardson</a>
 * @@author <a href="mailto:dlr@@collab.net">Daniel Rall</a>
 * @@version $Id: ProjectNewsManager.java,v 1.7 2000/11/11 04:49:50 dlr Exp $
d73 1
a73 1
     * manages. Doesn't actually exist yet.
a122 1

a157 1

d159 1
a159 1
      try
d249 1
a249 1
     * Gets a list of news items for a given project
d252 2
a253 2
     * @@param projectID    The database key of the project to get news for
     * @@return	         The dataset of news items
d258 1
a258 1
  public DataSet getNewsItem (Connection conn, String newsID)
a260 1
    String fmt = DateDisplay.dateTimeFormat ();
d264 1
a264 1
      try
a265 4
      //StringBuffer sqlStmt = new StringBuffer ("select headline, body, ");
      //sqlStmt.append ("date_format(event_date,'").append (fmt).
      //append ("') as event_date from ").append (TABLE_NAME);
      //newsItem = new TableDataSet (conn, sqlStmt.toString ());
d289 1
a289 1
    return newsItem;
d304 2
a305 3
  public Integer updateNews (Connection connection,
			     AccessControlList acl,
			     String newsItemID, String projectID,
d307 3
a309 3
			     String body,
			     String approvedBy, String publishOn,
			     String removeOn, String priority)
d320 1
a320 1
      if (newsItemID != null)
d324 2
a325 2
	  log.info ("Updating new news item news_ID=" + newsItemID);
	newsItems.where (NEWS_ID + '=' + newsItemID);
d327 1
a327 1
	newsItem = newsItems.getRecord (0);
d334 1
a334 1
	newsItem = newsItems.addRecord ();
d338 8
a345 8
      newsItem.setValue (PROJECT_ID, projectID);
      newsItem.setValue (EVENT_DATE, eventDate);
      newsItem.setValue (HEADLINE, headline);
      newsItem.setValue (BODY, body);
      newsItem.setValue (APPROVED_BY, approvedBy);
      newsItem.setValue (PUBLISH_ON, publishOn);
      newsItem.setValue (REMOVE_ON, removeOn);
      newsItem.setValue (PRIORITY, priority);
d351 1
a351 1
      String message = "Editing download : " + e.getMessage ();
d359 1
a359 1
      String message = "Editing Download: " + e.getMessage ();
d369 1
a369 1
    return new Integer (newsItem.getValue (NEWS_ID).asInt ());
d401 1
a401 1
      try
d421 1
a421 1
      registerToClose (newsItems);
d423 1
a423 1
    return newsItems.fetchRecords ();
a439 1
            
@


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