roller-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gma...@apache.org
Subject svn commit: r1598186 - in /roller/trunk/app/src: main/java/org/apache/roller/weblogger/business/ main/java/org/apache/roller/weblogger/business/jpa/ main/java/org/apache/roller/weblogger/business/themes/ main/java/org/apache/roller/weblogger/pojos/ mai...
Date Thu, 29 May 2014 00:45:21 GMT
Author: gmazza
Date: Thu May 29 00:45:20 2014
New Revision: 1598186

URL: http://svn.apache.org/r1598186
Log:
ROL-2005 Removed parentid, childdirectories from MediaFileDirectory; folders are now all top-level.

Modified:
    roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/MediaFileManager.java
    roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/jpa/JPAMediaFileManagerImpl.java
    roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/themes/ThemeManagerImpl.java
    roller/trunk/app/src/main/java/org/apache/roller/weblogger/pojos/MediaFileDirectory.java
    roller/trunk/app/src/main/java/org/apache/roller/weblogger/pojos/Weblog.java
    roller/trunk/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/MediaFileBase.java
    roller/trunk/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/MediaFileImageChooser.java
    roller/trunk/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/MediaFileView.java
    roller/trunk/app/src/main/resources/ApplicationResources.properties
    roller/trunk/app/src/main/resources/org/apache/roller/weblogger/pojos/MediaFileDirectory.orm.xml
    roller/trunk/app/src/main/resources/org/apache/roller/weblogger/pojos/Weblog.orm.xml
    roller/trunk/app/src/main/resources/sql/500-to-510-migration.vm
    roller/trunk/app/src/main/resources/sql/createdb.vm
    roller/trunk/app/src/main/webapp/WEB-INF/jsps/editor/MediaFileView.jsp
    roller/trunk/app/src/test/java/org/apache/roller/weblogger/business/MediaFileTest.java

