Author: snoopdave
Date: Tue Oct 2 17:00:14 2007
New Revision: 581437
URL: http://svn.apache.org/viewvc?rev=581437&view=rev
Log:
Fix for podcasting
http://opensource.atlassian.com/projects/roller/browse/ROL-1573
Modified:
roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/business/jpa/JPAWeblogManagerImpl.java
roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/pojos/WeblogEntry.java
roller/trunk/apps/weblogger/test/java/org/apache/roller/weblogger/business/WeblogEntryTest.java
Modified:
roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/business/jpa/JPAWeblogManagerImpl.java
URL:
http://svn.apache.org/viewvc/roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/business/jpa/JPAWeblogManagerImpl.java?rev=581437&r1=581436&r2=581437&view=diff
==============================================================================
---
roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/business/jpa/JPAWeblogManagerImpl.java
(original)
+++
roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/business/jpa/JPAWeblogManagerImpl.java
Tue Oct 2 17:00:14 2007
@@ -375,6 +375,17 @@
}
}
+ // remove attributes
+ if (entry.getEntryAttributes() != null) {
+ for (Iterator it = entry.getEntryAttributes().iterator();
it.hasNext(); ) {
+ WeblogEntryAttribute att = (WeblogEntryAttribute) it.next();
+ it.remove();
+ this.strategy.remove(att);
+ }
+ }
+ // TODO: can we eliminate this unnecessary flush with OpenJPA 1.0
+ this.strategy.flush();
+
// remove entry
this.strategy.remove(entry);
@@ -654,8 +665,6 @@
for (Iterator it = entry.getEntryAttributes().iterator();
it.hasNext();) {
WeblogEntryAttribute entryAttribute = (WeblogEntryAttribute)
it.next();
if (entryAttribute.getName().equals(name)) {
- //Call back the entity to adjust its internal state
- entry.onRemoveEntryAttribute(entryAttribute);
//Remove it from database
this.strategy.remove(entryAttribute);
//Remove it from the collection
Modified:
roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/pojos/WeblogEntry.java
URL:
http://svn.apache.org/viewvc/roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/pojos/WeblogEntry.java?rev=581437&r1=581436&r2=581437&view=diff
==============================================================================
---
roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/pojos/WeblogEntry.java
(original)
+++
roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/pojos/WeblogEntry.java
Tue Oct 2 17:00:14 2007
@@ -98,7 +98,6 @@
private WeblogCategory category = null;
// Collection of name/value entry attributes
- private Map attMap = new HashMap();
private Set attSet = new TreeSet();
private Set tagSet = new HashSet();
@@ -386,22 +385,8 @@
return attSet;
}
/** @ejb:persistent-field */
- public void setEntryAttributes(Set attSet) {
- this.attSet = attSet;
-
- // copy set to map
- if (attSet != null) {
- this.attSet = attSet;
- this.attMap = new HashMap();
- Iterator iter = this.attSet.iterator();
- while (iter.hasNext()) {
- WeblogEntryAttribute att = (WeblogEntryAttribute)iter.next();
- attMap.put(att.getName(), att);
- }
- } else {
- this.attSet = new TreeSet();
- this.attMap = new HashMap();
- }
+ public void setEntryAttributes(Set atts) {
+ this.attSet = atts;
}
@@ -411,27 +396,33 @@
* @roller.wrapPojoMethod type="simple"
*/
public String findEntryAttribute(String name) {
- WeblogEntryAttribute att = ((WeblogEntryAttribute)attMap.get(name));
- return (att != null) ? att.getValue() : null;
+ if (getEntryAttributes() != null) {
+ for (Iterator it = getEntryAttributes().iterator(); it.hasNext();
) {
+ WeblogEntryAttribute att = (WeblogEntryAttribute) it.next();
+ if (name.equals(att.getName())) return att.getValue();
+ }
+ }
+ return null;
}
-
-
+
public void putEntryAttribute(String name, String value) throws Exception {
- WeblogEntryAttribute att = (WeblogEntryAttribute)attMap.get(name);
+ WeblogEntryAttribute att = null;
+ for (Iterator it = getEntryAttributes().iterator(); it.hasNext(); ) {
+ WeblogEntryAttribute o = (WeblogEntryAttribute) it.next();
+ if (name.equals(o.getName())) {
+ att = o;
+ break;
+ }
+ }
if (att == null) {
att = new WeblogEntryAttribute();
att.setEntry(this);
att.setName(name);
att.setValue(value);
- attMap.put(name, att);
- attSet.add(att);
+ getEntryAttributes().add(att);
} else {
att.setValue(value);
}
- }
-
- public void onRemoveEntryAttribute(WeblogEntryAttribute att) throws
WebloggerException {
- attMap.remove(att.getName());
}
//-------------------------------------------------------------------------
Modified:
roller/trunk/apps/weblogger/test/java/org/apache/roller/weblogger/business/WeblogEntryTest.java
URL:
http://svn.apache.org/viewvc/roller/trunk/apps/weblogger/test/java/org/apache/roller/weblogger/business/WeblogEntryTest.java?rev=581437&r1=581436&r2=581437&view=diff
==============================================================================
---
roller/trunk/apps/weblogger/test/java/org/apache/roller/weblogger/business/WeblogEntryTest.java
(original)
+++
roller/trunk/apps/weblogger/test/java/org/apache/roller/weblogger/business/WeblogEntryTest.java
Tue Oct 2 17:00:14 2007
@@ -956,7 +956,63 @@
*/
public void testEntryAttributeCRUD() throws Exception {
- // TODO: implement entry attribute test
+ WeblogManager mgr = WebloggerFactory.getWeblogger().getWeblogManager();
+ WeblogEntry entry = null;
+
+ WeblogEntry testEntry = new WeblogEntry();
+ testEntry.setTitle("entryTestEntry");
+ testEntry.setLink("testEntryLink");
+ testEntry.setText("blah blah entry");
+ testEntry.setAnchor("testEntryAnchor");
+ testEntry.setPubTime(new java.sql.Timestamp(new
java.util.Date().getTime()));
+ testEntry.setUpdateTime(new java.sql.Timestamp(new
java.util.Date().getTime()));
+ testEntry.setWebsite(testWeblog);
+ testEntry.setCreator(testUser);
+
+ testEntry.putEntryAttribute("att_mediacast_url",
"http://podcast-schmodcast.com");
+ testEntry.putEntryAttribute("att_mediacast_type",
"application/drivel");
+ testEntry.putEntryAttribute("att_mediacast_length", "3141592654");
+
+ WeblogCategory cat =
mgr.getWeblogCategory(testWeblog.getDefaultCategory().getId());
+ testEntry.setCategory(cat);
+
+ // create a weblog entry
+ mgr.saveWeblogEntry(testEntry);
+ String id = testEntry.getId();
+ TestUtils.endSession(true);
+
+ // make sure entry was created
+ entry = mgr.getWeblogEntry(id);
+ assertNotNull(entry);
+ assertEquals(testEntry, entry);
+ assertNotNull(entry.getEntryAttributes());
+ assertEquals(3, entry.getEntryAttributes().size());
+ assertNotNull(entry.findEntryAttribute("att_mediacast_url"));
+ assertNotNull(entry.findEntryAttribute("att_mediacast_type"));
+ assertNotNull(entry.findEntryAttribute("att_mediacast_length"));
+ assertEquals("http://podcast-schmodcast.com",
entry.findEntryAttribute("att_mediacast_url"));
+ assertEquals("application/drivel",
entry.findEntryAttribute("att_mediacast_type"));
+ assertEquals("3141592654",
entry.findEntryAttribute("att_mediacast_length"));
+
+ // update a weblog entry
+ entry.setTitle("testtest");
+ mgr.saveWeblogEntry(entry);
+ TestUtils.endSession(true);
+
+ // make sure entry was updated
+ entry = null;
+ entry = mgr.getWeblogEntry(id);
+ assertNotNull(entry);
+ assertEquals("testtest", entry.getTitle());
+
+ // delete a weblog entry
+ mgr.removeWeblogEntry(entry);
+ TestUtils.endSession(true);
+
+ // make sure entry was deleted
+ entry = null;
+ entry = mgr.getWeblogEntry(id);
+ assertNull(entry);
}