Skip to content

Commit

Permalink
Merge branch 'master' into feature/credentials-refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
semancik committed Mar 20, 2017
2 parents 9d8fedd + 27487ef commit 26fa7c0
Show file tree
Hide file tree
Showing 38 changed files with 1,030 additions and 69 deletions.
Expand Up @@ -57,6 +57,7 @@
import com.evolveum.midpoint.web.session.SessionStorage;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang3.EnumUtils;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.form.OnChangeAjaxBehavior;
import org.apache.wicket.ajax.markup.html.AjaxLink;
Expand Down Expand Up @@ -112,28 +113,31 @@ public class AssignmentCatalogPanel<F extends AbstractRoleType> extends BasePane
private int itemsPerRow = 4;
private boolean showUserSelectionPopup = true;
private List<AssignmentEditorDto> listProviderData;

private AssignmentViewType defaultAssignmentViewType = AssignmentViewType.ROLE_CATALOG_VIEW;
List<AssignmentViewType> viewTypeList = new ArrayList<>();

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

public AssignmentCatalogPanel(String id, String rootOid, PageBase pageBase) {
public AssignmentCatalogPanel(String id, String rootOid, List<AssignmentViewType> viewTypeList, PageBase pageBase) {
super(id);
this.pageBase = pageBase;
this.rootOid = rootOid;
this.viewTypeList = viewTypeList;
AssignmentViewType.saveViewTypeToSession(pageBase, AssignmentViewType.ROLE_CATALOG_VIEW);
initLayout();
}

public AssignmentCatalogPanel(String id, PageBase pageBase) {
this(id, AssignmentViewType.getViewTypeFromSession(pageBase), pageBase);
public AssignmentCatalogPanel(String id, List<AssignmentViewType> viewTypeList, PageBase pageBase) {
this(id, AssignmentViewType.getViewTypeFromSession(pageBase), viewTypeList, pageBase);
}

public AssignmentCatalogPanel(String id, AssignmentViewType viewType, PageBase pageBase) {
public AssignmentCatalogPanel(String id, AssignmentViewType viewType, List<AssignmentViewType> viewTypeList, PageBase pageBase) {
super(id);
this.pageBase = pageBase;
AssignmentViewType.saveViewTypeToSession(pageBase, viewType);
AssignmentViewType.saveViewTypeToSession(pageBase, viewType);
this.viewTypeList = viewTypeList;
initLayout();
}

Expand Down Expand Up @@ -221,6 +225,7 @@ protected OrgTreeStateStorage getOrgTreeStateStorage(){
treePanel.setOutputMarkupId(true);
treePanelContainer.add(new AttributeAppender("class", "col-md-3"));
treePanelContainer.add(new VisibleEnableBehaviour(){
private static final long serialVersionUID = 1L;
@Override
public boolean isVisible(){
return !isCatalogOidEmpty();
Expand All @@ -243,6 +248,7 @@ public boolean isVisible(){
Label assignmentsOwnerLabel = new Label(ID_ASSIGNMENTS_OWNER_NAME,
createStringResource("AssignmentCatalogPanel.assignmentsOwner", assignmentsOwnerName));
assignmentsOwnerLabel.add(new VisibleEnableBehaviour(){
private static final long serialVersionUID = 1L;
@Override
public boolean isVisible(){
return AssignmentViewType.USER_TYPE.equals(pageBase.getSessionStorage().getRoleCatalog().getViewType());
Expand Down Expand Up @@ -295,6 +301,7 @@ private void selectTreeItemPerformed(SelectableBean<OrgType> selected, AjaxReque

private void initModels(){
selectedTreeItemOidModel = new IModel<String>() {
private static final long serialVersionUID = 1L;
@Override
public String getObject() {
return StringUtils.isEmpty(pageBase.getSessionStorage().getRoleCatalog().getSelectedOid()) ?
Expand All @@ -312,6 +319,7 @@ public void detach() {
}
};
viewModel = new IModel<AssignmentViewType>() {
private static final long serialVersionUID = 1L;
@Override
public AssignmentViewType getObject() {
return AssignmentViewType.getViewTypeFromSession(pageBase);
Expand All @@ -329,6 +337,7 @@ public void detach() {
};

searchModel = new LoadableModel<Search>(false) {
private static final long serialVersionUID = 1L;
@Override
public Search load() {
Search search = SearchFactory.createSearch(AbstractRoleType.class, pageBase.getPrismContext(),
Expand All @@ -338,6 +347,7 @@ public Search load() {
};

targetUserModel = new IModel<PrismObject<UserType>>() {
private static final long serialVersionUID = 1L;
@Override
public PrismObject<UserType> getObject() {
return getTargetUser();
Expand Down Expand Up @@ -367,6 +377,7 @@ private void initUserSelectionPanel(WebMarkupContainer headerPanel){
WebMarkupContainer targetUserContainer = new WebMarkupContainer(ID_TARGET_USER_CONTAINER);
targetUserContainer.setOutputMarkupId(true);
AjaxLink<String> targetUserButton = new AjaxLink<String>(ID_TARGET_USER_BUTTON) {
private static final long serialVersionUID = 1L;
@Override
public void onClick(AjaxRequestTarget target) {
if (showUserSelectionPopup) {
Expand All @@ -381,6 +392,7 @@ public void onClick(AjaxRequestTarget target) {
targetUserButton.add(label);

AjaxLink deleteButton = new AjaxLink(ID_DELETE_TARGET_USER_BUTTON) {
private static final long serialVersionUID = 1L;
@Override
public void onClick(AjaxRequestTarget target) {
showUserSelectionPopup = false;
Expand All @@ -389,6 +401,7 @@ public void onClick(AjaxRequestTarget target) {
}
};
deleteButton.add(new VisibleEnableBehaviour(){
private static final long serialVersionUID = 1L;
@Override
public boolean isVisible(){
return pageBase.getSessionStorage().getRoleCatalog().getTargetUser() != null;
Expand All @@ -398,9 +411,12 @@ public boolean isVisible(){
headerPanel.add(targetUserContainer);
}
private void initViewSelector(WebMarkupContainer headerPanel){
DropDownChoice<AssignmentViewType> viewSelect = new DropDownChoice(ID_VIEW_TYPE, viewModel, new ListModel(createAssignableTypesList()),
DropDownChoice<AssignmentViewType> viewSelect = new DropDownChoice(ID_VIEW_TYPE, viewModel,
Model.ofList(viewTypeList != null && viewTypeList.size() > 0 ?
viewTypeList : createAssignableTypesList()),
new EnumChoiceRenderer<AssignmentViewType>(this));
viewSelect.add(new OnChangeAjaxBehavior() {
private static final long serialVersionUID = 1L;

@Override
protected void onUpdate(AjaxRequestTarget target) {
Expand Down Expand Up @@ -430,6 +446,7 @@ private WebMarkupContainer getHeaderPanel(){
private DropDownChoice getViewSelectComponent(){
return (DropDownChoice)getHeaderPanel().get(ID_VIEW_TYPE);
}

private void initSearchPanel(WebMarkupContainer headerPanel) {
final Form searchForm = new Form(ID_SEARCH_FORM);
headerPanel.add(searchForm);
Expand All @@ -442,6 +459,7 @@ public boolean isVisible() {
searchForm.setOutputMarkupId(true);

SearchPanel search = new SearchPanel(ID_SEARCH, (IModel) searchModel, false) {
private static final long serialVersionUID = 1L;

@Override
public void searchPerformed(ObjectQuery query, AjaxRequestTarget target) {
Expand Down Expand Up @@ -487,7 +505,7 @@ protected ObjectQuery createContentQuery(ObjectQuery searchQuery) {
private ObjectQuery createMemberQuery(QName focusTypeClass) {
ObjectQuery query = new ObjectQuery();
ObjectFilter filter = null;
if (focusTypeClass.equals(RoleType.COMPLEX_TYPE)) {
if (RoleType.COMPLEX_TYPE.equals(focusTypeClass)) {
LOGGER.debug("Loading roles which the current user has right to assign");
OperationResult result = new OperationResult(OPERATION_LOAD_ASSIGNABLE_ROLES);
try {
Expand Down Expand Up @@ -606,10 +624,10 @@ private boolean isCatalogOidEmpty(){
private void initUserSelectionPopup(StringResourceModel title, boolean targetUserSelection, AjaxRequestTarget target) {

List<QName> supportedTypes = new ArrayList<>();
supportedTypes.add(getPageBase().getPrismContext().getSchemaRegistry()
supportedTypes.add(pageBase.getPrismContext().getSchemaRegistry()
.findObjectDefinitionByCompileTimeClass(UserType.class).getTypeName());
ObjectBrowserPanel<UserType> focusBrowser = new ObjectBrowserPanel<UserType>(getPageBase().getMainPopupBodyId(),
UserType.class, supportedTypes, false, getPageBase()) {
ObjectBrowserPanel<UserType> focusBrowser = new ObjectBrowserPanel<UserType>(pageBase.getMainPopupBodyId(),
UserType.class, supportedTypes, false, pageBase) {
@Override
protected void onSelectPerformed(AjaxRequestTarget target, UserType targetUser) {
super.onSelectPerformed(target, targetUser);
Expand All @@ -631,7 +649,7 @@ public StringResourceModel getTitle() {
}

};
getPageBase().showMainPopup(focusBrowser, target);
pageBase.showMainPopup(focusBrowser, target);
}

private WebMarkupContainer getTargetUserContainer(){
Expand Down Expand Up @@ -682,5 +700,6 @@ private PrismObject<UserType> getTargetUser(){
}
return pageBase.loadUserSelf(pageBase);
}

}

Expand Up @@ -33,6 +33,9 @@
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.Form;

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

/**
* Created by honchar.
*/
Expand All @@ -50,6 +53,7 @@ public class PageAssignmentShoppingKart extends PageSelf {
private static final String ID_MAIN_FORM = "mainForm";
private static final String DOT_CLASS = PageAssignmentShoppingKart.class.getName() + ".";
private static final String OPERATION_LOAD_ROLE_CATALOG_REFERENCE = DOT_CLASS + "loadRoleCatalogReference";
private static final String OPERATION_GET_ASSIGNMENT_VIEW_LIST = DOT_CLASS + "getAssignmentViewList";
private static final Trace LOGGER = TraceManager.getTrace(PageAssignmentShoppingKart.class);

private String catalogOid = null;
Expand Down Expand Up @@ -91,12 +95,40 @@ private String getRoleCatalogOid() {
}

private Component initMainPanel() {
AssignmentViewType viewType = AssignmentViewType.getViewTypeFromSession(getPageBase());
List<AssignmentViewType> viewTypeList = getAssignmentViewList();
AssignmentViewType viewType = null;
AssignmentViewType viewTypeIfNoRoleCatalog = null;
if (viewTypeList != null && viewTypeList.size() > 0){
for (AssignmentViewType assignmentViewType : viewTypeList){
if (AssignmentViewType.ROLE_CATALOG_VIEW.equals(assignmentViewType)){
viewType = AssignmentViewType.ROLE_CATALOG_VIEW;
break;
}
}
if (viewType == null){
viewType = viewTypeList.get(0);
viewTypeIfNoRoleCatalog = viewTypeList.get(0);
} else {
if (viewTypeList.size() == 1){
viewTypeIfNoRoleCatalog = viewTypeList.get(0);
} else {
for (AssignmentViewType assignmentViewType : viewTypeList){
if (!viewType.equals(assignmentViewType)){
viewTypeIfNoRoleCatalog = assignmentViewType;
break;
}
}
}
}
} else {
viewType = AssignmentViewType.ROLE_CATALOG_VIEW;
viewTypeIfNoRoleCatalog = AssignmentViewType.ROLE_TYPE;
}
if (AssignmentViewType.ROLE_CATALOG_VIEW.equals(viewType)) {
if (StringUtils.isEmpty(catalogOid)) {
if (isFirstInit) {
if (isFirstInit && !viewTypeIfNoRoleCatalog.equals(AssignmentViewType.ROLE_CATALOG_VIEW)) {
isFirstInit = false;
AssignmentCatalogPanel panel = new AssignmentCatalogPanel(ID_MAIN_PANEL, AssignmentViewType.ROLE_TYPE, PageAssignmentShoppingKart.this);
AssignmentCatalogPanel panel = new AssignmentCatalogPanel(ID_MAIN_PANEL, viewTypeIfNoRoleCatalog, viewTypeList, PageAssignmentShoppingKart.this);
panel.setOutputMarkupId(true);
return panel;
} else {
Expand All @@ -105,15 +137,41 @@ private Component initMainPanel() {
return panel;
}
} else {
AssignmentCatalogPanel panel = new AssignmentCatalogPanel(ID_MAIN_PANEL, catalogOid, PageAssignmentShoppingKart.this);
AssignmentCatalogPanel panel = new AssignmentCatalogPanel(ID_MAIN_PANEL, catalogOid, viewTypeList, PageAssignmentShoppingKart.this);
panel.setOutputMarkupId(true);
return panel;
}
} else {
AssignmentCatalogPanel panel = new AssignmentCatalogPanel(ID_MAIN_PANEL, PageAssignmentShoppingKart.this);
AssignmentCatalogPanel panel = new AssignmentCatalogPanel(ID_MAIN_PANEL, viewType, viewTypeList, PageAssignmentShoppingKart.this);
panel.setRootOid(catalogOid);
panel.setOutputMarkupId(true);
return panel;
}
}

private List<AssignmentViewType> getAssignmentViewList() {
OperationResult result = new OperationResult(OPERATION_GET_ASSIGNMENT_VIEW_LIST);
SystemConfigurationType config;
List<AssignmentViewType> assignmentViewTypes = new ArrayList<>();
try {
config = getModelInteractionService().getSystemConfiguration(result);
} catch (ObjectNotFoundException | SchemaException e) {
LOGGER.error("Error getting system configuration: {}", e.getMessage(), e);
return null;
}
if (config != null && config.getRoleManagement() != null
&& config.getRoleManagement().getRoleCatalogCollections() != null
&& config.getRoleManagement().getRoleCatalogCollections().getCollection() != null) {
for (ObjectCollectionUseType collection :
config.getRoleManagement().getRoleCatalogCollections().getCollection()){
for (AssignmentViewType viewType : AssignmentViewType.values()){
if (viewType.getUri().equals(collection.getCollectionUri())){
assignmentViewTypes.add(viewType);
}
}
}
}
return assignmentViewTypes;
}

}
Expand Up @@ -17,13 +17,28 @@
package com.evolveum.midpoint.web.page.self.dto;

import com.evolveum.midpoint.gui.api.page.PageBase;
import com.evolveum.midpoint.schema.constants.SchemaConstants;
import com.evolveum.midpoint.web.session.SessionStorage;

/**
* Created by honchar.
*/
public enum AssignmentViewType {
ROLE_CATALOG_VIEW, ROLE_TYPE, ORG_TYPE, SERVICE_TYPE, USER_TYPE;
ROLE_CATALOG_VIEW(SchemaConstants.OBJECT_COLLECTION_ROLE_CATALOG_URI),
ROLE_TYPE(SchemaConstants.OBJECT_COLLECTION_ALL_ROLES_URI),
ORG_TYPE(SchemaConstants.OBJECT_COLLECTION_ALL_ORGS_URI),
SERVICE_TYPE(SchemaConstants.OBJECT_COLLECTION_ALL_SERVICES_URI),
USER_TYPE(SchemaConstants.OBJECT_COLLECTION_USER_ASSIGNMENTS_URI);

private String uri;

AssignmentViewType(String uri){
this.uri = uri;
}

public String getUri() {
return uri;
}

public static AssignmentViewType getViewTypeFromSession(PageBase pageBase){
SessionStorage storage = pageBase.getSessionStorage();
Expand Down
Expand Up @@ -49,7 +49,7 @@ public class RoleCatalogStorage implements PageStorage, OrgTreeStateStorage {
private int selectedTabId = 0; //selected tab id on the Org. structure page
private SelectableBean<OrgType> collapsedItem = null; //collapsed tree item
private List<AssignmentEditorDto> assignmentShoppingCart; // a list of assignments in the shopping cart
private AssignmentViewType viewType = AssignmentViewType.ROLE_CATALOG_VIEW; //the current view type
private AssignmentViewType viewType = null; //the current view type
private PrismObject<UserType> targetUser = null;
private PrismObject<UserType> assignmentsUserOwner = null;
private List<AssignmentConflictDto> conflictsList;
Expand Down Expand Up @@ -154,9 +154,6 @@ public void setAssignmentShoppingCart(List<AssignmentEditorDto> assignmentShoppi
}

public AssignmentViewType getViewType() {
if (viewType == null){
viewType = AssignmentViewType.ROLE_TYPE;
}
return viewType;
}

Expand Down
Expand Up @@ -432,6 +432,12 @@ public abstract class SchemaConstants {
public static final QName OBJECT_COLLECTION_ALL_SERVICES_QNAME = new QName(NS_OBJECT_COLLECTIONS, "allServices");
public static final String OBJECT_COLLECTION_ALL_SERVICES_URI = QNameUtil.qNameToUri(OBJECT_COLLECTION_ALL_SERVICES_QNAME);

/**
* Collection that contains user's assignments.
*/
public static final QName OBJECT_COLLECTION_USER_ASSIGNMENTS_QNAME = new QName(NS_OBJECT_COLLECTIONS, "userAssignments");
public static final String OBJECT_COLLECTION_USER_ASSIGNMENTS_URI = QNameUtil.qNameToUri(OBJECT_COLLECTION_ALL_SERVICES_QNAME);

// Samples

public static final QName SAMPLES_SSN = new QName(SchemaConstants.NS_SAMPLES_EXTENSION, "ssn");
Expand Down
Expand Up @@ -577,6 +577,9 @@
<xsd:documentation>
Contains either generated value or value which will be validated
</xsd:documentation>
<xsd:appinfo>
<a:rawType/>
</xsd:appinfo>
</xsd:annotation>
</xsd:element>

Expand Down

0 comments on commit 26fa7c0

Please sign in to comment.