Modified: roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/MediaFileManager.java
URL: http://svn.apache.org/viewvc/roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/MediaFileManager.java?rev=1598186&r1=1598185&r2=1598186&view=diff
==============================================================================
--- roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/MediaFileManager.java
(original)
+++ roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/MediaFileManager.java
Thu May 29 00:45:20 2014
@@ -94,22 +94,15 @@ public interface MediaFileManager {
             throws WebloggerException;
 
     /**
-     * Create a media file directory with the given name
-     */
-    MediaFileDirectory createMediaFileDirectory(
-            MediaFileDirectory parentDirectory, String newDirName)
-            throws WebloggerException;
-
-    /**
      * Create a media file directory
      */
     void createMediaFileDirectory(MediaFileDirectory directory)
             throws WebloggerException;
 
     /**
-     * Create a media file directory given its path
+     * Create a media file directory with a given name.
      */
-    MediaFileDirectory createMediaFileDirectoryByName(Weblog weblog,
+    MediaFileDirectory createMediaFileDirectory(Weblog weblog,
             String name) throws WebloggerException;
 
     /**

Modified: roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/jpa/JPAMediaFileManagerImpl.java
URL: http://svn.apache.org/viewvc/roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/jpa/JPAMediaFileManagerImpl.java?rev=1598186&r1=1598185&r2=1598186&view=diff
==============================================================================
--- roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/jpa/JPAMediaFileManagerImpl.java
(original)
+++ roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/jpa/JPAMediaFileManagerImpl.java
Thu May 29 00:45:20 2014
@@ -143,30 +143,7 @@ public class JPAMediaFileManagerImpl imp
 
     /**
      * {@inheritDoc}
-     */
-    public MediaFileDirectory createMediaFileDirectory(
-            MediaFileDirectory parentDirectory, String newDirName)
-            throws WebloggerException {
-
-        if (parentDirectory.hasDirectory(newDirName)) {
-            throw new WebloggerException("Directory exists");
-        }
-
-        MediaFileDirectory newDirectory = parentDirectory
-                .createNewDirectory(newDirName);
-
-        // update weblog last modified date. date updated by saveWeblog()
-        roller.getWeblogManager().saveWeblog(newDirectory.getWeblog());
-
-        // Refresh associated parent for changes
-        roller.flush();
-        strategy.refresh(parentDirectory);
-
-        return newDirectory;
-    }
-
-    /**
-     * {@inheritDoc}
+     // TODO: Remove this method?
      */
     public void createMediaFileDirectory(MediaFileDirectory directory)
             throws WebloggerException {
@@ -176,77 +153,28 @@ public class JPAMediaFileManagerImpl imp
         roller.getWeblogManager().saveWeblog(directory.getWeblog());
 
         // Refresh associated parent for changes
-        strategy.refresh(directory.getParent());
+        // strategy.refresh(directory.getParent());
     }
 
     /**
      * {@inheritDoc}
      */
-    public MediaFileDirectory createMediaFileDirectoryByName(Weblog weblog,
+    public MediaFileDirectory createMediaFileDirectory(Weblog weblog,
             String requestedName) throws WebloggerException {
 
-        String path = requestedName;
-        log.debug("Creating dir: " + path);
-
-        if (path.startsWith("/")) {
-            path = path.substring(1);
-        }
-
-        if (path.endsWith("/")) {
-            path = path.substring(0, path.length() - 1);
-        }
-
-        if (path.equals("") || path.equals("default")) {
+        if (requestedName.equals("") || requestedName.equals("default")) {
             // Default cannot be created using this method.
             // Use createDefaultMediaFileDirectory instead
             throw new WebloggerException("Invalid name!");
         }
 
-        int lastPathIndex = path.lastIndexOf('/');
-
         MediaFileDirectory newDirectory;
-        if (lastPathIndex == -1) {
-
-            // Directory needs to be created under root
-            MediaFileDirectory root = getDefaultMediaFileDirectory(weblog);
-
-            if (root.hasDirectory(path)) {
-                throw new WebloggerException("Directory exists");
-            } else {
-                log.debug("    Created dir under ROOT");
-                newDirectory = root.createNewDirectory(path);
-            }
 
+        if (weblog.hasMediaFileDirectory(requestedName)) {
+            throw new WebloggerException("Directory exists");
         } else {
-
-            boolean created = false;
-
-            MediaFileDirectory base = getDefaultMediaFileDirectory(weblog);
-            String token;
-            String pathpart = "";
-            StringTokenizer toker = new StringTokenizer(path, "/");
-            while (toker.hasMoreTokens()) {
-                token = toker.nextToken();
-                if (!pathpart.endsWith("/")) {
-                    pathpart += "/" + token;
-                } else {
-                    pathpart += token;
-                }
-                MediaFileDirectory possibleBase = getMediaFileDirectoryByName(
-                        weblog, pathpart);
-                if (possibleBase == null) {
-                    base = base.createNewDirectory(token);
-                    log.debug("   Created new directory: " + base.getName());
-                    created = true;
-                    roller.flush();
-                } else {
-                    base = possibleBase;
-                }
-            }
-            if (!created || !requestedName.equals(base.getName())) {
-                throw new WebloggerException("ERROR directory not created");
-            }
-            newDirectory = base;
+            newDirectory = new MediaFileDirectory(weblog, requestedName, null);
+            log.debug("Created new Directory " + requestedName);
         }
 
         // update weblog last modified date. date updated by saveWeblog()
@@ -260,8 +188,8 @@ public class JPAMediaFileManagerImpl imp
      */
     public MediaFileDirectory createDefaultMediaFileDirectory(Weblog weblog)
             throws WebloggerException {
-        MediaFileDirectory defaultDirectory = new MediaFileDirectory(null, "default",
-                "default directory", weblog);
+        MediaFileDirectory defaultDirectory = new MediaFileDirectory(weblog, "default",
+                "default directory");
         createMediaFileDirectory(defaultDirectory);
         return defaultDirectory;
     }
@@ -508,14 +436,7 @@ public class JPAMediaFileManagerImpl imp
      */
     public MediaFileDirectory getDefaultMediaFileDirectory(Weblog weblog)
             throws WebloggerException {
-        Query q = this.strategy
-                .getNamedQuery("MediaFileDirectory.getByWeblogAndNoParent");
-        q.setParameter(1, weblog);
-        try {
-            return (MediaFileDirectory) q.getSingleResult();
-        } catch (NoResultException e) {
-            return null;
-        }
+        return getMediaFileDirectoryByName(weblog, "default");
     }
 
     /**
@@ -807,27 +728,24 @@ public class JPAMediaFileManagerImpl imp
             // a directory: go recursive
             if (files[i].isDirectory()) {
 
-                if (newDir.hasDirectory(files[i].getName())) {
+                if (weblog.hasMediaFileDirectory(files[i].getName())) {
                     // already have a mediafile directory for that
                     upgradeUploadsDir(weblog, user, files[i],
-                            newDir.getChildDirectory(files[i].getName()));
+                            weblog.getMediaFileDirectory(files[i].getName()));
 
                 } else {
                     // need to create a new mediafile directory
-                    MediaFileDirectory subDir = null;
+                    MediaFileDirectory secondDir = null;
                     try {
-                        subDir = newDir.createNewDirectory(files[i].getName());
-                        roller.getMediaFileManager().createMediaFileDirectory(
-                                subDir);
-                        newDir.getChildDirectories().add(subDir);
+                        secondDir = new MediaFileDirectory(weblog, files[i].getName(), null);
+                        roller.getMediaFileManager().createMediaFileDirectory(secondDir);
                         roller.flush();
                         dirCount++;
-
                     } catch (WebloggerException ex) {
                         log.error("ERROR creating directory: "
                                 + newDir.getName() + "/" + files[i].getName());
                     }
-                    upgradeUploadsDir(weblog, user, files[i], subDir);
+                    upgradeUploadsDir(weblog, user, files[i], secondDir);
                 }
 
             } else {
@@ -919,24 +837,15 @@ public class JPAMediaFileManagerImpl imp
             this.strategy.remove(mf);
         }
 
-        // Children
-        roller.flush();
+        dir.getWeblog().getMediaFileDirectories().remove(dir);
 
-        // Set<MediaFileDirectory> dirs = dir.getChildDirectories();
-        // Recursive fix ConcurrentModificationException
-        Set<MediaFileDirectory> dirs = Collections
-                .synchronizedSet(new HashSet<MediaFileDirectory>(dir
-                        .getChildDirectories()));
-        for (MediaFileDirectory md : dirs) {
-            removeMediaFileDirectory(md);
-        }
+        // Contained media files
+        roller.flush();
 
         this.strategy.remove(dir);
 
         // Refresh associated parent
         roller.flush();
-        strategy.refresh(dir.getParent());
-
     }
 
     public void removeMediaFileTag(String name, MediaFile entry)

Modified: roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/themes/ThemeManagerImpl.java
URL: http://svn.apache.org/viewvc/roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/themes/ThemeManagerImpl.java?rev=1598186&r1=1598185&r2=1598186&view=diff
==============================================================================
--- roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/themes/ThemeManagerImpl.java
(original)
+++ roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/themes/ThemeManagerImpl.java
Thu May 29 00:45:20 2014
@@ -323,8 +323,7 @@ public class ThemeManagerImpl implements
 						website, resource.getPath());
 				if (mdir == null) {
 					log.debug("    Creating directory: " + resource.getPath());
-					mdir = fileMgr.createMediaFileDirectory(
-							fileMgr.getDefaultMediaFileDirectory(website),
+					mdir = fileMgr.createMediaFileDirectory(website,
 							resource.getPath());
 					roller.flush();
 				} else {
@@ -355,7 +354,7 @@ public class ThemeManagerImpl implements
 							justPath);
 					if (mdir == null) {
 						log.debug("    Creating directory: " + justPath);
-						mdir = fileMgr.createMediaFileDirectoryByName(website,
+						mdir = fileMgr.createMediaFileDirectory(website,
 								justPath);
 						roller.flush();
 					}

Modified: roller/trunk/app/src/main/java/org/apache/roller/weblogger/pojos/MediaFileDirectory.java
URL: http://svn.apache.org/viewvc/roller/trunk/app/src/main/java/org/apache/roller/weblogger/pojos/MediaFileDirectory.java?rev=1598186&r1=1598185&r2=1598186&view=diff
==============================================================================
--- roller/trunk/app/src/main/java/org/apache/roller/weblogger/pojos/MediaFileDirectory.java
(original)
+++ roller/trunk/app/src/main/java/org/apache/roller/weblogger/pojos/MediaFileDirectory.java
Thu May 29 00:45:20 2014
@@ -33,26 +33,24 @@ public class MediaFileDirectory {
     String name;
     String description;
     Weblog weblog;
-    MediaFileDirectory parent;
-    Set<MediaFileDirectory> childDirectories = new HashSet<MediaFileDirectory>();
     Set<MediaFile> mediaFiles = new HashSet<MediaFile>();
 
     public MediaFileDirectory() {
     }
 
-    public MediaFileDirectory(MediaFileDirectory parent, String name,
-            String desc, Weblog weblog) {
+    public MediaFileDirectory(Weblog weblog, String name,
+            String desc) {
 
         this.id = UUIDGenerator.generateUUID();
         this.name = name;
         this.description = desc;
 
         this.weblog = weblog;
-        this.parent = parent;
+        weblog.getMediaFileDirectories().add(this);
     }
 
     public boolean isEmpty() {
-        return getChildDirectories().isEmpty() && getMediaFiles().isEmpty();
+        return getMediaFiles().isEmpty();
     }
 
     /**
@@ -96,18 +94,6 @@ public class MediaFileDirectory {
     }
 
     /**
-     * Return parent folder, or null if folder is root of hierarchy.
-     * 
-     */
-    public MediaFileDirectory getParent() {
-        return parent;
-    }
-
-    public void setParent(MediaFileDirectory parent) {
-        this.parent = parent;
-    }
-
-    /**
      * Get the weblog which owns this folder.
      * 
      */
@@ -132,18 +118,6 @@ public class MediaFileDirectory {
     }
 
     /**
-     * Get child folders of this folder.
-     * 
-     */
-    public Set<MediaFileDirectory> getChildDirectories() {
-        return this.childDirectories;
-    }
-
-    public void setChildDirectories(Set<MediaFileDirectory> folders) {
-        this.childDirectories = folders;
-    }
-
-    /**
      * Indicates whether this directory contains the specified file.
      * 
      * @param name
@@ -183,56 +157,6 @@ public class MediaFileDirectory {
         return null;
     }
 
-    /**
-     * Indicates whether this directory contains the specified sub-directory.
-     * 
-     * @param name
-     *            directory name
-     * @return true if the sub-directory is present, false otherwise.
-     */
-    public boolean hasDirectory(String name) {
-        Set<MediaFileDirectory> dirSet = this.getChildDirectories();
-        for (MediaFileDirectory directory : dirSet) {
-            if (directory.getName().equals(name)) {
-                return true;
-            }
-        }
-        return false;
-    }
-
-    public MediaFileDirectory getChildDirectory(String name) {
-        for (MediaFileDirectory dir : getChildDirectories()) {
-            if (name.equals(dir.getName())) {
-                return dir;
-            }
-        }
-        return null;
-    }
-
-    /**
-     * Creates a new sub-directory
-     * 
-     * @param name
-     *            new directory name
-     * @return reference to the newly created directory.
-     */
-    public MediaFileDirectory createNewDirectory(String name) {
-        MediaFileDirectory newDirectory = new MediaFileDirectory(this, name,
-                "", this.getWeblog());
-        this.getChildDirectories().add(newDirectory);
-        return newDirectory;
-    }
-
-    /**
-     * Removes a directory from this MediaFileDirectory's child list
-     * 
-     * @param mfd
-     *            Media directory to remove
-     */
-    public void removeChildDirectory(MediaFileDirectory mfd) {
-        this.getChildDirectories().remove(mfd);
-    }
-
     @Override
     public boolean equals(Object other) {
         if (other == this) {

Modified: roller/trunk/app/src/main/java/org/apache/roller/weblogger/pojos/Weblog.java
URL: http://svn.apache.org/viewvc/roller/trunk/app/src/main/java/org/apache/roller/weblogger/pojos/Weblog.java?rev=1598186&r1=1598185&r2=1598186&view=diff
==============================================================================
--- roller/trunk/app/src/main/java/org/apache/roller/weblogger/pojos/Weblog.java (original)
+++ roller/trunk/app/src/main/java/org/apache/roller/weblogger/pojos/Weblog.java Thu May 29
00:45:20 2014
@@ -98,6 +98,8 @@ public class Weblog implements Serializa
 
     private List<WeblogBookmarkFolder> bookmarkFolders = new ArrayList<WeblogBookmarkFolder>();
 
+    private List<MediaFileDirectory> mediaFileDirectories = new ArrayList<MediaFileDirectory>();
+
     public Weblog() {
     }
     
@@ -1011,6 +1013,14 @@ public class Weblog implements Serializa
         this.bookmarkFolders = bookmarkFolders;
     }
 
+    public List<MediaFileDirectory> getMediaFileDirectories() {
+        return mediaFileDirectories;
+    }
+
+    public void setMediaFileDirectories(List<MediaFileDirectory> mediaFileDirectories)
{
+        this.mediaFileDirectories = mediaFileDirectories;
+    }
+
     /**
      * Add a bookmark folder to this weblog.
      */
@@ -1044,4 +1054,30 @@ public class Weblog implements Serializa
         }
         return false;
     }
+
+    /**
+     * Indicates whether this weblog contains the specified media file directory
+     *
+     * @param name directory name
+     *
+     * @return true if directory is present, false otherwise.
+     */
+    public boolean hasMediaFileDirectory(String name) {
+        for (MediaFileDirectory directory : this.getMediaFileDirectories()) {
+            if (directory.getName().equals(name)) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    public MediaFileDirectory getMediaFileDirectory(String name) {
+        for (MediaFileDirectory dir : this.getMediaFileDirectories()) {
+            if (name.equals(dir.getName())) {
+                return dir;
+            }
+        }
+        return null;
+    }
+
 }

Modified: roller/trunk/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/MediaFileBase.java
URL: http://svn.apache.org/viewvc/roller/trunk/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/MediaFileBase.java?rev=1598186&r1=1598185&r2=1598186&view=diff
==============================================================================
--- roller/trunk/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/MediaFileBase.java
(original)
+++ roller/trunk/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/MediaFileBase.java
Thu May 29 00:45:20 2014
@@ -112,20 +112,6 @@ public class MediaFileBase extends UIAct
                 }
             }
 
-            if (dirIds != null && dirIds.length > 0) {
-                log.debug("Processing delete of " + dirIds.length
-                        + " media directories.");
-                manager = WebloggerFactory.getWeblogger().getMediaFileManager();
-                for (String dirId : dirIds) {
-                    log.debug("Deleting media file directory - " + dirId);
-                    MediaFileDirectory mediaFileDir = manager.getMediaFileDirectory(dirId);
-                    if (mediaFileDir != null) {
-                        mediaFileDir.getParent().removeChildDirectory(mediaFileDir);
-                        manager.removeMediaFileDirectory(mediaFileDir);
-                    }
-                }
-                refreshAllDirectories();
-            }
             WebloggerFactory.getWeblogger().getWeblogManager()
                     .saveWeblog(this.getActionWeblog());
 

Modified: roller/trunk/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/MediaFileImageChooser.java
URL: http://svn.apache.org/viewvc/roller/trunk/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/MediaFileImageChooser.java?rev=1598186&r1=1598185&r2=1598186&view=diff
==============================================================================
--- roller/trunk/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/MediaFileImageChooser.java
(original)
+++ roller/trunk/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/MediaFileImageChooser.java
Thu May 29 00:45:20 2014
@@ -47,7 +47,7 @@ public class MediaFileImageChooser exten
 
     private List<MediaFile>          childFiles;
     private MediaFileDirectory       currentDirectory;
-    private List<MediaFileDirectory> childDirectories;
+
 
     public MediaFileImageChooser() {
         this.actionName = "mediaFileImageChooser";
@@ -83,9 +83,6 @@ public class MediaFileImageChooser exten
                 this.directoryId = directory.getId();
             }
 
-            this.childDirectories = new ArrayList<MediaFileDirectory>();
-            this.childDirectories.addAll(directory.getChildDirectories());
-
             this.childFiles = new ArrayList<MediaFile>();
 
             // only add image files
@@ -95,8 +92,6 @@ public class MediaFileImageChooser exten
                 }
             }
 
-            Collections.sort(this.childDirectories,
-                    new MediaFileDirectoryComparator(DirectoryComparatorType.NAME));
             Collections.sort(this.childFiles,
                     new MediaFileComparator(MediaFileComparatorType.NAME));
 
@@ -190,17 +185,4 @@ public class MediaFileImageChooser exten
         this.currentDirectory = currentDirectory;
     }
 
-    /**
-     * @return the childDirectories
-     */
-    public List<MediaFileDirectory> getChildDirectories() {
-        return childDirectories;
-    }
-
-    /**
-     * @param childDirectories the childDirectories to set
-     */
-    public void setChildDirectories(List<MediaFileDirectory> childDirectories) {
-        this.childDirectories = childDirectories;
-    }
 }

