Java Code Examples for org.alfresco.repo.content.ContentStore#getRootLocation()

The following examples show how to use org.alfresco.repo.content.ContentStore#getRootLocation() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FileContentStoreTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Empty parent directories should be removed when a URL is removed.
 */
@Test
public void testDeleteRemovesEmptyDirs() throws Exception
{
    ContentStore store = getStore();
    String url = "store://1965/12/1/13/12/file.bin";
    
    // Ensure clean test data
    if (store.exists(url)) store.delete(url);
    
    String content = "Content for test: " + getName();
    store.getWriter(new ContentContext(null, url)).putContent(content);
    
    File root = new File(store.getRootLocation());
    
    assertDirExists(root, "");
    assertDirExists(root, "1965/12/1/13/12");
    
    store.delete(url);
    
    assertDirNotExists(root, "1965");
    // root should be untouched.
    assertDirExists(root, "");
}
 
Example 2
Source File: FilesystemSourceUtils.java    From alfresco-bulk-import with Apache License 2.0 6 votes vote down vote up
/**
 * Determines whether the given file is already located in an Alfresco managed content store.  Used to determine
 * whether to perform a streaming or in-place import.
 * 
 * @param contentStore The content store Alfresco is configured to use <i>(must not be null)</i>.
 * @param source The file to test.  Typically this would be the source directory for the import <i>(must not be null)</i>.
 * @return True if the given file is in an Alfresco managed content store, false otherwise.
 */
public final static boolean isInContentStore(final ContentStore contentStore, final File source)
{
    boolean      result           = false;
    final String contentStoreRoot = contentStore.getRootLocation();
    
    if (contentStoreRoot != null && contentStoreRoot.trim().length() > 0)
    {
        final File contentStoreRootFile = new File(contentStoreRoot);
        
        // If the content store root doesn't exist as a file, we're probably dealing with a non-filesystem content store
        if (contentStoreRootFile.exists() && contentStoreRootFile.isDirectory())
        {
            result = isInDirectory(contentStoreRoot, source.getAbsolutePath());
        }
    }

    return(result);
}
 
Example 3
Source File: FileContentStoreTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
@Test
public void testRootLocation() throws Exception
{
    ContentStore store = getStore();
    String root = store.getRootLocation();
    assertNotNull("Root value can't be null", root);
    File dir = new File(root);
    assertTrue("Root location for FileContentStore must exist", dir.exists());
}
 
Example 4
Source File: FileContentStoreTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Only non-empty directories should be deleted.
 */
@Test
public void testDeleteLeavesNonEmptyDirs()
{
    ContentStore store = getStore();
    String url = "store://1965/12/1/13/12/file.bin";
    
    // Ensure clean test data
    if (store.exists(url)) store.delete(url);
    
    String content = "Content for test: " + getName();
    store.getWriter(new ContentContext(null, url)).putContent(content);
    
    File root = new File(store.getRootLocation());
    
    assertDirExists(root, "");
    assertDirExists(root, "1965/12/1/13/12");
    
    // Make a directory non-empty
    String anotherUrl = "store://1965/12/3/another.bin";
    if (store.exists(anotherUrl)) store.delete(anotherUrl);
    store.getWriter(new ContentContext(null, anotherUrl));
    
    store.delete(url);
    
    // Parents of another.bin cannot be deleted
    assertDirExists(root, "1965");
    assertDirExists(root, "1965/12");
    // Non-parents of another.bin could be deleted
    assertDirNotExists(root, "1965/12/1");
    
    // root should be untouched.
    assertDirExists(root, "");
}