Ejemplo n.º 1
0
 private long getLatestData(ApiKey apiKey) {
   if (!apiKey.getConnector().hasFacets()) return Long.MAX_VALUE;
   final ObjectType[] objectTypes = apiKey.getConnector().objectTypes();
   if (objectTypes == null || objectTypes.length == 0) {
     final String maxTimeAtt =
         guestService.getApiKeyAttribute(apiKey, ApiKeyAttribute.MAX_TIME_KEY);
     // only return the ApiKey's maxTime if we have it cached as an attribute
     if (maxTimeAtt != null && StringUtils.isNotEmpty(maxTimeAtt)) {
       final DateTime dateTime =
           ISODateTimeFormat.dateHourMinuteSecondFraction()
               .withZoneUTC()
               .parseDateTime(maxTimeAtt);
       return dateTime.getMillis();
     }
   } else {
     long maxTime = Long.MIN_VALUE;
     for (ObjectType objectType : objectTypes) {
       final String maxTimeAtt =
           guestService.getApiKeyAttribute(
               apiKey, objectType.getApiKeyAttributeName(ApiKeyAttribute.MAX_TIME_KEY));
       if (maxTimeAtt != null && StringUtils.isNotEmpty(maxTimeAtt)) {
         final DateTime dateTime =
             ISODateTimeFormat.dateHourMinuteSecondFraction()
                 .withZoneUTC()
                 .parseDateTime(maxTimeAtt);
         final long maxObjectTypeTime = dateTime.getMillis();
         if (maxObjectTypeTime > maxTime) maxTime = maxObjectTypeTime;
       }
     }
     // only return the ApiKey's maxTime if we have it cached as an attribute for any its
     // connector's objectTypes
     if (maxTime > Long.MIN_VALUE) return maxTime;
   }
   // fall back to old method of querying the facets table
   AbstractFacet facet = null; // apiDataService.getLatestApiDataFacet(apiKey, null);
   return facet == null ? Long.MAX_VALUE : facet.end;
 }
Ejemplo n.º 2
0
 private long getLastSync(ApiKey apiKey) {
   if (!apiKey.getConnector().hasFacets()) return Long.MAX_VALUE;
   final String lastSyncTimeAtt =
       guestService.getApiKeyAttribute(apiKey, ApiKeyAttribute.LAST_SYNC_TIME_KEY);
   // only return the ApiKey's lastSyncTime if we have it cached as an attribute
   if (lastSyncTimeAtt != null && StringUtils.isNotEmpty(lastSyncTimeAtt)) {
     final DateTime dateTime =
         ISODateTimeFormat.dateHourMinuteSecondFraction()
             .withZoneUTC()
             .parseDateTime(lastSyncTimeAtt);
     return dateTime.getMillis();
   }
   // fall back to old method of querying the ApiUpdates table
   ApiUpdate update = null; // connectorUpdateService.getLastSuccessfulUpdate(apiKey);
   return update != null ? update.ts : Long.MAX_VALUE;
 }