Subversion Repositories bacoAlunos

Rev

Rev 1729 | Rev 1737 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1728 jmachado 1
package pt.estgp.estgweb.domain;
2
 
3
import com.owlike.genson.Genson;
4
import com.owlike.genson.TransformationException;
5
import org.json.JSONException;
6
import org.json.JSONObject;
7
 
8
import java.io.IOException;
9
import java.io.Serializable;
10
import java.util.ArrayList;
1729 jmachado 11
import java.util.HashSet;
1728 jmachado 12
 
13
/**
14
 * Created by jorgemachado on 13/04/17.
15
 */
16
public class ConfigurationSeparatorImpl extends ConfigurationSeparator {
1729 jmachado 17
 
1728 jmachado 18
    @1.5.0/docs/api/java/lang/Override.html">Override
19
    public 1.5.0/docs/api/java/io/Serializable.html">Serializable getSerializable()
20
    {
21
        return getId();
22
    }
23
 
1729 jmachado 24
    public ArrayList<Long> getSchoolsIds()
25
    {
26
        ArrayList<Long> schoolsIds = new ArrayList<Long>();
27
        for(CourseSchool school: getSchools())
28
            schoolsIds.add(school.getId());
29
        return schoolsIds;
30
    }
31
 
32
    public void setSchoolsIds(ArrayList<Long> ids)
33
    {
34
        setSchools(new HashSet<CourseSchool>());
35
        for(1.5.0/docs/api/java/lang/Long.html">Long id: ids)
36
        {
37
            CourseSchool school = new CourseSchoolImpl();
38
            school.setId(id);
39
            getSchools().add(school);
40
        }
41
    }
42
 
1728 jmachado 43
    static Genson confGenson = new Genson.Builder()
44
            .exclude(5+0%2Fdocs%2Fapi+Object">Object.class)
1729 jmachado 45
            .include("name", ConfigurationSeparatorImpl.class)
46
            .include("nameEn",ConfigurationSeparatorImpl.class)
47
            .include("nameEs",ConfigurationSeparatorImpl.class)
48
            .include("nameFr",ConfigurationSeparatorImpl.class)
49
            .include("description",ConfigurationSeparatorImpl.class)
1731 jmachado 50
             //Evita fazer o parse a todas as escolas, o set Ids vai colocar escolas na classe só com id
1729 jmachado 51
            .include("schoolsIds",ConfigurationSeparatorImpl.class)
1731 jmachado 52
            .include("pageSection", ConfigurationSeparatorImpl.class)
53
            .include("id", PageContent.class)
54
            .include("path", PageSectionImpl.class)
55
            .include("slug", PageSectionImpl.class)
1728 jmachado 56
            .create();
57
 
58
    public 1.5.0/docs/api/java/lang/String.html">String getJson() throws 1.5.0/docs/api/java/io/IOException.html">IOException, TransformationException
59
    {
60
        return confGenson.serialize(this);
61
    }
62
 
1729 jmachado 63
    public static 1.5.0/docs/api/java/lang/String.html">String getJson(ArrayList<ConfigurationSeparator> seps) throws 1.5.0/docs/api/java/io/IOException.html">IOException, TransformationException
1728 jmachado 64
    {
65
        return confGenson.serialize(seps);
66
    }
67
 
68
    public static ConfigurationSeparatorImpl loadFromJson(1.5.0/docs/api/java/lang/String.html">String json) throws 1.5.0/docs/api/java/io/IOException.html">IOException, TransformationException {
69
        return confGenson.deserialize(json, ConfigurationSeparatorImpl.class);
70
    }
71
 
72
    public JSONObject getJsonObject() throws 1.5.0/docs/api/java/io/IOException.html">IOException, TransformationException, JSONException {
73
        return new JSONObject(getJson());
74
    }
75
}