Search in sources :

Example 6 with BasicFileAttributeView

use of org.entando.entando.aps.system.services.storage.BasicFileAttributeView in project entando-core by entando.

the class FileBrowserAction method trash.

public String trash() {
    try {
        String validatePath = this.validateFullPath();
        if (null != validatePath)
            return validatePath;
        String fullPath = this.getCurrentPath() + this.getFilename();
        BasicFileAttributeView fileAttributeView = this.getStorageManager().getAttributes(fullPath, this.getProtectedFolderBoolean());
        if (null == fileAttributeView) {
            this.addActionError(this.getText("error.filebrowser.filepath.null"));
            return INPUT;
        }
        this.setStrutsAction(ApsAdminSystemConstants.DELETE);
    } catch (Throwable t) {
        _logger.error("error in trash", t);
        return FAILURE;
    }
    return SUCCESS;
}
Also used : BasicFileAttributeView(org.entando.entando.aps.system.services.storage.BasicFileAttributeView)

Example 7 with BasicFileAttributeView

use of org.entando.entando.aps.system.services.storage.BasicFileAttributeView in project entando-core by entando.

the class LocalStorageManagerInterface method getListDirectory.

public List<LinkedListItem> getListDirectory(Properties properties) throws Throwable {
    List<LinkedListItem> list = new ArrayList<LinkedListItem>();
    String pathValue = properties.getProperty(PARAM_PATH);
    String protectedValue = properties.getProperty(PARAM_IS_PROTECTED);
    boolean isProtected = StringUtils.equalsIgnoreCase(protectedValue, "true");
    try {
        if (StringUtils.isNotBlank(pathValue))
            pathValue = URLDecoder.decode(pathValue, "UTF-8");
        if (!StorageManagerUtil.isValidDirName(pathValue)) {
            throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "The path '" + pathValue + "' does not exists", Response.Status.CONFLICT);
        }
        BasicFileAttributeView[] files = this.getStorageManager().listAttributes(pathValue, isProtected);
        for (int i = 0; i < files.length; i++) {
            BasicFileAttributeView fileAttributeView = files[i];
            String url = this.getApiResourceURLWithParams(properties, fileAttributeView, pathValue, isProtected);
            LinkedListItem item = new LinkedListItem();
            item.setCode(this.buildResourcePath(fileAttributeView, pathValue));
            item.setUrl(url);
            list.add(item);
        }
    } catch (Throwable t) {
        _logger.error("Error extracting storage resources in path: {} and protected flag: {} ", pathValue, isProtected, t);
        throw t;
    }
    return list;
}
Also used : BasicFileAttributeView(org.entando.entando.aps.system.services.storage.BasicFileAttributeView) ArrayList(java.util.ArrayList) LinkedListItem(org.entando.entando.aps.system.services.api.model.LinkedListItem) ApiException(org.entando.entando.aps.system.services.api.model.ApiException)

Example 8 with BasicFileAttributeView

use of org.entando.entando.aps.system.services.storage.BasicFileAttributeView in project entando-core by entando.

the class FileBrowserAction method edit.

public String edit() {
    try {
        String result = this.validateTextFileExtension(this.getFilename());
        if (null != result)
            return result;
        String validatePath = this.validateFullPath();
        if (null != validatePath)
            return validatePath;
        String fullPath = this.getCurrentPath() + this.getFilename();
        BasicFileAttributeView fileAttributeView = this.getStorageManager().getAttributes(fullPath, this.getProtectedFolderBoolean());
        if (null == fileAttributeView || fileAttributeView.isDirectory()) {
            return INPUT;
        }
        String text = this.getStorageManager().readFile(fullPath, this.getProtectedFolderBoolean());
        this.setFileText(text);
        this.setStrutsAction(ApsAdminSystemConstants.EDIT);
    } catch (Throwable t) {
        _logger.error("error editing file, fullPath: {}", this.getCurrentPath(), t);
        return FAILURE;
    }
    return SUCCESS;
}
Also used : BasicFileAttributeView(org.entando.entando.aps.system.services.storage.BasicFileAttributeView)

Example 9 with BasicFileAttributeView

use of org.entando.entando.aps.system.services.storage.BasicFileAttributeView in project entando-core by entando.

the class TestFileBrowserAction method testBrowseFileSystem_1.

public void testBrowseFileSystem_1() throws Throwable {
    String result = this.executeList("admin", null, null);
    assertEquals(Action.SUCCESS, result);
    FileBrowserAction action = (FileBrowserAction) super.getAction();
    BasicFileAttributeView[] fileAttributes = action.getFilesAttributes();
    assertNotNull(fileAttributes);
    assertEquals(2, fileAttributes.length);
    for (int i = 0; i < fileAttributes.length; i++) {
        BasicFileAttributeView bfav = fileAttributes[i];
        assertTrue(bfav instanceof RootFolderAttributeView);
        assertTrue(bfav.isDirectory());
        if (i == 0) {
            assertEquals("public", bfav.getName());
        } else {
            assertEquals("protected", bfav.getName());
        }
    }
}
Also used : BasicFileAttributeView(org.entando.entando.aps.system.services.storage.BasicFileAttributeView)

Example 10 with BasicFileAttributeView

use of org.entando.entando.aps.system.services.storage.BasicFileAttributeView in project entando-core by entando.

the class TestFileBrowserAction method testBrowseFileSystem_2.

public void testBrowseFileSystem_2() throws Throwable {
    String result = this.executeList("admin", null, false);
    assertEquals(Action.SUCCESS, result);
    FileBrowserAction action = (FileBrowserAction) super.getAction();
    BasicFileAttributeView[] fileAttributes = action.getFilesAttributes();
    assertNotNull(fileAttributes);
    boolean containsConf = false;
    boolean prevDirectory = true;
    String prevName = null;
    for (int i = 0; i < fileAttributes.length; i++) {
        BasicFileAttributeView bfav = fileAttributes[i];
        if (!prevDirectory && bfav.isDirectory()) {
            fail();
        }
        if (bfav.isDirectory() && bfav.getName().equals("conf")) {
            containsConf = true;
        }
        if ((bfav.isDirectory() == prevDirectory) && null != prevName) {
            assertTrue(bfav.getName().compareTo(prevName) > 0);
        }
        prevName = bfav.getName();
        prevDirectory = bfav.isDirectory();
    }
    assertTrue(containsConf);
}
Also used : BasicFileAttributeView(org.entando.entando.aps.system.services.storage.BasicFileAttributeView)

Aggregations

BasicFileAttributeView (org.entando.entando.aps.system.services.storage.BasicFileAttributeView)10 ApiException (org.entando.entando.aps.system.services.api.model.ApiException)4 ByteArrayInputStream (java.io.ByteArrayInputStream)2 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 LinkedListItem (org.entando.entando.aps.system.services.api.model.LinkedListItem)1