Skip to content

Commit

Permalink
more fixes for unassign action on members panel
Browse files Browse the repository at this point in the history
# Conflicts:
#	gui/admin-gui/src/main/java/com/evolveum/midpoint/web/page/admin/roles/RoleGovernanceRelationsPanel.java
  • Loading branch information
KaterynaHonchar committed Jun 20, 2018
1 parent e63a10f commit 21135b6
Show file tree
Hide file tree
Showing 9 changed files with 532 additions and 8 deletions.
@@ -0,0 +1,20 @@
<!--
~ Copyright (c) 2010-2018 Evolveum
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->

<wicket:panel xmlns:wicket="http://wicket.apache.org">
<div wicket:id="objectListPanel" />
<wicket:child />
</wicket:panel>
@@ -0,0 +1,139 @@
/*
* Copyright (c) 2010-2018 Evolveum
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.evolveum.midpoint.gui.api.component;

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.result.OperationResult;
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.util.SelectableBean;
import com.evolveum.midpoint.web.security.SecurityUtils;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.RoleType;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model;

import java.util.ArrayList;
import java.util.List;

/**
* Created by honchar.
*/
public abstract class AbstractAssignmentPopupTabPanel<O extends ObjectType> extends BasePanel<List<O>> {

private static final long serialVersionUID = 1L;

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;

public AbstractAssignmentPopupTabPanel(String id, ObjectTypes type, IModel<List<O>> selectedObjectsList){
super(id, selectedObjectsList);
this.type = type;
}

@Override
protected void onInitialize(){
super.onInitialize();
add(initObjectListPanel());
initParametersPanel();
}

private PopupObjectListPanel initObjectListPanel(){
PopupObjectListPanel<O> listPanel = new PopupObjectListPanel<O>(ID_OBJECT_LIST_PANEL, (Class)type.getClassDefinition(), null, true,
getPageBase(), getModelObject()) {

private static final long serialVersionUID = 1L;

@Override
protected void onUpdateCheckbox(AjaxRequestTarget target) {
// if (type.equals(ObjectTypes.RESOURCE)) {
// target.add(AbstractAssignmentPopupTabPanel.this);
// }
onSelectionPerformed(target);
}

@Override
protected IModel<Boolean> getCheckBoxEnableModel(IModel<SelectableBean<O>> rowModel){
return getObjectSelectCheckBoxEnableModel();
}

@Override
protected ObjectQuery addFilterToContentQuery(ObjectQuery query) {
if (type.equals(RoleType.COMPLEX_TYPE)) {
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;
}

};

listPanel.setOutputMarkupId(true);
return listPanel;
}

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

protected List getSelectedObjectsList(){
PopupObjectListPanel objectListPanel = getObjectListPanel();
if (objectListPanel == null){
return new ArrayList();
}
return objectListPanel.getSelectedObjects();
}

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

protected abstract void initParametersPanel();

protected void onSelectionPerformed(AjaxRequestTarget target){}
}
@@ -0,0 +1,26 @@
<!--
~ Copyright (c) 2010-2017 Evolveum
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->

<wicket:panel xmlns:wicket="http://wicket.apache.org">
<form wicket:id="form">
<div wicket:id="tabsPanel"/>

<p align="right">
<a class="btn btn-default btn-sm" wicket:id="cancelButton"/>
<a class="btn btn-default btn-sm" wicket:id="assignButton"/>
</p>
</form>
</wicket:panel>

0 comments on commit 21135b6

Please sign in to comment.