AgentConfigGroupImpl.java
3.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* javax.jcr.Node
* javax.jcr.Property
* javax.jcr.RepositoryException
* org.apache.jackrabbit.util.Text
* org.apache.sling.settings.SlingSettingsService
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.day.cq.replication.impl;
import com.day.cq.replication.AgentConfig;
import com.day.cq.replication.AgentConfigGroup;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import javax.jcr.Node;
import javax.jcr.Property;
import javax.jcr.RepositoryException;
import org.apache.jackrabbit.util.Text;
import org.apache.sling.settings.SlingSettingsService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public final class AgentConfigGroupImpl
implements AgentConfigGroup {
private static final Logger log = LoggerFactory.getLogger(AgentConfigGroupImpl.class);
private final String id;
private final String name;
private String title;
private final String[] runModes;
private final boolean active;
private Map<String, AgentConfig> configs = new TreeMap<String, AgentConfig>();
private AgentConfigGroupImpl(String id, String name, String title, String[] runModes, boolean active) {
this.id = id;
this.name = name;
this.title = title;
this.runModes = runModes;
this.active = active;
}
public static String[] getRunModes(Node node) throws RepositoryException {
String[] runModes = null;
String name = node.getName();
if ("agents".equals(name)) {
runModes = new String[]{};
} else if (name.startsWith("agents.")) {
String[] segs = Text.explode((String)name, (int)46);
runModes = new String[segs.length - 1];
System.arraycopy(segs, 1, runModes, 0, runModes.length);
}
return runModes;
}
public static AgentConfigGroupImpl create(Node groupNode, SlingSettingsService slingSettings) {
try {
String[] runModes = AgentConfigGroupImpl.getRunModes(groupNode);
if (runModes == null) {
return null;
}
String title = "";
if (groupNode.hasProperty("jcr:content/jcr:title")) {
title = groupNode.getProperty("jcr:content/jcr:title").getString();
} else if (groupNode.hasProperty("jcr:title")) {
title = groupNode.getProperty("jcr:title").getString();
}
boolean active = false;
for (String m : runModes) {
if ("*".equals(m = m.trim())) {
active = true;
break;
}
if (!slingSettings.getRunModes().contains(m)) continue;
active = true;
break;
}
return new AgentConfigGroupImpl(groupNode.getPath(), groupNode.getName(), title, runModes, active);
}
catch (RepositoryException e) {
log.error("Error while reading agent config group node", (Throwable)e);
return null;
}
}
@Override
public String getId() {
return this.id;
}
@Override
public String getName() {
return this.name;
}
@Override
public String getTitle() {
return this.title;
}
@Override
public String[] getRunModes() {
return this.runModes;
}
@Override
public boolean isActive() {
return this.active;
}
@Override
public Map<String, AgentConfig> getConfigurations() {
return this.configs;
}
protected void update(Node node) throws RepositoryException {
if (node.hasProperty("jcr:content/jcr:title")) {
this.title = node.getProperty("jcr:content/jcr:title").getString();
}
}
}