Rev 1776 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1327 | jmachado | 1 | package pt.estgp.estgweb.services.entity; |
2 | |||
3 | import com.owlike.genson.Genson; |
||
1414 | jmachado | 4 | import pt.estgp.estgweb.domain.*; |
1327 | jmachado | 5 | import pt.estgp.estgweb.domain.dao.DaoFactory; |
6 | import pt.utl.ist.berserk.logic.serviceManager.IService; |
||
7 | |||
8 | import java.io.IOException; |
||
9 | import java.io.Serializable; |
||
1414 | jmachado | 10 | import java.util.ArrayList; |
1327 | jmachado | 11 | |
12 | /** |
||
13 | * Created by jorgemachado on 22/03/16. |
||
14 | */ |
||
15 | public class EntityServiceJson implements IService |
||
16 | { |
||
17 | static Genson courseUnitGenson = new Genson.Builder() |
||
18 | .exclude(5+0%2Fdocs%2Fapi+Object">Object.class) |
||
1778 | jmachado | 19 | .include(1.5.0/docs/api/java/lang/Boolean.html">Boolean.class) |
20 | .include(1.5.0/docs/api/java/lang/Integer.html">Integer.class) |
||
21 | .include(1.5.0/docs/api/java/lang/Long.html">Long.class) |
||
22 | .include(1.5.0/docs/api/java/lang/Double.html">Double.class) |
||
23 | .include(1.5.0/docs/api/java/lang/Float.html">Float.class) |
||
1327 | jmachado | 24 | .include("id", CourseUnit.class) |
25 | .include("semestre", CourseUnit.class) |
||
26 | .include("name", CourseUnit.class) |
||
27 | .include("code", CourseUnit.class) |
||
28 | .include("courseName", CourseUnit.class) |
||
29 | .include("courseYear",CourseUnit.class) |
||
30 | .include("importYear", CourseUnit.class) |
||
31 | .create(); |
||
32 | |||
1414 | jmachado | 33 | static Genson userGenson = new Genson.Builder() |
34 | .exclude(5+0%2Fdocs%2Fapi+Object">Object.class) |
||
35 | .exclude(User.class) |
||
36 | .exclude(GenericUser.class) |
||
37 | .exclude(Student.class) |
||
38 | .exclude(Teacher.class) |
||
1778 | jmachado | 39 | .include(1.5.0/docs/api/java/lang/Boolean.html">Boolean.class) |
40 | .include(1.5.0/docs/api/java/lang/Integer.html">Integer.class) |
||
41 | .include(1.5.0/docs/api/java/lang/Long.html">Long.class) |
||
42 | .include(1.5.0/docs/api/java/lang/Double.html">Double.class) |
||
43 | .include(1.5.0/docs/api/java/lang/Float.html">Float.class) |
||
1414 | jmachado | 44 | .include("id", User.class) |
45 | .include("name", User.class) |
||
46 | .include("sigesCode", User.class) |
||
47 | .include("email", User.class) |
||
48 | .include("roles", User.class) |
||
49 | |||
50 | .create(); |
||
51 | |||
1776 | jmachado | 52 | public 1.5.0/docs/api/java/lang/String.html">String courseUnit(CourseUnit cu) throws 1.5.0/docs/api/java/io/IOException.html">IOException { |
1414 | jmachado | 53 | return courseUnitGenson.serialize(cu); |
54 | } |
||
1776 | jmachado | 55 | public 1.5.0/docs/api/java/lang/String.html">String courseUnit(1.5.0/docs/api/java/io/Serializable.html">Serializable s) throws 1.5.0/docs/api/java/io/IOException.html">IOException { |
1327 | jmachado | 56 | CourseUnit cu = DaoFactory.getCourseUnitDaoImpl().get(s); |
57 | return courseUnitGenson.serialize(cu); |
||
58 | } |
||
1414 | jmachado | 59 | |
1776 | jmachado | 60 | public 1.5.0/docs/api/java/lang/String.html">String user(1.5.0/docs/api/java/io/Serializable.html">Serializable s) throws 1.5.0/docs/api/java/io/IOException.html">IOException { |
1414 | jmachado | 61 | User u = DaoFactory.getUserDaoImpl().get(s); |
62 | return userGenson.serialize(u); |
||
63 | } |
||
1776 | jmachado | 64 | public 1.5.0/docs/api/java/lang/String.html">String user(User u) throws 1.5.0/docs/api/java/io/IOException.html">IOException { |
1414 | jmachado | 65 | return userGenson.serialize(u); |
66 | } |
||
67 | |||
1776 | jmachado | 68 | public 1.5.0/docs/api/java/lang/String.html">String user(ArrayList<User> users) throws 1.5.0/docs/api/java/io/IOException.html">IOException { |
1414 | jmachado | 69 | return userGenson.serialize(users); |
70 | } |
||
1327 | jmachado | 71 | } |