Examples of IPersistenceManager


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

      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

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

    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

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

    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

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

    }

    //
    // If the gadget is not already registered, add it
    //
    IPersistenceManager persistenceManager = PersistenceManagerFactory.getPersistenceManager();
    if(persistenceManager.findWidgetByGuid(widget.getIdentifier()) == null){
      WidgetFactory.addNewWidget(widget);
      return true;
    } else {
      return false;
    }
View Full Code Here

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

   * @param widgetInstance
   * @param name
   * @param value
   */
  public static boolean updatePreference(IWidgetInstance widgetInstance, String name, String value){
        IPersistenceManager persistenceManager = PersistenceManagerFactory.getPersistenceManager();
        boolean found=false;
        IPreference preference = widgetInstance.getPreference(name);
        if (preference != null)
        {
            if(value==null || value.equalsIgnoreCase("null")){ 
                widgetInstance.getPreferences().remove(preference);
            }
            else{   
                preference.setDvalue(value);
            }
            found=true;
        }
        if(!found){ 
          if (value != null){
                preference = persistenceManager.newInstance(IPreference.class);
            preference.setDkey(name);
            preference.setDvalue(value);
            widgetInstance.getPreferences().add(preference);
          }
        } 
        persistenceManager.save(widgetInstance);
        return found;
  }
View Full Code Here

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

  /* (non-Javadoc)
   * @see org.apache.wookie.controller.Controller#index(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
   */
  protected void index(HttpServletRequest request, HttpServletResponse response) throws IOException{
      IPersistenceManager persistenceManager = PersistenceManagerFactory.getPersistenceManager();
    IWidgetService[] ws = persistenceManager.findAll(IWidgetService.class);
    boolean defaults = (request.getParameter("defaults") != null);
    returnXml(WidgetServiceHelper.createXMLWidgetServicesDocument(ws, getLocalPath(request),defaults, getLocales(request)), response);
  }
View Full Code Here

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

    IWidgetService ws;
    try {
      ws = getWidgetService(resourceId);
      throw new ResourceDuplicationException();
    } catch (ResourceNotFoundException e) {
        IPersistenceManager persistenceManager = PersistenceManagerFactory.getPersistenceManager();
      ws = persistenceManager.newInstance(IWidgetService.class);
      ws.setServiceName(resourceId);
      return persistenceManager.save(ws);
    }
  }
View Full Code Here

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

    IWidgetService service = getWidgetService(resourceId);
    if (service == null) throw new ResourceNotFoundException();
    String serviceName = service.getServiceName();
   
    // if exists, remove from widget default table
    IPersistenceManager persistenceManager = PersistenceManagerFactory.getPersistenceManager();
    IWidgetDefault[] widgetDefaults = persistenceManager.findByValue(IWidgetDefault.class, "widgetContext", serviceName);
    persistenceManager.delete(widgetDefaults);
   
    // delete from the widget service table
    persistenceManager.delete(service)
    // remove any widgetTypes for each widget that match
    IWidget[] widgets = persistenceManager.findWidgetsByType(serviceName);
    if (widgets == null||widgets.length==0) return true;
    for(IWidget widget : widgets){
      // remove any widget types for this widget
        Iterator<IWidgetType> typesIter = widget.getWidgetTypes().iterator();
        while(typesIter.hasNext()) {
            IWidgetType widgetType = typesIter.next();
                if(serviceName.equalsIgnoreCase(widgetType.getWidgetContext())){
                    typesIter.remove();
                }
        }
        persistenceManager.save(widget);
    }         
    return true;
  }
