Search in sources :

Example 61 with QueryType

use of net.opengis.wfs.v_1_1_0.QueryType in project midpoint by Evolveum.

the class TestOpenDj method test200SearchObjectsIterative.

@Test
public void test200SearchObjectsIterative() throws Exception {
    Task task = getTestTask();
    OperationResult result = task.getResult();
    ShadowType object = parseObjectType(ACCOUNT_SEARCH_ITERATIVE_FILE, ShadowType.class);
    System.out.println(SchemaDebugUtil.prettyPrint(object));
    System.out.println(object.asPrismObject().debugDump());
    String addedObjectOid = provisioningService.addObject(object.asPrismObject(), null, null, taskManager.createTaskInstance(), result);
    assertEquals(ACCOUNT_SEARCH_ITERATIVE_OID, addedObjectOid);
    final List<ShadowType> objectTypeList = new ArrayList<>();
    QueryType queryType = PrismTestUtil.parseAtomicValue(QUERY_ALL_ACCOUNTS_FILE, QueryType.COMPLEX_TYPE);
    ObjectQuery query = getQueryConverter().createObjectQuery(ShadowType.class, queryType);
    provisioningService.searchObjectsIterative(ShadowType.class, query, null, new ResultHandler<ShadowType>() {

        @Override
        public boolean handle(PrismObject<ShadowType> object, OperationResult parentResult) {
            return objectTypeList.add(object.asObjectable());
        }
    }, task, result);
    // TODO: check result
    System.out.println("ObjectType list size: " + objectTypeList.size());
    for (ObjectType objType : objectTypeList) {
        if (objType == null) {
            System.out.println("Object not found in repo");
        } else {
            // System.out.println("obj name: " + objType.getName());
            System.out.println(object.asPrismObject().debugDump());
        }
    }
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ArrayList(java.util.ArrayList) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) QueryType(com.evolveum.prism.xml.ns._public.query_3.QueryType) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) Test(org.testng.annotations.Test)

Example 62 with QueryType

use of net.opengis.wfs.v_1_1_0.QueryType in project midpoint by Evolveum.

the class AuditSearchTest method countObjects.

private int countObjects(ObjectQuery query, OperationResult operationResult, SelectorOptions<GetOperationOptions>... selectorOptions) throws SchemaException {
    QueryType queryType = prismContext.getQueryConverter().createQueryType(query);
    String serializedQuery = prismContext.xmlSerializer().serializeAnyData(queryType, SchemaConstants.MODEL_EXTENSION_OBJECT_QUERY);
    System.out.println("queryType = " + serializedQuery);
    // sanity check if it's re-parsable
    assertThat(prismContext.parserFor(serializedQuery).parseRealValue(QueryType.class)).isNotNull();
    return auditService.countObjects(query, Arrays.asList(selectorOptions), operationResult);
}
Also used : PolyString(com.evolveum.midpoint.prism.polystring.PolyString) QueryType(com.evolveum.prism.xml.ns._public.query_3.QueryType)

Example 63 with QueryType

use of net.opengis.wfs.v_1_1_0.QueryType in project midpoint by Evolveum.

the class SqaleRepoBaseTest method searchObjects.

/**
 * Search objects using {@link ObjectQuery}, including various logs and sanity checks.
 */
@SafeVarargs
@NotNull
protected final <T extends ObjectType> SearchResultList<T> searchObjects(@NotNull Class<T> type, ObjectQuery query, OperationResult operationResult, SelectorOptions<GetOperationOptions>... selectorOptions) throws SchemaException {
    display("QUERY: " + query);
    QueryType queryType = prismContext.getQueryConverter().createQueryType(query);
    String serializedQuery = prismContext.xmlSerializer().serializeAnyData(queryType, SchemaConstants.MODEL_EXTENSION_OBJECT_QUERY);
    display("Serialized QUERY: " + serializedQuery);
    // sanity check if it's re-parsable
    assertThat(prismContext.parserFor(serializedQuery).parseRealValue(QueryType.class)).isNotNull();
    return repositorySearchObjects(type, query, operationResult, selectorOptions);
}
Also used : QueryType(com.evolveum.prism.xml.ns._public.query_3.QueryType) NotNull(org.jetbrains.annotations.NotNull)

Example 64 with QueryType

use of net.opengis.wfs.v_1_1_0.QueryType in project midpoint by Evolveum.

the class QueryInterpreterTest method getQuery.

