Skip to content

Commit

Permalink
RepositoryService: removed listAccountShadowOwner/ResourceObjectShadows
Browse files Browse the repository at this point in the history
- listResourceObjectShadows wasn't used at all
- listAccountShadowOwner was replaced by generic query where used,
and ListAccountShadowOwnerTest was removed after consultation
- all touched files were cleaned up according to new standards
  • Loading branch information
virgo47 committed Mar 20, 2020
1 parent e561f9e commit 655dfac
Show file tree
Hide file tree
Showing 9 changed files with 301 additions and 751 deletions.
Expand Up @@ -30,6 +30,7 @@
import com.evolveum.midpoint.prism.path.*;
import com.evolveum.midpoint.prism.polystring.PolyString;
import com.evolveum.midpoint.prism.query.*;
import com.evolveum.midpoint.prism.query.builder.S_AtomicFilterExit;
import com.evolveum.midpoint.prism.util.CloneUtil;
import com.evolveum.midpoint.provisioning.api.*;
import com.evolveum.midpoint.repo.api.PreconditionViolationException;
Expand Down Expand Up @@ -1249,57 +1250,20 @@ public <T extends ObjectType> Integer countObjects(Class<T> type, ObjectQuery or

@Override
@Deprecated
public PrismObject<UserType> findShadowOwner(String accountOid, Task task, OperationResult parentResult)
throws ObjectNotFoundException, SecurityViolationException, SchemaException, ConfigurationException, ExpressionEvaluationException, CommunicationException {
public PrismObject<UserType> findShadowOwner(
String accountOid, Task task, OperationResult parentResult)
throws ObjectNotFoundException, SecurityViolationException, SchemaException,
ConfigurationException, ExpressionEvaluationException, CommunicationException {
Validate.notEmpty(accountOid, "Account oid must not be null or empty.");
Validate.notNull(parentResult, "Result type must not be null.");

enterModelMethod();

PrismObject<UserType> user;

LOGGER.trace("Listing account shadow owner for account with oid {}.", new Object[]{accountOid});

OperationResult result = parentResult.createSubresult(LIST_ACCOUNT_SHADOW_OWNER);
result.addParam("accountOid", accountOid);

try {

user = cacheRepositoryService.listAccountShadowOwner(accountOid, result);
result.recordSuccess();
} catch (ObjectNotFoundException ex) {
LoggingUtils.logException(LOGGER, "Account with oid {} doesn't exists", ex, accountOid);
result.recordFatalError("Account with oid '" + accountOid + "' doesn't exists", ex);
throw ex;
} catch (RuntimeException | Error ex) {
LoggingUtils.logException(LOGGER, "Couldn't list account shadow owner from repository"
+ " for account with oid {}", ex, accountOid);
result.recordFatalError("Couldn't list account shadow owner for account with oid '"
+ accountOid + "'.", ex);
throw ex;
} finally {
if (LOGGER.isTraceEnabled()) {
LOGGER.trace(result.dump(false));
}
exitModelMethod();
result.cleanupResult();
}

if (user != null) {
try {
user = user.cloneIfImmutable();
schemaTransformer.applySchemasAndSecurity(user, null, null,null, task, result);
} catch (SchemaException | SecurityViolationException | ConfigurationException |
ExpressionEvaluationException | ObjectNotFoundException | CommunicationException ex) {
LoggingUtils.logException(LOGGER, "Couldn't list account shadow owner from repository"
+ " for account with oid {}", ex, accountOid);
result.recordFatalError("Couldn't list account shadow owner for account with oid '"
+ accountOid + "'.", ex);
throw ex;
}
}

return user;
ObjectQuery query = prismContext.queryFor(UserType.class)
.item(UserType.F_LINK_REF)
.ref(accountOid)
.build();
SearchResultList<PrismObject<UserType>> prismObjects =
searchObjects(UserType.class, query, null, task, parentResult);
return MiscUtil.extractSingleton(prismObjects);
}

@Override
Expand Down

Large diffs are not rendered by default.

Expand Up @@ -7,31 +7,35 @@

package com.evolveum.midpoint.notifications.impl;

import javax.annotation.PostConstruct;

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

import com.evolveum.midpoint.notifications.api.NotificationManager;
import com.evolveum.midpoint.notifications.api.OperationStatus;
import com.evolveum.midpoint.notifications.impl.events.ResourceObjectEventImpl;
import com.evolveum.midpoint.prism.PrismContext;
import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.prism.query.ObjectQuery;
import com.evolveum.midpoint.provisioning.api.ChangeNotificationDispatcher;
import com.evolveum.midpoint.provisioning.api.ResourceOperationDescription;
import com.evolveum.midpoint.provisioning.api.ResourceOperationListener;
import com.evolveum.midpoint.repo.api.RepositoryService;
import com.evolveum.midpoint.schema.SearchResultList;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.task.api.LightweightIdentifierGenerator;
import com.evolveum.midpoint.task.api.Task;
import com.evolveum.midpoint.util.exception.ObjectNotFoundException;
import com.evolveum.midpoint.util.MiscUtil;
import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.util.logging.LoggingUtils;
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.UserType;

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

import javax.annotation.PostConstruct;

/**
* Converts provisioning events into notification events.
*/
Expand All @@ -42,6 +46,7 @@ public class AccountOperationListener implements ResourceOperationListener {

private static final String DOT_CLASS = AccountOperationListener.class.getName() + ".";

@Autowired private PrismContext prismContext;
@Autowired private LightweightIdentifierGenerator lightweightIdentifierGenerator;
@Autowired private ChangeNotificationDispatcher provisioningNotificationDispatcher;
@Autowired private NotificationManager notificationManager;
Expand Down Expand Up @@ -138,9 +143,9 @@ private void executeNotifyAny(OperationStatus status, ResourceOperationDescripti

@NotNull
private ResourceObjectEventImpl createRequest(OperationStatus status,
ResourceOperationDescription operationDescription,
Task task,
OperationResult result) {
ResourceOperationDescription operationDescription,
Task task,
OperationResult result) {

ResourceObjectEventImpl event = new ResourceObjectEventImpl(lightweightIdentifierGenerator,
operationDescription, status);
Expand Down Expand Up @@ -173,10 +178,17 @@ private PrismObject<UserType> findRequestee(String shadowOid, Task task, Operati
return task.getRequestee();
} else if (shadowOid != null) {
try {
PrismObject<UserType> user = cacheRepositoryService.listAccountShadowOwner(shadowOid, result);
ObjectQuery query = prismContext.queryFor(UserType.class)
.item(UserType.F_LINK_REF)
.ref(shadowOid)
.build();
SearchResultList<PrismObject<UserType>> prismObjects =
cacheRepositoryService.searchObjects(UserType.class, query, null, result);
PrismObject<UserType> user = MiscUtil.extractSingleton(prismObjects);

LOGGER.trace("listAccountShadowOwner for shadow {} yields {}", shadowOid, user);
return user;
} catch (ObjectNotFoundException e) {
} catch (SchemaException e) {
LOGGER.trace("There's a problem finding account {}", shadowOid, e);
return null;
}
Expand Down

0 comments on commit 655dfac

Please sign in to comment.