use of com.evolveum.midpoint.util.Holder in project midpoint by Evolveum.
the class DataLanguagePanel method onStateChanged.
@Override
protected void onStateChanged(int updatedIndex, AjaxRequestTarget target) {
String updatedLanguage = updatedIndex >= 0 && updatedIndex < LANGUAGES.size() ? LANGUAGES.get(updatedIndex) : LANGUAGES.get(0);
String currentObjectString = getObjectStringRepresentation();
if (StringUtils.isBlank(currentObjectString)) {
processLanguageSwitch(target, updatedIndex, updatedLanguage, currentObjectString);
return;
}
OperationResult result = new OperationResult(DataLanguagePanel.class.getName() + ".parseObject");
Holder<T> objectHolder = new Holder<>(null);
try {
pageBase.parseObject(currentObjectString, objectHolder, LANGUAGES.get(currentLanguageIndex), false, true, dataType, result);
if (result.isAcceptable()) {
Object updatedObject = objectHolder.getValue();
String updatedObjectString;
PrismSerializer<String> serializer = pageBase.getPrismContext().serializerFor(updatedLanguage);
if (List.class.isAssignableFrom(dataType)) {
@SuppressWarnings({ "unchecked", "raw" }) List<PrismObject<?>> list = (List<PrismObject<?>>) updatedObject;
if (list.size() != 1) {
updatedObjectString = serializer.serializeObjects(list);
} else {
updatedObjectString = serializer.serialize(list.get(0));
}
} else if (Objectable.class.isAssignableFrom(dataType)) {
updatedObjectString = serializer.serialize(((Objectable) updatedObject).asPrismObject());
} else {
updatedObjectString = serializer.serializeRealValue(updatedObject);
}
processLanguageSwitch(target, updatedIndex, updatedLanguage, updatedObjectString);
} else {
pageBase.showResult(result);
target.add(pageBase.getFeedbackPanel());
}
} catch (Exception ex) {
result.recordFatalError(createStringResource("DataLanguagePanel.message.onStateChanged.fatalError").getString(), ex);
pageBase.showResult(result);
target.add(this);
target.add(pageBase.getFeedbackPanel());
}
}
use of com.evolveum.midpoint.util.Holder in project midpoint by Evolveum.
the class TestPolicyDrivenRoleLifecycle method test030AttemptToActivateCorrectRoleC34.
/**
* Trying to activate `role-correct` that meets C1-C3 but has no owner (C4).
*/
@Test
public void test030AttemptToActivateCorrectRoleC34() throws Exception {
given();
Task task = getTestTask();
task.setOwner(userAdministrator.asPrismObject());
OperationResult result = task.getResult();
Holder<LensContext<?>> contextHolder = new Holder<>();
when();
then();
activateRoleAssertFailure(ROLE_CORRECT.oid, contextHolder, result, task);
dumpRules(contextHolder);
assertRoleAfter(ROLE_CORRECT.oid).assertPolicySituations(// see rule RE1
SITUATION_INCOMPLETE_ROLE);
}
use of com.evolveum.midpoint.util.Holder in project midpoint by Evolveum.
the class TestPolicyDrivenRoleLifecycle method test020AttemptToActivateIncompleteRoleC234.
/**
* Trying to activate `role-high-risk-empty` that does not meet e.g. C2 (missing description) but others as well.
*/
@Test
public void test020AttemptToActivateIncompleteRoleC234() throws Exception {
given();
Task task = getTestTask();
task.setOwner(userAdministrator.asPrismObject());
OperationResult result = task.getResult();
Holder<LensContext<?>> contextHolder = new Holder<>();
when();
then();
activateRoleAssertFailure(ROLE_HIGH_RISK_EMPTY.oid, contextHolder, result, task);
dumpRules(contextHolder);
assertRoleAfter(ROLE_HIGH_RISK_EMPTY.oid).assertPolicySituations(// see rule RE1
SITUATION_INCOMPLETE_ROLE);
}
use of com.evolveum.midpoint.util.Holder in project midpoint by Evolveum.
the class TestDummy method test110SearchIterative.
@Test
public void test110SearchIterative() throws Exception {
// GIVEN
Task task = getTestTask();
OperationResult result = createOperationResult();
// Make sure there is an account on resource that the provisioning has
// never seen before, so there is no shadow
// for it yet.
DummyAccount newAccount = new DummyAccount("meathook");
newAccount.addAttributeValues(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_FULLNAME_NAME, "Meathook");
newAccount.addAttributeValues(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_SHIP_NAME, "Sea Monkey");
newAccount.addAttributeValues(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_WEAPON_NAME, "hook");
newAccount.addAttributeValue(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_LOOT_NAME, 666);
newAccount.setEnabled(true);
newAccount.setPassword("parrotMonster");
dummyResource.addAccount(newAccount);
ObjectQuery query = ObjectQueryUtil.createResourceAndObjectClassQuery(RESOURCE_DUMMY_OID, new QName(MidPointConstants.NS_RI, SchemaConstants.ACCOUNT_OBJECT_CLASS_LOCAL_NAME), prismContext);
final XMLGregorianCalendar startTs = clock.currentTimeXMLGregorianCalendar();
final Holder<Boolean> seenMeathookHolder = new Holder<>(false);
final List<PrismObject<ShadowType>> foundObjects = new ArrayList<>();
ResultHandler<ShadowType> handler = (object, parentResult) -> {
foundObjects.add(object);
display("Found", object);
XMLGregorianCalendar endTs = clock.currentTimeXMLGregorianCalendar();
assertTrue(object.canRepresent(ShadowType.class));
try {
checkAccountShadow(object, parentResult, true);
} catch (SchemaException e) {
throw new SystemException(e.getMessage(), e);
}
assertCachingMetadata(object, false, startTs, endTs);
if (object.asObjectable().getName().getOrig().equals("meathook")) {
meathookAccountOid = object.getOid();
seenMeathookHolder.setValue(true);
try {
Integer loot = ShadowUtil.getAttributeValue(object, dummyResourceCtl.getAttributeQName(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_LOOT_NAME));
assertNotNull(loot);
assertEquals("Wrong meathook's loot", 666, (int) loot);
} catch (SchemaException e) {
throw new SystemException(e.getMessage(), e);
}
}
return true;
};
rememberCounter(InternalCounters.SHADOW_FETCH_OPERATION_COUNT);
// WHEN
provisioningService.searchObjectsIterative(ShadowType.class, query, null, handler, task, result);
// THEN
XMLGregorianCalendar endTs = clock.currentTimeXMLGregorianCalendar();
assertSuccess(result);
assertCounterIncrement(InternalCounters.SHADOW_FETCH_OPERATION_COUNT, 1);
assertEquals(4, foundObjects.size());
checkUniqueness(foundObjects);
assertProtected(foundObjects, 1);
PrismObject<ShadowType> shadowWillRepo = getShadowRepo(ACCOUNT_WILL_OID);
assertRepoShadowCachedAttributeValue(shadowWillRepo, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_SHIP_NAME, "Flying Dutchman");
checkRepoAccountShadowWill(shadowWillRepo, startTs, endTs);
PrismObject<ShadowType> shadowMeathook = getShadowRepo(meathookAccountOid);
display("Meathook shadow", shadowMeathook);
assertRepoShadowCachedAttributeValue(shadowMeathook, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_WEAPON_NAME, "hook");
assertRepoCachingMetadata(shadowMeathook, startTs, endTs);
// And again ...
foundObjects.clear();
rememberCounter(InternalCounters.SHADOW_FETCH_OPERATION_COUNT);
XMLGregorianCalendar startTs2 = clock.currentTimeXMLGregorianCalendar();
// WHEN
provisioningService.searchObjectsIterative(ShadowType.class, query, null, handler, task, result);
// THEN
XMLGregorianCalendar endTs2 = clock.currentTimeXMLGregorianCalendar();
assertCounterIncrement(InternalCounters.SHADOW_FETCH_OPERATION_COUNT, 1);
display("Found shadows", foundObjects);
assertEquals(4, foundObjects.size());
checkUniqueness(foundObjects);
assertProtected(foundObjects, 1);
PrismObject<ShadowType> shadowWillRepo2 = getShadowRepo(ACCOUNT_WILL_OID);
checkRepoAccountShadowWill(shadowWillRepo2, startTs2, endTs2);
PrismObject<ShadowType> shadowMeathook2 = getShadowRepo(meathookAccountOid);
assertRepoShadowCachedAttributeValue(shadowMeathook2, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_WEAPON_NAME, "hook");
assertRepoCachingMetadata(shadowMeathook2, startTs2, endTs2);
assertSteadyResource();
}
use of com.evolveum.midpoint.util.Holder in project midpoint by Evolveum.
the class TestDummyFoundAgain method test101AddAccountWithoutName.
@Test
public void test101AddAccountWithoutName() throws Exception {
// GIVEN
Task syncTask = getTestTask();
OperationResult result = syncTask.getResult();
syncServiceMock.reset();
List<PrismObject<ConnectorType>> connectors = repositoryService.searchObjects(ConnectorType.class, null, null, result);
assertNotNull(connectors);
// lets take first connector
PrismObject<ConnectorType> toBeFoundAgain = connectors.get(0);
connectorManager.invalidate(ConnectorType.class, toBeFoundAgain.getOid(), null);
repositoryService.deleteObject(ConnectorType.class, toBeFoundAgain.getOid(), result);
Holder<ConnectorType> discovered = new Holder<>();
// Consumer is called after initial inRepo check, we add connector again
// so add should fail.
connectorManager.setNotFoundInRepoConsumer(c -> {
discovered.setValue(c);
try {
repositoryService.addObject(toBeFoundAgain, null, result);
} catch (Exception e) {
throw new RuntimeException(e);
}
});
provisioningService.discoverConnectors(null, result);
assertNotNull(discovered.getValue());
assertEquals(discovered.getValue().getConnectorType(), toBeFoundAgain.asObjectable().getConnectorType());
List<PrismObject<ConnectorType>> connectorsAfter = repositoryService.searchObjects(ConnectorType.class, null, null, result);
assertEquals(connectorsAfter.size(), connectors.size());
}
Aggregations