Search in sources :

Example 41 with MetadataRepositoryException

use of com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException in project kylo by Teradata.

the class JcrServiceLevelAgreementProvider method removeAgreement.

/* (non-Javadoc)
     * @see com.thinkbiganalytics.metadata.sla.spi.ServiceLevelAgreementProvider#removeAgreement(com.thinkbiganalytics.metadata.sla.api.ServiceLevelAgreement.ID)
     */
@Override
public boolean removeAgreement(ID id) {
    try {
        Session session = getSession();
        SlaId slaId = (SlaId) id;
        Node slaNode = session.getNodeByIdentifier(slaId.getIdValue());
        if (slaNode != null) {
            JcrServiceLevelAgreement sla = new JcrServiceLevelAgreement(slaNode);
            addPostSlaChangeAction(sla, MetadataChange.ChangeType.DELETE);
            // remove any other relationships
            feedServiceLevelAgreementProvider.removeAllRelationships(id);
            slaNode.remove();
        }
        return true;
    } catch (ItemNotFoundException e) {
        return false;
    } catch (RepositoryException e) {
        throw new MetadataRepositoryException("Failed to retrieve the SLA node", e);
    }
}
Also used : MetadataRepositoryException(com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException) SlaId(com.thinkbiganalytics.metadata.modeshape.sla.JcrServiceLevelAgreement.SlaId) Node(javax.jcr.Node) MetadataRepositoryException(com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException) RepositoryException(javax.jcr.RepositoryException) Session(javax.jcr.Session) ItemNotFoundException(javax.jcr.ItemNotFoundException)

Example 42 with MetadataRepositoryException

use of com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException in project kylo by Teradata.

the class JcrServiceLevelAgreementProvider method builder.

/* (non-Javadoc)
     * @see com.thinkbiganalytics.metadata.sla.spi.ServiceLevelAgreementProvider#builder()
     */
@Override
public ServiceLevelAgreementBuilder builder() {
    try {
        Session session = getSession();
        Node slasNode = session.getNode(EntityUtil.pathForSla());
        Node slaNode = slasNode.addNode("sla-" + UUID.randomUUID(), "tba:sla");
        return builder(slaNode);
    } catch (RepositoryException e) {
        throw new MetadataRepositoryException("Failed to create an sla node", e);
    }
}
Also used : MetadataRepositoryException(com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException) Node(javax.jcr.Node) MetadataRepositoryException(com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException) RepositoryException(javax.jcr.RepositoryException) Session(javax.jcr.Session)

Example 43 with MetadataRepositoryException

use of com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException in project kylo by Teradata.

the class JcrPropertyUtil method getProperties.

public static Map<String, Object> getProperties(Node node) {
    try {
        Map<String, Object> propMap = new HashMap<>();
        PropertyIterator itr = node.getProperties();
        while (itr.hasNext()) {
            try {
                Property prop = (Property) itr.next();
                Object value = asValue(prop);
                propMap.put(prop.getName(), value);
            } catch (AccessDeniedException e) {
                log.debug("Access denied - skipping property", e);
            }
        }
        return propMap;
    } catch (AccessDeniedException e) {
        log.debug("Access denied", e);
        throw new AccessControlException(e.getMessage());
    } catch (RepositoryException e) {
        throw new MetadataRepositoryException("Failed to access properties", e);
    }
}
Also used : MetadataRepositoryException(com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException) AccessDeniedException(javax.jcr.AccessDeniedException) HashMap(java.util.HashMap) PropertyIterator(javax.jcr.PropertyIterator) AccessControlException(java.security.AccessControlException) JcrObject(com.thinkbiganalytics.metadata.modeshape.common.JcrObject) MetadataRepositoryException(com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException) RepositoryException(javax.jcr.RepositoryException) Property(javax.jcr.Property)

Example 44 with MetadataRepositoryException

use of com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException in project kylo by Teradata.

the class PropertiedMixin method clearAdditionalProperties.

default void clearAdditionalProperties() {
    try {
        Node propsNode = getPropertiesObject().getNode();
        Map<String, Object> props = getPropertiesObject().getProperties();
        for (Map.Entry<String, Object> prop : props.entrySet()) {
            if (!JcrPropertyUtil.hasProperty(propsNode.getPrimaryNodeType(), prop.getKey())) {
                Property property = propsNode.getProperty(prop.getKey());
                property.remove();
            }
        }
    } catch (RepositoryException e) {
        throw new MetadataRepositoryException("Unable to clear the Properties for this entity. ", e);
    }
}
Also used : MetadataRepositoryException(com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException) Node(javax.jcr.Node) RepositoryException(javax.jcr.RepositoryException) MetadataRepositoryException(com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException) Map(java.util.Map) HashMap(java.util.HashMap) Property(javax.jcr.Property)

Example 45 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)

Aggregations

MetadataRepositoryException (com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException)83 RepositoryException (javax.jcr.RepositoryException)79 Node (javax.jcr.Node)54 AccessDeniedException (javax.jcr.AccessDeniedException)29 AccessControlException (java.security.AccessControlException)28 Session (javax.jcr.Session)25 ArrayList (java.util.ArrayList)16 HashMap (java.util.HashMap)14 HashSet (java.util.HashSet)12 NodeIterator (javax.jcr.NodeIterator)12 Nonnull (javax.annotation.Nonnull)10 Value (javax.jcr.Value)10 Map (java.util.Map)9 Property (javax.jcr.Property)8 ItemNotFoundException (javax.jcr.ItemNotFoundException)7 QueryResult (javax.jcr.query.QueryResult)7 JcrObject (com.thinkbiganalytics.metadata.modeshape.common.JcrObject)6 AccessControlManager (javax.jcr.security.AccessControlManager)6 UserFieldDescriptor (com.thinkbiganalytics.metadata.api.extension.UserFieldDescriptor)5 List (java.util.List)5