예제 #1
0
  /**
   * Cleans repository data from database.
   *
   * @param rEntry the repository configuration
   * @throws DBCleanException
   */
  public static void cleanRepositoryData(RepositoryEntry rEntry) throws DBCleanException {
    SecurityHelper.validateSecurityPermission(JCRRuntimePermissions.MANAGE_REPOSITORY_PERMISSION);

    WorkspaceEntry wsEntry = rEntry.getWorkspaceEntries().get(0);

    boolean multiDB = getMultiDbParameter(wsEntry);
    if (multiDB) {
      for (WorkspaceEntry entry : rEntry.getWorkspaceEntries()) {
        cleanWorkspaceData(entry);
      }
    } else {
      Connection jdbcConn = getConnection(wsEntry);
      String dialect = resolveDialect(jdbcConn, wsEntry);
      boolean autoCommit = dialect.startsWith(DialectConstants.DB_DIALECT_SYBASE);

      try {
        jdbcConn.setAutoCommit(autoCommit);

        DBCleanerTool dbCleaner = getRepositoryDBCleaner(jdbcConn, rEntry);
        doClean(dbCleaner);
      } catch (SQLException e) {
        throw new DBCleanException(e);
      } finally {
        try {
          jdbcConn.close();
        } catch (SQLException e) {
          LOG.error("Can not close connection", e);
        }
      }
    }
  }
  /** {@inheritDoc} */
  public void start() {
    configuredTemplates_ = new HashMap<String, Set<String>>();
    RepositoryEntry repositoryEntry = null;
    try {
      repositoryEntry = repositoryService.getCurrentRepository().getConfiguration();
    } catch (RepositoryException e) {
      if (LOG.isErrorEnabled()) {
        LOG.error(e.getMessage(), e);
      }
    }

    String repoName = repositoryEntry.getName();
    String workspaceName = repositoryEntry.getSystemWorkspaceName();
    storedWorkspaces.put(repoName, workspaceName);
    basedApplicationTemplatesPath = hierarchyCreator.getJcrPath(BasePath.CMS_VIEWTEMPLATES_PATH);

    SessionProvider sessionProvider = SessionProvider.createSystemProvider();
    for (Iterator<String> repositories = storedWorkspaces.keySet().iterator();
        repositories.hasNext(); ) {
      String repository = repositories.next();
      try {
        Node storedTemplateHome = getBasedApplicationTemplatesHome(sessionProvider);
        importPredefinedTemplateToDB(storedTemplateHome);
      } catch (Exception e) {
        if (LOG.isErrorEnabled()) {
          LOG.error(
              "Exception when import predefine application template into repository: " + repository,
              e);
        }
      }
    }
    sessionProvider.close();
  }
예제 #3
0
 /**
  * This method will re-observer all nodes that have been ever observed with all repositories.
  *
  * @throws Exception
  */
 private void reInitObserver() throws Exception {
   RepositoryEntry repo = repoService_.getCurrentRepository().getConfiguration();
   ManageableRepository repository = repoService_.getCurrentRepository();
   String[] workspaceNames = repository.getWorkspaceNames();
   for (String workspace : workspaceNames) {
     Session session = repository.getSystemSession(workspace);
     QueryManager queryManager = null;
     try {
       queryManager = session.getWorkspace().getQueryManager();
     } catch (Exception e) {
       if (LOG.isErrorEnabled()) {
         LOG.error("Unexpected error", e);
       }
     }
     if (queryManager == null) {
       session.logout();
       continue;
     }
     try {
       Query query = queryManager.createQuery(WATCHABLE_MIXIN_QUERY, Query.XPATH);
       QueryResult queryResult = query.execute();
       for (NodeIterator iter = queryResult.getNodes(); iter.hasNext(); ) {
         Node observedNode = iter.nextNode();
         EmailNotifyListener emailNotifyListener = new EmailNotifyListener(observedNode);
         ObservationManager manager = session.getWorkspace().getObservationManager();
         List<String> list = getDocumentNodeTypes(observedNode);
         String[] observedNodeTypeNames = list.toArray(new String[list.size()]);
         manager.addEventListener(
             emailNotifyListener,
             Event.PROPERTY_CHANGED,
             observedNode.getPath(),
             true,
             null,
             observedNodeTypeNames,
             false);
       }
       session.logout();
     } catch (Exception e) {
       if (LOG.isWarnEnabled()) {
         LOG.warn(
             "==>>> Cannot init observer for node: "
                 + e.getLocalizedMessage()
                 + " in '"
                 + repo.getName()
                 + "' repository");
       }
       if (LOG.isErrorEnabled()) {
         LOG.error("Unexpected error", e);
       }
     }
   }
 }
예제 #4
0
  private void registerWorkspacesComponents()
      throws RepositoryException, RepositoryConfigurationException {
    // System workspace should be first initialized.
    for (WorkspaceEntry we : config.getWorkspaceEntries()) {
      if (we.getName().equals(config.getSystemWorkspaceName())) {
        registerWorkspace(we);
      }
    }

    // Initialize other (non system) workspaces.
    for (WorkspaceEntry we : config.getWorkspaceEntries()) {
      if (!we.getName().equals(config.getSystemWorkspaceName())) {
        registerWorkspace(we);
      }
    }
  }
예제 #5
0
  private void initAllWorkspaceComponentEntries(ExoContainer parent) {
    SystemParametersPersistenceConfigurator sppc =
        (SystemParametersPersistenceConfigurator)
            parent.getComponentInstanceOfType(SystemParametersPersistenceConfigurator.class);

    for (WorkspaceEntry workspaceEntry : config.getWorkspaceEntries()) {
      initWorkspaceComponentEntries(sppc, workspaceEntry);
    }
  }
예제 #6
0
  /**
   * RepositoryContainer constructor.
   *
   * @param parent container
   * @param config Repository configuration
   * @param addNamespacePlugins list of addNamespacePlugin
   * @throws RepositoryException container initialization error
   * @throws RepositoryConfigurationException configuration error
   * @throws PrivilegedActionException
   */
  public RepositoryContainer(
      final ExoContainer parent, RepositoryEntry config, List<ComponentPlugin> addNamespacePlugins)
      throws RepositoryException, RepositoryConfigurationException {

    super(new MX4JComponentAdapterFactory(), parent);

    // Defaults:
    if (config.getAccessControl() == null) config.setAccessControl(AccessControlPolicy.OPTIONAL);

    this.config = config;
    this.addNamespacePlugins = addNamespacePlugins;
    this.name = config.getName();

    try {
      SecurityHelper.doPrivilegedExceptionAction(
          new PrivilegedExceptionAction<Void>() {
            public Void run() throws RepositoryConfigurationException {
              context.setName(parent.getContext().getName() + "-" + name);
              try {
                parent.registerComponentInstance(name, RepositoryContainer.this);
                initAllWorkspaceComponentEntries(parent);
                registerComponents();
              } catch (Throwable t) // NOSONAR
              {
                unregisterAllComponents();
                parent.unregisterComponent(name);
                throw new RepositoryConfigurationException(
                    "Can not register repository container " + name + " in parent container.", t);
              }
              return null;
            }
          });
    } catch (PrivilegedActionException e) {
      Throwable ex = e.getCause();
      if (ex instanceof RepositoryConfigurationException) {
        throw (RepositoryConfigurationException) ex;
      } else {
        throw new RepositoryConfigurationException(ex.getMessage(), ex);
      }
    }
  }
예제 #7
0
  /**
   * Initialize worspaces (root node and jcr:system for system workspace).
   *
   * <p>Runs on container start.
   *
   * @throws RepositoryException
   * @throws RepositoryConfigurationException
   */
  private void init() throws RepositoryException, RepositoryConfigurationException {
    List<WorkspaceEntry> wsEntries = config.getWorkspaceEntries();

    NodeTypeDataManager typeManager =
        (NodeTypeDataManager) this.getComponentInstanceOfType(NodeTypeDataManager.class);
    NamespaceRegistryImpl namespaceRegistry =
        (NamespaceRegistryImpl) this.getComponentInstanceOfType(NamespaceRegistry.class);

    for (WorkspaceEntry ws : wsEntries) {
      initWorkspace(ws);
      WorkspaceContainer workspaceContainer = getWorkspaceContainer(ws.getName());
      SearchManager searchManager =
          (SearchManager) workspaceContainer.getComponentInstanceOfType(SearchManager.class);
      //         if (searchManager != null)
      //         {
      //            typeManager.addQueryHandler(searchManager.getHandler());
      //            namespaceRegistry.addQueryHandler(searchManager.getHandler());
      //         }
      //         else
      //         {
      //            log.warn("Search manager not configured for " + ws.getName());
      //         }
    }

    SystemSearchManagerHolder searchManager =
        (SystemSearchManagerHolder)
            this.getComponentInstanceOfType(SystemSearchManagerHolder.class);
    //      if (searchManager != null)
    //      {
    //         typeManager.addQueryHandler(searchManager.get().getHandler());
    //         namespaceRegistry.addQueryHandler(searchManager.get().getHandler());
    //      }
    //      else
    //      {
    //         log.warn("System search manager not configured ");
    //      }

  }
예제 #8
0
  /**
   * Returns database cleaner for repository.
   *
   * @param jdbcConn database connection which need to use
   * @param rEntry repository configuration
   * @return DBCleanerTool
   * @throws DBCleanException
   */
  public static DBCleanerTool getRepositoryDBCleaner(Connection jdbcConn, RepositoryEntry rEntry)
      throws DBCleanException {
    SecurityHelper.validateSecurityPermission(JCRRuntimePermissions.MANAGE_REPOSITORY_PERMISSION);

    WorkspaceEntry wsEntry = rEntry.getWorkspaceEntries().get(0);

    boolean multiDb = getMultiDbParameter(wsEntry);
    if (multiDb) {
      throw new DBCleanException(
          "It is not possible to create cleaner with common connection for multi database repository configuration");
    }

    String dialect = resolveDialect(jdbcConn, wsEntry);
    boolean autoCommit = dialect.startsWith(DialectConstants.DB_DIALECT_SYBASE);

    DBCleaningScripts scripts = DBCleaningScriptsFactory.prepareScripts(dialect, rEntry);

    return new DBCleanerTool(
        jdbcConn,
        autoCommit,
        scripts.getCleaningScripts(),
        scripts.getCommittingScripts(),
        scripts.getRollbackingScripts());
  }
예제 #9
0
 /**
  * Get workspace configuration entry by name.
  *
  * @param wsName workspace name
  * @return WorkspaceEntry
  */
 public WorkspaceEntry getWorkspaceEntry(String wsName) {
   for (WorkspaceEntry entry : config.getWorkspaceEntries()) {
     if (entry.getName().equals(wsName)) return entry;
   }
   return null;
 }