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

fr.ird.observe.dto.form.Form Maven / Gradle / Ivy

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

/*
 * #%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.ObserveDto;
import fr.ird.observe.spi.DtoModelHelper;
import java.io.Serializable;
import java.util.Optional;

public class Form implements ObserveDto, Serializable {

    public static final String PROPERTY_TYPE = "type";
    public static final String PROPERTY_OBJECT = "object";

    private static final long serialVersionUID = 1L;

    private final Class type;
    private final R object;
    private FormDefinition definition;

    public static  Form newFormDto(Class type, R object) {
        return new Form<>(type, object);
    }

    protected Form(Class type, R object) {
        this.type = type;
        this.object = object;
    }

    public R getObject() {
        return object;
    }

    public Class getType() {
        return type;
    }

    @Override
    public String toString() {
        return MoreObjects.toStringHelper(this)
                .add(PROPERTY_TYPE, type.getName())
                .toString();
    }

    public Optional> getDefinition() {
        if (definition == null) {
            definition = DtoModelHelper.getOptionalFormDefinition(type).orElse(null);
        }
        return Optional.ofNullable(definition);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy