Skip to content

Commit

Permalink
more cleanup for member panels, fixing type item search
Browse files Browse the repository at this point in the history
  • Loading branch information
katkav committed Apr 16, 2021
1 parent b95bad1 commit f9e388d
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 130 deletions.
Expand Up @@ -30,7 +30,6 @@
import com.evolveum.midpoint.gui.api.util.WebComponentUtil;
import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.prism.query.ObjectQuery;
import com.evolveum.midpoint.schema.constants.SchemaConstants;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.task.api.Task;
import com.evolveum.midpoint.util.exception.SchemaException;
Expand All @@ -46,7 +45,6 @@
import com.evolveum.midpoint.web.page.admin.PageAdminFocus;
import com.evolveum.midpoint.web.page.admin.PageAdminObjectDetails;
import com.evolveum.midpoint.web.page.admin.roles.AbstractRoleMemberPanel;
import com.evolveum.midpoint.web.page.admin.roles.AvailableRelationDto;
import com.evolveum.midpoint.web.page.admin.users.dto.UserDtoStatus;
import com.evolveum.midpoint.web.page.self.PageAssignmentShoppingCart;
import com.evolveum.midpoint.web.security.GuiAuthorizationConstants;
Expand Down Expand Up @@ -219,7 +217,7 @@ public boolean isVisible() {

public AbstractRoleMemberPanel<R> createMemberPanel(String panelId, PageBase parentPage) {

return new AbstractRoleMemberPanel<R>(panelId, new Model<>(getObject().asObjectable()), parentPage) {
return new AbstractRoleMemberPanel<R>(panelId, new Model<>(getObject().asObjectable())) {

private static final long serialVersionUID = 1L;

Expand All @@ -238,7 +236,7 @@ protected String getStorageKeyTabSuffix() {

public AbstractRoleMemberPanel<R> createGovernancePanel(String panelId, PageBase parentPage) {

return new AbstractRoleMemberPanel<R>(panelId, new Model<>(getObject().asObjectable()), parentPage) {
return new AbstractRoleMemberPanel<R>(panelId, new Model<>(getObject().asObjectable())) {

private static final long serialVersionUID = 1L;

Expand Down
Expand Up @@ -101,7 +101,7 @@ public String toString() {
'}';
}

public List<DisplayableValue<Class<? extends C>>> getAllowedValues(PageBase pageBase) {
public List<DisplayableValue<Class<? extends C>>> getAllowedValues() {
return allowedValues;
}

Expand Down
Expand Up @@ -38,10 +38,10 @@ public SearchTypePanel(String id, IModel<ContainerTypeSearchItem<C>> model) {
protected void initSearchItemField(WebMarkupContainer searchItemContainer) {
Component searchItemField = new WebMarkupContainer(ID_SEARCH_ITEM_FIELD);
ContainerTypeSearchItem<C> item = getModelObject();
if (item != null && item.getAllowedValues(getPageBase()) != null) {
List<DisplayableValue<Class<? extends C>>> allowedValues = item.getAllowedValues(getPageBase());
if (item != null && item.getAllowedValues() != null) {
List<DisplayableValue<Class<? extends C>>> allowedValues = item.getAllowedValues();
if (allowedValues != null && !allowedValues.isEmpty()) {
IModel<List<DisplayableValue<?>>> choices = new ListModel(item.getAllowedValues(getPageBase()));
IModel<List<DisplayableValue<?>>> choices = new ListModel(item.getAllowedValues());
searchItemField = createDropDownChoices(ID_SEARCH_ITEM_FIELD, new PropertyModel<>(getModel(), ContainerTypeSearchItem.F_TYPE), choices, false);
}
}
Expand Down
Expand Up @@ -28,7 +28,7 @@
public class ArchetypeMembersPanel extends AbstractRoleMemberPanel<ArchetypeType> {

public ArchetypeMembersPanel(String id, IModel<ArchetypeType> model, PageBase pageBase) {
super(id, model, pageBase);
super(id, model);
}

private static final long serialVersionUID = 1L;
Expand Down
Expand Up @@ -95,7 +95,6 @@ protected enum QueryScope {
protected static final String ID_CONTAINER_MEMBER = "memberContainer";
protected static final String ID_MEMBER_TABLE = "memberTable";

// private SearchBoxConfigurationHelper abstractRoleMemberSearchConfiguration;
private GuiObjectListPanelConfigurationType additionalPanelConfig;

private static final Map<QName, Map<String, String>> AUTHORIZATIONS = new HashMap<>();
Expand All @@ -115,7 +114,7 @@ protected enum QueryScope {
AUTHORIZATIONS.put(ArchetypeType.COMPLEX_TYPE, GuiAuthorizationConstants.ARCHETYPE_MEMBERS_AUTHORIZATIONS);
}

public AbstractRoleMemberPanel(String id, IModel<R> model, PageBase parentPage) {
public AbstractRoleMemberPanel(String id, IModel<R> model) {
super(id, model);
}

Expand All @@ -130,7 +129,6 @@ protected void initLayout() {
form.setOutputMarkupId(true);
add(form);
this.additionalPanelConfig = getAdditionalPanelConfig();
// this.abstractRoleMemberSearchConfiguration = new SearchBoxConfigurationHelper(additionalPanelConfig, getSupportedRelations());
initMemberTable(form);
setOutputMarkupId(true);
}
Expand Down Expand Up @@ -189,18 +187,13 @@ protected String getStorageKey() {
return AbstractRoleMemberPanel.this.createStorageKey();
}

// @Override
// protected ContainerTypeSearchItem getTypeItem(Class<? extends ObjectType> type, List<DisplayableValue<Class<? extends ObjectType>>> allowedValues) {
//
// }

protected PageStorage getPageStorage(String storageKey){
return getSession().getSessionStorage().getPageStorageMap().get(storageKey);
}

@Override
protected Search createSearch(Class<ObjectType> type) {
return createMemberSearch(type, getTypeItem(type, getAllowedTypes()));
return createMemberSearch(type);
}

@Override
Expand Down Expand Up @@ -234,31 +227,23 @@ private <O extends ObjectType> Class<O> getDefaultObjectTypeClass() {
return (Class<O>) WebComponentUtil.qnameToClass(getPageBase().getPrismContext(), objectTypeQname);
}

private Search createMemberSearch(Class<ObjectType> type, ContainerTypeSearchItem typeItem) {
Search search = null;
private Search createMemberSearch(Class<ObjectType> type) {
Search search;

MemberPanelStorage memberPanelStorage = getMemberPanelStorage();
if (memberPanelStorage == null) { //normally, this should not happen
ContainerTypeSearchItem<ObjectType> defaultTypeItem = new ContainerTypeSearchItem<ObjectType>(type);
ContainerTypeSearchItem<ObjectType> defaultTypeItem = new ContainerTypeSearchItem<>(type);
search = SearchFactory.createSearch(defaultTypeItem, null, null, null, getPageBase(), null, true, true, Search.PanelType.MEMBER_PANEL);
return search;
}

// ContainerTypeSearchItem oldTypeItem;
// if (search != null) {
// if (!search.isTypeChanged()) {
// return search;
// }
// oldTypeItem = search.getType();
// } else {
// oldTypeItem = typeItem;
// }

if (memberPanelStorage.getSearch() != null) {
return memberPanelStorage.getSearch();
}

ContainerTypeSearchItem searchTypeItem = new ContainerTypeSearchItem(WebComponentUtil.qnameToClass(getPrismContext(), memberPanelStorage.getDefaultObjectType()));
Class<ObjectType> typeClass = (Class<ObjectType>) WebComponentUtil.qnameToClass(getPrismContext(), memberPanelStorage.getDefaultObjectType());
SearchValue<Class<ObjectType>> searchClassValue = new SearchValue<>(typeClass, "ObjectType." + typeClass.getSimpleName());
ContainerTypeSearchItem searchTypeItem = new ContainerTypeSearchItem(searchClassValue, getAllowedTypes());
searchTypeItem.setConfiguration(memberPanelStorage.getObjectTypeSearchItem());
searchTypeItem.setVisible(true);

Expand Down Expand Up @@ -334,22 +319,6 @@ private String createStorageKey() {
return tableId.name() + "_" + getStorageKeyTabSuffix() + collectionName;
}




private R getParentVariables(VariablesMap variables) {
if (variables == null) {
return null;
}
try {
return (R) variables.getValue(ExpressionConstants.VAR_PARENT_OBJECT, AbstractRoleType.class);
} catch (SchemaException e) {
LOGGER.error("Couldn't load parent object.");
}
return null;
}


protected Class<? extends ObjectType> getChoiceForAllTypes () {
return FocusType.class;
}
Expand Down Expand Up @@ -378,8 +347,6 @@ protected MultiFunctinalButtonDto load() {

CompositedIconButtonDto mainButton = new CompositedIconButtonDto();
DisplayType mainButtonDisplayType = getCreateMemberButtonDisplayType();
// DisplayType mainButtonDisplayType = WebComponentUtil.createDisplayType(GuiStyleConstants.CLASS_ADD_NEW_OBJECT, "green",
// createStringResource("abstractRoleMemberPanel.menu.createMember", "", "").getString());
mainButton.setAdditionalButtonDisplayType(mainButtonDisplayType);

CompositedIconBuilder builder = new CompositedIconBuilder();
Expand Down Expand Up @@ -425,19 +392,12 @@ private MultifunctionalButton createAssignButton(String buttonId) {

@Override
protected void buttonClickPerformed(AjaxRequestTarget target, AssignmentObjectRelation relation, CompiledObjectCollectionView collectionView) {
List<QName> relations = relation != null && !CollectionUtils.isEmpty(relation.getRelations())
? Collections.singletonList(relation.getRelations().get(0))
: getMemberPanelStorage().getSupportedRelations();
List<QName> availableRelations = getMemberPanelStorage().getSupportedRelations();//new AvailableRelationDto(relations, getSupportedRelations().getDefaultRelation(), abstractRoleMemberSearchConfiguration.getDefaultRelationConfiguration());
List<QName> objectTypes = relation != null && !CollectionUtils.isEmpty(relation.getObjectTypes()) ?
relation.getObjectTypes() : null;
List<ObjectReferenceType> archetypeRefList = relation != null && !CollectionUtils.isEmpty(relation.getArchetypeRefs()) ?
relation.getArchetypeRefs() : null;
assignMembers(target, getMemberPanelStorage().getRelationSearchItem(), objectTypes, archetypeRefList, relation == null);
}



};
assignButton.add(AttributeAppender.append("class", "btn-margin-right"));

Expand Down Expand Up @@ -915,14 +875,6 @@ protected ObjectQuery getActionQuery(QueryScope scope, Collection<QName> relatio
return null;
}

// protected List<QName> getSupportedObjectTypes(boolean includeAbstractTypes) {
// if (!CollectionUtils.isEmpty(abstractRoleMemberSearchConfiguration.getDefaultObjectTypeConfiguration().getSupportedTypes())) {
// return abstractRoleMemberSearchConfiguration.getDefaultObjectTypeConfiguration().getSupportedTypes();
// }
// return getDefaultSupportedObjectTypes(includeAbstractTypes);
// }


protected List<QName> getDefaultSupportedObjectTypes(boolean includeAbstractTypes) {
return WebComponentUtil.createFocusTypeList(includeAbstractTypes);
}
Expand Down Expand Up @@ -1043,7 +995,4 @@ protected String getStorageKeyTabSuffix(){
return "";
}

// protected RelationSearchItemConfigurationType getDefaultRelationConfiguration() {
// return abstractRoleMemberSearchConfiguration.getDefaultRelationConfiguration();
// }
}
Expand Up @@ -31,9 +31,6 @@ public class SearchBoxConfigurationHelper implements Serializable {
private UserInterfaceFeatureType defaultTenantConfiguration = null;
private UserInterfaceFeatureType defaultProjectConfiguration = null;


private Class<ObjectType> defaultObjectTypeClass = null;

private List<QName> supportedRelations;
private List<QName> supportedObjectTypes;
private QName defaultRelation;
Expand Down Expand Up @@ -82,31 +79,10 @@ public ScopeSearchItemConfigurationType getDefaultSearchScopeConfiguration() {
return defaultScopeConfiguration;
}

private UserInterfaceElementVisibilityType getVisibility(UserInterfaceFeatureType feature) {
if (feature == null) {
return UserInterfaceElementVisibilityType.AUTOMATIC;
}

return feature.getVisibility();
}

public ObjectTypeSearchItemConfigurationType getDefaultObjectTypeConfiguration() {
if (defaultObjectTypeConfiguration == null) {
defaultObjectTypeConfiguration = searchBoxConfigurationType.getObjectTypeConfiguration();

// if (defaultObjectTypeConfiguration.getDefaultValue() == null) {
// if (searchBoxConfigurationType.getDefaultObjectType() != null) {
// defaultObjectTypeClass = (Class<ObjectType>) WebComponentUtil.qnameToClass(getPageBase().getPrismContext(),
// searchBoxConfigurationType.getDefaultObjectType());
// }
// } else {
// defaultObjectTypeClass = (Class<ObjectType>) WebComponentUtil.qnameToClass(getPageBase().getPrismContext(),
// defaultObjectTypeConfiguration.getDefaultValue());
// }

// if (defaultObjectTypeClass == null) {
// defaultObjectTypeClass = getDefaultObjectType();
// }
if (defaultObjectTypeConfiguration == null) {
defaultObjectTypeConfiguration = new ObjectTypeSearchItemConfigurationType();
}
Expand All @@ -117,6 +93,10 @@ public ObjectTypeSearchItemConfigurationType getDefaultObjectTypeConfiguration()
if (defaultObjectTypeConfiguration.getDefaultValue() == null) {
defaultObjectTypeConfiguration.setDefaultValue(defaultObjectType);
}

if (CollectionUtils.isEmpty(defaultObjectTypeConfiguration.getSupportedTypes())) {
defaultObjectTypeConfiguration.getSupportedTypes().addAll(supportedObjectTypes);
}
return defaultObjectTypeConfiguration;
}

Expand Down Expand Up @@ -163,18 +143,6 @@ public IndirectSearchItemConfigurationType getDefaultIndirectConfiguration() {
return defaultIndirectConfiguration;
}

public UserInterfaceElementVisibilityType getDefaultIndirecVisibility() {
return getVisibility(getDefaultIndirectConfiguration());
}

public PolyStringType getDefaultIndirectLabel() {
return getDefaultIndirectConfiguration().getDisplay().getLabel();
}

public PolyStringType getDefaultIndirectHelp() {
return getDefaultIndirectConfiguration().getDisplay().getHelp();
}

public UserInterfaceFeatureType getDefaultTenantConfiguration() {
if (defaultTenantConfiguration == null) {
defaultTenantConfiguration = searchBoxConfigurationType.getTenantConfiguration();
Expand All @@ -186,18 +154,6 @@ public UserInterfaceFeatureType getDefaultTenantConfiguration() {
return defaultTenantConfiguration;
}

public UserInterfaceElementVisibilityType getDefaultTenantVisibility() {
return getVisibility(getDefaultTenantConfiguration());
}

public PolyStringType getDefaultTenantLabel() {
return getDefaultTenantConfiguration().getDisplay().getLabel();
}

public PolyStringType getDefaultTenantHelp() {
return getDefaultTenantConfiguration().getDisplay().getHelp();
}

public UserInterfaceFeatureType getDefaultProjectConfiguration() {
if (defaultProjectConfiguration == null) {
defaultProjectConfiguration = searchBoxConfigurationType.getProjectConfiguration();
Expand All @@ -209,19 +165,6 @@ public UserInterfaceFeatureType getDefaultProjectConfiguration() {
return defaultProjectConfiguration;
}

public UserInterfaceElementVisibilityType getDefaultProjectVisibility() {
return getVisibility(getDefaultProjectConfiguration());
}

public PolyStringType getDefaultProjectLabel() {
return getDefaultProjectConfiguration().getDisplay().getLabel();
}

public PolyStringType getDefaultProjectHelp() {
return getDefaultProjectConfiguration().getDisplay().getHelp();
}


private void setDisplay(UserInterfaceFeatureType configuration, String orig, String labelKey, String helpKey) {
if (configuration.getDisplay() == null) {
DisplayType display = new DisplayType();
Expand Down
Expand Up @@ -31,7 +31,7 @@ public class OrgMemberPanel extends AbstractRoleMemberPanel<OrgType> {
private static final Trace LOGGER = TraceManager.getTrace(OrgMemberPanel.class);

public OrgMemberPanel(String id, IModel<OrgType> model, PageBase parentPage) {
super(id, model, parentPage);
super(id, model);
setOutputMarkupId(true);
}

Expand Down

0 comments on commit f9e388d

Please sign in to comment.