head	1.6;
access;
symbols
	dlr:1.1.1
	TIGRIS_0_9_2_4:1.2
	TIGRIS_0_9_2_3:1.2
	HELM_PEER_PORT_BRANCH:1.1.1.2
	TURBINE_PEER:1.4
	TIGRIS_0_9_2_1:1.4
	TIGRIS_0_9_2:1.2.0.6
	TIGRIS_0_9_0:1.2.0.4
	TIGRIS_0_8_4:1.2.0.2
	NEWHELM:1.1.1.1
	TIGRIS_NOV_12_2000:1.1.1;
locks; strict;
comment	@# @;


1.6
date	2001.02.22.22.48.36;	author edk;	state dead;
branches;
next	1.5;

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

1.4
date	2001.01.26.18.29.11;	author edk;	state Exp;
branches
	1.4.2.1;
next	1.3;

1.3
date	2001.01.26.05.24.08;	author edk;	state dead;
branches;
next	1.2;

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

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

1.1.1.1
date	2000.11.12.21.16.57;	author dlr;	state Exp;
branches;
next	1.1.1.2;

1.1.1.2
date	2001.02.21.00.35.34;	author dlr;	state Exp;
branches;
next	;

1.4.2.1
date	2001.01.28.01.02.20;	author dlr;	state dead;
branches;
next	1.4.2.2;

1.4.2.2
date	2001.02.20.09.49.21;	author edk;	state Exp;
branches;
next	;


desc
@@


1.6
log
@switch to using MailingListManagerSpec directly; now mailing list creation
works by getting the mailing list types from it.
@
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.tool.mail;

import java.util.List;
import java.util.Properties;
import java.util.Map;

import com.workingdogs.village.*;

import org.webmacro.util.Log;
import org.webmacro.servlet.HandlerException;

import java.sql.Connection;

import org.joist.database.*;

import org.tigris.helm.om.MailingList;
import org.tigris.helm.om.User;
import org.tigris.helm.om.Domain;
import org.tigris.helm.AlreadyExists;
import org.tigris.helm.security.AccessControlList;

import java.lang.reflect.*;

import java.io.InputStream;
import java.io.IOException;

/**
 * A business object for MailingLists
 *
 * @@author <a href="mailto:elicia@@collab.net">Elicia David</a>
 * @@author <a href="mailto:edk@@collab.net">Ed Korthof</a>
 * @@version $Id: MailingListConf.java,v 1.5 2001/02/21 01:08:26 dlr Exp $
 */
public class MailingListConf
{
    private static Log log = new Log("mlConf", "MailingListConf");
    private static boolean debug = true;

    private Domain domain;
    private Object mailingListManagerSpec = null;
    private boolean exists = true;
    private static boolean anzu = false;
    
    /**
     * Do we need to save?
     */
    private boolean needSave;

    // TODO : we should get this via reflection from a class in anzu
    private final static String clientProperties = "anzu.properties";


    /**
     * Constructor for per-domain MailingListconf
     */
    public MailingListConf(Domain domain)
    {
        this.domain = domain;
        this.needSave = false;
    }

