Search in sources :

Example 21 with ObjectFactory

use of org.apache.type_test.types3.ObjectFactory in project midpoint by Evolveum.

the class TestConsistencyMechanism method test511AssignAccountMorgan.

/**
 * assign account to the user morgan. Account with the same 'uid' (not dn, nut other secondary identifier already exists)
 * account should be linked to the user.
 */
@Test
public void test511AssignAccountMorgan() throws Exception {
    // GIVEN
    openDJController.assumeRunning();
    Task task = getTestTask();
    OperationResult result = task.getResult();
    dummyAuditService.clear();
    // prepare new OU in opendj
    openDJController.addEntryFromLdifFile(LDIF_CREATE_USERS_OU_FILE);
    PrismObject<UserType> user = repositoryService.getObject(UserType.class, USER_MORGAN_OID, null, result);
    display("User Morgan: ", user);
    ExpressionType expression = new ExpressionType();
    ObjectFactory of = new ObjectFactory();
    RawType raw = new RawType(prismContext.xnodeFactory().primitive("uid=morgan,ou=users,dc=example,dc=com").frozen(), prismContext);
    JAXBElement<?> val = of.createValue(raw);
    expression.getExpressionEvaluator().add(val);
    MappingType mapping = new MappingType();
    mapping.setExpression(expression);
    ResourceAttributeDefinitionType attrDefType = new ResourceAttributeDefinitionType();
    attrDefType.setRef(new ItemPathType(ItemPath.create(getOpenDjSecondaryIdentifierQName())));
    attrDefType.setOutbound(mapping);
    ConstructionType construction = new ConstructionType();
    construction.getAttribute().add(attrDefType);
    construction.setResourceRef(ObjectTypeUtil.createObjectRef(resourceTypeOpenDjrepo, prismContext));
    AssignmentType assignment = new AssignmentType();
    assignment.setConstruction(construction);
    // noinspection unchecked
    ObjectDelta<UserType> userDelta = prismContext.deltaFactory().object().createModificationAddContainer(UserType.class, USER_MORGAN_OID, UserType.F_ASSIGNMENT, assignment.asPrismContainerValue());
    Collection<ObjectDelta<? extends ObjectType>> deltas = MiscSchemaUtil.createCollection(userDelta);
    // WHEN
    when();
    modelService.executeChanges(deltas, null, task, result);
    // THEN
    then();
    result.computeStatus();
    // assertEquals("Expected handled error but got: " + result.getStatus(), OperationResultStatus.HANDLED_ERROR, result.getStatus());
    PrismObject<UserType> userMorgan = modelService.getObject(UserType.class, USER_MORGAN_OID, null, task, result);
    display("User morgan after", userMorgan);
    UserType userMorganType = userMorgan.asObjectable();
    assertEquals("Unexpected number of accountRefs", 1, userMorganType.getLinkRef().size());
    String accountOid = userMorganType.getLinkRef().iterator().next().getOid();
    // Check shadow
    PrismObject<ShadowType> accountShadow = repositoryService.getObject(ShadowType.class, accountOid, null, result);
    provisioningService.applyDefinition(accountShadow, task, result);
    assertShadowRepo(accountShadow, accountOid, "uid=morgan,ou=users,dc=example,dc=com", resourceTypeOpenDjrepo, RESOURCE_OPENDJ_ACCOUNT_OBJECTCLASS);
    // Check account
    PrismObject<ShadowType> accountModel = modelService.getObject(ShadowType.class, accountOid, null, task, result);
    assertShadowModel(accountModel, accountOid, "uid=morgan,ou=users,dc=example,dc=com", resourceTypeOpenDjrepo, RESOURCE_OPENDJ_ACCOUNT_OBJECTCLASS);
    ResourceAttribute<?> attributes = ShadowUtil.getAttribute(accountModel, new QName(MidPointConstants.NS_RI, "uid"));
    assertEquals("morgan", attributes.getAnyRealValue());
// TODO: check OpenDJ Account
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ItemPathType(com.evolveum.prism.xml.ns._public.types_3.ItemPathType) QName(javax.xml.namespace.QName) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) ObjectFactory(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectFactory) RawType(com.evolveum.prism.xml.ns._public.types_3.RawType) Test(org.testng.annotations.Test) AbstractModelIntegrationTest(com.evolveum.midpoint.model.test.AbstractModelIntegrationTest)

