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

fr.ird.observe.dto.reference.ReferentialDtoReference Maven / Gradle / Ivy

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

/*-
 * #%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.referential.ReferentialDto;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

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

/**
 * Created on 21/11/15.
 *
 * @author Tony Chemit - [email protected]
 */
public abstract class ReferentialDtoReference> extends DtoReference implements ReferentialDtoReferenceAware {

    public static final String PROPERTY_ENABLED = "enabled";
    public static final String PROPERTY_CODE = "code";

    private static final Logger log = LogManager.getLogger(ReferentialDtoReference.class);
    @SuppressWarnings({"unchecked", "rawtypes"})
    public static Set>> filterReferentialReference(Collection> types) {
        return (Set) types.stream().filter(ReferentialDtoReference.class::isAssignableFrom).collect(Collectors.toSet());
    }

    private final boolean needComment;
    private final boolean enabled;
    private final String homeId;

    protected ReferentialDtoReference(ReferentialDtoReferenceAware dto) {
        super(dto);
        this.enabled = dto.isEnabled();
        this.needComment = dto.isNeedComment();
        this.homeId = dto.getHomeId();
    }

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

    @Override
    public boolean isEnabled() {
        return enabled;
    }

    @Override
    public String getHomeId() {
        return homeId;
    }

    @Override
    public String toString() {
        MoreObjects.ToStringHelper toStringHelper = MoreObjects.toStringHelper(this)
                .add(PROPERTY_TYPE, getDtoType().getSimpleName())
                .add(ReferentialDto.PROPERTY_ID, getId());

        if (log.isDebugEnabled()) {
            toStringHelper
                    .add(PROPERTY_ENABLED, enabled)
                    .add(ReferentialDto.PROPERTY_NEED_COMMENT, needComment)
                    .add(ReferentialDto.PROPERTY_CREATE_DATE, getCreateDate())
                    .add(ReferentialDto.PROPERTY_LAST_UPDATE_DATE, getLastUpdateDate())
                    .add(ReferentialDto.PROPERTY_VERSION, getVersion())
                    .add(ReferentialDto.PROPERTY_HOME_ID, getHomeId());
        }
        return toStringHelper.toString();
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy