Search in sources :

Example 51 with PrismContext

use of com.evolveum.midpoint.prism.PrismContext in project midpoint by Evolveum.

the class AbstractTreeTablePanel method createOrgChildQuery.

protected ObjectQuery createOrgChildQuery() {
    SelectableBean<OrgType> dto = selected.getObject();
    String oid = dto != null && dto.getValue() != null ? dto.getValue().getOid() : getModel().getObject();
    BasicSearchPanel<String> basicSearch = (BasicSearchPanel) get(createComponentPath(ID_SEARCH_FORM, ID_BASIC_SEARCH));
    String object = basicSearch.getModelObject();
    DropDownChoice<String> searchScopeChoice = (DropDownChoice) get(createComponentPath(ID_SEARCH_FORM, ID_SEARCH_SCOPE));
    String scope = searchScopeChoice.getModelObject();
    if (StringUtils.isBlank(object)) {
        object = null;
    }
    PageBase page = getPageBase();
    PrismContext context = page.getPrismContext();
    S_AtomicFilterExit q;
    if (object == null || SEARCH_SCOPE_ONE.equals(scope)) {
        q = QueryBuilder.queryFor(OrgType.class, context).isDirectChildOf(oid);
    } else {
        q = QueryBuilder.queryFor(OrgType.class, context).isChildOf(oid);
    }
    if (object == null) {
        return q.build();
    }
    PolyStringNormalizer normalizer = context.getDefaultPolyStringNormalizer();
    String normalizedString = normalizer.normalize(object);
    if (StringUtils.isEmpty(normalizedString)) {
        return q.build();
    }
    ObjectQuery query = q.and().block().item(OrgType.F_NAME).containsPoly(normalizedString).matchingNorm().or().item(OrgType.F_DISPLAY_NAME).containsPoly(normalizedString).matchingNorm().build();
    if (LOGGER.isTraceEnabled()) {
        LOGGER.trace("Searching child orgs of org {} with query:\n{}", oid, query.debugDump());
    }
    return query;
}
Also used : DropDownChoice(org.apache.wicket.markup.html.form.DropDownChoice) BasicSearchPanel(com.evolveum.midpoint.web.component.BasicSearchPanel) OrgType(com.evolveum.midpoint.xml.ns._public.common.common_3.OrgType) PrismContext(com.evolveum.midpoint.prism.PrismContext) S_AtomicFilterExit(com.evolveum.midpoint.prism.query.builder.S_AtomicFilterExit) PageBase(com.evolveum.midpoint.gui.api.page.PageBase) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) PolyStringNormalizer(com.evolveum.midpoint.prism.polystring.PolyStringNormalizer)

Example 52 with PrismContext

use of com.evolveum.midpoint.prism.PrismContext in project midpoint by Evolveum.

the class TreeTablePanel method initObjectForAdd.

// TODO: merge this with AbstractRoleMemeberPanel.initObjectForAdd, also see MID-3233
private void initObjectForAdd(ObjectReferenceType parentOrgRef, QName type, QName relation, AjaxRequestTarget target) throws SchemaException {
    TreeTablePanel.this.getPageBase().hideMainPopup(target);
    PrismContext prismContext = TreeTablePanel.this.getPageBase().getPrismContext();
    PrismObjectDefinition def = prismContext.getSchemaRegistry().findObjectDefinitionByType(type);
    PrismObject obj = def.instantiate();
    ObjectType objType = (ObjectType) obj.asObjectable();
    if (FocusType.class.isAssignableFrom(obj.getCompileTimeClass())) {
        AssignmentType assignment = new AssignmentType();
        assignment.setTargetRef(parentOrgRef);
        ((FocusType) objType).getAssignment().add(assignment);
    }
    // TODO: fix MID-3234
    if (parentOrgRef == null) {
        ObjectType org = getTreePanel().getSelected().getValue();
        parentOrgRef = ObjectTypeUtil.createObjectRef(org);
        parentOrgRef.setRelation(relation);
        objType.getParentOrgRef().add(parentOrgRef);
    } else {
        objType.getParentOrgRef().add(parentOrgRef.clone());
    }
    WebComponentUtil.dispatchToObjectDetailsPage(obj, this);
}
Also used : PrismObject(com.evolveum.midpoint.prism.PrismObject) PrismContext(com.evolveum.midpoint.prism.PrismContext) PrismObjectDefinition(com.evolveum.midpoint.prism.PrismObjectDefinition)

