Skip to content

Commit

Permalink
ZFIN-9356: Fix email sending (ZFIN#1191)
Browse files Browse the repository at this point in the history
  • Loading branch information
rtaylorzfin authored Oct 25, 2024
1 parent 4427827 commit 2791339
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 28 deletions.
38 changes: 15 additions & 23 deletions server_apps/jenkins/jobs/Find-Empty-Publication-Files_w/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,48 +24,40 @@
</hudson.triggers.TimerTrigger>
</triggers>
<concurrentBuild>false</concurrentBuild>
<customWorkspace>$TARGETROOT</customWorkspace>
<builders>
<hudson.tasks.Shell>
<command>cd $SOURCEROOT &amp;&amp; gradle findEmptyPublicationFilesTask</command>
<command><![CDATA[
export ARTIFACTS_DIR=`pwd`
echo "ARTIFACTS_DIR: $ARTIFACTS_DIR"
cd $SOURCEROOT && gradle findEmptyPublicationFilesTask
]]></command>
</hudson.tasks.Shell>
</builders>
<publishers>
<hudson.tasks.ArtifactArchiver>
<artifacts>empty_publication_files.csv</artifacts>
<latestOnly>false</latestOnly>
<allowEmptyArchive>true</allowEmptyArchive>
</hudson.tasks.ArtifactArchiver>
<hudson.plugins.emailext.ExtendedEmailPublisher plugin="[email protected]">
<recipientList></recipientList>
<configuredTriggers>
<hudson.plugins.emailext.plugins.trigger.FailureTrigger>
<email>
<recipientList>@FAILURE-RECIPIENT-LIST@</recipientList>
<subject>$PROJECT_DEFAULT_SUBJECT</subject>
<body>${SCRIPT, template=&quot;reportBody.template&quot;}</body>
<subject>Found empty files</subject>
<body>Empty files found from scan for publication files without any contents.</body>
<sendToDevelopers>false</sendToDevelopers>
<sendToRequester>false</sendToRequester>
<includeCulprits>false</includeCulprits>
<sendToRecipientList>true</sendToRecipientList>
<attachmentsPattern>ensembl-transcript-report.txt</attachmentsPattern>
<attachBuildLog>false</attachBuildLog>
<compressBuildLog>false</compressBuildLog>
<attachmentsPattern></attachmentsPattern>
<attachBuildLog>true</attachBuildLog>
<compressBuildLog>true</compressBuildLog>
<replyTo></replyTo>
<contentType>project</contentType>
</email>
</hudson.plugins.emailext.plugins.trigger.FailureTrigger>
<hudson.plugins.emailext.plugins.trigger.SuccessTrigger>
<email>
<recipientList>@SUCCESS-RECIPIENT-LIST@</recipientList>
<subject>$PROJECT_DEFAULT_SUBJECT</subject>
<body>$PROJECT_DEFAULT_CONTENT</body>
<sendToDevelopers>false</sendToDevelopers>
<sendToRequester>false</sendToRequester>
<includeCulprits>false</includeCulprits>
<sendToRecipientList>true</sendToRecipientList>
<attachmentsPattern>ensembl-transcript-report.txt</attachmentsPattern>
<attachBuildLog>false</attachBuildLog>
<compressBuildLog>false</compressBuildLog>
<replyTo>$PROJECT_DEFAULT_REPLYTO</replyTo>
<contentType>project</contentType>
</email>
</hudson.plugins.emailext.plugins.trigger.SuccessTrigger>
</configuredTriggers>
<contentType>default</contentType>
<defaultSubject>[Jenkins][${INSTANCE}]: ${PROJECT_NAME}: ${BUILD_STATUS}</defaultSubject>
Expand Down
26 changes: 21 additions & 5 deletions source/org/zfin/publication/FindEmptyPublicationFilesTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
import org.zfin.ontology.datatransfer.AbstractScriptWrapper;
import org.zfin.publication.presentation.PublicationService;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.List;

import static org.zfin.repository.RepositoryFactory.getPublicationRepository;
Expand All @@ -12,20 +16,32 @@
* It prints the filename, publication ZDB ID, and filetype of each empty file.
*/
public class FindEmptyPublicationFilesTask extends AbstractScriptWrapper {
public static void main(String[] args) {
public static void main(String[] args) throws IOException {
FindEmptyPublicationFilesTask task = new FindEmptyPublicationFilesTask();
task.runTask();
}

private void runTask() {
private void runTask() throws IOException {
initAll();
PublicationService pubService = new PublicationService();
List<PublicationFile> files = getPublicationRepository().getAllPublicationFiles();
List<PublicationFile> emptyFiles = files.stream().filter(file -> pubService.getPublicationFileSizeOnDisk(file) == 0).toList();
System.out.println("Filename,Publication ZDB ID,Filetype");
for (PublicationFile file : emptyFiles) {
System.out.println(file.getFileName() + "," + file.getPublication().getZdbID() + "," + file.getType().getName());
String outputDir = ".";
if (System.getenv("ARTIFACTS_DIR") != null) {
outputDir = System.getenv("ARTIFACTS_DIR");
}
File outputReportFile = new File(outputDir, "empty_publication_files.csv");
System.out.println("Writing report to " + outputReportFile.getAbsolutePath());

try (BufferedWriter reportFileHandle = new BufferedWriter(new FileWriter(outputReportFile))) {
System.out.println("Filename,Publication ZDB ID,Filetype");
reportFileHandle.write("Filename,Publication ZDB ID,Filetype\n");
for (PublicationFile file : emptyFiles) {
System.out.println(file.getFileName() + "," + file.getPublication().getZdbID() + "," + file.getType().getName());
reportFileHandle.write(file.getFileName() + "," + file.getPublication().getZdbID() + "," + file.getType().getName() + "\n");
}
}

System.out.println("Found " + emptyFiles.size() + " empty publication files");
if(emptyFiles.size() > 0) {
System.exit(1);
Expand Down

0 comments on commit 2791339

Please sign in to comment.