use of org.pentaho.platform.api.repository2.unified.data.node.DataNode in project pentaho-platform by pentaho.
the class NodeRepositoryFileDataAdapter method unmarshal.
@Override
public NodeRepositoryFileData unmarshal(final NodeRepositoryFileDataDto v) {
DataNode node = toDataNode(v.node);
NodeRepositoryFileData data = new NodeRepositoryFileData(node);
return data;
}
use of org.pentaho.platform.api.repository2.unified.data.node.DataNode in project pentaho-platform by pentaho.
the class NodeRepositoryFileDataAdapter method toDataNodeDto.
protected void toDataNodeDto(final DataNodeDto nodeDto, final DataNode node) {
nodeDto.name = node.getName();
if (node.getId() != null) {
nodeDto.id = node.getId().toString();
}
List<DataPropertyDto> dtoProps = new ArrayList<DataPropertyDto>();
for (DataProperty prop : node.getProperties()) {
DataPropertyDto dtoProp = new DataPropertyDto();
dtoProp.name = prop.getName();
if ((prop.getType() == DataPropertyType.BOOLEAN) || (prop.getType() == DataPropertyType.DOUBLE) || (prop.getType() == DataPropertyType.LONG) || (prop.getType() == DataPropertyType.STRING) || (prop.getType() == DataPropertyType.REF)) {
dtoProp.value = prop.getString();
} else if (prop.getType() == DataPropertyType.DATE) {
Date dateProp = prop.getDate();
dtoProp.value = dateProp != null ? String.valueOf(dateProp.getTime()) : null;
} else {
throw new IllegalArgumentException();
}
dtoProp.type = prop.getType() != null ? prop.getType().ordinal() : -1;
dtoProps.add(dtoProp);
}
nodeDto.childProperties = dtoProps;
List<DataNodeDto> nodeDtos = new ArrayList<DataNodeDto>();
for (DataNode childNode : node.getNodes()) {
DataNodeDto child = new DataNodeDto();
nodeDtos.add(child);
toDataNodeDto(child, childNode);
}
nodeDto.childNodes = nodeDtos;
}
use of org.pentaho.platform.api.repository2.unified.data.node.DataNode in project pentaho-platform by pentaho.
the class DefaultUnifiedRepositoryContentIT method testCreateNodeFile.
@Test
public void testCreateNodeFile() throws Exception {
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);
login(USERNAME_SUZY, tenantAcme, new String[] { tenantAuthenticatedRoleName });
final String expectedName = "helloworld.doesnotmatter";
final String parentFolderPath = ClientRepositoryPaths.getUserHomeFolderPath(USERNAME_SUZY);
RepositoryFile parentFolder = repo.getFile(parentFolderPath);
final String expectedPath = parentFolderPath + RepositoryFile.SEPARATOR + expectedName;
final String serverPath = ServerRepositoryPaths.getTenantRootFolderPath() + parentFolderPath + RepositoryFile.SEPARATOR + "helloworld2.sample";
RepositoryFile sampleFile = createSampleFile(parentFolderPath, "helloworld2.sample", "dfdd", true, 83);
final Date EXP_DATE = new Date();
DataNode node = new DataNode("kdjd");
node.setProperty("ddf", "ljsdfkjsdkf");
DataNode newChild1 = node.addNode("herfkmdx");
newChild1.setProperty("sdfs", true);
newChild1.setProperty("ks3", EXP_DATE);
newChild1.setProperty("ids32", 7.32D);
newChild1.setProperty("erere3", 9856684583L);
newChild1.setProperty("tttss4", "843skdfj33ksaljdfj");
newChild1.setProperty("urei2", new DataNodeRef(sampleFile.getId()));
DataNode newChild2 = node.addNode(JcrStringHelper.fileNameEncode("pppq/qqs2"));
newChild2.setProperty(JcrStringHelper.fileNameEncode("ttt*ss4"), "843skdfj33ksaljdfj");
NodeRepositoryFileData data = new NodeRepositoryFileData(node);
RepositoryFile newFile = repo.createFile(parentFolder.getId(), new RepositoryFile.Builder(expectedName).build(), data, null);
assertNotNull(newFile.getId());
RepositoryFile foundFile = repo.getFile(expectedPath);
assertNotNull(foundFile);
assertEquals(expectedName, foundFile.getName());
DataNode foundNode = repo.getDataForRead(foundFile.getId(), NodeRepositoryFileData.class).getNode();
assertEquals(node.getName(), foundNode.getName());
assertNotNull(foundNode.getId());
assertEquals(node.getProperty("ddf"), foundNode.getProperty("ddf"));
int actualPropCount = 0;
for (DataProperty prop : foundNode.getProperties()) {
actualPropCount++;
}
assertEquals(1, actualPropCount);
assertTrue(foundNode.hasNode("herfkmdx"));
DataNode foundChild1 = foundNode.getNode("herfkmdx");
assertNotNull(foundChild1.getId());
assertEquals(newChild1.getName(), foundChild1.getName());
assertEquals(newChild1.getProperty("sdfs"), foundChild1.getProperty("sdfs"));
assertEquals(newChild1.getProperty("ks3"), foundChild1.getProperty("ks3"));
assertEquals(newChild1.getProperty("ids32"), foundChild1.getProperty("ids32"));
assertEquals(newChild1.getProperty("erere3"), foundChild1.getProperty("erere3"));
assertEquals(newChild1.getProperty("tttss4"), foundChild1.getProperty("tttss4"));
assertEquals(newChild1.getProperty("urei2"), foundChild1.getProperty("urei2"));
try {
repo.deleteFile(sampleFile.getId(), true, null);
fail();
} catch (UnifiedRepositoryException e) {
// should fail due to referential integrity (newFile payload has reference to sampleFile)
}
actualPropCount = 0;
for (DataProperty prop : newChild1.getProperties()) {
actualPropCount++;
}
assertEquals(6, actualPropCount);
assertTrue(foundNode.hasNode(JcrStringHelper.fileNameEncode("pppq/qqs2")));
DataNode foundChild2 = foundNode.getNode(JcrStringHelper.fileNameEncode("pppq/qqs2"));
assertNotNull(foundChild2.getId());
assertEquals(newChild2.getName(), foundChild2.getName());
assertEquals(newChild2.getProperty(JcrStringHelper.fileNameEncode("ttt:ss4")), foundChild2.getProperty(JcrStringHelper.fileNameEncode("ttt:ss4")));
actualPropCount = 0;
for (DataProperty prop : foundChild2.getProperties()) {
actualPropCount++;
}
assertEquals(1, actualPropCount);
// ordering
int i = 0;
for (DataNode currentNode : foundNode.getNodes()) {
if (i++ == 0) {
assertEquals(newChild1.getName(), currentNode.getName());
} else {
assertEquals(newChild2.getName(), currentNode.getName());
}
}
}
use of org.pentaho.platform.api.repository2.unified.data.node.DataNode in project pentaho-platform by pentaho.
the class DefaultUnifiedRepositoryContentIT method testGetReferrers.
@Test
public void testGetReferrers() throws Exception {
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);
login(USERNAME_SUZY, tenantAcme, new String[] { tenantAuthenticatedRoleName });
final String refereeFileName = "referee.sample";
final String referrerFileName = "referrer.sample";
final String parentFolderPath = ClientRepositoryPaths.getUserHomeFolderPath(USERNAME_SUZY);
RepositoryFile parentFolder = repo.getFile(parentFolderPath);
RepositoryFile refereeFile = createSampleFile(parentFolderPath, refereeFileName, "dfdd", true, 83);
DataNode node = new DataNode("kdjd");
node.setProperty("ddf", "ljsdfkjsdkf");
DataNode newChild1 = node.addNode("herfkmdx");
newChild1.setProperty("urei2", new DataNodeRef(refereeFile.getId()));
NodeRepositoryFileData data = new NodeRepositoryFileData(node);
repo.createFile(parentFolder.getId(), new RepositoryFile.Builder(referrerFileName).build(), data, null);
List<RepositoryFile> referrers = repo.getReferrers(refereeFile.getId());
assertNotNull(referrers);
assertEquals(1, referrers.size());
assertEquals(referrers.get(0).getName(), referrerFileName);
}
use of org.pentaho.platform.api.repository2.unified.data.node.DataNode in project pentaho-platform by pentaho.
the class DefaultUnifiedRepositoryContentIT method testSymbol.
private void testSymbol(char symbol, boolean isGood) {
DataNode goodNode = new DataNode("node");
goodNode.setProperty("property", "whatever");
NodeRepositoryFileData goodNodeData = new NodeRepositoryFileData(goodNode);
DataNode badNode = new DataNode("node" + symbol);
badNode.setProperty("property", "whatever");
NodeRepositoryFileData badNodeData = new NodeRepositoryFileData(badNode);
DataNode goodNodeBadProp = new DataNode("node");
goodNodeBadProp.setProperty("property" + symbol, "whatever");
NodeRepositoryFileData goodNodeBadPropData = new NodeRepositoryFileData(goodNodeBadProp);
final String parentFolderPath = ClientRepositoryPaths.getUserHomeFolderPath(PentahoSessionHolder.getSession().getName());
RepositoryFile parentFolder = repo.getFile(parentFolderPath);
try {
final String name = "folder" + symbol;
final RepositoryFile folder = repo.createFolder(parentFolder.getId(), new RepositoryFile.Builder(name).folder(true).build(), null);
failIfTrue(!isGood, symbol);
assertEquals(name, folder.getName());
} catch (UnifiedRepositoryMalformedNameException e) {
failIfTrue(isGood, symbol);
}
try {
final String name = "file" + symbol;
final RepositoryFile file = repo.createFile(parentFolder.getId(), new RepositoryFile.Builder(name).build(), goodNodeData, null);
failIfTrue(!isGood, symbol);
assertEquals(name, file.getName());
} catch (UnifiedRepositoryMalformedNameException e) {
failIfTrue(isGood, symbol);
}
try {
final RepositoryFile file = repo.getFile(parentFolder.getPath() + RepositoryFile.SEPARATOR + "file");
if (file != null) {
repo.deleteFile(file.getId(), null);
}
final RepositoryFile file1 = repo.createFile(parentFolder.getId(), new RepositoryFile.Builder("file").build(), badNodeData, null);
failIfTrue(!isGood, symbol);
assertEquals(badNodeData.getNode().getName(), repo.getDataForRead(file1.getId(), NodeRepositoryFileData.class).getNode().getName());
} catch (UnifiedRepositoryMalformedNameException e) {
failIfTrue(isGood, symbol);
}
try {
final RepositoryFile file = repo.getFile(parentFolder.getPath() + RepositoryFile.SEPARATOR + "file");
if (file != null) {
repo.deleteFile(file.getId(), null);
}
final RepositoryFile file1 = repo.createFile(parentFolder.getId(), new RepositoryFile.Builder("file").build(), goodNodeBadPropData, null);
failIfTrue(!isGood, symbol);
assertEquals(goodNodeBadPropData.getNode().getProperties().iterator().next().getName(), repo.getDataForRead(file1.getId(), NodeRepositoryFileData.class).getNode().getProperties().iterator().next().getName());
} catch (UnifiedRepositoryMalformedNameException e) {
failIfTrue(isGood, symbol);
}
}
Aggregations