Search in sources :

Example 46 with RepositoryFileDto

use of org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileDto in project pentaho-platform by pentaho.

the class FileService method doGetChildren.

public List<RepositoryFileDto> doGetChildren(String pathId, String filter, Boolean showHidden, Boolean includeAcls) {
    List<RepositoryFileDto> repositoryFileDtoList = new ArrayList<RepositoryFileDto>();
    RepositoryFileDto repositoryFileDto = getRepoWs().getFile(FileUtils.idToPath(pathId));
    if (repositoryFileDto != null && isPathValid(repositoryFileDto.getPath())) {
        RepositoryRequest repositoryRequest = getRepositoryRequest(repositoryFileDto, showHidden, filter, includeAcls);
        repositoryFileDtoList = getRepoWs().getChildrenFromRequest(repositoryRequest);
        // BISERVER-9599 - Use special sort order
        if (isShowingTitle(repositoryRequest)) {
            Collator collator = getCollator(Collator.PRIMARY);
            sortByLocaleTitle(collator, repositoryFileDtoList);
        }
    }
    return repositoryFileDtoList;
}
Also used : RepositoryFileDto(org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileDto) ArrayList(java.util.ArrayList) RepositoryRequest(org.pentaho.platform.api.repository2.unified.RepositoryRequest) Collator(java.text.Collator)

Example 47 with RepositoryFileDto

use of org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileDto in project pentaho-platform by pentaho.

the class FileService method doGetFileAcl.

/**
 * Retrieves the acls of the selected repository file
 *
 * @param pathId (colon separated path for the repository file)
 * @return <code> RepositoryFileAclDto </code>
 */
public RepositoryFileAclDto doGetFileAcl(String pathId) {
    RepositoryFileDto file = getRepoWs().getFile(FileUtils.idToPath(pathId));
    RepositoryFileAclDto fileAcl = getRepoWs().getAcl(file.getId());
    if (fileAcl.isEntriesInheriting()) {
        List<RepositoryFileAclAceDto> aces = getRepoWs().getEffectiveAcesWithForceFlag(file.getId(), fileAcl.isEntriesInheriting());
        fileAcl.setAces(aces, fileAcl.isEntriesInheriting());
    }
    addAdminRole(fileAcl);
    return fileAcl;
}
Also used : RepositoryFileDto(org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileDto) RepositoryFileAclAceDto(org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileAclAceDto) RepositoryFileAclDto(org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileAclDto)

Example 48 with RepositoryFileDto

use of org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileDto in project pentaho-platform by pentaho.

the class FileService method searchGeneratedContent.

/**
 * @param userDir          the user home directory
 * @param targetComparator the comparator to filter
 * @param metadataConstant the property used to get the file property to compare
 * @return list of <code> repositoryFileDto </code>
 * @throws FileNotFoundException
 * @private
 */
protected List<RepositoryFileDto> searchGeneratedContent(String userDir, String targetComparator, String metadataConstant) throws FileNotFoundException {
    List<RepositoryFileDto> content = new ArrayList<RepositoryFileDto>();
    RepositoryFile workspaceFolder = getRepository().getFile(userDir);
    if (workspaceFolder != null) {
        List<RepositoryFile> children = getRepository().getChildren(workspaceFolder.getId());
        for (RepositoryFile child : children) {
            if (!child.isFolder()) {
                Map<String, Serializable> fileMetadata = getRepository().getFileMetadata(child.getId());
                String creatorId = (String) fileMetadata.get(metadataConstant);
                if (creatorId != null && creatorId.equals(targetComparator)) {
                    content.add(toFileDto(child, null, false));
                }
            }
        }
    } else {
        logger.error(Messages.getInstance().getString("FileResource.WORKSPACE_FOLDER_NOT_FOUND", userDir));
        throw new FileNotFoundException(userDir);
    }
    return content;
}
Also used : RepositoryFileDto(org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileDto) Serializable(java.io.Serializable) ArrayList(java.util.ArrayList) FileNotFoundException(java.io.FileNotFoundException) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile)

Example 49 with RepositoryFileDto

use of org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileDto in project pentaho-platform by pentaho.

the class FileService method canRestoreToFolderWithNoConflicts.

/**
 * @param params
 *            id of files, separated by ','
 *
 * @return false if homeFolder has files
 *               with names and extension equal to passed files
 *         true otherwise
 *
 * @throws IllegalArgumentException
 *              if {@code params} is null
 */
public boolean canRestoreToFolderWithNoConflicts(String pathToFolder, String params) {
    if (params == null) {
        throw new IllegalArgumentException("parameters cannot be null");
    }
    List<RepositoryFileDto> filesInFolder = doGetChildren(pathToFolder, null, false, true);
    String[] sourceFileIds = FileUtils.convertCommaSeparatedStringToArray(params);
    for (RepositoryFileDto fileInFolder : filesInFolder) {
        for (String sourceFileId : sourceFileIds) {
            RepositoryFile fileToRestore = getRepository().getFileById(sourceFileId);
            if (fileToRestore.getName().equals(fileInFolder.getName())) {
                return false;
            }
        }
    }
    return true;
}
Also used : RepositoryFileDto(org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileDto) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile)

