use of com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException in project kylo by Teradata.
the class JcrPropertyUtil method asValue.
@SuppressWarnings("unchecked")
public static <T> T asValue(Property prop) {
// STRING, BOOLEAN, LONG, DOUBLE, PATH, ENTITY
try {
int code = prop.getType();
if (prop.isMultiple()) {
List<T> list = new ArrayList<>();
Value[] values = prop.getValues();
if (values != null) {
for (Value value : values) {
try {
T o = asValue(value, prop.getSession());
if (o != null) {
list.add(o);
}
} catch (AccessDeniedException e) {
// We are not allowd to see the value (likely a node reference) then
// just ignore this value in the result list.
}
}
}
if (list.size() > 0) {
return (T) list;
} else {
return (T) Collections.emptyList();
}
} else {
if (code == PropertyType.BOOLEAN) {
return (T) Boolean.valueOf(prop.getBoolean());
} else if (code == PropertyType.STRING) {
return (T) prop.getString();
} else if (code == PropertyType.LONG) {
return (T) Long.valueOf(prop.getLong());
} else if (code == PropertyType.DOUBLE) {
return (T) Double.valueOf(prop.getDouble());
} else if (code == PropertyType.PATH) {
return (T) prop.getPath();
} else if (code == PropertyType.REFERENCE || code == PropertyType.WEAKREFERENCE) {
try {
return (T) prop.getNode();
} catch (AccessDeniedException e) {
// We are not allowd to see the referenced node so return null;
return null;
}
} else {
return (T) asValue(prop.getValue(), prop.getSession());
}
}
} catch (AccessDeniedException e) {
log.debug("Access denied", e);
throw new AccessControlException(e.getMessage());
} catch (RepositoryException e) {
throw new MetadataRepositoryException("Failed to access property type", e);
}
}
use of com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException in project kylo by Teradata.
the class JcrPropertyUtil method setJsonObject.
public static <T> void setJsonObject(Node node, String name, Object value) {
try {
String json = writer.forType(value.getClass()).writeValueAsString(value);
setProperty(node, name, json);
} catch (IOException e) {
throw new MetadataRepositoryException("Failed to serialize JSON property: " + value, e);
}
}
use of com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException in project kylo by Teradata.
the class JcrPropertyUtil method removeAllFromSetProperty.
public static boolean removeAllFromSetProperty(Node node, String name) {
try {
// JcrVersionUtil.ensureCheckoutNode(node);
if (node == null) {
throw new IllegalArgumentException("Cannot remove a property from a null-node!");
}
if (name == null) {
throw new IllegalArgumentException("Cannot remove a property without a provided name");
}
Set<Value> values = new HashSet<>();
node.setProperty(name, (Value[]) values.stream().toArray(size -> new Value[size]));
return true;
} catch (AccessDeniedException e) {
log.debug("Access denied", e);
throw new AccessControlException(e.getMessage());
} catch (RepositoryException e) {
throw new MetadataRepositoryException("Failed to remove set property: " + name, e);
}
}
use of com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException in project kylo by Teradata.
the class JcrQueryUtil method queryRowItrNodeResultToList.
public static <T extends Object> List<T> queryRowItrNodeResultToList(QueryResult result, Class<T> type, String nodeName, Integer fetchSize) {
List<T> entities = new ArrayList<>();
if (result != null) {
try {
RowIterator rowIterator = result.getRows();
int cntr = 0;
while (rowIterator.hasNext()) {
Row row = rowIterator.nextRow();
Node node = row.getNode(nodeName);
T entity = JcrUtil.constructNodeObject(node, type, null);
entities.add(entity);
cntr++;
if (fetchSize != null && cntr == fetchSize) {
break;
}
}
} catch (RepositoryException e) {
throw new MetadataRepositoryException("Unable to parse QueryResult to List Row Iteration for type" + type + " and Node: " + nodeName, e);
}
}
return entities;
}
use of com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException in project kylo by Teradata.
the class JcrUtil method getNodesOfType.
public static List<Node> getNodesOfType(Node parentNode, String nodeType) {
try {
List<Node> list = new ArrayList<>();
NodeIterator itr = parentNode.getNodes();
while (itr.hasNext()) {
Node node = (Node) itr.next();
if (node.isNodeType(nodeType)) {
list.add(node);
}
}
return list;
} catch (AccessDeniedException e) {
log.debug("Access denied", e);
throw new AccessControlException(e.getMessage());
} catch (RepositoryException e) {
throw new MetadataRepositoryException("Failed to create set of child nodes of type: " + nodeType, e);
}
}
Aggregations