use of com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException in project kylo by Teradata.
the class EnsureTemplateFeedRelationshipsUpgradeAction method ensureFeedTemplateFeedRelationships.
private void ensureFeedTemplateFeedRelationships() {
// ensure the templates have the feed relationships
List<Feed> feeds = feedProvider.findAll();
if (feeds != null) {
feeds.stream().forEach(feed -> {
FeedManagerTemplate template = feed.getTemplate();
if (template != null) {
// ensure the template has feeds.
List<Feed> templateFeeds = null;
try {
templateFeeds = template.getFeeds();
} catch (MetadataRepositoryException e) {
// templateFeeds are weak references.
// if the template feeds return itemNotExists we need to reset it
Throwable rootCause = ExceptionUtils.getRootCause(e);
if (rootCause != null && rootCause instanceof ItemNotFoundException) {
// reset the reference collection. It will be rebuilt in the subsequent call
JcrPropertyUtil.removeAllFromSetProperty(((JcrFeedTemplate) template).getNode(), JcrFeedTemplate.FEEDS);
}
}
if (templateFeeds == null || !templateFeeds.contains(feed)) {
log.info("Updating relationship temlate: {} -> feed: {}", template.getName(), feed.getName());
template.addFeed(feed);
feedManagerTemplateProvider.update(template);
}
}
});
}
feedProvider.populateInverseFeedDependencies();
}
use of com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException in project kylo by Teradata.
the class JcrPropertyUtil method setUserProperties.
/**
* Sets the specified user-defined properties on the specified node.
*
* @param node the target node
* @param fields the predefined user fields
* @param properties the map of user-defined property names to values
* @throws IllegalStateException if a property name is encoded incorrectly
* @throws MetadataRepositoryException if the metadata repository is unavailable
*/
public static void setUserProperties(@Nonnull final Node node, @Nonnull final Set<UserFieldDescriptor> fields, @Nonnull final Map<String, String> properties) {
// Verify required properties are not empty
for (final UserFieldDescriptor field : fields) {
if (field.isRequired() && StringUtils.isEmpty(properties.get(field.getSystemName()))) {
throw new MissingUserPropertyException("Missing required property: " + field.getSystemName());
}
}
// Set properties on node
final Set<String> newProperties = new HashSet<>(properties.size());
final String prefix = JcrMetadataAccess.USR_PREFIX + ":";
properties.forEach((key, value) -> {
try {
final String name = prefix + URLEncoder.encode(key, USER_PROPERTY_ENCODING);
newProperties.add(name);
node.setProperty(name, value);
} catch (AccessDeniedException e) {
log.debug("Access denied", e);
throw new AccessControlException(e.getMessage());
} catch (RepositoryException e) {
throw new MetadataRepositoryException("Failed to set user property \"" + key + "\" on node: " + node, e);
} catch (UnsupportedEncodingException e) {
throw new IllegalStateException(e.toString(), e);
}
});
// Get node properties
final PropertyIterator iterator;
try {
iterator = node.getProperties();
} catch (AccessDeniedException e) {
log.debug("Access denied", e);
throw new AccessControlException(e.getMessage());
} catch (RepositoryException e) {
throw new MetadataRepositoryException("Failed to get properties for node: " + node, e);
}
// Remove properties from node
while (iterator.hasNext()) {
final Property property = iterator.nextProperty();
try {
final String name = property.getName();
if (name.startsWith(prefix) && !newProperties.contains(name)) {
property.remove();
}
} catch (AccessDeniedException e) {
log.debug("Access denied", e);
throw new AccessControlException(e.getMessage());
} catch (RepositoryException e) {
throw new MetadataRepositoryException("Failed to remove property \"" + property + "\" on node: " + node, e);
}
}
}
use of com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException in project kylo by Teradata.
the class JcrPropertyUtil method addToSetProperty.
public static boolean addToSetProperty(Node node, String name, Object value, boolean weakReference) {
try {
if (node == null) {
throw new IllegalArgumentException("Cannot set a property on a null-node!");
}
if (name == null) {
throw new IllegalArgumentException("Cannot set a property without a provided name");
}
Set<Value> values = null;
if (node.hasProperty(name)) {
values = Arrays.stream(node.getProperty(name).getValues()).map(v -> {
if (PropertyType.REFERENCE == v.getType() && weakReference) {
try {
Node n = JcrPropertyUtil.asValue(v, node.getSession());
return n.getSession().getValueFactory().createValue(n, true);
} catch (AccessDeniedException e) {
log.debug("Access denied", e);
throw new AccessControlException(e.getMessage());
} catch (RepositoryException e) {
throw new MetadataRepositoryException("Failed to add to set property: " + name + "->" + value, e);
}
} else {
return v;
}
}).collect(Collectors.toSet());
} else {
values = new HashSet<>();
}
Value newVal = createValue(node.getSession(), value, weakReference);
boolean result = values.add(newVal);
if (weakReference) {
Property property = node.setProperty(name, (Value[]) values.stream().toArray(size -> new Value[size]), PropertyType.WEAKREFERENCE);
} else {
Property property = node.setProperty(name, (Value[]) values.stream().toArray(size -> new Value[size]));
}
return result;
} catch (AccessDeniedException e) {
log.debug("Access denied", e);
throw new AccessControlException(e.getMessage());
} catch (RepositoryException e) {
throw new MetadataRepositoryException("Failed to add to set property: " + name + "->" + value, e);
}
}
use of com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException in project kylo by Teradata.
the class PropertiedMixin method mergeProperties.
/**
* Merges any new properties in with the other Extra Properties
*/
@Override
default Map<String, Object> mergeProperties(Map<String, Object> props) {
Map<String, Object> newProps = new HashMap<>();
Map<String, Object> origProps = getProperties();
if (origProps != null) {
newProps.putAll(origProps);
}
if (props != null) {
newProps.putAll(props);
}
JcrProperties properties = getPropertiesObject();
for (Map.Entry<String, Object> entry : newProps.entrySet()) {
try {
properties.setProperty(entry.getKey(), entry.getValue());
} catch (MetadataRepositoryException e) {
if (ExceptionUtils.getRootCause(e) instanceof ConstraintViolationException) {
// this is ok
} else {
throw e;
}
}
}
return newProps;
}
use of com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException in project kylo by Teradata.
the class JcrServiceLevelAgreement method clear.
public void clear() {
try {
Iterator<Node> grpItr = (Iterator<Node>) getNode().getNodes(GROUPS);
while (grpItr.hasNext()) {
Node group = grpItr.next();
group.remove();
}
grpItr = (Iterator<Node>) getNode().getNodes(DEFAULT_GROUP);
while (grpItr.hasNext()) {
Node group = grpItr.next();
group.remove();
}
} catch (RepositoryException e) {
throw new MetadataRepositoryException("Failed to clear the SLA obligation group nodes", e);
}
}
Aggregations