    protected static Constructor mailingListManagerSpecConstructor = null;
    protected static Method MLMS_getOptionTypes = null; // List
    protected static Method MLMS_getListTypes = null; // List
    protected static Method MLMS_getOptionsList = null; // List
    protected static Method MLMS_setBooleanOption = null; // void
    protected static Method MLMS_setStringOption = null; // void
    protected static Method MLMS_getBooleanOption = null; // void
    protected static Method MLMS_getStringOption = null; // void
    static {
        try {
            Class MLMSClass =
                Class.forName("org.tigris.anzu.client.MailingListManagerSpec");
            {
                Class argTypes[] = { String.class };
                mailingListManagerSpecConstructor =
                    MLMSClass.getConstructor(argTypes);
            }

            {
                Class argTypes[] = {};
                MLMS_getOptionTypes =
                    MLMSClass.getDeclaredMethod("getOptionTypes", argTypes);
                MLMS_getListTypes =
                    MLMSClass.getDeclaredMethod("getListTypes", argTypes);
            }

            {
                Class argTypes[] = { String[].class };
                MLMS_getOptionsList =
                    MLMSClass.getDeclaredMethod("getOptionsList", argTypes);
            }

            {
                Class argTypes[] = {
                    Map.class, String.class
                };
                MLMS_getBooleanOption =
                    MLMSClass.getDeclaredMethod("getBooleanOption", argTypes);
                MLMS_getStringOption =
                    MLMSClass.getDeclaredMethod("getStringOption", argTypes);
            }

            {
                Class argTypes[] = {
                    Map.class, String.class, String.class
                };
                MLMS_setStringOption =
                    MLMSClass.getDeclaredMethod("setStringOption", argTypes);
            }

            {
                Class argTypes[] = {
                    Map.class, String.class, Boolean.class
                };
                MLMS_setBooleanOption =
                    MLMSClass.getDeclaredMethod("setBooleanOption", argTypes);
            }
            anzu = true;
        } catch (ClassNotFoundException e) {
            log.debug("anzu classes do not appear to be in the classpath");
        } catch (NoSuchMethodException e) {
            log.debug("anzu classes missing expected method "+e.getMessage());
            e.printStackTrace();
            throw new RuntimeException("invalid version of anzu(missing)");
        } catch (SecurityException e) {
            log.debug("anzu req method is marked non-public "+e.getMessage());
            e.printStackTrace();
            throw new RuntimeException("invalid version of anzu(security)");
        }
    }

    /**
     * This method is used to connect with the anzu classes.  It does
     * implicitly connect to the remote anzu server.  It uses reflection
     * to avoid requiring anzu to compile.
     * 
     * @@return a boolean indicating whether or not the connection attempt
     * was successful
     */
    public boolean connect()
    {
        if (mailingListManagerSpec != null) return true;
        try {
            Object args[] = { domain };
            mailingListManagerSpec =
                mailingListManagerSpecConstructor.newInstance(args);
        } catch (Exception e) {
            log.debug("got exception trying to connect");
            log.exception(e);
            mailingListManagerSpec = null;
            return false;
        }
        return true;
    }

    private boolean anzuDisabled() throws HandlerException
    {
        if (!anzu) {
            log.error("anzu is not installed, so MailingList.* is noop");
            return true;
        } else if (!connect()) {
            log.error("unable to connect to anzu server; bailing out");
            throw new HandlerException("anzu is installed but the server " +
                    "is not running");
        }
        return false;
    }

    public void setBooleanOption(Map map, String option,
            Boolean value) throws HandlerException
    {
        if (anzuDisabled()) return;
        Object args[] = { map, option, value };
        try {
            MLMS_setBooleanOption.invoke(mailingListManagerSpec, args);
        } catch (Exception e) {
            log.exception(e);
            if (debug) log.debug("exception from anzu: "+e.getMessage());
            throw new HandlerException("anzu error: "+e.getMessage());
        }
    }


    public void setStringOption(Map map, String option,
            String value) throws HandlerException
    {
        if (anzuDisabled()) return;
        Object args[] = { map, option, value };
        try {
            MLMS_setStringOption.invoke(mailingListManagerSpec, args);
        } catch (Exception e) {
            log.exception(e);
            if (debug) log.debug("exception from anzu: "+e.getMessage());
            throw new HandlerException("anzu error: "+e.getMessage());
        }
    }

    public Boolean getBooleanOption(Map map,
            String option) throws HandlerException
    {
        if (anzuDisabled()) return null;
        Object args[] = { map, option };
        try {
            return (Boolean)
                MLMS_getBooleanOption.invoke(mailingListManagerSpec, args);
        } catch (Exception e) {
            log.exception(e);
            if (debug) log.debug("exception from anzu: "+e.getMessage());
            throw new HandlerException("anzu error: "+e.getMessage());
        }
    }

    public String getStringOption(Map map,
            String option) throws HandlerException
    {
        if (anzuDisabled()) return null;
        Object args[] = { map, option };
        try {
            return (String)
                MLMS_getStringOption.invoke(mailingListManagerSpec, args);
        } catch (Exception e) {
            log.exception(e);
            if (debug) log.debug("exception from anzu: "+e.getMessage());
            throw new HandlerException("anzu error: "+e.getMessage());
        }
    }

