use of org.pentaho.platform.api.repository2.unified.UnifiedRepositoryException in project pentaho-platform by pentaho.
the class PentahoMetadataDomainRepository method loadProperties.
protected Properties loadProperties(final RepositoryFile bundle) {
try {
Properties properties = null;
final SimpleRepositoryFileData bundleData = repository.getDataForRead(bundle.getId(), SimpleRepositoryFileData.class);
if (bundleData != null) {
properties = new Properties();
properties.load(bundleData.getStream());
} else {
if (logger.isWarnEnabled()) {
logger.warn("Could not load properties from repository file: " + bundle.getName());
}
}
return properties;
} catch (IOException e) {
throw new UnifiedRepositoryException(messages.getErrorString("PentahoMetadataDomainRepository.ERROR_0008_ERROR_IN_REPOSITORY", e.getLocalizedMessage()), e);
}
}
use of org.pentaho.platform.api.repository2.unified.UnifiedRepositoryException in project pentaho-platform by pentaho.
the class PentahoMetadataDomainRepository method getDomain.
/**
* retrieve a domain from the repo. This does lazy loading of the repo, so it calls reloadDomains() if not already
* loaded.
*
* @param domainId domain to get from the repository
* @return domain object
*/
@Override
public Domain getDomain(final String domainId) {
if (logger.isDebugEnabled()) {
logger.debug("getDomain(" + domainId + ")");
}
if (StringUtils.isEmpty(domainId)) {
throw new IllegalArgumentException(messages.getErrorString("PentahoMetadataDomainRepository.ERROR_0004_DOMAIN_ID_INVALID", domainId));
}
Domain domain = null;
try {
// Load the domain file
final RepositoryFile file = getMetadataRepositoryFile(domainId);
if (file != null) {
if (hasAccessFor(file)) {
SimpleRepositoryFileData data = repository.getDataForRead(file.getId(), SimpleRepositoryFileData.class);
if (data != null) {
InputStream is = data.getStream();
try {
domain = xmiParser.parseXmi(is);
} finally {
IOUtils.closeQuietly(is);
}
domain.setId(domainId);
logger.debug("loaded domain");
// Load any I18N bundles
loadLocaleStrings(domainId, domain);
logger.debug("loaded I18N bundles");
} else {
throw new UnifiedRepositoryException(messages.getErrorString("PentahoMetadataDomainRepository.ERROR_0005_ERROR_RETRIEVING_DOMAIN", domainId, "data not found"));
}
} else {
throw new PentahoAccessControlException(messages.getErrorString("PentahoMetadataDomainRepository.ERROR_0005_ERROR_RETRIEVING_DOMAIN", domainId, "access denied"));
}
}
} catch (Exception e) {
if (!(e instanceof UnifiedRepositoryException || e instanceof PentahoAccessControlException)) {
throw new UnifiedRepositoryException(messages.getErrorString("PentahoMetadataDomainRepository.ERROR_0005_ERROR_RETRIEVING_DOMAIN", domainId, e.getLocalizedMessage()), e);
}
}
// Return
return domain;
}
use of org.pentaho.platform.api.repository2.unified.UnifiedRepositoryException in project pentaho-platform by pentaho.
the class SchedulerResourceTest method testBlockoutWillFireError.
@Test
public void testBlockoutWillFireError() throws Exception {
JobScheduleRequest mockJobScheduleRequest = mock(JobScheduleRequest.class);
UnifiedRepositoryException mockUnifiedRepositoryException = mock(UnifiedRepositoryException.class);
SchedulerException mockSchedulerException = mock(SchedulerException.class);
Response mockUnifiedRepositoryExceptionResponse = mock(Response.class);
doReturn(mockUnifiedRepositoryExceptionResponse).when(schedulerResource).buildServerErrorResponse(mockUnifiedRepositoryException);
Response mockSchedulerExceptionResponse = mock(Response.class);
doReturn(mockSchedulerExceptionResponse).when(schedulerResource).buildServerErrorResponse(mockSchedulerException);
// Test 1
doThrow(mockUnifiedRepositoryException).when(schedulerResource).convertScheduleRequestToJobTrigger(mockJobScheduleRequest);
Response testResponse = schedulerResource.blockoutWillFire(mockJobScheduleRequest);
assertEquals(mockUnifiedRepositoryExceptionResponse, testResponse);
// Test 2
doThrow(mockSchedulerException).when(schedulerResource).convertScheduleRequestToJobTrigger(mockJobScheduleRequest);
testResponse = schedulerResource.blockoutWillFire(mockJobScheduleRequest);
assertEquals(mockSchedulerExceptionResponse, testResponse);
verify(schedulerResource, times(1)).buildServerErrorResponse(mockUnifiedRepositoryException);
verify(schedulerResource, times(1)).buildServerErrorResponse(mockSchedulerException);
verify(schedulerResource, times(2)).convertScheduleRequestToJobTrigger(mockJobScheduleRequest);
}
use of org.pentaho.platform.api.repository2.unified.UnifiedRepositoryException in project pentaho-platform by pentaho.
the class JcrRepositoryFileDao method internalCopyOrMove.
private void internalCopyOrMove(final Serializable fileId, final String destRelPath, final String versionMessage, final boolean copy) {
if (isKioskEnabled()) {
// $NON-NLS-1$
throw new RuntimeException(Messages.getInstance().getString("JcrRepositoryFileDao.ERROR_0006_ACCESS_DENIED"));
}
Assert.notNull(fileId);
jcrTemplate.execute(new JcrCallback() {
@Override
public Object doInJcr(final Session session) throws RepositoryException, IOException {
// if we're moving the file,
// check that user has permissions to remove the file from it's current location
RepositoryFile file = getFileById(fileId);
if (!copy) {
RepositoryFileAcl acl = aclDao.getAcl(fileId);
if (!accessVoterManager.hasAccess(file, RepositoryFilePermission.WRITE, acl, PentahoSessionHolder.getSession())) {
throw new AccessDeniedException(Messages.getInstance().getString("JcrRepositoryFileDao.ERROR_0006_ACCESS_DENIED_DELETE", fileId));
}
}
// check that user has permissions to write to the destination folder
RepositoryFile destFolder = getFile(destRelPath);
if (destFolder != null) {
RepositoryFileAcl destFolderAcl = aclDao.getAcl(destFolder.getId());
if (!accessVoterManager.hasAccess(destFolder, RepositoryFilePermission.WRITE, destFolderAcl, PentahoSessionHolder.getSession())) {
throw new AccessDeniedException(Messages.getInstance().getString("JcrRepositoryFileDao.ERROR_0006_ACCESS_DENIED_CREATE", destFolder.getId()));
}
}
PentahoJcrConstants pentahoJcrConstants = new PentahoJcrConstants(session);
String destAbsPath = pathConversionHelper.relToAbs(destRelPath);
String cleanDestAbsPath = destAbsPath;
if (cleanDestAbsPath.endsWith(RepositoryFile.SEPARATOR)) {
cleanDestAbsPath.substring(0, cleanDestAbsPath.length() - 1);
}
Node srcFileNode = session.getNodeByIdentifier(fileId.toString());
Serializable srcParentFolderId = JcrRepositoryFileUtils.getParentId(session, fileId);
boolean appendFileName = false;
boolean destExists = true;
Node destFileNode = null;
Node destParentFolderNode = null;
try {
destFileNode = (Node) session.getItem(JcrStringHelper.pathEncode(cleanDestAbsPath));
} catch (PathNotFoundException e) {
destExists = false;
}
if (destExists) {
// make sure it's a file or folder
Assert.isTrue(JcrRepositoryFileUtils.isSupportedNodeType(pentahoJcrConstants, destFileNode));
// existing item; make sure src is not a folder if dest is a file
Assert.isTrue(!(JcrRepositoryFileUtils.isPentahoFolder(pentahoJcrConstants, srcFileNode) && JcrRepositoryFileUtils.isPentahoFile(pentahoJcrConstants, destFileNode)), Messages.getInstance().getString(// $NON-NLS-1$
"JcrRepositoryFileDao.ERROR_0002_CANNOT_OVERWRITE_FILE_WITH_FOLDER"));
if (JcrRepositoryFileUtils.isPentahoFolder(pentahoJcrConstants, destFileNode)) {
// existing item; caller is not renaming file, only moving it
appendFileName = true;
destParentFolderNode = destFileNode;
} else {
// get parent of existing dest item
int lastSlashIndex = cleanDestAbsPath.lastIndexOf(RepositoryFile.SEPARATOR);
Assert.isTrue(lastSlashIndex > 1, Messages.getInstance().getString(// $NON-NLS-1$
"JcrRepositoryFileDao.ERROR_0003_ILLEGAL_DEST_PATH"));
String absPathToDestParentFolder = cleanDestAbsPath.substring(0, lastSlashIndex);
destParentFolderNode = (Node) session.getItem(JcrStringHelper.pathEncode(absPathToDestParentFolder));
}
} else {
// destination doesn't exist; go up one level to a folder that does exist
int lastSlashIndex = cleanDestAbsPath.lastIndexOf(RepositoryFile.SEPARATOR);
Assert.isTrue(lastSlashIndex > 1, Messages.getInstance().getString(// $NON-NLS-1$
"JcrRepositoryFileDao.ERROR_0003_ILLEGAL_DEST_PATH"));
String absPathToDestParentFolder = cleanDestAbsPath.substring(0, lastSlashIndex);
// JcrRepositoryFileUtils.checkName( cleanDestAbsPath.substring( lastSlashIndex + 1 ) );
try {
destParentFolderNode = (Node) session.getItem(JcrStringHelper.pathEncode(absPathToDestParentFolder));
} catch (PathNotFoundException e1) {
Assert.isTrue(false, Messages.getInstance().getString(// $NON-NLS-1$
"JcrRepositoryFileDao.ERROR_0004_PARENT_MUST_EXIST"));
}
Assert.isTrue(JcrRepositoryFileUtils.isPentahoFolder(pentahoJcrConstants, destParentFolderNode), Messages.getInstance().getString(// $NON-NLS-1$
"JcrRepositoryFileDao.ERROR_0005_PARENT_MUST_BE_FOLDER"));
}
if (!copy) {
JcrRepositoryFileUtils.checkoutNearestVersionableFileIfNecessary(session, pentahoJcrConstants, srcParentFolderId);
}
JcrRepositoryFileUtils.checkoutNearestVersionableNodeIfNecessary(session, pentahoJcrConstants, destParentFolderNode);
String finalEncodedSrcAbsPath = srcFileNode.getPath();
String finalEncodedDestAbsPath = null;
if (appendFileName) {
final String fileName = srcFileNode.getName();
if (JcrStringHelper.isEncoded(fileName)) {
finalEncodedDestAbsPath = JcrStringHelper.pathEncode(cleanDestAbsPath) + RepositoryFile.SEPARATOR + fileName;
} else {
finalEncodedDestAbsPath = JcrStringHelper.pathEncode(cleanDestAbsPath + RepositoryFile.SEPARATOR + fileName);
}
} else {
finalEncodedDestAbsPath = JcrStringHelper.pathEncode(cleanDestAbsPath);
}
try {
if (copy) {
session.getWorkspace().copy(finalEncodedSrcAbsPath, finalEncodedDestAbsPath);
} else {
session.getWorkspace().move(finalEncodedSrcAbsPath, finalEncodedDestAbsPath);
}
} catch (ItemExistsException iae) {
throw new UnifiedRepositoryException((file.isFolder() ? "Folder " : "File ") + "with path [" + cleanDestAbsPath + "] already exists in the repository");
}
JcrRepositoryFileUtils.checkinNearestVersionableNodeIfNecessary(session, pentahoJcrConstants, destParentFolderNode, versionMessage);
// if it's a move within the same folder, then the next checkin is unnecessary
if (!copy && !destParentFolderNode.getIdentifier().equals(srcParentFolderId.toString())) {
JcrRepositoryFileUtils.checkinNearestVersionableFileIfNecessary(session, pentahoJcrConstants, srcParentFolderId, versionMessage);
}
session.save();
return null;
}
});
}
use of org.pentaho.platform.api.repository2.unified.UnifiedRepositoryException in project pentaho-platform by pentaho.
the class FileSystemRepositoryFileDao method createFolder.
public RepositoryFile createFolder(Serializable parentFolderId, RepositoryFile file, RepositoryFileAcl acl, String versionMessage) {
try {
String folderNameWithPath = parentFolderId + "/" + file.getName();
File newFolder = new File(folderNameWithPath);
newFolder.mkdir();
final RepositoryFile repositoryFolder = internalGetFile(newFolder);
return repositoryFolder;
} catch (Throwable th) {
throw new UnifiedRepositoryException();
}
}
Aggregations