Skip to content

Commit

Permalink
Merge branch 'master' of github.com:Evolveum/midpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
katkav committed Sep 28, 2015
2 parents de96bfc + a6b093a commit c9fe1ef
Show file tree
Hide file tree
Showing 28 changed files with 3,254 additions and 124 deletions.
Expand Up @@ -2523,7 +2523,7 @@ TaskStatePanel.message.timeInfoWithDurationAndAgo={0} ({1} ago - in {2} ms)
TaskStatePanel.objectsProcessedFailure=Objects failed to be processed
TaskStatePanel.objectsProcessedSuccess=Objects successfully processed
TaskStatePanel.objectsTotal=Total objects processed
TaskStatePanel.opResult=Operation result#
TaskStatePanel.opResult=Operation result
TaskStatePanel.progress=Progress
TaskStatePanel.statistics=Operational statistics
TaskStatePanel.subtaskName=Name
Expand Down
2,654 changes: 2,654 additions & 0 deletions gui/admin-gui/src/main/resources/localization/Midpoint_de_DE.properties

Large diffs are not rendered by default.

Expand Up @@ -16,7 +16,10 @@

package com.evolveum.midpoint.schema.statistics;

import com.evolveum.midpoint.prism.Objectable;
import com.evolveum.midpoint.prism.PrismContext;
import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.prism.PrismObjectDefinition;
import com.evolveum.midpoint.prism.polystring.PolyString;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.OrgType;
Expand Down Expand Up @@ -55,4 +58,22 @@ public static <O extends ObjectType> String getDisplayName(PrismObject<O> object
return objectable.getClass().getSimpleName() + " " + objectable.getName();
}
}

public static QName getObjectType(ObjectType objectType, PrismContext prismContext) {
if (objectType == null) {
return null;
}
PrismObjectDefinition def = objectType.asPrismObject().getDefinition();
if (def == null) {
Class<? extends Objectable> clazz = objectType.asPrismObject().getCompileTimeClass();
if (clazz == null) {
return null;
}
def = prismContext.getSchemaRegistry().findObjectDefinitionByCompileTimeClass(clazz);
if (def == null) {
return ObjectType.COMPLEX_TYPE;
}
}
return def.getTypeName();
}
}
255 changes: 192 additions & 63 deletions infra/schema/src/main/resources/xml/ns/public/common/common-3.xsd

Large diffs are not rendered by default.

