use of org.pentaho.platform.api.repository2.unified.data.node.NodeRepositoryFileData in project pentaho-platform by pentaho.
the class FileSystemRepositoryFileDao method updateFile.
public RepositoryFile updateFile(RepositoryFile file, IRepositoryFileData data, String versionMessage) {
File f = new File(file.getId().toString());
FileOutputStream fos = null;
try {
fos = new FileOutputStream(f, false);
if (data instanceof SimpleRepositoryFileData) {
fos.write(inputStreamToBytes(((SimpleRepositoryFileData) data).getInputStream()));
} else if (data instanceof NodeRepositoryFileData) {
fos.write(inputStreamToBytes(new ByteArrayInputStream(((NodeRepositoryFileData) data).getNode().toString().getBytes())));
}
} catch (FileNotFoundException e) {
throw new UnifiedRepositoryException(e);
} catch (IOException e) {
throw new UnifiedRepositoryException(e);
} finally {
IOUtils.closeQuietly(fos);
}
return getFile(file.getPath());
}
use of org.pentaho.platform.api.repository2.unified.data.node.NodeRepositoryFileData in project pentaho-platform by pentaho.
the class FileSystemRepositoryFileDao method createFile.
public RepositoryFile createFile(Serializable parentFolderId, RepositoryFile file, IRepositoryFileData data, RepositoryFileAcl acl, String versionMessage) {
String fileNameWithPath = RepositoryFilenameUtils.concat(parentFolderId.toString(), file.getName());
FileOutputStream fos = null;
File f = new File(fileNameWithPath);
try {
f.createNewFile();
fos = new FileOutputStream(f);
if (data instanceof SimpleRepositoryFileData) {
fos.write(inputStreamToBytes(((SimpleRepositoryFileData) data).getInputStream()));
} else if (data instanceof NodeRepositoryFileData) {
fos.write(inputStreamToBytes(new ByteArrayInputStream(((NodeRepositoryFileData) data).getNode().toString().getBytes())));
}
} catch (FileNotFoundException e) {
throw new UnifiedRepositoryException("Error writing file [" + fileNameWithPath + "]", e);
} catch (IOException e) {
throw new UnifiedRepositoryException("Error writing file [" + fileNameWithPath + "]", e);
} finally {
IOUtils.closeQuietly(fos);
}
return internalGetFile(f);
}
use of org.pentaho.platform.api.repository2.unified.data.node.NodeRepositoryFileData in project pentaho-platform by pentaho.
the class UnifiedRepositoryTestUtils method stubGetData.
/**
* Stubs a {@code getDataForRead} call. The pairs specified will be used to construct a
* {@code NodeRepositoryFileData} .
*/
public static void stubGetData(final IUnifiedRepository repo, final String path, final String rootNodeName, final PathPropertyPair... pairs) {
final String prefix = RepositoryFile.SEPARATOR + rootNodeName;
DataNode rootNode = new DataNode(rootNodeName);
for (PathPropertyPair pair : pairs) {
if (!pair.getPath().startsWith(prefix)) {
throw new IllegalArgumentException("all paths must have a common prefix");
}
String[] pathSegments = pair.getPath().substring(prefix.length() + 1).split("/");
addChild(rootNode, pair.getProperty(), pathSegments, 0);
}
doReturn(new NodeRepositoryFileData(rootNode)).when(repo).getDataForRead(makeIdObject(path), NodeRepositoryFileData.class);
}
use of org.pentaho.platform.api.repository2.unified.data.node.NodeRepositoryFileData in project pentaho-platform by pentaho.
the class JcrBackedDatasourceMgmtServiceTest method testgetDatasourceById.
private void testgetDatasourceById(boolean throwException) throws Exception {
final String dotKdb = ".kdb";
IUnifiedRepository repo = mock(IUnifiedRepository.class);
NodeRepositoryFileData nodeRep = mock(NodeRepositoryFileData.class);
DataNode dataNode = mock(DataNode.class);
// stub out get parent folder
doReturn(new RepositoryFile.Builder("123", "databases").folder(true).build()).when(repo).getFileById(EXP_FILE_ID);
doReturn(reservedChars).when(repo).getReservedChars();
// stub out get file to delete
doReturn(new RepositoryFile.Builder(EXP_FILE_ID, EXP_DBMETA_NAME + dotKdb).build()).when(repo).getFileById(EXP_FILE_ID);
doReturn(nodeRep).when(repo).getDataForRead(any(), any());
doReturn(dataNode).when(nodeRep).getNode();
IDatasourceMgmtService datasourceMgmtService = new JcrBackedDatasourceMgmtService(repo, new DatabaseDialectService());
if (throwException) {
getDatasourceWithIdThrowException(repo);
}
assertNotNull(datasourceMgmtService.getDatasourceById(EXP_FILE_ID));
}
use of org.pentaho.platform.api.repository2.unified.data.node.NodeRepositoryFileData in project pentaho-platform by pentaho.
the class MondrianCatalogRepositoryHelper method addOlap4jServer.
public void addOlap4jServer(String name, String className, String URL, String user, String password, Properties props) {
final RepositoryFile etcOlapServers = repository.getFile(ETC_OLAP_SERVERS_JCR_FOLDER);
RepositoryFile entry = repository.getFile(ETC_OLAP_SERVERS_JCR_FOLDER + RepositoryFile.SEPARATOR + name);
if (entry == null) {
entry = repository.createFolder(etcOlapServers.getId(), new RepositoryFile.Builder(name).folder(true).build(), "Creating entry for olap server: " + name + " into folder " + ETC_OLAP_SERVERS_JCR_FOLDER);
}
final String path = ETC_OLAP_SERVERS_JCR_FOLDER + RepositoryFile.SEPARATOR + name + RepositoryFile.SEPARATOR + "metadata";
// Convert the properties to a serializable XML format.
final String xmlProperties;
final ByteArrayOutputStream os = new ByteArrayOutputStream();
try {
props.storeToXML(os, "Connection properties for server: " + name, "UTF-8");
xmlProperties = os.toString("UTF-8");
} catch (IOException e) {
// Very bad. Just throw.
throw new RuntimeException(e);
} finally {
try {
os.close();
} catch (IOException e) {
// Don't care. Just cleaning up.
}
}
final DataNode node = new DataNode("server");
node.setProperty("name", name);
node.setProperty("className", className);
node.setProperty("URL", URL);
node.setProperty("user", user);
node.setProperty("password", password);
node.setProperty("properties", xmlProperties);
NodeRepositoryFileData data = new NodeRepositoryFileData(node);
final RepositoryFile metadata = repository.getFile(path);
if (metadata == null) {
repository.createFile(entry.getId(), new RepositoryFile.Builder("metadata").build(), data, "Creating olap-server metadata for server " + name);
} else {
repository.updateFile(metadata, data, "Updating olap-server metadata for server " + name);
}
}
Aggregations