use of com.evolveum.midpoint.util.exception.SchemaException 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.util.exception.SchemaException 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.SchemaException in project midpoint by Evolveum.
the class ReportTypeUtil method applyDefinition.
public static void applyDefinition(PrismObject<ReportType> report, PrismContext prismContext) throws SchemaException {
PrismContainer<ReportConfigurationType> configuration = report.findContainer(ReportType.F_CONFIGURATION);
if (configuration == null) {
//nothing to apply definitions on
return;
}
PrismContainer xmlSchema = report.findContainer(ReportType.F_CONFIGURATION_SCHEMA);
Element xmlSchemaElement = ObjectTypeUtil.findXsdElement(xmlSchema);
if (xmlSchemaElement == null) {
//no schema definition available
throw new SchemaException("Couldn't find schema for configuration in report type " + report + ".");
}
PrismSchema schema = ReportTypeUtil.parseReportConfigurationSchema(report, prismContext);
PrismContainerDefinition<ReportConfigurationType> definition = ReportTypeUtil.findReportConfigurationDefinition(schema);
if (definition == null) {
//no definition found for container
throw new SchemaException("Couldn't find definitions for report type " + report + ".");
}
configuration.applyDefinition(definition, true);
}
use of com.evolveum.midpoint.util.exception.SchemaException in project midpoint by Evolveum.
the class ReportTypeUtil method loadJasperReport.
public static JasperReport loadJasperReport(ReportType reportType) throws SchemaException {
if (reportType.getTemplate() == null) {
throw new IllegalStateException("Could not create report. No jasper template defined.");
}
try {
// byte[] reportTemplate = Base64.decodeBase64(reportType.getTemplate());
//
// InputStream inputStreamJRXML = new ByteArrayInputStream(reportTemplate);
//JRXmlLoader.load(inputStreamJRXML);
JasperDesign jasperDesign = loadJasperDesign(reportType.getTemplate());
if (reportType.getTemplateStyle() != null) {
JRDesignReportTemplate templateStyle = new JRDesignReportTemplate(new JRDesignExpression("$P{" + PARAMETER_TEMPLATE_STYLES + "}"));
jasperDesign.addTemplate(templateStyle);
JRDesignParameter parameter = new JRDesignParameter();
parameter.setName(PARAMETER_TEMPLATE_STYLES);
parameter.setValueClass(JRTemplate.class);
parameter.setForPrompting(false);
jasperDesign.addParameter(parameter);
}
// if (StringUtils.isNotEmpty(finalQuery)){
JRDesignParameter parameter = new JRDesignParameter();
parameter.setName("finalQuery");
parameter.setValueClass(Object.class);
parameter.setForPrompting(false);
jasperDesign.addParameter(parameter);
// }
JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);
return jasperReport;
} catch (JRException ex) {
// LOGGER.error("Couldn't create jasper report design {}", ex.getMessage());
throw new SchemaException(ex.getMessage(), ex.getCause());
}
}
use of com.evolveum.midpoint.util.exception.SchemaException in project midpoint by Evolveum.
the class ModelCrudService method modifyObject.
/**
* <p>
* Modifies object using relative change description.
* </p>
* <p>
* Must fail if user with provided OID does not exists. Must fail if any of
* the described changes cannot be applied. Should be atomic.
* </p>
* <p>
* If two or more modify operations are executed in parallel, the operations
* should be merged. In case that the operations are in conflict (e.g. one
* operation adding a value and the other removing the same value), the
* result is not deterministic.
* </p>
* <p>
* The operation may fail if the modified object does not conform to the
* underlying schema of the storage system or the schema enforced by the
* implementation.
* </p>
*
* @param parentResult
* parent OperationResult (in/out)
* @throws ObjectNotFoundException
* specified object does not exist
* @throws SchemaException
* resulting object would violate the schema
* @throws ExpressionEvaluationException
* evaluation of expression associated with the object has failed
* @throws CommunicationException
* @throws ObjectAlreadyExistsException
* If the account or another "secondary" object already exists and cannot be created
* @throws PolicyViolationException
* Policy violation was detected during processing of the object
* @throws IllegalArgumentException
* wrong OID format, described change is not applicable
* @throws SystemException
* unknown error from underlying layers or other unexpected
* state
*/
public <T extends ObjectType> void modifyObject(Class<T> type, String oid, Collection<? extends ItemDelta> modifications, ModelExecuteOptions options, Task task, OperationResult parentResult) throws ObjectNotFoundException, SchemaException, ExpressionEvaluationException, CommunicationException, ConfigurationException, ObjectAlreadyExistsException, PolicyViolationException, SecurityViolationException {
Validate.notNull(modifications, "Object modification must not be null.");
Validate.notEmpty(oid, "Change oid must not be null or empty.");
Validate.notNull(parentResult, "Result type must not be null.");
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Modifying object with oid {}", oid);
LOGGER.trace(DebugUtil.debugDump(modifications));
}
if (modifications.isEmpty()) {
LOGGER.warn("Calling modifyObject with empty modificaiton set");
return;
}
ItemDelta.checkConsistence(modifications, ConsistencyCheckScope.THOROUGH);
// TODO: check definitions, but tolerate missing definitions in <attributes>
OperationResult result = parentResult.createSubresult(MODIFY_OBJECT);
result.addCollectionOfSerializablesAsParam("modifications", modifications);
RepositoryCache.enter();
try {
ObjectDelta<T> objectDelta = (ObjectDelta<T>) ObjectDelta.createModifyDelta(oid, modifications, type, prismContext);
Collection<ObjectDelta<? extends ObjectType>> deltas = MiscSchemaUtil.createCollection(objectDelta);
modelService.executeChanges(deltas, options, task, result);
result.computeStatus();
} catch (ExpressionEvaluationException ex) {
LOGGER.error("model.modifyObject failed: {}", ex.getMessage(), ex);
result.recordFatalError(ex);
throw ex;
} catch (ObjectNotFoundException ex) {
LOGGER.error("model.modifyObject failed: {}", ex.getMessage(), ex);
result.recordFatalError(ex);
throw ex;
} catch (SchemaException ex) {
ModelUtils.recordFatalError(result, ex);
throw ex;
} catch (ConfigurationException ex) {
ModelUtils.recordFatalError(result, ex);
throw ex;
} catch (SecurityViolationException ex) {
ModelUtils.recordFatalError(result, ex);
throw ex;
} catch (RuntimeException ex) {
ModelUtils.recordFatalError(result, ex);
throw ex;
} finally {
RepositoryCache.exit();
}
}
Aggregations