Skip to content

Commit 46eeba8

Browse files
committed
MCR-1340 use harmonized versions of initial command without surprising replacement of resource urls
1 parent 703af95 commit 46eeba8

File tree

5 files changed

+98
-92
lines changed

5 files changed

+98
-92
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 & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424

2525
import java.io.File;
2626
import java.lang.reflect.InvocationTargetException;
27+
import java.util.regex.Matcher;
28+
import java.util.regex.Pattern;
2729

2830
import org.apache.logging.log4j.LogManager;
2931
import org.apache.logging.log4j.Logger;
@@ -56,32 +58,28 @@ public MIRWizardMCRCommand(String name) {
5658
*/
5759
@Override
5860
public void doExecute() {
61+
5962
EntityManager em = MCREntityManagerProvider.getCurrentEntityManager();
63+
MCRCommandManager cm = new MCRCommandManager();
6064

6165
try {
6266
for (Element command : getInputXML().getChildren()) {
67+
6368
String cmd = command.getTextTrim();
64-
cmd = cmd.replaceAll("\n", "").replaceAll("\r", "").replaceAll(" ", " ");
65-
cmd = cmd.replaceAll(" ", " ");
69+
cmd = cmd.replaceAll("[\\r\\n]+", " ");
70+
cmd = cmd.replaceAll(" +", " ");
6671

6772
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-
}
73+
cmd = cmd.replaceAll(Pattern.quote("{" + attr.getName() + "}"),
74+
Matcher.quoteReplacement(attr.getValue()));
7775
}
7876

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

8179
EntityTransaction tx = em.getTransaction();
8280
tx.begin();
8381
try {
84-
mcrCmdMgr.invokeCommand(cmd);
82+
cm.invokeCommand(cmd);
8583
tx.commit();
8684
} catch (PersistenceException e) {
8785
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)