Search in sources :

Example 1 with Time

use of org.codice.alliance.nsili.common.UCO.Time 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 Time

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

the class SampleNsiliClient method createFileOrder.

private OrderContents createFileOrder(Product product, String[] supportedPackagingSpecs, String filename) throws Exception {
    NameName[] nameName = { new NameName("", "") };
    String orderPackageId = UUID.randomUUID().toString();
    TailoringSpec tailoringSpec = new TailoringSpec(nameName);
    PackagingSpec pSpec = new PackagingSpec(orderPackageId, supportedPackagingSpecs[0]);
    Calendar cal = Calendar.getInstance();
    cal.setTime(new java.util.Date());
    int year = cal.get(Calendar.YEAR);
    year++;
    AbsTime needByDate = new AbsTime(new Date((short) year, (short) 2, (short) 10), new Time((short) 10, (short) 0, (short) 0));
    MediaType[] mTypes = { new MediaType("", (short) 1) };
    String[] benums = new String[0];
    Rectangle region = new Rectangle(new Coordinate2d(1.1, 1.1), new Coordinate2d(2.2, 2.2));
    ImageSpec imageSpec = new ImageSpec();
    imageSpec.encoding = SupportDataEncoding.ASCII;
    imageSpec.rrds = new short[] { 1 };
    imageSpec.algo = "";
    imageSpec.bpp = 0;
    imageSpec.comp = "A";
    imageSpec.imgform = "A";
    imageSpec.imageid = "1234abc";
    imageSpec.geo_region_type = GeoRegionType.LAT_LON;
    Rectangle subSection = new Rectangle();
    subSection.lower_right = new Coordinate2d(0, 0);
    subSection.upper_left = new Coordinate2d(1, 1);
    imageSpec.sub_section = subSection;
    Any imageSpecAny = orb.create_any();
    ImageSpecHelper.insert(imageSpecAny, imageSpec);
    AlterationSpec aSpec = new AlterationSpec("JPEG", imageSpecAny, region, GeoRegionType.NULL_REGION);
    FileLocation fileLocation = new FileLocation("user", "pass", "localhost", "/nsili/file", filename);
    Destination destination = new Destination();
    destination.f_dest(fileLocation);
    ProductDetails[] productDetails = { new ProductDetails(mTypes, benums, aSpec, product, ALLIANCE) };
    DeliveryDetails[] deliveryDetails = { new DeliveryDetails(destination, "", "") };
    return new OrderContents(ALLIANCE, tailoringSpec, pSpec, needByDate, "Give me an order!", (short) 1, productDetails, deliveryDetails);
}
Also used : Destination(org.codice.alliance.nsili.common.GIAS.Destination) DeliveryDetails(org.codice.alliance.nsili.common.GIAS.DeliveryDetails) Rectangle(org.codice.alliance.nsili.common.UCO.Rectangle) Time(org.codice.alliance.nsili.common.UCO.Time) AbsTime(org.codice.alliance.nsili.common.UCO.AbsTime) ImageSpec(org.codice.alliance.nsili.common.GIAS.ImageSpec) Any(org.omg.CORBA.Any) AlterationSpec(org.codice.alliance.nsili.common.GIAS.AlterationSpec) AbsTime(org.codice.alliance.nsili.common.UCO.AbsTime) Coordinate2d(org.codice.alliance.nsili.common.UCO.Coordinate2d) ProductDetails(org.codice.alliance.nsili.common.GIAS.ProductDetails) MediaType(org.codice.alliance.nsili.common.GIAS.MediaType) NameName(org.codice.alliance.nsili.common.UCO.NameName) PackagingSpec(org.codice.alliance.nsili.common.GIAS.PackagingSpec) Calendar(java.util.Calendar) Date(org.codice.alliance.nsili.common.UCO.Date) TailoringSpec(org.codice.alliance.nsili.common.GIAS.TailoringSpec) OrderContents(org.codice.alliance.nsili.common.GIAS.OrderContents) FileLocation(org.codice.alliance.nsili.common.UCO.FileLocation)

