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