diff --git a/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/component/MultivalueContainerDetailsPanel.java b/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/component/MultivalueContainerDetailsPanel.java index 2d0ceeadd54..82c30b54710 100644 --- a/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/component/MultivalueContainerDetailsPanel.java +++ b/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/component/MultivalueContainerDetailsPanel.java @@ -1,86 +1,96 @@ -/* - * Copyright (c) 2018 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.impl.component; - -import com.evolveum.midpoint.gui.impl.prism.ItemPanelSettings; -import com.evolveum.midpoint.gui.impl.prism.ItemPanelSettingsBuilder; - -import org.apache.wicket.markup.html.WebMarkupContainer; -import org.apache.wicket.markup.html.panel.Panel; -import org.apache.wicket.model.IModel; - -import com.evolveum.midpoint.gui.api.component.BasePanel; -import com.evolveum.midpoint.gui.api.component.DisplayNamePanel; -import com.evolveum.midpoint.gui.api.prism.ItemWrapper; -import com.evolveum.midpoint.gui.impl.prism.PrismContainerValueWrapper; -import com.evolveum.midpoint.prism.Containerable; -import com.evolveum.midpoint.prism.path.ItemPath; -import com.evolveum.midpoint.web.component.form.Form; -import com.evolveum.midpoint.web.component.prism.ItemVisibility; - -/** - * @author skublik - */ - -public abstract class MultivalueContainerDetailsPanel extends BasePanel> { - private static final long serialVersionUID = 1L; - - private final static String ID_DISPLAY_NAME = "displayName"; - private final static String ID_BASIC_PANEL = "basicPanel"; - protected final static String ID_SPECIFIC_CONTAINERS_PANEL = "specificContainersPanel"; - - public MultivalueContainerDetailsPanel(String id, IModel> model){ - super(id, model); - } - - @Override - protected void onInitialize() { - super.onInitialize(); - initLayout(); - setOutputMarkupId(true); - } - - protected abstract DisplayNamePanel createDisplayNamePanel(String displayNamePanelId); - - private void initLayout(){ - - DisplayNamePanel displayNamePanel = createDisplayNamePanel(ID_DISPLAY_NAME); - - displayNamePanel.setOutputMarkupId(true); - add(displayNamePanel); - - addBasicContainerValuePanel(ID_BASIC_PANEL); - add(getSpecificContainers(ID_SPECIFIC_CONTAINERS_PANEL)); - } - - protected WebMarkupContainer getSpecificContainers(String contentAreaId) { - return new WebMarkupContainer(contentAreaId); - } - - protected void addBasicContainerValuePanel(String idPanel){ - add(getBasicContainerValuePanel(idPanel)); - } - - protected Panel getBasicContainerValuePanel(String idPanel){ - ItemPanelSettings settings = new ItemPanelSettingsBuilder() - .visibilityHandler(wrapper -> getBasicTabVisibity(wrapper)) - .showOnTopLevel(true) - .editabilityHandler(wrapper -> getBasicTabEditability(wrapper)) - .build(); - Panel containerValue = getPageBase().initContainerValuePanel(idPanel, getModel(), settings); - return containerValue; - } - - protected ItemVisibility getBasicTabVisibity(ItemWrapper itemWrapper) { //, ItemPath parentPath) { - return ItemVisibility.AUTO; - } - - protected boolean getBasicTabEditability(ItemWrapper itemWrapper) { - return true; - } - -} +/* + * Copyright (c) 2018 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.impl.component; + +import com.evolveum.midpoint.gui.impl.prism.ItemMandatoryHandler; +import com.evolveum.midpoint.gui.impl.prism.ItemPanelSettings; +import com.evolveum.midpoint.gui.impl.prism.ItemPanelSettingsBuilder; + +import org.apache.wicket.markup.html.WebMarkupContainer; +import org.apache.wicket.markup.html.panel.Panel; +import org.apache.wicket.model.IModel; + +import com.evolveum.midpoint.gui.api.component.BasePanel; +import com.evolveum.midpoint.gui.api.component.DisplayNamePanel; +import com.evolveum.midpoint.gui.api.prism.ItemWrapper; +import com.evolveum.midpoint.gui.impl.prism.PrismContainerValueWrapper; +import com.evolveum.midpoint.prism.Containerable; +import com.evolveum.midpoint.prism.path.ItemPath; +import com.evolveum.midpoint.web.component.form.Form; +import com.evolveum.midpoint.web.component.prism.ItemVisibility; + +/** + * @author skublik + */ + +public abstract class MultivalueContainerDetailsPanel extends BasePanel> { + private static final long serialVersionUID = 1L; + + private final static String ID_DISPLAY_NAME = "displayName"; + private final static String ID_BASIC_PANEL = "basicPanel"; + protected final static String ID_SPECIFIC_CONTAINERS_PANEL = "specificContainersPanel"; + + public MultivalueContainerDetailsPanel(String id, IModel> model){ + super(id, model); + } + + @Override + protected void onInitialize() { + super.onInitialize(); + initLayout(); + setOutputMarkupId(true); + } + + protected abstract DisplayNamePanel createDisplayNamePanel(String displayNamePanelId); + + private void initLayout(){ + + DisplayNamePanel displayNamePanel = createDisplayNamePanel(ID_DISPLAY_NAME); + + displayNamePanel.setOutputMarkupId(true); + add(displayNamePanel); + + addBasicContainerValuePanel(ID_BASIC_PANEL); + add(getSpecificContainers(ID_SPECIFIC_CONTAINERS_PANEL)); + } + + protected WebMarkupContainer getSpecificContainers(String contentAreaId) { + return new WebMarkupContainer(contentAreaId); + } + + protected void addBasicContainerValuePanel(String idPanel){ + add(getBasicContainerValuePanel(idPanel)); + } + + protected Panel getBasicContainerValuePanel(String idPanel){ + ItemPanelSettingsBuilder builder = new ItemPanelSettingsBuilder() + .visibilityHandler(wrapper -> getBasicTabVisibity(wrapper)) + .showOnTopLevel(true) + .editabilityHandler(wrapper -> getBasicTabEditability(wrapper)); + + if (getMandatoryHandler() != null) { + builder.mandatoryHandler(getMandatoryHandler()); + } + + ItemPanelSettings settings = builder.build(); + Panel containerValue = getPageBase().initContainerValuePanel(idPanel, getModel(), settings); + return containerValue; + } + + protected ItemVisibility getBasicTabVisibity(ItemWrapper itemWrapper) { //, ItemPath parentPath) { + return ItemVisibility.AUTO; + } + + protected boolean getBasicTabEditability(ItemWrapper itemWrapper) { + return true; + } + + protected ItemMandatoryHandler getMandatoryHandler() { + return null; + } + +} diff --git a/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/page/admin/configuration/component/ObjectPolicyConfigurationTabPanel.java b/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/page/admin/configuration/component/ObjectPolicyConfigurationTabPanel.java index 91d136cf7fc..63d2155a4dd 100644 --- a/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/page/admin/configuration/component/ObjectPolicyConfigurationTabPanel.java +++ b/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/impl/page/admin/configuration/component/ObjectPolicyConfigurationTabPanel.java @@ -14,6 +14,8 @@ import javax.xml.namespace.QName; +import com.evolveum.midpoint.gui.api.prism.ItemWrapper; +import com.evolveum.midpoint.gui.impl.prism.ItemMandatoryHandler; import com.evolveum.midpoint.model.api.AssignmentObjectRelation; import com.evolveum.midpoint.prism.path.ItemPath; import com.evolveum.midpoint.xml.ns._public.common.common_3.*; @@ -168,14 +170,44 @@ protected DisplayNamePanel createDisplayNamePanel new ItemRealValueModel(item.getModel()); return new DisplayNamePanel(displayNamePanelId, displayNameModel); } + + @Override + protected ItemMandatoryHandler getMandatoryHandler() { + return wrapper -> getMandatoryOverrideFor(wrapper); + + } }; return detailsPanel; } + private boolean getMandatoryOverrideFor(ItemWrapper itemWrapper) { + ItemPath conflictResolutionPath = ItemPath.create(SystemConfigurationType.F_DEFAULT_OBJECT_POLICY_CONFIGURATION, + ObjectPolicyConfigurationType.F_CONFLICT_RESOLUTION, ConflictResolutionType.F_ACTION); + if (conflictResolutionPath.equivalent(itemWrapper.getPath().namedSegmentsOnly())) { + return false; + } + + ItemPath adminGuiConfigDetails = ItemPath.create(SystemConfigurationType.F_DEFAULT_OBJECT_POLICY_CONFIGURATION, + ObjectPolicyConfigurationType.F_ADMIN_GUI_CONFIGURATION, ArchetypeAdminGuiConfigurationType.F_OBJECT_DETAILS); + + ItemPath detailsType = ItemPath.create(adminGuiConfigDetails, GuiObjectDetailsPageType.F_TYPE); + if (detailsType.equivalent(itemWrapper.getPath().namedSegmentsOnly())) { + return false; + } + + ItemPath formType = ItemPath.create(adminGuiConfigDetails, GuiObjectDetailsPageType.F_FORMS, ObjectFormType.F_TYPE); + if (formType.equivalent(itemWrapper.getPath().namedSegmentsOnly())) { + return false; + } + + return itemWrapper.isMandatory(); + } + private MultivalueContainerListPanelWithDetailsPanel getMultivalueContainerListPanel(){ return ((MultivalueContainerListPanelWithDetailsPanel)get(ID_OBJECTS_POLICY)); } + private ObjectQuery createQuery() { return getPageBase().getPrismContext().queryFor(ObjectPolicyConfigurationType.class) .all() diff --git a/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/component/assignment/SwitchAssignmentTypePanel.java b/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/component/assignment/SwitchAssignmentTypePanel.java index 1021d9bc5c2..33c88a7c98c 100644 --- a/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/component/assignment/SwitchAssignmentTypePanel.java +++ b/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/component/assignment/SwitchAssignmentTypePanel.java @@ -466,12 +466,11 @@ protected void cancelAssignmentDetailsPerformed(AjaxRequestTarget target) { } }; gdprAssignmentPanel.setOutputMarkupId(true); - SwitchAssignmentTypePanel.this.addOrReplace(gdprAssignmentPanel); - target.add(SwitchAssignmentTypePanel.this); + switchAssignmentTypePerformed(target, gdprAssignmentPanel, ID_CONSENT_ASSIGNMENTS); } }; consentsButton.setOutputMarkupId(true); - consentsButton.add(AttributeAppender.append("class", getButtonStyleModel(ID_SHOW_INDIRECT_ASSIGNMENTS))); + consentsButton.add(AttributeAppender.append("class", getButtonStyleModel(ID_CONSENT_ASSIGNMENTS))); consentsButton.add(new VisibleEnableBehaviour() { @Override public boolean isVisible() { diff --git a/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/page/admin/resources/ResourceDetailsTabPanel.java b/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/page/admin/resources/ResourceDetailsTabPanel.java index 8a8d92921b2..f0041494f42 100644 --- a/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/page/admin/resources/ResourceDetailsTabPanel.java +++ b/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/page/admin/resources/ResourceDetailsTabPanel.java @@ -1,702 +1,710 @@ -/* - * Copyright (c) 2010-2019 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.web.page.admin.resources; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import javax.xml.namespace.QName; - -import com.evolveum.midpoint.prism.path.ItemPath; -import com.evolveum.midpoint.web.page.admin.server.PageTask; - -import org.apache.commons.collections.CollectionUtils; -import org.apache.commons.lang.StringUtils; -import org.apache.wicket.ajax.AjaxRequestTarget; -import org.apache.wicket.extensions.markup.html.repeater.data.table.IColumn; -import org.apache.wicket.extensions.markup.html.repeater.data.table.PropertyColumn; -import org.apache.wicket.markup.html.panel.Panel; -import org.apache.wicket.markup.repeater.Item; -import org.apache.wicket.markup.repeater.RepeatingView; -import org.apache.wicket.model.IModel; -import org.apache.wicket.model.Model; -import org.apache.wicket.model.util.ListModel; -import org.apache.wicket.request.mapper.parameter.PageParameters; - -import com.evolveum.midpoint.common.SynchronizationUtils; -import com.evolveum.midpoint.common.refinery.RefinedObjectClassDefinition; -import com.evolveum.midpoint.common.refinery.RefinedResourceSchema; -import com.evolveum.midpoint.common.refinery.RefinedResourceSchemaImpl; -import com.evolveum.midpoint.gui.api.model.LoadableModel; -import com.evolveum.midpoint.gui.api.page.PageBase; -import com.evolveum.midpoint.gui.api.util.WebComponentUtil; -import com.evolveum.midpoint.gui.api.util.WebModelServiceUtils; -import com.evolveum.midpoint.prism.PrismObject; -import com.evolveum.midpoint.prism.PrismProperty; -import com.evolveum.midpoint.schema.constants.SchemaConstants; -import com.evolveum.midpoint.schema.processor.ObjectClassComplexTypeDefinition; -import com.evolveum.midpoint.schema.result.OperationResult; -import com.evolveum.midpoint.util.exception.SchemaException; -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.box.BasicInfoBoxPanel; -import com.evolveum.midpoint.web.component.box.InfoBoxPanel; -import com.evolveum.midpoint.web.component.box.InfoBoxType; -import com.evolveum.midpoint.web.component.data.BoxedTablePanel; -import com.evolveum.midpoint.web.component.data.column.ColumnTypeDto; -import com.evolveum.midpoint.web.component.data.column.ColumnUtils; -import com.evolveum.midpoint.web.component.data.column.LinkPanel; -import com.evolveum.midpoint.web.component.util.ListDataProvider; -import com.evolveum.midpoint.web.component.util.SelectableBeanImpl; -import com.evolveum.midpoint.web.page.admin.resources.dto.ResourceConfigurationDto; -import com.evolveum.midpoint.web.util.OnePageParameterEncoder; -import com.evolveum.midpoint.xml.ns._public.common.common_3.AvailabilityStatusType; -import com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorType; -import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectSynchronizationType; -import com.evolveum.midpoint.xml.ns._public.common.common_3.OperationalStateType; -import com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceActivationDefinitionType; -import com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceAttributeDefinitionType; -import com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceObjectTypeDefinitionType; -import com.evolveum.midpoint.xml.ns._public.common.common_3.ResourcePasswordDefinitionType; -import com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType; -import com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowKindType; -import com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType; -import com.evolveum.midpoint.xml.ns._public.common.common_3.TaskType; - -public class ResourceDetailsTabPanel extends Panel { - - private static final Trace LOGGER = TraceManager.getTrace(ResourceDetailsTabPanel.class); - - private static final String DOT_CLASS = ResourceDetailsTabPanel.class.getName() + "."; - private static final String OPERATION_SEARCH_TASKS_FOR_RESOURCE = DOT_CLASS + "seachTasks"; - - public static final String ID_LAST_AVAILABILITY_STATUS = "lastStatus"; - private static final String ID_SOURCE_TARGET = "sourceTarget"; - private static final String ID_SCHEMA_STATUS = "schemaStatus"; - - private static final String PANEL_CAPABILITIES = "capabilities"; - - private static final long serialVersionUID = 1L; - - LoadableModel capabilitiesModel; - - private PageBase parentPage; - - public ResourceDetailsTabPanel(String id, final IModel model, PageBase parentPage) { - super(id, model); - this.parentPage = parentPage; - - capabilitiesModel = new LoadableModel() { - private static final long serialVersionUID = 1L; - - @Override - protected CapabilitiesDto load() { - PrismObject resource = (PrismObject) model.getObject(); - return new CapabilitiesDto(resource.asObjectable()); - } - }; - - initLayout(model, parentPage); - } - - protected void initLayout(IModel model, PageBase parentPage) { - - PrismObject resourceObject = (PrismObject) model.getObject(); - ResourceType resource = resourceObject.asObjectable(); - - add(createLastAvailabilityStatusInfo(resource)); - - add(createSourceTargetInfo(resource)); - - add(createSchemaStatusInfo(resource)); - - CapabilitiesPanel capabilities = new CapabilitiesPanel(PANEL_CAPABILITIES, capabilitiesModel); - add(capabilities); - - List resourceConfigList = createResourceConfigList(resource); - - ListDataProvider resourceConfigProvider = new ListDataProvider<>( - ResourceDetailsTabPanel.this, new ListModel<>(resourceConfigList)); - - List> columns = Arrays.asList( - new ColumnTypeDto("ShadowType.kind", "objectTypeDefinition.kind", - ShadowType.F_KIND.getLocalPart()), - new ColumnTypeDto("ShadowType.objectClass", - "objectTypeDefinition.objectClass.localPart", - ShadowType.F_OBJECT_CLASS.getLocalPart()), - new ColumnTypeDto("ShadowType.intent", "objectTypeDefinition.intent", - ShadowType.F_INTENT.getLocalPart()), - new ColumnTypeDto("ResourceType.isSync", "sync", null)); - - List, String>> tableColumns = ColumnUtils.createColumns(columns); - - PropertyColumn tasksColumn = new PropertyColumn( - PageBase.createStringResourceStatic(this, "ResourceType.tasks"), "definedTasks") { - - @Override - public void populateItem(Item item, String componentId, final IModel rowModel) { - ResourceConfigurationDto conf = (ResourceConfigurationDto) rowModel.getObject(); - RepeatingView repeater = new RepeatingView(componentId); - for (final TaskType task : conf.getDefinedTasks()) { - repeater.add(new LinkPanel(repeater.newChildId(), - new Model<>(task.getName().getOrig())) { - - @Override - public void onClick(AjaxRequestTarget target) { - ResourceDetailsTabPanel.this.taskDetailsPerformed(target, task.getOid()); - } - - }); - } - - item.add(repeater); - } - - }; - - tableColumns.add(tasksColumn); - - BoxedTablePanel resourceConfig = new BoxedTablePanel("resourceConfig", - resourceConfigProvider, tableColumns); - resourceConfig.setAdditionalBoxCssClasses("box-success"); - add(resourceConfig); - - } - - private List createResourceConfigList(ResourceType resource) { - OperationResult result = new OperationResult(OPERATION_SEARCH_TASKS_FOR_RESOURCE); - - List> tasks = WebModelServiceUtils.searchObjects(TaskType.class, - parentPage.getPrismContext().queryFor(TaskType.class) - .item(TaskType.F_OBJECT_REF).ref(resource.getOid()) - .and() - .item(TaskType.F_PARENT).isNull() - .build(), - result, parentPage); - - List configs = new ArrayList<>(); - - if (resource.getSchemaHandling() == null) { - return configs; - } - - List objectTypes = resource.getSchemaHandling().getObjectType(); - - if (objectTypes == null) { - return configs; - } - - try { - for (ResourceObjectTypeDefinitionType objectType : objectTypes) { - ObjectSynchronizationType obejctSynchronization = null; - if (resource.getSynchronization() != null - && resource.getSynchronization().getObjectSynchronization() != null) { - - obejctSynchronization = getSynchronizationFor(objectType, - resource.getSynchronization().getObjectSynchronization(), - resource.asPrismObject()); - - } - List syncTask = new ArrayList<>(); - if (obejctSynchronization != null) { - syncTask = getTaskFor(tasks, obejctSynchronization, resource.asPrismObject()); - } - - ResourceConfigurationDto resourceConfig = new ResourceConfigurationDto(objectType, - obejctSynchronization != null, syncTask); - configs.add(resourceConfig); - } - } catch (SchemaException ex) { - LoggingUtils.logUnexpectedException(LOGGER, "Could not determine resource configuration", ex); - } - - return configs; - } - - private void taskDetailsPerformed(AjaxRequestTarget target, String taskOid) { - PageParameters parameters = new PageParameters(); - parameters.add(OnePageParameterEncoder.PARAMETER, taskOid); - ((PageBase) getPage()).navigateToNext(PageTask.class, parameters); - } - - private BasicInfoBoxPanel createSourceTargetInfo(ResourceType resource) { - - String backgroundColor = "bg-aqua"; - SourceTarget sourceTarget = determineIfSourceOrTarget(resource); - - String numberKey = null; - switch (sourceTarget) { - case SOURCE: - numberKey = "PageResource.resource.source"; - break; - case TARGET: - numberKey = "PageResource.resource.target"; - break; - case SOURCE_TARGET: - numberKey = "PageResource.resource.sourceAndTarget"; - break; - - default: - backgroundColor = "bg-gray"; - numberKey = "PageResource.resource.noMappings"; - break; - } - - InfoBoxType infoBoxType = new InfoBoxType(backgroundColor, sourceTarget.getCssClass(), - parentPage.getString("PageResource.resource.mappings")); - infoBoxType.setNumber(parentPage.getString(numberKey)); - - if (isSynchronizationDefined(resource)) { - infoBoxType.setDescription(parentPage.getString("PageResource.resource.sync")); - } - - Model boxModel = new Model<>(infoBoxType); - - return new BasicInfoBoxPanel(ID_SOURCE_TARGET, boxModel); - - } - - private InfoBoxPanel createLastAvailabilityStatusInfo(ResourceType resource) { - - String messageKey = "PageResource.resource.availabilityUnknown"; - String backgroundColor = "bg-gray"; - String icon = "fa fa-question"; - - OperationalStateType operationalState = resource.getOperationalState(); - if (operationalState != null) { - AvailabilityStatusType lastAvailabilityStatus = operationalState.getLastAvailabilityStatus(); - if (lastAvailabilityStatus != null) { - if (lastAvailabilityStatus == AvailabilityStatusType.UP) { - messageKey = "PageResource.resource.up"; - backgroundColor = "bg-green"; - icon = "fa fa-power-off"; - } else if (lastAvailabilityStatus == AvailabilityStatusType.DOWN) { - backgroundColor = "bg-red"; - messageKey = "PageResource.resource.down"; - icon = "fa fa-ban"; - } else if (lastAvailabilityStatus == AvailabilityStatusType.BROKEN) { - backgroundColor = "bg-yellow"; - messageKey = "PageResource.resource.broken"; - icon = "fa fa-warning"; - } - } - } - - InfoBoxType infoBoxType = new InfoBoxType(backgroundColor, icon, parentPage.getString(messageKey)); - - ConnectorType connectorType = (ConnectorType) resource.getConnectorRef().asReferenceValue().getObject().asObjectable(); - if (connectorType == null) { - // Connector not found. Probably bad connectorRef reference. - infoBoxType.setNumber("--"); - infoBoxType.setDescription("--"); - } else { - String connectorName = StringUtils.substringAfterLast( - WebComponentUtil.getEffectiveName(connectorType, ConnectorType.F_CONNECTOR_TYPE), "."); - String connectorVersion = connectorType.getConnectorVersion(); - infoBoxType.setNumber(connectorName); - infoBoxType.setDescription(connectorVersion); - } - - Model boxModel = new Model<>(infoBoxType); - - InfoBoxPanel lastAvailabilityStatus = new BasicInfoBoxPanel(ID_LAST_AVAILABILITY_STATUS, boxModel); - lastAvailabilityStatus.setOutputMarkupId(true); - - return lastAvailabilityStatus; - - } - - private InfoBoxPanel createSchemaStatusInfo(ResourceType resource) { - - String backgroundColor = "bg-gray"; - String icon = "fa fa-times"; - String numberMessage = null; - String description = null; - - Integer progress = null; - RefinedResourceSchema refinedSchema = null; - try { - refinedSchema = RefinedResourceSchemaImpl.getRefinedSchema(resource); - if (refinedSchema != null) { - backgroundColor = "bg-purple"; - icon = "fa fa-cubes"; - int numObjectTypes = 0; - List refinedDefinitions = refinedSchema - .getRefinedDefinitions(); - for (RefinedObjectClassDefinition refinedDefinition : refinedDefinitions) { - if (refinedDefinition.getKind() != null) { - numObjectTypes++; - } - } - int numAllDefinitions = refinedDefinitions.size(); - numberMessage = numObjectTypes + " " + parentPage.getString("PageResource.resource.objectTypes"); - if (numAllDefinitions != 0) { - progress = numObjectTypes * 100 / numAllDefinitions; - if (progress > 100) { - progress = 100; - } - } - description = numAllDefinitions + " " + parentPage.getString("PageResource.resource.schemaDefinitions"); - } else { - numberMessage = parentPage.getString("PageResource.resource.noSchema"); - } - } catch (SchemaException e) { - backgroundColor = "bg-danger"; - icon = "fa fa-warning"; - numberMessage = parentPage.getString("PageResource.resource.schemaError"); - } - - InfoBoxType infoBoxType = new InfoBoxType(backgroundColor, icon, - parentPage.getString("PageResource.resource.schema")); - infoBoxType.setNumber(numberMessage); - infoBoxType.setProgress(progress); - infoBoxType.setDescription(description); - - Model boxModel = new Model<>(infoBoxType); - - return new BasicInfoBoxPanel(ID_SCHEMA_STATUS, boxModel); - - } - - private ObjectSynchronizationType getSynchronizationFor( - ResourceObjectTypeDefinitionType obejctTypesDefinition, - List synchronizationPolicies, PrismObject resource) - throws SchemaException { - - for (ObjectSynchronizationType synchronizationPolicy : synchronizationPolicies) { - if (SynchronizationUtils.isPolicyApplicable(obejctTypesDefinition.getObjectClass(), - obejctTypesDefinition.getKind(), obejctTypesDefinition.getIntent(), synchronizationPolicy, - resource)) { - if (synchronizationPolicy.getObjectClass().isEmpty()) { - synchronizationPolicy.getObjectClass().add(obejctTypesDefinition.getObjectClass()); - } - return synchronizationPolicy; - } - } - - return null; - } - - private List getTaskFor(List> tasks, - ObjectSynchronizationType synchronizationPolicy, PrismObject resource) - throws SchemaException { - List syncTasks = new ArrayList<>(); - for (PrismObject task : tasks) { - PrismProperty taskKind = task - .findProperty(ItemPath.create(TaskType.F_EXTENSION, SchemaConstants.MODEL_EXTENSION_KIND)); - ShadowKindType taskKindValue = null; - if (taskKind != null) { - taskKindValue = taskKind.getRealValue(); - } - - PrismProperty taskIntent = task - .findProperty(ItemPath.create(TaskType.F_EXTENSION, SchemaConstants.MODEL_EXTENSION_INTENT)); - String taskIntentValue = null; - if (taskIntent != null) { - taskIntentValue = taskIntent.getRealValue(); - } - - PrismProperty taskObjectClass = task.findProperty( - ItemPath.create(TaskType.F_EXTENSION, SchemaConstants.MODEL_EXTENSION_OBJECTCLASS)); - QName taskObjectClassValue = null; - if (taskObjectClass != null) { - taskObjectClassValue = taskObjectClass.getRealValue(); - } - - // TODO: unify with determineObjectClass in Utils (model-impl, which - // is not accessible in admin-gui) - if (taskObjectClassValue == null) { - ObjectClassComplexTypeDefinition taskObjectClassDef = null; - RefinedResourceSchema schema = RefinedResourceSchemaImpl.getRefinedSchema(resource); - if (schema == null) { - throw new SchemaException( - "No schema defined in resource. Possible configuration problem?"); - } - if (taskKindValue == null && taskIntentValue == null) { - taskObjectClassDef = schema.findDefaultObjectClassDefinition(ShadowKindType.ACCOUNT); - } - - if (taskKindValue != null) { - if (StringUtils.isEmpty(taskIntentValue)) { - taskObjectClassDef = schema.findDefaultObjectClassDefinition(taskKindValue); - } else { - taskObjectClassDef = schema.findObjectClassDefinition(taskKindValue, taskIntentValue); - } - - } - if (taskObjectClassDef != null) { - taskObjectClassValue = taskObjectClassDef.getTypeName(); - } - } - - if (SynchronizationUtils.isPolicyApplicable(taskObjectClassValue, taskKindValue, taskIntentValue, - synchronizationPolicy, resource, true)) { - syncTasks.add(task.asObjectable()); - } - } - - return syncTasks; - } - - // TODO: ####### start of move to ResourceTypeUtil ########### - - private boolean isOutboundDefined(ResourceAttributeDefinitionType attr) { - return attr.getOutbound() != null - && (attr.getOutbound().getSource() != null || attr.getOutbound().getExpression() != null); - } - - private boolean isInboundDefined(ResourceAttributeDefinitionType attr) { - return attr.getInbound() != null && CollectionUtils.isNotEmpty(attr.getInbound()) - && (attr.getInbound().get(0).getTarget() != null - || attr.getInbound().get(0).getExpression() != null); - } - - private boolean isSynchronizationDefined(ResourceType resource) { - if (resource.getSynchronization() == null) { - return false; - } - - if (resource.getSynchronization().getObjectSynchronization().isEmpty()) { - return false; - } - - for (ObjectSynchronizationType syncType : resource.getSynchronization().getObjectSynchronization()) { - if (syncType.isEnabled() != null && !syncType.isEnabled()) { - continue; - } - - if (CollectionUtils.isEmpty(syncType.getReaction())) { - continue; - } - - return true; - - } - - return false; - - } - - private SourceTarget determineCredentialsMappings(ResourceType resource) { - if (resource.getSchemaHandling() != null - && CollectionUtils.isNotEmpty(resource.getSchemaHandling().getObjectType())) { - - boolean hasOutbound = false; - boolean hasInbound = false; - - for (ResourceObjectTypeDefinitionType resourceObjectTypeDefinition : resource.getSchemaHandling() - .getObjectType()) { - - if (hasInbound && hasOutbound) { - return SourceTarget.SOURCE_TARGET; - } - - if (resourceObjectTypeDefinition.getCredentials() == null) { - continue; - } - - if (resourceObjectTypeDefinition.getCredentials().getPassword() == null) { - continue; - } - - ResourcePasswordDefinitionType passwordDef = resourceObjectTypeDefinition.getCredentials() - .getPassword(); - if (!hasOutbound) { - hasOutbound = passwordDef.getOutbound() != null; - } - - if (!hasInbound) { - hasInbound = CollectionUtils.isNotEmpty(passwordDef.getInbound()); - } - } - - if (hasInbound) { - return SourceTarget.SOURCE; - } - - if (hasOutbound) { - return SourceTarget.TARGET; - } - - } - - return SourceTarget.NOT_DEFINED; - } - - private SourceTarget determineActivationMappings(ResourceType resource) { - if (resource.getSchemaHandling() != null - && CollectionUtils.isNotEmpty(resource.getSchemaHandling().getObjectType())) { - - boolean hasOutbound = false; - boolean hasInbound = false; - - for (ResourceObjectTypeDefinitionType resourceObjectTypeDefinition : resource.getSchemaHandling() - .getObjectType()) { - - if (hasInbound && hasOutbound) { - return SourceTarget.SOURCE_TARGET; - } - - if (resourceObjectTypeDefinition.getActivation() == null) { - continue; - } - - if (!hasOutbound) { - ResourceActivationDefinitionType activationDef = resourceObjectTypeDefinition - .getActivation(); - if (activationDef.getAdministrativeStatus() != null && CollectionUtils - .isNotEmpty(activationDef.getAdministrativeStatus().getOutbound())) { - hasOutbound = true; - } - } - - if (!hasOutbound) { - ResourceActivationDefinitionType activationDef = resourceObjectTypeDefinition - .getActivation(); - if (activationDef.getValidFrom() != null - && CollectionUtils.isNotEmpty(activationDef.getValidFrom().getOutbound())) { - hasOutbound = true; - } - } - - if (!hasOutbound) { - ResourceActivationDefinitionType activationDef = resourceObjectTypeDefinition - .getActivation(); - if (activationDef.getValidTo() != null - && CollectionUtils.isNotEmpty(activationDef.getValidTo().getOutbound())) { - hasOutbound = true; - } - } - - if (!hasOutbound) { - ResourceActivationDefinitionType activationDef = resourceObjectTypeDefinition - .getActivation(); - if (activationDef.getExistence() != null - && CollectionUtils.isNotEmpty(activationDef.getExistence().getOutbound())) { - hasOutbound = true; - } - } - - if (!hasInbound) { - ResourceActivationDefinitionType activationDef = resourceObjectTypeDefinition - .getActivation(); - if (activationDef.getAdministrativeStatus() != null && CollectionUtils - .isNotEmpty(activationDef.getAdministrativeStatus().getInbound())) { - hasInbound = true; - } - } - - if (!hasInbound) { - ResourceActivationDefinitionType activationDef = resourceObjectTypeDefinition - .getActivation(); - if (activationDef.getValidFrom() != null - && CollectionUtils.isNotEmpty(activationDef.getValidFrom().getInbound())) { - hasInbound = true; - } - } - - if (!hasInbound) { - ResourceActivationDefinitionType activationDef = resourceObjectTypeDefinition - .getActivation(); - if (activationDef.getValidTo() != null - && CollectionUtils.isNotEmpty(activationDef.getValidTo().getInbound())) { - hasInbound = true; - } - } - - if (!hasInbound) { - ResourceActivationDefinitionType activationDef = resourceObjectTypeDefinition - .getActivation(); - if (activationDef.getExistence() != null - && CollectionUtils.isNotEmpty(activationDef.getExistence().getInbound())) { - hasInbound = true; - } - } - } - - if (hasInbound) { - return SourceTarget.SOURCE; - } - - if (hasOutbound) { - return SourceTarget.TARGET; - } - - } - - return SourceTarget.NOT_DEFINED; - } - - private SourceTarget determineIfSourceOrTarget(ResourceType resource) { - - if (resource.getSchemaHandling() != null - && CollectionUtils.isNotEmpty(resource.getSchemaHandling().getObjectType())) { - - boolean hasOutbound = false; - boolean hasInbound = false; - - for (ResourceObjectTypeDefinitionType resourceObjectTypeDefinition : resource.getSchemaHandling() - .getObjectType()) { - if (CollectionUtils.isEmpty(resourceObjectTypeDefinition.getAttribute())) { - continue; - } - - if (hasInbound && hasOutbound) { - return SourceTarget.SOURCE_TARGET; - } - - for (ResourceAttributeDefinitionType attr : resourceObjectTypeDefinition.getAttribute()) { - - if (hasInbound && hasOutbound) { - return SourceTarget.SOURCE_TARGET; - } - - if (!hasOutbound) { - hasOutbound = isOutboundDefined(attr); - } - - if (!hasInbound) { - hasInbound = isInboundDefined(attr); - } - } - - // TODO: what about situation that we have only - } - - if (hasOutbound) { - return SourceTarget.TARGET; - } - - if (hasInbound) { - return SourceTarget.SOURCE; - } - - } - - return SourceTarget.NOT_DEFINED; - } - - // TODO: ####### end of move to ResourceTypeUtil ########### - - private enum SourceTarget { - - NOT_DEFINED("fa fa-square-o"), SOURCE("fa fa-sign-in"), TARGET("fa fa-sign-out"), SOURCE_TARGET("fa fa-exchange"); - - private String cssClass; - - SourceTarget(String cssClass) { - this.cssClass = cssClass; - } - - public String getCssClass() { - return cssClass; - } - } - -} +/* + * Copyright (c) 2010-2019 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.web.page.admin.resources; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import javax.xml.namespace.QName; + +import com.evolveum.midpoint.prism.path.ItemPath; +import com.evolveum.midpoint.web.page.admin.server.PageTask; + +import com.evolveum.midpoint.xml.ns._public.common.common_3.*; + +import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.lang.StringUtils; +import org.apache.wicket.ajax.AjaxRequestTarget; +import org.apache.wicket.extensions.markup.html.repeater.data.table.IColumn; +import org.apache.wicket.extensions.markup.html.repeater.data.table.PropertyColumn; +import org.apache.wicket.markup.html.panel.Panel; +import org.apache.wicket.markup.repeater.Item; +import org.apache.wicket.markup.repeater.RepeatingView; +import org.apache.wicket.model.IModel; +import org.apache.wicket.model.Model; +import org.apache.wicket.model.util.ListModel; +import org.apache.wicket.request.mapper.parameter.PageParameters; + +import com.evolveum.midpoint.common.SynchronizationUtils; +import com.evolveum.midpoint.common.refinery.RefinedObjectClassDefinition; +import com.evolveum.midpoint.common.refinery.RefinedResourceSchema; +import com.evolveum.midpoint.common.refinery.RefinedResourceSchemaImpl; +import com.evolveum.midpoint.gui.api.model.LoadableModel; +import com.evolveum.midpoint.gui.api.page.PageBase; +import com.evolveum.midpoint.gui.api.util.WebComponentUtil; +import com.evolveum.midpoint.gui.api.util.WebModelServiceUtils; +import com.evolveum.midpoint.prism.PrismObject; +import com.evolveum.midpoint.prism.PrismProperty; +import com.evolveum.midpoint.schema.constants.SchemaConstants; +import com.evolveum.midpoint.schema.processor.ObjectClassComplexTypeDefinition; +import com.evolveum.midpoint.schema.result.OperationResult; +import com.evolveum.midpoint.util.exception.SchemaException; +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.box.BasicInfoBoxPanel; +import com.evolveum.midpoint.web.component.box.InfoBoxPanel; +import com.evolveum.midpoint.web.component.box.InfoBoxType; +import com.evolveum.midpoint.web.component.data.BoxedTablePanel; +import com.evolveum.midpoint.web.component.data.column.ColumnTypeDto; +import com.evolveum.midpoint.web.component.data.column.ColumnUtils; +import com.evolveum.midpoint.web.component.data.column.LinkPanel; +import com.evolveum.midpoint.web.component.util.ListDataProvider; +import com.evolveum.midpoint.web.component.util.SelectableBeanImpl; +import com.evolveum.midpoint.web.page.admin.resources.dto.ResourceConfigurationDto; +import com.evolveum.midpoint.web.util.OnePageParameterEncoder; + +public class ResourceDetailsTabPanel extends Panel { + + private static final Trace LOGGER = TraceManager.getTrace(ResourceDetailsTabPanel.class); + + private static final String DOT_CLASS = ResourceDetailsTabPanel.class.getName() + "."; + private static final String OPERATION_SEARCH_TASKS_FOR_RESOURCE = DOT_CLASS + "seachTasks"; + + public static final String ID_LAST_AVAILABILITY_STATUS = "lastStatus"; + private static final String ID_SOURCE_TARGET = "sourceTarget"; + private static final String ID_SCHEMA_STATUS = "schemaStatus"; + + private static final String PANEL_CAPABILITIES = "capabilities"; + + private static final long serialVersionUID = 1L; + + LoadableModel capabilitiesModel; + + private PageBase parentPage; + + public ResourceDetailsTabPanel(String id, final IModel model, PageBase parentPage) { + super(id, model); + this.parentPage = parentPage; + + capabilitiesModel = new LoadableModel() { + private static final long serialVersionUID = 1L; + + @Override + protected CapabilitiesDto load() { + PrismObject resource = (PrismObject) model.getObject(); + return new CapabilitiesDto(resource.asObjectable()); + } + }; + + initLayout(model, parentPage); + } + + protected void initLayout(IModel model, PageBase parentPage) { + + PrismObject resourceObject = (PrismObject) model.getObject(); + ResourceType resource = resourceObject.asObjectable(); + + add(createLastAvailabilityStatusInfo(resource)); + + add(createSourceTargetInfo(resource)); + + add(createSchemaStatusInfo(resource)); + + CapabilitiesPanel capabilities = new CapabilitiesPanel(PANEL_CAPABILITIES, capabilitiesModel); + add(capabilities); + + List resourceConfigList = createResourceConfigList(resource); + + ListDataProvider resourceConfigProvider = new ListDataProvider<>( + ResourceDetailsTabPanel.this, new ListModel<>(resourceConfigList)); + + List> columns = Arrays.asList( + new ColumnTypeDto("ShadowType.kind", "objectTypeDefinition.kind", + ShadowType.F_KIND.getLocalPart()), + new ColumnTypeDto("ShadowType.objectClass", + "objectTypeDefinition.objectClass.localPart", + ShadowType.F_OBJECT_CLASS.getLocalPart()), + new ColumnTypeDto("ShadowType.intent", "objectTypeDefinition.intent", + ShadowType.F_INTENT.getLocalPart()), + new ColumnTypeDto("ResourceType.isSync", "sync", null)); + + List, String>> tableColumns = ColumnUtils.createColumns(columns); + + PropertyColumn tasksColumn = new PropertyColumn( + PageBase.createStringResourceStatic(this, "ResourceType.tasks"), "definedTasks") { + + @Override + public void populateItem(Item item, String componentId, final IModel rowModel) { + ResourceConfigurationDto conf = (ResourceConfigurationDto) rowModel.getObject(); + RepeatingView repeater = new RepeatingView(componentId); + for (final TaskType task : conf.getDefinedTasks()) { + repeater.add(new LinkPanel(repeater.newChildId(), + new Model<>(task.getName().getOrig())) { + + @Override + public void onClick(AjaxRequestTarget target) { + ResourceDetailsTabPanel.this.taskDetailsPerformed(target, task.getOid()); + } + + }); + } + + item.add(repeater); + } + + }; + + tableColumns.add(tasksColumn); + + BoxedTablePanel resourceConfig = new BoxedTablePanel("resourceConfig", + resourceConfigProvider, tableColumns); + resourceConfig.setAdditionalBoxCssClasses("box-success"); + add(resourceConfig); + + } + + private List createResourceConfigList(ResourceType resource) { + OperationResult result = new OperationResult(OPERATION_SEARCH_TASKS_FOR_RESOURCE); + + List> tasks = WebModelServiceUtils.searchObjects(TaskType.class, + parentPage.getPrismContext().queryFor(TaskType.class) + .item(TaskType.F_OBJECT_REF).ref(resource.getOid()) + .and() + .item(TaskType.F_PARENT).isNull() + .build(), + result, parentPage); + + List configs = new ArrayList<>(); + + if (resource.getSchemaHandling() == null) { + return configs; + } + + List objectTypes = resource.getSchemaHandling().getObjectType(); + + if (objectTypes == null) { + return configs; + } + + try { + for (ResourceObjectTypeDefinitionType objectType : objectTypes) { + ObjectSynchronizationType obejctSynchronization = null; + if (resource.getSynchronization() != null + && resource.getSynchronization().getObjectSynchronization() != null) { + + obejctSynchronization = getSynchronizationFor(objectType, + resource.getSynchronization().getObjectSynchronization(), + resource.asPrismObject()); + + } + List syncTask = new ArrayList<>(); + if (obejctSynchronization != null) { + syncTask = getTaskFor(tasks, obejctSynchronization, resource.asPrismObject()); + } + + ResourceConfigurationDto resourceConfig = new ResourceConfigurationDto(objectType, + obejctSynchronization != null, syncTask); + configs.add(resourceConfig); + } + } catch (SchemaException ex) { + LoggingUtils.logUnexpectedException(LOGGER, "Could not determine resource configuration", ex); + } + + return configs; + } + + private void taskDetailsPerformed(AjaxRequestTarget target, String taskOid) { + PageParameters parameters = new PageParameters(); + parameters.add(OnePageParameterEncoder.PARAMETER, taskOid); + ((PageBase) getPage()).navigateToNext(PageTask.class, parameters); + } + + private BasicInfoBoxPanel createSourceTargetInfo(ResourceType resource) { + + String backgroundColor = "bg-aqua"; + SourceTarget sourceTarget = determineIfSourceOrTarget(resource); + + String numberKey = null; + switch (sourceTarget) { + case SOURCE: + numberKey = "PageResource.resource.source"; + break; + case TARGET: + numberKey = "PageResource.resource.target"; + break; + case SOURCE_TARGET: + numberKey = "PageResource.resource.sourceAndTarget"; + break; + + default: + backgroundColor = "bg-gray"; + numberKey = "PageResource.resource.noMappings"; + break; + } + + InfoBoxType infoBoxType = new InfoBoxType(backgroundColor, sourceTarget.getCssClass(), + parentPage.getString("PageResource.resource.mappings")); + infoBoxType.setNumber(parentPage.getString(numberKey)); + + if (isSynchronizationDefined(resource)) { + infoBoxType.setDescription(parentPage.getString("PageResource.resource.sync")); + } + + Model boxModel = new Model<>(infoBoxType); + + return new BasicInfoBoxPanel(ID_SOURCE_TARGET, boxModel); + + } + + private InfoBoxPanel createLastAvailabilityStatusInfo(ResourceType resource) { + + String messageKey = "PageResource.resource.availabilityUnknown"; + String backgroundColor = "bg-gray"; + String icon = "fa fa-question"; + + OperationalStateType operationalState = resource.getOperationalState(); + if (operationalState != null) { + AvailabilityStatusType lastAvailabilityStatus = operationalState.getLastAvailabilityStatus(); + if (lastAvailabilityStatus != null) { + if (lastAvailabilityStatus == AvailabilityStatusType.UP) { + messageKey = "PageResource.resource.up"; + backgroundColor = "bg-green"; + icon = "fa fa-power-off"; + } else if (lastAvailabilityStatus == AvailabilityStatusType.DOWN) { + backgroundColor = "bg-red"; + messageKey = "PageResource.resource.down"; + icon = "fa fa-ban"; + } else if (lastAvailabilityStatus == AvailabilityStatusType.BROKEN) { + backgroundColor = "bg-yellow"; + messageKey = "PageResource.resource.broken"; + icon = "fa fa-warning"; + } + } + } + + InfoBoxType infoBoxType = new InfoBoxType(backgroundColor, icon, parentPage.getString(messageKey)); + + ConnectorType connectorType = getConnectorType(resource); + if (connectorType == null) { + // Connector not found. Probably bad connectorRef reference. + infoBoxType.setNumber("--"); + infoBoxType.setDescription("--"); + } else { + String connectorName = StringUtils.substringAfterLast( + WebComponentUtil.getEffectiveName(connectorType, ConnectorType.F_CONNECTOR_TYPE), "."); + String connectorVersion = connectorType.getConnectorVersion(); + infoBoxType.setNumber(connectorName); + infoBoxType.setDescription(connectorVersion); + } + + Model boxModel = new Model<>(infoBoxType); + + InfoBoxPanel lastAvailabilityStatus = new BasicInfoBoxPanel(ID_LAST_AVAILABILITY_STATUS, boxModel); + lastAvailabilityStatus.setOutputMarkupId(true); + + return lastAvailabilityStatus; + + } + + private ConnectorType getConnectorType(ResourceType resource) { + if (resource == null) { + return null; + } + + ObjectReferenceType connectorRef = resource.getConnectorRef(); + if (connectorRef == null) { + return null; + } + + PrismObject object = connectorRef.asReferenceValue().getObject(); + if (object == null) { + return null; + } + + return object.asObjectable(); + } + + private InfoBoxPanel createSchemaStatusInfo(ResourceType resource) { + + String backgroundColor = "bg-gray"; + String icon = "fa fa-times"; + String numberMessage = null; + String description = null; + + Integer progress = null; + RefinedResourceSchema refinedSchema = null; + try { + refinedSchema = RefinedResourceSchemaImpl.getRefinedSchema(resource); + if (refinedSchema != null) { + backgroundColor = "bg-purple"; + icon = "fa fa-cubes"; + int numObjectTypes = 0; + List refinedDefinitions = refinedSchema + .getRefinedDefinitions(); + for (RefinedObjectClassDefinition refinedDefinition : refinedDefinitions) { + if (refinedDefinition.getKind() != null) { + numObjectTypes++; + } + } + int numAllDefinitions = refinedDefinitions.size(); + numberMessage = numObjectTypes + " " + parentPage.getString("PageResource.resource.objectTypes"); + if (numAllDefinitions != 0) { + progress = numObjectTypes * 100 / numAllDefinitions; + if (progress > 100) { + progress = 100; + } + } + description = numAllDefinitions + " " + parentPage.getString("PageResource.resource.schemaDefinitions"); + } else { + numberMessage = parentPage.getString("PageResource.resource.noSchema"); + } + } catch (SchemaException e) { + backgroundColor = "bg-danger"; + icon = "fa fa-warning"; + numberMessage = parentPage.getString("PageResource.resource.schemaError"); + } + + InfoBoxType infoBoxType = new InfoBoxType(backgroundColor, icon, + parentPage.getString("PageResource.resource.schema")); + infoBoxType.setNumber(numberMessage); + infoBoxType.setProgress(progress); + infoBoxType.setDescription(description); + + Model boxModel = new Model<>(infoBoxType); + + return new BasicInfoBoxPanel(ID_SCHEMA_STATUS, boxModel); + + } + + private ObjectSynchronizationType getSynchronizationFor( + ResourceObjectTypeDefinitionType obejctTypesDefinition, + List synchronizationPolicies, PrismObject resource) + throws SchemaException { + + for (ObjectSynchronizationType synchronizationPolicy : synchronizationPolicies) { + if (SynchronizationUtils.isPolicyApplicable(obejctTypesDefinition.getObjectClass(), + obejctTypesDefinition.getKind(), obejctTypesDefinition.getIntent(), synchronizationPolicy, + resource)) { + if (synchronizationPolicy.getObjectClass().isEmpty()) { + synchronizationPolicy.getObjectClass().add(obejctTypesDefinition.getObjectClass()); + } + return synchronizationPolicy; + } + } + + return null; + } + + private List getTaskFor(List> tasks, + ObjectSynchronizationType synchronizationPolicy, PrismObject resource) + throws SchemaException { + List syncTasks = new ArrayList<>(); + for (PrismObject task : tasks) { + PrismProperty taskKind = task + .findProperty(ItemPath.create(TaskType.F_EXTENSION, SchemaConstants.MODEL_EXTENSION_KIND)); + ShadowKindType taskKindValue = null; + if (taskKind != null) { + taskKindValue = taskKind.getRealValue(); + } + + PrismProperty taskIntent = task + .findProperty(ItemPath.create(TaskType.F_EXTENSION, SchemaConstants.MODEL_EXTENSION_INTENT)); + String taskIntentValue = null; + if (taskIntent != null) { + taskIntentValue = taskIntent.getRealValue(); + } + + PrismProperty taskObjectClass = task.findProperty( + ItemPath.create(TaskType.F_EXTENSION, SchemaConstants.MODEL_EXTENSION_OBJECTCLASS)); + QName taskObjectClassValue = null; + if (taskObjectClass != null) { + taskObjectClassValue = taskObjectClass.getRealValue(); + } + + // TODO: unify with determineObjectClass in Utils (model-impl, which + // is not accessible in admin-gui) + if (taskObjectClassValue == null) { + ObjectClassComplexTypeDefinition taskObjectClassDef = null; + RefinedResourceSchema schema = RefinedResourceSchemaImpl.getRefinedSchema(resource); + if (schema == null) { + throw new SchemaException( + "No schema defined in resource. Possible configuration problem?"); + } + if (taskKindValue == null && taskIntentValue == null) { + taskObjectClassDef = schema.findDefaultObjectClassDefinition(ShadowKindType.ACCOUNT); + } + + if (taskKindValue != null) { + if (StringUtils.isEmpty(taskIntentValue)) { + taskObjectClassDef = schema.findDefaultObjectClassDefinition(taskKindValue); + } else { + taskObjectClassDef = schema.findObjectClassDefinition(taskKindValue, taskIntentValue); + } + + } + if (taskObjectClassDef != null) { + taskObjectClassValue = taskObjectClassDef.getTypeName(); + } + } + + if (SynchronizationUtils.isPolicyApplicable(taskObjectClassValue, taskKindValue, taskIntentValue, + synchronizationPolicy, resource, true)) { + syncTasks.add(task.asObjectable()); + } + } + + return syncTasks; + } + + // TODO: ####### start of move to ResourceTypeUtil ########### + + private boolean isOutboundDefined(ResourceAttributeDefinitionType attr) { + return attr.getOutbound() != null + && (attr.getOutbound().getSource() != null || attr.getOutbound().getExpression() != null); + } + + private boolean isInboundDefined(ResourceAttributeDefinitionType attr) { + return attr.getInbound() != null && CollectionUtils.isNotEmpty(attr.getInbound()) + && (attr.getInbound().get(0).getTarget() != null + || attr.getInbound().get(0).getExpression() != null); + } + + private boolean isSynchronizationDefined(ResourceType resource) { + if (resource.getSynchronization() == null) { + return false; + } + + if (resource.getSynchronization().getObjectSynchronization().isEmpty()) { + return false; + } + + for (ObjectSynchronizationType syncType : resource.getSynchronization().getObjectSynchronization()) { + if (syncType.isEnabled() != null && !syncType.isEnabled()) { + continue; + } + + if (CollectionUtils.isEmpty(syncType.getReaction())) { + continue; + } + + return true; + + } + + return false; + + } + + private SourceTarget determineCredentialsMappings(ResourceType resource) { + if (resource.getSchemaHandling() != null + && CollectionUtils.isNotEmpty(resource.getSchemaHandling().getObjectType())) { + + boolean hasOutbound = false; + boolean hasInbound = false; + + for (ResourceObjectTypeDefinitionType resourceObjectTypeDefinition : resource.getSchemaHandling() + .getObjectType()) { + + if (hasInbound && hasOutbound) { + return SourceTarget.SOURCE_TARGET; + } + + if (resourceObjectTypeDefinition.getCredentials() == null) { + continue; + } + + if (resourceObjectTypeDefinition.getCredentials().getPassword() == null) { + continue; + } + + ResourcePasswordDefinitionType passwordDef = resourceObjectTypeDefinition.getCredentials() + .getPassword(); + if (!hasOutbound) { + hasOutbound = passwordDef.getOutbound() != null; + } + + if (!hasInbound) { + hasInbound = CollectionUtils.isNotEmpty(passwordDef.getInbound()); + } + } + + if (hasInbound) { + return SourceTarget.SOURCE; + } + + if (hasOutbound) { + return SourceTarget.TARGET; + } + + } + + return SourceTarget.NOT_DEFINED; + } + + private SourceTarget determineActivationMappings(ResourceType resource) { + if (resource.getSchemaHandling() != null + && CollectionUtils.isNotEmpty(resource.getSchemaHandling().getObjectType())) { + + boolean hasOutbound = false; + boolean hasInbound = false; + + for (ResourceObjectTypeDefinitionType resourceObjectTypeDefinition : resource.getSchemaHandling() + .getObjectType()) { + + if (hasInbound && hasOutbound) { + return SourceTarget.SOURCE_TARGET; + } + + if (resourceObjectTypeDefinition.getActivation() == null) { + continue; + } + + if (!hasOutbound) { + ResourceActivationDefinitionType activationDef = resourceObjectTypeDefinition + .getActivation(); + if (activationDef.getAdministrativeStatus() != null && CollectionUtils + .isNotEmpty(activationDef.getAdministrativeStatus().getOutbound())) { + hasOutbound = true; + } + } + + if (!hasOutbound) { + ResourceActivationDefinitionType activationDef = resourceObjectTypeDefinition + .getActivation(); + if (activationDef.getValidFrom() != null + && CollectionUtils.isNotEmpty(activationDef.getValidFrom().getOutbound())) { + hasOutbound = true; + } + } + + if (!hasOutbound) { + ResourceActivationDefinitionType activationDef = resourceObjectTypeDefinition + .getActivation(); + if (activationDef.getValidTo() != null + && CollectionUtils.isNotEmpty(activationDef.getValidTo().getOutbound())) { + hasOutbound = true; + } + } + + if (!hasOutbound) { + ResourceActivationDefinitionType activationDef = resourceObjectTypeDefinition + .getActivation(); + if (activationDef.getExistence() != null + && CollectionUtils.isNotEmpty(activationDef.getExistence().getOutbound())) { + hasOutbound = true; + } + } + + if (!hasInbound) { + ResourceActivationDefinitionType activationDef = resourceObjectTypeDefinition + .getActivation(); + if (activationDef.getAdministrativeStatus() != null && CollectionUtils + .isNotEmpty(activationDef.getAdministrativeStatus().getInbound())) { + hasInbound = true; + } + } + + if (!hasInbound) { + ResourceActivationDefinitionType activationDef = resourceObjectTypeDefinition + .getActivation(); + if (activationDef.getValidFrom() != null + && CollectionUtils.isNotEmpty(activationDef.getValidFrom().getInbound())) { + hasInbound = true; + } + } + + if (!hasInbound) { + ResourceActivationDefinitionType activationDef = resourceObjectTypeDefinition + .getActivation(); + if (activationDef.getValidTo() != null + && CollectionUtils.isNotEmpty(activationDef.getValidTo().getInbound())) { + hasInbound = true; + } + } + + if (!hasInbound) { + ResourceActivationDefinitionType activationDef = resourceObjectTypeDefinition + .getActivation(); + if (activationDef.getExistence() != null + && CollectionUtils.isNotEmpty(activationDef.getExistence().getInbound())) { + hasInbound = true; + } + } + } + + if (hasInbound) { + return SourceTarget.SOURCE; + } + + if (hasOutbound) { + return SourceTarget.TARGET; + } + + } + + return SourceTarget.NOT_DEFINED; + } + + private SourceTarget determineIfSourceOrTarget(ResourceType resource) { + + if (resource.getSchemaHandling() != null + && CollectionUtils.isNotEmpty(resource.getSchemaHandling().getObjectType())) { + + boolean hasOutbound = false; + boolean hasInbound = false; + + for (ResourceObjectTypeDefinitionType resourceObjectTypeDefinition : resource.getSchemaHandling() + .getObjectType()) { + if (CollectionUtils.isEmpty(resourceObjectTypeDefinition.getAttribute())) { + continue; + } + + if (hasInbound && hasOutbound) { + return SourceTarget.SOURCE_TARGET; + } + + for (ResourceAttributeDefinitionType attr : resourceObjectTypeDefinition.getAttribute()) { + + if (hasInbound && hasOutbound) { + return SourceTarget.SOURCE_TARGET; + } + + if (!hasOutbound) { + hasOutbound = isOutboundDefined(attr); + } + + if (!hasInbound) { + hasInbound = isInboundDefined(attr); + } + } + + // TODO: what about situation that we have only + } + + if (hasOutbound) { + return SourceTarget.TARGET; + } + + if (hasInbound) { + return SourceTarget.SOURCE; + } + + } + + return SourceTarget.NOT_DEFINED; + } + + // TODO: ####### end of move to ResourceTypeUtil ########### + + private enum SourceTarget { + + NOT_DEFINED("fa fa-square-o"), SOURCE("fa fa-sign-in"), TARGET("fa fa-sign-out"), SOURCE_TARGET("fa fa-exchange"); + + private String cssClass; + + SourceTarget(String cssClass) { + this.cssClass = cssClass; + } + + public String getCssClass() { + return cssClass; + } + } + +} diff --git a/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/page/admin/resources/ResourceSummaryPanel.java b/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/page/admin/resources/ResourceSummaryPanel.java index 628f319e441..a65a86aa419 100644 --- a/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/page/admin/resources/ResourceSummaryPanel.java +++ b/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/page/admin/resources/ResourceSummaryPanel.java @@ -1,85 +1,85 @@ -/* - * Copyright (c) 2016-2017 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.web.page.admin.resources; - -import java.util.ArrayList; -import java.util.List; - -import com.evolveum.midpoint.xml.ns._public.common.common_3.AvailabilityStatusType; -import org.apache.wicket.model.IModel; - -import com.evolveum.midpoint.gui.api.GuiStyleConstants; -import com.evolveum.midpoint.gui.api.util.ModelServiceLocator; -import com.evolveum.midpoint.schema.util.ResourceTypeUtil; -import com.evolveum.midpoint.web.component.ObjectSummaryPanel; -import com.evolveum.midpoint.web.component.util.SummaryTag; -import com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType; - -public class ResourceSummaryPanel extends ObjectSummaryPanel { - private static final long serialVersionUID = 1L; - - public ResourceSummaryPanel(String id, IModel model, ModelServiceLocator serviceLocator) { - super(id, ResourceType.class, model, serviceLocator); - } - - @Override - protected List> getSummaryTagComponentList(){ - AvailabilityStatusType availability = ResourceTypeUtil.getLastAvailabilityStatus(getModelObject()); - - List> summaryTagList = new ArrayList<>(); - - SummaryTag summaryTag = new SummaryTag(ID_SUMMARY_TAG, getModel()) { - private static final long serialVersionUID = 1L; - - @Override - protected void initialize(ResourceType object) { - if (availability== null) { - setIconCssClass(GuiStyleConstants.CLASS_ICON_RESOURCE_UNKNOWN); - setLabel(getString("ResourceSummaryPanel.UNKNOWN")); - return; - } - setLabel(getString(ResourceSummaryPanel.this.getString(availability))); - switch(availability) { - case UP: - setIconCssClass(GuiStyleConstants.CLASS_ICON_ACTIVATION_ACTIVE); - break; - case DOWN: - setIconCssClass(GuiStyleConstants.CLASS_ICON_ACTIVATION_INACTIVE); - break; - case BROKEN: - setIconCssClass(GuiStyleConstants.CLASS_ICON_RESOURCE_BROKEN); - break; - - - } - } - }; - summaryTagList.add(summaryTag); - return summaryTagList; - } - - - @Override - protected String getIconCssClass() { - return GuiStyleConstants.CLASS_OBJECT_RESOURCE_ICON; - } - - @Override - protected String getIconBoxAdditionalCssClass() { - return "summary-panel-resource"; - } - - @Override - protected String getBoxAdditionalCssClass() { - return "summary-panel-resource"; - } - - @Override - protected boolean isIdentifierVisible() { - return false; - } -} +/* + * Copyright (c) 2016-2017 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.web.page.admin.resources; + +import java.util.ArrayList; +import java.util.List; + +import com.evolveum.midpoint.xml.ns._public.common.common_3.AvailabilityStatusType; +import org.apache.wicket.model.IModel; + +import com.evolveum.midpoint.gui.api.GuiStyleConstants; +import com.evolveum.midpoint.gui.api.util.ModelServiceLocator; +import com.evolveum.midpoint.schema.util.ResourceTypeUtil; +import com.evolveum.midpoint.web.component.ObjectSummaryPanel; +import com.evolveum.midpoint.web.component.util.SummaryTag; +import com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType; + +public class ResourceSummaryPanel extends ObjectSummaryPanel { + private static final long serialVersionUID = 1L; + + public ResourceSummaryPanel(String id, IModel model, ModelServiceLocator serviceLocator) { + super(id, ResourceType.class, model, serviceLocator); + } + + @Override + protected List> getSummaryTagComponentList(){ + AvailabilityStatusType availability = ResourceTypeUtil.getLastAvailabilityStatus(getModelObject()); + + List> summaryTagList = new ArrayList<>(); + + SummaryTag summaryTag = new SummaryTag(ID_SUMMARY_TAG, getModel()) { + private static final long serialVersionUID = 1L; + + @Override + protected void initialize(ResourceType object) { + if (availability== null) { + setIconCssClass(GuiStyleConstants.CLASS_ICON_RESOURCE_UNKNOWN); + setLabel(getString("ResourceSummaryPanel.UNKNOWN")); + return; + } + setLabel(ResourceSummaryPanel.this.getString(availability)); + switch(availability) { + case UP: + setIconCssClass(GuiStyleConstants.CLASS_ICON_ACTIVATION_ACTIVE); + break; + case DOWN: + setIconCssClass(GuiStyleConstants.CLASS_ICON_ACTIVATION_INACTIVE); + break; + case BROKEN: + setIconCssClass(GuiStyleConstants.CLASS_ICON_RESOURCE_BROKEN); + break; + + + } + } + }; + summaryTagList.add(summaryTag); + return summaryTagList; + } + + + @Override + protected String getIconCssClass() { + return GuiStyleConstants.CLASS_OBJECT_RESOURCE_ICON; + } + + @Override + protected String getIconBoxAdditionalCssClass() { + return "summary-panel-resource"; + } + + @Override + protected String getBoxAdditionalCssClass() { + return "summary-panel-resource"; + } + + @Override + protected boolean isIdentifierVisible() { + return false; + } +} diff --git a/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/page/self/PageAbstractSelfCredentials.java b/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/page/self/PageAbstractSelfCredentials.java index 93ed41f0fb7..a24c5a5d352 100644 --- a/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/page/self/PageAbstractSelfCredentials.java +++ b/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/page/self/PageAbstractSelfCredentials.java @@ -404,11 +404,21 @@ private boolean getPasswordOutbound(PrismObject shadow, Task task, O //TODO cannot be null? PrismObject resource = shadow.asObjectable().getResourceRef().asReferenceValue().getObject(); + //what to return when we don't have resource? + if (resource == null) { + return false; + } RefinedObjectClassDefinition rOCDef = getModelInteractionService().getEditObjectClassDefinition(shadow, resource, AuthorizationPhaseType.REQUEST, task, result); + if (rOCDef == null){ + return false; + } List passwordOutbound = rOCDef.getPasswordOutbound(); + if (passwordOutbound == null) { + return false; + } for (MappingType mapping : passwordOutbound) { if (MappingStrengthType.WEAK == mapping.getStrength()) { CredentialsCapabilityType capability = ResourceTypeUtil.getEffectiveCapability(resource.asObjectable(), CredentialsCapabilityType.class);