Skip to content

Commit

Permalink
Internal changes to configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
psidnell committed Dec 14, 2014
1 parent 64c711b commit 9fa66c5
Show file tree
Hide file tree
Showing 30 changed files with 694 additions and 426 deletions.
1 change: 1 addition & 0 deletions RELEASE-NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
**[Development Version](https://github.com/psidnell/ofexport2/archive/master.zip)**

- Fixed a date range bug.
- Made expression date format configurable.

**[1.0.13 (2014-12-13)](https://github.com/psidnell/ofexport2/archive/ofexport-v2-1.0.13.zip)**

Expand Down
2 changes: 2 additions & 0 deletions config/config.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
# The default value when filtering for dueSoon Tasks/Projects
dueSoon:7d

expressionDateFormat:yyyy-MM-dd

# Name of the root node when flattening hierarchies
flattenedRootName:Tasks

Expand Down
26 changes: 6 additions & 20 deletions config/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,12 @@
<value>${HOME}/Library/Caches/com.omnigroup.OmniFocus.MacAppStore/OmniFocusDatabase2</value>
</list>
</property>
<property name="nodeFactory" ref="nodefactory"/>
</bean>

<bean name="ofexport" class="org.psidnell.omnifocus.OFExport" />
<bean name="ofexport" class="org.psidnell.omnifocus.OFExport" init-method="init">
<property name="nodeFactory" ref="nodefactory"/>
</bean>

<bean name="main" class="org.psidnell.omnifocus.Main">
<property name="ofexport" ref="ofexport" />
Expand All @@ -34,27 +37,10 @@
<!-- Copy values we need from property file into the bean -->
<property name="dueSoon" value="${dueSoon}"/>
<property name="flattenedRootName" value="${flattenedRootName}"/>
<property name="expressionDateFormat" value="${expressionDateFormat}"/>
</bean>

<!-- Node Types -->

<bean name="folder" class="org.psidnell.omnifocus.model.Folder" scope="prototype">
<property name="configParams" ref="configparams"/>
</bean>

<bean name="project" class="org.psidnell.omnifocus.model.Project" scope="prototype">
<property name="configParams" ref="configparams"/>
</bean>

<bean name="projectinfo" class="org.psidnell.omnifocus.model.ProjectInfo" scope="prototype">
<property name="configParams" ref="configparams"/>
</bean>

<bean name="task" class="org.psidnell.omnifocus.model.Task" scope="prototype">
<property name="configParams" ref="configparams"/>
</bean>

<bean name="context" class="org.psidnell.omnifocus.model.Context" scope="prototype">
<bean name="nodefactory" class="org.psidnell.omnifocus.model.NodeFactory">
<property name="configParams" ref="configparams"/>
</bean>

Expand Down
5 changes: 4 additions & 1 deletion src/main/java/org/psidnell/omnifocus/CommandLine.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.psidnell.omnifocus.expr.ExprAttributePrinter;
import org.psidnell.omnifocus.model.Context;
import org.psidnell.omnifocus.model.Folder;
import org.psidnell.omnifocus.model.NodeFactory;
import org.psidnell.omnifocus.model.Project;
import org.psidnell.omnifocus.model.Task;
import org.psidnell.omnifocus.visitor.SimplifyFilter;
Expand Down Expand Up @@ -64,6 +65,7 @@ public class CommandLine implements BeanFactoryAware {
protected boolean open = false;
private ConfigParams config; // NOPMD it can't see into lambdas
protected String exportFile;
private NodeFactory nodeFactory; // NOPMD it can't see into lambdas

static {

Expand Down Expand Up @@ -231,7 +233,7 @@ public class CommandLine implements BeanFactoryAware {

OPTIONS.addOption(new ActiveOption<CommandLine>(
"F", false, "Flatten hierarchies.",
(m,o)->m.ofexport.addFilter (new FlattenFilter(m.config)),
(m,o)->m.ofexport.addFilter (new FlattenFilter(m.nodeFactory, m.config)),
AFTER_LOAD));

OPTIONS.addOption(new ActiveOption<CommandLine> (
Expand Down Expand Up @@ -333,5 +335,6 @@ public void setProcessor (ActiveOptionProcessor<CommandLine> processor) {
public void setBeanFactory(BeanFactory beanFactory) {
this.beanFactory = beanFactory;
config = beanFactory.getBean("configparams", ConfigParams.class);
nodeFactory = beanFactory.getBean("nodefactory", NodeFactory.class);
}
}
9 changes: 9 additions & 0 deletions src/main/java/org/psidnell/omnifocus/ConfigParams.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public class ConfigParams {

private String dueSoon;
private String flattenedRootName;
private String expressionDateFormat;

public void setDueSoon(String dueSoon) {
this.dueSoon = dueSoon;
Expand All @@ -41,4 +42,12 @@ public void setFlattenedRootName(String name) {
public String getFlattenedRootName() {
return flattenedRootName;
}

public void setExpressionDateFormat(String format) {
this.expressionDateFormat = format;
}

public String getExpressionDateFormat() {
return expressionDateFormat;
}
}
17 changes: 13 additions & 4 deletions src/main/java/org/psidnell/omnifocus/OFExport.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.psidnell.omnifocus.format.FreeMarkerFormatter;
import org.psidnell.omnifocus.model.Context;
import org.psidnell.omnifocus.model.Folder;
import org.psidnell.omnifocus.model.NodeFactory;
import org.psidnell.omnifocus.model.Project;
import org.psidnell.omnifocus.model.Task;
import org.psidnell.omnifocus.visitor.ClearMarkedVisitor;
Expand Down Expand Up @@ -68,13 +69,17 @@ public class OFExport {
private Folder projectRoot;
private Context contextRoot;

private NodeFactory nodeFactory;

public OFExport() {
projectRoot = new Folder();
projectRoot.setName("RootFolder");

}

public void init() {
projectRoot = nodeFactory.createFolder("RootFolder");
projectRoot.setId("__%%RootFolder"); // to give deterministic JSON/XML output

contextRoot = new Context();
contextRoot.setName("RootContext");
contextRoot = nodeFactory.createContext("RootContext");
contextRoot.setId("__%%RootContext"); // to give deterministic JSON/XML output
}

Expand Down Expand Up @@ -235,4 +240,8 @@ public void addTaskComparator(String expr) {
public void addContextComparator(String expr) {
sortingFilter.addContextComparator(new ExpressionComparator<>(expr, Context.class));
}

public void setNodeFactory(NodeFactory nodeFactory) {
this.nodeFactory = nodeFactory;
}
}
3 changes: 1 addition & 2 deletions src/main/java/org/psidnell/omnifocus/expr/Date.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,11 @@ public class Date extends ExpressionFunctions implements Comparable<Date> {

private java.util.Date date;
private java.util.Date roundedDate;
private ConfigParams config;

public Date(java.util.Date date, ConfigParams config) {
this.date = date;
this.roundedDate = roundToDay(date);
this.config = config;
setConfigParams(config);
}

public boolean isSet() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.util.Date;
import java.util.GregorianCalendar;

import org.psidnell.omnifocus.ConfigParams;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -39,10 +40,12 @@ public class ExpressionFunctions {

private static final int DAYS_IN_WEEK = 7;

public static final SimpleDateFormat YYYYMMDD = new SimpleDateFormat("yyyy-MM-dd");
private SimpleDateFormat dateFormat;

protected static final long DAY = 1000 * 60 * 60 * 24;

protected ConfigParams config;

public Date date(String dateStr) throws ParseException {
Calendar today = new GregorianCalendar();
return date(dateStr, today);
Expand Down Expand Up @@ -76,7 +79,7 @@ public Date date(String dateStr, Calendar today) throws ParseException {
}

if (result == null) {
result = roundToDay(YYYYMMDD.parse(dateStr));
result = roundToDay(dateFormat.parse(dateStr));
}

LOGGER.debug("date({}) = {}", dateStr, result);
Expand Down Expand Up @@ -289,4 +292,8 @@ public static Date roundToDay(Date d) {
return d == null ? null : new Date(DAY * (d.getTime() / DAY));
}

public void setConfigParams(ConfigParams config) {
this.config = config;
dateFormat = new SimpleDateFormat(config.getExpressionDateFormat());
}
}
3 changes: 2 additions & 1 deletion src/main/java/org/psidnell/omnifocus/model/Context.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,11 @@ public class Context extends NodeImpl implements ContextHierarchyNode{

private boolean allowsNextAction = true;

@Deprecated // Should use NodeFactory
public Context() {
}

@Deprecated // Should use NodeFactory
public Context(String name) {
this.name = name;
}
Expand Down Expand Up @@ -190,7 +192,6 @@ public void add(Context child) {

contexts.add(child);
child.setContextModeParent(this);

}

public void add(Task child) {
Expand Down
42 changes: 18 additions & 24 deletions src/main/java/org/psidnell/omnifocus/model/DataCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,10 @@
import java.util.function.Predicate;
import java.util.stream.Collectors;

import org.psidnell.omnifocus.ConfigParams;
import org.psidnell.omnifocus.sqlite.SQLiteDAO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;

import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import com.fasterxml.jackson.core.JsonGenerationException;
Expand All @@ -56,7 +53,7 @@
*
*/
@JsonPropertyOrder(alphabetic=true)
public class DataCache implements BeanFactoryAware {
public class DataCache {

private static final Logger LOGGER = LoggerFactory.getLogger(DataCache.class);

Expand All @@ -66,7 +63,7 @@ public class DataCache implements BeanFactoryAware {
private HashMap<String, Context> contexts = new HashMap<>();
private HashMap<String, Project> projects = new HashMap<>();

private BeanFactory beanFactory;
private NodeFactory nodeFactory;

public DataCache() {
// Jackson constructor
Expand All @@ -78,11 +75,12 @@ public DataCache(BeanFactory beanFactory) {
// Testing constructor
this.folders = new HashMap<>();
this.projInfos = new HashMap<>();
this.beanFactory = beanFactory;
this.nodeFactory = beanFactory.getBean("nodefactory", NodeFactory.class);
}

public DataCache(Collection<Folder> folders, Collection<ProjectInfo> projInfos, Collection<Task> tasks, Collection<Context> contexts, BeanFactory beanFactory) {
this. beanFactory = beanFactory;
// SQLiteDAO constructor
this.nodeFactory = beanFactory.getBean("nodefactory", NodeFactory.class);
folders.stream().forEach((n) -> add(n));
projInfos.stream().forEach((n) -> add(n));
tasks.stream().forEach((n) -> add(n));
Expand All @@ -92,16 +90,13 @@ public DataCache(Collection<Folder> folders, Collection<ProjectInfo> projInfos,
public final void build() {
LOGGER.info("Starting tree reconstruction");

Project inbox = beanFactory.getBean("project", Project.class);
inbox.setName("Inbox");
Project inbox = nodeFactory.createProject("Inbox");
inbox.setId("__%%Inbox"); // to give deterministic JSON/XML output

Context noContext = beanFactory.getBean("context", Context.class);
Context noContext = nodeFactory.createContext("Inbox");
noContext.setName("No Context");
noContext.setId("__%%NoContext"); // to give deterministic JSON/XML output

ConfigParams configParams = beanFactory.getBean("configparams", ConfigParams.class);

// Build Folder Hierarchy
for (Folder folder : folders.values()) {
String parentId = folder.getParentFolderId();
Expand Down Expand Up @@ -152,8 +147,7 @@ public final void build() {
// since a copy of the root tasks subtasks is taken
for (ProjectInfo projInfo : projInfos.values()) {
Task rootTask = tasks.get(projInfo.getRootTaskId());
Project project = new Project(projInfo, rootTask);
project.setConfigParams(configParams);
Project project = nodeFactory.createProject(projInfo, rootTask);

// Set containing Folder for project
String folderId = projInfo.getFolderId();
Expand Down Expand Up @@ -230,14 +224,14 @@ public static DataCache importData(File file, BeanFactory beanFactory) throws Fi
Reader in = new FileReader(file)) {
ObjectMapper mapper = new ObjectMapper();
DataCache result = mapper.readValue(in, DataCache.class);
NodeFactory nodeFactory = beanFactory.getBean("nodefactory", NodeFactory.class);
result.setNodeFactory(nodeFactory);

// Nodes didn't come from spring, must wire them manually
ConfigParams config = beanFactory.getBean("configparams", ConfigParams.class);
result.contexts.values().forEach((n)->n.setConfigParams(config));
result.folders.values().forEach((n)->n.setConfigParams(config));
result.projects.values().forEach((n)->n.setConfigParams(config));
result.tasks.values().forEach((n)->n.setConfigParams(config));
result.projInfos.values().forEach((n)->n.setConfigParams(config));
result.setBeanFactory (beanFactory);
result.contexts.values().forEach((n)->nodeFactory.initialise(n));
result.folders.values().forEach((n)->nodeFactory.initialise(n));
result.projects.values().forEach((n)->nodeFactory.initialise(n));
result.tasks.values().forEach((n)->nodeFactory.initialise(n));
return result;
}
}
Expand Down Expand Up @@ -281,8 +275,8 @@ public static void exportData(File file, Predicate<NodeImpl> filterFn, SQLiteDAO
}
}

@Override
public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
this.beanFactory = beanFactory;
private void setNodeFactory(NodeFactory nodeFactory) {
this.nodeFactory = nodeFactory;
}

}
2 changes: 2 additions & 0 deletions src/main/java/org/psidnell/omnifocus/model/Folder.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,11 @@ public class Folder extends NodeImpl implements ProjectHierarchyNode {

private boolean active = true;

@Deprecated // Should use NodeFactory
public Folder() {
}

@Deprecated // Should use NodeFactory
public Folder(String name) {
this.name = name;
}
Expand Down
Loading

0 comments on commit 9fa66c5

Please sign in to comment.