Search in sources :

Example 1 with Objectable

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

the class LensFocusContext method fromLensFocusContextType.

public static LensFocusContext fromLensFocusContextType(LensFocusContextType focusContextType, LensContext lensContext, Task task, OperationResult result) throws SchemaException, ConfigurationException, ObjectNotFoundException, CommunicationException, ExpressionEvaluationException {
    String objectTypeClassString = focusContextType.getObjectTypeClass();
    if (StringUtils.isEmpty(objectTypeClassString)) {
        throw new SystemException("Object type class is undefined in LensFocusContextType");
    }
    LensFocusContext lensFocusContext;
    try {
        lensFocusContext = new LensFocusContext(Class.forName(objectTypeClassString), lensContext);
    } catch (ClassNotFoundException e) {
        throw new SystemException("Couldn't instantiate LensFocusContext because object type class couldn't be found", e);
    }
    lensFocusContext.retrieveFromLensElementContextType(focusContextType, task, result);
    lensFocusContext.secondaryDeltas = ObjectDeltaWaves.fromObjectDeltaWavesType(focusContextType.getSecondaryDeltas(), lensContext.getPrismContext());
    // fixing provisioning type in delta (however, this is not usually needed, unless primary object is shadow or resource
    Objectable object;
    if (lensFocusContext.getObjectNew() != null) {
        object = lensFocusContext.getObjectNew().asObjectable();
    } else if (lensFocusContext.getObjectOld() != null) {
        object = lensFocusContext.getObjectOld().asObjectable();
    } else {
        object = null;
    }
    for (Object o : lensFocusContext.secondaryDeltas) {
        ObjectDelta<? extends ObjectType> delta = (ObjectDelta<? extends ObjectType>) o;
        if (delta != null) {
            lensFocusContext.fixProvisioningTypeInDelta(delta, object, task, result);
        }
    }
    return lensFocusContext;
}
Also used : Objectable(com.evolveum.midpoint.prism.Objectable) ObjectDeltaObject(com.evolveum.midpoint.repo.common.expression.ObjectDeltaObject) PrismObject(com.evolveum.midpoint.prism.PrismObject) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta)

Example 2 with Objectable

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

the class Validator method validateObjectInternal.

private EventResult validateObjectInternal(Element objectElement, OperationResult objectResult, OperationResult validatorResult) {
    try {
        Node postValidationTree = null;
        if (validateSchemas) {
            postValidationTree = validateSchema(objectElement, objectResult);
            if (postValidationTree == null) {
                // There was an error
                return EventResult.skipObject(objectResult.getMessage());
            }
        }
        if (handler != null) {
            EventResult cont;
            try {
                cont = handler.preMarshall(objectElement, postValidationTree, objectResult);
            } catch (RuntimeException e) {
                objectResult.recordFatalError("Internal error: preMarshall call failed: " + e.getMessage(), e);
                throw e;
            }
            if (!cont.isCont()) {
                if (objectResult.isUnknown()) {
                    objectResult.recordFatalError("Stopped after preMarshall, no reason given");
                }
                return cont;
            }
        }
        if (!objectResult.isAcceptable()) {
            // continue with this object.
            if (objectResult.isUnknown()) {
                objectResult.recordFatalError("Result not acceptable after preMarshall, no reason given");
            }
            return EventResult.skipObject();
        }
        PrismObject<? extends Objectable> object = prismContext.parserFor(objectElement).parse();
        try {
            object.checkConsistence();
        } catch (RuntimeException e) {
            objectResult.recordFatalError("Internal object inconsistence, probably a parser bug: " + e.getMessage(), e);
            return EventResult.skipObject(e.getMessage());
        }
        Objectable objectType = null;
        if (object != null) {
            objectType = object.asObjectable();
        }
        if (verbose) {
            LOGGER.trace("Processing OID " + objectType.getOid());
        }
        objectResult.addContext(OperationResult.CONTEXT_OBJECT, objectType);
        validateObject(objectType, objectResult);
        if (handler != null) {
            EventResult cont;
            try {
                cont = handler.postMarshall(object, objectElement, objectResult);
            } catch (RuntimeException e) {
                // Make sure that unhandled exceptions are recorded in object result before they are rethrown
                objectResult.recordFatalError("Internal error: postMarshall call failed: " + e.getMessage(), e);
                throw e;
            }
            if (!cont.isCont()) {
                if (objectResult.isUnknown()) {
                    objectResult.recordFatalError("Stopped after postMarshall, no reason given");
                }
                return cont;
            }
        }
        objectResult.recomputeStatus();
        return EventResult.cont();
    } catch (SchemaException ex) {
        if (verbose) {
            ex.printStackTrace();
        }
        if (handler != null) {
            try {
                handler.handleGlobalError(validatorResult);
            } catch (RuntimeException e) {
                // Make sure that unhandled exceptions are recorded in object result before they are rethrown
                objectResult.recordFatalError("Internal error: handleGlobalError call failed: " + e.getMessage(), e);
                throw e;
            }
        }
        objectResult.recordFatalError(ex);
        return EventResult.skipObject(ex.getMessage());
    } catch (RuntimeException ex) {
        validatorResult.recordFatalError("Couldn't parse object: " + ex.getMessage(), ex);
        if (verbose) {
            ex.printStackTrace();
        }
        if (handler != null) {
            try {
                handler.handleGlobalError(validatorResult);
            } catch (RuntimeException e) {
                // Make sure that unhandled exceptions are recorded in object result before they are rethrown
                objectResult.recordFatalError("Internal error: handleGlobalError call failed: " + e.getMessage(), e);
                throw e;
            }
        }
        objectResult.recordFatalError(ex);
        return EventResult.skipObject(ex.getMessage());
    }
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) Node(org.w3c.dom.Node) Objectable(com.evolveum.midpoint.prism.Objectable)

Example 3 with Objectable

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

the class LazyXPathVariableResolver method convertToXml.

// May return primitive types or DOM Node
public static Object convertToXml(Object variableValue, QName variableName, final PrismContext prismContext, String contextDescription) throws SchemaException {
    try {
        if (variableValue instanceof Objectable) {
            variableValue = ((Objectable) variableValue).asPrismObject();
        }
        if (variableValue instanceof PrismObject) {
            PrismObject<?> prismObject = (PrismObject<?>) variableValue;
            variableValue = prismObject.getPrismContext().domSerializer().serialize(prismObject);
        } else if (variableValue instanceof PrismProperty<?>) {
            PrismProperty<?> prismProperty = (PrismProperty<?>) variableValue;
            final List<Element> elementList = new ArrayList<Element>();
            for (PrismPropertyValue<?> value : prismProperty.getValues()) {
                Element valueElement = prismContext.domSerializer().serialize(value, prismProperty.getElementName());
                elementList.add(valueElement);
            }
            NodeList nodeList = new AdHocNodeList(elementList);
            variableValue = nodeList;
        } else if (variableValue instanceof PrismValue) {
            PrismValue pval = (PrismValue) variableValue;
            if (pval.getParent() == null) {
                // Set a fake parent to allow serialization
                pval.setParent(new AdHocItemable(prismContext));
            }
            variableValue = prismContext.domSerializer().serialize(pval, variableName);
        }
        if (!((variableValue instanceof Node) || variableValue instanceof NodeList) && !(variableValue.getClass().getPackage().getName().startsWith("java."))) {
            throw new SchemaException("Unable to convert value of variable " + variableName + " to XML, still got " + variableValue.getClass().getName() + ":" + variableValue + " value at the end");
        }
        return variableValue;
    } catch (SchemaException e) {
        if (variableValue != null && variableValue instanceof DebugDumpable) {
            LOGGER.trace("Value of variable {}:\n{}", variableName, ((DebugDumpable) variableValue).debugDump());
        }
        throw new SchemaException(e.getMessage() + " while processing variable " + variableName + " with value " + variableValue + " in " + contextDescription, e);
    } catch (RuntimeException e) {
        if (variableValue != null && variableValue instanceof DebugDumpable) {
            LOGGER.trace("Value of variable {}:\n{}", variableName, ((DebugDumpable) variableValue).debugDump());
        }
        throw new RuntimeException(e.getClass().getName() + ": " + e.getMessage() + " while processing variable " + variableName + " with value " + variableValue + " in " + contextDescription, e);
    }
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) Element(org.w3c.dom.Element) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) DebugDumpable(com.evolveum.midpoint.util.DebugDumpable) PrismValue(com.evolveum.midpoint.prism.PrismValue) PrismObject(com.evolveum.midpoint.prism.PrismObject) PrismProperty(com.evolveum.midpoint.prism.PrismProperty) Objectable(com.evolveum.midpoint.prism.Objectable) ArrayList(java.util.ArrayList) NodeList(org.w3c.dom.NodeList) List(java.util.List) PrismPropertyValue(com.evolveum.midpoint.prism.PrismPropertyValue)

Example 4 with Objectable

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

the class TestMisc method test200ExportUsers.

@Test
public void test200ExportUsers() throws Exception {
    final String TEST_NAME = "test200ExportUsers";
    TestUtil.displayTestTile(this, TEST_NAME);
    // GIVEN
    Task task = taskManager.createTaskInstance(TestMisc.class.getName() + "." + TEST_NAME);
    OperationResult result = task.getResult();
    // WHEN
    List<PrismObject<UserType>> users = modelService.searchObjects(UserType.class, null, SelectorOptions.createCollection(new ItemPath(), GetOperationOptions.createRaw()), task, result);
    // THEN
    result.computeStatus();
    display("Search users result", result);
    TestUtil.assertSuccess(result);
    assertEquals("Unexpected number of users", 5, users.size());
    for (PrismObject<UserType> user : users) {
        display("Exporting user", user);
        assertNotNull("Null definition in " + user, user.getDefinition());
        display("Definition", user.getDefinition());
        String xmlString = prismContext.serializeObjectToString(user, PrismContext.LANG_XML);
        display("Exported user", xmlString);
        Document xmlDocument = DOMUtil.parseDocument(xmlString);
        Schema javaxSchema = prismContext.getSchemaRegistry().getJavaxSchema();
        Validator validator = javaxSchema.newValidator();
        validator.setResourceResolver(prismContext.getEntityResolver());
        validator.validate(new DOMSource(xmlDocument));
        PrismObject<Objectable> parsedUser = prismContext.parseObject(xmlString);
        assertTrue("Re-parsed user is not equal to original: " + user, user.equals(parsedUser));
    }
}
Also used : Task(com.evolveum.midpoint.task.api.Task) DOMSource(javax.xml.transform.dom.DOMSource) Schema(javax.xml.validation.Schema) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Document(org.w3c.dom.Document) PrismObject(com.evolveum.midpoint.prism.PrismObject) Objectable(com.evolveum.midpoint.prism.Objectable) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) Validator(javax.xml.validation.Validator) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) Test(org.testng.annotations.Test)

Example 5 with Objectable

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

the class SearchTest method beforeClass.

@BeforeClass
public void beforeClass() throws Exception {
    super.beforeClass();
    PrismTestUtil.resetPrismContext(MidPointPrismContextFactory.FACTORY);
    FullTextSearchConfigurationType fullTextConfig = new FullTextSearchConfigurationType();
    FullTextSearchIndexedItemsConfigurationType entry = new FullTextSearchIndexedItemsConfigurationType();
    entry.getItem().add(new ItemPath(ObjectType.F_NAME).asItemPathType());
    entry.getItem().add(new ItemPath(ObjectType.F_DESCRIPTION).asItemPathType());
    fullTextConfig.getIndexed().add(entry);
    repositoryService.applyFullTextSearchConfiguration(fullTextConfig);
    LOGGER.info("Applying full text search configuration: {}", fullTextConfig);
    List<PrismObject<? extends Objectable>> objects = prismContext.parserFor(new File(FOLDER_BASIC, "objects.xml")).parseObjects();
    objects.addAll(prismContext.parserFor(new File(FOLDER_BASIC, "objects-2.xml")).parseObjects());
    OperationResult result = new OperationResult("add objects");
    for (PrismObject object : objects) {
        repositoryService.addObject(object, null, result);
    }
    result.recomputeStatus();
    assertTrue(result.isSuccess());
}
Also used : PrismObject(com.evolveum.midpoint.prism.PrismObject) Objectable(com.evolveum.midpoint.prism.Objectable) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) File(java.io.File) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) BeforeClass(org.testng.annotations.BeforeClass)

Aggregations

Objectable (com.evolveum.midpoint.prism.Objectable)26 PrismObject (com.evolveum.midpoint.prism.PrismObject)17 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)14 File (java.io.File)9 Test (org.testng.annotations.Test)9 PrismContext (com.evolveum.midpoint.prism.PrismContext)6 Node (org.w3c.dom.Node)6 ArrayList (java.util.ArrayList)5 List (java.util.List)5 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)4 Task (com.evolveum.midpoint.task.api.Task)4 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)4 EventHandler (com.evolveum.midpoint.common.validator.EventHandler)3 Validator (com.evolveum.midpoint.common.validator.Validator)3 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)3 Element (org.w3c.dom.Element)3 PageDescriptor (com.evolveum.midpoint.authentication.api.authorization.PageDescriptor)2 Url (com.evolveum.midpoint.authentication.api.authorization.Url)2 WebModelServiceUtils (com.evolveum.midpoint.gui.api.util.WebModelServiceUtils)2 PrismProperty (com.evolveum.midpoint.prism.PrismProperty)2