Example 53 with PrismContext

use of com.evolveum.midpoint.prism.PrismContext in project midpoint by Evolveum.

the class NameStep method applyState.

@Override
public void applyState() {
    parentPage.refreshIssues(null);
    if (parentPage.isReadOnly() || !isComplete()) {
        return;
    }
    PrismContext prismContext = parentPage.getPrismContext();
    Task task = parentPage.createSimpleTask(OPERATION_SAVE_RESOURCE);
    OperationResult result = task.getResult();
    boolean saved = false;
    try {
        PrismObject<ResourceType> resource = resourceModelRaw.getObject();
        PrismObject<ConnectorType> connector = getSelectedConnector();
        if (connector == null) {
            // should be treated by form validation
            throw new IllegalStateException("No connector selected");
        }
        ObjectDelta delta;
        final String oid = resource.getOid();
        boolean isNew = oid == null;
        if (isNew) {
            resource = prismContext.createObject(ResourceType.class);
            ResourceType resourceType = resource.asObjectable();
            resourceType.setName(PolyStringType.fromOrig(resourceNameModel.getObject()));
            resourceType.setDescription(resourceDescriptionModel.getObject());
            resourceType.setConnectorRef(ObjectTypeUtil.createObjectRef(connector));
            delta = ObjectDelta.createAddDelta(resource);
        } else {
            PrismObject<ResourceType> oldResourceObject = WebModelServiceUtils.loadObject(ResourceType.class, oid, GetOperationOptions.createRawCollection(), parentPage, parentPage.createSimpleTask("loadResource"), result);
            if (oldResourceObject == null) {
                throw new SystemException("Resource being edited (" + oid + ") couldn't be retrieved");
            }
            ResourceType oldResource = oldResourceObject.asObjectable();
            S_ItemEntry i = DeltaBuilder.deltaFor(ResourceType.class, prismContext);
            if (!StringUtils.equals(PolyString.getOrig(oldResource.getName()), resourceNameModel.getObject())) {
                i = i.item(ResourceType.F_NAME).replace(PolyString.fromOrig(resourceNameModel.getObject()));
            }
            if (!StringUtils.equals(oldResource.getDescription(), resourceDescriptionModel.getObject())) {
                i = i.item(ResourceType.F_DESCRIPTION).replace(resourceDescriptionModel.getObject());
            }
            String oldConnectorOid = oldResource.getConnectorRef() != null ? oldResource.getConnectorRef().getOid() : null;
            String newConnectorOid = connector.getOid();
            if (!StringUtils.equals(oldConnectorOid, newConnectorOid)) {
                i = i.item(ResourceType.F_CONNECTOR_REF).replace(ObjectTypeUtil.createObjectRef(connector).asReferenceValue());
            }
            if (!isConfigurationSchemaCompatible(connector)) {
                i = i.item(ResourceType.F_CONNECTOR_CONFIGURATION).replace();
            }
            delta = i.asObjectDelta(oid);
        }
        if (!delta.isEmpty()) {
            parentPage.logDelta(delta);
            WebModelServiceUtils.save(delta, ModelExecuteOptions.createRaw(), result, null, parentPage);
            parentPage.resetModels();
            saved = true;
        }
        if (isNew) {
            parentPage.setEditedResourceOid(delta.getOid());
        }
    } catch (RuntimeException | SchemaException ex) {
        LoggingUtils.logUnexpectedException(LOGGER, "Couldn't save resource", ex);
        result.recordFatalError("Couldn't save resource, reason: " + ex.getMessage(), ex);
    } finally {
        result.computeStatusIfUnknown();
        setResult(result);
    }
    if (parentPage.showSaveResultInPage(saved, result)) {
        parentPage.showResult(result);
    }
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) Task(com.evolveum.midpoint.task.api.Task) ConnectorType(com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorType) PrismContext(com.evolveum.midpoint.prism.PrismContext) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) SystemException(com.evolveum.midpoint.util.exception.SystemException) S_ItemEntry(com.evolveum.midpoint.prism.delta.builder.S_ItemEntry) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta)

Example 54 with PrismContext

use of com.evolveum.midpoint.prism.PrismContext in project midpoint by Evolveum.

the class PageDebugView method initViewButton.

