Search in sources :

Example 51 with RepositoryFileDto

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

Example 52 with RepositoryFileDto

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

Example 53 with RepositoryFileDto

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

the class FileResourceTest method testDoGetPropertiesError.

@Test
public void testDoGetPropertiesError() throws Exception {
    Exception mockFileNotFoundException = mock(FileNotFoundException.class);
    doThrow(mockFileNotFoundException).when(fileResource.fileService).doGetProperties(PATH_ID);
    Messages mockMessages = mock(Messages.class);
    doReturn(mockMessages).when(fileResource).getMessagesInstance();
    RepositoryFileDto testDto = fileResource.doGetProperties(PATH_ID);
    assertNull(testDto);
    verify(fileResource.fileService, times(1)).doGetProperties(PATH_ID);
    verify(fileResource, times(1)).getMessagesInstance();
    verify(mockMessages, times(1)).getString("SystemResource.GENERAL_ERROR");
}
Also used : RepositoryFileDto(org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileDto) Messages(org.pentaho.platform.web.http.messages.Messages) 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) WebApplicationException(javax.ws.rs.WebApplicationException) IllegalSelectorException(java.nio.channels.IllegalSelectorException) IOException(java.io.IOException) NoSuchBeanDefinitionException(org.springframework.beans.factory.NoSuchBeanDefinitionException) Test(org.junit.Test)

Example 54 with RepositoryFileDto

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

the class FileResourceTest method testDoGetContentCreator.

@Test
public void testDoGetContentCreator() throws Exception {
    RepositoryFileDto mockRepositoryFileDto = mock(RepositoryFileDto.class);
    doReturn(mockRepositoryFileDto).when(fileResource.fileService).doGetContentCreator(PATH_ID);
    RepositoryFileDto testDto = fileResource.doGetContentCreator(PATH_ID);
    assertEquals(mockRepositoryFileDto, testDto);
    verify(fileResource.fileService, times(1)).doGetContentCreator(PATH_ID);
}
Also used : RepositoryFileDto(org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileDto) Test(org.junit.Test)

Example 55 with RepositoryFileDto

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

the class FileResourceTest method testSetContentCreatorError.

@Test
public void testSetContentCreatorError() throws Exception {
    RepositoryFileDto mockRepositoryFileDto = mock(RepositoryFileDto.class);
    Response mockNotFoundResponse = mock(Response.class);
    doReturn(mockNotFoundResponse).when(fileResource).buildStatusResponse(Response.Status.NOT_FOUND);
    Response mockInternalServerErrorResponse = mock(Response.class);
    doReturn(mockInternalServerErrorResponse).when(fileResource).buildStatusResponse(INTERNAL_SERVER_ERROR);
    Messages mockMessages = mock(Messages.class);
    doReturn(mockMessages).when(fileResource).getMessagesInstance();
    // Test 1
    Exception mockFileNotFoundException = mock(FileNotFoundException.class);
    doThrow(mockFileNotFoundException).when(fileResource.fileService).doSetContentCreator(PATH_ID, mockRepositoryFileDto);
    Response testResponse = fileResource.doSetContentCreator(PATH_ID, mockRepositoryFileDto);
    assertEquals(mockNotFoundResponse, testResponse);
    // Test 2
    Throwable mockThrowable = mock(RuntimeException.class);
    doThrow(mockThrowable).when(fileResource.fileService).doSetContentCreator(PATH_ID, mockRepositoryFileDto);
    testResponse = fileResource.doSetContentCreator(PATH_ID, mockRepositoryFileDto);
    assertEquals(mockInternalServerErrorResponse, testResponse);
    verify(fileResource, times(1)).buildStatusResponse(Response.Status.NOT_FOUND);
    verify(fileResource, times(1)).buildStatusResponse(INTERNAL_SERVER_ERROR);
    verify(fileResource.fileService, times(2)).doSetContentCreator(PATH_ID, mockRepositoryFileDto);
    verify(mockMessages, times(1)).getErrorString("FileResource.FILE_NOT_FOUND", PATH_ID);
    verify(mockMessages, times(1)).getString("SystemResource.GENERAL_ERROR");
}
Also used : RepositoryFileDto(org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileDto) Response(javax.ws.rs.core.Response) Messages(org.pentaho.platform.web.http.messages.Messages) 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) WebApplicationException(javax.ws.rs.WebApplicationException) IllegalSelectorException(java.nio.channels.IllegalSelectorException) IOException(java.io.IOException) NoSuchBeanDefinitionException(org.springframework.beans.factory.NoSuchBeanDefinitionException) Test(org.junit.Test)

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