Search in sources :

Example 1 with Visitable

use of com.evolveum.midpoint.prism.Visitable in project midpoint by Evolveum.

the class PrismAsserts method assertNoEmptyItem.

public static void assertNoEmptyItem(PrismContainer<?> container) {
    Visitor visitor = new Visitor() {

        @Override
        public void visit(Visitable visitable) {
            if (visitable != null && visitable instanceof Item) {
                assertNotEmpty((Item<?, ?>) visitable);
            }
        }
    };
    container.accept(visitor);
}
Also used : Item(com.evolveum.midpoint.prism.Item) Visitor(com.evolveum.midpoint.prism.Visitor) Visitable(com.evolveum.midpoint.prism.Visitable)

Example 2 with Visitable

use of com.evolveum.midpoint.prism.Visitable in project midpoint by Evolveum.

the class OpResult method setShowMoreAll.

public void setShowMoreAll(final boolean show) {
    Visitor visitor = new Visitor() {

        @Override
        public void visit(Visitable visitable) {
            if (!(visitable instanceof OpResult)) {
                return;
            }
            OpResult result = (OpResult) visitable;
            result.setShowMore(show);
        }
    };
    accept(visitor);
}
Also used : Visitor(com.evolveum.midpoint.prism.Visitor) Visitable(com.evolveum.midpoint.prism.Visitable)

Example 3 with Visitable

use of com.evolveum.midpoint.prism.Visitable in project midpoint by Evolveum.

the class AuditServiceProxy method completeRecord.

/**
	 * Complete the record with data that can be computed or discovered from the
	 * environment
	 */
private void completeRecord(AuditEventRecord record, Task task) {
    LightweightIdentifier id = null;
    if (record.getEventIdentifier() == null) {
        id = lightweightIdentifierGenerator.generate();
        record.setEventIdentifier(id.toString());
    }
    if (record.getTimestamp() == null) {
        if (id == null) {
            record.setTimestamp(System.currentTimeMillis());
        } else {
            // To be consistent with the ID
            record.setTimestamp(id.getTimestamp());
        }
    }
    if (record.getTaskIdentifier() == null && task != null) {
        record.setTaskIdentifier(task.getTaskIdentifier());
    }
    if (record.getTaskOID() == null && task != null) {
        record.setTaskOID(task.getOid());
    }
    if (record.getChannel() == null && task != null) {
        record.setChannel(task.getChannel());
    }
    if (record.getInitiator() == null && task != null) {
        record.setInitiator(task.getOwner());
    }
    if (record.getNodeIdentifier() == null && taskManager != null) {
        record.setNodeIdentifier(taskManager.getNodeId());
    }
    HttpConnectionInformation connInfo = SecurityUtil.getCurrentConnectionInformation();
    if (connInfo == null && securityEnforcer != null) {
        connInfo = securityEnforcer.getStoredConnectionInformation();
    }
    if (connInfo != null) {
        if (record.getSessionIdentifier() == null) {
            record.setSessionIdentifier(connInfo.getSessionId());
        }
        if (record.getRemoteHostAddress() == null) {
            record.setRemoteHostAddress(connInfo.getRemoteHostAddress());
        }
        if (record.getHostIdentifier() == null) {
            record.setHostIdentifier(connInfo.getLocalHostName());
        }
    }
    if (record.getSessionIdentifier() == null && task != null) {
        record.setSessionIdentifier(task.getTaskIdentifier());
    }
    if (record.getDeltas() != null) {
        for (ObjectDeltaOperation<? extends ObjectType> objectDeltaOperation : record.getDeltas()) {
            ObjectDelta<? extends ObjectType> delta = objectDeltaOperation.getObjectDelta();
            final Map<String, PolyString> resolvedOids = new HashMap<>();
            Visitor namesResolver = new Visitor() {

                @Override
                public void visit(Visitable visitable) {
                    if (visitable instanceof PrismReferenceValue) {
                        PrismReferenceValue refVal = ((PrismReferenceValue) visitable);
                        String oid = refVal.getOid();
                        if (oid == null) {
                            // happen
                            return;
                        }
                        if (refVal.getTargetName() != null) {
                            resolvedOids.put(oid, refVal.getTargetName());
                            return;
                        }
                        if (resolvedOids.containsKey(oid)) {
                            // may
                            PolyString resolvedName = resolvedOids.get(oid);
                            // be
                            // null
                            refVal.setTargetName(resolvedName);
                            return;
                        }
                        if (refVal.getObject() != null) {
                            PolyString name = refVal.getObject().getName();
                            refVal.setTargetName(name);
                            resolvedOids.put(oid, name);
                            return;
                        }
                        if (repositoryService == null) {
                            LOGGER.warn("No repository, no OID resolution (for {})", oid);
                            return;
                        }
                        PrismObjectDefinition<? extends ObjectType> objectDefinition = null;
                        if (refVal.getTargetType() != null) {
                            objectDefinition = prismContext.getSchemaRegistry().findObjectDefinitionByType(refVal.getTargetType());
                        }
                        Class<? extends ObjectType> objectClass = null;
                        if (objectDefinition != null) {
                            objectClass = objectDefinition.getCompileTimeClass();
                        }
                        if (objectClass == null) {
                            // the default
                            objectClass = ObjectType.class;
                        // (shouldn't be
                        // needed)
                        }
                        SelectorOptions<GetOperationOptions> getNameOnly = SelectorOptions.create(new ItemPath(ObjectType.F_NAME), GetOperationOptions.createRetrieve(RetrieveOption.INCLUDE));
                        try {
                            PrismObject<? extends ObjectType> object = repositoryService.getObject(objectClass, oid, Arrays.asList(getNameOnly), new OperationResult("dummy"));
                            PolyString name = object.getName();
                            refVal.setTargetName(name);
                            resolvedOids.put(oid, name);
                            LOGGER.trace("Resolved {}: {} to {}", objectClass, oid, name);
                        } catch (ObjectNotFoundException e) {
                            LOGGER.trace("Couldn't determine the name for {}: {} as it does not exist", objectClass, oid, e);
                            resolvedOids.put(oid, null);
                        } catch (SchemaException | RuntimeException e) {
                            LOGGER.trace("Couldn't determine the name for {}: {} because of unexpected exception", objectClass, oid, e);
                            resolvedOids.put(oid, null);
                        }
                    }
                }
            };
            delta.accept(namesResolver);
        }
    }
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) Visitor(com.evolveum.midpoint.prism.Visitor) HashMap(java.util.HashMap) Visitable(com.evolveum.midpoint.prism.Visitable) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) GetOperationOptions(com.evolveum.midpoint.schema.GetOperationOptions) HttpConnectionInformation(com.evolveum.midpoint.security.api.HttpConnectionInformation) PrismReferenceValue(com.evolveum.midpoint.prism.PrismReferenceValue) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) LightweightIdentifier(com.evolveum.midpoint.task.api.LightweightIdentifier) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 4 with Visitable

