001 package videoautomat;
002 import sale.SaleProcess;
003 import sale.SalesPoint;
004 import users.ActionCapability;
005 import users.User;
006 import videoautomat.gui.Global;
007 import data.ooimpl.DataBasketImpl;
008 import data.ooimpl.StoringStockImpl;
009
010 /**
011 * This class implements the <code>User</code> of this application. It contains a <code>StoringStock</code> for
012 * storing the actually rented videos and holds the information which capabilities the user has.
013 */
014 public class AutomatUser extends User {
015 /**
016 * Key used to get the <code>ActionCapability</code> used to start a {@link SaleProcessAdmin}.
017 */
018 public static final String CAPABILITY_ADMIN = "admin";
019 /*
020 * The stock which holds the rented videos.
021 */
022 private StoringStockImpl ss_videos;
023 /**
024 * Constructs a new <code>AutomatUser</code>.
025 *
026 * @param user_ID
027 * the ID of the new user
028 * @param admin
029 * boolean to decide, whether this user has administrator privileges or not
030 */
031 public AutomatUser(String user_ID, char[] passWd, boolean admin) {
032 super(user_ID);
033 setPassWd(garblePassWD(passWd));
034 ss_videos = new StoringStockImpl(user_ID, VideoShop.getVideoCatalog());
035 ss_videos.addStockChangeListener(new StockChangeLogger(user_ID));
036 setCapability(new ActionCapability(
037 CAPABILITY_ADMIN,
038 Global.MSG_ACCESS,
039 new sale.Action() {
040 public void doAction(SaleProcess p, SalesPoint sp) throws Throwable {
041 sp.runProcess(new SaleProcessAdmin(), new DataBasketImpl());
042 }
043 }, admin));
044 }
045 /**
046 * @return a <code>StoringStock</code> containing the rented {@link VideoCassette}s of this user
047 */
048 public StoringStockImpl getVideoStock() {
049 return ss_videos;
050 }
051 }
052