Skip to content

Commit

Permalink
MID-7534 code improvements after review, provisioning operation conte…
Browse files Browse the repository at this point in the history
…xt marked with @NotNull
  • Loading branch information
1azyman committed Jun 16, 2023
1 parent bbe797b commit a1f7368
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public static ProvisioningService createProvisioningService() {
@NotNull Class<T> type,
@NotNull String oid,
@Nullable Collection<SelectorOptions<GetOperationOptions>> options,
@Nullable ProvisioningOperationContext context,
@NotNull ProvisioningOperationContext context,
@NotNull Task task,
@NotNull OperationResult parentResult) {
throw new UnsupportedOperationException();
Expand All @@ -54,7 +54,7 @@ public <T extends ObjectType> String addObject(
@NotNull PrismObject<T> object,
@Nullable OperationProvisioningScriptsType scripts,
@Nullable ProvisioningOperationOptions options,
@Nullable ProvisioningOperationContext context,
@NotNull ProvisioningOperationContext context,
@NotNull Task task,
@NotNull OperationResult parentResult) {
return null;
Expand Down Expand Up @@ -86,7 +86,7 @@ public <T extends ObjectType> SearchResultList<PrismObject<T>> searchObjects(
@NotNull Class<T> type,
@Nullable ObjectQuery query,
@Nullable Collection<SelectorOptions<GetOperationOptions>> options,
@Nullable ProvisioningOperationContext context,
@NotNull ProvisioningOperationContext context,
@NotNull Task task,
@NotNull OperationResult parentResult) {
return new SearchResultList<>(new ArrayList<>(0));
Expand All @@ -97,7 +97,7 @@ public <T extends ObjectType> Integer countObjects(
@NotNull Class<T> type,
@Nullable ObjectQuery query,
@Nullable Collection<SelectorOptions<GetOperationOptions>> options,
@Nullable ProvisioningOperationContext context,
@NotNull ProvisioningOperationContext context,
@NotNull Task task,
@NotNull OperationResult parentResult) {
return null;
Expand All @@ -109,7 +109,7 @@ public <T extends ObjectType> SearchResultMetadata searchObjectsIterative(
@Nullable ObjectQuery query,
@Nullable Collection<SelectorOptions<GetOperationOptions>> options,
@NotNull ResultHandler<T> handler,
@Nullable ProvisioningOperationContext context,
@NotNull ProvisioningOperationContext context,
@NotNull Task task,
@NotNull OperationResult parentResult) {
return null;
Expand All @@ -122,7 +122,7 @@ public <T extends ObjectType> String modifyObject(
@NotNull Collection<? extends ItemDelta<?, ?>> modifications,
@Nullable OperationProvisioningScriptsType scripts,
@Nullable ProvisioningOperationOptions options,
@Nullable ProvisioningOperationContext context,
@NotNull ProvisioningOperationContext context,
@NotNull Task task,
@NotNull OperationResult parentResult) {
return null;
Expand All @@ -134,7 +134,7 @@ public <T extends ObjectType> PrismObject<T> deleteObject(
String oid,
ProvisioningOperationOptions option,
OperationProvisioningScriptsType scripts,
@Nullable ProvisioningOperationContext context,
@NotNull ProvisioningOperationContext context,
Task task,
OperationResult parentResult) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ <T extends ObjectType> String addObject(
@NotNull PrismObject<T> object,
@Nullable OperationProvisioningScriptsType scripts,
@Nullable ProvisioningOperationOptions options,
@Nullable ProvisioningOperationContext context,
@NotNull ProvisioningOperationContext context,
@NotNull Task task,
@NotNull OperationResult parentResult)
throws ObjectAlreadyExistsException, SchemaException, CommunicationException, ObjectNotFoundException,
Expand Down Expand Up @@ -616,7 +616,7 @@ <T extends ObjectType> SearchResultList<PrismObject<T>> searchObjects(
@NotNull Class<T> type,
@Nullable ObjectQuery query,
@Nullable Collection<SelectorOptions<GetOperationOptions>> options,
@Nullable ProvisioningOperationContext context,
@NotNull ProvisioningOperationContext context,
@NotNull Task task,
@NotNull OperationResult parentResult)
throws SchemaException, ObjectNotFoundException, CommunicationException, ConfigurationException,
Expand Down Expand Up @@ -665,7 +665,7 @@ <T extends ObjectType> Integer countObjects(
@NotNull Class<T> type,
@Nullable ObjectQuery query,
@Nullable Collection<SelectorOptions<GetOperationOptions>> options,
@Nullable ProvisioningOperationContext context,
@NotNull ProvisioningOperationContext context,
@NotNull Task task,
@NotNull OperationResult parentResult)
throws SchemaException, ObjectNotFoundException, CommunicationException, ConfigurationException,
Expand Down Expand Up @@ -712,7 +712,7 @@ <T extends ObjectType> SearchResultMetadata searchObjectsIterative(
@Nullable ObjectQuery query,
@Nullable Collection<SelectorOptions<GetOperationOptions>> options,
@NotNull ResultHandler<T> handler,
@Nullable ProvisioningOperationContext context,
@NotNull ProvisioningOperationContext context,
@NotNull Task task,
@NotNull OperationResult parentResult)
throws SchemaException, ObjectNotFoundException, CommunicationException, ConfigurationException,
Expand Down Expand Up @@ -777,7 +777,7 @@ <T extends ObjectType> String modifyObject(
@NotNull Collection<? extends ItemDelta<?, ?>> modifications,
@Nullable OperationProvisioningScriptsType scripts,
@Nullable ProvisioningOperationOptions options,
@Nullable ProvisioningOperationContext context,
@NotNull ProvisioningOperationContext context,
@NotNull Task task,
@NotNull OperationResult parentResult) throws ObjectNotFoundException, SchemaException,
CommunicationException, ConfigurationException, SecurityViolationException, PolicyViolationException, ObjectAlreadyExistsException, ExpressionEvaluationException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,20 @@
import java.util.List;
import java.util.Objects;

import com.evolveum.midpoint.common.Clock;

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

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;

import com.evolveum.midpoint.common.Clock;
import com.evolveum.midpoint.prism.*;
import com.evolveum.midpoint.prism.crypto.Protector;
import com.evolveum.midpoint.prism.delta.*;
import com.evolveum.midpoint.prism.match.MatchingRule;
import com.evolveum.midpoint.prism.path.ItemPath;
import com.evolveum.midpoint.provisioning.api.EventDispatcher;
import com.evolveum.midpoint.provisioning.api.ResourceObjectClassification;
import com.evolveum.midpoint.provisioning.api.ShadowDeathEvent;
import com.evolveum.midpoint.provisioning.impl.ProvisioningContext;
import com.evolveum.midpoint.provisioning.impl.shadows.ConstraintsChecker;
Expand Down Expand Up @@ -142,24 +140,25 @@ public void executeRepoShadowModifications(
@NotNull OperationResult result)
throws ObjectNotFoundException, SchemaException {

repoModifications = new ArrayList<>(repoModifications);
List<ItemDelta<?, ?>> clonedModifications = new ArrayList<>();
clonedModifications.addAll(repoModifications);

if (!repoModifications.isEmpty()) {
MetadataUtil.addModificationMetadataDeltas((Collection<ItemDelta<?,?>>) repoModifications, repoShadow); // todo not very nice [viliam]
if (!clonedModifications.isEmpty()) {
MetadataUtil.addModificationMetadataDeltas(clonedModifications, repoShadow);

LOGGER.trace("Applying repository shadow modifications:\n{}", debugDumpLazily(repoModifications, 1));
LOGGER.trace("Applying repository shadow modifications:\n{}", debugDumpLazily(clonedModifications, 1));
try {
ConstraintsChecker.onShadowModifyOperation(repoModifications);
repositoryService.modifyObject(ShadowType.class, repoShadow.getOid(), repoModifications, result);
ConstraintsChecker.onShadowModifyOperation(clonedModifications);
repositoryService.modifyObject(ShadowType.class, repoShadow.getOid(), clonedModifications, result);
// Maybe we should catch ObjectNotFoundException here and issue death event. But unless such deletion occurred
// in raw mode by the administrator, we shouldn't care, because the thread that deleted the shadow should have
// updated the links accordingly.
if (wasMarkedDead(repoShadow, repoModifications)) {
if (wasMarkedDead(repoShadow, clonedModifications)) {
issueShadowDeathEvent(repoShadow.getOid(), ctx.getTask(), result);
}
// This is important e.g. to update opState.repoShadow content in case of ADD operation success
// - to pass newly-generated primary identifier to other parts of the code.
ItemDeltaCollectionsUtil.applyTo(repoModifications, repoShadow.asPrismObject());
ItemDeltaCollectionsUtil.applyTo(clonedModifications, repoShadow.asPrismObject());
LOGGER.trace("Shadow changes processed successfully.");
} catch (ObjectAlreadyExistsException ex) {
throw SystemException.unexpected(ex, "when updating shadow in the repository");
Expand Down Expand Up @@ -245,6 +244,7 @@ public boolean markLiveShadowExistingIfNotMarkedSo(ShadowType liveShadow, Operat
return markShadowExists(liveShadow, result);
}
}

/** @return false if the shadow was not found. */
private boolean markShadowExists(ShadowType repoShadow, OperationResult parentResult) throws SchemaException {
List<ItemDelta<?, ?>> shadowChanges = prismContext.deltaFor(ShadowType.class)
Expand Down Expand Up @@ -382,9 +382,7 @@ public PendingOperationType checkAndRecordPendingOperationBeforeExecution(
*
* @param currentResourceObject Current state of the resource object. Not shadowized yet.
* @param resourceObjectDelta Delta coming from the resource (if known).
*
* @return repository shadow as it should look like after the update
*
* @see ShadowDeltaComputerAbsolute
*/
public @NotNull ShadowType updateShadowInRepository(
Expand Down

0 comments on commit a1f7368

Please sign in to comment.