Example 3 with Time

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

the class SubmitStandingQueryRequestImpl method getDate.

public static Date getDate(LifeEvent lifeEvent) {
    Date date = null;
    if (lifeEvent != null) {
        if (lifeEvent.discriminator() == LifeEventType.ABSOLUTE_TIME) {
            date = convertAbsTime(lifeEvent.at());
        } else if (lifeEvent.discriminator() == LifeEventType.DAY_EVENT_TIME) {
            date = convertDayEventTime(lifeEvent.day_event());
        } else if (lifeEvent.discriminator() == LifeEventType.RELATIVE_TIME) {
            long now = System.currentTimeMillis();
            Time relTime = lifeEvent.rt();
            long offsetMsec = convertTimeToMillis(relTime);
            long time = now + offsetMsec;
            date = new Date(time);
        } else if (lifeEvent.discriminator() == LifeEventType.NAMED_EVENT) {
            LOGGER.debug("NAMED_EVENT not a supported LifeEvent type");
        }
    }
    return date;
}
Also used : Time(org.codice.alliance.nsili.common.UCO.Time) AbsTime(org.codice.alliance.nsili.common.UCO.AbsTime) LocalDateTime(java.time.LocalDateTime) DayEventTime(org.codice.alliance.nsili.common.GIAS.DayEventTime) DateTime(org.joda.time.DateTime) Date(java.util.Date)

Example 4 with Time

use of org.codice.alliance.nsili.common.UCO.Time 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 5 with Time

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

the class SubmitStandingQueryRequestImplTest method convertTimeToMillis.

@Test
public void convertTimeToMillis() {
    Time ucoTime = new Time((short) 01, (short) 01, (short) 01);
    long millis = SubmitStandingQueryRequestImpl.convertTimeToMillis(ucoTime);
    long checkMillis = (60 * 60 * 1000) + (60 * 1000) + 1000;
    assertThat(millis, is(checkMillis));
}
Also used : Time(org.codice.alliance.nsili.common.UCO.Time) AbsTime(org.codice.alliance.nsili.common.UCO.AbsTime) DayEventTime(org.codice.alliance.nsili.common.GIAS.DayEventTime) Test(org.junit.Test)

Aggregations

AbsTime (org.codice.alliance.nsili.common.UCO.AbsTime)11 Time (org.codice.alliance.nsili.common.UCO.Time)11 DayEventTime (org.codice.alliance.nsili.common.GIAS.DayEventTime)6 Test (org.junit.Test)5 Date (java.util.Date)4 Date (org.codice.alliance.nsili.common.UCO.Date)4 Calendar (java.util.Calendar)3 LifeEvent (org.codice.alliance.nsili.common.GIAS.LifeEvent)3 LocalDateTime (java.time.LocalDateTime)2 AlterationSpec (org.codice.alliance.nsili.common.GIAS.AlterationSpec)2 DeliveryDetails (org.codice.alliance.nsili.common.GIAS.DeliveryDetails)2 Destination (org.codice.alliance.nsili.common.GIAS.Destination)2 ImageSpec (org.codice.alliance.nsili.common.GIAS.ImageSpec)2 MediaType (org.codice.alliance.nsili.common.GIAS.MediaType)2 OrderContents (org.codice.alliance.nsili.common.GIAS.OrderContents)2 PackagingSpec (org.codice.alliance.nsili.common.GIAS.PackagingSpec)2 ProductDetails (org.codice.alliance.nsili.common.GIAS.ProductDetails)2 QueryLifeSpan (org.codice.alliance.nsili.common.GIAS.QueryLifeSpan)2 TailoringSpec (org.codice.alliance.nsili.common.GIAS.TailoringSpec)2 Coordinate2d (org.codice.alliance.nsili.common.UCO.Coordinate2d)2