head	1.11;
access;
symbols
	TIGRIS_1_1_0RC2:1.4
	TIGRIS_1_1_0RC1:1.4
	TIGRIS_1_1:1.4.0.4
	TIGRIS_1_0_8:1.4
	TIGRIS_1_0_8RC3:1.4
	TIGRIS_1_0_8RC2:1.4
	TIGRIS_1_0_8RC1:1.4
	TIGRIS_1_0_7:1.4
	TIGRIS_1_0_7RC3:1.4
	TIGRIS_1_0_7RC2:1.4
	TIGRIS_1_0_7RC1:1.4
	TIGRIS_1_0_6:1.4
	TIGRIS_1_0_6RC5:1.4
	TIGRIS_1_0_6RC4:1.4
	TIGRIS_1_0_6RC3:1.4
	TIGRIS_1_0_6RC2:1.4
	TIGRIS_1_0_6RC1:1.4
	TIGRIS_1_0_5:1.4
	TIGRIS_1_0_5RC6:1.4
	TIGRIS_1_0_5RC5:1.4
	TIGRIS_1_0_5RC4:1.4
	TIGRIS_1_0_5RC3:1.4
	TIGRIS_1_0_5RC2:1.4
	TIGRIS_1_0_5RC1:1.4
	TIGRIS_1_0_4:1.4
	TIGRIS_1_0_3:1.4
	TIGRIS_1_0_2:1.4
	TIGRIS_1_0_1:1.4
	TIGRIS_1_0:1.4.0.6
	TIGRIS_1_0_0:1.4
	TIGRIS_1_0_0_RC1:1.4.0.2
	dlr:1.1.1
	HELM_PEER_PORT_BRANCH:1.1.1.1;
locks; strict;
comment	@# @;


1.11
date	2001.08.11.09.08.07;	author dlr;	state Exp;
branches;
next	1.10;

1.10
date	2001.07.18.10.05.14;	author dlr;	state Exp;
branches;
next	1.9;

1.9
date	2001.07.17.20.10.49;	author leonardr;	state Exp;
branches;
next	1.8;

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

1.7
date	2001.05.23.01.50.15;	author dlr;	state Exp;
branches;
next	1.6;

1.6
date	2001.05.23.01.22.12;	author ms;	state Exp;
branches;
next	1.5;

1.5
date	2001.05.23.00.43.49;	author ms;	state Exp;
branches;
next	1.4;

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

1.3
date	2001.03.07.01.53.25;	author lucas;	state Exp;
branches;
next	1.2;

1.2
date	2001.02.21.01.08.23;	author dlr;	state Exp;
branches;
next	1.1;

1.1
date	2001.02.06.20.00.53;	author elicia;	state Exp;
branches
	1.1.1.1
	1.1.2.1;
next	;

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

1.1.2.1
date	2001.02.17.00.19.02;	author elicia;	state Exp;
branches;
next	;


desc
@@


1.11
log
@Upgrading to Turbine 3.0-dev, Fulcrum 1.0, and Torque 1.0.
@
text
@/* ================================================================
 * Copyright (c) 2000 CollabNet.  All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are
 * met:
 * 
 * 1. Redistributions of source code must retain the above copyright
 * notice, this list of conditions and the following disclaimer.
 * 
 * 2. Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 * 
 * 3. The end-user documentation included with the redistribution, if
 * any, must include the following acknowlegement: "This product includes
 * software developed by Collab.Net (http://www.Collab.Net/)."
 * Alternately, this acknowlegement may appear in the software itself, if
 * and wherever such third-party acknowlegements normally appear.
 * 
 * 4. The hosted project names must not be used to endorse or promote
 * products derived from this software without prior written
 * permission. For written permission, please contact info@@collab.net.
 * 
 * 5. Products derived from this software may not use the "Tigris" name
 * nor may "Tigris" appear in their names without prior written
 * permission of Collab.Net.
 * 
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 * IN NO EVENT SHALL COLLAB.NET OR ITS CONTRIBUTORS BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * ====================================================================
 * 
 * This software consists of voluntary contributions made by many
 * individuals on behalf of CollabNet.
 */


