Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: org/acs/damsel/srvr/repository/RepositoryMgr.java


1   package org.acs.damsel.srvr.repository;
2   
3   import java.io.*;
4   import java.sql.*;
5   import java.util.*;
6   
7   import org.acs.damsel.client.*;
8   import org.acs.damsel.srvr.*;
9   import org.acs.damsel.srvr.asset.*;
10  import org.acs.damsel.srvr.auth.*;
11  import org.acs.damsel.srvr.collection.*;
12  import org.acs.damsel.srvr.collection.Collection;
13  import org.acs.damsel.srvr.db.*;
14  import org.apache.log4j.*;
15  
16  /**
17   * <p>Title: RepositoryMgr</p>
18   * <p>Description: The RepositoryMgr Class manages the assets in the database.
19   * Assets can be added and removed from the database through the RepositoryMgr.
20   * </p>
21   * @version 1.0
22   */
23  public class RepositoryMgr implements Serializable {
24  
25    private static Logger log = Logger.getLogger(RepositoryMgr.class);
26  
27    /**
28     * Default constructor
29     */
30    public RepositoryMgr() {
31      BasicConfigurator.resetConfiguration();
32      PropertyConfigurator.configure(Config.instance().getLogPropertiesFileName());
33    }
34  
35    /**
36     * Method retrieves an asset from the database given the asset's filename.
37     * @param FileName String containung the assets file name
38     * @return Asset, the asset retrieved from the database
39     * @throws SQLException
40     */
41    public Asset getAsset(String FileName) throws SQLException {
42      Asset a = AssetDB.instance().getAsset(FileName);
43      return a;
44    }
45  
46    /**
47     * Checks if a specified asset is contained in the database.  Returns true
48     * if contained in the database, false otherwise.
49     * @param a Asset
50     * @return boolean
51     * @throws SQLException
52     */
53    public boolean isInAssetTable(Asset a) throws SQLException {
54      return AssetDB.instance().isAssetInDB(a);
55    }
56  
57    /**
58     * Adds a specified asset to the database.  The asset is added to the given
59     * collection. If the collection is public, the Asset is also added to the
60     * AllAssets collection. Note that AssetDB.addAsset checks to see if the asset
61     * already belongs to the given collection or if the asset is already in the
62     * AssetsTable.  In those cases, the asset will not be added again.
63     * @param a Asset to be added to the given collection
64     * @param collectionName String containing the name of the collection that the
65     * asset is to be added to
66     * @returns int, the number of rows affected by the add
67     * @throws SQLException
68     */
69    public int addAsset(Asset a, String collectionName) throws SQLException {
70      int numReturned = 0;
71      Collection coll = null;
72  
73        coll = ClientApp.instance().getCollectionMgr().getCollection(
74            collectionName);
75  
76  
77      AuthMgr aMgr = ClientApp.instance().getAuthMgr();
78      numReturned = AssetDB.instance().addAsset(a, collectionName);
79      // Check if the Collection is public and the Collection is NOT equal to AllAssets
80      if(coll.isPublic()  && !coll.getCollectionName().equals("AllAssets")){
81        AssetDB.instance().addAsset(a, "AllAssets");
82      }
83      return numReturned;
84    }
85  
86    /**
87     * Removes a specified asset from the database if the asset is contained
88     * within the database. (Both the AssetsCollectionsTable AND the AssetTable)
89     * @param a Asset to be removed
90     * @return int, number of rows affected in the assettable
91     * @throws SQLException
92     */
93    public int removeAsset(Asset a) throws SQLException {
94      if (this.isInAssetTable(a)) {
95         AssetDB.instance().removeAssetFromAllCollections(a);
96         return AssetDB.instance().deleteAsset(a);
97      }
98      return 0;
99    }
100 
101   /**
102    * Removes the Asset only from the AssetsCollectionsTable, leaving it in the
103    * AssetTable.
104    * @param a Asset to be removed
105    * @return int, number of rows affected by delete
106    * @throws SQLException
107    */
108   public int removeAssetFromAllCollections(Asset a) throws SQLException {
109     return AssetDB.instance().removeAssetFromAllCollections(a);
110   }
111 
112   /**
113    * Removes the specified asset from the collection. Checks if asset is in the
114    * specified collection, if so, removes the asset from the collection (by
115    * deleting the row in the AssetsCollectionsTable) and returns true. If asset
116    * is not in the collection, returns false and does not remove.
117    * @param asset Asset to be removed from the Collection
118    * @param collectionName String containing collection to remove the Asset from
119    * @return boolean
120    * @throws SQLException
121    */
122   public boolean removeAssetFromCollection(Asset asset, String collectionName)
123       throws SQLException{
124       return AssetDB.instance().removeAssetFromCollection(asset, collectionName);
125   }
126 
127   /**
128    * Updates the specified assets entry in the database.
129    * @param a Asset
130    * @throws SQLException
131    */
132   public void updateAsset(Asset a) throws SQLException {
133     AssetDB.instance().updateAsset(a);
134   }
135 
136   /**
137    * Method retrieves a list of all repositories existing in the database.
138    * @return Vector containing repository names
139    * @throws SQLException
140    */
141   public Vector getRepositoryList() throws SQLException{
142     return AssetDB.instance().getRepositoryList();
143   }
144 }