Search in sources :

Example 1 with RepositoryFileTreeDto

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

the class UnifiedRepositoryPurgeService method processRevisionDeletion.

private void processRevisionDeletion(PurgeUtilitySpecification purgeSpecification) throws PurgeDeletionException {
    RepositoryRequest repositoryRequest = new RepositoryRequest(purgeSpecification.getPath(), true, -1, purgeSpecification.getFileFilter());
    repositoryRequest.setTypes(FILES_TYPE_FILTER.FILES_FOLDERS);
    repositoryRequest.setIncludeMemberSet(new HashSet<String>(Arrays.asList(new String[] { "name", "id", "folder", "path", "versioned", "versionId", "locked" })));
    getLogger().debug("Creating file list");
    RepositoryFileTreeDto tree = getRepoWs().getTreeFromRequest(repositoryRequest);
    processPurgeForTree(tree, purgeSpecification);
}
Also used : RepositoryFileTreeDto(org.pentaho.platform.repository2.unified.webservices.RepositoryFileTreeDto) RepositoryRequest(org.pentaho.platform.api.repository2.unified.RepositoryRequest)

Example 2 with RepositoryFileTreeDto

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

the class UnifiedRepositoryPurgeService method processPurgeForTree.

private void processPurgeForTree(RepositoryFileTreeDto tree, PurgeUtilitySpecification purgeSpecification) {
    for (RepositoryFileTreeDto child : tree.getChildren()) {
        try {
            if (!child.getChildren().isEmpty()) {
                processPurgeForTree(child, purgeSpecification);
            }
            RepositoryFileDto file = child.getFile();
            getLogger().setCurrentFilePath(file.getPath());
            if (file.isVersioned()) {
                if (purgeSpecification.isPurgeFiles()) {
                    getLogger().info("Purge File");
                    // the latest version will be removed with deleteFileWithPermanentFlag
                    keepNumberOfVersions(file.getId(), 1);
                    getRepoWs().deleteFileWithPermanentFlag(file.getId(), true, "purge utility");
                } else if (purgeSpecification.isPurgeRevisions()) {
                    getLogger().info("Purging Revisions");
                    deleteAllVersions(file.getId());
                } else {
                    if (purgeSpecification.getBeforeDate() != null) {
                        getLogger().info("Checking/purging by Revision date");
                        deleteVersionsBeforeDate(file.getId(), purgeSpecification.getBeforeDate());
                    }
                    if (purgeSpecification.getVersionCount() >= 0) {
                        getLogger().info("Checking/purging by number of Revisions");
                        keepNumberOfVersions(file.getId(), purgeSpecification.getVersionCount());
                    }
                }
            }
        } catch (Exception e) {
            getLogger().error(e);
        }
    }
}
Also used : RepositoryFileDto(org.pentaho.platform.repository2.unified.webservices.RepositoryFileDto) RepositoryFileTreeDto(org.pentaho.platform.repository2.unified.webservices.RepositoryFileTreeDto) KettleException(org.pentaho.di.core.exception.KettleException)

Example 3 with RepositoryFileTreeDto

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

the class FileResourceTest method testDoGetTree.

@Test
public void testDoGetTree() {
    Integer depth = 0;
    String filter = "filter";
    Boolean showHidden = Boolean.TRUE;
    Boolean includeAcls = Boolean.TRUE;
    Boolean includeSysDirs = Boolean.FALSE;
    RepositoryFileTreeDto mockRepositoryFileTreeDto = mock(RepositoryFileTreeDto.class);
    doReturn(mockRepositoryFileTreeDto).when(fileResource.fileService).doGetTree(PATH_ID, depth, filter, showHidden, includeAcls, includeSysDirs);
    RepositoryFileTreeDto testDto = fileResource.doGetTree(PATH_ID, depth, filter, showHidden, includeAcls, includeSysDirs);
    assertEquals(mockRepositoryFileTreeDto, testDto);
    verify(fileResource.fileService).doGetTree(PATH_ID, depth, filter, showHidden, includeAcls, includeSysDirs);
}
Also used : RepositoryFileTreeDto(org.pentaho.platform.repository2.unified.webservices.RepositoryFileTreeDto) Test(org.junit.Test)

Example 4 with RepositoryFileTreeDto

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

