Author: areshetnyak
Date: 2011-11-29 06:55:14 -0500 (Tue, 29 Nov 2011)
New Revision: 5243
Modified:
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/script/groovy/GroovyScript2RestLoaderPlugin.java
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/script/groovy/GroovyScriptAddRepoPlugin.java
Log:
EXOJCR-1659 : GroovyScriptAddRepoPlugin and the GroovyScript2RestLoaderPlugin are used
current repository if repository name was not previously configured.
Modified:
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/script/groovy/GroovyScript2RestLoaderPlugin.java
===================================================================
---
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/script/groovy/GroovyScript2RestLoaderPlugin.java 2011-11-29
09:32:41 UTC (rev 5242)
+++
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/script/groovy/GroovyScript2RestLoaderPlugin.java 2011-11-29
11:55:14 UTC (rev 5243)
@@ -21,6 +21,7 @@
import org.exoplatform.container.component.BaseComponentPlugin;
import org.exoplatform.container.xml.InitParams;
import org.exoplatform.container.xml.PropertiesParam;
+import org.exoplatform.services.jcr.RepositoryService;
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;
@@ -28,6 +29,8 @@
import java.util.Iterator;
import java.util.List;
+import javax.jcr.RepositoryException;
+
/**
* @author <a href="mailto:andrew00x@gmail.com">Andrey
Parfonov</a>
* @version $Id: GroovyScript2RestLoaderPlugin.java 34445 2009-07-24 07:51:18Z dkatayev
$
@@ -38,6 +41,9 @@
/** Logger. */
private static final Log LOG =
ExoLogger.getLogger("exo.jcr.component.ext.GroovyScript2RestLoaderPlugin");
+ /** Repository service **/
+ private static RepositoryService repositoryService;
+
/** Configurations for scripts what were got from XML. */
private List<XMLGroovyScript2Rest> l = new
ArrayList<XMLGroovyScript2Rest>();
@@ -51,9 +57,12 @@
private String node;
@SuppressWarnings("unchecked")
- public GroovyScript2RestLoaderPlugin(InitParams params)
+ public GroovyScript2RestLoaderPlugin(InitParams params, RepositoryService
repoServiceo)
{
- repository = params.getValueParam("repository").getValue();
+ this.repositoryService = repoServiceo;
+
+ repository = params.containsKey("repository") ?
params.getValueParam("repository").getValue() : null;
+
workspace = params.getValueParam("workspace").getValue();
node = params.getValueParam("node").getValue();
Iterator<PropertiesParam> iterator = params.getPropertiesParamIterator();
@@ -75,11 +84,30 @@
}
/**
- * @return the repository
+ * Get working repository name. Returns the repository name from configuration
+ * if it previously configured and returns the name of current repository in other
case.
+ *
+ * @return String
+ * repository name
+ * @throws RepositoryException
*/
public String getRepository()
{
- return repository;
+ if (repository == null)
+ {
+ try
+ {
+ return
repositoryService.getCurrentRepository().getConfiguration().getName();
+ }
+ catch (RepositoryException e)
+ {
+ throw new RuntimeException("Can not get current repository and
repository name was not configured", e);
+ }
+ }
+ else
+ {
+ return repository;
+ }
}
/**
Modified:
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/script/groovy/GroovyScriptAddRepoPlugin.java
===================================================================
---
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/script/groovy/GroovyScriptAddRepoPlugin.java 2011-11-29
09:32:41 UTC (rev 5242)
+++
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/script/groovy/GroovyScriptAddRepoPlugin.java 2011-11-29
11:55:14 UTC (rev 5243)
@@ -23,6 +23,7 @@
import org.exoplatform.container.component.BaseComponentPlugin;
import org.exoplatform.container.xml.InitParams;
import org.exoplatform.container.xml.PropertiesParam;
+import org.exoplatform.services.jcr.RepositoryService;
import org.exoplatform.services.jcr.ext.resource.UnifiedNodeReference;
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;
@@ -37,6 +38,8 @@
import java.util.Iterator;
import java.util.Set;
+import javax.jcr.RepositoryException;
+
/**
* @author <a href="mailto:andrew00x@gmail.com">Andrey
Parfonov</a>
* @version $Id$
@@ -49,9 +52,12 @@
private final InitParams params;
- public GroovyScriptAddRepoPlugin(InitParams params)
+ private final RepositoryService repositoryService;
+
+ public GroovyScriptAddRepoPlugin(InitParams params, RepositoryService repoService)
{
this.params = params;
+ this.repositoryService = repoService;
}
@SuppressWarnings("unchecked")
@@ -65,7 +71,8 @@
while (iterator.hasNext())
{
PropertiesParam p = iterator.next();
- final String repository = p.getProperty("repository");
+ final String repository = getWorkingRepositoryName(p);
+
final String workspace = p.getProperty("workspace");
final String path = p.getProperty("path");
try
@@ -87,4 +94,34 @@
}
return repos;
}
+
+ /**
+ * Get working repository name. Returns the repository name from configuration
+ * if it previously configured and returns the name of current repository in other
case.
+ *
+ * @props PropertiesParam
+ * the properties parameters
+ * @return String
+ * repository name
+ * @throws RepositoryException
+ */
+ private String getWorkingRepositoryName(PropertiesParam props)
+ {
+
+ if (props.getProperty("repository") == null)
+ {
+ try
+ {
+ return
repositoryService.getCurrentRepository().getConfiguration().getName();
+ }
+ catch (RepositoryException e)
+ {
+ throw new RuntimeException("Can not get current repository and
repository name was not configured", e);
+ }
+ }
+ else
+ {
+ return props.getProperty("repository");
+ }
+ }
}
Show replies by date