use of com.evolveum.midpoint.util.annotation.Experimental in project midpoint by Evolveum.
the class LinkedObjectsFunctions method createLinkedSource.
// todo clean up!
@Experimental
public <T extends AssignmentHolderType> T createLinkedSource(String linkTypeName) throws SchemaException, ConfigurationException {
OperationResult currentResult = midpointFunctions.getCurrentResult();
LensFocusContext<?> focusContext = (LensFocusContext<?>) midpointFunctions.getFocusContext();
if (focusContext == null) {
throw new IllegalStateException("No focus context");
}
LinkTypeDefinitionType definition = focusContext.getSourceLinkTypeDefinition(linkTypeName, linkManager, currentResult);
if (definition == null) {
throw new IllegalStateException("No definition for source link type " + linkTypeName + " for " + focusContext);
}
LinkedObjectSelectorType selector = definition.getSelector();
if (selector == null) {
throw new IllegalStateException("Couldn't create new linked source object without a selector");
}
if (selector.getType() == null) {
throw new IllegalStateException("Couldn't create new linked source object without explicit type in the selector");
}
SchemaRegistry schemaRegistry = prismContext.getSchemaRegistry();
Class<?> objectClass = schemaRegistry.getCompileTimeClassForObjectType(selector.getType());
if (objectClass == null) {
throw new IllegalStateException("No object class for type " + selector.getType());
}
if (Modifier.isAbstract(objectClass.getModifiers())) {
throw new IllegalStateException("Class " + objectClass + " cannot be instantiated because it is abstract");
}
T newObject;
try {
// noinspection unchecked
newObject = (T) objectClass.getConstructor(PrismContext.class).newInstance(prismContext);
} catch (InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
throw new SystemException("Couldn't instantiate " + objectClass);
}
newObject.beginAssignment().targetRef(focusContext.getOid(), schemaRegistry.determineTypeForClassRequired(focusContext.getObjectTypeClass()));
ObjectReferenceType archetypeRef = MiscUtil.extractSingleton(selector.getArchetypeRef(), () -> new IllegalStateException("Couldn't instantiate object from selector with multiple archetypes"));
if (archetypeRef != null) {
newObject.beginAssignment().targetRef(archetypeRef.clone());
}
// TODO other things from the selector
return newObject;
}
use of com.evolveum.midpoint.util.annotation.Experimental in project midpoint by Evolveum.
the class LinkedObjectsFunctions method findLinkedTargets.
// Should be used after assignment evaluation!
@Experimental
@NotNull
<T extends AssignmentHolderType> List<T> findLinkedTargets(String linkTypeName) throws CommunicationException, ObjectNotFoundException, SchemaException, SecurityViolationException, ConfigurationException, ExpressionEvaluationException {
OperationResult currentResult = midpointFunctions.getCurrentResult();
LensFocusContext<?> focusContext = (LensFocusContext<?>) midpointFunctions.getFocusContext();
if (focusContext == null) {
throw new IllegalStateException("No focus context");
}
LinkTypeDefinitionType definition = focusContext.getTargetLinkTypeDefinition(linkTypeName, linkManager, currentResult);
if (definition == null) {
throw new IllegalStateException("No definition for target link type " + linkTypeName + " for " + focusContext);
}
Class<?> expectedClasses = getExpectedClass(definition.getSelector());
Set<PrismReferenceValue> membership = getMembership();
List<PrismReferenceValue> assignedWithMatchingRelation = membership.stream().filter(ref -> relationMatches(ref, definition.getSelector()) && objectTypeMatches(ref, expectedClasses)).collect(Collectors.toList());
// TODO deduplicate w.r.t. member/manager
// TODO optimize matching
List<T> objects = new ArrayList<>(assignedWithMatchingRelation.size());
for (PrismReferenceValue reference : assignedWithMatchingRelation) {
ObjectReferenceType ort = new ObjectReferenceType();
ort.setupReferenceValue(reference);
T object = midpointFunctions.resolveReferenceInternal(ort, true);
if (objectMatches(object, definition.getSelector())) {
objects.add(object);
}
}
return objects;
}
use of com.evolveum.midpoint.util.annotation.Experimental in project midpoint by Evolveum.
the class AbstractModelIntegrationTest method waitForTaskProgress.
@Experimental
protected Task waitForTaskProgress(String taskOid, long progressToReach, CheckedProducer<Boolean> extraTest, int timeout, int sleepTime, OperationResult waitResult) throws Exception {
Checker checker = new Checker() {
@Override
public boolean check() throws CommonException {
Task freshRepoTask = taskManager.getTaskWithResult(taskOid, waitResult);
displaySingleTask("Repo task while waiting for progress reach " + progressToReach, freshRepoTask);
Long heartbeat = activityBasedTaskHandler.heartbeat(freshRepoTask);
if (heartbeat != null) {
displayValue("Heartbeat", heartbeat);
}
long progress = heartbeat != null ? heartbeat : freshRepoTask.getLegacyProgress();
boolean extraTestSuccess = extraTest != null && Boolean.TRUE.equals(extraTest.get());
return extraTestSuccess || freshRepoTask.getExecutionState() == TaskExecutionStateType.SUSPENDED || freshRepoTask.getExecutionState() == TaskExecutionStateType.CLOSED || progress >= progressToReach;
}
@Override
public void timeout() {
try {
Task freshTask = taskManager.getTaskWithResult(taskOid, waitResult);
OperationResult result = freshTask.getResult();
logger.debug("Timed-out task:\n{}", freshTask.debugDump());
assert false : "Timeout (" + timeout + ") while waiting for " + freshTask + " progress. Last result " + result;
} catch (ObjectNotFoundException | SchemaException e) {
logger.error("Exception during task refresh: {}", e, e);
}
}
};
IntegrationTestTools.waitFor("Waiting for task " + taskOid + " progress reaching " + progressToReach, checker, timeout, sleepTime);
Task freshTask = taskManager.getTaskWithResult(taskOid, waitResult);
logger.debug("Final task:\n{}", freshTask.debugDump());
return freshTask;
}
use of com.evolveum.midpoint.util.annotation.Experimental in project midpoint by Evolveum.
the class ActivityItemProcessingStatistics method updateStatisticsForSimpleClients.
/**
* Very ugly hack. We create our own operation result (!!).
*/
@Experimental
private void updateStatisticsForSimpleClients() {
try {
activityState.updateProgressAndStatisticsNoCommit();
if (System.currentTimeMillis() > lastStatisticsUpdatedForSimpleClients + STATISTICS_UPDATE_INTERVAL) {
lastStatisticsUpdatedForSimpleClients = System.currentTimeMillis();
activityState.flushPendingTaskModificationsChecked(new OperationResult(OP_UPDATE_STATISTICS_FOR_SIMPLE_CLIENT));
}
} catch (ActivityRunException e) {
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't update statistics for a simple client in {}", e, this);
}
}
use of com.evolveum.midpoint.util.annotation.Experimental in project midpoint by Evolveum.
the class UcfChangeUtil method createFromAsyncProvisioningRequest.
/**
* Creates {@link UcfChangeType} from {@link JsonAsyncProvisioningRequest}. Assumes standard change representation.
* (I.e. not storing replaced values in attributes map.)
*/
@Experimental
public static UcfChangeType createFromAsyncProvisioningRequest(JsonAsyncProvisioningRequest request, String defaultNamespace, PrismContext prismContext) throws SchemaException {
String operation = request.getOperation();
QName objectClass = uriToQName(request.getObjectClass(), defaultNamespace);
if (request.isAdd()) {
return UcfChangeUtil.createForNewObject(objectClass, getAttributes(request, defaultNamespace), prismContext);
} else if (request.isModify()) {
return UcfChangeUtil.create(objectClass, getIdentifiers(request, defaultNamespace), createModifyDelta(request, defaultNamespace, prismContext), prismContext);
} else if (request.isDelete()) {
return UcfChangeUtil.create(objectClass, getIdentifiers(request, defaultNamespace), createDeleteDelta(), prismContext);
} else {
throw new IllegalArgumentException("Unsupported operation: " + request.getOperation());
}
}
Aggregations