package org.tigris.helm.project;

import java.util.*;
import java.text.*;
import javax.servlet.http.*;

import org.apache.turbine.util.Log;
import org.apache.commons.util.exception.NestableException;

import org.apache.velocity.context.Context;

import org.tigris.helm.security.*;
import org.tigris.helm.om.*;
import org.tigris.helm.tool.ContextAPI;

public class ProjectNewsAddAdvanced extends HelmServlet
{
    private static final boolean debug = true;

    private static String HEADLINE="headline";
    private static String BODY="body";
    private static String SUBMIT_CHANGES_ACTION="Add News Item";

    protected String processRequest(Context context)
        throws NestableException, RedirectException
    {
        String templateName = super.processRequest(context);
        String action = (String) context.get ("action");

        int month, year;

        try
        {
            User loginUser = getLoginUser(context);
            AccessControlList acl = loginUser.getACL();
            Project currentProject = getCurrentProject(context);
      
            // Get values from session
            HttpSession session = getSessionManager(context).getSession();
            String headline = (String)session.getValue(HEADLINE);
            String body = (String)session.getValue(BODY);
            Date eventDate = (Date)session.getValue("eventDate");
            if (headline == null || headline.equals(""))
                ContextAPI.addMissingField(context, "headline");
            if (body == null || body.equals(""))
                ContextAPI.addMissingField(context, "body");
            context.put(HEADLINE, headline);

            // Put current date into context as a default
            // Default remove month is current month plus one
            GregorianCalendar current = new GregorianCalendar();

            month = current.get(Calendar.MONTH) +1;
            String currentMonth = Integer.toString(month);
            String publishYear;
            year = current.get(Calendar.YEAR);
            String currentYear = Integer.toString(year);
            if (month == 12)
            {
                context.put("isDecember", "");
                publishYear = ContextAPI.processField(context, "publish_year");
            }
            else
            {
                publishYear = currentYear;
            }
            String currentDay = 
                Integer.toString(current.get(Calendar.DAY_OF_MONTH));
            context.put("current_month", currentMonth);
            context.put("current_day", currentDay);
            context.put("current_year", currentYear);
            context.put("next_year", Integer.toString(++year));

            context.put("default_remove_month", 
                    Integer.toString(current.get(Calendar.MONTH) +2));

            // Get user-entered values
            String publish = ContextAPI.processField(context, "publish");
            String publishMonth = ContextAPI.processField
                (context, "publish_month");
            String publishDay = ContextAPI.processField(context, "publish_day");
            String remove = ContextAPI.processField(context, "remove");
            String removeMonth = ContextAPI.processField(context, "remove_month");
            String removeDay = ContextAPI.processField(context, "remove_day");
            String removeYear = ContextAPI.processField(context, "remove_year");

            if (action.equals (SUBMIT_CHANGES_ACTION)) {

                // Do update -- publish and remove fields
                Date publishDate = null;
                Date removeDate = null;
                Calendar cal = new GregorianCalendar();
                cal.setLenient(false);

                // Format publish date
                // If user selected "immediately", set to today's date
                if (publish.equals("immediately"))
                {
                    publishDate = current.getTime(); 
                } else {
                    cal.set(Calendar.DAY_OF_MONTH, Integer.parseInt(publishDay));
                    cal.set(Calendar.MONTH, Integer.parseInt(publishMonth)-1);
                    cal.set(Calendar.YEAR, Integer.parseInt(publishYear));    
                    try
                    {
                        publishDate = cal.getTime();
                    }
                    catch (IllegalArgumentException e)
                    {
                        ContextAPI.addValidationError
                            (context, "Publish date is not valid.");
                    }
                } 
	  
                // Format remove date
                // If they set removeDate to "never", set to future date 3999-01-01 
                if (remove.equals("never"))
                {
                    DateFormat myFormat = new SimpleDateFormat("yyyy-MM-dd");
                    removeDate = myFormat.parse("3999-01-01");
                } else {
                    cal = new GregorianCalendar();
                    cal.setLenient(false);
                    cal.set(Calendar.DAY_OF_MONTH, Integer.parseInt(removeDay));
                    cal.set(Calendar.MONTH, Integer.parseInt(removeMonth)-1);
                    cal.set(Calendar.YEAR, Integer.parseInt(removeYear));    
                    try
                    {
                        removeDate = cal.getTime();

                        // If remove date is before publish date, show error message
                        if (removeDate.compareTo(publishDate) <= 0)
                        {
                            ContextAPI.addValidationError
                                (context, 
                                 "The remove date should be at least one day after the publish date.");
                        } else if (removeDate.compareTo(new Date()) <= 0) {
                            ContextAPI.addValidationError
                                (context, "The remove date should be later than the current date.");
                        }
                    }
                    catch (IllegalArgumentException e)
                    {
                        ContextAPI.addValidationError
                            (context, "Remove date is not valid.");
                    }
               
                } 
 
                // Check for errors
                if (ContextAPI.isValidUserInput(context))
                {
                    // If no errors, do add
                    // TODO: Remove hardcoded priority.
                    NewsItem newsItem = NewsItem.add
                        (acl, currentProject, eventDate, headline,
                         body, publishDate, removeDate, 1, null,
                         null);
                    redirectToURL(context, "ProjectNewsList");

                } 
                else 
                {
                    context.put("errors", "yes");
                }
            }
        }
        catch (RedirectException e)
        {
            throw e;
        }
        catch (Exception e)
        {
            Log.error (e);
            String message = "ProjectNewsAddAdvanced: " + e.getMessage ();
            if (debug) Log.info (message);
            context.put ("message", message);
        }
    
        if (debug) Log.debug ("ProjectNewsAddAdvanced:  done");
    
        return templateName;

    }
      

}				/* end class ProjectNewsAddAdvanced */
@


