Commit eff37fe6 by Tuukka Kivilahti

placepdf is nicer when it's sorted

1 parent dca42f4c
......@@ -9,6 +9,8 @@ import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
......@@ -622,7 +624,12 @@ public class PlaceBean implements PlaceBeanLocal {
@Override
public byte[] generatePlacesPdf(float width, float height, double font1, double font2) {
try {
return generatePlacesPdf(width, height, font1, font1, placeFacade.findAll());
List<Place> places = placeFacade.findAll();
Collections.sort(places);
logger.info("sorting places etc.");
return generatePlacesPdf(width, height, font1, font1, places);
} catch (Exception e) {
logger.error("Exception from place pdf generation.", e);
......
......@@ -79,50 +79,4 @@ public class PlaceMapBean implements PlaceMapBeanLocal {
return null;
}
/*
wanha, poistoon
public byte[] placeCodesPdf(List<Place> places) {
// double[] pageSize = new double[] { cardBackground.getWidth(),
// cardBackground.getHeight() };
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
PDF pdf;
try {
pdf = new PDF(outputStream);
pdf.setTitle("placecodes");
double pagex = 155.9;
double pagey = 48;
Page page = new Page(pdf, new double[] { pagex, pagey });
// Render texts
// Big font for nick
com.pdfjet.Font font = new com.pdfjet.Font(pdf, CoreFont.HELVETICA);
font.setSize(8.0);
TextLine line = new TextLine(font);
line.setText("testi");
line.setPosition(1, 1);
line.setColor(new double[] { 1.0, 1.0, 1.0 });
line.drawOn(page);
pdf.flush();
outputStream.close();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return outputStream.toByteArray();
}
*/
}
......@@ -134,7 +134,7 @@ public class PlaceFacade extends IntegerPkGenericFacade<Place> {
CriteriaQuery<Place> cq = cb.createQuery(Place.class);
Root<Place> root = cq.from(Place.class);
cq.where( cb.equal(root.get(Place_.map).get(EventMap_.event), eventBean.getCurrentEvent()));
cq.orderBy(cb.asc(root.get(Place_.name)));
//cq.orderBy(cb.asc(root.get(Place_.name)));
return getEm().createQuery(cq).getResultList();
}
}
......
......@@ -12,13 +12,14 @@ import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;
/**
*
*/
@Entity
@Table(name = "places")
public class Place extends GenericEntity {
public class Place extends GenericEntity implements Comparable<Place> {
/**
*
......@@ -274,4 +275,72 @@ public class Place extends GenericEntity {
this.disabled = disabled;
}
/**
* Note: this class has a natural ordering that is inconsistent with equals.
*/
@Override
@Transient
public int compareTo(Place o) {
if(this.getName().equals(o.getName())) {
return 0;
}
// check empty string etc.
if(o.getName().length() == 0) {
if(this.getName().length() > 0)
return 1;
return 0;
}
if(this.getName().length() == 0 && o.getName().length() > 0) {
return -1;
}
// check prefixes
String splitted[] = o.getName().split("[0-9]");
if(splitted[0].length() > 0) {
if(splitted[0].length() > this.getName().length()) {
return this.getName().compareTo(splitted[0]);
}
} else {
return 1;
}
String myPrefix = this.getName().substring(0, splitted[0].length());
if(myPrefix.compareTo(splitted[0]) != 0)
return myPrefix.compareTo(splitted[0]);
// prefixes are same, find numbers and check them
String otherNumber = o.getName().substring(splitted[0].length());
String myNumber = this.getName().substring(splitted[0].length());
try {
int other = Integer.parseInt(otherNumber);
int me = Integer.parseInt(myNumber);
if(other < me) {
return 1;
}
if(other > me)
return -1;
return 0;
} catch(NumberFormatException x) {
return myNumber.compareTo(otherNumber);
}
}
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!