use of org.pentaho.platform.api.repository2.unified.data.node.NodeRepositoryFileData in project pentaho-platform by pentaho.
the class DefaultUnifiedRepositoryContentIT method testMissingRef.
@Test
public void testMissingRef() throws Exception {
// if a user does not have permission to a reference, it is removed from the node structure and
// replaced with a missing link. previous releases would throw an exception.
// create a file that suzy does not have permission to
// create a file that suzy has permission to but references the one she doesn't
// load the file as suzy, make sure no exceptions occur and that the node is a missing reference
loginAsSysTenantAdmin();
ITenant tenantAcme = tenantManager.createTenant(systemTenant, TENANT_ID_ACME, tenantAdminRoleName, tenantAuthenticatedRoleName, ANONYMOUS_ROLE_NAME);
userRoleDao.createUser(tenantAcme, USERNAME_ADMIN, PASSWORD, "", new String[] { tenantAdminRoleName });
login(USERNAME_ADMIN, tenantAcme, new String[] { tenantAdminRoleName, tenantAuthenticatedRoleName });
userRoleDao.createUser(tenantAcme, USERNAME_SUZY, PASSWORD, "", null);
DataNode node = new DataNode("kdjd");
RepositoryFile sampleFile = createSampleFile(ClientRepositoryPaths.getPublicFolderPath(), "helloworld2.sample", "dfdd", true, 83);
RepositoryFileAcl acl = repo.getAcl(sampleFile.getId());
RepositoryFileAcl newAcl = new RepositoryFileAcl.Builder(acl).entriesInheriting(false).clearAces().build();
repo.updateAcl(newAcl);
node.setProperty("urei2", new DataNodeRef(sampleFile.getId()));
final String parentFolderPath = ClientRepositoryPaths.getPublicFolderPath();
final String expectedName = "helloworld.doesnotmatter";
RepositoryFile parentFolder = repo.getFile(parentFolderPath);
assertNotNull(parentFolder);
final String expectedPath = parentFolderPath + RepositoryFile.SEPARATOR + expectedName;
NodeRepositoryFileData data = new NodeRepositoryFileData(node);
RepositoryFile newFile = repo.createFile(parentFolder.getId(), new RepositoryFile.Builder(expectedName).build(), data, null);
assertNotNull(newFile.getId());
// now check that the ref is missing
login(USERNAME_SUZY, tenantAcme, new String[] { tenantAuthenticatedRoleName });
RepositoryFile foundFile = repo.getFile(expectedPath);
assertNotNull(foundFile);
DataNode foundNode = repo.getDataForRead(newFile.getId(), NodeRepositoryFileData.class).getNode();
DataProperty d = foundNode.getProperty("urei2");
assertNotNull(d);
assertTrue(d.getType() == DataPropertyType.REF);
assertTrue(d.getRef().getId() == DataNodeRef.REF_MISSING);
// now change permissions back so she can get access to the node, confirm things are back to normal
login(USERNAME_ADMIN, tenantAcme, new String[] { tenantAdminRoleName, tenantAuthenticatedRoleName });
newAcl = new RepositoryFileAcl.Builder(acl).entriesInheriting(true).clearAces().build();
repo.updateAcl(newAcl);
login(USERNAME_SUZY, tenantAcme, new String[] { tenantAuthenticatedRoleName });
foundFile = repo.getFile(expectedPath);
assertNotNull(foundFile);
foundNode = repo.getDataForRead(newFile.getId(), NodeRepositoryFileData.class).getNode();
d = foundNode.getProperty("urei2");
assertNotNull(d);
assertTrue(d.getType() == DataPropertyType.REF);
assertTrue(d.getRef().getId().equals(sampleFile.getId()));
}
use of org.pentaho.platform.api.repository2.unified.data.node.NodeRepositoryFileData in project pentaho-platform by pentaho.
the class DefaultUnifiedRepositoryJaxwsWebServiceIT method makeNodeRepositoryFileData1.
private NodeRepositoryFileData makeNodeRepositoryFileData1() {
DataNode node = new DataNode("testNode");
node.setProperty("prop1", "hello world");
node.setProperty("prop2", false);
node.setProperty("prop3", 12L);
return new NodeRepositoryFileData(node);
}
use of org.pentaho.platform.api.repository2.unified.data.node.NodeRepositoryFileData in project pentaho-platform by pentaho.
the class JcrBackedDatasourceMgmtService method updateDatasource.
private String updateDatasource(RepositoryFile file, IDatabaseConnection databaseConnection) throws NonExistingDatasourceException, DatasourceMgmtServiceException {
try {
if (file != null) {
file = new RepositoryFile.Builder(file).versionId(file.getVersionId()).id(file.getId()).title(RepositoryFile.DEFAULT_LOCALE, databaseConnection.getName()).build();
file = repository.updateFile(file, new NodeRepositoryFileData(databaseHelper.databaseConnectionToDataNode(databaseConnection)), null);
renameIfNecessary(databaseConnection, file);
return file.getId().toString();
} else {
throw new NonExistingDatasourceException(Messages.getInstance().getErrorString("DatasourceMgmtService.ERROR_0006_DATASOURCE_DOES_NOT_EXIST", // $NON-NLS-1$
databaseConnection.getName()));
}
// } catch(PasswordServiceException pse) {
// throw new DatasourceMgmtServiceException(Messages.getInstance()
// .getErrorString("DatasourceMgmtService.ERROR_0007_UNABLE_TO_ENCRYPT_PASSWORD"), pse ); //$NON-NLS-1$
} catch (UnifiedRepositoryException ure) {
throw new DatasourceMgmtServiceException(Messages.getInstance().getErrorString("DatasourceMgmtService.ERROR_0003_UNABLE_TO_UPDATE_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 JcrBackedDatasourceMgmtService method getDatasource.
private IDatabaseConnection getDatasource(RepositoryFile file) throws DatasourceMgmtServiceException {
try {
if (file != null) {
NodeRepositoryFileData data = repository.getDataForRead(file.getId(), NodeRepositoryFileData.class);
IDatabaseConnection databaseConnection = databaseHelper.dataNodeToDatabaseConnection(file.getId(), file.getTitle(), data.getNode());
// databaseMeta.setPassword(passwordService.decrypt(databaseMeta.getPassword()));
return databaseConnection;
} else {
throw new DatasourceMgmtServiceException(Messages.getInstance().getErrorString("DatasourceMgmtService.ERROR_0004_UNABLE_TO_RETRIEVE_DATASOURCE", "", // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
""));
}
// } 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", file.getName(), ure.getLocalizedMessage()), // $NON-NLS-1$
ure);
}
}
use of org.pentaho.platform.api.repository2.unified.data.node.NodeRepositoryFileData in project pentaho-kettle by pentaho.
the class PurRepository_DatabaseNames_IT method getDatabaseId_ReturnsExactMatch_PriorToCaseInsensitiveMatch.
@Test
public void getDatabaseId_ReturnsExactMatch_PriorToCaseInsensitiveMatch() throws Exception {
final String exact = "databaseExactMatch";
final String similar = exact.toLowerCase();
assertNotSame(similar, exact);
DatabaseMeta db = saveDatabase(exact);
// simulate legacy repository - store a DB with a name different only in case
// it became illegal to store such DB via API, thus create the file accessing UnifiedRepository directly
DatabaseMeta another = new DatabaseMeta();
another.setName(similar);
final String filename = PurRepository.checkAndSanitize(RepositoryFilenameUtils.escape(similar, unifiedRepository.getReservedChars()) + RepositoryObjectType.DATABASE.getExtension());
RepositoryFile file = new RepositoryFile.Builder(filename).title(similar).build();
file = unifiedRepository.createFile(purRepository.getDatabaseMetaParentFolderId(), file, new NodeRepositoryFileData(new DatabaseDelegate(purRepository).elementToDataNode(another)), null);
assertNotNull(file.getId());
assertNotSame(file.getId().toString(), db.getObjectId().toString());
ObjectId id = purRepository.getDatabaseID(exact);
assertEquals(db.getObjectId(), id);
}
Aggregations