use of org.pentaho.platform.api.repository2.unified.data.node.NodeRepositoryFileData in project pentaho-platform by pentaho.
the class JcrBackedDatasourceMgmtService method getDatasources.
public List<IDatabaseConnection> getDatasources() throws DatasourceMgmtServiceException {
try {
List<IDatabaseConnection> datasourceList = new ArrayList<IDatabaseConnection>();
List<RepositoryFile> repositoryFiles = getRepositoryFiles();
if (repositoryFiles != null) {
for (RepositoryFile file : repositoryFiles) {
NodeRepositoryFileData data = repository.getDataForRead(file.getId(), NodeRepositoryFileData.class);
IDatabaseConnection databaseConnection = databaseHelper.dataNodeToDatabaseConnection(file.getId(), file.getTitle(), data.getNode());
// IPasswordService passwordService = PentahoSystem.get(IPasswordService.class,
// PentahoSessionHolder.getSession());
// databaseMeta.setPassword(passwordService.decrypt(databaseMeta.getPassword()));
datasourceList.add(databaseConnection);
}
}
return datasourceList;
// } catch(PasswordServiceException pse) {
// throw new DatasourceMgmtServiceException(Messages.getInstance()
// .getErrorString("DatasourceMgmtService.ERROR_0008_UNABLE_TO_DECRYPT_PASSWORD"), pse ); //$NON-NLS-1$
} catch (UnifiedRepositoryException ure) {
throw new DatasourceMgmtServiceException(Messages.getInstance().getErrorString("DatasourceMgmtService.ERROR_0004_UNABLE_TO_RETRIEVE_DATASOURCE", "", ure.getLocalizedMessage()), // $NON-NLS-1$ //$NON-NLS-2$
ure);
}
}
use of org.pentaho.platform.api.repository2.unified.data.node.NodeRepositoryFileData in project pentaho-platform by pentaho.
the class JcrBackedDatasourceMgmtService method createDatasource.
public String createDatasource(IDatabaseConnection databaseConnection) throws DuplicateDatasourceException, DatasourceMgmtServiceException {
try {
// IPasswordService passwordService = PentahoSystem.get(IPasswordService.class,
// PentahoSessionHolder.getSession());
// databaseMeta.setPassword(passwordService.encrypt(databaseMeta.getPassword()));
RepositoryFile file = new RepositoryFile.Builder(RepositoryFilenameUtils.escape(databaseConnection.getName() + RepositoryObjectType.DATABASE.getExtension(), cachedReservedChars)).title(RepositoryFile.DEFAULT_LOCALE, databaseConnection.getName()).versioned(true).build();
file = repository.createFile(getDatabaseParentFolderId(), file, new NodeRepositoryFileData(databaseHelper.databaseConnectionToDataNode(databaseConnection)), null);
if (file != null && file.getId() != null) {
return file.getId().toString();
} else {
return null;
}
// } catch(PasswordServiceException pse) {
// throw new DatasourceMgmtServiceException(Messages.getInstance().getErrorString(
// "DatasourceMgmtService.ERROR_0007_UNABLE_TO_ENCRYPT_PASSWORD"), pse ); //$NON-NLS-1$
} catch (UnifiedRepositoryException ure) {
if (ure.getCause().toString().contains("ItemExistsException")) {
throw new DuplicateDatasourceException();
}
throw new DatasourceMgmtServiceException(Messages.getInstance().getErrorString("DatasourceMgmtService.ERROR_0001_UNABLE_TO_CREATE_DATASOURCE", databaseConnection.getName(), ure.getLocalizedMessage()), // $NON-NLS-1$
ure);
}
}
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);
}
Aggregations