@Nullable
private ObjectQuery getQuery(File file, Class<? extends Containerable> type) throws SchemaException, IOException {
    QueryType queryType = PrismTestUtil.parseAtomicValue(file, QueryType.COMPLEX_TYPE);
    logger.info("QUERY TYPE TO CONVERT : {}", ObjectQueryUtil.dump(queryType, prismContext));
    try {
        return getQueryConverter().createObjectQuery(type, queryType);
    } catch (Exception ex) {
        logger.info("error while converting query: " + ex.getMessage(), ex);
        return null;
    }
}
Also used : QueryType(com.evolveum.prism.xml.ns._public.query_3.QueryType) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) QueryException(com.evolveum.midpoint.repo.sqlbase.QueryException) IOException(java.io.IOException) Nullable(org.jetbrains.annotations.Nullable)

Example 65 with QueryType

use of net.opengis.wfs.v_1_1_0.QueryType in project midpoint by Evolveum.

the class PageRepositoryQuery method initLayout.

private void initLayout() {
    Form mainForm = new MidpointForm(ID_MAIN_FORM);
    add(mainForm);
    Label repositoryQueryLabel = new Label(ID_REPOSITORY_QUERY_LABEL, createStringResource("PageRepositoryQuery.midPoint", WebComponentUtil.getMidpointCustomSystemName(PageRepositoryQuery.this, "MidPoint")));
    repositoryQueryLabel.setOutputMarkupId(true);
    mainForm.add(repositoryQueryLabel);
    DropDownChoicePanel<QName> objectTypeChoice = new DropDownChoicePanel<>(ID_OBJECT_TYPE, new PropertyModel<>(model, RepoQueryDto.F_OBJECT_TYPE), new ListModel<>(WebComponentUtil.createObjectTypeList()), new QNameChoiceRenderer());
    objectTypeChoice.setOutputMarkupId(true);
    objectTypeChoice.getBaseFormComponent().setNullValid(true);
    objectTypeChoice.getBaseFormComponent().add(new OnChangeAjaxBehavior() {

        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            target.add(get(ID_MAIN_FORM).get(ID_MIDPOINT_QUERY_BUTTON_BAR));
        }
    });
    mainForm.add(objectTypeChoice);
    CheckFormGroup distinctCheck = new CheckFormGroup(ID_DISTINCT, new PropertyModel<>(model, RepoQueryDto.F_DISTINCT), createStringResource("PageRepositoryQuery.checkBox.distinct"), "col-xs-3", "col-xs-1");
    mainForm.add(distinctCheck);
    AceEditor editorMidPoint = new AceEditor(ID_EDITOR_MIDPOINT, new PropertyModel<>(model, RepoQueryDto.F_MIDPOINT_QUERY));
    editorMidPoint.setHeight(400);
    editorMidPoint.setResizeToMaxHeight(false);
    mainForm.add(editorMidPoint);
    Label queryLabel = new Label(ID_QUERY_LABEL, createQueryLabelModel());
    mainForm.add(queryLabel);
    AceEditor editorHibernate = new AceEditor(ID_QUERY_EDITOR, new PropertyModel<>(model, RepoQueryDto.F_HIBERNATE_QUERY));
    editorHibernate.setHeight(300);
    editorHibernate.setResizeToMaxHeight(false);
    editorHibernate.setReadonly(!isAdmin);
    editorHibernate.setMode(null);
    mainForm.add(editorHibernate);
    AceEditor hibernateParameters = new AceEditor(ID_PARAMETERS, new PropertyModel<>(model, RepoQueryDto.F_HIBERNATE_PARAMETERS));
    hibernateParameters.setReadonly(true);
    hibernateParameters.setHeight(100);
    hibernateParameters.setResizeToMaxHeight(false);
    hibernateParameters.setMode(null);
    mainForm.add(hibernateParameters);
    Label hibernateParametersNote = new Label(ID_HIBERNATE_PARAMETERS_NOTE, createStringResource("PageRepositoryQuery.hibernateParametersNote", WebComponentUtil.getMidpointCustomSystemName(PageRepositoryQuery.this, "midPoint")));
    hibernateParametersNote.setVisible(isAdmin && !isNativeRepo());
    mainForm.add(hibernateParametersNote);
    Label queryVsFilterNote = new Label(ID_QUERY_VS_FILTER_NOTE, createStringResource("PageRepositoryQuery.queryVsFilterNote", WebComponentUtil.getMidpointCustomSystemName(PageRepositoryQuery.this, "midPoint")));
    queryVsFilterNote.setOutputMarkupId(true);
    mainForm.add(queryVsFilterNote);
    WebMarkupContainer midPointQueryButtonBar = new WebMarkupContainer(ID_MIDPOINT_QUERY_BUTTON_BAR);
    midPointQueryButtonBar.setOutputMarkupId(true);
    mainForm.add(midPointQueryButtonBar);
    DataLanguagePanel<QueryType> dataLanguagePanel = new DataLanguagePanel<>(ID_VIEW_BUTTON_PANEL, dataLanguage, QueryType.class, PageRepositoryQuery.this) {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onLanguageSwitched(AjaxRequestTarget target, int updatedIndex, String updatedLanguage, String objectString) {
            model.getObject().setMidPointQuery(objectString);
            dataLanguage = updatedLanguage;
            target.add(mainForm);
        }

        @Override
        protected String getObjectStringRepresentation() {
            return model.getObject().getMidPointQuery();
        }
    };
    dataLanguagePanel.setOutputMarkupId(true);
    mainForm.add(dataLanguagePanel);
    AjaxSubmitButton executeMidPoint = new AjaxSubmitButton(ID_EXECUTE_MIDPOINT, createStringResource("PageRepositoryQuery.button.translateAndExecute")) {

        @Override
        protected void onError(AjaxRequestTarget target) {
            target.add(getFeedbackPanel());
        }

        @Override
        protected void onSubmit(AjaxRequestTarget target) {
            queryPerformed(Action.EXECUTE_MIDPOINT, target);
        }
    };
    midPointQueryButtonBar.add(executeMidPoint);
    AjaxSubmitButton compileMidPoint = new AjaxSubmitButton(ID_COMPILE_MIDPOINT, createCompileMidpointLabelModel()) {

        @Override
        protected void onError(AjaxRequestTarget target) {
            target.add(getFeedbackPanel());
        }

        @Override
        protected void onSubmit(AjaxRequestTarget target) {
            queryPerformed(Action.TRANSLATE_ONLY, target);
        }
    };
    midPointQueryButtonBar.add(compileMidPoint);
    AjaxSubmitButton useInObjectList = new AjaxSubmitButton(ID_USE_IN_OBJECT_LIST, createStringResource("PageRepositoryQuery.button.useInObjectList")) {

        @Override
        protected void onError(AjaxRequestTarget target) {
            target.add(getFeedbackPanel());
        }

        @Override
        protected void onSubmit(AjaxRequestTarget target) {
            useInObjectListPerformed(target);
        }
    };
    useInObjectList.add(new VisibleEnableBehaviour() {

        @Override
        public boolean isVisible() {
            return USE_IN_OBJECT_LIST_AVAILABLE_FOR.contains(model.getObject().getObjectType());
        }
    });
    midPointQueryButtonBar.add(useInObjectList);
    final DropDownChoicePanel<String> sampleChoice = new DropDownChoicePanel<>(ID_QUERY_SAMPLE, Model.of(""), Model.ofList(SAMPLES), new StringResourceChoiceRenderer("PageRepositoryQuery.sample"), true);
    sampleChoice.getBaseFormComponent().setNullValid(true);
    sampleChoice.getBaseFormComponent().add(new OnChangeAjaxBehavior() {

        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            String sampleName = sampleChoice.getModel().getObject();
            if (StringUtils.isEmpty(sampleName)) {
                return;
            }
            String resourceName = SAMPLES_DIR + "/" + sampleName + ".xml.data";
            InputStream is = PageRepositoryQuery.class.getResourceAsStream(resourceName);
            if (is != null) {
                try {
                    String localTypeName = StringUtils.substringBefore(sampleName, "_");
                    model.getObject().setObjectType(new QName(SchemaConstants.NS_C, localTypeName));
                    String xml = IOUtils.toString(is, StandardCharsets.UTF_8);
                    String serialization;
                    if (PrismContext.LANG_XML.equals(dataLanguage)) {
                        serialization = xml;
                    } else {
                        PrismContext prismContext = getPrismContext();
                        try {
                            QueryType parsed = prismContext.parserFor(xml).xml().parseRealValue(QueryType.class);
                            serialization = prismContext.serializerFor(dataLanguage).serializeRealValue(parsed);
                        } catch (Throwable t) {
                            serialization = "Couldn't serialize sample: " + t.getMessage();
                        }
                    }
                    model.getObject().setMidPointQuery(serialization);
                    model.getObject().setHibernateQuery("");
                    model.getObject().setHibernateParameters("");
                    model.getObject().setQueryResultObject(null);
                    model.getObject().resetQueryResultText();
                    target.add(PageRepositoryQuery.this);
                } catch (IOException e) {
                    LoggingUtils.logUnexpectedException(LOGGER, "Couldn't read sample from resource {}", e, resourceName);
                }
            } else {
                LOGGER.warn("Resource {} containing sample couldn't be found", resourceName);
            }
        }
    });
    mainForm.add(sampleChoice);
    AjaxSubmitButton executeHibernate = new AjaxSubmitButton(ID_EXECUTE_HIBERNATE, createStringResource("PageRepositoryQuery.button.execute")) {

        @Override
        protected void onError(AjaxRequestTarget target) {
            target.add(getFeedbackPanel());
        }

        @Override
        protected void onSubmit(AjaxRequestTarget target) {
            queryPerformed(Action.EXECUTE_HIBERNATE, target);
        }
    };
    executeHibernate.setVisible(isAdmin && !isNativeRepo());
    mainForm.add(executeHibernate);
    Label resultLabel = new Label(ID_RESULT_LABEL, new IModel<String>() {

        @Override
        public String getObject() {
            if (model.getObject().getQueryResultText() == null) {
                return "";
            }
            Object queryResult = model.getObject().getQueryResultObject();
            if (queryResult instanceof List) {
                return getString("PageRepositoryQuery.resultObjects", ((List) queryResult).size());
            } else if (queryResult instanceof Throwable) {
                return getString("PageRepositoryQuery.resultException", queryResult.getClass().getName());
            } else {
                // including null
                return getString("PageRepositoryQuery.result");
            }
        }
    });
    mainForm.add(resultLabel);
    WebMarkupContainer incompleteResultsNote = new WebMarkupContainer(ID_INCOMPLETE_RESULTS_NOTE);
    incompleteResultsNote.add(new VisibleEnableBehaviour() {

        @Override
        public boolean isVisible() {
            return !isAdmin && model.getObject().getQueryResultText() != null;
        }
    });
    mainForm.add(incompleteResultsNote);
    AceEditor resultText = new AceEditor(ID_RESULT_TEXT, new PropertyModel<>(model, RepoQueryDto.F_QUERY_RESULT_TEXT));
    resultText.setReadonly(true);
    resultText.setHeight(300);
    resultText.setResizeToMaxHeight(false);
    resultText.setMode(null);
    resultText.add(new VisibleEnableBehaviour() {

        @Override
        public boolean isVisible() {
            return model.getObject().getQueryResultText() != null;
        }
    });
    mainForm.add(resultText);
}
Also used : DropDownChoicePanel(com.evolveum.midpoint.web.component.input.DropDownChoicePanel) MidpointForm(com.evolveum.midpoint.web.component.form.MidpointForm) Form(org.apache.wicket.markup.html.form.Form) PrismContext(com.evolveum.midpoint.prism.PrismContext) Label(org.apache.wicket.markup.html.basic.Label) AceEditor(com.evolveum.midpoint.web.component.AceEditor) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) VisibleEnableBehaviour(com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour) QNameChoiceRenderer(com.evolveum.midpoint.web.component.input.QNameChoiceRenderer) AjaxSubmitButton(com.evolveum.midpoint.web.component.AjaxSubmitButton) StringResourceChoiceRenderer(com.evolveum.midpoint.web.util.StringResourceChoiceRenderer) QName(javax.xml.namespace.QName) InputStream(java.io.InputStream) MidpointForm(com.evolveum.midpoint.web.component.form.MidpointForm) DataLanguagePanel(com.evolveum.midpoint.web.component.input.DataLanguagePanel) IOException(java.io.IOException) OnChangeAjaxBehavior(org.apache.wicket.ajax.form.OnChangeAjaxBehavior) CheckFormGroup(com.evolveum.midpoint.web.component.form.CheckFormGroup) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) QueryType(com.evolveum.prism.xml.ns._public.query_3.QueryType)

