Skip to content

Commit

Permalink
Fix for resolveNames option and other minor ones.
Browse files Browse the repository at this point in the history
  • Loading branch information
mederly committed Jun 1, 2017
1 parent 8403214 commit efe3b81
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 10 deletions.
Expand Up @@ -1638,7 +1638,8 @@ public void keepPaths(List<ItemPath> keep) {
if (items != null) {
for (Iterator<Item<?, ?>> iterator = items.iterator(); iterator.hasNext(); ) {
Item<?, ?> item = iterator.next();
if (!ItemPath.containsSuperpathOrEquivalent(keep, item.getPath())) {
ItemPath itemPath = item.getPath().removeIdentifiers();
if (!ItemPath.containsSuperpathOrEquivalent(keep, itemPath)) {
iterator.remove();
} else {
if (item instanceof PrismContainer) {
Expand All @@ -1656,9 +1657,10 @@ public void removePaths(List<ItemPath> remove) {
if (items != null) {
for (Iterator<Item<?, ?>> iterator = items.iterator(); iterator.hasNext(); ) {
Item<?, ?> item = iterator.next();
if (ItemPath.containsEquivalent(remove, item.getPath())) {
ItemPath itemPath = item.getPath().removeIdentifiers();
if (ItemPath.containsEquivalent(remove, itemPath)) {
iterator.remove();
} else if (ItemPath.containsSuperpath(remove, item.getPath())) {
} else if (ItemPath.containsSuperpath(remove, itemPath)) {
if (item instanceof PrismContainer) {
((PrismContainer<?>) item).getValues().forEach(v -> v.removePaths(remove));
}
Expand Down
Expand Up @@ -187,6 +187,10 @@ private void add(QName qname) {
this.segments.add(createSegment(qname, false));
}

private void add(ItemPathSegment segment) {
this.segments.add(segment);
}

public static ItemPathSegment createSegment(QName qname, boolean variable) {
if (ParentPathSegment.QNAME.equals(qname)) {
return new ParentPathSegment();
Expand Down Expand Up @@ -343,6 +347,16 @@ public ItemPath normalize() {
return normalizedPath;
}

public ItemPath removeIdentifiers() {
ItemPath rv = new ItemPath();
for (ItemPathSegment segment : segments) {
if (!(segment instanceof IdItemPathSegment)) {
rv.add(segment);
}
}
return rv;
}

/**
* path1.compareComplex(path2) returns:
*
Expand Down
Expand Up @@ -652,12 +652,7 @@ public Response searchObjects(@PathParam("type") String type, QueryType queryTyp
}

private void removeExcludes(PrismObject<? extends ObjectType> object, List<String> exclude) {
for (ItemPath path : ItemPath.fromStringList(exclude)) {
Item item = object.findItem(path); // reduce to "removeItem" after fixing that method implementation
if (item != null) {
object.removeItem(item.getPath(), Item.class);
}
}
object.getValue().removePaths(ItemPath.fromStringList(exclude));
}

@POST
Expand Down
Expand Up @@ -56,7 +56,7 @@ public void resolveNamesIfRequested(Session session, List<? extends PrismContain
Visitor oidExtractor = visitable -> {
if (visitable instanceof PrismReferenceValue) {
PrismReferenceValue value = (PrismReferenceValue) visitable;
if (!ItemPath.containsSuperpathOrEquivalent(pathsToResolve, value.getPath())) {
if (!ItemPath.containsSubpathOrEquivalent(pathsToResolve, value.getPath())) {
return;
}
if (value.getTargetName() != null) { // just for sure
Expand Down

0 comments on commit efe3b81

Please sign in to comment.