Skip to content

Commit

Permalink
Merge branch 'feature/simulations' of github.com:Evolveum/midpoint in…
Browse files Browse the repository at this point in the history
…to feature/simulations
  • Loading branch information
1azyman committed Nov 10, 2022
2 parents 593a179 + b7d9c55 commit 9c0b32a
Show file tree
Hide file tree
Showing 37 changed files with 333 additions and 363 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import java.util.stream.Collectors;
import javax.xml.namespace.QName;

import com.evolveum.midpoint.provisioning.api.Resource;
import com.evolveum.midpoint.schema.util.Resource;

import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright (C) 2010-2022 Evolveum and contributors
*
* This work is dual-licensed under the Apache License 2.0
* and European Union Public License. See LICENSE file for details.
*/

package com.evolveum.midpoint.schema.util;

import com.evolveum.midpoint.xml.ns._public.common.common_3.PendingOperationExecutionStatusType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.PendingOperationType;

import com.evolveum.prism.xml.ns._public.types_3.ChangeTypeType;
import com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType;

import org.jetbrains.annotations.NotNull;

import static com.evolveum.midpoint.xml.ns._public.common.common_3.PendingOperationExecutionStatusType.EXECUTING;
import static com.evolveum.midpoint.xml.ns._public.common.common_3.PendingOperationExecutionStatusType.EXECUTION_PENDING;

