use of org.pentaho.platform.api.repository2.unified.data.node.DataNode in project pentaho-platform by pentaho.
the class JcrBackedDatasourceMgmtServiceTest method testGetDatasources.
@Test
public void testGetDatasources() throws Exception {
final String fileId = "456";
final String databasesFolderPath = "/etc/pdi/databases";
final String dotKdb = ".kdb";
IUnifiedRepository repo = mock(IUnifiedRepository.class);
// stub out get parent folder
doReturn(new RepositoryFile.Builder("123", "databases").folder(true).build()).when(repo).getFile(databasesFolderPath);
doReturn(reservedChars).when(repo).getReservedChars();
// stub out get file to update
RepositoryFile f = new RepositoryFile.Builder(fileId, EXP_DBMETA_NAME + dotKdb).path(databasesFolderPath + RepositoryFile.SEPARATOR + EXP_DBMETA_NAME + dotKdb).build();
doReturn(f).when(repo).getFile(databasesFolderPath + RepositoryFile.SEPARATOR + EXP_DBMETA_NAME + dotKdb);
final String EXP_HOST_NAME = "hello";
DataNode rootNode = new DataNode("databaseMeta");
// required
rootNode.setProperty("TYPE", "Hypersonic");
rootNode.setProperty("HOST_NAME", EXP_HOST_NAME);
// required
rootNode.addNode("attributes");
doReturn(new NodeRepositoryFileData(rootNode)).when(repo).getDataForRead(eq(fileId), eq(NodeRepositoryFileData.class));
IDatasourceMgmtService datasourceMgmtService = new JcrBackedDatasourceMgmtService(repo, new DatabaseDialectService());
IDatabaseConnection conn = datasourceMgmtService.getDatasourceByName(EXP_DBMETA_NAME);
assertEquals(EXP_HOST_NAME, conn.getHostname());
}
use of org.pentaho.platform.api.repository2.unified.data.node.DataNode in project pentaho-platform by pentaho.
the class NodeRepositoryFileDataAdapterTest method testMarshalUnmarshalDate.
private void testMarshalUnmarshalDate(Locale locale, TimeZone timeZone) throws Exception {
final Locale defaultLocale = Locale.getDefault();
final TimeZone defaultTimeZone = TimeZone.getDefault();
// $NON-NLS-1$
final String DATE_PROPERTY = "date";
NodeRepositoryFileDataAdapter adapter = new NodeRepositoryFileDataAdapter();
Date date = new Date();
// $NON-NLS-1$
DataNode node = new DataNode("");
node.setProperty(DATE_PROPERTY, date);
NodeRepositoryFileData data = new NodeRepositoryFileData(node);
NodeRepositoryFileData result;
// Convert using the provided locale
try {
Locale.setDefault(locale);
TimeZone.setDefault(timeZone);
NodeRepositoryFileDataDto dto = adapter.marshal(data);
result = adapter.unmarshal(dto);
} finally {
Locale.setDefault(defaultLocale);
TimeZone.setDefault(defaultTimeZone);
}
DataProperty property = result.getNode().getProperty(DATE_PROPERTY);
assertNotNull(property);
assertEquals(date, property.getDate());
}
use of org.pentaho.platform.api.repository2.unified.data.node.DataNode in project pentaho-platform by pentaho.
the class MondrianCatalogRepositoryHelper method createDatasourceMetadata.
/*
* Creates "/etc/mondrian/<catalog>/metadata" and the connection nodes
*/
private void createDatasourceMetadata(RepositoryFile catalog, String datasourceInfo) {
final String path = ETC_MONDRIAN_JCR_FOLDER + RepositoryFile.SEPARATOR + catalog.getName() + RepositoryFile.SEPARATOR + "metadata";
RepositoryFile metadata = repository.getFile(path);
String definition = "mondrian:/" + catalog.getName();
DataNode node = new DataNode("catalog");
node.setProperty("definition", encodeUrl(definition));
node.setProperty("datasourceInfo", datasourceInfo);
NodeRepositoryFileData data = new NodeRepositoryFileData(node);
if (metadata == null) {
repository.createFile(catalog.getId(), new RepositoryFile.Builder("metadata").build(), data, null);
} else {
repository.updateFile(metadata, data, null);
}
}
use of org.pentaho.platform.api.repository2.unified.data.node.DataNode in project pentaho-platform by pentaho.
the class JcrAclNodeHelper method createAclNode.
private RepositoryFile createAclNode(RepositoryFile fileToAddAclFor) {
DataNode dataNode = new DataNode("acl node");
DataNodeRef dataNodeRef = new DataNodeRef(fileToAddAclFor.getId());
dataNode.setProperty(TARGET, dataNodeRef);
dataNode.setProperty(IS_ACL_NODE, true);
NodeRepositoryFileData nodeRepositoryFileData = new NodeRepositoryFileData(dataNode);
return unifiedRepository.createFile(unifiedRepository.getFile("/").getId(), new RepositoryFile.Builder(UUID.randomUUID().toString()).aclNode(true).build(), nodeRepositoryFileData, "");
}
use of org.pentaho.platform.api.repository2.unified.data.node.DataNode in project pentaho-platform by pentaho.
the class JcrRepositoryFileDao method internalCreateFile.
private RepositoryFile internalCreateFile(final Serializable parentFolderId, final RepositoryFile file, final IRepositoryFileData content, final RepositoryFileAcl acl, final String versionMessage) {
if (isKioskEnabled()) {
// $NON-NLS-1$
throw new RuntimeException(Messages.getInstance().getString("JcrRepositoryFileDao.ERROR_0006_ACCESS_DENIED"));
}
/*
* PPP-3049: Changed the Assert.notNull(content) to code that creates a file with a single blank when the assert
* WOULD have been triggered.
*/
Assert.notNull(file);
Assert.isTrue(!file.isFolder());
// Get repository file info and acl info of parent
if (parentFolderId != null) {
RepositoryFile parentRepositoryFile = getFileById(parentFolderId);
if (parentRepositoryFile != null) {
RepositoryFileAcl parentAcl = aclDao.getAcl(parentRepositoryFile.getId());
// Invoke accessVoterManager to see if we have access to perform this operation
if (!accessVoterManager.hasAccess(parentRepositoryFile, RepositoryFilePermission.WRITE, parentAcl, PentahoSessionHolder.getSession())) {
return null;
}
}
}
// Assert.notNull(content);
DataNode emptyDataNode = new DataNode(file.getName());
// $NON-NLS-1$ //$NON-NLS-2$
emptyDataNode.setProperty(" ", "content");
final IRepositoryFileData emptyContent = new NodeRepositoryFileData(emptyDataNode);
return (RepositoryFile) jcrTemplate.execute(new JcrCallback() {
@Override
public Object doInJcr(final Session session) throws RepositoryException, IOException {
PentahoJcrConstants pentahoJcrConstants = new PentahoJcrConstants(session);
JcrRepositoryFileUtils.checkoutNearestVersionableFileIfNecessary(session, pentahoJcrConstants, parentFolderId);
Node fileNode = JcrRepositoryFileUtils.createFileNode(session, pentahoJcrConstants, parentFolderId, file, content == null ? emptyContent : content, findTransformerForWrite(content == null ? emptyContent.getClass() : content.getClass()));
// create a tmp file with correct path for default acl creation purposes.
String path = JcrRepositoryFileUtils.getAbsolutePath(session, pentahoJcrConstants, fileNode);
RepositoryFile tmpFile = new RepositoryFile.Builder(file).path(path).build();
// we must create the acl during checkout
aclDao.createAcl(fileNode.getIdentifier(), acl == null ? defaultAclHandler.createDefaultAcl(tmpFile) : acl);
session.save();
if (file.isVersioned()) {
JcrRepositoryFileUtils.checkinNearestVersionableNodeIfNecessary(session, pentahoJcrConstants, fileNode, versionMessage, file.getCreatedDate(), false);
}
JcrRepositoryFileUtils.checkinNearestVersionableFileIfNecessary(session, pentahoJcrConstants, parentFolderId, Messages.getInstance().getString("JcrRepositoryFileDao.USER_0002_VER_COMMENT_ADD_FILE", file.getName(), // $NON-NLS-1$ //$NON-NLS-2$
(parentFolderId == null ? "root" : parentFolderId.toString())));
return JcrRepositoryFileUtils.nodeToFile(session, pentahoJcrConstants, pathConversionHelper, lockHelper, fileNode);
}
});
}
Aggregations