package com.rostrvmsolutions.rostrvm.controlcentre.model; import com.rostrvmsolutions.rostrvm.controlcentre.gui.IDialogNewName; import com.rostrvmsolutions.rostrvm.controlcentre.model.folderdecorators.AdVisorFolderDecorator; import com.rostrvmsolutions.rostrvm.controlcentre.model.folderdecorators.AgentGroupFolderDecorator; import com.rostrvmsolutions.rostrvm.controlcentre.model.folderdecorators.AllUsersFolderDecorator; import com.rostrvmsolutions.rostrvm.controlcentre.model.folderdecorators.AnyPhoneFolderDecorator; import com.rostrvmsolutions.rostrvm.controlcentre.model.folderdecorators.BusinessOutcomesFolderDecorator; import com.rostrvmsolutions.rostrvm.controlcentre.model.folderdecorators.CallClassesFolderDecorator; import com.rostrvmsolutions.rostrvm.controlcentre.model.folderdecorators.CallDirectorACDFolderDecorator; import com.rostrvmsolutions.rostrvm.controlcentre.model.folderdecorators.CampaignFolderDecorator; import com.rostrvmsolutions.rostrvm.controlcentre.model.folderdecorators.CampaignsFolderDecorator; import com.rostrvmsolutions.rostrvm.controlcentre.model.folderdecorators.ControlCentreFolderDecorator; import com.rostrvmsolutions.rostrvm.controlcentre.model.folderdecorators.DoNotCallsFolderDecorator; import com.rostrvmsolutions.rostrvm.controlcentre.model.folderdecorators.FileEditorFolderDecorator; import com.rostrvmsolutions.rostrvm.controlcentre.model.folderdecorators.HardwareFolderDecorator; import com.rostrvmsolutions.rostrvm.controlcentre.model.folderdecorators.IFolderDecorator; import com.rostrvmsolutions.rostrvm.controlcentre.model.folderdecorators.IVRFolderDecorator; import com.rostrvmsolutions.rostrvm.controlcentre.model.folderdecorators.LineGroupFolderDecorator; import com.rostrvmsolutions.rostrvm.controlcentre.model.folderdecorators.ListFolderDecorator; import com.rostrvmsolutions.rostrvm.controlcentre.model.folderdecorators.ListsFolderDecorator; import com.rostrvmsolutions.rostrvm.controlcentre.model.folderdecorators.OutBoundFolderDecorator; import com.rostrvmsolutions.rostrvm.controlcentre.model.folderdecorators.RostrvmFolderDecorator; import com.rostrvmsolutions.rostrvm.controlcentre.model.folderdecorators.RoutingScriptFolderDecorator; import com.rostrvmsolutions.rostrvm.controlcentre.model.folderdecorators.CallDirectorFolderDecorator; import com.rostrvmsolutions.rostrvm.controlcentre.model.folderdecorators.DataManagementFolderDecorator; import com.rostrvmsolutions.rostrvm.controlcentre.model.folderdecorators.SkillsFolderDecorator; import com.rostrvmsolutions.rostrvm.controlcentre.model.folderdecorators.SkipCallsFolderDecorator; import com.rostrvmsolutions.rostrvm.controlcentre.model.folderdecorators.SoftACDQueueFolderDecorator; import com.rostrvmsolutions.rostrvm.controlcentre.model.folderdecorators.SuperVisorFolderDecorator; import com.rostrvmsolutions.rostrvm.controlcentre.model.folderdecorators.SwitchFolderDecorator; import com.rostrvmsolutions.rostrvm.controlcentre.model.folderdecorators.UserGroupFolderDecorator; import com.rostrvmsolutions.rostrvm.controlcentre.model.folderdecorators.UserGroupsFolderDecorator; import com.rostrvmsolutions.rostrvm.controlcentre.model.folderdecorators.UserStatusCodesFolderDecorator; import com.rostrvmsolutions.rostrvm.controlcentre.resources.Resources; import com.rostrvmsolutions.rostrvm.webservicebeans.controlcentre.Folder; import com.rostrvmsolutions.rostrvm.webservicebeans.controlcentre.Item; import com.rostrvmsolutions.rostrvm.webservicebeans.controlcentre.ItemProperties; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.TreeMap; /** * A wrapper around a folder and its data. It uses the decorator pattern to provide extra folder data. * @author Robert Stone * @version 7.0 * @since 7.0 */ public final class FolderDelegate { private static final Map decorators=new HashMap(); private final Folder folder; private final List items; private final Map itemRows=new HashMap(); private final List columnNames; private final String displayName; private IFolderDecorator decorator; static { decorators.put("rostrvm", new RostrvmFolderDecorator()); decorators.put("UserGroups", new UserGroupsFolderDecorator()); decorators.put("User Group:AllUsers", new AllUsersFolderDecorator()); decorators.put("Campaign", new CampaignFolderDecorator()); decorators.put("Campaigns", new CampaignsFolderDecorator()); decorators.put("List", new ListFolderDecorator()); decorators.put("Lists", new ListsFolderDecorator()); decorators.put("User Group", new UserGroupFolderDecorator()); decorators.put("Hardware", new HardwareFolderDecorator()); decorators.put("Switch:CallDirector ACD", new CallDirectorACDFolderDecorator()); decorators.put("BusinessOutcomes", new BusinessOutcomesFolderDecorator()); decorators.put("CallClasses", new CallClassesFolderDecorator()); decorators.put("RoutingScript", new RoutingScriptFolderDecorator()); decorators.put("Skills", new SkillsFolderDecorator()); decorators.put("UserStatusCodes", new UserStatusCodesFolderDecorator()); decorators.put("SkipCalls", new SkipCallsFolderDecorator()); decorators.put("DoNotCalls", new DoNotCallsFolderDecorator()); decorators.put("CallDirectors", new CallDirectorFolderDecorator()); decorators.put(SwitchFolderDecorator.AGENT_GROUP, new AgentGroupFolderDecorator()); decorators.put("LineGroup", new LineGroupFolderDecorator()); decorators.put("AnyPhone", new AnyPhoneFolderDecorator()); decorators.put(HardwareFolderDecorator.TYPE_SWITCH, new SwitchFolderDecorator()); decorators.put("IVR", new IVRFolderDecorator()); decorators.put("OutBound", new OutBoundFolderDecorator()); decorators.put("SuperVisor", new SuperVisorFolderDecorator()); decorators.put("SoftACDQueue", new SoftACDQueueFolderDecorator()); decorators.put("AdVisor", new AdVisorFolderDecorator()); decorators.put("ControlCentre", new ControlCentreFolderDecorator()); decorators.put("FileEditor", new FileEditorFolderDecorator()); decorators.put("DataManagement", new DataManagementFolderDecorator()); } /** * Find a decorator for the given folder type and name * @param type the folder type * @param name the folder name * @return the decorator (or null if none was found) */ public static IFolderDecorator getFolderDecorator(final String type, final String name) { IFolderDecorator decorator=decorators.get(type + ":" + name); if (decorator==null) { decorator=decorators.get(type); } return decorator; } /** * Create a new folder delegate * @param parentFolder the folder that contains this folder * @param folder the folder as read from the server */ public FolderDelegate(final FolderDelegate parentFolder, final Folder folder) { this.decorator=getFolderDecorator(folder.getType(), folder.getName()); this.folder=folder; this.displayName=parentFolder==null || !parentFolder.getFolder().isDynamic() ? Resources.getResource("_Folder_" + folder.getName(), folder.getName()) : folder.getName(); if (decorator==null) { // No decorator - get out list of column names and items from the // folder that was read from the server this.columnNames=processColumnIds(folder.getColumnIds()); this.items=new ArrayList(); for (Item item : folder.getItems()) { this.items.add(new ItemDelegate(folder, item)); } } else { // A decorator - it supplies our column names and items this.columnNames=processColumnIds(decorator.getColumnIds(this)); this.items=decorator.getItems(folder); } // Give each row an integer index int row=0; for (ItemDelegate item : items) { if (item!=null) { itemRows.put(item.getName().toLowerCase(), row++); } } } /** * Converts column Ids into meaningful names * @param columnIds a list of column Ids * @return a list of column names */ private List processColumnIds(final List columnIds) { final List newColumnNames=new ArrayList(columnIds.size()); for (String id : columnIds) { newColumnNames.add(Resources.getResource("_Column_" + id, id)); } return newColumnNames; } /** * @return the items contained in the folder */ public List getItems() { return items; } /** * @return the column names */ public List getColumnNames() { return columnNames; } /** * @return the folder as read from the server */ public Folder getFolder() { return folder; } /** * Return the integer index for a given item * @param itemName the item to locate * @return the index */ public Integer getItemRow(final String itemName) { return itemRows.get(itemName.toLowerCase()); } /** * Return the task groups that are applicable for the selected items * @param selection * @return a list of task groups */ public List getTaskGroups(final List selection) { return decorator==null ? null : decorator.getTaskGroups(this, selection); } /** * @return the types available for creating new items in this folder */ public List getNewTypes() { return decorator==null ? null : decorator.getNewTypes(this); } /** * The properties that should be applied to new items created in this folder * @param itemType the type of item * @param newNameDialog the dialog used to create the item * @return a list of properties to be applied to the item */ public List getNewItemPropertyValues( final String itemType, final IDialogNewName newNameDialog, final Object userData) { return decorator==null ? null : decorator.getNewItemPropertyValues(this, itemType, newNameDialog); } /** * @return the folder name */ public String getName() { return folder.getName(); } /** * @return the folder type */ public String getType() { return folder.getType(); } /** * @return the type used when storing this folders settings */ public String getSettingsType() { return decorator==null ? getType() : decorator.getSettingsType(this); } /** * @return the display name for the folder */ public String getDisplayName() { return displayName; } /** * Run a task * @param taskGroupId the task group id * @param taskId the task id * @param items the currently selected items */ public void runTask(final String taskGroupId, final String taskId, final List items) { if (decorator!=null) { decorator.runTask(this, items, taskGroupId, taskId); } } /** * @return the type to be used when denying access to this folder */ public List getNoAccessType() { final List empty=Collections.emptyList(); return decorator==null ? empty : decorator.getNoAccessType(this); } /** * Called after a new item has been created in this folder * @param newType the item type * @param newName the item name * @param newNameDialog the dialog that was used when creating the item * @return null for success, or a failure id */ public String postNew(final String newType, final String newName, final IDialogNewName newNameDialog) { return decorator==null ? null : decorator.postNew(this, newType, newName, newNameDialog); } @Override public boolean equals(Object obj) { final FolderDelegate otherFolder=(FolderDelegate)obj; // We consider folders to be equal if they have the same type and name return otherFolder==this || (otherFolder.getType().equals(getType()) && otherFolder.getName().equals(getName())); } @Override public int hashCode() { return getType().hashCode() + getName().hashCode(); } /** * Return the extra parameters to be used when deleteing items * @param items the items being deleted * @return the extra query parameters */ public List getDeleteExtraQueryParameters(final List items) { return decorator==null ? null : decorator.getDeleteExtraQueryParameters(this, items); } /** * Return the extra parameters to be used when renaming an item * @param renameItem the item being renamed * @return the extra query parameters */ public List getRenameExtraQueryParameters(final ItemDelegate renameItem) { return decorator==null ? null : decorator.getRenameExtraQueryParameters(this, renameItem); } /** * @return the extra query parameters to be used when creating a new item */ public List getNewExtraQueryParameters() { return decorator==null ? null : decorator.getNewExtraQueryParameters(this); } /** * Return the template to be used for creating component names * @param type the item type * @param subType the item sub type * @return the template */ public String getAutoGenerateOnNewTemplate(final String type, final String subType) { return decorator==null ? null : decorator.getAutoGenerateOnNewTemplate(this, type, subType); } /** * Return the sub types that are appopriate for the given item type * @param type the item type * @return a list of sub types */ public List getSubTypes(final String type) { return decorator==null ? null : decorator.getSubTypes(this, type); } /** * @return true if this folder support real time MIS, false if not */ public boolean supportsRealTimeMis() { return decorator==null ? false : decorator.supportsRealTimeMis(this); } /** * @return true if this folder support real time MIS only (ie. it doesn't refresh from the database), false if not */ public boolean isRealTimeUpdatesOnly() { return decorator==null ? false : decorator.isRealTimeUpdatesOnly(this); } /** * Return a name to use when creating new items. This will stop the user from * being able to enter a name. * @param type the item type * @return the name to use */ public String getNewNameOverride(final String type) { return decorator==null ? null : decorator.getNewNameOverride(this, type); } /** * Return the type that can be created * @param type the type * @return a type that can be created */ public String getNewTypeOverride(final String type) { return decorator==null ? type : decorator.getNewTypeOverride(this, type); } /** * Indicates whether or not a reconfigure is required afer creating a new item * @param newType the item type * @param newName the item name * @return true reconfigure required, false reconfigure not required */ public boolean isNewReconfigureRequired(final String newType, final String newName) { return decorator==null ? true : decorator.isNewReconfigureRequired(this, newType, newName); } /** * Return a dialog that is to be used when creating a new item * @param newType the item type * @param subTypes the possible sub types * @param nameAsNumber true if the item name is represented as a number, false if not * @param maxNameLength the maximum allowed length of the name * @param name the current name * @param enableShowProperties true to enable the 'Show Properties' false to disable * @throws com.rostrvmsolutions.rostrvm.controlcentre.comms.RostrvmAccessException * @throws com.rostrvmsolutions.rostrvm.webservicebeans.DatabaseLockedException * @return the dialog */ public IDialogNewName getNewNameDialog( final String newType, final List subTypes, final boolean nameAsNumber, final int maxNameLength, final String name, final boolean enableShowProperties) { return decorator==null ? null : decorator.getNewNameDialog( this, newType, subTypes, nameAsNumber, maxNameLength, name, enableShowProperties); } /** * @return the owner id for this folder */ public String[] getOwnerId() { return decorator==null ? null : decorator.getOwnerId(this); } /** * @return the tasks that are supported for all the folders we know about */ public static Map getSupportedTasks() { final Map supportedTasks=new TreeMap(); for (String type : decorators.keySet()) { final SupportedTasks itemSupportedTasks=decorators.get(type).getSupportedTasks(); if (itemSupportedTasks!=null) { supportedTasks.put(type, itemSupportedTasks); } } return supportedTasks; } /** * Return meta data that is used when working with a folder * @param folder the folder as read from the server * @param row the row of meta data to retrieve * @param column the column of meta data to retrive * @return the meta data */ public static String getFolderMetaData( final Folder folder, final int row, final int column) { final Object metaData=folder.getMetaDataColumns().get(row).getColumns().get(column); return metaData==null ? null : metaData.toString(); } /** * Return meta data that is used when working with a folder * @param folder the folder * @param row the row of meta data to retrieve * @param column the column of meta data to retrive * @return the meta data */ public static String getFolderMetaData( final FolderDelegate folder, final int row, final int column) { return getFolderMetaData(folder.getFolder(), row, column); } /** * @return return the permission types that are applicable for the folder */ public List getPermissionTypes() { return decorator==null ? Arrays.asList(getType()) : decorator.getPermissionTypes(this); } }