use of com.evolveum.midpoint.util.exception.SystemException in project midpoint by Evolveum.
the class SimpleParametricRoleSelector method getParamValue.
private String getParamValue(AssignmentEditorDto assignmentDto) {
PrismContainerValue newValue;
try {
newValue = assignmentDto.getNewValue(getPageBase().getPrismContext());
} catch (SchemaException e) {
throw new SystemException(e.getMessage(), e);
}
if (newValue != null) {
PrismProperty<String> paramProp = newValue.findProperty(parameterPath);
if (paramProp != null) {
return paramProp.getRealValue();
}
}
PrismContainerValue oldValue = assignmentDto.getOldValue();
if (oldValue != null) {
PrismProperty<String> paramProp = oldValue.findProperty(parameterPath);
if (paramProp != null) {
return paramProp.getRealValue();
}
}
return null;
}
use of com.evolveum.midpoint.util.exception.SystemException in project midpoint by Evolveum.
the class RefinedObjectClassDefinitionImpl method createBlankShadow.
@Override
public PrismObject<ShadowType> createBlankShadow(RefinedObjectClassDefinition definition) {
PrismObject<ShadowType> accountShadow;
try {
accountShadow = getPrismContext().createObject(ShadowType.class);
} catch (SchemaException e) {
// This should not happen
throw new SystemException("Internal error instantiating account shadow: " + e.getMessage(), e);
}
ShadowType accountShadowType = accountShadow.asObjectable();
accountShadowType.setIntent(getIntent());
accountShadowType.setKind(getKind());
accountShadowType.setObjectClass(getObjectClassDefinition().getTypeName());
accountShadowType.setResourceRef(ObjectTypeUtil.createObjectRef(getResourceType()));
// Setup definition
PrismObjectDefinition<ShadowType> newDefinition = accountShadow.getDefinition().cloneWithReplacedDefinition(ShadowType.F_ATTRIBUTES, definition.toResourceAttributeContainerDefinition());
accountShadow.setDefinition(newDefinition);
return accountShadow;
}
use of com.evolveum.midpoint.util.exception.SystemException in project midpoint by Evolveum.
the class Validator method validate.
public void validate(InputStream inputStream, OperationResult validatorResult, String objectResultOperationName) {
XMLStreamReader stream = null;
try {
Map<String, String> rootNamespaceDeclarations = new HashMap<String, String>();
XMLInputFactory xmlInputFactory = XMLInputFactory.newInstance();
stream = xmlInputFactory.createXMLStreamReader(inputStream);
int eventType = stream.nextTag();
if (eventType == XMLStreamConstants.START_ELEMENT) {
if (!QNameUtil.match(stream.getName(), SchemaConstants.C_OBJECTS)) {
// This has to be an import file with a single objects. Try
// to process it.
OperationResult objectResult = validatorResult.createSubresult(objectResultOperationName);
progress++;
objectResult.addContext(OperationResult.CONTEXT_PROGRESS, progress);
EventResult cont = null;
try {
cont = readFromStreamAndValidate(stream, objectResult, rootNamespaceDeclarations, validatorResult);
} catch (RuntimeException e) {
// Make sure that unexpected error is recorded.
objectResult.recordFatalError(e);
throw e;
}
if (!cont.isCont()) {
String message = null;
if (cont.getReason() != null) {
message = cont.getReason();
} else {
message = "Object validation failed (no reason given)";
}
if (objectResult.isUnknown()) {
objectResult.recordFatalError(message);
}
validatorResult.recordFatalError(message);
return;
}
// return to avoid processing objects in loop
validatorResult.computeStatus("Validation failed", "Validation warnings");
return;
}
// Extract root namespace declarations
for (int i = 0; i < stream.getNamespaceCount(); i++) {
rootNamespaceDeclarations.put(stream.getNamespacePrefix(i), stream.getNamespaceURI(i));
}
} else {
throw new SystemException("StAX Malfunction?");
}
while (stream.hasNext()) {
eventType = stream.next();
if (eventType == XMLStreamConstants.START_ELEMENT) {
OperationResult objectResult = validatorResult.createSubresult(objectResultOperationName);
progress++;
objectResult.addContext(OperationResult.CONTEXT_PROGRESS, progress);
EventResult cont = null;
try {
// Read and validate individual object from the stream
cont = readFromStreamAndValidate(stream, objectResult, rootNamespaceDeclarations, validatorResult);
} catch (RuntimeException e) {
if (objectResult.isUnknown()) {
// Make sure that unexpected error is recorded.
objectResult.recordFatalError(e);
}
throw e;
}
if (objectResult.isError()) {
errors++;
}
objectResult.cleanupResult();
validatorResult.summarize();
if (cont.isStop()) {
if (cont.getReason() != null) {
validatorResult.recordFatalError("Processing has been stopped: " + cont.getReason());
} else {
validatorResult.recordFatalError("Processing has been stopped");
}
// processed
return;
}
if (!cont.isCont()) {
if (stopAfterErrors > 0 && errors >= stopAfterErrors) {
validatorResult.recordFatalError("Too many errors (" + errors + ")");
return;
}
}
}
}
} catch (XMLStreamException ex) {
// validatorResult.recordFatalError("XML parsing error: " +
// ex.getMessage()+" on line "+stream.getLocation().getLineNumber(),ex);
validatorResult.recordFatalError("XML parsing error: " + ex.getMessage(), ex);
if (handler != null) {
handler.handleGlobalError(validatorResult);
}
return;
}
// Error count is sufficient. Detailed messages are in subresults
validatorResult.computeStatus(errors + " errors, " + (progress - errors) + " passed");
}
use of com.evolveum.midpoint.util.exception.SystemException in project midpoint by Evolveum.
the class ShadowUtil method getOrCreateAttributesContainer.
public static ResourceAttributeContainer getOrCreateAttributesContainer(PrismObject<? extends ShadowType> shadow, ObjectClassComplexTypeDefinition objectClassDefinition) {
ResourceAttributeContainer attributesContainer = getAttributesContainer(shadow);
if (attributesContainer != null) {
return attributesContainer;
}
ResourceAttributeContainer emptyContainer = ResourceAttributeContainer.createEmptyContainer(ShadowType.F_ATTRIBUTES, objectClassDefinition);
try {
shadow.add(emptyContainer);
} catch (SchemaException e) {
throw new SystemException("Unexpected schema error: " + e.getMessage(), e);
}
return emptyContainer;
}
use of com.evolveum.midpoint.util.exception.SystemException in project midpoint by Evolveum.
the class ModelObjectResolver method getObject.
public <T extends ObjectType> T getObject(Class<T> clazz, String oid, Collection<SelectorOptions<GetOperationOptions>> options, Task task, OperationResult result) throws ObjectNotFoundException, CommunicationException, SchemaException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException {
T objectType = null;
try {
PrismObject<T> object = null;
ObjectTypes.ObjectManager manager = ObjectTypes.getObjectManagerForClass(clazz);
final GetOperationOptions rootOptions = SelectorOptions.findRootOptions(options);
switch(manager) {
case PROVISIONING:
object = provisioning.getObject(clazz, oid, options, task, result);
if (object == null) {
throw new SystemException("Got null result from provisioning.getObject while looking for " + clazz.getSimpleName() + " with OID " + oid + "; using provisioning implementation " + provisioning.getClass().getName());
}
break;
case TASK_MANAGER:
object = taskManager.getObject(clazz, oid, options, result);
if (object == null) {
throw new SystemException("Got null result from taskManager.getObject while looking for " + clazz.getSimpleName() + " with OID " + oid + "; using task manager implementation " + taskManager.getClass().getName());
}
if (workflowManager != null && TaskType.class.isAssignableFrom(clazz) && !GetOperationOptions.isRaw(rootOptions) && !GetOperationOptions.isNoFetch(rootOptions)) {
workflowManager.augmentTaskObject(object, options, task, result);
}
break;
default:
object = cacheRepositoryService.getObject(clazz, oid, options, result);
if (object == null) {
throw new SystemException("Got null result from repository.getObject while looking for " + clazz.getSimpleName() + " with OID " + oid + "; using repository implementation " + cacheRepositoryService.getClass().getName());
}
}
objectType = object.asObjectable();
if (!clazz.isInstance(objectType)) {
throw new ObjectNotFoundException("Bad object type returned for referenced oid '" + oid + "'. Expected '" + clazz + "', but was '" + (objectType == null ? "null" : objectType.getClass()) + "'.");
}
if (hookRegistry != null) {
for (ReadHook hook : hookRegistry.getAllReadHooks()) {
hook.invoke(object, options, task, result);
}
}
} catch (SystemException | ObjectNotFoundException | CommunicationException | ConfigurationException | SecurityViolationException | ExpressionEvaluationException ex) {
result.recordFatalError(ex);
throw ex;
} catch (RuntimeException | Error ex) {
LoggingUtils.logException(LOGGER, "Error resolving object with oid {}, expected type was {}.", ex, oid, clazz);
throw new SystemException("Error resolving object with oid '" + oid + "': " + ex.getMessage(), ex);
} finally {
result.computeStatus();
}
return objectType;
}
Aggregations