@Override
 @Transactional(readOnly = true)
 public Collection findTrashedById(Long id) throws Exception {
   Collection temp = collectionRepository.findById(id);
   if (temp.getStatus().equals(CollectionStatus.TRASHED)) {
     return temp;
   }
   return null;
 }
  // MEGHNA: method for stopping a collection on FATAL_ERROR
  // separate method from stop needed to prevent looping in
  // updateStatusCollection() method
  public Collection stopFatalError(Long collectionId, Long userId) throws Exception {
    Collection collection = collectionRepository.findById(collectionId);
    // collection = collectionRepository.stop(collection.getId());

    Collection updateCollection = stopAidrFetcher(collection, userId);

    CollectionLog collectionLog = new CollectionLog(collection);
    collectionLogRepository.save(collectionLog);

    return updateCollection;
  }
  @Override
  @Transactional(readOnly = false)
  public Collection start(Long collectionId) throws Exception {

    // We are going to start new collection. Lets stop collection which is running for owner of the
    // new collection.
    Collection dbCollection = collectionRepository.findById(collectionId);
    Long userId = dbCollection.getOwner().getId();
    Collection alreadyRunningCollection =
        collectionRepository.getRunningCollectionStatusByUser(userId);
    if (alreadyRunningCollection != null) {
      this.stop(alreadyRunningCollection.getId(), userId);
    }

    return startFetcher(prepareFetcherRequest(dbCollection), dbCollection);
  }
  @Override
  @Transactional(readOnly = false)
  public Collection stop(Long collectionId, Long userId) throws Exception {
    Collection collection = collectionRepository.findById(collectionId);

    // Follwoing 2 lines added by koushik for downloadCount bug
    Collection c = this.statusByCollection(collection, userId);
    collection.setCount(c.getCount());

    Collection updateCollection = stopAidrFetcher(collection, userId);

    CollectionLog collectionLog = new CollectionLog(collection);
    collectionLog.setUpdatedBy(userId);
    collectionLogRepository.save(collectionLog);

    return updateCollection;
  }
 //  this method is common to get collection and should not filter by status
 @Override
 @Transactional(readOnly = true)
 public Collection findById(Long id) throws Exception {
   return collectionRepository.findById(id);
 }