Skip to content

Commit

Permalink
EventHandler: generalization to PrismContainer (for audit import/export)
Browse files Browse the repository at this point in the history
  • Loading branch information
virgo47 committed Dec 3, 2021
1 parent 6a0c951 commit 7772278
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 123 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1056,7 +1056,7 @@ private VisibleEnableBehaviour getShoppingCartVisibleBehavior() {
public boolean isVisible() {
return !isErrorPage() && isSideMenuVisible() &&
(WebComponentUtil.isAuthorized(AuthorizationConstants.AUTZ_UI_SELF_REQUESTS_ASSIGNMENTS_URL, PageSelf.AUTH_SELF_ALL_URI)
&& getSessionStorage().getRoleCatalog().getAssignmentShoppingCart().size() > 0);
&& getSessionStorage().getRoleCatalog().getAssignmentShoppingCart().size() > 0);
}
};
}
Expand Down Expand Up @@ -1454,7 +1454,7 @@ public <T> void parseObject(String lexicalRepresentation, final Holder<T> object
if (isListOfObjects) {
objectHolder.setValue((T) list);
}
EventHandler handler = new EventHandler() {
EventHandler<PrismObject<Objectable>, Objectable> handler = new EventHandler<>() {

@Override
public EventResult preMarshall(Element objectElement, Node postValidationTree,
Expand All @@ -1463,8 +1463,8 @@ public EventResult preMarshall(Element objectElement, Node postValidationTree,
}

@Override
public <O extends Objectable> EventResult postMarshall(PrismObject<O> object, Element objectElement,
OperationResult objectResult) {
public EventResult postMarshall(
PrismObject<Objectable> object, Element objectElement, OperationResult objectResult) {
if (isListOfObjects) {
list.add(object);
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
/*
* Copyright (c) 2010-2013 Evolveum and contributors
* Copyright (C) 2010-2021 Evolveum and contributors
*
* This work is dual-licensed under the Apache License 2.0
* and European Union Public License. See LICENSE file for details.
*/

package com.evolveum.midpoint.common.validator;

import com.evolveum.midpoint.prism.Objectable;
import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.schema.result.OperationResult;

import org.w3c.dom.Element;
import org.w3c.dom.Node;

import com.evolveum.midpoint.prism.Containerable;
import com.evolveum.midpoint.prism.PrismContainer;
import com.evolveum.midpoint.schema.result.OperationResult;

/**
* Set of callback methods used to convey information from the validator to the "working" code.
*
Expand All @@ -23,7 +23,7 @@
*
* @author Radovan Semancik
*/
public interface EventHandler {
public interface EventHandler<T extends PrismContainer<C>, C extends Containerable> {

/**
* Call-back called after deserializing to DOM and static schema validation but before unmarshal to JAXB.
Expand All @@ -47,16 +47,14 @@ public interface EventHandler {
* @param objectResult Operation result for this object
* @return true if the process should continue, false if it should stop
*/
<T extends Objectable> EventResult postMarshall(PrismObject<T> object, Element objectElement, OperationResult objectResult);
EventResult postMarshall(T object, Element objectElement, OperationResult objectResult);

/**
* Call-back to handle global errors.
*
* This callback will be called with any error that cannot be attributed to any particular object.
*
* @param currentResult Operation result pointing to the particular error.
* @return true if the process should continue, false if it should stop
*/
void handleGlobalError(OperationResult currentResult);

}
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
/*
* Copyright (c) 2010-2013 Evolveum and contributors
* Copyright (C) 2010-2021 Evolveum and contributors
*
* This work is dual-licensed under the Apache License 2.0
* and European Union Public License. See LICENSE file for details.
*/

package com.evolveum.midpoint.validator.test;

import static org.testng.AssertJUnit.*;
Expand Down Expand Up @@ -61,7 +60,7 @@ public void setup() throws SchemaException, SAXException, IOException {
@Test
public void resource1Valid() throws Exception {
OperationResult result = createOperationResult();
EventHandler handler = new EventHandler() {
EventHandler<PrismObject<Objectable>, Objectable> handler = new EventHandler<>() {

@Override
public EventResult preMarshall(Element objectElement, Node postValidationTree,
Expand All @@ -70,16 +69,17 @@ public EventResult preMarshall(Element objectElement, Node postValidationTree,
}

@Override
public <T extends Objectable> EventResult postMarshall(PrismObject<T> object, Element objectElement,
OperationResult objectResult) {
public EventResult postMarshall(
PrismObject<Objectable> object, Element objectElement, OperationResult objectResult) {
displayDumpable("Validating resource:", object);
object.checkConsistence();

PrismContainer<?> extensionContainer = object.getExtension();
PrismProperty<Integer> menProp = extensionContainer.findProperty(new ItemName("http://myself.me/schemas/whatever", "menOnChest"));
PrismProperty<Integer> menProp = extensionContainer.findProperty(
new ItemName("http://myself.me/schemas/whatever", "menOnChest"));
assertNotNull("No men on a dead man chest!", menProp);
assertEquals("Wrong number of men on a dead man chest", (Integer) 15, menProp.getAnyRealValue());
PrismPropertyDefinition menPropDef = menProp.getDefinition();
PrismPropertyDefinition<?> menPropDef = menProp.getDefinition();
assertNotNull("Men on a dead man chest NOT defined", menPropDef);
assertEquals("Wrong type for men on a dead man chest definition", DOMUtil.XSD_INT, menPropDef.getTypeName());
assertTrue("Men on a dead man chest definition not dynamic", menPropDef.isDynamic());
Expand All @@ -103,16 +103,16 @@ public void handlerTest() throws Exception {
final List<String> postMarshallHandledOids = new ArrayList<>();
final List<String> preMarshallHandledOids = new ArrayList<>();

EventHandler handler = new EventHandler() {

EventHandler<PrismObject<Objectable>, Objectable> handler = new EventHandler<>() {
@Override
public EventResult preMarshall(Element objectElement, Node postValidationTree, OperationResult objectResult) {
preMarshallHandledOids.add(objectElement.getAttribute("oid"));
return EventResult.cont();
}

@Override
public <T extends Objectable> EventResult postMarshall(PrismObject<T> object, Element objectElement, OperationResult objectResult) {
public EventResult postMarshall(
PrismObject<Objectable> object, Element objectElement, OperationResult objectResult) {
displayDumpable("Handler processing " + object + ", result:", objectResult);
postMarshallHandledOids.add(object.getOid());
return EventResult.cont();
Expand Down Expand Up @@ -215,10 +215,10 @@ public void noName() throws Exception {
}

private void validateFile(String filename, OperationResult result) throws FileNotFoundException {
validateFile(filename, (EventHandler) null, result);
validateFile(filename, (EventHandler<?, ?>) null, result);
}

private void validateFile(String filename, EventHandler handler, OperationResult result) throws FileNotFoundException {
private void validateFile(String filename, EventHandler<?, ?> handler, OperationResult result) throws FileNotFoundException {
LegacyValidator validator = new LegacyValidator(PrismTestUtil.getPrismContext());
if (handler != null) {
validator.setHandler(handler);
Expand Down

0 comments on commit 7772278

Please sign in to comment.