Example 22 with ObjectFactory

use of org.apache.type_test.types3.ObjectFactory in project midpoint by Evolveum.

the class TestPlentyOfAssignments method initSystem.

@Override
public void initSystem(Task initTask, OperationResult initResult) throws Exception {
    super.initSystem(initTask, initResult);
    initDummyResourcePirate(null, RESOURCE_DUMMY_FILE, RESOURCE_DUMMY_OID, initTask, initResult);
    importObjectFromFile(ROLE_BASIC_FILE, initResult);
    ObjectFactory objectFactory = new ObjectFactory();
    generateRoles(NUMBER_OF_GENERATED_EMPTY_ROLES, "Empty Role %04d", GENERATED_EMPTY_ROLE_OID_FORMAT, null, initResult);
    generateRoles(NUMBER_OF_GENERATED_DUMMY_ROLES, "Dummy Role %04d", GENERATED_DUMMY_ROLE_OID_FORMAT, (role, i) -> {
        ItemPathType attrPath = new ItemPathType(ItemPath.create(new QName(RESOURCE_DUMMY_NS, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_DRINK_NAME)));
        JAXBElement<Object> evaluator = objectFactory.createValue(formatRum(i));
        role.beginInducement().beginConstruction().resourceRef(RESOURCE_DUMMY_OID, ResourceType.COMPLEX_TYPE).kind(ShadowKindType.ACCOUNT).beginAttribute().ref(attrPath).beginOutbound().beginExpression().expressionEvaluator(evaluator);
    }, initResult);
    inspector = new CountingInspector();
    InternalMonitor.setInspector(inspector);
}
Also used : ObjectFactory(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectFactory) ItemPathType(com.evolveum.prism.xml.ns._public.types_3.ItemPathType) QName(javax.xml.namespace.QName) PrismObject(com.evolveum.midpoint.prism.PrismObject)

Example 23 with ObjectFactory

use of org.apache.type_test.types3.ObjectFactory in project midpoint by Evolveum.

the class TestPlentyOfAssignments method test200DummyGroups.

/**
 * Create dummy groups that can be used for associationTargetSearch later on.
 * Create them from midPoint so they have shadows.
 * <p>
 * MID-3938 #8
 */
@Test
public void test200DummyGroups() throws Exception {
    Task task = getTestTask();
    OperationResult result = task.getResult();
    // WHEN
    when();
    PrismObjectDefinition<ShadowType> shadowDef = prismContext.getSchemaRegistry().findObjectDefinitionByCompileTimeClass(ShadowType.class);
    PrismObjectDefinition<RoleType> roleDef = prismContext.getSchemaRegistry().findObjectDefinitionByCompileTimeClass(RoleType.class);
    ResourceSchema rSchema = ResourceSchemaFactory.getCompleteSchema(getDummyResourceObject());
    ResourceObjectClassDefinition rOcDef = rSchema.findObjectClassDefinition(getDummyResourceController().getGroupObjectClass());
    ObjectFactory objectFactory = new ObjectFactory();
    ItemPath nameAttributePath = ItemPath.create(ShadowType.F_ATTRIBUTES, SchemaConstants.ICFS_NAME);
    for (int i = 0; i < NUMBER_OF_GENERATED_DUMMY_GROUPS; i++) {
        PrismObject<ShadowType> shadow = shadowDef.instantiate();
        ShadowType shadowType = shadow.asObjectable();
        shadowType.resourceRef(RESOURCE_DUMMY_OID, ResourceType.COMPLEX_TYPE).objectClass(rOcDef.getTypeName());
        ResourceAttributeContainer attributesContainer = ShadowUtil.getOrCreateAttributesContainer(shadow, rOcDef);
        ResourceAttribute<String> nameAttribute = attributesContainer.findOrCreateAttribute(SchemaConstants.ICFS_NAME);
        String groupName = formatGroupName(i);
        nameAttribute.setRealValue(groupName);
        display("Group shadow " + i, shadow);
        addObject(shadow, task, result);
        PrismObject<RoleType> role = roleDef.instantiate();
        RoleType roleType = role.asObjectable();
        ItemPathType assPath = new ItemPathType(ItemPath.create(RESOURCE_DUMMY_ASSOCIATION_GROUP_QNAME));
        SearchObjectExpressionEvaluatorType associationTargetSearchType = new SearchObjectExpressionEvaluatorType();
        EqualFilter<String> filter = prismContext.queryFactory().createEqual(nameAttributePath, null, null, prismContext, groupName);
        SearchFilterType filterType = prismContext.getQueryConverter().createSearchFilterType(filter);
        associationTargetSearchType.setFilter(filterType);
        associationTargetSearchType.setSearchStrategy(ObjectSearchStrategyType.IN_REPOSITORY);
        JAXBElement<SearchObjectExpressionEvaluatorType> evaluator = objectFactory.createAssociationTargetSearch(associationTargetSearchType);
        roleType.oid(generateRoleOid(GENERATED_DUMMY_GROUP_ROLE_OID_FORMAT, i)).name(String.format("Group role %04d", i)).beginInducement().beginConstruction().resourceRef(RESOURCE_DUMMY_OID, ResourceType.COMPLEX_TYPE).kind(ShadowKindType.ACCOUNT).beginAssociation().ref(assPath).beginOutbound().beginExpression().expressionEvaluator(evaluator);
        try {
            IntegrationTestTools.displayXml("RRRRRRRRR group", role);
        } catch (SchemaException e) {
            throw new SystemException(e);
        }
        addObject(role, task, result);
    }
    // THEN
    then();
    assertSuccess(result);
    Collection<DummyGroup> dummyGroups = getDummyResource().listGroups();
    assertEquals("Wrong number of dummy groups", NUMBER_OF_GENERATED_DUMMY_GROUPS, dummyGroups.size());
    assertShadows(NUMBER_OF_GENERATED_DUMMY_GROUPS);
    assertObjects(RoleType.class, NUMBER_OF_GENERATED_EMPTY_ROLES + NUMBER_OF_GENERATED_DUMMY_ROLES + NUMBER_OF_ORDINARY_ROLES + NUMBER_OF_GENERATED_DUMMY_GROUPS);
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ItemPathType(com.evolveum.prism.xml.ns._public.types_3.ItemPathType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectFactory(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectFactory) SystemException(com.evolveum.midpoint.util.exception.SystemException) DummyGroup(com.evolveum.icf.dummy.resource.DummyGroup) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) SearchFilterType(com.evolveum.prism.xml.ns._public.query_3.SearchFilterType) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) Test(org.testng.annotations.Test)

Example 24 with ObjectFactory

use of org.apache.type_test.types3.ObjectFactory in project ddf by codice.

the class CswEndpoint method queryCsw.

private CswRecordCollection queryCsw(GetRecordsType request) throws CswException {
    if (LOGGER.isDebugEnabled()) {
        try {
            Writer writer = new StringWriter();
            try {
                Marshaller marshaller = CswQueryFactory.getJaxBContext().createMarshaller();
                marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
                JAXBElement<GetRecordsType> jaxbElement = new ObjectFactory().createGetRecords(request);
                marshaller.marshal(jaxbElement, writer);
            } catch (JAXBException e) {
                LOGGER.debug("Unable to marshall {} to XML", GetRecordsType.class, e);
            }
            LOGGER.debug(writer.toString());
        } catch (Exception e) {
            LOGGER.debug("Unable to create debug message for getRecordsType", e);
        }
    }
    QueryType query = (QueryType) request.getAbstractQuery().getValue();
    CswRecordCollection response = new CswRecordCollection();
    response.setRequest(request);
    response.setOutputSchema(request.getOutputSchema());
    response.setMimeType(request.getOutputFormat());
    response.setElementName(query.getElementName());
    response.setElementSetType((query.getElementSetName() != null) ? query.getElementSetName().getValue() : null);
    response.setResultType((ResultType) ObjectUtils.defaultIfNull(request.getResultType(), ResultType.HITS));
    if (ResultType.HITS.equals(request.getResultType()) || ResultType.RESULTS.equals(request.getResultType())) {
        QueryRequest queryRequest = queryFactory.getQuery(request);
        try {
            queryRequest = queryFactory.updateQueryRequestTags(queryRequest, request.getOutputSchema());
            LOGGER.debug("Attempting to execute paged query: {}", queryRequest);
            AtomicLong hitCount = new AtomicLong(0);
            QueryFunction qf = qr -> {
                SourceResponse sr = framework.query(qr);
                hitCount.compareAndSet(0, sr.getHits());
                return sr;
            };
            ResultIterable results = ResultIterable.resultIterable(qf, queryRequest, request.getMaxRecords().intValue());
            List<Result> resultList = results.stream().collect(Collectors.toList());
            // The hitCount Atomic is used here instead of just defaulting
            // to the size of the resultList because the size of the resultList
            // can be limited to request.getMaxRecords().intValue() which would
            // lead to an incorrect response for hits.
            // hitCount is set within the QueryFunction and will correspond to
            // all responses.
            long totalHits = hitCount.get();
            totalHits = totalHits != 0 ? totalHits : resultList.size();
            QueryResponse queryResponse = new QueryResponseImpl(queryRequest, resultList, totalHits);
            response.setSourceResponse(queryResponse);
        } catch (UnsupportedQueryException | CatalogQueryException e) {
            LOGGER.debug("Unable to query", e);
            throw new CswException(e);
        }
    }
    return response;
}
Also used : ScalarCapabilitiesType(net.opengis.filter.v_1_1_0.ScalarCapabilitiesType) Arrays(java.util.Arrays) StringUtils(org.apache.commons.lang.StringUtils) WKTReader(org.locationtech.jts.io.WKTReader) CreateRequest(ddf.catalog.operation.CreateRequest) Produces(javax.ws.rs.Produces) XMLUtils(org.codice.ddf.platform.util.XMLUtils) SpatialOperatorsType(net.opengis.filter.v_1_1_0.SpatialOperatorsType) RequestMethodType(net.opengis.ows.v_1_0_0.RequestMethodType) Future(java.util.concurrent.Future) MediaType(javax.ws.rs.core.MediaType) ServiceIdentification(net.opengis.ows.v_1_0_0.ServiceIdentification) Document(org.w3c.dom.Document) Map(java.util.Map) HeaderParam(javax.ws.rs.HeaderParam) BigInteger(java.math.BigInteger) ComparisonOperatorType(net.opengis.filter.v_1_1_0.ComparisonOperatorType) Csw(org.codice.ddf.spatial.ogc.csw.catalog.common.Csw) ServiceReference(org.osgi.framework.ServiceReference) HTTP(net.opengis.ows.v_1_0_0.HTTP) TransactionSummaryType(net.opengis.cat.csw.v_2_0_2.TransactionSummaryType) CancellationException(java.util.concurrent.CancellationException) StandardThreadFactoryBuilder(org.codice.ddf.platform.util.StandardThreadFactoryBuilder) ResourceRequestById(ddf.catalog.operation.impl.ResourceRequestById) Set(java.util.Set) LogicalOperators(net.opengis.filter.v_1_1_0.LogicalOperators) ResourceNotFoundException(ddf.catalog.resource.ResourceNotFoundException) Serializable(java.io.Serializable) MimeTypeParseException(javax.activation.MimeTypeParseException) Stream(java.util.stream.Stream) ParseException(org.locationtech.jts.io.ParseException) SpatialCapabilitiesType(net.opengis.filter.v_1_1_0.SpatialCapabilitiesType) CswConstants(org.codice.ddf.spatial.ogc.csw.catalog.common.CswConstants) UpdateResponse(ddf.catalog.operation.UpdateResponse) UriInfo(javax.ws.rs.core.UriInfo) QName(javax.xml.namespace.QName) SecurityUtils(org.apache.shiro.SecurityUtils) CswRequest(org.codice.ddf.spatial.ogc.csw.catalog.common.CswRequest) ResourceResponse(ddf.catalog.operation.ResourceResponse) SpatialOperatorType(net.opengis.filter.v_1_1_0.SpatialOperatorType) Iterables(com.google.common.collect.Iterables) ResultIterable(ddf.catalog.util.impl.ResultIterable) GeometryOperandsType(net.opengis.filter.v_1_1_0.GeometryOperandsType) DescribeRecordRequest(org.codice.ddf.spatial.ogc.csw.catalog.common.DescribeRecordRequest) GET(javax.ws.rs.GET) CatalogFramework(ddf.catalog.CatalogFramework) QueryResponseImpl(ddf.catalog.operation.impl.QueryResponseImpl) ResponsiblePartySubsetType(net.opengis.ows.v_1_0_0.ResponsiblePartySubsetType) DeleteResponse(ddf.catalog.operation.DeleteResponse) Callable(java.util.concurrent.Callable) Resource(ddf.catalog.resource.Resource) ArrayList(java.util.ArrayList) IdCapabilitiesType(net.opengis.filter.v_1_1_0.IdCapabilitiesType) Subject(org.apache.shiro.subject.Subject) DCP(net.opengis.ows.v_1_0_0.DCP) EID(net.opengis.filter.v_1_1_0.EID) CodeType(net.opengis.ows.v_1_0_0.CodeType) QueryRequest(ddf.catalog.operation.QueryRequest) CswActionTransformerProvider(org.codice.ddf.spatial.ogc.csw.catalog.endpoint.transformer.CswActionTransformerProvider) Result(ddf.catalog.data.Result) CreateRequestImpl(ddf.catalog.operation.impl.CreateRequestImpl) ObjectFactory(net.opengis.cat.csw.v_2_0_2.ObjectFactory) CswRecordCollection(org.codice.ddf.spatial.ogc.csw.catalog.common.CswRecordCollection) CapabilitiesType(net.opengis.cat.csw.v_2_0_2.CapabilitiesType) IngestException(ddf.catalog.source.IngestException) StringWriter(java.io.StringWriter) JAXBElement(javax.xml.bind.JAXBElement) ServiceProvider(net.opengis.ows.v_1_0_0.ServiceProvider) IOException(java.io.IOException) FederationException(ddf.catalog.federation.FederationException) UpdateAction(org.codice.ddf.spatial.ogc.csw.catalog.actions.UpdateAction) GetRecordsType(net.opengis.cat.csw.v_2_0_2.GetRecordsType) ExecutionException(java.util.concurrent.ExecutionException) AtomicLong(java.util.concurrent.atomic.AtomicLong) CswTransactionRequest(org.codice.ddf.spatial.ogc.csw.catalog.common.transaction.CswTransactionRequest) Paths(java.nio.file.Paths) DocumentBuilder(javax.xml.parsers.DocumentBuilder) LinkedBlockingDeque(java.util.concurrent.LinkedBlockingDeque) InsertResultType(net.opengis.cat.csw.v_2_0_2.InsertResultType) GetRecordsRequest(org.codice.ddf.spatial.ogc.csw.catalog.common.GetRecordsRequest) TransactionResponseType(net.opengis.cat.csw.v_2_0_2.TransactionResponseType) InsertAction(org.codice.ddf.spatial.ogc.csw.catalog.actions.InsertAction) QueryFilterTransformer(ddf.catalog.transform.QueryFilterTransformer) UpdateRequestImpl(ddf.catalog.operation.impl.UpdateRequestImpl) URL(java.net.URL) DescribeRecordResponseType(net.opengis.cat.csw.v_2_0_2.DescribeRecordResponseType) UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) LoggerFactory(org.slf4j.LoggerFactory) DeleteAction(org.codice.ddf.spatial.ogc.csw.catalog.actions.DeleteAction) CompletionService(java.util.concurrent.CompletionService) GetCapabilitiesRequest(org.codice.ddf.spatial.ogc.csw.catalog.common.GetCapabilitiesRequest) LogSanitizer(org.codice.ddf.log.sanitizer.LogSanitizer) QueryParam(javax.ws.rs.QueryParam) Consumes(javax.ws.rs.Consumes) DeleteRequestImpl(ddf.catalog.operation.impl.DeleteRequestImpl) TransformerManager(org.codice.ddf.spatial.ogc.csw.catalog.common.transformer.TransformerManager) Bundle(org.osgi.framework.Bundle) Splitter(com.google.common.base.Splitter) CatalogQueryException(ddf.catalog.util.impl.CatalogQueryException) Context(javax.ws.rs.core.Context) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) OnlineResourceType(net.opengis.ows.v_1_0_0.OnlineResourceType) Collection(java.util.Collection) GetRecordByIdType(net.opengis.cat.csw.v_2_0_2.GetRecordByIdType) CswException(org.codice.ddf.spatial.ogc.csw.catalog.common.CswException) Collectors(java.util.stream.Collectors) JAXBException(javax.xml.bind.JAXBException) ObjectUtils(org.apache.commons.lang.ObjectUtils) BundleContext(org.osgi.framework.BundleContext) Objects(java.util.Objects) QueryResponse(ddf.catalog.operation.QueryResponse) List(java.util.List) Attribute(ddf.catalog.data.Attribute) Operation(net.opengis.ows.v_1_0_0.Operation) SAXException(org.xml.sax.SAXException) Writer(java.io.Writer) Entry(java.util.Map.Entry) Optional(java.util.Optional) Geometry(org.locationtech.jts.geom.Geometry) ComparisonOperatorsType(net.opengis.filter.v_1_1_0.ComparisonOperatorsType) ExecutorCompletionService(java.util.concurrent.ExecutorCompletionService) SourceUnavailableException(ddf.catalog.source.SourceUnavailableException) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) SimpleLiteral(net.opengis.cat.csw.v_2_0_2.dc.elements.SimpleLiteral) Marshaller(javax.xml.bind.Marshaller) AttributeImpl(ddf.catalog.data.impl.AttributeImpl) HashMap(java.util.HashMap) DescribeRecordType(net.opengis.cat.csw.v_2_0_2.DescribeRecordType) ResultType(net.opengis.cat.csw.v_2_0_2.ResultType) Function(java.util.function.Function) SchemaComponentType(net.opengis.cat.csw.v_2_0_2.SchemaComponentType) HashSet(java.util.HashSet) GetCapabilitiesType(net.opengis.cat.csw.v_2_0_2.GetCapabilitiesType) CreateResponse(ddf.catalog.operation.CreateResponse) OperationsMetadata(net.opengis.ows.v_1_0_0.OperationsMetadata) Metacard(ddf.catalog.data.Metacard) QueryType(net.opengis.cat.csw.v_2_0_2.QueryType) MimeType(javax.activation.MimeType) UpdateRequest(ddf.catalog.operation.UpdateRequest) ResourceImpl(ddf.catalog.resource.impl.ResourceImpl) LinkedList(java.util.LinkedList) SpatialOperatorNameType(net.opengis.filter.v_1_1_0.SpatialOperatorNameType) DomainType(net.opengis.ows.v_1_0_0.DomainType) BoundingBoxType(net.opengis.ows.v_1_0_0.BoundingBoxType) GetRecordByIdRequest(org.codice.ddf.spatial.ogc.csw.catalog.common.GetRecordByIdRequest) ElementSetType(net.opengis.cat.csw.v_2_0_2.ElementSetType) POST(javax.ws.rs.POST) Logger(org.slf4j.Logger) ResourceNotSupportedException(ddf.catalog.resource.ResourceNotSupportedException) TimeUnit(java.util.concurrent.TimeUnit) FilterCapabilities(net.opengis.filter.v_1_1_0.FilterCapabilities) SourceResponse(ddf.catalog.operation.SourceResponse) QueryFunction(ddf.catalog.util.impl.QueryFunction) Element(org.w3c.dom.Element) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) BriefRecordType(net.opengis.cat.csw.v_2_0_2.BriefRecordType) QueryConstraintType(net.opengis.cat.csw.v_2_0_2.QueryConstraintType) Collections(java.util.Collections) Envelope(org.locationtech.jts.geom.Envelope) FrameworkUtil(org.osgi.framework.FrameworkUtil) UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) CswException(org.codice.ddf.spatial.ogc.csw.catalog.common.CswException) Result(ddf.catalog.data.Result) StringWriter(java.io.StringWriter) ObjectFactory(net.opengis.cat.csw.v_2_0_2.ObjectFactory) Marshaller(javax.xml.bind.Marshaller) QueryRequest(ddf.catalog.operation.QueryRequest) SourceResponse(ddf.catalog.operation.SourceResponse) JAXBException(javax.xml.bind.JAXBException) GetRecordsType(net.opengis.cat.csw.v_2_0_2.GetRecordsType) ResultIterable(ddf.catalog.util.impl.ResultIterable) CancellationException(java.util.concurrent.CancellationException) ResourceNotFoundException(ddf.catalog.resource.ResourceNotFoundException) MimeTypeParseException(javax.activation.MimeTypeParseException) ParseException(org.locationtech.jts.io.ParseException) IngestException(ddf.catalog.source.IngestException) IOException(java.io.IOException) FederationException(ddf.catalog.federation.FederationException) ExecutionException(java.util.concurrent.ExecutionException) UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) CatalogQueryException(ddf.catalog.util.impl.CatalogQueryException) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) CswException(org.codice.ddf.spatial.ogc.csw.catalog.common.CswException) JAXBException(javax.xml.bind.JAXBException) SAXException(org.xml.sax.SAXException) SourceUnavailableException(ddf.catalog.source.SourceUnavailableException) ResourceNotSupportedException(ddf.catalog.resource.ResourceNotSupportedException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) AtomicLong(java.util.concurrent.atomic.AtomicLong) QueryResponseImpl(ddf.catalog.operation.impl.QueryResponseImpl) QueryFunction(ddf.catalog.util.impl.QueryFunction) QueryResponse(ddf.catalog.operation.QueryResponse) CswRecordCollection(org.codice.ddf.spatial.ogc.csw.catalog.common.CswRecordCollection) CatalogQueryException(ddf.catalog.util.impl.CatalogQueryException) QueryType(net.opengis.cat.csw.v_2_0_2.QueryType) StringWriter(java.io.StringWriter) Writer(java.io.Writer)