Modified: roller/trunk/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/MediaFileView.java
URL: http://svn.apache.org/viewvc/roller/trunk/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/MediaFileView.java?rev=1598186&r1=1598185&r2=1598186&view=diff
==============================================================================
--- roller/trunk/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/MediaFileView.java
(original)
+++ roller/trunk/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/MediaFileView.java
Thu May 29 00:45:20 2014
@@ -56,8 +56,7 @@ public class MediaFileView extends Media
     
     private List<MediaFile>          childFiles;
     private MediaFileDirectory       currentDirectory;
-    private List<MediaFileDirectory> childDirectories;
-    
+
 
     // Search criteria - drop-down for file type
     private static List<KeyValueObject> FILE_TYPES = null;
@@ -136,8 +135,7 @@ public class MediaFileView extends Media
             try {
                 log.debug("Creating new directory - " + this.newDirectoryName);
                 MediaFileManager manager = WebloggerFactory.getWeblogger().getMediaFileManager();
-                MediaFileDirectory parentDirectory = manager.getDefaultMediaFileDirectory(getActionWeblog());
-                manager.createMediaFileDirectory(parentDirectory, this.newDirectoryName);
+                manager.createMediaFileDirectory(getActionWeblog(), this.newDirectoryName);
                 // flush changes
                 WebloggerFactory.getWeblogger().flush();
                 addMessage("mediaFile.directoryCreate.success");
@@ -189,9 +187,6 @@ public class MediaFileView extends Media
             this.directoryId = directory.getId();
             this.directoryName = directory.getName();
 
-            this.childDirectories = new ArrayList<MediaFileDirectory>();
-            this.childDirectories.addAll(directory.getChildDirectories());
-
             this.childFiles = new ArrayList<MediaFile>();
             this.childFiles.addAll(directory.getMediaFiles());
 
@@ -206,8 +201,6 @@ public class MediaFileView extends Media
             } else {
                 // default to sort by name
                 sortBy = "name";
-                Collections.sort(this.childDirectories,
-                    new MediaFileDirectoryComparator(DirectoryComparatorType.NAME));
                 Collections.sort(this.childFiles,
                     new MediaFileComparator(MediaFileComparatorType.NAME));
             }
