roller-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From snoopd...@apache.org
Subject svn commit: r812165 - in /roller/trunk/apps/weblogger: src/java/org/apache/roller/weblogger/business/jpa/ src/java/org/apache/roller/weblogger/business/startup/ src/java/org/apache/roller/weblogger/business/themes/ src/java/org/apache/roller/weblogger/...
Date Mon, 07 Sep 2009 14:48:20 GMT
Author: snoopdave
Date: Mon Sep  7 14:48:19 2009
New Revision: 812165

URL: http://svn.apache.org/viewvc?rev=812165&view=rev
Log:
Fixes related to ROL-1816

Modified:
    roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/business/jpa/JPAMediaFileManagerImpl.java
    roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/business/startup/WebloggerStartup.java
    roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/business/themes/ThemeManagerImpl.java
    roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/pojos/MediaFile.java
    roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/pojos/MediaFile.orm.xml
    roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/pojos/MediaFileDirectory.java
    roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/ui/rendering/servlets/ResourceServlet.java
    roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/ui/struts2/editor/MediaFileAdd.java
    roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/ui/struts2/editor/MediaFileSearch.java
    roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/ui/struts2/editor/MediaFileView.java
    roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/webservices/atomprotocol/MediaCollection.java
    roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/webservices/xmlrpc/MetaWeblogAPIHandler.java
    roller/trunk/apps/weblogger/src/sql/400-to-500-migration.vm
    roller/trunk/apps/weblogger/src/sql/createdb.vm
    roller/trunk/apps/weblogger/test/java/org/apache/roller/weblogger/business/MediaFileTest.java
    roller/trunk/apps/weblogger/test/java/org/apache/roller/weblogger/webservices/RollerAtomPubServerTest.java

Modified: roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/business/jpa/JPAMediaFileManagerImpl.java
URL: http://svn.apache.org/viewvc/roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/business/jpa/JPAMediaFileManagerImpl.java?rev=812165&r1=812164&r2=812165&view=diff
==============================================================================
--- roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/business/jpa/JPAMediaFileManagerImpl.java (original)
+++ roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/business/jpa/JPAMediaFileManagerImpl.java Mon Sep  7 14:48:19 2009
@@ -31,6 +31,7 @@
 
 import java.util.Properties;
 import java.util.Set;
+import java.util.StringTokenizer;
 import javax.persistence.NoResultException;
 import javax.persistence.Query;
 
@@ -140,8 +141,12 @@
     /**
      * {@inheritDoc}
      */
-    public MediaFileDirectory createMediaFileDirectoryByPath(Weblog weblog, String path)
+    public MediaFileDirectory createMediaFileDirectoryByPath(Weblog weblog, String requestedPath)
             throws WebloggerException {
+
+        String path = requestedPath;
+        log.debug("Creating dir: " + path);
+
         if (path.startsWith("/")) {
             path = path.substring(1);
         }
@@ -151,35 +156,56 @@
         }
 
         if (path.equals("")) {
-            /**
-             * Root cannot be created using this method. Use createRootMediaFileDirectory instead
-             */
+            // Root cannot be created using this method.
+            // Use createRootMediaFileDirectory instead
             throw new WebloggerException("Invalid path!");
         }
-
+        
         int lastPathIndex = path.lastIndexOf("/");
 
-        MediaFileDirectory parentDirectory;
-        String newDirName;
+        MediaFileDirectory newDirectory = null;
         if (lastPathIndex == -1) {
-            //Directory needs to be created under root
-            newDirName = path;
-            parentDirectory = getMediaFileRootDirectory(weblog);
-        } else {
-            String parentPath = path.substring(0, lastPathIndex);
-            newDirName = path.substring(lastPathIndex + 1);
-            parentDirectory = getMediaFileDirectoryByPath(weblog, "/" + parentPath);
-            // Validate whether the parent directory exists
-            if (parentDirectory == null) {
-                throw new WebloggerException("Parent directory does not exist");
+
+            // Directory needs to be created under root
+            MediaFileDirectory root = getMediaFileRootDirectory(weblog);
+
+            if (root.hasDirectory(path)) {
+                throw new WebloggerException("Directory exists");
+            } else {
+                log.debug("    Created dir under ROOT");
+                newDirectory = root.createNewDirectory(path);
             }
-        }
 
-        if (parentDirectory.hasDirectory(newDirName)) {
-            throw new WebloggerException("Directory exists");
-        }
+        } else {
 
-        MediaFileDirectory newDirectory = parentDirectory.createNewDirectory(newDirName);
+            boolean created = false;
+
+            MediaFileDirectory base = getMediaFileRootDirectory(weblog);
+            String token = null;
+            String pathpart = "";
+            StringTokenizer toker = new StringTokenizer(path, "/");
+            while (toker.hasMoreTokens()) {
+                token = toker.nextToken();
+                if (!pathpart.endsWith("/")) {
+                    pathpart += "/" + token;
+                } else {
+                    pathpart += token;
+                }
+                MediaFileDirectory possibleBase = getMediaFileDirectoryByPath(weblog, pathpart);
+                if (possibleBase == null) {
+                    base = base.createNewDirectory(token);
+                    log.debug("   Created new directory: " + base.getPath());
+                    created = true;
+                    roller.flush();
+                } else {
+                    base = possibleBase;
+                }
+            }           
+            if (!created || !requestedPath.equals(base.getPath())) {
+                throw new WebloggerException("ERROR directory not created");
+            }
+            newDirectory = base;
+        }
 
         // update weblog last modified date.  date updated by saveWeblog()
         roller.getWeblogManager().saveWeblog(weblog);
@@ -269,6 +295,9 @@
      */
     public MediaFileDirectory getMediaFileDirectoryByPath(Weblog weblog, String path)
             throws WebloggerException {
+
+        log.debug("Looking up weblog|path: " + weblog.getHandle() + "|" + path);
+
         Query q = this.persistenceStrategy.getNamedQuery(
                 "MediaFileDirectory.getByWeblogAndPath");
         q.setParameter(1, weblog);
@@ -287,11 +316,18 @@
             throws WebloggerException {
 
         // get directory
-        MediaFileDirectory mdir = getMediaFileDirectoryByPath(
-            weblog, path.substring(0, path.lastIndexOf("/")));
-        if (mdir == null) return null; // no such path found
-
-        return mdir.getMediaFile(path.substring(path.lastIndexOf("/")));
+        String fileName = path;
+        MediaFileDirectory mdir = null;
+        int slash = path.lastIndexOf("/");
+        if (slash > 0) {
+            mdir = getMediaFileDirectoryByPath(weblog, path.substring(0, slash));
+        } else {
+            mdir = getMediaFileRootDirectory(weblog);
+        }
+        if (slash != -1) {
+            fileName = fileName.substring(slash + 1);
+        }
+        return mdir.getMediaFile(fileName);
     }
 
     /**
@@ -299,15 +335,23 @@
      */
     public MediaFile getMediaFileByOriginalPath(Weblog weblog, String origpath) 
             throws WebloggerException {
+
+        if (!origpath.startsWith("/")) origpath = "/" + origpath;
+        
         Query q = this.persistenceStrategy.getNamedQuery(
                 "MediaFile.getByWeblogAndOrigpath");
         q.setParameter(1, weblog);
         q.setParameter(2, origpath);
+        MediaFile mf = null;
         try {
-            return (MediaFile) q.getSingleResult();
+            mf = (MediaFile) q.getSingleResult();
         } catch (NoResultException e) {
             return null;
         }
+        FileContentManager cmgr = WebloggerFactory.getWeblogger().getFileContentManager();
+        FileContent content = cmgr.getFileContent(mf.getDirectory().getWeblog(), mf.getId());
+        mf.setContent(content);
+        return mf;
     }
 
     /**
@@ -621,7 +665,7 @@
                 } else {
 
                     String originalPath = 
-                        ("/".equals(newDir.getPath()) ? "" : newDir.getPath()) + files[i].getName();
+                        ("/".equals(newDir.getPath()) ? "" : newDir.getPath()) + "/" + files[i].getName();
                     log.debug("    Upgrade file with original path: " + originalPath);
                     MediaFile mf = new MediaFile();
                     try {
@@ -633,6 +677,7 @@
                         mf.setLastUpdated(new Timestamp(files[i].lastModified()));
 
                         mf.setDirectory(newDir);
+                        mf.setWeblog(weblog);
                         mf.setCreatorUserName(user.getUserName());
                         mf.setSharedForGallery(Boolean.FALSE);
 

Modified: roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/business/startup/WebloggerStartup.java
URL: http://svn.apache.org/viewvc/roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/business/startup/WebloggerStartup.java?rev=812165&r1=812164&r2=812165&view=diff
==============================================================================
--- roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/business/startup/WebloggerStartup.java (original)
+++ roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/business/startup/WebloggerStartup.java Mon Sep  7 14:48:19 2009
@@ -176,8 +176,13 @@
         try {
             mailProvider = new MailProvider();
         } catch(StartupException ex) {
-            log.warn("Failed to setup mail provider, continuing anways.\n"+
-                    "Reason: "+ex.getMessage(), ex);
+            if (log.isDebugEnabled()) {
+                log.debug("Failed to setup mail provider, continuing anways.\n"
+                    + "Reason: " + ex.getMessage(), ex);
+            } else {
+                log.warn("Failed to setup mail provider, continuing anways.\n"
+                    + "Reason: " + ex.getMessage());
+            }
         }
         
         // now we need to deal with database install/upgrade logic

Modified: roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/business/themes/ThemeManagerImpl.java
URL: http://svn.apache.org/viewvc/roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/business/themes/ThemeManagerImpl.java?rev=812165&r1=812164&r2=812165&view=diff
==============================================================================
--- roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/business/themes/ThemeManagerImpl.java (original)
+++ roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/business/themes/ThemeManagerImpl.java Mon Sep  7 14:48:19 2009
@@ -303,6 +303,7 @@
                         // save file without file-type, quota checks, etc.
                         MediaFile mf = new MediaFile();
                         mf.setDirectory(mdir);
+                        mf.setWeblog(website);
                         mf.setName(justName);
                         mf.setOriginalPath(justPath);
                         mf.setContentType("text/plain");

Modified: roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/pojos/MediaFile.java
URL: http://svn.apache.org/viewvc/roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/pojos/MediaFile.java?rev=812165&r1=812164&r2=812165&view=diff
==============================================================================
--- roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/pojos/MediaFile.java (original)
+++ roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/pojos/MediaFile.java Mon Sep  7 14:48:19 2009
@@ -51,6 +51,8 @@
     private String      creatorUserName;
     private MediaFileDirectory directory;
     private Set<MediaFileTag>  tags;
+    private Weblog      weblog;
+
     
     // TODO: anchor to be populated
     private String      anchor;
@@ -267,4 +269,18 @@
     public void setOriginalPath(String originalPath) {
         this.originalPath = originalPath;
     }
+
+    /**
+     * @return the weblog
+     */
+    public Weblog getWeblog() {
+        return weblog;
+    }
+
+    /**
+     * @param weblog the weblog to set
+     */
+    public void setWeblog(Weblog weblog) {
+        this.weblog = weblog;
+    }
 }

