Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/Evolveum/midpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
katkav committed Oct 20, 2017
2 parents b66e074 + a4ad63b commit e6ebad1
Show file tree
Hide file tree
Showing 36 changed files with 712 additions and 191 deletions.
Expand Up @@ -119,7 +119,6 @@
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.Validate;
import org.apache.poi.ss.formula.functions.T;
import org.apache.wicket.*;
import org.apache.wicket.Component;
import org.apache.wicket.ajax.AbstractDefaultAjaxBehavior;
Expand Down Expand Up @@ -158,7 +157,6 @@
import javax.management.MBeanServer;
import javax.management.MBeanServerFactory;
import javax.management.ObjectName;
import java.awt.*;
import java.io.Serializable;
import java.util.*;
import java.util.List;
Expand Down Expand Up @@ -1044,11 +1042,13 @@ public OpResult showResult(OperationResult result, String errorMessageKey, boole
Validate.notNull(result, "Operation result must not be null.");
Validate.notNull(result.getStatus(), "Operation result status must not be null.");

Object scriptResult = executeResultScriptHook(result);
if (scriptResult instanceof OperationResult) {
result = (OperationResult) scriptResult;
OperationResult scriptResult = executeResultScriptHook(result);
if (scriptResult == null) {
return null;
}

result = scriptResult;

OpResult opResult = OpResult.getOpResult((PageBase) getPage(), result);
opResult.determineBackgroundTaskVisibility(this);
switch (opResult.getStatus()) {
Expand Down Expand Up @@ -1095,10 +1095,15 @@ private OperationResult executeResultScriptHook(OperationResult result) {
OperationResult topResult = task.getResult();
try {
ExpressionFactory factory = getExpressionFactory();
Expression expression = factory.makeExpression(expressionType, null, contextDesc, task, topResult);
PrismPropertyDefinition<String> outputDefinition = new PrismPropertyDefinitionImpl<>(
ExpressionConstants.OUTPUT_ELEMENT_NAME, OperationResultType.COMPLEX_TYPE, getPrismContext());
Expression expression = factory.makeExpression(expressionType, outputDefinition, contextDesc, task, topResult);

ExpressionVariables variables = new ExpressionVariables();
variables.addVariableDefinition(ExpressionConstants.VAR_INPUT, result);

OperationResultType resultType = result.createOperationResultType();

variables.addVariableDefinition(ExpressionConstants.VAR_INPUT, resultType);

ExpressionEvaluationContext context = new ExpressionEvaluationContext(null, variables, contextDesc, task, topResult);
PrismValueDeltaSetTriple<PrismPropertyValue<?>> outputTriple = expression.evaluate(context);
Expand All @@ -1115,9 +1120,18 @@ private OperationResult executeResultScriptHook(OperationResult result) {
throw new SchemaException("Expression " + contextDesc + " produced more than one value");
}

return values.iterator().next().getRealValue();
OperationResultType newResultType = values.iterator().next().getRealValue();
if (newResultType == null) {
return null;
}

return OperationResult.createOperationResult(newResultType);
} catch (SchemaException | ExpressionEvaluationException | ObjectNotFoundException e) {
result.recordFatalError(e);
topResult.recordFatalError(e);
if (StringUtils.isEmpty(result.getMessage())) {
topResult.setMessage("Couldn't process operation result script hook.");
}
topResult.addSubresult(result);
LoggingUtils.logUnexpectedException(LOGGER, contextDesc, e);
if (InternalsConfig.nonCriticalExceptionsAreFatal()) {
throw new SystemException(e.getMessage(), e);
Expand Down
Expand Up @@ -93,7 +93,7 @@ private List<PrismValue> getExpressionValues(List<JAXBElement<?>> elements, Pris
return null;
}

Item item = StaticExpressionUtil.parseValueElements(elements, definition, "gui", context);
Item item = StaticExpressionUtil.parseValueElements(elements, definition, "gui");
return item.getValues();
}

Expand Down
Expand Up @@ -34,7 +34,7 @@
*/
@PageDescriptor(url = "/result")
public class PageOperationResult extends PageBase {
private static final long serialVersionUID = 1L;
private static final long serialVersionUID = 1L;

private static final String ID_BACK = "back";

Expand All @@ -54,21 +54,24 @@ public PageOperationResult(OperationResult result) {
}

private void initLayout() {
if (result != null) {
OpResult opresult = showResult(result);
opresult.setShowMoreAll(true);
}
if (result != null) {
OpResult opresult = showResult(result);
if (opresult != null) {
opresult.setShowMoreAll(true);
} else {
warn(getString("PageOperationResult.noResultAvailable"));
}
}

AjaxButton back = new AjaxButton(ID_BACK, createStringResource("PageError.button.back")) {
private static final long serialVersionUID = 1L;
AjaxButton back = new AjaxButton(ID_BACK, createStringResource("PageError.button.back")) {
private static final long serialVersionUID = 1L;

@Override
@Override
public void onClick(AjaxRequestTarget target) {
backPerformed(target);
}
};
add(back);

}

private void backPerformed(AjaxRequestTarget target) {
Expand Down
Expand Up @@ -3797,4 +3797,5 @@ ExclusionPolicyConstraintPanel.exclusionTitle=Exclusion
ValuePolicyBasicPanel.valuePolicy.name=Name
ValuePolicyBasicPanel.valuePolicy.description=Description
comboInput.nullValid=Choose one
ContainerPanel.containerProperties=Properties
ContainerPanel.containerProperties=Properties
PageOperationResult.noResultAvailable=No operation result available. It was probably "deleted" via script hook.
Expand Up @@ -29,8 +29,8 @@
import com.evolveum.midpoint.prism.PrismPropertyDefinition;
import com.evolveum.midpoint.prism.PrismValue;
import com.evolveum.midpoint.prism.xnode.RootXNode;
import com.evolveum.midpoint.prism.xnode.XNode;
import com.evolveum.midpoint.schema.constants.SchemaConstants;
import com.evolveum.midpoint.util.DOMUtil;
import com.evolveum.midpoint.util.JAXBUtil;
import com.evolveum.midpoint.util.MiscUtil;
import com.evolveum.midpoint.util.exception.SchemaException;
Expand Down Expand Up @@ -80,7 +80,7 @@ public static Object getStaticOutput(ExpressionType expressionType, PrismPropert
public static <X> PrismProperty<X> getPropertyStatic(ExpressionType expressionType, PrismPropertyDefinition outputDefinition,
String contextDescription, PrismContext prismContext) throws SchemaException {
Collection<JAXBElement<?>> expressionEvaluatorElement = expressionType.getExpressionEvaluator();
return (PrismProperty) parseValueElements(expressionEvaluatorElement, outputDefinition, contextDescription, prismContext);
return (PrismProperty) parseValueElements(expressionEvaluatorElement, outputDefinition, contextDescription);
}

/**
Expand All @@ -92,32 +92,32 @@ public static <X> Collection<X> getPropertyStaticRealValues(ExpressionType expre
return output.getRealValues();
}


public static <IV extends PrismValue,ID extends ItemDefinition> Item<IV,ID> parseValueElements(Collection<?> valueElements, ID outputDefinition,
String contextDescription, PrismContext prismContext) throws SchemaException {

Item<IV,ID> output = null;

public static ItemDefinition<?> deriveOutputDefinitionFromValueElements(QName elementName, Collection<JAXBElement<?>> valueElements, String contextDescription, PrismContext prismContext)
throws SchemaException {
QName overallType = null;
for (Object valueElement: valueElements) {
if (!(valueElement instanceof JAXBElement<?>)) {
throw new SchemaException("Literal expression cannot handle element "+valueElement+" "+valueElement.getClass().getName()+" in "
+contextDescription);
RawType rawType = getRawType(valueElement, contextDescription);
QName currentType = rawType.getExplicitTypeName();
if (currentType != null) {
QName unified = prismContext.getSchemaRegistry().unifyTypes(overallType, currentType);
if (unified == null) {
throw new SchemaException("Couldn't unify types " + overallType + " and " + currentType + " in " + contextDescription);
}
overallType = unified;
}
QName valueElementName = JAXBUtil.getElementQName(valueElement);
if (!valueElementName.equals(SchemaConstants.C_VALUE)) {
throw new SchemaException("Literal expression cannot handle element <"+valueElementName + "> in "+ contextDescription);
}

JAXBElement<?> jaxbElement = (JAXBElement<?>)valueElement;
// not checking declaredType because it may be Object.class instead ... but actual type must be of RawType
if (jaxbElement.getValue() != null && !(jaxbElement.getValue() instanceof RawType)) {
throw new SchemaException("Literal expression cannot handle JAXBElement value type "+jaxbElement.getValue().getClass()+" in "
+contextDescription);
}

RawType rawType = (RawType)jaxbElement.getValue();
}
if (overallType == null) {
overallType = DOMUtil.XSD_STRING;
}
int maxOccurs = valueElements.size() > 1 ? -1 : 1;
return prismContext.getSchemaRegistry().createAdHocDefinition(elementName, overallType, 0, maxOccurs);
}

//Item<V> elementItem = xnodeProcessor.parseItem(rawType.getXnode(), outputDefinition.getName(), outputDefinition);
public static <IV extends PrismValue,ID extends ItemDefinition> Item<IV,ID> parseValueElements(Collection<?> valueElements,
ID outputDefinition, String contextDescription) throws SchemaException {
Item<IV,ID> output = null;
for (Object valueElement: valueElements) {
RawType rawType = getRawType(valueElement, contextDescription);
Item<IV,ID> elementItem = rawType.getParsedItem(outputDefinition);
if (output == null) {
output = elementItem;
Expand All @@ -128,6 +128,24 @@ public static <IV extends PrismValue,ID extends ItemDefinition> Item<IV,ID> pars
return output;
}

private static RawType getRawType(Object valueElement, String contextDescription) throws SchemaException {
if (!(valueElement instanceof JAXBElement<?>)) {
throw new SchemaException("Literal expression cannot handle element "+valueElement+" "+valueElement.getClass().getName()+" in "
+contextDescription);
}
QName valueElementName = JAXBUtil.getElementQName(valueElement);
if (!valueElementName.equals(SchemaConstants.C_VALUE)) {
throw new SchemaException("Literal expression cannot handle element <"+valueElementName + "> in "+ contextDescription);
}
JAXBElement<?> jaxbElement = (JAXBElement<?>)valueElement;
// not checking declaredType because it may be Object.class instead ... but actual type must be of RawType
if (jaxbElement.getValue() != null && !(jaxbElement.getValue() instanceof RawType)) {
throw new SchemaException("Literal expression cannot handle JAXBElement value type "+jaxbElement.getValue().getClass()+" in "
+contextDescription);
}
return (RawType)jaxbElement.getValue();
}

public static <IV extends PrismValue,ID extends ItemDefinition> List<JAXBElement<RawType>> serializeValueElements(Item<IV,ID> item, String contextDescription) throws SchemaException {
if (item == null) {
return null;
Expand Down
Expand Up @@ -688,4 +688,9 @@ public void trimTo(@NotNull Collection<ItemPath> paths) {
public boolean isShared() {
return false;
}

@Override
public boolean isReferenceMarker() {
return structuralObjectClassDefinition.isReferenceMarker();
}
}
Expand Up @@ -366,7 +366,12 @@ public boolean isContainerMarker() {
return refinedObjectClassDefinition.isContainerMarker();
}

@Override
@Override
public boolean isReferenceMarker() {
return refinedObjectClassDefinition.isReferenceMarker();
}

@Override
public boolean isPrimaryIdentifier(QName attrName) {
return refinedObjectClassDefinition.isPrimaryIdentifier(attrName);
}
Expand Down
Expand Up @@ -637,6 +637,11 @@ public QName getExtensionForType() {
return originalObjectClassDefinition.getExtensionForType(); // most probably null
}

@Override
public boolean isReferenceMarker() {
return originalObjectClassDefinition.isReferenceMarker(); // most probably false
}

@Override
public boolean isContainerMarker() {
return originalObjectClassDefinition.isContainerMarker(); // most probably false
Expand Down
Expand Up @@ -97,10 +97,10 @@ private void doRoundtrip(PrismProperty<?> origProperty, ItemDefinition propDef,
}
}

PrismProperty<String> parsedPropery = (PrismProperty<String>)(Item) StaticExpressionUtil.parseValueElements(valueElements, propDef, "here again", prismContext);
PrismProperty<String> parsedProperty = (PrismProperty<String>)(Item) StaticExpressionUtil.parseValueElements(valueElements, propDef, "here again");

// THEN
assertEquals("Roundtrip failed", origProperty, parsedPropery);
assertEquals("Roundtrip failed", origProperty, parsedProperty);
}

}
Expand Up @@ -64,6 +64,12 @@ public interface ComplexTypeDefinition extends TypeDefinition, LocalDefinitionSt
@Nullable
QName getExtensionForType();

/**
* Flag indicating whether this type was marked as "objectReference"
* in the original schema.
*/
boolean isReferenceMarker();

/**
* Flag indicating whether this type was marked as "container"
* in the original schema. Does not provide any information to
Expand Down
Expand Up @@ -45,6 +45,7 @@ public class ComplexTypeDefinitionImpl extends TypeDefinitionImpl implements Com

private static final long serialVersionUID = 2655797837209175037L;
@NotNull private final List<ItemDefinition> itemDefinitions = new ArrayList<>();
private boolean referenceMarker;
private boolean containerMarker;
private boolean objectMarker;
private boolean xsdAnyMarker;
Expand Down Expand Up @@ -99,6 +100,15 @@ public void setExtensionForType(QName extensionForType) {
this.extensionForType = extensionForType;
}

@Override
public boolean isReferenceMarker() {
return referenceMarker;
}

public void setReferenceMarker(boolean referenceMarker) {
this.referenceMarker = referenceMarker;
}

@Override
public boolean isContainerMarker() {
return containerMarker;
Expand Down
Expand Up @@ -97,8 +97,8 @@ public PrismContainer<?> getExtension() {

@Override
public PrismObjectValue<O> clone() {
PrismObjectValue<O> clone = new PrismObjectValue<O>(
getOriginType(), getOriginObject(), getParent(), getId(), null, this.prismContext, oid, version);
PrismObjectValue<O> clone = new PrismObjectValue<>(
getOriginType(), getOriginObject(), getParent(), getId(), complexTypeDefinition, this.prismContext, oid, version);
copyValues(clone);
return clone;
}
Expand Down
Expand Up @@ -275,6 +275,12 @@ public void addRealValue(T valueToAdd) {
addValue(pval);
}

public void addRealValues(T... valuesToAdd) {
for (T valueToAdd : valuesToAdd) {
addRealValue(valueToAdd);
}
}

public boolean deleteValues(Collection<PrismPropertyValue<T>> pValuesToDelete) {
checkMutability();
boolean changed = false;
Expand Down
Expand Up @@ -214,6 +214,9 @@ private ComplexTypeDefinition processComplexTypeDefinition(XSComplexType complex
if (isPropertyContainer(complexType)) {
ctd.setContainerMarker(true);
}
if (isObjectReference(complexType)) {
ctd.setReferenceMarker(true);
}

ctd.setDefaultNamespace(getDefaultNamespace(complexType));
ctd.setIgnoredNamespaces(getIgnoredNamespaces(complexType));
Expand Down
Expand Up @@ -169,4 +169,12 @@ <ID extends ItemDefinition> ComparisonResult compareDefinitions(@NotNull ID def1
throws SchemaException;

boolean isAssignableFrom(@NotNull QName superType, @NotNull QName subType);

/**
* Returns most specific common supertype for these two. If any of input params is null, it means it is ignored
* @return null if unification cannot be done (or if both input types are null)
*/
QName unifyTypes(QName type1, QName type2);

ItemDefinition<?> createAdHocDefinition(QName elementName, QName typeName, int minOccurs, int maxOccurs);
}

0 comments on commit e6ebad1

Please sign in to comment.