Search in sources :

Example 6 with SortAttribute

use of org.codice.alliance.nsili.common.GIAS.SortAttribute in project alliance by codice.

the class StandingQueryMgrImplTest method testSubmitStandingQuery.

@Test
public void testSubmitStandingQuery() throws InvalidInputParameter, SystemFault, ProcessingFault {
    String[] resultAttributes = new String[0];
    SortAttribute[] sortAttributes = new SortAttribute[0];
    LifeEvent start = new LifeEvent();
    start.at(LifeEventType.ABSOLUTE_TIME, new AbsTime(new Date((short) 2016, (short) 05, (short) 01), new Time((short) 00, (short) 00, (short) 00)));
    LifeEvent stop = new LifeEvent();
    stop.at(LifeEventType.ABSOLUTE_TIME, new AbsTime(new Date((short) 2050, (short) 05, (short) 01), new Time((short) 00, (short) 00, (short) 00)));
    LifeEvent frequency1 = new LifeEvent();
    frequency1.rt(LifeEventType.RELATIVE_TIME, new Time((short) 00, (short) 01, (short) 00));
    LifeEvent[] frequency = new LifeEvent[] { frequency1 };
    QueryLifeSpan lifeSpan = new QueryLifeSpan(start, stop, frequency);
    Query query = new Query(NsiliConstants.NSIL_ALL_VIEW, bqsQuery);
    SubmitStandingQueryRequest request = standingQueryMgr.submit_standing_query(query, resultAttributes, sortAttributes, lifeSpan, new NameValue[0]);
    assertThat(request, notNullValue());
}
Also used : SubmitStandingQueryRequest(org.codice.alliance.nsili.common.GIAS.SubmitStandingQueryRequest) AbsTime(org.codice.alliance.nsili.common.UCO.AbsTime) SortAttribute(org.codice.alliance.nsili.common.GIAS.SortAttribute) Query(org.codice.alliance.nsili.common.GIAS.Query) QueryLifeSpan(org.codice.alliance.nsili.common.GIAS.QueryLifeSpan) LifeEvent(org.codice.alliance.nsili.common.GIAS.LifeEvent) Time(org.codice.alliance.nsili.common.UCO.Time) AbsTime(org.codice.alliance.nsili.common.UCO.AbsTime) Date(org.codice.alliance.nsili.common.UCO.Date) Test(org.junit.Test)

Example 7 with SortAttribute

use of org.codice.alliance.nsili.common.GIAS.SortAttribute in project alliance by codice.

the class SubmitStandingQueryRequestImplTest method setupStandingQueryRequest.

private void setupStandingQueryRequest() throws InvalidInputParameter, SystemFault, ProcessingFault, WrongPolicy, ServantAlreadyActive, ObjectAlreadyActive {
    Query query = getQuery();
    String[] resultAttributes = new String[0];
    SortAttribute[] sortAttributes = new SortAttribute[0];
    QueryLifeSpan lifespan = getEmptyLifespan();
    NameValue[] properties = new NameValue[0];
    // Set artificially low for for test cases.
    long defaultUpdateFrequencyMsec = 2000;
    int maxPendingResults = 10000;
    long maxWaitToStartTimeMsecs = TimeUnit.MINUTES.toMillis(5);
    standingQueryRequest = new SubmitStandingQueryRequestImpl(query, resultAttributes, sortAttributes, lifespan, properties, mockFramework, filterBuilder, defaultUpdateFrequencyMsec, null, maxPendingResults, true, false, maxWaitToStartTimeMsecs);
    standingQueryRequest.register_callback(mockCallback2);
    String managerId = UUID.randomUUID().toString();
    rootPOA.activate_object_with_id(managerId.getBytes(Charset.forName(NsiliEndpoint.ENCODING)), standingQueryRequest);
    rootPOA.create_reference_with_id(managerId.getBytes(Charset.forName(NsiliEndpoint.ENCODING)), CreationMgrHelper.id());
}
Also used : NameValue(org.codice.alliance.nsili.common.UCO.NameValue) Query(org.codice.alliance.nsili.common.GIAS.Query) SortAttribute(org.codice.alliance.nsili.common.GIAS.SortAttribute) QueryLifeSpan(org.codice.alliance.nsili.common.GIAS.QueryLifeSpan) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) SubmitStandingQueryRequestImpl(org.codice.alliance.nsili.endpoint.requests.SubmitStandingQueryRequestImpl)

