@Override
 @Transactional(readOnly = false)
 public Collection updateAndGetRunningCollectionStatusByUser(Long userId) throws Exception {
   Collection collection = collectionRepository.getRunningCollectionStatusByUser(userId);
   if (collection != null) {
     logger.info(
         "User with ID: '"
             + userId
             + "' has a running collection with code: '"
             + collection.getCode());
     return statusByCollection(collection, userId);
   } else {
     // logger.info("User with ID: '" + userId + "' don't have any running collections. Nothing to
     // update." );
     //            If there is no running collection there is still can be collection with status
     // 'Initializing'.
     //            This happens because we update collection information from fetcher before
     // collection was started.
     //            So we need to update from Fetcher this kind of collections as well.
     collection = collectionRepository.getInitializingCollectionStatusByUser(userId);
     if (collection != null) {
       return statusByCollection(collection, userId);
     }
   }
   return null;
 }
  @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 = true)
 public Collection getRunningCollectionStatusByUser(Long userId) throws Exception {
   return collectionRepository.getRunningCollectionStatusByUser(userId);
 }