use of org.pentaho.platform.api.repository2.unified.UnifiedRepositoryException 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.UnifiedRepositoryException in project pentaho-platform by pentaho.
the class FileSystemRepositoryFileDao method setFileMetadata.
public void setFileMetadata(final Serializable fileId, Map<String, Serializable> metadataMap) {
final File targetFile = new File(fileId.toString());
if (targetFile.exists()) {
FileOutputStream fos = null;
try {
final File metadataDir = new File(targetFile.getParent() + File.separatorChar + ".metadata");
if (!metadataDir.exists()) {
metadataDir.mkdir();
}
final File metadataFile = new File(metadataDir, targetFile.getName());
if (!metadataFile.exists()) {
metadataFile.createNewFile();
}
final StringBuilder data = new StringBuilder();
for (String key : metadataMap.keySet()) {
data.append(key).append('=');
if (metadataMap.get(key) != null) {
data.append(metadataMap.get(key).toString());
}
data.append('\n');
}
fos = new FileOutputStream(metadataFile);
fos.write(data.toString().getBytes());
} catch (FileNotFoundException e) {
throw new UnifiedRepositoryException("Error writing file metadata [" + fileId + "]", e);
} catch (IOException e) {
throw new UnifiedRepositoryException("Error writing file metadata [" + fileId + "]", e);
} finally {
IOUtils.closeQuietly(fos);
}
}
}
use of org.pentaho.platform.api.repository2.unified.UnifiedRepositoryException 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.UnifiedRepositoryException 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.UnifiedRepositoryException in project pentaho-platform by pentaho.
the class FileSystemRepositoryFileDao method getData.
@SuppressWarnings("unchecked")
public <T extends IRepositoryFileData> T getData(Serializable fileId, Serializable versionId, Class<T> dataClass) {
File f = new File(fileId.toString());
T data = null;
try {
if (SimpleRepositoryFileData.class.getName().equals(dataClass.getName())) {
data = (T) new SimpleRepositoryFileData(new FileInputStream(f), "UTF-8", "text/plain");
} else if (NodeRepositoryFileData.class.getName().equals(dataClass.getName())) {
throw new UnsupportedOperationException("This operation is not support by this repository");
}
} catch (FileNotFoundException e) {
throw new UnifiedRepositoryException(e);
}
return data;
}
Aggregations