Search in sources :

Example 1 with NodePropertyValue

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

the class PropertyFieldProcessor method getDefaultValue.

private Object getDefaultValue(QName name, ContentModelItemData<?> data) {
    PropertyDefinition propDef = data.getPropertyDefinition(name);
    if (propDef != null) {
        QName typeQName = propDef.getDataType().getName();
        String strDefaultValue = propDef.getDefaultValue();
        if (NodePropertyValue.isDataTypeSupported(typeQName)) {
            // convert to the appropriate type
            NodePropertyValue pv = new NodePropertyValue(typeQName, strDefaultValue);
            return pv.getValue(typeQName);
        }
        return strDefaultValue;
    }
    return null;
}
Also used : QName(org.alfresco.service.namespace.QName) NodePropertyValue(org.alfresco.repo.domain.node.NodePropertyValue) PropertyDefinition(org.alfresco.service.cmr.dictionary.PropertyDefinition)

Example 2 with NodePropertyValue

use of org.alfresco.repo.domain.node.NodePropertyValue 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 3 with NodePropertyValue

use of org.alfresco.repo.domain.node.NodePropertyValue 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 NodePropertyValue

use of org.alfresco.repo.domain.node.NodePropertyValue 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)

Aggregations

NodePropertyValue (org.alfresco.repo.domain.node.NodePropertyValue)4 NodePropertyEntity (org.alfresco.repo.domain.node.NodePropertyEntity)3 NodePropertyKey (org.alfresco.repo.domain.node.NodePropertyKey)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 QName (org.alfresco.service.namespace.QName)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 PropertyDefinition (org.alfresco.service.cmr.dictionary.PropertyDefinition)1