Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
mederly committed Mar 6, 2020
2 parents ed8e7b8 + 20efabf commit f9c046a
Show file tree
Hide file tree
Showing 61 changed files with 1,223 additions and 2,304 deletions.
Expand Up @@ -266,9 +266,7 @@ public static <T> String fromXmlEnum(T enumValue) {
Field field;
try {
field = enumValue.getClass().getField(fieldName);
} catch (SecurityException e) {
throw new IllegalArgumentException("Error getting field from "+enumValue, e);
} catch (NoSuchFieldException e) {
} catch (SecurityException | NoSuchFieldException e) {
throw new IllegalArgumentException("Error getting field from "+enumValue, e);
}
XmlEnumValue annotation = field.getAnnotation(XmlEnumValue.class);
Expand Down
Expand Up @@ -6,26 +6,26 @@
*/
package com.evolveum.midpoint.schema;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Objects;

import org.apache.commons.collections4.CollectionUtils;
import org.jetbrains.annotations.NotNull;

import com.evolveum.midpoint.prism.PrismContext;
import com.evolveum.midpoint.prism.path.ItemPath;
import com.evolveum.midpoint.prism.path.UniformItemPath;
import com.evolveum.midpoint.prism.path.ItemPathCollectionsUtil;
import com.evolveum.midpoint.prism.path.UniformItemPath;
import com.evolveum.midpoint.util.ShortDumpable;
import com.evolveum.midpoint.util.annotation.Experimental;
import com.evolveum.midpoint.xml.ns._public.common.common_3.GetOperationOptionsType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.IterationMethodType;
import org.apache.commons.collections4.CollectionUtils;
import org.jetbrains.annotations.NotNull;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Objects;

/**
* @author semancik
*
*/
public class GetOperationOptions extends AbstractOptions implements Serializable, Cloneable, ShortDumpable {
private static final long serialVersionUID = 1L;
Expand Down Expand Up @@ -129,7 +129,7 @@ public class GetOperationOptions extends AbstractOptions implements Serializable
* The default value is zero, which means that a fresh value must always be returned. This means that caches that do
* not guarantee fresh value cannot be used. If non-zero value is specified then such caches may be used. In case that
* Long.MAX_VALUE is specified then the caches are always used and fresh value is never retrieved.
*
* <p>
* Null value is special in one more aspect: it allows to return partial cached data in case that the original is not
* accessible. E.g. in that case provisioning can return repository shadow in case that the resource is not reachable.
* Explicit specification of staleness=0 disables this behavior.
Expand Down Expand Up @@ -158,11 +158,11 @@ public class GetOperationOptions extends AbstractOptions implements Serializable
/**
* Should the results be made distinct.
* Not all providers support this option.
*
* <p>
* BEWARE:
* - may bring a potentially huge performance penalty
* - may interfere with paging (!)
*
* - may bring a potentially huge performance penalty
* - may interfere with paging (!)
* <p>
* So please consider this option an EXPERIMENTAL, for now.
*/
@Experimental
Expand All @@ -187,7 +187,7 @@ public class GetOperationOptions extends AbstractOptions implements Serializable
* Whether this operation is already part of the execution phase. I.e. the request authorization was already
* processed. This means that the operation is in fact operation invoked within another operation,
* e.g. invoked from script or expression evaluator.
*
* <p>
* WARNING: THIS OPTION MUST NOT BE AVAILABLE FROM REMOTE INTERFACES.
* This is safe to use from a secure area of JVM, where the components can trick model to circumvent
* authorizations anyway. But it must not be available outside of the secure area.
Expand Down Expand Up @@ -358,11 +358,11 @@ public static boolean isNoFetch(GetOperationOptions options) {
return options.noFetch;
}

/**
* No not fetch any information from external sources, e.g. do not fetch account data from resource,
* do not fetch resource schema, etc.
* Such operation returns only the data stored in midPoint repository.
*/
/**
* No not fetch any information from external sources, e.g. do not fetch account data from resource,
* do not fetch resource schema, etc.
* Such operation returns only the data stored in midPoint repository.
*/
public static GetOperationOptions createNoFetch() {
GetOperationOptions opts = new GetOperationOptions();
opts.setNoFetch(true);
Expand Down Expand Up @@ -476,11 +476,11 @@ public static Collection<SelectorOptions<GetOperationOptions>> createRawCollecti
return SelectorOptions.createCollection(createRaw());
}

/**
* No not fetch any information from external sources, e.g. do not fetch account data from resource,
* do not fetch resource schema, etc.
* Such operation returns only the data stored in midPoint repository.
*/
/**
* No not fetch any information from external sources, e.g. do not fetch account data from resource,
* do not fetch resource schema, etc.
* Such operation returns only the data stored in midPoint repository.
*/
public static Collection<SelectorOptions<GetOperationOptions>> createNoFetchCollection() {
return SelectorOptions.createCollection(createNoFetch());
}
Expand Down Expand Up @@ -756,11 +756,11 @@ public static boolean isDistinct(GetOperationOptions options) {
/**
* Should the results be made distinct.
* Not all providers support this option.
*
* <p>
* BEWARE:
* - may bring a potentially huge performance penalty
* - may interfere with paging (!)
*
* - may bring a potentially huge performance penalty
* - may interfere with paging (!)
* <p>
* So please consider this option an EXPERIMENTAL, for now.
*/
@Experimental
Expand Down Expand Up @@ -898,8 +898,8 @@ public GetOperationOptions relationalValueSearchQuery(RelationalValueSearchQuery

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof GetOperationOptions)) return false;
if (this == o) { return true; }
if (!(o instanceof GetOperationOptions)) { return false; }
GetOperationOptions that = (GetOperationOptions) o;
return retrieve == that.retrieve &&
Objects.equals(resolve, that.resolve) &&
Expand Down Expand Up @@ -1033,23 +1033,23 @@ public static GetOperationOptions fromRestOptions(List<String> options, Definiti
return rv;
}


@NotNull
@SafeVarargs
public static Collection<SelectorOptions<GetOperationOptions>> merge(PrismContext prismContext,
Collection<SelectorOptions<GetOperationOptions>>... parts) {
final UniformItemPath EMPTY_PATH = prismContext.emptyPath();
final UniformItemPath emptyPath = prismContext.emptyPath();
Collection<SelectorOptions<GetOperationOptions>> merged = new ArrayList<>();
for (Collection<SelectorOptions<GetOperationOptions>> part : parts) {
for (SelectorOptions<GetOperationOptions> increment : CollectionUtils.emptyIfNull(part)) {
if (increment != null) { // should always be so
Collection<GetOperationOptions> existing = SelectorOptions.findOptionsForPath(merged, increment.getItemPath(EMPTY_PATH));
Collection<GetOperationOptions> existing = SelectorOptions.findOptionsForPath(
merged, increment.getItemPath(emptyPath));
if (existing.isEmpty()) {
merged.add(increment);
} else if (existing.size() == 1) {
existing.iterator().next().merge(increment.getOptions());
} else {
throw new AssertionError("More than one options for path: " + increment.getItemPath(EMPTY_PATH));
throw new AssertionError("More than one options for path: " + increment.getItemPath(emptyPath));
}
}
}
Expand Down
Expand Up @@ -6,30 +6,32 @@
*/
package com.evolveum.midpoint.schema;

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

import java.io.Serializable;
import java.util.*;
import java.util.Objects;
import java.util.*;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.stream.Collectors;

import com.evolveum.midpoint.prism.PrismContext;
import com.evolveum.midpoint.prism.path.*;
import com.evolveum.midpoint.util.DebugDumpable;
import com.evolveum.midpoint.util.MiscUtil;
import com.evolveum.midpoint.util.ShortDumpable;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.ObjectUtils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import static com.evolveum.midpoint.util.MiscUtil.emptyIfNull;
import com.evolveum.midpoint.prism.PrismContext;
import com.evolveum.midpoint.prism.path.ItemPath;
import com.evolveum.midpoint.prism.path.ItemPathCollectionsUtil;
import com.evolveum.midpoint.prism.path.UniformItemPath;
import com.evolveum.midpoint.util.DebugDumpable;
import com.evolveum.midpoint.util.MiscUtil;
import com.evolveum.midpoint.util.ShortDumpable;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;

/**
* @author semancik
*
*/
public class SelectorOptions<T> implements Serializable, DebugDumpable, ShortDumpable {
private static final long serialVersionUID = 1L;
Expand Down Expand Up @@ -72,7 +74,7 @@ public static <T> Collection<SelectorOptions<T>> createCollection(T options) {

public static <T> Collection<SelectorOptions<T>> createCollection(T options, UniformItemPath... paths) {
Collection<SelectorOptions<T>> optionsCollection = new ArrayList<>(paths.length);
for (UniformItemPath path: paths) {
for (UniformItemPath path : paths) {
optionsCollection.add(create(path, options));
}
return optionsCollection;
Expand Down Expand Up @@ -128,7 +130,7 @@ public static <T> T findRootOptions(Collection<SelectorOptions<T>> options) {
if (options == null) {
return null;
}
for (SelectorOptions<T> oooption: options) {
for (SelectorOptions<T> oooption : options) {
if (oooption.isRoot()) {
return oooption.getOptions();
}
Expand Down Expand Up @@ -156,7 +158,7 @@ public static <T> Collection<SelectorOptions<T>> updateRootOptions(Collection<Se
@NotNull
public static <T> Collection<T> findOptionsForPath(Collection<SelectorOptions<T>> options, @NotNull UniformItemPath path) {
Collection<T> rv = new ArrayList<>();
for (SelectorOptions<T> oooption: CollectionUtils.emptyIfNull(options)) {
for (SelectorOptions<T> oooption : CollectionUtils.emptyIfNull(options)) {
if (path.equivalent(oooption.getItemPathOrNull())) {
rv.add(oooption.getOptions());
}
Expand Down Expand Up @@ -229,12 +231,12 @@ public static List<SelectorOptions<GetOperationOptions>> filterRetrieveOptions(
public static <T> Map<T, Collection<UniformItemPath>> extractOptionValues(Collection<SelectorOptions<GetOperationOptions>> options,
Function<GetOperationOptions, T> supplier, PrismContext prismContext) {
Map<T, Collection<UniformItemPath>> rv = new HashMap<>();
final UniformItemPath EMPTY_PATH = prismContext.emptyPath();
final UniformItemPath emptyPath = prismContext.emptyPath();
for (SelectorOptions<GetOperationOptions> selectorOption : CollectionUtils.emptyIfNull(options)) {
T value = supplier.apply(selectorOption.getOptions());
if (value != null) {
Collection<UniformItemPath> itemPaths = rv.computeIfAbsent(value, t -> new HashSet<>());
itemPaths.add(selectorOption.getItemPath(EMPTY_PATH));
itemPaths.add(selectorOption.getItemPath(emptyPath));
}
}
return rv;
Expand All @@ -245,8 +247,8 @@ public static <T> Map<T, Collection<UniformItemPath>> extractOptionValues(Collec
//region hashCode, equals, toString
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
if (this == o) { return true; }
if (o == null || getClass() != o.getClass()) { return false; }
SelectorOptions<?> that = (SelectorOptions<?>) o;
return Objects.equals(selector, that.selector) && Objects.equals(options, that.options);
}
Expand Down Expand Up @@ -280,7 +282,7 @@ public void shortDump(StringBuilder sb) {
if (options == null) {
sb.append("null");
} else if (options instanceof ShortDumpable) {
((ShortDumpable)options).shortDump(sb);
((ShortDumpable) options).shortDump(sb);
} else {
sb.append(options);
}
Expand Down
Expand Up @@ -167,25 +167,31 @@ public void testResolvePathPolyStringOdoNorm() throws Exception {

}

private <T> T resolvePath(String path, final String TEST_NAME)
throws SchemaException, ObjectNotFoundException, IOException, CommunicationException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException {
private <T> T resolvePath(String path, final String exprShortDesc)
throws SchemaException, ObjectNotFoundException, IOException, CommunicationException,
ConfigurationException, SecurityViolationException, ExpressionEvaluationException {
ExpressionVariables variables = createVariables();
return resolvePath(path, variables, TEST_NAME);
return resolvePath(path, variables, exprShortDesc);
}

private <T> T resolvePathOdo(String path, final String TEST_NAME) throws SchemaException, ObjectNotFoundException, IOException, CommunicationException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException {
private <T> T resolvePathOdo(String path, final String exprShortDesc)
throws SchemaException, ObjectNotFoundException, IOException, CommunicationException,
ConfigurationException, SecurityViolationException, ExpressionEvaluationException {
ExpressionVariables variables = createVariablesOdo();
return resolvePath(path, variables, TEST_NAME);
return resolvePath(path, variables, exprShortDesc);
}

private <T> T resolvePath(String path, ExpressionVariables variables, final String TEST_NAME) throws SchemaException, ObjectNotFoundException, CommunicationException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException {
private <T> T resolvePath(String path, ExpressionVariables variables, String exprShortDesc)
throws SchemaException, ObjectNotFoundException, CommunicationException,
ConfigurationException, SecurityViolationException, ExpressionEvaluationException {
OperationResult result = createOperationResult();
ItemPath itemPath = toItemPath(path);

// WHEN
ObjectResolver objectResolver = new DirectoryFileObjectResolver(MidPointTestConstants.OBJECTS_DIR);
Object resolved = ExpressionUtil.resolvePathGetValue(itemPath, variables, false, null, objectResolver,
PrismTestUtil.getPrismContext(), TEST_NAME, new NullTaskImpl(), result);
Object resolved = ExpressionUtil.resolvePathGetValue(
itemPath, variables, false, null, objectResolver,
PrismTestUtil.getPrismContext(), exprShortDesc, new NullTaskImpl(), result);

// THEN
IntegrationTestTools.display("Resolved", resolved);
Expand Down

0 comments on commit f9c046a

Please sign in to comment.