Example 25 with ObjectFactory

use of org.apache.type_test.types3.ObjectFactory in project ddf by codice.

the class AbstractCswSource method createQuery.

private JAXBElement<QueryType> createQuery(QueryRequest queryRequest, ElementSetType elementSetType, List<QName> elementNames) throws UnsupportedQueryException {
    QueryType queryType = new QueryType();
    QName queryTypeQName = null;
    try {
        if (StringUtils.isNotBlank(cswSourceConfiguration.getQueryTypeName())) {
            String[] parts = cswSourceConfiguration.getQueryTypeName().split(":");
            if (parts.length > 1) {
                queryTypeQName = new QName(cswSourceConfiguration.getQueryTypeNamespace(), parts[1], parts[0]);
            } else {
                queryTypeQName = new QName(cswSourceConfiguration.getQueryTypeNamespace(), cswSourceConfiguration.getQueryTypeName());
            }
        }
    } catch (IllegalArgumentException e) {
        LOGGER.debug("Unable to parse query type QName of {}.  Defaulting to CSW Record", cswSourceConfiguration.getQueryTypeName());
    }
    if (queryTypeQName == null) {
        queryTypeQName = new QName(CswConstants.CSW_OUTPUT_SCHEMA, CswConstants.CSW_RECORD_LOCAL_NAME, CswConstants.CSW_NAMESPACE_PREFIX);
    }
    QueryRequest transformedQueryRequest = cswQueryFilterTransformerProvider != null ? cswQueryFilterTransformerProvider.getTransformer(cswSourceConfiguration.getQueryTypeName()).map(it -> it.transform(queryRequest, null)).orElse(queryRequest) : queryRequest;
    queryType.setTypeNames(Arrays.asList(queryTypeQName));
    if (null != elementSetType) {
        queryType.setElementSetName(createElementSetName(elementSetType));
    } else if (!CollectionUtils.isEmpty(elementNames)) {
        queryType.setElementName(elementNames);
    } else {
        queryType.setElementSetName(createElementSetName(ElementSetType.FULL));
    }
    SortByType sortBy = createSortBy(transformedQueryRequest);
    if (sortBy != null) {
        queryType.setSortBy(sortBy);
    }
    QueryConstraintType constraint = createQueryConstraint(transformedQueryRequest);
    if (null != constraint) {
        queryType.setConstraint(constraint);
    }
    ObjectFactory objectFactory = new ObjectFactory();
    return objectFactory.createQuery(queryType);
}
Also used : QueryRequest(ddf.catalog.operation.QueryRequest) ObjectFactory(net.opengis.cat.csw.v_2_0_2.ObjectFactory) QName(javax.xml.namespace.QName) SortByType(net.opengis.filter.v_1_1_0.SortByType) QueryType(net.opengis.cat.csw.v_2_0_2.QueryType) QueryConstraintType(net.opengis.cat.csw.v_2_0_2.QueryConstraintType)

Aggregations

Test (org.junit.Test)23 JAXBElement (javax.xml.bind.JAXBElement)22 ObjectFactory (net.opengis.cat.csw.v_2_0_2.ObjectFactory)20 QueryType (net.opengis.cat.csw.v_2_0_2.QueryType)18 GetRecordsType (net.opengis.cat.csw.v_2_0_2.GetRecordsType)17 QName (javax.xml.namespace.QName)13 CswRecordCollection (org.codice.ddf.spatial.ogc.csw.catalog.common.CswRecordCollection)13 XStream (com.thoughtworks.xstream.XStream)12 ByteArrayInputStream (java.io.ByteArrayInputStream)12 GetRecordsResponseType (net.opengis.cat.csw.v_2_0_2.GetRecordsResponseType)12 SearchResultsType (net.opengis.cat.csw.v_2_0_2.SearchResultsType)12 ArrayList (java.util.ArrayList)11 Marshaller (javax.xml.bind.Marshaller)11 ElementSetNameType (net.opengis.cat.csw.v_2_0_2.ElementSetNameType)11 MarshallingContext (com.thoughtworks.xstream.converters.MarshallingContext)10 HierarchicalStreamWriter (com.thoughtworks.xstream.io.HierarchicalStreamWriter)10 StringWriter (java.io.StringWriter)10 BigInteger (java.math.BigInteger)10 JAXBContext (javax.xml.bind.JAXBContext)10 ObjectFactory (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectFactory)8