1.10
log
@Ported Joist Redirect*Exception to Helm.
@
text
@d55 1
a55 1
import org.apache.turbine.util.TurbineException;
d72 1
a72 1
        throws TurbineException, RedirectException
@


1.9
log
@Ported servlets to new error-handling mechanism.
@
text
@a49 1
import java.util.Date;
a51 2
import java.sql.*;
import javax.servlet.*;
d56 1
a56 2
import org.apache.turbine.util.TurbineException;
import org.webmacro.util.*;
a58 2
import org.joist.security.*;

d65 1
a65 1
    private static boolean debug = true;
@


1.8
log
@added imageURL and original article URL fields
@
text
@d67 1
a67 1
import org.tigris.helm.om.*;
d71 1
a71 1
  private static boolean debug = true;
d73 3
a75 3
  private static String HEADLINE="headline";
  private static String BODY="body";
  private static String SUBMIT_CHANGES_ACTION="Add News Item";
d77 5
a81 8
  protected String processRequest(Context ctx)
    throws TurbineException, RedirectException
  {
    String templateName = super.processRequest(ctx);
    String action = (String) ctx.get ("action");

    ArrayList validationErrors = new ArrayList ();
    ArrayList missingFields = new ArrayList ();
d83 1
a83 1
    int month, year;
d85 5
a89 5
    try
    {
      User loginUser = getLoginUser(ctx);
      AccessControlList acl = loginUser.getACL();
      Project currentProject = getCurrentProject(ctx);
d91 76
a166 74
      // Get values from session
      HttpSession session = getSessionManager(ctx).getSession();
      String headline = (String)session.getValue(HEADLINE);
      String body = (String)session.getValue(BODY);
      Date eventDate = (Date)session.getValue("eventDate");
      if (headline == null || headline.equals(""))
         missingFields.add("headline");
      if (body == null || body.equals(""))
         missingFields.add("body");
      ctx.put(HEADLINE, headline);

      // Put current date into context as a default
      // Default remove month is current month plus one
      GregorianCalendar current = new GregorianCalendar();

      month = current.get(Calendar.MONTH) +1;
      String currentMonth = Integer.toString(month);
      String publishYear;
      year = current.get(Calendar.YEAR);
      String currentYear = Integer.toString(year);
      if (month == 12)
      {
          ctx.put("isDecember", "");
          publishYear = processField(ctx, "publish_year");
      }
      else
      {
          publishYear = currentYear;
      }
      String currentDay = 
	    Integer.toString(current.get(Calendar.DAY_OF_MONTH));
      ctx.put("current_month", currentMonth);
      ctx.put("current_day", currentDay);
      ctx.put("current_year", currentYear);
      ctx.put("next_year", Integer.toString(++year));

      ctx.put("default_remove_month", 
		  Integer.toString(current.get(Calendar.MONTH) +2));

	  // Get user-entered values
      String publish = processField(ctx, "publish");
      String publishMonth = processField(ctx, "publish_month");
      String publishDay = processField(ctx, "publish_day");
      String remove = processField(ctx, "remove");
      String removeMonth = processField(ctx, "remove_month");
      String removeDay = processField(ctx, "remove_day");
      String removeYear = processField(ctx, "remove_year");

      if (action.equals (SUBMIT_CHANGES_ACTION)) {

          // Do update -- publish and remove fields
          Date publishDate = null;
          Date removeDate = null;
          Calendar cal = new GregorianCalendar();
          cal.setLenient(false);

          // Format publish date
	      // If user selected "immediately", set to today's date
	      if (publish.equals("immediately"))
	      {
              publishDate = current.getTime(); 
          } else {
              cal.set(Calendar.DAY_OF_MONTH, Integer.parseInt(publishDay));
              cal.set(Calendar.MONTH, Integer.parseInt(publishMonth)-1);
              cal.set(Calendar.YEAR, Integer.parseInt(publishYear));    
              try
	          {
                  publishDate = cal.getTime();
              }
              catch (IllegalArgumentException e)
              {
		          validationErrors.add("Publish date is not valid.");
              }
	      } 
d168 32
a199 28
	      // Format remove date
          // If they set removeDate to "never", set to future date 3999-01-01 
	      if (remove.equals("never"))
	      {
 	          DateFormat myFormat = new SimpleDateFormat("yyyy-MM-dd");
	          removeDate = myFormat.parse("3999-01-01");
          } else {
              cal = new GregorianCalendar();
              cal.setLenient(false);
              cal.set(Calendar.DAY_OF_MONTH, Integer.parseInt(removeDay));
              cal.set(Calendar.MONTH, Integer.parseInt(removeMonth)-1);
              cal.set(Calendar.YEAR, Integer.parseInt(removeYear));    
              try
              {
                  removeDate = cal.getTime();

                  // If remove date is before publish date, show error message
                  if (removeDate.compareTo(publishDate) <= 0)
                  {
                      validationErrors.add("The remove date should be at least one day after the publish date.");
                  } else if (removeDate.compareTo(new Date()) <= 0) {
	                  validationErrors.add("The remove date should be later than the current date.");
                  }
              }
              catch (IllegalArgumentException e)
              {
		          validationErrors.add("Remove date is not valid.");
              }
d201 1
a201 1
	      } 
d203 29
a231 28
	      // Check for errors
          if (isValidUserInput(missingFields, validationErrors))
	      {
              // If no errors, do add
	          // TODO: Remove hardcoded priority.
              NewsItem newsItem = NewsItem.add
                  (acl, currentProject, eventDate, headline,
                  body, publishDate, removeDate, 1, null,
                  null);
              redirectToURL(ctx, "ProjectNewsList");

          } else {
              reportInvalidUserInput(ctx, missingFields, validationErrors);
	          ctx.put("errors", "yes");
          }
       }
    }
    catch (RedirectException e)
    {
       throw e;
    }
    catch (Exception e)
    {
      Log.error (e);
      String message = "ProjectNewsAddAdvanced: " + e.getMessage ();
      if (debug) Log.info (message);
      ctx.put ("message", message);
    }
d233 1
a233 1
    if (debug) Log.debug ("ProjectNewsAddAdvanced:  done");
d235 1
a235 1
    return templateName;
d237 1
a237 1
  }
