Search in sources :

Example 86 with ObjectType

use of org.mitre.cybox.cybox_2.ObjectType in project midpoint by Evolveum.

the class ReferenceValueSearchPopupPanel method customizationPopoverForm.

@Override
protected void customizationPopoverForm(MidpointForm midpointForm) {
    FeedbackAlerts feedback = new FeedbackAlerts(ID_FEEDBACK);
    feedback.setOutputMarkupId(true);
    midpointForm.add(feedback);
    PropertyModel<String> oidModel = new PropertyModel<>(getModel(), "oid") {

        @Override
        public void setObject(String object) {
            super.setObject(object);
            if (StringUtils.isBlank(object)) {
                ReferenceValueSearchPopupPanel.this.getModelObject().asReferenceValue().setObject(null);
                ReferenceValueSearchPopupPanel.this.getModelObject().setTargetName(null);
                ReferenceValueSearchPopupPanel.this.getModelObject().setRelation(null);
            }
        }
    };
    TextField<String> oidField = new TextField<>(ID_OID, oidModel);
    oidField.add(new EmptyOnBlurAjaxFormUpdatingBehaviour());
    oidField.setOutputMarkupId(true);
    oidField.add(new EnableBehaviour(this::isItemPanelEnabled));
    midpointForm.add(oidField);
    ReferenceAutocomplete nameField = new ReferenceAutocomplete(ID_NAME, Model.of(getModelObject()), new AutoCompleteReferenceRenderer(), getPageBase()) {

        private static final long serialVersionUID = 1L;

        @Override
        protected boolean isAllowedNotFoundObjectRef() {
            return ReferenceValueSearchPopupPanel.this.isAllowedNotFoundObjectRef();
        }

        @Override
        protected <O extends ObjectType> Class<O> getReferenceTargetObjectType() {
            if (getModelObject() != null && getModelObject().getType() != null) {
                return (Class<O>) WebComponentUtil.qnameToClass(PrismContext.get(), getModelObject().getType());
            }
            return super.getReferenceTargetObjectType();
        }
    };
    feedback.setFilter(new ComponentFeedbackMessageFilter(nameField));
    nameField.getBaseFormComponent().add(new AjaxFormComponentUpdatingBehavior("blur") {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            updateModel(nameField.getBaseFormComponent().getModelObject(), midpointForm, target);
        }
    });
    nameField.setOutputMarkupId(true);
    nameField.add(new EnableBehaviour(this::isItemPanelEnabled));
    midpointForm.add(nameField);
    DropDownChoicePanel<QName> type = new DropDownChoicePanel<>(ID_TYPE, new PropertyModel<>(getModel(), "type"), Model.ofList(getSupportedTargetList()), new QNameObjectTypeChoiceRenderer(), true);
    type.setOutputMarkupId(true);
    type.add(new VisibleEnableBehaviour() {

        private static final long serialVersionUID = 1L;

        @Override
        public boolean isEnabled() {
            return getSupportedTargetList().size() > 1 && isItemPanelEnabled();
        }
    });
    type.getBaseFormComponent().add(new EmptyOnBlurAjaxFormUpdatingBehaviour());
    type.getBaseFormComponent().add(new AjaxFormComponentUpdatingBehavior("change") {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            ObjectReferenceType ref = nameField.getAutoCompleteConverter(ObjectReferenceType.class, null).convertToObject(nameField.getBaseFormComponent().getValue(), WebComponentUtil.getCurrentLocale());
            updateModel(ref, midpointForm, target);
            target.add(oidField);
            target.add(ReferenceValueSearchPopupPanel.this);
        }
    });
    midpointForm.add(type);
    WebMarkupContainer relationContainer = new WebMarkupContainer(ID_RELATION_CONTAINER);
    midpointForm.add(relationContainer);
    relationContainer.add(new VisibleBehaviour(() -> getAllowedRelations().size() > 0));
    List<QName> allowedRelations = new ArrayList<>(getAllowedRelations());
    DropDownChoicePanel<QName> relation = new DropDownChoicePanel<>(ID_RELATION, new PropertyModel<>(getModel(), "relation"), Model.ofList(allowedRelations), new QNameObjectTypeChoiceRenderer(), true);
    relation.setOutputMarkupId(true);
    relation.add(new VisibleEnableBehaviour() {

        private static final long serialVersionUID = 1L;

        @Override
        public boolean isEnabled() {
            return getAllowedRelations().size() > 1 && isItemPanelEnabled();
        }
    });
    relation.getBaseFormComponent().add(new EmptyOnBlurAjaxFormUpdatingBehaviour());
    relationContainer.add(relation);
    AjaxButton selectObject = new AjaxButton(ID_SELECT_OBJECT_BUTTON, createStringResource("ReferenceValueSearchPopupPanel.selectObject")) {

        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(AjaxRequestTarget target) {
            List<QName> supportedTypes = getSupportedTargetList();
            if (CollectionUtils.isEmpty(supportedTypes)) {
                supportedTypes = WebComponentUtil.createObjectTypeList();
            }
            ObjectBrowserPanel<O> objectBrowserPanel = new ObjectBrowserPanel<>(getPageBase().getMainPopupBodyId(), null, supportedTypes, false, getPageBase(), null) {

                private static final long serialVersionUID = 1L;

                @Override
                protected void onSelectPerformed(AjaxRequestTarget target, O object) {
                    getPageBase().hideMainPopup(target);
                    if (ReferenceValueSearchPopupPanel.this.getModel().getObject() == null) {
                        ReferenceValueSearchPopupPanel.this.getModel().setObject(new ObjectReferenceType());
                    }
                    ReferenceValueSearchPopupPanel.this.getModelObject().setOid(object.getOid());
                    ReferenceValueSearchPopupPanel.this.getModelObject().setTargetName(object.getName());
                    ReferenceValueSearchPopupPanel.this.getModelObject().setType(object.asPrismObject().getComplexTypeDefinition().getTypeName());
                    target.add(oidField);
                    target.add(nameField);
                    target.add(type);
                }
            };
            getPageBase().showMainPopup(objectBrowserPanel, target);
        }
    };
    selectObject.add(new VisibleBehaviour(() -> getPageBase().getMainPopup().getContentComponent() == null));
    midpointForm.add(selectObject);
}
Also used : DropDownChoicePanel(com.evolveum.midpoint.web.component.input.DropDownChoicePanel) VisibleBehaviour(com.evolveum.midpoint.web.component.util.VisibleBehaviour) EmptyOnBlurAjaxFormUpdatingBehaviour(com.evolveum.midpoint.web.page.admin.configuration.component.EmptyOnBlurAjaxFormUpdatingBehaviour) ArrayList(java.util.ArrayList) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) AjaxButton(com.evolveum.midpoint.web.component.AjaxButton) AutoCompleteReferenceRenderer(com.evolveum.midpoint.gui.api.component.autocomplete.AutoCompleteReferenceRenderer) TextField(org.apache.wicket.markup.html.form.TextField) VisibleEnableBehaviour(com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour) EnableBehaviour(com.evolveum.midpoint.web.component.util.EnableBehaviour) VisibleEnableBehaviour(com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour) AjaxFormComponentUpdatingBehavior(org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior) QName(javax.xml.namespace.QName) PropertyModel(org.apache.wicket.model.PropertyModel) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) ComponentFeedbackMessageFilter(org.apache.wicket.feedback.ComponentFeedbackMessageFilter) ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) FeedbackAlerts(com.evolveum.midpoint.web.component.message.FeedbackAlerts) ObjectBrowserPanel(com.evolveum.midpoint.gui.api.component.ObjectBrowserPanel) QNameObjectTypeChoiceRenderer(com.evolveum.midpoint.web.component.input.QNameObjectTypeChoiceRenderer)

Example 87 with ObjectType

use of org.mitre.cybox.cybox_2.ObjectType in project midpoint by Evolveum.

the class AbstractGuiIntegrationTest method getServiceLocator.

protected ModelServiceLocator getServiceLocator(final Task pageTask) {
    return new ModelServiceLocator() {

        @Override
        public ModelService getModelService() {
            return modelService;
        }

        @Override
        public ModelInteractionService getModelInteractionService() {
            return modelInteractionService;
        }

        @Override
        public DashboardService getDashboardService() {
            return dashboardService;
        }

        @Override
        public Task createSimpleTask(String operationName) {
            MidPointPrincipal user = AuthUtil.getPrincipalUser();
            if (user == null) {
                throw new IllegalStateException("No authenticated user");
            }
            return WebModelServiceUtils.createSimpleTask(operationName, SchemaConstants.CHANNEL_USER_URI, user.getFocus().asPrismObject(), taskManager);
        }

        @Override
        public PrismContext getPrismContext() {
            return prismContext;
        }

        @Override
        public SecurityEnforcer getSecurityEnforcer() {
            return securityEnforcer;
        }

        @Override
        public SecurityContextManager getSecurityContextManager() {
            return securityContextManager;
        }

        @NotNull
        @Override
        public CompiledGuiProfile getCompiledGuiProfile() {
            Task task = createSimpleTask("getCompiledGuiProfile");
            try {
                return getModelInteractionService().getCompiledGuiProfile(task, task.getResult());
            } catch (ObjectNotFoundException | SchemaException | CommunicationException | ConfigurationException | SecurityViolationException | ExpressionEvaluationException e) {
                throw new SystemException(e.getMessage(), e);
            }
        }

        @Override
        public Task getPageTask() {
            return pageTask;
        }

        @Override
        public ExpressionFactory getExpressionFactory() {
            return expressionFactory;
        }

        @Override
        public LocalizationService getLocalizationService() {
            return localizationService;
        }

        @Override
        public Locale getLocale() {
            return Locale.US;
        }

        @Override
        public GuiComponentRegistry getRegistry() {
            return registry;
        }

        @Override
        public <O extends ObjectType> PrismObjectWrapperFactory<O> findObjectWrapperFactory(PrismObjectDefinition<O> objectDef) {
            return registry.getObjectWrapperFactory(objectDef);
        }

        @Override
        public <I extends Item, IW extends ItemWrapper> IW createItemWrapper(I item, ItemStatus status, WrapperContext ctx) throws SchemaException {
            ItemWrapperFactory<IW, ?, ?> factory = registry.findWrapperFactory(item.getDefinition(), null);
            ctx.setCreateIfEmpty(true);
            return factory.createWrapper(null, item, status, ctx);
        }

        @Override
        public <IW extends ItemWrapper, VW extends PrismValueWrapper, PV extends PrismValue> VW createValueWrapper(IW parentWrapper, PV newValue, ValueStatus status, WrapperContext context) throws SchemaException {
            ItemWrapperFactory<IW, VW, PV> factory = registry.findWrapperFactory(parentWrapper, null);
            return factory.createValueWrapper(parentWrapper, newValue, status, context);
        }

        @Override
        public MidpointFormValidatorRegistry getFormValidatorRegistry() {
            return null;
        }

        @Override
        public AdminGuiConfigurationMergeManager getAdminGuiConfigurationMergeManager() {
            return null;
        }

        @Override
        public CorrelationService getCorrelationService() {
            return null;
        }
    };
}
Also used : ItemStatus(com.evolveum.midpoint.gui.api.prism.ItemStatus) Task(com.evolveum.midpoint.task.api.Task) ItemWrapper(com.evolveum.midpoint.gui.api.prism.wrapper.ItemWrapper) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) WrapperContext(com.evolveum.midpoint.gui.api.factory.wrapper.WrapperContext) PrismValueWrapper(com.evolveum.midpoint.gui.api.prism.wrapper.PrismValueWrapper) ValueStatus(com.evolveum.midpoint.web.component.prism.ValueStatus) MidPointPrincipal(com.evolveum.midpoint.security.api.MidPointPrincipal) ModelServiceLocator(com.evolveum.midpoint.gui.api.util.ModelServiceLocator)

Example 88 with ObjectType

use of org.mitre.cybox.cybox_2.ObjectType in project midpoint by Evolveum.

the class ReferenceConverter method convertToObject.

@Override
public ObjectReferenceType convertToObject(String value, Locale locale) throws ConversionException {
    Class<ObjectType> type = getReferenceTargetObjectType();
    ObjectQuery query = pageBase.getPrismContext().queryFor(type).item(ObjectType.F_NAME).eq(value).matchingNorm().build();
    List<PrismObject<ObjectType>> objectsList = WebModelServiceUtils.searchObjects(type, query, new OperationResult("searchObjects"), pageBase);
    if (CollectionUtils.isNotEmpty(objectsList)) {
        if (objectsList.size() == 1) {
            return ObjectTypeUtil.createObjectRefWithFullObject(objectsList.get(0), pageBase.getPrismContext());
        }
        pageBase.error("Couldn't specify one object by name '" + value + "' and type " + type.getSimpleName() + ". Please will try specific type of object.");
    }
    ObjectReferenceType ref = null;
    if (isAllowedNotFoundObjectRef()) {
        ref = new ObjectReferenceType();
        ref.setTargetName(new PolyStringType(value));
        if (baseComponent != null && baseComponent.getModelObject() instanceof ObjectReferenceType) {
            if (((ObjectReferenceType) baseComponent.getModelObject()).getRelation() == null) {
                ref.setRelation(pageBase.getPrismContext().getDefaultRelation());
            } else {
                ref.setRelation(((ObjectReferenceType) baseComponent.getModelObject()).getRelation());
            }
            ref.setType(WebComponentUtil.classToQName(PrismContext.get(), type));
        }
    }
    return ref;
}
Also used : PolyStringType(com.evolveum.prism.xml.ns._public.types_3.PolyStringType) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) PrismObject(com.evolveum.midpoint.prism.PrismObject) ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery)

