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