@@ -279,25 +272,6 @@ public class MediaFileView extends Media
     }
 
     /**
-     * Returns the hierarchy of the current directory. This is useful in
-     * displaying path information as breadcrumb.
-     */
-    public List<KeyValueObject> getCurrentDirectoryHierarchy() {
-        List<KeyValueObject> directoryHierarchy = new ArrayList<KeyValueObject>();
-
-        String fullPath = "/" + this.currentDirectory.getName();
-        String dpath = "";
-        if (fullPath.length() > 1) {
-            String[] directoryNames = fullPath.substring(1).split("/");
-            for (String directoryName : directoryNames) {
-                dpath = dpath + "/" + directoryName;
-                directoryHierarchy.add(new KeyValueObject(dpath, directoryName));
-            }
-        }
-        return directoryHierarchy;
-    }
-
-    /**
      * Delete selected media files.
      * 
      */
@@ -325,7 +299,6 @@ public class MediaFileView extends Media
             if (directoryId != null) {
                 log.debug("Deleting media file folder - " + directoryId + " (" + directoryName
+ ")");
                 MediaFileDirectory mediaFileDir = manager.getMediaFileDirectory(directoryId);
-                mediaFileDir.getParent().removeChildDirectory(mediaFileDir);
                 manager.removeMediaFileDirectory(mediaFileDir);
                 refreshAllDirectories();
                 WebloggerFactory.getWeblogger().getWeblogManager().saveWeblog(this.getActionWeblog());
@@ -378,14 +351,6 @@ public class MediaFileView extends Media
         this.directoryId = id;
     }
 
