Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/Property.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ public class Property implements Ordered, Klass {
*/
private boolean persisted;

private boolean isTransient;

/** Name of collection wrapper. */
private String collectionName;

Expand Down Expand Up @@ -329,6 +331,16 @@ public void setPersisted(boolean persisted) {
this.persisted = persisted;
}

@JsonProperty
@JacksonXmlProperty(namespace = DxfNamespaces.DXF_2_0)
public boolean isTransient() {
return isTransient;
}

public void setTransient(boolean isTransient) {
this.isTransient = isTransient;
}

@JsonProperty
@JacksonXmlProperty(namespace = DxfNamespaces.DXF_2_0)
public String getCollectionName() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.ArrayList;
Expand All @@ -69,6 +70,7 @@
import org.hisp.dhis.schema.Property;
import org.hisp.dhis.schema.SchemaService;
import org.hisp.dhis.system.util.ReflectionUtils;
import org.hisp.dhis.translation.Translatable;
import org.springframework.util.ClassUtils;

/**
Expand All @@ -94,7 +96,7 @@
*/
public class JacksonPropertyIntrospector implements PropertyIntrospector {
@Override
public void introspect(Class<?> type, Map<String, Property> properties) {

Check failure on line 99 in dhis-2/dhis-services/dhis-service-schema/src/main/java/org/hisp/dhis/schema/introspection/JacksonPropertyIntrospector.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Refactor this method to reduce its Cognitive Complexity from 20 to the 15 allowed.

See more on https://sonarcloud.io/project/issues?id=dhis2_dhis2-core&issues=AZ9-hFMTRLmHBnfB9aOG&open=AZ9-hFMTRLmHBnfB9aOG&pullRequest=24474
Map<String, Property> persistedProperties = new HashMap<>(properties);
properties.clear();
Set<String> classFieldNames = ReflectionUtils.getAllFieldNames(type);
Expand All @@ -115,6 +117,20 @@

if (persistedProperties.containsKey(fieldName)) {
initFromPersistedProperty(property, persistedProperties.get(fieldName));
} else {
Method getter = property.getGetterMethod();
if (getter != null) {
Class<?> declaringClass = getter.getDeclaringClass();
if (declaringClass.getName().startsWith("Base")
&& !property.isTransient()
&& (!getter.isAnnotationPresent(Translatable.class)
|| !persistedProperties.containsKey(
getter.getAnnotation(Translatable.class).propertyName()))) {
// this is assumed to be an inherited property that is not persisted,
// so we skip it and do not add it
continue;
}
}
}

initFromDescription(property);
Expand Down Expand Up @@ -222,6 +238,7 @@
private static void initFromPersistedProperty(Property property, Property persisted) {
property.setPersisted(true);
property.setWritable(true);
property.setTransient(false);
property.setFieldName(persisted.getFieldName());
property.setUnique(persisted.isUnique());
property.setRequired(persisted.isRequired());
Expand Down Expand Up @@ -329,6 +346,7 @@

property.setName(name);
property.setFieldName(fieldName);
property.setTransient(Modifier.isTransient(field.getModifiers()));
property.setSetterMethod(findSetterMethod(fieldName, type, field.getType()));
property.setGetterMethod(findGetterMethod(fieldName, type));
property.setNamespace(trimToNull(jsonProperty.namespace()));
Expand Down
Loading