Skip to content

Commit

Permalink
Log tracking of unknown fields during code generation
Browse files Browse the repository at this point in the history
Addresses RM-20853
  • Loading branch information
pdo-axelor authored and admin committed Sep 19, 2019
1 parent 3cfa027 commit 37eb656
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -596,4 +596,8 @@ class Entity {
def names = fields.collect { it.name }
return "Entity(name: $name, fields: $names)"
}

public Track getTrack() {
return track;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class Track {
private List<Annotation> fields = []
private List<Annotation> messages = []
private List<Annotation> contents = []
private List<Annotation> names = []

private Set<String> imports = []

Expand Down Expand Up @@ -69,6 +70,7 @@ class Track {
String condition = node.'@if'

imports += ['com.axelor.db.annotations.TrackField']
names += name

def annon = new Annotation(this.entity, "TrackField")
.add("name", name)
Expand Down Expand Up @@ -138,4 +140,8 @@ class Track {
track.merge(this);
return track;
}

List<String> getNames() {
return names;
}
}
12 changes: 12 additions & 0 deletions axelor-gradle/src/main/java/com/axelor/tools/x2j/Generator.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import java.util.HashSet;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.function.Function;
import org.slf4j.Logger;
Expand Down Expand Up @@ -173,6 +174,17 @@ private List<File> render(Collection<Entity> items, boolean doLookup) throws IOE
entity.merge(it);
}

Optional.ofNullable(entity.getTrack())
.ifPresent(
track ->
track
.getNames()
.stream()
.filter(trackName -> !entity.getPropertyMap().keySet().contains(trackName))
.forEach(
trackName ->
log.error("{}: track unknown field: {}", entity.getName(), trackName)));

entityFile.getParentFile().mkdirs();
if (repoFile != null) {
repoFile.getParentFile().mkdirs();
Expand Down
3 changes: 3 additions & 0 deletions changelogs/unreleased/log-unknown-tracked-fields.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
title: Log tracking of unknown fields during code generation
type: feature

0 comments on commit 37eb656

Please sign in to comment.