Search in sources :

Example 1 with NodePropertyKey

use of org.alfresco.repo.domain.node.NodePropertyKey in project alfresco-repository by Alfresco.

the class ReEncryptor method reEncryptProperties.

protected void reEncryptProperties(final List<NodePropertyEntity> properties, final String lockToken) {
    final Iterator<NodePropertyEntity> it = properties.iterator();
    // TODO use BatchProcessWorkerAdaptor?
    BatchProcessor.BatchProcessWorker<NodePropertyEntity> worker = new BatchProcessor.BatchProcessWorker<NodePropertyEntity>() {

        public String getIdentifier(NodePropertyEntity entity) {
            return String.valueOf(entity.getNodeId());
        }

        public void beforeProcess() throws Throwable {
            refreshLock(lockToken, chunkSize * 100L);
        }

        public void afterProcess() throws Throwable {
        }

        public void process(final NodePropertyEntity entity) throws Throwable {
            NodePropertyValue nodePropValue = entity.getValue();
            // TODO check that we have the correct type i.e. can be cast to Serializable
            Serializable value = nodePropValue.getSerializableValue();
            if (value instanceof SealedObject) {
                SealedObject sealed = (SealedObject) value;
                NodePropertyKey propertyKey = entity.getKey();
                QName propertyQName = qnameDAO.getQName(propertyKey.getQnameId()).getSecond();
                // decrypt...
                Serializable decrypted = metadataEncryptor.decrypt(propertyQName, sealed);
                // ...and then re-encrypt. The new key will be used.
                Serializable resealed = metadataEncryptor.encrypt(propertyQName, decrypted);
                // TODO update resealed using batch update?
                // does the node DAO do batch updating?
                nodeDAO.setNodeProperties(entity.getNodeId(), Collections.singletonMap(propertyQName, resealed));
            } else {
                NodePropertyKey nodeKey = entity.getKey();
                QName propertyQName = qnameDAO.getQName(nodeKey.getQnameId()).getSecond();
                logger.warn("Encountered an encrypted property that is not a SealedObject, for node id " + entity.getNodeId() + ", property " + propertyQName);
            }
        }
    };
    BatchProcessWorkProvider<NodePropertyEntity> provider = new BatchProcessWorkProvider<NodePropertyEntity>() {

        @Override
        public int getTotalEstimatedWorkSize() {
            return properties.size();
        }

        @Override
        public Collection<NodePropertyEntity> getNextWork() {
            List<NodePropertyEntity> sublist = new ArrayList<NodePropertyEntity>(chunkSize);
            synchronized (it) {
                int count = 0;
                while (it.hasNext() && count < chunkSize) {
                    sublist.add(it.next());
                    count++;
                }
            }
            return sublist;
        }
    };
    new BatchProcessor<NodePropertyEntity>("Reencryptor", transactionHelper, provider, numThreads, chunkSize, applicationContext, logger, 100).process(worker, splitTxns);
}
Also used : Serializable(java.io.Serializable) QName(org.alfresco.service.namespace.QName) NodePropertyEntity(org.alfresco.repo.domain.node.NodePropertyEntity) ArrayList(java.util.ArrayList) SealedObject(javax.crypto.SealedObject) BatchProcessWorkProvider(org.alfresco.repo.batch.BatchProcessWorkProvider) BatchProcessor(org.alfresco.repo.batch.BatchProcessor) NodePropertyValue(org.alfresco.repo.domain.node.NodePropertyValue) NodePropertyKey(org.alfresco.repo.domain.node.NodePropertyKey)

Example 2 with NodePropertyKey

use of org.alfresco.repo.domain.node.NodePropertyKey in project alfresco-repository by Alfresco.

the class NodeDAOImpl method selectNodeProperties.

@Override
protected Map<NodeVersionKey, Map<NodePropertyKey, NodePropertyValue>> selectNodeProperties(Long nodeId, Set<Long> qnameIds) {
    NodePropertyEntity prop = new NodePropertyEntity();
    // Node
    prop.setNodeId(nodeId);
    // QName(s)
    switch(qnameIds.size()) {
        case 0:
            // Ignore
            break;
        case 1:
            prop.setKey(new NodePropertyKey());
            prop.getKey().setQnameId(qnameIds.iterator().next());
            break;
        default:
            prop.setQnameIds(new ArrayList<Long>(qnameIds));
    }
    List<NodePropertyEntity> rows = template.selectList(SELECT_NODE_PROPERTIES, prop);
    return makePersistentPropertiesMap(rows);
}
Also used : NodePropertyKey(org.alfresco.repo.domain.node.NodePropertyKey) NodePropertyEntity(org.alfresco.repo.domain.node.NodePropertyEntity)

Example 3 with NodePropertyKey

