[Amavisadmin-svn] SF.net SVN: amavisadmin: [21] amavisadmin/trunk
Status: Beta
Brought to you by:
streindl
From: <str...@us...> - 2007-01-17 18:37:40
|
Revision: 21 http://amavisadmin.svn.sourceforge.net/amavisadmin/?rev=21&view=rev Author: streindl Date: 2007-01-17 10:27:34 -0800 (Wed, 17 Jan 2007) Log Message: ----------- Migration job handling and first job for initial migration Modified Paths: -------------- amavisadmin/trunk/tools/reposInfo.pl Added Paths: ----------- amavisadmin/trunk/src/java/de/sreindl/amavisadmin/migration/ amavisadmin/trunk/src/java/de/sreindl/amavisadmin/migration/MigrateV0toV1.java amavisadmin/trunk/src/java/de/sreindl/amavisadmin/migration/MigrationJob.java Added: amavisadmin/trunk/src/java/de/sreindl/amavisadmin/migration/MigrateV0toV1.java =================================================================== --- amavisadmin/trunk/src/java/de/sreindl/amavisadmin/migration/MigrateV0toV1.java (rev 0) +++ amavisadmin/trunk/src/java/de/sreindl/amavisadmin/migration/MigrateV0toV1.java 2007-01-17 18:27:34 UTC (rev 21) @@ -0,0 +1,117 @@ +/* + * Copyright (C) 2007 Stephen Reindl + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +/* + * MigrateV0toV1.java + * + * Created on 16. Januar 2007, 19:24 + * + */ + +package de.sreindl.amavisadmin.migration; + +import de.sreindl.amavisadmin.db.MailAddress; +import de.sreindl.amavisadmin.db.MailAddressDAO; +import de.sreindl.amavisadmin.db.User; +import de.sreindl.amavisadmin.db.UserDAO; +import de.sreindl.amavisadmin.db.util.HibernateSessionFactory; +import java.util.Iterator; +import java.util.List; +import javax.swing.text.rtf.RTFEditorKit; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.hibernate.Query; +import org.hibernate.Session; +import org.hibernate.Transaction; + +/** + * The following activities are performed here: + *<ul> + *<li> Create default user if not already there </li> + *<li> Update table maddr table to include the user email addresses of + * the already registered users (if any).</li> + *</ul> + * @author sreindl + */ +public class MigrateV0toV1 implements MigrationJob { + + private static Log log = LogFactory.getLog(MigrateV0toV1.class); + + /** Creates a new instance of MigrateV0toV1 */ + public MigrateV0toV1() { + } + + /** + * Perform Migration + */ + public void migrate() throws Exception { + log.info("Migrate from DB Version 0 to DB Version 1"); + migrateUsers(); + addDefaultUser(); + log.info("Job migration successfully performed"); + } + + private void migrateUsers() { + MailAddressDAO dao = new MailAddressDAO(); + MailAddress entry = null; + Session session = HibernateSessionFactory.getSession(); + Query qry = session.createQuery("from User"); + Iterator i = qry.iterate(); + while (i.hasNext()) { + User user = (User)i.next(); + if (user.getEmail() == null || user.getEmail().equals(defaultUserEmail)) { + continue; // skip + } + entry = dao.findByEmail(user.getEmail()); + if (entry == null) { + log.info("New entry for user " + user.getUsername()); + // add new entry + entry = new MailAddress(user.getEmail(), + MailAddressDAO.generateDomain(user.getEmail())); + entry.setUser(user); + session.save(entry); + } else if (entry.getUser() != null && entry.getUser().equals(user)) { + log.info("Mail Entry for user " + user.getUsername() + " already exists"); + } else { + log.info("Mail Entry for user " + user.getUsername() + " updated."); + // update existing + entry.setUser(user); + session.update(entry); + } + } + } + + private void addDefaultUser() { + UserDAO dao = new UserDAO(); + MailAddress entry = null; + List ent = dao.findByEmail(defaultUserEmail); + if (ent.size() > 0) { + // already there -> ok + return; + } + log.info ("Adding default user"); + // add new default entry + Session session = HibernateSessionFactory.getSession(); + User user = new User(1, 1, defaultUserEmail, "Global Match", null, "", 0, "", false); + session.save(user); + } + + /** + * Default match + */ + private static final String defaultUserEmail = "@."; +} Property changes on: amavisadmin/trunk/src/java/de/sreindl/amavisadmin/migration/MigrateV0toV1.java ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:eol-style + native Added: amavisadmin/trunk/src/java/de/sreindl/amavisadmin/migration/MigrationJob.java =================================================================== --- amavisadmin/trunk/src/java/de/sreindl/amavisadmin/migration/MigrationJob.java (rev 0) +++ amavisadmin/trunk/src/java/de/sreindl/amavisadmin/migration/MigrationJob.java 2007-01-17 18:27:34 UTC (rev 21) @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2007 Stephen Reindl + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +/* + * MigrationJob.java + * + * Created on 16. Januar 2007, 19:29 + */ + +package de.sreindl.amavisadmin.migration; + +/** + * Interface that is used to describe jobs that need to be started during + * database migration. + * + * @author sreindl + */ +public interface MigrationJob { + /** + * Migration job. + */ + public void migrate() throws Exception; +} Property changes on: amavisadmin/trunk/src/java/de/sreindl/amavisadmin/migration/MigrationJob.java ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:eol-style + native Modified: amavisadmin/trunk/tools/reposInfo.pl =================================================================== --- amavisadmin/trunk/tools/reposInfo.pl 2007-01-17 18:23:00 UTC (rev 20) +++ amavisadmin/trunk/tools/reposInfo.pl 2007-01-17 18:27:34 UTC (rev 21) @@ -19,12 +19,14 @@ use SVK::XD; use Cwd; + my $op = shift; +my $_info = undef; # use svn info -my $funcRev = sub { +sub funcRev { my( $path, $info, $pool ) = @_; - print $info->rev; + $_info = $info; }; my $statusChanged = 0; @@ -35,7 +37,8 @@ my $ctx = SVN::Client->new(); if ($op eq "REV") { - $ctx->info( 'build.xml', undef, undef, $funcRev, 0 ); + $ctx->info( 'build.xml', undef, undef, \&funcRev, 0 ); + print $_info->rev; } elsif ($op eq "STATUS") { $ctx->status(getcwd(), undef, $funcStatus, 1, 0, 0, 0); if ($statusChanged) { @@ -51,4 +54,13 @@ print "BUILD"; } } elsif ($op eq "TAG") { + $ctx->info( 'build.xml', undef, undef, \&funcRev, 0 ); + my $url = $_info->URL; + if ($url =~ /trunk/) { + print "trunk"; + } elsif ($url =~ /branches\/([^\/]+)\//) { + print "branch $1"; + } elsif ($url =~ /tags\/([^\/]+)\//) { + print "tag $1"; + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |