Skip to content

Commit

Permalink
SimpleFocalObjectNotifier and FocusType filter (MID-2044).
Browse files Browse the repository at this point in the history
  • Loading branch information
mederly committed Oct 2, 2014
1 parent 2c1c020 commit a20ecdb
Show file tree
Hide file tree
Showing 9 changed files with 335 additions and 131 deletions.
Expand Up @@ -8784,7 +8784,6 @@
Focus types supported by this handler. (Default: all)
Types not listed are filtered out: not handled by this handler nor any of its successors.
(Relevant only for model-generated events.)
NOT IMPLEMENTED YET.
</xsd:documentation>
</xsd:annotation>
</xsd:element>
Expand Down Expand Up @@ -8816,6 +8815,13 @@
</xsd:documentation>
</xsd:annotation>
</xsd:element>
<xsd:element name="simpleFocalObjectNotifier" type="tns:SimpleFocalObjectNotifierType" minOccurs="0" maxOccurs="unbounded">
<xsd:annotation>
<xsd:documentation>
TODO
</xsd:documentation>
</xsd:annotation>
</xsd:element>
<xsd:element name="simpleResourceObjectNotifier" type="tns:SimpleResourceObjectNotifierType" minOccurs="0" maxOccurs="unbounded">
<xsd:annotation>
<xsd:documentation>
Expand Down Expand Up @@ -9075,6 +9081,18 @@
</xsd:complexType>

<xsd:complexType name="SimpleUserNotifierType">
<xsd:annotation>
<xsd:documentation>
TODO
</xsd:documentation>
</xsd:annotation>
<xsd:complexContent>
<xsd:extension base="tns:SimpleFocalObjectNotifierType">
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>

<xsd:complexType name="SimpleFocalObjectNotifierType">
<xsd:annotation>
<xsd:documentation>
TODO
Expand Down
Expand Up @@ -20,6 +20,7 @@

import com.evolveum.midpoint.common.refinery.ResourceShadowDiscriminator;
import com.evolveum.midpoint.model.api.ProgressInformation;
import com.evolveum.midpoint.prism.PrismContext;
import com.evolveum.midpoint.util.DebugDumpable;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType;

Expand All @@ -40,4 +41,6 @@ public interface ModelContext<F extends ObjectType> extends Serializable, DebugD
Class<F> getFocusClass();

void reportProgress(ProgressInformation progress);

PrismContext getPrismContext(); // use with care
}
Expand Up @@ -19,6 +19,8 @@
import com.evolveum.midpoint.model.api.context.ModelContext;
import com.evolveum.midpoint.model.api.context.ModelElementContext;
import com.evolveum.midpoint.model.api.context.ModelProjectionContext;
import com.evolveum.midpoint.prism.PrismContainerDefinition;
import com.evolveum.midpoint.prism.PrismContext;
import com.evolveum.midpoint.prism.delta.ChangeType;
import com.evolveum.midpoint.prism.delta.ObjectDelta;
import com.evolveum.midpoint.schema.ObjectDeltaOperation;
Expand All @@ -29,8 +31,9 @@
import com.evolveum.midpoint.xml.ns._public.common.common_3.EventCategoryType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.EventOperationType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.EventStatusType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.UserType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.FocusType;

import javax.xml.namespace.QName;
import java.util.ArrayList;
import java.util.List;

Expand Down Expand Up @@ -140,10 +143,10 @@ public boolean isCategoryType(EventCategoryType eventCategoryType) {
return eventCategoryType == EventCategoryType.MODEL_EVENT;
}