use of org.alfresco.repo.domain.node.NodePropertyKey in project alfresco-repository by Alfresco.

the class NodeDAOImpl method makePersistentPropertiesMap.

/**
 * Pull out the key-value pairs from the rows
 */
private Map<NodeVersionKey, Map<NodePropertyKey, NodePropertyValue>> makePersistentPropertiesMap(List<NodePropertyEntity> rows) {
    Map<NodeVersionKey, Map<NodePropertyKey, NodePropertyValue>> results = new HashMap<NodeVersionKey, Map<NodePropertyKey, NodePropertyValue>>(3);
    for (NodePropertyEntity row : rows) {
        Long nodeId = row.getNodeId();
        Long nodeVersion = row.getNodeVersion();
        if (nodeId == null || nodeVersion == null) {
            throw new RuntimeException("Expect results with a Node and Version: " + row);
        }
        NodeVersionKey nodeTxnKey = new NodeVersionKey(nodeId, nodeVersion);
        Map<NodePropertyKey, NodePropertyValue> props = results.get(nodeTxnKey);
        if (props == null) {
            props = new HashMap<NodePropertyKey, NodePropertyValue>(17);
            results.put(nodeTxnKey, props);
        }
        props.put(row.getKey(), row.getValue());
    }
    // Done
    return results;
}
Also used : AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) NodeVersionKey(org.alfresco.repo.domain.node.NodeVersionKey) HashMap(java.util.HashMap) NodePropertyKey(org.alfresco.repo.domain.node.NodePropertyKey) NodePropertyValue(org.alfresco.repo.domain.node.NodePropertyValue) NodePropertyEntity(org.alfresco.repo.domain.node.NodePropertyEntity) HashMap(java.util.HashMap) Map(java.util.Map)

Example 4 with NodePropertyKey

use of org.alfresco.repo.domain.node.NodePropertyKey in project alfresco-repository by Alfresco.

the class NodeDAOImpl method makePersistentRows.

/**
 * Convert key-value pairs into rows
 */
private List<NodePropertyEntity> makePersistentRows(Long nodeId, Map<NodePropertyKey, NodePropertyValue> map) {
    List<NodePropertyEntity> rows = new ArrayList<NodePropertyEntity>(map.size());
    for (Map.Entry<NodePropertyKey, NodePropertyValue> entry : map.entrySet()) {
        NodePropertyEntity row = new NodePropertyEntity();
        row.setNodeId(nodeId);
        row.setKey(entry.getKey());
        row.setValue(entry.getValue());
        rows.add(row);
    }
    // Done
    return rows;
}
Also used : NodePropertyKey(org.alfresco.repo.domain.node.NodePropertyKey) NodePropertyValue(org.alfresco.repo.domain.node.NodePropertyValue) NodePropertyEntity(org.alfresco.repo.domain.node.NodePropertyEntity) ArrayList(java.util.ArrayList) HashMap(java.util.HashMap) Map(java.util.Map)

Example 5 with NodePropertyKey

use of org.alfresco.repo.domain.node.NodePropertyKey in project alfresco-repository by Alfresco.

the class NodeDAOImpl method deleteNodeProperties.

@Override
protected int deleteNodeProperties(Long nodeId, List<NodePropertyKey> propKeys) {
    Assert.notNull(nodeId, "Must have 'nodeId'");
    Assert.notNull(nodeId, "Must have 'propKeys'");
    if (propKeys.size() == 0) {
        return 0;
    }
    NodePropertyEntity prop = new NodePropertyEntity();
    // Node
    prop.setNodeId(nodeId);
    startBatch();
    int count = 0;
    try {
        for (NodePropertyKey propKey : propKeys) {
            prop.setKey(propKey);
            count += template.delete(DELETE_NODE_PROPERTIES, prop);
        }
    } finally {
        executeBatch();
    }
    return count;
}
Also used : NodePropertyKey(org.alfresco.repo.domain.node.NodePropertyKey) NodePropertyEntity(org.alfresco.repo.domain.node.NodePropertyEntity)

Aggregations

NodePropertyEntity (org.alfresco.repo.domain.node.NodePropertyEntity)5 NodePropertyKey (org.alfresco.repo.domain.node.NodePropertyKey)5 NodePropertyValue (org.alfresco.repo.domain.node.NodePropertyValue)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Serializable (java.io.Serializable)1 SealedObject (javax.crypto.SealedObject)1 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)1 BatchProcessWorkProvider (org.alfresco.repo.batch.BatchProcessWorkProvider)1 BatchProcessor (org.alfresco.repo.batch.BatchProcessor)1 NodeVersionKey (org.alfresco.repo.domain.node.NodeVersionKey)1 QName (org.alfresco.service.namespace.QName)1