Skip to content

Commit

Permalink
more refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
KaterynaHonchar committed Jun 26, 2018
1 parent 1c1975f commit e5bf588
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 40 deletions.
Expand Up @@ -48,8 +48,6 @@ public abstract class AbstractAssignmentPopupTabPanel<O extends ObjectType> exte
private static final String ID_OBJECT_LIST_PANEL = "objectListPanel";

private static final String DOT_CLASS = AbstractAssignmentPopupTabPanel.class.getName();
private static final Trace LOGGER = TraceManager.getTrace(AbstractAssignmentPopupTabPanel.class);
private static final String OPERATION_LOAD_ASSIGNABLE_ROLES = DOT_CLASS + "loadAssignableRoles";

private ObjectTypes type;
protected List<O> selectedObjects;
Expand Down Expand Up @@ -91,29 +89,7 @@ protected IModel<Boolean> getCheckBoxEnableModel(IModel<SelectableBean<O>> rowMo

@Override
protected ObjectQuery addFilterToContentQuery(ObjectQuery query) {
LOGGER.debug("Loading roles which the current user has right to assign");
Task task = AbstractAssignmentPopupTabPanel.this.getPageBase().createSimpleTask(OPERATION_LOAD_ASSIGNABLE_ROLES);
OperationResult result = task.getResult();
ObjectFilter filter = null;
try {
ModelInteractionService mis = AbstractAssignmentPopupTabPanel.this.getPageBase().getModelInteractionService();
RoleSelectionSpecification roleSpec =
mis.getAssignableRoleSpecification(SecurityUtils.getPrincipalUser().getUser().asPrismObject(), task, result);
filter = roleSpec.getFilter();
} catch (Exception ex) {
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't load available roles", ex);
result.recordFatalError("Couldn't load available roles", ex);
} finally {
result.recomputeStatus();
}
if (!result.isSuccess() && !result.isHandledError()) {
AbstractAssignmentPopupTabPanel.this.getPageBase().showResult(result);
}
if (query == null){
query = new ObjectQuery();
}
query.addFilter(filter);
return query;
return AbstractAssignmentPopupTabPanel.this.addFilterToContentQuery(query);
}

};
Expand All @@ -128,9 +104,7 @@ public boolean isVisible(){
return listPanel;
}

protected PopupObjectListPanel getObjectListPanel(){
return (PopupObjectListPanel)get(ID_OBJECT_LIST_PANEL);
}
protected abstract void initParametersPanel();

protected List getSelectedObjectsList(){
PopupObjectListPanel objectListPanel = getObjectListPanel();
Expand All @@ -140,17 +114,23 @@ protected List getSelectedObjectsList(){
return objectListPanel.getSelectedObjects();
}

protected PopupObjectListPanel getObjectListPanel(){
return (PopupObjectListPanel)get(ID_OBJECT_LIST_PANEL);
}

protected void onSelectionPerformed(AjaxRequestTarget target){}

protected IModel<Boolean> getObjectSelectCheckBoxEnableModel(IModel<SelectableBean<O>> rowModel){
return Model.of(true);
}

protected ObjectQuery addFilterToContentQuery(ObjectQuery query){
return query;
}

protected abstract List<AssignmentType> getSelectedAssignmentsList();

protected boolean isObjectListPanelVisible(){
return true;
}

protected abstract void initParametersPanel();

protected void onSelectionPerformed(AjaxRequestTarget target){}
}
Expand Up @@ -231,14 +231,14 @@ private int getTabPanelSelectedCount(WebMarkupContainer panel){
return 0;
}

private TabbedPanel getTabbedPanel(){
return (TabbedPanel) get(ID_FORM).get(ID_TABS_PANEL);
}

private void tabLabelPanelUpdate(AjaxRequestTarget target){
target.add(getTabbedPanel());
}

private TabbedPanel getTabbedPanel(){
return (TabbedPanel) get(ID_FORM).get(ID_TABS_PANEL);
}

protected void addPerformed(AjaxRequestTarget target, List newAssignmentsList) {
getPageBase().hideMainPopup(target);
}
Expand Down
Expand Up @@ -16,14 +16,22 @@
package com.evolveum.midpoint.gui.api.component;

