Search in sources :

Example 6 with NodePropertyEntity

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

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

the class NodeDAOImpl method selectNodePropertiesByTypes.

@Override
@SuppressWarnings("rawtypes")
public List<NodePropertyEntity> selectNodePropertiesByTypes(Set<QName> qnames) {
    final List<NodePropertyEntity> properties = new ArrayList<NodePropertyEntity>();
    // qnames of properties that are encrypted
    Set<Long> qnameIds = qnameDAO.convertQNamesToIds(qnames, false);
    if (qnameIds.size() > 0) {
        IdsEntity param = new IdsEntity();
        param.setIds(new ArrayList<Long>(qnameIds));
        // TODO - use a callback approach
        template.select(SELECT_PROPERTIES_BY_TYPES, param, new ResultHandler() {

            @Override
            public void handleResult(ResultContext context) {
                properties.add((NodePropertyEntity) context.getResultObject());
            }
        });
    }
    return properties;
}
Also used : ResultContext(org.apache.ibatis.session.ResultContext) DefaultResultContext(org.apache.ibatis.executor.result.DefaultResultContext) IdsEntity(org.alfresco.ibatis.IdsEntity) NodePropertyEntity(org.alfresco.repo.domain.node.NodePropertyEntity) ArrayList(java.util.ArrayList) ResultHandler(org.apache.ibatis.session.ResultHandler)

Example 8 with NodePropertyEntity

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

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

the class ReEncryptor method reEncryptImpl.

protected int reEncryptImpl() {
    // Take out a re-encryptor lock
    RetryingTransactionCallback<String> txnWork = new RetryingTransactionCallback<String>() {

        public String execute() throws Exception {
            String lockToken = getLock(20000L);
            return lockToken;
        }
    };
    String lockToken = transactionService.getRetryingTransactionHelper().doInTransaction(txnWork, false, true);
    if (lockToken == null) {
        logger.warn("Can't get lock. Assume multiple re-encryptors ...");
        return 0;
    }
    // get encrypted properties
    Collection<PropertyDefinition> propertyDefs = dictionaryDAO.getPropertiesOfDataType(DataTypeDefinition.ENCRYPTED);
    Set<QName> qnames = new HashSet<QName>();
    for (PropertyDefinition propDef : propertyDefs) {
        qnames.add(propDef.getName());
    }
    // TODO use callback mechanism, or select based on set of nodes?
    List<NodePropertyEntity> properties = nodeDAO.selectNodePropertiesByTypes(qnames);
    if (logger.isDebugEnabled()) {
        logger.debug("Found " + properties.size() + " properties to re-encrypt...");
    }
    // reencrypt these properties TODO don't call if num props == 0
    reEncryptProperties(properties, lockToken);
    if (logger.isDebugEnabled()) {
        logger.debug("...done re-encrypting.");
    }
    return properties.size();
}
Also used : RetryingTransactionCallback(org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback) QName(org.alfresco.service.namespace.QName) NodePropertyEntity(org.alfresco.repo.domain.node.NodePropertyEntity) PropertyDefinition(org.alfresco.service.cmr.dictionary.PropertyDefinition) HashSet(java.util.HashSet)

Example 10 with NodePropertyEntity

use of org.alfresco.repo.domain.node.NodePropertyEntity 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)12 NodePropertyKey (org.alfresco.repo.domain.node.NodePropertyKey)5 ArrayList (java.util.ArrayList)4 NodePropertyValue (org.alfresco.repo.domain.node.NodePropertyValue)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 IdsEntity (org.alfresco.ibatis.IdsEntity)2 BatchProcessor (org.alfresco.repo.batch.BatchProcessor)2 QName (org.alfresco.service.namespace.QName)2 DefaultResultContext (org.apache.ibatis.executor.result.DefaultResultContext)2 ResultContext (org.apache.ibatis.session.ResultContext)2 ResultHandler (org.apache.ibatis.session.ResultHandler)2 Serializable (java.io.Serializable)1 HashSet (java.util.HashSet)1 SealedObject (javax.crypto.SealedObject)1 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)1 BatchProcessWorkProvider (org.alfresco.repo.batch.BatchProcessWorkProvider)1 NodeVersionKey (org.alfresco.repo.domain.node.NodeVersionKey)1 RetryingTransactionHelper (org.alfresco.repo.transaction.RetryingTransactionHelper)1 RetryingTransactionCallback (org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback)1