code: private void clean(HudsonCollector collector, List<HudsonJob> existingJobs) {
          Set<ObjectId> uniqueIDs = new HashSet<>();
          for (com.capitalone.dashboard.model.Component comp : dbComponentRepository
                  .findAll()) {
  
              if (CollectionUtils.isEmpty(comp.getCollectorItems())) continue;
  
              List<CollectorItem> itemList = comp.getCollectorItems().get(CollectorType.Build);
  
              if (CollectionUtils.isEmpty(itemList)) continue;
  
              for (CollectorItem ci : itemList) {
                  if (collector.getId().equals(ci.getCollectorId())) {
                      uniqueIDs.add(ci.getId());
                  }
              }
          }
          List<HudsonJob> stateChangeJobList = new ArrayList<>();
          for (HudsonJob job : existingJobs) {
              if ((job.isEnabled() && !uniqueIDs.contains(job.getId())) ||  // if it was enabled but not on a dashboard
                      (!job.isEnabled() && uniqueIDs.contains(job.getId()))) { // OR it was disabled and now on a dashboard
                  job.setEnabled(uniqueIDs.contains(job.getId()));
                  stateChangeJobList.add(job);
              }
          }
          if (!CollectionUtils.isEmpty(stateChangeJobList)) {
              hudsonJobRepository.save(stateChangeJobList);
          }
      }
docs: Clean up unused hudson/jenkins collector items
  
  @param collector    the {@link HudsonCollector}
  @param existingJobs