use of com.evolveum.midpoint.schema.SelectorOptions in project midpoint by Evolveum.
the class TestResources method test200GetResourceRawAfterSchema.
@Test
public void test200GetResourceRawAfterSchema() throws Exception {
final String TEST_NAME = "test200GetResourceRawAfterSchema";
TestUtil.displayTestTile(this, TEST_NAME);
// GIVEN
Task task = taskManager.createTaskInstance(TestResources.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
assumeAssignmentPolicy(AssignmentPolicyEnforcementType.POSITIVE);
IntegrationTestTools.assertNoRepoCache();
Collection<SelectorOptions<GetOperationOptions>> options = SelectorOptions.createCollection(GetOperationOptions.createRaw());
// WHEN
PrismObject<ResourceType> resource = modelService.getObject(ResourceType.class, RESOURCE_DUMMY_OID, options, task, result);
// THEN
IntegrationTestTools.assertNoRepoCache();
SqlRepoTestUtil.assertVersionProgress(null, resource.getVersion());
lastVersion = resource.getVersion();
display("Initial version", lastVersion);
result.computeStatus();
TestUtil.assertSuccess("getObject result", result);
IntegrationTestTools.displayXml("Initialized dummy resource", resource);
}
use of com.evolveum.midpoint.schema.SelectorOptions in project midpoint by Evolveum.
the class AbstractManualResourceTest method test102GetAccountWillFuture.
@Test
public void test102GetAccountWillFuture() throws Exception {
final String TEST_NAME = "test102GetAccountWillFuture";
displayTestTile(TEST_NAME);
// GIVEN
Task task = createTask(TEST_NAME);
OperationResult result = task.getResult();
syncServiceMock.reset();
Collection<SelectorOptions<GetOperationOptions>> options = SelectorOptions.createCollection(GetOperationOptions.createPointInTimeType(PointInTimeType.FUTURE));
// WHEN
displayWhen(TEST_NAME);
PrismObject<ShadowType> shadowProvisioning = provisioningService.getObject(ShadowType.class, ACCOUNT_WILL_OID, options, task, result);
// THEN
displayThen(TEST_NAME);
assertSuccess(result);
display("Provisioning shadow", shadowProvisioning);
ShadowType shadowTypeProvisioning = shadowProvisioning.asObjectable();
assertShadowName(shadowProvisioning, ACCOUNT_WILL_USERNAME);
assertEquals("Wrong kind (provisioning)", ShadowKindType.ACCOUNT, shadowTypeProvisioning.getKind());
assertAttribute(shadowProvisioning, ATTR_USERNAME_QNAME, ACCOUNT_WILL_USERNAME);
assertAttribute(shadowProvisioning, ATTR_FULLNAME_QNAME, ACCOUNT_WILL_FULLNAME);
assertNoAttribute(shadowProvisioning, ATTR_DESCRIPTION_QNAME);
assertShadowActivationAdministrativeStatus(shadowProvisioning, ActivationStatusType.ENABLED);
assertShadowExists(shadowProvisioning, true);
// TODO
// assertShadowPassword(shadowProvisioning);
}
use of com.evolveum.midpoint.schema.SelectorOptions in project midpoint by Evolveum.
the class ReportFunctions method searchCertificationDefinitions.
// TODO implement if needed
// <O extends Containerable> RefFilter createReferenceEqualFilter(QName propertyName, Class<O> type, String... oids) {
// return RefFilter.createReferenceEqual(propertyName, type, prismContext, oids);
// }
// <O extends Containerable> RefFilter createReferenceEqualFilter(ItemPath propertyPath, Class<O> type, String... oids) throws SchemaException {
// return RefFilter.createReferenceEqual(propertyPath, type, prismContext, oids);
// }
// Object parseObjectFromXML (String xml) throws SchemaException {
// return prismContext.parserFor(xml).xml().parseAnyData();
// }
/**
* Retrieves all definitions.
* Augments them by count of campaigns (all + open ones).
*
* TODO query parameters, customizable sorting
* definitions and campaigns counts are expected to be low, so we can afford to go through all of them here
*/
public Collection<PrismObject<AccessCertificationDefinitionForReportType>> searchCertificationDefinitions() throws ConfigurationException, SchemaException, ObjectNotFoundException, CommunicationException, SecurityViolationException, ExpressionEvaluationException {
Task task = taskManager.createTaskInstance();
OperationResult result = task.getResult();
Collection<SelectorOptions<GetOperationOptions>> options = SelectorOptions.createCollection(GetOperationOptions.createResolveNames());
List<PrismObject<AccessCertificationDefinitionType>> definitions = model.searchObjects(AccessCertificationDefinitionType.class, null, options, task, result);
final Map<String, PrismObject<AccessCertificationDefinitionForReportType>> definitionsForReportMap = new HashMap<>();
for (PrismObject<AccessCertificationDefinitionType> definition : definitions) {
// create subclass with the values copied from the superclass
PrismObject<AccessCertificationDefinitionForReportType> definitionForReport = prismContext.createObjectable(AccessCertificationDefinitionForReportType.class).asPrismObject();
for (Item<?, ?> item : definition.getValue().getItems()) {
definitionForReport.getValue().add(item.clone());
}
definitionsForReportMap.put(definition.getOid(), definitionForReport);
}
ResultHandler<AccessCertificationCampaignType> handler = (campaignObject, parentResult) -> {
AccessCertificationCampaignType campaign = campaignObject.asObjectable();
if (campaign.getDefinitionRef() != null) {
String definitionOid = campaign.getDefinitionRef().getOid();
PrismObject<AccessCertificationDefinitionForReportType> definitionObject = definitionsForReportMap.get(definitionOid);
if (definitionObject != null) {
AccessCertificationDefinitionForReportType definition = definitionObject.asObjectable();
int campaigns = definition.getCampaigns() != null ? definition.getCampaigns() : 0;
definition.setCampaigns(campaigns + 1);
AccessCertificationCampaignStateType state = campaign.getState();
if (state != AccessCertificationCampaignStateType.CREATED && state != CLOSED) {
int openCampaigns = definition.getOpenCampaigns() != null ? definition.getOpenCampaigns() : 0;
definition.setOpenCampaigns(openCampaigns + 1);
}
}
}
return true;
};
model.searchObjectsIterative(AccessCertificationCampaignType.class, null, handler, null, task, result);
List<PrismObject<AccessCertificationDefinitionForReportType>> rv = new ArrayList<>(definitionsForReportMap.values());
Collections.sort(rv, (o1, o2) -> {
String n1 = o1.asObjectable().getName().getOrig();
String n2 = o2.asObjectable().getName().getOrig();
if (n1 == null) {
n1 = "";
}
return n1.compareTo(n2);
});
for (PrismObject<AccessCertificationDefinitionForReportType> defObject : rv) {
AccessCertificationDefinitionForReportType def = defObject.asObjectable();
if (def.getCampaigns() == null) {
def.setCampaigns(0);
}
if (def.getOpenCampaigns() == null) {
def.setOpenCampaigns(0);
}
}
return rv;
}
use of com.evolveum.midpoint.schema.SelectorOptions in project midpoint by Evolveum.
the class ReportFunctions method getCertificationCampaigns.
public List<PrismObject<AccessCertificationCampaignType>> getCertificationCampaigns(Boolean alsoClosedCampaigns) throws SchemaException, ConfigurationException, ObjectNotFoundException, CommunicationException, SecurityViolationException, ExpressionEvaluationException {
Task task = taskManager.createTaskInstance();
ObjectQuery query = QueryBuilder.queryFor(AccessCertificationCampaignType.class, prismContext).asc(F_NAME).build();
if (!Boolean.TRUE.equals(alsoClosedCampaigns)) {
query.addFilter(QueryBuilder.queryFor(AccessCertificationCampaignType.class, prismContext).not().item(F_STATE).eq(CLOSED).buildFilter());
}
Collection<SelectorOptions<GetOperationOptions>> options = SelectorOptions.createCollection(GetOperationOptions.createResolveNames());
options.add(SelectorOptions.create(AccessCertificationCampaignType.F_CASE, GetOperationOptions.createRetrieve(RetrieveOption.INCLUDE)));
return model.searchObjects(AccessCertificationCampaignType.class, query, options, task, task.getResult());
}
use of com.evolveum.midpoint.schema.SelectorOptions in project midpoint by Evolveum.
the class TestLdap method test202AssignLdapAccountToGuybrush.
/**
* Just a first step for the following test.
* Also, Guybrush has a photo. Check that binary property mapping works.
*/
@Test
public void test202AssignLdapAccountToGuybrush() throws Exception {
final String TEST_NAME = "test202AssignLdapAccountToGuybrush";
TestUtil.displayTestTile(this, TEST_NAME);
// GIVEN
Task task = taskManager.createTaskInstance(TestLdap.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
byte[] photoIn = Files.readAllBytes(Paths.get(DOT_JPG_FILENAME));
display("Photo in", MiscUtil.binaryToHex(photoIn));
modifyUserReplace(USER_GUYBRUSH_OID, UserType.F_JPEG_PHOTO, task, result, photoIn);
Collection<SelectorOptions<GetOperationOptions>> options = SelectorOptions.createCollection(UserType.F_JPEG_PHOTO, GetOperationOptions.createRetrieve(RetrieveOption.INCLUDE));
PrismObject<UserType> userBefore = modelService.getObject(UserType.class, USER_GUYBRUSH_OID, options, task, result);
display("User before", userBefore);
byte[] userJpegPhotoBefore = userBefore.asObjectable().getJpegPhoto();
assertEquals("Photo byte length changed (user before)", photoIn.length, userJpegPhotoBefore.length);
assertTrue("Photo bytes do not match (user before)", Arrays.equals(photoIn, userJpegPhotoBefore));
// WHEN
TestUtil.displayWhen(TEST_NAME);
assignAccount(USER_GUYBRUSH_OID, RESOURCE_OPENDJ_OID, null, task, result);
// THEN
TestUtil.displayThen(TEST_NAME);
result.computeStatus();
TestUtil.assertSuccess(result);
Entry entry = assertOpenDjAccount(USER_GUYBRUSH_USERNAME, USER_GUYBRUSH_FULL_NAME, true);
byte[] jpegPhotoLdap = OpenDJController.getAttributeValueBinary(entry, "jpegPhoto");
assertNotNull("No jpegPhoto in LDAP entry", jpegPhotoLdap);
assertEquals("Byte length changed (LDAP)", photoIn.length, jpegPhotoLdap.length);
assertTrue("Bytes do not match (LDAP)", Arrays.equals(photoIn, jpegPhotoLdap));
PrismObject<UserType> userAfter = modelService.getObject(UserType.class, USER_GUYBRUSH_OID, options, task, result);
display("User after", userAfter);
String accountOid = getSingleLinkOid(userAfter);
PrismObject<ShadowType> shadow = getShadowModel(accountOid);
PrismContainer<?> attributesContainer = shadow.findContainer(ShadowType.F_ATTRIBUTES);
QName jpegPhotoQName = new QName(RESOURCE_OPENDJ_NAMESPACE, "jpegPhoto");
PrismProperty<byte[]> jpegPhotoAttr = attributesContainer.findProperty(jpegPhotoQName);
byte[] photoBytesOut = jpegPhotoAttr.getValues().get(0).getValue();
display("Photo bytes out", MiscUtil.binaryToHex(photoBytesOut));
assertEquals("Photo byte length changed (shadow)", photoIn.length, photoBytesOut.length);
assertTrue("Photo bytes do not match (shadow)", Arrays.equals(photoIn, photoBytesOut));
assertUsers(NUM_INITIAL_USERS);
}
Aggregations