Skip to content

Commit

Permalink
MODFQMMGR-267 Only replace defined entity types when initializing
Browse files Browse the repository at this point in the history
This commit changes the entity type initialization process, so that only
the entity types that are defined in JSON files are replaced. Any that
are in the DB, but aren't defined in JSON files, will be left untouched.
This prevents a non-deterministic test failure (in
FqlToSqlConverterServiceIT) and also allows for custom entity types
  • Loading branch information
mweaver-ebsco committed Apr 17, 2024
1 parent 0acdeed commit ada5dfa
Showing 1 changed file with 20 additions and 13 deletions.
33 changes: 20 additions & 13 deletions src/main/java/org/folio/fqm/repository/EntityTypeRepository.java
Expand Up @@ -86,21 +86,28 @@ public List<RawEntityTypeSummary> getEntityTypeSummary(Set<UUID> entityTypeIds)
.map(row -> new RawEntityTypeSummary(row.get(idField), row.get(nameField)));
}

public void replaceEntityTypeDefinitions(List<EntityType> entityTypes) throws JsonProcessingException {
public void replaceEntityTypeDefinitions(List<EntityType> entityTypes) {
log.info("Replacing entity type definitions with new set of {} entities", entityTypes.size());

// we use this instead of truncate since it has better rollback support
jooqContext.deleteFrom(table(TABLE_NAME)).execute();

InsertValuesStep2<Record, UUID, JSONB> insert = jooqContext
.insertInto(table(TABLE_NAME))
.columns(field(ID_FIELD_NAME, UUID.class), field(DEFINITION_FIELD_NAME, JSONB.class));

for (EntityType entityType : entityTypes) {
insert.values(UUID.fromString(entityType.getId()), JSONB.jsonb(objectMapper.writeValueAsString(entityType)));
}

insert.execute();
jooqContext.transaction(transaction -> {
transaction.dsl()
.deleteFrom(table(TABLE_NAME))
.where(
field(ID_FIELD_NAME, UUID.class)
.in(entityTypes.stream().map(et -> UUID.fromString(et.getId())).toList())
)
.execute();

InsertValuesStep2<Record, UUID, JSONB> insert = transaction.dsl()
.insertInto(table(TABLE_NAME))
.columns(field(ID_FIELD_NAME, UUID.class), field(DEFINITION_FIELD_NAME, JSONB.class));

for (EntityType entityType : entityTypes) {
insert.values(UUID.fromString(entityType.getId()), JSONB.jsonb(objectMapper.writeValueAsString(entityType)));
}

insert.execute();
});
}

private List<EntityTypeColumn> fetchColumnNamesForCustomFields(UUID entityTypeId) {
Expand Down

0 comments on commit ada5dfa

Please sign in to comment.