Author: gmazza
Date: Sun Feb 9 19:05:35 2014
New Revision: 1566356
URL: http://svn.apache.org/r1566356
Log:
Removed persistence of WeblogCategory path column as part of move to top-level
Categories. Synthesized WeblogCategory.getPath() method still available until
rest of application switches over to getName().
Modified:
roller/trunk/app/pom.xml
roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/WeblogEntryManager.java
roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/jpa/JPAWeblogEntryManagerImpl.java
roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/jpa/JPAWeblogManagerImpl.java
roller/trunk/app/src/main/java/org/apache/roller/weblogger/pojos/WeblogCategory.java
roller/trunk/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/Entries.java
roller/trunk/app/src/main/resources/org/apache/roller/weblogger/pojos/WeblogCategory.orm.xml
roller/trunk/app/src/main/resources/org/apache/roller/weblogger/pojos/WeblogEntry.orm.xml
roller/trunk/app/src/test/java/org/apache/roller/weblogger/business/WeblogCategoryCRUDTest.java
roller/trunk/app/src/test/java/org/apache/roller/weblogger/business/WeblogCategoryFunctionalityTest.java
Modified: roller/trunk/app/pom.xml
URL:
http://svn.apache.org/viewvc/roller/trunk/app/pom.xml?rev=1566356&r1=1566355&r2=1566356&view=diff
==============================================================================
--- roller/trunk/app/pom.xml (original)
+++ roller/trunk/app/pom.xml Sun Feb 9 19:05:35 2014
@@ -550,6 +550,9 @@
<value>${basedir}/target</value>
</property>
</systemProperties>
+ <!--excludes>
+ <exclude>**/??.java</exclude>
+ </excludes-->
</configuration>
</plugin>
Modified:
roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/WeblogEntryManager.java
URL:
http://svn.apache.org/viewvc/roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/WeblogEntryManager.java?rev=1566356&r1=1566355&r2=1566356&view=diff
==============================================================================
---
roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/WeblogEntryManager.java
(original)
+++
roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/WeblogEntryManager.java
Sun Feb 9 19:05:35 2014
@@ -241,15 +241,24 @@ public interface WeblogEntryManager {
/**
- * Get category specified by website and categoryPath.
+ * Get category specified by website and name.
* @param website Website of WeblogCategory.
- * @param categoryPath Path of WeblogCategory, relative to category root.
+ * @param categoryName Name of WeblogCategory
+ */
+ WeblogCategory getWeblogCategoryByName(Weblog website,
+ String categoryName) throws WebloggerException;
+
+
+ /**
+ * Get category specified by website and name. Will be removed soon, as
all categories
+ * are now top-level.
+ * @param website Website of WeblogCategory.
+ * @param categoryName Path of WeblogCategory
*/
WeblogCategory getWeblogCategoryByPath(Weblog website,
- String categoryPath) throws WebloggerException;
-
-
- /**
+ String categoryPath) throws
WebloggerException;
+
+ /**
* Get WebLogCategory objects for a website.
*/
List<WeblogCategory> getWeblogCategories(Weblog website, boolean
includeRoot)
Modified:
roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/jpa/JPAWeblogEntryManagerImpl.java
URL:
http://svn.apache.org/viewvc/roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/jpa/JPAWeblogEntryManagerImpl.java?rev=1566356&r1=1566355&r2=1566356&view=diff
==============================================================================
---
roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/jpa/JPAWeblogEntryManagerImpl.java
(original)
+++
roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/jpa/JPAWeblogEntryManagerImpl.java
Sun Feb 9 19:05:35 2014
@@ -152,30 +152,6 @@ public class JPAWeblogEntryManagerImpl i
cat.getWebsite());
}
- // updates the paths of all descendents of the given category
- private void updatePathTree(WeblogCategory cat)
- throws WebloggerException {
-
- log.debug("Updating path tree for category "+cat.getPath());
-
- for (WeblogCategory childCat : cat.getWeblogCategories()) {
- log.debug("OLD child category path was "+childCat.getPath());
-
- // update path and save
- if("/".equals(cat.getPath())) {
- childCat.setPath("/" + childCat.getName());
- } else {
- childCat.setPath(cat.getPath() + "/" + childCat.getName());
- }
- saveWeblogCategory(childCat);
-
- log.debug("NEW child category path is "+ childCat.getPath());
-
- // then make recursive call to update this cats children
- updatePathTree(childCat);
- }
- }
-
/**
* @inheritDoc
*/
@@ -394,7 +370,7 @@ public class JPAWeblogEntryManagerImpl i
}
}
- if (catName != null && !catName.trim().equals("/")) {
+ if (catName != null) {
category = getWeblogCategoryByPath(current.getWebsite(), catName);
if (category != null) {
params.add(size++, category);
@@ -788,8 +764,8 @@ public class JPAWeblogEntryManagerImpl i
// ensure that no sibling categories share the same name
WeblogCategory parent = cat.getParent();
if (null != parent) {
- return (getWeblogCategoryByPath(
- cat.getWebsite(), cat.getPath()) != null);
+ return (getWeblogCategoryByName(
+ cat.getWebsite(), cat.getName()) != null);
}
return false;
@@ -952,32 +928,30 @@ public class JPAWeblogEntryManagerImpl i
/**
* @inheritDoc
*/
+ public WeblogCategory getWeblogCategoryByName(Weblog website,
+ String categoryName) throws WebloggerException {
+ return getWeblogCategoryByName(website, null, categoryName);
+ }
+
public WeblogCategory getWeblogCategoryByPath(Weblog website,
- String categoryPath) throws WebloggerException {
- return getWeblogCategoryByPath(website, null, categoryPath);
+ String categoryPath) throws
WebloggerException {
+ return getWeblogCategoryByName(website, null,
categoryPath.substring(1));
}
-
+
/**
* @inheritDoc
*/
// TODO: ditch this method in favor of getWeblogCategoryByPath(weblog,
path)
- public WeblogCategory getWeblogCategoryByPath(Weblog website,
- WeblogCategory category, String path) throws WebloggerException {
+ public WeblogCategory getWeblogCategoryByName(Weblog website,
+ WeblogCategory category, String name) throws WebloggerException {
- if (path == null || path.trim().equals("/")) {
+ if (name == null) {
return getRootWeblogCategory(website);
} else {
- String catPath = path;
-
- // all cat paths must begin with a '/'
- if(!catPath.startsWith("/")) {
- catPath = "/"+catPath;
- }
-
// now just do simple lookup by path
Query q = strategy.getNamedQuery(
- "WeblogCategory.getByPath&Website");
- q.setParameter(1, catPath);
+ "WeblogCategory.getByName&Website");
+ q.setParameter(1, name);
q.setParameter(2, website);
try {
return (WeblogCategory)q.getSingleResult();
Modified:
roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/jpa/JPAWeblogManagerImpl.java
URL:
http://svn.apache.org/viewvc/roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/jpa/JPAWeblogManagerImpl.java?rev=1566356&r1=1566355&r2=1566356&view=diff
==============================================================================
---
roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/jpa/JPAWeblogManagerImpl.java
(original)
+++
roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/jpa/JPAWeblogManagerImpl.java
Sun Feb 9 19:05:35 2014
@@ -219,9 +219,9 @@ public class JPAWeblogManagerImpl implem
// remove entries
Query refQuery = strategy.getNamedQuery("WeblogEntry.getByWebsite");
refQuery.setParameter(1, website);
- List entries = refQuery.getResultList();
- for (Object object : entries) {
- emgr.removeWeblogEntry((WeblogEntry) object);
+ List<WeblogEntry> entries = refQuery.getResultList();
+ for (WeblogEntry entry : entries) {
+ emgr.removeWeblogEntry(entry);
}
this.strategy.flush();
@@ -230,7 +230,13 @@ public class JPAWeblogManagerImpl implem
if (null != rootCat) {
this.strategy.remove(rootCat);
}
-
+
+ // delete all weblog categories
+ Query removeCategories= strategy.getNamedUpdate(
+ "WeblogCategory.removeByWebsite");
+ removeCategories.setParameter(1, website);
+ removeCategories.executeUpdate();
+
// remove permissions
for (WeblogPermission perm : umgr.getWeblogPermissions(website)) {
umgr.revokeWeblogPermission(perm.getWeblog(), perm.getUser(),
WeblogPermission.ALL_ACTIONS);
Modified:
roller/trunk/app/src/main/java/org/apache/roller/weblogger/pojos/WeblogCategory.java
URL:
http://svn.apache.org/viewvc/roller/trunk/app/src/main/java/org/apache/roller/weblogger/pojos/WeblogCategory.java?rev=1566356&r1=1566355&r2=1566356&view=diff
==============================================================================
---
roller/trunk/app/src/main/java/org/apache/roller/weblogger/pojos/WeblogCategory.java
(original)
+++
roller/trunk/app/src/main/java/org/apache/roller/weblogger/pojos/WeblogCategory.java
Sun Feb 9 19:05:35 2014
@@ -46,8 +46,7 @@ public class WeblogCategory implements S
private String name = null;
private String description = null;
private String image = null;
- private String path = null;
-
+
// associations
private Weblog website = null;
private WeblogCategory parentCategory = null;
@@ -69,15 +68,6 @@ public class WeblogCategory implements S
this.website = website;
this.parentCategory = parent;
-
- // calculate path
- if(parent == null) {
- this.path = "/";
- } else if("/".equals(parent.getPath())) {
- this.path = "/"+name;
- } else {
- this.path = parent.getPath() + "/" + name;
- }
}
@@ -87,7 +77,7 @@ public class WeblogCategory implements S
StringBuilder buf = new StringBuilder();
buf.append("{");
buf.append(getId());
- buf.append(", ").append(getPath());
+ buf.append(", ").append(getName());
buf.append("}");
return buf.toString();
}
@@ -101,8 +91,8 @@ public class WeblogCategory implements S
if (other instanceof WeblogCategory) {
WeblogCategory o = (WeblogCategory)other;
return new EqualsBuilder()
- .append(getPath(), o.getPath())
- //.append(getWebsite(), o.getWebsite())
+ .append(getName(), o.getName())
+ .append(getWebsite(), o.getWebsite())
.isEquals();
}
return false;
@@ -110,8 +100,8 @@ public class WeblogCategory implements S
public int hashCode() {
return new HashCodeBuilder()
- .append(getPath())
- //.append(getWebsite())
+ .append(getName())
+ .append(getWebsite())
.toHashCode();
}
@@ -171,17 +161,13 @@ public class WeblogCategory implements S
/**
- * The full path to this category in the hierarchy.
+ * The full path to this category in the hierarchy. Will be removed soon,
+ * as all categories are now top-level, use getName() going forward.
*/
public String getPath() {
- return this.path;
- }
-
- public void setPath(String path) {
- this.path = path;
+ return this.parentCategory != null ? ("/" + name) : "/";
}
-
-
+
/**
* Get the weblog which owns this category.
*/
@@ -204,7 +190,7 @@ public class WeblogCategory implements S
public void setParent(WeblogCategory parent) {
this.parentCategory = parent;
}
-
+
/**
* Get child categories of this category.
@@ -276,16 +262,13 @@ public class WeblogCategory implements S
*/
public boolean descendentOf(WeblogCategory ancestor) {
- // if this is a root node then we can't be a descendent
- if(getParent() == null) {
- return false;
+ if (parentCategory == ancestor) {
+ return true;
} else {
- // if our path starts with our parents path then we are a
descendent
- return getPath().startsWith(ancestor.getPath());
+ return false;
}
-
}
-
+
/**
* Determine if category is in use. Returns true if any weblog entries
@@ -300,48 +283,15 @@ public class WeblogCategory implements S
}
+
// convenience method for updating the category name, which triggers a
path tree rebuild
public void updateName(String newName) throws WebloggerException {
// update name
setName(newName);
-
- // calculate path
- if(getParent() == null) {
- setPath("/");
- } else if("/".equals(getParent().getPath())) {
- setPath("/"+getName());
- } else {
- setPath(getParent().getPath() + "/" + getName());
- }
-
+
// update path tree for all children
- updatePathTree(this);
- }
-
-
- // updates the paths of all descendents of the given category
- public static void updatePathTree(WeblogCategory cat)
- throws WebloggerException {
-
- log.debug("Updating path tree for category "+cat.getPath());
-
- for (WeblogCategory childCat : cat.getWeblogCategories()) {
- log.debug("OLD child category path was "+childCat.getPath());
-
- // update path and save
- if("/".equals(cat.getPath())) {
- childCat.setPath("/" + childCat.getName());
- } else {
- childCat.setPath(cat.getPath() + "/" + childCat.getName());
- }
-
WebloggerFactory.getWeblogger().getWeblogEntryManager().saveWeblogCategory(childCat);
-
- log.debug("NEW child category path is "+ childCat.getPath());
-
- // then make recursive call to update this cats children
- updatePathTree(childCat);
- }
+
WebloggerFactory.getWeblogger().getWeblogEntryManager().saveWeblogCategory(this);
}
-
+
}
Modified:
roller/trunk/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/Entries.java
URL:
http://svn.apache.org/viewvc/roller/trunk/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/Entries.java?rev=1566356&r1=1566355&r2=1566356&view=diff
==============================================================================
---
roller/trunk/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/Entries.java
(original)
+++
roller/trunk/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/Entries.java
Sun Feb 9 19:05:35 2014
@@ -168,7 +168,6 @@ public class Entries extends UIAction {
WeblogCategory tmpCat = new WeblogCategory();
tmpCat.setName("Any");
- tmpCat.setPath("");
cats.add(tmpCat);
List<WeblogCategory> weblogCats = Collections.EMPTY_LIST;
Modified:
roller/trunk/app/src/main/resources/org/apache/roller/weblogger/pojos/WeblogCategory.orm.xml
URL:
http://svn.apache.org/viewvc/roller/trunk/app/src/main/resources/org/apache/roller/weblogger/pojos/WeblogCategory.orm.xml?rev=1566356&r1=1566355&r2=1566356&view=diff
==============================================================================
---
roller/trunk/app/src/main/resources/org/apache/roller/weblogger/pojos/WeblogCategory.orm.xml
(original)
+++
roller/trunk/app/src/main/resources/org/apache/roller/weblogger/pojos/WeblogCategory.orm.xml
Sun Feb 9 19:05:35 2014
@@ -7,8 +7,8 @@
<entity metadata-complete="true" name="WeblogCategory"
class="org.apache.roller.weblogger.pojos.WeblogCategory"
access="PROPERTY">
<table name="weblogcategory"/>
- <named-query name="WeblogCategory.getByPath&Website">
- <query>SELECT w FROM WeblogCategory w WHERE w.path = ?1 AND
w.website = ?2</query>
+ <named-query name="WeblogCategory.getByName&Website">
+ <query>SELECT w FROM WeblogCategory w WHERE w.name = ?1 AND
w.website = ?2</query>
</named-query>
<named-query name="WeblogCategory.getByWebsite">
<query>SELECT w FROM WeblogCategory w WHERE w.website =
?1</query>
@@ -19,6 +19,9 @@
<named-query name="WeblogCategory.getByWebsite&ParentNotNull">
<query>SELECT w FROM WeblogCategory w WHERE w.website = ?1 AND
w.parent IS NOT NULL</query>
</named-query>
+ <named-query name="WeblogCategory.removeByWebsite">
+ <query>DELETE FROM WeblogCategory w WHERE w.website = ?1</query>
+ </named-query>
<attributes>
<id name="id">
<column name="id"/>
@@ -32,9 +35,6 @@
<basic name="image">
<column name="image" insertable="true" updatable="true"
unique="false"/>
</basic>
- <basic name="path">
- <column name="path" insertable="true" updatable="true"
unique="false"/>
- </basic>
<many-to-one name="website"
target-entity="org.apache.roller.weblogger.pojos.Weblog">
<join-column name="websiteid" insertable="true"
updatable="true" nullable="false"/>
</many-to-one>
Modified:
roller/trunk/app/src/main/resources/org/apache/roller/weblogger/pojos/WeblogEntry.orm.xml
URL:
http://svn.apache.org/viewvc/roller/trunk/app/src/main/resources/org/apache/roller/weblogger/pojos/WeblogEntry.orm.xml?rev=1566356&r1=1566355&r2=1566356&view=diff
==============================================================================
---
roller/trunk/app/src/main/resources/org/apache/roller/weblogger/pojos/WeblogEntry.orm.xml
(original)
+++
roller/trunk/app/src/main/resources/org/apache/roller/weblogger/pojos/WeblogEntry.orm.xml
Sun Feb 9 19:05:35 2014
@@ -12,9 +12,6 @@
<named-query name="WeblogEntry.getByCategory">
<query>SELECT w FROM WeblogEntry w WHERE w.category = ?1</query>
</named-query>
- <named-query
name="WeblogEntry.getByStatus&Category.pathLike&Website">
- <query>SELECT w FROM WeblogEntry w WHERE w.status = ?1 AND
w.category.path LIKE ?2 AND w.website = ?3</query>
- </named-query>
<named-query
name="WeblogEntry.getByPinnedToMain&statusOrderByPubTimeDesc">
<query>SELECT w FROM WeblogEntry w WHERE w.pinnedToMain = ?1 AND
w.status = ?2 ORDER BY w.pubTime DESC</query>
</named-query>
Modified:
roller/trunk/app/src/test/java/org/apache/roller/weblogger/business/WeblogCategoryCRUDTest.java
URL:
http://svn.apache.org/viewvc/roller/trunk/app/src/test/java/org/apache/roller/weblogger/business/WeblogCategoryCRUDTest.java?rev=1566356&r1=1566355&r2=1566356&view=diff
==============================================================================
---
roller/trunk/app/src/test/java/org/apache/roller/weblogger/business/WeblogCategoryCRUDTest.java
(original)
+++
roller/trunk/app/src/test/java/org/apache/roller/weblogger/business/WeblogCategoryCRUDTest.java
Sun Feb 9 19:05:35 2014
@@ -91,10 +91,12 @@ public class WeblogCategoryCRUDTest exte
WeblogCategory testCat = new WeblogCategory(testWeblog, null, "root",
"root", null);
assertTrue(root.equals(testCat));
-
- testCat = new WeblogCategory(testWeblog, root, "root", "root", null);
+ mgr.removeWeblogCategory(testCat);
+
+ testCat = new WeblogCategory(testWeblog, root, "other name", "root",
null);
assertFalse(root.equals(testCat));
-
+ mgr.removeWeblogCategory(testCat);
+
log.info("END");
}
@@ -175,13 +177,10 @@ public class WeblogCategoryCRUDTest exte
testWeblog = TestUtils.getManagedWebsite(testWeblog);
WeblogCategory root = mgr.getRootWeblogCategory(testWeblog);
- // add a small category tree /subcat/subcat2
+ // add a category child item /subcat
WeblogCategory subcat = new WeblogCategory(testWeblog, root,
"subcatTest1", null, null);
root.addCategory(subcat);
mgr.saveWeblogCategory(subcat);
- WeblogCategory subcat2 = new WeblogCategory(testWeblog, subcat,
"subcatTest2", null, null);
- subcat.addCategory(subcat2);
- mgr.saveWeblogCategory(subcat2);
TestUtils.endSession(true);
// check that subcat tree can be navigated
@@ -190,10 +189,8 @@ public class WeblogCategoryCRUDTest exte
assertEquals(1, root.getWeblogCategories().size());
subcat = (WeblogCategory) root.getWeblogCategories().iterator().next();
assertEquals("subcatTest1", subcat.getName());
- assertEquals(1, subcat.getWeblogCategories().size());
- subcat2 = (WeblogCategory)
subcat.getWeblogCategories().iterator().next();
- assertEquals("subcatTest2", subcat2.getName());
-
+ assertEquals(0, subcat.getWeblogCategories().size());
+
// now delete category and subcats should be deleted by cascade
mgr.removeWeblogCategory(subcat);
TestUtils.endSession(true);
@@ -202,7 +199,7 @@ public class WeblogCategoryCRUDTest exte
testWeblog = TestUtils.getManagedWebsite(testWeblog);
root = mgr.getRootWeblogCategory(testWeblog);
assertEquals(0, root.getWeblogCategories().size());
-
assertNull(mgr.getWeblogCategoryByPath(TestUtils.getManagedWebsite(testWeblog),
"/subcatTest1/subcatTest2"));
+
assertNull(mgr.getWeblogCategoryByPath(TestUtils.getManagedWebsite(testWeblog),
"/subcatTest1"));
log.info("END");
}
Modified:
roller/trunk/app/src/test/java/org/apache/roller/weblogger/business/WeblogCategoryFunctionalityTest.java
URL:
http://svn.apache.org/viewvc/roller/trunk/app/src/test/java/org/apache/roller/weblogger/business/WeblogCategoryFunctionalityTest.java?rev=1566356&r1=1566355&r2=1566356&view=diff
==============================================================================
---
roller/trunk/app/src/test/java/org/apache/roller/weblogger/business/WeblogCategoryFunctionalityTest.java
(original)
+++
roller/trunk/app/src/test/java/org/apache/roller/weblogger/business/WeblogCategoryFunctionalityTest.java
Sun Feb 9 19:05:35 2014
@@ -180,28 +180,28 @@ public class WeblogCategoryFunctionality
/**
* Lookup category by path.
*/
- public void testLookupCategoryByPath() throws Exception {
+ public void testLookupCategoryByName() throws Exception {
log.info("BEGIN");
WeblogEntryManager mgr =
WebloggerFactory.getWeblogger().getWeblogEntryManager();
testWeblog = TestUtils.getManagedWebsite(testWeblog);
- WeblogCategory cat = mgr.getWeblogCategoryByPath(testWeblog,
"/catTest-cat1");
+ WeblogCategory cat = mgr.getWeblogCategoryByName(testWeblog,
"catTest-cat1");
assertNotNull(cat);
assertEquals(cat, cat1);
- cat = mgr.getWeblogCategoryByPath(testWeblog,
"/catTest-cat1/catTest-cat2/catTest-cat3");
+ cat = mgr.getWeblogCategoryByName(testWeblog, "catTest-cat3");
assertNotNull(cat);
assertEquals(cat, cat3);
// test lazy lookup, specifying just a name without slashes
- cat = mgr.getWeblogCategoryByPath(testWeblog, "catTest-cat1");
+ cat = mgr.getWeblogCategoryByName(testWeblog, "catTest-cat1");
assertNotNull(cat);
assertEquals(cat, cat1);
// if no path is specified we should get the root category
- cat = mgr.getWeblogCategoryByPath(testWeblog, null);
+ cat = mgr.getWeblogCategoryByName(testWeblog, null);
assertNotNull(cat);
assertEquals(cat.getPath(), "/");