[jboss-svn-commits] JBL Code SVN: r25591 - in labs/jbosslabs/labs-3.0-build/integration/cs-hfurl/src: main/java/org/jboss/labs/clearspace/plugin/hfurl/dao and 1 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Wed Mar 11 10:25:59 EDT 2009
Author: lkrzyzanek
Date: 2009-03-11 10:25:59 -0400 (Wed, 11 Mar 2009)
New Revision: 25591
Modified:
labs/jbosslabs/labs-3.0-build/integration/cs-hfurl/src/main/java/org/jboss/labs/clearspace/plugin/hfurl/DbHFURLManager.java
labs/jbosslabs/labs-3.0-build/integration/cs-hfurl/src/main/java/org/jboss/labs/clearspace/plugin/hfurl/dao/DbHFURLDAOImpl.java
labs/jbosslabs/labs-3.0-build/integration/cs-hfurl/src/main/java/org/jboss/labs/clearspace/plugin/hfurl/dao/HFURLDAO.java
labs/jbosslabs/labs-3.0-build/integration/cs-hfurl/src/test/java/org/jboss/labs/clearspace/plugin/hfurl/DbHFURLManagerTest.java
Log:
added implementation of inserting, updating new HF URL entries
Modified: labs/jbosslabs/labs-3.0-build/integration/cs-hfurl/src/main/java/org/jboss/labs/clearspace/plugin/hfurl/DbHFURLManager.java
===================================================================
--- labs/jbosslabs/labs-3.0-build/integration/cs-hfurl/src/main/java/org/jboss/labs/clearspace/plugin/hfurl/DbHFURLManager.java 2009-03-11 14:25:31 UTC (rev 25590)
+++ labs/jbosslabs/labs-3.0-build/integration/cs-hfurl/src/main/java/org/jboss/labs/clearspace/plugin/hfurl/DbHFURLManager.java 2009-03-11 14:25:59 UTC (rev 25591)
@@ -25,9 +25,12 @@
import java.util.Map;
import java.util.Map.Entry;
+import org.apache.log4j.LogManager;
+import org.apache.log4j.Logger;
import org.jboss.labs.clearspace.plugin.hfurl.dao.HFURLBean;
import org.jboss.labs.clearspace.plugin.hfurl.dao.HFURLDAO;
+import com.jivesoftware.community.Document;
import com.jivesoftware.community.event.DocumentEvent;
import com.jivesoftware.community.event.DocumentListener;
@@ -38,6 +41,8 @@
*/
public class DbHFURLManager implements HFURLManager, DocumentListener {
+ private static final Logger log = LogManager.getLogger(DbHFURLManager.class);
+
/**
* A cache for HF URL titles.<br>
* Key is DocumentID<br>
@@ -48,6 +53,9 @@
private HFURLDAO hfURLDAO;
public String createHFURLTitle(String documentTitle) {
+ if (log.isDebugEnabled()) {
+ log.debug("createHFURLTitle from doc title: " + documentTitle);
+ }
// remove white spaces
String hfURLTitle = documentTitle.replaceAll("[\\s]+", "");
@@ -66,6 +74,10 @@
// URL Encode - not needed because all special characters are removed
// hfURLTitle = URLEncoder.encode(hfURLTitle, "UTF-8");
+ if (log.isDebugEnabled()) {
+ log.debug("created HF URL title " + hfURLTitle);
+ }
+
return hfURLTitle;
}
@@ -92,89 +104,98 @@
return documentID;
}
- public void setHfURLCache(Map<String, String> hfURLCache) {
- this.hfURLCache = hfURLCache;
- }
-
// DOCUMENT LISTENER METHODS
public void binaryBodyDownloaded(DocumentEvent event) {
- // TODO Auto-generated method stub
-
}
public void documentAdded(DocumentEvent event) {
- // TODO Auto-generated method stub
-
+ if (log.isDebugEnabled()) {
+ log.debug("documentAdded: " + event.getDocument().getDocumentID());
+ }
+ Document doc = event.getDocument();
+ String hfURLTitle = createHFURLTitle(doc.getSubject());
+ HFURLBean bean = new HFURLBean(doc.getDocumentID(), hfURLTitle);
+ hfURLDAO.createHFURL(bean);
}
public void documentDeleted(DocumentEvent event) {
- // TODO Auto-generated method stub
-
+ if (log.isDebugEnabled()) {
+ log.debug("documentDeleted: " + event.getDocument().getDocumentID());
+ }
+ hfURLDAO.deleteHFURL(event.getDocument().getDocumentID());
}
public void documentExpired(DocumentEvent event) {
- // TODO Auto-generated method stub
-
}
public void documentExpireWarning(DocumentEvent event) {
- // TODO Auto-generated method stub
-
}
public void documentModified(DocumentEvent event) {
- // TODO Auto-generated method stub
+ if (log.isDebugEnabled()) {
+ log.debug("documentModified: " + event.getDocument().getDocumentID());
+ }
+ Map<String, ? extends Object> params = event.getParams();
+ if ("titleModify".equals(params.get("Type"))) {
+ Document doc = event.getDocument();
+ HFURLBean bean = hfURLDAO.getByDocumentId(doc.getDocumentID());
+ String hfURLTitle = createHFURLTitle(doc.getSubject());
+ bean.setHfTitle(hfURLTitle);
+
+ hfURLDAO.updateHFURL(bean);
+ }
}
public void documentMoved(DocumentEvent event) {
- // TODO Auto-generated method stub
-
}
public void documentRated(DocumentEvent event) {
- // TODO Auto-generated method stub
-
}
public void documentRelatedObjectAdded(DocumentEvent event) {
- // TODO Auto-generated method stub
-
}
public void documentRelatedObjectDeleted(DocumentEvent event) {
- // TODO Auto-generated method stub
-
}
public void documentUndeleted(DocumentEvent event) {
// TODO Auto-generated method stub
-
+ if (log.isDebugEnabled()) {
+ log.debug("documentUndeleted: " + event.getDocument().getDocumentID());
+ }
}
public void documentViewed(DocumentEvent event) {
- // TODO Auto-generated method stub
-
}
public void versionAdded(DocumentEvent event) {
// TODO Auto-generated method stub
-
+ if (log.isDebugEnabled()) {
+ log.debug("versionAdded: " + event.getDocument().getDocumentID());
+ }
}
public void versionDeleting(DocumentEvent event) {
// TODO Auto-generated method stub
-
+ if (log.isDebugEnabled()) {
+ log.debug("versionDeleting: " + event.getDocument().getDocumentID());
+ }
}
public void versionModified(DocumentEvent event) {
// TODO Auto-generated method stub
-
+ if (log.isDebugEnabled()) {
+ log.debug("versionModified: " + event.getDocument().getDocumentID());
+ }
}
public void setHfURLDAO(HFURLDAO hfURLDAO) {
this.hfURLDAO = hfURLDAO;
}
+ public void setHfURLCache(Map<String, String> hfURLCache) {
+ this.hfURLCache = hfURLCache;
+ }
}
Modified: labs/jbosslabs/labs-3.0-build/integration/cs-hfurl/src/main/java/org/jboss/labs/clearspace/plugin/hfurl/dao/DbHFURLDAOImpl.java
===================================================================
--- labs/jbosslabs/labs-3.0-build/integration/cs-hfurl/src/main/java/org/jboss/labs/clearspace/plugin/hfurl/dao/DbHFURLDAOImpl.java 2009-03-11 14:25:31 UTC (rev 25590)
+++ labs/jbosslabs/labs-3.0-build/integration/cs-hfurl/src/main/java/org/jboss/labs/clearspace/plugin/hfurl/dao/DbHFURLDAOImpl.java 2009-03-11 14:25:59 UTC (rev 25591)
@@ -25,9 +25,11 @@
import java.sql.SQLException;
import org.springframework.jdbc.core.simple.ParameterizedRowMapper;
+import org.springframework.transaction.annotation.Transactional;
import com.jivesoftware.base.database.dao.DAOException;
import com.jivesoftware.base.database.dao.JiveJdbcDaoSupport;
+import com.jivesoftware.base.database.sequence.SequenceManager;
/**
* DB Implementation of HF URL DAO
@@ -37,18 +39,63 @@
*/
public class DbHFURLDAOImpl extends JiveJdbcDaoSupport implements HFURLDAO {
+ public static final int HFURL_MAP_SEQ = 5000;
+
private static final String SELECT_FIELDS = "SELECT id, hfTitle, documentID ";
+ private static final String LOAD_HFURL_BY_HFTITLE = SELECT_FIELDS
+ + " FROM humanFriendlyURLMap WHERE hfTitle=?";
+
private static final String LOAD_HFURL_BY_DOCUMENT_ID = SELECT_FIELDS
- + " FROM humanFriendlyURLMap WHERE hfTitle=?";
+ + " FROM humanFriendlyURLMap WHERE documentID=?";
+ private static final String INSERT_HFURL_ENTRY = "INSERT INTO humanFriendlyURLMap (id, hfTitle, documentID) VALUES (?, ?, ?)";
+
+ private static final String UPDATE_HFURL_ENTRY = "UPDATE humanFriendlyURLMap SET hfTitle=?, documentID=? WHERE id=?";
+
+ private static final String DELETE_HFURL_ENTRY_BY_ID = "DELETE FROM humanFriendlyURLMap WHERE id=?";
+
+ private static final String DELETE_HFURL_ENTRY_BY_DOCUMENT_ID = "DELETE FROM humanFriendlyURLMap WHERE documentID=?";
+
private static final HfURLMapMapper mapper = new HfURLMapMapper();
public HFURLBean getByHfURLTitle(String hfURLTitle) throws DAOException {
- return this.getSimpleJdbcTemplate().queryForObject(
- LOAD_HFURL_BY_DOCUMENT_ID, mapper, hfURLTitle);
+ return this.getSimpleJdbcTemplate().queryForObject(LOAD_HFURL_BY_HFTITLE,
+ mapper, hfURLTitle);
}
+
+ public HFURLBean getByDocumentId(String documentId) throws DAOException {
+ return this.getSimpleJdbcTemplate().queryForObject(LOAD_HFURL_BY_DOCUMENT_ID,
+ mapper, documentId);
+ }
+
+ @Transactional
+ public HFURLBean createHFURL(HFURLBean bean) throws DAOException {
+ bean.setId(SequenceManager.nextID(HFURL_MAP_SEQ));
+
+ getSimpleJdbcTemplate().update(INSERT_HFURL_ENTRY, bean.getId(),
+ bean.getHfTitle(), bean.getDocumentID());
+
+ return bean;
+ }
+
+ @Transactional
+ public HFURLBean updateHFURL(HFURLBean bean) throws DAOException {
+ getSimpleJdbcTemplate().update(UPDATE_HFURL_ENTRY, bean.getHfTitle(),
+ bean.getDocumentID(), bean.getId());
+
+ return bean;
+ }
+
+ public void deleteHFURL(Long id) throws DAOException {
+ getSimpleJdbcTemplate().update(DELETE_HFURL_ENTRY_BY_ID, id);
+ }
+
+ public void deleteHFURL(String documentId) throws DAOException {
+ getSimpleJdbcTemplate().update(DELETE_HFURL_ENTRY_BY_DOCUMENT_ID, documentId);
+ }
+
static final class HfURLMapMapper implements
ParameterizedRowMapper<HFURLBean> {
public HFURLBean mapRow(ResultSet rs, int rowNum) throws SQLException {
Modified: labs/jbosslabs/labs-3.0-build/integration/cs-hfurl/src/main/java/org/jboss/labs/clearspace/plugin/hfurl/dao/HFURLDAO.java
===================================================================
--- labs/jbosslabs/labs-3.0-build/integration/cs-hfurl/src/main/java/org/jboss/labs/clearspace/plugin/hfurl/dao/HFURLDAO.java 2009-03-11 14:25:31 UTC (rev 25590)
+++ labs/jbosslabs/labs-3.0-build/integration/cs-hfurl/src/main/java/org/jboss/labs/clearspace/plugin/hfurl/dao/HFURLDAO.java 2009-03-11 14:25:59 UTC (rev 25591)
@@ -27,7 +27,6 @@
* Human friendly DAO interface
*
* @author <a href="mailto:lkrzyzan at redhat.com">Libor Krzyzanek</a>
- *
*/
public interface HFURLDAO {
@@ -39,5 +38,48 @@
* @throws DAOException
*/
public HFURLBean getByHfURLTitle(String hfURLTitle) throws DAOException;
+
+ /**
+ * Get by documentId
+ *
+ * @param documentId
+ * @return HF URL Bean
+ * @throws DAOException
+ */
+ public HFURLBean getByDocumentId(String documentId) throws DAOException;
+ /**
+ * Create new entry
+ *
+ * @param bean bean to delete
+ * @return bean with assigned id
+ * @throws DAOException
+ */
+ public HFURLBean createHFURL(HFURLBean bean) throws DAOException;
+
+ /**
+ * Update HF URL entry
+ *
+ * @param bean bean to delete
+ * @return updated entry
+ * @throws DAOException
+ */
+ public HFURLBean updateHFURL(HFURLBean bean) throws DAOException;
+
+ /**
+ * Delete entry
+ *
+ * @param id id of bean
+ * @throws DAOException
+ */
+ public void deleteHFURL(Long id) throws DAOException;
+
+ /**
+ * Delete entry
+ *
+ * @param documentId document ID
+ * @throws DAOException
+ */
+ public void deleteHFURL(String documentId) throws DAOException;
+
}
Modified: labs/jbosslabs/labs-3.0-build/integration/cs-hfurl/src/test/java/org/jboss/labs/clearspace/plugin/hfurl/DbHFURLManagerTest.java
===================================================================
--- labs/jbosslabs/labs-3.0-build/integration/cs-hfurl/src/test/java/org/jboss/labs/clearspace/plugin/hfurl/DbHFURLManagerTest.java 2009-03-11 14:25:31 UTC (rev 25590)
+++ labs/jbosslabs/labs-3.0-build/integration/cs-hfurl/src/test/java/org/jboss/labs/clearspace/plugin/hfurl/DbHFURLManagerTest.java 2009-03-11 14:25:59 UTC (rev 25591)
@@ -35,55 +35,91 @@
/**
* Test of DbHFURLManager
+ *
* @author <a href="mailto:lkrzyzan at redhat.com">Libor Krzyzanek</a>
- *
+ *
*/
public class DbHFURLManagerTest {
private DbHFURLManager hfURLManager;
-
+
private Map<String, String> hfURLCache;
-
-
-
+
@Before
public void setupHFURLManager() {
hfURLManager = new DbHFURLManager();
-
+
hfURLCache = new HashMap<String, String>();
-
+
hfURLCache.put("DOC-1234", "documentwithfriendlyurl");
hfURLCache.put("DOC-2345", "documentwithfriendlyurl2");
-
+
hfURLManager.setHfURLCache(hfURLCache);
- hfURLManager.setHfURLDAO(new HFURLDAO() {
- public HFURLBean getByHfURLTitle(String hfURLTitle) throws DAOException {
- return null;
- }
- });
+ hfURLManager.setHfURLDAO(new DummyHFURLDAO());
}
-
+
+ class DummyHFURLDAO implements HFURLDAO {
+
+ public HFURLBean createHFURL(HFURLBean bean) throws DAOException {
+ return null;
+ }
+
+ public void deleteHFURL(Long id) throws DAOException {
+ }
+
+ public void deleteHFURL(String documentId) throws DAOException {
+ }
+
+ public HFURLBean getByDocumentId(String documentId) throws DAOException {
+ return null;
+ }
+
+ public HFURLBean getByHfURLTitle(String hfURLTitle) throws DAOException {
+ return null;
+ }
+
+ public HFURLBean updateHFURL(HFURLBean bean) throws DAOException {
+ return null;
+ }
+ }
+
/**
- * Test method for {@link org.jboss.labs.clearspace.plugin.hfurl.DbHFURLManager#createHFURLTitle(java.lang.String)}.
+ * Test method for
+ * {@link org.jboss.labs.clearspace.plugin.hfurl.DbHFURLManager#createHFURLTitle(java.lang.String)}
+ * .
*/
@Test
public void testCreateHFURLTitle() {
- assertEquals("documentwithfriendlyurl", hfURLManager.createHFURLTitle("document with friendly url"));
- assertEquals("morethanonespace", hfURLManager.createHFURLTitle("more than one space"));
- assertEquals("UPPERCASEDOCUMENTTITLE", hfURLManager.createHFURLTitle("UPPER CASE DOCUMENT TITLE"));
-
- assertEquals("specialcharacters", hfURLManager.createHFURLTitle("special characters :!@#$%^&*()\"\"\u00a7()[]?><~\u00b1_+`"));
- assertEquals("titlewith-hyphen", hfURLManager.createHFURLTitle("title with - hyphen"));
- assertEquals("NationalcharactersescrzyaiedtnESCRZYAIEDTN", hfURLManager.createHFURLTitle("National characters: \u011b\u0161\u010d\u0159\u017e\u00fd\u00e1\u00ed\u00e9\u010f\u0165\u0148\u011a\u0160\u010c\u0158\u017d\u00dd\u00c1\u00cd\u00c9\u010e\u0164\u0147"));
+ assertEquals("documentwithfriendlyurl", hfURLManager
+ .createHFURLTitle("document with friendly url"));
+ assertEquals("morethanonespace", hfURLManager
+ .createHFURLTitle("more than one space"));
+ assertEquals("UPPERCASEDOCUMENTTITLE", hfURLManager
+ .createHFURLTitle("UPPER CASE DOCUMENT TITLE"));
+
+ assertEquals(
+ "specialcharacters",
+ hfURLManager
+ .createHFURLTitle("special characters :!@#$%^&*()\"\"\u00a7()[]?><~\u00b1_+`"));
+ assertEquals("titlewith-hyphen", hfURLManager
+ .createHFURLTitle("title with - hyphen"));
+ assertEquals(
+ "NationalcharactersescrzyaiedtnESCRZYAIEDTN",
+ hfURLManager
+ .createHFURLTitle("National characters: \u011b\u0161\u010d\u0159\u017e\u00fd\u00e1\u00ed\u00e9\u010f\u0165\u0148\u011a\u0160\u010c\u0158\u017d\u00dd\u00c1\u00cd\u00c9\u010e\u0164\u0147"));
}
/**
- * Test method for {@link org.jboss.labs.clearspace.plugin.hfurl.DbHFURLManager#getDocumentID(java.lang.String)}.
+ * Test method for
+ * {@link org.jboss.labs.clearspace.plugin.hfurl.DbHFURLManager#getDocumentID(java.lang.String)}
+ * .
*/
@Test
public void testGetDocumentID() {
- assertEquals("DOC-1234", hfURLManager.getDocumentID("documentwithfriendlyurl"));
- assertEquals("DOC-2345", hfURLManager.getDocumentID("documentwithfriendlyurl2"));
+ assertEquals("DOC-1234", hfURLManager
+ .getDocumentID("documentwithfriendlyurl"));
+ assertEquals("DOC-2345", hfURLManager
+ .getDocumentID("documentwithfriendlyurl2"));
assertEquals(null, hfURLManager.getDocumentID("not-existing"));
}
More information about the jboss-svn-commits
mailing list