the class FileResourceTest method testDoGetRootTree.

@Test
public void testDoGetRootTree() {
    Integer depth = 0;
    String filter = "filter";
    Boolean showHidden = Boolean.TRUE;
    Boolean includeAcls = Boolean.TRUE;
    RepositoryFileTreeDto mockRepositoryFileTreeDto = mock(RepositoryFileTreeDto.class);
    doReturn(mockRepositoryFileTreeDto).when(fileResource.fileService).doGetTree(FileUtils.PATH_SEPARATOR, depth, filter, showHidden, includeAcls);
    RepositoryFileTreeDto testDto = fileResource.doGetRootTree(depth, filter, showHidden, includeAcls);
    assertEquals(mockRepositoryFileTreeDto, testDto);
    verify(fileResource.fileService, times(1)).doGetTree(FileUtils.PATH_SEPARATOR, depth, filter, showHidden, includeAcls);
}
Also used : RepositoryFileTreeDto(org.pentaho.platform.repository2.unified.webservices.RepositoryFileTreeDto) Test(org.junit.Test)

Example 5 with RepositoryFileTreeDto

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

the class UnifiedRepositoryPurgeServiceTest method getPurgeService.

// create the necessary mocks for running a full Purge Utility job
private static UnifiedRepositoryPurgeService getPurgeService(IUnifiedRepository mockRepo) {
    UnifiedRepositoryPurgeService purgeService = new UnifiedRepositoryPurgeService(mockRepo);
    DefaultUnifiedRepositoryWebService mockRepoWs = mock(DefaultUnifiedRepositoryWebService.class);
    UnifiedRepositoryPurgeService.repoWs = mockRepoWs;
    // Create a mocked tree to be returned
    JAXBContext jc;
    RepositoryFileTreeDto tree = null;
    try {
        jc = JAXBContext.newInstance(RepositoryFileTreeDto.class);
        Unmarshaller unmarshaller = jc.createUnmarshaller();
        ByteArrayInputStream xml = new ByteArrayInputStream(treeResponse.getBytes());
        tree = (RepositoryFileTreeDto) unmarshaller.unmarshal(xml);
    } catch (JAXBException e) {
        e.printStackTrace();
        fail("Test class has invalid xml representation of tree");
    }
    when(mockRepoWs.getTreeFromRequest(any(RepositoryRequest.class))).thenReturn(tree);
    return purgeService;
}
Also used : DefaultUnifiedRepositoryWebService(org.pentaho.platform.repository2.unified.webservices.DefaultUnifiedRepositoryWebService) ByteArrayInputStream(java.io.ByteArrayInputStream) RepositoryFileTreeDto(org.pentaho.platform.repository2.unified.webservices.RepositoryFileTreeDto) JAXBException(javax.xml.bind.JAXBException) JAXBContext(javax.xml.bind.JAXBContext) RepositoryRequest(org.pentaho.platform.api.repository2.unified.RepositoryRequest) Unmarshaller(javax.xml.bind.Unmarshaller)

Aggregations

RepositoryFileTreeDto (org.pentaho.platform.repository2.unified.webservices.RepositoryFileTreeDto)9 RepositoryRequest (org.pentaho.platform.api.repository2.unified.RepositoryRequest)4 ArrayList (java.util.ArrayList)3 Test (org.junit.Test)3 RepositoryFileDto (org.pentaho.platform.repository2.unified.webservices.RepositoryFileDto)3 Collator (java.text.Collator)2 RepositoryFileTree (org.pentaho.gwt.widgets.client.filechooser.RepositoryFileTree)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 Serializable (java.io.Serializable)1 HashMap (java.util.HashMap)1 JAXBContext (javax.xml.bind.JAXBContext)1 JAXBException (javax.xml.bind.JAXBException)1 Unmarshaller (javax.xml.bind.Unmarshaller)1 Matchers.anyBoolean (org.mockito.Matchers.anyBoolean)1 Matchers.anyString (org.mockito.Matchers.anyString)1 KettleException (org.pentaho.di.core.exception.KettleException)1 RepositoryFile (org.pentaho.gwt.widgets.client.filechooser.RepositoryFile)1 DefaultUnifiedRepositoryWebService (org.pentaho.platform.repository2.unified.webservices.DefaultUnifiedRepositoryWebService)1