-    public List<MediaFileDirectory> getChildDirectories() {
-        return childDirectories;
-    }
-
-    public void setChildDirectories(List<MediaFileDirectory> directories) {
-        this.childDirectories = directories;
-    }
-
     public List<MediaFile> getChildFiles() {
         return childFiles;
     }

Modified: roller/trunk/app/src/main/resources/ApplicationResources.properties
URL: http://svn.apache.org/viewvc/roller/trunk/app/src/main/resources/ApplicationResources.properties?rev=1598186&r1=1598185&r2=1598186&view=diff
==============================================================================
--- roller/trunk/app/src/main/resources/ApplicationResources.properties (original)
+++ roller/trunk/app/src/main/resources/ApplicationResources.properties Thu May 29 00:45:20
2014
@@ -1103,7 +1103,7 @@ mediaFileView.others=Others
 mediaFileView.kb=KB
 mediaFileView.mb=MB
 mediaFileView.bytes=Bytes
-mediaFileView.name=Name
+mediaFileView.name=Folder
 mediaFileView.date=Date
 mediaFileView.type=Type
 mediaFileView.size=Size

Modified: roller/trunk/app/src/main/resources/org/apache/roller/weblogger/pojos/MediaFileDirectory.orm.xml
URL: http://svn.apache.org/viewvc/roller/trunk/app/src/main/resources/org/apache/roller/weblogger/pojos/MediaFileDirectory.orm.xml?rev=1598186&r1=1598185&r2=1598186&view=diff
==============================================================================
--- roller/trunk/app/src/main/resources/org/apache/roller/weblogger/pojos/MediaFileDirectory.orm.xml
(original)
+++ roller/trunk/app/src/main/resources/org/apache/roller/weblogger/pojos/MediaFileDirectory.orm.xml
Thu May 29 00:45:20 2014
@@ -9,9 +9,6 @@
         <named-query name="MediaFileDirectory.getByWeblog">
             <query>SELECT d FROM MediaFileDirectory d WHERE d.weblog = ?1</query>
         </named-query>
