use of com.evolveum.midpoint.web.component.assignment.AssignmentEditorDto in project midpoint by Evolveum.
the class UserDelegationsTabPanel method initLayout.
private void initLayout() {
WebMarkupContainer delegations = new WebMarkupContainer(ID_DELEGATIONS_CONTAINER);
delegations.setOutputMarkupId(true);
add(delegations);
AssignmentTablePanel panel = new AssignmentTablePanel<UserType>(ID_DELEGATIONS_PANEL, delegationsModel) {
private static final long serialVersionUID = 1L;
@Override
public void populateAssignmentDetailsPanel(ListItem<AssignmentEditorDto> item) {
DelegationEditorPanel editor = new DelegationEditorPanel(ID_ROW, item.getModel(), false, privilegesListModel);
item.add(editor);
}
@Override
public String getExcludeOid() {
return getObjectWrapper().getOid();
}
public IModel<String> getLabel() {
return createStringResource("FocusType.delegations");
}
@Override
protected List<InlineMenuItem> createAssignmentMenu() {
List<InlineMenuItem> items = new ArrayList<>();
InlineMenuItem item;
if (WebComponentUtil.isAuthorized(AuthorizationConstants.AUTZ_UI_DELEGATE_ACTION_URL)) {
item = new InlineMenuItem(createStringResource("AssignmentTablePanel.menu.addDelegation")) {
private static final long serialVersionUID = 1L;
@Override
public InlineMenuItemAction initAction() {
return new InlineMenuItemAction() {
private static final long serialVersionUID = 1L;
@Override
public void onClick(AjaxRequestTarget target) {
List<QName> supportedTypes = new ArrayList<>();
supportedTypes.add(UserType.COMPLEX_TYPE);
ObjectFilter filter = getPrismContext().queryFactory().createInOid(getObjectWrapper().getOid());
ObjectFilter notFilter = getPrismContext().queryFactory().createNot(filter);
ObjectBrowserPanel<UserType> panel = new ObjectBrowserPanel<UserType>(getPageBase().getMainPopupBodyId(), UserType.class, supportedTypes, false, getPageBase(), notFilter) {
private static final long serialVersionUID = 1L;
@Override
protected void onSelectPerformed(AjaxRequestTarget target, UserType user) {
getPageBase().hideMainPopup(target);
List<ObjectType> newAssignmentsList = new ArrayList<>();
newAssignmentsList.add(user);
addSelectedAssignablePerformed(target, newAssignmentsList, null, getPageBase().getMainPopup().getId());
}
};
panel.setOutputMarkupId(true);
getPageBase().showMainPopup(panel, target);
}
};
}
};
items.add(item);
}
if (WebComponentUtil.isAuthorized(AuthorizationConstants.AUTZ_UI_ADMIN_UNASSIGN_ACTION_URI)) {
item = new InlineMenuItem(createStringResource("AssignmentTablePanel.menu.deleteDelegation")) {
private static final long serialVersionUID = 1L;
@Override
public InlineMenuItemAction initAction() {
return new InlineMenuItemAction() {
private static final long serialVersionUID = 1L;
@Override
public void onClick(AjaxRequestTarget target) {
deleteAssignmentPerformed(target, null);
}
};
}
};
items.add(item);
}
return items;
}
@Override
protected String getNoAssignmentsSelectedMessage() {
return getString("AssignmentTablePanel.message.noDelegationsSelected");
}
@Override
protected String getAssignmentsDeleteMessage(AssignmentEditorDto dto) {
return createStringResource("AssignmentTablePanel.modal.message.deleteDelegation", getSelectedAssignments().size()).getString();
}
@Override
protected List<AssignmentEditorDto> getAssignmentListToProcess(AssignmentEditorDto dto) {
if (dto != null) {
return Collections.singletonList(dto);
} else {
return getSelectedAssignments();
}
}
@Override
protected void addSelectedAssignablePerformed(AjaxRequestTarget target, List<ObjectType> newAssignments, QName relation, String popupId) {
ModalWindow window = (ModalWindow) get(popupId);
if (window != null) {
window.close(target);
}
getPageBase().hideMainPopup(target);
if (newAssignments.isEmpty()) {
warn(getString("AssignmentTablePanel.message.noAssignmentSelected"));
target.add(getPageBase().getFeedbackPanel());
return;
}
for (ObjectType object : newAssignments) {
try {
AssignmentEditorDto dto = AssignmentEditorDto.createDtoAddFromSelectedObject(((PrismObject<UserType>) getObjectWrapper().getObject()).asObjectable(), WebComponentUtil.getDefaultRelationOrFail(RelationKindType.DELEGATION), getPageBase(), (UserType) object);
dto.setPrivilegeLimitationList(privilegesListModel.getObject());
delegationsModel.getObject().add(dto);
} catch (Exception e) {
error(getString("AssignmentTablePanel.message.couldntAssignObject", object.getName(), e.getMessage()));
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't assign object", e);
}
}
reloadAssignmentsPanel(target);
reloadMainFormButtons(target);
}
};
delegations.add(panel);
}
use of com.evolveum.midpoint.web.component.assignment.AssignmentEditorDto in project midpoint by Evolveum.
the class PageUser method processDeputyAssignments.
@Override
protected boolean processDeputyAssignments(boolean previewOnly) {
boolean isAnythingChanged = false;
for (AssignmentEditorDto dto : delegationsModel.getObject()) {
if (!UserDtoStatus.MODIFY.equals(dto.getStatus())) {
if (!previewOnly) {
UserType user = dto.getDelegationOwner();
saveDelegationToUser(user.asPrismObject(), dto);
}
isAnythingChanged = true;
}
}
return isAnythingChanged;
}
use of com.evolveum.midpoint.web.component.assignment.AssignmentEditorDto in project midpoint by Evolveum.
the class PageUser method loadDelegatedByMeAssignments.
private List<AssignmentEditorDto> loadDelegatedByMeAssignments() {
OperationResult result = new OperationResult(OPERATION_LOAD_DELEGATED_BY_ME_ASSIGNMENTS);
List<AssignmentEditorDto> list = new ArrayList<>();
try {
Task task = createSimpleTask(OPERATION_LOAD_DELEGATED_BY_ME_ASSIGNMENTS);
PrismReferenceValue referenceValue = getPrismContext().itemFactory().createReferenceValue(getObjectWrapper().getOid(), UserType.COMPLEX_TYPE);
referenceValue.setRelation(WebComponentUtil.getDefaultRelationOrFail(RelationKindType.DELEGATION));
ObjectFilter refFilter = getPrismContext().queryFor(UserType.class).item(UserType.F_ASSIGNMENT, AssignmentType.F_TARGET_REF).ref(referenceValue).buildFilter();
ObjectQuery query = getPrismContext().queryFactory().createQuery(refFilter);
List<PrismObject<UserType>> usersList = getModelService().searchObjects(UserType.class, query, null, task, result);
List<String> processedUsersOid = new ArrayList<>();
if (usersList != null && usersList.size() > 0) {
for (PrismObject<UserType> user : usersList) {
if (processedUsersOid.contains(user.getOid())) {
continue;
}
List<AssignmentType> assignments = user.asObjectable().getAssignment();
for (AssignmentType assignment : assignments) {
if (assignment.getTargetRef() != null && StringUtils.isNotEmpty(assignment.getTargetRef().getOid()) && assignment.getTargetRef().getOid().equals(getObjectWrapper().getOid())) {
AssignmentEditorDto dto = new AssignmentEditorDto(UserDtoStatus.MODIFY, assignment, this, user.asObjectable());
dto.setEditable(false);
list.add(dto);
}
}
processedUsersOid.add(user.getOid());
}
}
} catch (Exception ex) {
result.recomputeStatus();
showResult(result);
}
Collections.sort(list);
return list;
}
Aggregations