Example 89 with ObjectType

use of org.mitre.cybox.cybox_2.ObjectType in project midpoint by Evolveum.

the class PageFocusDetails method finishPreviewProcessing.

private void finishPreviewProcessing(AjaxRequestTarget target, OperationResult result) {
    showResult(result);
    target.add(getFeedbackPanel());
    Map<PrismObject<F>, ModelContext<? extends ObjectType>> modelContextMap = new LinkedHashMap<>();
    collectObjectsForPreview(modelContextMap);
    DetailsFragment detailsFragment = createDetailsFragment();
    replace(detailsFragment);
    target.add(detailsFragment);
    navigateToNext(new PageFocusPreviewChanges(modelContextMap));
}
Also used : ModelContext(com.evolveum.midpoint.model.api.context.ModelContext) PrismObject(com.evolveum.midpoint.prism.PrismObject) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) DetailsFragment(com.evolveum.midpoint.gui.impl.page.admin.DetailsFragment) LinkedHashMap(java.util.LinkedHashMap)

Example 90 with ObjectType

use of org.mitre.cybox.cybox_2.ObjectType in project midpoint by Evolveum.

the class ExpressionVariableEditorDialog method createObjectReferenceListDeprecated.

private List<ObjectReferenceType> createObjectReferenceListDeprecated() {
    objectMap.clear();
    OperationResult result = new OperationResult(OPERATION_LOAD_REPOSITORY_OBJECTS);
    Task task = getPageBase().createSimpleTask(OPERATION_LOAD_REPOSITORY_OBJECTS);
    List<PrismObject<ObjectType>> objects = null;
    List<ObjectReferenceType> references = new ArrayList<>();
    try {
        objects = getPageBase().getModelService().searchObjects(ObjectType.class, null, null, task, result);
        result.recomputeStatus();
    } catch (CommonException | RuntimeException e) {
        result.recordFatalError("ExpressionVariableEditorDialog.message.createObjectReferenceListDeprecated.fatalError", e);
        LoggingUtils.logUnexpectedException(LOGGER, "Couldn't load objects from repository", e);
    }
    if (objects != null) {
        ObjectReferenceType ref;
        for (PrismObject<ObjectType> obj : objects) {
            objectMap.put(obj.getOid(), WebComponentUtil.getName(obj));
            ref = new ObjectReferenceType();
            ref.setOid(obj.getOid());
            references.add(ref);
        }
    }
    return references;
}
Also used : PrismObject(com.evolveum.midpoint.prism.PrismObject) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) Task(com.evolveum.midpoint.task.api.Task) ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) ArrayList(java.util.ArrayList) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) CommonException(com.evolveum.midpoint.util.exception.CommonException)

Aggregations

ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)243 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)126 Test (org.testng.annotations.Test)97 Task (com.evolveum.midpoint.task.api.Task)82 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)79 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)78 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)68 OperationResultType (com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType)55 ArrayList (java.util.ArrayList)51 Holder (javax.xml.ws.Holder)48 QName (javax.xml.namespace.QName)32 ObjectReferenceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType)30 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)29 AbstractModelIntegrationTest (com.evolveum.midpoint.model.test.AbstractModelIntegrationTest)28 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)26 PrismObject (com.evolveum.midpoint.prism.PrismObject)25 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)25 SelectorQualifiedGetOptionsType (com.evolveum.midpoint.xml.ns._public.common.common_3.SelectorQualifiedGetOptionsType)24 SystemConfigurationType (com.evolveum.midpoint.xml.ns._public.common.common_3.SystemConfigurationType)23 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)22