-        <named-query name="MediaFileDirectory.getByWeblogAndNoParent">
-            <query>SELECT d FROM MediaFileDirectory d WHERE d.weblog = ?1 AND d.parent
IS NULL</query>
-        </named-query>
         <named-query name="MediaFileDirectory.getByWeblogAndName">
             <query>SELECT d FROM MediaFileDirectory d WHERE d.weblog = ?1 AND d.name
= ?2</query>
         </named-query>
@@ -28,16 +25,6 @@
             <many-to-one name="weblog" target-entity="org.apache.roller.weblogger.pojos.Weblog">
                 <join-column name="websiteid" insertable="true" updatable="true" nullable="false"/>
             </many-to-one>
-            <many-to-one name="parent" target-entity="org.apache.roller.weblogger.pojos.MediaFileDirectory">
-                <join-column name="parentid" insertable="true" updatable="true" nullable="true"/>
-            </many-to-one>
-            <one-to-many name="childDirectories" mapped-by="parent" target-entity="org.apache.roller.weblogger.pojos.MediaFileDirectory"
fetch="LAZY">
-                <order-by>name</order-by>
-                <cascade>
-                    <cascade-persist/>
-                    <cascade-remove/>
-                </cascade>
-            </one-to-many>
             <one-to-many name="mediaFiles" mapped-by="directory" target-entity="org.apache.roller.weblogger.pojos.MediaFile"
fetch="LAZY">
                 <order-by>name</order-by>
                 <cascade>

Modified: roller/trunk/app/src/main/resources/org/apache/roller/weblogger/pojos/Weblog.orm.xml
URL: http://svn.apache.org/viewvc/roller/trunk/app/src/main/resources/org/apache/roller/weblogger/pojos/Weblog.orm.xml?rev=1598186&r1=1598185&r2=1598186&view=diff
==============================================================================
--- roller/trunk/app/src/main/resources/org/apache/roller/weblogger/pojos/Weblog.orm.xml (original)
+++ roller/trunk/app/src/main/resources/org/apache/roller/weblogger/pojos/Weblog.orm.xml Thu
May 29 00:45:20 2014
@@ -175,6 +175,12 @@
                     <cascade-remove/>
                 </cascade>
             </one-to-many>
+            <one-to-many name="mediaFileDirectories" target-entity="org.apache.roller.weblogger.pojos.MediaFileDirectory"
mapped-by="weblog">
+                <cascade>
+                    <cascade-persist/>
+                    <cascade-remove/>
+                </cascade>
+            </one-to-many>
 			<transient name="theme"/>
 			<transient name="creator"/>
 			<transient name="defaultPage"/>

Modified: roller/trunk/app/src/main/resources/sql/500-to-510-migration.vm
URL: http://svn.apache.org/viewvc/roller/trunk/app/src/main/resources/sql/500-to-510-migration.vm?rev=1598186&r1=1598185&r2=1598186&view=diff
==============================================================================
--- roller/trunk/app/src/main/resources/sql/500-to-510-migration.vm (original)
+++ roller/trunk/app/src/main/resources/sql/500-to-510-migration.vm Thu May 29 00:45:20 2014
@@ -51,5 +51,4 @@ update folder set name = 'default' where
 update roller_mediafiledir set name = #concat("name" "id") where name = 'default';
 update roller_mediafiledir set name = 'default' where name = 'root' and parentid is null;
 #dropColumn("roller_mediafiledir", "path")
--- #dropColumn("roller_mediafiledir", "parentid")
-
+#dropColumn("roller_mediafiledir", "parentid")

Modified: roller/trunk/app/src/main/resources/sql/createdb.vm
URL: http://svn.apache.org/viewvc/roller/trunk/app/src/main/resources/sql/createdb.vm?rev=1598186&r1=1598185&r2=1598186&view=diff
==============================================================================
--- roller/trunk/app/src/main/resources/sql/createdb.vm (original)
+++ roller/trunk/app/src/main/resources/sql/createdb.vm Thu May 29 00:45:20 2014
@@ -504,8 +504,7 @@ create table roller_mediafiledir (
     id               varchar(48) not null primary key,
     name             varchar(255) not null,
     description      varchar(255),
-    websiteid        varchar(48) not null,
-    parentid         varchar(48)
+    websiteid        varchar(48) not null
 );
 
 

Modified: roller/trunk/app/src/main/webapp/WEB-INF/jsps/editor/MediaFileView.jsp
URL: http://svn.apache.org/viewvc/roller/trunk/app/src/main/webapp/WEB-INF/jsps/editor/MediaFileView.jsp?rev=1598186&r1=1598185&r2=1598186&view=diff
==============================================================================
--- roller/trunk/app/src/main/webapp/WEB-INF/jsps/editor/MediaFileView.jsp (original)
+++ roller/trunk/app/src/main/webapp/WEB-INF/jsps/editor/MediaFileView.jsp Thu May 29 00:45:20
2014
@@ -291,16 +291,7 @@
 <s:else>
 
     <p class="subtitle">
-        <s:text name="mediaFileView.name"/> /
-        <s:iterator id="directory" value="currentDirectoryHierarchy">
-
-            <s:url id="getDirectoryByPathUrl" action="mediaFileView">
-                <s:param name="directoryName" value="#directory.key" />
-                <s:param name="weblog" value="%{actionWeblog.handle}" />
-            </s:url>
-            <s:a href="%{getDirectoryByPathUrl}"><s:property value="#directory.value"
/></s:a> /
-
-        </s:iterator>
+        <s:text name="mediaFileView.name"/>: <s:text name="currentDirectory.name"
/>
     </p>
     <p class="pagetip">
         <s:text name="mediaFileView.dirPageTip" />
