Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
Antti Väyrynen
/
Moya
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit eff37fe6
authored
Jun 05, 2014
by
Tuukka Kivilahti
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
placepdf is nicer when it's sorted
1 parent
dca42f4c
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
79 additions
and
49 deletions
code/MoyaBeans/ejbModule/fi/codecrew/moya/beans/PlaceBean.java
code/MoyaBeans/ejbModule/fi/codecrew/moya/beans/PlaceMapBean.java
code/MoyaBeans/ejbModule/fi/codecrew/moya/facade/PlaceFacade.java
code/MoyaDatabase/src/fi/codecrew/moya/model/Place.java
code/MoyaBeans/ejbModule/fi/codecrew/moya/beans/PlaceBean.java
View file @
eff37fe
...
...
@@ -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
);
...
...
code/MoyaBeans/ejbModule/fi/codecrew/moya/beans/PlaceMapBean.java
View file @
eff37fe
...
...
@@ -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();
}
*/
}
code/MoyaBeans/ejbModule/fi/codecrew/moya/facade/PlaceFacade.java
View file @
eff37fe
...
...
@@ -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
();
}
}
...
...
code/MoyaDatabase/src/fi/codecrew/moya/model/Place.java
View file @
eff37fe
...
...
@@ -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
);
}
}
}
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment