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;
}
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());
}
}
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);
}
}
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));
}
}
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());
}
Aggregations