public List<ObjectDelta<UserType>> getUserDeltas() {
List<ObjectDelta<UserType>> retval = new ArrayList<ObjectDelta<UserType>>();
public List<ObjectDelta<FocusType>> getFocusDeltas() {
List<ObjectDelta<FocusType>> retval = new ArrayList<>();
Class c = modelContext.getFocusClass();
if (c != null && UserType.class.isAssignableFrom(c)) {
if (c != null && FocusType.class.isAssignableFrom(c)) {
for (Object o : getFocusExecutedDeltas()) {
ObjectDeltaOperation objectDeltaOperation = (ObjectDeltaOperation) o;
retval.add(objectDeltaOperation.getObjectDelta());
Expand All @@ -152,7 +155,29 @@ public List<ObjectDelta<UserType>> getUserDeltas() {
return retval;
}

public ObjectDelta<UserType> getSummarizedUserDeltas() throws SchemaException {
return ObjectDelta.summarize(getUserDeltas());
public ObjectDelta<? extends FocusType> getSummarizedFocusDeltas() throws SchemaException {
return ObjectDelta.summarize(getFocusDeltas());
}

public boolean hasFocusOfType(Class<? extends FocusType> clazz) {
return clazz.isAssignableFrom(getFocusContext().getObjectTypeClass());
}

public boolean hasFocusOfType(QName focusType) {
PrismContext prismContext = getModelContext().getPrismContext();
if (prismContext == null) {
throw new IllegalStateException("No prismContext in model context");
}
PrismContainerDefinition pcd = prismContext.getSchemaRegistry().findContainerDefinitionByType(focusType);
if (pcd == null) {
LOGGER.warn("Couldn't find definition for type " + focusType);
return false;
}
Class expectedClass = pcd.getCompileTimeClass();
if (expectedClass == null) {
LOGGER.warn("Couldn't find class for type " + focusType);
return false;
}
return hasFocusOfType(expectedClass);
}
}
Expand Up @@ -178,6 +178,7 @@ private void formatContainerValue(StringBuilder sb, String prefix, PrismContaine
String prefixSubContainer = prefix + " ";
formatContainerValue(sb, prefixSubContainer, subContainerValue, mightBeRemoved, hiddenPaths, showOperationalAttributes);
}
sb.append("\n");
} else {
sb.append("Unexpected Item type: ");
sb.append(item);
Expand Down
Expand Up @@ -22,13 +22,15 @@
import com.evolveum.midpoint.notifications.impl.helpers.CategoryFilterHelper;
import com.evolveum.midpoint.notifications.impl.helpers.ChainHelper;
import com.evolveum.midpoint.notifications.impl.helpers.ExpressionFilterHelper;
import com.evolveum.midpoint.notifications.impl.helpers.FocusTypeFilterHelper;
import com.evolveum.midpoint.notifications.impl.helpers.ForkHelper;
import com.evolveum.midpoint.notifications.impl.helpers.KindIntentFilterHelper;
import com.evolveum.midpoint.notifications.impl.helpers.OperationFilterHelper;
import com.evolveum.midpoint.notifications.impl.helpers.StatusFilterHelper;
import com.evolveum.midpoint.notifications.impl.notifiers.AccountPasswordNotifier;
import com.evolveum.midpoint.notifications.impl.notifiers.GeneralNotifier;
import com.evolveum.midpoint.notifications.impl.notifiers.SimpleResourceObjectNotifier;
import com.evolveum.midpoint.notifications.impl.notifiers.SimpleFocalObjectNotifier;
import com.evolveum.midpoint.notifications.impl.notifiers.SimpleUserNotifier;
import com.evolveum.midpoint.notifications.impl.notifiers.SimpleWorkflowNotifier;
import com.evolveum.midpoint.notifications.impl.notifiers.UserPasswordNotifier;
Expand Down Expand Up @@ -71,6 +73,9 @@ public class AggregatedEventHandler extends BaseHandler {
@Autowired
private KindIntentFilterHelper kindIntentFilter;

@Autowired
private FocusTypeFilterHelper focusTypeFilterHelper;

@Autowired
private ExpressionFilterHelper expressionFilter;

Expand All @@ -80,6 +85,9 @@ public class AggregatedEventHandler extends BaseHandler {
@Autowired
private ForkHelper forkHelper;

@Autowired
protected SimpleFocalObjectNotifier simpleFocalObjectNotifier;

@Autowired
protected SimpleUserNotifier simpleUserNotifier;

Expand Down Expand Up @@ -114,11 +122,13 @@ public boolean processEvent(Event event, EventHandlerType eventHandlerType, Noti
operationFilter.processEvent(event, eventHandlerType, notificationManager, task, result) &&
statusFilter.processEvent(event, eventHandlerType, notificationManager, task, result) &&
kindIntentFilter.processEvent(event, eventHandlerType, notificationManager, task, result) &&
focusTypeFilterHelper.processEvent(event, eventHandlerType, notificationManager, task, result) &&
expressionFilter.processEvent(event, eventHandlerType, notificationManager, task, result) &&
chainHelper.processEvent(event, eventHandlerType, notificationManager, task, result) &&
forkHelper.processEvent(event, eventHandlerType, notificationManager, task, result);

shouldContinue = shouldContinue && processNotifiers(event, eventHandlerType.getSimpleUserNotifier(), notificationManager, task, result);
shouldContinue = shouldContinue && processNotifiers(event, eventHandlerType.getSimpleFocalObjectNotifier(), notificationManager, task, result);
shouldContinue = shouldContinue && processNotifiers(event, eventHandlerType.getSimpleResourceObjectNotifier(), notificationManager, task, result);
shouldContinue = shouldContinue && processNotifiers(event, eventHandlerType.getSimpleWorkflowNotifier(), notificationManager, task, result);
shouldContinue = shouldContinue && processNotifiers(event, eventHandlerType.getUserPasswordNotifier(), notificationManager, task, result);
Expand Down
@@ -0,0 +1,68 @@
/*
* Copyright (c) 2010-2014 Evolveum
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.evolveum.midpoint.notifications.impl.helpers;

import com.evolveum.midpoint.notifications.api.NotificationManager;
import com.evolveum.midpoint.notifications.api.events.Event;
import com.evolveum.midpoint.notifications.api.events.ModelEvent;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.task.api.Task;
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.midpoint.xml.ns._public.common.common_3.EventHandlerType;
import org.springframework.stereotype.Component;

import javax.xml.namespace.QName;

/**
* @author mederly
*/
@Component
public class FocusTypeFilterHelper extends BaseHelper {

private static final Trace LOGGER = TraceManager.getTrace(FocusTypeFilterHelper.class);

@Override
public boolean processEvent(Event event, EventHandlerType eventHandlerType, NotificationManager notificationManager,
Task task, OperationResult result) {

if (eventHandlerType.getFocusType().isEmpty()) {
return true;
}

if (!(event instanceof ModelEvent)) {
return true; // or should we return false?
}
ModelEvent modelEvent = (ModelEvent) event;

logStart(LOGGER, event, eventHandlerType, eventHandlerType.getStatus());

boolean retval = false;

for (QName focusType : eventHandlerType.getFocusType()) {
if (focusType == null) {
LOGGER.warn("Filtering on null focusType; filter = " + eventHandlerType);
} else if (modelEvent.hasFocusOfType(focusType)) {
retval = true;
break;
}
}

logEnd(LOGGER, event, eventHandlerType, retval);
return retval;
}
}

0 comments on commit a20ecdb

Please sign in to comment.