Search in sources :

Example 1 with CanonicalItemPath

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());
}
Also used : CanonicalItemPath(com.evolveum.midpoint.prism.path.CanonicalItemPath)

Example 2 with CanonicalItemPath

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;
}
Also used : PolyString(com.evolveum.midpoint.prism.polystring.PolyString) AuditReferenceValue(com.evolveum.midpoint.audit.api.AuditReferenceValue) Timestamp(java.sql.Timestamp) CanonicalItemPath(com.evolveum.midpoint.prism.path.CanonicalItemPath) DtoTranslationException(com.evolveum.midpoint.repo.sql.util.DtoTranslationException) PrismObject(com.evolveum.midpoint.prism.PrismObject) DtoTranslationException(com.evolveum.midpoint.repo.sql.util.DtoTranslationException) PrismReferenceValue(com.evolveum.midpoint.prism.PrismReferenceValue) ROperationResultStatus(com.evolveum.midpoint.repo.sql.data.common.enums.ROperationResultStatus) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) CanonicalItemPath(com.evolveum.midpoint.prism.path.CanonicalItemPath) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Aggregations

CanonicalItemPath (com.evolveum.midpoint.prism.path.CanonicalItemPath)2 AuditReferenceValue (com.evolveum.midpoint.audit.api.AuditReferenceValue)1 PrismObject (com.evolveum.midpoint.prism.PrismObject)1 PrismReferenceValue (com.evolveum.midpoint.prism.PrismReferenceValue)1 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)1 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)1 ROperationResultStatus (com.evolveum.midpoint.repo.sql.data.common.enums.ROperationResultStatus)1 DtoTranslationException (com.evolveum.midpoint.repo.sql.util.DtoTranslationException)1 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)1 Timestamp (java.sql.Timestamp)1