fr.ird.observe.spi.ServiceBusinessProject Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of toolkit-service Show documentation
Show all versions of toolkit-service Show documentation
ObServe Toolkit Service module
The newest version!
package fr.ird.observe.spi;
/*-
* #%L
* ObServe Toolkit :: Service
* %%
* 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.data.ContainerDto;
import fr.ird.observe.dto.data.EditableDto;
import fr.ird.observe.dto.data.OpenableDto;
import fr.ird.observe.dto.data.SimpleDto;
import fr.ird.observe.dto.reference.DataDtoReference;
import fr.ird.observe.spi.context.ContainerDtoServiceContext;
import fr.ird.observe.spi.context.EditableDtoServiceContext;
import fr.ird.observe.spi.context.OpenableDtoServiceContext;
import fr.ird.observe.spi.context.SimpleDtoServiceContext;
import fr.ird.observe.spi.mapping.ContainerDtoToServiceContextMapping;
import fr.ird.observe.spi.mapping.EditableDtoToServiceContextMapping;
import fr.ird.observe.spi.mapping.OpenableDtoToServiceContextMapping;
import fr.ird.observe.spi.mapping.SimpleDtoToServiceContextMapping;
import fr.ird.observe.spi.module.BusinessModule;
import fr.ird.observe.spi.module.BusinessProject;
import fr.ird.observe.spi.module.BusinessSubModule;
import io.ultreia.java4all.lang.Strings;
import io.ultreia.java4all.util.ServiceLoaders;
import java.util.Objects;
/**
* Created on 17/10/2020.
*
* @author Tony Chemit - [email protected]
* @since 8.0.1
*/
public class ServiceBusinessProject {
private static ServiceBusinessProject INSTANCE;
private final OpenableDtoToServiceContextMapping openableDtoToServiceContextMapping;
private final EditableDtoToServiceContextMapping editableDtoToServiceContextMapping;
private final SimpleDtoToServiceContextMapping simpleDtoToServiceContextMapping;
private final ContainerDtoToServiceContextMapping containerDtoToServiceContextMapping;
public static String getSpiName(BusinessProject businessProject, String packageName, String dtoName) {
BusinessModule businessModule = businessProject.getBusinessModule(packageName);
BusinessSubModule businessSubModule = businessProject.getBusinessSubModule(businessModule, packageName);
return Strings.convertToConstantName(String.format("%s%s%sSpi",
Strings.capitalize(businessModule.getName().toLowerCase()),
Strings.capitalize(businessSubModule.getName().toLowerCase()),
ProjectPackagesDefinition.cleanType(dtoName)));
}
public static ServiceBusinessProject get() {
return INSTANCE == null ? INSTANCE = ServiceLoaders.loadUniqueService(ServiceBusinessProject.class) : INSTANCE;
}
public static OpenableDtoServiceContext fromOpenableDto(Class dtoType) {
return get().getOpenableDtoToServiceContextMapping().fromDto(dtoType);
}
public static EditableDtoServiceContext fromEditableDto(Class dtoType) {
return get().getEditableDtoToServiceContextMapping().fromDto(dtoType);
}
public static SimpleDtoServiceContext fromSimpleDto(Class dtoType) {
return get().getSimpleDtoToServiceContextMapping().fromDto(dtoType);
}
public static > ContainerDtoServiceContext, D> fromContainerDto(Class dtoType) {
return get().getContainerDtoToServiceContextMapping().fromDto(dtoType);
}
protected ServiceBusinessProject(OpenableDtoToServiceContextMapping openableDtoToServiceContextMapping, EditableDtoToServiceContextMapping editableDtoToServiceContextMapping, SimpleDtoToServiceContextMapping simpleDtoToServiceContextMapping, ContainerDtoToServiceContextMapping containerDtoToServiceContextMapping) {
this.openableDtoToServiceContextMapping = Objects.requireNonNull(openableDtoToServiceContextMapping);
this.editableDtoToServiceContextMapping = editableDtoToServiceContextMapping;
this.simpleDtoToServiceContextMapping = simpleDtoToServiceContextMapping;
this.containerDtoToServiceContextMapping = containerDtoToServiceContextMapping;
}
public OpenableDtoToServiceContextMapping getOpenableDtoToServiceContextMapping() {
return openableDtoToServiceContextMapping;
}
public EditableDtoToServiceContextMapping getEditableDtoToServiceContextMapping() {
return editableDtoToServiceContextMapping;
}
public SimpleDtoToServiceContextMapping getSimpleDtoToServiceContextMapping() {
return simpleDtoToServiceContextMapping;
}
public ContainerDtoToServiceContextMapping getContainerDtoToServiceContextMapping() {
return containerDtoToServiceContextMapping;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy