taylor      01/11/19 21:01:22

  Modified:    src/java/org/apache/jetspeed/services/psmlmanager
                        CastorPsmlManagerService.java PsmlImporter.java
                        PsmlManagerService.java
               src/java/org/apache/jetspeed/services/psmlmanager/db
                        DatabasePsmlManagerService.java
  Removed:     src/java/org/apache/jetspeed/services/psmlmanager/db
                        DatabaseInitializer.java
  Log:
  - added export() method to PsmlManagerService interface.
  - updated PsmlImporter to use export() entry point
  - wrote CastorPsmlManagerService.export() to properly handle service initialization 
and multiple service problems.
  - still todo: write export() method for DatabasePsmlManagerService (to export from 
db to file system)
  
  Revision  Changes    Path
  1.12      +101 -29   
jakarta-jetspeed/src/java/org/apache/jetspeed/services/psmlmanager/CastorPsmlManagerService.java
  
  Index: CastorPsmlManagerService.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/services/psmlmanager/CastorPsmlManagerService.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- CastorPsmlManagerService.java     2001/11/12 03:40:25     1.11
  +++ CastorPsmlManagerService.java     2001/11/20 05:01:22     1.12
  @@ -112,7 +112,7 @@
    * @author <a href="mailto:[EMAIL PROTECTED]";>Raphaël Luta</a>
    * @author <a href="mailto:[EMAIL PROTECTED]";>David Sean Taylor</a>
    * @author <a href="mailto:[EMAIL PROTECTED]";>Santiago Gala</a>
  - * @version $Id: CastorPsmlManagerService.java,v 1.11 2001/11/12 03:40:25 taylor 
Exp $
  + * @version $Id: CastorPsmlManagerService.java,v 1.12 2001/11/20 05:01:22 taylor 