Example 8 with SortAttribute

use of org.codice.alliance.nsili.common.GIAS.SortAttribute in project alliance by codice.

the class NsiliSource method getSortAttributes.

/**
 * Sets a SortAttribute[] to be used in a query. The STANAG 4559 Spec has no mechanism to sort
 * queries by RELEVANCE or Shortest/Longest distance from a point, so they are ignored.
 *
 * @param sortBy - sortBy object specified in the Search UI
 * @return - an array of SortAttributes sent in the query to the source.
 */
private SortAttribute[] getSortAttributes(SortBy sortBy) {
    if (excludeSortOrder) {
        return new SortAttribute[0];
    }
    if (sortBy == null || sortableAttributes == null) {
        // Default to sorting by Date/Time modified if no sorting provided
        return new SortAttribute[] { new SortAttribute(NsiliConstants.NSIL_CARD + "." + NsiliConstants.DATE_TIME_MODIFIED, Polarity.DESCENDING) };
    }
    String sortAttribute = sortBy.getPropertyName().getPropertyName();
    Polarity sortPolarity;
    if (sortBy.getSortOrder().toSQL().equals(ASC)) {
        sortPolarity = Polarity.ASCENDING;
    } else {
        sortPolarity = Polarity.DESCENDING;
    }
    String cardDateTimeModifiedAttribute = NsiliConstants.NSIL_CARD + "." + NsiliConstants.DATE_TIME_MODIFIED;
    String cardSourceDateTimeModified = NsiliConstants.NSIL_CARD + "." + NsiliConstants.SOURCE_DATE_TIME_MODIFIED;
    String dateTimeDeclaredAttribute = NsiliConstants.NSIL_FILE + "." + NsiliConstants.DATE_TIME_DECLARED;
    if (sortAttribute.equals(Metacard.MODIFIED)) {
        List<SortAttribute> modifiedAttrs = new ArrayList<>();
        if (isAttributeSupported(cardDateTimeModifiedAttribute)) {
            modifiedAttrs.add(new SortAttribute(cardDateTimeModifiedAttribute, sortPolarity));
        }
        if (isAttributeSupported(cardSourceDateTimeModified)) {
            modifiedAttrs.add(new SortAttribute(cardSourceDateTimeModified, sortPolarity));
        }
        return modifiedAttrs.toArray(new SortAttribute[0]);
    } else if (sortAttribute.equals(Metacard.CREATED) && isAttributeSupported(dateTimeDeclaredAttribute)) {
        SortAttribute[] sortAttributeArray = { new SortAttribute(dateTimeDeclaredAttribute, sortPolarity) };
        return sortAttributeArray;
    } else {
        return new SortAttribute[0];
    }
}
Also used : SortAttribute(org.codice.alliance.nsili.common.GIAS.SortAttribute) ArrayList(java.util.ArrayList) Polarity(org.codice.alliance.nsili.common.GIAS.Polarity)

Example 9 with SortAttribute

use of org.codice.alliance.nsili.common.GIAS.SortAttribute in project alliance by codice.

the class NsiliSourceTest method testQuerySortingNullSortBy.

@Test
public void testQuerySortingNullSortBy() throws Exception {
    QueryImpl propertyIsLikeQuery = new QueryImpl(builder.attribute(Metacard.CONTENT_TYPE).is().equalTo().text(GMTI));
    SortBy sortBy = null;
    propertyIsLikeQuery.setSortBy(sortBy);
    source.query(new QueryRequestImpl(propertyIsLikeQuery));
    ArgumentCaptor<SortAttribute[]> argumentCaptor = ArgumentCaptor.forClass(SortAttribute[].class);
    verify(catalogMgr).submit_query(any(Query.class), any(String[].class), argumentCaptor.capture(), any(NameValue[].class));
    // Sort attributes are always forced to be at least 1
    assertThat(argumentCaptor.getValue().length, is(1));
}
Also used : QueryImpl(ddf.catalog.operation.impl.QueryImpl) SortAttribute(org.codice.alliance.nsili.common.GIAS.SortAttribute) Query(org.codice.alliance.nsili.common.GIAS.Query) SortBy(org.opengis.filter.sort.SortBy) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) Test(org.junit.Test)

Example 10 with SortAttribute

use of org.codice.alliance.nsili.common.GIAS.SortAttribute in project alliance by codice.

the class NsiliSourceTest method testQuerySupportedDescendingSorting.

@Test
public void testQuerySupportedDescendingSorting() throws Exception {
    QueryImpl propertyIsLikeQuery = new QueryImpl(builder.attribute(Metacard.CONTENT_TYPE).is().equalTo().text(GMTI));
    SortBy sortBy = new SortByImpl(Metacard.MODIFIED, SortOrder.DESCENDING);
    propertyIsLikeQuery.setSortBy(sortBy);
    source.query(new QueryRequestImpl(propertyIsLikeQuery));
    ArgumentCaptor<SortAttribute[]> argumentCaptor = ArgumentCaptor.forClass(SortAttribute[].class);
    verify(catalogMgr).submit_query(any(Query.class), any(String[].class), argumentCaptor.capture(), any(NameValue[].class));
    String sortAttr = NsiliConstants.NSIL_CARD + "." + NsiliConstants.DATE_TIME_MODIFIED;
    assertThat(argumentCaptor.getValue()[0].attribute_name, is(sortAttr));
    assertThat(argumentCaptor.getValue()[0].sort_polarity, is(Polarity.DESCENDING));
}
Also used : QueryImpl(ddf.catalog.operation.impl.QueryImpl) SortAttribute(org.codice.alliance.nsili.common.GIAS.SortAttribute) Query(org.codice.alliance.nsili.common.GIAS.Query) SortByImpl(ddf.catalog.filter.impl.SortByImpl) SortBy(org.opengis.filter.sort.SortBy) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Aggregations

SortAttribute (org.codice.alliance.nsili.common.GIAS.SortAttribute)13 Query (org.codice.alliance.nsili.common.GIAS.Query)7 Test (org.junit.Test)7 QueryImpl (ddf.catalog.operation.impl.QueryImpl)5 QueryRequestImpl (ddf.catalog.operation.impl.QueryRequestImpl)5 SortBy (org.opengis.filter.sort.SortBy)5 SortByImpl (ddf.catalog.filter.impl.SortByImpl)4 SubmitQueryRequest (org.codice.alliance.nsili.common.GIAS.SubmitQueryRequest)4 ArrayList (java.util.ArrayList)3 DAGListHolder (org.codice.alliance.nsili.common.UCO.DAGListHolder)3 QueryLifeSpan (org.codice.alliance.nsili.common.GIAS.QueryLifeSpan)2 NameValue (org.codice.alliance.nsili.common.UCO.NameValue)2 Matchers.anyString (org.mockito.Matchers.anyString)2 Metacard (ddf.catalog.data.Metacard)1 Result (ddf.catalog.data.Result)1 ResultImpl (ddf.catalog.data.impl.ResultImpl)1 SourceResponseImpl (ddf.catalog.operation.impl.SourceResponseImpl)1 ExecutionException (java.util.concurrent.ExecutionException)1 Future (java.util.concurrent.Future)1 ScheduledFuture (java.util.concurrent.ScheduledFuture)1