@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());
    }
  }
Ejemplo n.º 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;
    }
  }
  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);
    }
  }