コード例 #1
0
  private Collection adaptCollectionDetailsInfoToCollection(
      CollectionDetailsInfo collectionInfo, UserAccount user) {

    Collection collection = new Collection();
    collection.setDurationHours(collectionInfo.getDurationHours());
    collection.setCode(collectionInfo.getCode());
    collection.setName(collectionInfo.getName());
    collection.setClassifierEnabled(false);
    collection.setProvider(CollectionType.valueOf(collectionInfo.getProvider()));
    collection.setOwner(user);
    collection.setStatus(CollectionStatus.NOT_RUNNING);
    collection.setPubliclyListed(true); // TODO: change default behavior to user choice

    collection.setGeoR(collectionInfo.getGeoR());
    collection.setGeo(collectionInfo.getGeo());
    collection.setTrack(collectionInfo.getTrack());
    collection.setCrisisType(crisisTypeService.getById(collectionInfo.getCrisisType()));
    collection.setFollow(collectionInfo.getFollow());
    collection.setLangFilters(collectionInfo.getLangFilters());
    collection.setMicromappersEnabled(Boolean.FALSE);
    collection.setProvider(CollectionType.valueOf(collectionInfo.getProvider()));
    collection.setPurpose(collectionInfo.getPurpose());
    collection.setFetchInterval(collectionInfo.getFetchInterval());
    collection.setFetchFrom(collectionInfo.getFetchFrom());

    if (CollectionType.SMS.equals(collectionInfo.getProvider())) {
      collection.setTrack(null);
      collection.setLangFilters(null);
      collection.setGeo(null);
      collection.setFollow(null);
    }

    Timestamp now = new Timestamp(System.currentTimeMillis());
    collection.setCreatedAt(now);
    collection.setUpdatedAt(now);
    return collection;
  }
コード例 #2
0
  @Override
  @Transactional(readOnly = false)
  public boolean updateCollection(CollectionUpdateInfo collectionUpdateInfo, Long userId) {

    String filteredTrack = "";
    try {
      Collection collection = findByCode(collectionUpdateInfo.getCode());

      if (!collection.getName().equals(collectionUpdateInfo.getName())) {
        if (!existName(collectionUpdateInfo.getName())) {
          collection.setName(collectionUpdateInfo.getName());
        } else {
          return false;
        }
      }
      // if collection exists with same name

      collection.setProvider(CollectionType.valueOf(collectionUpdateInfo.getProvider()));
      collection.setFollow(collectionUpdateInfo.getFollow());
      collection.setFetchInterval(collectionUpdateInfo.getFetchInterval());
      collection.setFetchFrom(collectionUpdateInfo.getFetchFrom());
      filteredTrack = collectionUpdateInfo.getTrack();

      if (!StringUtils.isEmpty(filteredTrack)) {
        filteredTrack = getFilteredTrack(filteredTrack);

        if (StringUtils.isEmpty(filteredTrack)) {
          return false;
        }
      }
      collection.setTrack(filteredTrack);
      collection.setGeo(collectionUpdateInfo.getGeo());
      collection.setGeoR(collectionUpdateInfo.getGeoR());
      collection.setDurationHours(Integer.parseInt(collectionUpdateInfo.getDurationHours()));
      collection.setLangFilters(collectionUpdateInfo.getLangFilters());

      Long crisisTypeId = Long.parseLong(collectionUpdateInfo.getCrisisType());
      CrisisType crisisType = crisisTypeService.getById(crisisTypeId);
      if (crisisType != null) {
        collection.setCrisisType(crisisType);
      } else {
        logger.error(
            "Crisis Type Id: "
                + crisisTypeId
                + " does not exist. Can't update the collection : "
                + collectionUpdateInfo.getCode());
        return false;
      }

      if (CollectionType.SMS.equals(collection.getProvider())) {
        collection.setTrack(null);
        collection.setLangFilters(null);
        collection.setGeo(null);
        collection.setGeoR(null);
        collection.setFollow(null);
      }
      if (collection.getProvider() == CollectionType.Twitter) {
        collection.setFollow(
            this.getFollowTwitterIDs(
                collectionUpdateInfo.getFollow(), collection.getOwner().getUserName()));
      }

      collectionRepository.update(collection);
      // first make an entry in log if collection is running
      if (CollectionStatus.RUNNING_WARNING.equals(collection.getStatus())
          || CollectionStatus.RUNNING.equals(collection.getStatus())) {

        this.stop(collection.getId(), userId);
        this.startFetcher(this.prepareFetcherRequest(collection), collection);
      }
      return true;
    } catch (Exception e) {

      logger.error("Unable to update the collection : " + collectionUpdateInfo.getCode(), e);
      return false;
    }
  }