Skip to content
Snippets Groups Projects
Commit ca71611f authored by Brice Copy's avatar Brice Copy
Browse files

Fix issues with empty param lists

parent 5d5529c1
No related branches found
No related tags found
No related merge requests found
Pipeline #978595 failed
......@@ -85,22 +85,22 @@ public class C2MonBroadcastService {
@Get
public void onGetSubscribe(AtmosphereResource resource) {
obtainBroadcasterFactory(resource);
String[] subscriptionsIdToAdd = resource.getRequest().getParameterValues("id");
List<SubscriptionUpdateTagIdentifier> tagIdentifiersById = Arrays.asList(subscriptionsIdToAdd).stream()
.map(id -> SubscriptionUpdateTagIdentifier.builder().id(Long.valueOf(id)).build())
.collect(Collectors.toList());
String[] subscriptionsNamesToAdd = resource.getRequest().getParameterValues("name");
List<SubscriptionUpdateTagIdentifier> tagIdentifiersByName = Arrays.asList(subscriptionsNamesToAdd).stream()
.map(name -> SubscriptionUpdateTagIdentifier.builder().name(name).build())
.collect(Collectors.toList());
tagIdentifiersById.addAll(tagIdentifiersByName);
resource.suspend();
subscribeTagsByTagIdentifier(resource, tagIdentifiersById);
// String[] subscriptionsIdToAdd = resource.getRequest().getParameterValues("id");
//
// List<SubscriptionUpdateTagIdentifier> tagIdentifiersById = Arrays.asList(subscriptionsIdToAdd).stream()
// .map(id -> SubscriptionUpdateTagIdentifier.builder().id(Long.valueOf(id)).build())
// .collect(Collectors.toList());
//
// String[] subscriptionsNamesToAdd = resource.getRequest().getParameterValues("name");
//
// List<SubscriptionUpdateTagIdentifier> tagIdentifiersByName = Arrays.asList(subscriptionsNamesToAdd).stream()
// .map(name -> SubscriptionUpdateTagIdentifier.builder().name(name).build())
// .collect(Collectors.toList());
//
//
// tagIdentifiersById.addAll(tagIdentifiersByName);
// resource.suspend();
// subscribeTagsByTagIdentifier(resource, tagIdentifiersById);
}
public Set<Long> subscribeTagsByTagIdentifier(AtmosphereResource resource, List<SubscriptionUpdateTagIdentifier> subscriptionsToAdd) {
......@@ -108,42 +108,45 @@ public class C2MonBroadcastService {
Set<String> tagNamesList = subscriptionsToAdd.stream().map(SubscriptionUpdateTagIdentifier::getName).collect(Collectors.toSet());
Set<Long> validTagIds = new HashSet<>();
if(!tagIdsList.isEmpty()) {
if(!tagIdsList.isEmpty() && tagIdsList.iterator().next() != null) {
this.logger.debug("Subscribing to tags IDs {}", tagIdsList.stream().map( Object::toString ).collect(Collectors.joining(",")));
}
if(!tagNamesList.isEmpty()) {
if(!tagNamesList.isEmpty() && tagNamesList.iterator().next() != null) {
this.logger.debug("Subscribing to tags Names {}", tagNamesList.stream().collect(Collectors.joining(",")));
}
try {
// TODO : We should validate the tags before subscribing
for (Long tagToAdd : tagIdsList) {
if(this.logger.isDebugEnabled()) {
this.logger.debug("Associating res {} with tag id {} ", resource.uuid(), tagToAdd);
}
m_broadcasterFactory.lookup(tagToAdd, true).addAtmosphereResource(resource);
validTagIds.add(tagToAdd);
if (tagToAdd != null) {
if (this.logger.isDebugEnabled()) {
this.logger.debug("Associating res {} with tag id {} ", resource.uuid(), tagToAdd);
}
m_broadcasterFactory.lookup(tagToAdd, true).addAtmosphereResource(resource);
validTagIds.add(tagToAdd);
}
}
// TODO : Only subscribe to valid tags and return only those in the return result.
c2monTagService.subscribe(tagIdsList, broadcastingTagListener);
c2monTagService.subscribe(validTagIds, broadcastingTagListener);
} catch (Exception e) {
this.logger.warn("Failed tag subscription by ID : ", e);
}
try {
Set<Long> newTagNameIds = new HashSet<>();
// TODO : We should validate the tags before subscribing
for (String tagNameToAdd : tagNamesList) {
Collection<Tag> tags = c2monTagService.findByName(tagNameToAdd);
for (Tag tag: tags) {
if(this.logger.isDebugEnabled()) {
this.logger.debug("Associating res {} with tag id {} (tag name {}) ", resource.uuid(), tag.getId(), tag.getName());
}
m_broadcasterFactory.lookup(tag.getId(), true).addAtmosphereResource(resource);
validTagIds.add(tag.getId());
if(tagNameToAdd!= null){
Collection<Tag> tags = c2monTagService.findByName(tagNameToAdd);
for (Tag tag: tags) {
if(this.logger.isDebugEnabled()) {
this.logger.debug("Associating res {} with tag id {} (tag name {}) ", resource.uuid(), tag.getId(), tag.getName());
}
m_broadcasterFactory.lookup(tag.getId(), true).addAtmosphereResource(resource);
newTagNameIds.add(tag.getId());
}
}
}
// TODO : Only subscribe to valid tags and return only those in the return result.
c2monTagService.subscribe(tagIdsList, broadcastingTagListener);
c2monTagService.subscribe(newTagNameIds, broadcastingTagListener);
} catch (Exception e) {
this.logger.warn("Failed tag subscription: ", e);
}
......
package cern.c2mon.client.atmosphere;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class SubscriptionUpdateTagIdentifier {
Long id;
String name;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment