Search in sources :

Example 1 with NameValue

use of org.codice.alliance.nsili.common.UCO.NameValue in project alliance by codice.

the class SampleNsiliClient method testStandingQueryMgr.

public void testStandingQueryMgr() throws Exception {
    if (standingQueryMgr != null) {
        LOGGER.info("----------------------");
        LOGGER.info("Standing Query Manager Test");
        Event[] events = standingQueryMgr.get_event_descriptions();
        if (events != null) {
            Arrays.stream(events).forEach(event -> LOGGER.info("Event: {}\n Name: {}\n Desc: {}", event.event_type.value(), event.event_name, event.event_description));
        }
        LifeEvent start = new LifeEvent();
        java.util.Date startDate = new java.util.Date();
        start.at(ResultDAGConverter.getAbsTime(startDate));
        LifeEvent end = new LifeEvent();
        final long ONE_YEAR_IN_MS = TimeUnit.DAYS.toMillis(365);
        long endTime = System.currentTimeMillis() + ONE_YEAR_IN_MS;
        java.util.Date endDate = new java.util.Date();
        endDate.setTime(endTime);
        end.at(ResultDAGConverter.getAbsTime(endDate));
        LifeEvent[] frequency = new LifeEvent[1];
        LifeEvent freqOne = new LifeEvent();
        Time time = new Time((short) 0, (short) 0, 30.0f);
        freqOne.rt(time);
        frequency[0] = freqOne;
        QueryLifeSpan queryLifeSpan = new QueryLifeSpan(start, end, frequency);
        NameValue[] props = new NameValue[0];
        String callbackId = UUID.randomUUID().toString();
        try {
            standingQueryRequest = standingQueryMgr.submit_standing_query(STANDING_ALL_QUERY, getResultAttributes(), getSortableAttributes(), queryLifeSpan, props);
            standingQueryRequest.set_user_info(ALLIANCE);
            standingQueryRequest.set_number_of_hits(200);
            TestNsiliStandingQueryCallback nsiliCallback = new TestNsiliStandingQueryCallback(standingQueryRequest);
            final String ENCODING = "ISO-8859-1";
            try {
                poa.activate_object_with_id(callbackId.getBytes(Charset.forName(ENCODING)), nsiliCallback);
            } catch (ServantAlreadyActive | ObjectAlreadyActive | WrongPolicy e) {
                LOGGER.error("Order : Unable to activate callback object, already active : {}", NsilCorbaExceptionUtil.getExceptionDetails(e), e);
            }
            org.omg.CORBA.Object obj = poa.create_reference_with_id(callbackId.getBytes(Charset.forName(ENCODING)), CallbackHelper.id());
            Callback callback = CallbackHelper.narrow(obj);
            String standingQueryCallbackId = standingQueryRequest.register_callback(callback);
            nsiliCallback.setCallbackID(standingQueryCallbackId);
            standingQueryCallbacks.add(nsiliCallback);
            LOGGER.info("Registered NSILI Callback: {}", standingQueryCallbackId);
            LOGGER.info("Standing Query Submitted");
        } catch (Exception e) {
            LOGGER.debug("Error submitting standing query: ", NsilCorbaExceptionUtil.getExceptionDetails(e));
            throw (e);
        }
    } else {
        LOGGER.info("StandingQueryMgr is not initialized, unable to test");
    }
}
Also used : ObjectAlreadyActive(org.omg.PortableServer.POAPackage.ObjectAlreadyActive) Time(org.codice.alliance.nsili.common.UCO.Time) AbsTime(org.codice.alliance.nsili.common.UCO.AbsTime) Date(org.codice.alliance.nsili.common.UCO.Date) KeyManagementException(java.security.KeyManagementException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) MalformedURLException(java.net.MalformedURLException) CertificateException(java.security.cert.CertificateException) NameValue(org.codice.alliance.nsili.common.UCO.NameValue) WrongPolicy(org.omg.PortableServer.POAPackage.WrongPolicy) Callback(org.codice.alliance.nsili.common.CB.Callback) QueryLifeSpan(org.codice.alliance.nsili.common.GIAS.QueryLifeSpan) Event(org.codice.alliance.nsili.common.GIAS.Event) LifeEvent(org.codice.alliance.nsili.common.GIAS.LifeEvent) LifeEvent(org.codice.alliance.nsili.common.GIAS.LifeEvent) ServantAlreadyActive(org.omg.PortableServer.POAPackage.ServantAlreadyActive)

Example 2 with NameValue

use of org.codice.alliance.nsili.common.UCO.NameValue in project alliance by codice.

the class SampleNsiliClient method logDescription.

