Search in sources :

Example 11 with StringKeyStringValueDto

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

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

the class FileService method doSetLocaleProperties.

/**
 * Set the list of locale properties for a given locale
 *
 * @param pathId
 * @param locale
 * @param properties
 */
public void doSetLocaleProperties(String pathId, String locale, List<StringKeyStringValueDto> properties) throws Exception {
    RepositoryFileDto file = getRepoWs().getFile(idToPath(pathId));
    Properties fileProperties = new Properties();
    if (properties != null && !properties.isEmpty()) {
        for (StringKeyStringValueDto dto : properties) {
            fileProperties.put(dto.getKey(), dto.getValue());
        }
    }
    getRepoWs().setLocalePropertiesForFileByFileId(file.getId(), locale, fileProperties);
}
Also used : RepositoryFileDto(org.pentaho.platform.repository2.unified.webservices.RepositoryFileDto) StringKeyStringValueDto(org.pentaho.platform.repository2.unified.webservices.StringKeyStringValueDto) Properties(java.util.Properties)

Example 13 with StringKeyStringValueDto

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

the class FileServiceTest method doSetMetadataException.

@Test
public void doSetMetadataException() {
    String pathId = "path:to:file:file1.ext";
    List<StringKeyStringValueDto> stringKeyStringValueDtos = new ArrayList<StringKeyStringValueDto>();
    doReturn("/path/to/file/file1.ext").when(fileService).idToPath(pathId);
    doReturn(false).when(fileService.policy).isAllowed(RepositoryReadAction.NAME);
    doReturn(false).when(fileService.policy).isAllowed(RepositoryCreateAction.NAME);
    doReturn(false).when(fileService.policy).isAllowed(AdministerSecurityAction.NAME);
    RepositoryFileDto file = mock(RepositoryFileDto.class);
    doReturn(file).when(fileService.defaultUnifiedRepositoryWebService).getFile(anyString());
    RepositoryFileAclDto repositoryFileAclDto = mock(RepositoryFileAclDto.class);
    doReturn("sessionName").when(repositoryFileAclDto).getOwner();
    doReturn(repositoryFileAclDto).when(fileService.defaultUnifiedRepositoryWebService).getAcl(anyString());
    IPentahoSession pentahoSession = mock(IPentahoSession.class);
    doReturn(pentahoSession).when(fileService).getSession();
    doReturn("sessionName1").when(pentahoSession).getName();
    try {
        fileService.doSetMetadata(pathId, stringKeyStringValueDtos);
        fail();
    } catch (GeneralSecurityException e) {
    // Should catch the exception
    }
    verify(fileService.defaultUnifiedRepositoryWebService).getFile(anyString());
    verify(fileService.defaultUnifiedRepositoryWebService).getAcl(anyString());
    verify(repositoryFileAclDto).getOwner();
    verify(fileService.policy).isAllowed(anyString());
}
Also used : StringKeyStringValueDto(org.pentaho.platform.repository2.unified.webservices.StringKeyStringValueDto) RepositoryFileDto(org.pentaho.platform.repository2.unified.webservices.RepositoryFileDto) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) RepositoryFileAclDto(org.pentaho.platform.repository2.unified.webservices.RepositoryFileAclDto) GeneralSecurityException(java.security.GeneralSecurityException) ArrayList(java.util.ArrayList) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 14 with StringKeyStringValueDto

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

the class FileServiceTest method doGetMetadataException.

@Test
public void doGetMetadataException() {
    String pathId = "path:to:file:file1.ext";
    doReturn(null).when(fileService.defaultUnifiedRepositoryWebService).getFile(anyString());
    try {
        List<StringKeyStringValueDto> list = fileService.doGetMetadata(pathId);
        fail();
    } catch (FileNotFoundException e) {
    // Should catch exception
    }
    verify(fileService.defaultUnifiedRepositoryWebService).getFile(anyString());
}
Also used : StringKeyStringValueDto(org.pentaho.platform.repository2.unified.webservices.StringKeyStringValueDto) FileNotFoundException(java.io.FileNotFoundException) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 15 with StringKeyStringValueDto

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

the class FileResourceTest method testDoSetMetadataError.

@Test
public void testDoSetMetadataError() throws Exception {
    List<StringKeyStringValueDto> metadata = mock(List.class);
    Response mockUnauthorizedResponse = mock(Response.class);
    doReturn(mockUnauthorizedResponse).when(fileResource).buildStatusResponse(Response.Status.UNAUTHORIZED);
    Throwable mockThrowable = mock(RuntimeException.class);
    String errMsg = "errMsg";
    doReturn(errMsg).when(mockThrowable).getMessage();
    Response mockThrowableResponse = mock(Response.class);
    doReturn(mockThrowableResponse).when(fileResource).buildServerErrorResponse(errMsg);
    // Test 1
    Exception mockGeneralSecurityException = mock(GeneralSecurityException.class);
    doThrow(mockGeneralSecurityException).when(fileResource.fileService).doSetMetadata(PATH_ID, metadata);
    Response testResponse = fileResource.doSetMetadata(PATH_ID, metadata);
    assertEquals(mockUnauthorizedResponse, testResponse);
    // Test 2
    doThrow(mockThrowable).when(fileResource.fileService).doSetMetadata(PATH_ID, metadata);
    testResponse = fileResource.doSetMetadata(PATH_ID, metadata);
    assertEquals(mockThrowableResponse, testResponse);
    verify(fileResource.fileService, times(2)).doSetMetadata(PATH_ID, metadata);
    verify(fileResource, times(1)).buildStatusResponse(Response.Status.UNAUTHORIZED);
    verify(mockThrowable, times(1)).getMessage();
    verify(fileResource, times(1)).buildServerErrorResponse(errMsg);
}
Also used : StringKeyStringValueDto(org.pentaho.platform.repository2.unified.webservices.StringKeyStringValueDto) Response(javax.ws.rs.core.Response) 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

StringKeyStringValueDto (org.pentaho.platform.repository2.unified.webservices.StringKeyStringValueDto)15 RepositoryFileDto (org.pentaho.platform.repository2.unified.webservices.RepositoryFileDto)11 Test (org.junit.Test)9 FileNotFoundException (java.io.FileNotFoundException)7 GeneralSecurityException (java.security.GeneralSecurityException)7 ArrayList (java.util.ArrayList)7 Matchers.anyString (org.mockito.Matchers.anyString)6 IOException (java.io.IOException)4 Serializable (java.io.Serializable)4 IllegalSelectorException (java.nio.channels.IllegalSelectorException)4 InvalidParameterException (java.security.InvalidParameterException)4 Properties (java.util.Properties)4 PentahoAccessControlException (org.pentaho.platform.api.engine.PentahoAccessControlException)4 UnifiedRepositoryAccessDeniedException (org.pentaho.platform.api.repository2.unified.UnifiedRepositoryAccessDeniedException)4 RepositoryFileAclDto (org.pentaho.platform.repository2.unified.webservices.RepositoryFileAclDto)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 HashMap (java.util.HashMap)2 WebApplicationException (javax.ws.rs.WebApplicationException)2 Response (javax.ws.rs.core.Response)2 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)2