@


1.7
log
@Ported Helm from WebMacro to Velocity.
@
text
@d207 2
a208 1
                  body, publishDate, removeDate, 1);
@


1.6
log
@fixed npe in year
@
text
@d58 2
d61 1
a61 1
import org.webmacro.servlet.*;
d77 2
a78 2
  protected String processRequest (Connection conn, WebContext ctx)
    throws HandlerException, RedirectException
d80 1
a80 1
    String templateName = super.processRequest (conn, ctx);
@


1.5
log
@only let next year be specified in december of previous year
@
text
@d109 3
d115 5
a122 2
      year = current.get(Calendar.YEAR);
      String currentYear = Integer.toString(year);
a134 1
      String publishYear = processField(ctx, "publish_year");
@


1.4
log
@changed so that news item is added after the advanced options step as per issue 3029
@
text
@d84 2
d106 7
a112 2
      String currentMonth = 
	    Integer.toString(current.get(Calendar.MONTH) +1);
d115 2
a116 2
      String currentYear = 
	    Integer.toString(current.get(Calendar.YEAR));
d120 2
@


1.3
log
@Corrected regex madness for Torque upgrade.  -dlr
@
text
@d55 1
d71 2
a77 3
    if (debug)
      Log.debug ("ProjectNewsAddAdvanced: started!");

