use of com.evolveum.prism.xml.ns._public.query_3.SearchFilterType in project midpoint by Evolveum.
the class AbstractTestForExchangeConnector method listRequestableRoles.
protected Collection<RoleType> listRequestableRoles() throws SAXException, IOException, FaultMessage, JAXBException {
SearchFilterType filter = ModelClientUtil.parseSearchFilterType("<equal xmlns='http://prism.evolveum.com/xml/ns/public/query-3' xmlns:c='http://midpoint.evolveum.com/xml/ns/public/common/common-3' >" + "<path>c:requestable</path>" + "<value>true</value>" + "</equal>");
QueryType query = new QueryType();
query.setFilter(filter);
SelectorQualifiedGetOptionsType options = new SelectorQualifiedGetOptionsType();
Holder<ObjectListType> objectListHolder = new Holder<ObjectListType>();
Holder<OperationResultType> resultHolder = new Holder<OperationResultType>();
modelPort.searchObjects(ModelClientUtil.getTypeQName(RoleType.class), query, options, objectListHolder, resultHolder);
ObjectListType objectList = objectListHolder.value;
return (Collection) objectList.getObject();
}
use of com.evolveum.prism.xml.ns._public.query_3.SearchFilterType in project midpoint by Evolveum.
the class TestJaxbConstruction method testUserConstruction.
@Test
public void testUserConstruction() throws JAXBException, SchemaException {
System.out.println("\n\n ===[ testUserConstruction ]===\n");
// GIVEN
PrismContext prismContext = PrismTestUtil.getPrismContext();
UserType userType = new UserType();
prismContext.adopt(userType);
PrismObject<UserType> user = userType.asPrismObject();
assertNotNull("No object definition after adopt", user.getDefinition());
SchemaTestUtil.assertUserDefinition(user.getDefinition());
// fullName: PolyString
userType.setFullName(new PolyStringType("Čučoriedka"));
PrismProperty<PolyString> fullNameProperty = user.findProperty(UserType.F_FULL_NAME);
PolyString fullName = fullNameProperty.getRealValue();
assertEquals("Wrong fullName orig", "Čučoriedka", fullName.getOrig());
assertEquals("Wrong fullName norm", "cucoriedka", fullName.getNorm());
// description: setting null value
userType.setDescription(null);
PrismProperty<String> descriptionProperty = user.findProperty(UserType.F_DESCRIPTION);
assertNull("Unexpected description property " + descriptionProperty, descriptionProperty);
// description: setting null value
userType.setDescription("blah blah");
descriptionProperty = user.findProperty(UserType.F_DESCRIPTION);
assertEquals("Wrong description value", "blah blah", descriptionProperty.getRealValue());
// description: resetting null value
userType.setDescription(null);
descriptionProperty = user.findProperty(UserType.F_DESCRIPTION);
assertNull("Unexpected description property (after reset) " + descriptionProperty, descriptionProperty);
// Extension
ExtensionType extension = new ExtensionType();
userType.setExtension(extension);
user.checkConsistence();
PrismContainer<Containerable> extensionContainer = user.findContainer(GenericObjectType.F_EXTENSION);
checkExtension(extensionContainer, "user extension after setExtension");
checkExtension(extension, "user extension after setExtension");
AssignmentType assignmentType = new AssignmentType();
userType.getAssignment().add(assignmentType);
user.checkConsistence();
user.assertDefinitions();
// Assignment
ExtensionType assignmentExtension = new ExtensionType();
assignmentType.setExtension(assignmentExtension);
user.assertDefinitions();
user.checkConsistence();
checkExtension(assignmentExtension, "assignment extension after setExtension");
user.checkConsistence();
user.assertDefinitions();
// accountRef/account
ObjectReferenceType accountRefType = new ObjectReferenceType();
accountRefType.setOid(USER_ACCOUNT_REF_1_OID);
MapXNode filterElement = createFilter();
SearchFilterType filter = new SearchFilterType();
filter.setFilterClauseXNode(filterElement);
accountRefType.setFilter(filter);
userType.getLinkRef().add(accountRefType);
assertAccountRefs(userType, USER_ACCOUNT_REF_1_OID);
user.checkConsistence();
user.assertDefinitions();
PrismReference accountRef = user.findReference(UserType.F_LINK_REF);
assertEquals("1/ Wrong accountRef values", 1, accountRef.getValues().size());
PrismReferenceValue accountRefVal0 = accountRef.getValue(0);
SearchFilterType prismFilter = accountRefVal0.getFilter();
assertNotNull("Filter have not passed", prismFilter);
//assertTrue("Bad filter in reference", prismFilter instanceof EqualsFilter);
// assertEquals("Difference filter", filterElement, prismFilter);
ShadowType accountShadowType = new ShadowType();
prismContext.adopt(accountShadowType);
accountShadowType.setOid(USER_ACCOUNT_REF_1_OID);
userType.getLink().add(accountShadowType);
//value still should be only one... (reference was only resolved)
assertEquals("2/ Wrong accountRef values", 1, user.findReference(UserType.F_LINK_REF).getValues().size());
accountShadowType = new ShadowType();
prismContext.adopt(accountShadowType);
accountShadowType.setOid(USER_ACCOUNT_REF_2_OID);
userType.getLink().add(accountShadowType);
assertEquals("3/ Wrong accountRef values", 2, user.findReference(UserType.F_LINK_REF).getValues().size());
assertAccountRefs(userType, USER_ACCOUNT_REF_1_OID, USER_ACCOUNT_REF_2_OID);
user.checkConsistence();
user.assertDefinitions();
assertEquals("4/ Wrong accountRef values", 2, accountRef.getValues().size());
PrismAsserts.assertReferenceValues(accountRef, USER_ACCOUNT_REF_1_OID, USER_ACCOUNT_REF_2_OID);
}
use of com.evolveum.prism.xml.ns._public.query_3.SearchFilterType in project midpoint by Evolveum.
the class TestJaxbConstruction method testUserConstructionBeforeAdopt.
@Test
public void testUserConstructionBeforeAdopt() throws Exception {
System.out.println("\n\n ===[ testUserConstructionBeforeAdopt ]===\n");
// GIVEN
PrismContext prismContext = PrismTestUtil.getPrismContext();
UserType userType = new UserType();
userType.setFullName(new PolyStringType("Čučoriedka"));
userType.setDescription("blah blah");
ExtensionType extension = new ExtensionType();
userType.setExtension(extension);
AssignmentType assignmentType = new AssignmentType();
userType.getAssignment().add(assignmentType);
// Assignment
ExtensionType assignmentExtension = new ExtensionType();
assignmentType.setExtension(assignmentExtension);
// accountRef/account
ObjectReferenceType accountRefType = new ObjectReferenceType();
accountRefType.setOid(USER_ACCOUNT_REF_1_OID);
MapXNode filterElement = createFilter();
SearchFilterType filter = new SearchFilterType();
filter.setFilterClauseXNode(filterElement);
accountRefType.setFilter(filter);
userType.getLinkRef().add(accountRefType);
ShadowType accountShadowType = new ShadowType();
accountShadowType.setOid(USER_ACCOUNT_REF_1_OID);
userType.getLink().add(accountShadowType);
accountShadowType = new ShadowType();
accountShadowType.setOid(USER_ACCOUNT_REF_2_OID);
userType.getLink().add(accountShadowType);
// WHEN
prismContext.adopt(userType);
// THEN
PrismObject<UserType> user = userType.asPrismObject();
assertNotNull("No object definition after adopt", user.getDefinition());
SchemaTestUtil.assertUserDefinition(user.getDefinition());
// fullName: PolyString
PrismProperty<PolyString> fullNameProperty = user.findProperty(UserType.F_FULL_NAME);
user.checkConsistence();
user.assertDefinitions();
PolyString fullName = fullNameProperty.getRealValue();
assertEquals("Wrong fullName orig", "Čučoriedka", fullName.getOrig());
assertEquals("Wrong fullName norm", "cucoriedka", fullName.getNorm());
PrismProperty<String> descriptionProperty = user.findProperty(UserType.F_DESCRIPTION);
assertEquals("Wrong description value", "blah blah", descriptionProperty.getRealValue());
PrismContainer<Containerable> extensionContainer = user.findContainer(GenericObjectType.F_EXTENSION);
checkExtension(extensionContainer, "user extension");
checkExtension(extension, "user extension");
PrismReference accountRef = user.findReference(UserType.F_LINK_REF);
assertEquals("Wrong accountRef values", 2, accountRef.getValues().size());
PrismAsserts.assertReferenceValues(accountRef, USER_ACCOUNT_REF_1_OID, USER_ACCOUNT_REF_2_OID);
PrismReferenceValue accountRefVal0 = accountRef.getValue(0);
SearchFilterType prismFilter = accountRefVal0.getFilter();
assertNotNull("Filter have not passed", prismFilter);
// assertTrue("Wrong filter in reference " , prismFilter instanceof EqualsFilter);
// assertEquals("Difference filter", filterElement, prismFilter);
assertAccountRefs(userType, USER_ACCOUNT_REF_1_OID, USER_ACCOUNT_REF_2_OID);
user.assertDefinitions();
user.checkConsistence();
}
use of com.evolveum.prism.xml.ns._public.query_3.SearchFilterType in project midpoint by Evolveum.
the class TestParseFilter method testParseFilterFile.
@Test
public void testParseFilterFile() throws Exception {
System.out.println("===[ testParseFilterFile ]===");
// GIVEN
PrismContext prismContext = PrismTestUtil.getPrismContext();
// WHEN
SearchFilterType filter = prismContext.parserFor(FILTER_FILE).parseRealValue(SearchFilterType.class);
// THEN
System.out.println("Parsed filter:");
System.out.println(filter.debugDump());
String serialized = PrismTestUtil.serializeJaxbElementToString(new JAXBElement<SearchFilterType>(new QName(SchemaConstants.NS_QUERY, "filter"), SearchFilterType.class, filter));
System.out.println("JAXB serialization result:\n" + serialized);
// WHEN2
SearchFilterType filter2 = prismContext.parserFor(serialized).parseRealValue(SearchFilterType.class);
System.out.println("Reparsed filter:");
System.out.println(filter2.debugDump());
// THEN2
assertEquals("Parsed and serialized+parsed filters do not match", filter, filter2);
}
use of com.evolveum.prism.xml.ns._public.query_3.SearchFilterType in project midpoint by Evolveum.
the class Utils method resolveRef.
private static void resolveRef(PrismReferenceValue refVal, RepositoryService repository, boolean enforceReferentialIntegrity, boolean forceFilterReevaluation, EvaluationTimeType evaluationTimeType, PrismContext prismContext, String contextDesc, boolean throwExceptionOnFailure, OperationResult parentResult) {
String refName = refVal.getParent() != null ? refVal.getParent().getElementName().toString() : "(unnamed)";
if ((refVal.getResolutionTime() != null && refVal.getResolutionTime() != evaluationTimeType) || (refVal.getResolutionTime() == null && evaluationTimeType != EvaluationTimeType.IMPORT)) {
LOGGER.trace("Skipping resolution of reference {} in {} because the resolutionTime is set to {}", refName, contextDesc, refVal.getResolutionTime());
return;
}
OperationResult result = parentResult.createMinorSubresult(OPERATION_RESOLVE_REFERENCE);
result.addContext(OperationResult.CONTEXT_ITEM, refName);
QName typeQName = null;
if (refVal.getTargetType() != null) {
typeQName = refVal.getTargetType();
}
if (typeQName == null) {
PrismReferenceDefinition definition = (PrismReferenceDefinition) refVal.getParent().getDefinition();
if (definition != null) {
typeQName = definition.getTargetTypeName();
}
}
Class<? extends ObjectType> type = ObjectType.class;
if (typeQName != null) {
type = prismContext.getSchemaRegistry().determineCompileTimeClass(typeQName);
if (type == null) {
result.recordWarning("Unknown type specified in reference or definition of reference " + refName + ": " + typeQName);
type = ObjectType.class;
}
}
SearchFilterType filter = refVal.getFilter();
if (!StringUtils.isBlank(refVal.getOid()) && (!forceFilterReevaluation || filter == null)) {
// We have OID (and "force filter reevaluation" is not requested or not possible)
if (filter != null) {
// We have both filter and OID. We will choose OID, but let's at
// least log a warning
LOGGER.debug("Both OID and filter for property {} in {}, OID takes precedence", refName, contextDesc);
}
// Nothing to resolve, but let's check if the OID exists
PrismObject<? extends ObjectType> object = null;
try {
object = repository.getObject(type, refVal.getOid(), null, result);
} catch (ObjectNotFoundException e) {
String message = "Reference " + refName + " refers to a non-existing object " + refVal.getOid();
if (enforceReferentialIntegrity) {
LOGGER.error(message);
result.recordFatalError(message);
if (throwExceptionOnFailure) {
throw new SystemException(message, e);
}
} else {
LOGGER.warn(message);
result.recordWarning(message);
}
} catch (SchemaException e) {
String message = "Schema error while trying to retrieve object " + refVal.getOid() + " : " + e.getMessage();
result.recordPartialError(message, e);
LOGGER.error(message, e);
// But continue otherwise
}
if (object != null && refVal.getOriginType() != null) {
// Check if declared and actual type matches
if (!object.getClass().equals(type)) {
result.recordWarning("Type mismatch on property " + refName + ": declared:" + refVal.getOriginType() + ", actual: " + object.getClass());
}
}
result.recordSuccessIfUnknown();
parentResult.computeStatus();
return;
}
if (filter == null) {
if (refVal.getObject() != null) {
LOGGER.trace("Skipping resolution of reference {} in {} because the object is present and the filter is not", refName, contextDesc);
result.recordNotApplicableIfUnknown();
return;
}
// No OID and no filter. We are lost.
String message = "Neither OID nor filter for property " + refName + ": cannot resolve reference";
result.recordFatalError(message);
if (throwExceptionOnFailure) {
throw new SystemException(message);
}
return;
}
// No OID and we have filter. Let's check the filter a bit
ObjectFilter objFilter;
try {
PrismObjectDefinition objDef = prismContext.getSchemaRegistry().findObjectDefinitionByCompileTimeClass(type);
objFilter = QueryConvertor.parseFilter(filter, objDef);
} catch (SchemaException ex) {
LOGGER.error("Failed to convert object filter from filter because of: " + ex.getMessage() + "; filter: " + filter.debugDump(), ex);
throw new SystemException("Failed to convert object filter from filter. Reason: " + ex.getMessage(), ex);
}
LOGGER.trace("Resolving using filter {}", objFilter.debugDump());
List<PrismObject<? extends ObjectType>> objects;
QName objectType = refVal.getTargetType();
if (objectType == null) {
String message = "Missing definition of type of reference " + refName;
result.recordFatalError(message);
if (throwExceptionOnFailure) {
throw new SystemException(message);
}
return;
}
if (containExpression(objFilter)) {
result.recordSuccessIfUnknown();
return;
}
try {
ObjectQuery query = ObjectQuery.createObjectQuery(objFilter);
objects = (List) repository.searchObjects(type, query, null, result);
} catch (SchemaException e) {
// This is unexpected, but may happen. Record fatal error
String message = "Repository schema error during resolution of reference " + refName;
result.recordFatalError(message, e);
if (throwExceptionOnFailure) {
throw new SystemException(message, e);
}
return;
} catch (SystemException e) {
// We don't want this to tear down entire import.
String message = "Repository system error during resolution of reference " + refName;
result.recordFatalError(message, e);
if (throwExceptionOnFailure) {
throw new SystemException(message, e);
}
return;
}
if (objects.isEmpty()) {
String message = "Repository reference " + refName + " cannot be resolved: filter matches no object";
result.recordFatalError(message);
if (throwExceptionOnFailure) {
throw new SystemException(message);
}
return;
}
if (objects.size() > 1) {
String message = "Repository reference " + refName + " cannot be resolved: filter matches " + objects.size() + " objects";
result.recordFatalError(message);
if (throwExceptionOnFailure) {
throw new SystemException(message);
}
return;
}
// Bingo. We have exactly one object.
String oid = objects.get(0).getOid();
refVal.setOid(oid);
result.recordSuccessIfUnknown();
}
Aggregations