Modified: roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/pojos/MediaFile.orm.xml
URL: http://svn.apache.org/viewvc/roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/pojos/MediaFile.orm.xml?rev=812165&r1=812164&r2=812165&view=diff
==============================================================================
--- roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/pojos/MediaFile.orm.xml (original)
+++ roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/pojos/MediaFile.orm.xml Mon Sep  7 14:48:19 2009
@@ -50,7 +50,10 @@
                 <column name="creator" insertable="true" updatable="true" unique="false" />
             </basic>
             <many-to-one name="directory" target-entity="org.apache.roller.weblogger.pojos.MediaFileDirectory">
-                <join-column name="directory_id" insertable="true" updatable="true" nullable="false"/>
+                <join-column name="directoryid" insertable="true" updatable="true" nullable="false"/>
+            </many-to-one>
+            <many-to-one name="weblog" target-entity="org.apache.roller.weblogger.pojos.Weblog">
+                <join-column name="weblogid" insertable="true" updatable="true" nullable="false"/>
             </many-to-one>
             <one-to-many name="tags" mapped-by="mediaFile" target-entity="org.apache.roller.weblogger.pojos.MediaFileTag">
                 <cascade>

Modified: roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/pojos/MediaFileDirectory.java
URL: http://svn.apache.org/viewvc/roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/pojos/MediaFileDirectory.java?rev=812165&r1=812164&r2=812165&view=diff
==============================================================================
--- roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/pojos/MediaFileDirectory.java (original)
+++ roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/pojos/MediaFileDirectory.java Mon Sep  7 14:48:19 2009
@@ -17,6 +17,7 @@
  */
 package org.apache.roller.weblogger.pojos;
 
+import java.util.HashSet;
 import java.util.Set;
 
 import org.apache.commons.lang.builder.EqualsBuilder;
