use of de.symeda.sormas.api.feature.FeatureType in project SORMAS-Project by hzi-braunschweig.
the class ImportFacadeEjb method appendListOfFields.
/**
* Builds a list of all fields in the case and its relevant sub entities. IMPORTANT: The order
* is not guaranteed; at the time of writing, clazz.getDeclaredFields() seems to return the
* fields in the order of declaration (which is what we need here), but that could change
* in the future.
*/
private void appendListOfFields(List<ImportColumn> importColumns, Class<?> clazz, String prefix, char separator) {
for (Field field : clazz.getDeclaredFields()) {
if (Modifier.isStatic(field.getModifiers())) {
continue;
}
String currentCountry = configFacade.getCountryCode();
CountryFieldVisibilityChecker visibilityChecker = new CountryFieldVisibilityChecker(currentCountry);
if (!visibilityChecker.isVisible(field)) {
continue;
}
Method readMethod;
try {
readMethod = clazz.getDeclaredMethod("get" + WordUtils.capitalize(field.getName()));
} catch (NoSuchMethodException e) {
try {
readMethod = clazz.getDeclaredMethod("is" + WordUtils.capitalize(field.getName()));
} catch (NoSuchMethodException f) {
continue;
}
}
// Fields without a getter or whose getters are declared in a superclass are ignored
if (readMethod.getDeclaringClass() != clazz) {
continue;
}
// Fields with the @ImportIgnore annotation are ignored
if (readMethod.isAnnotationPresent(ImportIgnore.class)) {
continue;
}
// Fields that are depending on a certain feature type to be active may be ignored
if (readMethod.isAnnotationPresent(DependingOnFeatureType.class)) {
List<FeatureType> activeServerFeatures = featureConfigurationFacade.getActiveServerFeatureTypes();
if (!activeServerFeatures.isEmpty() && !activeServerFeatures.contains(readMethod.getAnnotation(DependingOnFeatureType.class).featureType())) {
continue;
}
}
// List types are ignored
if (Collection.class.isAssignableFrom(field.getType())) {
continue;
}
// Certain field types are ignored
if (field.getType() == UserReferenceDto.class) {
continue;
}
// Other non-infrastructure EntityDto/ReferenceDto classes, recursively call this method to include fields of the sub-entity
if (EntityDto.class.isAssignableFrom(field.getType()) && !isInfrastructureClass(field.getType())) {
appendListOfFields(importColumns, field.getType(), StringUtils.isEmpty(prefix) ? field.getName() + "." : prefix + field.getName() + ".", separator);
} else if (PersonReferenceDto.class.isAssignableFrom(field.getType()) && !isInfrastructureClass(field.getType())) {
appendListOfFields(importColumns, PersonDto.class, StringUtils.isEmpty(prefix) ? field.getName() + "." : prefix + field.getName() + ".", separator);
addPrimaryPhoneAndEmail(separator, importColumns);
} else {
importColumns.add(ImportColumn.from(clazz, prefix + field.getName(), field.getType(), separator));
}
}
}
use of de.symeda.sormas.api.feature.FeatureType in project SORMAS-Project by hzi-braunschweig.
the class FeatureConfigurationFacadeEjb method getActiveServerFeatureTypes.
@Override
public List<FeatureType> getActiveServerFeatureTypes() {
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<FeatureType> cq = cb.createQuery(FeatureType.class);
Root<FeatureConfiguration> root = cq.from(FeatureConfiguration.class);
List<FeatureType> serverFeatures = FeatureType.getAllServerFeatures();
if (serverFeatures.isEmpty()) {
return null;
}
cq.where(cb.and(root.get(FeatureConfiguration.FEATURE_TYPE).in(serverFeatures), cb.isTrue(root.get(FeatureConfiguration.ENABLED))));
cq.select(root.get(FeatureConfiguration.FEATURE_TYPE));
return em.createQuery(cq).getResultList();
}
Aggregations