Skip to content

Commit

Permalink
task: Rename eventProperty to eventField [DHIS2-18549] (#19373)
Browse files Browse the repository at this point in the history
  • Loading branch information
muilpp authored Dec 4, 2024
1 parent dc4e5d0 commit 890be96
Show file tree
Hide file tree
Showing 14 changed files with 156 additions and 174 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<many-to-one name="dataElement" class="org.hisp.dhis.dataelement.DataElement" column="dataelementid"
foreign-key="fk_eventchangelog_dataelementid" />

<property name="eventProperty" length="100" />
<property name="eventField" length="100" />

<property name="previousValue" length="50000" />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public void addDataValueChangeLog(

@Override
@Transactional
public void addPropertyChangeLog(
public void addFieldChangeLog(
@Nonnull Event currentEvent, @Nonnull Event event, @Nonnull String username) {
logIfChanged(
"occurredAt", Event::getOccurredDate, this::formatDate, currentEvent, event, username);
Expand Down Expand Up @@ -133,7 +133,7 @@ public Set<Pair<String, Class<?>>> getFilterableFields() {
}

private <T> void logIfChanged(
String propertyName,
String field,
Function<Event, T> valueExtractor,
Function<T, String> formatter,
Event currentEvent,
Expand All @@ -148,34 +148,27 @@ private <T> void logIfChanged(

EventChangeLog eventChangeLog =
new EventChangeLog(
event,
null,
propertyName,
currentValue,
newValue,
changeLogType,
new Date(),
userName);
event, null, field, currentValue, newValue, changeLogType, new Date(), userName);

hibernateEventChangeLogStore.addEventChangeLog(eventChangeLog);
}
}

private ChangeLogType getChangeLogType(String oldValue, String newValue) {
if (isNewProperty(oldValue, newValue)) {
if (isFieldCreated(oldValue, newValue)) {
return ChangeLogType.CREATE;
} else if (isUpdateProperty(oldValue, newValue)) {
} else if (isFieldUpdated(oldValue, newValue)) {
return ChangeLogType.UPDATE;
} else {
return ChangeLogType.DELETE;
}
}

private boolean isNewProperty(String originalValue, String payloadValue) {
private boolean isFieldCreated(String originalValue, String payloadValue) {
return originalValue == null && payloadValue != null;
}

private boolean isUpdateProperty(String originalValue, String payloadValue) {
private boolean isFieldUpdated(String originalValue, String payloadValue) {
return originalValue != null && payloadValue != null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public class EventChangeLog {

private DataElement dataElement;

private String eventProperty;
private String eventField;

private String previousValue;

Expand All @@ -63,40 +63,40 @@ public class EventChangeLog {
public EventChangeLog(
Event event,
DataElement dataElement,
String eventProperty,
String eventField,
String previousValue,
String currentValue,
ChangeLogType changeLogType,
Date created,
String createdByUsername) {
this(event, dataElement, eventProperty, previousValue, currentValue, changeLogType, created);
this(event, dataElement, eventField, previousValue, currentValue, changeLogType, created);
this.createdByUsername = createdByUsername;
}

public EventChangeLog(
Event event,
DataElement dataElement,
String eventProperty,
String eventField,
String previousValue,
String currentValue,
ChangeLogType changeLogType,
Date created,
UserInfoSnapshot createdBy) {
this(event, dataElement, eventProperty, previousValue, currentValue, changeLogType, created);
this(event, dataElement, eventField, previousValue, currentValue, changeLogType, created);
this.createdBy = createdBy;
}

private EventChangeLog(
Event event,
DataElement dataElement,
String eventProperty,
String eventField,
String previousValue,
String currentValue,
ChangeLogType changeLogType,
Date created) {
this.event = event;
this.dataElement = dataElement;
this.eventProperty = eventProperty;
this.eventField = eventField;
this.previousValue = previousValue;
this.currentValue = currentValue;
this.changeLogType = changeLogType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ void addDataValueChangeLog(
ChangeLogType changeLogType,
String userName);

void addPropertyChangeLog(
void addFieldChangeLog(
@Nonnull Event currentEvent, @Nonnull Event event, @Nonnull String userName);

void deleteTrackedEntityDataValueChangeLog(Event event);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public class HibernateEventChangeLogStore {
private static final String COLUMN_CHANGELOG_CREATED = "ecl.created";
private static final String COLUMN_CHANGELOG_USER = "ecl.createdByUsername";
private static final String COLUMN_CHANGELOG_DATA_ELEMENT = "d.uid";
private static final String COLUMN_CHANGELOG_PROPERTY = "ecl.eventProperty";
private static final String COLUMN_CHANGELOG_FIELD = "ecl.eventField";

private static final String DEFAULT_ORDER =
COLUMN_CHANGELOG_CREATED + " " + SortDirection.DESC.getValue();
Expand All @@ -73,13 +73,13 @@ public class HibernateEventChangeLogStore {
entry("createdAt", COLUMN_CHANGELOG_CREATED),
entry("username", COLUMN_CHANGELOG_USER),
entry("dataElement", COLUMN_CHANGELOG_DATA_ELEMENT),
entry("property", COLUMN_CHANGELOG_PROPERTY));
entry("field", COLUMN_CHANGELOG_FIELD));

private static final Map<Pair<String, Class<?>>, String> FILTERABLE_FIELDS =
Map.ofEntries(
entry(Pair.of("username", String.class), COLUMN_CHANGELOG_USER),
entry(Pair.of("dataElement", UID.class), COLUMN_CHANGELOG_DATA_ELEMENT),
entry(Pair.of("property", String.class), COLUMN_CHANGELOG_PROPERTY));
entry(Pair.of("field", String.class), COLUMN_CHANGELOG_FIELD));

private final EntityManager entityManager;

Expand All @@ -102,7 +102,7 @@ public Page<EventChangeLog> getEventChangeLogs(
"""
select ecl.event,
ecl.dataElement,
ecl.eventProperty,
ecl.eventField,
ecl.previousValue,
ecl.currentValue,
ecl.changeLogType,
Expand Down Expand Up @@ -147,7 +147,7 @@ public Page<EventChangeLog> getEventChangeLogs(
row -> {
Event e = (Event) row[0];
DataElement dataElement = (DataElement) row[1];
String eventProperty = (String) row[2];
String eventField = (String) row[2];
String previousValue = (String) row[3];
String currentValue = (String) row[4];
ChangeLogType changeLogType = (ChangeLogType) row[5];
Expand All @@ -160,7 +160,7 @@ public Page<EventChangeLog> getEventChangeLogs(
return new EventChangeLog(
e,
dataElement,
eventProperty,
eventField,
previousValue,
currentValue,
changeLogType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,6 @@ private Set<UID> validateTrackedEntityAttributes(TrackedEntity trackedEntity)
throw new NotFoundException(TrackedEntity.class, trackedEntity.getUid());
}

return attributes.stream().map(a -> UID.of(a.getUid())).collect(Collectors.toSet());
return attributes.stream().map(UID::of).collect(Collectors.toSet());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ protected void updateDataValues(
Event currentEntity,
UserDetails user) {
handleDataValues(entityManager, preheat, event.getDataValues(), payloadEntity, user);
eventChangeLogService.addPropertyChangeLog(currentEntity, payloadEntity, user.getUsername());
eventChangeLogService.addFieldChangeLog(currentEntity, payloadEntity, user.getUsername());
}

private void handleDataValues(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-- DHIS2-18549

alter table eventchangelog rename eventproperty to eventfield;
Loading

0 comments on commit 890be96

Please sign in to comment.