use of com.evolveum.midpoint.util.exception.SchemaException in project midpoint by Evolveum.
the class QueryJaxbConvertor method createObjectQueryInternal.
public static <O extends Containerable> ObjectQuery createObjectQueryInternal(PrismContainerDefinition<O> objDef, SearchFilterType filterType, PagingType pagingType, PrismContext prismContext) throws SchemaException {
try {
ObjectQuery query = new ObjectQuery();
if (filterType != null && filterType.containsFilterClause()) {
MapXNode rootFilter = filterType.getFilterClauseXNode();
ObjectFilter filter = QueryConvertor.parseFilter(rootFilter, objDef);
query.setFilter(filter);
}
if (pagingType != null) {
ObjectPaging paging = PagingConvertor.createObjectPaging(pagingType);
query.setPaging(paging);
}
return query;
} catch (SchemaException ex) {
throw new SchemaException("Failed to convert query. Reason: " + ex.getMessage(), ex);
}
}
use of com.evolveum.midpoint.util.exception.SchemaException in project midpoint by Evolveum.
the class QueryJaxbConvertor method createTypeObjectQuery.
public static ObjectQuery createTypeObjectQuery(QueryType queryType, PrismContext prismContext) throws SchemaException {
if (queryType == null) {
return null;
}
if (queryType.getFilter() == null) {
return null;
}
if (queryType.getFilter().containsFilterClause()) {
MapXNode mapXnode = queryType.getFilter().getFilterClauseXNode();
QName type = mapXnode.getParsedPrimitiveValue(QueryConvertor.ELEMENT_TYPE, DOMUtil.XSD_QNAME);
if (type == null) {
throw new SchemaException("Query does not countain type filter. Cannot by parse.");
}
Class clazz = prismContext.getSchemaRegistry().determineCompileTimeClass(type);
if (clazz == null) {
PrismObjectDefinition objDef = prismContext.getSchemaRegistry().findObjectDefinitionByType(type);
if (objDef != null) {
clazz = objDef.getCompileTimeClass();
}
}
if (clazz == null) {
throw new SchemaException("Type defined in query is not valid. " + type);
}
return createObjectQuery(clazz, queryType, prismContext);
}
return null;
}
use of com.evolveum.midpoint.util.exception.SchemaException in project midpoint by Evolveum.
the class DomToSchemaProcessor method processComplexTypeDefinition.
/**
* Creates ComplexTypeDefinition object from a single XSD complexType
* definition.
*
* @param complexType
* XS complex type definition
*/
private ComplexTypeDefinition processComplexTypeDefinition(XSComplexType complexType) throws SchemaException {
SchemaDefinitionFactory definitionFactory = getDefinitionFactory();
ComplexTypeDefinitionImpl ctd = (ComplexTypeDefinitionImpl) definitionFactory.createComplexTypeDefinition(complexType, prismContext, complexType.getAnnotation());
ComplexTypeDefinition existingComplexTypeDefinition = schema.findComplexTypeDefinition(ctd.getTypeName());
if (existingComplexTypeDefinition != null) {
// infinite loops;
return existingComplexTypeDefinition;
}
// Add to the schema right now to avoid loops - even if it is not
// complete yet
// The definition may reference itself
schema.add(ctd);
XSContentType content = complexType.getContentType();
XSContentType explicitContent = complexType.getExplicitContent();
if (content != null) {
XSParticle particle = content.asParticle();
if (particle != null) {
XSTerm term = particle.getTerm();
if (term.isModelGroup()) {
Boolean inherited = null;
if (explicitContent == null || content == explicitContent) {
inherited = false;
}
addPropertyDefinitionListFromGroup(term.asModelGroup(), ctd, inherited, explicitContent);
}
}
XSAnnotation annotation = complexType.getAnnotation();
Element extensionAnnotationElement = SchemaProcessorUtil.getAnnotationElement(annotation, A_EXTENSION);
if (extensionAnnotationElement != null) {
QName extensionType = DOMUtil.getQNameAttribute(extensionAnnotationElement, A_EXTENSION_REF.getLocalPart());
if (extensionType == null) {
throw new SchemaException("The " + A_EXTENSION + "annontation on " + ctd.getTypeName() + " complex type does not have " + A_EXTENSION_REF.getLocalPart() + " attribute", A_EXTENSION_REF);
}
ctd.setExtensionForType(extensionType);
}
}
markRuntime(ctd);
if (complexType.isAbstract()) {
ctd.setAbstract(true);
}
QName superType = determineSupertype(complexType);
if (superType != null) {
ctd.setSuperType(superType);
}
if (isObjectDefinition(complexType)) {
ctd.setObjectMarker(true);
}
if (isPropertyContainer(complexType)) {
ctd.setContainerMarker(true);
}
ctd.setDefaultNamespace(getDefaultNamespace(complexType));
ctd.setIgnoredNamespaces(getIgnoredNamespaces(complexType));
if (isAny(complexType)) {
ctd.setXsdAnyMarker(true);
}
if (isList(complexType)) {
ctd.setListMarker(true);
}
extractDocumentation(ctd, complexType.getAnnotation());
if (getSchemaRegistry() != null) {
Class<?> compileTimeClass = getSchemaRegistry().determineCompileTimeClass(ctd.getTypeName());
ctd.setCompileTimeClass(compileTimeClass);
}
definitionFactory.finishComplexTypeDefinition(ctd, complexType, prismContext, complexType.getAnnotation());
// Attempt to create object or container definition from this complex
// type
PrismContainerDefinition<?> defFromComplexType = getDefinitionFactory().createExtraDefinitionFromComplexType(complexType, ctd, prismContext, complexType.getAnnotation());
if (defFromComplexType != null) {
markRuntime(defFromComplexType);
schema.add(defFromComplexType);
}
return ctd;
}
use of com.evolveum.midpoint.util.exception.SchemaException in project midpoint by Evolveum.
the class DomToSchemaProcessor method addPropertyDefinitionListFromGroup.
/**
* Creates ComplexTypeDefinition object from a XSModelGroup inside XSD
* complexType definition. This is a recursive method. It can create
* "anonymous" internal PropertyContainerDefinitions. The definitions will
* be added to the ComplexTypeDefinition provided as parameter.
*
* @param group
* XSD XSModelGroup
* @param ctd
* ComplexTypeDefinition that will hold the definitions
* @param inherited
* Are these properties inherited? (null means we don't know and
* we'll determine that from explicitContent)
* @param explicitContent
* Explicit (i.e. non-inherited) content of the type being parsed
* - filled-in only for subtypes!
*/
private void addPropertyDefinitionListFromGroup(XSModelGroup group, ComplexTypeDefinition ctd, Boolean inherited, XSContentType explicitContent) throws SchemaException {
XSParticle[] particles = group.getChildren();
for (XSParticle p : particles) {
boolean particleInherited = inherited != null ? inherited : (p != explicitContent);
XSTerm pterm = p.getTerm();
if (pterm.isModelGroup()) {
addPropertyDefinitionListFromGroup(pterm.asModelGroup(), ctd, particleInherited, explicitContent);
}
// xs:element inside complex type
if (pterm.isElementDecl()) {
XSAnnotation annotation = selectAnnotationToUse(p.getAnnotation(), pterm.getAnnotation());
XSElementDecl elementDecl = pterm.asElementDecl();
QName elementName = new QName(elementDecl.getTargetNamespace(), elementDecl.getName());
QName typeFromAnnotation = getTypeAnnotation(p.getAnnotation());
XSType xsType = elementDecl.getType();
if (isObjectReference(xsType, annotation)) {
processObjectReferenceDefinition(xsType, elementName, annotation, ctd, p, particleInherited);
} else if (isObjectDefinition(xsType)) {
// This is object reference. It also has its *Ref equivalent
// which will get parsed.
// therefore it is safe to ignore
} else if (xsType.getName() == null && typeFromAnnotation == null) {
if (isAny(xsType)) {
if (isPropertyContainer(elementDecl)) {
XSAnnotation containerAnnotation = xsType.getAnnotation();
PrismContainerDefinition<?> containerDefinition = createPropertyContainerDefinition(xsType, p, null, containerAnnotation, false);
((PrismContainerDefinitionImpl) containerDefinition).setInherited(particleInherited);
((ComplexTypeDefinitionImpl) ctd).add(containerDefinition);
} else {
PrismPropertyDefinitionImpl propDef = createPropertyDefinition(xsType, elementName, DOMUtil.XSD_ANY, ctd, annotation, p);
propDef.setInherited(particleInherited);
((ComplexTypeDefinitionImpl) ctd).add(propDef);
}
}
} else if (isPropertyContainer(elementDecl)) {
// Create an inner PropertyContainer. It is assumed that
// this is a XSD complex type
XSComplexType complexType = (XSComplexType) xsType;
ComplexTypeDefinition complexTypeDefinition = null;
if (typeFromAnnotation != null && complexType != null && !typeFromAnnotation.equals(getType(xsType))) {
// We need to locate our own complex type definition
if (isMyNamespace(typeFromAnnotation)) {
complexTypeDefinition = getOrProcessComplexType(typeFromAnnotation);
} else {
complexTypeDefinition = getPrismContext().getSchemaRegistry().findComplexTypeDefinition(typeFromAnnotation);
}
if (complexTypeDefinition == null) {
throw new SchemaException("Cannot find definition of complex type " + typeFromAnnotation + " as specified in type override annotation at " + elementName);
}
} else {
complexTypeDefinition = processComplexTypeDefinition(complexType);
}
XSAnnotation containerAnnotation = complexType.getAnnotation();
PrismContainerDefinition<?> containerDefinition = createPropertyContainerDefinition(xsType, p, complexTypeDefinition, containerAnnotation, false);
if (isAny(xsType)) {
((PrismContainerDefinitionImpl) containerDefinition).setRuntimeSchema(true);
((PrismContainerDefinitionImpl) containerDefinition).setDynamic(true);
}
((PrismContainerDefinitionImpl) containerDefinition).setInherited(particleInherited);
((ComplexTypeDefinitionImpl) ctd).add(containerDefinition);
} else {
// Create a property definition (even if this is a XSD
// complex type)
QName typeName = new QName(xsType.getTargetNamespace(), xsType.getName());
PrismPropertyDefinitionImpl propDef = createPropertyDefinition(xsType, elementName, typeName, ctd, annotation, p);
propDef.setInherited(particleInherited);
((ComplexTypeDefinitionImpl) ctd).add(propDef);
}
}
}
}
use of com.evolveum.midpoint.util.exception.SchemaException in project midpoint by Evolveum.
the class XNodeProcessorUtil method parseProtectedType.
public static <T> void parseProtectedType(ProtectedDataType<T> protectedType, MapXNode xmap, PrismContext prismContext, ParsingContext pc) throws SchemaException {
RootXNode xEncryptedData = xmap.getEntryAsRoot(ProtectedDataType.F_ENCRYPTED_DATA);
if (xEncryptedData != null) {
if (!(xEncryptedData.getSubnode() instanceof MapXNode)) {
throw new SchemaException("Cannot parse encryptedData from " + xEncryptedData);
}
EncryptedDataType encryptedDataType = prismContext.parserFor(xEncryptedData).context(pc).parseRealValue(EncryptedDataType.class);
protectedType.setEncryptedData(encryptedDataType);
} else {
// Check for legacy EncryptedData
RootXNode xLegacyEncryptedData = xmap.getEntryAsRoot(ProtectedDataType.F_XML_ENC_ENCRYPTED_DATA);
if (xLegacyEncryptedData != null) {
if (!(xLegacyEncryptedData.getSubnode() instanceof MapXNode)) {
throw new SchemaException("Cannot parse EncryptedData from " + xEncryptedData);
}
RootXNode xConvertedEncryptedData = (RootXNode) xLegacyEncryptedData.cloneTransformKeys(in -> {
String elementName = StringUtils.uncapitalize(in.getLocalPart());
if (elementName.equals("type")) {
return null;
}
return new QName(null, elementName);
});
EncryptedDataType encryptedDataType = prismContext.parserFor(xConvertedEncryptedData).context(pc).parseRealValue(EncryptedDataType.class);
protectedType.setEncryptedData(encryptedDataType);
if (protectedType instanceof ProtectedStringType) {
transformEncryptedValue(protectedType, prismContext);
}
}
}
RootXNode xHashedData = xmap.getEntryAsRoot(ProtectedDataType.F_HASHED_DATA);
if (xHashedData != null) {
if (!(xHashedData.getSubnode() instanceof MapXNode)) {
throw new SchemaException("Cannot parse hashedData from " + xHashedData);
}
HashedDataType hashedDataType = prismContext.parserFor(xHashedData).context(pc).parseRealValue(HashedDataType.class);
protectedType.setHashedData(hashedDataType);
}
// protected data empty..check for clear value
if (protectedType.isEmpty()) {
XNode xClearValue = xmap.get(ProtectedDataType.F_CLEAR_VALUE);
if (xClearValue == null) {
//TODO: try to use common namespace (only to be compatible with previous versions)
//FIXME maybe add some warning, info...
xClearValue = xmap.get(new QName(ProtectedDataType.F_CLEAR_VALUE.getLocalPart()));
}
if (xClearValue == null) {
return;
}
if (!(xClearValue instanceof PrimitiveXNode)) {
//this is maybe not good..
throw new SchemaException("Cannot parse clear value from " + xClearValue);
}
// TODO: clearValue
T clearValue = (T) ((PrimitiveXNode) xClearValue).getParsedValue(DOMUtil.XSD_STRING, String.class);
protectedType.setClearValue(clearValue);
}
}
Aggregations