/*
 * Tanaguru - Automated webpage assessment
 * Copyright (C) 2008-2011  Open-S Company
 *
 * This file is part of Tanaguru.
 *
 * Tanaguru is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * Contact us by mail: open-s AT open-s DOT com
 */
package org.opens.tanaguru.entity.reference;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import javax.persistence.*;
import javax.xml.bind.annotation.XmlElementRef;
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlRootElement;
import org.hibernate.collection.PersistentBag;

/**
 * 
 * @author jkowalczyk
 */
@Entity
@Table(name = "THEME")
@XmlRootElement
public class ThemeImpl implements Theme, Serializable {

    @Column(name = "Cd_Theme")
    private String code;
    @OneToMany(mappedBy = "theme", cascade = CascadeType.ALL)
    private Collection<CriterionImpl> criterionList;
    @Column(name = "Description")
    private String description;
    @Id
    @GeneratedValue
    @Column(name = "Id_Theme")
    private Long id;
    @Column(name = "Label", nullable = false)
    private String label;
    @Column(name = "Rank")
    private int rank;

    public ThemeImpl() {
        super();
        criterionList = new ArrayList<CriterionImpl>();
    }

    public ThemeImpl(String code, String label, String description) {
        this();
        this.code = code;
        this.label = label;
        this.description = description;
    }

    @Override
    public String getCode() {
        return code;
    }

    @Override
    @XmlElementWrapper
    @XmlElementRef(type = org.opens.tanaguru.entity.reference.CriterionImpl.class)
    public List<Criterion> getCriterionList() {
        if (criterionList instanceof PersistentBag) {
            return (PersistentBag)criterionList;
        }
        return (List<Criterion>) (ArrayList)criterionList;
    }

    @Override
    public String getDescription() {
        return description;
    }

    @Override
    public Long getId() {
        return id;
    }

    @Override
    public String getLabel() {
        return label;
    }

    @Override
    public int getRank() {
        return rank;
    }

    @Override
    public void setCode(String code) {
        this.code = code;
    }

    @Override
    public void setCriterionList(List<Criterion> criterionList) {
        for (Criterion cr : criterionList) {
            this.criterionList.add((CriterionImpl)cr);
        }
    }

    @Override
    public void setDescription(String description) {
        this.description = description;
    }

    @Override
    public void setId(Long id) {
        this.id = id;
    }

    @Override
    public void setLabel(String label) {
        this.label = label;
    }

    @Override
    public void setRank(int rank) {
        this.rank = rank;
    }
}

@@ -1488,26 +1488,20 @@
 private 
-Collection
+List
 %3CCriteri

change type of returned list of entities to collections (revert)