Search in sources :

Example 1 with JcrExtensiblePropertyCollection

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

the class JcrPropertyUtil method setProperties.

public static Node setProperties(Session session, Node entNode, Map<String, Object> props) {
    ValueFactory factory;
    try {
        factory = session.getValueFactory();
        if (props != null) {
            // JcrVersionUtil.ensureCheckoutNode(entNode);
            for (Map.Entry<String, Object> entry : props.entrySet()) {
                if (entry.getValue() instanceof JcrExtensiblePropertyCollection) {
                    JcrExtensiblePropertyCollection propertyCollection = ((JcrExtensiblePropertyCollection) entry.getValue());
                    propertyCollection.getCollectionType();
                    Value[] values = new Value[propertyCollection.getCollection().size()];
                    int i = 0;
                    for (Object o : propertyCollection.getCollection()) {
                        boolean weak = false;
                        if (propertyCollection.getCollectionType() == PropertyType.WEAKREFERENCE) {
                            weak = true;
                        }
                        Value value = createValue(session, o, weak);
                        values[i] = value;
                        i++;
                    }
                    entNode.setProperty(entry.getKey(), values);
                } else {
                    Value value = asValue(factory, entry.getValue());
                    entNode.setProperty(entry.getKey(), value);
                }
            }
        }
        return entNode;
    } catch (AccessDeniedException e) {
        log.debug("Access denied", e);
        throw new AccessControlException(e.getMessage());
    } catch (RepositoryException e) {
        throw new MetadataRepositoryException("Failed to set properties", e);
    }
}
Also used : MetadataRepositoryException(com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException) AccessDeniedException(javax.jcr.AccessDeniedException) JcrExtensiblePropertyCollection(com.thinkbiganalytics.metadata.modeshape.extension.JcrExtensiblePropertyCollection) AccessControlException(java.security.AccessControlException) MetadataRepositoryException(com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException) RepositoryException(javax.jcr.RepositoryException) ValueFactory(javax.jcr.ValueFactory) Value(javax.jcr.Value) JcrObject(com.thinkbiganalytics.metadata.modeshape.common.JcrObject) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

MetadataRepositoryException (com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException)1 JcrObject (com.thinkbiganalytics.metadata.modeshape.common.JcrObject)1 JcrExtensiblePropertyCollection (com.thinkbiganalytics.metadata.modeshape.extension.JcrExtensiblePropertyCollection)1 AccessControlException (java.security.AccessControlException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 AccessDeniedException (javax.jcr.AccessDeniedException)1 RepositoryException (javax.jcr.RepositoryException)1 Value (javax.jcr.Value)1 ValueFactory (javax.jcr.ValueFactory)1