[overlord-commits] Overlord SVN: r1006 - in activity-monitor/trunk: gui/war/src/main/java/org/jboss/bpm/monitor/gui/client and 2 other directories.
overlord-commits at lists.jboss.org
overlord-commits at lists.jboss.org
Fri Mar 12 09:26:07 EST 2010
Author: heiko.braun at jboss.com
Date: 2010-03-12 09:26:06 -0500 (Fri, 12 Mar 2010)
New Revision: 1006
Added:
activity-monitor/trunk/gui/war/src/main/java/org/jboss/bpm/monitor/gui/client/ChartData.java
activity-monitor/trunk/gui/war/src/main/java/org/jboss/bpm/monitor/gui/client/HistoryRecords.java
activity-monitor/trunk/gui/war/src/main/java/org/jboss/bpm/monitor/gui/client/JSOModel.java
activity-monitor/trunk/gui/war/src/main/java/org/jboss/bpm/monitor/gui/server/ChartDataService.java
activity-monitor/trunk/gui/war/src/main/java/org/jboss/bpm/monitor/gui/server/HistoryRecordsService.java
Removed:
activity-monitor/trunk/gui/war/src/main/java/org/jboss/bpm/monitor/gui/client/BPAFDataAccess.java
activity-monitor/trunk/gui/war/src/main/java/org/jboss/bpm/monitor/gui/server/BPAFService.java
Modified:
activity-monitor/trunk/gui/war/pom.xml
activity-monitor/trunk/gui/war/src/main/java/org/jboss/bpm/monitor/gui/client/DebugPanel.java
activity-monitor/trunk/gui/war/src/main/java/org/jboss/bpm/monitor/gui/client/RecentActivityView.java
activity-monitor/trunk/model/src/main/java/org/jboss/bpm/monitor/model/metric/Timespan.java
Log:
First roundtrip chronoscope example
Modified: activity-monitor/trunk/gui/war/pom.xml
===================================================================
--- activity-monitor/trunk/gui/war/pom.xml 2010-03-12 13:06:43 UTC (rev 1005)
+++ activity-monitor/trunk/gui/war/pom.xml 2010-03-12 14:26:06 UTC (rev 1006)
@@ -27,7 +27,7 @@
<artifactId>activity-monitor-model</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
-
+
<!-- Errai -->
<dependency>
<groupId>org.jboss.errai</groupId>
Deleted: activity-monitor/trunk/gui/war/src/main/java/org/jboss/bpm/monitor/gui/client/BPAFDataAccess.java
===================================================================
--- activity-monitor/trunk/gui/war/src/main/java/org/jboss/bpm/monitor/gui/client/BPAFDataAccess.java 2010-03-12 13:06:43 UTC (rev 1005)
+++ activity-monitor/trunk/gui/war/src/main/java/org/jboss/bpm/monitor/gui/client/BPAFDataAccess.java 2010-03-12 14:26:06 UTC (rev 1006)
@@ -1,20 +0,0 @@
-/* jboss.org */
-package org.jboss.bpm.monitor.gui.client;
-
-import org.jboss.errai.bus.server.annotations.Remote;
-
-import java.util.List;
-
-/**
- * @author: Heiko Braun <hbraun at redhat.com>
- * @date: Mar 11, 2010
- */
- at Remote
-public interface BPAFDataAccess
-{
- List<String> getProcessDefinitionKeys();
-
- List<String> getProcessInstanceKeys(String definitionKey);
-
- List<String> getActivityKeys(String instanceKey);
-}
Added: activity-monitor/trunk/gui/war/src/main/java/org/jboss/bpm/monitor/gui/client/ChartData.java
===================================================================
--- activity-monitor/trunk/gui/war/src/main/java/org/jboss/bpm/monitor/gui/client/ChartData.java (rev 0)
+++ activity-monitor/trunk/gui/war/src/main/java/org/jboss/bpm/monitor/gui/client/ChartData.java 2010-03-12 14:26:06 UTC (rev 1006)
@@ -0,0 +1,15 @@
+/* jboss.org */
+package org.jboss.bpm.monitor.gui.client;
+
+import org.jboss.bpm.monitor.model.metric.Timespan;
+import org.jboss.errai.bus.server.annotations.Remote;
+
+/**
+ * @author: Heiko Braun <hbraun at redhat.com>
+ * @date: Mar 12, 2010
+ */
+ at Remote
+public interface ChartData
+{
+ String getDefinitionActivity(String processDefiniton, String timespanValue);
+}
Modified: activity-monitor/trunk/gui/war/src/main/java/org/jboss/bpm/monitor/gui/client/DebugPanel.java
===================================================================
--- activity-monitor/trunk/gui/war/src/main/java/org/jboss/bpm/monitor/gui/client/DebugPanel.java 2010-03-12 13:06:43 UTC (rev 1005)
+++ activity-monitor/trunk/gui/war/src/main/java/org/jboss/bpm/monitor/gui/client/DebugPanel.java 2010-03-12 14:26:06 UTC (rev 1006)
@@ -153,7 +153,7 @@
model.clear();
- BPAFDataAccess rpcService = MessageBuilder.createCall(
+ HistoryRecords rpcService = MessageBuilder.createCall(
new RemoteCallback<List<String>>()
{
@@ -165,7 +165,7 @@
processDefinitions.layout();
}
},
- BPAFDataAccess.class
+ HistoryRecords.class
);
rpcService.getProcessDefinitionKeys();
@@ -179,7 +179,7 @@
model.clear();
- BPAFDataAccess rpcService = MessageBuilder.createCall(
+ HistoryRecords rpcService = MessageBuilder.createCall(
new RemoteCallback<List<String>>()
{
@@ -191,7 +191,7 @@
processInstances.layout();
}
},
- BPAFDataAccess.class
+ HistoryRecords.class
);
rpcService.getProcessInstanceKeys(
@@ -211,7 +211,7 @@
model.clear();
- BPAFDataAccess rpcService = MessageBuilder.createCall(
+ HistoryRecords rpcService = MessageBuilder.createCall(
new RemoteCallback<List<String>>()
{
@@ -223,7 +223,7 @@
activities.layout();
}
},
- BPAFDataAccess.class
+ HistoryRecords.class
);
rpcService.getActivityKeys(
Copied: activity-monitor/trunk/gui/war/src/main/java/org/jboss/bpm/monitor/gui/client/HistoryRecords.java (from rev 1002, activity-monitor/trunk/gui/war/src/main/java/org/jboss/bpm/monitor/gui/client/BPAFDataAccess.java)
===================================================================
--- activity-monitor/trunk/gui/war/src/main/java/org/jboss/bpm/monitor/gui/client/HistoryRecords.java (rev 0)
+++ activity-monitor/trunk/gui/war/src/main/java/org/jboss/bpm/monitor/gui/client/HistoryRecords.java 2010-03-12 14:26:06 UTC (rev 1006)
@@ -0,0 +1,20 @@
+/* jboss.org */
+package org.jboss.bpm.monitor.gui.client;
+
+import org.jboss.errai.bus.server.annotations.Remote;
+
+import java.util.List;
+
+/**
+ * @author: Heiko Braun <hbraun at redhat.com>
+ * @date: Mar 11, 2010
+ */
+ at Remote
+public interface HistoryRecords
+{
+ List<String> getProcessDefinitionKeys();
+
+ List<String> getProcessInstanceKeys(String definitionKey);
+
+ List<String> getActivityKeys(String instanceKey);
+}
Added: activity-monitor/trunk/gui/war/src/main/java/org/jboss/bpm/monitor/gui/client/JSOModel.java
===================================================================
--- activity-monitor/trunk/gui/war/src/main/java/org/jboss/bpm/monitor/gui/client/JSOModel.java (rev 0)
+++ activity-monitor/trunk/gui/war/src/main/java/org/jboss/bpm/monitor/gui/client/JSOModel.java 2010-03-12 14:26:06 UTC (rev 1006)
@@ -0,0 +1,20 @@
+/* jboss.org */
+package org.jboss.bpm.monitor.gui.client;
+
+import com.google.gwt.core.client.JavaScriptObject;
+
+/**
+ * @author: Heiko Braun <hbraun at redhat.com>
+ * @date: Mar 12, 2010
+ */
+public class JSOModel extends JavaScriptObject
+{
+ protected JSOModel()
+ {
+ }
+
+ public static native JSOModel fromJson(String jsonString) /*-{
+ return eval('(' + jsonString + ')');
+ }-*/;
+
+}
Modified: activity-monitor/trunk/gui/war/src/main/java/org/jboss/bpm/monitor/gui/client/RecentActivityView.java
===================================================================
--- activity-monitor/trunk/gui/war/src/main/java/org/jboss/bpm/monitor/gui/client/RecentActivityView.java 2010-03-12 13:06:43 UTC (rev 1005)
+++ activity-monitor/trunk/gui/war/src/main/java/org/jboss/bpm/monitor/gui/client/RecentActivityView.java 2010-03-12 14:26:06 UTC (rev 1006)
@@ -3,19 +3,19 @@
import com.google.gwt.core.client.GWT;
import org.gwt.mosaic.ui.client.layout.LayoutPanel;
+import org.jboss.errai.bus.client.api.RemoteCallback;
+import org.jboss.errai.bus.client.api.base.MessageBuilder;
import org.jboss.errai.workspaces.client.api.ProvisioningCallback;
import org.jboss.errai.workspaces.client.api.WidgetProvider;
import org.jboss.errai.workspaces.client.api.annotations.LoadTool;
-import org.timepedia.chronoscope.client.*;
+import org.timepedia.chronoscope.client.ChronoscopeOptions;
+import org.timepedia.chronoscope.client.Dataset;
+import org.timepedia.chronoscope.client.Datasets;
import org.timepedia.chronoscope.client.browser.ChartPanel;
import org.timepedia.chronoscope.client.browser.Chronoscope;
import org.timepedia.chronoscope.client.browser.json.GwtJsonDataset;
import org.timepedia.chronoscope.client.browser.json.JsonDatasetJSO;
-import org.timepedia.chronoscope.client.canvas.View;
-import org.timepedia.chronoscope.client.canvas.ViewReadyCallback;
import org.timepedia.chronoscope.client.data.tuple.Tuple2D;
-import org.timepedia.chronoscope.client.overlays.Marker;
-import org.timepedia.chronoscope.client.overlays.OverlayClickListener;
/**
* @author: Heiko Braun <hbraun at redhat.com>
@@ -35,64 +35,55 @@
{
panel = new LayoutPanel();
+ ChartData rpcService = MessageBuilder.createCall(
+ new RemoteCallback<String>()
+ {
+ public void callback(String response)
+ {
+ renderChart(response);
+ }
+ },
+ ChartData.class
+ );
- try {
- // You must specify the chart dimensions for now, rather than have the chart
- // grow to fill its container
- int chartWidth = 450;
- int chartHeight = (int) (chartWidth / GOLDEN__RATIO);
+ rpcService.getDefinitionActivity("OrderCheckoutProcess", "Last 7 Days");
- // Chronoscope.enableHistorySupport(true);
- Chronoscope.setFontBookRendering(true);
- ChronoscopeOptions.setErrorReporting(true);
- Chronoscope.setMicroformatsEnabled(false);
- Chronoscope.setShowCredits(false);
- Chronoscope.initialize();
+ callback.onSuccess(panel);
+ }
- Chronoscope chronoscope = Chronoscope.getInstance();
+ private void renderChart(String jsonData)
+ {
+ // Chronoscope.enableHistorySupport(true);
+ Chronoscope.setFontBookRendering(true);
+ ChronoscopeOptions.setErrorReporting(true);
+ Chronoscope.setMicroformatsEnabled(false);
+ Chronoscope.setShowCredits(false);
+ Chronoscope.initialize();
+ Chronoscope chronoscope = Chronoscope.getInstance();
+
+ try
+ {
+ int chartWidth = 450;
+ int chartHeight = (int) (chartWidth / GOLDEN__RATIO);
+
final Datasets<Tuple2D> datasets = new Datasets<Tuple2D>();
datasets.add(chronoscope.getDatasetReader().createDatasetFromJson(
- new GwtJsonDataset(getJson("dataset")))
+ new GwtJsonDataset(JSOModel.fromJson(jsonData)))
);
-
-// MockDatasetFactory datasetFactory = new MockDatasetFactory();
-// Dataset mockDataset = datasetFactory.getBasicDataset();
-// datasets.add(mockDataset);
-
Dataset[] dsArray = datasets.toArray();
final ChartPanel chartPanel = Chronoscope
.createTimeseriesChart(dsArray, chartWidth, chartHeight);
-
- chartPanel.setReadyListener(new ViewReadyCallback() {
- public void onViewReady(final View view) {
- /*Dataset dataset = datasets.get(0);
- final Marker m = new Marker(
- dataset.getDomainExtrema().midpoint(), "A", 0);
- m.addOverlayClickListener(new OverlayClickListener() {
- public void onOverlayClick(Overlay overlay, int x, int y) {
- m.openInfoWindow("Hello");
- }
- });
- XYPlot plot = view.getChart().getPlot();
- //plot.setDatasetRenderer(1, new BarChartXYRenderer());
- plot.addOverlay(m);
- plot.redraw();*/
- }
- });
-
panel.add(chartPanel);
}
catch (Exception e)
{
- GWT.log("Failed to create chart", e);
+ GWT.log("Failed to create chart", e);
}
-
- callback.onSuccess(panel);
}
private static native JsonDatasetJSO getJson(String varName) /*-{
Deleted: activity-monitor/trunk/gui/war/src/main/java/org/jboss/bpm/monitor/gui/server/BPAFService.java
===================================================================
--- activity-monitor/trunk/gui/war/src/main/java/org/jboss/bpm/monitor/gui/server/BPAFService.java 2010-03-12 13:06:43 UTC (rev 1005)
+++ activity-monitor/trunk/gui/war/src/main/java/org/jboss/bpm/monitor/gui/server/BPAFService.java 2010-03-12 14:26:06 UTC (rev 1006)
@@ -1,58 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2006, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.bpm.monitor.gui.server;
-
-import org.jboss.bpm.monitor.gui.client.BPAFDataAccess;
-import org.jboss.bpm.monitor.model.BPAFDataSource;
-import org.jboss.bpm.monitor.model.DefaultBPAFDataSource;
-import org.jboss.errai.bus.client.api.Message;
-import org.jboss.errai.bus.client.api.MessageCallback;
-import org.jboss.errai.bus.server.annotations.Service;
-
-import java.util.ArrayList;
-import java.util.List;
-
- at Service
-public class BPAFService implements BPAFDataAccess
-{
- BPAFDataSource dataSource;
-
- public BPAFService()
- {
- this.dataSource = new DefaultBPAFDataSource();
- }
-
- public List<String> getProcessDefinitionKeys()
- {
- return dataSource.getProcessDefinitions();
- }
-
- public List<String> getProcessInstanceKeys(String definition)
- {
- return dataSource.getProcessInstances(definition);
- }
-
- public List<String> getActivityKeys(String instance)
- {
- return dataSource.getActivityDefinitions(instance);
- }
-}
Added: activity-monitor/trunk/gui/war/src/main/java/org/jboss/bpm/monitor/gui/server/ChartDataService.java
===================================================================
--- activity-monitor/trunk/gui/war/src/main/java/org/jboss/bpm/monitor/gui/server/ChartDataService.java (rev 0)
+++ activity-monitor/trunk/gui/war/src/main/java/org/jboss/bpm/monitor/gui/server/ChartDataService.java 2010-03-12 14:26:06 UTC (rev 1006)
@@ -0,0 +1,74 @@
+/* jboss.org */
+package org.jboss.bpm.monitor.gui.server;
+
+import org.jboss.bpm.monitor.gui.client.ChartData;
+import org.jboss.bpm.monitor.model.BPAFDataSource;
+import org.jboss.bpm.monitor.model.DefaultBPAFDataSource;
+import org.jboss.bpm.monitor.model.bpaf.Event;
+import org.jboss.bpm.monitor.model.json.XYDataSetJSO;
+import org.jboss.bpm.monitor.model.metric.Grouping;
+import org.jboss.bpm.monitor.model.metric.Timespan;
+import org.jboss.errai.bus.server.annotations.Service;
+
+import java.util.*;
+
+/**
+ * Turn history records into JSON data that can be consumed by the chart renderer.
+ * @author: Heiko Braun <hbraun at redhat.com>
+ * @date: Mar 12, 2010
+ */
+ at Service
+public class ChartDataService implements ChartData
+{
+
+ BPAFDataSource dataSource;
+
+ public ChartDataService()
+ {
+ this.dataSource = new DefaultBPAFDataSource();
+ }
+
+ /**
+ * Delegates to {@link org.jboss.bpm.monitor.model.BPAFDataSource#getDefinitionEvents(String, org.jboss.bpm.monitor.model.metric.Timespan)}
+ * @param processDefiniton a processDefinitionID
+ * @param timespanValue a timespan string identifier
+ * @return JSON data
+ */
+ public String getDefinitionActivity(String processDefiniton, String timespanValue)
+ {
+ final Timespan timespan = Timespan.fromValue(timespanValue);
+
+ List<Event> events = dataSource.getDefinitionEvents(processDefiniton, timespan);
+
+ SortedMap<Date, List<Event>> grouped;
+
+ switch (timespan.getUnit())
+ {
+ case DAY:
+ grouped = Grouping.byDay(events, timespan);
+ break;
+ default:
+ throw new IllegalArgumentException("UNIT not supported: "+timespan.getUnit());
+
+ }
+
+ XYDataSetJSO dataSet = new XYDataSetJSO(
+ "Process Instances "+timespan.getTitle(),
+ UUID.randomUUID().toString()
+ );
+
+ List<Long> domainData = new ArrayList<Long>(grouped.size());
+ List<Long> rangeData = new ArrayList<Long>(grouped.size());
+ for(Date d : grouped.keySet())
+ {
+ domainData.add(d.getTime());
+ rangeData.add(new Integer(grouped.get(d).size()).longValue());
+ }
+
+ dataSet.getDomain().add(domainData);
+ dataSet.getRange().add(rangeData);
+ dataSet.setAxis("date");
+
+ return dataSet.toJSO();
+ }
+}
Copied: activity-monitor/trunk/gui/war/src/main/java/org/jboss/bpm/monitor/gui/server/HistoryRecordsService.java (from rev 1002, activity-monitor/trunk/gui/war/src/main/java/org/jboss/bpm/monitor/gui/server/BPAFService.java)
===================================================================
--- activity-monitor/trunk/gui/war/src/main/java/org/jboss/bpm/monitor/gui/server/HistoryRecordsService.java (rev 0)
+++ activity-monitor/trunk/gui/war/src/main/java/org/jboss/bpm/monitor/gui/server/HistoryRecordsService.java 2010-03-12 14:26:06 UTC (rev 1006)
@@ -0,0 +1,55 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.bpm.monitor.gui.server;
+
+import org.jboss.bpm.monitor.gui.client.HistoryRecords;
+import org.jboss.bpm.monitor.model.BPAFDataSource;
+import org.jboss.bpm.monitor.model.DefaultBPAFDataSource;
+import org.jboss.errai.bus.server.annotations.Service;
+
+import java.util.List;
+
+ at Service
+public class HistoryRecordsService implements HistoryRecords
+{
+ BPAFDataSource dataSource;
+
+ public HistoryRecordsService()
+ {
+ this.dataSource = new DefaultBPAFDataSource();
+ }
+
+ public List<String> getProcessDefinitionKeys()
+ {
+ return dataSource.getProcessDefinitions();
+ }
+
+ public List<String> getProcessInstanceKeys(String definition)
+ {
+ return dataSource.getProcessInstances(definition);
+ }
+
+ public List<String> getActivityKeys(String instance)
+ {
+ return dataSource.getActivityDefinitions(instance);
+ }
+}
Modified: activity-monitor/trunk/model/src/main/java/org/jboss/bpm/monitor/model/metric/Timespan.java
===================================================================
--- activity-monitor/trunk/model/src/main/java/org/jboss/bpm/monitor/model/metric/Timespan.java 2010-03-12 13:06:43 UTC (rev 1005)
+++ activity-monitor/trunk/model/src/main/java/org/jboss/bpm/monitor/model/metric/Timespan.java 2010-03-12 14:26:06 UTC (rev 1006)
@@ -15,16 +15,30 @@
{
private long start;
private long end;
+
+ public static final String LAST_24_HOURS = "Last 24 Hours";
+ public static final String LAST_DAY = "Last Day";
+ public static final String LAST_7_DAYS = "Last 7 Days";
+ public static final String LAST_WEEK = "Last Week";
+ public static final String LAST_4_WEEKS = "Last 4 Weeks";
+ public static final String LAST_MONTH = "Last Month";
+ public static final String LAST_3_MONTH = "Last 3 Month";
+ public static final String LAST_QUARTER = "Last Quarter";
+ public static final String LAST_12_MONTH = "Last 12 Month";
+ public static final String LAST_YEAR = "Last Year";
public enum UNIT {HOUR, DAY, WEEK, MONTH, YEAR }
private UNIT unit;
+
+ private String title;
- public Timespan(long start, long end, UNIT unit)
+ public Timespan(long start, long end, UNIT unit, String title)
{
this.start = start;
this.end = end;
this.unit = unit;
+ this.title = title;
}
public long getStart()
@@ -42,6 +56,11 @@
return unit;
}
+ public String getTitle()
+ {
+ return title;
+ }
+
public String toString()
{
return "Timespan{ "+new Date(start)+" - "+new Date(end)+" }";
@@ -57,7 +76,7 @@
cal.roll(Calendar.DAY_OF_YEAR, -1);
long t0 = cal.getTimeInMillis();
- return new Timespan(t0, t1, UNIT.HOUR);
+ return new Timespan(t0, t1, UNIT.HOUR, LAST_24_HOURS);
}
public static Timespan lastDay()
@@ -75,7 +94,7 @@
cal.set(Calendar.SECOND, 0);
long t0 = cal.getTimeInMillis();
- return new Timespan(t0, t1, UNIT.HOUR);
+ return new Timespan(t0, t1, UNIT.HOUR, LAST_DAY);
}
public static Timespan last7Days()
@@ -86,7 +105,7 @@
cal.roll(Calendar.DAY_OF_YEAR, -7);
long t0 = cal.getTimeInMillis();
- return new Timespan(t0, t1, UNIT.DAY);
+ return new Timespan(t0, t1, UNIT.DAY, LAST_7_DAYS);
}
public static Timespan lastWeek()
@@ -107,7 +126,7 @@
cal.set(Calendar.SECOND, 0);
long t0 = cal.getTimeInMillis();
- return new Timespan(t0, t1, UNIT.DAY);
+ return new Timespan(t0, t1, UNIT.DAY, LAST_WEEK);
}
public static Timespan last4Weeks()
@@ -118,7 +137,7 @@
cal.roll(Calendar.WEEK_OF_YEAR, -4);
long t0 = cal.getTimeInMillis();
- return new Timespan(t0, t1, UNIT.DAY);
+ return new Timespan(t0, t1, UNIT.DAY, LAST_4_WEEKS);
}
public static Timespan lastMonth()
@@ -139,7 +158,7 @@
cal.set(Calendar.SECOND, 0);
long t0 = cal.getTimeInMillis();
- return new Timespan(t0, t1, UNIT.DAY);
+ return new Timespan(t0, t1, UNIT.DAY, LAST_MONTH);
}
@@ -151,7 +170,7 @@
cal.roll(Calendar.MONTH, -3);
long t0 = cal.getTimeInMillis();
- return new Timespan(t0, t1, UNIT.WEEK);
+ return new Timespan(t0, t1, UNIT.WEEK, LAST_3_MONTH);
}
public static Timespan lastQuarter()
@@ -182,7 +201,7 @@
cal.set(Calendar.SECOND, 0);
long t0 = cal.getTimeInMillis();
- return new Timespan(t0, t1, UNIT.WEEK);
+ return new Timespan(t0, t1, UNIT.WEEK, LAST_QUARTER);
}
@@ -194,7 +213,7 @@
cal.roll(Calendar.YEAR, -1);
long t0 = cal.getTimeInMillis();
- return new Timespan(t0, t1, UNIT.MONTH);
+ return new Timespan(t0, t1, UNIT.MONTH, LAST_12_MONTH);
}
public static Timespan lastYear()
@@ -217,6 +236,37 @@
cal.set(Calendar.SECOND, 0);
long t0 = cal.getTimeInMillis();
- return new Timespan(t0, t1, UNIT.MONTH);
+ return new Timespan(t0, t1, UNIT.MONTH, LAST_YEAR);
}
+
+ public static Timespan fromValue(String value)
+ {
+ Timespan t = null;
+
+ if(LAST_24_HOURS.equals(value))
+ t = last24Hours();
+ else if(LAST_DAY.equals(value))
+ t =lastDay();
+ else if(LAST_7_DAYS.equals(value))
+ t =last7Days();
+ else if(LAST_WEEK.equals(value))
+ t =lastWeek();
+ else if(LAST_4_WEEKS.equals(value))
+ t =last4Weeks();
+ else if(LAST_MONTH.equals(value))
+ t =lastMonth();
+ else if(LAST_3_MONTH.equals(value))
+ t =last3Month();
+ else if(LAST_QUARTER.equals(value))
+ t =lastQuarter();
+ else if(LAST_12_MONTH.equals(value))
+ t =last12Month();
+ else if(LAST_YEAR.equals(value))
+ t =lastYear();
+
+ if(null==t)
+ throw new IllegalArgumentException("Unknown value: "+value);
+
+ return t;
+ }
}
More information about the overlord-commits
mailing list