Skip to content
Snippets Groups Projects
Commit 1632c17d authored by Justin Cleveland's avatar Justin Cleveland
Browse files

(partial commit) XNAT-1649 - Archive mount point is missing, but system runs without a message

parent b24fa17d
No related branches found
No related tags found
No related merge requests found
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
*/ */
package org.nrg.xnat.initialization.tasks; package org.nrg.xnat.initialization.tasks;
import org.nrg.mail.services.MailService;
import org.nrg.xdat.preferences.SiteConfigPreferences; import org.nrg.xdat.preferences.SiteConfigPreferences;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
...@@ -21,6 +22,8 @@ import org.springframework.jdbc.core.JdbcTemplate; ...@@ -21,6 +22,8 @@ import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.ResultSetExtractor; import org.springframework.jdbc.core.ResultSetExtractor;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import javax.inject.Inject;
import javax.mail.MessagingException;
import java.io.File; import java.io.File;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
...@@ -36,27 +39,18 @@ public class SystemPathVerification extends AbstractInitializingTask { ...@@ -36,27 +39,18 @@ public class SystemPathVerification extends AbstractInitializingTask {
} }
private final static ArrayList<String> pathErrors = new ArrayList<>(); private final static ArrayList<String> pathErrors = new ArrayList<>();
public static String pathErrorWarning = null;
@Override @Override
public void run() { public void run() {
try { try {
String archivePath = _siteConfigPreferences.getArchivePath(); validatePath(_config.getArchivePath(), "Archive", true);
validatePath(archivePath, "Archive", true);
final ProjectExtractor pe = new ProjectExtractor(); final ProjectExtractor pe = new ProjectExtractor();
final SubjectExtractor se = new SubjectExtractor();
final Map<String, String> projects = _template.query("SELECT id, name FROM xnat_projectdata", pe); final Map<String, String> projects = _template.query("SELECT id, name FROM xnat_projectdata", pe);
if(projects.size() > 0){
final Map<String, String> subjects = _template.query("SELECT id, name FROM xnat_subjectdata", se);
if(subjects.size() > 0){
}
}
if(pathErrors.size() > 0) { if(pathErrors.size() > 0) {
// Send warning email to admin and issue browser notification
// Send warning email to admin notifyOfPathErrors(projects.size());
System.out.println(pathErrors);
} }
complete(); complete();
} catch (Exception e) { } catch (Exception e) {
...@@ -73,16 +67,7 @@ System.out.println(pathErrors); ...@@ -73,16 +67,7 @@ System.out.println(pathErrors);
pathErrors.add(displayName+" path \""+path+"\" is not a directory."); pathErrors.add(displayName+" path \""+path+"\" is not a directory.");
return false; return false;
} else if (checkForFiles) { } else if (checkForFiles) {
// check for actual subdirectories and files existing here
/*
FileFilter directoryFilter = new FileFilter() {
public boolean accept(File file) {
return file.isDirectory();
}
};
*/
File[] files = filePath.listFiles(); File[] files = filePath.listFiles();
//directoryFilter);
final String noFiles = displayName + " files do not exist under \"" + path + "\"."; final String noFiles = displayName + " files do not exist under \"" + path + "\".";
if(files == null) { if(files == null) {
pathErrors.add(noFiles); pathErrors.add(noFiles);
...@@ -92,13 +77,6 @@ System.out.println(pathErrors); ...@@ -92,13 +77,6 @@ System.out.println(pathErrors);
pathErrors.add(noFiles); pathErrors.add(noFiles);
return false; return false;
} }
/*
else {
for (File file : files) {
System.out.println(file);
}
}
*/
} }
return true; return true;
} }
...@@ -114,14 +92,32 @@ else { ...@@ -114,14 +92,32 @@ else {
} }
} }
private static class SubjectExtractor implements ResultSetExtractor<Map<String, String>> { private void notifyOfPathErrors(int numProjects) {
@Override if(numProjects > 0) {
public Map<String, String> extractData(final ResultSet results) throws SQLException, DataAccessException { int i = 1;
final Map<String, String> subjects = new HashMap<>(); String adminEmail = _config.getAdminEmail();
while (results.next()) { String sysName = _config.getSiteId();
subjects.put(results.getString(1), results.getString(2)); String emailSubj = sysName + " " + this.getTaskName() + " Failure";
StringBuffer sb = new StringBuffer(emailSubj);
String singPlurl = " has";
if (numProjects > 1) {
singPlurl = "s have";
}
sb.append("\nThe following system path error" + singPlurl + " been discovered:");
for (String err : pathErrors) {
sb.append("\t");
sb.append(i);
sb.append(". ");
sb.append(err);
}
pathErrorWarning = sb.toString();
logger.error(pathErrorWarning);
_config.setPathErrorWarning(pathErrorWarning);
try {
_mailService.sendHtmlMessage(adminEmail, adminEmail, emailSubj, pathErrorWarning);
} catch (MessagingException e) {
logger.error("", e);
} }
return subjects;
} }
} }
...@@ -131,7 +127,10 @@ else { ...@@ -131,7 +127,10 @@ else {
@Lazy @Lazy
private JdbcTemplate _template; private JdbcTemplate _template;
@Inject
private MailService _mailService;
@Autowired @Autowired
@Lazy @Lazy
private SiteConfigPreferences _siteConfigPreferences; private SiteConfigPreferences _config;
} }
...@@ -7,8 +7,6 @@ ...@@ -7,8 +7,6 @@
fieldDate.attr('placeholder', 'MM/DD/YYYY'); fieldDate.attr('placeholder', 'MM/DD/YYYY');
openCal = $('#openCal-passwordExpirationDate'); openCal = $('#openCal-passwordExpirationDate');
openCal.click(openCalendar); openCal.click(openCalendar);
// fieldInterval[0].style.width = '40px';
// fieldInterval[0].style.textAlign = 'right';
fieldInterval[0].style.marginTop='10px'; fieldInterval[0].style.marginTop='10px';
fieldDate[0].style.width = '90px'; fieldDate[0].style.width = '90px';
fieldDate[0].style.marginTop='10px'; fieldDate[0].style.marginTop='10px';
......
...@@ -94,6 +94,10 @@ ...@@ -94,6 +94,10 @@
</div> </div>
#end #end
#if ($siteConfig.pathErrorWarning)
<h1>$siteConfig.pathErrorWarning</h1>
#end
<div id="main_nav"> <div id="main_nav">
<div class="inner"> <div class="inner">
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment