use of org.pentaho.platform.api.repository2.unified.IRepositoryFileData in project pentaho-kettle by pentaho.
the class StreamToJobNodeConverter method convert.
/**
* @param inputStream
* @param charset
* @param mimeType
* @return
*/
public IRepositoryFileData convert(final InputStream inputStream, final String charset, final String mimeType) {
try {
long size = inputStream.available();
JobMeta jobMeta = new JobMeta();
Repository repository = connectToRepository();
Document doc = PDIImportUtil.loadXMLFrom(inputStream);
if (doc != null) {
jobMeta.loadXML(doc.getDocumentElement(), repository, null);
JobDelegate delegate = new JobDelegate(repository, this.unifiedRepository);
delegate.saveSharedObjects(jobMeta, null);
return new NodeRepositoryFileData(delegate.elementToDataNode(jobMeta), size);
} else {
return null;
}
} catch (Exception e) {
return null;
}
}
use of org.pentaho.platform.api.repository2.unified.IRepositoryFileData in project pentaho-platform by pentaho.
the class RepositoryFileImportFileHandler method createFile.
/**
* Creates a new file in the repository
*
* @param bundle
* @param data
*/
protected RepositoryFile createFile(final RepositoryFileImportBundle bundle, final String repositoryPath, final IRepositoryFileData data) throws PlatformImportException {
if (solutionHelper.isInApprovedExtensionList(repositoryPath)) {
final RepositoryFile file = new RepositoryFile.Builder(bundle.getName()).hidden(isHiddenBundle(bundle)).schedulable(bundle.isSchedulable()).title(RepositoryFile.DEFAULT_LOCALE, getTitle(bundle.getTitle() != null ? bundle.getTitle() : bundle.getName())).versioned(true).build();
final Serializable parentId = checkAndCreatePath(repositoryPath, getImportSession().getCurrentManifestKey());
final RepositoryFileAcl acl = bundle.getAcl();
if (null == acl) {
return repository.createFile(parentId, file, data, bundle.getComment());
} else {
return repository.createFile(parentId, file, data, acl, bundle.getComment());
}
} else {
getLogger().trace("The file [" + repositoryPath + "] is not in the list of approved file extension that can be stored in the repository.");
return null;
}
}
use of org.pentaho.platform.api.repository2.unified.IRepositoryFileData in project pentaho-platform by pentaho.
the class MondrianCatalogRepositoryHelper method addHostedCatalog.
public void addHostedCatalog(InputStream mondrianFile, String catalogName, String datasourceInfo) throws Exception {
RepositoryFile catalog = createCatalog(catalogName, datasourceInfo);
File tempFile = File.createTempFile("tempFile", null);
tempFile.deleteOnExit();
FileOutputStream outputStream = new FileOutputStream(tempFile);
IOUtils.copy(mondrianFile, outputStream);
RepositoryFile repoFile = new RepositoryFile.Builder("schema.xml").build();
org.pentaho.platform.plugin.services.importexport.RepositoryFileBundle repoFileBundle = new org.pentaho.platform.plugin.services.importexport.RepositoryFileBundle(repoFile, null, ETC_MONDRIAN_JCR_FOLDER + RepositoryFile.SEPARATOR + catalogName + RepositoryFile.SEPARATOR, tempFile, "UTF-8", "text/xml");
RepositoryFile schema = repository.getFile(ETC_MONDRIAN_JCR_FOLDER + RepositoryFile.SEPARATOR + catalogName + RepositoryFile.SEPARATOR + "schema.xml");
IRepositoryFileData data = new StreamConverter().convert(repoFileBundle.getInputStream(), repoFileBundle.getCharset(), repoFileBundle.getMimeType());
if (schema == null) {
RepositoryFile schemaFile = repository.createFile(catalog.getId(), repoFileBundle.getFile(), data, null);
if (schemaFile != null) {
// make sure the folder is not set to hidden if the schema is not hidden
RepositoryFile catalogFolder = repository.getFile(ETC_MONDRIAN_JCR_FOLDER + RepositoryFile.SEPARATOR + catalogName);
if (catalogFolder.isHidden() != schemaFile.isHidden()) {
RepositoryFile unhiddenFolder = (new RepositoryFile.Builder(catalogFolder)).hidden(schemaFile.isHidden()).build();
repository.updateFolder(unhiddenFolder, "");
}
}
} else {
repository.updateFile(schema, data, null);
}
}
use of org.pentaho.platform.api.repository2.unified.IRepositoryFileData in project pentaho-platform by pentaho.
the class OlapServiceImplTest method testImportHostedOverwriteFlag.
/**
* Verifies that we can create locally hosted mondrian instances.
*/
@Test
public void testImportHostedOverwriteFlag() throws Exception {
final String testFolderPath = mondrianFolderPath + RepositoryFile.SEPARATOR + "myHostedServer";
// Stub the hosted server
stubGetChildren(repository, mondrianFolderPath, "myHostedServer");
final String testServerPath = mondrianFolderPath + RepositoryFile.SEPARATOR + "myHostedServer";
stubGetFolder(repository, testServerPath);
stubGetChildren(repository, testServerPath, "metadata");
final String metadataPath = testServerPath + RepositoryFile.SEPARATOR + "metadata";
stubGetFile(repository, metadataPath);
stubGetFile(repository, testFolderPath + RepositoryFile.SEPARATOR + "schema.xml");
stubGetData(repository, metadataPath, "catalog", pathPropertyPair("/catalog/definition", "mondrian:/SteelWheels"), pathPropertyPair("/catalog/datasourceInfo", "Provider=mondrian;DataSource=SteelWheels;"));
final InputStream is = this.getClass().getResourceAsStream("/solution/security/steelwheels.mondrian.xml");
// Try to save it without the overwrite flag. We expect it to fail.
try {
olapService.addHostedCatalog("myHostedServer", "Provider=mondrian;DataSource=SampleData", is, false, session);
fail();
} catch (IOlapServiceException e) {
assertEquals(IOlapServiceException.Reason.ALREADY_EXISTS, e.getReason());
assertTrue(e.getMessage().contains("OlapServiceImpl.ERROR_0004"));
}
// Make sure we didn't invoke the update or write methods.
verify(repository, never()).updateFile((RepositoryFile) anyObject(), (IRepositoryFileData) anyObject(), anyString());
verify(repository, never()).createFile((RepositoryFile) anyObject(), (RepositoryFile) anyObject(), (IRepositoryFileData) anyObject(), anyString());
// Now do it again.
olapService.addHostedCatalog("myHostedServer", "Provider=mondrian;DataSource=SampleData", is, true, session);
verify(repository).updateFile(argThat(isLikeFile(makeFileObject(metadataPath))), argThat(hasData(pathPropertyPair("/catalog/definition", "mondrian:/" + "myHostedServer"), pathPropertyPair("/catalog/datasourceInfo", "Provider=mondrian;DataSource=SampleData"))), anyString());
verify(repository).updateFile(argThat(isLikeFile(makeFileObject(testFolderPath + RepositoryFile.SEPARATOR + "schema.xml"))), any(IRepositoryFileData.class), anyString());
}
use of org.pentaho.platform.api.repository2.unified.IRepositoryFileData in project pentaho-platform by pentaho.
the class ZipExportProcessorTest method init.
@Before
public void init() throws IOException, PlatformInitializationException, DomainIdNullException, DomainAlreadyExistsException, DomainStorageException {
List<Locale> availableLocales = java.util.Collections.singletonList(LOCALE_DEFAULT);
Properties localePropertries = new Properties();
localePropertries.setProperty("name1", "value1");
final RepositoryFile file0 = new RepositoryFile.Builder("").path("/").id("/").folder(true).build();
final RepositoryFile file1 = new RepositoryFile.Builder("home").path("/home/").id("/home/").folder(true).build();
final RepositoryFile file2 = new RepositoryFile.Builder("test user").path("/home/test user/").id("/home/test user/").folder(true).build();
final RepositoryFile file3 = new RepositoryFile.Builder("two words").path("/home/test user/two words/").id("/home/test user/two words/").folder(true).build();
final RepositoryFile fileX = new RepositoryFile.Builder("eval (+)%.prpt").path("/home/test user/two words/eval (+)%.prpt").id("/home/test user/two words/eval (+)%.prpt").folder(false).build();
final RepositoryFile[] repoFiles = new RepositoryFile[] { file0, file1, file2, file3, fileX };
final Map<Serializable, RepositoryFile> repoFilesMap = new HashMap<Serializable, RepositoryFile>();
for (RepositoryFile f : repoFiles) {
repoFilesMap.put(f.getId(), f);
}
repo = mock(IUnifiedRepository.class);
final Answer<RepositoryFile> answerRepoGetFile = new Answer<RepositoryFile>() {
@Override
public RepositoryFile answer(InvocationOnMock invocation) throws Throwable {
Object[] args = invocation.getArguments();
final Object fileId = args[0];
return getRepoFile(repoFilesMap, fileId);
}
};
Mockito.doAnswer(answerRepoGetFile).when(repo).getFile(anyString());
Mockito.doAnswer(answerRepoGetFile).when(repo).getFile(anyString(), Mockito.anyBoolean());
Mockito.doAnswer(answerRepoGetFile).when(repo).getFile(anyString(), Mockito.anyBoolean(), any(IPentahoLocale.class));
Mockito.doAnswer(answerRepoGetFile).when(repo).getFile(anyString(), any(IPentahoLocale.class));
Mockito.doAnswer(answerRepoGetFile).when(repo).getFileById(any(Serializable.class));
Mockito.doAnswer(answerRepoGetFile).when(repo).getFileById(any(Serializable.class), Mockito.anyBoolean());
Mockito.doAnswer(answerRepoGetFile).when(repo).getFileById(any(Serializable.class), Mockito.anyBoolean(), any(IPentahoLocale.class));
Mockito.doAnswer(answerRepoGetFile).when(repo).getFileById(any(Serializable.class), any(IPentahoLocale.class));
Answer<List<RepositoryFile>> answerRepoGetChildren = new Answer<List<RepositoryFile>>() {
@Override
public List<RepositoryFile> answer(InvocationOnMock invocation) throws Throwable {
// returns the following item from <repoFiles>
RepositoryRequest r = (RepositoryRequest) invocation.getArguments()[0];
String path = r.getPath();
RepositoryFile thisFile = getRepoFile(repoFilesMap, path);
if (thisFile == null || !thisFile.isFolder()) {
return Collections.emptyList();
}
for (int i = 0, n = repoFiles.length - 1; i < n; i++) {
RepositoryFile iFile = repoFiles[i];
if (iFile == thisFile || iFile.getId().equals(thisFile.getId())) {
return Collections.singletonList(repoFiles[i + 1]);
}
}
return Collections.emptyList();
}
};
Mockito.doAnswer(answerRepoGetChildren).when(repo).getChildren(any(RepositoryRequest.class));
doReturn(availableLocales).when(repo).getAvailableLocalesForFile(Mockito.any(RepositoryFile.class));
doReturn(availableLocales).when(repo).getAvailableLocalesForFileById(Mockito.any(Serializable.class));
doReturn(availableLocales).when(repo).getAvailableLocalesForFileByPath(Mockito.any(String.class));
doReturn(localePropertries).when(repo).getLocalePropertiesForFileById(Mockito.any(File.class), Mockito.anyString());
RepositoryFileSid sid = mock(RepositoryFileSid.class);
doReturn("testUser").when(sid).getName();
doReturn(Type.USER).when(sid).getType();
final RepositoryFileAcl mockAcl = mock(RepositoryFileAcl.class);
doReturn(sid).when(mockAcl).getOwner();
doReturn(mockAcl).when(repo).getAcl(any(Serializable.class));
Answer<IRepositoryFileData> answerGetDataForRead = new Answer<IRepositoryFileData>() {
@Override
public IRepositoryFileData answer(InvocationOnMock invocation) throws Throwable {
Serializable id = (Serializable) invocation.getArguments()[0];
RepositoryFile file = getRepoFile(repoFilesMap, id);
if (!file.isFolder()) {
return new SimpleRepositoryFileData(new ByteArrayInputStream(new byte[0]), "UTF-8", MIME_PRPT.getName());
}
return null;
}
};
doAnswer(answerGetDataForRead).when(repo).getDataForRead(Mockito.any(Serializable.class), Mockito.any(Class.class));
exportHandler = new DefaultExportHandler();
defaultConverter = new StreamConverter(repo);
PentahoSystem.clearObjectFactory();
microPlatform = new MicroPlatform(getSolutionPath());
microPlatform.defineInstance(IUnifiedRepository.class, repo);
// microPlatform.defineInstance( IPlatformMimeResolver.class, mimeResolver );
microPlatform.defineInstance(ISolutionEngine.class, Mockito.mock(SolutionEngine.class));
microPlatform.defineInstance(IDatasourceMgmtService.class, Mockito.mock(IDatasourceMgmtService.class));
microPlatform.start();
exportSession = new StandaloneSession();
PentahoSessionHolder.setStrategyName(PentahoSessionHolder.MODE_GLOBAL);
PentahoSessionHolder.setSession(exportSession);
}
Aggregations