use of com.evolveum.midpoint.prism.Visitable in project midpoint by Evolveum.

the class CryptoUtil method checkEncrypted.

// Checks that everything is encrypted
public static <T extends ObjectType> void checkEncrypted(final PrismObject<T> object) {
    Visitor visitor = new Visitor() {

        @Override
        public void visit(Visitable visitable) {
            if (!(visitable instanceof PrismPropertyValue)) {
                return;
            }
            PrismPropertyValue<?> pval = (PrismPropertyValue<?>) visitable;
            checkEncrypted(pval);
        }
    };
    try {
        object.accept(visitor);
    } catch (IllegalStateException e) {
        throw new IllegalStateException(e.getMessage() + " in " + object, e);
    }
}
Also used : Visitor(com.evolveum.midpoint.prism.Visitor) Visitable(com.evolveum.midpoint.prism.Visitable) PrismPropertyValue(com.evolveum.midpoint.prism.PrismPropertyValue)

Example 5 with Visitable

use of com.evolveum.midpoint.prism.Visitable in project midpoint by Evolveum.

the class CryptoUtil method checkEncrypted.

// Checks that everything is encrypted
public static <T extends ObjectType> void checkEncrypted(final ObjectDelta<T> delta) {
    Visitor visitor = new Visitor() {

        @Override
        public void visit(Visitable visitable) {
            if (!(visitable instanceof PrismPropertyValue)) {
                return;
            }
            PrismPropertyValue<?> pval = (PrismPropertyValue<?>) visitable;
            checkEncrypted(pval);
        }
    };
    try {
        delta.accept(visitor);
    } catch (IllegalStateException e) {
        throw new IllegalStateException(e.getMessage() + " in delta " + delta, e);
    }
}
Also used : Visitor(com.evolveum.midpoint.prism.Visitor) Visitable(com.evolveum.midpoint.prism.Visitable) PrismPropertyValue(com.evolveum.midpoint.prism.PrismPropertyValue)

Aggregations

Visitable (com.evolveum.midpoint.prism.Visitable)9 Visitor (com.evolveum.midpoint.prism.Visitor)9 PrismPropertyValue (com.evolveum.midpoint.prism.PrismPropertyValue)4 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)3 Item (com.evolveum.midpoint.prism.Item)2 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)2 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)2 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)2 ItemDefinition (com.evolveum.midpoint.prism.ItemDefinition)1 Objectable (com.evolveum.midpoint.prism.Objectable)1 OriginType (com.evolveum.midpoint.prism.OriginType)1 PrismContainer (com.evolveum.midpoint.prism.PrismContainer)1 PrismReferenceValue (com.evolveum.midpoint.prism.PrismReferenceValue)1 PrismValue (com.evolveum.midpoint.prism.PrismValue)1 ItemDelta (com.evolveum.midpoint.prism.delta.ItemDelta)1 CompareResult (com.evolveum.midpoint.prism.path.ItemPath.CompareResult)1 PrimitiveXNode (com.evolveum.midpoint.prism.xnode.PrimitiveXNode)1 GetOperationOptions (com.evolveum.midpoint.schema.GetOperationOptions)1 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)1 HttpConnectionInformation (com.evolveum.midpoint.security.api.HttpConnectionInformation)1