    public List getListTypes() throws HandlerException
    {
        if (anzuDisabled()) return null;
        try {
            return (List)MLMS_getListTypes.invoke(mailingListManagerSpec, null);
        } catch (Exception e) {
            log.exception(e);
            if (debug) log.debug("exception from anzu: "+e.getMessage());
            throw new HandlerException("anzu error: "+e.getMessage());
        }
    }

    public List getOptionsList(String type) throws HandlerException
    {
        if (anzuDisabled()) return null;
        Object args[] = { type };
        try {
            return (List)
                MLMS_getOptionsList.invoke(mailingListManagerSpec, args);
        } catch (Exception e) {
            log.exception(e);
            if (debug) log.debug("exception from anzu: "+e.getMessage());
            throw new HandlerException("anzu error: "+e.getMessage());
        }
    }

    public List getOptionTypes() throws HandlerException
    {
        if (anzuDisabled()) return null;
        try {
            return (List)
                MLMS_getOptionTypes.invoke(mailingListManagerSpec, null);
        } catch (Exception e) {
            log.exception(e);
            if (debug) log.debug("exception from anzu: "+e.getMessage());
            throw new HandlerException("anzu error: "+e.getMessage());
        }
    }

//    public Map getOptionsMap() throws HandlerException
//    {
//        if (anzuDisabled()) return null;
//        try {
//            return (Map)MLMS_getOptionsMap.invoke(mailingListManagerSpec, null);
//        } catch (Exception e) {
//            log.exception(e);
//            if (debug) log.debug("exception from anzu: "+e.getMessage());
//            throw new HandlerException("anzu error: "+e.getMessage());
//        }
//    }
}
@


1.5
log
@This is the highest revision from the HELM_PEER_PORT_BRANCH.  The previous import caused too many conflicts to resolve manually
@
text
@d78 1
a78 1
 * @@version $Id: MailingListConf.java,v 1.4.2.2 2001/02/20 09:49:21 edk Exp $
@


1.4
log
@readding all the files as part of the process of returning to the way
things were as of tuesday
@
text
@d61 4
a64 2
import org.tigris.helm.database.*;
import org.tigris.helm.domain.User;
a66 1
import org.tigris.helm.domain.Domain;
d78 1
a78 1
 * @@version $Id: MailingListConf.java,v 1.2 2000/11/13 19:45:21 edk Exp $
a85 3
    private DataManager dMgr;
    private MailingListManager mlMgr;
    private Connection connection;
d102 1
a102 1
    public MailingListConf(Connection c, DataManager dMgr, Domain domain)
a103 4
        this.connection = c;
        this.dMgr = dMgr;
        this.mlMgr = (MailingListManager)
            dMgr.getManager("org.tigris.helm.database.MailingListManager");
@


1.4.2.1
log
@Porting to the Turbine Peer system.  -dlr and leonardr
@
text
@d77 1
a77 1
 * @@version $Id: MailingListConf.java,v 1.4 2001/01/26 18:29:11 edk Exp $
@


1.4.2.2
log
@* port MailingList* to the peer system
* add some necessary methods to MailingList, update AnzuTask to use those
* this compiles, but some methods still need to be implemented, so it
  doesn't all work
@
text
@d61 2
a62 4

import org.tigris.helm.om.MailingList;
import org.tigris.helm.om.User;
import org.tigris.helm.om.Domain;
d65 1
d85 3
d104 1
a104 1
    public MailingListConf(Domain domain)
d106 4
@


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


1.2
log
@updates from last night: use ArrayList instead of String[]'s; and correct
Util's prefix pattern
@
text
@d77 1
a77 1
 * @@version $Id: MailingListConf.java,v 1.1 2000/11/06 21:47:10 edk Exp $
@


1.1
log
@Initial revision
@
text
@@


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


1.1.1.2
log
@Replacing the HEAD with the HELM_PEER_PORT_BRANCH.
@
text
@d61 2
a62 4

import org.tigris.helm.om.MailingList;
import org.tigris.helm.om.User;
import org.tigris.helm.om.Domain;
d65 1
d77 1
a77 1
 * @@version $Id: MailingListConf.java,v 1.4.2.2 2001/02/20 09:49:21 edk Exp $
d85 3
d104 1
a104 1
    public MailingListConf(Domain domain)
d106 4
@