@@ -24,18 +25,17 @@
 
 /**
  * Represents a Media file directory.
- * 
  */
 public class MediaFileDirectory {
 
     String id;
     String name;
     String description;
-    MediaFileDirectory parent;
     Weblog weblog;
     String path;
-    Set<MediaFileDirectory> childDirectories;
-    Set<MediaFile> mediaFiles;
+    MediaFileDirectory      parent;
+    Set<MediaFileDirectory> childDirectories = new HashSet<MediaFileDirectory>();
+    Set<MediaFile>          mediaFiles = new HashSet<MediaFile>();
 
     public MediaFileDirectory() {
     }

Modified: roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/ui/rendering/servlets/ResourceServlet.java
URL: http://svn.apache.org/viewvc/roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/ui/rendering/servlets/ResourceServlet.java?rev=812165&r1=812164&r2=812165&view=diff
==============================================================================
--- roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/ui/rendering/servlets/ResourceServlet.java (original)
+++ roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/ui/rendering/servlets/ResourceServlet.java Mon Sep  7 14:48:19 2009
@@ -41,11 +41,8 @@
 
 
 /**
- * Serves files uploaded by users as well as static resources in shared themes.
- *
- * Since we keep resources in a location outside of the webapp
- * context we need a way to serve them up.  This servlet assumes that
- * resources are stored on a filesystem in the "uploads.dir" directory.
+ * Serves fixed-path files such as old-style uploads and theme resources,
+ * which must exist at a fixed-path even if moved in media file folders.
  *
  * @web.servlet name="ResourcesServlet" load-on-startup="5"
  * @web.servlet-mapping url-pattern="/roller-ui/rendering/resources/*"

Modified: roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/ui/struts2/editor/MediaFileAdd.java
URL: http://svn.apache.org/viewvc/roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/ui/struts2/editor/MediaFileAdd.java?rev=812165&r1=812164&r2=812165&view=diff
==============================================================================
--- roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/ui/struts2/editor/MediaFileAdd.java (original)
+++ roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/ui/struts2/editor/MediaFileAdd.java Mon Sep  7 14:48:19 2009
@@ -101,6 +101,7 @@
     			MediaFile mediaFile = new MediaFile();
     			bean.copyTo(mediaFile);
     			mediaFile.setDirectory(getDirectory());
+                        mediaFile.setWeblog(getActionWeblog());
     			mediaFile.setLength(this.uploadedFile.length());
     			mediaFile.setInputStream(new FileInputStream(this.uploadedFile));
     			mediaFile.setContentType(this.uploadedFileContentType);

Modified: roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/ui/struts2/editor/MediaFileSearch.java
URL: http://svn.apache.org/viewvc/roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/ui/struts2/editor/MediaFileSearch.java?rev=812165&r1=812164&r2=812165&view=diff
==============================================================================
--- roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/ui/struts2/editor/MediaFileSearch.java (original)
+++ roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/ui/struts2/editor/MediaFileSearch.java Mon Sep  7 14:48:19 2009
@@ -15,7 +15,6 @@
  * copyright in this work, please see the NOTICE file in the top level
  * directory of this distribution.
  */
-
 package org.apache.roller.weblogger.ui.struts2.editor;
 
 import java.util.ArrayList;
@@ -39,70 +38,60 @@
  */
 @SuppressWarnings("serial")
 public class MediaFileSearch extends MediaFileBase {
-    private static Log log = LogFactory.getLog(MediaFileSearch.class);
 
+    private static Log log = LogFactory.getLog(MediaFileSearch.class);
     // Search criteria - drop-down for file type 
     private static final List<String> FILE_TYPES;
-
     // Search criteria - drop-down for size filter
     private static final List<KeyValueObject> SIZE_FILTER_TYPES;
-
     // Search criteria - drop-down for size unit
     private static final List<KeyValueObject> SIZE_UNITS;
-
     // Sort options for search results.
     private static final List<KeyValueObject> SORT_OPTIONS;
-    
     // Pager for displaying search results.
     private MediaFilePager pager;
-
     // Path of new directory to be created.
     private String newDirectoryPath;
-    
+
     static {
-    	/**
-    	 * Initialize drop-down values.
-    	 * 
-    	 */
-    	
-    	FILE_TYPES = Arrays.asList("", "Audio", "Video", "Image", "Others");
-        
-    	SIZE_FILTER_TYPES = Arrays.asList(
-        		new KeyValueObject(0, "greater than"),
-        		new KeyValueObject(1, "greater than or equal to"),
-        		new KeyValueObject(2, "equal to"),
-        		new KeyValueObject(3, "less than or equal to"),
-        		new KeyValueObject(4, "less than")
-        		);
-
-    	SIZE_UNITS = Arrays.asList(
-        		new KeyValueObject(0, "bytes"),
-        		new KeyValueObject(1, "kilobytes"),
-        		new KeyValueObject(2, "megabytes")
-        		);
-        
-    	SORT_OPTIONS = Arrays.asList(
-        		new KeyValueObject(0, "Name"),
-        		new KeyValueObject(1, "Date Uploaded"),
-        		new KeyValueObject(2, "Type")
-        		); 
+        /**
+         * Initialize drop-down values.
+         *
+         */
+        FILE_TYPES = Arrays.asList("", "Audio", "Video", "Image", "Others");
+
+        SIZE_FILTER_TYPES = Arrays.asList(
+                new KeyValueObject(0, "greater than"),
+                new KeyValueObject(1, "greater than or equal to"),
+                new KeyValueObject(2, "equal to"),
+                new KeyValueObject(3, "less than or equal to"),
+                new KeyValueObject(4, "less than"));
+
+        SIZE_UNITS = Arrays.asList(
+                new KeyValueObject(0, "bytes"),
+                new KeyValueObject(1, "kilobytes"),
+                new KeyValueObject(2, "megabytes"));
+
+        SORT_OPTIONS = Arrays.asList(
+                new KeyValueObject(0, "Name"),
+                new KeyValueObject(1, "Date Uploaded"),
+                new KeyValueObject(2, "Type"));
     }
-    
-    private MediaFileSearchBean bean =  new MediaFileSearchBean();
+    private MediaFileSearchBean bean = new MediaFileSearchBean();
 
     public MediaFileSearch() {
         this.actionName = "mediaFileSearch";
         this.desiredMenu = "editor";
         this.pageTitle = "mediaFile.search.title";
     }
-    
+
     /**
      * Prepares search action
      */
     public void myPrepare() {
-    	refreshAllDirectories();
+        refreshAllDirectories();
     }
-    
+
     /**
      * Show form for adding a new media file.
      * 
@@ -110,62 +99,62 @@
      */
     @SkipValidation
     public String execute() {
-		return INPUT;
+        return INPUT;
     }
-    
+
     /**
      * Save a media file.
      * 
      * @return String The result of the action.
      */
     public String search() {
-    	boolean valSuccess = myValidate();
-    	if (valSuccess) {
-    		MediaFileFilter filter = new MediaFileFilter();
-    		bean.copyTo(filter);
-    		MediaFileManager manager = WebloggerFactory.getWeblogger().getMediaFileManager();
-    		try {
-    			List<MediaFile> rawResults = manager.searchMediaFiles(getActionWeblog(), filter);
-    			boolean hasMore = false;
-    			List<MediaFile> results = new ArrayList<MediaFile>();
-    			results.addAll(rawResults);
-    			if (results.size() > MediaFileSearchBean.PAGE_SIZE) {
-    				results.remove(results.size() - 1);
-    				hasMore = true;
-    			}
-    			
-    			this.pager = new MediaFilePager(bean.getPageNum(), results, hasMore);
-    			
-    			if (results.isEmpty()) {
+        boolean valSuccess = myValidate();
+        if (valSuccess) {
+            MediaFileFilter filter = new MediaFileFilter();
+            bean.copyTo(filter);
+            MediaFileManager manager = WebloggerFactory.getWeblogger().getMediaFileManager();
+            try {
+                List<MediaFile> rawResults = manager.searchMediaFiles(getActionWeblog(), filter);
+                boolean hasMore = false;
+                List<MediaFile> results = new ArrayList<MediaFile>();
+                results.addAll(rawResults);
+                if (results.size() > MediaFileSearchBean.PAGE_SIZE) {
+                    results.remove(results.size() - 1);
+                    hasMore = true;
+                }
+
+                this.pager = new MediaFilePager(bean.getPageNum(), results, hasMore);
+
+                if (results.isEmpty()) {
                     addError("MediaFile.error.search.noResults");
-    			}
-	    		return SUCCESS;
-			} catch (Exception e) {
-	            log.error("Error applying search criteria", e);
+                }
+                return SUCCESS;
+            } catch (Exception e) {
+                log.error("Error applying search criteria", e);
                 // TODO: i18n
                 addError("Error applying search criteria");
-			}
-    		
-    	}
-		return INPUT;
+            }
+
+        }
+        return INPUT;
     }
-    
+
     /**
      * Delete the selected media file.
      * 
      */
     public String delete() {
-    	doDeleteMediaFile();
-    	return search();
+        doDeleteMediaFile();
+        return search();
     }
-    
+
     /**
      * Include selected media file in public gallery.
      * 
      */
     public String includeInGallery() {
-    	doIncludeMediaFileInGallery();
-    	return search();
+        doIncludeMediaFileInGallery();
+        return search();
     }
 
     /**
@@ -173,105 +162,100 @@
      * 
      */
     public String deleteSelected() {
-    	doDeleteSelected();
-    	return search();
+        doDeleteSelected();
+        return search();
     }
-    
+
     /**
      * Move selected media files to a directory.
      * 
      */
     public String moveSelected() {
         doMoveSelected();
-    	return search();
+        return search();
     }
-    
+
     /**
      * Creates a directory by its path
      * 
      */
     public String createDirByPath() {
-    	boolean dirCreated = false;
-		if (StringUtils.isEmpty(this.newDirectoryPath)) {
-			addError("mediaFile.error.search.dirPathEmpty");
-		}
-		else if (!this.newDirectoryPath.startsWith("/")) {
-			addError("mediaFile.error.search.dirPathInvalid");
-		}
-		else {
-	    	try {
-				log.debug("Creating directory by path - " + this.newDirectoryPath);
-				MediaFileManager manager = WebloggerFactory.getWeblogger().getMediaFileManager();
-				manager.createMediaFileDirectoryByPath(getActionWeblog(), this.newDirectoryPath);
-				// flush changes
-				WebloggerFactory.getWeblogger().flush();
-				addMessage("mediaFile.directoryCreate.success");
-				dirCreated = true;
-			} catch (WebloggerException e) {
-	            log.error("Error creating new directory by path", e);
-	            // TODO: i18n
-	            addError("Error creating new directory by path");
-			}
-		}
-        
-		if (dirCreated) {
-			// Refresh list of directories so the newly created directory is included.
-			refreshAllDirectories();
-		}
-    	return search();
+        boolean dirCreated = false;
+        if (StringUtils.isEmpty(this.newDirectoryPath)) {
+            addError("mediaFile.error.search.dirPathEmpty");
+        } else if (!this.newDirectoryPath.startsWith("/")) {
+            addError("mediaFile.error.search.dirPathInvalid");
+        } else {
+            try {
+                log.debug("Creating directory by path - " + this.newDirectoryPath);
+                MediaFileManager manager = WebloggerFactory.getWeblogger().getMediaFileManager();
+                manager.createMediaFileDirectoryByPath(getActionWeblog(), this.newDirectoryPath);
+                // flush changes
+                WebloggerFactory.getWeblogger().flush();
+                addMessage("mediaFile.directoryCreate.success");
+                dirCreated = true;
+            } catch (WebloggerException e) {
+                log.error("Error creating new directory by path", e);
+                // TODO: i18n
+                addError("Error creating new directory by path");
+            }
+        }
+
+        if (dirCreated) {
+            // Refresh list of directories so the newly created directory is included.
+            refreshAllDirectories();
+        }
+        return search();
     }
-    
+
     /**
      * Validates search input
      */
     public boolean myValidate() {
-        if (StringUtils.isEmpty(bean.getName())
-        	&& StringUtils.isEmpty(bean.getTags())
-        	&& StringUtils.isEmpty(bean.getType())
-        	&& bean.getSize() == 0) {
-        	addError("MediaFile.error.search.empty");
-        	return false;
+        if (StringUtils.isEmpty(bean.getName()) && StringUtils.isEmpty(bean.getTags()) && StringUtils.isEmpty(bean.getType()) && bean.getSize() == 0) {
+            addError("MediaFile.error.search.empty");
+            return false;
         }
         return true;
     }
-    
+
     public MediaFileSearchBean getBean() {
-    	return bean;
+        return bean;
     }
-    
+
     public void setBean(MediaFileSearchBean b) {
-    	this.bean = b;
+        this.bean = b;
     }
-    
+
     public List<String> getFileTypes() {
-    	return FILE_TYPES;
+        return FILE_TYPES;
     }
-    
+
     public List<KeyValueObject> getSizeFilterTypes() {
-    	return SIZE_FILTER_TYPES;
+        return SIZE_FILTER_TYPES;
     }
-    
+
     public List<KeyValueObject> getSizeUnits() {
-    	return SIZE_UNITS;
+        return SIZE_UNITS;
     }
 
     public List<KeyValueObject> getSortOptions() {
-    	return SORT_OPTIONS;
+        return SORT_OPTIONS;
     }
 
     public MediaFilePager getPager() {
-		return pager;
-	}
+        return pager;
+    }
+
+    public void setPager(MediaFilePager pager) {
+        this.pager = pager;
+    }
+
+    public String getNewDirectoryPath() {
+        return newDirectoryPath;
+    }
 
-	public void setPager(MediaFilePager pager) {
-		this.pager = pager;
-	}
-
-	public String getNewDirectoryPath() {
-		return newDirectoryPath;
-	}
-
-	public void setNewDirectoryPath(String newDirectoryPath) {
-		this.newDirectoryPath = newDirectoryPath;
-	}
+    public void setNewDirectoryPath(String newDirectoryPath) {
+        this.newDirectoryPath = newDirectoryPath;
+    }
 }

Modified: roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/ui/struts2/editor/MediaFileView.java
URL: http://svn.apache.org/viewvc/roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/ui/struts2/editor/MediaFileView.java?rev=812165&r1=812164&r2=812165&view=diff
==============================================================================
--- roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/ui/struts2/editor/MediaFileView.java (original)
+++ roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/ui/struts2/editor/MediaFileView.java Mon Sep  7 14:48:19 2009
@@ -57,11 +57,11 @@
     }
     private String directoryId;
     private String directoryPath;
-    private MediaFileDirectory currentDirectory;
     private String sortBy;
-    private List<MediaFileDirectory> childDirectories;
-    private List<MediaFile> childFiles;
     private String newDirectoryName;
