Skip to content

Commit 2911713

Browse files
PLUGINS-332 Fixing trailing url issue in whitelist & Cleanup
1 parent 447e425 commit 2911713

22 files changed

Lines changed: 385 additions & 532 deletions

src/main/java/org/nrg/xsync/components/XsyncSitePreferencesBean.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ public long getTokenRefreshIntervalInMillis() {
204204
try {
205205
return calculateIntervalInMillis(DEFAULT_TOKEN_REFRESH_INTERVAL);
206206
} catch (InvalidValueException e1) {
207-
return (long) (1000 * 60 * 60 * 10);
207+
return 1000 * 60 * 60 * 10;
208208
}
209209
}
210210
}
@@ -298,8 +298,9 @@ private static long calculateIntervalInMillis(final String intervalStr) throws I
298298
} else {
299299
throw new InvalidValueException("XSync - Interval too short - Specify minimum of " + minIntervalMilis*1000*60 + " minutes.");
300300
}
301-
}else
301+
} else {
302302
throw new InvalidValueException("XSync - Invalid interval specified - " + intervalStr);
303+
}
303304
}
304305

305306
private void addInitialWhitelistSitesToPreferences() {

src/main/java/org/nrg/xsync/discoverer/JsonUtils.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
*/
1717
public class JsonUtils {
1818
private static final Logger _log = LoggerFactory.getLogger(JsonUtils.class);
19-
2019

2120
public JsonNode toJSONFromMap(List<Map<String,Object>> results) {
2221
ObjectMapper objectMapper = new ObjectMapper();
@@ -44,8 +43,8 @@ public JsonNode toJSONFromList(List<String> results) {
4443

4544
public void debug(String name, List<Map<String, Object>> list) {
4645
ObjectMapper objectMapper = new ObjectMapper();
47-
JsonNode json = null;
48-
ObjectNode root = null;
46+
JsonNode json;
47+
ObjectNode root;
4948
try {
5049
String jsonAsStr = objectMapper.writeValueAsString(list);
5150
root = objectMapper.createObjectNode();

src/main/java/org/nrg/xsync/discoverer/ProjectChangeDiscoverer.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import java.util.concurrent.Callable;
99

1010
import lombok.extern.slf4j.Slf4j;
11+
import org.apache.commons.collections.CollectionUtils;
1112
import org.nrg.config.services.ConfigService;
1213
import org.nrg.framework.services.SerializerService;
1314
import org.nrg.mail.services.MailService;
@@ -256,7 +257,7 @@ private void syncProjectResources() {
256257
ResourceUtils resourceUtils = new ResourceUtils(_projectSyncConfiguration);
257258

258259
List<Map<String, Object>> resourceRows = getProjectResourcesModifiedSinceLastSync();
259-
if (resourceRows == null || resourceRows.size() < 1) {
260+
if (!CollectionUtils.isEmpty(resourceRows)) {
260261
return;
261262
}
262263
String remoteProjectId = _projectSyncConfiguration.getProjectSyncConfigurationFromDB().getSyncinfo().getRemoteProjectId();
@@ -268,7 +269,7 @@ private void syncProjectResources() {
268269
if (label != null && label.equalsIgnoreCase(XsyncUtils.PROJECT_SYNC_LOG_RESOURCE_LABEL)) {
269270
continue;
270271
}
271-
_log.debug("Resource " + row.get("label") + " has been modfied since " + this.getLastSyncStartTime());
272+
_log.debug("Resource {} has been modified since {}", row.get("label"), this.getLastSyncStartTime());
272273
if (_projectSyncConfiguration.isResourceToBeSynced(label)) {
273274
String status = (String) row.get("status");
274275
if (_syncAll) {
@@ -403,7 +404,6 @@ private void updateProjectResource(String localProjectArchivePath, String resour
403404
}
404405
}
405406

406-
407407
private List<Map<String, Object>> getSubjectsModifiedSinceLastSync() {
408408
//Any entity that is derived from the subject or linked to the subject
409409
//if modified, would result in an update in the last_modified column
@@ -423,7 +423,6 @@ private List<Map<String, Object>> getSubjectsSharedIntoProject() {
423423
return _jdbcTemplate.queryForList(query, _parameters);
424424
}
425425

426-
427426
/**
428427
* Append failed subjects.
429428
*
@@ -441,7 +440,7 @@ private List<Map<String, Object>> getQueryForFetchingSubjectsWhoseExperimentsMar
441440
MapSqlParameterSource parameters = new MapSqlParameterSource();
442441
parameters.addValue("project", _projectId);
443442
boolean skipSubjectIdCheck = false;
444-
if (excludeIds.size() > 0) {
443+
if (!excludeIds.isEmpty()) {
445444
parameters.addValue(QueryResultUtil.SUBJECT_IDS, excludeIds);
446445
} else {
447446
skipSubjectIdCheck = true;
@@ -456,7 +455,7 @@ private List<Map<String, Object>> getProjectResourcesModifiedSinceLastSync() {
456455
}
457456

458457
private void syncSubject(XnatSubjectdata localSubject) throws Exception {
459-
_log.debug("Exporting " + localSubject.getId());
458+
_log.debug("Exporting {}", localSubject.getId());
460459
SubjectDataSync remoteSubject = new SubjectDataSync(_manager, _xnatInfo, _queryResultUtil, (JdbcTemplate) _jdbcTemplate.getJdbcOperations(),
461460
localSubject, _projectSyncConfiguration, _user, _syncAll, _observer, _serializer, _syncStatusService);
462461
remoteSubject.sync(true);
@@ -478,7 +477,7 @@ private void deleteSubject(String deletedSubjectLocalId, String deletedSubjectLa
478477
subject.setId(remoteId);
479478
ConflictCheckUtil.checkForConflict(subject, remoteId, _projectSyncConfiguration,
480479
_jdbcTemplate, _queryResultUtil, _manager);
481-
_log.debug("Deleting subject " + subject.getId() + " from remote project " + subject.getProject());
480+
_log.debug("Deleting subject {} from remote project {}", subject.getId(), subject.getProject());
482481
try {
483482
RemoteConnectionHandler remoteConnectionHandler = new RemoteConnectionHandler(_jdbcTemplate, _queryResultUtil);
484483
RemoteConnection connection = remoteConnectionHandler.getConnection(_projectId, remoteUrl);
@@ -569,5 +568,4 @@ public String generateMappingReport(String reportFormat, String objectType) thro
569568
XsyncProjectReportGenerator reportGenerator = new XsyncProjectReportGenerator(_manager, _queryResultUtil, _jdbcTemplate, _projectSyncConfiguration, _serializer, _user);
570569
return reportGenerator.generateMappingReport(reportFormat, objectType);
571570
}
572-
573571
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package org.nrg.xsync.pojo;
2+
3+
import lombok.AllArgsConstructor;
4+
import lombok.Getter;
5+
import lombok.NoArgsConstructor;
6+
import lombok.Setter;
7+
8+
@NoArgsConstructor
9+
@AllArgsConstructor
10+
@Getter
11+
@Setter
12+
public class XsyncRemoteCredentialsPojo {
13+
private String host;
14+
private String localProject;
15+
private String remoteProject;
16+
private Boolean syncNewOnly;
17+
private String alias;
18+
private String secret;
19+
private String username;
20+
private String estimatedExpirationTime;
21+
}

src/main/java/org/nrg/xsync/scheduler/XsyncScheduler.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import org.nrg.xsync.services.local.impl.XSyncAliasTokenRefresh;
1010
import org.slf4j.Logger;
1111
import org.slf4j.LoggerFactory;
12-
import org.springframework.beans.factory.annotation.Autowired;
1312
import org.springframework.context.annotation.Bean;
1413
import org.springframework.context.annotation.Configuration;
1514
import org.springframework.scheduling.annotation.EnableScheduling;
@@ -48,29 +47,29 @@ public TriggerTask refreshToken(final XsyncAliasRefreshService aliasRefreshServi
4847
@Bean
4948
//Run Hourly sync at 30 minutes past the hour, every hour
5049
public TriggerTask syncProjectsMarkedAsHourlySync(HourlySyncService hourlySyncService) {
51-
_logger.debug("Initializing HourlySync TriggerTask: " + hourlySyncService);
50+
_logger.debug("Initializing HourlySync TriggerTask: {}", hourlySyncService);
5251
return new TriggerTask(hourlySyncService, new CronTrigger("0 30 * * * ?"));
5352
}
5453

5554

5655
@Bean
57-
//Run Daily sync everyday at 00:00 hours
56+
//Run Daily sync every day at 00:00 hours
5857
public TriggerTask syncProjectsMarkedAsDailySync(final DailySyncService dailySyncService) {
59-
_logger.debug("Initializing DailySync TriggerTask: " + dailySyncService);
58+
_logger.debug("Initializing DailySync TriggerTask: {}", dailySyncService);
6059
return new TriggerTask(dailySyncService, new CronTrigger("0 0 0 * * *"));
6160
}
6261

6362
@Bean
6463
//Run every SAT of the week at 01:00 hours
6564
public TriggerTask syncProjectsMarkedAsWeeklySync(final WeeklySyncService weeklySyncService) {
66-
_logger.debug("Initializing WeeklySync TriggerTask: " + weeklySyncService);
65+
_logger.debug("Initializing WeeklySync TriggerTask: {}", weeklySyncService);
6766
return new TriggerTask(weeklySyncService, new CronTrigger("0 0 1 ? * SAT"));
6867
}
6968

7069
@Bean
7170
//Run every month on 1st of the month at 02:00 hours
7271
public TriggerTask syncProjectsMarkedAsMonthlySync(final MonthlySyncService monthlySyncService) {
73-
_logger.debug("Initializing MontlySync TriggerTask: " + monthlySyncService);
72+
_logger.debug("Initializing MontlySync TriggerTask: {}", monthlySyncService);
7473
return new TriggerTask(monthlySyncService, new CronTrigger("0 0 2 1 * *"));
7574
}
7675

src/main/java/org/nrg/xsync/services/local/impl/WhitelistXsyncSiteServiceImpl.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ public void addWhiteListSitesFromJson(List<WhitelistSitePojo> whitelistSitePojos
5252
@Override
5353
public List<WhitelistSitePojo> addOrUpdateWhitelistSiteFromSiteAdmin(WhitelistSitePojo whitelistSitePojo) throws DataFormatException {
5454
SiteClassification newSiteClassification = getSiteClassification(whitelistSitePojo);
55-
5655
WhitelistSite newSite;
5756
if (getDao().findWhitelistSiteBySiteId(whitelistSitePojo.getSiteId()) == null) {
5857
newSite = new WhitelistSite(whitelistSitePojo.getSiteId(), whitelistSitePojo.getSiteName(),
@@ -65,7 +64,6 @@ public List<WhitelistSitePojo> addOrUpdateWhitelistSiteFromSiteAdmin(WhitelistSi
6564
}
6665

6766
getDao().saveOrUpdate(newSite);
68-
6967
return getAllWhitelistedSites();
7068
}
7169

src/main/java/org/nrg/xsync/tools/XSyncTools.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import java.util.List;
55
import java.util.Map;
66

7+
import org.apache.commons.collections.CollectionUtils;
78
import org.nrg.xdat.om.XsyncXsyncassessordata;
89
import org.nrg.xdat.om.XsyncXsyncremotemapdata;
910
import org.nrg.xft.event.EventMetaI;
@@ -65,7 +66,7 @@ public boolean hasBeenSyncedAlready(String localProjectId, String local_id, Stri
6566
parameters.addValue("REMOTE_URL", remoteUrl);
6667

6768
List<Map<String, Object>> syncMapRows = _jdbcTemplate.queryForList(query, parameters);
68-
if (syncMapRows != null && syncMapRows.size() > 0) {
69+
if (!CollectionUtils.isEmpty(syncMapRows)) {
6970
hasBeenSyncedAlready = true;
7071
}
7172
return hasBeenSyncedAlready;
@@ -112,7 +113,7 @@ public void updateSyncAssessor(ExperimentSyncItem expSyncItem, String remoteProj
112113
private XsyncXsyncassessordata getXsyncAssessor(String exptId, String remote_url) {
113114
XsyncXsyncassessordata assessor = null;
114115
ArrayList<XsyncXsyncassessordata> okToSyncDatas = XsyncXsyncassessordata.getXsyncXsyncassessordatasByField("xsync:xsyncAssessorData/synced_experiment_id", exptId, _user, true);
115-
if (okToSyncDatas != null && okToSyncDatas.size() > 0) {
116+
if (!CollectionUtils.isEmpty(okToSyncDatas)) {
116117
for (XsyncXsyncassessordata okToSyncData : okToSyncDatas) {
117118
if (okToSyncData.getRemoteUrl().equals(remote_url)) {
118119
assessor = okToSyncData;
@@ -135,9 +136,9 @@ public boolean hasExperimentBeenSuccessfullySyncedInThePast(String localProjectI
135136
parameters.addValue("REMOTE_URL", remoteUrl);
136137

137138
List<Map<String, Object>> syncMapRows = _jdbcTemplate.queryForList(query, parameters);
138-
if (syncMapRows != null && syncMapRows.size() > 0) {
139+
if (!CollectionUtils.isEmpty(syncMapRows)) {
139140
hasBeenSyncedAlready = true;
140-
Map<String, Object> row = syncMapRows.get(0);
141+
Map<String, Object> row = syncMapRows.getFirst();
141142
String syncStatus = (String)row.get("sync_status");
142143
if (syncStatus.equals(XsyncUtils.SYNC_STATUS_SYNCED_AND_VERIFIED)) {
143144
hasBeenSyncedAlready = true;

src/main/java/org/nrg/xsync/tools/XsyncObserver.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public void update(Observable observable, Object item) {
5757
bWriter.newLine();
5858
bWriter.flush();
5959
} catch (IOException e) {
60-
logger.error("An error occurred writing the log sync file " + logFile.getAbsolutePath(), e);
60+
logger.error("An error occurred writing the log sync file {}", logFile.getAbsolutePath(), e);
6161
}
6262
}
6363
}
@@ -81,7 +81,7 @@ public void close(XnatAbstractresourceI syncResource) {
8181
try {
8282
FileUtils.CopyFile(logFile, dest, true);
8383
}catch(Exception e) {
84-
logger.error("Unable to save file " + logFile.getAbsolutePath() + " to " + dest.getAbsolutePath(),e);
84+
logger.error("Unable to save file {} to {}", logFile.getAbsolutePath(), dest.getAbsolutePath(), e);
8585
}
8686
}
8787

src/main/java/org/nrg/xsync/tools/XsyncURIUtils.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,7 @@ public String getRemoteAssignedId(final RemoteConnectionResponse connectionRespo
122122
String remote_id_with_line_breaks = connectionResponse.getResponseBody();
123123
remote_id_with_line_breaks = remote_id_with_line_breaks.replaceAll("\\r\\n|\\r|\\n", "");
124124
_logger.debug("connectionResopnse.getResponseBody()=" + remote_id_with_line_breaks);
125-
String remote_id_parts[] = remote_id_with_line_breaks.split("/");
126-
String remote_id = remote_id_parts[remote_id_parts.length-1];
127-
return remote_id;
125+
String[] remote_id_parts = remote_id_with_line_breaks.split("/");
126+
return remote_id_parts[remote_id_parts.length-1];
128127
}
129128
}

src/main/java/org/nrg/xsync/utils/ConflictCheckUtil.java

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import java.util.List;
44
import java.util.Map;
55

6+
import org.apache.commons.collections.CollectionUtils;
67
import org.nrg.xdat.model.XnatExperimentdataI;
78
import org.nrg.xdat.model.XnatSubjectdataI;
89
import org.nrg.xsync.configuration.ProjectSyncConfiguration;
@@ -33,9 +34,9 @@ public static void checkForConflict(XnatSubjectdataI subject, String remoteId,
3334
final RemoteConnectionResponse connectionResponse = manager.getResult(connection,uri);
3435
if (connectionResponse.wasSuccessful()) {
3536
final List<Map<String, String>> result = getResultList(connectionResponse);;
36-
if (result != null && result.size()>0) {
37-
final String remoteSessionLabel = result.get(0).get("label");
38-
final String remoteSessionProject = result.get(0).get("project");
37+
if (!CollectionUtils.isEmpty(result)) {
38+
final String remoteSessionLabel = result.getFirst().get("label");
39+
final String remoteSessionProject = result.getFirst().get("project");
3940
if (remoteSessionLabel != null && remoteSessionProject != null) {
4041
if (subject.getLabel().equals(remoteSessionLabel) && remoteProjectId.equals(remoteSessionProject)) {
4142
return;
@@ -44,11 +45,11 @@ public static void checkForConflict(XnatSubjectdataI subject, String remoteId,
4445
" exists at destination with a different label or in a different project.");
4546
}
4647
}
47-
} else if (result.size() == 0) {
48+
} else {
4849
return;
4950
}
5051
}
51-
throw new XsyncConflictCheckFailureException("Cound not check for subject label conflict (SUBJECT=" + subject.getLabel() + ")");
52+
throw new XsyncConflictCheckFailureException("Could not check for subject label conflict (SUBJECT=" + subject.getLabel() + ")");
5253
}
5354

5455
public static void checkForConflict(XnatExperimentdataI exp, String remoteId,
@@ -66,35 +67,35 @@ public static void checkForConflict(XnatExperimentdataI exp, String remoteId,
6667
if (result == null || result.isEmpty()) {
6768
return;
6869
}
69-
final String remoteSessionLabel = result.get(0).get("label");
70-
final String remoteSessionProject = result.get(0).get("project");
70+
final String remoteSessionLabel = result.getFirst().get("label");
71+
final String remoteSessionProject = result.getFirst().get("project");
7172
if (exp.getLabel().equals(remoteSessionLabel) && remoteProjectId.equals(remoteSessionProject)) {
7273
return;
7374
} else {
7475
throw new XsyncIdConflictException("Experiment " + remoteId +
7576
" exists at destination with a different label or in a different project.");
7677
}
7778
}
78-
throw new XsyncConflictCheckFailureException("Cound not check for experiment label conflict (EXPERIMENT=" + exp.getLabel() + ")");
79+
throw new XsyncConflictCheckFailureException("Could not check for experiment label conflict (EXPERIMENT=" + exp.getLabel() + ")");
7980
}
8081

8182
@SuppressWarnings("unchecked")
8283
private static List<Map<String, String>> getResultList(RemoteConnectionResponse connectionResponse) throws XsyncConflictCheckFailureException {
83-
final String responseBody = connectionResponse.getResponseBody();
84-
final Map<String,Map<String,Object>> responseObj =
85-
_gson.fromJson(responseBody, new TypeToken<Map<String,Map<String,Object>>>(){}.getType());
86-
if (responseObj == null) {
87-
return null;
88-
}
89-
final Map<String, Object> resultSet = responseObj.get("ResultSet");
90-
if (resultSet == null) {
91-
return null;
92-
}
93-
final Object resultObj = resultSet.get("Result");
94-
if (resultObj instanceof List) {
95-
return (List<Map<String,String>>)resultObj;
96-
}
97-
throw new XsyncConflictCheckFailureException("Failed to get results list");
84+
final String responseBody = connectionResponse.getResponseBody();
85+
final Map<String,Map<String,Object>> responseObj =
86+
_gson.fromJson(responseBody, new TypeToken<Map<String,Map<String,Object>>>(){}.getType());
87+
if (responseObj == null) {
88+
return null;
89+
}
90+
final Map<String, Object> resultSet = responseObj.get("ResultSet");
91+
if (resultSet == null) {
92+
return null;
93+
}
94+
final Object resultObj = resultSet.get("Result");
95+
if (resultObj instanceof List) {
96+
return (List<Map<String,String>>)resultObj;
97+
}
98+
throw new XsyncConflictCheckFailureException("Failed to get results list");
9899
}
99100

100101
}

0 commit comments

Comments
 (0)