use of com.evolveum.midpoint.util.Holder in project midpoint by Evolveum.
the class MidpointFunctionsImpl method isUniqueAccountValue.
private <T> boolean isUniqueAccountValue(ResourceType resourceType, final ShadowType shadowType, QName attributeName, T attributeValue, Task task, OperationResult result) throws SchemaException, ObjectNotFoundException, CommunicationException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException {
Validate.notNull(resourceType, "Null resource");
Validate.notNull(shadowType, "Null shadow");
Validate.notNull(attributeName, "Null attribute name");
Validate.notNull(attributeValue, "Null attribute value");
ObjectQuery query = createAttributeQuery(resourceType, attributeName, attributeValue);
LOGGER.trace("Determining uniqueness of attribute {} using query:\n{}", attributeName, query.debugDumpLazily());
final Holder<Boolean> isUniqueHolder = new Holder<>(true);
ResultHandler<ShadowType> handler = (object, parentResult) -> {
if (shadowType.getOid() == null) {
// We have found a conflicting object
isUniqueHolder.setValue(false);
return false;
} else {
if (shadowType.getOid().equals(object.getOid())) {
// We have found ourselves. No conflict (yet). Just go on.
return true;
} else {
// We have found someone else. Conflict.
isUniqueHolder.setValue(false);
return false;
}
}
};
modelObjectResolver.searchIterative(ShadowType.class, query, createReadOnlyCollection(), handler, task, result);
return isUniqueHolder.getValue();
}
use of com.evolveum.midpoint.util.Holder in project midpoint by Evolveum.
the class ProjectionsLoadOperation method getOrCreateContextForValueToAdd.
private void getOrCreateContextForValueToAdd(PrismReferenceValue refVal, OperationResult result) throws SchemaException, ObjectNotFoundException, CommunicationException, ConfigurationException, ExpressionEvaluationException, SecurityViolationException, PolicyViolationException {
String oid = refVal.getOid();
LensProjectionContext projectionContext;
Holder<Boolean> objectDoesExistInRepoHolder = new Holder<>(false);
if (oid == null) {
projectionContext = getOrCreateContextForValueToAddNoOid(refVal, result);
} else {
projectionContext = getOrCreateProjectionForValueToAddWithOid(refVal, objectDoesExistInRepoHolder, result);
}
if (context.isDoReconciliationForAllProjections() && objectDoesExistInRepoHolder.getValue()) {
projectionContext.setDoReconciliation(true);
}
projectionContext.setFresh(true);
}
use of com.evolveum.midpoint.util.Holder in project midpoint by Evolveum.
the class TestConnectorMultiInstance method test125ReadJackDummyYellowTwoBlocking.
/**
* Block two read operations. Make sure that new connector instance is created.
*/
@Test
public void test125ReadJackDummyYellowTwoBlocking() throws Exception {
dummyResourceYellow.setBlockOperations(true);
final Holder<PrismObject<ShadowType>> shadowHolder1 = new Holder<>();
final Holder<PrismObject<ShadowType>> shadowHolder2 = new Holder<>();
// WHEN
Thread t1 = executeInNewThread("get1", () -> {
PrismObject<ShadowType> shadow = getShadowModel(accountJackYellowOid);
logger.trace("Got shadow {}", shadow);
shadowHolder1.setValue(shadow);
});
Thread t2 = executeInNewThread("get2", new FailableRunnable() {
@Override
public void run() throws Exception {
PrismObject<ShadowType> shadow = getShadowModel(accountJackYellowOid);
logger.trace("Got shadow {}", shadow);
shadowHolder2.setValue(shadow);
}
});
// Give the new threads a chance to get blocked
Thread.sleep(500);
assertConnectorInstances("yellow (blocked)", RESOURCE_DUMMY_YELLOW_OID, 2, 0);
assertNull("Unexpected shadow 1", shadowHolder1.getValue());
assertNull("Unexpected shadow 2", shadowHolder2.getValue());
dummyResourceYellow.unblockAll();
t1.join();
t2.join();
// THEN
dummyResourceYellow.setBlockOperations(false);
PrismObject<ShadowType> shadowYellow1 = shadowHolder1.getValue();
assertNotNull("No shadow 1", shadowHolder1.getValue());
display("Shadow yellow 1", shadowYellow1);
PrismObject<ShadowType> shadowYellow2 = shadowHolder2.getValue();
assertNotNull("No shadow 2", shadowHolder2.getValue());
display("Shadow yellow 2", shadowYellow2);
assertConnectorInstances("yellow", RESOURCE_DUMMY_YELLOW_OID, 0, 2);
assertConnectorToStringDifferent(shadowYellow2, dummyResourceCtlYellow, getConnectorToString(shadowYellow1, dummyResourceCtlYellow));
assertConnectorStaticVal(shadowYellow1, dummyResourceCtlYellow, initialConnectorStaticVal);
assertConnectorStaticVal(shadowYellow2, dummyResourceCtlYellow, initialConnectorStaticVal);
assertDummyAccount(RESOURCE_DUMMY_YELLOW_NAME, ACCOUNT_JACK_DUMMY_USERNAME, ACCOUNT_JACK_DUMMY_FULLNAME, true);
}
use of com.evolveum.midpoint.util.Holder in project midpoint by Evolveum.
the class AbstractSecurityTest method dropPowerOfAttorneyAllow.
protected MidPointPrincipal dropPowerOfAttorneyAllow() throws Exception {
Holder<MidPointPrincipal> principalHolder = new Holder<>();
assertAllow("assumePowerOfAttorney", (task, result) -> {
MidPointPrincipal attorneyPrincipal = modelInteractionService.dropPowerOfAttorney(task, result);
principalHolder.setValue(attorneyPrincipal);
});
return principalHolder.getValue();
}
use of com.evolveum.midpoint.util.Holder in project midpoint by Evolveum.
the class ConnectorInstanceConnIdImpl method count.
@Override
public int count(ResourceObjectDefinition objectDefinition, final ObjectQuery query, PagedSearchCapabilityType pagedSearchCapabilityType, UcfExecutionContext ctx, OperationResult parentResult) throws CommunicationException, GenericFrameworkException, SchemaException, UnsupportedOperationException {
// Result type for this operation
final OperationResult result = parentResult.createSubresult(ConnectorInstance.class.getName() + ".count");
result.addArbitraryObjectAsParam("objectClass", objectDefinition);
result.addContext("connector", connectorType);
if (objectDefinition == null) {
result.recordFatalError("Object class not defined");
throw new IllegalArgumentException("objectClass not defined");
}
ObjectClass icfObjectClass = objectClassToConnId(objectDefinition);
final boolean useConnectorPaging = pagedSearchCapabilityType != null;
if (!useConnectorPaging) {
throw new UnsupportedOperationException("ConnectorInstanceIcfImpl.count operation is supported only in combination with connector-implemented paging");
}
OperationOptionsBuilder optionsBuilder = new OperationOptionsBuilder();
optionsBuilder.setAttributesToGet(Name.NAME);
optionsBuilder.setPagedResultsOffset(1);
optionsBuilder.setPageSize(1);
if (pagedSearchCapabilityType.getDefaultSortField() != null) {
String orderByIcfName = connIdNameMapper.convertAttributeNameToConnId(pagedSearchCapabilityType.getDefaultSortField(), objectDefinition, "(default sorting field)");
boolean isAscending = pagedSearchCapabilityType.getDefaultSortDirection() != OrderDirectionType.DESCENDING;
optionsBuilder.setSortKeys(new SortKey(orderByIcfName, isAscending));
}
OperationOptions options = optionsBuilder.build();
// Connector operation cannot create result for itself, so we need to
// create result for it
OperationResult icfResult = result.createSubresult(ConnectorFacade.class.getName() + ".search");
icfResult.addArbitraryObjectAsParam("objectClass", icfObjectClass);
icfResult.addContext("connector", connIdConnectorFacade.getClass());
int retval;
InternalMonitor.recordConnectorOperation("search");
ConnIdOperation operation = recordIcfOperationStart(ctx, ProvisioningOperation.ICF_SEARCH, objectDefinition);
try {
Filter filter = convertFilterToIcf(query, objectDefinition);
final Holder<Integer> fetched = new Holder<>(0);
ResultsHandler connIdHandler = new ResultsHandler() {
@Override
public boolean handle(ConnectorObject connectorObject) {
// actually, this should execute at most once
fetched.setValue(fetched.getValue() + 1);
return false;
}
@Override
public String toString() {
return "(midPoint counting result handler)";
}
};
LOGGER.trace("Invoking ConnId search operation (to count objects): {}", operation);
SearchResult searchResult = connIdConnectorFacade.search(icfObjectClass, filter, connIdHandler, options);
recordIcfOperationEnd(ctx, operation, null);
if (searchResult == null || searchResult.getRemainingPagedResults() == -1) {
throw new UnsupportedOperationException("Connector does not seem to support paged searches or does not provide object count information");
} else {
retval = fetched.getValue() + searchResult.getRemainingPagedResults();
}
icfResult.recordSuccess();
} catch (IntermediateException inex) {
recordIcfOperationEnd(ctx, operation, inex);
SchemaException ex = (SchemaException) inex.getCause();
icfResult.recordFatalError(ex);
result.recordFatalError(ex);
throw ex;
} catch (UnsupportedOperationException uoe) {
recordIcfOperationEnd(ctx, operation, uoe);
icfResult.recordFatalError(uoe);
result.recordFatalError(uoe);
throw uoe;
} catch (Throwable ex) {
recordIcfOperationEnd(ctx, operation, ex);
Throwable midpointEx = processConnIdException(ex, this, icfResult);
result.computeStatus();
// exception
if (midpointEx instanceof CommunicationException) {
throw (CommunicationException) midpointEx;
} else if (midpointEx instanceof GenericFrameworkException) {
throw (GenericFrameworkException) midpointEx;
} else if (midpointEx instanceof SchemaException) {
throw (SchemaException) midpointEx;
} else if (midpointEx instanceof RuntimeException) {
throw (RuntimeException) midpointEx;
} else if (midpointEx instanceof Error) {
throw (Error) midpointEx;
} else {
throw new SystemException("Got unexpected exception: " + ex.getClass().getName() + ": " + ex.getMessage(), ex);
}
}
if (result.isUnknown()) {
result.recordSuccess();
}
return retval;
}
Aggregations