@@ -309,7 +300,7 @@
 </s:else>
 
 
-<s:if test="childFiles || childDirectories || (pager && pager.items.size() >
0)">
+<s:if test="childFiles || (pager && pager.items.size() > 0)">
 
   <s:form id="mediaFileViewForm" name="mediaFileViewForm" action="mediaFileView">
 	<s:hidden name="salt" />
@@ -492,11 +483,13 @@
 
                         <s:select id="moveTargetMenu" name="selectedDirectory" list="allDirectories"
listKey="id" listValue="name" />
                     </s:if>
-
-                    <s:if test="currentDirectory.name != 'default' && !pager">
-                        <s:submit value="%{getText('mediaFileView.deleteFolder')}" action="mediaFileView!deleteFolder"
onclick="onDeleteFolder();return false;"/>
-                    </s:if>
                 </span>
+
+                <s:if test="currentDirectory.name != 'default' && !pager">
+                    <span style="float:right">
+                            <s:submit value="%{getText('mediaFileView.deleteFolder')}"
action="mediaFileView!deleteFolder" onclick="onDeleteFolder();return false;"/>
+                    </span>
+                </s:if>
             </div>
         </s:if>
 

Modified: roller/trunk/app/src/test/java/org/apache/roller/weblogger/business/MediaFileTest.java
URL: http://svn.apache.org/viewvc/roller/trunk/app/src/test/java/org/apache/roller/weblogger/business/MediaFileTest.java?rev=1598186&r1=1598185&r2=1598186&view=diff
==============================================================================
--- roller/trunk/app/src/test/java/org/apache/roller/weblogger/business/MediaFileTest.java
(original)
+++ roller/trunk/app/src/test/java/org/apache/roller/weblogger/business/MediaFileTest.java
Thu May 29 00:45:20 2014
@@ -103,23 +103,23 @@ public class MediaFileTest extends TestC
         testWeblog = TestUtils.getManagedWebsite(testWeblog);
 
         try {
-            mfMgr.createMediaFileDirectoryByName(testWeblog, "");
+            mfMgr.createMediaFileDirectory(testWeblog, "");
             assertTrue(false);
         } catch (WebloggerException e) {
             assertTrue(true);
         }
 
         try {
-            mfMgr.createMediaFileDirectoryByName(testWeblog, "default");
+            mfMgr.createMediaFileDirectory(testWeblog, "default");
             assertTrue(false);
         } catch (WebloggerException e) {
             assertTrue(true);
         }
 
         MediaFileDirectory newDirectory1 = mfMgr
-                .createMediaFileDirectoryByName(testWeblog, "test1");
+                .createMediaFileDirectory(testWeblog, "test1");
         MediaFileDirectory newDirectory2 = mfMgr
-                .createMediaFileDirectoryByName(testWeblog, "test2");
+                .createMediaFileDirectory(testWeblog, "test2");
         TestUtils.endSession(true);
 
         testWeblog = TestUtils.getManagedWebsite(testWeblog);
@@ -134,7 +134,7 @@ public class MediaFileTest extends TestC
 
         // show throw error when creating directory that already exists
         try {
-            mfMgr.createMediaFileDirectoryByName(testWeblog, "test1");
+            mfMgr.createMediaFileDirectory(testWeblog, "test1");
             assertTrue(false);
         } catch (WebloggerException e) {
             assertTrue(true);
@@ -215,15 +215,13 @@ public class MediaFileTest extends TestC
         MediaFileDirectory rootDirectory = mfMgr
                 .getDefaultMediaFileDirectory(testWeblog);
 
-        MediaFileDirectory directory2 = new MediaFileDirectory(rootDirectory,
-                "dir2", "directory 2", testWeblog);
+        MediaFileDirectory directory2 = new MediaFileDirectory(testWeblog,
+                "dir2", "directory 2" );
         mfMgr.createMediaFileDirectory(directory2);
-        rootDirectory.getChildDirectories().add(directory2);
 
-        MediaFileDirectory directory3 = new MediaFileDirectory(rootDirectory,
-                "dir3", "directory 3", testWeblog);
+        MediaFileDirectory directory3 = new MediaFileDirectory(testWeblog,
+                "dir3", "directory 3");
         mfMgr.createMediaFileDirectory(directory3);
-        rootDirectory.getChildDirectories().add(directory3);
 
         TestUtils.endSession(true);
 
@@ -885,21 +883,18 @@ public class MediaFileTest extends TestC
         MediaFileDirectory rootDirectory = mfMgr
                 .getDefaultMediaFileDirectory(testWeblog);
 
-        MediaFileDirectory directory1 = new MediaFileDirectory(rootDirectory,
-                "dir1", "directory 1", testWeblog);
+        MediaFileDirectory directory1 = new MediaFileDirectory(testWeblog,
+                "dir1", "directory 1");
         mfMgr.createMediaFileDirectory(directory1);
-        rootDirectory.getChildDirectories().add(directory1);
 
-        MediaFileDirectory directory2 = new MediaFileDirectory(rootDirectory,
-                "dir2", "directory 2", testWeblog);
+        MediaFileDirectory directory2 = new MediaFileDirectory(testWeblog,
+                "dir2", "directory 2");
         mfMgr.createMediaFileDirectory(directory2);
-        rootDirectory.getChildDirectories().add(directory2);
 
-        MediaFileDirectory directory3 = new MediaFileDirectory(rootDirectory,
-                "dir3", "directory 3", testWeblog);
+        MediaFileDirectory directory3 = new MediaFileDirectory(testWeblog,
+                "dir3", "directory 3");
         mfMgr.createMediaFileDirectory(directory3);
-        rootDirectory.getChildDirectories().add(directory3);
-        
+
         TestUtils.endSession(true);
         
         testWeblog = TestUtils.getManagedWebsite(testWeblog);
@@ -936,9 +931,9 @@ public class MediaFileTest extends TestC
         testWeblog = TestUtils.getManagedWebsite(testWeblog);
         rootDirectory = mfMgr.getMediaFileDirectory(rootDirectory.getId());
 
-        Set<MediaFileDirectory> childDirectories = rootDirectory
-                .getChildDirectories();
-        assertEquals(3, childDirectories.size());
+        List<MediaFileDirectory> childDirectories = testWeblog
+                .getMediaFileDirectories();
+        assertEquals(4, childDirectories.size());
         assertTrue(containsName(childDirectories, "dir1"));
         assertTrue(containsName(childDirectories, "dir2"));
         assertTrue(containsName(childDirectories, "dir3"));
@@ -979,18 +974,16 @@ public class MediaFileTest extends TestC
         try {
 
             MediaFileDirectory directory1 = new MediaFileDirectory(
-                    rootDirectory, "dir1", "directory 1", testWeblog);
+                    testWeblog, "dir1", "directory 1");
             mfMgr.createMediaFileDirectory(directory1);
-            rootDirectory.getChildDirectories().add(directory1);
             String dir1Id = directory1.getId();
 
             MediaFileDirectory directory2 = new MediaFileDirectory(
-                    rootDirectory, "dir2", "directory 2", testWeblog);
+                    testWeblog, "dir2", "directory 2");
             mfMgr.createMediaFileDirectory(directory2);
