use of org.pentaho.platform.api.repository2.unified.RepositoryFileTree in project pentaho-kettle by pentaho.
the class PurRepositoryExporter method exportAllObjects.
public synchronized void exportAllObjects(ProgressMonitorListener monitor, String xmlFilename, RepositoryDirectoryInterface root, String exportType) throws KettleException {
initBatchSize();
OutputStream os = null;
OutputStreamWriter writer = null;
try {
os = new BufferedOutputStream(KettleVFS.getOutputStream(xmlFilename, false));
writer = new OutputStreamWriter(os, Const.XML_ENCODING);
if (monitor != null) {
// $NON-NLS-1$
monitor.beginTask("Exporting the repository to XML...", 3);
}
// $NON-NLS-1$
root = root == null ? repository.findDirectory("/") : root;
String path = root.getPath();
RepositoryFileTree repoTree = repository.loadRepositoryFileTree(path);
writer.write(XMLHandler.getXMLHeader());
// $NON-NLS-1$
writer.write("<repository>" + Const.CR + Const.CR);
if (monitor != null) {
monitor.worked(1);
}
if (exportType.equals("all") || exportType.equals("trans")) {
// $NON-NLS-1$ //$NON-NLS-2$
// Dump the transformations...
// $NON-NLS-1$
writer.write("<transformations>" + Const.CR);
// exportAllTransformations(monitor, repoTree, repoDirTree, writer);
export(monitor, repoTree, writer, new TransformationBatchExporter());
// $NON-NLS-1$
writer.write("</transformations>" + Const.CR);
}
if (exportType.equals("all") || exportType.equals("jobs")) {
// $NON-NLS-1$ //$NON-NLS-2$
// Now dump the jobs...
// $NON-NLS-1$
writer.write("<jobs>" + Const.CR);
export(monitor, repoTree, writer, new JobBatchExporter());
// $NON-NLS-1$
writer.write("</jobs>" + Const.CR);
}
// $NON-NLS-1$
writer.write("</repository>" + Const.CR + Const.CR);
if (monitor != null) {
monitor.worked(1);
// $NON-NLS-1$ //$NON-NLS-2$
monitor.subTask("Saving XML to file [" + xmlFilename + "]");
monitor.worked(1);
}
} catch (IOException e) {
// $NON-NLS-1$
log.logError(BaseMessages.getString(PKG, "PurRepositoryExporter.ERROR_CREATE_FILE", xmlFilename), e);
} finally {
try {
if (writer != null) {
writer.close();
}
} catch (Exception e) {
// $NON-NLS-1$
log.logError(BaseMessages.getString(PKG, "PurRepositoryExporter.ERROR_CLOSE_FILE", xmlFilename), e);
}
}
if (monitor != null) {
monitor.done();
}
}
use of org.pentaho.platform.api.repository2.unified.RepositoryFileTree in project pentaho-kettle by pentaho.
the class PurRepositoryExporter method export.
/**
* Export objects by directory, breadth first.
*
* @param monitor
* Feedback handler
* @param root
* Root of repository to export from
* @param writer
* Output stream the exporter uses to serialize repository objects
* @param exporter
* Processes groups of nodes per directory
* @throws KettleException
* error performing export
*/
private void export(final ProgressMonitorListener monitor, final RepositoryFileTree root, final OutputStreamWriter writer, final RepositoryFileBatchExporter exporter) throws KettleException {
List<RepositoryFileTree> subdirectories = new ArrayList<RepositoryFileTree>();
// Assume the repository objects are loaded. If they're null then there are no repository objects in this directory
if (root.getChildren() != null && !root.getChildren().isEmpty()) {
Iterator<RepositoryFileTree> repObjIter = root.getChildren().iterator();
List<RepositoryFile> files = new ArrayList<RepositoryFile>();
// Walk the tree collecting subdirectories and objects to export
while ((monitor == null || !monitor.isCanceled()) && repObjIter.hasNext()) {
RepositoryFileTree repObj = repObjIter.next();
if (repObj.getFile().isFolder()) {
// This is a directory, cache it so we can export it after the current folder's objects
subdirectories.add(repObj);
continue;
} else if (!exporter.canExport(repObj.getFile())) {
// Cannot export this type
continue;
}
files.add(repObj.getFile());
}
if (!files.isEmpty()) {
log.logBasic(BaseMessages.getString(PKG, "PurRepositoryExporter.BASIC_EXPORT_FROM", files.size(), exporter.getFriendlyTypeName(), // $NON-NLS-1$
root.getFile().getPath()));
// Only fetch batchSize transformations at a time
for (int i = 0; (monitor == null || !monitor.isCanceled()) && i < files.size(); i += batchSize) {
int start = i;
int end = Math.min(i + batchSize, files.size());
List<RepositoryFile> group = files.subList(start, end);
if (monitor != null) {
monitor.subTask("Loading " + group.size() + " " + exporter.getFriendlyTypeName() + " from " + // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
root.getFile().getPath());
}
try {
exporter.export(monitor, group, writer);
} catch (KettleException ex) {
log.logError(BaseMessages.getString(PKG, "PurRepositoryExporter.ERROR_EXPORT", exporter.getFriendlyTypeName(), root.getFile().getPath()), // $NON-NLS-1$
ex);
}
}
}
// Export subdirectories
Iterator<RepositoryFileTree> subdirIter = subdirectories.iterator();
while ((monitor == null || !monitor.isCanceled()) && subdirIter.hasNext()) {
export(monitor, subdirIter.next(), writer, exporter);
}
}
}
use of org.pentaho.platform.api.repository2.unified.RepositoryFileTree in project pentaho-platform by pentaho.
the class GeneratedContentCleanerTest method testExecute_noFilesToDelete.
@Test
public void testExecute_noFilesToDelete() throws Exception {
final Date fixedDate = new SimpleDateFormat("d/m/yyyy").parse("1/1/2015");
RepositoryFile file = new RepositoryFile.Builder(DEFAULT_STRING, FILE_ID).folder(false).createdDate(fixedDate).build();
RepositoryFileTree tree = new RepositoryFileTree(file, null);
when(repo.getTree(anyString(), eq(-1), anyString(), eq(true))).thenReturn(tree);
generatedContentCleaner.execute();
verify(repo, never()).deleteFile(any(Serializable.class), eq(true), anyString());
}
use of org.pentaho.platform.api.repository2.unified.RepositoryFileTree in project pentaho-platform by pentaho.
the class GeneratedContentCleanerTest method testExecute_oldFilesInFolderDeleted.
@Test
public void testExecute_oldFilesInFolderDeleted() throws Exception {
final Date fixedDate = new SimpleDateFormat("d/m/yyyy").parse("1/1/2015");
RepositoryFile folder = new RepositoryFile.Builder(FOlDER_ID, DEFAULT_STRING).folder(true).build();
RepositoryFile file = new RepositoryFile.Builder(FILE_ID, DEFAULT_STRING).folder(false).createdDate(fixedDate).build();
RepositoryFileTree childRepoFileTree = new RepositoryFileTree(file, null);
RepositoryFileTree rootRepoFileTree = new RepositoryFileTree(folder, Collections.singletonList(childRepoFileTree));
when(repo.getTree(anyString(), eq(-1), anyString(), eq(true))).thenReturn(rootRepoFileTree);
Map<String, Serializable> values = new HashMap<String, Serializable>();
values.put(QuartzScheduler.RESERVEDMAPKEY_LINEAGE_ID, "lineageIdGoesHere");
when(repo.getFileMetadata(FILE_ID)).thenReturn(values);
generatedContentCleaner.execute();
verify(repo).deleteFile(eq(FILE_ID), eq(true), anyString());
assertEquals(0, generatedContentCleaner.getAge());
}
use of org.pentaho.platform.api.repository2.unified.RepositoryFileTree in project pentaho-platform by pentaho.
the class DefaultUnifiedRepositoryContentIT method testGetTreeWithShowHidden.
@Test
public void testGetTreeWithShowHidden() throws Exception {
RepositoryFileTree root = null;
loginAsSysTenantAdmin();
ITenant tenantAcme = tenantManager.createTenant(systemTenant, TENANT_ID_ACME, tenantAdminRoleName, tenantAuthenticatedRoleName, ANONYMOUS_ROLE_NAME);
userRoleDao.createUser(tenantAcme, USERNAME_ADMIN, PASSWORD, "", new String[] { tenantAdminRoleName });
login(USERNAME_ADMIN, tenantAcme, new String[] { tenantAdminRoleName, tenantAuthenticatedRoleName });
userRoleDao.createUser(tenantAcme, USERNAME_SUZY, PASSWORD, "", null);
login(USERNAME_SUZY, tenantAcme, new String[] { tenantAuthenticatedRoleName });
RepositoryFile publicFolder = repo.getFile(ClientRepositoryPaths.getUserHomeFolderPath(PentahoSessionHolder.getSession().getName()));
final String dataString = "Hello World!";
final String encoding = "UTF-8";
byte[] data = dataString.getBytes(encoding);
ByteArrayInputStream dataStream = new ByteArrayInputStream(data);
final String mimeType = "text/plain";
final SimpleRepositoryFileData content = new SimpleRepositoryFileData(dataStream, encoding, mimeType);
RepositoryFile newFile1 = repo.createFile(publicFolder.getId(), new RepositoryFile.Builder("helloworld.xaction").versioned(true).hidden(true).build(), content, null);
root = repo.getTree(new RepositoryRequest(publicFolder.getPath(), true, -1, null));
assertFalse(root.getChildren().isEmpty());
root = repo.getTree(new RepositoryRequest(publicFolder.getPath(), false, -1, null));
assertTrue(root.getChildren().isEmpty());
}
Aggregations