Skip to content

Commit b566058

Browse files
authored
MCR-1340 use harmonized versions of initial command without surprising replacement of resource urls (#1035)
1 parent 784f381 commit b566058

File tree

5 files changed

+98
-96
lines changed

5 files changed

+98
-96
lines changed

mir-cli/src/main/config/acl/defaultrules-commands.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@ update permission preview for id default_mods with rulefile ${app.home}/config/a
88
update permission read for id default_mods with rulefile ${app.home}/config/acl/grant-all.xml described by ${acl-description.all}
99
update permission writedb for id default_mods with rulefile ${app.home}/config/acl/grant-editors.xml described by ${acl-description.editors}
1010
update permission deletedb for id default_mods with rulefile ${app.home}/config/acl/grant-admin.xml described by ${acl-description.admins}
11+
update permission view-derivate for id default_mods with rulefile ${app.home}/config/acl/grant-all.xml described by ${acl-description.all}
1112
update permission addurn for id default_derivate with rulefile ${app.home}/config/acl/grant-editors.xml described by ${acl-description.editors}
1213
update permission read for id derivate:mir_access:intern with rulefile ${app.home}/config/acl/require-login.xml described by ${acl-description.require-login}
13-
update permission read for id derivate:mir_access:unlimited with rulefile ${app.home}/config/acl/grant-all.xml described by ${acl-description.require-login}
14+
update permission read for id derivate:mir_access:unlimited with rulefile ${app.home}/config/acl/grant-all.xml described by ${acl-description.all}
1415

1516
update permission writedb for id mir_genres with rulefile ${app.home}/config/acl/grant-admin.xml described by ${acl-description.admins}
1617
update permission writedb for id mir_institutes with rulefile ${app.home}/config/acl/grant-admin.xml described by ${acl-description.admins}

mir-wizard/src/main/java/org/mycore/mir/wizard/command/MIRWizardMCRCommand.java

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,15 @@
2222
*/
2323
package org.mycore.mir.wizard.command;
2424

25-
import java.io.File;
2625
import java.lang.reflect.InvocationTargetException;
26+
import java.util.regex.Matcher;
27+
import java.util.regex.Pattern;
2728

2829
import org.apache.logging.log4j.LogManager;
2930
import org.apache.logging.log4j.Logger;
3031
import org.jdom2.Attribute;
3132
import org.jdom2.Element;
3233
import org.mycore.backend.jpa.MCREntityManagerProvider;
33-
import org.mycore.common.content.MCRContent;
34-
import org.mycore.common.content.MCRJDOMContent;
35-
import org.mycore.common.xml.MCRURIResolver;
3634
import org.mycore.frontend.cli.MCRCommandManager;
3735
import org.mycore.mir.wizard.MIRWizardCommand;
3836

@@ -56,32 +54,28 @@ public MIRWizardMCRCommand(String name) {
5654
*/
5755
@Override
5856
public void doExecute() {
57+
5958
EntityManager em = MCREntityManagerProvider.getCurrentEntityManager();
59+
MCRCommandManager cm = new MCRCommandManager();
6060

6161
try {
6262
for (Element command : getInputXML().getChildren()) {
63+
6364
String cmd = command.getTextTrim();
64-
cmd = cmd.replaceAll("\n", "").replaceAll("\r", "").replaceAll(" ", " ");
65-
cmd = cmd.replaceAll(" ", " ");
65+
cmd = cmd.replaceAll("[\\r\\n]+", " ");
66+
cmd = cmd.replaceAll(" +", " ");
6667

6768
for (Attribute attr : command.getAttributes()) {
68-
if (attr.getValue().startsWith("resource:")) {
69-
File tmpFile = File.createTempFile("resfile", ".xml");
70-
MCRContent source = new MCRJDOMContent(MCRURIResolver.instance().resolve(attr.getValue()));
71-
source.sendTo(tmpFile);
72-
73-
cmd = cmd.replace("{" + attr.getName() + "}", tmpFile.getAbsolutePath());
74-
} else {
75-
cmd = cmd.replace("{" + attr.getName() + "}", attr.getValue());
76-
}
69+
cmd = cmd.replaceAll(Pattern.quote("{" + attr.getName() + "}"),
70+
Matcher.quoteReplacement(attr.getValue()));
7771
}
7872

79-
MCRCommandManager mcrCmdMgr = new MCRCommandManager();
73+
LOGGER.info("Executing command: {}", cmd);
8074

8175
EntityTransaction tx = em.getTransaction();
8276
tx.begin();
8377
try {
84-
mcrCmdMgr.invokeCommand(cmd);
78+
cm.invokeCommand(cmd);
8579
tx.commit();
8680
} catch (PersistenceException e) {
8781
tx.rollback();
Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,25 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<commands>
33
<command file="resource:setup/acl/permissions.xml">load permissions data from file {file}</command>
4-
<command file="resource:setup/acl/grant-all.xml" describedBy="always allowed">update permission read for id default with rulefile {file} described by {describedBy}</command>
5-
<command file="resource:setup/acl/grant-admin.xml" describedBy="administrators only">update permission writedb for id default with rulefile {file} described by {describedBy}</command>
6-
<command file="resource:setup/acl/grant-admin.xml" describedBy="administrators only">update permission deletedb for id default with rulefile {file} described by {describedBy}</command>
7-
<command file="resource:setup/acl/grant-all.xml" describedBy="always allowed">update permission view for id default_mods with rulefile {file} described by {describedBy}</command>
8-
<command file="resource:setup/acl/grant-all.xml" describedBy="always allowed">update permission read for id default_mods with rulefile {file} described by {describedBy}</command>
9-
<command file="resource:setup/acl/grant-editors.xml" describedBy="administrators and editors">update permission writedb for id default_mods with rulefile {file} described by {describedBy}</command>
10-
<command file="resource:setup/acl/grant-admin.xml" describedBy="administrators only">update permission deletedb for id default_mods with rulefile {file} described by {describedBy}</command>
11-
<command file="resource:setup/acl/grant-all.xml" describedBy="always allowed">update permission view-derivate for id default_mods with rulefile {file} described by {describedBy}</command>
12-
<command file="resource:setup/acl/grant-editors.xml" describedBy="administrators and editors">update permission addurn for id default_derivate with rulefile {file} described by {describedBy}</command>
13-
<command file="resource:setup/acl/require-login.xml" describedBy="require login">update permission read for id derivate:mir_access:intern with rulefile {file} described by {describedBy}</command>
144

15-
<command file="resource:setup/acl/grant-admin.xml" describedBy="administrators only"> update permission writedb for id mir_genres with rulefile {file} described by {describedBy} </command>
16-
<command file="resource:setup/acl/grant-admin.xml" describedBy="administrators only"> update permission writedb for id mir_institutes with rulefile {file} described by {describedBy} </command>
17-
<command file="resource:setup/acl/grant-admin.xml" describedBy="administrators only"> update permission writedb for id mir_licenses with rulefile {file} described by {describedBy} </command>
18-
<command file="resource:setup/acl/grant-admin.xml" describedBy="administrators only"> update permission writedb for id rfc5646 with rulefile {file} described by {describedBy} </command>
19-
<command file="resource:setup/acl/grant-admin.xml" describedBy="administrators only"> update permission writedb for id marcrelator with rulefile {file} described by {describedBy} </command>
20-
<command file="resource:setup/acl/grant-admin.xml" describedBy="administrators only"> update permission writedb for id noteTypes with rulefile {file} described by {describedBy} </command>
21-
<command file="resource:setup/acl/grant-admin.xml" describedBy="administrators only"> update permission writedb for id SDNB with rulefile {file} described by {describedBy} </command>
5+
<command file="resource:setup/acl/grant-all.xml" describedBy="always allowed">update permission read for id default with rule {file} described by {describedBy}</command>
6+
<command file="resource:setup/acl/grant-admin.xml" describedBy="administrators only">update permission writedb for id default with rule {file} described by {describedBy}</command>
7+
<command file="resource:setup/acl/grant-admin.xml" describedBy="administrators only">update permission deletedb for id default with rule {file} described by {describedBy}</command>
8+
<command file="resource:setup/acl/grant-all.xml" describedBy="always allowed">update permission view for id default_mods with rule {file} described by {describedBy}</command>
9+
<command file="resource:setup/acl/grant-all.xml" describedBy="always allowed">update permission preview for id default_mods with rule {file} described by {describedBy}</command>
10+
<command file="resource:setup/acl/grant-all.xml" describedBy="always allowed">update permission read for id default_mods with rule {file} described by {describedBy}</command>
11+
<command file="resource:setup/acl/grant-editors.xml" describedBy="administrators and editors">update permission writedb for id default_mods with rule {file} described by {describedBy}</command>
12+
<command file="resource:setup/acl/grant-admin.xml" describedBy="administrators only">update permission deletedb for id default_mods with rule {file} described by {describedBy}</command>
13+
<command file="resource:setup/acl/grant-all.xml" describedBy="always allowed">update permission view-derivate for id default_mods with rule {file} described by {describedBy}</command>
14+
<command file="resource:setup/acl/grant-editors.xml" describedBy="administrators and editors">update permission addurn for id default_derivate with rule {file} described by {describedBy}</command>
15+
<command file="resource:setup/acl/require-login.xml" describedBy="require login">update permission read for id derivate:mir_access:intern with rule {file} described by {describedBy}</command>
16+
<command file="resource:setup/acl/grant-all.xml" describedBy="always allowed">update permission read for id derivate:mir_access:unlimited with rule {file} described by {describedBy}</command>
2217

23-
</commands>
18+
<command file="resource:setup/acl/grant-admin.xml" describedBy="administrators only">update permission writedb for id mir_genres with rule {file} described by {describedBy}</command>
19+
<command file="resource:setup/acl/grant-admin.xml" describedBy="administrators only">update permission writedb for id mir_institutes with rule {file} described by {describedBy}</command>
20+
<command file="resource:setup/acl/grant-admin.xml" describedBy="administrators only">update permission writedb for id mir_licenses with rule {file} described by {describedBy}</command>
21+
<command file="resource:setup/acl/grant-admin.xml" describedBy="administrators only">update permission writedb for id rfc5646 with rule {file} described by {describedBy}</command>
22+
<command file="resource:setup/acl/grant-admin.xml" describedBy="administrators only">update permission writedb for id marcrelator with rule {file} described by {describedBy}</command>
23+
<command file="resource:setup/acl/grant-admin.xml" describedBy="administrators only">update permission writedb for id noteTypes with rule {file} described by {describedBy}</command>
24+
<command file="resource:setup/acl/grant-admin.xml" describedBy="administrators only">update permission writedb for id SDNB with rule {file} described by {describedBy}</command>
25+
</commands>
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<commands>
3-
<command file="resource:setup/acl/grant-all.xml" describeBy="always allowed">update permission read for id
4-
restapi:/ with rulefile {file} described by {describeBy}
3+
<command file="resource:setup/acl/grant-all.xml" describedBy="always allowed">update permission read for id
4+
restapi:/ with rule {file} described by {describedBy}
55
</command>
66
</commands>

0 commit comments

Comments
 (0)