use of com.evolveum.midpoint.util.exception.CommunicationException in project midpoint by Evolveum.
the class ResourceObjectReferenceResolver method fetchResourceObject.
PrismObject<ShadowType> fetchResourceObject(ProvisioningContext ctx, Collection<? extends ResourceAttribute<?>> identifiers, AttributesToReturn attributesToReturn, @Nullable PrismObject<ShadowType> repoShadow, OperationResult parentResult) throws ObjectNotFoundException, CommunicationException, SchemaException, SecurityViolationException, ConfigurationException, ExpressionEvaluationException {
ConnectorInstance connector = ctx.getConnector(ReadCapabilityType.class, parentResult);
ResourceObjectDefinition objectDefinition = ctx.getObjectDefinitionRequired();
try {
ReadCapabilityType readCapability = ctx.getEffectiveCapability(ReadCapabilityType.class);
if (readCapability == null) {
throw new UnsupportedOperationException("Resource does not support 'read' operation: " + ctx.toHumanReadableDescription());
}
if (Boolean.TRUE.equals(readCapability.isCachingOnly())) {
return repoShadow;
}
ResourceObjectIdentification identification = ResourceObjectIdentification.create(objectDefinition, identifiers);
ResourceObjectIdentification resolvedIdentification = resolvePrimaryIdentifiers(ctx, identification, parentResult);
resolvedIdentification.validatePrimaryIdentifiers();
return connector.fetchObject(resolvedIdentification, attributesToReturn, ctx.getUcfExecutionContext(), parentResult);
} catch (ObjectNotFoundException e) {
// Not finishing the result because we did not create it! (The same for other catch clauses.)
parentResult.recordFatalErrorNotFinish("Object not found. Identifiers: " + identifiers + ". Reason: " + e.getMessage(), e);
throw new ObjectNotFoundException("Object not found. identifiers=" + identifiers + ", objectclass=" + PrettyPrinter.prettyPrint(objectDefinition.getTypeName()) + ": " + e.getMessage(), e, repoShadow != null ? repoShadow.getOid() : null);
} catch (CommunicationException e) {
parentResult.recordFatalErrorNotFinish("Error communication with the connector " + connector + ": " + e.getMessage(), e);
throw e;
} catch (GenericFrameworkException e) {
parentResult.recordFatalErrorNotFinish("Generic error in the connector " + connector + ". Reason: " + e.getMessage(), e);
throw new GenericConnectorException("Generic error in the connector " + connector + ". Reason: " + e.getMessage(), e);
} catch (SchemaException ex) {
parentResult.recordFatalErrorNotFinish("Can't get resource object, schema error: " + ex.getMessage(), ex);
throw ex;
} catch (ExpressionEvaluationException ex) {
parentResult.recordFatalErrorNotFinish("Can't get resource object, expression error: " + ex.getMessage(), ex);
throw ex;
} catch (ConfigurationException e) {
parentResult.recordFatalErrorNotFinish(e);
throw e;
}
}
use of com.evolveum.midpoint.util.exception.CommunicationException in project midpoint by Evolveum.
the class TestUcfDummyMulti method test210TwoBlockingSearches.
@Test
public void test210TwoBlockingSearches() throws Exception {
// GIVEN
UcfExecutionContext ctx = createExecutionContext();
final ResourceObjectClassDefinition accountDefinition = resourceSchema.findObjectClassDefinitionRequired(ACCOUNT_OBJECT_CLASS_NAME);
// Determine object class from the schema
OperationResult result1 = createOperationResult();
final List<PrismObject<ShadowType>> searchResults1 = new ArrayList<>();
final ObjectHandler handler1 = (ucfObject, result) -> {
checkUcfShadow(ucfObject.getResourceObject(), accountDefinition);
searchResults1.add(ucfObject.getResourceObject());
return true;
};
OperationResult result2 = createOperationResult();
final List<PrismObject<ShadowType>> searchResults2 = new ArrayList<>();
final ObjectHandler handler2 = (ucfObject, result) -> {
checkUcfShadow(ucfObject.getResourceObject(), accountDefinition);
searchResults2.add(ucfObject.getResourceObject());
return true;
};
dummyResource.setBlockOperations(true);
// WHEN
Thread t1 = new Thread(() -> {
try {
cc.search(accountDefinition, null, handler1, null, null, null, null, ctx, result1);
} catch (CommunicationException | GenericFrameworkException | SchemaException | SecurityViolationException | ObjectNotFoundException e) {
logger.error("Error in the search: {}", e.getMessage(), e);
}
});
t1.setName("search1");
t1.start();
// Give the new thread a chance to get blocked
Thread.sleep(500);
ConnectorOperationalStatus opStat = cc.getOperationalStatus();
displayDumpable("stats (blocked 1)", opStat);
assertEquals("Wrong pool active", (Integer) 1, opStat.getPoolStatusNumActive());
assertEquals("Wrong pool active", (Integer) 0, opStat.getPoolStatusNumIdle());
assertEquals("Unexpected number of search results", 0, searchResults1.size());
Thread t2 = new Thread(() -> {
try {
cc.search(accountDefinition, null, handler2, null, null, null, null, ctx, result2);
} catch (CommunicationException | GenericFrameworkException | SchemaException | SecurityViolationException | ObjectNotFoundException e) {
logger.error("Error in the search: {}", e.getMessage(), e);
}
});
t2.setName("search2");
t2.start();
// Give the new thread a chance to get blocked
Thread.sleep(500);
opStat = cc.getOperationalStatus();
displayDumpable("stats (blocked 2)", opStat);
assertEquals("Wrong pool active", (Integer) 2, opStat.getPoolStatusNumActive());
assertEquals("Wrong pool active", (Integer) 0, opStat.getPoolStatusNumIdle());
assertEquals("Unexpected number of search results", 0, searchResults1.size());
dummyResource.unblockAll();
t1.join();
t2.join();
dummyResource.setBlockOperations(false);
// THEN
assertEquals("Unexpected number of search results 1", 1, searchResults1.size());
assertEquals("Unexpected number of search results 2", 1, searchResults2.size());
opStat = cc.getOperationalStatus();
displayDumpable("stats (final)", opStat);
assertEquals("Wrong pool active", (Integer) 0, opStat.getPoolStatusNumActive());
assertEquals("Wrong pool active", (Integer) 2, opStat.getPoolStatusNumIdle());
PrismObject<ShadowType> searchResult1 = searchResults1.get(0);
displayDumpable("Search result 1", searchResult1);
PrismObject<ShadowType> searchResult2 = searchResults2.get(0);
displayDumpable("Search result 2", searchResult2);
}
use of com.evolveum.midpoint.util.exception.CommunicationException in project midpoint by Evolveum.
the class ExpressionValidator method validate.
@Override
public void validate(IValidatable<T> validatable) {
ExpressionType expressionType = expressionTypeModel.getObject();
if (expressionType == null) {
return;
}
PrismContext prismContext = serviceLocator.getPrismContext();
Object valueToValidate = getValueToValidate(validatable);
String contextDesc = " form component expression validation ";
PrismPropertyDefinition<OperationResultType> outputDefinition = prismContext.definitionFactory().createPropertyDefinition(ExpressionConstants.OUTPUT_ELEMENT_NAME, OperationResultType.COMPLEX_TYPE);
Task task = serviceLocator.createSimpleTask(OPERATION_EVALUATE_EXPRESSION);
OperationResult result = new OperationResult(OPERATION_EVALUATE_EXPRESSION);
ExpressionFactory expressionFactory = serviceLocator.getExpressionFactory();
Expression<PrismPropertyValue<OperationResultType>, PrismPropertyDefinition<OperationResultType>> expression;
try {
expression = expressionFactory.makeExpression(expressionType, outputDefinition, MiscSchemaUtil.getExpressionProfile(), contextDesc, task, result);
} catch (SchemaException | ObjectNotFoundException | SecurityViolationException e) {
ValidationError error = new ValidationError();
error.setMessage("Cannot make expression: " + e.getMessage());
validatable.error(error);
return;
}
VariablesMap variables = new VariablesMap();
Class typeClass = (valueToValidate == null ? String.class : valueToValidate.getClass());
variables.put(ExpressionConstants.VAR_INPUT, valueToValidate, typeClass);
variables.putObject(ExpressionConstants.VAR_OBJECT, (ObjectType) getObjectType(), ObjectType.class);
ExpressionEvaluationContext context = new ExpressionEvaluationContext(null, variables, contextDesc, task);
PrismValueDeltaSetTriple<PrismPropertyValue<OperationResultType>> outputTriple;
try {
outputTriple = expression.evaluate(context, result);
} catch (SchemaException | ExpressionEvaluationException | ObjectNotFoundException | CommunicationException | ConfigurationException | SecurityViolationException e) {
ValidationError error = new ValidationError();
error.setMessage("Cannot evaluate expression: " + e.getMessage());
validatable.error(error);
return;
}
if (outputTriple == null) {
return;
}
Collection<PrismPropertyValue<OperationResultType>> outputValues = outputTriple.getNonNegativeValues();
if (outputValues.isEmpty()) {
return;
}
if (outputValues.size() > 1) {
ValidationError error = new ValidationError();
error.setMessage("Expression " + contextDesc + " produced more than one value");
validatable.error(error);
}
OperationResultType operationResultType = outputValues.iterator().next().getRealValue();
if (operationResultType == null) {
return;
}
OperationResult returnResult = OperationResult.createOperationResult(operationResultType);
if (!returnResult.isSuccess()) {
ValidationError error = new ValidationError();
if (returnResult.getUserFriendlyMessage() != null) {
error.setMessage(WebModelServiceUtils.translateMessage(returnResult, serviceLocator));
} else {
error.setMessage(returnResult.getMessage());
}
validatable.error(error);
}
}
use of com.evolveum.midpoint.util.exception.CommunicationException in project midpoint by Evolveum.
the class ResourceConnectorPanel method initLayout.
private void initLayout() {
setOutputMarkupId(true);
IModel<List<ConnectorOperationalStatus>> statsModel = new IModel<>() {
private static final long serialVersionUID = 1L;
@Override
public List<ConnectorOperationalStatus> getObject() {
Task task = getPageBase().createSimpleTask(OPERATION_GET_CONNECTOR_OPERATIONAL_STATUS);
OperationResult result = task.getResult();
List<ConnectorOperationalStatus> status = null;
try {
status = getPageBase().getModelInteractionService().getConnectorOperationalStatus(getModelObject().getOid(), task, result);
} catch (SchemaException | ObjectNotFoundException | CommunicationException | ConfigurationException | ExpressionEvaluationException e) {
LOGGER.error("Error getting connector status for {}: {}", getModelObject(), e.getMessage(), e);
getPageBase().showResult(result);
}
return status;
}
};
ListView<ConnectorOperationalStatus> listview = new ListView<ConnectorOperationalStatus>(ID_CONNECTOR_LIST, statsModel) {
private static final long serialVersionUID = 1L;
protected void populateItem(ListItem<ConnectorOperationalStatus> item) {
item.add(new Label("label", item.getModel()));
IModel<ConnectorOperationalStatus> statModel = item.getModel();
item.add(createLabel(statModel, ID_CONNECTOR_NAME, ConnectorOperationalStatus.F_CONNECTOR_NAME));
item.add(createLabel(statModel, ID_CONNECOTR_CLASS, ConnectorOperationalStatus.F_CONNECTOR_CLASS_NAME));
item.add(createLabel(statModel, ID_POOL_CONFIG_MIN_SIZE, ConnectorOperationalStatus.F_POOL_CONFIG_MIN_SIZE));
item.add(createLabel(statModel, ID_POOL_CONFIG_MAX_SIZE, ConnectorOperationalStatus.F_POOL_CONFIG_MAX_SIZE));
item.add(createLabel(statModel, ID_POOL_CONFIG_MIN_IDLE, ConnectorOperationalStatus.F_POOL_CONFIG_MIN_IDLE));
item.add(createLabel(statModel, ID_POOL_CONFIG_MAX_IDLE, ConnectorOperationalStatus.F_POOL_CONFIG_MAX_IDLE));
item.add(createLabel(statModel, ID_POOL_CONFIG_WAIT_TIMEOUT, ConnectorOperationalStatus.F_POOL_CONFIG_WAIT_TIMEOUT));
item.add(createLabel(statModel, ID_POOL_CONFIG_MIN_EVICTABLE_IDLE_TIME, ConnectorOperationalStatus.F_POOL_CONFIG_MIN_EVICTABLE_IDLE_TIME));
item.add(createLabel(statModel, ID_POOL_STATUS_NUM_IDLE, ConnectorOperationalStatus.F_POOL_STATUS_NUM_IDLE));
item.add(createLabel(statModel, ID_POOL_STATUS_NUM_ACTIVE, ConnectorOperationalStatus.F_POOL_STATUS_NUM_ACTIVE));
}
};
add(listview);
}
use of com.evolveum.midpoint.util.exception.CommunicationException in project midpoint by Evolveum.
the class ValuePolicyProcessor method testProhibitedValues.
private StringLimitationResult testProhibitedValues(String newPassword, ProhibitedValuesType prohibitedValuesType, ObjectBasedValuePolicyOriginResolver<?> originResolver, String shortDesc, Task task, OperationResult result, List<LocalizableMessage> messages) throws SchemaException, ObjectNotFoundException, ExpressionEvaluationException, CommunicationException, ConfigurationException, SecurityViolationException {
if (prohibitedValuesType == null || originResolver == null) {
return null;
}
StringLimitationResult limitation = new StringLimitationResult();
PolyStringType name = new PolyStringType("prohibited value");
PolyStringTranslationType translation = new PolyStringTranslationType();
translation.setKey("ValuePolicy.prohibitedValueName");
name.setTranslation(translation);
limitation.setName(name);
PolyStringType help = new PolyStringType("");
PolyStringTranslationType helpTranslation = new PolyStringTranslationType();
helpTranslation.setKey("ValuePolicy.prohibitedValue");
help.setTranslation(helpTranslation);
limitation.setHelp(help);
limitation.setSuccess(true);
Consumer<ProhibitedValueItemType> failAction = (prohibitedItemType) -> {
LocalizableMessage msg = new LocalizableMessageBuilder().key("ValuePolicy.prohibitedValue").build();
result.addSubresult(new OperationResult("Prohibited value", OperationResultStatus.FATAL_ERROR, msg));
messages.add(msg);
limitation.setSuccess(false);
};
checkProhibitedValues(newPassword, prohibitedValuesType, originResolver, failAction, shortDesc, task, result);
return limitation;
}
Aggregations