use of com.evolveum.midpoint.prism.path.CanonicalItemPath in project midpoint by Evolveum.
the class XPathTest method assertCanonical.
private void assertCanonical(ItemPath path, Class<? extends Containerable> clazz, String... representations) {
CanonicalItemPath canonicalItemPath = CanonicalItemPath.create(path, clazz, PrismTestUtil.getPrismContext());
System.out.println(path + " => " + canonicalItemPath.asString() + " (" + clazz + ")");
for (int i = 0; i < representations.length; i++) {
String c = canonicalItemPath.allUpToIncluding(i).asString();
assertEquals("Wrong string representation of length " + (i + 1), representations[i], c);
}
assertEquals("Wrong string representation ", representations[representations.length - 1], canonicalItemPath.asString());
}
use of com.evolveum.midpoint.prism.path.CanonicalItemPath in project midpoint by Evolveum.
the class RAuditEventRecord method toRepo.
public static RAuditEventRecord toRepo(AuditEventRecord record, PrismContext prismContext) throws DtoTranslationException {
Validate.notNull(record, "Audit event record must not be null.");
Validate.notNull(prismContext, "Prism context must not be null.");
RAuditEventRecord repo = new RAuditEventRecord();
if (record.getRepoId() != null) {
repo.setId(record.getRepoId());
}
repo.setChannel(record.getChannel());
if (record.getTimestamp() != null) {
repo.setTimestamp(new Timestamp(record.getTimestamp()));
}
repo.setEventStage(RAuditEventStage.toRepo(record.getEventStage()));
repo.setEventType(RAuditEventType.toRepo(record.getEventType()));
repo.setSessionIdentifier(record.getSessionIdentifier());
repo.setEventIdentifier(record.getEventIdentifier());
repo.setHostIdentifier(record.getHostIdentifier());
repo.setRemoteHostAddress(record.getRemoteHostAddress());
repo.setNodeIdentifier(record.getNodeIdentifier());
repo.setParameter(record.getParameter());
repo.setMessage(RUtil.trimString(record.getMessage(), AuditService.MAX_MESSAGE_SIZE));
if (record.getOutcome() != null) {
repo.setOutcome(RUtil.getRepoEnumValue(record.getOutcome().createStatusType(), ROperationResultStatus.class));
}
repo.setTaskIdentifier(record.getTaskIdentifier());
repo.setTaskOID(record.getTaskOID());
repo.setResult(record.getResult());
try {
if (record.getTarget() != null) {
PrismReferenceValue target = record.getTarget();
repo.setTargetName(getOrigName(target));
repo.setTargetOid(target.getOid());
repo.setTargetType(ClassMapper.getHQLTypeForQName(target.getTargetType()));
}
if (record.getTargetOwner() != null) {
PrismObject targetOwner = record.getTargetOwner();
repo.setTargetOwnerName(getOrigName(targetOwner));
repo.setTargetOwnerOid(targetOwner.getOid());
}
if (record.getInitiator() != null) {
PrismObject<UserType> initiator = record.getInitiator();
repo.setInitiatorName(getOrigName(initiator));
repo.setInitiatorOid(initiator.getOid());
}
for (ObjectDeltaOperation<?> delta : record.getDeltas()) {
if (delta == null) {
continue;
}
ObjectDelta<?> objectDelta = delta.getObjectDelta();
for (ItemDelta<?, ?> itemDelta : objectDelta.getModifications()) {
ItemPath path = itemDelta.getPath();
if (path != null) {
// TODO what if empty?
CanonicalItemPath canonical = CanonicalItemPath.create(path, objectDelta.getObjectTypeClass(), prismContext);
for (int i = 0; i < canonical.size(); i++) {
RAuditItem changedItem = RAuditItem.toRepo(repo, canonical.allUpToIncluding(i).asString());
repo.getChangedItems().add(changedItem);
}
}
}
RObjectDeltaOperation rDelta = RObjectDeltaOperation.toRepo(repo, delta, prismContext);
rDelta.setTransient(true);
rDelta.setRecord(repo);
repo.getDeltas().add(rDelta);
}
for (Map.Entry<String, Set<String>> propertyEntry : record.getProperties().entrySet()) {
for (String propertyValue : propertyEntry.getValue()) {
repo.getPropertyValues().add(RAuditPropertyValue.toRepo(repo, propertyEntry.getKey(), RUtil.trimString(propertyValue, AuditService.MAX_PROPERTY_SIZE)));
}
}
for (Map.Entry<String, Set<AuditReferenceValue>> referenceEntry : record.getReferences().entrySet()) {
for (AuditReferenceValue referenceValue : referenceEntry.getValue()) {
repo.getReferenceValues().add(RAuditReferenceValue.toRepo(repo, referenceEntry.getKey(), referenceValue));
}
}
} catch (Exception ex) {
throw new DtoTranslationException(ex.getMessage(), ex);
}
return repo;
}
Aggregations