Package org.apache.wookie.beans.util

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


        IPersistenceManager persistenceManager = PersistenceManagerFactory.getPersistenceManager();
    request.setAttribute("services", persistenceManager.findAll(IWidgetService.class));             //$NON-NLS-1$
  }

  private void retrieveWidgets(HttpServletRequest request){
        IPersistenceManager persistenceManager = PersistenceManagerFactory.getPersistenceManager();
    request.setAttribute("widgets", persistenceManager.findAll(IWidget.class)); //$NON-NLS-1$
  }
View Full Code Here


      return;
    }

    try
      if(zipFile.exists()){
                IPersistenceManager persistenceManager = PersistenceManagerFactory.getPersistenceManager();
        final String[] locales = properties.getStringArray("widget.locales");
        W3CWidgetFactory fac = new W3CWidgetFactory();
        fac.setLocales(locales);
        fac.setLocalPath(getServletContext().getContextPath()+properties.getString("widget.widgetfolder"));
        fac.setOutputDirectory(WIDGETFOLDER);
        fac.setFeatures(Features.getFeatureNames());
        fac.setStartPageProcessor(new StartPageProcessor());
        W3CWidget widgetModel = fac.parse(zipFile);
        WidgetJavascriptSyntaxAnalyzer jsa = new WidgetJavascriptSyntaxAnalyzer(fac.getUnzippedWidgetDirectory());       
              if(persistenceManager.findWidgetByGuid(widgetModel.getIdentifier()) == null){
          // ADD
          IWidget widget = WidgetFactory.addNewWidget(widgetModel, null, zipFile, false);
          Object dbkey = widget.getId();
          // widget added
          request.setAttribute("message_value", "'"+ widgetModel.getLocalName("en") +"' - " + localizedMessages.getString("WidgetAdminServlet.19")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$         
          retrieveServices(request);
          request.setAttribute("hasValidated", Boolean.valueOf(true));                                   //$NON-NLS-1$
          request.setAttribute("dbkey", dbkey); //$NON-NLS-1$
       
        else{
          // UPDATE
          // Update the widget metadata and configuration details
          WidgetFactory.update(widgetModel, persistenceManager.findWidgetByGuid(widgetModel.getIdentifier()), false, zipFile);
          request.setAttribute("message_value", "'"+ widgetModel.getLocalName("en") +"' - " + localizedMessages.getString("WidgetAdminServlet.20")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$         
        }
      }
      else{
        // no file found to be uploaded - shouldn't happen
View Full Code Here

  private static void migrateSharedDataKeys(String oldKey, String newKey){

    //
    // Locate instances using the old key and migrate to the new key
    //
    IPersistenceManager persistenceManager = PersistenceManagerFactory.getPersistenceManager();
    IWidgetInstance[] widgetInstances = persistenceManager.findByValue(IWidgetInstance.class, "sharedDataKey", oldKey);
    for (IWidgetInstance widgetInstance:widgetInstances){
      widgetInstance.setSharedDataKey(newKey);
      persistenceManager.save(widgetInstance);
    }

    //
    // locate shared data objects using the old key and migrate to the new key
    //
    ISharedData[] sharedDataItems = persistenceManager.findByValue(ISharedData.class, "sharedDataKey", oldKey);
    for (ISharedData sharedData: sharedDataItems){
      sharedData.setSharedDataKey(newKey);
      persistenceManager.save(sharedData);
    }
   
    _logger.debug("upgraded widget instances and shared data from 0.9.0. Old key:"+oldKey+" . New key:"+newKey+". "+widgetInstances.length+" widget instances  and "+sharedDataItems.length+" shared data objects updated.");
  }
View Full Code Here

   * @return
   */
  private static String toXml(IWidgetService service, String localIconPath, boolean defaults, String[] locales){
    String out = "\n<service name=\""+service.getServiceName()+"\">\n";
    IWidget[] widgets;
    IPersistenceManager persistenceManager = PersistenceManagerFactory.getPersistenceManager();
    if (defaults){
       widgets = new IWidget[]{persistenceManager.findWidgetDefaultByType(service.getServiceName())};
    } else {
      widgets = persistenceManager.findWidgetsByType(service.getServiceName());
    }
    for (IWidget widget:widgets) out += WidgetHelper.toXml(widget, localIconPath, locales);
    out +="</service>\n";
    return out;
  }
View Full Code Here

  protected void show(String resourceId, HttpServletRequest request,
      HttpServletResponse response) throws ResourceNotFoundException,
      UnauthorizedAccessException, IOException {
    // attempt to get specific widget by id; note that this is the internal
    // widget integer ID and not the widget URI
    IPersistenceManager persistenceManager = PersistenceManagerFactory.getPersistenceManager();
    IWidget widget = persistenceManager.findById(IWidget.class, resourceId);
    if (widget == null) throw new ResourceNotFoundException();
    // redirect to the UDD
    if (widget.getUpdateLocation() ==  null) throw new ResourceNotFoundException();
    response.sendRedirect(widget.getUpdateLocation());
  }
View Full Code Here

      UnauthorizedAccessException {
      // Check to see if we're requiring updates over HTTPS - if not output a warning
      boolean onlyUseHttps = Boolean.parseBoolean(request.getParameter("use-https"));
      if (!onlyUseHttps) _logger.warn("checking for updates using non-secure method");
      // Get all installed widgets
      IPersistenceManager persistenceManager = PersistenceManagerFactory.getPersistenceManager();
      IWidget[] widgets = persistenceManager.findAll(IWidget.class);
      // Create a W3CWidget factory for the current context
      W3CWidgetFactory factory  = getFactory(request.getSession().getServletContext());
      // Iterate over the widgets and attempt to install updates
      for (IWidget widget: widgets){
        try {
View Full Code Here

  @Override
  protected void update(String resourceId, HttpServletRequest request)
      throws ResourceNotFoundException, InvalidParametersException,
      UnauthorizedAccessException {
      // attempt to get specific widget by id
      IPersistenceManager persistenceManager = PersistenceManagerFactory.getPersistenceManager();
      IWidget widget = persistenceManager.findById(IWidget.class, resourceId);
      if (widget == null) throw new ResourceNotFoundException();
      // FIXME localize error messages
      try {
        W3CWidgetFactory factory  = getFactory(request.getSession().getServletContext());
        installUpdate(factory, widget, false);
View Full Code Here

         WgtWatcher watcher = new WgtWatcher();
         watcher.setWatchDir(deploy);
         watcher.setListener(new WgtWatcher.FileChangeListener(){
           public void fileModified(File f) {
                 // get persistence manager for this thread
                        IPersistenceManager persistenceManager = PersistenceManagerFactory.getPersistenceManager();
             try{
               persistenceManager.begin();
               File upload = WidgetFileUtils.dealWithDroppedFile(UPLOADFOLDER, f);
               W3CWidgetFactory fac = new W3CWidgetFactory();
               fac.setLocales(locales);
               fac.setLocalPath(contextPath+localWidgetFolderPath);
               fac.setOutputDirectory(WIDGETFOLDER);
               fac.setFeatures(Features.getFeatureNames());
               fac.setStartPageProcessor(new StartPageProcessor());
               W3CWidget model = fac.parse(upload);
               WidgetJavascriptSyntaxAnalyzer jsa = new WidgetJavascriptSyntaxAnalyzer(fac.getUnzippedWidgetDirectory());
               if(persistenceManager.findWidgetByGuid(model.getIdentifier()) == null) {
                 WidgetFactory.addNewWidget(model, null, upload, true)
                 String message = model.getLocalName("en") +"' - " + localizedMessages.getString("WidgetAdminServlet.19");
                 _logger.info(message);
                 FlashMessage.getInstance().message(message);
               } else {
                 String message = model.getLocalName("en") +"' - " + localizedMessages.getString("WidgetAdminServlet.20");
                 WidgetFactory.update(model, persistenceManager.findWidgetByGuid(model.getIdentifier()), true, upload);
                 _logger.info(message);
                 FlashMessage.getInstance().message(message);
               }
               persistenceManager.commit();
             } catch (IOException e) {
                            persistenceManager.rollback();
               String error = f.getName()+":"+localizedMessages.getString("WidgetHotDeploy.1") + " - " + e.getLocalizedMessage();
               FlashMessage.getInstance().error(error);
               _logger.error(error, e);
             } catch (BadWidgetZipFileException e) {
                            persistenceManager.rollback();
               String error = f.getName()+":"+localizedMessages.getString("WidgetHotDeploy.2") + " - " + e.getLocalizedMessage();
               FlashMessage.getInstance().error(error);
               _logger.error(error, e);
             } catch (BadManifestException e) {
                            persistenceManager.rollback();
               String error = f.getName()+":"+localizedMessages.getString("WidgetHotDeploy.3") + " - " + e.getLocalizedMessage();
               FlashMessage.getInstance().error(error);
               _logger.error(error, e);
             } catch (Exception e) {
                            persistenceManager.rollback();
               String error = f.getName()+":"+e.getLocalizedMessage();
               FlashMessage.getInstance().error(error);
               _logger.error(error, e);
            } finally {
                    // close thread persistence manager
View Full Code Here

   * @return a list containing all the updates available.
   */
  public List<UpdateInformation> getAllUpdates(){
    ArrayList<UpdateInformation> updates = new ArrayList<UpdateInformation>();
    // Get all installed widgets
    IPersistenceManager persistenceManager = PersistenceManagerFactory.getPersistenceManager();
    IWidget[] widgets = persistenceManager.findAll(IWidget.class);
    for (IWidget widget: widgets){
      // Check for a valid update document; if there is one, create a new UpdateInformation object and add to list
      UpdateDescriptionDocument udd = UpdateUtils.checkForUpdate(widget.getUpdateLocation(), widget.getVersion());
      if (udd != null){
        UpdateInformation info = new UpdateInformation();
View Full Code Here

    String name = request.getParameter("name");
    if (name == null || name.trim().equals("")) throw new InvalidParametersException();
    IWidgetService ws = getWidgetService(resourceId);
    if (ws == null) throw new ResourceNotFoundException();
    ws.setServiceName(name);
    IPersistenceManager persistenceManager = PersistenceManagerFactory.getPersistenceManager();
    persistenceManager.save(ws);
  }
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.