All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.aoindustries.aoserv.client.EmailListTable Maven / Gradle / Ivy

There is a newer version: 1.92.0
Show newest version
/*
 * aoserv-client - Java client for the AOServ platform.
 * Copyright (C) 2001-2013, 2016  AO Industries, Inc.
 *     [email protected]
 *     7262 Bull Pen Cir
 *     Mobile, AL 36695
 *
 * This file is part of aoserv-client.
 *
 * aoserv-client is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * aoserv-client is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with aoserv-client.  If not, see .
 */
package com.aoindustries.aoserv.client;

import com.aoindustries.aoserv.client.validator.AccountingCode;
import com.aoindustries.io.TerminalWriter;
import java.io.IOException;
import java.io.Reader;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**
 * @see  EmailList
 *
 * @author  AO Industries, Inc.
 */
final public class EmailListTable extends CachedTableIntegerKey {

	EmailListTable(AOServConnector connector) {
		super(connector, EmailList.class);
	}

	private static final OrderBy[] defaultOrderBy = {
		new OrderBy(EmailList.COLUMN_PATH_name, ASCENDING),
		new OrderBy(EmailList.COLUMN_LINUX_SERVER_ACCOUNT_name+'.'+LinuxServerAccount.COLUMN_AO_SERVER_name+'.'+AOServer.COLUMN_HOSTNAME_name, ASCENDING)
	};
	@Override
	OrderBy[] getDefaultOrderBy() {
		return defaultOrderBy;
	}

	public int addEmailList(
		String path,
		LinuxServerAccount linuxAccountObject,
		LinuxServerGroup linuxGroupObject
	) throws IllegalArgumentException, IOException, SQLException {
		if (!EmailList.isValidRegularPath(path)) throw new IllegalArgumentException("Invalid list path: " + path);

		return connector.requestIntQueryIL(
			true,
			AOServProtocol.CommandID.ADD,
			SchemaTable.TableID.EMAIL_LISTS,
			path,
			linuxAccountObject.pkey,
			linuxGroupObject.pkey
		);
	}

	@Override
	public EmailList get(int pkey) throws IOException, SQLException {
		return getUniqueRow(EmailList.COLUMN_PKEY, pkey);
	}

	List getEmailLists(Business business) throws IOException, SQLException {
		AccountingCode accounting=business.pkey;
		List cached = getRows();
		int len = cached.size();
		List matches=new ArrayList<>(len);
		for (int c = 0; c < len; c++) {
			EmailList list = cached.get(c);
			if (
				list
				.getLinuxServerGroup()
				.getLinuxGroup()
				.getPackage()
				.accounting
				.equals(accounting)
			) matches.add(list);
		}
		return matches;
	}

	List getEmailLists(Package pack) throws IOException, SQLException {
		String packName=pack.name;

		List cached=getRows();
		int size=cached.size();
		List matches=new ArrayList<>(size);
		for(int c=0;c getEmailLists(LinuxServerAccount lsa) throws IOException, SQLException {
		return getIndexedRows(EmailList.COLUMN_LINUX_SERVER_ACCOUNT, lsa.pkey);
	}

	EmailList getEmailList(AOServer ao, String path) throws IOException, SQLException {
		int aoPKey=ao.pkey;
		List cached=getRows();
		int size=cached.size();
		for(int c=0;c2) {
							out.print(args[c]);
							out.print(": ");
						}
						out.println("true");
					} catch(IllegalArgumentException ia) {
						if(args.length>2) {
							out.print(args[c]);
							out.print(": ");
						}
						out.println(ia.getMessage());
					}
					out.flush();
				}
			}
			return true;
		} else if(command.equalsIgnoreCase(AOSHCommand.DISABLE_EMAIL_LIST)) {
			if(AOSH.checkParamCount(AOSHCommand.DISABLE_EMAIL_LIST, args, 3, err)) {
				out.println(
					connector.getSimpleAOClient().disableEmailList(
						args[1],
						args[2],
						args[3]
					)
				);
				out.flush();
			}
			return true;
		} else if(command.equalsIgnoreCase(AOSHCommand.ENABLE_EMAIL_LIST)) {
			if(AOSH.checkParamCount(AOSHCommand.ENABLE_EMAIL_LIST, args, 2, err)) {
				connector.getSimpleAOClient().enableEmailList(args[1], args[2]);
			}
			return true;
		} else if(command.equalsIgnoreCase(AOSHCommand.GET_EMAIL_LIST)) {
			if(AOSH.checkParamCount(AOSHCommand.GET_EMAIL_LIST, args, 2, err)) {
				out.println(connector.getSimpleAOClient().getEmailListAddressList(args[1], args[2]));
				out.flush();
			}
			return true;
		} else if(command.equalsIgnoreCase(AOSHCommand.REMOVE_EMAIL_LIST)) {
			if(AOSH.checkParamCount(AOSHCommand.REMOVE_EMAIL_LIST, args, 2, err)) {
				connector.getSimpleAOClient().removeEmailList(args[1], args[2]);
			}
			return true;
		} else if(command.equalsIgnoreCase(AOSHCommand.SET_EMAIL_LIST)) {
			if(AOSH.checkParamCount(AOSHCommand.SET_EMAIL_LIST, args, 3, err)) {
				connector.getSimpleAOClient().setEmailListAddressList(args[1], args[2], args[3]);
			}
			return true;
		}
		return false;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy