use of com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException in project kylo by Teradata.
the class JcrExtensibleEntityProvider method getEntities.
public List<ExtensibleEntity> getEntities(String typeName) {
String qualifiedName = this.typeProvider.ensureTypeName(typeName);
List<ExtensibleEntity> list = new ArrayList<>();
Session session = getSession();
try {
String path = EntityUtil.pathForExtensibleEntity(qualifiedName);
if (session.nodeExists(path)) {
Node typeNameNode = session.getNode(path);
NodeIterator entityItr = typeNameNode.getNodes();
while (entityItr.hasNext()) {
Node entNode = (Node) entityItr.next();
list.add(new JcrExtensibleEntity(entNode));
}
}
return list;
} catch (RepositoryException e) {
throw new MetadataRepositoryException("Failed to retrieve list of extensible entities", e);
}
}
use of com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException in project kylo by Teradata.
the class JcrExtensibleEntityProvider method createEntity.
@Override
public ExtensibleEntity createEntity(ExtensibleType type, Map<String, Object> props) {
JcrExtensibleType typeImpl = (JcrExtensibleType) type;
Session session = getSession();
try {
String path = EntityUtil.pathForExtensibleEntity();
Node entitiesNode = session.getNode(path);
Node typesNode = null;
if (entitiesNode.hasNode(typeImpl.getJcrName())) {
typesNode = entitiesNode.getNode(typeImpl.getJcrName());
} else {
typesNode = entitiesNode.addNode(typeImpl.getJcrName(), "nt:folder");
}
Node entNode = typesNode.addNode(typeImpl.getName() + "-" + UUID.randomUUID().toString(), typeImpl.getJcrName());
Map<String, Object> reassignedProps = mapCollectionProperties(typeImpl, props);
entNode = JcrPropertyUtil.setProperties(session, entNode, reassignedProps);
return new JcrExtensibleEntity(entNode);
} catch (RepositoryException e) {
throw new MetadataRepositoryException("Failed to create new extensible entity of type: " + typeImpl.getJcrName(), e);
}
}
use of com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException in project kylo by Teradata.
the class JcrExtensibleType method getFieldDescriptors.
@Override
public Set<FieldDescriptor> getFieldDescriptors() {
try {
Set<FieldDescriptor> set = new HashSet<>();
for (PropertyDefinition def : this.nodeType.getPropertyDefinitions()) {
if (this.typeNode.hasNode(def.getName())) {
Node descrNode = this.typeNode.getNode(def.getName());
set.add(new JcrFieldDescriptor(descrNode, def));
}
}
return set;
} catch (RepositoryException e) {
throw new MetadataRepositoryException("Unable to get property descriptors for type: " + this.nodeType.getName(), e);
}
}
use of com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException in project kylo by Teradata.
the class JcrExtensibleTypeProvider method ensureTypeDescriptors.
public void ensureTypeDescriptors() {
try {
Session session = JcrMetadataAccess.getActiveSession();
Node typesNode = session.getRootNode().getNode(ExtensionsConstants.TYPES);
NodeTypeManager typeMgr = (NodeTypeManager) session.getWorkspace().getNodeTypeManager();
NodeTypeIterator typeItr = typeMgr.getPrimaryNodeTypes();
NodeType extensionsType = typeMgr.getNodeType(ExtensionsConstants.EXTENSIBLE_ENTITY_TYPE);
while (typeItr.hasNext()) {
NodeType type = (NodeType) typeItr.next();
if (type.isNodeType(ExtensionsConstants.EXTENSIBLE_ENTITY_TYPE) && !type.equals(extensionsType) && !typesNode.hasNode(type.getName())) {
Node descrNode = typesNode.addNode(type.getName(), ExtensionsConstants.TYPE_DESCRIPTOR_TYPE);
descrNode.setProperty("jcr:title", simpleName(type.getName()));
descrNode.setProperty("jcr:description", "");
PropertyDefinition[] defs = type.getPropertyDefinitions();
for (PropertyDefinition def : defs) {
String fieldName = def.getName();
String prefix = namePrefix(fieldName);
if (!ExtensionsConstants.STD_PREFIXES.contains(prefix) && !descrNode.hasNode(fieldName)) {
Node propNode = descrNode.addNode(def.getName(), ExtensionsConstants.FIELD_DESCRIPTOR_TYPE);
propNode.setProperty("jcr:title", def.getName().replace("^.*:", ""));
propNode.setProperty("jcr:description", "");
}
}
}
}
NodeIterator nodeItr = typesNode.getNodes();
while (nodeItr.hasNext()) {
Node typeNode = (Node) nodeItr.next();
if (!typeMgr.hasNodeType(typeNode.getName())) {
typeNode.remove();
}
}
} catch (RepositoryException e) {
throw new MetadataRepositoryException("Failed to ensure extensible type metadata", e);
}
}
use of com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException in project kylo by Teradata.
the class JcrExtensibleTypeProvider method deleteType.
@Override
public boolean deleteType(final ID id) {
final Session session = getSession();
final JcrExtensibleType.TypeId typeId = (JcrExtensibleType.TypeId) id;
try {
final Node typeNode = session.getNodeByIdentifier(typeId.getIdValue());
final String typeName = typeNode.getName();
session.getWorkspace().getNodeTypeManager().unregisterNodeType(typeName);
session.getRootNode().getNode(ExtensionsConstants.TYPES + "/" + typeName).remove();
return JcrExtensibleEntityProvider.cleanupDeletedType(session, typeName);
} catch (ItemNotFoundException | NoSuchNodeTypeException | NullPointerException e) {
// KYLO-8: Ignore NPE caused by unregistering a node type
return true;
} catch (UnsupportedRepositoryOperationException e) {
return false;
} catch (RepositoryException e) {
throw new MetadataRepositoryException("Unable to retrieve extensible type: " + id, e);
}
}
Aggregations