fr.ird.observe.spi.ProjectPackagesDefinition Maven / Gradle / Ivy
Show all versions of common-dto Show documentation
package fr.ird.observe.spi;
/*-
* #%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 org.apache.commons.lang3.StringUtils;
/**
* Represents some packages used in a project.
*
* Mainly the dto package, entity package Created on 25/07/19.
*
* @author Tony Chemit - [email protected]
* @since ?
*/
public interface ProjectPackagesDefinition {
String getDtoRootPackage();
String getDtoReferentialPackage();
String getDtoDataPackage();
String getEntityRootPackage();
String getEntityReferentialPackage();
String getEntityDataPackage();
default boolean isReferential(Class type) {
return isReferentialFromPackageName(type.getPackage().getName());
}
default boolean isReferentialFromPackageName(String packageName) {
return packageName.startsWith(getDtoReferentialPackage());
}
default boolean isData(Class type) {
return isDataFromPackageName(type.getPackage().getName());
}
default boolean isDataFromPackageName(String packageName) {
return packageName.startsWith(getDtoDataPackage());
}
default String getRelativeDtoPackage(String dtoClassName) {
return StringUtils.removeStart(dtoClassName, getDtoRootPackage());
}
default String getRelativeEntityPackage(String dtoClassName) {
return StringUtils.removeStart(dtoClassName, getEntityRootPackage());
}
static String cleanType(String fqn) {
if (fqn.endsWith("Dto")) {
return fqn.substring(0, fqn.length() - 3);
}
if (fqn.endsWith("Reference")) {
return fqn.substring(0, fqn.length() - 9);
}
// for entity, hibernate proxy gives use some class name like Entity_xxx
int index = fqn.indexOf("_");
if (index > -1) {
fqn = fqn.substring(0, index);
} else {
// for entity, hibernate
index = fqn.indexOf("@");
if (index > -1) {
fqn = fqn.substring(0, index);
}
}
if (fqn.endsWith("Impl")) {
return fqn.substring(0, fqn.length() - 4);
}
return fqn;
}
}