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

fr.ird.observe.dto.form.FormDefinition 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.collect.ImmutableMap;
import fr.ird.observe.dto.IdDto;
import fr.ird.observe.dto.reference.DtoReferenceDefinition;
import fr.ird.observe.dto.reference.ReferentialDtoReference;
import fr.ird.observe.dto.reference.ReferentialDtoReferenceDefinition;
import fr.ird.observe.dto.referential.ReferentialDto;

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

/**
 * For a given of type {@link #type}, define all dependencies of referential set it need.
 * 

* Means, for each property which is a reference to a dto, let's grab mark it, this make use possible then to download *

* in one request, all referential references required by this object. * Created on 11/11/15. * * @author Tony Chemit - [email protected] */ public class FormDefinition { private final Class type; private final ImmutableMap> properties; public static Builder builder(Class type) { return new Builder<>(type); } public ImmutableMap> getProperties() { return properties; } FormDefinition(Class type, ImmutableMap> properties) { this.type = type; this.properties = properties; } public Class getType() { return type; } public Set> getPropertiesTypes() { return properties.values().stream().map(DtoReferenceDefinition::getDtoType).collect(Collectors.toSet()); } public Set> getPropertiesReferenceTypes() { return properties.values().stream().map(DtoReferenceDefinition::getType).collect(Collectors.toSet()); } public static class Builder { private final Class type; private final ImmutableMap.Builder> propertiesBuilder; public Builder(Class type) { this.type = type; this.propertiesBuilder = ImmutableMap.builder(); } public

> Builder addProperty(String name, ReferentialDtoReferenceDefinition definition) { propertiesBuilder.put(name, definition); return this; } public FormDefinition build() { return new FormDefinition<>(type, propertiesBuilder.build()); } } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy