ItEr60S04ValidacionEProbasFuncionaisItEr59S04: Removing previous gannt printing system.
It's not being used right now.
This commit is contained in:
parent
f85c38c7db
commit
2f9ded01f2
5 changed files with 0 additions and 543 deletions
|
|
@ -1,115 +0,0 @@
|
|||
/*
|
||||
* This file is part of NavalPlan
|
||||
*
|
||||
* Copyright (C) 2009 Fundación para o Fomento da Calidade Industrial e
|
||||
* Desenvolvemento Tecnolóxico de Galicia
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.zkoss.ganttz.print;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.management.timer.Timer;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Diego Pino Garcia <dpino@igalia.com>
|
||||
*
|
||||
*/
|
||||
public class GanttDiagramURIStore {
|
||||
|
||||
private static Map<String, GanttDiagramURIData> resources = new HashMap<String, GanttDiagramURIData>();
|
||||
|
||||
public static String storeURI(String URI) {
|
||||
List<String> URIs = new ArrayList<String>();
|
||||
URIs.add(URI);
|
||||
return storeURIs(URIs);
|
||||
}
|
||||
|
||||
public static String storeURIs(List<String> URIs) {
|
||||
String key = UUID.randomUUID().toString();
|
||||
resources.put(key, new GanttDiagramURIData(URIs));
|
||||
return key;
|
||||
}
|
||||
|
||||
public static List<String> getURIsById(String id) {
|
||||
clean();
|
||||
final GanttDiagramURIData data = resources.get(id);
|
||||
if (data != null) {
|
||||
return data.getURIs();
|
||||
}
|
||||
return new ArrayList<String>();
|
||||
}
|
||||
|
||||
public static void clean() {
|
||||
clean(GanttDiagramURIData.EXPIRE_TIME);
|
||||
}
|
||||
|
||||
public static void clean(long lifespan) {
|
||||
final Set<String> keys = resources.keySet();
|
||||
for (Iterator<String> i = keys.iterator(); i.hasNext(); ) {
|
||||
final String key = (String) i.next();
|
||||
final GanttDiagramURIData data = resources.get(key);
|
||||
if (data.hasExpired(lifespan)) {
|
||||
i.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static int size() {
|
||||
return resources.size();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Diego Pino Garcia <dpino@igalia.com>
|
||||
*
|
||||
*/
|
||||
private static class GanttDiagramURIData {
|
||||
|
||||
private static final long EXPIRE_TIME = Timer.ONE_HOUR;
|
||||
|
||||
private long timestamp;
|
||||
|
||||
private List<String> URIs = new ArrayList<String>();
|
||||
|
||||
public GanttDiagramURIData(List<String> URIs) {
|
||||
this.timestamp = currentTime();
|
||||
this.URIs.addAll(URIs);
|
||||
}
|
||||
|
||||
public boolean hasExpired(long lifespan) {
|
||||
return ((timestamp + lifespan - currentTime()) <= 0);
|
||||
}
|
||||
|
||||
private long currentTime() {
|
||||
return System.currentTimeMillis();
|
||||
}
|
||||
|
||||
public List<String> getURIs() {
|
||||
return Collections.unmodifiableList(URIs);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,201 +0,0 @@
|
|||
/*
|
||||
* This file is part of NavalPlan
|
||||
*
|
||||
* Copyright (C) 2009 Fundación para o Fomento da Calidade Industrial e
|
||||
* Desenvolvemento Tecnolóxico de Galicia
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.zkoss.ganttz.print;
|
||||
|
||||
import gantt.builder.ChartBuilder;
|
||||
import gantt.builder.DatasetBuilder;
|
||||
import gantt.data.ExtendedGanttCategoryDataset;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Collection;
|
||||
import java.util.Comparator;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.jfree.chart.JFreeChart;
|
||||
import org.jfree.data.gantt.TaskSeries;
|
||||
import org.zkoss.ganttz.data.GanttDiagramGraph;
|
||||
import org.zkoss.ganttz.data.Task;
|
||||
import org.zkoss.ganttz.servlets.CallbackServlet;
|
||||
import org.zkoss.ganttz.servlets.handlers.GeneratePrintPageHandler;
|
||||
import org.zkoss.ganttz.servlets.handlers.JFreeChartHandler;
|
||||
import org.zkoss.ganttz.timetracker.zoom.ZoomLevel;
|
||||
import org.zkoss.zk.ui.Executions;
|
||||
|
||||
public class Print {
|
||||
|
||||
private static final int INTERVAL_LENGTH_IN_MINUTES = 300 * 24 * 30;
|
||||
|
||||
private static final String DEFAULT_SERIES_NAME = "Scheduled";
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public static void print(GanttDiagramGraph diagramGraph) {
|
||||
try {
|
||||
printGanttHorizontalPagingDemo(diagramGraph);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public static void printGanttHorizontalPagingDemo(GanttDiagramGraph diagramGraph)
|
||||
throws Exception {
|
||||
DatasetBuilder datasetBuilder = new DatasetBuilder();
|
||||
|
||||
final List<Task> tasks = diagramGraph.getTasks();
|
||||
final Date begin = getSmallestBeginDate(tasks);
|
||||
final Date end = getBiggestFinishDate(tasks);
|
||||
|
||||
// Create series
|
||||
List<TaskSeries> taskSeriesList = new ArrayList<TaskSeries>();
|
||||
final TaskSeries taskSeries = datasetBuilder.createTaskSeries(diagramGraph,
|
||||
DEFAULT_SERIES_NAME);
|
||||
taskSeriesList.add(taskSeries);
|
||||
|
||||
// Create dataset and split it
|
||||
final ExtendedGanttCategoryDataset dataset = datasetBuilder
|
||||
.createDataset(taskSeriesList);
|
||||
|
||||
List<ExtendedGanttCategoryDataset> subdatasets = datasetBuilder
|
||||
.splitDatasetInIntervals(dataset, begin, end,
|
||||
INTERVAL_LENGTH_IN_MINUTES);
|
||||
|
||||
// Show resulting printing page
|
||||
final List<String> URIs = convertDatasetsToURIs(subdatasets);
|
||||
final String id = GanttDiagramURIStore.storeURIs(URIs);
|
||||
final String URL = generatePrintPage(id);
|
||||
showPage(URL);
|
||||
}
|
||||
|
||||
private static void showPage(String URL) {
|
||||
Executions.getCurrent().sendRedirect(URL, "_blank");
|
||||
}
|
||||
|
||||
private static String generatePrintPage(String id) {
|
||||
final GeneratePrintPageHandler handler = new GeneratePrintPageHandler(id);
|
||||
String URL = CallbackServlet.registerAndCreateURLFor(getCurrentRequest(), handler);
|
||||
URL = URL.replace("/navalplanner-webapp", "");
|
||||
return URL;
|
||||
}
|
||||
|
||||
private static HttpServletRequest getCurrentRequest() {
|
||||
return (HttpServletRequest) Executions.getCurrent().getNativeRequest();
|
||||
}
|
||||
|
||||
private static List<String> convertDatasetsToURIs(List<ExtendedGanttCategoryDataset> datasets) {
|
||||
List<String> result = new ArrayList<String>();
|
||||
|
||||
for (ExtendedGanttCategoryDataset each : datasets) {
|
||||
final JFreeChartHandler handler = new JFreeChartHandler(
|
||||
createChart(each));
|
||||
final String uri = CallbackServlet.registerAndCreateURLFor(getCurrentRequest(),
|
||||
handler);
|
||||
result.add(uri);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static JFreeChart createChart(ExtendedGanttCategoryDataset dataset) {
|
||||
final ChartBuilder chartBuilder = new ChartBuilder();
|
||||
return chartBuilder.createChart("Gantt Diagram",
|
||||
"Tasks", "Date", dataset, true, true, false, ZoomLevel.DETAIL_TWO);
|
||||
}
|
||||
|
||||
private static Date getSmallestBeginDate(
|
||||
List<org.zkoss.ganttz.data.Task> tasks) {
|
||||
if (tasks.isEmpty())
|
||||
return Calendar.getInstance().getTime();
|
||||
return getSmallest(getStartDates(tasks));
|
||||
}
|
||||
|
||||
private static Date getBiggestFinishDate(
|
||||
List<org.zkoss.ganttz.data.Task> tasks) {
|
||||
if (tasks.isEmpty())
|
||||
return Calendar.getInstance().getTime();
|
||||
return getBiggest(getEndDates(tasks));
|
||||
}
|
||||
|
||||
private static List<Date> getStartDates(
|
||||
List<org.zkoss.ganttz.data.Task> tasks) {
|
||||
ArrayList<Date> result = new ArrayList<Date>();
|
||||
for (org.zkoss.ganttz.data.Task t : tasks) {
|
||||
result.add(t.getBeginDate());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static List<Date> getEndDates(List<org.zkoss.ganttz.data.Task> tasks) {
|
||||
ArrayList<Date> result = new ArrayList<Date>();
|
||||
for (org.zkoss.ganttz.data.Task t : tasks) {
|
||||
result.add(t.getEndDate());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static <T extends Comparable<? super T>> T getSmallest(
|
||||
Collection<T> elements) {
|
||||
return getSmallest(elements, new Comparator<T>() {
|
||||
|
||||
@Override
|
||||
public int compare(T o1, T o2) {
|
||||
return o1.compareTo(o2);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static <T extends Comparable<? super T>> T getBiggest(
|
||||
Collection<T> elements) {
|
||||
return getSmallest(elements, new Comparator<T>() {
|
||||
|
||||
@Override
|
||||
public int compare(T o1, T o2) {
|
||||
return o2.compareTo(o1);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static <T> T getSmallest(Collection<T> elements,
|
||||
Comparator<T> comparator) {
|
||||
List<T> withoutNulls = removeNulls(elements);
|
||||
if (withoutNulls.isEmpty())
|
||||
throw new IllegalArgumentException("at least one required");
|
||||
T result = null;
|
||||
for (T element : withoutNulls) {
|
||||
result = result == null ? element : (comparator.compare(result,
|
||||
element) < 0 ? result : element);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static <T> List<T> removeNulls(Collection<T> elements) {
|
||||
ArrayList<T> result = new ArrayList<T>();
|
||||
for (T e : elements) {
|
||||
if (e != null) {
|
||||
result.add(e);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,98 +0,0 @@
|
|||
/*
|
||||
* This file is part of NavalPlan
|
||||
*
|
||||
* Copyright (C) 2009 Fundación para o Fomento da Calidade Industrial e
|
||||
* Desenvolvemento Tecnolóxico de Galicia
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.zkoss.ganttz.servlets.handlers;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.List;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.zkoss.ganttz.print.GanttDiagramURIStore;
|
||||
import org.zkoss.ganttz.servlets.CallbackServlet.IServletRequestHandler;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Diego Pino Garcia <dpino@igalia.com>
|
||||
*
|
||||
*/
|
||||
public class GeneratePrintPageHandler implements IServletRequestHandler {
|
||||
|
||||
private static final String DEFAULT_TITLE = "Xestion-produccion";
|
||||
|
||||
private String id;
|
||||
|
||||
private String title = DEFAULT_TITLE;
|
||||
|
||||
public GeneratePrintPageHandler(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handle(HttpServletRequest request, HttpServletResponse response)
|
||||
throws ServletException, IOException {
|
||||
PrintWriter writer = response.getWriter();
|
||||
final String page = getPage();
|
||||
writer.write(page);
|
||||
writer.close();
|
||||
}
|
||||
|
||||
private String getPage() {
|
||||
String result = "";
|
||||
result += page_template;
|
||||
result = result.replace("###TITLE###", getTitle());
|
||||
result = result.replace("###GANTT_DIAGRAM_IMAGES###", getDiagramImages());
|
||||
return result;
|
||||
}
|
||||
|
||||
private String getDiagramImages() {
|
||||
String result = "";
|
||||
final List<String> URIs = GanttDiagramURIStore.getURIsById(id);
|
||||
for(String URI: URIs) {
|
||||
result += image_template.replace("###URI###", URI);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static final String page_template = new StringBuilder()
|
||||
.append("<html>")
|
||||
.append("<head><title>###TITLE###</title></head>")
|
||||
.append("<body>###GANTT_DIAGRAM_IMAGES###</body>")
|
||||
.append("</html>")
|
||||
.toString();
|
||||
|
||||
private static final String image_template = new StringBuilder()
|
||||
.append("<div>")
|
||||
.append("<img src='###URI###'/>")
|
||||
.append("</div>")
|
||||
.toString();
|
||||
|
||||
}
|
||||
|
|
@ -1,70 +0,0 @@
|
|||
/*
|
||||
* This file is part of NavalPlan
|
||||
*
|
||||
* Copyright (C) 2009 Fundación para o Fomento da Calidade Industrial e
|
||||
* Desenvolvemento Tecnolóxico de Galicia
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.zkoss.ganttz.servlets.handlers;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.ServletOutputStream;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.jfree.chart.ChartUtilities;
|
||||
import org.jfree.chart.JFreeChart;
|
||||
import org.zkoss.ganttz.servlets.CallbackServlet.IServletRequestHandler;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Diego Pino Garcia <dpino@igalia.com>
|
||||
*
|
||||
*/
|
||||
public class JFreeChartHandler implements IServletRequestHandler {
|
||||
|
||||
private JFreeChart chart;
|
||||
|
||||
private static final int WIDTH = 800;
|
||||
|
||||
private static final int HEIGHT = 600;
|
||||
|
||||
public JFreeChartHandler(JFreeChart chart) {
|
||||
this.chart = chart;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handle(HttpServletRequest request, HttpServletResponse response)
|
||||
throws ServletException, IOException {
|
||||
toPNG(response, this.chart);
|
||||
}
|
||||
|
||||
private void toPNG(HttpServletResponse response, JFreeChart chart) throws IOException {
|
||||
response.setContentType("image/png");
|
||||
ServletOutputStream writer = response.getOutputStream();
|
||||
writer.write(encodeAsPNG(chart));
|
||||
writer.close();
|
||||
}
|
||||
|
||||
private static byte[] encodeAsPNG(JFreeChart chart) throws IOException {
|
||||
final BufferedImage chartImage = chart.createBufferedImage(WIDTH, HEIGHT);
|
||||
return ChartUtilities.encodeAsPNG(chartImage);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,59 +0,0 @@
|
|||
/*
|
||||
* This file is part of NavalPlan
|
||||
*
|
||||
* Copyright (C) 2009 Fundación para o Fomento da Calidade Industrial e
|
||||
* Desenvolvemento Tecnolóxico de Galicia
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.zkoss.ganttz.print;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.management.timer.Timer;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class GanttDiagramURIStoreTest {
|
||||
|
||||
private String URI = "http://www.igalia.com";
|
||||
|
||||
@Test
|
||||
public void testStoreURIs() {
|
||||
String id = GanttDiagramURIStore.storeURI(URI);
|
||||
List<String> URIs = GanttDiagramURIStore.getURIsById(id);
|
||||
assertNotNull(URIs);
|
||||
String uri = URIs.get(0);
|
||||
assertEquals(uri, URI);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCleanAllResources() {
|
||||
GanttDiagramURIStore.storeURI(URI);
|
||||
GanttDiagramURIStore.clean(0);
|
||||
assertEquals(0, GanttDiagramURIStore.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDoNotCleanResourceInmediatelyAfterInsertingIt() {
|
||||
GanttDiagramURIStore.storeURI(URI);
|
||||
GanttDiagramURIStore.clean(Timer.ONE_MINUTE);
|
||||
assertEquals(1, GanttDiagramURIStore.size());
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue