All Downloads are FREE. Search and download functionalities are using the official Maven repository.

fr.ird.observe.dto.referential.ReferentialDto Maven / Gradle / Ivy

There is a newer version: 4.34
Show newest version
package fr.ird.observe.dto.referential;

/*-
 * #%L
 * ObServe Toolkit :: Common Dto
 * %%
 * Copyright (C) 2017 - 2020 IRD, Ultreia.io
 * %%
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public
 * License along with this program.  If not, see
 * .
 * #L%
 */

import com.google.common.base.MoreObjects;
import fr.ird.observe.dto.IdDto;
import fr.ird.observe.dto.reference.ReferentialDtoReferenceAware;
import io.ultreia.java4all.bean.spi.GenerateJavaBeanDefinition;

import java.util.Collection;
import java.util.Set;
import java.util.stream.Collectors;

@GenerateJavaBeanDefinition
public abstract class ReferentialDto extends IdDto implements ReferentialDtoReferenceAware {

    public static final String PROPERTY_ENABLED = "enabled";

    private static final long serialVersionUID = 1L;

    public static final String PROPERTY_CODE = "code";

    public static final String PROPERTY_STATUS = "status";

    public static final String PROPERTY_URI = "uri";

    public static final String PROPERTY_NEED_COMMENT = "needComment";

    public static final String PROPERTY_VERSION = "version";

    public static final String PROPERTY_CREATE_DATE = "createDate";

    public static final String PROPERTY_HOME_ID = "homeId";

    @SuppressWarnings("unchecked")
    public static Set> filterReferentialDto(Collection> types) {
        return (Set) types.stream().filter(ReferentialDto.class::isAssignableFrom).collect(Collectors.toSet());
    }

    protected String code;
    protected ReferenceStatus status;
    protected String uri;
    protected String homeId;

    protected boolean needComment;

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        String oldValue = getCode();
        this.code = code;
        firePropertyChange(PROPERTY_CODE, oldValue, code);
    }

    public ReferenceStatus getStatus() {
        return status;
    }

    public void setStatus(ReferenceStatus status) {
        ReferenceStatus oldValue = getStatus();
        this.status = status;
        firePropertyChange(PROPERTY_STATUS, oldValue, status);
    }

    public String getUri() {
        return uri;
    }

    public void setUri(String uri) {
        String oldValue = getUri();
        this.uri = uri;
        firePropertyChange(PROPERTY_URI, oldValue, uri);
    }

    @Override
    public boolean isNeedComment() {
        return needComment;
    }

    public void setNeedComment(boolean needComment) {
        boolean oldValue = isNeedComment();
        this.needComment = needComment;
        firePropertyChange(PROPERTY_NEED_COMMENT, oldValue, needComment);
    }

    @Override
    public boolean isEnabled() {
        return ReferenceStatus.enabled == status;
    }

    public void setEnabled(boolean enabled) {
        setStatus(enabled ? ReferenceStatus.enabled : ReferenceStatus.disabled);
    }

    public String getHomeId() {
        return homeId;
    }

    public void setHomeId(String homeId) {
        String oldValue = getHomeId();
        this.homeId = homeId;
        firePropertyChange(PROPERTY_HOME_ID, oldValue, homeId);
    }

    @Override
    public String toString() {
        return MoreObjects.toStringHelper(this)
                .add(PROPERTY_ID, id)
                .add(PROPERTY_HOME_ID, homeId)
                .add(PROPERTY_ENABLED, isEnabled())
                .add(PROPERTY_NEED_COMMENT, needComment)
                .add(PROPERTY_CREATE_DATE, createDate)
                .add(PROPERTY_LAST_UPDATE_DATE, lastUpdateDate)
                .add(PROPERTY_VERSION, version)
                .toString();
    }

    public  void toDto(D dto) {
        super.toDto(dto);
        dto.setStatus(getStatus());
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy