Search in sources :

Example 1 with MetadataRepositoryException

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();
}
Also used : MetadataRepositoryException(com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException) JcrFeedTemplate(com.thinkbiganalytics.metadata.modeshape.template.JcrFeedTemplate) FeedManagerTemplate(com.thinkbiganalytics.metadata.api.template.FeedManagerTemplate) Feed(com.thinkbiganalytics.metadata.api.feed.Feed) JcrFeed(com.thinkbiganalytics.metadata.modeshape.feed.JcrFeed) ItemNotFoundException(javax.jcr.ItemNotFoundException)

Example 2 with MetadataRepositoryException

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);
        }
    }
}
Also used : MetadataRepositoryException(com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException) AccessDeniedException(javax.jcr.AccessDeniedException) UserFieldDescriptor(com.thinkbiganalytics.metadata.api.extension.UserFieldDescriptor) JcrUserFieldDescriptor(com.thinkbiganalytics.metadata.modeshape.extension.JcrUserFieldDescriptor) PropertyIterator(javax.jcr.PropertyIterator) AccessControlException(java.security.AccessControlException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) MetadataRepositoryException(com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException) RepositoryException(javax.jcr.RepositoryException) MissingUserPropertyException(com.thinkbiganalytics.metadata.api.MissingUserPropertyException) Property(javax.jcr.Property) HashSet(java.util.HashSet)

Example 3 with MetadataRepositoryException

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);
    }
}
Also used : MetadataRepositoryException(com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException) AccessDeniedException(javax.jcr.AccessDeniedException) Node(javax.jcr.Node) Value(javax.jcr.Value) AccessControlException(java.security.AccessControlException) MetadataRepositoryException(com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException) RepositoryException(javax.jcr.RepositoryException) Property(javax.jcr.Property)

Example 4 with MetadataRepositoryException

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;
}
Also used : MetadataRepositoryException(com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException) HashMap(java.util.HashMap) JcrProperties(com.thinkbiganalytics.metadata.modeshape.common.JcrProperties) ConstraintViolationException(javax.jcr.nodetype.ConstraintViolationException) Map(java.util.Map) HashMap(java.util.HashMap)

Example 5 with MetadataRepositoryException

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);
    }
}
Also used : MetadataRepositoryException(com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException) Node(javax.jcr.Node) Iterator(java.util.Iterator) MetadataRepositoryException(com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException) RepositoryException(javax.jcr.RepositoryException)

Aggregations

MetadataRepositoryException (com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException)99 RepositoryException (javax.jcr.RepositoryException)90 Node (javax.jcr.Node)61 AccessControlException (java.security.AccessControlException)36 AccessDeniedException (javax.jcr.AccessDeniedException)36 Session (javax.jcr.Session)29 ArrayList (java.util.ArrayList)19 HashMap (java.util.HashMap)17 HashSet (java.util.HashSet)16 NodeIterator (javax.jcr.NodeIterator)14 Value (javax.jcr.Value)14 Nonnull (javax.annotation.Nonnull)13 Map (java.util.Map)12 Property (javax.jcr.Property)12 Set (java.util.Set)10 DateTime (org.joda.time.DateTime)10 UserFieldDescriptor (com.thinkbiganalytics.metadata.api.extension.UserFieldDescriptor)9 ItemNotFoundException (javax.jcr.ItemNotFoundException)9 Collection (java.util.Collection)8 List (java.util.List)8