private SyncFile _getSyncFile(FullHttpRequest fullHttpRequest) { String[] pathArray = StringUtils.split(fullHttpRequest.uri(), "/"); if (pathArray.length != 4) { return null; } String lanServerUuid = pathArray[0]; long repositoryId = GetterUtil.getLong(pathArray[1]); long typePK = GetterUtil.getLong(pathArray[2]); long versionId = GetterUtil.getLong(pathArray[3]); if (lanServerUuid.isEmpty() || (repositoryId == 0) || (typePK == 0) || (versionId == 0)) { return null; } List<SyncAccount> syncAccounts = SyncAccountService.findSyncAccounts(lanServerUuid); for (SyncAccount syncAccount : syncAccounts) { SyncFile syncFile = SyncFileService.fetchSyncFile( repositoryId, syncAccount.getSyncAccountId(), typePK, versionId); if ((syncFile != null) && (syncFile.getState() == SyncFile.STATE_SYNCED)) { return syncFile; } } return null; }
@Test public void testAddAccount() throws Exception { SyncAccount syncAccount = SyncAccountService.addSyncAccount( filePathName, "*****@*****.**", "test", "http://localhost:8080/api/jsonws"); _syncAccount = SyncAccountService.fetchSyncAccount(syncAccount.getSyncAccountId()); Assert.assertNotNull(_syncAccount); }
public static SyncLanClient createSyncLanClient(int port) throws Exception { SyncLanClient syncLanClient = new SyncLanClient(); Map<String, Set<Long>> endpoints = new HashMap<>(); for (SyncAccount syncAccount : SyncAccountService.findAll()) { if (!syncAccount.isActive() || !syncAccount.isLanEnabled()) { continue; } endpoints.put( syncAccount.getLanServerUuid(), SyncSiteService.getActiveGroupIds(syncAccount.getSyncAccountId())); } syncLanClient.setEndpoints(endpoints); syncLanClient.setPort(port); syncLanClient.setSyncLanClientUuid(getSyncLanClientUuid()); return syncLanClient; }
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; }