Skip to content

Commit

Permalink
assignable relations filter for gui part of shopping cart
Browse files Browse the repository at this point in the history
  • Loading branch information
KaterynaHonchar committed Oct 7, 2019
1 parent 048a3b9 commit b9aa5e4
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 4 deletions.
Expand Up @@ -2927,14 +2927,29 @@ public static RelationRegistry getStaticallyProvidedRelationRegistry() {

public static ObjectFilter getAssignableRolesFilter(PrismObject<? extends FocusType> focusObject, Class<? extends AbstractRoleType> type, AssignmentOrder assignmentOrder,
OperationResult result, Task task, PageBase pageBase) {
return getAssignableRolesFilter(focusObject, type, null, assignmentOrder, result, task, pageBase);
}

public static ObjectFilter getAssignableRolesFilter(PrismObject<? extends FocusType> focusObject, Class<? extends AbstractRoleType> type,
QName relation, AssignmentOrder assignmentOrder,
OperationResult result, Task task, PageBase pageBase) {
ObjectFilter filter = null;
LOGGER.debug("Loading objects which can be assigned");
try {
ModelInteractionService mis = pageBase.getModelInteractionService();
RoleSelectionSpecification roleSpec =
mis.getAssignableRoleSpecification(focusObject, type, assignmentOrder.getOrder(), task, result);
// TODO: make this relation-aware
filter = roleSpec.getGlobalFilter();
if (relation != null){
ObjectFilter relationFilter = roleSpec.getRelationFilter(relation);
if (filter == null){
return relationFilter;
} else if (relationFilter == null){
return filter;
} else {
return pageBase.getPrismContext().queryFactory().createOr(filter, relationFilter);
}
}
} catch (Exception ex) {
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't load available roles", ex);
result.recordFatalError(pageBase.createStringResource("WebComponentUtil.message.getAssignableRolesFilter.fatalError").getString(), ex);
Expand All @@ -2947,6 +2962,29 @@ public static ObjectFilter getAssignableRolesFilter(PrismObject<? extends FocusT
return filter;
}

public static List<QName> getAssignableRelationsList(PrismObject<? extends FocusType> focusObject, Class<? extends AbstractRoleType> type,
AssignmentOrder assignmentOrder,
OperationResult result, Task task, PageBase pageBase){
List<QName> relationsList = null;
LOGGER.debug("Loading assignable relations list");
try {
ModelInteractionService mis = pageBase.getModelInteractionService();
RoleSelectionSpecification roleSpec =
mis.getAssignableRoleSpecification(focusObject, type, assignmentOrder.getOrder(), task, result);
relationsList = roleSpec != null && roleSpec.getGlobalFilter() == null && roleSpec.getRelationMap() != null ?
new ArrayList<QName>(roleSpec.getRelationMap().keySet()) : null;
} catch (Exception ex) {
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't load assignable relations list", ex);
result.recordFatalError(pageBase.createStringResource("WebComponentUtil.message.getAssignableRelationsList.fatalError").getString(), ex);
} finally {
result.recomputeStatus();
}
if (!result.isSuccess() && !result.isHandledError()) {
pageBase.showResult(result);
}
return relationsList;
}

public static String formatDurationWordsForLocal(long durationMillis, boolean suppressLeadingZeroElements,
boolean suppressTrailingZeroElements, PageBase pageBase){

Expand Down
Expand Up @@ -29,6 +29,7 @@
import com.evolveum.midpoint.web.page.admin.users.dto.UserDtoStatus;
import com.evolveum.midpoint.web.session.RoleCatalogStorage;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;
import org.apache.commons.collections.CollectionUtils;
import org.apache.wicket.AttributeModifier;
import org.apache.wicket.ajax.AjaxChannel;
import org.apache.wicket.ajax.AjaxRequestTarget;
Expand Down Expand Up @@ -63,6 +64,7 @@ public abstract class AbstractShoppingCartTabPanel<R extends AbstractRoleType> e

private static final String DOT_CLASS = AbstractShoppingCartTabPanel.class.getName() + ".";
private static final String OPERATION_LOAD_ASSIGNABLE_ROLES = DOT_CLASS + "loadAssignableRoles";
private static final String OPERATION_LOAD_ASSIGNABLE_RELATIONS_LIST = DOT_CLASS + "loadAssignableRelationsList";
private static final String OPERATION_LOAD_ASSIGNMENTS_LIMIT = DOT_CLASS + "loadAssignmentsLimit";
private static final Trace LOGGER = TraceManager.getTrace(AbstractShoppingCartTabPanel.class);

Expand Down Expand Up @@ -221,14 +223,18 @@ private void initRelationPanel(WebMarkupContainer parametersPanel){
relationContainer.setOutputMarkupId(true);
parametersPanel.add(relationContainer);

List<QName> availableRelations = WebComponentUtil.getCategoryRelationChoices(AreaCategoryType.SELF_SERVICE, getPageBase());
List<QName> assignableRelationsList = getAvailableRelationsList();
if (CollectionUtils.isNotEmpty(assignableRelationsList)){
getRoleCatalogStorage().setSelectedRelation(assignableRelationsList.get(0));
}
relationContainer.add(new RelationDropDownChoicePanel(ID_RELATION, getRoleCatalogStorage().getSelectedRelation(),
availableRelations, false){
assignableRelationsList, false){
private static final long serialVersionUID = 1L;

@Override
protected void onValueChanged(AjaxRequestTarget target){
getRoleCatalogStorage().setSelectedRelation(getRelationValue());
target.add(AbstractShoppingCartTabPanel.this);
}

@Override
Expand All @@ -238,6 +244,18 @@ protected IModel<String> getRelationLabelModel(){
});
}

private List<QName> getAvailableRelationsList(){
List<QName> availableRelations = WebComponentUtil.getCategoryRelationChoices(AreaCategoryType.SELF_SERVICE, getPageBase());
Task task = getPageBase().createSimpleTask(OPERATION_LOAD_ASSIGNABLE_RELATIONS_LIST);
OperationResult result = task.getResult();
List<QName> assignableRelationsList = WebComponentUtil.getAssignableRelationsList(getTargetUser().asPrismObject(), (Class) ObjectTypes.getObjectTypeClass(getQueryType()),
WebComponentUtil.AssignmentOrder.ASSIGNMENT, result, task, getPageBase());
if (CollectionUtils.isEmpty(assignableRelationsList)){
return availableRelations;
}
return assignableRelationsList;
}

private void initButtonsPanel(WebMarkupContainer parametersPanel){
AjaxButton addAllButton = new AjaxButton(ID_ADD_ALL_BUTTON, createStringResource("AbstractShoppingCartTabPanel.addAllButton")) {
private static final long serialVersionUID = 1L;
Expand Down Expand Up @@ -418,7 +436,7 @@ private ObjectFilter getAssignableRolesFilter() {
Task task = getPageBase().createSimpleTask(OPERATION_LOAD_ASSIGNABLE_ROLES);
OperationResult result = task.getResult();
return WebComponentUtil.getAssignableRolesFilter(getTargetUser().asPrismObject(), (Class) ObjectTypes.getObjectTypeClass(getQueryType()),
WebComponentUtil.AssignmentOrder.ASSIGNMENT, result, task, getPageBase());
getNewAssignmentRelation(), WebComponentUtil.AssignmentOrder.ASSIGNMENT, result, task, getPageBase());
}

protected abstract QName getQueryType();
Expand Down
Expand Up @@ -31,6 +31,10 @@ public int size() {
return relationMap.size();
}

public Map<QName, ObjectFilter> getRelationMap() {
return relationMap;
}

public ObjectFilter getGlobalFilter() {
return globalFilter;
}
Expand Down

0 comments on commit b9aa5e4

Please sign in to comment.