Examples of Guest


Examples of org.fluxtream.core.domain.Guest

            }
        }
    }

    private void rebuildMetadata(final String username, long apiKeyId) {
        final Guest guest = guestService.getGuest(username);
        String entityName = JPAUtils.getEntityName(LocationFacet.class);
        int i=0;
        final Query facetsQuery = em.createQuery(String.format("SELECT facet FROM %s facet WHERE facet.apiKeyId=? ORDER BY facet.start ASC", entityName));
        facetsQuery.setParameter(1, apiKeyId);
        while(true) {
            facetsQuery.setFirstResult(i);
            facetsQuery.setMaxResults(1000);
            final List<LocationFacet> rawLocations = facetsQuery.getResultList();
            //System.out.println(username + ": retrieved " + rawLocations.size() + " location datapoints (offset is " + i + ")");
            if (rawLocations.size()==0)
                break;
            //System.out.println(username + ":   " + AbstractLocalTimeFacet.timeStorageFormat.withZoneUTC().print(rawLocations.get(0).start));

            long then = System.currentTimeMillis();
            // Loop over the points to see if they're already included in visited cities entries
            // it's important that the location points in the locations list are for a single apiKeyId
            // and are in forward chronological order.  Only add locations that aren't already contained
            // within a VisitedCity item to the newLocations list
            List<LocationFacet> newLocations=new ArrayList<LocationFacet>();
            VisitedCity existingVisitedCityRecord = null;

            for (LocationFacet locationFacet : rawLocations) {
                // Check to see if this location is in the current existingVisitedCityRecord (if any)
                if(existingVisitedCityRecord !=null && locationFacet.start <=existingVisitedCityRecord.end) {
                    // This location falls within the last fetched visited cities record, skip it
                    continue;
                }
                // This location doesn't fall within the last fetched visited cities record (if any).
                // See if it fits in a new one.  Note that this really assumes that locationFacet.start
                // and locationFacet.end are the same and VisitedCity records are non-overlapping.
                // It returns null if there are no visited city
                // records overlapping the current point and non-null if there is one.
                existingVisitedCityRecord = JPAUtils.findUnique(em, VisitedCity.class,
                                                              "visitedCities.byApiAndTime",
                                                              locationFacet.apiKeyId,
                                                              locationFacet.start,
                                                              locationFacet.end);
                if(existingVisitedCityRecord == null) {
                    // This is a new point, add it
                    newLocations.add(locationFacet);
                }
                else {
                    // This point is already covered, skip it
                }
            }

            if(newLocations.size()>0) {
                long start = newLocations.get(0).start;
                System.out.println(username + ": processing " + newLocations.size() + " new " + entityName +
                                   " datapoints (offset is " + i + ", start is " + start +
                                   " = " + AbstractLocalTimeFacet.timeStorageFormat.withZoneUTC().print(start) + " UTC)");
                updateLocationMetadata(guest.getId(), newLocations);
            }
            else {
                System.out.println(username + ": no new " + entityName + " location datapoints (offset is " + i + ")");
            }
View Full Code Here

Examples of org.fluxtream.core.domain.Guest

    }

    @RequestMapping(value="/")
    public ModelAndView devIndex(HttpServletResponse response) {
        noCache(response);
        final Guest guest = AuthHelper.getGuest();
        if (guest!=null)
            return new ModelAndView("redirect:/dev/home");
        final ModelAndView mav = new ModelAndView("developer/index", "release", env.get("release"));
        mav.addObject("visibility", "public");
        return mav;
View Full Code Here

Examples of org.fluxtream.core.domain.Guest

    @RequestMapping(value = "/home")
    public ModelAndView partnersHome(HttpServletResponse response, ModelMap model) {
        noCache(response);
        final ModelAndView mav = new ModelAndView("developer/index", "release", env.get("release"));
        String release = env.get("release");
        final Guest guest = AuthHelper.getGuest();
        model.addObject("avatarURL", getGravatarImageURL(guest));
        model.addObject("guestName", guest.getGuestName());
        model.addObject("release", release);
        mav.addObject("visibility", "partners");
        return mav;
    }
View Full Code Here

Examples of org.fluxtream.core.domain.Guest

    }

    @RequestMapping(value = "/partners/partials/{partial}")
    public String partnersPartial(@PathVariable("partial") String partial, ModelMap model) {
        String release = env.get("release");
        final Guest guest = AuthHelper.getGuest();
        model.addObject("guestName", guest.getGuestName());
        model.addObject("avatarURL", getGravatarImageURL(guest));
        model.addObject("release", release);
        return "/developer/partners/partials/" + partial;
    }
View Full Code Here

Examples of org.fluxtream.core.domain.Guest

    String contents = HttpUtils.fetch(tunnelUrl, params);
    response.getWriter().write(contents);
  }

    private boolean checkForPermissionAccess(long targetUid){
        Guest guest = AuthHelper.getGuest();
        return targetUid == guest.getId() || guest.hasRole(Guest.ROLE_ADMIN) || guest.hasRole(Guest.ROLE_ADMIN);
    }
View Full Code Here

Examples of org.fluxtream.core.domain.Guest

  public ModelAndView upgradeToken(HttpServletRequest request) throws IOException, UnexpectedHttpResponseCodeException {

        String scope = (String) request.getSession().getAttribute("oauth2Scope");
        Connector scopedApi = systemService.getApiFromGoogleScope(scope);

        Guest guest = AuthHelper.getGuest();

        String errorParameter = request.getParameter("error");
        if (errorParameter!=null) {
            notificationsService.addNamedNotification(guest.getId(), Notification.Type.WARNING,
                                                      scopedApi.statusNotificationName(),
                                                      "There was a problem importing your " + scopedApi.prettyName() + " data: " + errorParameter);
            return new ModelAndView("redirect:/app/");
        }

    String swapTokenUrl = "https://accounts.google.com/o/oauth2/token";
    String code = request.getParameter("code");
    String redirectUri = ControllerSupport.getLocationBase(request, env) + "google/oauth2/swapToken";
   
    Map<String,String> params = new HashMap<String,String>();
    params.put("code", code);
    params.put("client_id", env.get("google.client.id"));
    params.put("client_secret", env.get("google.client.secret"));
    params.put("redirect_uri", redirectUri);
    params.put("grant_type", "authorization_code");

      // Get the google branding info.  Default to fluxtream if not set, but can override in
      // oauth.properties by setting the default google.client.brandName parameter
      String brandName = env.get("google.client.brandName");
      if(brandName == null) {
         // Not set in oauth.properties file, default to "Fluxtream"
         brandName="Fluxtream";
      }

      // Try to renew the token.  On failure leave token=null
      JSONObject token = null;

      try {
         String fetched = HttpUtils.fetch(swapTokenUrl, params);
         token = JSONObject.fromObject(fetched);
      } catch(Throwable e) {
         token = null;
      }

        ApiKey apiKey;
        final boolean isRenewToken = request.getSession().getAttribute(APIKEYID_ATTRIBUTE) != null;
        if (isRenewToken) {
            String apiKeyId = (String)request.getSession().getAttribute(APIKEYID_ATTRIBUTE);
            apiKey = guestService.getApiKey(Long.valueOf(apiKeyId));
            if (apiKey==null) {
                Exception e = new Exception();
                String stackTrace = ExceptionUtils.getStackTrace(e);
                String errorMessage = "no apiKey with id '%s'... It looks like you are trying to renew the tokens of a non-existing Connector (/ApiKey)";
                return errorController.handleError(500, errorMessage, stackTrace);
            }

            if (token == null || !token.has("refresh_token")) {
                String message = (new StringBuilder("<p>We couldn't get your oauth2 refresh token.  "))
                        .append("Something went wrong.</p>")
                        .append("<p>You'll have to surf to your ")
                        .append("<a target='_new'  href='https://accounts.google.com/b/0/IssuedAuthSubTokens'>token mgmt page at Google</a> ")
                        .append("and hit \"Revoke Access\" next to \"").append(brandName).append(" — ").append(getGooglePrettyName(scopedApi)).append("\"</p>")
                      .append("<p>Then please, head to <a href=\"javascript:App.manageConnectors()\">Manage Connectors</a> ")
                      .append("and renew your tokens (look for the <i class=\"icon-resize-small icon-large\"></i> icon)</p>")
                        .append("<p>We apologize for the inconvenience</p>").toString();

                notificationsService.addNamedNotification(guest.getId(),
                                                     Notification.Type.ERROR,
                                                     apiKey.getConnector().statusNotificationName(),
                                                     message);
                // Record permanent failure since this connector won't work again until
                // it is reauthenticated
                guestService.setApiKeyStatus(apiKey.getId(), ApiKey.Status.STATUS_PERMANENT_FAILURE, null, ApiKey.PermanentFailReason.NEEDS_REAUTH);
                return new ModelAndView("redirect:/app");
            }

            // Remove oauth1 keys if upgrading from previous connector version.
            // Remember whether or not we're upgrading from previous connector version.
            // If so, do a full history update.  Otherwise don't force a full
            // history update and allow the update to be whatever it normally would be
            boolean upgradeFromOauth1 = false;

            if (guestService.getApiKeyAttribute(apiKey, "googleConsumerKey")!=null) {
                guestService.removeApiKeyAttribute(apiKey.getId(), "googleConsumerKey");
                upgradeFromOauth1 = true;
            }
            if (guestService.getApiKeyAttribute(apiKey, "googleConsumerSecret")!=null) {
                guestService.removeApiKeyAttribute(apiKey.getId(), "googleConsumerSecret");
                upgradeFromOauth1 = true;
            }

            // If upgradeFromOauth1 reset the connector to force a full reimport on google calendar,
            // otherwise just do a normal update
            if (apiKey.getConnector().getName().equals("google_calendar")) {
                connectorUpdateService.flushUpdateWorkerTasks(apiKey, upgradeFromOauth1);
            }

        } else {
            apiKey = guestService.createApiKey(guest.getId(), scopedApi);
        }

        // We need to store google.client.id and google.client.secret with the
        // apiKeyAttributes in either the case of original creation of the key
        // or token renewal.  createApiKey actually handles the former case, but
View Full Code Here

Examples of org.fluxtream.core.domain.Guest

                                                     @PathVariable("apiKeyId") long apiKeyId) {
        ModelAndView mav = getAdminModel();
        mav.addObject("subview", "connectorDetails");
        final ApiKey apiKey = guestService.getApiKey(apiKeyId);
        final Map<String, Object> connectorInstanceModel = connectorInstanceModelFactory.createConnectorInstanceModel(apiKey);
        final Guest guest = guestService.getGuestById(guestId);
        final List<ApiUpdate> lastUpdates = connectorUpdateService.getUpdates(apiKey, 100, 0);
        mav.addObject("guest", guest);
        mav.addObject("guestId", guest.getId());
        mav.addObject("apiKeyId", apiKeyId);
        mav.addObject("apiKey", apiKey);
        mav.addObject("attributes", guestService.getApiKeyAttributes(apiKeyId));
        mav.addObject("connectorInstanceModel", connectorInstanceModel);
        mav.addObject("lastUpdates", lastUpdates);
View Full Code Here

Examples of org.fluxtream.core.domain.Guest

    @Secured({ "ROLE_ADMIN" })
    @RequestMapping("/admin/{guestId}")
    public ModelAndView showUserApiKeys(@PathVariable("guestId") long guestId) {
        ModelAndView mav = getAdminModel();
        mav.addObject("subview", "allConnectors");
        final Guest guest = guestService.getGuestById(guestId);
        final List<ApiKey> apiKeys = guestService.getApiKeys(guest.getId());
        mav.addObject("username", guest.username);
        mav.addObject("guestId", guest.getId());
        mav.addObject("connectorInstanceModels", getConnectorInstanceModels(apiKeys));
        return mav;
    }
View Full Code Here

Examples of org.fluxtream.core.domain.Guest

    if (password2.equals("")) required.add("password2");
    if (password.length()<8)
      errors.add("passwordTooShort");
    if (!password.equals(password2))
      errors.add("passwordsDontMatch");
        final Guest guestByEmail = guestService.getGuestByEmail(email);
        if (guestByEmail !=null && guestByEmail.getUserRoles().contains("ROLE_USER"))
      errors.add("userExists");
         
//    String remoteAddr = request.getRemoteAddr();
//        ReCaptchaImpl reCaptcha = new ReCaptchaImpl();
//        reCaptcha.setPrivateKey("6LeXl8QSAAAAADjPASFlMINNRVwtlpcvGugcr2RI");
//
//        ReCaptchaResponse reCaptchaResponse = reCaptcha.checkAnswer(remoteAddr, challenge, uresponse);
//
//    if (!reCaptchaResponse.isValid())
//    errors.add("wrongCaptcha");
   
    if (errors.size()==0&&required.size()==0) {
      logger.info("action=register success=true username="+username + " email=" + email);
            final Guest guest = guestService.createGuest(username, firstname, lastname, password, email, Guest.RegistrationMethod.REGISTRATION_METHOD_FORM, null);
            final String autoLoginToken = generateSecureRandomString();
            guestService.setAutoLoginToken(guest.getId(), autoLoginToken);
      request.setAttribute("autoLoginToken", autoLoginToken);
      return new ModelAndView("accountCreationComplete");
    } else {
      logger.info("action=register errors=true");
            ModelAndView mav = new ModelAndView("createAccount");
View Full Code Here

Examples of org.fluxtream.core.domain.Guest

        .getAuthentication();
    if (auth == null || !auth.isAuthenticated())
      return mav;
    mav.setViewName("home");

        Guest guest = guestService.getGuestById(guestId);

    mav.addObject("fullname", guest.getGuestName());

        String release = env.get("release");
    request.setAttribute("guestName", guest.getGuestName());
        request.setAttribute("coachees", buddiesService.getTrustingBuddies(guestId));
        request.setAttribute("useMinifiedJs", Boolean.valueOf(env.get("useMinifiedJs")));

    if (SecurityUtils.isDemoUser())
      request.setAttribute("demo", true);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.