private void initViewButton(Form mainForm) {
    List<String> propertyKeysList = Arrays.asList("PageDebugView.xmlViewButton", "PageDebugView.xmlJsonButton", "PageDebugView.xmlYamlButton");
    int selectedIndex = 0;
    if (PrismContext.LANG_JSON.equals(dataLanguage)) {
        selectedIndex = 1;
    } else if (PrismContext.LANG_YAML.equals(dataLanguage)) {
        selectedIndex = 2;
    }
    MultiStateHorizontalButton viewButtonPanel = new MultiStateHorizontalButton(ID_VIEW_BUTTON_PANEL, selectedIndex, propertyKeysList, PageDebugView.this) {

        @Override
        protected void onStateChanged(int index, AjaxRequestTarget target) {
            OperationResult result = new OperationResult(OPERATION_VALIDATE_OBJECT);
            Holder<PrismObject<ObjectType>> objectHolder = new Holder<>(null);
            try {
                validateObject(result, objectHolder);
                if (result.isAcceptable()) {
                    if (index == 1) {
                        dataLanguage = PrismContext.LANG_JSON;
                    } else if (index == 2) {
                        dataLanguage = PrismContext.LANG_YAML;
                    } else {
                        dataLanguage = PrismContext.LANG_XML;
                    }
                    PrismObject<ObjectType> updatedObject = objectHolder.getValue();
                    PrismContext context = getMidpointApplication().getPrismContext();
                    String objectStr = context.serializerFor(dataLanguage).serialize(updatedObject);
                    objectViewDto.setXml(objectStr);
                    setSelectedIndex(index);
                    addOrReplaceEditor();
                    target.add(mainForm);
                    target.add(getFeedbackPanel());
                } else {
                    showResult(result);
                    target.add(getFeedbackPanel());
                }
            } catch (Exception ex) {
                result.recordFatalError("Couldn't change the language.", ex);
                showResult(result);
                target.add(getFeedbackPanel());
            }
        }
    };
    viewButtonPanel.setOutputMarkupId(true);
    mainForm.add(viewButtonPanel);
}
Also used : MultiStateHorizontalButton(com.evolveum.midpoint.web.component.input.MultiStateHorizontalButton) PrismContext(com.evolveum.midpoint.prism.PrismContext) Holder(com.evolveum.midpoint.util.Holder) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) RestartResponseException(org.apache.wicket.RestartResponseException) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) PrismObject(com.evolveum.midpoint.prism.PrismObject)

Example 55 with PrismContext

use of com.evolveum.midpoint.prism.PrismContext in project midpoint by Evolveum.

the class ExecuteChangesHandlerDto method getOptions.

public String getOptions() {
    ModelExecuteOptionsType options = taskDto.getExtensionPropertyRealValue(SchemaConstants.MODEL_EXTENSION_EXECUTE_OPTIONS, ModelExecuteOptionsType.class);
    if (options == null) {
        return null;
    }
    PrismContext prismContext = MidPointApplication.get().getPrismContext();
    try {
        return WebXmlUtil.stripNamespaceDeclarations(prismContext.xmlSerializer().serializeAnyData(options, SchemaConstants.MODEL_EXTENSION_EXECUTE_OPTIONS));
    } catch (SchemaException e) {
        throw new SystemException("Couldn't serialize model execute options: " + e.getMessage(), e);
    }
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) SystemException(com.evolveum.midpoint.util.exception.SystemException) PrismContext(com.evolveum.midpoint.prism.PrismContext) ModelExecuteOptionsType(com.evolveum.midpoint.xml.ns._public.common.common_3.ModelExecuteOptionsType)

Aggregations

PrismContext (com.evolveum.midpoint.prism.PrismContext)104 Test (org.testng.annotations.Test)59 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)15 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)15 QName (javax.xml.namespace.QName)15 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)13 Task (com.evolveum.midpoint.task.api.Task)11 SchemaRegistry (com.evolveum.midpoint.prism.schema.SchemaRegistry)10 ResourceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType)10 PrismObject (com.evolveum.midpoint.prism.PrismObject)9 SystemException (com.evolveum.midpoint.util.exception.SystemException)9 File (java.io.File)8 PrismPropertyDefinition (com.evolveum.midpoint.prism.PrismPropertyDefinition)7 ArrayList (java.util.ArrayList)7 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)6 AssignmentType (com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType)6 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)6 Protector (com.evolveum.midpoint.prism.crypto.Protector)5 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)5 MidPointApplication (com.evolveum.midpoint.web.security.MidPointApplication)5