Skip to content

Commit

Permalink
Delegated to me tab is added
Browse files Browse the repository at this point in the history
  • Loading branch information
KaterynaHonchar committed Nov 16, 2016
1 parent f9525e5 commit 74da159
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 18 deletions.
Expand Up @@ -53,6 +53,9 @@ public class ComponentConstants {
public static final QName UI_FOCUS_TAB_DELEGATIONS = new QName(NS_COMPONENTS_PREFIX, "focusTabDelegations");
public static final String UI_FOCUS_TAB_DELEGATIONS_URL = QNameUtil.qNameToUri(UI_FOCUS_TAB_DELEGATIONS);

public static final QName UI_FOCUS_TAB_DELEGATED_TO_ME = new QName(NS_COMPONENTS_PREFIX, "focusTabDelegatedToMe");
public static final String UI_FOCUS_TAB_DELEGATED_TO_ME_URL = QNameUtil.qNameToUri(UI_FOCUS_TAB_DELEGATED_TO_ME);

public static final QName UI_FOCUS_TAB_POLICY_CONSTRAINTS = new QName(NS_COMPONENTS_PREFIX, "focusTabPolicyConstraints");
public static final String UI_FOCUS_TAB_POLICY_CONSTRAINTS_URL = QNameUtil.qNameToUri(UI_FOCUS_TAB_POLICY_CONSTRAINTS);

Expand Down
Expand Up @@ -135,11 +135,14 @@ public class AssignmentEditorPanel extends BasePanel<AssignmentEditorDto> {
protected WebMarkupContainer headerRow;
protected PageBase pageBase;
protected List<AssignmentsPreviewDto> privilegesList;
protected UserType delegationUser;

public AssignmentEditorPanel(String id, IModel<AssignmentEditorDto> model,
List<AssignmentsPreviewDto> privilegesList, PageBase pageBase) {
List<AssignmentsPreviewDto> privilegesList,
UserType delegationUser, PageBase pageBase) {
super(id, model);
this.pageBase = pageBase;
this.delegationUser = delegationUser;
this.privilegesList = privilegesList;

initLayout();
Expand Down
Expand Up @@ -17,12 +17,17 @@
package com.evolveum.midpoint.web.component.assignment;

import com.evolveum.midpoint.gui.api.page.PageBase;
import com.evolveum.midpoint.gui.api.util.WebModelServiceUtils;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.task.api.Task;
import com.evolveum.midpoint.web.component.AjaxButton;
import com.evolveum.midpoint.web.component.DateInput;
import com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour;
import com.evolveum.midpoint.web.page.admin.users.component.AssignmentPreviewDialog;
import com.evolveum.midpoint.web.page.admin.users.component.AssignmentsPreviewDto;
import com.evolveum.midpoint.web.page.admin.users.dto.UserDtoStatus;
import com.evolveum.midpoint.xml.ns._public.common.common_3.UserType;
import org.apache.commons.lang3.StringUtils;
import org.apache.wicket.AttributeModifier;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.markup.html.AjaxLink;
Expand Down Expand Up @@ -60,16 +65,20 @@ public class DelegationEditorPanel extends AssignmentEditorPanel {
private static final String ID_LIMIT_PRIVILEGES_BUTTON = "limitPrivilegesButton";
private List<String> privilegesNames = new ArrayList<>();

private static final String DOT_CLASS = DelegationEditorPanel.class.getName() + ".";
private static final String OPERATION_GET_TARGET_REF_NAME = DOT_CLASS + "getTargetRefName";

private boolean delegatedToMe;
private List<UserType> usersToUpdate;

public DelegationEditorPanel(String id, IModel<AssignmentEditorDto> delegationTargetObjectModel,
boolean delegatedToMe, List<AssignmentsPreviewDto> privilegesList, PageBase pageBase) {
super(id, delegationTargetObjectModel, privilegesList, pageBase);
List<AssignmentsPreviewDto> privilegesList, UserType user, PageBase pageBase) {
super(id, delegationTargetObjectModel, privilegesList, user, pageBase);
}

@Override
protected void initHeaderRow(){
delegatedToMe = delegationUser == null;
AjaxCheckBox selected = new AjaxCheckBox(ID_SELECTED,
new PropertyModel<Boolean>(getModel(), AssignmentEditorDto.F_SELECTED)) {
private static final long serialVersionUID = 1L;
Expand Down Expand Up @@ -109,7 +118,10 @@ public void onClick(AjaxRequestTarget target) {

Label nameLabel;
if (delegatedToMe) {
nameLabel = new Label(ID_NAME_LABEL, createAssignmentNameLabelModel(false));
OperationResult result = new OperationResult(OPERATION_GET_TARGET_REF_NAME);
Task task = pageBase.createSimpleTask(OPERATION_GET_TARGET_REF_NAME);
nameLabel = new Label(ID_NAME_LABEL,
WebModelServiceUtils.resolveReferenceName(getModelObject().getTargetRef(), pageBase, task, result));
} else {
nameLabel = new Label(ID_NAME_LABEL, pageBase.createStringResource("DelegationEditorPanel.meLabel"));
}
Expand Down Expand Up @@ -139,9 +151,9 @@ public void onClick(AjaxRequestTarget target) {

Label delegatedToNameLabel;
if (delegatedToMe) {
delegatedToNameLabel = new Label(ID_NAME_LABEL, pageBase.createStringResource("DelegationEditorPanel.meLabel"));
delegatedToNameLabel = new Label(ID_DELEGATED_TO_LABEL, pageBase.createStringResource("DelegationEditorPanel.meLabel"));
} else {
delegatedToNameLabel = new Label(ID_DELEGATED_TO_LABEL, createTargetModel());
delegatedToNameLabel = new Label(ID_DELEGATED_TO_LABEL, getUserDisplayName());
}
delegatedToNameLabel.setOutputMarkupId(true);
delegatedToName.add(delegatedToNameLabel);
Expand Down Expand Up @@ -196,6 +208,12 @@ protected void addButtonClicked(AjaxRequestTarget target, List<AssignmentsPrevie
pageBase.showMainPopup(assignmentPreviewDialog, target);
}
};
limitPrivilegesButton.add(new VisibleEnableBehaviour(){
@Override
public boolean isVisible(){
return UserDtoStatus.ADD.equals(getModelObject().getStatus());
}
});
body.add(limitPrivilegesButton);
};

Expand All @@ -212,4 +230,14 @@ private List<String> getPrivilegesNamesList(){
private void reloadBodyComponent(AjaxRequestTarget target){
target.add(get(ID_BODY));
}

private String getUserDisplayName(){
String displayName = "";
if (delegationUser.getFullName() != null && StringUtils.isNotEmpty(delegationUser.getFullName().getOrig())){
displayName = delegationUser.getFullName().getOrig() + "(" + delegationUser.getName().getOrig() + ")";
} else {
displayName = delegationUser.getName().getOrig();
}
return displayName;
}
}
Expand Up @@ -47,6 +47,7 @@
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;
import com.evolveum.prism.xml.ns._public.query_3.QueryType;
import com.evolveum.prism.xml.ns._public.query_3.SearchFilterType;
import org.apache.commons.collections.map.HashedMap;
import org.apache.commons.lang3.StringUtils;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.extensions.ajax.markup.html.modal.ModalWindow;
Expand Down Expand Up @@ -91,6 +92,7 @@ public class PageUser extends PageAdminFocus<UserType> {
private static final String ID_TASK_TABLE = "taskTable";
private static final String ID_TASKS = "tasks";
private LoadableModel<List<AssignmentEditorDto>> delegationsModel;
private Map<AssignmentEditorDto, UserType> assignmentUserMap = new HashMap();
private LoadableModel<List<AssignmentEditorDto>> delegatedToMeModel;

private HashMap<UserType, AssignmentEditorDto> usersToUpdateMap = new HashMap<>();
Expand Down Expand Up @@ -199,7 +201,7 @@ public WebMarkupContainer createPanel(String panelId) {
@Override
public void populateItem(ListItem<AssignmentEditorDto> item) {
DelegationEditorPanel editor = new DelegationEditorPanel(ID_ROW, item.getModel(),
false, privilegesList, PageUser.this);
privilegesList, assignmentUserMap.get(item.getModelObject()), PageUser.this);
item.add(editor);
}

Expand All @@ -210,10 +212,6 @@ public String getExcludeOid() {

@Override
protected List<InlineMenuItem> createAssignmentMenu() {
List<AssignmentEditorDto> dd = delegatedToMeModel.getObject();
if (dd != null){

}
List<InlineMenuItem> items = new ArrayList<>();

InlineMenuItem item;
Expand Down Expand Up @@ -306,7 +304,44 @@ public String getCount() {
}
});

authorization = new FocusTabVisibleBehavior(unwrapModel(),
ComponentConstants.UI_FOCUS_TAB_DELEGATED_TO_ME_URL);
tabs.add(new CountablePanelTab(parentPage.createStringResource("FocusType.delegatedToMe"), authorization)
{
private static final long serialVersionUID = 1L;

@Override
public WebMarkupContainer createPanel(String panelId) {
return new AssignmentTablePanel<UserType>(panelId, parentPage.createStringResource("FocusType.delegatedToMe"),
delegatedToMeModel) {
private static final long serialVersionUID = 1L;

@Override
public void populateItem(ListItem<AssignmentEditorDto> item) {
DelegationEditorPanel editor = new DelegationEditorPanel(ID_ROW, item.getModel(),
privilegesList, null, PageUser.this);
item.add(editor);
}

@Override
public String getExcludeOid() {
return getObject().getOid();
}

@Override
protected List<InlineMenuItem> createAssignmentMenu() {
return new ArrayList<>();
}

};
}

@Override
public String getCount() {
return Integer.toString(delegatedToMeModel.getObject() == null ?
0 : delegatedToMeModel.getObject().size());
}
});
}

};
Expand Down Expand Up @@ -356,7 +391,9 @@ private List<AssignmentEditorDto> loadDelegatedByMeAssignments() {
if (assignment.getTargetRef() != null &&
StringUtils.isNotEmpty(assignment.getTargetRef().getOid()) &&
assignment.getTargetRef().getOid().equals(getObjectWrapper().getOid())) {
list.add(new AssignmentEditorDto(UserDtoStatus.MODIFY, assignment, this));
AssignmentEditorDto dto = new AssignmentEditorDto(UserDtoStatus.MODIFY, assignment, this);
list.add(dto);
assignmentUserMap.put(dto, user.asObjectable());
}
}
}
Expand Down Expand Up @@ -385,12 +422,6 @@ private List<AssignmentsPreviewDto> getUserPrivilegesList(){

@Override
protected void processDeputyAssignments(){
// for (AssignmentEditorDto dto : getAssignmentsModel().getObject()){
// if (dto.getTargetRef() != null && SchemaConstants.ORG_DEPUTY.equals(dto.getTargetRef().getRelation()) &&
// dto.getTargetRef().getOid().equals(getObjectWrapper().getOid())){
// getAssignmentsModel().getObject().remove(dto);
// }
// }
for (UserType user : usersToUpdateMap.keySet()){
List<AssignmentType> userAssignments = user.getAssignment();
List<AssignmentEditorDto> userAssignmentsDtos = new ArrayList<>();
Expand Down
Expand Up @@ -132,6 +132,7 @@ FocusType.activation=Activation
FocusType.assignment=Assignments
FocusType.inducement=Inducements
FocusType.delegations=Delegations
FocusType.delegatedToMe=Delegated to me
FocusType.displayName=Display Name
LockoutStatusType.LOCKED=Locked
LockoutStatusType.NORMAL=Normal
Expand Down

0 comments on commit 74da159

Please sign in to comment.