View Full Code Here

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

        logger.info("Run test");
       
        //
        // allocate and begin persistence manager transaction
        //
        IPersistenceManager persistenceManager = PersistenceManagerFactory.getPersistenceManager();
        persistenceManager.begin();

        //
        // test findAll method for IWidget
        //
        IWidget [] allWidgets = persistenceManager.findAll(IWidget.class);
        assertNotNull(allWidgets);
        assertEquals(1, allWidgets.length);

        //
        // test findById  for IWidget
        //
        Object widgetId = allWidgets[0].getId();
        IWidget widgetById = persistenceManager.findById(IWidget.class, widgetId);
        assertNotNull(widgetById);
        assertEquals(allWidgets[0], widgetById);
       
        //
        // test findByValue method for IWidget
        //
        String widgetGuid = allWidgets[0].getIdentifier();
        IWidget [] widgetsByValue = persistenceManager.findByValue(IWidget.class, "guid", widgetGuid);
        assertNotNull(widgetsByValue);
        assertEquals(1, widgetsByValue.length);
        assertEquals(allWidgets[0], widgetsByValue[0]);
              
        //
        // test findByValues methods for IWidget
        //
        Map<String,Object> values = new HashMap<String,Object>();
        values.put("height", allWidgets[0].getHeight());
        values.put("width", allWidgets[0].getWidth());
        //
        // removed for now as this is a deprecated method, and can't be called
        // at this point due to transaction boundaries.
        //
        //values.put("widgetAuthor", allWidgets[0].getWidgetAuthor());
        IWidget [] widgetsByValues = persistenceManager.findByValues(IWidget.class, values);
        assertNotNull(widgetsByValues);
        assertEquals(1, widgetsByValues.length);
        assertEquals(allWidgets[0], widgetsByValues[0]);
       
        //
        // test custom widget query methods
        //
        IWidget widgetByGuid = persistenceManager.findWidgetByGuid(widgetGuid);
        assertNotNull(widgetByGuid);
        assertEquals(allWidgets[0], widgetByGuid);
       
        //
        // rollback and close persistence manager transaction
        //
        persistenceManager.rollback();
        PersistenceManagerFactory.closePersistenceManager();
       
        //
        // allocate and begin persistence manager transaction
        //
        persistenceManager = PersistenceManagerFactory.getPersistenceManager();
        persistenceManager.begin();

        //
        // Get the first existing API key
        // and first existing Widget to use as the basis of a 
        // new Widget Instance
        //
        String apiKey = "TEST";
        IWidget [] widgets = persistenceManager.findAll(IWidget.class);
        IWidget widget = widgets[0];       
        widgetGuid = widget.getIdentifier();
       
        //
        // check that the Widget Instance does not yet exist
        //
        IWidgetInstance widgetInstance = persistenceManager.findWidgetInstanceByGuid(apiKey, "test", "test-shared-data-key", widgetGuid);
        assertNull(widgetInstance);
       
        //
        // Create the Widget Instance
        //
        widgetInstance = persistenceManager.newInstance(IWidgetInstance.class);
       
        //
        // Set some properties, including preferences
        //
        widgetInstance.setApiKey(apiKey);
        widgetInstance.setWidget(widget);
        widgetInstance.setIdKey("test");
        widgetInstance.setLang("en");
        widgetInstance.setNonce("nonce-test");
        widgetInstance.setOpensocialToken("");
        widgetInstance.setSharedDataKey("test-shared-data-key");
        widgetInstance.setShown(true);
        widgetInstance.setUserId("test");
        IPreference widgetInstancePreference = persistenceManager.newInstance(IPreference.class);
        widgetInstancePreference.setDkey("sharedDataKey");
        widgetInstancePreference.setDvalue("test-shared-data-key");
        widgetInstancePreference.setReadOnly(true);
        widgetInstance.getPreferences().add(widgetInstancePreference);
        //
        // Save the widget instance
        //
        persistenceManager.save(widgetInstance);

        //
        // create a participant
        //
        IParticipant participant = persistenceManager.newInstance(IParticipant.class);
        //participant.setWidget(widget);
        participant.setSharedDataKey("test-shared-data-key");
        participant.setParticipantId("test");
        participant.setParticipantDisplayName("");
        participant.setParticipantThumbnailUrl("");
        persistenceManager.save(participant);

        //
        // commit and close persistence manager transaction
        //
        persistenceManager.commit();
        PersistenceManagerFactory.closePersistenceManager();

        //
        // allocate and begin persistence manager transaction
        //
        persistenceManager = PersistenceManagerFactory.getPersistenceManager();
        persistenceManager.begin();
       
        //
        // Get the widget instance created in the previous transaction
        //
        widgets = persistenceManager.findAll(IWidget.class);
        widget = widgets[0];
        IWidgetInstance widgetInstance0 = persistenceManager.findWidgetInstanceByGuid(apiKey, "test", "test-shared-data-key", widgetGuid);
        assertNotNull(widgetInstance0);
        widgetGuid = widget.getIdentifier();
       
        //
        // Get the widget instance created in the previous transaction via "widget GUID"
        //
        IWidgetInstance widgetInstance1 = persistenceManager.findWidgetInstanceByGuid(apiKey, "test", "test-shared-data-key", widgetGuid);
        assertNotNull(widgetInstance1);
        assertEquals(widgetInstance0, widgetInstance1);
       
        //
        // Get the widget instance created in the previous transaction via instance_idkey
        //
        IWidgetInstance widgetInstance2 = persistenceManager.findWidgetInstanceByIdKey("test");
        assertNotNull(widgetInstance2);
        assertEquals(widgetInstance0, widgetInstance2);
       
        //
        // Get the participant created in the previous transaction by widget instance
        //
      
        IParticipant [] participants =  new SharedContext(widgetInstance0).getParticipants();
        assertNotNull(participants);
        assertEquals(1, participants.length);
       
        //
        // Get the participant created in the previous transaction by widget instance
        //
        participant =  new SharedContext(widgetInstance0).getViewer(widgetInstance0);
        assertNotNull(participant);
       
        //
        // delete all the test objects
        //
        persistenceManager.delete(widgetInstance0);
        persistenceManager.delete(participant);
       
        //
        // commit and close persistence manager transaction
        //
        persistenceManager.commit();
        PersistenceManagerFactory.closePersistenceManager();

        //
        // allocate and begin persistence manager transaction
        //
        persistenceManager = PersistenceManagerFactory.getPersistenceManager();
        persistenceManager.begin();
       
        //
        // verify test deletes
        //
        IWidgetInstance [] widgetInstances = persistenceManager.findAll(IWidgetInstance.class);
        assertNotNull(widgetInstances);
        assertEquals(0, widgetInstances.length);
        participants = persistenceManager.findAll(IParticipant.class);
        assertNotNull(participants);
       
        // TODO - this fails with the result being 1
        // assertEquals(0, participants.length);
       
        //
        // rollback and close persistence manager transaction
        //
        persistenceManager.rollback();
        PersistenceManagerFactory.closePersistenceManager();

        logger.info("Test run");
    }
