Subversion Repositories bacoAlunos

Rev

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

Rev Author Line No. Line
1670 jmachado 1
package pt.estgp.estgweb.domain;
2
 
3
import com.owlike.genson.Genson;
4
import com.owlike.genson.TransformationException;
1675 jmachado 5
import org.json.JSONArray;
1670 jmachado 6
import org.json.JSONException;
7
import org.json.JSONObject;
8
 
9
import java.io.IOException;
10
import java.io.Serializable;
1675 jmachado 11
import java.util.ArrayList;
1670 jmachado 12
import java.util.List;
1675 jmachado 13
import java.util.Set;
1670 jmachado 14
 
15
/**
16
 * Created by jorgemachado on 23/02/17.
17
 */
18
public class RepositoryDocumentCollectionImpl extends RepositoryDocumentCollection {
19
    @1.5.0/docs/api/java/lang/Override.html">Override
20
    public 1.5.0/docs/api/java/io/Serializable.html">Serializable getSerializable() {
21
        return getId();
22
    }
23
 
24
 
1675 jmachado 25
    static Genson genson;
26
 
27
    static {
28
        Genson.Builder gensonBuilder =  new Genson.Builder()
1670 jmachado 29
            .exclude(5+0%2Fdocs%2Fapi+Object">Object.class)
30
            .include(RepositoryDocumentCollectionImpl.class)
31
            .include(1.5.0/docs/api/java/lang/String.html">String.class)
1675 jmachado 32
            .exclude("parent", RepositoryDocumentCollection.class);
33
        genson = gensonBuilder.create();
1670 jmachado 34
 
1675 jmachado 35
    }
1670 jmachado 36
    public 1.5.0/docs/api/java/lang/String.html">String toJson() throws 1.5.0/docs/api/java/io/IOException.html">IOException, TransformationException
37
    {
38
        return genson.serialize(this);
39
    }
40
 
41
    public static 1.5.0/docs/api/java/lang/String.html">String toJson(List<RepositoryDocumentCollection> collections) throws 1.5.0/docs/api/java/io/IOException.html">IOException, TransformationException
42
    {
43
        return genson.serialize(collections);
44
    }
1675 jmachado 45
    public static JSONArray toJsonArray(Set<RepositoryDocumentCollectionImpl> collections) throws 1.5.0/docs/api/java/io/IOException.html">IOException, TransformationException, JSONException {
46
        ArrayList<RepositoryDocumentCollectionImpl> collectionsList  = new ArrayList<RepositoryDocumentCollectionImpl>(collections);
47
        return toJsonArray(collectionsList);
48
    }
1670 jmachado 49
 
1675 jmachado 50
    public static JSONArray toJsonArray(List<RepositoryDocumentCollectionImpl> collections) throws 1.5.0/docs/api/java/io/IOException.html">IOException, TransformationException, JSONException {
51
        return new JSONArray(genson.serialize(collections));
52
    }
53
 
1670 jmachado 54
    public static RepositoryDocumentCollectionImpl loadFromJson(1.5.0/docs/api/java/lang/String.html">String json) throws 1.5.0/docs/api/java/io/IOException.html">IOException, TransformationException {
55
        return genson.deserialize(json, RepositoryDocumentCollectionImpl.class);
56
    }
57
 
58
    public JSONObject toJsonObject() throws 1.5.0/docs/api/java/io/IOException.html">IOException, TransformationException, JSONException {
59
        return new JSONObject(toJson());
60
    }
1675 jmachado 61
 
62
    public 1.5.0/docs/api/java/lang/String.html">String getPathName()
63
    {
64
        if(getParent()==null)
65
            return getName();
66
        else
67
            return getParent().getPathName() + " - " + getName();
68
    }
1670 jmachado 69
}
70