Search in sources :

Example 81 with RepositoryFileDto

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

the class FileService method getSourceFileIdsThatNotConflictWithFolderFiles.

/**
 * Conflict occurs if one of source files has the same
 * name with any of folder files.
 *
 * @param params
 *            String with file ids, separated by comma
 * @param pathToFolder
 *            path to folder
 *
 * @return String
 *            with file ids of not conflict files, separated by comma
 */
protected String getSourceFileIdsThatNotConflictWithFolderFiles(String pathToFolder, String params) {
    String[] sourceFileIds = FileUtils.convertCommaSeparatedStringToArray(params);
    List<String> nonConflictFileIdsList = new ArrayList<>();
    List<RepositoryFileDto> homeFolderFiles = doGetChildren(pathToFolder, null, true, true);
    for (String sourceFileId : sourceFileIds) {
        boolean isConflict = false;
        RepositoryFile fileToRestore = getRepository().getFileById(sourceFileId);
        if (fileToRestore == null) {
            logger.error("Could not get file with id: " + sourceFileId);
            continue;
        }
        for (RepositoryFileDto fileInHomeFolder : homeFolderFiles) {
            if (fileToRestore.getName().equals(fileInHomeFolder.getName())) {
                isConflict = true;
                break;
            }
        }
        if (!isConflict) {
            nonConflictFileIdsList.add(sourceFileId);
        }
    }
    return getCommaSeparatedFileIds(nonConflictFileIdsList);
}
Also used : RepositoryFileDto(org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileDto) ArrayList(java.util.ArrayList) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile)

Example 82 with RepositoryFileDto

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

the class FileService method getFolderFileIdsThatConflictWithSource.

public String getFolderFileIdsThatConflictWithSource(String pathToFolder, String params) {
    if (params == null) {
        throw new IllegalArgumentException("parameters cannot be null");
    }
    String[] sourceFileIds = FileUtils.convertCommaSeparatedStringToArray(params);
    List<String> conflictFileIdsList = new ArrayList<>();
    List<RepositoryFileDto> homeFolderFiles = doGetChildren(pathToFolder, null, false, true);
    for (RepositoryFileDto fileInHomeFolder : homeFolderFiles) {
        for (String sourceFileId : sourceFileIds) {
            RepositoryFile fileToRestore = getRepository().getFileById(sourceFileId);
            if (fileToRestore.getName().equals(fileInHomeFolder.getName())) {
                conflictFileIdsList.add(fileInHomeFolder.getId());
            }
        }
    }
    return getCommaSeparatedFileIds(conflictFileIdsList);
}
Also used : RepositoryFileDto(org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileDto) ArrayList(java.util.ArrayList) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile)

Example 83 with RepositoryFileDto

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

the class FileService method doSetContentCreator.

/**
 * Store content creator of the selected repository file
 *
 * @param pathId colon separated path for the repository file
 * <pre function="syntax.xml">
 *    :path:to:file:id
 * </pre>
 * @param contentCreator repository file
 * <pre function="syntax.xml">
 *   <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
 *     &lt;repositoryFileDto&gt;
 *     &lt;createdDate&gt;1402911997019&lt;/createdDate&gt;
 *     &lt;fileSize&gt;3461&lt;/fileSize&gt;
 *     &lt;folder&gt;false&lt;/folder&gt;
 *     &lt;hidden&gt;false&lt;/hidden&gt;
 *     &lt;id&gt;ff11ac89-7eda-4c03-aab1-e27f9048fd38&lt;/id&gt;
 *     &lt;lastModifiedDate&gt;1406647160536&lt;/lastModifiedDate&gt;
 *     &lt;locale&gt;en&lt;/locale&gt;
 *     &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;
 *     &lt;locked&gt;false&lt;/locked&gt;
 *     &lt;name&gt;myFile.prpt&lt;/name&gt;&lt;/name&gt;
 *     &lt;originalParentFolderPath&gt;/public/admin&lt;/originalParentFolderPath&gt;
 *     &lt;ownerType&gt;-1&lt;/ownerType&gt;
 *     &lt;path&gt;/public/admin/ff11ac89-7eda-4c03-aab1-e27f9048fd38&lt;/path&gt;
 *     &lt;title&gt;myFile&lt;/title&gt;
 *     &lt;versionId&gt;1.9&lt;/versionId&gt;
 *     &lt;versioned&gt;true&lt;/versioned&gt;
 *   &lt;/repositoryFileAclDto&gt;
 * </pre>
 * @throws FileNotFoundException
 */
