Skip to content
This repository was archived by the owner on Sep 16, 2024. It is now read-only.

Commit 5f66b45

Browse files
committed
Merging 2.10.0 from dev
1 parent 2d8d613 commit 5f66b45

File tree

12 files changed

+378
-112
lines changed

12 files changed

+378
-112
lines changed

build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ dependencies {
2020
compile 'org.springframework:spring-context:4.1.5.RELEASE'
2121

2222
testCompile 'junit:junit:4+'
23+
testCompile 'org.springframework:spring-test:4.1.5.RELEASE'
2324

2425
// Used for testing loading modules from the classpath
2526
testRuntime files("lib/modules.jar")

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
group=com.marklogic
22
javadocsDir=../gh-pages-marklogic-java/javadocs
3-
version=2.9.1
3+
version=2.10.0

src/main/java/com/marklogic/client/helper/DatabaseClientConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public class DatabaseClientConfig {
1515
private Authentication authentication = Authentication.DIGEST;
1616
private SSLContext sslContext;
1717
private SSLHostnameVerifier sslHostnameVerifier;
18-
18+
1919
public DatabaseClientConfig(String host, int port, String username, String password) {
2020
this.host = host;
2121
this.port = port;

src/main/java/com/marklogic/client/modulesloader/tokenreplacer/DefaultModuleTokenReplacer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public class DefaultModuleTokenReplacer extends LoggingObject implements ModuleT
2020
private Properties properties;
2121
private PropertyPlaceholderHelper helper;
2222
private List<PropertiesSource> propertiesSources = new ArrayList<>();
23-
private String propertyPrefix = "@ml.";
23+
private String propertyPrefix;
2424

2525
public void addPropertiesSource(PropertiesSource source) {
2626
this.propertiesSources.add(source);

src/main/java/com/marklogic/client/modulesloader/tokenreplacer/RoxyModuleTokenReplacer.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ public class RoxyModuleTokenReplacer extends DefaultModuleTokenReplacer {
1010

1111
public RoxyModuleTokenReplacer() {
1212
super();
13+
setPropertyPrefix("@ml.");
1314
addPropertiesSource(new FilePropertiesSource(new File("deploy/default.properties")));
1415
addPropertiesSource(new FilePropertiesSource(new File("deploy/build.properties")));
1516
addPropertiesSource(new FilePropertiesSource(new File("deploy/local.properties")));

src/main/java/com/marklogic/client/qconsole/impl/DefaultWorkspaceManager.java

Lines changed: 94 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -16,110 +16,101 @@
1616

1717
/**
1818
* Default implementation that uses the ML Java Client API to manage workspaces. By default, workspaces
19-
* will be exported and imported to/from ~/.qconsole/workspaces/(ML username).
19+
* will be exported and imported to/from ~/.qconsole/workspaces/(ML username). This can be overridden by
20+
* calling setBaseDir.
2021
*/
2122
public class DefaultWorkspaceManager extends LoggingObject implements WorkspaceManager {
2223

23-
private DatabaseClient client;
24-
25-
private File baseDir;
26-
27-
public DefaultWorkspaceManager(DatabaseClient client) {
28-
this.client = client;
29-
}
30-
31-
@Override
32-
public List<File> exportWorkspaces(String user, String... workspaceNames) {
33-
String xquery = "declare namespace qconsole='http://marklogic.com/appservices/qconsole'; " +
34-
"declare variable $user external; " +
35-
"cts:search(/qconsole:workspace, cts:element-value-query(xs:QName('qconsole:userid'), string(xdmp:user($user))))";
36-
37-
EvalResultIterator result = client.newServerEval()
38-
.addVariable("user", user)
39-
.xquery(xquery).eval();
40-
41-
if (baseDir == null) {
42-
baseDir = getDefaultWorkspacesDir();
43-
}
44-
45-
File userDir = new File(baseDir, user);
46-
userDir.mkdirs();
47-
48-
List<File> files = new ArrayList<>();
49-
50-
while (result.hasNext()) {
51-
DOMHandle dom = result.next().get(new DOMHandle());
52-
String workspaceId = getWorkspaceId(dom);
53-
File f = new File(userDir, workspaceId + ".xml");
54-
try {
55-
FileCopyUtils.copy(dom.toBuffer(), f);
56-
if (logger.isInfoEnabled()) {
57-
logger.info(format("Exported workspace %s to %s", workspaceId, f.getAbsolutePath()));
58-
}
59-
files.add(f);
60-
} catch (IOException ie) {
61-
throw new RuntimeException("Unable to write workspace XML to file, workspace ID: " + workspaceId + "; cause: " + ie.getMessage());
62-
}
63-
}
64-
65-
return files;
66-
}
67-
68-
protected String getWorkspaceId(DOMHandle dom) {
69-
return dom.get().getDocumentElement().getElementsByTagNameNS("http://marklogic.com/appservices/qconsole", "id").item(0).getTextContent();
70-
}
71-
72-
@Override
73-
public List<File> importWorkspaces(String user, String... workspaceNames) {
74-
if (baseDir == null) {
75-
baseDir = getDefaultWorkspacesDir();
76-
}
77-
78-
List<File> files = new ArrayList<>();
79-
80-
File userDir = new File(baseDir, user);
81-
if (!userDir.exists()) {
82-
return files;
83-
}
84-
85-
String xquery = "import module namespace amped-qconsole = 'http://marklogic.com/appservices/qconsole/util-amped' at '/MarkLogic/appservices/qconsole/qconsole-amped.xqy'; " +
86-
"declare variable $workspace external; " +
87-
"declare variable $uri external; " +
88-
"amped-qconsole:qconsole-document-insert($uri, $workspace)";
89-
90-
for (File f : userDir.listFiles()) {
91-
if (f.isFile() && f.getName().endsWith(".xml")) {
92-
client.newServerEval()
93-
.addVariable("uri", "/workspaces/" + f.getName())
94-
.addVariable("workspace", new FileHandle(f).withFormat(Format.XML))
95-
.xquery(xquery).eval();
96-
97-
if (logger.isInfoEnabled()) {
98-
logger.info(format("Imported workspace from %s", f.getAbsolutePath()));
99-
}
100-
101-
files.add(f);
102-
}
103-
}
104-
105-
return files;
106-
}
107-
108-
/**
109-
* Defaults to ~/.qconsole/workspaces.
110-
*
111-
* @return
112-
*/
113-
protected File getDefaultWorkspacesDir() {
114-
File homeDir = new File(System.getProperty("user.home"));
115-
File qcDir = new File(homeDir, ".qconsole");
116-
File dir = new File(qcDir, "workspaces");
117-
dir.mkdirs();
118-
return dir;
119-
}
120-
121-
122-
public void setBaseDir(File baseDir) {
123-
this.baseDir = baseDir;
124-
}
24+
private DatabaseClient client;
25+
26+
private File baseDir;
27+
28+
public DefaultWorkspaceManager(DatabaseClient client) {
29+
this.client = client;
30+
}
31+
32+
@Override
33+
public List<File> exportWorkspaces(String user, String... workspaceNames) {
34+
if (baseDir == null) {
35+
baseDir = getDefaultWorkspacesDir();
36+
}
37+
38+
File userDir = new File(baseDir, user);
39+
userDir.mkdirs();
40+
41+
List<File> files = new ArrayList<>();
42+
43+
for (String workspaceName : workspaceNames) {
44+
EvalResultIterator result = client.newServerEval()
45+
.addVariable("user", user)
46+
.addVariable("workspace", workspaceName)
47+
.xquery(QconsoleScripts.EXPORT).eval();
48+
49+
while (result.hasNext()) {
50+
DOMHandle dom = result.next().get(new DOMHandle());
51+
File f = new File(userDir, workspaceName + ".xml");
52+
try {
53+
FileCopyUtils.copy(dom.toBuffer(), f);
54+
if (logger.isInfoEnabled()) {
55+
logger.info(format("Exported workspace %s to %s", workspaceName, f.getAbsolutePath()));
56+
}
57+
files.add(f);
58+
} catch (IOException ie) {
59+
throw new RuntimeException("Unable to write workspace XML to file, workspace: " + workspaceName + "; cause: " + ie.getMessage());
60+
}
61+
}
62+
}
63+
64+
return files;
65+
}
66+
67+
@Override
68+
public List<File> importWorkspaces(String user, String... workspaceNames) {
69+
if (baseDir == null) {
70+
baseDir = getDefaultWorkspacesDir();
71+
}
72+
73+
List<File> files = new ArrayList<>();
74+
75+
File userDir = new File(baseDir, user);
76+
if (!userDir.exists()) {
77+
return files;
78+
}
79+
80+
for (String workspace : workspaceNames) {
81+
File f = new File(userDir, workspace + ".xml");
82+
if (f.isFile() && f.exists()) {
83+
client.newServerEval()
84+
.addVariable("user", user)
85+
.addVariable("exported-workspace", new FileHandle(f).withFormat(Format.XML))
86+
.xquery(QconsoleScripts.IMPORT).eval();
87+
88+
if (logger.isInfoEnabled()) {
89+
logger.info(format("Imported workspace from %s", f.getAbsolutePath()));
90+
}
91+
92+
files.add(f);
93+
}
94+
}
95+
96+
return files;
97+
}
98+
99+
/**
100+
* Defaults to ~/.qconsole/workspaces.
101+
*
102+
* @return
103+
*/
104+
protected File getDefaultWorkspacesDir() {
105+
File homeDir = new File(System.getProperty("user.home"));
106+
File qcDir = new File(homeDir, ".qconsole");
107+
File dir = new File(qcDir, "workspaces");
108+
dir.mkdirs();
109+
return dir;
110+
}
111+
112+
113+
public void setBaseDir(File baseDir) {
114+
this.baseDir = baseDir;
115+
}
125116
}

0 commit comments

Comments
 (0)