private void logDescription(RequestDescription description) {
    if (description == null) {
        LOGGER.warn("Notified with no details");
        return;
    }
    LOGGER.info("\t user_info: {}", description.user_info);
    LOGGER.info("\t type: {}", description.request_type);
    LOGGER.info("\t request_info: {}", description.request_info);
    if (description.request_details != null && description.request_details.length > 0) {
        LOGGER.info("\t details: {}", description.request_details.length);
        for (NameValue nameValue : description.request_details) {
            logDetails(nameValue);
        }
    }
}
Also used : NameValue(org.codice.alliance.nsili.common.UCO.NameValue)

Example 3 with NameValue

use of org.codice.alliance.nsili.common.UCO.NameValue in project alliance by codice.

the class NsiliSource method submitQuery.

/**
 * Submits and completes a BQS Query to the STANAG 4559 server and returns the response.
 *
 * @param queryRequest - the query request generated from the search
 * @param query - a BQS query
 * @param resultAttributes - a list of desired result attributes
 * @param sortAttributes - a list of attributes to sort by
 * @param properties - a list of properties for the query
 * @return - the server's response
 */
private SourceResponse submitQuery(QueryRequest queryRequest, org.codice.alliance.nsili.common.GIAS.Query query, String[] resultAttributes, SortAttribute[] sortAttributes, NameValue[] properties) {
    DAGListHolder dagListHolder = new DAGListHolder();
    SourceResponseImpl sourceResponse = null;
    long numHits = 0;
    try {
        synchronized (queryLockObj) {
            LOGGER.debug("{} : Submit query: {}", sourceId, query.bqs_query);
            LOGGER.debug("{} : Requesting result attributes: {}", sourceId, resultAttributes);
            LOGGER.debug("{} : Sort Attributes: {}", sourceId, sortAttributes);
            LOGGER.debug("{} : Properties: {}", sourceId, properties);
            HitCountRequest hitCountRequest = catalogMgr.hit_count(query, properties);
            IntHolder hitHolder = new IntHolder();
            hitCountRequest.complete(hitHolder);
            numHits = hitHolder.value;
            SubmitQueryRequest submitQueryRequest;
            if (hitHolder.value > 1) {
                submitQueryRequest = catalogMgr.submit_query(query, resultAttributes, sortAttributes, properties);
            } else {
                submitQueryRequest = catalogMgr.submit_query(query, resultAttributes, new SortAttribute[0], new NameValue[0]);
            }
            submitQueryRequest.set_user_info(ddfOrgName);
            submitQueryRequest.set_number_of_hits(maxHitCount);
            submitQueryRequest.complete_DAG_results(dagListHolder);
        }
    } catch (ProcessingFault | SystemFault | InvalidInputParameter e) {
        LOGGER.debug("{} : Unable to query source. {}", sourceId, NsilCorbaExceptionUtil.getExceptionDetails(e), e);
    }
    if (dagListHolder.value != null) {
        List<Result> results = new ArrayList<>();
        String id = getId();
        List<Future> futures = new ArrayList<>(dagListHolder.value.length);
        for (DAG dag : dagListHolder.value) {
            Callable<Result> convertRunner = () -> {
                DAGConverter dagConverter = new DAGConverter(resourceReader);
                dagConverter.setNsiliMetacardType(nsiliMetacardType);
                Metacard card = dagConverter.convertDAG(dag, swapCoordinates, id);
                if (card != null) {
                    if (LOGGER.isTraceEnabled()) {
                        DAGConverter.logMetacard(card, getId());
                    }
                    return new ResultImpl(card);
                } else {
                    LOGGER.debug("{} : Unable to convert DAG to metacard, returned card is null", getId());
                }
                return null;
            };
            futures.add(completionService.submit(convertRunner));
        }
        Future<Result> completedFuture;
        while (!futures.isEmpty()) {
            try {
                completedFuture = completionService.take();
                futures.remove(completedFuture);
                results.add(completedFuture.get());
            } catch (ExecutionException e) {
                LOGGER.debug("Unable to create result.", e);
            } catch (InterruptedException ignore) {
            // ignore
            }
        }
        sourceResponse = new SourceResponseImpl(queryRequest, results, numHits);
    } else {
        LOGGER.debug("{} : Source returned empty DAG list", getId());
    }
    return sourceResponse;
}
Also used : SourceResponseImpl(ddf.catalog.operation.impl.SourceResponseImpl) ArrayList(java.util.ArrayList) ResultImpl(ddf.catalog.data.impl.ResultImpl) ProcessingFault(org.codice.alliance.nsili.common.UCO.ProcessingFault) Result(ddf.catalog.data.Result) SubmitQueryRequest(org.codice.alliance.nsili.common.GIAS.SubmitQueryRequest) SystemFault(org.codice.alliance.nsili.common.UCO.SystemFault) IntHolder(org.omg.CORBA.IntHolder) InvalidInputParameter(org.codice.alliance.nsili.common.UCO.InvalidInputParameter) ExecutionException(java.util.concurrent.ExecutionException) SortAttribute(org.codice.alliance.nsili.common.GIAS.SortAttribute) DAG(org.codice.alliance.nsili.common.UCO.DAG) DAGListHolder(org.codice.alliance.nsili.common.UCO.DAGListHolder) HitCountRequest(org.codice.alliance.nsili.common.GIAS.HitCountRequest) DAGConverter(org.codice.alliance.nsili.transformer.DAGConverter) NameValue(org.codice.alliance.nsili.common.UCO.NameValue) Metacard(ddf.catalog.data.Metacard) ScheduledFuture(java.util.concurrent.ScheduledFuture) Future(java.util.concurrent.Future)

Example 4 with NameValue

use of org.codice.alliance.nsili.common.UCO.NameValue in project alliance by codice.

the class OrderMgrImplTest method testOrder.

@Test
public void testOrder() throws Exception {
    NameValue protocolProp = new NameValue();
    protocolProp.aname = "PROTOCOL";
    Any protoValueAny = orb.create_any();
    protoValueAny.insert_string("https");
    protocolProp.value = protoValueAny;
    NameValue portProp = new NameValue();
    portProp.aname = "PORT";
    Any portValueAny = orb.create_any();
    portValueAny.insert_long(8993);
    portProp.value = portValueAny;
    NameValue[] properties = new NameValue[] { protocolProp, portProp };
    orderMgr.order(null, properties);
}
Also used : NameValue(org.codice.alliance.nsili.common.UCO.NameValue) Any(org.omg.CORBA.Any) Test(org.junit.Test)

Example 5 with NameValue

use of org.codice.alliance.nsili.common.UCO.NameValue in project alliance by codice.

the class ProductMgrImplTest method testGetRelatedFilesWithBadPort.

@Test
public void testGetRelatedFilesWithBadPort() throws Exception {
    MetacardImpl testMetacard = new MetacardImpl();
    testMetacard.setId(testMetacardId);
    testMetacard.setTitle("JUnit Test Card");
    Result testResult = new ResultImpl(testMetacard);
    DAG dag = ResultDAGConverter.convertResult(testResult, orb, rootPOA, new ArrayList<>(), new HashMap<>());
    Product product = ProductHelper.extract(dag.nodes[0].value);
    Product[] products = new Product[] { product };
    String userName = "";
    String password = "";
    String hostName = "localhost";
    String pathName = "/nsili/file";
    FileLocation location = new FileLocation(userName, password, hostName, pathName, null);
    NameValue[] props = new NameValue[1];
    Any portAny = orb.create_any();
    portAny.insert_string("NOPE");
    NameValue prop = new NameValue("PORT", portAny);
    props[0] = prop;
    GetRelatedFilesRequest request = productMgr.get_related_files(products, location, NsiliConstants.THUMBNAIL_TYPE, props);
    assertThat(request, notNullValue());
}
Also used : Product(org.codice.alliance.nsili.common.UID.Product) ResultImpl(ddf.catalog.data.impl.ResultImpl) DAG(org.codice.alliance.nsili.common.UCO.DAG) Any(org.omg.CORBA.Any) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Result(ddf.catalog.data.Result) NameValue(org.codice.alliance.nsili.common.UCO.NameValue) FileLocation(org.codice.alliance.nsili.common.UCO.FileLocation) GetRelatedFilesRequest(org.codice.alliance.nsili.common.GIAS.GetRelatedFilesRequest) Test(org.junit.Test)

Aggregations

NameValue (org.codice.alliance.nsili.common.UCO.NameValue)13 Any (org.omg.CORBA.Any)6 DAG (org.codice.alliance.nsili.common.UCO.DAG)5 Result (ddf.catalog.data.Result)4 ResultImpl (ddf.catalog.data.impl.ResultImpl)4 GetRelatedFilesRequest (org.codice.alliance.nsili.common.GIAS.GetRelatedFilesRequest)4 FileLocation (org.codice.alliance.nsili.common.UCO.FileLocation)4 Product (org.codice.alliance.nsili.common.UID.Product)4 Test (org.junit.Test)4 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)3 IOException (java.io.IOException)2 MalformedURLException (java.net.MalformedURLException)2 URISyntaxException (java.net.URISyntaxException)2 KeyManagementException (java.security.KeyManagementException)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 CertificateException (java.security.cert.CertificateException)2 OrderRequest (org.codice.alliance.nsili.common.GIAS.OrderRequest)2 QueryLifeSpan (org.codice.alliance.nsili.common.GIAS.QueryLifeSpan)2 SortAttribute (org.codice.alliance.nsili.common.GIAS.SortAttribute)2 ObjectAlreadyActive (org.omg.PortableServer.POAPackage.ObjectAlreadyActive)2