コード例 #1
0
  public static SyncSite activateSyncSite(long syncAccountId, boolean reset) {
    SyncSite syncSite = fetchSyncSite(syncAccountId);

    syncSite.setActive(true);

    if (reset) {
      syncSite.setRemoteSyncTime(0);
    }

    update(syncSite);

    return syncSite;
  }
コード例 #2
0
  @Override
  public boolean equals(Object object) {
    if (object == this) {
      return true;
    }

    if (!(object instanceof SyncSite)) {
      return false;
    }

    SyncSite syncSite = (SyncSite) object;

    if (syncSite.getSyncSiteId() == syncSiteId) {
      return true;
    } else {
      return false;
    }
  }
コード例 #3
0
  public static SyncAccount activateSyncAccount(long syncAccountId, boolean reset) {

    SyncAccount syncAccount = fetchSyncAccount(syncAccountId);

    syncAccount.setActive(true);

    update(syncAccount);

    if (reset) {
      List<SyncSite> syncSites = SyncSiteService.findSyncSites(syncAccountId);

      for (SyncSite syncSite : syncSites) {
        syncSite.setRemoteSyncTime(0);

        SyncSiteService.update(syncSite);
      }
    }

    return syncAccount;
  }
コード例 #4
0
  protected void addSyncWatchEvent(String eventType, Path filePath) {
    try {
      String filePathName = filePath.toString();

      Path parentFilePath = filePath.getParent();

      String parentFilePathName = parentFilePath.toString();

      SyncAccount syncAccount = SyncAccountService.fetchSyncAccount(getSyncAccountId());

      if (isDuplicateEvent(eventType, filePath.toString(), getSyncAccountId())) {

        return;
      }

      if (filePathName.equals(syncAccount.getFilePathName())
          || parentFilePathName.equals(syncAccount.getFilePathName())) {

        return;
      }

      long repositoryId = getRepositoryId(filePath);

      if (repositoryId <= 0) {
        return;
      }

      SyncSite syncSite = SyncSiteService.fetchSyncSite(repositoryId, getSyncAccountId());

      Set<Long> activeSyncSiteIds = SyncSiteService.getActiveSyncSiteIds(getSyncAccountId());

      if (!activeSyncSiteIds.contains(syncSite.getSyncSiteId())) {
        return;
      }

      SyncWatchEventService.addSyncWatchEvent(
          eventType, filePathName, getFileType(eventType, filePath), getSyncAccountId());
    } catch (Exception e) {
      _logger.error(e.getMessage(), e);
    }
  }
コード例 #5
0
  public static void setFilePathName(long syncAccountId, String targetFilePathName) {

    // Sync account

    SyncAccount syncAccount = fetchSyncAccount(syncAccountId);

    String sourceFilePathName = syncAccount.getFilePathName();

    syncAccount.setFilePathName(targetFilePathName);

    update(syncAccount);

    // Sync files

    List<SyncFile> syncFiles = SyncFileService.findSyncFiles(syncAccountId);

    for (SyncFile syncFile : syncFiles) {
      String syncFileFilePathName = syncFile.getFilePathName();

      syncFileFilePathName = syncFileFilePathName.replace(sourceFilePathName, targetFilePathName);

      syncFile.setFilePathName(syncFileFilePathName);

      SyncFileService.update(syncFile);
    }

    // Sync sites

    List<SyncSite> syncSites = SyncSiteService.findSyncSites(syncAccountId);

    for (SyncSite syncSite : syncSites) {
      String syncSiteFilePathName = syncSite.getFilePathName();

      syncSiteFilePathName = syncSiteFilePathName.replace(sourceFilePathName, targetFilePathName);

      syncSite.setFilePathName(syncSiteFilePathName);

      SyncSiteService.update(syncSite);
    }
  }
コード例 #6
0
  @Override
  protected void processResponse(String response) throws Exception {
    Set<Long> remoteSyncSiteIds = new HashSet<Long>();

    ObjectMapper objectMapper = new ObjectMapper();

    List<SyncSite> remoteSyncSites =
        objectMapper.readValue(response, new TypeReference<List<SyncSite>>() {});

    for (SyncSite remoteSyncSite : remoteSyncSites) {
      SyncSite localSyncSite =
          SyncSiteService.fetchSyncSite(remoteSyncSite.getGroupId(), getSyncAccountId());

      if (localSyncSite == null) {
        SyncAccount syncAccount = SyncAccountService.fetchSyncAccount(getSyncAccountId());

        remoteSyncSite.setFilePathName(
            syncAccount.getFilePathName() + "/" + remoteSyncSite.getName());

        remoteSyncSite.setSyncAccountId(getSyncAccountId());

        SyncSiteService.update(remoteSyncSite);

        remoteSyncSiteIds.add(remoteSyncSite.getSyncSiteId());
      } else {
        localSyncSite.setDescription(remoteSyncSite.getDescription());
        localSyncSite.setFriendlyURL(remoteSyncSite.getFriendlyURL());
        localSyncSite.setName(remoteSyncSite.getName());
        localSyncSite.setType(remoteSyncSite.getType());
        localSyncSite.setTypeSettings(remoteSyncSite.getTypeSettings());
        localSyncSite.setSite(remoteSyncSite.getSite());

        SyncSiteService.update(localSyncSite);

        remoteSyncSiteIds.add(localSyncSite.getSyncSiteId());
      }
    }

    List<SyncSite> localSyncSites = SyncSiteService.findSyncSites(getSyncAccountId());

    for (SyncSite localSyncSite : localSyncSites) {
      if (remoteSyncSiteIds.contains(localSyncSite.getSyncSiteId())) {
        continue;
      }

      SyncSiteService.deleteSyncSite(localSyncSite.getSyncSiteId());
    }
  }
コード例 #7
0
  public static SyncAccount addSyncAccount(
      String filePathName,
      String login,
      int maxConnections,
      String name,
      String password,
      int pollInterval,
      SyncSite[] syncSites,
      boolean trustSelfSigned,
      String url)
      throws Exception {

    // Sync account

    SyncAccount syncAccount = new SyncAccount();

    syncAccount.setFilePathName(filePathName);
    syncAccount.setLogin(login);
    syncAccount.setMaxConnections(maxConnections);
    syncAccount.setName(name);
    syncAccount.setPassword(Encryptor.encrypt(password));
    syncAccount.setPollInterval(pollInterval);
    syncAccount.setTrustSelfSigned(trustSelfSigned);
    syncAccount.setUrl(url);

    _syncAccountPersistence.create(syncAccount);

    // Sync file

    Files.createDirectories(Paths.get(filePathName));

    SyncFileService.addSyncFile(
        null,
        null,
        filePathName,
        FileUtil.getFileKey(filePathName),
        filePathName,
        null,
        filePathName,
        0,
        0,
        syncAccount.getSyncAccountId(),
        SyncFile.TYPE_SYSTEM);

    // Sync sites

    if (syncSites != null) {
      for (SyncSite syncSite : syncSites) {
        String syncSiteName = syncSite.getName();

        if (!FileUtil.isValidFileName(syncSiteName)) {
          syncSiteName = String.valueOf(syncSite.getGroupId());
        }

        syncSite.setFilePathName(syncAccount.getFilePathName() + "/" + syncSiteName);

        syncSite.setSyncAccountId(syncAccount.getSyncAccountId());

        SyncSiteService.update(syncSite);
      }
    }

    return syncAccount;
  }