Revision 43290
Added by Claudio Atzori almost 8 years ago
modules/cnr-enabling-inspector/trunk/src/main/java/eu/dnetlib/enabling/inspector/SubscriptionController.java | ||
---|---|---|
10 | 10 |
import javax.xml.xpath.XPathExpressionException; |
11 | 11 |
import javax.xml.xpath.XPathFactory; |
12 | 12 |
|
13 |
import eu.dnetlib.enabling.is.sn.SubscriptionRegistry; |
|
13 | 14 |
import org.apache.commons.logging.Log; |
14 | 15 |
import org.apache.commons.logging.LogFactory; |
15 | 16 |
import org.springframework.stereotype.Controller; |
... | ... | |
38 | 39 |
/** |
39 | 40 |
* is sn subscription registries. |
40 | 41 |
*/ |
41 |
@Resource(name = "issResourceStateNotificationRegistries")
|
|
42 |
private transient List<ResourceStateSubscriptionRegistry> registries;
|
|
42 |
@Resource(name = "issResourceStateNotificationRegistry")
|
|
43 |
private transient SubscriptionRegistry registry;
|
|
43 | 44 |
|
44 | 45 |
/** |
45 | 46 |
* allows to control the global enable of issn. |
... | ... | |
65 | 66 |
@RequestMapping("/inspector/sn.do") |
66 | 67 |
String listSubscriptions(final Model model) throws XPathExpressionException { |
67 | 68 |
|
68 |
log.debug("registries: " + registries);
|
|
69 |
log.debug("registries: " + registry);
|
|
69 | 70 |
|
70 | 71 |
final List<Map<String, String>> subscriptions = new ArrayList<Map<String, String>>(); |
71 |
for (ResourceStateSubscriptionRegistry registry : registries) { |
|
72 |
for (ResourceStateSubscription sub : registry.getSubscriptionDao().listSubscriptions()) { |
|
73 |
final Map<String, String> attrs = new HashMap<String, String>(); // NOPMD |
|
74 |
attrs.put("prefix", sub.getPrefix()); |
|
75 |
attrs.put("type", sub.getType()); |
|
76 |
attrs.put("resourceId", sub.getResourceId()); |
|
77 |
attrs.put("xpath", sub.getXpath()); |
|
78 |
attrs.put("id", sub.getSubscriptionId()); |
|
79 | 72 |
|
80 |
final DOMResult result = new DOMResult(); // NOPMD |
|
81 |
sub.getSubscriberAsEpr().writeTo(result); |
|
82 |
attrs.put("address", XPathFactory.newInstance().newXPath().evaluate("//*[local-name() = 'Address']", result.getNode())); |
|
83 |
subscriptions.add(attrs); |
|
84 |
} |
|
73 |
for (ResourceStateSubscription sub : registry.listSubscriptions()) { |
|
74 |
final Map<String, String> attrs = new HashMap<String, String>(); // NOPMD |
|
75 |
attrs.put("prefix", sub.getPrefix()); |
|
76 |
attrs.put("type", sub.getType()); |
|
77 |
attrs.put("resourceId", sub.getResourceId()); |
|
78 |
attrs.put("xpath", sub.getXpath()); |
|
79 |
attrs.put("id", sub.getSubscriptionId()); |
|
80 |
|
|
81 |
final DOMResult result = new DOMResult(); // NOPMD |
|
82 |
sub.getSubscriberAsEpr().writeTo(result); |
|
83 |
attrs.put("address", XPathFactory.newInstance().newXPath().evaluate("//*[local-name() = 'Address']", result.getNode())); |
|
84 |
subscriptions.add(attrs); |
|
85 | 85 |
} |
86 | 86 |
|
87 | 87 |
model.addAttribute("subscriptions", subscriptions); |
... | ... | |
103 | 103 |
@RequestMapping("/inspector/snByAddress.do") |
104 | 104 |
String listSubscriptionsByAddress(final Model model, @RequestParam(value="address", required=false) final String address) throws XPathExpressionException { |
105 | 105 |
|
106 |
log.debug("registries: " + registries);
|
|
106 |
log.debug("registries: " + registry);
|
|
107 | 107 |
|
108 | 108 |
final List<Map<String, String>> subscriptions = new ArrayList<Map<String, String>>(); |
109 | 109 |
log.debug("Address is "+address); |
110 | 110 |
|
111 | 111 |
model.addAttribute("address", address); |
112 | 112 |
|
113 |
for (ResourceStateSubscriptionRegistry registry : registries) { |
|
114 |
for (ResourceStateSubscription sub : registry.getSubscriptionDao().listSubscriptions()) { |
|
115 |
final DOMResult result = new DOMResult(); // NOPMD |
|
116 |
sub.getSubscriberAsEpr().writeTo(result); |
|
117 |
final String addr = XPathFactory.newInstance().newXPath().evaluate("//*[local-name() = 'Address']", result.getNode()); |
|
118 |
|
|
119 |
if ( address==null || (addr != null && addr.startsWith(address)) ) { |
|
120 |
final Map<String, String> attrs = new HashMap<String, String>(); // NOPMD |
|
121 |
attrs.put("prefix", sub.getPrefix()); |
|
122 |
attrs.put("type", sub.getType()); |
|
123 |
attrs.put("resourceId", sub.getResourceId()); |
|
124 |
attrs.put("xpath", sub.getXpath()); |
|
125 |
attrs.put("id", sub.getSubscriptionId()); |
|
126 |
attrs.put("address", addr); |
|
127 |
subscriptions.add(attrs); |
|
128 |
} |
|
113 |
for (ResourceStateSubscription sub : registry.listSubscriptions()) { |
|
114 |
final DOMResult result = new DOMResult(); // NOPMD |
|
115 |
sub.getSubscriberAsEpr().writeTo(result); |
|
116 |
final String addr = XPathFactory.newInstance().newXPath().evaluate("//*[local-name() = 'Address']", result.getNode()); |
|
117 |
|
|
118 |
if ( address==null || (addr != null && addr.startsWith(address)) ) { |
|
119 |
final Map<String, String> attrs = new HashMap<String, String>(); // NOPMD |
|
120 |
attrs.put("prefix", sub.getPrefix()); |
|
121 |
attrs.put("type", sub.getType()); |
|
122 |
attrs.put("resourceId", sub.getResourceId()); |
|
123 |
attrs.put("xpath", sub.getXpath()); |
|
124 |
attrs.put("id", sub.getSubscriptionId()); |
|
125 |
attrs.put("address", addr); |
|
126 |
subscriptions.add(attrs); |
|
129 | 127 |
} |
130 | 128 |
} |
131 |
|
|
129 |
|
|
132 | 130 |
model.addAttribute("subscriptions", subscriptions); |
133 | 131 |
model.addAttribute("enabled", !inhibitionCondition.isTrue()); |
134 | 132 |
return "inspector/subscriptionsByAddress"; |
... | ... | |
153 | 151 |
*/ |
154 | 152 |
@RequestMapping("/inspector/deleteSubscription.do") |
155 | 153 |
String deleteSubscription(@RequestParam("id") final String subscriptionId) { |
156 |
for (ResourceStateSubscriptionRegistry registry : registries) { |
|
157 |
if (registry.getSubscriptionDao().removeSubscription(subscriptionId)) |
|
158 |
break; |
|
159 |
} |
|
154 |
registry.removeSubscription(subscriptionId); |
|
160 | 155 |
return "redirect:sn.do"; |
161 | 156 |
} |
162 | 157 |
|
... | ... | |
175 | 170 |
final List<String> deleted = new ArrayList<String>(); |
176 | 171 |
|
177 | 172 |
if (address != null && address.length() > "http://".length()) { |
178 |
for (ResourceStateSubscriptionRegistry registry : registries) { |
|
179 |
for (ResourceStateSubscription sub : registry.getSubscriptionDao().listSubscriptions()) { |
|
180 |
final DOMResult result = new DOMResult(); // NOPMD |
|
181 |
sub.getSubscriberAsEpr().writeTo(result); |
|
182 |
final String addr = XPathFactory.newInstance().newXPath().evaluate("//*[local-name() = 'Address']", result.getNode()); |
|
183 |
|
|
184 |
if (addr != null && addr.startsWith(address)) { |
|
185 |
String id = sub.getSubscriptionId(); |
|
186 |
registry.getSubscriptionDao().removeSubscription(id); |
|
187 |
deleted.add(id + " ("+ addr +")"); |
|
188 |
} |
|
173 |
|
|
174 |
for (ResourceStateSubscription sub : registry.listSubscriptions()) { |
|
175 |
final DOMResult result = new DOMResult(); // NOPMD |
|
176 |
sub.getSubscriberAsEpr().writeTo(result); |
|
177 |
final String addr = XPathFactory.newInstance().newXPath().evaluate("//*[local-name() = 'Address']", result.getNode()); |
|
178 |
|
|
179 |
if (addr != null && addr.startsWith(address)) { |
|
180 |
String id = sub.getSubscriptionId(); |
|
181 |
registry.removeSubscription(id); |
|
182 |
deleted.add(id + " ("+ addr +")"); |
|
189 | 183 |
} |
190 | 184 |
} |
191 | 185 |
} |
Also available in: Unified diff
adapted to changes in enabling layer: we will support only one subscription registry