-            rootDirectory.getChildDirectories().add(directory2);
 
             MediaFileDirectory directory3 = new MediaFileDirectory(
-                    rootDirectory, "dir3", "directory 3", testWeblog);
+                    testWeblog, "dir3", "directory 3");
             mfMgr.createMediaFileDirectory(directory3);
             //rootDirectory.getChildDirectories().add(directory3);
             
@@ -1154,40 +1147,31 @@ public class MediaFileTest extends TestC
         MediaFileDirectory rootDirectory = mfMgr
                 .getDefaultMediaFileDirectory(testWeblog);
 
-        MediaFileDirectory directory1 = new MediaFileDirectory(rootDirectory,
-                "dir1", "directory 1", testWeblog);
+        MediaFileDirectory directory1 = new MediaFileDirectory(testWeblog,
+                "dir1", "directory 1");
         mfMgr.createMediaFileDirectory(directory1);
-        rootDirectory.getChildDirectories().add(directory1);
 
-        MediaFileDirectory directory2 = new MediaFileDirectory(rootDirectory,
-                "dir2", "directory 2", testWeblog);
+        MediaFileDirectory directory2 = new MediaFileDirectory(testWeblog,
+                "dir2", "directory 2");
         mfMgr.createMediaFileDirectory(directory2);
-        rootDirectory.getChildDirectories().add(directory2);
 
-        MediaFileDirectory directory3 = new MediaFileDirectory(rootDirectory,
-                "dir3", "directory 3", testWeblog);
+        MediaFileDirectory directory3 = new MediaFileDirectory(testWeblog,
+                "dir3", "directory 3");
         mfMgr.createMediaFileDirectory(directory3);
-        rootDirectory.getChildDirectories().add(directory3);
 
         TestUtils.endSession(true);
 
         testWeblog = TestUtils.getManagedWebsite(testWeblog);
         rootDirectory = mfMgr.getMediaFileDirectory(rootDirectory.getId());
 
-        Set<MediaFileDirectory> childDirectories = rootDirectory
-                .getChildDirectories();
+        List<MediaFileDirectory> childDirectories = testWeblog.getMediaFileDirectories();
+
         assertEquals(3, childDirectories.size());
 
         TestUtils.endSession(true);
 
         testWeblog = TestUtils.getManagedWebsite(testWeblog);
 
-        // Using named query MediaFileDirectory.getByWeblogAndNoParent
-        MediaFileDirectory directory = mfMgr
-                .getDefaultMediaFileDirectory(testWeblog);
-
-        assertEquals(3, directory.getChildDirectories().size());
-
         // Delete folder
         MediaFileDirectory directoryById = mfMgr
                 .getMediaFileDirectory(directory1.getId());
@@ -1195,14 +1179,6 @@ public class MediaFileTest extends TestC
         mfMgr.removeMediaFileDirectory(directoryById);
         TestUtils.endSession(true);
 
-        directory = null;
-
-        // Using named query again MediaFileDirectory.getByWeblogAndNoParent
-        directory = mfMgr.getDefaultMediaFileDirectory(testWeblog);
-
-        // There should only be two, the database only has two.
-        assertEquals(2, directory.getChildDirectories().size());
-
         TestUtils.endSession(true);
         TestUtils.teardownWeblog(testWeblog.getId());
         TestUtils.teardownUser(testUser.getUserName());



Mime
View raw message