use of com.evolveum.midpoint.util.exception.SchemaException in project midpoint by Evolveum.
the class DistinguishedNameMatchingRule method match.
/* (non-Javadoc)
* @see com.evolveum.midpoint.model.match.MatchingRule#match(java.lang.Object, java.lang.Object)
*/
@Override
public boolean match(String a, String b) throws SchemaException {
if (StringUtils.isBlank(a) && StringUtils.isBlank(b)) {
return true;
}
if (StringUtils.isBlank(a) || StringUtils.isBlank(b)) {
return false;
}
LdapName dnA;
try {
dnA = new LdapName(a);
} catch (InvalidNameException e) {
throw new SchemaException("String '" + a + "' is not a DN: " + e.getMessage(), e);
}
LdapName dnB;
try {
dnB = new LdapName(b);
} catch (InvalidNameException e) {
throw new SchemaException("String '" + b + "' is not a DN: " + e.getMessage(), e);
}
return dnA.equals(dnB);
}
use of com.evolveum.midpoint.util.exception.SchemaException in project midpoint by Evolveum.
the class SchemaToDomProcessor method parseSchema.
/**
* Main entry point.
*
* @param schema midPoint schema
* @return XSD schema in DOM form
* @throws SchemaException error parsing the midPoint schema or converting values
*/
@NotNull
Document parseSchema(PrismSchema schema) throws SchemaException {
if (schema == null) {
throw new IllegalArgumentException("Schema can't be null.");
}
this.schema = schema;
try {
// here the document is initialized
init();
// Process complex types first.
Collection<ComplexTypeDefinition> complexTypes = schema.getDefinitions(ComplexTypeDefinition.class);
for (ComplexTypeDefinition complexTypeDefinition : complexTypes) {
addComplexTypeDefinition(complexTypeDefinition, document.getDocumentElement());
}
Collection<Definition> definitions = schema.getDefinitions();
for (Definition definition : definitions) {
if (definition instanceof PrismContainerDefinition) {
// Add property container definition. This will add <complexType> and <element> definitions to XSD
addContainerDefinition((PrismContainerDefinition) definition, document.getDocumentElement(), document.getDocumentElement());
} else if (definition instanceof PrismPropertyDefinition) {
// Add top-level property definition. It will create <element> XSD definition
addPropertyDefinition((PrismPropertyDefinition) definition, document.getDocumentElement());
} else if (definition instanceof ComplexTypeDefinition) {
// Skip this. Already processed above.
} else {
throw new IllegalArgumentException("Encountered unsupported definition in schema: " + definition);
}
// TODO: process unprocessed ComplexTypeDefinitions
}
// Add import definition. These were accumulated during previous processing.
addImports();
} catch (Exception ex) {
throw new SchemaException("Couldn't parse schema, reason: " + ex.getMessage(), ex);
}
return document;
}
use of com.evolveum.midpoint.util.exception.SchemaException in project midpoint by Evolveum.
the class SchemaRegistryImpl method initialize.
/**
* This can be used to read additional schemas even after the registry was initialized.
*/
@Override
public void initialize() throws SAXException, IOException, SchemaException {
if (prismContext == null) {
throw new IllegalStateException("Prism context not set");
}
if (namespacePrefixMapper == null) {
throw new IllegalStateException("Namespace prefix mapper not set");
}
try {
// TODO remove (all of these)
LOGGER.trace("initialize() starting");
initResolver();
LOGGER.trace("initResolver() done");
parsePrismSchemas();
LOGGER.trace("parsePrismSchemas() done");
parseJavaxSchema();
LOGGER.trace("parseJavaxSchema() done");
compileCompileTimeClassList();
LOGGER.trace("compileCompileTimeClassList() done");
initialized = true;
} catch (SAXException ex) {
if (ex instanceof SAXParseException) {
SAXParseException sex = (SAXParseException) ex;
throw new SchemaException("Error parsing schema " + sex.getSystemId() + " line " + sex.getLineNumber() + ": " + sex.getMessage(), sex);
}
throw ex;
}
}
use of com.evolveum.midpoint.util.exception.SchemaException in project midpoint by Evolveum.
the class DomToSchemaProcessor method parseSchema.
private XSSchemaSet parseSchema(Element schema) throws SchemaException {
// Make sure that the schema parser sees all the namespace declarations
DOMUtil.fixNamespaceDeclarations(schema);
XSSchemaSet xss = null;
try {
TransformerFactory transfac = TransformerFactory.newInstance();
Transformer trans = transfac.newTransformer();
trans.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no");
trans.setOutputProperty(OutputKeys.INDENT, "yes");
DOMSource source = new DOMSource(schema);
ByteArrayOutputStream out = new ByteArrayOutputStream();
StreamResult result = new StreamResult(out);
trans.transform(source, result);
XSOMParser parser = createSchemaParser();
InputSource inSource = new InputSource(new ByteArrayInputStream(out.toByteArray()));
// XXX: hack: it's here to make entity resolver work...
inSource.setSystemId("SystemId");
// XXX: end hack
inSource.setEncoding("utf-8");
parser.parse(inSource);
xss = parser.getResult();
} catch (SAXException e) {
throw new SchemaException("XML error during XSD schema parsing: " + e.getMessage() + "(embedded exception " + e.getException() + ") in " + shortDescription, e);
} catch (TransformerException e) {
throw new SchemaException("XML transformer error during XSD schema parsing: " + e.getMessage() + "(locator: " + e.getLocator() + ", embedded exception:" + e.getException() + ") in " + shortDescription, e);
} catch (RuntimeException e) {
// This sometimes happens, e.g. NPEs in Saxon
if (LOGGER.isErrorEnabled()) {
LOGGER.error("Unexpected error {} during parsing of schema:\n{}", e.getMessage(), DOMUtil.serializeDOMToString(schema));
}
throw new SchemaException("XML error during XSD schema parsing: " + e.getMessage() + " in " + shortDescription, e);
}
return xss;
}
use of com.evolveum.midpoint.util.exception.SchemaException in project midpoint by Evolveum.
the class AccessCertificationCloseStageTriggerHandler method handle.
@Override
public <O extends ObjectType> void handle(PrismObject<O> prismObject, TriggerType trigger, Task task, OperationResult result) {
try {
ObjectType object = prismObject.asObjectable();
if (!(object instanceof AccessCertificationCampaignType)) {
LOGGER.error("Trigger of this type is supported only on {} objects, not on {}", AccessCertificationCampaignType.class.getSimpleName(), object.getClass().getName());
return;
}
AccessCertificationCampaignType campaign = (AccessCertificationCampaignType) object;
LOGGER.info("Automatically closing current stage of {}", ObjectTypeUtil.toShortString(campaign));
if (campaign.getState() != IN_REVIEW_STAGE) {
LOGGER.warn("Campaign {} is not in a review stage; this 'close stage' trigger will be ignored.", ObjectTypeUtil.toShortString(campaign));
return;
}
int currentStageNumber = campaign.getStageNumber();
certificationManager.closeCurrentStage(campaign.getOid(), currentStageNumber, task, result);
if (currentStageNumber < CertCampaignTypeUtil.getNumberOfStages(campaign)) {
LOGGER.info("Automatically opening next stage of {}", ObjectTypeUtil.toShortString(campaign));
certificationManager.openNextStage(campaign.getOid(), currentStageNumber + 1, task, result);
} else {
LOGGER.info("Automatically starting remediation for {}", ObjectTypeUtil.toShortString(campaign));
certificationManager.startRemediation(campaign.getOid(), task, result);
}
} catch (SchemaException | ObjectNotFoundException | ObjectAlreadyExistsException | SecurityViolationException | RuntimeException e) {
LoggingUtils.logException(LOGGER, "Couldn't close current campaign and possibly advance to the next one", e);
}
}
Aggregations