import com.evolveum.midpoint.gui.api.util.WebComponentUtil;
import com.evolveum.midpoint.model.api.ModelInteractionService;
import com.evolveum.midpoint.model.api.RoleSelectionSpecification;
import com.evolveum.midpoint.prism.query.ObjectFilter;
import com.evolveum.midpoint.prism.query.ObjectQuery;
import com.evolveum.midpoint.schema.constants.ObjectTypes;
import com.evolveum.midpoint.schema.constants.SchemaConstants;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.schema.util.ObjectTypeUtil;
import com.evolveum.midpoint.task.api.Task;
import com.evolveum.midpoint.util.logging.LoggingUtils;
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.midpoint.web.component.assignment.RelationTypes;
import com.evolveum.midpoint.web.component.input.DropDownChoicePanel;
import com.evolveum.midpoint.web.page.admin.configuration.component.EmptyOnChangeAjaxFormUpdatingBehavior;
import com.evolveum.midpoint.web.security.SecurityUtils;
import com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.FocusType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType;
Expand All @@ -47,6 +55,7 @@ public class FocusTypeAssignmentPopupTabPanel<F extends FocusType> extends Abstr

private static final String DOT_CLASS = FocusTypeAssignmentPopupTabPanel.class.getName();
private static final Trace LOGGER = TraceManager.getTrace(FocusTypeAssignmentPopupTabPanel.class);
private static final String OPERATION_LOAD_ASSIGNABLE_ROLES = DOT_CLASS + "loadAssignableRoles";

public FocusTypeAssignmentPopupTabPanel(String id, ObjectTypes type){
this(id, type, new ArrayList<>());
Expand All @@ -71,10 +80,6 @@ protected void initParametersPanel(){
relationContainer.add(relationSelector);
}

private DropDownChoicePanel getRelationDropDown(){
return (DropDownChoicePanel)get(ID_RELATION_CONTAINER).get(ID_RELATION);
}

@Override
protected List<AssignmentType> getSelectedAssignmentsList(){
List<AssignmentType> assignmentList = new ArrayList<>();
Expand All @@ -95,4 +100,35 @@ public QName getRelationValue(){
}
return relation.getRelation();
}

private DropDownChoicePanel getRelationDropDown(){
return (DropDownChoicePanel)get(ID_RELATION_CONTAINER).get(ID_RELATION);
}

@Override
protected ObjectQuery addFilterToContentQuery(ObjectQuery query){
LOGGER.debug("Loading roles which the current user has right to assign");
Task task = getPageBase().createSimpleTask(OPERATION_LOAD_ASSIGNABLE_ROLES);
OperationResult result = task.getResult();
ObjectFilter filter = null;
try {
ModelInteractionService mis = getPageBase().getModelInteractionService();
RoleSelectionSpecification roleSpec =
mis.getAssignableRoleSpecification(SecurityUtils.getPrincipalUser().getUser().asPrismObject(), task, result);
filter = roleSpec.getFilter();
} catch (Exception ex) {
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't load available roles", ex);
result.recordFatalError("Couldn't load available roles", ex);
} finally {
result.recomputeStatus();
}
if (!result.isSuccess() && !result.isHandledError()) {
getPageBase().showResult(result);
}
if (query == null){
query = new ObjectQuery();
}
query.addFilter(filter);
return query;
}
}
Expand Up @@ -16,13 +16,17 @@
package com.evolveum.midpoint.gui.api.component;

import com.evolveum.midpoint.schema.constants.ObjectTypes;
import com.evolveum.midpoint.schema.util.ObjectTypeUtil;
import com.evolveum.midpoint.web.component.util.SelectableBean;
import com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour;
import com.evolveum.midpoint.web.page.admin.orgs.OrgTreeAssignablePanel;
import com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.FocusType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.OrgType;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.model.IModel;

import javax.xml.namespace.QName;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
Expand Down Expand Up @@ -121,6 +125,12 @@ protected List getSelectedObjectsList(){
}
}

@Override
protected List<AssignmentType> getSelectedAssignmentsList(){
isOrgTreeView = true;
return super.getSelectedAssignmentsList();
}

protected void onOrgTreeCheckBoxSelectionPerformed(AjaxRequestTarget target){}

public boolean isOrgTreeView(){
Expand Down

0 comments on commit e5bf588

Please sign in to comment.