Skip to content

Commit

Permalink
MID-7777 blind attempt to fix classpath searching issues for panels
Browse files Browse the repository at this point in the history
(cherry picked from commit 0148f62)
  • Loading branch information
1azyman committed Apr 1, 2022
1 parent faf8876 commit f1c866c
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import com.evolveum.midpoint.schema.util.MiscSchemaUtil;
import com.evolveum.midpoint.util.ClassPathUtil;
import com.evolveum.midpoint.util.QNameUtil;
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.midpoint.web.application.*;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;
import com.evolveum.prism.xml.ns._public.types_3.ItemPathType;
Expand All @@ -45,6 +47,8 @@
@Component
public class DefaultGuiConfigurationCompiler implements GuiProfileCompilable {

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

@Autowired private GuiProfileCompilerRegistry registry;
@Autowired private PrismContext prismContext;
@Autowired private AdminGuiConfigurationMergeManager adminGuiConfigurationMergeManager;
Expand Down Expand Up @@ -106,7 +110,7 @@ private static synchronized Collection<Class<?>> getCollectionClasses() {
}

private Collection<Class<?>> getPanelInstanceClasses() {
Collection<Class<?>> result = new ArrayList<>();
Collection<Class<?>> result = new HashSet<>();
result.addAll(getClassesForAnnotation(PanelInstance.class, additionalPackagesToScan));
result.addAll(getClassesForAnnotation(PanelInstances.class, additionalPackagesToScan));

Expand Down Expand Up @@ -205,22 +209,42 @@ private List<CompiledObjectCollectionView> compileDefaultCollectionViews(Collect
return compiledObjectCollectionViews;
}

private List<PanelInstance> getPanelInstancesAnnotations(Class<?> clazz) {
List<PanelInstance> instances = new ArrayList<>();
if (clazz == null) {
return instances;
}

PanelInstance i = clazz.getAnnotation(PanelInstance.class);
if (i != null) {
instances.add(i);
}

PanelInstances pis = clazz.getAnnotation(PanelInstances.class);
if (pis != null) {
instances.addAll(Arrays.asList(pis.value()));
}

return instances;
}

private void processShadowPanels(CompiledGuiProfile compiledGuiProfile) {
List<ContainerPanelConfigurationType> shadowPanels = new ArrayList<>();
for (Class<?> clazz : getPanelInstanceClasses()) {
PanelInstance instance = clazz.getAnnotation(PanelInstance.class);
if (instance == null) {
continue;
}
if (!instance.applicableForType().equals(ShadowType.class)) {
continue;
}
for (PanelInstance instance : getPanelInstancesAnnotations(clazz)) {
if (instance == null) {
continue;
}
if (!instance.applicableForType().equals(ShadowType.class)) {
continue;
}

if (compiledGuiProfile.getObjectDetails() == null) {
compiledGuiProfile.setObjectDetails(new GuiObjectDetailsSetType());
if (compiledGuiProfile.getObjectDetails() == null) {
compiledGuiProfile.setObjectDetails(new GuiObjectDetailsSetType());
}
ContainerPanelConfigurationType shadowPanel = compileContainerPanelConfiguration(clazz, ShadowType.class, instance);
shadowPanels.add(shadowPanel);
}
ContainerPanelConfigurationType shadowPanel = compileContainerPanelConfiguration(clazz, ShadowType.class, instance);
shadowPanels.add(shadowPanel);
}

if (compiledGuiProfile.getObjectDetails() == null) {
Expand Down Expand Up @@ -306,13 +330,8 @@ private Set<Class<? extends Containerable>> findSupportedContainerables() {
Set<Class<? extends Containerable>> containerables = new HashSet<>();

for (Class<?> clazz : getPanelInstanceClasses()) {
PanelInstances pis = clazz.getAnnotation(PanelInstances.class);
if (pis != null) {
Arrays.asList(pis.value()).forEach(pi -> addSupportedContainerable(containerables, pi));
}

PanelInstance pi = clazz.getAnnotation(PanelInstance.class);
addSupportedContainerable(containerables, pi);
List<PanelInstance> pis = getPanelInstancesAnnotations(clazz);
pis.forEach(pi -> addSupportedContainerable(containerables, pi));
}

return containerables;
Expand Down Expand Up @@ -364,13 +383,8 @@ private List<ContainerPanelConfigurationType> getPanelsFor(Class<? extends Conta
List<ContainerPanelConfigurationType> panels = new ArrayList<>();

for (Class<?> clazz : getPanelInstanceClasses()) {
PanelInstances pis = clazz.getAnnotation(PanelInstances.class);
if (pis != null) {
Arrays.asList(pis.value()).forEach(pi -> addPanelsFor(panels, containerable, clazz, pi));
}

PanelInstance pi = clazz.getAnnotation(PanelInstance.class);
addPanelsFor(panels, containerable, clazz, pi);
List<PanelInstance> pis = getPanelInstancesAnnotations(clazz);
pis.forEach(pi -> addPanelsFor(panels, containerable, clazz, pi));
}

MiscSchemaUtil.sortDetailsPanels(panels);
Expand Down Expand Up @@ -493,20 +507,21 @@ private void compileDisplay(PanelInstance panelInstance, ContainerPanelConfigura
private List<ContainerPanelConfigurationType> processChildren(Class<? extends Containerable> containerable, Class<?> parentClass) {
List<ContainerPanelConfigurationType> configs = new ArrayList<>();
for (Class<?> clazz : getPanelInstanceClasses()) {
PanelInstance panelInstance = clazz.getAnnotation(PanelInstance.class);
if (isNotApplicableFor(containerable, panelInstance)) {
continue;
}
if (!isSubPanel(panelInstance)) {
continue;
}
for (PanelInstance panelInstance : getPanelInstancesAnnotations(clazz)) {
if (isNotApplicableFor(containerable, panelInstance)) {
continue;
}
if (!isSubPanel(panelInstance)) {
continue;
}

if (!panelInstance.childOf().equals(parentClass)) {
continue;
}
if (!panelInstance.childOf().equals(parentClass)) {
continue;
}

ContainerPanelConfigurationType config = compileContainerPanelConfiguration(clazz, containerable, panelInstance);
configs.add(config);
ContainerPanelConfigurationType config = compileContainerPanelConfiguration(clazz, containerable, panelInstance);
configs.add(config);
}
}

MiscSchemaUtil.sortDetailsPanels(configs);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -381,17 +381,35 @@ private boolean isApplicableForOperation(ContainerPanelConfigurationType configu
}

private void initMainPanel(ContainerPanelConfigurationType panelConfig, MidpointForm form) {
if (panelConfig == null) {
addErrorPanel(form, MessagePanel.MessagePanelType.WARN,"AbstractPageObjectDetails.noPanels");
return;
}

getSessionStorage().setObjectDetailsStorage("details" + getType().getSimpleName(), panelConfig);
String panelType = panelConfig.getPanelType();
if (panelType == null) {
addErrorPanel(form, MessagePanel.MessagePanelType.ERROR,"AbstractPageObjectDetails.panelTypeUndefined", panelConfig.getIdentifier());
return;
}
Class<? extends Panel> panelClass = findObjectPanel(panelConfig.getPanelType());

Class<? extends Panel> panelClass = findObjectPanel(panelType);
Panel panel = WebComponentUtil.createPanel(panelClass, ID_MAIN_PANEL, objectDetailsModels, panelConfig);
form.addOrReplace(panel);
if (panel != null) {
form.addOrReplace(panel);
return;
}

addErrorPanel(form, MessagePanel.MessagePanelType.ERROR, "AbstractPageObjectDetails.panelErrorInitialization", panelConfig.getIdentifier(), panelType);
}

private void addErrorPanel(MidpointForm form, MessagePanel.MessagePanelType type, String message, Object... params) {
WebMarkupContainer panel = new MessagePanel(ID_MAIN_PANEL, type,
createStringResource(message, params), false);
panel.add(AttributeAppender.append("style", "margin-top: 20px;"));

form.addOrReplace(panel);
}

private DetailsNavigationPanel initNavigation() {
return createNavigationPanel(getPanelConfigurations());
Expand Down

0 comments on commit f1c866c

Please sign in to comment.