Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/Evolveum/midpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
KaterynaHonchar committed Sep 9, 2021
2 parents fd3b3c5 + 50c05b6 commit 20bfdcb
Show file tree
Hide file tree
Showing 102 changed files with 1,521 additions and 612 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import java.util.*;
import javax.annotation.PostConstruct;

import com.evolveum.midpoint.gui.api.prism.ItemStatus;
import com.evolveum.midpoint.prism.polystring.PolyString;

import com.evolveum.midpoint.schema.util.MiscSchemaUtil;
Expand Down Expand Up @@ -241,6 +242,10 @@ private ContainerPanelConfigurationType compileContainerPanelConfiguration(Class
if (panelInstance.defaultPanel()) {
config.setDefault(true);
}
if (Arrays.stream(panelInstance.status()).filter(s -> ItemStatus.ADDED == s).count() == 1) {
config.setVisibleForAdd(true);
}

return config;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@
import com.evolveum.midpoint.web.component.util.VisibleBehaviour;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;

import org.jetbrains.annotations.NotNull;

/**
* Created by honchar.
*/
Expand All @@ -77,7 +79,7 @@ public class AssignmentPopup extends BasePanel<AssignmentPopupDto> implements Po
private static final String DOT_CLASS = AssignmentPopup.class.getName() + ".";
protected static final String OPERATION_LOAD_ASSIGNMENT_HOLDER_SPECIFICATION = DOT_CLASS + "loadAssignmentHolderSpecification";

public AssignmentPopup(String id, IModel<AssignmentPopupDto> model) {
public AssignmentPopup(String id, @NotNull IModel<AssignmentPopupDto> model) {
super(id, model);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,7 @@ public void onClick(AjaxRequestTarget ajaxRequestTarget) {
}
}
};
navigateToObject.add(new VisibleBehaviour(() -> DisplayNamePanel.this.getModelObject() instanceof ObjectType &&
StringUtils.isNotEmpty(((ObjectType) DisplayNamePanel.this.getModelObject()).getOid()) &&
WebComponentUtil.getObjectDetailsPage(((ObjectType) DisplayNamePanel.this.getModelObject()).getClass()) != null));
navigateToObject.add(new VisibleBehaviour(() -> hasDetailsPage()));
navigateToObject.setOutputMarkupId(true);
add(navigateToObject);

Expand All @@ -110,9 +108,17 @@ protected void populateItem(ListItem<String> item) {
};

add(descriptionLabels);
}

// add(new Label(ID_DESCRIPTION, getDescriptionLabelsModel()));
// add(new Label(ID_PENDING_OPERATION, getPendingOperationLabelModel()));
private boolean hasDetailsPage() {
C containerable = getModelObject();
if (!(containerable instanceof ObjectType)) {
return false;
}
if (((ObjectType) containerable).getOid().isBlank()) {
return false;
}
return WebComponentUtil.hasDetailsPage(containerable.getClass());
}

protected WebMarkupContainer createTypeImagePanel(String idTypeImage) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.wicket.Component;
import org.apache.wicket.RestartResponseException;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.behavior.AttributeAppender;
import org.apache.wicket.extensions.markup.html.repeater.data.table.DataTable;
Expand Down Expand Up @@ -575,4 +576,15 @@ public IModel<String> getConfirmationMessageModel(){
}
};
}