View Full Code Here

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

        logger.info("Run test");
       
        //
        // allocate and begin persistence manager transaction
        //
        IPersistenceManager persistenceManager = PersistenceManagerFactory.getPersistenceManager();
        persistenceManager.begin();

        //
        // test findAll method for IWidget
        //
        IWidget [] allWidgets = persistenceManager.findAll(IWidget.class);
        assertNotNull(allWidgets);
        assertEquals(1, allWidgets.length);

        //
        // test findById  for IWidget
        //
        Object widgetId = allWidgets[0].getId();
        IWidget widgetById = persistenceManager.findById(IWidget.class, widgetId);
        assertNotNull(widgetById);
        assertEquals(allWidgets[0], widgetById);
       
        //
        // test findByValue method for IWidget
        //
        String widgetGuid = allWidgets[0].getGuid();
        IWidget [] widgetsByValue = persistenceManager.findByValue(IWidget.class, "guid", widgetGuid);
        assertNotNull(widgetsByValue);
        assertEquals(1, widgetsByValue.length);
        assertEquals(allWidgets[0], widgetsByValue[0]);
              
        //
        // test findByValues methods for IWidget
        //
        Map<String,Object> values = new HashMap<String,Object>();
        values.put("height", allWidgets[0].getHeight());
        values.put("width", allWidgets[0].getWidth());
        //
        // removed for now as this is a deprecated method, and can't be called
        // at this point due to transaction boundaries.
        //
        //values.put("widgetAuthor", allWidgets[0].getWidgetAuthor());
        IWidget [] widgetsByValues = persistenceManager.findByValues(IWidget.class, values);
        assertNotNull(widgetsByValues);
        assertEquals(1, widgetsByValues.length);
        assertEquals(allWidgets[0], widgetsByValues[0]);
       
        //
        // test custom widget query methods
        //
        IWidget widgetByGuid = persistenceManager.findWidgetByGuid(widgetGuid);
        assertNotNull(widgetByGuid);
        assertEquals(allWidgets[0], widgetByGuid);
       
        //
        // rollback and close persistence manager transaction
        //
        persistenceManager.rollback();
        PersistenceManagerFactory.closePersistenceManager();
       
        //
        // allocate and begin persistence manager transaction
        //
        persistenceManager = PersistenceManagerFactory.getPersistenceManager();
        persistenceManager.begin();

        //
        // Get the first existing API key
        // and first existing Widget to use as the basis of a 
        // new Widget Instance
        //
        String apiKey = "TEST";
        IWidget [] widgets = persistenceManager.findAll(IWidget.class);
        IWidget widget = widgets[0];       
        widgetGuid = widget.getGuid();
       
        //
        // check that the Widget Instance does not yet exist
        //
        IWidgetInstance widgetInstance = persistenceManager.findWidgetInstanceByGuid(apiKey, "test", "test-shared-data-key", widgetGuid);
        assertNull(widgetInstance);
       
        //
        // Create the Widget Instance
        //
        widgetInstance = persistenceManager.newInstance(IWidgetInstance.class);
       
        //
        // Set some properties, including preferences
        //
        widgetInstance.setApiKey(apiKey);
        widgetInstance.setWidget(widget);
        widgetInstance.setIdKey("test");
        widgetInstance.setLang("en");
        widgetInstance.setNonce("nonce-test");
        widgetInstance.setOpensocialToken("");
        widgetInstance.setSharedDataKey("test-shared-data-key");
        widgetInstance.setShown(true);
        widgetInstance.setUserId("test");
        IPreference widgetInstancePreference = persistenceManager.newInstance(IPreference.class);
        widgetInstancePreference.setDkey("sharedDataKey");
        widgetInstancePreference.setDvalue("test-shared-data-key");
        widgetInstancePreference.setReadOnly(true);
        widgetInstance.getPreferences().add(widgetInstancePreference);
        //
        // Save the widget instance
        //
        persistenceManager.save(widgetInstance);

        //
        // create a participant
        //
        IParticipant participant = persistenceManager.newInstance(IParticipant.class);
        //participant.setWidget(widget);
        participant.setSharedDataKey("test-shared-data-key");
        participant.setParticipantId("test");
        participant.setParticipantDisplayName("");
        participant.setParticipantThumbnailUrl("");
        persistenceManager.save(participant);

        //
        // commit and close persistence manager transaction
        //
        persistenceManager.commit();
        PersistenceManagerFactory.closePersistenceManager();

        //
        // allocate and begin persistence manager transaction
        //
        persistenceManager = PersistenceManagerFactory.getPersistenceManager();
        persistenceManager.begin();
       
        //
        // Get the widget instance created in the previous transaction
        //
        widgets = persistenceManager.findAll(IWidget.class);
        widget = widgets[0];
        IWidgetInstance widgetInstance0 = persistenceManager.findWidgetInstanceByGuid(apiKey, "test", "test-shared-data-key", widgetGuid);
        assertNotNull(widgetInstance0);
        widgetGuid = widget.getGuid();
       
        //
        // Get the widget instance created in the previous transaction via "widget GUID"
        //
        IWidgetInstance widgetInstance1 = persistenceManager.findWidgetInstanceByGuid(apiKey, "test", "test-shared-data-key", widgetGuid);
        assertNotNull(widgetInstance1);
        assertEquals(widgetInstance0, widgetInstance1);
       
        //
        // Get the widget instance created in the previous transaction via instance_idkey
        //
        IWidgetInstance widgetInstance2 = persistenceManager.findWidgetInstanceByIdKey("test");
        assertNotNull(widgetInstance2);
        assertEquals(widgetInstance0, widgetInstance2);
       
        //
        // Get the participant created in the previous transaction by widget instance
        //
      
        IParticipant [] participants =  new SharedContext(widgetInstance0).getParticipants();
        assertNotNull(participants);
        assertEquals(1, participants.length);
       
        //
        // Get the participant created in the previous transaction by widget instance
        //
        participant =  new SharedContext(widgetInstance0).getViewer(widgetInstance0);
        assertNotNull(participant);
       
        //
        // delete all the test objects
        //
        persistenceManager.delete(widgetInstance0);
        persistenceManager.delete(participant);
       
        //
        // commit and close persistence manager transaction
        //
        persistenceManager.commit();
        PersistenceManagerFactory.closePersistenceManager();

        //
        // allocate and begin persistence manager transaction
        //
        persistenceManager = PersistenceManagerFactory.getPersistenceManager();
        persistenceManager.begin();
       
        //
        // verify test deletes
        //
        IWidgetInstance [] widgetInstances = persistenceManager.findAll(IWidgetInstance.class);
        assertNotNull(widgetInstances);
        assertEquals(0, widgetInstances.length);
        participants = persistenceManager.findAll(IParticipant.class);
        assertNotNull(participants);
       
        // TODO - this fails with the result being 1
        // assertEquals(0, participants.length);
       
        //
        // rollback and close persistence manager transaction
        //
        persistenceManager.rollback();
        PersistenceManagerFactory.closePersistenceManager();

        logger.info("Test run");
    }
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.