Skip to content

Commit

Permalink
upgrade to commons-collections4 in our code, including cleanup/reformat
Browse files Browse the repository at this point in the history
  • Loading branch information
virgo47 committed Sep 4, 2020
1 parent e774667 commit 3d4f9b7
Show file tree
Hide file tree
Showing 73 changed files with 2,262 additions and 2,421 deletions.
4 changes: 0 additions & 4 deletions gui/admin-gui/pom.xml
Expand Up @@ -573,10 +573,6 @@
<groupId>org.apache.commons</groupId>
<artifactId>commons-configuration2</artifactId>
</dependency>
<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
</dependency>
<dependency>
<groupId>commons-beanutils</groupId>
<artifactId>commons-beanutils</artifactId>
Expand Down
@@ -1,35 +1,35 @@
/*
* Copyright (c) 2010-2018 Evolveum and contributors
* Copyright (C) 2010-2020 Evolveum and contributors
*
* This work is dual-licensed under the Apache License 2.0
* and European Union Public License. See LICENSE file for details.
*/
package com.evolveum.midpoint.gui.api.component;

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

import org.apache.commons.collections4.CollectionUtils;
import org.apache.wicket.Component;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.extensions.markup.html.repeater.data.table.IColumn;
import org.apache.wicket.markup.html.panel.Fragment;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model;

import com.evolveum.midpoint.prism.query.ObjectFilter;
import com.evolveum.midpoint.prism.query.ObjectQuery;
import com.evolveum.midpoint.prism.query.OrFilter;
import com.evolveum.midpoint.prism.query.RefFilter;
import com.evolveum.midpoint.schema.constants.ObjectTypes;
import com.evolveum.midpoint.web.component.data.column.ColumnUtils;
import com.evolveum.midpoint.web.component.util.SelectableBean;
import com.evolveum.midpoint.web.component.util.SelectableBeanImpl;
import com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour;
import com.evolveum.midpoint.xml.ns._public.common.common_3.AbstractRoleType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentHolderType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType;
import org.apache.commons.collections.CollectionUtils;
import org.apache.wicket.Component;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.extensions.markup.html.repeater.data.table.IColumn;
import org.apache.wicket.markup.html.panel.Fragment;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model;

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

/**
* Created by honchar
Expand All @@ -43,12 +43,12 @@ public abstract class AbstractPopupTabPanel<O extends ObjectType> extends BasePa

protected List<O> preSelectedObjects = new ArrayList<>();

public AbstractPopupTabPanel(String id){
public AbstractPopupTabPanel(String id) {
super(id);
}

@Override
protected void onInitialize(){
protected void onInitialize() {
super.onInitialize();
setOutputMarkupId(true);
add(initObjectListPanel());
Expand All @@ -60,17 +60,17 @@ protected void onInitialize(){
add(parametersPanelFragment);
}

protected Component initObjectListPanel(){
PopupObjectListPanel<O> listPanel = new PopupObjectListPanel<O>(ID_OBJECT_LIST_PANEL, (Class)getObjectType().getClassDefinition(),
protected Component initObjectListPanel() {
PopupObjectListPanel<O> listPanel = new PopupObjectListPanel<O>(ID_OBJECT_LIST_PANEL, (Class) getObjectType().getClassDefinition(),
true, getPageBase()) {

private static final long serialVersionUID = 1L;

@Override
protected List<IColumn<SelectableBean<O>, String>> createColumns() {
if (AbstractRoleType.class.isAssignableFrom(getType())){
if (AbstractRoleType.class.isAssignableFrom(getType())) {
List<IColumn<SelectableBean<O>, String>> columns = new ArrayList<>();
columns.addAll((Collection)ColumnUtils.getDefaultAbstractRoleColumns(false));
columns.addAll((Collection) ColumnUtils.getDefaultAbstractRoleColumns(false));
return columns;
} else {
return super.createColumns();
Expand All @@ -83,52 +83,52 @@ protected void onUpdateCheckbox(AjaxRequestTarget target, IModel<SelectableBean<
}

@Override
protected List<O> getPreselectedObjectList(){
protected List<O> getPreselectedObjectList() {
return getPreselectedObjects();
}

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

@Override
protected ObjectQuery addFilterToContentQuery(ObjectQuery query) {
ObjectQuery queryWithFilters = AbstractPopupTabPanel.this.addFilterToContentQuery(query);
if (queryWithFilters == null){
if (queryWithFilters == null) {
queryWithFilters = AbstractPopupTabPanel.this.getPageBase().getPrismContext().queryFactory().createQuery();
}
List<ObjectReferenceType> archetypeRefList = getArchetypeRefList();
if (!CollectionUtils.isEmpty(archetypeRefList)){
if (!CollectionUtils.isEmpty(archetypeRefList)) {
List<ObjectFilter> archetypeRefFilterList = new ArrayList<>();

for (ObjectReferenceType archetypeRef : archetypeRefList){
for (ObjectReferenceType archetypeRef : archetypeRefList) {
ObjectFilter filter = AbstractPopupTabPanel.this.getPageBase().getPrismContext().queryFor(AssignmentHolderType.class)
.item(AssignmentHolderType.F_ARCHETYPE_REF).ref(archetypeRef.getOid())
.buildFilter();
((RefFilter)filter).setTargetTypeNullAsAny(true);
((RefFilter)filter).setRelationNullAsAny(true);
((RefFilter) filter).setTargetTypeNullAsAny(true);
((RefFilter) filter).setRelationNullAsAny(true);
archetypeRefFilterList.add(filter);
}
if (!CollectionUtils.isEmpty(archetypeRefFilterList)){
if (!CollectionUtils.isEmpty(archetypeRefFilterList)) {
OrFilter archetypeRefOrFilter =
AbstractPopupTabPanel.this.getPageBase().getPrismContext().queryFactory().createOr(archetypeRefFilterList);
queryWithFilters.addFilter(archetypeRefOrFilter);
}
}

ObjectFilter subTypeFilter = getSubtypeFilter();
if (subTypeFilter != null){
if (subTypeFilter != null) {
queryWithFilters.addFilter(subTypeFilter);
}
return queryWithFilters;
}

};
listPanel.add(new VisibleEnableBehaviour(){
listPanel.add(new VisibleEnableBehaviour() {
private static final long serialVersionUID = 1L;

public boolean isVisible(){
public boolean isVisible() {
return isObjectListPanelVisible();
}
});
Expand All @@ -138,47 +138,48 @@ public boolean isVisible(){

protected abstract void initParametersPanel(Fragment parametersPanel);

protected List<O> getPreselectedObjects(){
protected List<O> getPreselectedObjects() {
return null;
}

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

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

protected void onSelectionPerformed(AjaxRequestTarget target, IModel<SelectableBean<O>> rowModel){}
protected void onSelectionPerformed(AjaxRequestTarget target, IModel<SelectableBean<O>> rowModel) {
}

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

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

protected List<ObjectReferenceType> getArchetypeRefList(){
protected List<ObjectReferenceType> getArchetypeRefList() {
return null;
}

protected ObjectFilter getSubtypeFilter(){
protected ObjectFilter getSubtypeFilter() {
return null;
}

protected boolean isObjectListPanelVisible(){
protected boolean isObjectListPanelVisible() {
return true;
}

protected abstract ObjectTypes getObjectType();

protected boolean isInducement(){
protected boolean isInducement() {
return false;
}
}
@@ -1,23 +1,18 @@
/*
* Copyright (c) 2010-2018 Evolveum and contributors
* Copyright (C) 2010-2020 Evolveum and contributors
*
* This work is dual-licensed under the Apache License 2.0
* and European Union Public License. See LICENSE file for details.
*/
package com.evolveum.midpoint.gui.api.component;

import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.xml.namespace.QName;

import com.evolveum.midpoint.prism.PrismConstants;
import com.evolveum.midpoint.schema.constants.SchemaConstants;
import com.evolveum.midpoint.util.QNameUtil;

import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.map.HashedMap;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.panel.Fragment;

