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());
}
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());
}
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];
}
}
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));
}
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));
}
Aggregations