Skip to content

Commit

Permalink
RepositoryService: Javadoc for advance/returnUnusedValuesToSequence()
Browse files Browse the repository at this point in the history
Parameter names were renamed/clarified in API/implementations as well.
  • Loading branch information
virgo47 committed Jul 26, 2021
1 parent 9fef133 commit ce9d0b2
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -222,17 +222,20 @@ public <T extends ObjectType> int countObjects(Class<T> type, ObjectQuery query,
}

@Override
public boolean isAnySubordinate(String upperOrgOid, Collection<String> lowerObjectOids) {
public boolean isAnySubordinate(
String ancestorOrgOid, Collection<String> descendantOrgOids) {
return false;
}

@Override
public <O extends ObjectType> boolean isDescendant(PrismObject<O> object, String orgOid) {
public <O extends ObjectType> boolean isDescendant(
PrismObject<O> object, String ancestorOrgOid) {
return false;
}

@Override
public <O extends ObjectType> boolean isAncestor(PrismObject<O> object, String oid) {
public <O extends ObjectType> boolean isAncestor(
PrismObject<O> ancestorOrg, String descendantOrgOid) {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@

import java.util.Collection;

import com.evolveum.midpoint.util.annotation.Experimental;

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

Expand All @@ -21,6 +19,7 @@
import com.evolveum.midpoint.repo.api.query.ObjectFilterExpressionEvaluator;
import com.evolveum.midpoint.schema.*;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.util.annotation.Experimental;
import com.evolveum.midpoint.util.exception.*;
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;
Expand Down Expand Up @@ -299,7 +298,8 @@ <T extends ObjectType> String getVersion(Class<T> type, String oid, OperationRes
* @param parentResult Operation result into which we put our result
*/
@Experimental
@NotNull default <T extends ObjectType> ModifyObjectResult<T> modifyObjectDynamically(
@NotNull
default <T extends ObjectType> ModifyObjectResult<T> modifyObjectDynamically(
@NotNull Class<T> type,
@NotNull String oid,
@Nullable Collection<SelectorOptions<GetOperationOptions>> getOptions,
Expand Down Expand Up @@ -442,11 +442,45 @@ <T extends ObjectType> SearchResultMetadata searchObjectsIterative(Class<T> type
OperationResult parentResult)
throws SchemaException;

boolean isAnySubordinate(String upperOrgOid, Collection<String> lowerObjectOids) throws SchemaException;
/**
* Returns `true` if any of organizations identified with `descendantOrgOids` is under
* organization identified by `ancestorOrgOid`.
* For this method organization is under itself, that is `isAnySubordinate(oid, List.of(oid))`
* returns `true`.
* Using of non-organizational OID for `ancestorOrgOid` is sure to result in `false`.
* Non-organizational OIDs in `descendantOrgOids` do not help with `true` result either.
*
* @param ancestorOrgOid identifier of ancestor (upper) organization
* @param descendantOrgOids identifiers of potential descendant organizations
*/
boolean isAnySubordinate(String ancestorOrgOid, Collection<String> descendantOrgOids)
throws SchemaException;

<O extends ObjectType> boolean isDescendant(PrismObject<O> object, String orgOid) throws SchemaException;
/**
* Returns `true` if the `object` is under the organization identified with `ancestorOrg`.
* For this method *organization is NOT under itself*, that is `isDescendant(org, oidOfThatOrg)`
* returns `false` - which is not a symmetric behavior with {@link #isAncestor(PrismObject, String)}.
* On the other hand, the `object` here can be non-organization as the actual tested objects
* are targets of its `parentOrgRefs`.
*
* @param object object of any type tested to belong under Org with `ancestorOrgOid`
* @param ancestorOrgOid identifier of ancestor organization
*/
<O extends ObjectType> boolean isDescendant(PrismObject<O> object, String ancestorOrgOid)
throws SchemaException;

<O extends ObjectType> boolean isAncestor(PrismObject<O> object, String oid) throws SchemaException;
/**
* Returns `true` if the organization identified with `descendantOrgOid` is under `ancestorOrg`.
* For this method organization is under itself, that is `isAncestor(org, oidOfThatOrg)`
* returns `true`.
* Despite type parameter, only `PrismObject<OrgType>` can return `true` and `descendantOrgOid`
* must belong to the `OrgType` object as well, e.g. user under `ancestorOrg` returns `false`.
*
* @param ancestorOrg ancestor organization
* @param descendantOrgOid identifier of potential descendant organization
*/
<O extends ObjectType> boolean isAncestor(PrismObject<O> ancestorOrg, String descendantOrgOid)
throws SchemaException;

/**
* <p>Returns the object representing owner of specified shadow.</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,33 +248,33 @@ public void testOrgClosureConsistency(boolean repairIfNecessary, OperationResult
}

@Override
public boolean isAnySubordinate(String upperOrgOid, Collection<String> lowerObjectOids)
public boolean isAnySubordinate(String ancestorOrgOid, Collection<String> descendantOrgOids)
throws SchemaException {
Long startTime = repoOpStart();
try {
return repositoryService.isAnySubordinate(upperOrgOid, lowerObjectOids);
return repositoryService.isAnySubordinate(ancestorOrgOid, descendantOrgOids);
} finally {
repoOpEnd(startTime);
}
}

@Override
public <O extends ObjectType> boolean isDescendant(PrismObject<O> object, String orgOid)
public <O extends ObjectType> boolean isDescendant(PrismObject<O> object, String ancestorOrgOid)
throws SchemaException {
Long startTime = repoOpStart();
try {
return repositoryService.isDescendant(object, orgOid);
return repositoryService.isDescendant(object, ancestorOrgOid);
} finally {
repoOpEnd(startTime);
}
}

@Override
public <O extends ObjectType> boolean isAncestor(PrismObject<O> object, String oid)
public <O extends ObjectType> boolean isAncestor(PrismObject<O> ancestorOrg, String descendantOrgOid)
throws SchemaException {
Long startTime = repoOpStart();
try {
return repositoryService.isAncestor(object, oid);
return repositoryService.isAncestor(ancestorOrg, descendantOrgOid);
} finally {
repoOpEnd(startTime);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -901,8 +901,8 @@ public <T extends Containerable> SearchResultList<T> searchContainers(
// This operation does not use parent OperationResult, so the exception handling is simpler.
@Override
public boolean isAnySubordinate(String ancestorOrgOid, Collection<String> descendantOrgOids) {
Validate.notNull(ancestorOrgOid, "upperOrgOid must not be null.");
Validate.notNull(descendantOrgOids, "lowerObjectOids must not be null.");
Validate.notNull(ancestorOrgOid, "ancestorOrgOid must not be null.");
Validate.notNull(descendantOrgOids, "descendantOrgOids must not be null.");

LOGGER.trace("Querying for subordination upper {}, lower {}",
ancestorOrgOid, descendantOrgOids);
Expand All @@ -916,7 +916,7 @@ public boolean isAnySubordinate(String ancestorOrgOid, Collection<String> descen
try {
return isAnySubordinateAttempt(UUID.fromString(ancestorOrgOid),
descendantOrgOids.stream()
.map(s -> UUID.fromString(s))
.map(oid -> UUID.fromString(oid))
.collect(Collectors.toList()));
} catch (Exception e) {
throw new SystemException(
Expand All @@ -943,9 +943,9 @@ private boolean isAnySubordinateAttempt(UUID ancestorOrgOid, Collection<UUID> lo

@Override
public <O extends ObjectType> boolean isDescendant(
PrismObject<O> descendant, String ancestorOrgOid)
PrismObject<O> object, String ancestorOrgOid)
throws SchemaException {
List<ObjectReferenceType> objParentOrgRefs = descendant.asObjectable().getParentOrgRef();
List<ObjectReferenceType> objParentOrgRefs = object.asObjectable().getParentOrgRef();
List<String> objParentOrgOids = new ArrayList<>(objParentOrgRefs.size());
for (ObjectReferenceType objParentOrgRef : objParentOrgRefs) {
objParentOrgOids.add(objParentOrgRef.getOid());
Expand All @@ -955,14 +955,12 @@ public <O extends ObjectType> boolean isDescendant(

@Override
public <O extends ObjectType> boolean isAncestor(
PrismObject<O> ancestorOrg, String descendantOid)
PrismObject<O> ancestorOrg, String descendantOrgOid)
throws SchemaException {
if (ancestorOrg.getOid() == null) {
return false;
}
Collection<String> oidList = new ArrayList<>(1);
oidList.add(descendantOid);
return isAnySubordinate(ancestorOrg.getOid(), oidList);
return isAnySubordinate(ancestorOrg.getOid(), List.of(descendantOrgOid));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1006,15 +1006,15 @@ private <T extends ObjectType> SearchResultMetadata searchObjectsIterativeBySing
}

@Override
public boolean isAnySubordinate(String upperOrgOid, Collection<String> lowerObjectOids) {
Validate.notNull(upperOrgOid, "upperOrgOid must not be null.");
Validate.notNull(lowerObjectOids, "lowerObjectOids must not be null.");
public boolean isAnySubordinate(String ancestorOrgOid, Collection<String> descendantOrgOids) {
Validate.notNull(ancestorOrgOid, "upperOrgOid must not be null.");
Validate.notNull(descendantOrgOids, "lowerObjectOids must not be null.");

if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Querying for subordination upper {}, lower {}", upperOrgOid, lowerObjectOids);
LOGGER.trace("Querying for subordination upper {}, lower {}", ancestorOrgOid, descendantOrgOids);
}

if (lowerObjectOids.isEmpty()) {
if (descendantOrgOids.isEmpty()) {
// trivial case
return false;
}
Expand All @@ -1027,9 +1027,9 @@ public boolean isAnySubordinate(String upperOrgOid, Collection<String> lowerObje
try {
while (true) {
try {
return objectRetriever.isAnySubordinateAttempt(upperOrgOid, lowerObjectOids);
return objectRetriever.isAnySubordinateAttempt(ancestorOrgOid, descendantOrgOids);
} catch (RuntimeException ex) {
attempt = baseHelper.logOperationAttempt(upperOrgOid, OP_IS_ANY_SUBORDINATE, attempt, ex, null);
attempt = baseHelper.logOperationAttempt(ancestorOrgOid, OP_IS_ANY_SUBORDINATE, attempt, ex, null);
pm.registerOperationNewAttempt(opHandle, attempt);
}
}
Expand Down Expand Up @@ -1247,23 +1247,23 @@ public <O extends ObjectType> boolean selectorMatches(
}

@Override
public <O extends ObjectType> boolean isDescendant(PrismObject<O> object, String orgOid) {
public <O extends ObjectType> boolean isDescendant(PrismObject<O> object, String ancestorOrgOid) {
List<ObjectReferenceType> objParentOrgRefs = object.asObjectable().getParentOrgRef();
List<String> objParentOrgOids = new ArrayList<>(objParentOrgRefs.size());
for (ObjectReferenceType objParentOrgRef : objParentOrgRefs) {
objParentOrgOids.add(objParentOrgRef.getOid());
}
return isAnySubordinate(orgOid, objParentOrgOids);
return isAnySubordinate(ancestorOrgOid, objParentOrgOids);
}

@Override
public <O extends ObjectType> boolean isAncestor(PrismObject<O> object, String oid) {
if (object.getOid() == null) {
public <O extends ObjectType> boolean isAncestor(PrismObject<O> ancestorOrg, String descendantOrgOid) {
if (ancestorOrg.getOid() == null) {
return false;
}
Collection<String> oidList = new ArrayList<>(1);
oidList.add(oid);
return isAnySubordinate(object.getOid(), oidList);
oidList.add(descendantOrgOid);
return isAnySubordinate(ancestorOrg.getOid(), oidList);
}

@Override
Expand Down

0 comments on commit ce9d0b2

Please sign in to comment.