Subversion Repositories bacoAlunos

Rev

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

package pt.estgp.estgweb.domain;

import com.owlike.genson.Genson;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.IOException;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashSet;

/**
 * Created by jorgemachado on 13/04/17.
 */

public class ConfigurationSeparatorImpl extends ConfigurationSeparator {

    @1.5.0/docs/api/java/lang/Override.html">Override
    public 1.5.0/docs/api/java/io/Serializable.html">Serializable getSerializable()
    {
        return getId();
    }

    public ArrayList<Long> getSchoolsIds()
    {
        ArrayList<Long> schoolsIds = new ArrayList<Long>();
        for(CourseSchool school: getSchools())
            schoolsIds.add(school.getId());
        return schoolsIds;
    }

    public void setSchoolsIds(ArrayList<Long> ids)
    {
        setSchools(new HashSet<CourseSchool>());
        for(1.5.0/docs/api/java/lang/Long.html">Long id: ids)
        {
            CourseSchool school = new CourseSchoolImpl();
            school.setId(id);
            getSchools().add(school);
        }
    }

    public ArrayList<String> getAllowedRoles()
    {
        ArrayList<String> roles = new ArrayList<String>();
        if(getSchools() != null)
        {
            for(CourseSchool sc : getSchools())
            {
                if(isShowStudents())
                    roles.add(sc.getStudentRole());
                if(isShowTeachers())
                    roles.add(sc.getTeacherRole());
                if(isShowWorkers())
                    roles.add(sc.getFuncionarioRole());
            }
        }
        return roles;
    }

    public 1.5.0/docs/api/java/lang/String.html">String getSeparatorKey()
    {
        return "ConfigSeparator" + getId();
    }

    static Genson confGenson = new Genson.Builder()
            .exclude(5+0%2Fdocs%2Fapi+Object">Object.class)
            .include("name", ConfigurationSeparatorImpl.class)
            .include("nameEn",ConfigurationSeparatorImpl.class)
            .include("nameEs",ConfigurationSeparatorImpl.class)
            .include("nameFr",ConfigurationSeparatorImpl.class)
            .include("description",ConfigurationSeparatorImpl.class)
            .include("position", ConfigurationSeparatorImpl.class)
             //Evita fazer o parse a todas as escolas, o set Ids vai colocar escolas na classe só com id
            .include("schoolsIds", ConfigurationSeparatorImpl.class)
            .include("pageSection", ConfigurationSeparatorImpl.class)
            .include("id", PageContent.class)
            .include("path", PageSectionImpl.class)
            .include("slug", PageSectionImpl.class)
            .create();

    public 1.5.0/docs/api/java/lang/String.html">String getJson() throws 1.5.0/docs/api/java/io/IOException.html">IOException
    {
        return confGenson.serialize(this);
    }

    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
    {
        return confGenson.serialize(seps);
    }

    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 {
        return confGenson.deserialize(json, ConfigurationSeparatorImpl.class);
    }

    public JSONObject getJsonObject() throws 1.5.0/docs/api/java/io/IOException.html">IOException, JSONException {
        return new JSONObject(getJson());
    }
}