Aggregations

QueryType (com.evolveum.prism.xml.ns._public.query_3.QueryType)91 Test (org.junit.Test)89 QueryImpl (ddf.catalog.operation.impl.QueryImpl)71 QueryType (net.opengis.cat.csw.v_2_0_2.QueryType)67 GetRecordsType (net.opengis.cat.csw.v_2_0_2.GetRecordsType)58 Test (org.testng.annotations.Test)52 QName (javax.xml.namespace.QName)50 JAXBElement (javax.xml.bind.JAXBElement)44 SearchFilterType (com.evolveum.prism.xml.ns._public.query_3.SearchFilterType)38 ArrayList (java.util.ArrayList)37 QueryRequestImpl (ddf.catalog.operation.impl.QueryRequestImpl)34 Filter (org.opengis.filter.Filter)32 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)23 SortBy (org.opengis.filter.sort.SortBy)22 QueryConstraintType (net.opengis.cat.csw.v_2_0_2.QueryConstraintType)21 CswRecordCollection (org.codice.ddf.spatial.ogc.csw.catalog.common.CswRecordCollection)21 SortByImpl (ddf.catalog.filter.impl.SortByImpl)20 ElementSetNameType (net.opengis.cat.csw.v_2_0_2.ElementSetNameType)19 CswException (org.codice.ddf.spatial.ogc.csw.catalog.common.CswException)19 ObjectFactory (net.opengis.cat.csw.v_2_0_2.ObjectFactory)18