Skip to content

Commit

Permalink
unify script variable conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
katkav committed Sep 15, 2016
1 parent d3896f2 commit 7cc8235
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 15 deletions.
Expand Up @@ -237,6 +237,10 @@ public V getValue(int index) {
return values.get(index);
}

public abstract <X> X getRealValue();

public abstract <X> Collection<X> getRealValues();

public boolean hasValue(PrismValue value, boolean ignoreMetadata) {
return (findValue(value, ignoreMetadata) != null);
}
Expand Down
Expand Up @@ -112,6 +112,28 @@ public boolean canRepresent(Class<?> compileTimeClass) {
public List<PrismContainerValue<C>> getValues() {
return (List<PrismContainerValue<C>>) super.getValues();
}

@Override
public Collection<C> getRealValues() {
if (getValues() == null) {
return null;
}
List<C> realValues = new ArrayList<>(getValues().size());
for (PrismContainerValue<C> value : getValues()) {
realValues.add(value.asContainerable());
}

return realValues;

}

@Override
public C getRealValue() {
if (getValue() == null) {
return null;
}
return getValue().asContainerable();
}

public PrismContainerValue<C> getValue() {
if (getValues().size() == 1) {
Expand Down
Expand Up @@ -1583,16 +1583,4 @@ public static <T extends Containerable> List<PrismContainerValue<T>> toPcvList(L
return rv;
}

public static <T extends Containerable> List<T> fromPcvList(List<PrismContainerValue<T>> values) {
if (values == null) {
return null;
}
List<T> realValues = new ArrayList<>(values.size());
for (PrismContainerValue<T> value : values) {
realValues.add(value.asContainerable());
}

return realValues;

}
}
Expand Up @@ -129,6 +129,7 @@ public <X> List<PrismPropertyValue<X>> getValues(Class<X> type) {
return (List) getValues();
}

@Override
public Collection<T> getRealValues() {
Collection<T> realValues = new ArrayList<T>(getValues().size());
for (PrismPropertyValue<T> pValue: getValues()) {
Expand All @@ -140,6 +141,7 @@ public Collection<T> getRealValues() {
/**
* Type override, also for compatibility.
*/

public <X> Collection<X> getRealValues(Class<X> type) {
Collection<X> realValues = new ArrayList<X>(getValues().size());
for (PrismPropertyValue<T> pValue: getValues()) {
Expand All @@ -164,6 +166,7 @@ public PrismPropertyValue<T> getAnyValue() {
return values.iterator().next();
}

@Override
public T getRealValue() {
if (getValue() == null) {
return null;
Expand Down
Expand Up @@ -16,6 +16,8 @@

package com.evolveum.midpoint.prism;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import javax.xml.namespace.QName;
Expand Down Expand Up @@ -100,6 +102,26 @@ private PrismReferenceValue getValue(String oid) {
}
return null;
}

@Override
public Referencable getRealValue() {
if (getValue() == null) {
return null;
}
return getValue().asReferencable();
}

@Override
public Collection<Referencable> getRealValues() {
if (getValues() == null) {
return null;
}
List<Referencable> realValues = new ArrayList<>(getValues().size());
for (PrismReferenceValue refVal : getValues()) {
realValues.add(refVal.asReferencable());
}
return realValues;
}


public boolean add(PrismReferenceValue value) {
Expand Down
Expand Up @@ -15,6 +15,7 @@
*/
package com.evolveum.midpoint.model.common.expression;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
Expand Down Expand Up @@ -263,6 +264,34 @@ public static Object convertVariableValue(Object originalValue, String variableN
return prop.getValues();
}
}
if (originalValue instanceof PrismReference) {
PrismReference prop = (PrismReference)originalValue;
PrismReferenceDefinition def = prop.getDefinition();
if (def != null) {
if (def.isSingleValue()) {
return prop.getRealValue();
} else {
return prop.getRealValues();
}
} else {
return prop.getValues();
}
}
if (originalValue instanceof PrismContainer<?>) {
PrismContainer<?> container = (PrismContainer<?>)originalValue;
PrismContainerDefinition<?> def = container.getDefinition();
if (def != null) {
if (def.isSingleValue()) {
return container.getRealValue();
} else {
return container.getRealValues();

}
} else {
return container.getValues();
}
}

return originalValue;
}

Expand Down
Expand Up @@ -428,8 +428,7 @@ private List<PasswordHistoryEntryType> getSortedHistoryList(
if (historyEntries.isEmpty()) {
return new ArrayList<>();
}
List<PasswordHistoryEntryType> historyEntryValues = PrismContainerValue
.fromPcvList(historyEntries.getValues());
List<PasswordHistoryEntryType> historyEntryValues = (List<PasswordHistoryEntryType>) historyEntries.getRealValues();

Collections.sort(historyEntryValues, new Comparator<PasswordHistoryEntryType>() {

Expand Down
Expand Up @@ -17,6 +17,7 @@
package com.evolveum.midpoint.model.impl.lens.projector;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import org.apache.commons.lang3.StringUtils;
Expand Down Expand Up @@ -176,7 +177,7 @@ private <F extends FocusType> List<String> determineOldPasswordValues(PrismObjec
return null;
}

List<PasswordHistoryEntryType> historyEntryValues = PrismContainerValue.fromPcvList(historyEntries.getValues());
Collection<PasswordHistoryEntryType> historyEntryValues = historyEntries.getRealValues();
oldPasswords = new ArrayList<>(historyEntryValues.size());
for (PasswordHistoryEntryType historyEntryValue : historyEntryValues) {
try {
Expand Down

0 comments on commit 7cc8235

Please sign in to comment.