Expand All @@ -28,9 +23,11 @@
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.QNameUtil;
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.midpoint.web.component.input.RelationDropDownChoicePanel;
Expand All @@ -42,7 +39,7 @@
/**
* Created by honchar
*/
public class FocusTypeAssignmentPopupTabPanel<F extends FocusType> extends AbstractAssignmentPopupTabPanel<F>{
public class FocusTypeAssignmentPopupTabPanel<F extends FocusType> extends AbstractAssignmentPopupTabPanel<F> {

private static final long serialVersionUID = 1L;

Expand All @@ -53,17 +50,19 @@ public class FocusTypeAssignmentPopupTabPanel<F extends FocusType> extends Abstr
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){
public FocusTypeAssignmentPopupTabPanel(String id, ObjectTypes type) {
super(id, type);
}

@Override
protected void initParametersPanel(Fragment parametersPanel){
protected void initParametersPanel(Fragment parametersPanel) {
WebMarkupContainer relationContainer = new WebMarkupContainer(ID_RELATION_CONTAINER);
relationContainer.setOutputMarkupId(true);
parametersPanel.add(relationContainer);

List<QName> relationsList = getPredefinedRelation() != null ? Arrays.asList(getPredefinedRelation()) : getSupportedRelations();
List<QName> relationsList = getPredefinedRelation() != null
? Collections.singletonList(getPredefinedRelation())
: getSupportedRelations();
relationContainer.add(new RelationDropDownChoicePanel(ID_RELATION, getDefaultRelationIfInList(relationsList),
relationsList, false));
}
Expand All @@ -72,14 +71,14 @@ protected List<QName> getSupportedRelations() {
return WebComponentUtil.getCategoryRelationChoices(AreaCategoryType.ADMINISTRATION, getPageBase());
}

protected QName getPredefinedRelation(){
protected QName getPredefinedRelation() {
return null;
}

private QName getDefaultRelationIfInList(List<QName> relationsList){
if (CollectionUtils.isNotEmpty(relationsList)){
for (QName relation : relationsList){
if (QNameUtil.match(relation, SchemaConstants.ORG_DEFAULT)){
private QName getDefaultRelationIfInList(List<QName> relationsList) {
if (CollectionUtils.isNotEmpty(relationsList)) {
for (QName relation : relationsList) {
if (QNameUtil.match(relation, SchemaConstants.ORG_DEFAULT)) {
return SchemaConstants.ORG_DEFAULT;
}
}
Expand All @@ -88,52 +87,58 @@ private QName getDefaultRelationIfInList(List<QName> relationsList){
}

@Override
protected Map<String, AssignmentType> getSelectedAssignmentsMap(){
Map<String, AssignmentType> assignmentsMap = new HashedMap();
protected Map<String, AssignmentType> getSelectedAssignmentsMap() {
Map<String, AssignmentType> assignmentsMap = new HashMap<>();

List<F> selectedObjects = getObjectType().equals(ObjectTypes.ORG) ? getPreselectedObjects() : getSelectedObjectsList();
QName relation = getRelationValue();
selectedObjects.forEach(selectedObject -> {
assignmentsMap.put(selectedObject.getOid(), ObjectTypeUtil.createAssignmentTo(selectedObject, relation));
});
selectedObjects.forEach(selectedObject ->
assignmentsMap.put(
selectedObject.getOid(),
ObjectTypeUtil.createAssignmentTo(selectedObject, relation)));
return assignmentsMap;
}

public QName getRelationValue(){
public QName getRelationValue() {
RelationDropDownChoicePanel relationPanel = getRelationDropDown();
return relationPanel.getRelationValue();
}

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

@Override
protected ObjectQuery addFilterToContentQuery(ObjectQuery query){
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 = WebComponentUtil.getAssignableRolesFilter(getTargetedAssignemntObject(), (Class<AbstractRoleType>) getObjectType().getClassDefinition(),
isInducement() ? WebComponentUtil.AssignmentOrder.INDUCEMENT : WebComponentUtil.AssignmentOrder.ASSIGNMENT, result, task, getPageBase());
ObjectFilter filter = WebComponentUtil.getAssignableRolesFilter(
getTargetedAssignemntObject(),
(Class<AbstractRoleType>) getObjectType().getClassDefinition(),
isInducement()
? WebComponentUtil.AssignmentOrder.INDUCEMENT
: WebComponentUtil.AssignmentOrder.ASSIGNMENT,
result, task, getPageBase());
if (query == null) {
query = getPrismContext().queryFactory().createQuery();
}
query.addFilter(filter);
return query;
}

protected boolean isInducement(){
protected boolean isInducement() {
PrismContainerWrapper<AssignmentType> assignmentWrapper = getAssignmentWrapperModel();
if (assignmentWrapper != null && assignmentWrapper.getPath() != null && assignmentWrapper.getPath().containsNameExactly(AbstractRoleType.F_INDUCEMENT)){
if (assignmentWrapper != null && assignmentWrapper.getPath() != null && assignmentWrapper.getPath().containsNameExactly(AbstractRoleType.F_INDUCEMENT)) {
return true;
}
return false;
}

protected <O extends FocusType> PrismObject<O> getTargetedAssignemntObject() {
PrismContainerWrapper<AssignmentType> assignmentWrapper = getAssignmentWrapperModel();
if (assignmentWrapper == null){
if (assignmentWrapper == null) {
return null;
}
PrismObjectWrapper<O> w = (PrismObjectWrapper<O>) assignmentWrapper.getParent().getParent();
Expand All @@ -148,7 +153,7 @@ protected PrismContainerWrapper<AssignmentType> getAssignmentWrapperModel() {
}

@Override
protected ObjectTypes getObjectType(){
protected ObjectTypes getObjectType() {
return ObjectTypes.FOCUS_TYPE;
}
}

0 comments on commit 3d4f9b7

Please sign in to comment.