Skip to content

Commit fe43665

Browse files
committed
Adding a new method to retrieve a complete list of tags (w/t owner)
1 parent 2d42f3a commit fe43665

File tree

2 files changed

+72
-12
lines changed

2 files changed

+72
-12
lines changed

app/channel/channelfinder/src/main/java/org/phoebus/channelfinder/ChannelFinderClient.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,20 @@ public interface ChannelFinderClient {
3838
public Collection<String> getAllPropertyNames();
3939

4040
public Collection<Channel> getAllChannels();
41+
42+
/**
43+
* GEt a list of all the tags
44+
* @return list of all tags
45+
*/
46+
public Collection<Tag> getAllTags();
47+
4148
/**
4249
* Get a list of names of all the tags currently present on the
4350
* channelfinder service.
4451
*
4552
* @return a list of names of all the existing {@link Tag}s.
4653
*/
47-
public Collection<String> getAllTags();
54+
public Collection<String> getAllTagNames();
4855

4956
/**
5057
* Returns a channel that exactly matches the channelName

app/channel/channelfinder/src/main/java/org/phoebus/channelfinder/ChannelFinderClientImpl.java

Lines changed: 64 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -342,10 +342,10 @@ public List<Property> call() throws Exception {
342342
/**
343343
* Get a list of names of all the tags currently present on the
344344
* channelfinder service.
345-
*
345+
*
346346
* @return a list of names of all the existing {@link Tag}s.
347347
*/
348-
public Collection<String> getAllTags() {
348+
public Collection<String> getAllTagNames() {
349349
return wrappedSubmit(new Callable<Collection<String>>() {
350350
private final ObjectMapper mapper = new ObjectMapper();
351351

@@ -375,6 +375,43 @@ public Collection<String> call() {
375375
});
376376
}
377377

378+
private final ObjectMapper mapper = new ObjectMapper();
379+
/**
380+
* Get a list of names of all the tags currently present on the
381+
* channelfinder service.
382+
*
383+
* @return a list of names of all the existing {@link Tag}s.
384+
*/
385+
public Collection<Tag> getAllTags() {
386+
return wrappedSubmit(new Callable<List<Tag>>() {
387+
388+
@Override
389+
public List<Tag> call() {
390+
Collection<String> allTags = new HashSet<String>();
391+
List<XmlTag> xmltags = new ArrayList<XmlTag>();
392+
try {
393+
xmltags = mapper.readValue(
394+
cfResource.path(resourceTags)
395+
.accept(MediaType.APPLICATION_JSON)
396+
.get(String.class), new TypeReference<List<XmlTag>>() { });
397+
} catch ( JsonParseException | JsonMappingException e) {
398+
log.log(Level.WARNING, "Failed to parse the list of tags", e);
399+
} catch ( IOException e) {
400+
log.log(Level.WARNING, "Failed to parse the list of tags", e);
401+
} catch (UniformInterfaceException e) {
402+
throw new ChannelFinderException(e);
403+
} catch (ClientHandlerException e) {
404+
throw new ChannelFinderException(e);
405+
}
406+
for (XmlTag xmltag : xmltags) {
407+
allTags.add(xmltag.getName());
408+
}
409+
return xmltags.stream().map(xmlTag -> new Tag(xmlTag)).collect(Collectors.toList());
410+
411+
}
412+
});
413+
}
414+
378415
@Deprecated
379416
public static void resetPreferences() {
380417
try {
@@ -459,7 +496,9 @@ public SetChannel(XmlChannel xmlChannel) {
459496
public void run() {
460497
ObjectMapper mapper = new ObjectMapper();
461498
try {
462-
cfAuthenticatedResource.path(resourceChannels).path(this.pxmlChannel.getName()).type(MediaType.APPLICATION_JSON)
499+
cfAuthenticatedResource
500+
.path(resourceChannels).path(this.pxmlChannel.getName())
501+
.type(MediaType.APPLICATION_JSON)
463502
.put(mapper.writeValueAsString(this.pxmlChannel));
464503
} catch (JsonProcessingException e) {
465504
log.log(Level.WARNING, "Failed to process the list of channel ", e);
@@ -494,7 +533,10 @@ public void run() {
494533
mapper.writeValue(out, this.pxmlchannels);
495534
final byte[] data = ((ByteArrayOutputStream) out).toByteArray();
496535
String test = new String(data);
497-
cfAuthenticatedResource.path(resourceChannels).type(MediaType.APPLICATION_JSON).put(test);
536+
cfAuthenticatedResource
537+
.path(resourceChannels)
538+
.type(MediaType.APPLICATION_JSON)
539+
.put(test);
498540
} catch (JsonParseException | JsonMappingException e) {
499541
log.log(Level.WARNING, "Failed to process the list of channels ", e);
500542
} catch ( IOException e) {
@@ -582,8 +624,11 @@ public SetTag(XmlTag xmlTag) {
582624
public void run() {
583625
ObjectMapper mapper = new ObjectMapper();
584626
try {
585-
cfAuthenticatedResource.path(resourceTags).path(this.pxmlTag.getName()).type(MediaType.APPLICATION_JSON)
586-
.accept(MediaType.APPLICATION_JSON).put(mapper.writeValueAsString(this.pxmlTag));
627+
cfAuthenticatedResource
628+
.path(resourceTags).path(this.pxmlTag.getName())
629+
.type(MediaType.APPLICATION_JSON)
630+
.accept(MediaType.APPLICATION_JSON)
631+
.put(mapper.writeValueAsString(this.pxmlTag));
587632
} catch (JsonProcessingException e) {
588633
log.log(Level.WARNING, "Failed to process the list of tags ", e);
589634
}
@@ -778,7 +823,9 @@ private class UpdateTag implements Runnable {
778823
@Override
779824
public void run() {
780825
try {
781-
cfAuthenticatedResource.path(resourceTags).path(this.pxmlTag.getName()).type(MediaType.APPLICATION_JSON)
826+
cfAuthenticatedResource
827+
.path(resourceTags).path(this.pxmlTag.getName())
828+
.type(MediaType.APPLICATION_JSON)
782829
.post(mapper.writeValueAsString(this.pxmlTag));
783830
} catch (UniformInterfaceException e) {
784831
throw new ChannelFinderException(e);
@@ -1043,7 +1090,8 @@ public Collection<Channel> call() throws Exception {
10431090
List<XmlChannel> xmlchannels = new ArrayList<XmlChannel>();
10441091
long start = System.currentTimeMillis();
10451092
try {
1046-
xmlchannels = mapper.readValue(cfResource.path(resourceChannels).queryParams(this.map)
1093+
xmlchannels = mapper.readValue(cfResource.path(resourceChannels)
1094+
.queryParams(this.map)
10471095
.accept(MediaType.APPLICATION_JSON).get(String.class), new TypeReference<List<XmlChannel>>() {
10481096
});
10491097
} catch (Exception e) {
@@ -1245,7 +1293,10 @@ private class DeleteElementfromChannel implements Runnable
12451293
@Override
12461294
public void run()
12471295
{
1248-
cfAuthenticatedResource.path(this.elementType).path(this.elementName).path(this.channelName)
1296+
cfAuthenticatedResource
1297+
.path(this.elementType)
1298+
.path(this.elementName)
1299+
.path(this.channelName)
12491300
.accept(MediaType.APPLICATION_JSON).delete();
12501301
}
12511302

@@ -1308,8 +1359,10 @@ public Collection<Channel> getAllChannels()
13081359
List<XmlChannel> xmlchannels = new ArrayList<XmlChannel>();
13091360
try {
13101361
xmlchannels = mapper.readValue(
1311-
cfAuthenticatedResource.path(resourceChannels).accept(MediaType.APPLICATION_JSON).get(String.class),
1312-
new TypeReference<List<XmlChannel>>() {
1362+
cfAuthenticatedResource
1363+
.path(resourceChannels)
1364+
.accept(MediaType.APPLICATION_JSON)
1365+
.get(String.class), new TypeReference<List<XmlChannel>>() {
13131366
});
13141367
} catch (JsonParseException | JsonMappingException e) {
13151368
log.log(Level.WARNING, "Failed to parse the list of channels ", e);

0 commit comments

Comments
 (0)