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