[jboss-svn-commits] JBL Code SVN: r25609 - in labs/jbosslabs/labs-3.0-build/integration/cs-hfurl/src: test/java/org/jboss/labs/clearspace/plugin/hfurl and 1 other directory.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Thu Mar 12 05:46:57 EDT 2009
Author: lkrzyzanek
Date: 2009-03-12 05:46:57 -0400 (Thu, 12 Mar 2009)
New Revision: 25609
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/test/java/org/jboss/labs/clearspace/plugin/hfurl/DbHFURLManagerTest.java
Log:
changed implementation for deleting and undeleting documents
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-12 09:46:00 UTC (rev 25608)
+++ labs/jbosslabs/labs-3.0-build/integration/cs-hfurl/src/main/java/org/jboss/labs/clearspace/plugin/hfurl/DbHFURLManager.java 2009-03-12 09:46:57 UTC (rev 25609)
@@ -29,12 +29,16 @@
import org.apache.log4j.Logger;
import org.jboss.labs.clearspace.plugin.hfurl.dao.HFURLBean;
import org.jboss.labs.clearspace.plugin.hfurl.dao.HFURLDAO;
+import org.springframework.dao.EmptyResultDataAccessException;
+import com.jivesoftware.base.database.dao.DAOException;
import com.jivesoftware.community.Document;
+import com.jivesoftware.community.DocumentState;
import com.jivesoftware.community.event.DocumentEvent;
import com.jivesoftware.community.event.DocumentListener;
/**
+ * DB Implementation of HF URL Manager
*
* @author <a href="mailto:lkrzyzan at redhat.com">Libor Krzyzanek</a>
*
@@ -69,7 +73,7 @@
sun.text.Normalizer.DECOMP, 0);
// remove special characters
- hfURLTitle = hfURLTitle.replaceAll("[^a-zA-Z-]+", "");
+ hfURLTitle = hfURLTitle.replaceAll("[^a-zA-Z0-9-]+", "");
// URL Encode - not needed because all special characters are removed
// hfURLTitle = URLEncoder.encode(hfURLTitle, "UTF-8");
@@ -94,10 +98,13 @@
}
}
} else {
- HFURLBean bean = hfURLDAO.getByHfURLTitle(hfURLTitle);
- if (bean != null) {
+ HFURLBean bean;
+ try {
+ bean = hfURLDAO.getByHfURLTitle(hfURLTitle);
documentID = bean.getDocumentID();
hfURLCache.put(documentID, hfURLTitle);
+ } catch (EmptyResultDataAccessException e) {
+ documentID = "DOC-"; // non existing document
}
}
@@ -123,7 +130,9 @@
if (log.isDebugEnabled()) {
log.debug("documentDeleted: " + event.getDocument().getDocumentID());
}
- hfURLDAO.deleteHFURL(event.getDocument().getDocumentID());
+ // this notification is fired when administrator delete document.
+ // it's not fired when user mark document as deleted.
+ // This case is handled by document modified with document state = deleted
}
public void documentExpired(DocumentEvent event) {
@@ -135,10 +144,16 @@
public void documentModified(DocumentEvent event) {
if (log.isDebugEnabled()) {
log.debug("documentModified: " + event.getDocument().getDocumentID());
+ log.debug("event params: " + event.getParams());
+ log.debug("Document state: " + event.getDocument().getDocumentState());
}
+
Map<String, ? extends Object> params = event.getParams();
+ Document doc = event.getDocument();
+
+ // Title modify
if ("titleModify".equals(params.get("Type"))) {
- Document doc = event.getDocument();
+ log.debug("Title is modified - go to refresh HF URL Map");
HFURLBean bean = hfURLDAO.getByDocumentId(doc.getDocumentID());
String hfURLTitle = createHFURLTitle(doc.getSubject());
@@ -146,6 +161,21 @@
hfURLDAO.updateHFURL(bean);
}
+
+ // User delete - it's not Administrator delete that fire documentDeleted
+ // event
+ if ("documentStateModify".equals(params.get("Type"))
+ && doc.getDocumentState().equals(DocumentState.DELETED)) {
+ log.debug("State of document changed to DELETED");
+ hfURLDAO.deleteHFURL(event.getDocument().getDocumentID());
+ hfURLCache.remove(event.getDocument().getDocumentID());
+ }
+
+ // Here is one special case of changing title - when user restore version
+ // which has another title CS doesn't fire this event.
+
+ // At now we don't care because changing title at all is not done very
+ // frequently
}
public void documentMoved(DocumentEvent event) {
@@ -161,31 +191,38 @@
}
public void documentUndeleted(DocumentEvent event) {
- // TODO Auto-generated method stub
if (log.isDebugEnabled()) {
log.debug("documentUndeleted: " + event.getDocument().getDocumentID());
}
+ Document doc = event.getDocument();
+
+ try {
+ hfURLDAO.getByDocumentId(doc.getDocumentID());
+ // document HF URL founded - should not happen but rather check it
+ } catch (EmptyResultDataAccessException e) {
+ // document HF ULR not founded. Create new one
+ String hfURLTitle = createHFURLTitle(doc.getSubject());
+ HFURLBean bean = new HFURLBean(doc.getDocumentID(), hfURLTitle);
+ hfURLDAO.createHFURL(bean);
+ }
}
public void documentViewed(DocumentEvent event) {
}
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());
}
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-12 09:46:00 UTC (rev 25608)
+++ labs/jbosslabs/labs-3.0-build/integration/cs-hfurl/src/test/java/org/jboss/labs/clearspace/plugin/hfurl/DbHFURLManagerTest.java 2009-03-12 09:46:57 UTC (rev 25609)
@@ -30,6 +30,7 @@
import org.jboss.labs.clearspace.plugin.hfurl.dao.HFURLDAO;
import org.junit.Before;
import org.junit.Test;
+import org.springframework.dao.EmptyResultDataAccessException;
import com.jivesoftware.base.database.dao.DAOException;
@@ -70,17 +71,23 @@
public void deleteHFURL(String documentId) throws DAOException {
}
- public HFURLBean getByDocumentId(String documentId) throws DAOException {
+ public HFURLBean getByDocumentId(String documentId)
+ throws EmptyResultDataAccessException {
return null;
}
- public HFURLBean getByHfURLTitle(String hfURLTitle) throws DAOException {
+ public HFURLBean getByHfURLTitle(String hfURLTitle)
+ throws EmptyResultDataAccessException {
+ if ("not-existing".equals(hfURLTitle)) {
+ throw new EmptyResultDataAccessException("non existing document", 1);
+ }
return null;
}
public HFURLBean updateHFURL(HFURLBean bean) throws DAOException {
return null;
}
+
}
/**
@@ -103,6 +110,8 @@
.createHFURLTitle("special characters :!@#$%^&*()\"\"\u00a7()[]?><~\u00b1_+`"));
assertEquals("titlewith-hyphen", hfURLManager
.createHFURLTitle("title with - hyphen"));
+ assertEquals("titlewithnumbers0123456789", hfURLManager
+ .createHFURLTitle("title with numbers 0123456789"));
assertEquals(
"NationalcharactersescrzyaiedtnESCRZYAIEDTN",
hfURLManager
@@ -121,7 +130,7 @@
assertEquals("DOC-2345", hfURLManager
.getDocumentID("documentwithfriendlyurl2"));
- assertEquals(null, hfURLManager.getDocumentID("not-existing"));
+ assertEquals("DOC-", hfURLManager.getDocumentID("not-existing"));
}
}
More information about the jboss-svn-commits
mailing list