-
Notifications
You must be signed in to change notification settings - Fork 236
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
REPORT-770 : Add a user interface component that enables viewing and … #168
Open
mozzy11
wants to merge
1
commit into
openmrs:master
Choose a base branch
from
mozzy11:REPORT-770
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
69 changes: 69 additions & 0 deletions
69
api-tests/src/test/java/org/openmrs/module/reporting/evaluation/DeleteOldLogsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/** | ||
* This Source Code Form is subject to the terms of the Mozilla Public License, | ||
* v. 2.0. If a copy of the MPL was not distributed with this file, You can | ||
* obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under | ||
* the terms of the Healthcare Disclaimer located at http://openmrs.org/license. | ||
* | ||
* Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS | ||
* graphic logo is a trademark of OpenMRS Inc. | ||
*/ | ||
package org.openmrs.module.reporting.evaluation; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.openmrs.module.reporting.ReportingConstants; | ||
import org.openmrs.util.OpenmrsUtil; | ||
|
||
public class DeleteOldLogsTest { | ||
|
||
File baseDir = OpenmrsUtil.getDirectoryInApplicationDataDirectory(ReportingConstants.REPORT_RESULTS_DIRECTORY_NAME); | ||
|
||
Path test= Paths.get(baseDir.getAbsolutePath(),"test.reportlog"); | ||
File test_file = test.toFile(); | ||
|
||
@Before | ||
public void init() throws IOException { | ||
test_file.createNewFile(); | ||
} | ||
|
||
@Test | ||
public void Should_DeleteLogFlesExceedingSevendays() throws IOException { | ||
//Setting the file to exist over seven days | ||
long exceedingDays = 8 ; | ||
test_file.setLastModified(exceedingDays * (24 * 60 * 60 * 1000)); | ||
|
||
// asserting that the file exists befor the servlet DeleteOldLogs is called | ||
Assert.assertTrue(test_file.exists()); | ||
|
||
DeleteOldLogFiles delete = new DeleteOldLogFiles (); | ||
delete.deleteOldLogs(); | ||
|
||
//Asserting that the Log file will be deleted after seven days | ||
Assert.assertFalse(test_file.exists()); | ||
} | ||
|
||
@Test | ||
public void Should_NotDeleteLogFilesBeforeSevenDayPass() throws IOException { | ||
|
||
// asserting that the file exists befor the servlet DeleteOldLogs is called | ||
Assert.assertTrue(test_file.exists()); | ||
|
||
DeleteOldLogFiles delete = new DeleteOldLogFiles (); | ||
delete.deleteOldLogs(); | ||
|
||
//Asserting that the Log file will Not be deleted after seven days | ||
Assert.assertTrue(test_file.exists()); | ||
} | ||
|
||
} | ||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
api/src/main/java/org/openmrs/module/reporting/evaluation/DeleteOldLogFiles.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/** | ||
* This Source Code Form is subject to the terms of the Mozilla Public License, | ||
* v. 2.0. If a copy of the MPL was not distributed with this file, You can | ||
* obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under | ||
* the terms of the Healthcare Disclaimer located at http://openmrs.org/license. | ||
* | ||
* Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS | ||
* graphic logo is a trademark of OpenMRS Inc. | ||
*/ | ||
|
||
package org.openmrs.module.reporting.evaluation; | ||
import java.io.File; | ||
import java.util.Date; | ||
|
||
import javax.servlet.ServletException; | ||
import javax.servlet.http.HttpServlet; | ||
|
||
import org.apache.commons.io.FilenameUtils; | ||
import org.apache.commons.lang3.StringUtils; | ||
import org.apache.commons.logging.Log; | ||
import org.apache.commons.logging.LogFactory; | ||
import org.openmrs.module.reporting.ReportingConstants; | ||
import org.openmrs.util.OpenmrsUtil; | ||
|
||
|
||
|
||
public class DeleteOldLogFiles extends HttpServlet { | ||
|
||
private static final long serialVersionUID = 1L; | ||
// Servlet to delete old Logs on module startup | ||
protected static final Log log = LogFactory.getLog(DeleteOldLogFiles.class); | ||
|
||
|
||
public void deleteOldLogs(){ | ||
//maximum number of days to keep log files is 7 | ||
long alloweddays = 7; | ||
File baseDir = OpenmrsUtil.getDirectoryInApplicationDataDirectory(ReportingConstants.REPORT_RESULTS_DIRECTORY_NAME); | ||
File[] fList = baseDir.listFiles(); | ||
|
||
if (fList != null){ | ||
for (File file : fList){ | ||
String fileExt = FilenameUtils.getExtension(file.toString()); | ||
if (file.isFile() && StringUtils.equals(fileExt, "reportlog")){ | ||
|
||
long diff = new Date().getTime() - file.lastModified(); | ||
long maximumTime = (alloweddays * (24 * 60 * 60 * 1000)); | ||
|
||
if (diff > maximumTime) { | ||
file.delete(); | ||
} | ||
|
||
} | ||
} | ||
|
||
} | ||
} | ||
|
||
@Override | ||
public void init() throws ServletException { | ||
deleteOldLogs(); | ||
} | ||
|
||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a better way to deal with the nullpointer problem rather than catching it?