mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-09-10 14:11:58 +00:00
[ACS-9736] Refactor audit record builder and add unit test for NodeRef handling
This commit is contained in:
@@ -47,10 +47,20 @@ public class AuditRecordUtils
|
|||||||
* is a length of key root.
|
* is a length of key root.
|
||||||
* @return a preloaded {@link AuditRecord.Builder}
|
* @return a preloaded {@link AuditRecord.Builder}
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public static AuditRecord.Builder generateAuditRecordBuilder(Map<String, Serializable> data, int keyRootLength)
|
public static AuditRecord.Builder generateAuditRecordBuilder(Map<String, Serializable> data, int keyRootLength)
|
||||||
{
|
{
|
||||||
var auditRecordBuilder = AuditRecord.builder();
|
var auditRecordBuilder = AuditRecord.builder();
|
||||||
|
|
||||||
|
var rootNode = createRootNode(data, keyRootLength);
|
||||||
|
|
||||||
|
auditRecordBuilder.setAuditRecordData(rootNode);
|
||||||
|
|
||||||
|
return auditRecordBuilder;
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
private static HashMap<String, Serializable> createRootNode(Map<String, Serializable> data, int keyRootLength)
|
||||||
|
{
|
||||||
var rootNode = new HashMap<String, Serializable>();
|
var rootNode = new HashMap<String, Serializable>();
|
||||||
|
|
||||||
data.forEach((k, v) -> {
|
data.forEach((k, v) -> {
|
||||||
@@ -63,14 +73,17 @@ public class AuditRecordUtils
|
|||||||
}
|
}
|
||||||
current.put(keys[keys.length - 1], decodeValueByInstance(v));
|
current.put(keys[keys.length - 1], decodeValueByInstance(v));
|
||||||
});
|
});
|
||||||
auditRecordBuilder.setAuditRecordData(rootNode);
|
return rootNode;
|
||||||
|
|
||||||
return auditRecordBuilder;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
private static Serializable decodeValueByInstance(Serializable value)
|
private static Serializable decodeValueByInstance(Serializable value)
|
||||||
{
|
{
|
||||||
if (value instanceof NodeRef)
|
if (value instanceof HashMap<?, ?>)
|
||||||
|
{
|
||||||
|
return createRootNode((HashMap<String, Serializable>) value, 0);
|
||||||
|
}
|
||||||
|
else if (value instanceof NodeRef)
|
||||||
{
|
{
|
||||||
return ((NodeRef) value).getId();
|
return ((NodeRef) value).getId();
|
||||||
}
|
}
|
||||||
|
@@ -37,6 +37,7 @@ import java.util.Map;
|
|||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import org.alfresco.service.cmr.repository.NodeRef;
|
||||||
import org.alfresco.service.namespace.QName;
|
import org.alfresco.service.namespace.QName;
|
||||||
|
|
||||||
public class AuditRecordUtilsTest
|
public class AuditRecordUtilsTest
|
||||||
@@ -78,4 +79,45 @@ public class AuditRecordUtilsTest
|
|||||||
assertEquals(testData.get("/alfresco-access/transaction/properties/to"), properties.get("to"));
|
assertEquals(testData.get("/alfresco-access/transaction/properties/to"), properties.get("to"));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
@Test
|
||||||
|
public void testGenerateAuditRecordBuilderTestNodeRef()
|
||||||
|
{
|
||||||
|
var testData = new HashMap<String, Serializable>();
|
||||||
|
var expectedValue = new HashMap<String, Serializable>();
|
||||||
|
|
||||||
|
expectedValue.put("nodeRef", new NodeRef("workspace://SpacesStore/bfa612e6-1a02-46a0-a612-e61a02e6a036"));
|
||||||
|
expectedValue.put("objectId", "bfa612e6-1a02-46a0-a612-e61a02e6a036;1.0");
|
||||||
|
|
||||||
|
testData.put("/CMISChangeLog/CREATED/result/value", expectedValue);
|
||||||
|
|
||||||
|
var builder = AuditRecordUtils.generateAuditRecordBuilder(testData, "/CMISChangeLog/".length());
|
||||||
|
builder.setAuditRecordType("CMISChangeLog");
|
||||||
|
var auditRecord = builder.build();
|
||||||
|
|
||||||
|
assertNotNull(auditRecord);
|
||||||
|
|
||||||
|
assertEquals("CMISChangeLog", auditRecord.getAuditApplicationId());
|
||||||
|
|
||||||
|
var auditData = auditRecord.getAuditData();
|
||||||
|
assertEquals(1, auditData.size());
|
||||||
|
|
||||||
|
var created = (HashMap<String, ?>) auditData.get("CREATED");
|
||||||
|
assertNotNull(created);
|
||||||
|
|
||||||
|
assertEquals(1, created.size());
|
||||||
|
var result = (HashMap<String, Object>) created.get("result");
|
||||||
|
assertNotNull(result);
|
||||||
|
assertEquals(1, result.size());
|
||||||
|
|
||||||
|
var resultValue = (HashMap<String, Object>) result.get("value");
|
||||||
|
assertNotNull(resultValue);
|
||||||
|
assertEquals(2, resultValue.size());
|
||||||
|
|
||||||
|
var expectedNodeRef = (NodeRef) expectedValue.get("nodeRef");
|
||||||
|
assertEquals(expectedNodeRef.getId(), resultValue.get("nodeRef"));
|
||||||
|
assertEquals(expectedValue.get("objectId"), resultValue.get("objectId"));
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user