Package org.fluxtream.core.connectors

Examples of org.fluxtream.core.connectors.ObjectType


                        break;
                    }
                }
            }
            if (apiKey != null){
                ObjectType objectType = null;
                for (ObjectType objType : apiKey.getConnector().objectTypes()){
                    if (objType.getName().equals(objectTypeName)){
                        objectType = objType;
                    }
                }
View Full Code Here


    private JSONArray getDeviceStatusesArray(final UpdateInfo updateInfo)
            throws RateLimitReachedException, UpdateFailedException, AuthExpiredException, UnexpectedResponseCodeException {
        String urlString = "https://api.fitbit.com/1/user/-/devices.json";

        final ObjectType customObjectType = ObjectType.getCustomObjectType(GET_USER_DEVICES_CALL);
        final int getUserDevicesObjectTypeID = customObjectType.value();
        String json = makeRestCall(updateInfo, getUserDevicesObjectTypeID,
                urlString);
        return JSONArray.fromObject(json);
    }
View Full Code Here

    @Override
    public List<TimespanModel> getTimespans(final long startMillis, final long endMillis, final ApiKey apiKey, final String channelName) {
        List<TimespanModel> items = new ArrayList<TimespanModel>();
        final TimeInterval timeInterval = new SimpleTimeInterval(startMillis, endMillis, TimeUnit.ARBITRARY, TimeZone.getTimeZone("UTC"));
        Connector connector = apiKey.getConnector();
        final ObjectType sleep = ObjectType.getObjectType(connector, "sleep");

        String objectTypeName = apiKey.getConnector().getName() + "-" + sleep.getName();
        List<AbstractFacet> facets = getFacetsInTimespanOrderedByEnd(timeInterval,apiKey, sleep);

        for (AbstractFacet facet : facets){
            FitbitSleepFacet sleepFacet = (FitbitSleepFacet)facet;
            simpleMergeAddTimespan(items,new TimespanModel(sleepFacet.start,sleepFacet.end, "on",objectTypeName),startMillis,endMillis);
View Full Code Here

                                                            final String value) {
        Connector connector = apiKey.getConnector();

        TimeInterval timeInterval = metadataService.getArbitraryTimespanMetadata(apiKey.getGuestId(), start, end).getTimeInterval();

        final ObjectType sleep = ObjectType.getObjectType(connector, "sleep");

        List<AbstractFacet> facets = getFacetsInTimespan(timeInterval, apiKey, sleep);

        return getFacetVOsForFacets(facets, timeInterval, guestSettings);
    }
View Full Code Here

  }

  void retrieveSmsEntriesSince(UpdateInfo updateInfo, BigInteger historyId) throws Exception {
    long then = System.currentTimeMillis();
    String query = "(incremental sms log retrieval)";
    ObjectType smsObjectType = ObjectType.getObjectType(connector(), "sms");
    String smsFolderName = getSettingsOrPortLegacySettings(updateInfo.apiKey).smsFolderName;
    try {
            Gmail gmail = getGmailService(updateInfo.apiKey);
            String email = getEmailAddress(updateInfo.apiKey);

            BigInteger originalHistoryId = historyId;

            Label smsLabel = null;

            for (Label label : gmail.users().labels().list(email).execute().getLabels()){
                if (label.getName().equals(smsFolderName)){
                    smsLabel = label;
                }
            }
            if (smsLabel == null)
                throw new FolderNotFoundException();

            //if we get to this point then we were able to access the folder and should delete our error notification
            Notification errorNotification = notificationsService.getNamedNotification(updateInfo.getGuestId(), connector().getName() + ".smsFolderError");
            if (errorNotification != null && !errorNotification.deleted){
                notificationsService.deleteNotification(updateInfo.getGuestId(),errorNotification.getId());
            }

            Properties props = new Properties();
            Session session = Session.getDefaultInstance(props, null);

            if (historyId != null){
                ListHistoryResponse historyResponse = null;
                BigInteger queryHistoryId = historyId;
                do{
                    historyResponse = invokeListHistory(gmail,email,queryHistoryId,smsLabel.getId(),historyResponse == null ? null : historyResponse.getNextPageToken());
                    if (historyResponse == null){
                        //if historyResponse is null that means we got a 404 error which means historyId is no longer valid
                        historyId = null;
                        break;
                    }
                    List<History> histories = historyResponse.getHistory();
                    for (History history : histories){
                        if (history.getMessages() == null)
                            continue;
                        for (Message messageStub : history.getMessages()){
                            Message message = invokeGetMessage(gmail, email, messageStub.getId());
                            if (message == null)
                                continue;
                            if (historyId.compareTo(message.getHistoryId()) < 0)
                                historyId = message.getHistoryId();
                            byte[] emailBytes = Base64.decodeBase64(message.getRaw());
                            MimeMessage mimeMessage = new MimeMessage(session, new ByteArrayInputStream(emailBytes));

                            if (flushEntry(updateInfo, email, mimeMessage, SmsEntryFacet.class) == null){
                                throw new Exception("Could not persist SMS");
                            }
                        }
                    }
                } while (historyResponse.getNextPageToken() != null);
            }
            if (historyId == null){
                ListMessagesResponse listResponse = null;
                do{
                    listResponse = invokeList(gmail,email,smsLabel.getId(),listResponse == null ? null : listResponse.getNextPageToken());
                    if (listResponse.getMessages() == null){
                        continue;
                    }
                    for (Message messageStub : listResponse.getMessages()){
                        Message message = invokeGetMessage(gmail, email, messageStub.getId());
                        if (message == null)
                            continue;
                        if (historyId == null || historyId.compareTo(message.getHistoryId()) < 0)
                            historyId = message.getHistoryId();
                        byte[] emailBytes = Base64.decodeBase64(message.getRaw());
                        MimeMessage mimeMessage = new MimeMessage(session, new ByteArrayInputStream(emailBytes));

                        if (flushEntry(updateInfo, email, mimeMessage, SmsEntryFacet.class) == null){
                            throw new Exception("Could not persist SMS");
                        }
                    }

                } while (listResponse.getNextPageToken() != null);
            }
            if (historyId != null && !historyId.equals(originalHistoryId)){
                updateHistoryId(updateInfo,smsObjectType,historyId);
            }

    } catch (MessagingException ex){
            notificationsService.addNamedNotification(updateInfo.getGuestId(),
                                                      Notification.Type.ERROR, connector().getName() + ".smsFolderError",
                                                      "The SMS folder configured for SMS Backup, \"" + smsFolderName + "\", does not exist. Either change it in your connector settings or check if SMS Backup is set to use this folder.");
            throw new UpdateFailedException("Couldn't open SMS folder.",true, null);
        }
        catch (Exception ex) {
            ex.printStackTrace();
      reportFailedApiCall(updateInfo.apiKey, smsObjectType.value(),
          then, query, Utils.stackTrace(ex), ex.getMessage());
      throw ex;
    }
  }
View Full Code Here

  }

  void retrieveCallLogSinceDate(UpdateInfo updateInfo, BigInteger historyId) throws Exception {
    long then = System.currentTimeMillis();
    String query = "(incremental call log retrieval)";
    ObjectType callLogObjectType = ObjectType.getObjectType(connector(),
        "call_log");
    String callLogFolderName = getSettingsOrPortLegacySettings(updateInfo.apiKey).callLogFolderName;
    try {
            Gmail gmail = getGmailService(updateInfo.apiKey);
            String email = getEmailAddress(updateInfo.apiKey);

            BigInteger originalHistoryId = historyId;

            Label callLogLabel = null;

            for (Label label : gmail.users().labels().list(email).execute().getLabels()){
                if (label.getName().equals(callLogFolderName)){
                    callLogLabel = label;
                }
            }
            if (callLogLabel == null)
                throw new FolderNotFoundException();

            //if we get to this point then we were able to access the folder and should delete our error notification
            Notification errorNotification = notificationsService.getNamedNotification(updateInfo.getGuestId(), connector().getName() + ".callLogFolderError");
            if (errorNotification != null && !errorNotification.deleted){
                notificationsService.deleteNotification(updateInfo.getGuestId(),errorNotification.getId());
            }

            Properties props = new Properties();
            Session session = Session.getDefaultInstance(props, null);

            if (historyId != null){
                ListHistoryResponse historyResponse = null;
                BigInteger queryHistoryId = historyId;
                do{
                    historyResponse = invokeListHistory(gmail,email,queryHistoryId,callLogLabel.getId(),historyResponse == null ? null : historyResponse.getNextPageToken());
                    if (historyResponse == null){
                        //if historyResponse is null that means we got a 404 error which means historyId is no longer valid
                        historyId = null;
                        break;
                    }
                    List<History> histories = historyResponse.getHistory();
                    for (History history : histories){
                        if (history.getMessages() == null)
                            continue;
                        for (Message messageStub : history.getMessages()){
                            Message message = invokeGetMessage(gmail, email, messageStub.getId());
                            if (message == null)
                                continue;
                            if (historyId.compareTo(message.getHistoryId()) < 0)
                                historyId = message.getHistoryId();
                            byte[] emailBytes = Base64.decodeBase64(message.getRaw());
                            MimeMessage mimeMessage = new MimeMessage(session, new ByteArrayInputStream(emailBytes));

                            if (flushEntry(updateInfo, email, mimeMessage, CallLogEntryFacet.class) == null){
                                throw new Exception("Could not persist Call log");
                            }
                        }
                    }
                } while (historyResponse.getNextPageToken() != null);
            }
            if (historyId == null){
                ListMessagesResponse listResponse = null;
                do{
                    listResponse = invokeList(gmail,email,callLogLabel.getId(),listResponse == null ? null : listResponse.getNextPageToken());
                    if (listResponse.getMessages() == null){
                        continue;
                    }
                    for (Message messageStub : listResponse.getMessages()){
                        Message message = invokeGetMessage(gmail, email, messageStub.getId());
                        if (message == null)
                            continue;
                        if (historyId == null || historyId.compareTo(message.getHistoryId()) < 0)
                            historyId = message.getHistoryId();
                        byte[] emailBytes = Base64.decodeBase64(message.getRaw());
                        MimeMessage mimeMessage = new MimeMessage(session, new ByteArrayInputStream(emailBytes));

                        if (flushEntry(updateInfo, email, mimeMessage, CallLogEntryFacet.class) == null){
                            throw new Exception("Could not persist Call log");
                        }
                    }

                } while (listResponse.getNextPageToken() != null);
            }
            if (historyId != null && !historyId.equals(originalHistoryId)){
                updateHistoryId(updateInfo,callLogObjectType,historyId);
            }

      countSuccessfulApiCall(updateInfo.apiKey, callLogObjectType.value(), then, query);
    }
        catch (MessagingException ex){
            notificationsService.addNamedNotification(updateInfo.getGuestId(), Notification.Type.ERROR, connector().getName() + ".callLogFolderError",
                                  "The call log folder configured for SMS Backup, \"" + callLogFolderName + "\", does not exist. Either change it in your connector settings or check if SMS Backup is set to use this folder.");
            throw new UpdateFailedException("Couldn't open Call Log folder.",true, null);
        }
        catch (Exception ex) {
            ex.printStackTrace();
      reportFailedApiCall(updateInfo.apiKey,
          callLogObjectType.value(), then, query, Utils.stackTrace(ex),
                    ex.getMessage());
      throw ex;
    }
  }
View Full Code Here

    public List<AbstractFacetVO<AbstractFacet>> getFacetVOs(final GuestSettings guestSettings, final ApiKey apiKey, final String objectTypeName, final long start, final long end, final String value) {
        Connector connector = apiKey.getConnector();

        TimeInterval timeInterval = metadataService.getArbitraryTimespanMetadata(apiKey.getGuestId(), start, end).getTimeInterval();

        final ObjectType objectType = ObjectType.getObjectType(connector, value);

        List<AbstractFacet> facets = getFacetsInTimespan(timeInterval, apiKey, objectType);

        return getFacetVOsForFacets(facets,timeInterval,guestSettings);
    }
View Full Code Here

TOP

Related Classes of org.fluxtream.core.connectors.ObjectType

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.