Search in sources :

Example 21 with RepositoryFileDto

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

the class FileResourceTest method testSetContentCreator.

@Test
public void testSetContentCreator() throws Exception {
    RepositoryFileDto mockRepositoryFileDto = mock(RepositoryFileDto.class);
    doNothing().when(fileResource.fileService).doSetContentCreator(PATH_ID, mockRepositoryFileDto);
    Response mockOkResponse = mock(Response.class);
    doReturn(mockOkResponse).when(fileResource).buildOkResponse();
    Response testResponse = fileResource.doSetContentCreator(PATH_ID, mockRepositoryFileDto);
    assertEquals(mockOkResponse, testResponse);
    verify(fileResource.fileService, times(1)).doSetContentCreator(PATH_ID, mockRepositoryFileDto);
    verify(fileResource, times(1)).buildOkResponse();
}
Also used : RepositoryFileDto(org.pentaho.platform.repository2.unified.webservices.RepositoryFileDto) Response(javax.ws.rs.core.Response) Test(org.junit.Test)

Example 22 with RepositoryFileDto

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

the class FileResourceIT method testDeleteFiles.

@Test
public void testDeleteFiles() {
    loginAsRepositoryAdmin();
    ITenant systemTenant = tenantManager.createTenant(null, ServerRepositoryPaths.getPentahoRootFolderName(), adminAuthorityName, authenticatedAuthorityName, "Anonymous");
    userRoleDao.createUser(systemTenant, sysAdminUserName, "password", "", new String[] { adminAuthorityName });
    ITenant mainTenant_1 = tenantManager.createTenant(systemTenant, MAIN_TENANT_1, adminAuthorityName, authenticatedAuthorityName, "Anonymous");
    userRoleDao.createUser(mainTenant_1, "admin", "password", "", new String[] { adminAuthorityName });
    try {
        login("admin", mainTenant_1, new String[] { authenticatedAuthorityName });
        String testFile1Id = "abc.txt";
        String testFile2Id = "def.txt";
        // set object in PentahoSystem
        mp.defineInstance(IUnifiedRepository.class, repo);
        String publicFolderPath = ClientRepositoryPaths.getPublicFolderPath();
        createTestFile(publicFolderPath.replaceAll("/", ":") + ":" + testFile1Id, "abcdefg");
        createTestFile(publicFolderPath.replaceAll("/", ":") + ":" + testFile2Id, "abcdefg");
        createTestFolder(":home:admin");
        RepositoryFile file1 = repo.getFile(publicFolderPath + "/" + testFile1Id);
        RepositoryFile file2 = repo.getFile(publicFolderPath + "/" + testFile2Id);
        WebResource webResource = resource();
        webResource.path("repo/files/delete").entity(file1.getId() + "," + file2.getId()).put();
        RepositoryFileDto[] deletedFiles = webResource.path("repo/files/deleted").accept(APPLICATION_XML).get(RepositoryFileDto[].class);
        assertEquals(2, deletedFiles.length);
        webResource.path("repo/files/deletepermanent").entity(file2.getId()).put();
    } catch (Throwable ex) {
        TestCase.fail();
    } finally {
        cleanupUserAndRoles(mainTenant_1);
        cleanupUserAndRoles(systemTenant);
    }
}
Also used : RepositoryFileDto(org.pentaho.platform.repository2.unified.webservices.RepositoryFileDto) ITenant(org.pentaho.platform.api.mt.ITenant) WebResource(com.sun.jersey.api.client.WebResource) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) JerseyTest(com.sun.jersey.test.framework.JerseyTest) Test(org.junit.Test)

Example 23 with RepositoryFileDto

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

the class RepositoryFileUtils method convertFromRepositoryFile.

public static RepositoryFileDto convertFromRepositoryFile(RepositoryFile file) {
    RepositoryFileDto repositoryFile = new RepositoryFileDto();
    repositoryFile.setCreatedDate(file.getCreatedDate());
    repositoryFile.setDeletedDate(file.getDeletedDate());
    repositoryFile.setDescription(file.getDescription());
    repositoryFile.setFolder(file.isFolder());
    repositoryFile.setHidden(file.isHidden());
    repositoryFile.setAclNode(false);
    repositoryFile.setId(file.getId());
    repositoryFile.setLastModifiedDate(file.getLastModifiedDate());
    repositoryFile.setLocale(file.getLocale());
    repositoryFile.setLockDate(file.getLockDate());
    repositoryFile.setLocked(file.isLocked());
    repositoryFile.setLockMessage(file.getLockMessage());
    repositoryFile.setLockOwner(file.getLockOwner());
    repositoryFile.setName(file.getName());
    repositoryFile.setOriginalParentFolderPath(file.getOriginalParentFolderPath());
    repositoryFile.setOriginalParentFolderPath(file.getOriginalParentFolderPath());
    repositoryFile.setOwner(file.getOwner());
    repositoryFile.setPath(file.getPath());
    repositoryFile.setTitle(file.getTitle());
    repositoryFile.setVersionId(file.getVersionId());
    return repositoryFile;
}
Also used : RepositoryFileDto(org.pentaho.platform.repository2.unified.webservices.RepositoryFileDto)

Example 24 with RepositoryFileDto

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

the class FileService method doGetLocaleProperties.

/**
 * Retrieve the list of locale properties for a given locale
 *
 * @param pathId (colon separated path for the repository file)
 * @param locale
 * @return
 */
public List<StringKeyStringValueDto> doGetLocaleProperties(String pathId, String locale) {
    RepositoryFileDto file = getRepoWs().getFile(idToPath(pathId));
    List<StringKeyStringValueDto> keyValueList = new ArrayList<StringKeyStringValueDto>();
    if (file != null) {
        PropertiesWrapper propertiesWrapper = getRepoWs().getLocalePropertiesForFileById(file.getId(), locale);
        if (propertiesWrapper != null) {
            Properties properties = propertiesWrapper.getProperties();
            if (properties != null && !properties.isEmpty()) {
                for (String key : properties.stringPropertyNames()) {
                    keyValueList.add(getStringKeyStringValueDto(key, properties.getProperty(key)));
                }
            }
        }
    }
    return keyValueList;
}
Also used : RepositoryFileDto(org.pentaho.platform.repository2.unified.webservices.RepositoryFileDto) StringKeyStringValueDto(org.pentaho.platform.repository2.unified.webservices.StringKeyStringValueDto) ArrayList(java.util.ArrayList) PropertiesWrapper(org.pentaho.platform.repository2.unified.webservices.PropertiesWrapper) Properties(java.util.Properties)

Example 25 with RepositoryFileDto

use of org.pentaho.platform.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.repository2.unified.webservices.RepositoryFileDto) ArrayList(java.util.ArrayList) RepositoryRequest(org.pentaho.platform.api.repository2.unified.RepositoryRequest) Collator(java.text.Collator)

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