OpenConcerto

Dépôt officiel du code source de l'ERP OpenConcerto
sonarqube

svn://code.openconcerto.org/openconcerto

Rev

Rev 150 | Blame | Compare with Previous | Last modification | View Log | RSS feed

package org.openconcerto.modules.operation;

import java.util.List;

import org.jopencalendar.model.Flag;
import org.jopencalendar.model.JCalendarItem;
import org.openconcerto.sql.element.SQLElementDirectory;
import org.openconcerto.sql.model.SQLRowValues;
import org.openconcerto.utils.CollectionUtils;

public class JCalendarItemDB extends JCalendarItem {
    private final SQLRowValues item;
    private final SQLRowValues group;
    private final OperationSQLElement operationElem;
    private final SQLRowValues operation;
    private String status;
    private String type;
    private String plannerXML;
    private String plannerUID;
    private String siteName;
    private String siteComment;
    private Number siteId;

    public JCalendarItemDB(final SQLElementDirectory dir, final SQLRowValues r) {
        assert r.isFrozen();
        this.item = r;
        this.group = dir.getElement(this.item.getTable()).getContainer(this.item);
        if (this.group == null) {
            throw new IllegalArgumentException("no group found for row " + r);
        }
        this.operationElem = dir.getElement(OperationSQLElement.class);
        if (this.operationElem == null) {
            throw new IllegalStateException("no element found " + OperationSQLElement.class);
        }
        this.operation = CollectionUtils.getSole(this.group.getReferentRows(this.operationElem.getTable()));
    }

    // OK since frozen
    public final SQLRowValues getRow() {
        return this.item;
    }

    public final OperationSQLElement getSourceElement() {
        return this.operationElem;
    }

    // OK since frozen
    public final SQLRowValues getSource() {
        return this.operation;
    }

    public final boolean isPlanned() {
        // there's also a flag "planned" but it's for the UI
        return !this.getSource().getString("PLANNER_UID").isEmpty();
    }

    // OK since frozen
    public final SQLRowValues getUserRow() {
        return (SQLRowValues) this.getSource().getForeign("ID_USER_COMMON");
    }

    // OK since frozen
    public final SQLRowValues getCalendarGroup() {
        return this.group;
    }

    public int getIdCalendarGroup() {
        return this.getCalendarGroup().getID();
    }

    @Override
    public int hashCode() {
        return this.getId();
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj)
            return true;
        if (obj == null)
            return false;
        if (getClass() != obj.getClass())
            return false;
        final JCalendarItemDB o = (JCalendarItemDB) obj;
        return this.item.equalsAsRow(o.item);
    }

    public void setOperationStatus(String status) {
        this.status = status;
    }

    public String getStatus() {
        return this.status;
    }

    public void setOperationType(String type) {
        this.type = type;
    }

    public String getType() {
        return this.type;
    }

    public String getFlagsString() {
        final List<Flag> flags = getFlags();
        final int size = flags.size();
        String str = "";
        for (int i = 0; i < size; i++) {
            str += flags.get(i).getTypeId();
            if (i < size - 1) {
                str += ",";
            }
        }
        return str;
    }

    public String getPlannerXML() {
        return this.plannerXML;
    }

    public void setPlannerXML(String string) {
        this.plannerXML = string;
    }

    public String getPlannerUID() {
        return this.plannerUID;
    }

    public void setPlannerUID(String plannerUID) {
        this.plannerUID = plannerUID;
    }

    public String getSiteName() {
        return this.siteName;
    }

    public void setSiteName(String siteName) {
        this.siteName = siteName;
    }

    public String getSiteComment() {
        return this.siteComment;
    }

    public void setSiteComment(String siteComment) {
        this.siteComment = siteComment;
    }

    public void setSiteId(Number idNumber) {
        this.siteId = idNumber;
    }

    public Number getSiteId() {
        return this.siteId;
    }

    public int getId() {
        return this.getRow().getID();
    }
}