Package org.apache.wookie.beans.util

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


   * Destroy a widget and all dependent objects and references
   * @param id the id of the widget
   * @return true if the widget is destroyed successfully
   */
  public static boolean destroy(Object id){
      IPersistenceManager persistenceManager = PersistenceManagerFactory.getPersistenceManager();
    IWidget widget = persistenceManager.findById(IWidget.class, id);
    return destroy(widget);
  }
View Full Code Here


  public static boolean destroy(IWidget widget){

    if(widget==null) return false;
   
    // remove any defaults for this widget
        IPersistenceManager persistenceManager = PersistenceManagerFactory.getPersistenceManager();
    IWidgetDefault[] widgetDefault = persistenceManager.findByValue(IWidgetDefault.class, "widget", widget);
    if (widgetDefault.length == 1) persistenceManager.delete(widgetDefault[0]);
   
    // remove any widget instances for this widget
    IWidgetInstance[] instances = persistenceManager.findByValue(IWidgetInstance.class, "widget", widget)
    for(IWidgetInstance instance : instances){
     
      // Delete all participants and shared data associated with any instances
      //
      // Note that we don't call this within WidgetInstanceFactory.destroy() as
      // if called in a different context (to remove just one instance) it would
      // have the side effect of deleting participants and shared data from other instances,
      // not just the one being deleted.
      //
      // Note also that we have to use the instance as the hook for removing participants as there is no
      // specific query for getting participants for a widget.
      //           
      IParticipant[] participants = persistenceManager.findParticipants(instance);
      persistenceManager.delete(participants);
          ISharedData[] sharedData =  SharedDataHelper.findSharedData(instance);
          persistenceManager.delete(sharedData);
         
      // remove any preferences
      IPreference[] preferences = persistenceManager.findByValue(IPreference.class, "widgetInstance", instance);
      persistenceManager.delete(preferences);
     
      // remove the instance
      WidgetInstanceFactory.destroy(instance);
     
    }

    // remove any AccessRequests
        IAccessRequest[] accessRequests = persistenceManager.findByValue(IAccessRequest.class, "widget", widget);
        persistenceManager.delete(accessRequests);
       
    // remove the widget itself
    persistenceManager.delete(widget);
    return true;
  }
View Full Code Here

   * @param model the updated widget model
   * @param widget the existing widget
   * @param grantAccessRequests set to true to grant any access requests defined by the model
   */
  public static void update( W3CWidget model, IWidget widget,  boolean grantAccessRequests, File zipFile){
      IPersistenceManager persistenceManager = PersistenceManagerFactory.getPersistenceManager();
    
    widget.setDir(model.getDir());
        widget.setLang(model.getLang());
        widget.setDefaultLocale(model.getDefaultLocale());
    widget.setGuid(model.getIdentifier());
    widget.setHeight(model.getHeight());
    widget.setWidth(model.getWidth());
    widget.setVersion(model.getVersion());
    widget.setUpdateLocation(model.getUpdate());
   
    // Clear old values
    widget.setStartFiles(null);
    widget.setNames(null);
    widget.setDescriptions(null);
    widget.setLicenses(null);
    widget.setFeatures(null)
    widget.setWidgetIcons(null);
    widget.setPreferenceDefaults(null);
    // We set this here to ensure widgets already imported in to
    // a 0.9.0 version of wookie get this value set. See WOOKIE-256
      if(zipFile != null){
        widget.setPackagePath(zipFile.getPath());
      }
    // Set with updated values
    createAuthor(persistenceManager, model,widget);
    createStartFiles(persistenceManager, model,widget);
    createNames(persistenceManager, model,widget);
    createDescriptions(persistenceManager, model,widget);
    createIcons(persistenceManager, model, widget);
    createLicenses(persistenceManager, model,widget);   
    createPreferences(persistenceManager, model,widget);
    createFeatures(persistenceManager, model,widget);
        persistenceManager.save(widget);
    createAccessRequests(persistenceManager, model, widget, grantAccessRequests);
  }
View Full Code Here

  @Override
  public void show(String resourceId,HttpServletRequest request, HttpServletResponse response) throws UnauthorizedAccessException,ResourceNotFoundException, IOException{
    if (!WidgetKeyManager.isValidRequest(request)) throw new UnauthorizedAccessException();
    IWidgetInstance instance = WidgetInstancesController.findWidgetInstance(request);
    if (instance == null) throw new ResourceNotFoundException();
    IPersistenceManager persistenceManager = PersistenceManagerFactory.getPersistenceManager();
    IParticipant[] participants = persistenceManager.findParticipants(instance);
    returnXml(ParticipantHelper.createXMLParticipantsDocument(participants), response);
  }
View Full Code Here

  public static boolean addParticipantToWidgetInstance(IWidgetInstance instance,
      String participantId, String participantDisplayName,
      String participantThumbnailUrl) {

    // Does participant already exist?
        IPersistenceManager persistenceManager = PersistenceManagerFactory.getPersistenceManager();
    Map<String, Object> map = new HashMap<String, Object>();
    map.put("sharedDataKey", SharedDataHelper.getInternalSharedDataKey(instance));//$NON-NLS-1$
    map.put("participantId", participantId);//$NON-NLS-1$
    if (persistenceManager.findByValues(IParticipant.class, map).length != 0) return false;   

    // Add participant
    IParticipant participant = persistenceManager.newInstance(IParticipant.class);
    participant.setParticipantId(participantId);
    participant.setParticipantDisplayName(participantDisplayName);
    participant.setParticipantThumbnailUrl(participantThumbnailUrl);
    participant.setSharedDataKey(SharedDataHelper.getInternalSharedDataKey(instance));
    persistenceManager.save(participant);
    return true;
  }
View Full Code Here

   */
  private static boolean removeParticipantFromWidgetInstance(IWidgetInstance instance,
      String participantId) {
    IParticipant[] participants;
    // Does participant exist?
        IPersistenceManager persistenceManager = PersistenceManagerFactory.getPersistenceManager();
    Map<String, Object> map = new HashMap<String, Object>();
    map.put("sharedDataKey", SharedDataHelper.getInternalSharedDataKey(instance));//$NON-NLS-1$
    map.put("participantId", participantId);//$NON-NLS-1$
    participants = persistenceManager.findByValues(IParticipant.class, map);
    if (participants.length != 1) return false
    // Remove participant
    persistenceManager.delete(participants[0]);
    return true;
  }
View Full Code Here

   * @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

   * @param append
   * @return
   */
  public synchronized static boolean updateSharedDataEntry(IWidgetInstance widgetInstance, String name, String value, boolean append){
    IWidget widget = widgetInstance.getWidget();
        IPersistenceManager persistenceManager = PersistenceManagerFactory.getPersistenceManager();
        boolean found=false;
        ISharedData sharedData = SharedDataHelper.findSharedData(widgetInstance, name);
        if (sharedData != null)
        {
            if(value==null || value.equalsIgnoreCase("null")){
              persistenceManager.delete(sharedData);
            }
            else{   
                if(append){
                    sharedData.setDvalue(sharedData.getDvalue() + value);
                }
                else{
                    sharedData.setDvalue(value);
                }
            }
            found=true;
        }
    if(!found){    
      if(value!=null){
        String sharedDataKey = SharedDataHelper.getInternalSharedDataKey(widgetInstance);   
        sharedData = persistenceManager.newInstance(ISharedData.class);
        sharedData.setSharedDataKey(sharedDataKey);
        sharedData.setDkey(name);
        sharedData.setDvalue(value);
        persistenceManager.save(sharedData);
      }
    }
        persistenceManager.save(widget);
        return found;
  }
View Full Code Here

      IOException {

    IAccessRequest[] accessRequests = null;
   
    String widgetId = request.getParameter("widgetId");
        IPersistenceManager persistenceManager = PersistenceManagerFactory.getPersistenceManager();
        if (widgetId == null){
            accessRequests = persistenceManager.findAll(IAccessRequest.class);
        }
    if (widgetId != null && widgetId.trim().length()>0){
      // Filter by widgetId
      IWidget widget = persistenceManager.findById(IWidget.class, widgetId);
            if (widget != null) accessRequests = persistenceManager.findByValue(IAccessRequest.class, "widget", widget);
    }
   
    switch (format(request)) {
      case XML: returnXml(AccessRequestHelper.createXMLAccessRequestDocument(accessRequests),response);break;
      case HTML: returnHtml(AccessRequestHelper.createAccessRequestHTMLTable(accessRequests),response);break;
View Full Code Here

  @Override
  protected void show(String resourceId, HttpServletRequest request,
      HttpServletResponse response) throws ResourceNotFoundException,
      UnauthorizedAccessException, IOException {
        IPersistenceManager persistenceManager = PersistenceManagerFactory.getPersistenceManager();
    IAccessRequest ar = persistenceManager.findById(IAccessRequest.class, resourceId);
    if (ar == null) throw new ResourceNotFoundException();
   
    switch (format(request)) {
      case XML: returnXml(AccessRequestHelper.createXMLAccessRequestDocument(new IAccessRequest[]{ar}),response);break;
      case HTML: returnHtml(AccessRequestHelper.createAccessRequestHTMLTable(new IAccessRequest[]{ar}),response);break;
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.