Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into feature/upgrade-pro…
Browse files Browse the repository at this point in the history
…cess
  • Loading branch information
1azyman committed May 4, 2023
2 parents d97b96c + 6707aac commit 0111bcc
Show file tree
Hide file tree
Showing 23 changed files with 205 additions and 193 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@
import com.evolveum.midpoint.web.component.prism.ValueStatus;
import com.evolveum.midpoint.web.component.util.VisibleBehaviour;
import com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour;
import com.evolveum.midpoint.web.page.admin.certification.handlers.CertGuiHandlerRegistry;
import com.evolveum.midpoint.web.page.error.PageError404;
import com.evolveum.midpoint.web.security.MidPointApplication;
import com.evolveum.midpoint.web.security.MidPointAuthWebSession;
Expand Down Expand Up @@ -246,6 +247,9 @@ public abstract class PageAdminLTE extends WebPage implements ModelServiceLocato
@SpringBean
private SimulationResultManager simulationResultManager;

@SpringBean
private CertGuiHandlerRegistry certGuiHandlerRegistry;

// No need for this to store in session. It is used only during single init and render.
private transient Task pageTask;

Expand Down Expand Up @@ -546,6 +550,10 @@ public SimulationResultManager getSimulationResultManager() {
return simulationResultManager;
}

public CertGuiHandlerRegistry getCertGuiHandlerRegistry() {
return certGuiHandlerRegistry;
}

public MidPointApplication getMidpointApplication() {
return (MidPointApplication) getApplication();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import com.evolveum.midpoint.task.api.TaskManager;
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.midpoint.web.page.admin.certification.handlers.CertGuiHandlerRegistry;

/**
* Created by Viliam Repan (lazyman).
Expand Down Expand Up @@ -89,7 +90,8 @@
},
basePackageClasses = {
TextAreaPanelFactory.class,
GuiComponentRegistryImpl.class
GuiComponentRegistryImpl.class,
CertGuiHandlerRegistry.class
})
@EnableScheduling
public class MidPointSpringApplication extends AbstractSpringBootApplication {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ public void populateItem(Item<ICellPopulator<CertCaseOrWorkItemDto>> item, Strin
} else {
handlerUri = ((PageCertCampaign) page).getCampaignHandlerUri();
}
CertGuiHandler handler = CertGuiHandlerRegistry.instance().getHandler(handlerUri);
CertGuiHandler handler = page.getCertGuiHandlerRegistry().getHandler(handlerUri);
if (handler != null) {
String title = handler.getCaseInfoButtonTitle(rowModel, page);
item.add(AttributeModifier.replace("title", title));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,41 @@
package com.evolveum.midpoint.web.page.admin.certification.handlers;

import com.evolveum.midpoint.certification.api.AccessCertificationApiConstants;
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
import org.springframework.stereotype.Component;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
* Provides a correct handler for a given handler URI.
*
* Very primitive implementation (for now).
*/
@Component
public class CertGuiHandlerRegistry {

public static CertGuiHandlerRegistry instance() {
return new CertGuiHandlerRegistry(); // TODO
private static final Trace LOGGER = TraceManager.getTrace(CertGuiHandlerRegistry.class);

private Map<String, CertGuiHandler> handlers = new ConcurrentHashMap<>();

public void registerCertGuiHandler(String uri, CertGuiHandler handler) {
LOGGER.trace("Registering cert gui handler {} for {}", handler, uri);
handlers.put(uri, handler);
}

public CertGuiHandler getHandler(String uri) {
if (uri == null) {
return null;
}
switch (uri) {
case AccessCertificationApiConstants.DIRECT_ASSIGNMENT_HANDLER_URI:
return new DirectAssignmentCertGuiHandler();
case AccessCertificationApiConstants.EXCLUSION_HANDLER_URI:
return new DirectAssignmentCertGuiHandler(); // TODO
default:
throw new IllegalArgumentException("Unknown handler URI: " + uri);

CertGuiHandler certGuiHandler = handlers.get(uri);
if (certGuiHandler == null) {
throw new IllegalArgumentException("Unknown handler URI: " + uri);
}

return certGuiHandler;
}

@SuppressWarnings("unused")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

package com.evolveum.midpoint.web.page.admin.certification.handlers;

import com.evolveum.midpoint.certification.api.AccessCertificationApiConstants;
import com.evolveum.midpoint.gui.api.page.PageBase;
import com.evolveum.midpoint.gui.api.util.WebComponentUtil;
import com.evolveum.midpoint.gui.api.util.WebModelServiceUtils;
Expand All @@ -27,15 +28,28 @@

import org.apache.commons.lang3.StringUtils;
import org.apache.wicket.model.IModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.xml.namespace.QName;

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

@Component
public class DirectAssignmentCertGuiHandler implements CertGuiHandler {
private static final Trace LOGGER = TraceManager.getTrace(DirectAssignmentCertGuiHandler.class);

@Autowired
protected CertGuiHandlerRegistry certGuiHandlerRegistry;

@PostConstruct
public void register() {
certGuiHandlerRegistry.registerCertGuiHandler(AccessCertificationApiConstants.DIRECT_ASSIGNMENT_HANDLER_URI, this);
certGuiHandlerRegistry.registerCertGuiHandler(AccessCertificationApiConstants.EXCLUSION_HANDLER_URI, this);
}

@Override
public String getCaseInfoButtonTitle(IModel<? extends CertCaseOrWorkItemDto> rowModel, PageBase page) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.midpoint.web.boot.AbstractSpringBootApplication;
import com.evolveum.midpoint.web.page.admin.certification.handlers.CertGuiHandlerRegistry;

/**
* @author katka
Expand Down Expand Up @@ -69,7 +70,8 @@
},
basePackageClasses = {
TextAreaPanelFactory.class,
GuiComponentRegistryImpl.class
GuiComponentRegistryImpl.class,
CertGuiHandlerRegistry.class
})
public class TestMidPointSpringApplication extends AbstractSpringBootApplication {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import com.evolveum.midpoint.util.QNameUtil;
import com.evolveum.midpoint.util.annotation.Experimental;

import java.util.function.Supplier;

import static com.evolveum.midpoint.util.QNameUtil.getLocalPart;

/**
Expand All @@ -37,6 +39,30 @@
@Experimental
public class ConfigErrorReporter {

public static Object lazy(Supplier<Object> supplier) {
return new Object() {
@Override
public String toString() {
return String.valueOf(supplier.get());
}
};
}

public static String describe(@NotNull InboundMappingType inboundMapping) {
PrismContainerValue<?> pcv = inboundMapping.asPrismContainerValue();
var itemDef = PrismValueUtil.getNearestValueOfType(pcv, ResourceItemDefinitionType.class);
if (itemDef != null) {
return describeLocally(inboundMapping) + " in " + describe(itemDef);
} else {
return describeLocally(inboundMapping);
}
}

private static String describeLocally(@NotNull InboundMappingType mapping) {
String name = mapping.getName();
return name != null ? "inbound mapping '" + name + "'" : "inbound mapping";
}

public static String describe(@NotNull ItemRefinedDefinitionType itemRefinedDefinition) {
PrismContainerValue<?> pcv = itemRefinedDefinition.asPrismContainerValue();
Objectable top = PrismValueUtil.getRootObject(pcv);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9099,17 +9099,33 @@
<xsd:complexContent>
<xsd:extension base="tns:MappingType">
<xsd:sequence>
<xsd:element name="evaluationPhases" type="tns:InboundMappingEvaluationPhasesType" minOccurs="0">
<xsd:annotation>
<xsd:documentation>
Phase or phases in which the mapping should be evaluated.
(Default evaluation phases for given object type are taken into account as well.)
</xsd:documentation>
<xsd:appinfo>
<a:displayName>InboundMappingType.evaluationPhases</a:displayName>
</xsd:appinfo>
</xsd:annotation>
</xsd:element>
<xsd:choice>
<xsd:element name="evaluationPhases" type="tns:InboundMappingEvaluationPhasesType" minOccurs="0">
<xsd:annotation>
<xsd:documentation>
Phase or phases in which the mapping should be evaluated.
(Default evaluation phases for given object type are taken into account as well.)
Mutually exclusive with "use" item.
</xsd:documentation>
<xsd:appinfo>
<a:displayName>InboundMappingType.evaluationPhases</a:displayName>
</xsd:appinfo>
</xsd:annotation>
</xsd:element>
<xsd:element name="use" type="tns:InboundMappingUseType" minOccurs="0">
<xsd:annotation>
<xsd:documentation>
What purpose or purposes does the inbound mapping serve?
This is a simplified version of "evaluationPhases" item and is mutually exclusive with it.
If present, it overrides any default evaluation phases.
</xsd:documentation>
<xsd:appinfo>
<a:displayName>InboundMappingType.use</a:displayName>
<a:since>4.8</a:since>
</xsd:appinfo>
</xsd:annotation>
</xsd:element>
</xsd:choice>
</xsd:sequence>
</xsd:extension>
</xsd:complexContent>
Expand Down Expand Up @@ -9197,6 +9213,50 @@
</xsd:restriction>
</xsd:simpleType>

<xsd:simpleType name="InboundMappingUseType">
<xsd:annotation>
<xsd:documentation>
What purpose or purposes does the inbound mapping serve?
</xsd:documentation>
<xsd:appinfo>
<a:since>4.8</a:since>
</xsd:appinfo>
</xsd:annotation>
<xsd:restriction base="xsd:string">
<xsd:enumeration value="dataTransfer">
<xsd:annotation>
<xsd:documentation>
The mapping is used for the data transfer, i.e. moves data from the resource objects to focus objects.
</xsd:documentation>
<xsd:appinfo>
<jaxb:typesafeEnumMember name="DATA_TRANSFER"/>
</xsd:appinfo>
</xsd:annotation>
</xsd:enumeration>
<xsd:enumeration value="correlation">
<xsd:annotation>
<xsd:documentation>
The mapping is used for the correlation. It prepares data for correlation rules, but does not
directly manipulate the content of the focus objects.
</xsd:documentation>
<xsd:appinfo>
<jaxb:typesafeEnumMember name="CORRELATION"/>
</xsd:appinfo>
</xsd:annotation>
</xsd:enumeration>
<xsd:enumeration value="all">
<xsd:annotation>
<xsd:documentation>
The mapping is used for all purposes: currently, this means both correlation and data transfer.
</xsd:documentation>
<xsd:appinfo>
<jaxb:typesafeEnumMember name="ALL"/>
</xsd:appinfo>
</xsd:annotation>
</xsd:enumeration>
</xsd:restriction>
</xsd:simpleType>

<xsd:complexType name="OrgType">
<xsd:annotation>
<xsd:documentation>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@

package com.evolveum.midpoint.model.impl.lens.projector.focus.inbounds.prep;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.stream.Collectors;

import com.evolveum.midpoint.prism.path.ItemPath;

import com.evolveum.midpoint.schema.error.ConfigErrorReporter;
import com.evolveum.midpoint.util.exception.ConfigurationException;
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;
Expand All @@ -23,7 +25,10 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import static com.evolveum.midpoint.schema.error.ConfigErrorReporter.lazy;
import static com.evolveum.midpoint.util.MiscUtil.configCheck;
import static com.evolveum.midpoint.xml.ns._public.common.common_3.InboundMappingEvaluationPhaseType.BEFORE_CORRELATION;
import static com.evolveum.midpoint.xml.ns._public.common.common_3.InboundMappingUseType.*;

/**
* Determines applicability of a mapping in given evaluation phase.
Expand Down Expand Up @@ -58,20 +63,38 @@ class ApplicabilityEvaluator {
this.correlationItemPaths = correlationItemPaths;
}

List<InboundMappingType> filterApplicableMappingBeans(List<InboundMappingType> beans) {
return beans.stream()
.filter(this::isApplicable)
.collect(Collectors.toList());
List<InboundMappingType> filterApplicableMappingBeans(List<InboundMappingType> beans) throws ConfigurationException {
List<InboundMappingType> applicableBeans = new ArrayList<>();
for (InboundMappingType bean : beans) {
if (isApplicable(bean)) {
applicableBeans.add(bean);
}
}
return applicableBeans;
}

private boolean isApplicable(@NotNull InboundMappingType mappingBean) {
private boolean isApplicable(@NotNull InboundMappingType mappingBean) throws ConfigurationException {
InboundMappingEvaluationPhasesType mappingPhases = mappingBean.getEvaluationPhases();
InboundMappingUseType use = mappingBean.getUse();
configCheck(mappingPhases == null || use == null,
"Both 'evaluationPhases' and 'use' items present in %s",
lazy(() -> ConfigErrorReporter.describe(mappingBean)));
if (mappingPhases != null) {
if (mappingPhases.getExclude().contains(currentPhase)) {
return false;
} else if (mappingPhases.getInclude().contains(currentPhase)) {
return true;
}
} else if (use != null) {
// The "use" information is definite, if present. Default phases nor correlation usage are not taken into account.
switch (currentPhase) {
case BEFORE_CORRELATION:
return use == CORRELATION || use == ALL;
case CLOCKWORK:
return use == DATA_TRANSFER || use == ALL;
default:
throw new AssertionError(currentPhase);
}
}

if (defaultPhases.contains(currentPhase)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ abstract <V extends PrismValue, D extends ItemDefinition<?>> InboundMappingInCon
@NotNull List<InboundMappingType> selectMappingBeansForEvaluationPhase(
@NotNull List<InboundMappingType> beans,
boolean resourceItemLocalCorrelatorDefined,
@NotNull Collection<ItemPath> correlationItemPaths) {
@NotNull Collection<ItemPath> correlationItemPaths) throws ConfigurationException {
InboundMappingEvaluationPhaseType currentPhase = getCurrentEvaluationPhase();
List<InboundMappingType> filtered =
new ApplicabilityEvaluator(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,6 @@
<target>
<path>name</path>
</target>
<evaluationPhases>
<include>beforeCorrelation</include>
</evaluationPhases>
</inbound>
</attribute>
<attribute>
Expand Down

0 comments on commit 0111bcc

Please sign in to comment.