Search in sources :

Example 26 with RepositoryFileDto

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

the class FileService method doGetContentCreator.

/**
 * Gets the content creator of the specified file
 *
 * @param pathId
 * @return
 */
public RepositoryFileDto doGetContentCreator(String pathId) throws FileNotFoundException {
    RepositoryFileDto file = getRepoWs().getFile(idToPath(pathId));
    if (file == null) {
        throw new FileNotFoundException();
    }
    Map<String, Serializable> fileMetadata = getRepository().getFileMetadata(file.getId());
    String creatorId = (String) fileMetadata.get(PentahoJcrConstants.PHO_CONTENTCREATOR);
    if (creatorId != null && creatorId.length() > 0) {
        return getRepoWs().getFileById(creatorId);
    }
    return null;
}
Also used : RepositoryFileDto(org.pentaho.platform.repository2.unified.webservices.RepositoryFileDto) Serializable(java.io.Serializable) FileNotFoundException(java.io.FileNotFoundException)

Example 27 with RepositoryFileDto

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

the class FileService method setFileAcls.

/**
 * Save the acls of the selected file to the repository
 *
 * This method is used to update and save the acls of the selected file to the repository
 *
 * @param pathId @param pathId colon separated path for the repository file
 *               <pre function="syntax.xml">
 *               :path:to:file:id
 *               </pre>
 * @param acl    Acl of the repository file <code> RepositoryFileAclDto </code>
 * @throws FileNotFoundException
 */
public void setFileAcls(String pathId, RepositoryFileAclDto acl) throws FileNotFoundException {
    RepositoryFileDto file = getRepoWs().getFile(idToPath(pathId));
    if (file == null) {
        // file does not exist or is not readable but we can't tell at this point
        throw new FileNotFoundException();
    }
    acl.setId(file.getId());
    // here we remove fake admin role added for display purpose only
    List<RepositoryFileAclAceDto> aces = acl.getAces();
    if (aces != null) {
        Iterator<RepositoryFileAclAceDto> it = aces.iterator();
        while (it.hasNext()) {
            RepositoryFileAclAceDto ace = it.next();
            if (!ace.isModifiable()) {
                it.remove();
            }
        }
    }
    getRepoWs().updateAcl(acl);
}
Also used : RepositoryFileDto(org.pentaho.platform.repository2.unified.webservices.RepositoryFileDto) RepositoryFileAclAceDto(org.pentaho.platform.repository2.unified.webservices.RepositoryFileAclAceDto) FileNotFoundException(java.io.FileNotFoundException)

Example 28 with RepositoryFileDto

use of org.pentaho.platform.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.repository2.unified.webservices.RepositoryFileDto) LocaleMapDto(org.pentaho.platform.repository2.unified.webservices.LocaleMapDto) ArrayList(java.util.ArrayList) FileNotFoundException(java.io.FileNotFoundException) PentahoLocale(org.pentaho.platform.repository2.locale.PentahoLocale) 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)

Example 29 with RepositoryFileDto

use of org.pentaho.platform.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.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 30 with RepositoryFileDto

use of org.pentaho.platform.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.repository2.unified.webservices.RepositoryFileDto) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile)

Aggregations

RepositoryFileDto (org.pentaho.platform.repository2.unified.webservices.RepositoryFileDto)66 Test (org.junit.Test)42 Matchers.anyString (org.mockito.Matchers.anyString)26 FileNotFoundException (java.io.FileNotFoundException)23 ArrayList (java.util.ArrayList)20 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)18 Serializable (java.io.Serializable)15 GeneralSecurityException (java.security.GeneralSecurityException)11 StringKeyStringValueDto (org.pentaho.platform.repository2.unified.webservices.StringKeyStringValueDto)9 IllegalSelectorException (java.nio.channels.IllegalSelectorException)8 InvalidParameterException (java.security.InvalidParameterException)8 PentahoAccessControlException (org.pentaho.platform.api.engine.PentahoAccessControlException)8 UnifiedRepositoryAccessDeniedException (org.pentaho.platform.api.repository2.unified.UnifiedRepositoryAccessDeniedException)8 IOException (java.io.IOException)7 IRepositoryFileData (org.pentaho.platform.api.repository2.unified.IRepositoryFileData)6 RepositoryFileAcl (org.pentaho.platform.api.repository2.unified.RepositoryFileAcl)6 RepositoryFileAclDto (org.pentaho.platform.repository2.unified.webservices.RepositoryFileAclDto)6 Properties (java.util.Properties)4 WebApplicationException (javax.ws.rs.WebApplicationException)4 RepositoryFileAclAceDto (org.pentaho.platform.repository2.unified.webservices.RepositoryFileAclAceDto)4