a80 3
    if (debug)
        Log.debug ("ProjectNewsAddAdvanced: action=" + action);

d90 10
a99 8
      // Get current newsItem to edit
      String newsID = ctx.getForm("newsID");
      if (newsID == null)
      {
          redirectToURL(ctx, "ProjectNewsAdd");
      }
      NewsItem newsItem = (NewsItem)NewsItemPeer.getInstance(newsID);
      ctx.put("newsItem", newsItem);
a115 1

d126 2
a127 2
      if (action.equals (SUBMIT_CHANGES_ACTION))
      {
d174 1
a174 1
	              validationErrors.add("The remove date should be later than the current date.");
d187 6
a192 5
             // If no errors, do update
	         // TODO: Remove hardcoded priority.
	         newsItem.edit(acl, null, null, null, 
                           publishDate, removeDate, null);
             redirectToURL(ctx, "ProjectNewsList");
a194 1
                 Log.debug("ERRORS");
d198 1
a198 1
      }
@


1.2
log
@This is the highest revision from the HELM_PEER_PORT_BRANCH.  The previous import caused too many conflicts to resolve manually
@
text
@d64 1
a64 2
import org.tigris.helm.om.peer.*;

@


1.1
log
@added these servlets as advanced options to provide publish and removal dates for news items
@
text
@d56 1
d63 2
a64 1
import org.tigris.helm.domain.*;
d67 1
a67 1
public class ProjectNewsAddAdvanced extends org.tigris.helm.security.HelmServlet
a68 3
  public static final String versionID =
    "$Id: ProjectNewsAdd.java,v 1.22 2001/02/02 01:10:22 elicia Exp $";
  private static Log log = new Log ("ProjectNewsAddAdvanced", "PrjNwsAddAdv");
a72 4

    /**
     *  Display and process the login screen.
     */
d77 1
a77 1
      log.debug ("ProjectNewsAddAdvanced: started!");
d83 1
a83 1
        log.debug ("ProjectNewsAddAdvanced: action=" + action);
d90 2
a92 1
      AccessControlList acl = getACL(ctx, conn);
d96 5
a100 1
      NewsItem newsItem = new NewsItem(conn, dMgr, newsID);
d163 2
d171 8
a183 7
              // If remove date is before publish date, show error message
	          if (removeDate.compareTo(publishDate) <= 0)
	          {
	              validationErrors.add("The remove date should be at least one day after the publish date.");
	          } else if (removeDate.compareTo(new Date()) <= 0) {
	              validationErrors.add("The remove date should be later than the current date.");
	          }