@Override
protected void objectDetailsPerformed(AjaxRequestTarget target, O object) {
if (WebComponentUtil.hasDetailsPage(object.getClass())) {
WebComponentUtil.dispatchToObjectDetailsPage(object.getClass(), object.getOid(), this, true);
} else {
error("Could not find proper response page");
throw new RestartResponseException(getPageBase());
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import com.evolveum.midpoint.gui.impl.page.admin.assignmentholder.component.assignmentType.AbstractAssignmentTypePanel;
import com.evolveum.midpoint.gui.impl.page.admin.ObjectDetailsModels;

import com.evolveum.midpoint.gui.impl.page.admin.org.PageOrg;

import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.*;
import org.apache.commons.lang3.math.NumberUtils;
Expand Down Expand Up @@ -220,6 +222,9 @@ public final class WebComponentUtil {
private static final Map<Class<? extends ObjectType>, Class<? extends PageBase>> OBJECT_DETAILS_PAGE_MAP;
private static final Map<Class<? extends ObjectType>, Class<? extends PageBase>> CREATE_NEW_OBJECT_PAGE_MAP;


private static final Map<Class<? extends ObjectType>, Class<? extends PageBase>> OBJECT_DETAILS_PAGE_MAP_NEW;

static {
OBJECT_DETAILS_PAGE_MAP = new HashMap<>();
OBJECT_DETAILS_PAGE_MAP.put(UserType.class, PageUser.class);
Expand All @@ -237,6 +242,23 @@ public final class WebComponentUtil {
OBJECT_DETAILS_PAGE_MAP.put(ObjectTemplateType.class, PageObjectTemplate.class);
}

static {
OBJECT_DETAILS_PAGE_MAP_NEW = new HashMap<>();
OBJECT_DETAILS_PAGE_MAP_NEW.put(UserType.class, com.evolveum.midpoint.gui.impl.page.admin.user.PageUser.class);
OBJECT_DETAILS_PAGE_MAP_NEW.put(OrgType.class, PageOrg.class);
OBJECT_DETAILS_PAGE_MAP_NEW.put(RoleType.class, com.evolveum.midpoint.gui.impl.page.admin.role.PageRole.class);
OBJECT_DETAILS_PAGE_MAP_NEW.put(ServiceType.class, com.evolveum.midpoint.gui.impl.page.admin.service.PageService.class);
OBJECT_DETAILS_PAGE_MAP_NEW.put(ResourceType.class, com.evolveum.midpoint.gui.impl.page.admin.resource.PageResource.class);
OBJECT_DETAILS_PAGE_MAP_NEW.put(TaskType.class, com.evolveum.midpoint.gui.impl.page.admin.task.PageTask.class);
OBJECT_DETAILS_PAGE_MAP_NEW.put(ReportType.class, com.evolveum.midpoint.gui.impl.page.admin.report.PageReport.class);
OBJECT_DETAILS_PAGE_MAP_NEW.put(ValuePolicyType.class, PageValuePolicy.class);
OBJECT_DETAILS_PAGE_MAP_NEW.put(CaseType.class, com.evolveum.midpoint.gui.impl.page.admin.cases.PageCase.class);
OBJECT_DETAILS_PAGE_MAP_NEW.put(ArchetypeType.class, PageArchetype.class);
OBJECT_DETAILS_PAGE_MAP_NEW.put(ShadowType.class, PageAccount.class);
OBJECT_DETAILS_PAGE_MAP_NEW.put(ObjectCollectionType.class, PageObjectCollection.class);
OBJECT_DETAILS_PAGE_MAP_NEW.put(ObjectTemplateType.class, PageObjectTemplate.class);
}

static {
CREATE_NEW_OBJECT_PAGE_MAP = new HashMap<>();
CREATE_NEW_OBJECT_PAGE_MAP.put(ResourceType.class, PageResourceWizard.class);
Expand Down Expand Up @@ -818,7 +840,7 @@ public static boolean isAuthorized(Collection<String> actions) {
}

public static boolean isAuthorized(Class<? extends ObjectType> clazz) {
Class<? extends PageBase> detailsPage = WebComponentUtil.getObjectDetailsPage(clazz);
Class<? extends PageBase> detailsPage = getObjectDetailsPage(clazz);
if (detailsPage == null) {
return false;
}
Expand Down Expand Up @@ -2476,6 +2498,21 @@ public static void dispatchToObjectDetailsPage(PrismObject obj, Component compon
dispatchToObjectDetailsPage(obj, false, component);
}

private static boolean isNewDesignEnabled() {
MidPointApplication app = MidPointApplication.get();
ModelInteractionService service = app.getModelInteractionService();
Task task = app.createSimpleTask("get compiledGui profile");
OperationResult result = task.getResult();
try {
CompiledGuiProfile compiledGuiProfile = service.getCompiledGuiProfile(task, result);
return compiledGuiProfile.isUseNewDesign();
} catch (Throwable e) {
LOGGER.error("Cannot get compiled gui profile, {}", e.getMessage(), e);
}
//if somthing happen just return true, by default we want new design
return true;
}

// shows the actual object that is passed via parameter (not its state in repository)
public static void dispatchToObjectDetailsPage(PrismObject obj, boolean isNewObject, Component component) {
Class newObjectPageClass = isNewObject ? getNewlyCreatedObjectPage(obj.getCompileTimeClass()) : getObjectDetailsPage(obj.getCompileTimeClass());
Expand All @@ -2490,8 +2527,13 @@ public static void dispatchToObjectDetailsPage(PrismObject obj, boolean isNewObj
constructor = newObjectPageClass.getConstructor(PageParameters.class);
page = (PageBase) constructor.newInstance(new PageParameters());
} else {
constructor = newObjectPageClass.getConstructor(PrismObject.class, boolean.class);
page = (PageBase) constructor.newInstance(obj, isNewObject);
if (isNewDesignEnabled()) {
constructor = newObjectPageClass.getConstructor(PrismObject.class);
page = (PageBase) constructor.newInstance(obj);
} else {
constructor = newObjectPageClass.getConstructor(PrismObject.class, boolean.class);
page = (PageBase) constructor.newInstance(obj, isNewObject);
}

}
if (component.getPage() instanceof PageBase) {
Expand Down Expand Up @@ -2531,18 +2573,20 @@ public static boolean hasDetailsPage(Class<?> clazz) {
return OBJECT_DETAILS_PAGE_MAP.containsKey(clazz);
}

public static String getStorageKeyForTableId(TableId tableId) {
return STORAGE_TABLE_ID_MAP.get(tableId);
}

public static Class<? extends PageBase> getObjectDetailsPage(Class<? extends ObjectType> type) {
if (isNewDesignEnabled()) {
return OBJECT_DETAILS_PAGE_MAP_NEW.get(type);
}
return OBJECT_DETAILS_PAGE_MAP.get(type);
}

public static Class<? extends PageBase> getNewlyCreatedObjectPage(Class<? extends ObjectType> type) {
if (ResourceType.class.equals(type)) {
return CREATE_NEW_OBJECT_PAGE_MAP.get(type);
} else {
if (isNewDesignEnabled()) {
return OBJECT_DETAILS_PAGE_MAP_NEW.get(type);
}
return OBJECT_DETAILS_PAGE_MAP.get(type);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import com.evolveum.midpoint.gui.api.component.MainObjectListPanel;
import com.evolveum.midpoint.gui.api.page.PageBase;
import com.evolveum.midpoint.gui.impl.page.admin.assignmentholder.PageAssignmentHolderDetails;
import com.evolveum.midpoint.gui.impl.page.admin.user.PageUser;
import com.evolveum.midpoint.web.component.*;

Expand Down Expand Up @@ -199,9 +200,9 @@ public <AH extends AssignmentHolderType> PrismObject<AH> getFocusObject(){
return mainPanel.getObjectWrapper().getObject();
}
PageBase pageBase = getPageBase();
if (pageBase != null && pageBase instanceof PageUser) {
PageUser pageUser = (PageUser) pageBase;
return (PrismObject<AH>) pageUser.getPrismObject();
if (pageBase != null && pageBase instanceof PageAssignmentHolderDetails) {
PageAssignmentHolderDetails pageAssignmentHolderDetails = (PageAssignmentHolderDetails) pageBase;
return (PrismObject<AH>) pageAssignmentHolderDetails.getPrismObject();
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@

import java.util.List;

import com.evolveum.midpoint.gui.api.prism.ItemStatus;
import com.evolveum.midpoint.gui.api.util.WebDisplayTypeUtil;

import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.markup.html.AjaxLink;
Expand Down Expand Up @@ -152,9 +154,8 @@ private void addLabel(AjaxLink<Void> link, ListItem<ContainerPanelConfigurationT
}

private void addCount(AjaxLink<Void> link, ListItem<ContainerPanelConfigurationType> item) {
IModel<String> countModel = createCountModel(item.getModel());
Label label = new Label(ID_COUNT, countModel);
label.add(new VisibleBehaviour(() -> countModel.getObject() != null));
Label label = new Label(ID_COUNT, createCountModel(item.getModel()));
label.add(new VisibleBehaviour(() -> getCounterProvider(item.getModel()) != null));
link.add(label);
}

Expand Down Expand Up @@ -189,25 +190,40 @@ protected void onClickPerformed(ContainerPanelConfigurationType config, AjaxRequ

private IModel<String> createCountModel(IModel<ContainerPanelConfigurationType> panelModel) {
return new ReadOnlyModel<>( () -> {
ContainerPanelConfigurationType config = panelModel.getObject();
String panelInstanceIdentifier = config.getIdentifier();

SimpleCounter<ObjectDetailsModels<O>, O> counter = getPageBase().getCounterProvider(panelInstanceIdentifier);
if (counter == null || counter.getClass().equals(SimpleCounter.class)) {
SimpleCounter<ObjectDetailsModels<O>, O> counter = getCounterProvider(panelModel);
if (counter == null) {
return null;
}

int count = counter.count(objectDetailsModel, getPageBase());
return String.valueOf(count);
});
}

private SimpleCounter<ObjectDetailsModels<O>, O> getCounterProvider(IModel<ContainerPanelConfigurationType> panelModel) {
ContainerPanelConfigurationType config = panelModel.getObject();
String panelInstanceIdentifier = config.getIdentifier();

SimpleCounter<ObjectDetailsModels<O>, O> counter = getPageBase().getCounterProvider(panelInstanceIdentifier);
if (counter == null || counter.getClass().equals(SimpleCounter.class)) {
return null;
}
return counter;
}

private boolean isMenuItemVisible(ContainerPanelConfigurationType config) {
if (config == null) {
return true;
}

return WebComponentUtil.getElementVisibility(config.getVisibility());
return WebComponentUtil.getElementVisibility(config.getVisibility()) && isVisibleForAddApply(config);
}

private boolean isVisibleForAddApply(ContainerPanelConfigurationType config) {
ItemStatus status = objectDetailsModel.getObjectStatus();
if (status == ItemStatus.NOT_CHANGED) {
return true;
}
return ItemStatus.ADDED == status && BooleanUtils.isTrue(config.isVisibleForAdd());
}

protected void onClickPerformed(ContainerPanelConfigurationType config, AjaxRequestTarget target) {
Expand Down

0 comments on commit 20bfdcb

Please sign in to comment.