Expand Up @@ -52,6 +52,7 @@
import com.evolveum.midpoint.prism.delta.PrismValueDeltaSetTriple;
import com.evolveum.midpoint.repo.api.RepositoryService;
import com.evolveum.midpoint.schema.constants.ExpressionConstants;
import com.evolveum.midpoint.schema.constants.ObjectTypes;
import com.evolveum.midpoint.schema.constants.SchemaConstants;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.schema.util.ObjectResolver;
Expand Down Expand Up @@ -423,12 +424,17 @@ private void evaluateTarget(EvaluatedAssignmentImpl<F> assignment, AssignmentPat
if (targetType instanceof AbstractRoleType) {
boolean roleConditionTrue = evaluateAbstractRole(assignment, assignmentPathSegment, evaluateOld, mode, isValid, (AbstractRoleType)targetType, source, sourceDescription,
assignmentPath, task, result);
if (roleConditionTrue && mode != PlusMinusZero.MINUS && targetType instanceof OrgType && assignmentPath.getEvaluationOrder() == 1) {
if (roleConditionTrue && mode != PlusMinusZero.MINUS && assignmentPath.getEvaluationOrder() == 1) {
PrismReferenceValue refVal = new PrismReferenceValue();
refVal.setObject(targetType.asPrismObject());
refVal.setTargetType(ObjectTypes.getObjectType(targetType.getClass()).getTypeQName());
refVal.setRelation(relation);
assignment.addOrgRefVal(refVal);
}
refVal.setTargetName(targetType.getName().toPolyString());
assignment.addMembershipRefVal(refVal);
if (targetType instanceof OrgType) {
assignment.addOrgRefVal(refVal);
}
}
} else {
throw new SchemaException("Unknown assignment target type "+ObjectTypeUtil.toShortString(targetType)+" in "+sourceDescription);
}
Expand Down
Expand Up @@ -60,6 +60,7 @@ public class EvaluatedAssignmentImpl<F extends FocusType> implements EvaluatedAs
private DeltaSetTriple<Construction<F>> constructions;
private DeltaSetTriple<EvaluatedAbstractRoleImpl> roles;
private Collection<PrismReferenceValue> orgRefVals;
private Collection<PrismReferenceValue> membershipRefVals;
private Collection<Authorization> authorizations;
private Collection<Mapping<? extends PrismPropertyValue<?>,? extends PrismPropertyDefinition<?>>> focusMappings;
private PrismObject<?> target;
Expand All @@ -72,6 +73,7 @@ public EvaluatedAssignmentImpl() {
constructions = new DeltaSetTriple<>();
roles = new DeltaSetTriple<>();
orgRefVals = new ArrayList<>();
membershipRefVals = new ArrayList<>();
authorizations = new ArrayList<>();
focusMappings = new ArrayList<>();
}
Expand Down Expand Up @@ -154,6 +156,14 @@ public Collection<PrismReferenceValue> getOrgRefVals() {
public void addOrgRefVal(PrismReferenceValue org) {
orgRefVals.add(org);
}

public Collection<PrismReferenceValue> getMembershipRefVals() {
return membershipRefVals;
}

public void addMembershipRefVal(PrismReferenceValue org) {
membershipRefVals.add(org);
}

/* (non-Javadoc)
* @see com.evolveum.midpoint.model.impl.lens.EvaluatedAssignment#getAuthorizations()
Expand Down
Expand Up @@ -18,9 +18,11 @@

import java.util.ArrayList;
import java.util.Collection;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
Expand Down Expand Up @@ -62,6 +64,7 @@
import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.prism.PrismObjectDefinition;
import com.evolveum.midpoint.prism.PrismPropertyValue;
import com.evolveum.midpoint.prism.PrismReference;
import com.evolveum.midpoint.prism.PrismReferenceDefinition;
import com.evolveum.midpoint.prism.PrismReferenceValue;
import com.evolveum.midpoint.prism.PrismValue;
Expand All @@ -72,6 +75,7 @@
import com.evolveum.midpoint.prism.delta.ObjectDelta;
import com.evolveum.midpoint.prism.delta.PlusMinusZero;
import com.evolveum.midpoint.prism.delta.PrismValueDeltaSetTriple;
import com.evolveum.midpoint.prism.delta.ReferenceDelta;
import com.evolveum.midpoint.prism.path.IdItemPathSegment;
import com.evolveum.midpoint.prism.path.ItemPath;
import com.evolveum.midpoint.prism.path.NameItemPathSegment;
Expand All @@ -89,6 +93,7 @@
import com.evolveum.midpoint.schema.util.ObjectTypeUtil;
import com.evolveum.midpoint.schema.util.SchemaDebugUtil;
import com.evolveum.midpoint.task.api.Task;
import com.evolveum.midpoint.util.MiscUtil;
import com.evolveum.midpoint.util.QNameUtil;
import com.evolveum.midpoint.util.exception.CommunicationException;
import com.evolveum.midpoint.util.exception.ConfigurationException;
Expand Down Expand Up @@ -1608,5 +1613,65 @@ private <V extends PrismValue, D extends ItemDefinition, F extends FocusType> XM

return nextRecomputeTime;
}

public <F extends ObjectType> void processMembershipRef(LensContext<F> context,
OperationResult result) throws SchemaException {
LensFocusContext<F> focusContext = context.getFocusContext();
if (focusContext == null || !FocusType.class.isAssignableFrom(focusContext.getObjectTypeClass())) {
return;
}
Collection<PrismReferenceValue> newValues = new ArrayList<>();
DeltaSetTriple<EvaluatedAssignmentImpl> evaluatedAssignmentTriple = context.getEvaluatedAssignmentTriple();
if (evaluatedAssignmentTriple == null) {
return;
}

for (EvaluatedAssignmentImpl<?> evalAssignment: evaluatedAssignmentTriple.getNonNegativeValues()) {
for (PrismReferenceValue membershipRefVal: evalAssignment.getMembershipRefVals()) {
boolean found = false;
for (PrismReferenceValue exVal: newValues) {
if (exVal.getOid().equals(membershipRefVal.getOid())) {
found = true;
break;
}
}
if (!found) {
PrismReferenceValue ref = membershipRefVal.clone();
ref.setRelation(null);
newValues.add(ref);
}
}
}

PrismObject<F> focusOld = focusContext.getObjectOld();
if (focusOld == null) {
if (newValues.isEmpty()) {
return;
}
} else {
PrismReference roleMemPrismRef = focusOld.findReference(FocusType.F_ROLE_MEMBERSHIP_REF);
if (roleMemPrismRef == null || roleMemPrismRef.isEmpty()) {
if (newValues.isEmpty()) {
return;
}
} else {
Comparator<PrismReferenceValue> comparator = new Comparator<PrismReferenceValue>() {
@Override
public int compare(PrismReferenceValue a, PrismReferenceValue b) {
return a.getOid().compareTo(b.getOid());
}
};
if (MiscUtil.unorderedCollectionEquals(newValues, roleMemPrismRef.getValues(), comparator)) {
return;
}
}
}

PrismReferenceDefinition membershipRefDef = focusContext.getObjectDefinition().findItemDefinition(FocusType.F_ROLE_MEMBERSHIP_REF,
PrismReferenceDefinition.class);
ReferenceDelta membershipRefDelta = new ReferenceDelta(FocusType.F_ROLE_MEMBERSHIP_REF, membershipRefDef,
focusContext.getObjectDefinition().getPrismContext());
membershipRefDelta.setValuesToReplace(newValues);
focusContext.swallowToSecondaryDelta(membershipRefDelta);
}
}
Expand Up @@ -224,6 +224,7 @@ private <F extends FocusType> void processFocusFocus(LensContext<F> context, Str

assignmentProcessor.processAssignmentsProjections(context, now, task, result);
assignmentProcessor.processOrgAssignments(context, result);
assignmentProcessor.processMembershipRef(context, result);
context.recompute();

assignmentProcessor.checkForAssignmentConflicts(context, result);
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010-2014 Evolveum
* Copyright (c) 2010-2015 Evolveum
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Expand Up @@ -19,6 +19,7 @@
import com.evolveum.midpoint.model.api.ScriptExecutionException;
import com.evolveum.midpoint.model.api.ScriptExecutionResult;
import com.evolveum.midpoint.model.api.ScriptingService;
import com.evolveum.midpoint.model.impl.sync.TaskHandlerUtil;
import com.evolveum.midpoint.prism.PrismProperty;
import com.evolveum.midpoint.schema.constants.SchemaConstants;
import com.evolveum.midpoint.schema.result.OperationResult;
Expand Down Expand Up @@ -71,6 +72,8 @@ public TaskRunResult run(Task task) {
}

try {
TaskHandlerUtil.initAllStatistics(task, true, false);
task.setProgress(0);
ScriptExecutionResult executionResult = scriptingService.evaluateExpression(executeScriptProperty.getValue().getValue().getScriptingExpression().getValue(), task, result);
LOGGER.debug("Execution output: {} item(s)", executionResult.getDataOutput().size());
LOGGER.debug("Execution result:\n", executionResult.getConsoleOutput());
Expand All @@ -80,10 +83,13 @@ public TaskRunResult run(Task task) {
result.recordFatalError("Couldn't execute script: " + e.getMessage(), e);
LoggingUtils.logException(LOGGER, "Couldn't execute script", e);
runResult.setRunResultStatus(TaskRunResult.TaskRunResultStatus.PERMANENT_ERROR);
} finally {
TaskHandlerUtil.storeAllStatistics(task);
}

task.getResult().computeStatus();
runResult.setOperationResult(task.getResult());
runResult.setProgress(task.getProgress()); // incremented directly in actions implementations
return runResult;
}

Expand Down
Expand Up @@ -175,6 +175,7 @@ public ExecutionContext evaluateExpression(ExecuteScriptType executeScript, Task
return evaluateExpression(executeScript.getScriptingExpression().getValue(), task, result);
}

// use in tests only (we need the task at least to report progress/statistics)
public ExecutionContext evaluateExpression(ScriptingExpressionType expression, OperationResult result) throws ScriptExecutionException {
Task task = taskManager.createTaskInstance();
return evaluateExpression(expression, task, result);
Expand Down
Expand Up @@ -61,7 +61,14 @@ public Data execute(ActionExpressionType expression, Data input, ExecutionContex
if (item instanceof PrismObject) {
PrismObject<? extends ObjectType> prismObject = (PrismObject) item;
ObjectType objectType = prismObject.asObjectable();
operationsHelper.applyDelta(createAddDelta(objectType), operationsHelper.createExecutionOptions(raw), context, result);
long started = operationsHelper.recordStart(context, objectType);
try {
operationsHelper.applyDelta(createAddDelta(objectType), operationsHelper.createExecutionOptions(raw), context, result);
operationsHelper.recordEnd(context, objectType, started, null);
} catch (Throwable ex) {
operationsHelper.recordEnd(context, objectType, started, ex);
throw ex; // TODO think about this
}
context.println("Added " + item.toString() + rawSuffix(raw));
} else {
throw new ScriptExecutionException("Item couldn't be added, because it is not a PrismObject: " + item.toString());
Expand Down
Expand Up @@ -93,7 +93,14 @@ public Data execute(ActionExpressionType expression, Data input, ExecutionContex
if (item instanceof PrismObject && ((PrismObject) item).asObjectable() instanceof FocusType) {
PrismObject<? extends ObjectType> prismObject = (PrismObject) item;
ObjectType objectType = prismObject.asObjectable();
operationsHelper.applyDelta(createDelta(objectType, resources, roles), operationsHelper.createExecutionOptions(raw), context, result);
long started = operationsHelper.recordStart(context, objectType);
try {
operationsHelper.applyDelta(createDelta(objectType, resources, roles), operationsHelper.createExecutionOptions(raw), context, result);
operationsHelper.recordEnd(context, objectType, started, null);
} catch (Throwable ex) {
operationsHelper.recordEnd(context, objectType, started, ex);
throw ex; // TODO reconsider this
}
context.println("Modified " + item.toString() + rawSuffix(raw));
} else {
throw new ScriptExecutionException("Item could not be modified, because it is not a PrismObject of FocusType: " + item.toString());
Expand Down
Expand Up @@ -61,7 +61,14 @@ public Data execute(ActionExpressionType expression, Data input, ExecutionContex
if (item instanceof PrismObject) {
PrismObject<? extends ObjectType> prismObject = (PrismObject) item;
ObjectType objectType = prismObject.asObjectable();
operationsHelper.applyDelta(createDeleteDelta(objectType), operationsHelper.createExecutionOptions(raw), context, result);
long started = operationsHelper.recordStart(context, objectType);
try {
operationsHelper.applyDelta(createDeleteDelta(objectType), operationsHelper.createExecutionOptions(raw), context, result);
operationsHelper.recordEnd(context, objectType, started, null);
} catch (Throwable ex) {
operationsHelper.recordEnd(context, objectType, started, ex);
throw ex; // TODO think about this
}
context.println("Deleted " + item.toString() + rawSuffix(raw));
} else {
throw new ScriptExecutionException("Item couldn't be deleted, because it is not a PrismObject: " + item.toString());
Expand Down
Expand Up @@ -76,9 +76,12 @@ public Data execute(ActionExpressionType expression, Data input, ExecutionContex
if (item instanceof PrismObject && ((PrismObject) item).asObjectable() instanceof ConnectorHostType) {
PrismObject<ConnectorHostType> connectorHostTypePrismObject = (PrismObject) item;
Set<ConnectorType> newConnectors;
long started = operationsHelper.recordStart(context, connectorHostTypePrismObject.asObjectable());
try {
newConnectors = modelService.discoverConnectors(connectorHostTypePrismObject.asObjectable(), context.getTask(), result);
} catch (CommunicationException | SecurityViolationException | SchemaException | ConfigurationException | ObjectNotFoundException e) {
operationsHelper.recordEnd(context, connectorHostTypePrismObject.asObjectable(), started, null);
} catch (CommunicationException | SecurityViolationException | SchemaException | ConfigurationException | ObjectNotFoundException | RuntimeException e) {
operationsHelper.recordEnd(context, connectorHostTypePrismObject.asObjectable(), started, e);
throw new ScriptExecutionException("Couldn't discover connectors from " + connectorHostTypePrismObject, e);
}
context.println("Discovered " + newConnectors.size() + " new connector(s) from " + connectorHostTypePrismObject);
Expand Down
Expand Up @@ -68,14 +68,21 @@ public Data execute(ActionExpressionType expression, Data input, ExecutionContex
if (item instanceof PrismObject) {
PrismObject<? extends ObjectType> prismObject = (PrismObject) item;
ObjectType objectType = prismObject.asObjectable();
if (objectType instanceof FocusType) {
operationsHelper.applyDelta(createEnableDisableDelta((FocusType) objectType, isEnable), context, result);
context.println((isEnable ? "Enabled " : "Disabled ") + item.toString());
} else if (objectType instanceof ShadowType) {
operationsHelper.applyDelta(createEnableDisableDelta((ShadowType) objectType, isEnable), context, result);
context.println((isEnable ? "Enabled " : "Disabled ") + item.toString());
} else {
throw new ScriptExecutionException("Item could not be enabled/disabled, because it is not a FocusType nor ShadowType: " + item.toString());
long started = operationsHelper.recordStart(context, objectType);
try {
if (objectType instanceof FocusType) {
operationsHelper.applyDelta(createEnableDisableDelta((FocusType) objectType, isEnable), context, result);
context.println((isEnable ? "Enabled " : "Disabled ") + item.toString());
} else if (objectType instanceof ShadowType) {
operationsHelper.applyDelta(createEnableDisableDelta((ShadowType) objectType, isEnable), context, result);
context.println((isEnable ? "Enabled " : "Disabled ") + item.toString());
} else {
throw new ScriptExecutionException("Item could not be enabled/disabled, because it is not a FocusType nor ShadowType: " + item.toString());
}
operationsHelper.recordEnd(context, objectType, started, null);
} catch (Throwable ex) {
operationsHelper.recordEnd(context, objectType, started, ex);
throw ex;
}
} else {
throw new ScriptExecutionException("Item could not be enabled/disabled, because it is not a PrismObject: " + item.toString());
Expand Down

0 comments on commit c9fe1ef

Please sign in to comment.