Skip to content

Commit

Permalink
Issue #58
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt Harrah (frizbog) committed Jan 22, 2017
1 parent 267d265 commit e2660d0
Show file tree
Hide file tree
Showing 10 changed files with 114 additions and 30 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
/.DS_Store
/.pmd
/.checkstyle
/build/
Original file line number Diff line number Diff line change
Expand Up @@ -59,25 +59,15 @@
*/
public class ConflictingDatesAnalyzer extends AAnalyzer {

/**
* The gedcom being analyzed
*/
private Gedcom gedcom;

/**
* The results we will return
*/
private final List<AResult> result = new ArrayList<>();

/**
* {@inheritDoc}
*/
@Override
public List<AResult> analyze(Gedcom g) {
gedcom = g;
List<AResult> result = new ArrayList<>();

checkIndividualEvents();
checkFamilyEvents();
checkIndividualEvents(g, result);
checkFamilyEvents(g, result);

Collections.sort(result, new MixedResultSortComparator());
return result;
Expand Down Expand Up @@ -114,8 +104,13 @@ public AnalysisTag[] getTags() {

/**
* Check the family events
*
* @param gedcom
* the gedcom
* @param result
* the results
*/
private void checkFamilyEvents() {
private void checkFamilyEvents(Gedcom gedcom, List<AResult> result) {
DateParser dp = new DateParser();
for (Family i : gedcom.getFamilies().values()) {
Map<FamilyEventType, List<AbstractEvent>> indEventsByType = new TreeMap<>();
Expand Down Expand Up @@ -171,8 +166,13 @@ private void checkFamilyEvents() {

/**
* Check individual events for conflicts
*
* @param gedcom
* the gedcom
* @param result
* the results
*/
private void checkIndividualEvents() {
private void checkIndividualEvents(Gedcom gedcom, List<AResult> result) {
DateParser dp = new DateParser();
for (Individual i : gedcom.getIndividuals().values()) {
Map<IndividualEventType, List<AbstractEvent>> indEventsByType = new TreeMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,14 @@ public class FutureBirthDeathDatesAnalyzer extends AAnalyzer {
/**
* Date parser
*/
private final DateParser dp = new DateParser();

/**
* Right now
*/
private final Date now = new Date();
private static final DateParser DP = new DateParser();

/**
* {@inheritDoc}
*/
@Override
public List<AResult> analyze(Gedcom g) {
Date now = new Date();

List<AResult> result = new ArrayList<>();

Expand All @@ -73,7 +69,7 @@ public List<AResult> analyze(Gedcom g) {
for (IndividualEvent b : births) {
if (b.getDate() != null && b.getDate().getValue() != null && !b.getDate().getValue().isEmpty()) {
String dateString = b.getDate().getValue();
Date bd = dp.parse(dateString);
Date bd = DP.parse(dateString);
if (bd != null && now.before(bd)) {
result.add(new IndividualRelatedResult(i, IndividualEventType.BIRTH.getDisplay(), dateString, null));
}
Expand All @@ -83,7 +79,7 @@ public List<AResult> analyze(Gedcom g) {
for (IndividualEvent d : deaths) {
if (d.getDate() != null && d.getDate().getValue() != null && !d.getDate().getValue().isEmpty()) {
String dateString = d.getDate().getValue();
Date dd = dp.parse(dateString);
Date dd = DP.parse(dateString);
if (dd != null && now.before(dd)) {
result.add(new IndividualRelatedResult(i, IndividualEventType.DEATH.getDisplay(), dateString, null));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public class MarriedAtYoungAgeAnalyzer extends AAnalyzer {
/**
* Date parser
*/
DateParser dp = new DateParser();
private static final DateParser DP = new DateParser();

@Override
public List<AResult> analyze(Gedcom g) {
Expand All @@ -81,7 +81,7 @@ public List<AResult> analyze(Gedcom g) {
for (FamilyEvent e : f.getEvents()) {
if (e.getType() == FamilyEventType.MARRIAGE) {
if (e.getDate() != null && e.getDate().getValue() != null) {
Date d = dp.parse(e.getDate().getValue());
Date d = DP.parse(e.getDate().getValue());
if (d != null && d.before(earliestMarriageDate)) {
earliestMarriage = e;
earliestMarriageDate = d;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public class PeopleWhoLivedPast100Analyzer extends AAnalyzer {
/**
* Date parser
*/
private final DateParser dateParser = new DateParser();
private static final DateParser DP = new DateParser();

/**
* {@inheritDoc}
Expand All @@ -78,7 +78,7 @@ public List<AResult> analyze(Gedcom g) {
String earliestBirthDateString = null;
for (IndividualEvent b : births) {
if (b.getDate() != null && b.getDate().getValue() != null) {
Date bd = dateParser.parse(b.getDate().getValue(), ImpreciseDatePreference.FAVOR_EARLIEST);
Date bd = DP.parse(b.getDate().getValue(), ImpreciseDatePreference.FAVOR_EARLIEST);
if (bd != null && (earliestBirthDate == null || bd.before(earliestBirthDate))) {
earliestBirthDate = bd;
earliestBirthDateString = b.getDate().getValue();
Expand All @@ -93,7 +93,7 @@ public List<AResult> analyze(Gedcom g) {
String latestDeathDateString = null;
for (IndividualEvent d : deaths) {
if (d.getDate() != null && d.getDate().getValue() != null) {
Date dd = dateParser.parse(d.getDate().getValue(), ImpreciseDatePreference.FAVOR_LATEST);
Date dd = DP.parse(d.getDate().getValue(), ImpreciseDatePreference.FAVOR_LATEST);
if (dd != null && (latestDeathDate == null || dd.after(latestDeathDate))) {
latestDeathDate = dd;
latestDeathDateString = d.getDate().getValue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public class PeopleWithoutDeathEventsAnalyzer extends AAnalyzer {
/**
* Date parser
*/
private final DateParser dateParser = new DateParser();
private static final DateParser DP = new DateParser();

/**
* {@inheritDoc}
Expand Down Expand Up @@ -82,7 +82,7 @@ public List<AResult> analyze(Gedcom g) {
String earliestBirthDateString = null;
for (IndividualEvent b : births) {
if (b.getDate() != null && b.getDate().getValue() != null) {
Date bd = dateParser.parse(b.getDate().getValue(), ImpreciseDatePreference.FAVOR_EARLIEST);
Date bd = DP.parse(b.getDate().getValue(), ImpreciseDatePreference.FAVOR_EARLIEST);
if (bd != null && (earliestBirthDate == null || bd.before(earliestBirthDate))) {
earliestBirthDate = bd;
earliestBirthDateString = b.getDate().getValue();
Expand Down
65 changes: 65 additions & 0 deletions src/main/java/org/gedantic/web/MyHttpSessionListener.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* Copyright (c) 2016 Matthew R. Harrah
*
* MIT License
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
package org.gedantic.web;

import javax.servlet.annotation.WebListener;
import javax.servlet.http.HttpSessionEvent;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@WebListener
public class MyHttpSessionListener implements javax.servlet.http.HttpSessionListener {

/** Logger */
private static final Logger LOG = LoggerFactory.getLogger(MyHttpSessionListener.class.getName());

private int sessionCount = 0;

@Override
public void sessionCreated(HttpSessionEvent arg0) {

Runtime rt = Runtime.getRuntime();
long maxMemory = rt.maxMemory();
long freeMemory = rt.freeMemory();
sessionCount++;
LOG.info("sessionCreate - freeMemory:" + Double.toString(freeMemory / (1024 * 1024)) + " maxMemory:" + Double.toString(
maxMemory / (1024 * 1024)) + " count: " + sessionCount);
}

@Override
public void sessionDestroyed(HttpSessionEvent arg0) {

Runtime rt = Runtime.getRuntime();
long maxMemory = rt.maxMemory();
long freeMemory = rt.freeMemory();
sessionCount--;
LOG.info("sessionDestroy - freeMemory:" + Double.toString(freeMemory / (1024 * 1024)) + " maxMemory:" + Double.toString(
maxMemory / (1024 * 1024)) + " count: " + sessionCount);
}

}
12 changes: 12 additions & 0 deletions src/main/java/org/gedantic/web/servlet/AnalyzerServlet.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,20 @@ private void process(HttpServletRequest req, HttpServletResponse resp) throws Se
return;

}

Runtime rt = Runtime.getRuntime();
long maxMemory = rt.maxMemory();
long freeMemory = rt.freeMemory();
LOG.info("before analysis " + a.getId() + " - freeMemory:" + Double.toString(freeMemory / (1024 * 1024)) + " maxMemory:"
+ Double.toString(maxMemory / (1024 * 1024)));

List<? extends AResult> results = a.analyze(g);

maxMemory = rt.maxMemory();
freeMemory = rt.freeMemory();
LOG.info("after analysis " + a.getId() + " - freeMemory:" + Double.toString(freeMemory / (1024 * 1024)) + " maxMemory:"
+ Double.toString(maxMemory / (1024 * 1024)));

if ("true".equals(req.getParameter("excel"))) {
@SuppressWarnings("resource")
Workbook wb = new WorkbookCreator(a, results).create();
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/org/gedantic/web/servlet/FileUploadHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,13 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
response.setStatus(403);
}
}

Runtime rt = Runtime.getRuntime();
long maxMemory = rt.maxMemory();
long freeMemory = rt.freeMemory();
LOG.info("fileUploaded - freeMemory:" + Double.toString(freeMemory / (1024 * 1024)) + " maxMemory:" + Double.toString(
maxMemory / (1024 * 1024)));

LOG.debug("<doPost");
}
}
3 changes: 3 additions & 0 deletions src/webapp/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Manifest-Version: 1.0
Class-Path:

0 comments on commit e2660d0

Please sign in to comment.