use of javax.xml.datatype.XMLGregorianCalendar in project midpoint by Evolveum.
the class AbstractObjTemplateSyncTest method assertShadowOperationalData.
protected void assertShadowOperationalData(PrismObject<ShadowType> shadow, SynchronizationSituationType expectedSituation) {
ShadowType shadowType = shadow.asObjectable();
SynchronizationSituationType actualSituation = shadowType.getSynchronizationSituation();
assertEquals("Wrong situation in shadow " + shadow, expectedSituation, actualSituation);
XMLGregorianCalendar actualTimestampCal = shadowType.getSynchronizationTimestamp();
assert actualTimestampCal != null : "No synchronization timestamp in shadow " + shadow;
long actualTimestamp = XmlTypeConverter.toMillis(actualTimestampCal);
assert actualTimestamp >= timeBeforeSync : "Synchronization timestamp was not updated in shadow " + shadow;
// TODO: assert sync description
}
use of javax.xml.datatype.XMLGregorianCalendar in project midpoint by Evolveum.
the class ShadowCache method expirePendingOperations.
private boolean expirePendingOperations(ProvisioningContext ctx, PrismObject<ShadowType> repoShadow, ObjectDelta<ShadowType> shadowDelta, XMLGregorianCalendar now, OperationResult parentResult) throws ObjectNotFoundException, SchemaException, CommunicationException, ConfigurationException, ExpressionEvaluationException {
ShadowType shadowType = repoShadow.asObjectable();
Duration gracePeriod = null;
ResourceConsistencyType consistency = ctx.getResource().getConsistency();
if (consistency != null) {
gracePeriod = consistency.getPendingOperationGracePeriod();
}
boolean atLeastOneOperationRemains = false;
for (PendingOperationType pendingOperation : shadowType.getPendingOperation()) {
ItemPath containerPath = pendingOperation.asPrismContainerValue().getPath();
OperationResultStatusType statusType = pendingOperation.getResultStatus();
XMLGregorianCalendar completionTimestamp = pendingOperation.getCompletionTimestamp();
if (isCompleted(statusType) && isOverGrace(now, gracePeriod, completionTimestamp)) {
LOGGER.trace("Deleting pending operation because it is completed '{}' (and over grace): {}", statusType.value(), pendingOperation);
shadowDelta.addModificationDeleteContainer(new ItemPath(ShadowType.F_PENDING_OPERATION), pendingOperation.clone());
} else {
atLeastOneOperationRemains = true;
}
}
return atLeastOneOperationRemains;
}
use of javax.xml.datatype.XMLGregorianCalendar in project midpoint by Evolveum.
the class ShadowCache method canReturnCached.
private boolean canReturnCached(Collection<SelectorOptions<GetOperationOptions>> options, PrismObject<ShadowType> repositoryShadow, ResourceType resource) throws ConfigurationException {
if (resourceReadIsCachingOnly(resource)) {
return true;
}
PointInTimeType pit = GetOperationOptions.getPointInTimeType(SelectorOptions.findRootOptions(options));
if (pit != null) {
if (pit != PointInTimeType.CACHED) {
return false;
}
}
long stalenessOption = GetOperationOptions.getStaleness(SelectorOptions.findRootOptions(options));
if (stalenessOption == 0L) {
return false;
}
CachingMetadataType cachingMetadata = repositoryShadow.asObjectable().getCachingMetadata();
if (cachingMetadata == null) {
if (stalenessOption == Long.MAX_VALUE) {
// We must return cached version but there is no cached version.
throw new ConfigurationException("Cached version of " + repositoryShadow + " requested, but there is no cached value");
}
return false;
}
if (stalenessOption == Long.MAX_VALUE) {
return true;
}
XMLGregorianCalendar retrievalTimestamp = cachingMetadata.getRetrievalTimestamp();
if (retrievalTimestamp == null) {
return false;
}
long retrievalTimestampMillis = XmlTypeConverter.toMillis(retrievalTimestamp);
return (clock.currentTimeMillis() - retrievalTimestampMillis < stalenessOption);
}
use of javax.xml.datatype.XMLGregorianCalendar in project midpoint by Evolveum.
the class AbstractBasicDummyTest method test103GetAccountNoFetch.
@Test
public void test103GetAccountNoFetch() throws Exception {
final String TEST_NAME = "test103GetAccountNoFetch";
TestUtil.displayTestTile(TEST_NAME);
// GIVEN
OperationResult result = new OperationResult(AbstractBasicDummyTest.class.getName() + "." + TEST_NAME);
rememberShadowFetchOperationCount();
GetOperationOptions rootOptions = new GetOperationOptions();
rootOptions.setNoFetch(true);
Collection<SelectorOptions<GetOperationOptions>> options = SelectorOptions.createCollection(rootOptions);
XMLGregorianCalendar startTs = clock.currentTimeXMLGregorianCalendar();
// WHEN
PrismObject<ShadowType> shadow = provisioningService.getObject(ShadowType.class, ACCOUNT_WILL_OID, options, null, result);
// THEN
XMLGregorianCalendar endTs = clock.currentTimeXMLGregorianCalendar();
result.computeStatus();
display("getObject result", result);
TestUtil.assertSuccess(result);
assertShadowFetchOperationCountIncrement(0);
display("Retrieved account shadow", shadow);
assertNotNull("No dummy account", shadow);
checkAccountShadow(shadow, result, false, startTs, endTs);
// This is noFetch. Therefore the read should NOT update the caching timestamp
checkRepoAccountShadowWill(shadow, null, startTs);
checkConsistency(shadow);
assertSteadyResource();
}
use of javax.xml.datatype.XMLGregorianCalendar in project midpoint by Evolveum.
the class AbstractBasicDummyTest method test106GetModifiedAccount.
/**
* Make a native modification to an account and read it again. Make sure that
* fresh data are returned - even though caching may be in effect.
* MID-3481
*/
@Test
public void test106GetModifiedAccount() throws Exception {
final String TEST_NAME = "test106GetModifiedAccount";
TestUtil.displayTestTile(TEST_NAME);
// GIVEN
OperationResult result = new OperationResult(AbstractBasicDummyTest.class.getName() + "." + TEST_NAME);
rememberShadowFetchOperationCount();
DummyAccount accountWill = getDummyAccountAssert(transformNameFromResource(ACCOUNT_WILL_USERNAME), willIcfUid);
accountWill.replaceAttributeValue(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_TITLE_NAME, "Pirate");
accountWill.replaceAttributeValue(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_SHIP_NAME, "Black Pearl");
accountWill.setEnabled(false);
XMLGregorianCalendar startTs = clock.currentTimeXMLGregorianCalendar();
// WHEN
TestUtil.displayWhen(TEST_NAME);
PrismObject<ShadowType> shadow = provisioningService.getObject(ShadowType.class, ACCOUNT_WILL_OID, null, null, result);
// THEN
TestUtil.displayThen(TEST_NAME);
result.computeStatus();
display("getObject result", result);
TestUtil.assertSuccess(result);
assertShadowFetchOperationCountIncrement(1);
XMLGregorianCalendar endTs = clock.currentTimeXMLGregorianCalendar();
display("Retrieved account shadow", shadow);
assertNotNull("No dummy account", shadow);
assertAttribute(shadow, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_TITLE_NAME, "Pirate");
assertAttribute(shadow, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_SHIP_NAME, "Black Pearl");
assertAttribute(shadow, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_WEAPON_NAME, "Sword", "LOVE");
assertAttribute(shadow, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_LOOT_NAME, 42);
Collection<ResourceAttribute<?>> attributes = ShadowUtil.getAttributes(shadow);
assertEquals("Unexpected number of attributes", 7, attributes.size());
PrismObject<ShadowType> shadowRepo = repositoryService.getObject(ShadowType.class, ACCOUNT_WILL_OID, null, result);
checkRepoAccountShadowWillBasic(shadowRepo, startTs, endTs, null);
assertRepoShadowCachedAttributeValue(shadowRepo, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_TITLE_NAME, "Pirate");
assertRepoShadowCachedAttributeValue(shadowRepo, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_SHIP_NAME, "Black Pearl");
assertRepoShadowCachedAttributeValue(shadowRepo, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_WEAPON_NAME, "sword", "love");
assertRepoShadowCachedAttributeValue(shadowRepo, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_LOOT_NAME, 42);
assertRepoShadowCacheActivation(shadowRepo, ActivationStatusType.DISABLED);
checkConsistency(shadow);
assertCachingMetadata(shadow, false, startTs, endTs);
assertSteadyResource();
}
Aggregations