+    private List<MediaFile>          childFiles;
+    private MediaFileDirectory       currentDirectory;
+    private List<MediaFileDirectory> childDirectories;
 
     public MediaFileView() {
         this.actionName = "mediaFileView";

Modified: roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/webservices/atomprotocol/MediaCollection.java
URL: http://svn.apache.org/viewvc/roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/webservices/atomprotocol/MediaCollection.java?rev=812165&r1=812164&r2=812165&view=diff
==============================================================================
--- roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/webservices/atomprotocol/MediaCollection.java (original)
+++ roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/webservices/atomprotocol/MediaCollection.java Mon Sep  7 14:48:19 2009
@@ -132,6 +132,7 @@
 
                     MediaFile mf = new MediaFile();
                     mf.setDirectory(mdir);
+                    mf.setWeblog(website);
                     mf.setName(fileName);
                     mf.setOriginalPath(justPath);
                     mf.setContentType(contentType);

Modified: roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/webservices/xmlrpc/MetaWeblogAPIHandler.java
URL: http://svn.apache.org/viewvc/roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/webservices/xmlrpc/MetaWeblogAPIHandler.java?rev=812165&r1=812164&r2=812165&view=diff
==============================================================================
--- roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/webservices/xmlrpc/MetaWeblogAPIHandler.java (original)
+++ roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/webservices/xmlrpc/MetaWeblogAPIHandler.java Mon Sep  7 14:48:19 2009
@@ -371,6 +371,7 @@
             // Try to save file
             MediaFile mf = new MediaFile();
             mf.setDirectory(root);
+            mf.setWeblog(website);
             mf.setName(name);
             mf.setContentType(type);
             mf.setInputStream(new ByteArrayInputStream(bits));

Modified: roller/trunk/apps/weblogger/src/sql/400-to-500-migration.vm
URL: http://svn.apache.org/viewvc/roller/trunk/apps/weblogger/src/sql/400-to-500-migration.vm?rev=812165&r1=812164&r2=812165&view=diff
==============================================================================
--- roller/trunk/apps/weblogger/src/sql/400-to-500-migration.vm (original)
+++ roller/trunk/apps/weblogger/src/sql/400-to-500-migration.vm Mon Sep  7 14:48:19 2009
@@ -108,7 +108,8 @@
     origpath        varchar(255),
     content_type    varchar(50)  not null,
     copyright_text  varchar(1023),
-    directory_id    varchar(48),
+    directoryid     varchar(48) not null,
+    weblogid        varchar(48) not null,
     size_in_bytes   integer,
     date_uploaded   $db.TIMESTAMP_SQL_TYPE not null,
     last_updated    $db.TIMESTAMP_SQL_TYPE,
@@ -134,7 +135,7 @@
 
 -- media files
 alter table roller_mediafile add constraint roller_mediafiledir_id_fk
-    foreign key (directory_id) references roller_mediafiledir(id) $!db.ADDL_FK_PARAMS ;
+    foreign key (directoryid) references roller_mediafiledir(id) $!db.ADDL_FK_PARAMS ;
 
 alter table roller_mediafiletag add constraint roller_mediafile_id_tag_fk
     foreign key (mediafile_id) references roller_mediafile(id) $!db.ADDL_FK_PARAMS ;

Modified: roller/trunk/apps/weblogger/src/sql/createdb.vm
URL: http://svn.apache.org/viewvc/roller/trunk/apps/weblogger/src/sql/createdb.vm?rev=812165&r1=812164&r2=812165&view=diff
==============================================================================
--- roller/trunk/apps/weblogger/src/sql/createdb.vm (original)
+++ roller/trunk/apps/weblogger/src/sql/createdb.vm Mon Sep  7 14:48:19 2009
@@ -538,7 +538,8 @@
     origpath        varchar(255),
     content_type    varchar(50)  not null,
     copyright_text  varchar(1023),
-    directory_id    varchar(48),
+    directoryid     varchar(48) not null,
+    weblogid        varchar(48) not null,
     size_in_bytes   integer,
     date_uploaded   $db.TIMESTAMP_SQL_TYPE not null,
     last_updated    $db.TIMESTAMP_SQL_TYPE,
@@ -608,8 +609,8 @@
     foreign key ( folderid ) references folder( id ) $!db.ADDL_FK_PARAMS ;
 
 -- media files
-alter table media_file add constraint media_file_directory_id_fk
-    foreign key (directory_id) references media_file_directory(id) $!db.ADDL_FK_PARAMS ;
+alter table media_file add constraint media_file_directoryid_fk
+    foreign key (directoryid) references media_file_directory(id) $!db.ADDL_FK_PARAMS ;
 
 alter table media_file_tag add constraint media_file_id_tag_fk
     foreign key (media_file_id) references media_file(id) $!db.ADDL_FK_PARAMS ;

Modified: roller/trunk/apps/weblogger/test/java/org/apache/roller/weblogger/business/MediaFileTest.java
URL: http://svn.apache.org/viewvc/roller/trunk/apps/weblogger/test/java/org/apache/roller/weblogger/business/MediaFileTest.java?rev=812165&r1=812164&r2=812165&view=diff
==============================================================================
--- roller/trunk/apps/weblogger/test/java/org/apache/roller/weblogger/business/MediaFileTest.java (original)
+++ roller/trunk/apps/weblogger/test/java/org/apache/roller/weblogger/business/MediaFileTest.java Mon Sep  7 14:48:19 2009
@@ -1,24 +1,22 @@
 /*
-* Licensed to the Apache Software Foundation (ASF) under one or more
-*  contributor license agreements.  The ASF licenses this file to You
-* under the Apache License, Version 2.0 (the "License"); you may not
-* use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*     http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.  For additional information regarding
-* copyright in this work, please see the NOTICE file in the top level
-* directory of this distribution.
-*/
-
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
 package org.apache.roller.weblogger.business;
 
-
 import java.io.File;
 import java.util.Arrays;
 import java.util.Collection;
@@ -50,22 +48,21 @@
  * Test media file related business operations.
  */
 public class MediaFileTest extends TestCase {
-    
+
     public static Log log = LogFactory.getLog(MediaFileTest.class);
     //static final String runtimeEnv;
-
     public final static String TEST_IMAGE = "/hawk.jpg";
 
     public MediaFileTest() {
     }
-    
+
     public void setUp() throws Exception {
         TestUtils.setupWeblogger();
     }
-    
+
     public void tearDown() throws Exception {
     }
-    
+
     /**
      * Test creation of directory by path
      */
@@ -73,9 +70,9 @@
     public void testCreateMediaFileDirectoryByPath() throws Exception {
         User testUser = null;
         Weblog testWeblog = null;
-        
-    	// TODO: Setup code, to be moved to setUp method.
-    	System.out.println("Before setting up weblogger");
+
+        // TODO: Setup code, to be moved to setUp method.
+        System.out.println("Before setting up weblogger");
         // setup weblogger
         try {
             testUser = TestUtils.setupUser("mediaFileTestUser8");
@@ -90,86 +87,79 @@
          * Real test starts here.
          */
         MediaFileManager mfMgr = WebloggerFactory.getWeblogger().getMediaFileManager();
-        
+
         testWeblog = TestUtils.getManagedWebsite(testWeblog);
-        MediaFileDirectory rootDirectory = new MediaFileDirectory(null, "root", "root d", testWeblog);
-        mfMgr.createMediaFileDirectory(rootDirectory);
-        assertNotNull(rootDirectory.getId() != null);
+
+        // no need to create root directory, that is done automatically now
+        //MediaFileDirectory rootDirectory = new MediaFileDirectory(null, "root", "root d", testWeblog);
+        //mfMgr.createMediaFileDirectory(rootDirectory);
+        //assertNotNull(rootDirectory.getId() != null);
+
         TestUtils.endSession(true);
-        
+
         testWeblog = TestUtils.getManagedWebsite(testWeblog);
 
         try {
             mfMgr.createMediaFileDirectoryByPath(testWeblog, "");
-        	assertTrue(false);
-        }
-        catch (WebloggerException e) {
-        	assertTrue(true);
+            assertTrue(false);
+        } catch (WebloggerException e) {
+            assertTrue(true);
         }
-        
+
         try {
             mfMgr.createMediaFileDirectoryByPath(testWeblog, "/");
-        	assertTrue(false);
-        }
-        catch (WebloggerException e) {
-        	assertTrue(true);
+            assertTrue(false);
+        } catch (WebloggerException e) {
+            assertTrue(true);
         }
-        
+
         MediaFileDirectory newDirectory1 = mfMgr.createMediaFileDirectoryByPath(testWeblog, "/test1");
         MediaFileDirectory newDirectory2 = mfMgr.createMediaFileDirectoryByPath(testWeblog, "/test2/");
         TestUtils.endSession(true);
-        
+
         testWeblog = TestUtils.getManagedWebsite(testWeblog);
 
         MediaFileDirectory newDirectory1ById = mfMgr.getMediaFileDirectory(newDirectory1.getId());
         assertEquals(newDirectory1, newDirectory1ById);
-        
+
         MediaFileDirectory newDirectory2ById = mfMgr.getMediaFileDirectory(newDirectory2.getId());
         assertEquals("test2", newDirectory2ById.getName());
 
+        // show throw error when creating directory that already exists
         try {
             mfMgr.createMediaFileDirectoryByPath(testWeblog, "test1");
-        	assertTrue(false);
-        }
-        catch (WebloggerException e) {
-        	assertTrue(true);
+            assertTrue(false);
+        } catch (WebloggerException e) {
+            assertTrue(true);
         }
 
-        try {
-            mfMgr.createMediaFileDirectoryByPath(testWeblog, "/test1/test2/test3");
-        	assertTrue(false);
-        }
-        catch (WebloggerException e) {
-        	assertTrue(true);
-        }
-        
         MediaFileDirectory newDirectory3 = mfMgr.createMediaFileDirectoryByPath(testWeblog, "/test1/test2");
         TestUtils.endSession(true);
-        
+
         testWeblog = TestUtils.getManagedWebsite(testWeblog);
         MediaFileDirectory newDirectory3ById = mfMgr.getMediaFileDirectory(newDirectory3.getId());
         assertEquals(newDirectory3, newDirectory3ById);
-        
+
         MediaFileDirectory newDirectory4 = mfMgr.createMediaFileDirectoryByPath(testWeblog, "/test1/test2/test3");
         TestUtils.endSession(true);
-        
+
         testWeblog = TestUtils.getManagedWebsite(testWeblog);
         MediaFileDirectory newDirectory4ById = mfMgr.getMediaFileDirectory(newDirectory4.getId());
         assertEquals(newDirectory4, newDirectory4ById);
 
+        // show throw error when creating directory that already exists
         try {
             mfMgr.createMediaFileDirectoryByPath(testWeblog, "/test1/test2/test3");
-        	assertTrue(false);
-        }
-        catch (WebloggerException e) {
-        	assertTrue(true);
+            assertTrue(false);
+        } catch (WebloggerException e) {
+            assertTrue(true);
         }
 
         TestUtils.endSession(true);
         TestUtils.teardownWeblog(testWeblog.getId());
         TestUtils.teardownUser(testUser.getUserName());
     }
-    
+
     /**
      * Test directory creation
      */
@@ -177,9 +167,9 @@
     public void testCreateMediaFileDirectory() throws Exception {
         User testUser = null;
         Weblog testWeblog = null;
-        
-    	// TODO: Setup code, to be moved to setUp method.
-    	System.out.println("Before setting up weblogger");
+
+        // TODO: Setup code, to be moved to setUp method.
+        System.out.println("Before setting up weblogger");
         // setup weblogger
         try {
             testUser = TestUtils.setupUser("mediaFileTestUser");
@@ -194,17 +184,23 @@
          * Real test starts here.
          */
         MediaFileManager mfMgr = WebloggerFactory.getWeblogger().getMediaFileManager();
-        
+
         testWeblog = TestUtils.getManagedWebsite(testWeblog);
-        MediaFileDirectory directory = new MediaFileDirectory(null, "root", "root d", testWeblog);
-        mfMgr.createMediaFileDirectory(directory);
-        assertEquals("/", directory.getPath());
-        assertNotNull(directory.getId() != null);
+
+        // no need to create root directory, that is done automatically now
+        MediaFileDirectory directory = mfMgr.getMediaFileRootDirectory(testWeblog);
+
+        //MediaFileDirectory directory = new MediaFileDirectory(null, "root", "root d", testWeblog);
+        //mfMgr.createMediaFileDirectory(directory);
+        //assertEquals("/", directory.getPath());
+        //assertNotNull(directory.getId() != null);
+
+
         TestUtils.endSession(true);
-        
+
         MediaFileDirectory directoryById = mfMgr.getMediaFileDirectory(directory.getId());
         assertEquals(directory, directoryById);
-        
+
         testWeblog = TestUtils.getManagedWebsite(testWeblog);
         MediaFileDirectory rootDirectory = mfMgr.getMediaFileRootDirectory(testWeblog);
         assertEquals(directory, rootDirectory);
@@ -213,30 +209,31 @@
         TestUtils.teardownWeblog(testWeblog.getId());
         TestUtils.teardownUser(testUser.getUserName());
     }
-    
-    
-    
+
     /**
      * Test getting list of all directories for a given user.
      */
     public void testGetMediaFileDirectories() throws Exception {
-        
+
         User testUser = null;
         Weblog testWeblog = null;
         testUser = TestUtils.setupUser("mediaFileTestUser2");
         testWeblog = TestUtils.setupWeblog("mediaFileTestWeblog2", testUser);
-        
+
         MediaFileManager mfMgr = WebloggerFactory.getWeblogger().getMediaFileManager();
 
-        MediaFileDirectory rootDirectory = new MediaFileDirectory(null, "root", "root d", testWeblog);
-        mfMgr.createMediaFileDirectory(rootDirectory);
+        // no need to create root directory, that is done automatically now
+        MediaFileDirectory rootDirectory = mfMgr.getMediaFileRootDirectory(testWeblog);
+
+        //MediaFileDirectory rootDirectory = new MediaFileDirectory(null, "root", "root d", testWeblog);
+        //mfMgr.createMediaFileDirectory(rootDirectory);
 
         MediaFileDirectory directory2 = new MediaFileDirectory(rootDirectory, "dir2", "directory 2", testWeblog);
         mfMgr.createMediaFileDirectory(directory2);
 
         MediaFileDirectory directory3 = new MediaFileDirectory(rootDirectory, "dir3", "directory 3", testWeblog);
         mfMgr.createMediaFileDirectory(directory3);
-        
+
         TestUtils.endSession(true);
 
         testWeblog = TestUtils.getManagedWebsite(testWeblog);
@@ -246,38 +243,42 @@
         assertTrue(containsPath(directories, "/"));
         assertTrue(containsPath(directories, "/dir2"));
         assertTrue(containsPath(directories, "/dir3"));
-        
+
 
         TestUtils.endSession(true);
         TestUtils.teardownWeblog(testWeblog.getId());
         TestUtils.teardownUser(testUser.getUserName());
     }
-    
+
     /**
      * Test utility to determine whether the given list of directories 
      * contains a directory of given path.
      * 
      */
     private boolean containsPath(Collection<MediaFileDirectory> directories, String path) {
-    	for (MediaFileDirectory directory: directories) {
-    		if (path.equals(directory.getPath())) return true;
-    	}
-    	return false;
-    	
+        for (MediaFileDirectory directory : directories) {
+            if (path.equals(directory.getPath())) {
+                return true;
+            }
+        }
+        return false;
+
     }
-    
+
     /**
      * Test utility to determine whether the list of files contains a file with given name.
      * 
      */
     private boolean containsFileWithName(Collection<MediaFile> files, String name) {
-    	for (MediaFile file: files) {
-    		if (name.equals(file.getName())) return true;
-    	}
-    	return false;
-    	
+        for (MediaFile file : files) {
+            if (name.equals(file.getName())) {
+                return true;
+            }
+        }
+        return false;
+
     }
-    
+
     /**
      * Test deletion of media file
      */
@@ -286,17 +287,20 @@
         Weblog testWeblog = null;
         testUser = TestUtils.setupUser("mediaFileTestUser4");
         testWeblog = TestUtils.setupWeblog("mediaFileTestWeblog4", testUser);
-        
+
         MediaFileManager mfMgr = WebloggerFactory.getWeblogger().getMediaFileManager();
 
-        MediaFileDirectory rootDirectory = new MediaFileDirectory(null, "root", "root d", testWeblog);
-        mfMgr.createMediaFileDirectory(rootDirectory);
+        // no need to create root directory, that is done automatically now
+        MediaFileDirectory rootDirectory = mfMgr.getMediaFileRootDirectory(testWeblog);
+
+        //MediaFileDirectory rootDirectory = new MediaFileDirectory(null, "root", "root d", testWeblog);
+        //mfMgr.createMediaFileDirectory(rootDirectory);
 
         TestUtils.endSession(true);
 
         testWeblog = TestUtils.getManagedWebsite(testWeblog);
         rootDirectory = mfMgr.getMediaFileDirectory(rootDirectory.getId());
-        
+
         MediaFile mediaFile = new MediaFile();
         mediaFile.setName("test4.jpg");
         mediaFile.setDescription("This is a test image 4");
@@ -304,35 +308,36 @@
         mediaFile.setSharedForGallery(false);
         mediaFile.setLength(3000);
         mediaFile.setDirectory(rootDirectory);
+        mediaFile.setWeblog(testWeblog);
         mediaFile.setContentType("image/jpeg");
         mediaFile.setInputStream(getClass().getResourceAsStream(TEST_IMAGE));
-        
+
         MediaFileTag tag1 = new MediaFileTag("tst4work", mediaFile);
         MediaFileTag tag2 = new MediaFileTag("tst4home", mediaFile);
         Set<MediaFileTag> tags = new HashSet<MediaFileTag>();
         tags.add(tag1);
         tags.add(tag2);
         mediaFile.setTags(tags);
-        
+
         mfMgr.createMediaFile(testWeblog, mediaFile);
         String id = mediaFile.getId();
         TestUtils.endSession(true);
         assertNotNull(id);
         assertNotNull(id.length() > 0);
-        
+
         testWeblog = TestUtils.getManagedWebsite(testWeblog);
         MediaFile mediaFile1 = mfMgr.getMediaFile(id);
-        
+
         assertEquals("test4.jpg", mediaFile1.getName());
         assertNotNull(mediaFile1.getTags());
         assertEquals(2, mediaFile1.getTags().size());
-        
+
         mfMgr.removeMediaFile(testWeblog, mediaFile1);
         TestUtils.endSession(true);
-        
+
         MediaFile mediaFile2 = mfMgr.getMediaFile(id);
         assertNull(mediaFile2);
-    	
+
 
         TestUtils.endSession(true);
         TestUtils.teardownWeblog(testWeblog.getId());
@@ -343,22 +348,25 @@
      * Test creation of media file.
      */
     public void testCreateMediaFile() throws Exception {
-        
+
         User testUser = null;
         Weblog testWeblog = null;
         testUser = TestUtils.setupUser("mediaFileTestUser3");
         testWeblog = TestUtils.setupWeblog("mediaFileTestWeblog3", testUser);
-        
+
         MediaFileManager mfMgr = WebloggerFactory.getWeblogger().getMediaFileManager();
 
-        MediaFileDirectory rootDirectory = new MediaFileDirectory(null, "root", "root d", testWeblog);
-        mfMgr.createMediaFileDirectory(rootDirectory);
+        // no need to create root directory, that is done automatically now
+        MediaFileDirectory rootDirectory = mfMgr.getMediaFileRootDirectory(testWeblog);
+
+        //MediaFileDirectory rootDirectory = new MediaFileDirectory(null, "root", "root d", testWeblog);
+        //mfMgr.createMediaFileDirectory(rootDirectory);
 
         TestUtils.endSession(true);
 
         testWeblog = TestUtils.getManagedWebsite(testWeblog);
         rootDirectory = mfMgr.getMediaFileDirectory(rootDirectory.getId());
-        
+
         MediaFile mediaFile = new MediaFile();
         mediaFile.setName("test.jpg");
         mediaFile.setDescription("This is a test image");
@@ -366,21 +374,22 @@
         mediaFile.setSharedForGallery(true);
         mediaFile.setLength(2000);
         mediaFile.setDirectory(rootDirectory);
+        mediaFile.setWeblog(testWeblog);
         mediaFile.setInputStream(getClass().getResourceAsStream(TEST_IMAGE));
         mediaFile.setContentType("image/jpeg");
-        
+
         MediaFileTag tag1 = new MediaFileTag("work", mediaFile);
         MediaFileTag tag2 = new MediaFileTag("home", mediaFile);
         Set<MediaFileTag> tags = new HashSet<MediaFileTag>();
         tags.add(tag1);
         tags.add(tag2);
         mediaFile.setTags(tags);
-        
+
         mfMgr.createMediaFile(testWeblog, mediaFile);
         TestUtils.endSession(true);
         assertNotNull(mediaFile.getId());
         assertNotNull(mediaFile.getId().length() > 0);
-        
+
         testWeblog = TestUtils.getManagedWebsite(testWeblog);
         MediaFile mediaFile1 = mfMgr.getMediaFile(mediaFile.getId());
         assertEquals("test.jpg", mediaFile1.getName());
@@ -398,22 +407,25 @@
      * Test searching media file.
      */
     public void testSearchMediaFile() throws Exception {
-        
+
         User testUser = null;
         Weblog testWeblog = null;
         testUser = TestUtils.setupUser("mediaFileTestUser7");
         testWeblog = TestUtils.setupWeblog("mediaFileTestWeblog7", testUser);
-        
+
         MediaFileManager mfMgr = WebloggerFactory.getWeblogger().getMediaFileManager();
 
-        MediaFileDirectory rootDirectory = new MediaFileDirectory(null, "root", "root d", testWeblog);
-        mfMgr.createMediaFileDirectory(rootDirectory);
+        // no need to create root directory, that is done automatically now
+        MediaFileDirectory rootDirectory = mfMgr.getMediaFileRootDirectory(testWeblog);
+
+        //MediaFileDirectory rootDirectory = new MediaFileDirectory(null, "root", "root d", testWeblog);
+        //mfMgr.createMediaFileDirectory(rootDirectory);
 
         TestUtils.endSession(true);
 
         testWeblog = TestUtils.getManagedWebsite(testWeblog);
         rootDirectory = mfMgr.getMediaFileDirectory(rootDirectory.getId());
-        
+
         MediaFile mediaFile = new MediaFile();
         mediaFile.setName("test_work.jpg");
         mediaFile.setDescription("This is a test image");
@@ -421,19 +433,20 @@
         mediaFile.setSharedForGallery(true);
         mediaFile.setLength(2000);
         mediaFile.setDirectory(rootDirectory);
+        mediaFile.setWeblog(testWeblog);
         mediaFile.setInputStream(getClass().getResourceAsStream(TEST_IMAGE));
         mediaFile.setContentType("image/jpeg");
-        
+
         MediaFileTag tag1 = new MediaFileTag("work", mediaFile);
         Set<MediaFileTag> tags = new HashSet<MediaFileTag>();
         tags.add(tag1);
         mediaFile.setTags(tags);
-        
+
         mfMgr.createMediaFile(testWeblog, mediaFile);
         TestUtils.endSession(true);
         assertNotNull(mediaFile.getId());
         assertNotNull(mediaFile.getId().length() > 0);
-        
+
         testWeblog = TestUtils.getManagedWebsite(testWeblog);
         MediaFile mediaFile1 = new MediaFile();
         mediaFile1 = new MediaFile();
@@ -443,19 +456,20 @@
         mediaFile1.setSharedForGallery(true);
         mediaFile1.setLength(3000);
         mediaFile1.setDirectory(rootDirectory);
+        mediaFile1.setWeblog(testWeblog);
         mediaFile1.setInputStream(getClass().getResourceAsStream(TEST_IMAGE));
         mediaFile1.setContentType("image/jpeg");
-        
+
         MediaFileTag tag2 = new MediaFileTag("home", mediaFile1);
         tags = new HashSet<MediaFileTag>();
         tags.add(tag2);
         mediaFile1.setTags(tags);
-        
+
         mfMgr.createMediaFile(testWeblog, mediaFile1);
         TestUtils.endSession(true);
         assertNotNull(mediaFile1.getId());
         assertNotNull(mediaFile1.getId().length() > 0);
-        
+
         testWeblog = TestUtils.getManagedWebsite(testWeblog);
         MediaFile mediaFile2 = new MediaFile();
         mediaFile2 = new MediaFile();
@@ -464,15 +478,16 @@
         mediaFile2.setCopyrightText("test pers copyright text");
         mediaFile2.setSharedForGallery(true);
         mediaFile2.setLength(4000);
+        mediaFile2.setWeblog(testWeblog);
         mediaFile2.setDirectory(rootDirectory);
         mediaFile2.setInputStream(getClass().getResourceAsStream(TEST_IMAGE));
         mediaFile2.setContentType("image/jpeg");
-        
+
         MediaFileTag tag3 = new MediaFileTag("home", mediaFile2);
         tags = new HashSet<MediaFileTag>();
         tags.add(tag3);
         mediaFile2.setTags(tags);
-        
+
         mfMgr.createMediaFile(testWeblog, mediaFile2);
         TestUtils.endSession(true);
         assertNotNull(mediaFile2.getId());
@@ -481,33 +496,33 @@
         testWeblog = TestUtils.getManagedWebsite(testWeblog);
 
         List<MediaFile> searchResults;
-        
+
         MediaFileFilter filter1 = new MediaFileFilter();
         filter1.setName("mytest.jpg");
         searchResults = mfMgr.searchMediaFiles(testWeblog, filter1);
         assertTrue(searchResults.isEmpty());
-        
+
         MediaFileFilter filter2 = new MediaFileFilter();
         filter2.setName("test_home.jpg");
         searchResults = mfMgr.searchMediaFiles(testWeblog, filter2);
         assertFalse(searchResults.isEmpty());
-        assertEquals(mediaFile1.getId(), ((MediaFile)searchResults.get(0)).getId());
-        assertNotNull(((MediaFile)searchResults.get(0)).getDirectory());
-        assertEquals("/", ((MediaFile)searchResults.get(0)).getDirectory().getPath());
+        assertEquals(mediaFile1.getId(), ((MediaFile) searchResults.get(0)).getId());
+        assertNotNull(((MediaFile) searchResults.get(0)).getDirectory());
+        assertEquals("/", ((MediaFile) searchResults.get(0)).getDirectory().getPath());
 
         MediaFileFilter filter3 = new MediaFileFilter();
         filter3.setName("test_work.jpg");
         searchResults = mfMgr.searchMediaFiles(testWeblog, filter3);
         assertFalse(searchResults.isEmpty());
-        assertEquals(mediaFile.getId(), ((MediaFile)searchResults.get(0)).getId());
+        assertEquals(mediaFile.getId(), ((MediaFile) searchResults.get(0)).getId());
 
         MediaFileFilter filter4 = new MediaFileFilter();
         filter4.setTags(Arrays.asList("work"));
         searchResults = mfMgr.searchMediaFiles(testWeblog, filter4);
         assertFalse(searchResults.isEmpty());
         assertEquals(1, searchResults.size());
-        assertEquals("test_work.jpg", ((MediaFile)searchResults.get(0)).getName());
-        
+        assertEquals("test_work.jpg", ((MediaFile) searchResults.get(0)).getName());
+
         MediaFileFilter filter5 = new MediaFileFilter();
         filter5.setTags(Arrays.asList("home"));
         searchResults = mfMgr.searchMediaFiles(testWeblog, filter5);
@@ -520,7 +535,7 @@
         searchResults = mfMgr.searchMediaFiles(testWeblog, filter6);
         assertFalse(searchResults.isEmpty());
         assertEquals(1, searchResults.size());
-        assertEquals("test_work.jpg", ((MediaFile)searchResults.get(0)).getName());
+        assertEquals("test_work.jpg", ((MediaFile) searchResults.get(0)).getName());
 
         MediaFileFilter filter7 = new MediaFileFilter();
         filter7.setSize(3000);
@@ -528,7 +543,7 @@
         searchResults = mfMgr.searchMediaFiles(testWeblog, filter7);
         assertFalse(searchResults.isEmpty());
         assertEquals(1, searchResults.size());
-        assertEquals("test_home.jpg", ((MediaFile)searchResults.get(0)).getName());
+        assertEquals("test_home.jpg", ((MediaFile) searchResults.get(0)).getName());
 
         MediaFileFilter filter8 = new MediaFileFilter();
         filter8.setSize(3000);
@@ -536,7 +551,7 @@
         searchResults = mfMgr.searchMediaFiles(testWeblog, filter8);
         assertFalse(searchResults.isEmpty());
         assertEquals(1, searchResults.size());
-        assertEquals("test_pers.jpg", ((MediaFile)searchResults.get(0)).getName());
+        assertEquals("test_pers.jpg", ((MediaFile) searchResults.get(0)).getName());
 
         MediaFileFilter filter9 = new MediaFileFilter();
         filter9.setSize(3000);
@@ -578,18 +593,21 @@
         Weblog testWeblog = null;
         testUser = TestUtils.setupUser("mediaFileTestUser9");
         testWeblog = TestUtils.setupWeblog("mediaFileTestWeblog9", testUser);
-    	
+
         MediaFileManager mfMgr = WebloggerFactory.getWeblogger().getMediaFileManager();
 
-        MediaFileDirectory rootDirectory = new MediaFileDirectory(null, "root", "root d", testWeblog);
-        mfMgr.createMediaFileDirectory(rootDirectory);
+        // no need to create root directory, that is done automatically now
+        MediaFileDirectory rootDirectory = mfMgr.getMediaFileRootDirectory(testWeblog);
+
+        //MediaFileDirectory rootDirectory = new MediaFileDirectory(null, "root", "root d", testWeblog);
+        //mfMgr.createMediaFileDirectory(rootDirectory);
 
         TestUtils.endSession(true);
 
         testWeblog = TestUtils.getManagedWebsite(testWeblog);
         rootDirectory = mfMgr.getMediaFileDirectory(rootDirectory.getId());
 
-        for (int i = 0; i < 15; i ++) {
+        for (int i = 0; i < 15; i++) {
             MediaFile mediaFile = new MediaFile();
             mediaFile.setName("test_file<index>.jpg".replace("<index>", i + ""));
             mediaFile.setDescription("This is a test image");
@@ -597,6 +615,7 @@
             mediaFile.setSharedForGallery(true);
             mediaFile.setLength(2000);
             mediaFile.setDirectory(rootDirectory);
+            mediaFile.setWeblog(testWeblog);
             mediaFile.setInputStream(getClass().getResourceAsStream(TEST_IMAGE));
             mediaFile.setContentType("image/jpeg");
             mfMgr.createMediaFile(testWeblog, mediaFile);
@@ -605,14 +624,14 @@
         }
         TestUtils.endSession(true);
         testWeblog = TestUtils.getManagedWebsite(testWeblog);
-        
+
         MediaFileFilter filter1 = new MediaFileFilter();
         filter1.setSize(1000);
         filter1.setSizeFilterType(SizeFilterType.GT);
         List<MediaFile> searchResults1 = mfMgr.searchMediaFiles(testWeblog, filter1);
         assertFalse(searchResults1.isEmpty());
         assertEquals(15, searchResults1.size());
-        
+
         MediaFileFilter filter2 = new MediaFileFilter();
         filter2.setSize(1000);
         filter2.setSizeFilterType(SizeFilterType.GT);
@@ -647,7 +666,7 @@
         TestUtils.teardownWeblog(testWeblog.getId());
         TestUtils.teardownUser(testUser.getUserName());
     }
-    
+
     /**
      * Test searching media file with paging logic.
      */
@@ -656,18 +675,21 @@
         Weblog testWeblog = null;
         testUser = TestUtils.setupUser("mediaFileTestUser10");
         testWeblog = TestUtils.setupWeblog("mediaFileTestWeblog10", testUser);
-    	
+
         MediaFileManager mfMgr = WebloggerFactory.getWeblogger().getMediaFileManager();
 
-        MediaFileDirectory rootDirectory = new MediaFileDirectory(null, "root", "root d", testWeblog);
-        mfMgr.createMediaFileDirectory(rootDirectory);
+        // no need to create root directory, that is done automatically now
+        MediaFileDirectory rootDirectory = mfMgr.getMediaFileRootDirectory(testWeblog);
+
+        //MediaFileDirectory rootDirectory = new MediaFileDirectory(null, "root", "root d", testWeblog);
+        //mfMgr.createMediaFileDirectory(rootDirectory);
 
         TestUtils.endSession(true);
 
         testWeblog = TestUtils.getManagedWebsite(testWeblog);
         rootDirectory = mfMgr.getMediaFileDirectory(rootDirectory.getId());
         String[] contentTypes = {"image/gif", "image/jpeg", "image/bmp"};
-        for (int i = 0; i < 3; i ++) {
+        for (int i = 0; i < 3; i++) {
             MediaFile mediaFile = new MediaFile();
             mediaFile.setName("test_file<index>.jpg".replace("<index>", i + ""));
             mediaFile.setDescription("This is a test image");
@@ -675,6 +697,7 @@
             mediaFile.setSharedForGallery(true);
             mediaFile.setLength(2000);
             mediaFile.setDirectory(rootDirectory);
+            mediaFile.setWeblog(testWeblog);
             mediaFile.setInputStream(getClass().getResourceAsStream(TEST_IMAGE));
             mediaFile.setContentType(contentTypes[i]);
             mfMgr.createMediaFile(testWeblog, mediaFile);
@@ -683,7 +706,7 @@
         }
         TestUtils.endSession(true);
         testWeblog = TestUtils.getManagedWebsite(testWeblog);
-        
+
         MediaFileFilter filter1 = new MediaFileFilter();
         filter1.setSize(1000);
         filter1.setSizeFilterType(SizeFilterType.GT);
@@ -721,7 +744,7 @@
         TestUtils.teardownWeblog(testWeblog.getId());
         TestUtils.teardownUser(testUser.getUserName());
     }
-    
+
     /**
      * Test media file update
      */
@@ -730,17 +753,20 @@
         Weblog testWeblog = null;
         testUser = TestUtils.setupUser("mediaFileTestUser5");
         testWeblog = TestUtils.setupWeblog("mediaFileTestWeblog5", testUser);
-        
+
         MediaFileManager mfMgr = WebloggerFactory.getWeblogger().getMediaFileManager();
 
-        MediaFileDirectory rootDirectory = new MediaFileDirectory(null, "root", "root d", testWeblog);
-        mfMgr.createMediaFileDirectory(rootDirectory);
+        // no need to create root directory, that is done automatically now
+        MediaFileDirectory rootDirectory = mfMgr.getMediaFileRootDirectory(testWeblog);
+
+        //MediaFileDirectory rootDirectory = new MediaFileDirectory(null, "root", "root d", testWeblog);
+        //mfMgr.createMediaFileDirectory(rootDirectory);
 
         TestUtils.endSession(true);
 
         testWeblog = TestUtils.getManagedWebsite(testWeblog);
         rootDirectory = mfMgr.getMediaFileDirectory(rootDirectory.getId());
-        
+
         MediaFile mediaFile = new MediaFile();
         mediaFile.setName("test5.jpg");
         mediaFile.setDescription("This is a test image 5");
@@ -748,25 +774,27 @@
         mediaFile.setSharedForGallery(false);
         mediaFile.setLength(3000);
         mediaFile.setDirectory(rootDirectory);
+        mediaFile.setWeblog(testWeblog);
         mediaFile.setInputStream(getClass().getResourceAsStream(TEST_IMAGE));
         mediaFile.setContentType("image/jpeg");
-        
-        
+
+
         MediaFileTag tag1 = new MediaFileTag("tst5work", mediaFile);
         MediaFileTag tag2 = new MediaFileTag("tst5home", mediaFile);
         Set<MediaFileTag> tags = new HashSet<MediaFileTag>();
         tags.add(tag1);
         tags.add(tag2);
         mediaFile.setTags(tags);
-        
+
         mfMgr.createMediaFile(testWeblog, mediaFile);
         String id = mediaFile.getId();
         TestUtils.endSession(true);
         assertNotNull(id);
         assertNotNull(id.length() > 0);
-        
+
         testWeblog = TestUtils.getManagedWebsite(testWeblog);
         MediaFile mediaFile1 = mfMgr.getMediaFile(id);
+        mediaFile1.setWeblog(testWeblog);
         mediaFile1.setName("updated.gif");
         mediaFile1.setDescription("updated desc");
         mediaFile1.setCopyrightText("updated copyright");
@@ -774,7 +802,7 @@
         mediaFile1.setSharedForGallery(true);
         mfMgr.updateMediaFile(testWeblog, mediaFile1);
         TestUtils.endSession(true);
-        
+
         MediaFile mediaFile2 = mfMgr.getMediaFile(id);
         assertEquals("updated.gif", mediaFile2.getName());
         assertEquals("updated desc", mediaFile2.getDescription());
@@ -797,11 +825,14 @@
         Weblog testWeblog = null;
         testUser = TestUtils.setupUser("mediaFileTestUser6");
         testWeblog = TestUtils.setupWeblog("mediaFileTestWeblog6", testUser);
-        
+
         MediaFileManager mfMgr = WebloggerFactory.getWeblogger().getMediaFileManager();
 
-        MediaFileDirectory rootDirectory = new MediaFileDirectory(null, "root", "root d", testWeblog);
-        mfMgr.createMediaFileDirectory(rootDirectory);
+        // no need to create root directory, that is done automatically now
+        MediaFileDirectory rootDirectory = mfMgr.getMediaFileRootDirectory(testWeblog);
+
+        //MediaFileDirectory rootDirectory = new MediaFileDirectory(null, "root", "root d", testWeblog);
+        //mfMgr.createMediaFileDirectory(rootDirectory);
 
         MediaFileDirectory directory1 = new MediaFileDirectory(rootDirectory, "dir1", "directory 1", testWeblog);
         mfMgr.createMediaFileDirectory(directory1);
@@ -811,10 +842,11 @@
 
         MediaFileDirectory directory3 = new MediaFileDirectory(rootDirectory, "dir3", "directory 3", testWeblog);
         mfMgr.createMediaFileDirectory(directory3);
-        
-        
+
+
         MediaFile mediaFile = new MediaFile();
         mediaFile.setDirectory(rootDirectory);
+        mediaFile.setWeblog(testWeblog);
         mediaFile.setName("test6_1.jpg");
         mediaFile.setDescription("This is a test image 6.1");
         mediaFile.setCopyrightText("test 6.1 copyright text");
@@ -826,6 +858,7 @@
 
         MediaFile mediaFile2 = new MediaFile();
         mediaFile2.setDirectory(rootDirectory);
+        mediaFile2.setWeblog(testWeblog);
         mediaFile2.setName("test6_2.jpg");
         mediaFile2.setDescription("This is a test image 6.2");
         mediaFile2.setCopyrightText("test 6.2 copyright text");
@@ -834,29 +867,29 @@
         mediaFile2.setInputStream(getClass().getResourceAsStream(TEST_IMAGE));
         mediaFile2.setContentType("image/jpeg");
         mfMgr.createMediaFile(testWeblog, mediaFile2);
-        
+
         TestUtils.endSession(true);
 
         testWeblog = TestUtils.getManagedWebsite(testWeblog);
         rootDirectory = mfMgr.getMediaFileDirectory(rootDirectory.getId());
-        
+
         Set<MediaFileDirectory> childDirectories = rootDirectory.getChildDirectories();
         assertEquals(3, childDirectories.size());
         assertTrue(containsPath(childDirectories, "/dir1"));
         assertTrue(containsPath(childDirectories, "/dir2"));
         assertTrue(containsPath(childDirectories, "/dir3"));
-        
+
         Set<MediaFile> mediaFiles = rootDirectory.getMediaFiles();
         assertEquals(2, mediaFiles.size());
         assertTrue(containsFileWithName(mediaFiles, "test6_1.jpg"));
         assertTrue(containsFileWithName(mediaFiles, "test6_2.jpg"));
         TestUtils.endSession(true);
-        
+
         testWeblog = TestUtils.getManagedWebsite(testWeblog);
         rootDirectory = mfMgr.getMediaFileDirectory(rootDirectory.getId());
         assertTrue(rootDirectory.hasMediaFile("test6_1.jpg"));
         assertTrue(rootDirectory.hasMediaFile("test6_2.jpg"));
-        
+
 
         TestUtils.endSession(true);
         TestUtils.teardownWeblog(testWeblog.getId());
@@ -871,10 +904,13 @@
         Weblog testWeblog = null;
         testUser = TestUtils.setupUser("mediaFileTestUser11");
         testWeblog = TestUtils.setupWeblog("mediaFileTestUser11", testUser);
-        
+
         MediaFileManager mfMgr = WebloggerFactory.getWeblogger().getMediaFileManager();
 
-        MediaFileDirectory rootDirectory = new MediaFileDirectory(null, "root", "root d", testWeblog);
+        // no need to create root directory, that is done automatically now
+        MediaFileDirectory rootDirectory = mfMgr.getMediaFileRootDirectory(testWeblog);
+
+        //MediaFileDirectory rootDirectory = new MediaFileDirectory(null, "root", "root d", testWeblog);
         mfMgr.createMediaFileDirectory(rootDirectory);
 
         MediaFileDirectory directory1 = new MediaFileDirectory(rootDirectory, "dir1", "directory 1", testWeblog);
@@ -886,10 +922,11 @@
 
         MediaFileDirectory directory3 = new MediaFileDirectory(rootDirectory, "dir3", "directory 3", testWeblog);
         mfMgr.createMediaFileDirectory(directory3);
-        
-        
+
+
         MediaFile mediaFile = new MediaFile();
         mediaFile.setDirectory(rootDirectory);
+        mediaFile.setWeblog(testWeblog);
         mediaFile.setName("test7_1.jpg");
         mediaFile.setDescription("This is a test image 7.1");
         mediaFile.setCopyrightText("test 7.1 copyright text");
@@ -901,6 +938,7 @@
 
         MediaFile mediaFile2 = new MediaFile();
         mediaFile2.setDirectory(rootDirectory);
+        mediaFile2.setWeblog(testWeblog);
         mediaFile2.setName("test7_2.jpg");
         mediaFile2.setDescription("This is a test image 7.2");
         mediaFile2.setCopyrightText("test 7.2 copyright text");
@@ -909,24 +947,24 @@
         mediaFile2.setInputStream(getClass().getResourceAsStream(TEST_IMAGE));
         mediaFile2.setContentType("image/jpeg");
         mfMgr.createMediaFile(testWeblog, mediaFile2);
-        
+
         TestUtils.endSession(true);
 
         testWeblog = TestUtils.getManagedWebsite(testWeblog);
         rootDirectory = mfMgr.getMediaFileDirectory(rootDirectory.getId());
-        
+
         Set<MediaFile> mediaFiles = rootDirectory.getMediaFiles();
         assertEquals(2, mediaFiles.size());
         assertTrue(containsFileWithName(mediaFiles, "test7_1.jpg"));
         assertTrue(containsFileWithName(mediaFiles, "test7_2.jpg"));
-        
+
         MediaFileDirectory targetDirectory = mfMgr.getMediaFileDirectory(dir1Id);
         mfMgr.moveMediaFiles(mediaFiles, targetDirectory);
         TestUtils.endSession(true);
-        
+
         rootDirectory = mfMgr.getMediaFileDirectory(rootDirectory.getId());
         targetDirectory = mfMgr.getMediaFileDirectory(dir1Id);
-        
+
         mediaFiles = targetDirectory.getMediaFiles();
         assertEquals(2, mediaFiles.size());
         assertTrue(containsFileWithName(mediaFiles, "test7_1.jpg"));
@@ -934,7 +972,7 @@
 
         mediaFiles = rootDirectory.getMediaFiles();
         assertEquals(0, mediaFiles.size());
-        
+
 
         TestUtils.endSession(true);
         TestUtils.teardownWeblog(testWeblog.getId());
@@ -960,24 +998,24 @@
             testWeblog2 = TestUtils.setupWeblog("testblog2", testUser);
 
             MediaFileManager mgr = WebloggerFactory.getWeblogger().getMediaFileManager();
-            JPAMediaFileManagerImpl mmgr = (JPAMediaFileManagerImpl)mgr;
+            JPAMediaFileManagerImpl mmgr = (JPAMediaFileManagerImpl) mgr;
 
-            assertTrue("Upgrade required",mmgr.isFileStorageUpgradeRequired());
+            assertTrue("Upgrade required", mmgr.isFileStorageUpgradeRequired());
 
             mmgr.upgradeFileStorage();
             TestUtils.endSession(true);
 
-            assertFalse("Upgrade required",mmgr.isFileStorageUpgradeRequired());
+            assertFalse("Upgrade required", mmgr.isFileStorageUpgradeRequired());
 
             // now, let's check to see if migration was sucessful
 
             MediaFileDirectory root1 = mgr.getMediaFileRootDirectory(testWeblog1);
             assertNotNull("testblog1's mediafile dir exists", root1);
             assertNotNull(mgr.getMediaFileByPath(testWeblog1, "/sub1/hawk.jpg"));
-            assertNotNull(mgr.getMediaFileByPath(testWeblog1, "/sub2/sub2/nasa.jpg"));
+            assertNotNull(mgr.getMediaFileByPath(testWeblog1, "/sub1/sub2/nasa.jpg"));
             assertNotNull(mgr.getMediaFileByPath(testWeblog1, "/roller50-prop.png"));
 
-            assertNotNull(mgr.getMediaFileByOriginalPath(testWeblog2, "/sub1/hawk.jpg"));
+            assertNotNull(mgr.getMediaFileByOriginalPath(testWeblog1, "/sub1/hawk.jpg"));
 
             MediaFileDirectory root2 = mgr.getMediaFileRootDirectory(testWeblog2);
             assertNotNull("testblog2's mediafile dir exists", root2);
@@ -987,8 +1025,7 @@
 
         } finally {
 
-            File statusFile = new File(WebloggerConfig.getProperty("uploads.dir")
-                + File.separator + JPAMediaFileManagerImpl.MIGRATIION_STATUS_FILENAME);
+            File statusFile = new File(WebloggerConfig.getProperty("uploads.dir") + File.separator + JPAMediaFileManagerImpl.MIGRATIION_STATUS_FILENAME);
             statusFile.delete();
 
             // reset dir max to old value

Modified: roller/trunk/apps/weblogger/test/java/org/apache/roller/weblogger/webservices/RollerAtomPubServerTest.java
URL: http://svn.apache.org/viewvc/roller/trunk/apps/weblogger/test/java/org/apache/roller/weblogger/webservices/RollerAtomPubServerTest.java?rev=812165&r1=812164&r2=812165&view=diff
==============================================================================
--- roller/trunk/apps/weblogger/test/java/org/apache/roller/weblogger/webservices/RollerAtomPubServerTest.java (original)
+++ roller/trunk/apps/weblogger/test/java/org/apache/roller/weblogger/webservices/RollerAtomPubServerTest.java Mon Sep  7 14:48:19 2009
@@ -261,6 +261,7 @@
         mediaFile.setDescription(desc);
         mediaFile.setSharedForGallery(false);
         mediaFile.setDirectory(parent);
+        mediaFile.setWeblog(weblog);
         mediaFile.setContentType(contentType);
         mediaFile.setInputStream(is);
         WebloggerFactory.getWeblogger().getMediaFileManager().createMediaFile(weblog, mediaFile);



Mime
View raw message