|
34 | 34 | import com.evolveum.midpoint.xml.ns._public.common.common_3.*; |
35 | 35 |
|
36 | 36 | import org.apache.commons.lang3.StringUtils; |
| 37 | +import java.util.List; |
37 | 38 | import org.apache.wicket.ajax.AjaxRequestTarget; |
38 | 39 | import org.apache.wicket.behavior.AttributeAppender; |
39 | 40 | import org.apache.wicket.markup.html.WebMarkupContainer; |
|
51 | 52 | public class BaseUrlConnectorStepPanel extends AbstractFormWizardStepPanel<ConnectorDevelopmentDetailsModel> { |
52 | 53 |
|
53 | 54 | private static final String PANEL_TYPE = "cdw-base-url"; |
54 | | - public static final ItemName PROPERTY_ITEM_NAME = ItemName.from("", "baseAddress"); |
| 55 | + public static final ItemName BASE_ADDRESS_ITEM_NAME = ItemName.from("", "baseAddress"); |
| 56 | + public static final ItemName DEVELOPMENT_MODE_ITEM_NAME = ItemName.from("", "developmentMode"); |
| 57 | + public static final ItemName SCIM_BASE_URL_ITEM_NAME = ItemName.from("", "scimBaseUrl"); |
55 | 58 |
|
56 | 59 | private static final String ID_AI_ALERT = "aiAlert"; |
57 | 60 |
|
@@ -83,12 +86,14 @@ protected IModel<? extends PrismContainerWrapper> getContainerFormModel() { |
83 | 86 | protected void onInitialize() { |
84 | 87 | super.onInitialize(); |
85 | 88 | try { |
86 | | - PrismPropertyValueWrapper<Object> suggestedValue = getDetailsModel().getObjectWrapper().findProperty( |
87 | | - ItemPath.create(ConnectorDevelopmentType.F_APPLICATION, ConnDevApplicationInfoType.F_BASE_API_ENDPOINT)).getValue(); |
88 | | - if (StringUtils.isNotEmpty((String) suggestedValue.getRealValue())) { |
89 | | - PrismPropertyValueWrapper<String> configurationValue = (PrismPropertyValueWrapper<String>) getContainerFormModel().getObject().findProperty(PROPERTY_ITEM_NAME).getValue(); |
90 | | - if (StringUtils.isEmpty(configurationValue.getRealValue())) { |
91 | | - configurationValue.setRealValue((String) suggestedValue.getRealValue()); |
| 89 | + String suggestedUrl = (String) getDetailsModel().getObjectWrapper().findProperty( |
| 90 | + ItemPath.create(ConnectorDevelopmentType.F_APPLICATION, ConnDevApplicationInfoType.F_BASE_API_ENDPOINT)) |
| 91 | + .getValue().getRealValue(); |
| 92 | + if (StringUtils.isNotEmpty(suggestedUrl)) { |
| 93 | + ItemName urlField = isScim() ? SCIM_BASE_URL_ITEM_NAME : BASE_ADDRESS_ITEM_NAME; |
| 94 | + PrismPropertyValueWrapper<String> fieldValue = (PrismPropertyValueWrapper<String>) getContainerFormModel().getObject().findProperty(urlField).getValue(); |
| 95 | + if (StringUtils.isEmpty(fieldValue.getRealValue())) { |
| 96 | + fieldValue.setRealValue(suggestedUrl); |
92 | 97 | } |
93 | 98 | } |
94 | 99 | } catch (SchemaException e) { |
@@ -186,22 +191,48 @@ protected IModel<?> getSubTextModel() { |
186 | 191 | } |
187 | 192 |
|
188 | 193 | protected boolean checkMandatory(ItemWrapper wrapper) { |
189 | | - if (QNameUtil.match(wrapper.getItemName(), PROPERTY_ITEM_NAME)) { |
190 | | - return true; |
| 194 | + if (isScim()) { |
| 195 | + if (QNameUtil.match(wrapper.getItemName(), SCIM_BASE_URL_ITEM_NAME)) { |
| 196 | + return true; |
| 197 | + } |
| 198 | + } else { |
| 199 | + if (QNameUtil.match(wrapper.getItemName(), BASE_ADDRESS_ITEM_NAME)) { |
| 200 | + return true; |
| 201 | + } |
191 | 202 | } |
192 | 203 | return wrapper.isMandatory(); |
193 | 204 | } |
194 | 205 |
|
195 | 206 | @Override |
196 | 207 | protected ItemVisibilityHandler getVisibilityHandler() { |
197 | 208 | return wrapper -> { |
198 | | - if (QNameUtil.match(wrapper.getItemName(), PROPERTY_ITEM_NAME)) { |
199 | | - return ItemVisibility.AUTO; |
| 209 | + if (isScim()) { |
| 210 | + if (scimItemNames().stream().anyMatch(name -> QNameUtil.match(wrapper.getItemName(), name))) { |
| 211 | + return ItemVisibility.AUTO; |
| 212 | + } |
| 213 | + } else { |
| 214 | + if (QNameUtil.match(wrapper.getItemName(), BASE_ADDRESS_ITEM_NAME)) { |
| 215 | + return ItemVisibility.AUTO; |
| 216 | + } |
200 | 217 | } |
201 | 218 | return ItemVisibility.HIDDEN; |
202 | 219 | }; |
203 | 220 | } |
204 | 221 |
|
| 222 | + private List<ItemName> scimItemNames() { |
| 223 | + return List.of(SCIM_BASE_URL_ITEM_NAME, DEVELOPMENT_MODE_ITEM_NAME); |
| 224 | + } |
| 225 | + |
| 226 | + private boolean isScim() { |
| 227 | + try { |
| 228 | + PrismPropertyWrapper<ConnDevIntegrationType> integrationType = getDetailsModel().getObjectWrapper().findProperty( |
| 229 | + ItemPath.create(ConnectorDevelopmentType.F_CONNECTOR, ConnDevConnectorType.F_INTEGRATION_TYPE)); |
| 230 | + return ConnDevIntegrationType.SCIM.equals(integrationType.getValue().getRealValue()); |
| 231 | + } catch (SchemaException e) { |
| 232 | + return false; |
| 233 | + } |
| 234 | + } |
| 235 | + |
205 | 236 | @Override |
206 | 237 | public String getStepId() { |
207 | 238 | return PANEL_TYPE; |
@@ -236,7 +267,8 @@ public boolean onNextPerformed(AjaxRequestTarget target) { |
236 | 267 |
|
237 | 268 | @Override |
238 | 269 | public boolean isCompleted() { |
| 270 | + ItemName fieldToCheck = isScim() ? SCIM_BASE_URL_ITEM_NAME : BASE_ADDRESS_ITEM_NAME; |
239 | 271 | return ConnectorDevelopmentWizardUtil.existTestingResourcePropertyValue( |
240 | | - getDetailsModel(), getPanelType(), PROPERTY_ITEM_NAME); |
| 272 | + getDetailsModel(), getPanelType(), fieldToCheck); |
241 | 273 | } |
242 | 274 | } |
0 commit comments