com.aoindustries.aoserv.client.Reseller Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of aoserv-client Show documentation
Show all versions of aoserv-client Show documentation
Java client for the AOServ Platform.
/*
* aoserv-client - Java client for the AOServ platform.
* Copyright (C) 2009-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.aoserv.client.validator.ValidationException;
import com.aoindustries.io.CompressedDataInputStream;
import com.aoindustries.io.CompressedDataOutputStream;
import java.io.IOException;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
/**
* A reseller may handle support tickets..
*
* @see Business
* @see Brand
*
* @author AO Industries, Inc.
*/
final public class Reseller extends CachedObjectAccountingCodeKey {
static final int COLUMN_ACCOUNTING = 0;
static final String COLUMN_ACCOUNTING_name = "accounting";
private boolean ticket_auto_escalate;
@Override
Object getColumnImpl(int i) {
switch(i) {
case COLUMN_ACCOUNTING : return pkey;
case 1: return ticket_auto_escalate;
default: throw new IllegalArgumentException("Invalid index: "+i);
}
}
public Brand getBrand() throws SQLException, IOException {
Brand br = table.connector.getBrands().get(pkey);
if(br==null) throw new SQLException("Unable to find Brand: "+pkey);
return br;
}
public boolean getTicketAutoEscalate() {
return ticket_auto_escalate;
}
@Override
public SchemaTable.TableID getTableID() {
return SchemaTable.TableID.RESELLERS;
}
@Override
public void init(ResultSet result) throws SQLException {
try {
int pos = 1;
pkey = AccountingCode.valueOf(result.getString(pos++));
ticket_auto_escalate = result.getBoolean(pos++);
} catch(ValidationException e) {
throw new SQLException(e);
}
}
@Override
public void read(CompressedDataInputStream in) throws IOException {
try {
pkey=AccountingCode.valueOf(in.readUTF()).intern();
ticket_auto_escalate = in.readBoolean();
} catch(ValidationException e) {
throw new IOException(e);
}
}
@Override
public void write(CompressedDataOutputStream out, AOServProtocol.Version version) throws IOException {
out.writeUTF(pkey.toUpperCase());
out.writeBoolean(ticket_auto_escalate);
}
public List getTicketAssignments() throws IOException, SQLException {
return table.connector.getTicketAssignments().getTicketAssignments(this);
}
/**
* Gets the immediate parent of this reseller or null
if none available.
*/
public Reseller getParentReseller() throws IOException, SQLException {
Business bu = getBrand().getBusiness();
if(bu==null) return null;
Business parent = bu.getParentBusiness();
while(parent!=null) {
Brand parentBrand = parent.getBrand();
if(parentBrand!=null) {
Reseller parentReseller = parentBrand.getReseller();
if(parentReseller!=null) return parentReseller;
}
}
return null;
}
/**
* The children of the resller are any resellers that have their closest parent
* business (that is a reseller) equal to this one.
*/
public List getChildResellers() throws IOException, SQLException {
List children = new ArrayList<>();
for(Reseller reseller : table.connector.getResellers().getRows()) {
if(!reseller.equals(this) && this.equals(reseller.getParentReseller())) children.add(reseller);
}
return children;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy