fr.ird.observe.toolkit.eugene.templates.BinderHelper Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of eugene-templates-extension Show documentation
Show all versions of eugene-templates-extension Show documentation
ObServe Eugene templates extension module
package fr.ird.observe.toolkit.eugene.templates;
/*-
* #%L
* ObServe Toolkit :: Eugene Templates Extension
* %%
* Copyright (C) 2017 - 2019 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 fr.ird.observe.dto.data.DataDto;
import fr.ird.observe.dto.reference.DataDtoReference;
import fr.ird.observe.dto.reference.ReferentialDtoReference;
import fr.ird.observe.dto.referential.ReferentialDto;
import fr.ird.observe.spi.ProjectPackagesDefinitionInstance;
import fr.ird.observe.spi.type.TypeTranslators;
/**
* Created by tchemit on 31/08/17.
*
* @author Tony Chemit - [email protected]
*/
class BinderHelper {
static String generateBinderName(String binderPackageName, String fqn, String dtoName) {
String relativeName = getRelativeDtoPackage(fqn);
int lastIndex = relativeName.lastIndexOf(".");
return binderPackageName + relativeName.substring(0, lastIndex + 1) + dtoName + "Binder";
}
static String generateRelativeName(String binderPackageName, String fqn, String dtoName, String suffix) {
String relativeName = getRelativeDtoPackage(fqn);
int lastIndex = relativeName.lastIndexOf(".");
return binderPackageName + relativeName.substring(0, lastIndex + 1) + dtoName +suffix;
}
static String cleanId(String id) {
if (id.endsWith("Dto")) {
return id.substring(0, id.length() - 3);
}
if (id.endsWith("Reference")) {
return id.substring(0, id.length() - 9);
}
// for entity, hibernate proxy gives use some class name like Entity_xxx
int index = id.indexOf("_");
if (index > -1) {
id = id.substring(0, index);
} else {
// for entity, hibernate
index = id.indexOf("@");
if (index > -1) {
id = id.substring(0, index);
}
}
if (id.endsWith("Impl")) {
return id.substring(0, id.length() - 4);
}
return id;
}
public static boolean isReferentialFromPackageName(String packageName) {
return packageName.contains(".referential");
// return packageName.startsWith(DTO_REFERENTIAL_PACKAGE);
}
public static String getRelativeDtoPackage(String dtoClassName) {
return ProjectPackagesDefinitionInstance.get().getRelativeDtoPackage(dtoClassName);
// return StringUtils.removeStart(dtoClassName, DTO_ROOT_PACKAGE);
}
public static String cleanDtoType(boolean referential, String fqn) {
return TypeTranslators.getTranslator(referential ? ReferentialDto.class : DataDto.class).cleanType(fqn);
}
public static String cleanDtoReferenceType(boolean referential, String fqn) {
return TypeTranslators.getTranslator(referential ? ReferentialDtoReference.class : DataDtoReference.class).cleanType(fqn);
}
}