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);
}
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);
}
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;
}
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;
}
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;
}
Aggregations