public void doSetContentCreator(String pathId, RepositoryFileDto contentCreator) throws FileNotFoundException {
    RepositoryFileDto file = getRepoWs().getFile(idToPath(pathId));
    if (file == null) {
        throw new FileNotFoundException();
    }
    try {
        Map<String, Serializable> fileMetadata = getRepository().getFileMetadata(file.getId());
        fileMetadata.put(PentahoJcrConstants.PHO_CONTENTCREATOR, contentCreator.getId());
        getRepository().setFileMetadata(file.getId(), fileMetadata);
    } catch (Exception e) {
        throw new InternalError();
    }
}
Also used : RepositoryFileDto(org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileDto) Serializable(java.io.Serializable) FileNotFoundException(java.io.FileNotFoundException) 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)

Example 84 with RepositoryFileDto

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

the class FileService method doMoveFiles.

/**
 * Moves a list of files from its current location to another.
 * <p/>
 * Moves a list of files from its current location to another, the list should be comma separated.
 *
 * @param destPathId colon separated path for the repository file
 * <pre function="syntax.xml">
 *    :path:to:file:id
 * </pre>
 * @param params comma separated list of files to be moved
 * <pre function="syntax.xml">
 *    path1,path2,...
 * </pre>
 *
 * @return boolean <code>true</code>  if all files were moved correctly or <code>false</code> if the destiny path is
 * not available
 * @throws FileNotFoundException
 */
public void doMoveFiles(String destPathId, String params) throws FileNotFoundException {
    String idToPath = idToPath(destPathId);
    RepositoryFileDto repositoryFileDto = getRepoWs().getFile(idToPath);
    if (repositoryFileDto == null) {
        throw new FileNotFoundException(idToPath);
    }
    String[] sourceFileIds = FileUtils.convertCommaSeparatedStringToArray(params);
    int i = 0;
    try {
        for (; i < sourceFileIds.length; i++) {
            getRepoWs().moveFile(sourceFileIds[i], repositoryFileDto.getPath(), null);
        }
    } catch (IllegalArgumentException | UnifiedRepositoryAccessDeniedException e) {
        throw e;
    } catch (Exception e) {
        throw new InternalError();
    }
}
Also used : RepositoryFileDto(org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileDto) UnifiedRepositoryAccessDeniedException(org.pentaho.platform.api.repository2.unified.UnifiedRepositoryAccessDeniedException) FileNotFoundException(java.io.FileNotFoundException) 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)

Example 85 with RepositoryFileDto

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

the class FileServiceIT method doGetContentCreator.

@Test
public void doGetContentCreator() {
    String pathId = "path:to:file:file1.ext";
    String fileId = "file1";
    String creatorId = "creatorId";
    Map<String, Serializable> fileMetadata = mock(HashMap.class);
    doReturn(creatorId).when(fileMetadata).get("contentCreator");
    doReturn(fileMetadata).when(fileService.repository).getFileMetadata(fileId);
    doReturn("/path/to/file/file1.ext").when(fileService).idToPath(pathId);
    RepositoryFileDto repositoryFileDto = mock(RepositoryFileDto.class);
    doReturn(fileId).when(repositoryFileDto).getId();
    doReturn(repositoryFileDto).when(fileService.defaultUnifiedRepositoryWebService).getFile(nullable(String.class));
    RepositoryFileDto repositoryFileDto1 = mock(RepositoryFileDto.class);
    doReturn(repositoryFileDto1).when(fileService.defaultUnifiedRepositoryWebService).getFileById(creatorId);
    // Test 1
    RepositoryFileDto repositoryFileDto2 = null;
    try {
        repositoryFileDto2 = fileService.doGetContentCreator(pathId);
    } catch (Exception e) {
        fail();
    }
    assertEquals(repositoryFileDto1, repositoryFileDto2);
    // Test 2
    doReturn(null).when(fileMetadata).get("contentCreator");
    try {
        repositoryFileDto2 = fileService.doGetContentCreator(pathId);
        assertEquals(null, repositoryFileDto2);
    } catch (Exception e) {
        fail();
    }
    // Test 3
    doReturn("").when(fileMetadata).get("contentCreator");
    try {
        repositoryFileDto2 = fileService.doGetContentCreator(pathId);
        assertEquals(null, repositoryFileDto2);
    } catch (Exception e) {
        fail();
    }
    verify(fileService, times(3)).idToPath(pathId);
    verify(fileService.repository, times(3)).getFileMetadata(fileId);
    verify(fileService.defaultUnifiedRepositoryWebService, times(3)).getFile(nullable(String.class));
    verify(fileService.defaultUnifiedRepositoryWebService).getFileById(nullable(String.class));
}
Also used : RepositoryFileDto(org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileDto) Serializable(java.io.Serializable) GeneralSecurityException(java.security.GeneralSecurityException) InvalidParameterException(java.security.InvalidParameterException) IllegalSelectorException(java.nio.channels.IllegalSelectorException) PentahoAccessControlException(org.pentaho.platform.api.engine.PentahoAccessControlException) FileNotFoundException(java.io.FileNotFoundException) ObjectFactoryException(org.pentaho.platform.api.engine.ObjectFactoryException) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

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