Exp $
    */
   public class CastorPsmlManagerService extends TurbineBaseService
       implements PsmlManagerService
  @@ -153,18 +153,21 @@
       /** the base refresh rate for documents */
       private long scanRate = 1000 * 60;
   
  +    /** the import/export consumer service **/
  +    private PsmlManagerService consumer = null;
  +    private boolean importFlag = false;
  +
       /**
        * This is the early initialization method called by the 
        * Turbine <code>Service</code> framework
        */
       public void init( ServletConfig conf ) throws InitializationException
       {
  -        System.out.println("in castor psml init");
           if (getInit())
           {
               return;
           }
  -
  +      
           // get configuration parameters from Jetspeed Resources
           ResourceService serviceConf = 
((TurbineServices)TurbineServices.getInstance())
                                                        
.getResources(PsmlManagerService.SERVICE_NAME);
  @@ -196,7 +199,6 @@
   
           //Mark that we are done
           setInit(true);
  -        System.out.println("exit castor psml init");
   
           // Test
           //testCases();
  @@ -207,8 +209,6 @@
       /** Late init method from Turbine Service model */
       public void init() throws InitializationException
       {
  -        System.out.println("in late castor psml init");
  -
           while( !getInit() )
           {
               //Not yet...
  @@ -221,8 +221,6 @@
                   Log.error( ie );
               }
           }
  -        System.out.println("exit LATE castor psml init");
  -
       }
   
       
  @@ -339,7 +337,7 @@
               synchronized (documents)
               {
                   // store the document in the hash and reference it to the watcher
  -                Profile newProfile = new BaseProfile(locator);
  +                Profile newProfile = createProfile(locator); 
                   newProfile.setDocument(doc);
                   documents.put(name, new WeakReference(newProfile));
               }
  @@ -385,6 +383,7 @@
                   doc.setPortlets(portlets);
   
                   this.watcher.addFile(fileOrUrl,f);
  +
               }
               catch (IOException e)
               {
  @@ -995,7 +994,7 @@
           int qm = locator.getQueryMode();
           if ((qm & QueryLocator.QUERY_ANON) == QueryLocator.QUERY_ANON)
           {
  -            Profile profile = new BaseProfile();
  +            Profile profile = createProfile();
               profile.setAnonymous(true);
               StringBuffer path = new StringBuffer();
               path.append(PATH_ANON);
  @@ -1012,7 +1011,7 @@
           }
           if ((qm & QueryLocator.QUERY_USER) == QueryLocator.QUERY_USER)
           {
  -            Profile profile = new BaseProfile();
  +            Profile profile = createProfile();
               StringBuffer path = new StringBuffer();
               path.append(PATH_USER);
               String name = null;
  @@ -1040,7 +1039,7 @@
           }
           if ((qm & QueryLocator.QUERY_ROLE) == QueryLocator.QUERY_ROLE)
           {
  -            Profile profile = new BaseProfile();
  +            Profile profile = createProfile();
               StringBuffer path = new StringBuffer();
               path.append(PATH_ROLE);
               String name = null;
  @@ -1068,7 +1067,7 @@
           }
           if ((qm & QueryLocator.QUERY_GROUP) == QueryLocator.QUERY_GROUP)
           {
  -            Profile profile = new BaseProfile();
  +            Profile profile = createProfile();
               StringBuffer path = new StringBuffer();
               path.append(PATH_GROUP);
               String name = null;
  @@ -1098,6 +1097,63 @@
           return list.iterator();
       }
   
  +    /** Create a profile based on import flag.
  +     *
  +     */
  +    private Profile createProfile()
  +    {
  +        if (importFlag)
  +            return new ImportProfile(this, this.consumer);
  +        else
  +            return new BaseProfile();
  +    }
  +
  +    private Profile createProfile(ProfileLocator locator)
  +    {
  +        if (importFlag)
  +            return new ImportProfile(this, this.consumer, locator);
  +        else
  +            return new BaseProfile(locator);
  +    }
  +
  +    /** Query for a collection of profiles given a profile locator criteria.
  +     *  This method should be used when importing or exporting profiles between 
services.
  +     *
  +     * @param locator The profile locator criteria.
  +     * @return The count of profiles exported.
  +     */
  +    public int export(PsmlManagerService consumer, QueryLocator locator)
  +    {
  +        importFlag = true;
  +        Iterator profiles = null;
  +        int count = 0;
  +        try
  +        {
  +            this.consumer = consumer;
  +            profiles = query(locator);
  +        
  +            while (profiles.hasNext() )
  +            {
  +                Profile profile = (Profile)profiles.next();
  +                //dumpProfile(profile);
  +                consumer.createDocument(profile);  
  +                count++;
  +            }
  +        }
  +        catch(Exception e)
  +        {
  +            e.printStackTrace();
  +            Log.error("Failed to export profiles to DB: " + e.toString() );
  +
  +        }
  +        finally
  +        {
  +            importFlag = false;
  +        }
  +        return count;
  +    }
  +
  +
       /** Query for a collection of profiles given a profile locator criteria.
        *  To specify 'all' - use '*' in the criteria
        *
  @@ -1343,24 +1399,40 @@
           while (it.hasNext() )
           {
               Profile profile = (Profile)it.next();
  -            User user = profile.getUser();
  -            Group group = profile.getGroup();
  -            Role role = profile.getRole();
  -            if (profile.getAnonymous() == true)
  -                System.out.println("ANON USER");
  -            System.out.println("RESOURCE = " + profile.getName());
  -            if (null != user)
  -                System.out.println("USER = " + user.getUserName() );
  -            if (null != group)
  -                System.out.println("GROUP = " + group.getName() );
  -            if (null != role)
  -                System.out.println("ROLE = " + role.getName() );
  -            System.out.println("MEDIA TYPE = " + profile.getMediaType());
  -            System.out.println("LANGUAGE = " + profile.getLanguage());
  -            System.out.println("COUNTRY = " + profile.getCountry());
  -            System.out.println("----------------------");
  +            dumpProfile(profile);
           }
           System.out.println("===============================================");
  +    }
  +
  +    private void dumpProfile(Profile profile)
  +    {
  +        User user = profile.getUser();
  +        Group group = profile.getGroup();
  +        Role role = profile.getRole();
  +        if (profile.getAnonymous() == true)
  +            System.out.println("ANON USER");
  +        System.out.println("RESOURCE = " + profile.getName());
  +        if (null != user)
  +            System.out.println("USER = " + user.getUserName() );
  +        if (null != group)
  +            System.out.println("GROUP = " + group.getName() );
  +        if (null != role)
  +            System.out.println("ROLE = " + role.getName() );
  +        System.out.println("MEDIA TYPE = " + profile.getMediaType());
  +        System.out.println("LANGUAGE = " + profile.getLanguage());
  +        System.out.println("COUNTRY = " + profile.getCountry());
  +        PSMLDocument doc = profile.getDocument();
  +        if (null == doc)
  +            System.out.println("Document is null");
  +        else
  +        {
  +            if (null == profile.getName())
  +                System.out.println("profile name is null");
  +            else
  +                System.out.println("Doc.name=" + profile.getName());
  +        }    
  +
  +        System.out.println("----------------------");
       }
   
   }
  
  
  
  1.2       +17 -31    
jakarta-jetspeed/src/java/org/apache/jetspeed/services/psmlmanager/PsmlImporter.java
  
  Index: PsmlImporter.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/services/psmlmanager/PsmlImporter.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- PsmlImporter.java 2001/11/12 16:02:19     1.1
  +++ PsmlImporter.java 2001/11/20 05:01:22     1.2
  @@ -81,6 +81,7 @@
   import org.apache.turbine.util.security.DataBackendException; 
   import org.apache.turbine.util.security.UnknownEntityException; 
   import org.apache.turbine.util.Log;
  +import javax.servlet.ServletConfig;
   
   /**
    * Reads all PSML files from the file system and imports them into PSML DB
  @@ -94,48 +95,32 @@
       {
       }
   
  -    public void run()
  +    public void run(ServletConfig conf)
       {
  -        System.out.println("in run of impporter");
  -        if (alreadyImported())
  -            return;
  -
  +        String msg = "Running PSMLImporter...";
  +        System.out.println(msg);
  +        Log.note(msg);
  +        int count = 0;
           try
           {
  +           if (alreadyImported())
  +                return; 
               PsmlManagerService fileService = 
(PsmlManagerService)TurbineServices.getInstance().getService("PsmlImportManager");     
               QueryLocator locator = new QueryLocator(QueryLocator.QUERY_ALL);
  -            Iterator profiles = fileService.query(locator);
  -            System.out.println("Starting");
  -    
  -            while (profiles.hasNext() )
  -            {
  -                Profile profile = (Profile)profiles.next();
  -                dumpProfile(profile);
  -                PsmlManager.store(profile);  
  -            }
  +            count = fileService.export(PsmlManager.getService(), locator);
           }
           catch (Exception e)
           {
               System.out.println("Error importing: " + e.toString());
               Log.error("Error importing: " + e.toString());
               e.printStackTrace();
  -        }
  -        System.out.println("ending importer");
  -
  +        }             
  +        msg = "PSMLImporter completed. Exported " + count + " profiles";
  +        System.out.println(msg);
  +        Log.note(msg);
       }
   
   
  -    private void dump( Iterator it )
  -    {
  -        System.out.println("===============================================");
  -        while (it.hasNext() )
  -        {
  -            Profile profile = (Profile)it.next();
  -            dumpProfile(profile);
  -        }
  -        System.out.println("===============================================");
  -    }
  -
       private void dumpProfile(Profile profile)
       {
           User user = profile.getUser();
  @@ -162,14 +147,15 @@
           {
               // dst: why not get a count(*) from ANON table?
   
  -            //User user = securityService.getUser(admin);
               User user = JetspeedSecurity.getUser("admin");
               QueryLocator ql = new QueryLocator(QueryLocator.QUERY_USER);
               ql.setUser(user);
  -            //Iterator iterator = psmlManagerService.query(ql);
               Iterator iterator = PsmlManager.query(ql);
               while (iterator.hasNext())
  -            {
  +            {                      
  +                String msg = "PSMLImporter: Detected database is populated. No need 
to import.";
  +                System.out.println(msg);
  +                Log.info(msg);
                   return true;    // record found
               }
               return false;   // record not found
  
  
  
  1.8       +11 -1     
jakarta-jetspeed/src/java/org/apache/jetspeed/services/psmlmanager/PsmlManagerService.java
  
  Index: PsmlManagerService.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/services/psmlmanager/PsmlManagerService.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- PsmlManagerService.java   2001/11/12 03:40:26     1.7
  +++ PsmlManagerService.java   2001/11/20 05:01:22     1.8
  @@ -70,7 +70,7 @@
    * This service is responsible for loading and saving PSML documents.
    *
    * @author <a href="mailto:[EMAIL PROTECTED]";>Raphaël Luta</a>
  - * @version $Id: PsmlManagerService.java,v 1.7 2001/11/12 03:40:26 taylor Exp $
  + * @version $Id: PsmlManagerService.java,v 1.8 2001/11/20 05:01:22 taylor Exp $
    */
   public interface PsmlManagerService extends Service
   {
  @@ -162,9 +162,19 @@
       /** Query for a collection of profiles given a profile locator criteria.
        *
        * @param locator The profile locator criteria.
  +     *
  +     * @return A collection of profiles that match the criteria specified in the 
locator.
        */
       public Iterator query( QueryLocator locator );
   
  +    /** Export profiles from this service into another service
  +     *
  +     * @param consumer The PSML consumer service, receives PSML from this service.
  +     * @param locator The profile locator criteria.
  +     *
  +     * @return The count of profiles exported.
  +     */
  +    public int export(PsmlManagerService consumer, QueryLocator locator);
   
   }
   
  
  
  
  1.3       +18 -10    
jakarta-jetspeed/src/java/org/apache/jetspeed/services/psmlmanager/db/DatabasePsmlManagerService.java
  
  Index: DatabasePsmlManagerService.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/services/psmlmanager/db/DatabasePsmlManagerService.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- DatabasePsmlManagerService.java   2001/11/12 16:06:08     1.2
  +++ DatabasePsmlManagerService.java   2001/11/20 05:01:22     1.3
  @@ -143,13 +143,15 @@
       private final static String REFRESH_RATE = "refresh-rate";
       private final static long DEFAULT_REFRESH_RATE = 60 * 60 * 8 * 1000; //8hrs
   
  +    /** the import/export consumer service **/
  +    private PsmlManagerService consumer = null;
  +
       /**
        * This is the early initialization method called by the
        * Turbine <code>Service</code> framework
        */
       public void init(ServletConfig conf) throws InitializationException 
       {
  -        System.out.println("initalizing Dbpsml");
           if (getInit())
           {
               return;
  @@ -161,23 +163,17 @@
           //Mark that we are done
           setInit(true);
           Log.note("Done initializing DatabasePsmlManagerService.");
  -        System.out.println("done initalizing Dbpsml");
  -
  -        System.out.println("Running Importer");
   
           try
           {
               PsmlImporter importer = new PsmlImporter();
  -            importer.run();
  +            importer.run(conf);
           }
           catch (Exception e)
           {
  -            System.out.println("Error importing: " + e.toString());
               Log.error("Error importing: " + e.toString());
               e.printStackTrace();            
           }
  -        System.out.println("Done Running Importer");
  -
       }
   
       /**
  @@ -207,8 +203,8 @@
               throw new InitializationException("Missing default refresh rate 
parameter, during initializing DatabasePsmlManagerService, using defaults");
           }
   
  -        this.refresher = new CacheRefresher();
  -        refresher.start();
  +//        this.refresher = new CacheRefresher();
  + //       refresher.start();
   
       }
   
  @@ -749,6 +745,7 @@
           catch (Exception e)
           {
               Log.error("Error occurred in Database PSML Manager: " + e);
  +            e.printStackTrace();
           }
   
           return new ArrayList().iterator();  // return empty non-null iterator
  @@ -1006,5 +1003,16 @@
               Log.error("Delete from table JETSPEED_GROUP_PROFILE failed");
               throw new RuntimeException("Could not delete documents for given group 
from DB");
           }
  +    }
  +
  +    /** Query for a collection of profiles given a profile locator criteria.
  +     *  This method should be used when importing or exporting profiles between 
services.
  +     *
  +     * @param locator The profile locator criteria.
  +     * @return The count of profiles exported.
  +     */
  +    public int export(PsmlManagerService consumer, QueryLocator locator)
  +    {
  +        return 0; // TODO: implement
       }
   }
  
  
  

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to