
fr.ird.observe.dto.form.FormDefinition Maven / Gradle / Ivy
package fr.ird.observe.dto.form;
/*-
* #%L
* ObServe Toolkit :: Dto
* %%
* Copyright (C) 2017 - 2021 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 fr.ird.observe.dto.BusinessDto;
import fr.ird.observe.dto.reference.ReferentialDtoReference;
import fr.ird.observe.dto.reference.ReferentialDtoReferenceDefinition;
import fr.ird.observe.dto.referential.ReferentialDto;
import java.util.LinkedHashMap;
import java.util.Map;
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 {
/**
* Property defines on each referential, it defines the list of references of this type.
*/
public static final String REFERENTIAL_LIST_HEADER = "referentialListHeader";
private final Class type;
private final Map> properties;
public static class Builder {
private final Class type;
private final Map> propertiesBuilder;
public Builder(Class type) {
this.type = type;
this.propertiesBuilder = new LinkedHashMap<>();
}
public Builder addProperty(String name, ReferentialDtoReferenceDefinition definition) {
propertiesBuilder.put(name, definition);
return this;
}
public FormDefinition build() {
return new FormDefinition<>(type, propertiesBuilder);
}
}
public static Builder builder(Class type) {
return new Builder<>(type);
}
FormDefinition(Class type, Map> properties) {
this.type = type;
this.properties = properties;
}
public Map> getProperties() {
return properties;
}
public Class getType() {
return type;
}
public Set> getPropertiesTypes() {
return properties.values().stream().map(ReferentialDtoReferenceDefinition::getDtoType).collect(Collectors.toSet());
}
public Set> getPropertiesReferenceTypes() {
return properties.values().stream().map(ReferentialDtoReferenceDefinition::getType).collect(Collectors.toSet());
}
}