exo-jcr SVN: r3227 - kernel/branches/2.2.4-GA-perf/exo.kernel.commons/src/main/java/org/exoplatform/commons/utils.
by do-not-reply@jboss.org
Author: julien_viet
Date: 2010-09-30 11:29:38 -0400 (Thu, 30 Sep 2010)
New Revision: 3227
Modified:
kernel/branches/2.2.4-GA-perf/exo.kernel.commons/src/main/java/org/exoplatform/commons/utils/MapResourceBundle.java
Log:
TESTFR-11: Intern strings in MapResourceBundle
Modified: kernel/branches/2.2.4-GA-perf/exo.kernel.commons/src/main/java/org/exoplatform/commons/utils/MapResourceBundle.java
===================================================================
--- kernel/branches/2.2.4-GA-perf/exo.kernel.commons/src/main/java/org/exoplatform/commons/utils/MapResourceBundle.java 2010-09-30 14:58:48 UTC (rev 3226)
+++ kernel/branches/2.2.4-GA-perf/exo.kernel.commons/src/main/java/org/exoplatform/commons/utils/MapResourceBundle.java 2010-09-30 15:29:38 UTC (rev 3227)
@@ -25,8 +25,6 @@
import java.util.Locale;
import java.util.Map;
import java.util.ResourceBundle;
-import java.util.Set;
-import java.util.Vector;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -36,41 +34,43 @@
public class MapResourceBundle extends ResourceBundle implements Serializable
{
- private final static String REGEXP = "#\\{.*\\}";
+ private final static Pattern PATTERN = Pattern.compile("#\\{.*\\}");
- private Map props = new HashMap();
+ private Map<String, String> props;
private Locale locale;
public MapResourceBundle(Locale l)
{
this.locale = l;
+ this.props = new HashMap<String, String>();
}
public MapResourceBundle(ResourceBundle rB, Locale l)
{
+ Map<String, String> props = new HashMap<String, String>();
+ doMerge(props, rB);
+
+ //
this.locale = l;
- initMap(rB);
+ this.props = props;
}
- private void initMap(ResourceBundle rB)
+ private static void doMerge(Map<String, String> props, ResourceBundle rB)
{
- Enumeration e = rB.getKeys();
+ Enumeration<String> e = rB.getKeys();
while (e.hasMoreElements())
{
- String s = (String)e.nextElement();
- try
+ String key = e.nextElement();
+ if (props.get(key) == null)
{
- if (props.get(s) == null)
+ Object o = rB.getObject(key);
+ if (o instanceof String)
{
- String[] newArray = rB.getStringArray(s);
- props.put(s, newArray);
+ String value = (String)o;
+ props.put(key.intern(), value.intern());
}
}
- catch (ClassCastException ex)
- {
- props.put(s, rB.getObject(s));
- }
}
}
@@ -79,9 +79,20 @@
return props.get(key);
}
- public Enumeration getKeys()
+ public Enumeration<String> getKeys()
{
- return new Vector(props.keySet()).elements();
+ final Iterator<String> i = props.keySet().iterator();
+ return new Enumeration<String>()
+ {
+ public boolean hasMoreElements()
+ {
+ return i.hasNext();
+ }
+ public String nextElement()
+ {
+ return i.next();
+ }
+ };
}
public Locale getLocale()
@@ -89,69 +100,63 @@
return this.locale;
}
- public void add(String key, Object value)
+ public void add(String key, Object o)
{
- props.put(key, value);
+ if (key != null && o instanceof String)
+ {
+ String value = (String)o;
+ props.put(key.intern(), value.intern());
+ }
}
public void remove(String key)
{
- props.remove(key);
+ if (key != null)
+ {
+ props.remove(key);
+ }
}
public void merge(ResourceBundle bundle)
{
- Enumeration e = bundle.getKeys();
- while (e.hasMoreElements())
- {
- String s = (String)e.nextElement();
- Object value = bundle.getObject(s);
- try
- {
- String[] newArray = bundle.getStringArray(s);
- if (props.get(s) == null)
- {
- props.put(s, newArray);
- }
- }
- catch (ClassCastException ex)
- {
- props.put(s, value);
- }
- }
+ doMerge(props, bundle);
}
public void resolveDependencies()
{
- Map tempMap = new HashMap();
- Set keys = props.keySet();
- Pattern pattern = Pattern.compile(REGEXP);
- for (Iterator iter = keys.iterator(); iter.hasNext();)
+ Map<String, String> tempMap = new HashMap<String ,String>();
+ for (String element : props.keySet())
{
- String element = (String)iter.next();
- String value = lookupKey(element, pattern);
- tempMap.put(element, value);
+ String value = lookupKey(element);
+ if (value != null)
+ {
+ tempMap.put(element.intern(), value.intern());
+ }
}
props = tempMap;
}
- private String lookupKey(String key, Pattern pattern)
+ private String lookupKey(String key)
{
- String s = (String)props.get(key);
+ String s = props.get(key);
if (s == null)
+ {
return key;
- Matcher matcher = pattern.matcher(s);
+ }
+
+ //
+ Matcher matcher = PATTERN.matcher(s);
if (matcher.find())
{
- return recursivedResolving(s, pattern);
+ return recursivedResolving(s);
}
return s;
}
- private String recursivedResolving(String key, Pattern pattern)
+ private String recursivedResolving(String key)
{
String resolved = key;
- StringBuffer sB = new StringBuffer();
+ StringBuilder sB = new StringBuilder();
while (resolved.indexOf("#{") != -1)
{
sB.setLength(0);
@@ -159,7 +164,7 @@
int lastIndex = resolved.indexOf('}', firstIndex);
String realKey = resolved.substring(firstIndex + 2, lastIndex);
sB.append(resolved.substring(0, firstIndex));
- sB.append(lookupKey(realKey, pattern));
+ sB.append(lookupKey(realKey));
sB.append(resolved.substring(lastIndex + 1));
resolved = sB.toString();
}
13 years, 7 months
exo-jcr SVN: r3226 - jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl.
by do-not-reply@jboss.org
Author: areshetnyak
Date: 2010-09-30 10:58:48 -0400 (Thu, 30 Sep 2010)
New Revision: 3226
Modified:
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/BackupManagerImpl.java
Log:
EXOJCR-747 : Make backup restore easier implementation.
Modified: jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/BackupManagerImpl.java
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/BackupManagerImpl.java 2010-09-30 14:03:18 UTC (rev 3225)
+++ jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/BackupManagerImpl.java 2010-09-30 14:58:48 UTC (rev 3226)
@@ -106,34 +106,76 @@
protected static Log log = ExoLogger.getLogger("exo.jcr.component.ext.BackupManagerImpl");
+ /**
+ * Name of default incremental job period parameter in configuration.
+ */
private final static String DEFAULT_INCREMENTAL_JOB_PERIOD = "default-incremental-job-period";
+ /**
+ * Name of backup properties parameter in configuration.
+ */
private final static String BACKUP_PROPERTIES = "backup-properties";
+ /**
+ * Name of full backup type parameter in configuration.
+ */
private final static String FULL_BACKUP_TYPE = "full-backup-type";
+ /**
+ * Name of incremental backup type parameter in configuration.
+ */
private final static String INCREMENTAL_BACKUP_TYPE = "incremental-backup-type";
+ /**
+ * Name of backup dir parameter in configuration.
+ */
private final static String BACKUP_DIR = "backup-dir";
+ /**
+ * Backup messages log max. size.
+ */
private static final int MESSAGES_MAXSIZE = 5;
private static final String SERVICE_NAME = "BackupManager";
+ /**
+ * The timeout to checking finish of backup.
+ */
private static final long AUTO_STOPPER_TIMEOUT = 5000;
+ /**
+ * Value of default incremental job period.
+ */
private long defaultIncrementalJobPeriod;
+ /**
+ * Value of default incremental period.
+ */
private String defIncrPeriod;
+ /**
+ * Path to backup folder.
+ */
private String backupDir;
+ /**
+ * Value of full backup type.
+ */
private String fullBackupType;
+ /**
+ * Value of incremental backup type.
+ */
private String incrementalBackupType;
+ /**
+ * Set of current workspace backups.
+ */
private final Set<BackupChain> currentBackups;
+ /**
+ * Set of current repository backups.
+ */
private final Set<RepositoryBackupChain> currentRepositoryBackups;
/**
@@ -146,8 +188,14 @@
*/
private List<JobRepositoryRestore> restoreRepositoryJobs;
+ /**
+ * Initialization parameters of service.
+ */
private InitParams initParams;
+ /**
+ * Directory to log.
+ */
private File logsDirectory;
private final RepositoryService repoService;
13 years, 7 months
exo-jcr SVN: r3225 - jcr/trunk/exo.jcr.docs/exo.jcr.docs.developer/en/src/main/docbook/en-US/modules/jcr/backup.
by do-not-reply@jboss.org
Author: tolusha
Date: 2010-09-30 10:03:18 -0400 (Thu, 30 Sep 2010)
New Revision: 3225
Modified:
jcr/trunk/exo.jcr.docs/exo.jcr.docs.developer/en/src/main/docbook/en-US/modules/jcr/backup/exojcr-backup-service.xml
Log:
EXOJCR-747: fix wikibook
Modified: jcr/trunk/exo.jcr.docs/exo.jcr.docs.developer/en/src/main/docbook/en-US/modules/jcr/backup/exojcr-backup-service.xml
===================================================================
--- jcr/trunk/exo.jcr.docs/exo.jcr.docs.developer/en/src/main/docbook/en-US/modules/jcr/backup/exojcr-backup-service.xml 2010-09-30 14:02:07 UTC (rev 3224)
+++ jcr/trunk/exo.jcr.docs/exo.jcr.docs.developer/en/src/main/docbook/en-US/modules/jcr/backup/exojcr-backup-service.xml 2010-09-30 14:03:18 UTC (rev 3225)
@@ -483,13 +483,13 @@
restore of system workspace, than we need restore all repository.</para>
</highlights>
- <para>The resore of existed workspace or repositry is avaleble. </para>
+ <para>The resore of existed workspace or repositry is avaleble.</para>
<para>For restore will be used spacial methods:</para>
<programlisting> /**
* Restore existed workspace. Previous data will be deleted.
- * For getting status of workspace restore use can use
+ * For getting status of workspace restore can use
* BackupManager.getLastRestore(String repositoryName, String workspaceName) method
*
* @param workspaceBackupIdentifier
@@ -526,7 +526,7 @@
/**
* Restore existed repository. Previous data will be deleted.
- * For getting status of repository restore use can use
+ * For getting status of repository restore can use
* BackupManager.getLastRestore(String repositoryName) method
*
* @param repositoryBackupIdentifier
@@ -544,7 +544,7 @@
/**
* Restore existed repository. Previous data will be deleted.
- * For getting status of repository restore use can use
+ * For getting status of repository restore can use
* BackupManager.getLastRestore(String repositoryName) method
*
* @param log
@@ -584,87 +584,5 @@
<para>restore from backup.</para>
</listitem>
</itemizedlist>
-
- <example>
- <title>Make backup of workspace and restore it.</title>
-
- <para><programlisting> // backup
- File backDir = new File("target/backup/ws1");
- backDir.mkdirs();
-
- BackupConfig config = new BackupConfig();
- config.setRepository(repository.getName());
- config.setWorkspace("ws1");
- config.setBackupType(BackupManager.FULL_BACKUP_ONLY);
- config.setBackupDir(backDir);
-
- backup.startBackup(config);
-
- BackupChain bch = backup.findBackup(repository.getName(), "ws1");
-
- // wait till full backup will be stopped
- while (bch.getFullBackupState() != BackupJob.FINISHED)
- {
- Thread.yield();
- Thread.sleep(50);
- }
-
- // stop fullBackup
- backup.stopBackup(bch);
-
- // restore
- RepositoryEntry re = (RepositoryEntry)ws1Session.getContainer().getComponentInstanceOfType(RepositoryEntry.class);
- WorkspaceEntry ws1 = null;
- for (WorkspaceEntry we : re.getWorkspaceEntries())
- {
- if (ws1Session.getWorkspace().getName().equals(we.getName()))
- {
- ws1 = we;
- break;
- }
- }
-
- File backLog = new File(bch.getLogFilePath());
- BackupChainLog bchLog = new BackupChainLog(backLog);
-
- backup.restoreExistedWorkspace(bchLog, re.getName(), ws1, false);</programlisting></para>
- </example>
-
- <example>
- <title>Make backup of repository and restore it.</title>
-
- <para><programlisting> // backup
- File backDir = new File("target/backup");
- backDir.mkdirs();
-
- RepositoryBackupConfig config = new RepositoryBackupConfig();
- config.setRepository(repository.getName());
- config.setBackupType(BackupManager.FULL_BACKUP_ONLY);
- config.setBackupDir(backDir);
-
- backup.startBackup(config);
-
- RepositoryBackupChain bch = backup.findRepositoryBackup(repository.getName());
-
- // wait till full backup will be stopped
- while (bch.getState() != RepositoryBackupChain.FINISHED)
- {
- Thread.yield();
- Thread.sleep(50);
- }
-
- // stop fullBackup
- backup.stopBackup(bch);
-
- // restore
- RepositoryEntry baseRE =
- (RepositoryEntry)ws1Session.getContainer().getComponentInstanceOfType(RepositoryEntry.class);
- RepositoryEntry re = makeRepositoryEntry(baseRE.getName(), baseRE, null, null);
-
- File backLog = new File(bch.getLogFilePath());
- RepositoryBackupChainLog bchLog = new RepositoryBackupChainLog(backLog);
-
- backup.restoreExistedRepository(bchLog, re, false);</programlisting></para>
- </example>
</section>
</chapter>
13 years, 7 months
exo-jcr SVN: r3224 - jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup.
by do-not-reply@jboss.org
Author: tolusha
Date: 2010-09-30 10:02:07 -0400 (Thu, 30 Sep 2010)
New Revision: 3224
Modified:
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/ExtendedBackupManager.java
Log:
EXOJCR-747: fix javadoc
Modified: jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/ExtendedBackupManager.java
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/ExtendedBackupManager.java 2010-09-30 13:03:22 UTC (rev 3223)
+++ jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/ExtendedBackupManager.java 2010-09-30 14:02:07 UTC (rev 3224)
@@ -31,7 +31,7 @@
{
/**
* Restore existed workspace. Previous data will be deleted.
- * For getting status of workspace restore use can use
+ * For getting status of workspace restore can use
* BackupManager.getLastRestore(String repositoryName, String workspaceName) method
*
* @param workspaceBackupIdentifier
@@ -50,7 +50,7 @@
/**
* Restore existed workspace. Previous data will be deleted.
- * For getting status of workspace restore use can use
+ * For getting status of workspace restore can use
* BackupManager.getLastRestore(String repositoryName, String workspaceName) method
*
* @param log
@@ -68,7 +68,7 @@
/**
* Restore existed repository. Previous data will be deleted.
- * For getting status of repository restore use can use
+ * For getting status of repository restore can use
* BackupManager.getLastRestore(String repositoryName) method
*
* @param repositoryBackupIdentifier
@@ -86,7 +86,7 @@
/**
* Restore existed repository. Previous data will be deleted.
- * For getting status of repository restore use can use
+ * For getting status of repository restore can use
* BackupManager.getLastRestore(String repositoryName) method
*
* @param log
13 years, 7 months
exo-jcr SVN: r3223 - jcr/trunk/exo.jcr.docs/exo.jcr.docs.developer/en/src/main/docbook/en-US/modules/jcr/backup.
by do-not-reply@jboss.org
Author: areshetnyak
Date: 2010-09-30 09:03:22 -0400 (Thu, 30 Sep 2010)
New Revision: 3223
Modified:
jcr/trunk/exo.jcr.docs/exo.jcr.docs.developer/en/src/main/docbook/en-US/modules/jcr/backup/exojcr-backup-service.xml
Log:
EXOJCR-747 : Make backup restore easier documentation.
Modified: jcr/trunk/exo.jcr.docs/exo.jcr.docs.developer/en/src/main/docbook/en-US/modules/jcr/backup/exojcr-backup-service.xml
===================================================================
--- jcr/trunk/exo.jcr.docs/exo.jcr.docs.developer/en/src/main/docbook/en-US/modules/jcr/backup/exojcr-backup-service.xml 2010-09-30 11:43:34 UTC (rev 3222)
+++ jcr/trunk/exo.jcr.docs/exo.jcr.docs.developer/en/src/main/docbook/en-US/modules/jcr/backup/exojcr-backup-service.xml 2010-09-30 13:03:22 UTC (rev 3223)
@@ -474,4 +474,197 @@
operation cycle as the chainPeriod and incrementalPeriod will be applied
again. That behaviour may be changed in the future.</para>
</section>
+
+ <section>
+ <title>Restore existing workspace or repository</title>
+
+ <highlights>
+ <para>Restore of existed system workspace was not supported. When need
+ restore of system workspace, than we need restore all repository.</para>
+ </highlights>
+
+ <para>The resore of existed workspace or repositry is avaleble. </para>
+
+ <para>For restore will be used spacial methods:</para>
+
+ <programlisting> /**
+ * Restore existed workspace. Previous data will be deleted.
+ * For getting status of workspace restore use can use
+ * BackupManager.getLastRestore(String repositoryName, String workspaceName) method
+ *
+ * @param workspaceBackupIdentifier
+ * backup identifier
+ * @param workspaceEntry
+ * new workspace configuration
+ * @param asynchronous
+ * if 'true' restore will be in asynchronous mode (i.e. in separated thread)
+ * @throws BackupOperationException
+ * if backup operation exception occurred
+ * @throws BackupConfigurationException
+ * if configuration exception occurred
+ */
+ void restoreExistedWorkspace(String workspaceBackupIdentifier, String repositoryName, WorkspaceEntry workspaceEntry,
+ boolean asynchronous) throws BackupOperationException, BackupConfigurationException;
+
+ /**
+ * Restore existed workspace. Previous data will be deleted.
+ * For getting status of workspace restore use can use
+ * BackupManager.getLastRestore(String repositoryName, String workspaceName) method
+ *
+ * @param log
+ * workspace backup log
+ * @param workspaceEntry
+ * new workspace configuration
+ * @param asynchronous
+ * if 'true' restore will be in asynchronous mode (i.e. in separated thread)
+ * @throws BackupOperationException
+ * if backup operation exception occurred
+ * @throws BackupConfigurationException
+ * if configuration exception occurred
+ */
+ void restoreExistedWorkspace(BackupChainLog log, String repositoryName, WorkspaceEntry workspaceEntry, boolean asynchronous) throws BackupOperationException, BackupConfigurationException;
+
+ /**
+ * Restore existed repository. Previous data will be deleted.
+ * For getting status of repository restore use can use
+ * BackupManager.getLastRestore(String repositoryName) method
+ *
+ * @param repositoryBackupIdentifier
+ * backup identifier
+ * @param repositoryEntry
+ * new repository configuration
+ * @param asynchronous
+ * if 'true' restore will be in asynchronous mode (i.e. in separated thread)
+ * @throws BackupOperationException
+ * if backup operation exception occurred
+ * @throws BackupConfigurationException
+ * if configuration exception occurred
+ */
+ void restoreExistedRepository(String repositoryBackupIdentifier, RepositoryEntry repositoryEntry, boolean asynchronous) throws BackupOperationException, BackupConfigurationException;
+
+ /**
+ * Restore existed repository. Previous data will be deleted.
+ * For getting status of repository restore use can use
+ * BackupManager.getLastRestore(String repositoryName) method
+ *
+ * @param log
+ * repository backup log
+ * @param repositoryEntry
+ * new repository configuration
+ * @param asynchronous
+ * if 'true' restore will be in asynchronous mode (i.e. in separated thread)
+ * @throws BackupOperationException
+ * if backup operation exception occurred
+ * @throws BackupConfigurationException
+ * if configuration exception occurred
+ */
+ void restoreExistedRepository(RepositoryBackupChainLog log, RepositoryEntry repositoryEntry, boolean asynchronous)
+ throws BackupOperationException, BackupConfigurationException;</programlisting>
+
+ <para>These methods for restore will do:</para>
+
+ <itemizedlist>
+ <listitem>
+ <para>remove existed workspace or repository;</para>
+ </listitem>
+
+ <listitem>
+ <para>clean database;</para>
+ </listitem>
+
+ <listitem>
+ <para>clean index data;</para>
+ </listitem>
+
+ <listitem>
+ <para>clean value storage;</para>
+ </listitem>
+
+ <listitem>
+ <para>restore from backup.</para>
+ </listitem>
+ </itemizedlist>
+
+ <example>
+ <title>Make backup of workspace and restore it.</title>
+
+ <para><programlisting> // backup
+ File backDir = new File("target/backup/ws1");
+ backDir.mkdirs();
+
+ BackupConfig config = new BackupConfig();
+ config.setRepository(repository.getName());
+ config.setWorkspace("ws1");
+ config.setBackupType(BackupManager.FULL_BACKUP_ONLY);
+ config.setBackupDir(backDir);
+
+ backup.startBackup(config);
+
+ BackupChain bch = backup.findBackup(repository.getName(), "ws1");
+
+ // wait till full backup will be stopped
+ while (bch.getFullBackupState() != BackupJob.FINISHED)
+ {
+ Thread.yield();
+ Thread.sleep(50);
+ }
+
+ // stop fullBackup
+ backup.stopBackup(bch);
+
+ // restore
+ RepositoryEntry re = (RepositoryEntry)ws1Session.getContainer().getComponentInstanceOfType(RepositoryEntry.class);
+ WorkspaceEntry ws1 = null;
+ for (WorkspaceEntry we : re.getWorkspaceEntries())
+ {
+ if (ws1Session.getWorkspace().getName().equals(we.getName()))
+ {
+ ws1 = we;
+ break;
+ }
+ }
+
+ File backLog = new File(bch.getLogFilePath());
+ BackupChainLog bchLog = new BackupChainLog(backLog);
+
+ backup.restoreExistedWorkspace(bchLog, re.getName(), ws1, false);</programlisting></para>
+ </example>
+
+ <example>
+ <title>Make backup of repository and restore it.</title>
+
+ <para><programlisting> // backup
+ File backDir = new File("target/backup");
+ backDir.mkdirs();
+
+ RepositoryBackupConfig config = new RepositoryBackupConfig();
+ config.setRepository(repository.getName());
+ config.setBackupType(BackupManager.FULL_BACKUP_ONLY);
+ config.setBackupDir(backDir);
+
+ backup.startBackup(config);
+
+ RepositoryBackupChain bch = backup.findRepositoryBackup(repository.getName());
+
+ // wait till full backup will be stopped
+ while (bch.getState() != RepositoryBackupChain.FINISHED)
+ {
+ Thread.yield();
+ Thread.sleep(50);
+ }
+
+ // stop fullBackup
+ backup.stopBackup(bch);
+
+ // restore
+ RepositoryEntry baseRE =
+ (RepositoryEntry)ws1Session.getContainer().getComponentInstanceOfType(RepositoryEntry.class);
+ RepositoryEntry re = makeRepositoryEntry(baseRE.getName(), baseRE, null, null);
+
+ File backLog = new File(bch.getLogFilePath());
+ RepositoryBackupChainLog bchLog = new RepositoryBackupChainLog(backLog);
+
+ backup.restoreExistedRepository(bchLog, re, false);</programlisting></para>
+ </example>
+ </section>
</chapter>
13 years, 7 months
exo-jcr SVN: r3222 - jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl.
by do-not-reply@jboss.org
Author: tolusha
Date: 2010-09-30 07:43:34 -0400 (Thu, 30 Sep 2010)
New Revision: 3222
Added:
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/IndexCleanHelper.java
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/ValueStorageCleanHelper.java
Removed:
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/IndexCleanerService.java
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/ValueStorageCleanerService.java
Log:
EXOJCR-747: code cleanup
Added: jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/IndexCleanHelper.java
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/IndexCleanHelper.java (rev 0)
+++ jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/IndexCleanHelper.java 2010-09-30 11:43:34 UTC (rev 3222)
@@ -0,0 +1,83 @@
+/*
+ * Copyright (C) 2003-2010 eXo Platform SAS.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Affero General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see<http://www.gnu.org/licenses/>.
+ */
+package org.exoplatform.services.jcr.ext.backup.impl;
+
+import org.exoplatform.services.jcr.config.QueryHandlerParams;
+import org.exoplatform.services.jcr.config.RepositoryConfigurationException;
+import org.exoplatform.services.jcr.config.WorkspaceEntry;
+
+import java.io.File;
+import java.io.IOException;
+
+/**
+ * IndexCleanerService deliver tools for clean index data of workspace or repository.
+ *
+ * Created by The eXo Platform SAS.
+ *
+ * <br/>Date: 2010
+ *
+ * @author <a href="mailto:alex.reshetnyak@exoplatform.com.ua">Alex Reshetnyak</a>
+ * @version $Id: IndexCleanerService.java 3210 2010-09-28 12:01:50Z areshetnyak $
+ */
+public class IndexCleanHelper
+{
+ /**
+ * Remove all file of workspace index.
+ *
+ * @param wsConfig - workspace configuration.
+ * @param isSystem - 'true' to clean system workspace.
+ * @throws RepositoryConfigurationException - exception on parsing workspace configuration
+ * @throws IOException - exception on remove index folder
+ */
+ public void removeWorkspaceIndex(WorkspaceEntry wsConfig, boolean isSystem) throws RepositoryConfigurationException, IOException
+ {
+ String indexDir = wsConfig.getQueryHandler().getParameterValue(QueryHandlerParams.PARAM_INDEX_DIR);
+
+ removeFolder(new File(indexDir));
+
+ if (isSystem)
+ {
+ removeFolder(new File(indexDir + "_system"));
+ }
+ }
+
+ /**
+ * Remove folder
+ */
+ private void removeFolder(File dir) throws IOException
+ {
+ if (dir.isDirectory())
+ {
+ for (File subFile : dir.listFiles())
+ {
+ removeFolder(subFile);
+ }
+
+ if (!dir.delete())
+ {
+ throw new IOException("Index folder was not deleted : " + dir.getCanonicalPath());
+ }
+ }
+ else
+ {
+ if (!dir.delete())
+ {
+ throw new IOException("Index file was not deleted : " + dir.getCanonicalPath());
+ }
+ }
+ }
+}
Deleted: jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/IndexCleanerService.java
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/IndexCleanerService.java 2010-09-30 10:31:24 UTC (rev 3221)
+++ jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/IndexCleanerService.java 2010-09-30 11:43:34 UTC (rev 3222)
@@ -1,87 +0,0 @@
-/*
- * Copyright (C) 2003-2010 eXo Platform SAS.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Affero General Public License
- * as published by the Free Software Foundation; either version 3
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, see<http://www.gnu.org/licenses/>.
- */
-package org.exoplatform.services.jcr.ext.backup.impl;
-
-import java.io.File;
-import java.io.IOError;
-import java.io.IOException;
-
-import javax.jcr.RepositoryException;
-import javax.naming.NamingException;
-
-import org.exoplatform.services.jcr.config.QueryHandlerParams;
-import org.exoplatform.services.jcr.config.RepositoryConfigurationException;
-import org.exoplatform.services.jcr.config.WorkspaceEntry;
-
-/**
- * IndexCleanerService deliver tools for clean index data of workspace or repository.
- *
- * Created by The eXo Platform SAS.
- *
- * <br/>Date: 2010
- *
- * @author <a href="mailto:alex.reshetnyak@exoplatform.com.ua">Alex Reshetnyak</a>
- * @version $Id$
- */
-public class IndexCleanerService
-{
- /**
- * Remove all file of workspace index.
- *
- * @param wsConfig - workspace configuration.
- * @param isSystem - 'true' to clean system workspace.
- * @throws RepositoryConfigurationException - exception on parsing workspace configuration
- * @throws IOException - exception on remove index folder
- */
- public static void removeWorkspaceIndex(WorkspaceEntry wsConfig, boolean isSystem) throws RepositoryConfigurationException, IOException
- {
- String indexDir = wsConfig.getQueryHandler().getParameterValue(QueryHandlerParams.PARAM_INDEX_DIR);
-
- removeFolder(new File(indexDir));
-
- if (isSystem)
- {
- removeFolder(new File(indexDir + "_system"));
- }
- }
-
- /**
- * Remove folder
- */
- private static void removeFolder(File dir) throws IOException
- {
- if (dir.isDirectory())
- {
- for (File subFile : dir.listFiles())
- {
- removeFolder(subFile);
- }
-
- if (!dir.delete())
- {
- throw new IOException("Index folder was not deleted : " + dir.getCanonicalPath());
- }
- }
- else
- {
- if (!dir.delete())
- {
- throw new IOException("Index file was not deleted : " + dir.getCanonicalPath());
- }
- }
- }
-}
Added: jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/ValueStorageCleanHelper.java
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/ValueStorageCleanHelper.java (rev 0)
+++ jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/ValueStorageCleanHelper.java 2010-09-30 11:43:34 UTC (rev 3222)
@@ -0,0 +1,88 @@
+/*
+ * Copyright (C) 2003-2010 eXo Platform SAS.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Affero General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see<http://www.gnu.org/licenses/>.
+ */
+package org.exoplatform.services.jcr.ext.backup.impl;
+
+import org.exoplatform.services.jcr.config.ContainerEntry;
+import org.exoplatform.services.jcr.config.RepositoryConfigurationException;
+import org.exoplatform.services.jcr.config.ValueStorageEntry;
+import org.exoplatform.services.jcr.config.WorkspaceEntry;
+import org.exoplatform.services.jcr.impl.storage.value.fs.FileValueStorage;
+
+import java.io.File;
+import java.io.IOException;
+
+/**
+ * Created by The eXo Platform SAS.
+ *
+ * <br/>Date: 2010
+ *
+ * @author <a href="mailto:alex.reshetnyak@exoplatform.com.ua">Alex Reshetnyak</a>
+ * @version $Id: ValueStorageCleanerService.java 3219 2010-09-30 07:40:51Z areshetnyak $
+ */
+public class ValueStorageCleanHelper
+{
+
+ /**
+ * Clear workspace value storage.
+ *
+ * @param wEntry
+ * workspace configuration
+ * @throws RepositoryConfigurationException
+ * @throws IOException
+ */
+ public void removeWorkspaceValueStorage(WorkspaceEntry wEntry) throws RepositoryConfigurationException, IOException
+ {
+ ContainerEntry containerEntry = wEntry.getContainer();
+
+ if (containerEntry.getValueStorages() != null)
+ {
+ for (ValueStorageEntry valueStorageEntry : containerEntry.getValueStorages())
+ {
+ String path = valueStorageEntry.getParameterValue(FileValueStorage.PATH);
+
+ removeFolder(new File(path));
+ }
+ }
+ }
+
+ /**
+ * Remove folder
+ */
+ private void removeFolder(File dir) throws IOException
+ {
+ if (dir.isDirectory())
+ {
+ for (File subFile : dir.listFiles())
+ {
+ removeFolder(subFile);
+ }
+
+ if (!dir.delete())
+ {
+ throw new IOException("Value storage folder was not deleted : " + dir.getCanonicalPath());
+ }
+ }
+ else
+ {
+ if (!dir.delete())
+ {
+ throw new IOException("Value storage file was not deleted : " + dir.getCanonicalPath());
+ }
+ }
+ }
+
+}
Deleted: jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/ValueStorageCleanerService.java
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/ValueStorageCleanerService.java 2010-09-30 10:31:24 UTC (rev 3221)
+++ jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/ValueStorageCleanerService.java 2010-09-30 11:43:34 UTC (rev 3222)
@@ -1,80 +0,0 @@
-/*
- * Copyright (C) 2003-2010 eXo Platform SAS.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Affero General Public License
- * as published by the Free Software Foundation; either version 3
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, see<http://www.gnu.org/licenses/>.
- */
-package org.exoplatform.services.jcr.ext.backup.impl;
-
-import java.io.File;
-import java.io.IOException;
-
-import org.exoplatform.services.jcr.config.ContainerEntry;
-import org.exoplatform.services.jcr.config.RepositoryConfigurationException;
-import org.exoplatform.services.jcr.config.ValueStorageEntry;
-import org.exoplatform.services.jcr.config.WorkspaceEntry;
-import org.exoplatform.services.jcr.impl.storage.value.fs.FileValueStorage;
-
-/**
- * Created by The eXo Platform SAS.
- *
- * <br/>Date: 2010
- *
- * @author <a href="mailto:alex.reshetnyak@exoplatform.com.ua">Alex Reshetnyak</a>
- * @version $Id$
- */
-public class ValueStorageCleanerService
-{
-
- public static void removeWorkspaceValueStorage(WorkspaceEntry wEntry) throws RepositoryConfigurationException, IOException
- {
- ContainerEntry containerEntry = wEntry.getContainer();
-
- if (containerEntry.getValueStorages() != null)
- {
- for (ValueStorageEntry valueStorageEntry : containerEntry.getValueStorages())
- {
- String path = valueStorageEntry.getParameterValue(FileValueStorage.PATH);
-
- removeFolder(new File(path));
- }
- }
- }
-
- /**
- * Remove folder
- */
- private static void removeFolder(File dir) throws IOException
- {
- if (dir.isDirectory())
- {
- for (File subFile : dir.listFiles())
- {
- removeFolder(subFile);
- }
-
- if (!dir.delete())
- {
- throw new IOException("Value storage folder was not deleted : " + dir.getCanonicalPath());
- }
- }
- else
- {
- if (!dir.delete())
- {
- throw new IOException("Value storage file was not deleted : " + dir.getCanonicalPath());
- }
- }
- }
-
-}
13 years, 7 months
exo-jcr SVN: r3221 - in jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup: impl and 1 other directory.
by do-not-reply@jboss.org
Author: tolusha
Date: 2010-09-30 06:31:24 -0400 (Thu, 30 Sep 2010)
New Revision: 3221
Modified:
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/ExtendedBackupManager.java
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/BackupManagerImpl.java
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/JobExistedRepositoryRestore.java
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/JobExistedWorkspaceRestore.java
Log:
EXOJCR-747: code cleanup
Modified: jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/ExtendedBackupManager.java
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/ExtendedBackupManager.java 2010-09-30 09:29:30 UTC (rev 3220)
+++ jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/ExtendedBackupManager.java 2010-09-30 10:31:24 UTC (rev 3221)
@@ -30,78 +30,77 @@
public interface ExtendedBackupManager extends BackupManager
{
/**
- * Restoration over an existing repository.
- * Will be deleted old data.
- * Get status of repository restore was necessary use JobRepositoryRestore BackupManager.getLastRestore(String repositoryName).
+ * Restore existed workspace. Previous data will be deleted.
+ * For getting status of workspace restore use can use
+ * BackupManager.getLastRestore(String repositoryName, String workspaceName) method
*
- * @param log
- * RepositoryBackupChainLog, the repository backup log
- * @param repositoryEntry
- * RepositoryEntry, the repository entry
+ * @param workspaceBackupIdentifier
+ * backup identifier
+ * @param workspaceEntry
+ * new workspace configuration
* @param asynchronous
- * boolean, in 'true' then asynchronous restore.
+ * if 'true' restore will be in asynchronous mode (i.e. in separated thread)
* @throws BackupOperationException
- * will be generate the exception BackupOperationException
+ * if backup operation exception occurred
* @throws BackupConfigurationException
- * will be generate the exception BackupConfigurationException
+ * if configuration exception occurred
*/
- void restoreExistedRepository(RepositoryBackupChainLog log, RepositoryEntry repositoryEntry, boolean asynchronous) throws BackupOperationException, BackupConfigurationException;
-
+ void restoreExistedWorkspace(String workspaceBackupIdentifier, String repositoryName, WorkspaceEntry workspaceEntry,
+ boolean asynchronous) throws BackupOperationException, BackupConfigurationException;
+
/**
- * Restoration over an existing workspace.
- * Will be deleted old data.
- * Get status of workspace restore was necessary use JobWorkspaceRestore BackupManager.getLastRestore(String repositoryName, String workspaceName).
+ * Restore existed workspace. Previous data will be deleted.
+ * For getting status of workspace restore use can use
+ * BackupManager.getLastRestore(String repositoryName, String workspaceName) method
*
* @param log
- * BackupChainLog, the backup log
- * @param repositoryName
- * String, repository name
+ * workspace backup log
* @param workspaceEntry
- * WorkspaceEntry, the workspace entry
+ * new workspace configuration
* @param asynchronous
- * boolean, in 'true' then asynchronous restore.
+ * if 'true' restore will be in asynchronous mode (i.e. in separated thread)
* @throws BackupOperationException
- * will be generate the exception BackupOperationException
+ * if backup operation exception occurred
* @throws BackupConfigurationException
- * will be generate the exception BackupConfigurationException
+ * if configuration exception occurred
*/
void restoreExistedWorkspace(BackupChainLog log, String repositoryName, WorkspaceEntry workspaceEntry, boolean asynchronous) throws BackupOperationException, BackupConfigurationException;
-
+
/**
- * Restoration over an existing repository.
- * Will be deleted old data.
- * Get status of repository restore was necessary use JobRepositoryRestore BackupManager.getLastRestore(String repositoryName).
+ * Restore existed repository. Previous data will be deleted.
+ * For getting status of repository restore use can use
+ * BackupManager.getLastRestore(String repositoryName) method
*
* @param repositoryBackupIdentifier
- * String, identifier of repository backup
+ * backup identifier
* @param repositoryEntry
- * RepositoryEntry, the repository entry
+ * new repository configuration
* @param asynchronous
- * boolean, in 'true' then asynchronous restore.
+ * if 'true' restore will be in asynchronous mode (i.e. in separated thread)
* @throws BackupOperationException
- * will be generate the exception BackupOperationException
+ * if backup operation exception occurred
* @throws BackupConfigurationException
- * will be generate the exception BackupConfigurationException
+ * if configuration exception occurred
*/
void restoreExistedRepository(String repositoryBackupIdentifier, RepositoryEntry repositoryEntry, boolean asynchronous) throws BackupOperationException, BackupConfigurationException;
-
+
/**
- * Restoration over an existing workspace.
- * Will be deleted old data.
- * Get status of workspace restore was necessary use JobWorkspaceRestore BackupManager.getLastRestore(String repositoryName, String workspaceName).
+ * Restore existed repository. Previous data will be deleted.
+ * For getting status of repository restore use can use
+ * BackupManager.getLastRestore(String repositoryName) method
*
- * @param workspaceBackupIdentifier
- * String, identifier of workspace backup
- * @param repositoryName
- * String, repository name
- * @param workspaceEntry
- * WorkspaceEntry, the workspace entry
+ * @param log
+ * repository backup log
+ * @param repositoryEntry
+ * new repository configuration
* @param asynchronous
- * boolean, in 'true' then asynchronous restore.
+ * if 'true' restore will be in asynchronous mode (i.e. in separated thread)
* @throws BackupOperationException
- * will be generate the exception BackupOperationException
+ * if backup operation exception occurred
* @throws BackupConfigurationException
- * will be generate the exception BackupConfigurationException
+ * if configuration exception occurred
*/
- void restoreExistedWorkspace(String workspaceBackupIdentifier, String repositoryName, WorkspaceEntry workspaceEntry, boolean asynchronous) throws BackupOperationException, BackupConfigurationException;
+ void restoreExistedRepository(RepositoryBackupChainLog log, RepositoryEntry repositoryEntry, boolean asynchronous)
+ throws BackupOperationException, BackupConfigurationException;
+
}
Modified: jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/BackupManagerImpl.java
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/BackupManagerImpl.java 2010-09-30 09:29:30 UTC (rev 3220)
+++ jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/BackupManagerImpl.java 2010-09-30 10:31:24 UTC (rev 3221)
@@ -18,29 +18,6 @@
*/
package org.exoplatform.services.jcr.ext.backup.impl;
-import java.io.ByteArrayOutputStream;
-import java.io.EOFException;
-import java.io.File;
-import java.io.FileFilter;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.ObjectInputStream;
-import java.io.PrintWriter;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import javax.jcr.PathNotFoundException;
-import javax.jcr.RepositoryException;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
-
import org.apache.commons.collections.map.HashedMap;
import org.exoplatform.container.xml.InitParams;
import org.exoplatform.container.xml.PropertiesParam;
@@ -71,6 +48,7 @@
import org.exoplatform.services.jcr.ext.backup.RepositoryBackupChain;
import org.exoplatform.services.jcr.ext.backup.RepositoryBackupChainLog;
import org.exoplatform.services.jcr.ext.backup.RepositoryBackupConfig;
+import org.exoplatform.services.jcr.ext.backup.RepositoryRestoreExeption;
import org.exoplatform.services.jcr.ext.backup.WorkspaceRestoreException;
import org.exoplatform.services.jcr.ext.common.SessionProvider;
import org.exoplatform.services.jcr.ext.registry.RegistryEntry;
@@ -93,6 +71,29 @@
import org.w3c.dom.Element;
import org.xml.sax.SAXException;
+import java.io.ByteArrayOutputStream;
+import java.io.EOFException;
+import java.io.File;
+import java.io.FileFilter;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.PrintWriter;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import javax.jcr.PathNotFoundException;
+import javax.jcr.RepositoryException;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+
/**
* Created by The eXo Platform SAS .<br/>
*
@@ -1566,16 +1567,16 @@
{
try
{
- //repository should be existed
+ // repository should be existed
repoService.getRepository(repositoryEntry.getName());
}
catch (RepositoryException e)
{
- throw new WorkspaceRestoreException("Repository \"" + repositoryEntry.getName() + "\" should be existed", e);
+ throw new RepositoryRestoreExeption("Repository \"" + repositoryEntry.getName() + "\" should be existed", e);
}
catch (RepositoryConfigurationException e)
{
- throw new WorkspaceRestoreException("Repository \"" + repositoryEntry.getName() + "\" should be existed", e);
+ throw new RepositoryRestoreExeption("Repository \"" + repositoryEntry.getName() + "\" should be existed", e);
}
Map<String, BackupChainLog> workspacesMapping = new HashedMap();
@@ -1663,10 +1664,10 @@
{
try
{
- //repository should be existed
+ // repository should be existed
repoService.getRepository(repositoryName);
- //workspace should be existed
+ // workspace should be existed
if (!workspaceAlreadyExist(repositoryName, workspaceEntry.getName()))
{
throw new WorkspaceRestoreException("Workspace \"" + workspaceEntry.getName() + "\" should be existed in repository \"" + repositoryName + "\".");
Modified: jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/JobExistedRepositoryRestore.java
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/JobExistedRepositoryRestore.java 2010-09-30 09:29:30 UTC (rev 3220)
+++ jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/JobExistedRepositoryRestore.java 2010-09-30 10:31:24 UTC (rev 3221)
@@ -49,12 +49,28 @@
*/
private final DBCleanerService dbCleanerService;
+ /**
+ * Value storage cleaner.
+ */
+ private final ValueStorageCleanHelper valueStorageCleanHelper;
+
+ /**
+ * Index storage cleaner.
+ */
+ private final IndexCleanHelper indexCleanHelper;
+
+ /**
+ * JobExistedRepositoryRestore constructor.
+ */
public JobExistedRepositoryRestore(RepositoryService repoService, BackupManagerImpl backupManagerImpl,
RepositoryEntry repositoryEntry, Map<String, BackupChainLog> workspacesMapping,
RepositoryBackupChainLog backupChainLog)
{
super(repoService, backupManagerImpl, repositoryEntry, workspacesMapping, backupChainLog);
+
this.dbCleanerService = new DBCleanerService();
+ this.valueStorageCleanHelper = new ValueStorageCleanHelper();
+ this.indexCleanHelper = new IndexCleanHelper();
}
@Override
@@ -65,13 +81,14 @@
{
try
{
+ // get current repository configuration
RepositoryEntry repositoryEntry =
repositoryService.getConfig().getRepositoryConfiguration(this.repositoryEntry.getName());
if (repositoryEntry == null)
{
- throw new RepositoryRestoreExeption("Repository " + this.repositoryEntry.getName()
- + " did not found configuration");
+ throw new RepositoryRestoreExeption("Current repository configuration " + this.repositoryEntry.getName()
+ + " did not found");
}
boolean isDefault =
@@ -99,14 +116,14 @@
//clean index
for (WorkspaceEntry wEntry : repositoryEntry.getWorkspaceEntries())
{
- IndexCleanerService.removeWorkspaceIndex(wEntry,
+ indexCleanHelper.removeWorkspaceIndex(wEntry,
repositoryEntry.getSystemWorkspaceName().equals(wEntry.getName()));
}
//clean value storage
for (WorkspaceEntry wEntry : repositoryEntry.getWorkspaceEntries())
{
- ValueStorageCleanerService.removeWorkspaceValueStorage(wEntry);
+ valueStorageCleanHelper.removeWorkspaceValueStorage(wEntry);
}
super.restoreRepository();
Modified: jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/JobExistedWorkspaceRestore.java
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/JobExistedWorkspaceRestore.java 2010-09-30 09:29:30 UTC (rev 3220)
+++ jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/JobExistedWorkspaceRestore.java 2010-09-30 10:31:24 UTC (rev 3221)
@@ -42,7 +42,7 @@
public class JobExistedWorkspaceRestore extends JobWorkspaceRestore
{
/**
- * The apache logger.
+ * The logger.
*/
private static Log log = ExoLogger.getLogger("exo.jcr.component.ext.JobExistedWorkspaceRestore");
@@ -51,11 +51,27 @@
*/
private final DBCleanerService dbCleanerService;
+ /**
+ * Value storage cleaner.
+ */
+ private final ValueStorageCleanHelper valueStorageCleaner;
+
+ /**
+ * Index cleaner.
+ */
+ private final IndexCleanHelper indexCleanHelper;
+
+ /**
+ * JobExistedWorkspaceRestore constructor.
+ */
public JobExistedWorkspaceRestore(RepositoryService repositoryService, BackupManager backupManager,
String repositoryName, BackupChainLog log, WorkspaceEntry wEntry)
{
super(repositoryService, backupManager, repositoryName, log, wEntry);
+
this.dbCleanerService = new DBCleanerService();
+ this.valueStorageCleaner = new ValueStorageCleanHelper();
+ this.indexCleanHelper = new IndexCleanHelper();
}
/**
@@ -66,6 +82,7 @@
{
try
{
+ // get current workspace configuration
WorkspaceEntry wEntry = null;;
for (WorkspaceEntry entry : repositoryService.getRepository(repositoryName).getConfiguration()
.getWorkspaceEntries())
@@ -79,8 +96,8 @@
if (wEntry == null)
{
- throw new WorkspaceRestoreException("Workspace " + this.wEntry.getName() + " did not found in repository "
- + repositoryName + " configuration");
+ throw new WorkspaceRestoreException("Workspace " + this.wEntry.getName()
+ + " did not found in current repository " + repositoryName + " configuration");
}
boolean isSystem =
@@ -96,10 +113,10 @@
dbCleanerService.cleanWorkspaceData(wEntry);
//clean index
- IndexCleanerService.removeWorkspaceIndex(wEntry, isSystem);
+ indexCleanHelper.removeWorkspaceIndex(wEntry, isSystem);
//clean value storage
- ValueStorageCleanerService.removeWorkspaceValueStorage(wEntry);
+ valueStorageCleaner.removeWorkspaceValueStorage(wEntry);
super.restore();
}
13 years, 7 months
exo-jcr SVN: r3220 - in jcr/trunk: exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core and 2 other directories.
by do-not-reply@jboss.org
Author: tolusha
Date: 2010-09-30 05:29:30 -0400 (Thu, 30 Sep 2010)
New Revision: 3220
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/RepositoryContainer.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/RepositoryImpl.java
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/JobExistedWorkspaceRestore.java
jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/TestBackupManager.java
Log:
EXOJCR-747: avoid restore of system workspace only as part of repository restore
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/RepositoryContainer.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/RepositoryContainer.java 2010-09-30 07:40:51 UTC (rev 3219)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/RepositoryContainer.java 2010-09-30 09:29:30 UTC (rev 3220)
@@ -253,10 +253,6 @@
workspaceContainer.registerComponentImplementation(containerType);
if (isSystem)
{
- if (getComponentInstanceOfType(SystemDataContainerHolder.class) != null)
- {
- unregisterComponent(SystemDataContainerHolder.class);
- }
registerComponentInstance(new SystemDataContainerHolder(
(WorkspaceDataContainer)workspaceContainer.getComponentInstanceOfType(WorkspaceDataContainer.class)));
}
@@ -383,11 +379,6 @@
{
// system workspace
systemDataManager = wsDataManager;
-
- if (getComponentInstanceOfType(LocalWorkspaceDataManagerStub.class) != null)
- {
- unregisterComponent(LocalWorkspaceDataManagerStub.class);
- }
registerComponentInstance(systemDataManager);
}
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/RepositoryImpl.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/RepositoryImpl.java 2010-09-30 07:40:51 UTC (rev 3219)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/RepositoryImpl.java 2010-09-30 09:29:30 UTC (rev 3220)
@@ -81,8 +81,8 @@
/**
* SYSTEM credentials.
*/
- private static final CredentialsImpl SYSTEM_CREDENTIALS =
- new CredentialsImpl(SystemIdentity.SYSTEM, "".toCharArray());
+ private static final CredentialsImpl SYSTEM_CREDENTIALS = new CredentialsImpl(SystemIdentity.SYSTEM,
+ "".toCharArray());
/**
* Logger.
@@ -181,7 +181,16 @@
*/
public boolean canRemoveWorkspace(String workspaceName) throws NoSuchWorkspaceException
{
- return canRemoveWorkspace(workspaceName, false);
+ if (repositoryContainer.getWorkspaceEntry(workspaceName) == null)
+ throw new NoSuchWorkspaceException("No such workspace " + workspaceName);
+
+ if (workspaceName.equals(config.getSystemWorkspaceName()))
+ return false;
+
+ SessionRegistry sessionRegistry =
+ (SessionRegistry)repositoryContainer.getComponentInstance(SessionRegistry.class);
+
+ return sessionRegistry != null && !sessionRegistry.isInUse(workspaceName);
}
/**
@@ -462,9 +471,9 @@
StreamImporter importer =
eiFactory.getWorkspaceImporter(rootData, ImportUUIDBehavior.IMPORT_UUID_COLLISION_THROW, dataManager,
- dataManager, sysSession.getWorkspace().getNodeTypesHolder(), sysSession.getLocationFactory(), sysSession
- .getValueFactory(), getNamespaceRegistry(), sysSession.getAccessManager(), sysSession.getUserState(),
- context, this, wsName);
+ dataManager, sysSession.getWorkspace().getNodeTypesHolder(), sysSession.getLocationFactory(),
+ sysSession.getValueFactory(), getNamespaceRegistry(), sysSession.getAccessManager(),
+ sysSession.getUserState(), context, this, wsName);
importer.importStream(xmlStream);
}
finally
@@ -627,18 +636,13 @@
*/
public void removeWorkspace(String workspaceName) throws RepositoryException
{
- removeWorkspace(workspaceName, false);
- }
+ if (!canRemoveWorkspace(workspaceName))
- /**
- * Remove system workspace.
- * Workspace become stopped, removed from container and removed from repository configuration.
- *
- * @throws RepositoryException - if workspace is in use, or can't be removed for other reason
- */
- public void removeSystemWorkspace() throws RepositoryException
- {
- removeWorkspace(config.getSystemWorkspaceName(), true);
+ throw new RepositoryException("Workspace " + workspaceName + " in use. If you want to "
+ + " remove workspace close all open sessions");
+
+ internalRemoveWorkspace(workspaceName);
+ config.getWorkspaceEntries().remove(repositoryContainer.getWorkspaceEntry(workspaceName));
}
/**
@@ -703,55 +707,6 @@
}
}
- /**
- * Remove workspace.
- *
- * @param workspaceName
- * workspace name
- * @param allowRemoveSystemWorkspacew
- * allow to remove system workspace
- * @throws RepositoryException
- * if any Exception is occurred
- */
- private void removeWorkspace(String workspaceName, boolean allowRemoveSystemWorkspacew) throws RepositoryException
- {
- if (!canRemoveWorkspace(workspaceName, allowRemoveSystemWorkspacew))
-
- throw new RepositoryException("Workspace " + workspaceName + " in use. If you want to "
- + " remove workspace close all open sessions");
-
- internalRemoveWorkspace(workspaceName);
- config.getWorkspaceEntries().remove(repositoryContainer.getWorkspaceEntry(workspaceName));
- }
-
- /**
- * Indicates if specific workspace can be removed.
- *
- * @param workspaceName
- * workspace name
- * @param allowRemoveSystemWorkspace
- * allow to remove system workspacw
- * @return
- * true if workspace can be removed or false in ather case
- * @throws NoSuchWorkspaceException
- * if any Exception is occured
- */
- private boolean canRemoveWorkspace(String workspaceName, boolean allowRemoveSystemWorkspace)
- throws NoSuchWorkspaceException
- {
- if (repositoryContainer.getWorkspaceEntry(workspaceName) == null)
- throw new NoSuchWorkspaceException("No such workspace " + workspaceName);
-
- if (!allowRemoveSystemWorkspace && workspaceName.equals(config.getSystemWorkspaceName()))
- return false;
-
- SessionRegistry sessionRegistry =
- (SessionRegistry)repositoryContainer.getComponentInstance(SessionRegistry.class);
-
- return sessionRegistry != null && !sessionRegistry.isInUse(workspaceName);
-
- }
-
@Override
public String toString()
{
Modified: jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/JobExistedWorkspaceRestore.java
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/JobExistedWorkspaceRestore.java 2010-09-30 07:40:51 UTC (rev 3219)
+++ jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/JobExistedWorkspaceRestore.java 2010-09-30 09:29:30 UTC (rev 3220)
@@ -24,7 +24,6 @@
import org.exoplatform.services.jcr.ext.backup.BackupChainLog;
import org.exoplatform.services.jcr.ext.backup.BackupManager;
import org.exoplatform.services.jcr.ext.backup.WorkspaceRestoreException;
-import org.exoplatform.services.jcr.impl.core.RepositoryImpl;
import org.exoplatform.services.jcr.impl.core.SessionRegistry;
import org.exoplatform.services.jcr.impl.util.jdbc.cleaner.DBCleanerService;
import org.exoplatform.services.log.ExoLogger;
@@ -91,16 +90,7 @@
//close all session
forceCloseSession(repositoryName, wEntry.getName());
- //remove workspace
- if (isSystem)
- {
- RepositoryImpl repositoryImpl = (RepositoryImpl)repositoryService.getRepository(repositoryName);
- repositoryImpl.removeSystemWorkspace();
- }
- else
- {
- repositoryService.getRepository(repositoryName).removeWorkspace(wEntry.getName());
- }
+ repositoryService.getRepository(repositoryName).removeWorkspace(wEntry.getName());
//clean database
dbCleanerService.cleanWorkspaceData(wEntry);
Modified: jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/TestBackupManager.java
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/TestBackupManager.java 2010-09-30 07:40:51 UTC (rev 3219)
+++ jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/TestBackupManager.java 2010-09-30 09:29:30 UTC (rev 3220)
@@ -18,6 +18,15 @@
*/
package org.exoplatform.services.jcr.ext.backup;
+import org.apache.commons.collections.map.HashedMap;
+import org.exoplatform.services.jcr.config.RepositoryEntry;
+import org.exoplatform.services.jcr.config.WorkspaceEntry;
+import org.exoplatform.services.jcr.core.ManageableRepository;
+import org.exoplatform.services.jcr.ext.backup.impl.JobRepositoryRestore;
+import org.exoplatform.services.jcr.ext.backup.impl.JobWorkspaceRestore;
+import org.exoplatform.services.jcr.impl.core.RepositoryImpl;
+import org.exoplatform.services.jcr.impl.core.SessionImpl;
+
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
@@ -25,20 +34,9 @@
import java.util.Map;
import javax.jcr.Node;
-import javax.jcr.Repository;
import javax.jcr.RepositoryException;
-import javax.jcr.Session;
import javax.jcr.lock.Lock;
-import org.apache.commons.collections.map.HashedMap;
-import org.exoplatform.services.jcr.config.RepositoryEntry;
-import org.exoplatform.services.jcr.config.WorkspaceEntry;
-import org.exoplatform.services.jcr.core.ManageableRepository;
-import org.exoplatform.services.jcr.ext.backup.impl.JobRepositoryRestore;
-import org.exoplatform.services.jcr.ext.backup.impl.JobWorkspaceRestore;
-import org.exoplatform.services.jcr.impl.core.RepositoryImpl;
-import org.exoplatform.services.jcr.impl.core.SessionImpl;
-
/**
* Created by The eXo Platform SAS.
* Author : Peter Nedonosko peter.nedonosko(a)exoplatform.com.ua
@@ -272,8 +270,8 @@
ws1TestRoot.save(); // log here via listener
// before(*), log here via listener
- ws1TestRoot.getSession().getWorkspace().move(ws1TestRoot.getNode("node_6").getPath(),
- ws1TestRoot.getPath() + "/node_4"); // in place of
+ ws1TestRoot.getSession().getWorkspace()
+ .move(ws1TestRoot.getNode("node_6").getPath(), ws1TestRoot.getPath() + "/node_4"); // in place of
// 4 removed
// stop all
@@ -319,14 +317,14 @@
assertFalse("Property should be removed", ws1backTestRoot.getNode("node_2").hasProperty("exo:data"));
- compareStream(new ByteArrayInputStream("aaa".getBytes()), ws1backTestRoot.getNode("node_3").getProperty(
- "exo:data").getStream());
+ compareStream(new ByteArrayInputStream("aaa".getBytes()),
+ ws1backTestRoot.getNode("node_3").getProperty("exo:data").getStream());
assertTrue("Node should be mix:lockable ", ws1backTestRoot.getNode("node_5").isNodeType("mix:lockable"));
assertFalse("Node should be not locked ", ws1backTestRoot.getNode("node_5").isLocked());
- assertEquals("Node should be mix:referenceable and UUID should be " + id6, id6, ws1backTestRoot.getNode(
- "node_4").getUUID());
+ assertEquals("Node should be mix:referenceable and UUID should be " + id6, id6,
+ ws1backTestRoot.getNode("node_4").getUUID());
}
catch (Exception e)
{
@@ -346,8 +344,8 @@
public void testFullBackupRestoreAsync() throws Exception
{
SessionImpl sessionWS1 = (SessionImpl)repository.login(credentials, "ws1");
- sessionWS1.getRootNode().addNode("backupTest").addNode("node_5").setProperty("exo:data",
- "Restored content should be same");
+ sessionWS1.getRootNode().addNode("backupTest").addNode("node_5")
+ .setProperty("exo:data", "Restored content should be same");
sessionWS1.save();
// backup
@@ -505,8 +503,8 @@
{
SessionImpl sessionWS1 = (SessionImpl)repository.login(credentials, "ws3");
- sessionWS1.getRootNode().addNode("asdasdasda", "nt:unstructured").setProperty("data",
- new FileInputStream(createBLOBTempFile(1024)));
+ sessionWS1.getRootNode().addNode("asdasdasda", "nt:unstructured")
+ .setProperty("data", new FileInputStream(createBLOBTempFile(1024)));
sessionWS1.save();
// 1-st backup
@@ -543,8 +541,8 @@
assertNotNull(back1.getRootNode().getNode("asdasdasda").getProperty("data"));
// add date to restored workspace
- back1.getRootNode().addNode("gdfgrghfhf", "nt:unstructured").setProperty("data",
- new FileInputStream(createBLOBTempFile(1024)));
+ back1.getRootNode().addNode("gdfgrghfhf", "nt:unstructured")
+ .setProperty("data", new FileInputStream(createBLOBTempFile(1024)));
back1.save();
}
else
@@ -786,8 +784,8 @@
assertNotNull(bchLog.getFinishedTime());
backup.restore(bchLog, newRepositoryEntry, false);
- assertEquals(JobWorkspaceRestore.RESTORE_SUCCESSFUL, backup.getLastRepositoryRestore(
- newRepositoryEntry.getName()).getStateRestore());
+ assertEquals(JobWorkspaceRestore.RESTORE_SUCCESSFUL,
+ backup.getLastRepositoryRestore(newRepositoryEntry.getName()).getStateRestore());
// check
ManageableRepository restoredRepository = repositoryService.getRepository(newRepositoryName);
@@ -1229,7 +1227,7 @@
else
fail("There are no backup files in " + backDir.getAbsolutePath());
}
-
+
public void testExistedWorkspaceRestore() throws Exception
{
// backup
@@ -1306,7 +1304,7 @@
else
fail("There are no backup files in " + backDir.getAbsolutePath());
}
-
+
public void testExistedWorkspaceRestoreAsync() throws Exception
{
// backup
@@ -1359,9 +1357,9 @@
assertNotNull(bchLog.getFinishedTime());
backup.restoreExistedWorkspace(bchLog, re.getName(), ws1, true);
-
+
while (backup.getLastRestore(repository.getName(), ws1.getName()).getStateRestore() != JobWorkspaceRestore.RESTORE_SUCCESSFUL
- && backup.getLastRestore(repository.getName(), ws1.getName()).getStateRestore() != JobWorkspaceRestore.RESTORE_FAIL)
+ && backup.getLastRestore(repository.getName(), ws1.getName()).getStateRestore() != JobWorkspaceRestore.RESTORE_FAIL)
{
Thread.sleep(50);
}
@@ -1389,7 +1387,7 @@
else
fail("There are no backup files in " + backDir.getAbsolutePath());
}
-
+
public void testExistedWorkspaceRestoreAsync2() throws Exception
{
// backup
@@ -1442,9 +1440,9 @@
assertNotNull(bchLog.getFinishedTime());
backup.restoreExistedWorkspace(bchLog.getBackupId(), re.getName(), ws1, true);
-
+
while (backup.getLastRestore(repository.getName(), ws1.getName()).getStateRestore() != JobWorkspaceRestore.RESTORE_SUCCESSFUL
- && backup.getLastRestore(repository.getName(), ws1.getName()).getStateRestore() != JobWorkspaceRestore.RESTORE_FAIL)
+ && backup.getLastRestore(repository.getName(), ws1.getName()).getStateRestore() != JobWorkspaceRestore.RESTORE_FAIL)
{
Thread.sleep(50);
}
@@ -1472,7 +1470,7 @@
else
fail("There are no backup files in " + backDir.getAbsolutePath());
}
-
+
public void testExistedRepositoryRestore() throws Exception
{
// backup
@@ -1501,8 +1499,9 @@
backup.stopBackup(bch);
// restore
- RepositoryEntry baseRE = (RepositoryEntry)ws1Session.getContainer().getComponentInstanceOfType(RepositoryEntry.class);
- RepositoryEntry re = makeRepositoryEntry(baseRE.getName() , baseRE, null, null);
+ RepositoryEntry baseRE =
+ (RepositoryEntry)ws1Session.getContainer().getComponentInstanceOfType(RepositoryEntry.class);
+ RepositoryEntry re = makeRepositoryEntry(baseRE.getName(), baseRE, null, null);
File backLog = new File(bch.getLogFilePath());
if (backLog.exists())
@@ -1513,10 +1512,10 @@
assertNotNull(bchLog.getFinishedTime());
backup.restoreExistedRepository(bchLog, re, false);
-
- assertEquals(JobWorkspaceRestore.RESTORE_SUCCESSFUL, backup.getLastRepositoryRestore(
- re.getName()).getStateRestore());
+ assertEquals(JobWorkspaceRestore.RESTORE_SUCCESSFUL, backup.getLastRepositoryRestore(re.getName())
+ .getStateRestore());
+
// check
ManageableRepository restoredRepository = repositoryService.getRepository(re.getName());
@@ -1545,7 +1544,7 @@
else
fail("There are no backup files in " + backDir.getAbsolutePath());
}
-
+
public void testExistedRepositoryRestoreMultiDB() throws Exception
{
RepositoryImpl repositoryDB7 = (RepositoryImpl)repositoryService.getRepository("db7");
@@ -1553,15 +1552,15 @@
for (String wsName : repositoryDB7.getWorkspaceNames())
{
SessionImpl sessionWS = (SessionImpl)repositoryDB7.login(credentials, wsName);
-
+
Node wsTestRoot = sessionWS.getRootNode().addNode("backupTest");
sessionWS.getRootNode().save();
addContent(wsTestRoot, 1, 10, 1);
sessionWS.getRootNode().save();
}
-
+
SessionImpl sessionWS = (SessionImpl)repositoryDB7.login(credentials, WS_NAME);
-
+
// backup
File backDir = new File("target/backup");
backDir.mkdirs();
@@ -1588,8 +1587,9 @@
backup.stopBackup(bch);
// restore
- RepositoryEntry baseRE = (RepositoryEntry)sessionWS.getContainer().getComponentInstanceOfType(RepositoryEntry.class);
- RepositoryEntry re = makeRepositoryEntry(baseRE.getName() , baseRE, null, null);
+ RepositoryEntry baseRE =
+ (RepositoryEntry)sessionWS.getContainer().getComponentInstanceOfType(RepositoryEntry.class);
+ RepositoryEntry re = makeRepositoryEntry(baseRE.getName(), baseRE, null, null);
File backLog = new File(bch.getLogFilePath());
if (backLog.exists())
@@ -1600,10 +1600,10 @@
assertNotNull(bchLog.getFinishedTime());
backup.restoreExistedRepository(bchLog, re, false);
-
- assertEquals(JobWorkspaceRestore.RESTORE_SUCCESSFUL, backup.getLastRepositoryRestore(
- re.getName()).getStateRestore());
+ assertEquals(JobWorkspaceRestore.RESTORE_SUCCESSFUL, backup.getLastRepositoryRestore(re.getName())
+ .getStateRestore());
+
// check
ManageableRepository restoredRepository = repositoryService.getRepository(re.getName());
@@ -1632,7 +1632,7 @@
else
fail("There are no backup files in " + backDir.getAbsolutePath());
}
-
+
public void testExistedRepositoryRestoreAsync() throws Exception
{
// backup
@@ -1661,8 +1661,9 @@
backup.stopBackup(bch);
// restore
- RepositoryEntry baseRE = (RepositoryEntry)ws1Session.getContainer().getComponentInstanceOfType(RepositoryEntry.class);
- RepositoryEntry re = makeRepositoryEntry(baseRE.getName() , baseRE, null, null);
+ RepositoryEntry baseRE =
+ (RepositoryEntry)ws1Session.getContainer().getComponentInstanceOfType(RepositoryEntry.class);
+ RepositoryEntry re = makeRepositoryEntry(baseRE.getName(), baseRE, null, null);
File backLog = new File(bch.getLogFilePath());
if (backLog.exists())
@@ -1673,18 +1674,18 @@
assertNotNull(bchLog.getFinishedTime());
backup.restoreExistedRepository(bchLog, re, true);
-
+
JobRepositoryRestore job = backup.getLastRepositoryRestore(re.getName());
-
+
while (job.getStateRestore() != JobRepositoryRestore.REPOSITORY_RESTORE_SUCCESSFUL
- && job.getStateRestore() != JobRepositoryRestore.REPOSITORY_RESTORE_FAIL)
+ && job.getStateRestore() != JobRepositoryRestore.REPOSITORY_RESTORE_FAIL)
{
Thread.sleep(50);
}
-
- assertEquals(JobRepositoryRestore.REPOSITORY_RESTORE_SUCCESSFUL, backup.getLastRepositoryRestore(
- re.getName()).getStateRestore());
+ assertEquals(JobRepositoryRestore.REPOSITORY_RESTORE_SUCCESSFUL, backup.getLastRepositoryRestore(re.getName())
+ .getStateRestore());
+
// check
ManageableRepository restoredRepository = repositoryService.getRepository(re.getName());
@@ -1713,7 +1714,7 @@
else
fail("There are no backup files in " + backDir.getAbsolutePath());
}
-
+
public void testExistedRepositoryRestoreAsync2() throws Exception
{
// backup
@@ -1742,8 +1743,9 @@
backup.stopBackup(bch);
// restore
- RepositoryEntry baseRE = (RepositoryEntry)ws1Session.getContainer().getComponentInstanceOfType(RepositoryEntry.class);
- RepositoryEntry re = makeRepositoryEntry(baseRE.getName() , baseRE, null, null);
+ RepositoryEntry baseRE =
+ (RepositoryEntry)ws1Session.getContainer().getComponentInstanceOfType(RepositoryEntry.class);
+ RepositoryEntry re = makeRepositoryEntry(baseRE.getName(), baseRE, null, null);
File backLog = new File(bch.getLogFilePath());
if (backLog.exists())
@@ -1754,18 +1756,18 @@
assertNotNull(bchLog.getFinishedTime());
backup.restoreExistedRepository(bchLog.getBackupId(), re, true);
-
+
JobRepositoryRestore job = backup.getLastRepositoryRestore(re.getName());
-
+
while (job.getStateRestore() != JobRepositoryRestore.REPOSITORY_RESTORE_SUCCESSFUL
- && job.getStateRestore() != JobRepositoryRestore.REPOSITORY_RESTORE_FAIL)
+ && job.getStateRestore() != JobRepositoryRestore.REPOSITORY_RESTORE_FAIL)
{
Thread.sleep(50);
}
-
- assertEquals(JobWorkspaceRestore.RESTORE_SUCCESSFUL, backup.getLastRepositoryRestore(
- re.getName()).getStateRestore());
+ assertEquals(JobWorkspaceRestore.RESTORE_SUCCESSFUL, backup.getLastRepositoryRestore(re.getName())
+ .getStateRestore());
+
// check
ManageableRepository restoredRepository = repositoryService.getRepository(re.getName());
@@ -1794,182 +1796,18 @@
else
fail("There are no backup files in " + backDir.getAbsolutePath());
}
-
- public void testExistedSystemWorkspaceRestore() throws Exception
- {
- String systemWS = repository.getSystemWorkspaceName();
-
- // backup
- File backDir = new File("target/backup/" + systemWS);
- backDir.mkdirs();
- BackupConfig config = new BackupConfig();
- config.setRepository(repository.getName());
- config.setWorkspace(systemWS);
- config.setBackupType(BackupManager.FULL_BACKUP_ONLY);
-
- config.setBackupDir(backDir);
-
- backup.startBackup(config);
-
- BackupChain bch = backup.findBackup(repository.getName(), systemWS);
-
- // wait till full backup will be stopped
- while (bch.getFullBackupState() != BackupJob.FINISHED)
- {
- Thread.yield();
- Thread.sleep(50);
- }
-
- // stop fullBackup
-
- if (bch != null)
- backup.stopBackup(bch);
- else
- fail("Can't get fullBackup chain");
-
- // restore
- RepositoryEntry re = (RepositoryEntry)ws1Session.getContainer().getComponentInstanceOfType(RepositoryEntry.class);
- WorkspaceEntry ws1 = null;
- for (WorkspaceEntry we : re.getWorkspaceEntries())
- {
- if (systemWS.equals(we.getName()))
- {
- ws1 = we;
- break;
- }
- }
-
- File backLog = new File(bch.getLogFilePath());
- if (backLog.exists())
- {
- BackupChainLog bchLog = new BackupChainLog(backLog);
-
- assertNotNull(bchLog.getStartedTime());
- assertNotNull(bchLog.getFinishedTime());
-
- backup.restoreExistedWorkspace(bchLog, re.getName(), ws1, false);
-
- // check
- SessionImpl back1 = null;
- try
- {
- back1 = (SessionImpl)repository.login(credentials, systemWS);
- Node ws1backTestRoot = back1.getRootNode().getNode("backupTest");
- assertEquals("Restored content should be same", "property-5", ws1backTestRoot.getNode("node_5")
- .getProperty("exo:data").getString());
- }
- catch (Exception e)
- {
- e.printStackTrace();
- fail(e.getMessage());
- }
- finally
- {
- if (back1 != null)
- back1.logout();
- }
- }
- else
- fail("There are no backup files in " + backDir.getAbsolutePath());
- }
-
- public void testExistedSystemWorkspaceRestoreAsync() throws Exception
- {
- String systemWS = repository.getSystemWorkspaceName();
-
- // backup
- File backDir = new File("target/backup/" + systemWS);
- backDir.mkdirs();
-
- BackupConfig config = new BackupConfig();
- config.setRepository(repository.getName());
- config.setWorkspace(systemWS);
- config.setBackupType(BackupManager.FULL_BACKUP_ONLY);
-
- config.setBackupDir(backDir);
-
- backup.startBackup(config);
-
- BackupChain bch = backup.findBackup(repository.getName(), systemWS);
-
- // wait till full backup will be stopped
- while (bch.getFullBackupState() != BackupJob.FINISHED)
- {
- Thread.yield();
- Thread.sleep(50);
- }
-
- // stop fullBackup
-
- if (bch != null)
- backup.stopBackup(bch);
- else
- fail("Can't get fullBackup chain");
-
- // restore
- RepositoryEntry re = (RepositoryEntry)ws1Session.getContainer().getComponentInstanceOfType(RepositoryEntry.class);
- WorkspaceEntry ws1 = null;
- for (WorkspaceEntry we : re.getWorkspaceEntries())
- {
- if (systemWS.equals(we.getName()))
- {
- ws1 = we;
- break;
- }
- }
-
- File backLog = new File(bch.getLogFilePath());
- if (backLog.exists())
- {
- BackupChainLog bchLog = new BackupChainLog(backLog);
-
- assertNotNull(bchLog.getStartedTime());
- assertNotNull(bchLog.getFinishedTime());
-
- backup.restoreExistedWorkspace(bchLog, re.getName(), ws1, true);
-
- while (backup.getLastRestore(repository.getName(), ws1.getName()).getStateRestore() != JobWorkspaceRestore.RESTORE_SUCCESSFUL
- && backup.getLastRestore(repository.getName(), ws1.getName()).getStateRestore() != JobWorkspaceRestore.RESTORE_FAIL)
- {
- Thread.sleep(50);
- }
-
- // check
- SessionImpl back1 = null;
- try
- {
- back1 = (SessionImpl)repository.login(credentials, systemWS);
- Node ws1backTestRoot = back1.getRootNode().getNode("backupTest");
- assertEquals("Restored content should be same", "property-5", ws1backTestRoot.getNode("node_5")
- .getProperty("exo:data").getString());
- }
- catch (Exception e)
- {
- e.printStackTrace();
- fail(e.getMessage());
- }
- finally
- {
- if (back1 != null)
- back1.logout();
- }
- }
- else
- fail("There are no backup files in " + backDir.getAbsolutePath());
- }
-
public void testExistedWorkspaceRestoreMultiDB() throws Exception
{
RepositoryImpl repositoryDB7 = (RepositoryImpl)repositoryService.getRepository("db7");
- SessionImpl sessionWS = (SessionImpl) repositoryDB7.login(credentials, "ws1");
+ SessionImpl sessionWS = (SessionImpl)repositoryDB7.login(credentials, "ws1");
Node wsTestRoot = sessionWS.getRootNode().addNode("backupTest");
sessionWS.getRootNode().save();
addContent(wsTestRoot, 1, 10, 1);
sessionWS.getRootNode().save();
-
+
// backup
File backDir = new File("target/backup/ws1");
backDir.mkdirs();
13 years, 7 months
exo-jcr SVN: r3219 - in jcr/trunk/exo.jcr.component.ext/src: test/java/org/exoplatform/services/jcr/ext/backup and 1 other directories.
by do-not-reply@jboss.org
Author: areshetnyak
Date: 2010-09-30 03:40:51 -0400 (Thu, 30 Sep 2010)
New Revision: 3219
Modified:
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/ValueStorageCleanerService.java
jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/TestBackupManager.java
jcr/trunk/exo.jcr.component.ext/src/test/resources/conf/standalone/test-configuration.xml
jcr/trunk/exo.jcr.component.ext/src/test/resources/conf/standalone/test-jcr-ext-config.xml
Log:
EXOJCR-747 : Make backup restore easier implementation.
Modified: jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/ValueStorageCleanerService.java
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/ValueStorageCleanerService.java 2010-09-29 12:40:05 UTC (rev 3218)
+++ jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/ValueStorageCleanerService.java 2010-09-30 07:40:51 UTC (rev 3219)
@@ -16,8 +16,14 @@
*/
package org.exoplatform.services.jcr.ext.backup.impl;
+import java.io.File;
+import java.io.IOException;
+
+import org.exoplatform.services.jcr.config.ContainerEntry;
+import org.exoplatform.services.jcr.config.RepositoryConfigurationException;
import org.exoplatform.services.jcr.config.ValueStorageEntry;
import org.exoplatform.services.jcr.config.WorkspaceEntry;
+import org.exoplatform.services.jcr.impl.storage.value.fs.FileValueStorage;
/**
* Created by The eXo Platform SAS.
@@ -30,12 +36,45 @@
public class ValueStorageCleanerService
{
- public static void removeWorkspaceValueStorage(WorkspaceEntry wEntry)
+ public static void removeWorkspaceValueStorage(WorkspaceEntry wEntry) throws RepositoryConfigurationException, IOException
{
- /*for( ValueStorageEntry valueStorageEntry : wEntry.getContainer().getValueStorages())
- {
-
- }*/
+ ContainerEntry containerEntry = wEntry.getContainer();
+
+ if (containerEntry.getValueStorages() != null)
+ {
+ for (ValueStorageEntry valueStorageEntry : containerEntry.getValueStorages())
+ {
+ String path = valueStorageEntry.getParameterValue(FileValueStorage.PATH);
+
+ removeFolder(new File(path));
+ }
+ }
}
+
+ /**
+ * Remove folder
+ */
+ private static void removeFolder(File dir) throws IOException
+ {
+ if (dir.isDirectory())
+ {
+ for (File subFile : dir.listFiles())
+ {
+ removeFolder(subFile);
+ }
+
+ if (!dir.delete())
+ {
+ throw new IOException("Value storage folder was not deleted : " + dir.getCanonicalPath());
+ }
+ }
+ else
+ {
+ if (!dir.delete())
+ {
+ throw new IOException("Value storage file was not deleted : " + dir.getCanonicalPath());
+ }
+ }
+ }
}
Modified: jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/TestBackupManager.java
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/TestBackupManager.java 2010-09-29 12:40:05 UTC (rev 3218)
+++ jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/TestBackupManager.java 2010-09-30 07:40:51 UTC (rev 3219)
@@ -18,15 +18,6 @@
*/
package org.exoplatform.services.jcr.ext.backup;
-import org.apache.commons.collections.map.HashedMap;
-import org.exoplatform.services.jcr.config.RepositoryEntry;
-import org.exoplatform.services.jcr.config.WorkspaceEntry;
-import org.exoplatform.services.jcr.core.ManageableRepository;
-import org.exoplatform.services.jcr.ext.backup.impl.BackupManagerImpl;
-import org.exoplatform.services.jcr.ext.backup.impl.JobRepositoryRestore;
-import org.exoplatform.services.jcr.ext.backup.impl.JobWorkspaceRestore;
-import org.exoplatform.services.jcr.impl.core.SessionImpl;
-
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
@@ -34,9 +25,20 @@
import java.util.Map;
import javax.jcr.Node;
+import javax.jcr.Repository;
import javax.jcr.RepositoryException;
+import javax.jcr.Session;
import javax.jcr.lock.Lock;
+import org.apache.commons.collections.map.HashedMap;
+import org.exoplatform.services.jcr.config.RepositoryEntry;
+import org.exoplatform.services.jcr.config.WorkspaceEntry;
+import org.exoplatform.services.jcr.core.ManageableRepository;
+import org.exoplatform.services.jcr.ext.backup.impl.JobRepositoryRestore;
+import org.exoplatform.services.jcr.ext.backup.impl.JobWorkspaceRestore;
+import org.exoplatform.services.jcr.impl.core.RepositoryImpl;
+import org.exoplatform.services.jcr.impl.core.SessionImpl;
+
/**
* Created by The eXo Platform SAS.
* Author : Peter Nedonosko peter.nedonosko(a)exoplatform.com.ua
@@ -1544,6 +1546,93 @@
fail("There are no backup files in " + backDir.getAbsolutePath());
}
+ public void testExistedRepositoryRestoreMultiDB() throws Exception
+ {
+ RepositoryImpl repositoryDB7 = (RepositoryImpl)repositoryService.getRepository("db7");
+
+ for (String wsName : repositoryDB7.getWorkspaceNames())
+ {
+ SessionImpl sessionWS = (SessionImpl)repositoryDB7.login(credentials, wsName);
+
+ Node wsTestRoot = sessionWS.getRootNode().addNode("backupTest");
+ sessionWS.getRootNode().save();
+ addContent(wsTestRoot, 1, 10, 1);
+ sessionWS.getRootNode().save();
+ }
+
+ SessionImpl sessionWS = (SessionImpl)repositoryDB7.login(credentials, WS_NAME);
+
+ // backup
+ File backDir = new File("target/backup");
+ backDir.mkdirs();
+
+ RepositoryBackupConfig config = new RepositoryBackupConfig();
+ config.setRepository(repositoryDB7.getName());
+ config.setBackupType(BackupManager.FULL_BACKUP_ONLY);
+
+ config.setBackupDir(backDir);
+
+ backup.startBackup(config);
+
+ RepositoryBackupChain bch = backup.findRepositoryBackup(repositoryDB7.getName());
+
+ // wait till full backup will be stopped
+ while (bch.getState() != RepositoryBackupChain.FINISHED)
+ {
+ Thread.yield();
+ Thread.sleep(50);
+ }
+
+ // stop fullBackup
+
+ backup.stopBackup(bch);
+
+ // restore
+ RepositoryEntry baseRE = (RepositoryEntry)sessionWS.getContainer().getComponentInstanceOfType(RepositoryEntry.class);
+ RepositoryEntry re = makeRepositoryEntry(baseRE.getName() , baseRE, null, null);
+
+ File backLog = new File(bch.getLogFilePath());
+ if (backLog.exists())
+ {
+ RepositoryBackupChainLog bchLog = new RepositoryBackupChainLog(backLog);
+
+ assertNotNull(bchLog.getStartedTime());
+ assertNotNull(bchLog.getFinishedTime());
+
+ backup.restoreExistedRepository(bchLog, re, false);
+
+ assertEquals(JobWorkspaceRestore.RESTORE_SUCCESSFUL, backup.getLastRepositoryRestore(
+ re.getName()).getStateRestore());
+
+ // check
+ ManageableRepository restoredRepository = repositoryService.getRepository(re.getName());
+
+ for (String wsName : restoredRepository.getWorkspaceNames())
+ {
+ SessionImpl back1 = null;
+ try
+ {
+ back1 = (SessionImpl)restoredRepository.login(credentials, wsName);
+ Node ws1backTestRoot = back1.getRootNode().getNode("backupTest");
+ assertEquals("Restored content should be same", "property-5", ws1backTestRoot.getNode("node_5")
+ .getProperty("exo:data").getString());
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ fail(e.getMessage());
+ }
+ finally
+ {
+ if (back1 != null)
+ back1.logout();
+ }
+ }
+ }
+ else
+ fail("There are no backup files in " + backDir.getAbsolutePath());
+ }
+
public void testExistedRepositoryRestoreAsync() throws Exception
{
// backup
@@ -1869,4 +1958,90 @@
else
fail("There are no backup files in " + backDir.getAbsolutePath());
}
+
+ public void testExistedWorkspaceRestoreMultiDB() throws Exception
+ {
+ RepositoryImpl repositoryDB7 = (RepositoryImpl)repositoryService.getRepository("db7");
+
+ SessionImpl sessionWS = (SessionImpl) repositoryDB7.login(credentials, "ws1");
+
+ Node wsTestRoot = sessionWS.getRootNode().addNode("backupTest");
+ sessionWS.getRootNode().save();
+ addContent(wsTestRoot, 1, 10, 1);
+ sessionWS.getRootNode().save();
+
+ // backup
+ File backDir = new File("target/backup/ws1");
+ backDir.mkdirs();
+
+ BackupConfig config = new BackupConfig();
+ config.setRepository(repositoryDB7.getName());
+ config.setWorkspace("ws1");
+ config.setBackupType(BackupManager.FULL_BACKUP_ONLY);
+
+ config.setBackupDir(backDir);
+
+ backup.startBackup(config);
+
+ BackupChain bch = backup.findBackup(repositoryDB7.getName(), "ws1");
+
+ // wait till full backup will be stopped
+ while (bch.getFullBackupState() != BackupJob.FINISHED)
+ {
+ Thread.yield();
+ Thread.sleep(50);
+ }
+
+ // stop fullBackup
+
+ if (bch != null)
+ backup.stopBackup(bch);
+ else
+ fail("Can't get fullBackup chain");
+
+ // restore
+ RepositoryEntry re = (RepositoryEntry)sessionWS.getContainer().getComponentInstanceOfType(RepositoryEntry.class);
+ WorkspaceEntry ws1 = null;
+ for (WorkspaceEntry we : re.getWorkspaceEntries())
+ {
+ if (sessionWS.getWorkspace().getName().equals(we.getName()))
+ {
+ ws1 = we;
+ break;
+ }
+ }
+
+ File backLog = new File(bch.getLogFilePath());
+ if (backLog.exists())
+ {
+ BackupChainLog bchLog = new BackupChainLog(backLog);
+
+ assertNotNull(bchLog.getStartedTime());
+ assertNotNull(bchLog.getFinishedTime());
+
+ backup.restoreExistedWorkspace(bchLog, re.getName(), ws1, false);
+
+ // check
+ SessionImpl back1 = null;
+ try
+ {
+ back1 = (SessionImpl)repositoryDB7.login(credentials, "ws1");
+ Node ws1backTestRoot = back1.getRootNode().getNode("backupTest");
+ assertEquals("Restored content should be same", "property-5", ws1backTestRoot.getNode("node_5")
+ .getProperty("exo:data").getString());
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ fail(e.getMessage());
+ }
+ finally
+ {
+ if (back1 != null)
+ back1.logout();
+ }
+ }
+ else
+ fail("There are no backup files in " + backDir.getAbsolutePath());
+ }
}
Modified: jcr/trunk/exo.jcr.component.ext/src/test/resources/conf/standalone/test-configuration.xml
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/test/resources/conf/standalone/test-configuration.xml 2010-09-29 12:40:05 UTC (rev 3218)
+++ jcr/trunk/exo.jcr.component.ext/src/test/resources/conf/standalone/test-configuration.xml 2010-09-30 07:40:51 UTC (rev 3219)
@@ -1881,6 +1881,61 @@
<init-params>
<value-param>
<name>bind-name</name>
+ <value>jdbcjcr26</value>
+ </value-param>
+ <value-param>
+ <name>class-name</name>
+ <value>javax.sql.DataSource</value>
+ </value-param>
+ <value-param>
+ <name>factory</name>
+ <value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
+ </value-param>
+ <properties-param>
+ <name>ref-addresses</name>
+ <description>ref-addresses</description>
+ <property name="driverClassName" value="org.hsqldb.jdbcDriver" />
+ <property name="url" value="jdbc:hsqldb:file:target/temp/data/jcr26" />
+ <property name="username" value="sa" />
+ <property name="password" value="" />
+ </properties-param>
+ </init-params>
+ </component-plugin>
+
+ <component-plugin>
+ <name>bind.datasource</name>
+ <set-method>addPlugin</set-method>
+ <type>org.exoplatform.services.naming.BindReferencePlugin</type>
+ <init-params>
+ <value-param>
+ <name>bind-name</name>
+ <value>jdbcjcr27</value>
+ </value-param>
+ <value-param>
+ <name>class-name</name>
+ <value>javax.sql.DataSource</value>
+ </value-param>
+ <value-param>
+ <name>factory</name>
+ <value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
+ </value-param>
+ <properties-param>
+ <name>ref-addresses</name>
+ <description>ref-addresses</description>
+ <property name="driverClassName" value="org.hsqldb.jdbcDriver" />
+ <property name="url" value="jdbc:hsqldb:file:target/temp/data/jcr27" />
+ <property name="username" value="sa" />
+ <property name="password" value="" />
+ </properties-param>
+ </init-params>
+ </component-plugin>
+ <component-plugin>
+ <name>bind.datasource</name>
+ <set-method>addPlugin</set-method>
+ <type>org.exoplatform.services.naming.BindReferencePlugin</type>
+ <init-params>
+ <value-param>
+ <name>bind-name</name>
<value>jdbcjcr_to_rest_repo_1</value>
</value-param>
<value-param>
Modified: jcr/trunk/exo.jcr.component.ext/src/test/resources/conf/standalone/test-jcr-ext-config.xml
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/test/resources/conf/standalone/test-jcr-ext-config.xml 2010-09-29 12:40:05 UTC (rev 3218)
+++ jcr/trunk/exo.jcr.component.ext/src/test/resources/conf/standalone/test-jcr-ext-config.xml 2010-09-30 07:40:51 UTC (rev 3219)
@@ -36,6 +36,16 @@
<property name="max-buffer-size" value="200k" />
<property name="swap-directory" value="target/temp/swap/ws" />
</properties>
+ <value-storages>
+ <value-storage id="draft" class="org.exoplatform.services.jcr.impl.storage.value.fs.TreeFileValueStorage">
+ <properties>
+ <property name="path" value="../temp/values/backup" />
+ </properties>
+ <filters>
+ <filter property-type="Binary" />
+ </filters>
+ </value-storage>
+ </value-storages>
</container>
<cache enabled="true">
<properties>
@@ -338,7 +348,7 @@
</workspace>
</workspaces>
</repository>
- <repository name="db6" system-workspace="ws" default-workspace="ws">
+ <repository name="db7" system-workspace="ws" default-workspace="ws">
<security-domain>exo-domain</security-domain>
<access-control>optional</access-control>
<authentication-policy>org.exoplatform.services.jcr.impl.core.access.JAASAuthenticator</authentication-policy>
@@ -347,13 +357,23 @@
<!-- for system storage -->
<container class="org.exoplatform.services.jcr.impl.storage.jdbc.optimisation.CQJDBCWorkspaceDataContainer">
<properties>
- <property name="source-name" value="jdbcjcr24" />
+ <property name="source-name" value="jdbcjcr26" />
<property name="dialect" value="hsqldb" />
- <property name="multi-db" value="false" />
+ <property name="multi-db" value="true" />
<property name="update-storage" value="true" />
<property name="max-buffer-size" value="200k" />
- <property name="swap-directory" value="target/temp/swap/db6_ws" />
+ <property name="swap-directory" value="target/temp/swap/db7_ws" />
</properties>
+ <value-storages>
+ <value-storage id="draft" class="org.exoplatform.services.jcr.impl.storage.value.fs.TreeFileValueStorage">
+ <properties>
+ <property name="path" value="../temp/values/db7_ws" />
+ </properties>
+ <filters>
+ <filter property-type="Binary" />
+ </filters>
+ </value-storage>
+ </value-storages>
</container>
<cache enabled="true">
<properties>
@@ -363,20 +383,30 @@
</cache>
<query-handler class="org.exoplatform.services.jcr.impl.core.query.lucene.SearchIndex">
<properties>
- <property name="index-dir" value="target/temp/index/db6_ws" />
+ <property name="index-dir" value="target/temp/index/db7_ws" />
</properties>
</query-handler>
</workspace>
<workspace name="ws1">
<container class="org.exoplatform.services.jcr.impl.storage.jdbc.optimisation.CQJDBCWorkspaceDataContainer">
<properties>
- <property name="source-name" value="jdbcjcr24" />
+ <property name="source-name" value="jdbcjcr27" />
<property name="dialect" value="hsqldb" />
- <property name="multi-db" value="false" />
+ <property name="multi-db" value="true" />
<property name="update-storage" value="true" />
<property name="max-buffer-size" value="200k" />
- <property name="swap-directory" value="target/temp/swap/db6_ws1" />
+ <property name="swap-directory" value="target/temp/swap/db7_ws1" />
</properties>
+ <value-storages>
+ <value-storage id="draft" class="org.exoplatform.services.jcr.impl.storage.value.fs.TreeFileValueStorage">
+ <properties>
+ <property name="path" value="../temp/values/db7_ws1" />
+ </properties>
+ <filters>
+ <filter property-type="Binary" />
+ </filters>
+ </value-storage>
+ </value-storages>
</container>
<cache enabled="true">
<properties>
@@ -386,33 +416,10 @@
</cache>
<query-handler class="org.exoplatform.services.jcr.impl.core.query.lucene.SearchIndex">
<properties>
- <property name="index-dir" value="target/temp/index/db6_ws1" />
+ <property name="index-dir" value="target/temp/index/db7_ws1" />
</properties>
</query-handler>
</workspace>
- <workspace name="ws2">
- <container class="org.exoplatform.services.jcr.impl.storage.jdbc.optimisation.CQJDBCWorkspaceDataContainer">
- <properties>
- <property name="source-name" value="jdbcjcr24" />
- <property name="dialect" value="hsqldb" />
- <property name="multi-db" value="false" />
- <property name="update-storage" value="true" />
- <property name="max-buffer-size" value="200k" />
- <property name="swap-directory" value="target/temp/swap/db6_ws2" />
- </properties>
- </container>
- <cache enabled="true">
- <properties>
- <property name="max-size" value="5k" />
- <property name="live-time" value="1h" />
- </properties>
- </cache>
- <query-handler class="org.exoplatform.services.jcr.impl.core.query.lucene.SearchIndex">
- <properties>
- <property name="index-dir" value="target/temp/index/db6_ws2" />
- </properties>
- </query-handler>
- </workspace>
</workspaces>
</repository>
</repositories>
13 years, 7 months
exo-jcr SVN: r3218 - in jcr/trunk/exo.jcr.component.core/src: test/java/org/exoplatform/services/jcr/api/lock and 1 other directory.
by do-not-reply@jboss.org
Author: sergiykarpenko
Date: 2010-09-29 08:40:05 -0400 (Wed, 29 Sep 2010)
New Revision: 3218
Added:
jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/api/lock/TestLockPermissions.java
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/NodeImpl.java
Log:
EXOJCR-979: lock/unlock operations now checks does session have SET_PROPERTY permission
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/NodeImpl.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/NodeImpl.java 2010-09-29 09:52:33 UTC (rev 3217)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/NodeImpl.java 2010-09-29 12:40:05 UTC (rev 3218)
@@ -218,8 +218,8 @@
}
// Validate
- if (session.getWorkspace().getNodeTypesHolder()
- .isNodeType(type.getName(), nodeData().getPrimaryTypeName(), nodeData().getMixinTypeNames()))
+ if (session.getWorkspace().getNodeTypesHolder().isNodeType(type.getName(), nodeData().getPrimaryTypeName(),
+ nodeData().getMixinTypeNames()))
{
throw new ConstraintViolationException("Can not add mixin type " + mixinName + " to " + getPath());
}
@@ -285,8 +285,8 @@
// find node type
NodeDefinitionData nodeDef =
- session.getWorkspace().getNodeTypesHolder()
- .getChildNodeDefinition(name, nodeData().getPrimaryTypeName(), nodeData().getMixinTypeNames());
+ session.getWorkspace().getNodeTypesHolder().getChildNodeDefinition(name, nodeData().getPrimaryTypeName(),
+ nodeData().getMixinTypeNames());
if (nodeDef == null)
{
@@ -357,16 +357,16 @@
checkValid();
NodeTypeData type =
- session.getWorkspace().getNodeTypesHolder()
- .getNodeType(locationFactory.parseJCRName(mixinName).getInternalName());
+ session.getWorkspace().getNodeTypesHolder().getNodeType(
+ locationFactory.parseJCRName(mixinName).getInternalName());
if (type == null)
{
throw new NoSuchNodeTypeException("Nodetype not found (mixin) " + mixinName);
}
- if (session.getWorkspace().getNodeTypesHolder()
- .isNodeType(type.getName(), nodeData().getPrimaryTypeName(), nodeData().getMixinTypeNames()))
+ if (session.getWorkspace().getNodeTypesHolder().isNodeType(type.getName(), nodeData().getPrimaryTypeName(),
+ nodeData().getMixinTypeNames()))
{
return false;
}
@@ -789,8 +789,8 @@
for (int i = 1; i < myPath.getDepth(); i++)
{
ancestor = (NodeData)dataManager.getItemData(ancestor, myPath.getEntries()[i], ItemType.NODE);
- if (corrSession.getWorkspace().getNodeTypesHolder()
- .isNodeType(Constants.MIX_REFERENCEABLE, ancestor.getPrimaryTypeName(), ancestor.getMixinTypeNames()))
+ if (corrSession.getWorkspace().getNodeTypesHolder().isNodeType(Constants.MIX_REFERENCEABLE,
+ ancestor.getPrimaryTypeName(), ancestor.getMixinTypeNames()))
{
NodeData corrAncestor = (NodeData)corrDataManager.getItemData(ancestor.getIdentifier());
if (corrAncestor == null)
@@ -859,8 +859,8 @@
new NodeDefinitionData(null, null, true, true, OnParentVersionAction.ABORT, false,
new InternalQName[]{requiredName}, null, true);
this.nodeDefinition =
- new NodeDefinitionImpl(ntData, nodeTypesHolder, nodeTypeManager, sysLocFactory,
- session.getValueFactory(), session.getTransientNodesManager());
+ new NodeDefinitionImpl(ntData, nodeTypesHolder, nodeTypeManager, sysLocFactory, session
+ .getValueFactory(), session.getTransientNodesManager());
}
}
else
@@ -869,8 +869,8 @@
NodeData parent = (NodeData)dataManager.getItemData(getParentIdentifier());
this.definition =
- nodeTypesHolder.getChildNodeDefinition(getInternalName(), parent.getPrimaryTypeName(),
- parent.getMixinTypeNames());
+ nodeTypesHolder.getChildNodeDefinition(getInternalName(), parent.getPrimaryTypeName(), parent
+ .getMixinTypeNames());
if (definition == null)
{
@@ -886,8 +886,8 @@
}
nodeDefinition =
- new NodeDefinitionImpl(definition, nodeTypesHolder, nodeTypeManager, sysLocFactory,
- session.getValueFactory(), session.getTransientNodesManager());
+ new NodeDefinitionImpl(definition, nodeTypesHolder, nodeTypeManager, sysLocFactory, session
+ .getValueFactory(), session.getTransientNodesManager());
}
}
@@ -1468,8 +1468,8 @@
{
checkValid();
- return session.getWorkspace().getNodeTypesHolder()
- .isNodeType(qName, nodeData().getPrimaryTypeName(), nodeData().getMixinTypeNames());
+ return session.getWorkspace().getNodeTypesHolder().isNodeType(qName, nodeData().getPrimaryTypeName(),
+ nodeData().getMixinTypeNames());
}
/**
@@ -1559,8 +1559,8 @@
}
this.definition =
- session.getWorkspace().getNodeTypesHolder()
- .getChildNodeDefinition(getInternalName(), parent.getPrimaryTypeName(), parent.getMixinTypeNames());
+ session.getWorkspace().getNodeTypesHolder().getChildNodeDefinition(getInternalName(),
+ parent.getPrimaryTypeName(), parent.getMixinTypeNames());
if (definition == null)
{
@@ -1591,6 +1591,15 @@
throw new LockException("Node is not lockable " + getPath());
}
+ // session.checkPermission(getPath(), PermissionType.SET_PROPERTY) is not used because RepositoryException
+ // is wrapped into AccessControlException
+ if (!session.getAccessManager().hasPermission(getACL(), new String[]{PermissionType.SET_PROPERTY},
+ session.getUserState().getIdentity()))
+ {
+ throw new AccessDeniedException("Access denied: lock operation " + getPath() + " for: " + session.getUserID()
+ + " item owner " + getACL().getOwner());
+ }
+
if (dataManager.hasPendingChanges(getInternalPath()))
{
throw new InvalidItemStateException("Node has pending unsaved changes " + getPath());
@@ -1631,6 +1640,15 @@
throw new LockException("Node is not lockable " + getPath());
}
+ // session.checkPermission(getPath(), PermissionType.SET_PROPERTY) is not used because RepositoryException
+ // is wrapped into AccessControlException
+ if (!session.getAccessManager().hasPermission(getACL(), new String[]{PermissionType.SET_PROPERTY},
+ session.getUserState().getIdentity()))
+ {
+ throw new AccessDeniedException("Access denied: lock operation " + getPath() + " for: " + session.getUserID()
+ + " item owner " + getACL().getOwner());
+ }
+
if (dataManager.hasPendingChanges(getInternalPath()))
{
throw new InvalidItemStateException("Node has pending unsaved changes " + getPath());
@@ -1962,7 +1980,7 @@
QPath destPath = locationFactory.parseRelPath(relPath).getInternalPath();
NodeImpl destParent =
(NodeImpl)dataManager.getItem(nodeData(), destPath.makeParentPath().getEntries(), false, ItemType.NODE);
-
+
if (destParent == null)
{
throw new PathNotFoundException("Parent not found for " + relPath);
@@ -2125,8 +2143,8 @@
checkValid();
- return doUpdateProperty(this, locationFactory.parseJCRName(name).getInternalName(),
- valueFactory.createValue(value), false, PropertyType.UNDEFINED);
+ return doUpdateProperty(this, locationFactory.parseJCRName(name).getInternalName(), valueFactory
+ .createValue(value), false, PropertyType.UNDEFINED);
}
@@ -2139,8 +2157,8 @@
checkValid();
- return doUpdateProperty(this, locationFactory.parseJCRName(name).getInternalName(),
- valueFactory.createValue(value), false, PropertyType.UNDEFINED);
+ return doUpdateProperty(this, locationFactory.parseJCRName(name).getInternalName(), valueFactory
+ .createValue(value), false, PropertyType.UNDEFINED);
}
@@ -2153,8 +2171,8 @@
checkValid();
- return doUpdateProperty(this, locationFactory.parseJCRName(name).getInternalName(),
- valueFactory.createValue(value), false, PropertyType.UNDEFINED);
+ return doUpdateProperty(this, locationFactory.parseJCRName(name).getInternalName(), valueFactory
+ .createValue(value), false, PropertyType.UNDEFINED);
}
/**
@@ -2166,8 +2184,8 @@
checkValid();
- return doUpdateProperty(this, locationFactory.parseJCRName(name).getInternalName(),
- valueFactory.createValue(value), false, PropertyType.UNDEFINED);
+ return doUpdateProperty(this, locationFactory.parseJCRName(name).getInternalName(), valueFactory
+ .createValue(value), false, PropertyType.UNDEFINED);
}
/**
@@ -2179,8 +2197,8 @@
checkValid();
- return doUpdateProperty(this, locationFactory.parseJCRName(name).getInternalName(),
- valueFactory.createValue(value), false, PropertyType.UNDEFINED);
+ return doUpdateProperty(this, locationFactory.parseJCRName(name).getInternalName(), valueFactory
+ .createValue(value), false, PropertyType.UNDEFINED);
}
@@ -2193,8 +2211,8 @@
checkValid();
- return doUpdateProperty(this, locationFactory.parseJCRName(name).getInternalName(),
- valueFactory.createValue(value), false, PropertyType.UNDEFINED);
+ return doUpdateProperty(this, locationFactory.parseJCRName(name).getInternalName(), valueFactory
+ .createValue(value), false, PropertyType.UNDEFINED);
}
@@ -2207,8 +2225,8 @@
checkValid();
- return doUpdateProperty(this, locationFactory.parseJCRName(name).getInternalName(),
- valueFactory.createValue(value), false, PropertyType.UNDEFINED);
+ return doUpdateProperty(this, locationFactory.parseJCRName(name).getInternalName(), valueFactory
+ .createValue(value), false, PropertyType.UNDEFINED);
}
@@ -2221,8 +2239,8 @@
checkValid();
- return doUpdateProperty(this, locationFactory.parseJCRName(name).getInternalName(),
- valueFactory.createValue(value, type), false, type);
+ return doUpdateProperty(this, locationFactory.parseJCRName(name).getInternalName(), valueFactory.createValue(
+ value, type), false, type);
}
/**
@@ -2344,6 +2362,15 @@
throw new InvalidItemStateException("Node has pending unsaved changes " + getPath());
}
+ // session.checkPermission(getPath(), PermissionType.SET_PROPERTY) is not used because RepositoryException
+ // is wrapped into AccessControlException
+ if (!session.getAccessManager().hasPermission(getACL(), new String[]{PermissionType.SET_PROPERTY},
+ session.getUserState().getIdentity()))
+ {
+ throw new AccessDeniedException("Access denied: unlock operation " + getPath() + " for: "
+ + session.getUserID() + " item owner " + getACL().getOwner());
+ }
+
doUnlock();
session.getActionHandler().postUnlock(this);
@@ -2433,8 +2460,8 @@
}
// Check if node is not protected
NodeDefinitionData childNodeDefinition =
- session.getWorkspace().getNodeTypesHolder()
- .getChildNodeDefinition(name, nodeData().getPrimaryTypeName(), nodeData().getMixinTypeNames());
+ session.getWorkspace().getNodeTypesHolder().getChildNodeDefinition(name, nodeData().getPrimaryTypeName(),
+ nodeData().getMixinTypeNames());
if (childNodeDefinition == null)
{
throw new ConstraintViolationException("Can't find child node definition for "
@@ -2651,16 +2678,16 @@
QPath.makeChildPath(newData.getQPath().makeParentPath(), newData.getQPath().getName(), sameNameIndex);
newData =
- new TransientNodeData(siblingPath, newData.getIdentifier(), newData.getPersistedVersion(),
- newData.getPrimaryTypeName(), newData.getMixinTypeNames(), j, newData.getParentIdentifier(),
- newData.getACL());
+ new TransientNodeData(siblingPath, newData.getIdentifier(), newData.getPersistedVersion(), newData
+ .getPrimaryTypeName(), newData.getMixinTypeNames(), j, newData.getParentIdentifier(), newData
+ .getACL());
}
else
{
newData =
new TransientNodeData(newData.getQPath(), newData.getIdentifier(), newData.getPersistedVersion(),
- newData.getPrimaryTypeName(), newData.getMixinTypeNames(), j, newData.getParentIdentifier(),
- newData.getACL());
+ newData.getPrimaryTypeName(), newData.getMixinTypeNames(), j, newData.getParentIdentifier(), newData
+ .getACL());
}
/*
@@ -2774,9 +2801,8 @@
}
TransientPropertyData tdata =
- new TransientPropertyData(QPath.makeChildPath(getInternalPath(), name), existed.getIdentifier(),
- existed.getPersistedVersion(), existed.getType(), existed.getParentIdentifier(), existed.isMultiValued(),
- values);
+ new TransientPropertyData(QPath.makeChildPath(getInternalPath(), name), existed.getIdentifier(), existed
+ .getPersistedVersion(), existed.getType(), existed.getParentIdentifier(), existed.isMultiValued(), values);
return tdata;
}
@@ -2794,9 +2820,8 @@
}
TransientPropertyData tdata =
- new TransientPropertyData(QPath.makeChildPath(getInternalPath(), name), existed.getIdentifier(),
- existed.getPersistedVersion(), existed.getType(), existed.getParentIdentifier(), existed.isMultiValued(),
- value);
+ new TransientPropertyData(QPath.makeChildPath(getInternalPath(), name), existed.getIdentifier(), existed
+ .getPersistedVersion(), existed.getType(), existed.getParentIdentifier(), existed.isMultiValued(), value);
return tdata;
}
@@ -2858,9 +2883,9 @@
}
mergeFailed =
- new TransientPropertyData(mergeFailed.getQPath(), mergeFailed.getIdentifier(),
- mergeFailed.getPersistedVersion(), mergeFailed.getType(), mergeFailed.getParentIdentifier(),
- mergeFailed.isMultiValued(), mergeFailedRefs);
+ new TransientPropertyData(mergeFailed.getQPath(), mergeFailed.getIdentifier(), mergeFailed
+ .getPersistedVersion(), mergeFailed.getType(), mergeFailed.getParentIdentifier(), mergeFailed
+ .isMultiValued(), mergeFailedRefs);
state = ItemState.UPDATED;
}
@@ -2914,8 +2939,8 @@
{
NodeDefinitionData def =
- session.getWorkspace().getNodeTypesHolder()
- .getChildNodeDefinition(nameToAdd, parentNode.getPrimaryTypeName(), parentNode.getMixinTypeNames());
+ session.getWorkspace().getNodeTypesHolder().getChildNodeDefinition(nameToAdd, parentNode.getPrimaryTypeName(),
+ parentNode.getMixinTypeNames());
boolean allowSns = def.isAllowsSameNameSiblings();
@@ -2973,8 +2998,8 @@
// create new nodedata, [PN] fix of use index as persisted version
NodeData nodeData =
- new TransientNodeData(path, identifier, -1, primaryTypeName, mixinTypeNames, orderNum,
- parentNode.getInternalIdentifier(), acl);
+ new TransientNodeData(path, identifier, -1, primaryTypeName, mixinTypeNames, orderNum, parentNode
+ .getInternalIdentifier(), acl);
// Create new Node
ItemState state = ItemState.createAddedState(nodeData, false);
@@ -3062,10 +3087,9 @@
// to jcr:predecessors (with doneMerge) or just removed from
// jcr:mergeFailed (with cancelMerge) the jcr:mergeFailed
// property is automatically remove
- changesLog.add(ItemState.createDeletedState(
- new TransientPropertyData(mergeFailed.getQPath(), mergeFailed.getIdentifier(), mergeFailed
- .getPersistedVersion(), mergeFailed.getType(), mergeFailed.getParentIdentifier(), mergeFailed
- .isMultiValued(), mergeFailed.getValues()), true));
+ changesLog.add(ItemState.createDeletedState(new TransientPropertyData(mergeFailed.getQPath(), mergeFailed
+ .getIdentifier(), mergeFailed.getPersistedVersion(), mergeFailed.getType(), mergeFailed
+ .getParentIdentifier(), mergeFailed.isMultiValued(), mergeFailed.getValues()), true));
}
}
@@ -3073,9 +3097,9 @@
{
NodeData nodeData = (NodeData)data;
data =
- new TransientNodeData(nodeData.getQPath(), nodeData.getIdentifier(), nodeData.getPersistedVersion(),
- nodeData.getPrimaryTypeName(), nodeData.getMixinTypeNames(), nodeData.getOrderNumber(),
- nodeData.getParentIdentifier(), acl);
+ new TransientNodeData(nodeData.getQPath(), nodeData.getIdentifier(), nodeData.getPersistedVersion(), nodeData
+ .getPrimaryTypeName(), nodeData.getMixinTypeNames(), nodeData.getOrderNumber(), nodeData
+ .getParentIdentifier(), acl);
}
private void updateMixin(List<InternalQName> newMixin) throws RepositoryException
@@ -3086,9 +3110,8 @@
NodeData nodeData = (NodeData)data;
data =
- new TransientNodeData(nodeData.getQPath(), nodeData.getIdentifier(), nodeData.getPersistedVersion(),
- nodeData.getPrimaryTypeName(), mixins, nodeData.getOrderNumber(), nodeData.getParentIdentifier(),
- nodeData.getACL());
+ new TransientNodeData(nodeData.getQPath(), nodeData.getIdentifier(), nodeData.getPersistedVersion(), nodeData
+ .getPrimaryTypeName(), mixins, nodeData.getOrderNumber(), nodeData.getParentIdentifier(), nodeData.getACL());
// ((TransientNodeData)data).setMixinTypeNames(mixins);
Added: jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/api/lock/TestLockPermissions.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/api/lock/TestLockPermissions.java (rev 0)
+++ jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/api/lock/TestLockPermissions.java 2010-09-29 12:40:05 UTC (rev 3218)
@@ -0,0 +1,250 @@
+/*
+ * Copyright (C) 2003-2010 eXo Platform SAS.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Affero General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see<http://www.gnu.org/licenses/>.
+ */
+package org.exoplatform.services.jcr.api.lock;
+
+import org.exoplatform.services.jcr.JcrAPIBaseTest;
+import org.exoplatform.services.jcr.access.PermissionType;
+import org.exoplatform.services.jcr.core.CredentialsImpl;
+import org.exoplatform.services.jcr.impl.core.NodeImpl;
+
+import java.security.AccessControlException;
+import java.util.HashMap;
+
+import javax.jcr.AccessDeniedException;
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.jcr.lock.Lock;
+
+/**
+ * Created by The eXo Platform SAS.
+ *
+ * <br/>Date:
+ *
+ * @author <a href="karpenko.sergiy(a)gmail.com">Karpenko Sergiy</a>
+ * @version $Id: TestLockPermissions.java 111 2008-11-11 11:11:11Z serg $
+ */
+public class TestLockPermissions extends JcrAPIBaseTest
+{
+
+ private Node lockedNode = null;
+
+ public void setUp() throws Exception
+ {
+
+ super.setUp();
+
+ if (lockedNode == null)
+ try
+ {
+ lockedNode = root.addNode("rootLockPermissionsTest");
+ // if (lockedNode.canAddMixin("mix:lockable"))
+ // lockedNode.addMixin("mix:lockable");
+ root.save();
+ }
+ catch (RepositoryException e)
+ {
+ fail("Child node must be accessible and readable. But error occurs: " + e);
+ }
+ }
+
+ @Override
+ public void tearDown() throws Exception
+ {
+ lockedNode.remove();
+ session.save();
+ super.tearDown();
+ }
+
+ public void testLockAccessDeniedException() throws RepositoryException
+ {
+ Session session1 = repository.login(new CredentialsImpl("root", "exo".toCharArray()), "ws");
+ NodeImpl nodeToLockSession1 =
+ (NodeImpl)session1.getRootNode().getNode("rootLockPermissionsTest").addNode("testLockSesssionScoped");
+ nodeToLockSession1.addMixin("mix:lockable");
+ nodeToLockSession1.addMixin("exo:owneable");
+ nodeToLockSession1.addMixin("exo:privilegeable");
+
+ // change permission
+ HashMap<String, String[]> perm = new HashMap<String, String[]>();
+ perm.put("john", new String[]{PermissionType.READ});
+ nodeToLockSession1.setPermissions(perm);
+ session1.save();
+
+ nodeToLockSession1.lock(true, false);// boolean isSessionScoped=false
+ assertTrue(nodeToLockSession1.isLocked());
+ nodeToLockSession1.unlock();
+ assertFalse(nodeToLockSession1.isLocked());
+
+ Session session2 = repository.login(new CredentialsImpl("john", "exo".toCharArray()), "ws");
+ session2.checkPermission(nodeToLockSession1.getPath(), PermissionType.READ);
+ try
+ {
+ session2.checkPermission(nodeToLockSession1.getPath(), PermissionType.SET_PROPERTY);
+ fail("AccessControlException should have been thrown ");
+ }
+ catch (AccessControlException e)
+ {
+ //ok
+ }
+
+ Node nodeToLockSession2 =
+ session2.getRootNode().getNode("rootLockPermissionsTest").getNode("testLockSesssionScoped");
+ assertFalse(nodeToLockSession2.isLocked());
+ try
+ {
+ try
+ {
+ // trying to lock
+ nodeToLockSession2.lock(true, false);
+ fail("Node locked. An AccessDeniedException should be thrown on set property but doesn't");
+ }
+ catch (AccessDeniedException e)
+ {
+ // ok
+ }
+ }
+ finally
+ {
+ if (nodeToLockSession1.isLocked())
+ {
+ nodeToLockSession1.unlock();
+ }
+ session1.logout();
+ session2.logout();
+ }
+ }
+
+ public void testLockTimedAccessDeniedException() throws RepositoryException
+ {
+ Session session1 = repository.login(new CredentialsImpl("root", "exo".toCharArray()), "ws");
+ NodeImpl nodeToLockSession1 =
+ (NodeImpl)session1.getRootNode().getNode("rootLockPermissionsTest").addNode("testLockTimed");
+ nodeToLockSession1.addMixin("mix:lockable");
+ nodeToLockSession1.addMixin("exo:owneable");
+ nodeToLockSession1.addMixin("exo:privilegeable");
+
+ // change permission
+ HashMap<String, String[]> perm = new HashMap<String, String[]>();
+ perm.put("john", new String[]{PermissionType.READ});
+ nodeToLockSession1.setPermissions(perm);
+ session1.save();
+
+ nodeToLockSession1.lock(true, 100000);
+ assertTrue(nodeToLockSession1.isLocked());
+ nodeToLockSession1.unlock();
+ assertFalse(nodeToLockSession1.isLocked());
+
+ Session session2 = repository.login(new CredentialsImpl("john", "exo".toCharArray()), "ws");
+ session2.checkPermission(nodeToLockSession1.getPath(), PermissionType.READ);
+ try
+ {
+ session2.checkPermission(nodeToLockSession1.getPath(), PermissionType.SET_PROPERTY);
+ fail("AccessControlException should have been thrown ");
+ }
+ catch (AccessControlException e)
+ {
+ //ok
+ }
+
+ NodeImpl nodeToLockSession2 =
+ (NodeImpl)session2.getRootNode().getNode("rootLockPermissionsTest").getNode("testLockTimed");
+ assertFalse(nodeToLockSession2.isLocked());
+ try
+ {
+ try
+ {
+ // trying to lock
+ nodeToLockSession2.lock(true, 100000);
+ fail("Node locked. An AccessDeniedException should be thrown on set property but doesn't");
+ }
+ catch (AccessDeniedException e)
+ {
+ // ok
+ }
+ }
+ finally
+ {
+ if (nodeToLockSession1.isLocked())
+ {
+ nodeToLockSession1.unlock();
+ }
+ session1.logout();
+ session2.logout();
+ }
+ }
+
+ public void testUnlockAccessDeniedException() throws RepositoryException
+ {
+ Session session1 = repository.login(new CredentialsImpl("root", "exo".toCharArray()), "ws");
+ NodeImpl nodeToLockSession1 =
+ (NodeImpl)session1.getRootNode().getNode("rootLockPermissionsTest").addNode("testUnlock");
+ nodeToLockSession1.addMixin("mix:lockable");
+ nodeToLockSession1.addMixin("exo:owneable");
+ nodeToLockSession1.addMixin("exo:privilegeable");
+
+ // change permission
+ HashMap<String, String[]> perm = new HashMap<String, String[]>();
+ perm.put("john", new String[]{PermissionType.READ});
+ nodeToLockSession1.setPermissions(perm);
+ session1.save();
+
+ Lock lock = nodeToLockSession1.lock(true, 100000);
+ assertTrue(nodeToLockSession1.isLocked());
+
+ Session session2 = repository.login(new CredentialsImpl("john", "exo".toCharArray()), "ws");
+ session2.checkPermission(nodeToLockSession1.getPath(), PermissionType.READ);
+ try
+ {
+ session2.checkPermission(nodeToLockSession1.getPath(), PermissionType.SET_PROPERTY);
+ fail("AccessControlException should have been thrown ");
+ }
+ catch (AccessControlException e)
+ {
+ //ok
+ }
+
+ NodeImpl nodeToLockSession2 =
+ (NodeImpl)session2.getRootNode().getNode("rootLockPermissionsTest").getNode("testUnlock");
+ assertTrue(nodeToLockSession2.isLocked());
+ try
+ {
+ try
+ {
+ session2.addLockToken(lock.getLockToken());
+
+ // trying to unlock
+ nodeToLockSession2.unlock();
+ fail("Node locked. An AccessDeniedException should be thrown on set property but doesn't");
+ }
+ catch (AccessDeniedException e)
+ {
+ // ok
+ }
+ }
+ finally
+ {
+ if (nodeToLockSession1.isLocked())
+ {
+ nodeToLockSession1.unlock();
+ }
+ session1.logout();
+ session2.logout();
+ }
+ }
+
+}
13 years, 7 months