fr.ird.observe.toolkit.eugene.templates.DtoModel Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of eugene-templates Show documentation
Show all versions of eugene-templates Show documentation
ObServe Eugene templates module
The newest version!
package fr.ird.observe.toolkit.eugene.templates;
/*-
* #%L
* ObServe Toolkit :: Eugene Templates
* %%
* Copyright (C) 2008 - 2017 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 com.google.common.collect.ImmutableSet;
import fr.ird.observe.dto.IdHelper;
import org.nuiton.eugene.EugeneCoreTagValues;
import org.nuiton.eugene.LogProxy;
import org.nuiton.eugene.java.BeanTransformerTagValues;
import org.nuiton.eugene.java.EugeneJavaTagValues;
import org.nuiton.eugene.java.JavaGeneratorUtil;
import org.nuiton.eugene.models.object.ObjectModel;
import org.nuiton.eugene.models.object.ObjectModelClass;
import org.nuiton.eugene.models.object.ObjectModelPackage;
/**
* Created by tchemit on 15/09/17.
*
* @author Tony Chemit - [email protected]
*/
public class DtoModel {
public final EugeneCoreTagValues eugeneTagValues;
public final EugeneJavaTagValues javaTemplatesTagValues;
public final BeanTransformerTagValues beanTagValues;
public final ToolkitTagValues toolkitTagValues;
public final DtoTransformerContext context;
public final DtoTransformerContext referenceContext;
public final DtoTransformerContext formContext;
public final ObjectModelPackage defaultPackage;
public final boolean useJava8;
public final LogProxy log;
public final ObjectModel model;
public final ImmutableSet helpers;
public final ImmutableMap helpersNameTranslation;
public DtoModel(EugeneCoreTagValues eugeneTagValues, EugeneJavaTagValues javaTemplatesTagValues, BeanTransformerTagValues beanTagValues, ToolkitTagValues toolkitTagValues, LogProxy log, ObjectModel model, String defaultPackageName) {
this.eugeneTagValues = eugeneTagValues;
this.javaTemplatesTagValues = javaTemplatesTagValues;
this.beanTagValues = beanTagValues;
this.toolkitTagValues = toolkitTagValues;
this.log = log;
this.model = model;
useJava8 = javaTemplatesTagValues.isUseJava8(model);
defaultPackage = model.getPackage(defaultPackageName);
ImmutableMap.Builder helpersNameTranslationBuilder = new ImmutableMap.Builder<>();
ImmutableSet.Builder helpersBuilder = new ImmutableSet.Builder<>();
context = new DtoTransformerContext(model, defaultPackageName, eugeneTagValues, javaTemplatesTagValues, beanTagValues, true, true, aClass -> {
ObjectModelPackage aPackage = model.getPackage(aClass.getPackageName());
boolean skip = EugeneCoreTagValues.isSkip(aClass, aPackage);
boolean canGenerateHelper = !skip && beanTagValues.isGenerateHelper(aClass, aPackage, model);
if (canGenerateHelper) {
helpersBuilder.add(aClass);
String helperNamePrefix = beanTagValues.getHelperClassNamePrefixTagValue(aClass, aPackage, model);
String helperNameSuffix = beanTagValues.getHelperClassNameSuffixTagValue(aClass, aPackage, model);
String generateHelperName = JavaGeneratorUtil.generateName(helperNamePrefix, aClass.getName(), helperNameSuffix);
helpersNameTranslationBuilder.put(aClass, generateHelperName);
}
return true;
}, log);
referenceContext = new DtoTransformerContext(model, defaultPackageName, eugeneTagValues, javaTemplatesTagValues, beanTagValues, false, false, input -> {
ObjectModelPackage aPackage = model.getPackage(input.getPackageName());
boolean referential = IdHelper.isReferentialFromPackageName(aPackage.getName());
String referencesTagValue = toolkitTagValues.getReferencesTagValue(input);
return referencesTagValue != null || referential;
}, log);
formContext = new DtoTransformerContext(model, defaultPackageName, eugeneTagValues, javaTemplatesTagValues, beanTagValues, false, false, input -> {
ObjectModelPackage aPackage = model.getPackage(input.getPackageName());
String formTagValue = toolkitTagValues.getFormTagValue(input, aPackage);
return formTagValue != null;
}, log);
helpers = helpersBuilder.build();
helpersNameTranslation = helpersNameTranslationBuilder.build();
}
}