agave-notifications/notifications-core/src/main/java/org/iplantc/service/notification/model/NotificationAttemptCodec.java
/**
     * Decodes a BSON value from the given reader into an instance of the type parameter {@code T}.
     *
     * @param reader         the BSON reader
     * @param decoderContext the decoder context
     * @return an instance of the type parameter {@code T}.
     */
Decodes a BSON value from the given reader into an instance of the type parameter  T.
@param reader         the BSON reader
@param decoderContext the decoder context
@return an instance of the type parameter  T.
Decodes a BSON value from the given reader into an instance of the type parameter T . @param reader the BSON reader @param decoderContext the decoder context @return an instance of the type parameter T .
@Override
    public NotificationAttempt decode(BsonReader reader, DecoderContext decoderContext) {
        NotificationAttempt notificationAttempt = new NotificationAttempt();
        Document document = documentCodec.decode(reader, decoderContext);
        try {
            Date created = document.getDate("created");
            if (created != null)
                notificationAttempt.setCreated(created.toInstant());
        } catch (Exception e) {
            e.printStackTrace();
        }
        try {
            Date instant = document.getDate("startedTime");
            if (instant != null)
                notificationAttempt.setStartTime(instant.toInstant());
        } catch (Exception e) {
            e.printStackTrace();
        }
        try {
            Date instant = document.getDate("endedTime");
            if (instant != null)
                notificationAttempt.setEndTime(instant.toInstant());
        } catch (Exception e) {
            e.printStackTrace();
        }
        try {
            Date instant = document.getDate("scheduledTime");
            if (instant != null)
                notificationAttempt.setScheduledTime(instant.toInstant());
        } catch (Exception e) {
            e.printStackTrace();
        }
        String associatedUuid = document.getString("associatedUuid");
        notificationAttempt.setAssociatedUuid(associatedUuid);
        int attemptNumber = document.getInteger("attemptNumber");
        notificationAttempt.setAttemptNumber(attemptNumber);
        String content = document.getString("content");
        if (StringUtils.isNotEmpty(content))
            notificationAttempt.setContent(content);
        String event = document.getString("event");
        if (StringUtils.isNotEmpty(event))
            notificationAttempt.setEventName(event);
        String uuid = document.getString("id");
        if (StringUtils.isNotEmpty(uuid))
            notificationAttempt.setUuid(uuid);
        String notificationId = document.getString("notificationId");
        if (StringUtils.isNotEmpty(notificationId))
            notificationAttempt.setNotificationId(notificationId);
        String owner = document.getString("owner");
        if (StringUtils.isNotEmpty(owner)) {
            notificationAttempt.setOwner(owner);
        }
        String tenantId = document.getString("tenantId");
        if (StringUtils.isNotEmpty(tenantId)) {
            notificationAttempt.setTenantId(tenantId);
        }
        String callbackUrl = document.getString("url");
        if (StringUtils.isNotEmpty(callbackUrl)) {
            notificationAttempt.setCallbackUrl(callbackUrl);
        }
        Document documentResponse = document.get("response", Document.class);
        if (documentResponse != null) {
            NotificationAttemptResponse response = new NotificationAttemptResponse();
            String message = documentResponse.getString("message");
            response.setMessage(message);
            int code = documentResponse.getInteger("code");
            response.setCode(code);
            notificationAttempt.setResponse(response);
        }
        return notificationAttempt;
    }
@ Override public NotificationAttempt decode ( BsonReader reader , DecoderContext decoderContext ) { NotificationAttempt notificationAttempt = new NotificationAttempt ( ) ; Document document = documentCodec . decode ( reader , decoderContext ) ; try { Date created = document . getDate ( "created" ) ; if ( created != null ) notificationAttempt . setCreated ( created . toInstant ( ) ) ; } catch ( Exception e ) { e . printStackTrace ( ) ; } try { Date instant = document . getDate ( "startedTime" ) ; if ( instant != null ) notificationAttempt . setStartTime ( instant . toInstant ( ) ) ; } catch ( Exception e ) { e . printStackTrace ( ) ; } try { Date instant = document . getDate ( "endedTime" ) ; if ( instant != null ) notificationAttempt . setEndTime ( instant . toInstant ( ) ) ; } catch ( Exception e ) { e . printStackTrace ( ) ; } try { Date instant = document . getDate ( "scheduledTime" ) ; if ( instant != null ) notificationAttempt . setScheduledTime ( instant . toInstant ( ) ) ; } catch ( Exception e ) { e . printStackTrace ( ) ; } String associatedUuid = document . getString ( "associatedUuid" ) ; notificationAttempt . setAssociatedUuid ( associatedUuid ) ; int attemptNumber = document . getInteger ( "attemptNumber" ) ; notificationAttempt . setAttemptNumber ( attemptNumber ) ; String content = document . getString ( "content" ) ; if ( StringUtils . isNotEmpty ( content ) ) notificationAttempt . setContent ( content ) ; String event = document . getString ( "event" ) ; if ( StringUtils . isNotEmpty ( event ) ) notificationAttempt . setEventName ( event ) ; String uuid = document . getString ( "id" ) ; if ( StringUtils . isNotEmpty ( uuid ) ) notificationAttempt . setUuid ( uuid ) ; String notificationId = document . getString ( "notificationId" ) ; if ( StringUtils . isNotEmpty ( notificationId ) ) notificationAttempt . setNotificationId ( notificationId ) ; String owner = document . getString ( "owner" ) ; if ( StringUtils . isNotEmpty ( owner ) ) { notificationAttempt . setOwner ( owner ) ; } String tenantId = document . getString ( "tenantId" ) ; if ( StringUtils . isNotEmpty ( tenantId ) ) { notificationAttempt . setTenantId ( tenantId ) ; } String callbackUrl = document . getString ( "url" ) ; if ( StringUtils . isNotEmpty ( callbackUrl ) ) { notificationAttempt . setCallbackUrl ( callbackUrl ) ; } Document documentResponse = document . get ( "response" , Document . class ) ; if ( documentResponse != null ) { NotificationAttemptResponse response = new NotificationAttemptResponse ( ) ; String message = documentResponse . getString ( "message" ) ; response . setMessage ( message ) ; int code = documentResponse . getInteger ( "code" ) ; response . setCode ( code ) ; notificationAttempt . setResponse ( response ) ; } return notificationAttempt ; }
Decodes a BSON value from the given reader into an instance of the type parameter {@code T}.
Decodes a BSON value from the given reader into an instance of the type parameter { @code T } .