Example 50 with RepositoryFileDto

use of org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileDto in project pentaho-platform by pentaho.

the class FileService method doGetFileLocales.

/**
 * Retrieves the list of locale map for the selected repository file. The list will be empty if a problem occurs.
 *
 * @param pathId colon separated path for the repository file
 * <pre function="syntax.xml">
 *    :path:to:file:id
 * </pre>
 * @return <code>List<LocaleMapDto></code> the list of locales
 *         <pre function="syntax.xml">
 *           <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
 *           &lt;localePropertiesMapEntries&gt;
 *             &lt;localeMapDto&gt;
 *               &lt;locale&gt;default&lt;/locale&gt;
 *               &lt;properties&gt;
 *                 &lt;stringKeyStringValueDto&gt;
 *                   &lt;key&gt;file.title&lt;/key&gt;
 *                   &lt;value&gt;myFile&lt;/value&gt;
 *                 &lt;/stringKeyStringValueDto&gt;
 *                 &lt;stringKeyStringValueDto&gt;
 *                   &lt;key&gt;jcr:primaryType&lt;/key&gt;
 *                   &lt;value&gt;nt:unstructured&lt;/value&gt;
 *                 &lt;/stringKeyStringValueDto&gt;
 *                 &lt;stringKeyStringValueDto&gt;
 *                   &lt;key&gt;title&lt;/key&gt;
 *                   &lt;value&gt;myFile&lt;/value&gt;
 *                 &lt;/stringKeyStringValueDto&gt;
 *                 &lt;stringKeyStringValueDto&gt;
 *                   &lt;key&gt;file.description&lt;/key&gt;
 *                   &lt;value&gt;myFile Description&lt;/value&gt;
 *                 &lt;/stringKeyStringValueDto&gt;
 *               &lt;/properties&gt;
 *             &lt;/localeMapDto&gt;
 *           &lt;/localePropertiesMapEntries&gt;
 *         </pre>
 * @throws FileNotFoundException
 */
public List<LocaleMapDto> doGetFileLocales(String pathId) throws FileNotFoundException {
    List<LocaleMapDto> availableLocales = new ArrayList<LocaleMapDto>();
    RepositoryFileDto file = getRepoWs().getFile(idToPath(pathId));
    if (file == null) {
        throw new FileNotFoundException();
    }
    try {
        List<PentahoLocale> locales = getRepoWs().getAvailableLocalesForFileById(file.getId());
        if (locales != null && !locales.isEmpty()) {
            for (PentahoLocale locale : locales) {
                availableLocales.add(new LocaleMapDto(locale.toString(), null));
            }
        }
    } catch (Exception e) {
        throw new InternalError();
    }
    return availableLocales;
}
Also used : RepositoryFileDto(org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileDto) LocaleMapDto(org.pentaho.platform.api.repository2.unified.webservices.LocaleMapDto) ArrayList(java.util.ArrayList) FileNotFoundException(java.io.FileNotFoundException) PentahoLocale(org.pentaho.platform.repository2.locale.PentahoLocale) UnifiedRepositoryException(org.pentaho.platform.api.repository2.unified.UnifiedRepositoryException) GeneralSecurityException(java.security.GeneralSecurityException) InvalidParameterException(java.security.InvalidParameterException) PentahoAccessControlException(org.pentaho.platform.api.engine.PentahoAccessControlException) UnifiedRepositoryAccessDeniedException(org.pentaho.platform.api.repository2.unified.UnifiedRepositoryAccessDeniedException) FileNotFoundException(java.io.FileNotFoundException) PlatformImportException(org.pentaho.platform.plugin.services.importer.PlatformImportException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ExportException(org.pentaho.platform.plugin.services.importexport.ExportException) IllegalSelectorException(java.nio.channels.IllegalSelectorException) IOException(java.io.IOException)

Aggregations

Test (org.junit.Test)77 RepositoryFileDto (org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileDto)77 FileNotFoundException (java.io.FileNotFoundException)35 ArrayList (java.util.ArrayList)34 RepositoryFileDto (org.pentaho.platform.repository2.unified.webservices.RepositoryFileDto)29 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)27 Serializable (java.io.Serializable)26 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)26 Matchers.anyString (org.mockito.Matchers.anyString)25 GeneralSecurityException (java.security.GeneralSecurityException)14 StringKeyStringValueDto (org.pentaho.platform.api.repository2.unified.webservices.StringKeyStringValueDto)11 IllegalSelectorException (java.nio.channels.IllegalSelectorException)9 InvalidParameterException (java.security.InvalidParameterException)9 PentahoAccessControlException (org.pentaho.platform.api.engine.PentahoAccessControlException)9 Properties (java.util.Properties)8 UnifiedRepositoryAccessDeniedException (org.pentaho.platform.api.repository2.unified.UnifiedRepositoryAccessDeniedException)8 DefaultUnifiedRepositoryWebService (org.pentaho.platform.repository2.unified.webservices.DefaultUnifiedRepositoryWebService)8 IOException (java.io.IOException)7 IRepositoryFileData (org.pentaho.platform.api.repository2.unified.IRepositoryFileData)7 RepositoryFileAcl (org.pentaho.platform.api.repository2.unified.RepositoryFileAcl)7