[jboss-svn-commits] JBL Code SVN: r32240 - in labs/jbosslabs/labs-3.0-build/integration/sbs-blogs-migration/trunk/src: main/java/org/jboss/labs/sbs/plugin/bm/dao and 4 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Fri Mar 26 09:51:40 EDT 2010
Author: lkrzyzanek
Date: 2010-03-26 09:51:40 -0400 (Fri, 26 Mar 2010)
New Revision: 32240
Added:
labs/jbosslabs/labs-3.0-build/integration/sbs-blogs-migration/trunk/src/main/java/org/jboss/labs/sbs/plugin/bm/DbOldBlogsManager.java
labs/jbosslabs/labs-3.0-build/integration/sbs-blogs-migration/trunk/src/main/java/org/jboss/labs/sbs/plugin/bm/OldBlogsManager.java
labs/jbosslabs/labs-3.0-build/integration/sbs-blogs-migration/trunk/src/main/java/org/jboss/labs/sbs/plugin/bm/dao/
labs/jbosslabs/labs-3.0-build/integration/sbs-blogs-migration/trunk/src/main/java/org/jboss/labs/sbs/plugin/bm/dao/OldBlogEntryBean.java
labs/jbosslabs/labs-3.0-build/integration/sbs-blogs-migration/trunk/src/test/java/org/jboss/labs/sbs/plugin/bm/DbOldBlogsManagerTest.java
labs/jbosslabs/labs-3.0-build/integration/sbs-blogs-migration/trunk/src/test/resources/user1/
labs/jbosslabs/labs-3.0-build/integration/sbs-blogs-migration/trunk/src/test/resources/user1/entry1.meta
labs/jbosslabs/labs-3.0-build/integration/sbs-blogs-migration/trunk/src/test/resources/user1/entry1.txt
Modified:
labs/jbosslabs/labs-3.0-build/integration/sbs-blogs-migration/trunk/src/main/java/org/jboss/labs/sbs/plugin/bm/struts/AdminBlogsMigrationAction.java
Log:
Added loading old blog posts form input streamds
Added: labs/jbosslabs/labs-3.0-build/integration/sbs-blogs-migration/trunk/src/main/java/org/jboss/labs/sbs/plugin/bm/DbOldBlogsManager.java
===================================================================
--- labs/jbosslabs/labs-3.0-build/integration/sbs-blogs-migration/trunk/src/main/java/org/jboss/labs/sbs/plugin/bm/DbOldBlogsManager.java (rev 0)
+++ labs/jbosslabs/labs-3.0-build/integration/sbs-blogs-migration/trunk/src/main/java/org/jboss/labs/sbs/plugin/bm/DbOldBlogsManager.java 2010-03-26 13:51:40 UTC (rev 32240)
@@ -0,0 +1,88 @@
+/*
+ * JBoss Community http://jboss.org/
+ *
+ * Copyright (c) 2010 Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT A WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License, v.2.1 along with this distribution; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ *
+ * Red Hat Author(s): Libor Krzyzanek
+ */
+package org.jboss.labs.sbs.plugin.bm;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.util.Date;
+import java.util.Properties;
+
+import org.jboss.labs.sbs.plugin.bm.dao.OldBlogEntryBean;
+
+/**
+ * DB Implementation of DbOldBlogsManager
+ *
+ *
+ * @author <a href="mailto:lkrzyzan at redhat.com">Libor Krzyzanek</a>
+ */
+public class DbOldBlogsManager implements OldBlogsManager {
+ /**
+ * Line separator for the system
+ */
+ public static final String LINE_SEPARATOR = System
+ .getProperty("line.separator");
+
+ @Override
+ public OldBlogEntryBean loadOldBlogPost(InputStream data, InputStream meta,
+ String encoding) throws IOException {
+ OldBlogEntryBean bean = new OldBlogEntryBean();
+
+ boolean hasLoadedTitle = false;
+
+ BufferedReader br = new BufferedReader(
+ new InputStreamReader(data, encoding));
+ String line;
+ StringBuffer description = new StringBuffer();
+ while ((line = br.readLine()) != null) {
+ if (!hasLoadedTitle) {
+ bean.setTitle(line);
+ hasLoadedTitle = true;
+ } else {
+ description.append(line);
+ description.append(LINE_SEPARATOR);
+ }
+ }
+ bean.setBody(description.toString());
+ br.close();
+
+ Properties metaData = new Properties();
+ metaData.load(meta);
+ meta.close();
+
+ bean.setAuthor(metaData
+ .getProperty(OldBlogEntryBean.BLOG_ENTRY_METADATA_AUTHOR));
+ try {
+ String timeStamp = metaData
+ .getProperty(OldBlogEntryBean.BLOG_ENTRY_METADATA_TIMESTAMP);
+ if (timeStamp != null) {
+ bean.setCreated(new Date(Long.parseLong(timeStamp)));
+ }
+ } catch (NumberFormatException e) {
+ // timeStamp is not a number.
+ }
+
+ return bean;
+ }
+
+}
Property changes on: labs/jbosslabs/labs-3.0-build/integration/sbs-blogs-migration/trunk/src/main/java/org/jboss/labs/sbs/plugin/bm/DbOldBlogsManager.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: labs/jbosslabs/labs-3.0-build/integration/sbs-blogs-migration/trunk/src/main/java/org/jboss/labs/sbs/plugin/bm/OldBlogsManager.java
===================================================================
--- labs/jbosslabs/labs-3.0-build/integration/sbs-blogs-migration/trunk/src/main/java/org/jboss/labs/sbs/plugin/bm/OldBlogsManager.java (rev 0)
+++ labs/jbosslabs/labs-3.0-build/integration/sbs-blogs-migration/trunk/src/main/java/org/jboss/labs/sbs/plugin/bm/OldBlogsManager.java 2010-03-26 13:51:40 UTC (rev 32240)
@@ -0,0 +1,47 @@
+/*
+ * JBoss Community http://jboss.org/
+ *
+ * Copyright (c) 2010 Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT A WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License, v.2.1 along with this distribution; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ *
+ * Red Hat Author(s): Libor Krzyzanek
+ */
+package org.jboss.labs.sbs.plugin.bm;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+import org.jboss.labs.sbs.plugin.bm.dao.OldBlogEntryBean;
+
+/**
+ * Old blogs manager interface
+ *
+ * @author <a href="mailto:lkrzyzan at redhat.com">Libor Krzyzanek</a>
+ */
+public interface OldBlogsManager {
+
+ /**
+ * Load old blog and create blog value object
+ *
+ * @param data data
+ * @param meta metadata
+ * @param encoding encoding of those input streamds
+ * @return
+ */
+ public OldBlogEntryBean loadOldBlogPost(InputStream data, InputStream meta,
+ String encoding) throws IOException;
+
+}
Property changes on: labs/jbosslabs/labs-3.0-build/integration/sbs-blogs-migration/trunk/src/main/java/org/jboss/labs/sbs/plugin/bm/OldBlogsManager.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: labs/jbosslabs/labs-3.0-build/integration/sbs-blogs-migration/trunk/src/main/java/org/jboss/labs/sbs/plugin/bm/dao/OldBlogEntryBean.java
===================================================================
--- labs/jbosslabs/labs-3.0-build/integration/sbs-blogs-migration/trunk/src/main/java/org/jboss/labs/sbs/plugin/bm/dao/OldBlogEntryBean.java (rev 0)
+++ labs/jbosslabs/labs-3.0-build/integration/sbs-blogs-migration/trunk/src/main/java/org/jboss/labs/sbs/plugin/bm/dao/OldBlogEntryBean.java 2010-03-26 13:51:40 UTC (rev 32240)
@@ -0,0 +1,147 @@
+/*
+ * JBoss Community http://jboss.org/
+ *
+ * Copyright (c) 2010 Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT A WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License, v.2.1 along with this distribution; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ *
+ * Red Hat Author(s): Libor Krzyzanek
+ */
+package org.jboss.labs.sbs.plugin.bm.dao;
+
+import java.util.Date;
+
+/**
+ * Bean of old blog entry (Blojsom blog entry).
+ *
+ * @author <a href="mailto:lkrzyzan at redhat.com">Libor Krzyzanek</a>
+ */
+public class OldBlogEntryBean {
+ /**
+ * Entry Meta Data Key for author
+ */
+ public static final String BLOG_ENTRY_METADATA_AUTHOR = "blog-entry-author";
+
+ /**
+ * Entry meta-data key for entry time
+ */
+ public static final String BLOG_ENTRY_METADATA_TIMESTAMP = "blog-entry-metadata-timestamp";
+
+ /** Title of blog entry. */
+ private String title;
+
+ /** Body of blog entry. */
+ private String body;
+
+ /** Date of creation. */
+ private Date created;
+
+ /** Date of last modification. */
+ private Date modified;
+
+ /** Author of this blog entry. */
+ private String author;
+
+ /**
+ * Gets the title of blog entry.
+ *
+ * @return the title of blog entry
+ */
+ public String getTitle() {
+ return title;
+ }
+
+ /**
+ * Sets the title of blog entry.
+ *
+ * @param title the new title of blog entry
+ */
+ public void setTitle(String title) {
+ this.title = title;
+ }
+
+ /**
+ * Gets the body of blog entry.
+ *
+ * @return the body of blog entry
+ */
+ public String getBody() {
+ return body;
+ }
+
+ /**
+ * Sets the body of blog entry.
+ *
+ * @param body the new body of blog entry
+ */
+ public void setBody(String body) {
+ this.body = body;
+ }
+
+ /**
+ * Gets the date of creation.
+ *
+ * @return the date of creation
+ */
+ public Date getCreated() {
+ return created;
+ }
+
+ /**
+ * Sets the date of creation.
+ *
+ * @param created the new date of creation
+ */
+ public void setCreated(Date created) {
+ this.created = created;
+ }
+
+ /**
+ * Gets the date of last modification.
+ *
+ * @return the date of last modification
+ */
+ public Date getModified() {
+ return modified;
+ }
+
+ /**
+ * Sets the date of last modification.
+ *
+ * @param modified the new date of last modification
+ */
+ public void setModified(Date modified) {
+ this.modified = modified;
+ }
+
+ /**
+ * Sets the author of this blog entry.
+ *
+ * @param author the new author of this blog entry
+ */
+ public void setAuthor(String author) {
+ this.author = author;
+ }
+
+ /**
+ * Gets the author of this blog entry.
+ *
+ * @return the author of this blog entry
+ */
+ public String getAuthor() {
+ return author;
+ }
+
+}
Property changes on: labs/jbosslabs/labs-3.0-build/integration/sbs-blogs-migration/trunk/src/main/java/org/jboss/labs/sbs/plugin/bm/dao/OldBlogEntryBean.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: labs/jbosslabs/labs-3.0-build/integration/sbs-blogs-migration/trunk/src/main/java/org/jboss/labs/sbs/plugin/bm/struts/AdminBlogsMigrationAction.java
===================================================================
--- labs/jbosslabs/labs-3.0-build/integration/sbs-blogs-migration/trunk/src/main/java/org/jboss/labs/sbs/plugin/bm/struts/AdminBlogsMigrationAction.java 2010-03-26 13:35:08 UTC (rev 32239)
+++ labs/jbosslabs/labs-3.0-build/integration/sbs-blogs-migration/trunk/src/main/java/org/jboss/labs/sbs/plugin/bm/struts/AdminBlogsMigrationAction.java 2010-03-26 13:51:40 UTC (rev 32240)
@@ -31,6 +31,7 @@
/**
* Start migration of blogs into SBS
+ *
* @return
*/
public String migrateBlogs2SBS() {
Added: labs/jbosslabs/labs-3.0-build/integration/sbs-blogs-migration/trunk/src/test/java/org/jboss/labs/sbs/plugin/bm/DbOldBlogsManagerTest.java
===================================================================
--- labs/jbosslabs/labs-3.0-build/integration/sbs-blogs-migration/trunk/src/test/java/org/jboss/labs/sbs/plugin/bm/DbOldBlogsManagerTest.java (rev 0)
+++ labs/jbosslabs/labs-3.0-build/integration/sbs-blogs-migration/trunk/src/test/java/org/jboss/labs/sbs/plugin/bm/DbOldBlogsManagerTest.java 2010-03-26 13:51:40 UTC (rev 32240)
@@ -0,0 +1,55 @@
+/*
+ * JBoss Community http://jboss.org/
+ *
+ * Copyright (c) 2010 Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT A WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License, v.2.1 along with this distribution; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ *
+ * Red Hat Author(s): Libor Krzyzanek
+ */
+package org.jboss.labs.sbs.plugin.bm;
+
+import static org.junit.Assert.assertEquals;
+
+import java.io.IOException;
+import java.util.Date;
+
+import org.jboss.labs.sbs.plugin.bm.dao.OldBlogEntryBean;
+import org.junit.Test;
+
+/**
+ * Test of DbOldBlogsManager
+ *
+ * @author <a href="mailto:lkrzyzan at redhat.com">Libor Krzyzanek</a>
+ */
+public class DbOldBlogsManagerTest {
+
+ @Test
+ public void testLoadOldBlogPost() throws IOException {
+ OldBlogsManager manager = new DbOldBlogsManager();
+
+ OldBlogEntryBean bean = manager.loadOldBlogPost(DbOldBlogsManagerTest.class
+ .getResourceAsStream("/user1/entry1.txt"), DbOldBlogsManagerTest.class
+ .getResourceAsStream("/user1/entry1.meta"), "UTF-8");
+
+ assertEquals(new Date(1269610718469l), bean.getCreated());
+ assertEquals("admin", bean.getAuthor());
+ assertEquals("Title of blog entry", bean.getTitle());
+ assertEquals("<p>Data</p>" + DbOldBlogsManager.LINE_SEPARATOR
+ + "<p>other line</p>" + DbOldBlogsManager.LINE_SEPARATOR + "etc."
+ + DbOldBlogsManager.LINE_SEPARATOR, bean.getBody());
+ }
+
+}
Property changes on: labs/jbosslabs/labs-3.0-build/integration/sbs-blogs-migration/trunk/src/test/java/org/jboss/labs/sbs/plugin/bm/DbOldBlogsManagerTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: labs/jbosslabs/labs-3.0-build/integration/sbs-blogs-migration/trunk/src/test/resources/user1/entry1.meta
===================================================================
--- labs/jbosslabs/labs-3.0-build/integration/sbs-blogs-migration/trunk/src/test/resources/user1/entry1.meta (rev 0)
+++ labs/jbosslabs/labs-3.0-build/integration/sbs-blogs-migration/trunk/src/test/resources/user1/entry1.meta 2010-03-26 13:51:40 UTC (rev 32240)
@@ -0,0 +1,3 @@
+#Tue Oct 05 14:11:58 EDT 2004
+blog-entry-author=admin
+blog-entry-metadata-timestamp=1269610718469
Added: labs/jbosslabs/labs-3.0-build/integration/sbs-blogs-migration/trunk/src/test/resources/user1/entry1.txt
===================================================================
--- labs/jbosslabs/labs-3.0-build/integration/sbs-blogs-migration/trunk/src/test/resources/user1/entry1.txt (rev 0)
+++ labs/jbosslabs/labs-3.0-build/integration/sbs-blogs-migration/trunk/src/test/resources/user1/entry1.txt 2010-03-26 13:51:40 UTC (rev 32240)
@@ -0,0 +1,4 @@
+Title of blog entry
+<p>Data</p>
+<p>other line</p>
+etc.
Property changes on: labs/jbosslabs/labs-3.0-build/integration/sbs-blogs-migration/trunk/src/test/resources/user1/entry1.txt
___________________________________________________________________
Name: svn:mime-type
+ text/plain
More information about the jboss-svn-commits
mailing list