Package org.apache.wookie.beans.util

Examples of org.apache.wookie.beans.util.IPersistenceManager


   * @param request
   * @return
   */
  public static IWidgetInstance findWidgetInstance(HttpServletRequest request){
    IWidgetInstance instance;
    IPersistenceManager persistenceManager = PersistenceManagerFactory.getPersistenceManager();

    // Try using the id_key parameter
    String id_key = request.getParameter("id_key"); //$NON-NLS-1$
    if (id_key != null & id_key != ""){
      instance = persistenceManager.findWidgetInstanceByIdKey(id_key);
      return instance;
    }
   
    // Try using the resource part of the path as an id key e.g. widgetinstances/xyz
    id_key = getResourceId(request);
    if (id_key != null & id_key != ""){
      instance = persistenceManager.findWidgetInstanceByIdKey(id_key);
      return instance;
    }

    //
    // If all else fails, try using instance parameters
View Full Code Here


   * @return the widget instance, or null if there is no matching instance
   * @throws UnsupportedEncodingException
   */
  public static IWidgetInstance findWidgetInstance(String apiKey, String userId, String sharedDataKey, String widgetId, String serviceType) throws UnsupportedEncodingException{
    IWidgetInstance instance;
    IPersistenceManager persistenceManager = PersistenceManagerFactory.getPersistenceManager();
    if (widgetId != null){
      widgetId = URLDecoder.decode(widgetId, "UTF-8"); //$NON-NLS-1$
      _logger.debug("Looking for widget instance with widgetid of " + widgetId);
      instance = persistenceManager.findWidgetInstanceByGuid(apiKey, userId, sharedDataKey, widgetId);
    } else {
      _logger.debug("Looking for widget instance of service type " + serviceType);
      instance = persistenceManager.findWidgetInstance(apiKey, userId, sharedDataKey, serviceType);
    }
    return instance;
  }
View Full Code Here

   */
  public static boolean revokeKey(String value){
    if (value == null) return false;
    if (value.trim().equals("")) return false;
    value = value.trim();
    IPersistenceManager persistenceManager = PersistenceManagerFactory.getPersistenceManager();
    IApiKey[] key = persistenceManager.findByValue(IApiKey.class, "value", value);
    if (key == null || key.length !=1) return false;
    return revokeKey(persistenceManager, key[0]);
  }
View Full Code Here

   * @throws EmailException if there is a problem sending the email notification about this key
   * @throws SystemUnavailableException if there is a problem generating the key
   */
  public static void createKey(HttpServletRequest request, String email, Messages localizedMessages) throws SystemUnavailableException, EmailException {
     
      IPersistenceManager persistenceManager = PersistenceManagerFactory.getPersistenceManager();
    IApiKey key = persistenceManager.newInstance(IApiKey.class);
    key.setEmail(email);

    // generate a nonce
    RandomGUID r = new RandomGUID();
    String nonce = "nonce-" + r.toString();         //$NON-NLS-1$

    // now use SHA hash on the nonce       
    String hashKey = HashGenerator.getInstance().encrypt(nonce+email)

    // get rid of any chars that might upset a url...
    hashKey = hashKey.replaceAll("=", ".eq."); //$NON-NLS-1$ //$NON-NLS-2$
    hashKey = hashKey.replaceAll("\\?", ".qu."); //$NON-NLS-1$ //$NON-NLS-2$
    hashKey = hashKey.replaceAll("&", ".am."); //$NON-NLS-1$ //$NON-NLS-2$
    hashKey = hashKey.replaceAll("\\+", ".pl."); //$NON-NLS-1$ //$NON-NLS-2$

    key.setValue(hashKey);
    persistenceManager.save(key);
   
    String message = localizedMessages.getString("WidgetKeyManager.0")+hashKey+" \n"//$NON-NLS-1$//$NON-NLS-2$
    message+="\n" + localizedMessages.getString("WidgetKeyManager.1"); //$NON-NLS-1$ //$NON-NLS-2$
   
    Configuration properties = (Configuration) request.getSession().getServletContext().getAttribute("properties"); //$NON-NLS-1$
View Full Code Here

   * @see org.apache.wookie.controller.Controller#index(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
   */
  @Override
  protected void index(HttpServletRequest request, HttpServletResponse response)
      throws UnauthorizedAccessException, IOException {
    IPersistenceManager persistenceManager = PersistenceManagerFactory.getPersistenceManager();
    IApiKey[] apiKeys = persistenceManager.findAll(IApiKey.class);
    returnXml(ApiKeyHelper.createXML(apiKeys),response);
  }
View Full Code Here

      throws ResourceDuplicationException, InvalidParametersException,
      UnauthorizedAccessException {
    String value = request.getParameter("apikey");
    String email = request.getParameter("email");
    if (value == null || email == null || value.trim().length() ==0 || email.trim().length() == 0) throw new InvalidParametersException();
    IPersistenceManager persistenceManager = PersistenceManagerFactory.getPersistenceManager();
    Map<String, Object> values = new HashMap<String, Object>();
    values.put("value", value);
    values.put("email", email);
    if (persistenceManager.findByValues(IApiKey.class, values).length > 0){
      throw new ResourceDuplicationException();
    }
   
    IApiKey apiKey = persistenceManager.newInstance(IApiKey.class);
    apiKey.setValue(value);
    apiKey.setEmail(email);
    persistenceManager.save(apiKey);
    _logger.info("New API key registered for "+email);
    return true;
  }
View Full Code Here

   */
  @Override
  protected boolean remove(String resourceId, HttpServletRequest request)
      throws ResourceNotFoundException, UnauthorizedAccessException,
      InvalidParametersException {
    IPersistenceManager persistenceManager = PersistenceManagerFactory.getPersistenceManager();
    IApiKey apiKey = persistenceManager.findById(IApiKey.class, resourceId);
    if (apiKey == null) throw new ResourceNotFoundException();
    persistenceManager.delete(apiKey);
    _logger.info("API key deleted for "+apiKey.getEmail());
    return true;
  }
View Full Code Here

      JSONArray policiesJson = new JSONArray();
      for(Policy policy: policies){
        JSONObject policyJson = new JSONObject();
        policyJson.put("scope", policy.getScope());
        if (!policy.getScope().equals("*")){
          IPersistenceManager persistenceManager = PersistenceManagerFactory.getPersistenceManager();
          IWidget widget = persistenceManager.findWidgetByGuid(policy.getScope());
          if (widget != null){
            policyJson.put("widget-title", WidgetHelper.getEncodedWidgetTitle(widget, null));
          }
        }
        policyJson.put("origin", policy.getOrigin());
View Full Code Here

    if ((resourceId == null) || resourceId.equals("")){
      index(resourceId, request, response);
      return;
    }
    // attempt to get specific widget by id
    IPersistenceManager persistenceManager = PersistenceManagerFactory.getPersistenceManager();
    IWidget widget = persistenceManager.findById(IWidget.class, resourceId);
    // support queries by type
    if (widget == null) {
      IWidgetService[] services = persistenceManager.findByValue(IWidgetService.class, "serviceName", resourceId);
        if (services != null && services.length == 1) {
          IWidget[] widgets = persistenceManager.findWidgetsByType(resourceId);
            returnXml(WidgetHelper.createXMLWidgetsDocument(widgets, getLocalPath(request), getLocales(request)),response);
            return;
        }
    }
    // return widget result
View Full Code Here

    IWidget[] widgets;
   
    // If the request has the parameter ?all, return all widgets.
    // If the request contains a String resource identifier
    // such as "/chat", return all matching widgets
        IPersistenceManager persistenceManager = PersistenceManagerFactory.getPersistenceManager();
    if (request.getParameter("all") != null
        || (resourceId != null && !resourceId.equals(""))) {
      if (resourceId != null && !resourceId.equals("")) {
        widgets = persistenceManager.findWidgetsByType(resourceId);
      } else {
        widgets = persistenceManager.findAll(IWidget.class);
      }
      // Otherwise, return default widgets for the defined services. In
      // future we may want
      // to move this into the Services controller.
    } else {
      ArrayList<IWidget> widgetsarr = new ArrayList<IWidget>();
      for (IWidgetDefault widgetDefault : persistenceManager.findAll(IWidgetDefault.class)) {
        widget = widgetDefault.getWidget();
        if (!widget.getGuid().equals("http://notsupported")) {
          widgetsarr.add(widget);
        }
      }
View Full Code Here

TOP

Related Classes of org.apache.wookie.beans.util.IPersistenceManager

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.