d194 1
a194 1
             redirectToURL(ctx, "ProjectNews");
d197 1
d209 3
a211 3
      log.exception (e);
      String message = "ProjectNewsAddAdd: " + e.getMessage ();
      if (debug) log.info (message);
d215 1
a215 1
    if (debug) log.debug ("ProjectNewsAddAdd:  done");
@


1.1.1.1
log
@Replacing the HEAD with the HELM_PEER_PORT_BRANCH.
@
text
@a55 1
import org.apache.turbine.util.Log;
d62 1
a62 2
import org.tigris.helm.om.*;
import org.tigris.helm.om.peer.*;
d65 1
a65 1
public class ProjectNewsAddAdvanced extends HelmServlet
d67 3
d74 4
d82 1
a82 1
      Log.debug ("ProjectNewsAddAdvanced: started!");
d88 1
a88 1
        Log.debug ("ProjectNewsAddAdvanced: action=" + action);
a94 2
      User loginUser = getLoginUser(ctx);
      AccessControlList acl = loginUser.getACL();
d96 1
d100 1
a100 5
      if (newsID == null)
      {
          redirectToURL(ctx, "ProjectNewsAdd");
      }
      NewsItem newsItem = (NewsItem)NewsItemPeer.getInstance(newsID);
a162 2
              cal = new GregorianCalendar();
              cal.setLenient(false);
a168 8

                  // If remove date is before publish date, show error message
                  if (removeDate.compareTo(publishDate) <= 0)
                  {
                      validationErrors.add("The remove date should be at least one day after the publish date.");
                  } else if (removeDate.compareTo(new Date()) <= 0) {
	              validationErrors.add("The remove date should be later than the current date.");
                  }
d174 7
d191 1
a191 1
             redirectToURL(ctx, "ProjectNewsList");
a193 1
                 Log.debug("ERRORS");
d205 3
a207 3
      Log.error (e);
      String message = "ProjectNewsAddAdvanced: " + e.getMessage ();
      if (debug) Log.info (message);
d211 1
a211 1
    if (debug) Log.debug ("ProjectNewsAddAdvanced:  done");
@


1.1.2.1
log
@split add and edit methods into two steps-- advanced options are optional
@
text
@a55 1
import org.apache.turbine.util.Log;
d62 1
a62 2
import org.tigris.helm.om.*;
import org.tigris.helm.om.peer.*;
d65 1
a65 1
public class ProjectNewsAddAdvanced extends HelmServlet
d67 3
d74 4
d82 1
a82 1
      Log.debug ("ProjectNewsAddAdvanced: started!");
d88 1
a88 1
        Log.debug ("ProjectNewsAddAdvanced: action=" + action);
a94 2
      User loginUser = getLoginUser(ctx);
      AccessControlList acl = loginUser.getACL();
d96 1
d100 1
a100 5
      if (newsID == null)
      {
          redirectToURL(ctx, "ProjectNewsAdd");
      }
      NewsItem newsItem = (NewsItem)NewsItemPeer.getInstance(newsID);
a162 2
              cal = new GregorianCalendar();
              cal.setLenient(false);
a168 8

                  // If remove date is before publish date, show error message
                  if (removeDate.compareTo(publishDate) <= 0)
                  {
                      validationErrors.add("The remove date should be at least one day after the publish date.");
                  } else if (removeDate.compareTo(new Date()) <= 0) {
	              validationErrors.add("The remove date should be later than the current date.");
                  }
d174 7
d191 1
a191 1
             redirectToURL(ctx, "ProjectNewsList");
a193 1
                 Log.debug("ERRORS");
d205 3
a207 3
      Log.error (e);
      String message = "ProjectNewsAddAdvanced: " + e.getMessage ();
      if (debug) Log.info (message);
d211 1
a211 1
    if (debug) Log.debug ("ProjectNewsAddAdvanced:  done");
@