public class PendingOperationTypeUtil {

public static boolean isAdd(@NotNull PendingOperationType operation) {
ObjectDeltaType delta = operation.getDelta();
return delta != null && delta.getChangeType() == ChangeTypeType.ADD;
}

public static boolean isPendingOrExecuting(PendingOperationType operation) {
PendingOperationExecutionStatusType status = operation.getExecutionStatus();
return status == EXECUTION_PENDING || status == EXECUTING;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,18 @@
* and European Union Public License. See LICENSE file for details.
*/

package com.evolveum.midpoint.provisioning.api;
package com.evolveum.midpoint.schema.util;

import com.evolveum.midpoint.prism.*;
import com.evolveum.midpoint.prism.path.ItemName;
import com.evolveum.midpoint.prism.path.ItemPath;
import com.evolveum.midpoint.prism.query.ObjectQuery;
import com.evolveum.midpoint.prism.query.builder.QueryItemDefinitionResolver;
import com.evolveum.midpoint.prism.query.builder.S_FilterExit;
import com.evolveum.midpoint.prism.query.builder.S_MatchingRuleEntry;
import com.evolveum.midpoint.schema.constants.SchemaConstants;
import com.evolveum.midpoint.schema.processor.*;
import com.evolveum.midpoint.schema.processor.ResourceObjectDefinition;
import com.evolveum.midpoint.schema.processor.ResourceObjectTypeDefinition;
import com.evolveum.midpoint.schema.processor.ResourceSchema;
import com.evolveum.midpoint.schema.processor.ResourceSchemaFactory;
import com.evolveum.midpoint.util.annotation.Experimental;
import com.evolveum.midpoint.util.exception.ConfigurationException;
import com.evolveum.midpoint.util.exception.SchemaException;
Expand All @@ -27,7 +28,6 @@

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.VisibleForTesting;

import javax.xml.namespace.QName;
import java.util.Collection;
Expand All @@ -36,6 +36,20 @@
/**
* "One stop shop" for accessing various aspects of a resource (defined by {@link ResourceType} object).
*
* Currently used for:
*
* - accessing the schema,
* - creating queries.
*
* Resides as low as in `schema` module, because it is used also in AbstractIntegrationTest class.
* This limits the functionality provided, though.
*
* Open questions:
*
* - Should we change the name to reflect that it is more schema-oriented?
* - Should we merge this class e.g. with {@link ResourceSchema}? Or {@link ResourceTypeUtil}?
* - Should we add more functionality here and move back to `provisioning-api`?
*
* HIGHLY EXPERIMENTAL (maybe not a good idea at all)
*/
@Experimental
Expand Down Expand Up @@ -96,41 +110,12 @@ public static Resource of(@NotNull PrismObject<ResourceType> resourceObject) {
.and().item(ShadowType.F_OBJECT_CLASS).eq(objectClassName);
}

// Beware, no kind/intent/OC filter is set here.
// Beware, no kind/intent/OC filter is set here. Must be private.
private S_FilterExit queryFor(@NotNull ResourceObjectDefinition objectDefinition) {
return PrismContext.get().queryFor(ShadowType.class, new ResourceItemDefinitionResolver(objectDefinition))
.item(ShadowType.F_RESOURCE_REF).ref(resourceBean.getOid());
}

/** This looks for `ACCOUNT/default`, not for the default intent of `ACCOUNT`. TODO better name? */
@VisibleForTesting
public @NotNull S_MatchingRuleEntry queryForAccountDefault() throws SchemaException, ConfigurationException {
return queryFor(ShadowKindType.ACCOUNT, SchemaConstants.INTENT_DEFAULT);
}

/** This looks for `ACCOUNT/default`, not for the default intent of `ACCOUNT`. TODO better name? */
@VisibleForTesting
public ObjectQuery allAccountDefaultObjectsQuery() throws SchemaException, ConfigurationException {
return queryForAccountDefault()
.build();
}

/** This looks for `ACCOUNT/default`, not for the default intent of `ACCOUNT`. TODO better name? */
@VisibleForTesting
public ObjectQuery accountDefaultObjectsQuery(QName attributeName, Object attributeValue)
throws SchemaException, ConfigurationException {
return queryForAccountDefault()
.and().item(ShadowType.F_ATTRIBUTES, attributeName).eq(attributeValue)
.build();
}

@VisibleForTesting
public @NotNull ResourceObjectDefinition getDefaultAccountDefinitionRequired()
throws SchemaException, ConfigurationException {
return getCompleteSchemaRequired()
.findDefaultDefinitionForKindRequired(ShadowKindType.ACCOUNT);
}

private static class ResourceItemDefinitionResolver implements QueryItemDefinitionResolver {

@NotNull private final ResourceObjectDefinition definition;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -799,8 +799,8 @@ public static ResourceAttribute<?> fixAttributePath(ResourceAttribute<?> attribu
}

// TODO: may be useful to move to ResourceObjectClassDefinition later?
public static void validateAttributeSchema(
ShadowType shadow, ResourceObjectDefinition objectDefinition) throws SchemaException {
public static void validateAttributeSchema(ShadowType shadow, ResourceObjectDefinition objectDefinition)
throws SchemaException {
ResourceAttributeContainer attributesContainer = getAttributesContainer(shadow);
for (ResourceAttribute<?> attribute: attributesContainer.getAttributes()) {
validateAttribute(attribute, objectDefinition);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -822,8 +822,7 @@ public void test166PasswordLoginLifecycleProposedGoodPassword() throws Exception
Task task = getTestTask();
OperationResult result = task.getResult();

modifyUserReplace(USER_JACK_OID, UserType.F_LIFECYCLE_STATE, task, result,
SchemaConstants.LIFECYCLE_PROPOSED);
modifyUserReplace(USER_JACK_OID, UserType.F_LIFECYCLE_STATE, task, result, SchemaConstants.LIFECYCLE_PROPOSED);

loginJackGoodPasswordExpectDenied();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ default PrismObject<O> getObjectAny() {
/**
* @return List of all executed deltas (in fact, {@link ObjectDeltaOperation} objects).
*/
List<? extends ObjectDeltaOperation<?>> getExecutedDeltas();
List<? extends ObjectDeltaOperation<O>> getExecutedDeltas();

/**
* TODO is this method ever used?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1121,7 +1121,7 @@ List<ObjectReferenceType> getMembersAsReferences(String orgOid)
/**
* Used for account activation notifier to collect all shadows which are going to be activated.
*/
List<ShadowType> getShadowsToActivate(Collection<? extends ModelElementContext> projectionContexts);
List<ShadowType> getShadowsToActivate(Collection<? extends ModelProjectionContext> projectionContexts);

String createRegistrationConfirmationLink(UserType userType);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@
*/
package com.evolveum.midpoint.model.impl.expr;

import static com.evolveum.midpoint.prism.delta.ObjectDelta.isAdd;
import static com.evolveum.midpoint.schema.GetOperationOptions.createNoFetchCollection;

import static com.evolveum.midpoint.util.MiscUtil.emptyIfNull;

import static java.util.Collections.emptyList;
import static java.util.Collections.singleton;

Expand Down Expand Up @@ -1434,24 +1433,17 @@ public CaseService getWorkflowService() {
}

@Override
public List<ShadowType> getShadowsToActivate(Collection<? extends ModelElementContext> projectionContexts) {
public List<ShadowType> getShadowsToActivate(Collection<? extends ModelProjectionContext> projectionContexts) {
List<ShadowType> shadows = new ArrayList<>();

//noinspection unchecked
for (ModelElementContext<ShadowType> projectionCtx : projectionContexts) {

List<? extends ObjectDeltaOperation> executedShadowDeltas = projectionCtx.getExecutedDeltas();
//noinspection unchecked
for (ObjectDeltaOperation<ShadowType> shadowDelta : executedShadowDeltas) {
if (shadowDelta.getExecutionResult().getStatus() == OperationResultStatus.SUCCESS
&& shadowDelta.getObjectDelta().getChangeType() == ChangeType.ADD) {
PrismObject<ShadowType> shadow = shadowDelta.getObjectDelta().getObjectToAdd();
PrismProperty<String> pLifecycleState = shadow.findProperty(ShadowType.F_LIFECYCLE_STATE);
if (pLifecycleState != null && !pLifecycleState.isEmpty() && SchemaConstants.LIFECYCLE_PROPOSED
.equals(pLifecycleState.getRealValue())) {
shadows.add(shadow.asObjectable());
for (ModelProjectionContext projectionCtx : projectionContexts) {
List<? extends ObjectDeltaOperation<ShadowType>> executedOperations = projectionCtx.getExecutedDeltas();
for (ObjectDeltaOperation<ShadowType> executedOperation : executedOperations) {
ObjectDelta<ShadowType> shadowDelta = executedOperation.getObjectDelta();
if (isAdd(shadowDelta) && executedOperation.getStatus() == OperationResultStatus.SUCCESS) {
ShadowType shadow = shadowDelta.getObjectToAdd().asObjectable();
if (SchemaConstants.LIFECYCLE_PROPOSED.equals(shadow.getLifecycleState())) {
shadows.add(shadow);
}

}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -558,9 +558,8 @@ public boolean operationMatches(ChangeTypeType operation) {
//endregion

//region Executed deltas
@NotNull
@Override
public List<LensObjectDeltaOperation<O>> getExecutedDeltas() {
public @NotNull List<LensObjectDeltaOperation<O>> getExecutedDeltas() {
return executedDeltas;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import com.evolveum.midpoint.model.api.context.ProjectionContextKey;

import com.evolveum.midpoint.provisioning.api.ProvisioningService;
import com.evolveum.midpoint.provisioning.api.Resource;
import com.evolveum.midpoint.schema.util.Resource;
import com.evolveum.midpoint.schema.GetOperationOptions;
import com.evolveum.midpoint.schema.SchemaService;
import com.evolveum.midpoint.schema.SelectorOptions;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import com.evolveum.midpoint.model.api.correlation.CompleteCorrelationResult;
import com.evolveum.midpoint.model.impl.correlation.CorrelationCaseManager;
import com.evolveum.midpoint.model.impl.correlation.CorrelationServiceImpl;
import com.evolveum.midpoint.provisioning.api.Resource;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;

import org.jetbrains.annotations.NotNull;
Expand Down Expand Up @@ -251,8 +250,7 @@ private CompleteCorrelationResult correlateAccount(String accountName, Task task
throws CommonException {
List<PrismObject<ShadowType>> objects = provisioningService.searchObjects(
ShadowType.class,
Resource.of(DUMMY_RESOURCE_SOURCE.getObjectable())
.accountDefaultObjectsQuery(SchemaConstants.ICFS_NAME, name),
accountDefaultObjectsQuery(DUMMY_RESOURCE_SOURCE, SchemaConstants.ICFS_NAME, name),
null,
task,
result);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@

import com.evolveum.midpoint.model.common.archetypes.ArchetypeManager;

import com.evolveum.midpoint.provisioning.api.Resource;

import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.mutable.MutableInt;
import org.jetbrains.annotations.NotNull;
Expand Down Expand Up @@ -1880,9 +1878,11 @@ protected PrismObject<ShadowType> findAccountByUsername(String username, PrismOb
return findAccountByUsername(username, resource, task, result);
}

/** Looks for default `ACCOUNT` object class. */
protected PrismObject<ShadowType> findAccountByUsername(String username, PrismObject<ResourceType> resource,
Task task, OperationResult result) throws SchemaException, ObjectNotFoundException, SecurityViolationException, CommunicationException, ConfigurationException, ExpressionEvaluationException {
ObjectQuery query = createAccountShadowQuery(username, resource);
Task task, OperationResult result) throws SchemaException, ObjectNotFoundException, SecurityViolationException,
CommunicationException, ConfigurationException, ExpressionEvaluationException {
ObjectQuery query = defaultAccountPrimaryIdentifierQuery(username, resource);
List<PrismObject<ShadowType>> accounts = modelService.searchObjects(ShadowType.class, query, null, task, result);
if (accounts.isEmpty()) {
return null;
Expand Down Expand Up @@ -2001,10 +2001,11 @@ protected <O extends ObjectType> void assertNoObjectByName(
}
}

/** Looks for default `ACCOUNT` object class. */
protected void assertNoShadow(
String username, PrismObject<ResourceType> resource, OperationResult result)
throws SchemaException, ConfigurationException {
ObjectQuery query = createAccountShadowQuery(username, resource);
ObjectQuery query = defaultAccountPrimaryIdentifierQuery(username, resource);
List<PrismObject<ShadowType>> accounts =
repositoryService.searchObjects(ShadowType.class, query, null, result);
if (accounts.isEmpty()) {
Expand All @@ -2014,9 +2015,10 @@ protected void assertNoShadow(
assert false : "Found shadow for " + username + " on " + resource + " while not expecting it: " + accounts;
}

/** Looks for default `ACCOUNT` object class. */
protected ShadowAsserter<Void> assertShadow(String username, PrismObject<ResourceType> resource)
throws SchemaException, ConfigurationException {
ObjectQuery query = createAccountShadowQuery(username, resource);
ObjectQuery query = defaultAccountPrimaryIdentifierQuery(username, resource);
OperationResult result = new OperationResult("assertShadow");
List<PrismObject<ShadowType>> accounts = repositoryService.searchObjects(ShadowType.class, query, null, result);
if (accounts.isEmpty()) {
Expand Down Expand Up @@ -2047,16 +2049,6 @@ protected PrismObject<ShadowType> findShadowByNameViaModel(
return shadows.iterator().next();
}

@Override
protected ObjectQuery createAccountShadowQuery(String username, PrismObject<ResourceType> resourceObject)
throws SchemaException, ConfigurationException {
Resource resource = Resource.of(resourceObject);
ResourceAttributeDefinition<?> primaryIdentifier =
resource.getDefaultAccountDefinitionRequired()
.getPrimaryIdentifierRequired();
return resource.accountDefaultObjectsQuery(primaryIdentifier.getItemName(), username);
}

protected <F extends FocusType> String getSingleLinkOid(PrismObject<F> focus) {
PrismReferenceValue accountRefValue = getSingleLinkRef(focus);
assertNull("Unexpected object in linkRefValue", accountRefValue.getObject());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import com.evolveum.midpoint.prism.path.ItemPath;
import com.evolveum.midpoint.prism.query.ObjectQuery;
import com.evolveum.midpoint.provisioning.api.ProvisioningService;
import com.evolveum.midpoint.provisioning.api.Resource;
import com.evolveum.midpoint.schema.util.Resource;
import com.evolveum.midpoint.repo.api.PreconditionViolationException;
import com.evolveum.midpoint.schema.constants.MidPointConstants;
import com.evolveum.midpoint.schema.processor.ResourceAttributeDefinition;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
*/
package com.evolveum.midpoint.notifications.impl.notifiers;

import java.util.Collection;
import java.util.Date;
import java.util.List;

Expand All @@ -16,7 +15,6 @@

import com.evolveum.midpoint.common.Clock;
import com.evolveum.midpoint.model.api.ModelService;
import com.evolveum.midpoint.model.api.context.ModelElementContext;
import com.evolveum.midpoint.notifications.api.events.ModelEvent;
import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.schema.processor.ResourceAttribute;
Expand Down Expand Up @@ -149,8 +147,9 @@ private String getRequestorDisplayName(ObjectType requester) {
}

private List<ShadowType> getShadowsToActivate(ModelEvent modelEvent) {
Collection<? extends ModelElementContext<?>> projectionContexts = modelEvent.getProjectionContexts();
return getMidpointFunctions().getShadowsToActivate(projectionContexts);
return getMidpointFunctions()
.getShadowsToActivate(
modelEvent.getProjectionContexts());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -540,11 +540,9 @@ public boolean isTypeBased() {
getObjectDefinitionRequired());
}

public void validateSchema(ShadowType shadow)
throws ObjectNotFoundException,
SchemaException, CommunicationException, ConfigurationException, ExpressionEvaluationException {
public void validateSchemaIfConfigured(ShadowType shadow) throws SchemaException {
if (ResourceTypeUtil.isValidateSchema(resource)) {
ShadowUtil.validateAttributeSchema(shadow, getObjectDefinition());
ShadowUtil.validateAttributeSchema(shadow, resourceObjectDefinition);
}
}

Expand Down Expand Up @@ -592,16 +590,21 @@ public AttributesToReturn createAttributesToReturn() {

// Methods delegated to shadow caretaker (convenient to be here, but not sure if it's ok...)

/** Beware! Creates a new context based on the shadow kind/intent/OC. */
public ProvisioningContext applyAttributesDefinition(@NotNull PrismObject<ShadowType> shadow)
throws SchemaException, ConfigurationException {
return getCaretaker().applyAttributesDefinition(this, shadow);
return getCaretaker().applyAttributesDefinitionInNewContext(this, shadow);
}

/** Beware! Creates a new context based on the shadow kind/intent/OC. */
public ProvisioningContext applyAttributesDefinition(@NotNull ShadowType shadow)
throws SchemaException, ConfigurationException {
return getCaretaker().applyAttributesDefinition(this, shadow);
return getCaretaker().applyAttributesDefinitionInNewContext(this, shadow);
}

/**
* Beware! For shadows being added, this method creates a separate (child) provisioning context.
*/
public void applyAttributesDefinition(@NotNull ObjectDelta<ShadowType> delta)
throws SchemaException, ConfigurationException {
getCaretaker().applyAttributesDefinition(this, delta);
Expand Down

0 comments on commit 9c0b32a

Please sign in to comment.