taylor 01/11/12 08:02:19 Modified: src/java/org/apache/jetspeed/services/psmlmanager/db DatabaseInitializer.java Added: src/java/org/apache/jetspeed/services/psmlmanager PsmlImporter.java Log: imports Psml from file system to database Revision Changes Path 1.1 jakarta-jetspeed/src/java/org/apache/jetspeed/services/psmlmanager/PsmlImporter.java Index: PsmlImporter.java =================================================================== /* ==================================================================== * The Apache Software License, Version 1.1 * * Copyright (c) 2000-2001 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, * if any, must include the following acknowledgment: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowledgment may appear in the software itself, * if and wherever such third-party acknowledgments normally appear. * * 4. The names "Apache" and "Apache Software Foundation" and * "Apache Jetspeed" must not be used to endorse or promote products * derived from this software without prior written permission. For * written permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache" or * "Apache Jetspeed", nor may "Apache" appear in their name, without * prior written permission of the Apache Software Foundation. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. */ package org.apache.jetspeed.services.psmlmanager; import java.util.Iterator; import org.apache.turbine.om.security.User; import org.apache.turbine.om.security.Role; import org.apache.turbine.om.security.Group; import org.apache.turbine.om.security.TurbineUser; import org.apache.turbine.om.security.TurbineRole; import org.apache.turbine.om.security.TurbineGroup; import org.apache.turbine.services.TurbineServices; import org.apache.jetspeed.services.psmlmanager.db.DatabasePsmlManagerService; // Jetspeed Security service import org.apache.jetspeed.services.JetspeedSecurity; // Profile and ProfileLocator interface import org.apache.jetspeed.om.profile.Profile; import org.apache.jetspeed.om.profile.ProfileLocator; import org.apache.jetspeed.services.PsmlManager; import org.apache.jetspeed.om.profile.QueryLocator; import org.apache.turbine.services.InitializationException; import org.apache.turbine.util.TurbineConfig; import org.apache.turbine.util.security.DataBackendException; import org.apache.turbine.util.security.UnknownEntityException; import org.apache.turbine.util.Log; /** * Reads all PSML files from the file system and imports them into PSML DB * * @author <a href="mailto:[EMAIL PROTECTED]">David Sean Taylor</a> * @version */ public class PsmlImporter { public PsmlImporter() { } public void run() { System.out.println("in run of impporter"); if (alreadyImported()) return; try { 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); } } catch (Exception e) { System.out.println("Error importing: " + e.toString()); Log.error("Error importing: " + e.toString()); e.printStackTrace(); } System.out.println("ending importer"); } 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(); 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("----------------------"); } private boolean alreadyImported() { try { // 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()) { return true; // record found } return false; // record not found } catch (UnknownEntityException e) { return false; // record not found } catch (DataBackendException e) { Log.error("Error detecting database on import: " + e.toString()); System.out.println("Error detecting database on import: " + e.toString()); } return false; } } 1.2 +1 -0 jakarta-jetspeed/src/java/org/apache/jetspeed/services/psmlmanager/db/DatabaseInitializer.java Index: DatabaseInitializer.java =================================================================== RCS file: /home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/services/psmlmanager/db/DatabaseInitializer.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- DatabaseInitializer.java 2001/11/12 03:40:28 1.1 +++ DatabaseInitializer.java 2001/11/12 16:02:19 1.2 @@ -600,6 +600,7 @@ while (files.hasNext()) { + Profile profile = mapFileToProfile((File)files.next()); dumpProfile(profile);
-- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>