Skip to content

Commit

Permalink
DefaultGuiConfigurationCompiler: cleanup, generics, added missing log
Browse files Browse the repository at this point in the history
  • Loading branch information
virgo47 committed Apr 12, 2022
1 parent e4fd682 commit a6bbb1b
Showing 1 changed file with 37 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,19 @@

package com.evolveum.midpoint.gui.api;

import java.lang.annotation.Annotation;
import java.lang.reflect.InvocationTargetException;
import java.util.*;
import javax.annotation.PostConstruct;
import javax.xml.namespace.QName;

import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.wicket.markup.html.panel.Panel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import com.evolveum.midpoint.gui.impl.util.GuiImplUtil;
import com.evolveum.midpoint.model.api.AdminGuiConfigurationMergeManager;
import com.evolveum.midpoint.model.api.authentication.CompiledGuiProfile;
Expand All @@ -31,19 +44,6 @@
import com.evolveum.prism.xml.ns._public.types_3.PolyStringTranslationType;
import com.evolveum.prism.xml.ns._public.types_3.PolyStringType;

import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.wicket.markup.html.panel.Panel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.xml.namespace.QName;
import java.lang.annotation.Annotation;
import java.lang.reflect.InvocationTargetException;
import java.util.*;

@Component
public class DefaultGuiConfigurationCompiler implements GuiProfileCompilable {

Expand Down Expand Up @@ -74,11 +74,12 @@ public class DefaultGuiConfigurationCompiler implements GuiProfileCompilable {

private static final Map<String, Class<? extends Panel>> PANELS_MAP = new HashMap<>();

private static final Map<String, SimpleCounter> COUNTERS_MAP = new HashMap<>();
private static final Map<String, SimpleCounter<?, ?>> COUNTERS_MAP = new HashMap<>();

private Boolean experimentalFeaturesEnabled = false;

private static synchronized Collection<Class<?>> getClassesForAnnotation(Class<? extends Annotation> annotation, String additionalPackagesToScan) {
private static synchronized Collection<Class<?>> getClassesForAnnotation(
Class<? extends Annotation> annotation, String additionalPackagesToScan) {
Collection<Class<?>> result = SCANNED_CLASSES_MAP.get(annotation);
if (result != null) {
return result;
Expand Down Expand Up @@ -152,13 +153,16 @@ private void compileDefaultDetailsPages(CompiledGuiProfile compiledGuiProfile) {
for (GuiObjectDetailsPageType defaultDetailsPage : detailsPages) {

//objects
GuiObjectDetailsPageType compiledPageType = compiledGuiProfile.findObjectDetailsConfiguration(defaultDetailsPage.getType());
GuiObjectDetailsPageType mergedDetailsPage = adminGuiConfigurationMergeManager.mergeObjectDetailsPageConfiguration(defaultDetailsPage, compiledPageType);
GuiObjectDetailsPageType compiledPageType =
compiledGuiProfile.findObjectDetailsConfiguration(defaultDetailsPage.getType());
GuiObjectDetailsPageType mergedDetailsPage =
adminGuiConfigurationMergeManager.mergeObjectDetailsPageConfiguration(defaultDetailsPage, compiledPageType);

if (compiledGuiProfile.getObjectDetails() == null) {
compiledGuiProfile.setObjectDetails(new GuiObjectDetailsSetType(prismContext));
}
compiledGuiProfile.getObjectDetails().getObjectDetailsPage().removeIf(p -> QNameUtil.match(p.getType(), defaultDetailsPage.getType()));
compiledGuiProfile.getObjectDetails().getObjectDetailsPage()
.removeIf(p -> QNameUtil.match(p.getType(), defaultDetailsPage.getType()));
compiledGuiProfile.getObjectDetails().getObjectDetailsPage().add(mergedDetailsPage.cloneWithoutId());
}
}
Expand All @@ -168,7 +172,9 @@ private void mergeCollectionViewsWithDefault(CompiledGuiProfile compiledGuiProfi
List<CompiledObjectCollectionView> defaultCollectionViews = compileDefaultCollectionViews(classes);

for (CompiledObjectCollectionView defaultCollectionView : defaultCollectionViews) {
CompiledObjectCollectionView compiledObjectCollectionView = compiledGuiProfile.findObjectCollectionView(defaultCollectionView.getContainerType(), defaultCollectionView.getViewIdentifier());
CompiledObjectCollectionView compiledObjectCollectionView =
compiledGuiProfile.findObjectCollectionView(
defaultCollectionView.getContainerType(), defaultCollectionView.getViewIdentifier());
if (compiledObjectCollectionView == null) {
compiledGuiProfile.getObjectCollectionViews().add(defaultCollectionView);
continue;
Expand All @@ -178,12 +184,14 @@ private void mergeCollectionViewsWithDefault(CompiledGuiProfile compiledGuiProfi

}

private void mergeCollectionViews(CompiledObjectCollectionView compiledObjectCollectionView, CompiledObjectCollectionView defaulCollectionView) {
DisplayType displayType = adminGuiConfigurationMergeManager.mergeDisplayType(compiledObjectCollectionView.getDisplay(), defaulCollectionView.getDisplay());
private void mergeCollectionViews(CompiledObjectCollectionView compiledObjectCollectionView,
CompiledObjectCollectionView defaultCollectionView) {
DisplayType displayType = adminGuiConfigurationMergeManager.mergeDisplayType(
compiledObjectCollectionView.getDisplay(), defaultCollectionView.getDisplay());
compiledObjectCollectionView.setDisplay(displayType);

if (compiledObjectCollectionView.getApplicableForOperation() == null) {
compiledObjectCollectionView.setApplicableForOperation(defaulCollectionView.getApplicableForOperation());
compiledObjectCollectionView.setApplicableForOperation(defaultCollectionView.getApplicableForOperation());
}
}

Expand All @@ -195,7 +203,8 @@ private List<CompiledObjectCollectionView> compileDefaultCollectionViews(Collect
continue;
}
ObjectTypes objectType = ObjectTypes.getObjectType(collectionInstance.applicableForType());
CompiledObjectCollectionView defaultCollectionView = new CompiledObjectCollectionView(objectType.getTypeQName(), collectionInstance.identifier());
CompiledObjectCollectionView defaultCollectionView =
new CompiledObjectCollectionView(objectType.getTypeQName(), collectionInstance.identifier());
defaultCollectionView.setDisplay(createDisplayType(collectionInstance.display()));
compiledObjectCollectionViews.add(defaultCollectionView);
defaultCollectionView.setDefaultView(true);
Expand Down Expand Up @@ -254,7 +263,8 @@ private void processShadowPanels(CompiledGuiProfile compiledGuiProfile) {
}

for (GuiShadowDetailsPageType shadowDetailsPage : compiledGuiProfile.getObjectDetails().getShadowDetailsPage()) {
List<ContainerPanelConfigurationType> mergedPanels = adminGuiConfigurationMergeManager.mergeContainerPanelConfigurationType(shadowPanels, shadowDetailsPage.getPanel());
List<ContainerPanelConfigurationType> mergedPanels =
adminGuiConfigurationMergeManager.mergeContainerPanelConfigurationType(shadowPanels, shadowDetailsPage.getPanel());
shadowDetailsPage.getPanel().clear();
shadowDetailsPage.getPanel().addAll(mergedPanels);
}
Expand Down Expand Up @@ -296,13 +306,14 @@ private synchronized void fillInCountersMap() {
Counter counterDefinition = clazz.getAnnotation(Counter.class);
if (counterDefinition != null) {
Class<? extends SimpleCounter> counterProvider = counterDefinition.provider();
PanelInstance panelInstance = clazz.getAnnotation(PanelInstance.class);
try {
PanelInstance panelInstance = clazz.getAnnotation(PanelInstance.class);
if (panelInstance != null) {
COUNTERS_MAP.put(panelInstance.identifier(), counterProvider.getDeclaredConstructor().newInstance());
}
} catch (InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
//TODO log at least
LOGGER.warn("Problem instantiating counter of type {} for panel identifier '{}'",
counterDefinition.getClass().getName(), panelInstance.identifier(), e);
}
}
}
Expand Down

0 comments on commit a6bbb1b

Please sign in to comment.