use of com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException in project kylo by Teradata.
the class JcrExtensibleEntityProvider method findEntitiesMatchingProperty.
/**
* Return a list of the ExtensibleEntity objects that match a given ExtensibleEntity property and value
* restricting to a specific jcr extension type
*/
public List<? extends ExtensibleEntity> findEntitiesMatchingProperty(String typeName, String propName, Object value) {
String qualifiedName = ((JcrExtensibleTypeProvider) this.typeProvider).ensureTypeName(typeName);
HashMap<String, String> params = new HashMap<>();
String query = "SELECT * FROM [" + qualifiedName + "] as t WHERE t.[" + propName + "] = $v";
params.put("v", value.toString());
QueryResult result = null;
try {
result = JcrQueryUtil.query(getSession(), query, params);
List<JcrExtensibleEntity> entities = JcrQueryUtil.queryResultToList(result, JcrExtensibleEntity.class);
return entities;
} catch (RepositoryException e) {
throw new MetadataRepositoryException("Unable to execute Criteria Query for " + typeName + ". Query is: " + query, e);
}
}
use of com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException in project kylo by Teradata.
the class JcrExtensibleTypeProvider method getType.
@Override
public ExtensibleType getType(final ID id) {
final JcrExtensibleType.TypeId typeId = (JcrExtensibleType.TypeId) id;
final Session session = getSession();
try {
final Node typeNode = session.getNodeByIdentifier(typeId.getIdValue());
final NodeType nodeType = session.getWorkspace().getNodeTypeManager().getNodeType(typeNode.getName());
return new JcrExtensibleType(typeNode, nodeType);
} catch (ItemNotFoundException e) {
return null;
} catch (NoSuchNodeTypeException | PathNotFoundException e) {
return null;
} catch (RepositoryException e) {
throw new MetadataRepositoryException("Failure retriving exstenible type with ID: " + id, e);
}
}
use of com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException in project kylo by Teradata.
the class JcrExtensibleTypeProvider method buildType.
/**
* Builds the type defined by the specified builder.
*
* @param builder the builder for the type
* @return the type
* @throws MetadataRepositoryException if the repository is unavailable
* @throws TypeAlreadyExistsException if a type with the same name already exists
*/
@Nonnull
private ExtensibleType buildType(@Nonnull final TypeBuilder builder) {
try {
// Remove existing type and subgraph
if (builder.node != null) {
builder.node.remove();
}
// Get or create the type node
final Session session = getSession();
final Node typeNode;
if (!session.nodeExists(JcrUtil.path(session.getRootNode().getPath(), ExtensionsConstants.TYPES + "/" + builder.name).toString())) {
typeNode = session.getRootNode().addNode(ExtensionsConstants.TYPES + "/" + builder.name, ExtensionsConstants.TYPE_DESCRIPTOR_TYPE);
} else {
throw new TypeAlreadyExistsException(builder.name);
}
// Update type metadata
if (builder.displayName != null) {
typeNode.setProperty(JcrExtensibleType.NAME, builder.displayName);
}
if (builder.description != null) {
typeNode.setProperty(JcrExtensibleType.DESCRIPTION, builder.description);
}
// Update type definition
final NodeTypeManager typeMgr = session.getWorkspace().getNodeTypeManager();
final NodeTypeTemplate nodeTemplate = typeMgr.createNodeTypeTemplate();
nodeTemplate.setName(builder.name);
if (builder.supertype != null) {
final JcrExtensibleType superImpl = (JcrExtensibleType) builder.supertype;
final String supername = superImpl.getJcrName();
nodeTemplate.setDeclaredSuperTypeNames(new String[] { ExtensionsConstants.EXTENSIBLE_ENTITY_TYPE, supername });
} else {
nodeTemplate.setDeclaredSuperTypeNames(new String[] { ExtensionsConstants.EXTENSIBLE_ENTITY_TYPE });
}
// Update field definitions
@SuppressWarnings("unchecked") final List<PropertyDefinitionTemplate> propertyDefinitionTemplates = nodeTemplate.getPropertyDefinitionTemplates();
for (final FieldBuilder bldr : builder.fieldBuilders) {
// Create field
PropertyDefinitionTemplate propDef = typeMgr.createPropertyDefinitionTemplate();
propDef.setName(bldr.name);
propDef.setRequiredType(asCode(bldr.type));
propDef.setMandatory(bldr.required);
propDef.setMultiple(bldr.collection);
propertyDefinitionTemplates.add(propDef);
// Set field metadata
Node fieldNode = typeNode.addNode(bldr.name, ExtensionsConstants.FIELD_DESCRIPTOR_TYPE);
for (final Map.Entry<String, String> entry : bldr.metadata.entrySet()) {
fieldNode.setProperty(entry.getKey(), entry.getValue());
}
}
NodeType nodeType = typeMgr.registerNodeType(nodeTemplate, true);
return new JcrExtensibleType(typeNode, nodeType);
} catch (RepositoryException e) {
throw new MetadataRepositoryException("Failed to create type: " + builder.name, e);
}
}
use of com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException in project kylo by Teradata.
the class FeedDetails method createNewPrecondition.
protected Node createNewPrecondition() {
try {
Node feedNode = getNode();
Node precondNode = JcrUtil.getOrCreateNode(feedNode, FeedDetails.PRECONDITION, JcrFeed.PRECONDITION_TYPE);
if (precondNode.hasProperty(JcrFeedPrecondition.SLA_REF)) {
precondNode.getProperty(JcrFeedPrecondition.SLA_REF).remove();
}
if (precondNode.hasNode(JcrFeedPrecondition.SLA)) {
precondNode.getNode(JcrFeedPrecondition.SLA).remove();
}
return precondNode.addNode(JcrFeedPrecondition.SLA, JcrFeedPrecondition.SLA_TYPE);
} catch (RepositoryException e) {
throw new MetadataRepositoryException("Failed to create the precondition for feed " + getParentFeed().getId(), e);
}
}
use of com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException in project kylo by Teradata.
the class JcrExtensibleTypeProvider method getType.
@Override
public ExtensibleType getType(final String name) {
final Session session = getSession();
final String typeName = ensureTypeName(name);
try {
final NodeType nodeType = session.getWorkspace().getNodeTypeManager().getNodeType(typeName);
final Node typeNode = session.getRootNode().getNode(ExtensionsConstants.TYPES + "/" + typeName);
return new JcrExtensibleType(typeNode, nodeType);
} catch (NoSuchNodeTypeException | PathNotFoundException e) {
return null;
} catch (RepositoryException e) {
throw new MetadataRepositoryException("Failed to lookup extensible type: " + name, e);
}
}
Aggregations