Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Capture addl metadata on generation invocations #933

Merged
merged 1 commit into from
Jun 26, 2024
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
14 changes: 9 additions & 5 deletions api/app/controllers/Code.scala
Original file line number Diff line number Diff line change
Expand Up @@ -151,17 +151,19 @@ class Code @Inject() (
// TODO: Should we merge the org attributes into the provided invocation form? I think that
// was the original intent, but not sure if it would impact anybody. For now going to log
// the instance for which this results in a change.
/*
val updatedAttributes = orgAttributeUtil.merge(data.version.organization, gws.generator.attributes, data.invocationForm.attributes)
if (updatedAttributes != data.invocationForm.attributes) {
val newAttributes = updatedAttributes.filterNot { a =>
data.invocationForm.attributes.map(_.name).contains(a.name)
}.mkString(", ")
//println(s"Code.orgAttributes org[${data.version.organization.key}] newAttributes: $newAttributes")
println(s"Code.orgAttributes org[${data.version.organization.key}] newAttributes: $newAttributes")
} else {
//println(s"Code.orgAttributes org[${data.version.organization.key}] newAttributes: NONE")
println(s"Code.orgAttributes org[${data.version.organization.key}] newAttributes: NONE")
}
*/

recordInvocation(gws.generator.key)
recordInvocation(params, gws.generator.key)

new Client(wSClient, service.uri).invocations.postByKey(
key = gws.generator.key,
Expand Down Expand Up @@ -224,9 +226,11 @@ class Code @Inject() (
Conflict(Json.toJson(Validation.errors(messages)))
}

private[this] def recordInvocation(generatorKey: String): Unit = {
private[this] def recordInvocation(params: CodeParams, generatorKey: String): Unit = {
generatorInvocationsDao.insert(Constants.DefaultUserGuid, GeneratorInvocationForm(
key = generatorKey
key = generatorKey,
organizationKey = Some(params.orgKey),
applicationKey = Some(params.applicationKey)
))
()
}
Expand Down
54 changes: 37 additions & 17 deletions api/app/db/generated/PsqlApibuilderGeneratorInvocationsDao.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,25 @@ import play.api.db.Database
case class GeneratorInvocation(
id: String,
key: String,
organizationKey: Option[String],
applicationKey: Option[String],
updatedByGuid: String,
createdAt: DateTime,
updatedAt: DateTime
) {

lazy val form: GeneratorInvocationForm = GeneratorInvocationForm(
key = key
key = key,
organizationKey = organizationKey,
applicationKey = applicationKey
)

}

case class GeneratorInvocationForm(
key: String
key: String,
organizationKey: Option[String],
applicationKey: Option[String]
)

object GeneratorInvocationsTable {
Expand All @@ -35,11 +41,13 @@ object GeneratorInvocationsTable {
object Columns {
val Id: String = "id"
val Key: String = "key"
val OrganizationKey: String = "organization_key"
val ApplicationKey: String = "application_key"
val UpdatedByGuid: String = "updated_by_guid"
val CreatedAt: String = "created_at"
val UpdatedAt: String = "updated_at"
val HashCode: String = "hash_code"
val all: List[String] = List(Id, Key, UpdatedByGuid, CreatedAt, UpdatedAt, HashCode)
val all: List[String] = List(Id, Key, OrganizationKey, ApplicationKey, UpdatedByGuid, CreatedAt, UpdatedAt, HashCode)
}
}

Expand All @@ -50,6 +58,8 @@ trait BaseGeneratorInvocationsDao {
private[this] val BaseQuery = Query("""
| select generator_invocations.id,
| generator_invocations.key,
| generator_invocations.organization_key,
| generator_invocations.application_key,
| generator_invocations.updated_by_guid,
| generator_invocations.created_at,
| generator_invocations.updated_at,
Expand Down Expand Up @@ -132,12 +142,16 @@ object GeneratorInvocationsDao {
val parser: RowParser[GeneratorInvocation] = {
SqlParser.str("id") ~
SqlParser.str("key") ~
SqlParser.str("organization_key").? ~
SqlParser.str("application_key").? ~
SqlParser.str("updated_by_guid") ~
SqlParser.get[DateTime]("created_at") ~
SqlParser.get[DateTime]("updated_at") map {
case id ~ key ~ updatedByGuid ~ createdAt ~ updatedAt => GeneratorInvocation(
case id ~ key ~ organizationKey ~ applicationKey ~ updatedByGuid ~ createdAt ~ updatedAt => GeneratorInvocation(
id = id,
key = key,
organizationKey = organizationKey,
applicationKey = applicationKey,
updatedByGuid = updatedByGuid,
createdAt = createdAt,
updatedAt = updatedAt
Expand All @@ -158,14 +172,16 @@ class GeneratorInvocationsDao @Inject() (

private[this] val InsertQuery = Query("""
| insert into generator_invocations
| (id, key, updated_by_guid, hash_code)
| (id, key, organization_key, application_key, updated_by_guid, hash_code)
| values
| ({id}, {key}, {updated_by_guid}, {hash_code}::bigint)
| ({id}, {key}, {organization_key}, {application_key}, {updated_by_guid}, {hash_code}::bigint)
""".stripMargin)

private[this] val UpdateQuery = Query("""
| update generator_invocations
| set key = {key},
| organization_key = {organization_key},
| application_key = {application_key},
| updated_by_guid = {updated_by_guid},
| hash_code = {hash_code}::bigint
| where id = {id}
Expand All @@ -175,15 +191,19 @@ class GeneratorInvocationsDao @Inject() (
private[this] def bindQuery(query: Query, form: GeneratorInvocationForm): Query = {
query.
bind("key", form.key).
bind("organization_key", form.organizationKey).
bind("application_key", form.applicationKey).
bind("hash_code", form.hashCode())
}

private[this] def toNamedParameter(updatedBy: UUID, id: String, form: GeneratorInvocationForm): Seq[NamedParameter] = {
Seq(
scala.Symbol("id") -> id,
scala.Symbol("key") -> form.key,
scala.Symbol("updated_by_guid") -> updatedBy,
scala.Symbol("hash_code") -> form.hashCode()
"id" -> id,
"key" -> form.key,
"organization_key" -> form.organizationKey,
"application_key" -> form.applicationKey,
"updated_by_guid" -> updatedBy,
"hash_code" -> form.hashCode()
)
}

Expand All @@ -198,7 +218,7 @@ class GeneratorInvocationsDao @Inject() (
bindQuery(InsertQuery, form).
bind("id", id).
bind("updated_by_guid", updatedBy).
anormSql.execute()(c)
anormSql().execute()(c)
id
}

Expand Down Expand Up @@ -235,7 +255,7 @@ class GeneratorInvocationsDao @Inject() (
bindQuery(UpdateQuery, form).
bind("id", id).
bind("updated_by_guid", updatedBy).
anormSql.execute()(c)
anormSql().execute()(c)
()
}

Expand Down Expand Up @@ -283,8 +303,8 @@ class GeneratorInvocationsDao @Inject() (
setJournalDeletedByUserId(c, deletedBy)
Query("delete from generator_invocations")
.equals("id", id)
.anormSql.executeUpdate()(c)
()
.anormSql().executeUpdate()(c)
()
}

def deleteAllByIds(deletedBy: UUID, ids: Seq[String]): Unit = {
Expand All @@ -297,12 +317,12 @@ class GeneratorInvocationsDao @Inject() (
setJournalDeletedByUserId(c, deletedBy)
Query("delete from generator_invocations")
.in("id", ids)
.anormSql.executeUpdate()(c)
()
.anormSql().executeUpdate()(c)
()
}

def setJournalDeletedByUserId(c: Connection, deletedBy: UUID): Unit = {
anorm.SQL(s"SET journal.deleted_by_user_id = '${deletedBy}'").executeUpdate()(c)
Query(s"SET journal.deleted_by_user_id = '${deletedBy}'").anormSql().executeUpdate()(c)
()
}

Expand Down
68 changes: 34 additions & 34 deletions api/app/db/generated/PsqlApibuilderTasksDao.scala
Original file line number Diff line number Diff line change
Expand Up @@ -360,17 +360,17 @@ class TasksDao @Inject() (

private[this] def toNamedParameter(updatedBy: UUID, form: TaskForm): Seq[NamedParameter] = {
Seq(
scala.Symbol("id") -> form.id,
scala.Symbol("type") -> form.`type`,
scala.Symbol("type_id") -> form.typeId,
scala.Symbol("organization_guid") -> form.organizationGuid,
scala.Symbol("num_attempts") -> form.numAttempts,
scala.Symbol("next_attempt_at") -> form.nextAttemptAt,
scala.Symbol("errors") -> form.errors.map { v => Json.toJson(v).toString },
scala.Symbol("stacktrace") -> form.stacktrace,
scala.Symbol("data") -> form.data.toString,
scala.Symbol("updated_by_guid") -> updatedBy,
scala.Symbol("hash_code") -> form.hashCode()
"id" -> form.id,
"type" -> form.`type`,
"type_id" -> form.typeId,
"organization_guid" -> form.organizationGuid,
"num_attempts" -> form.numAttempts,
"next_attempt_at" -> form.nextAttemptAt,
"errors" -> form.errors.map { v => Json.toJson(v).toString },
"stacktrace" -> form.stacktrace,
"data" -> form.data.toString,
"updated_by_guid" -> updatedBy,
"hash_code" -> form.hashCode()
)
}

Expand All @@ -390,7 +390,7 @@ class TasksDao @Inject() (
bindQuery(UpsertQuery, form).
bind("id", form.id).
bind("updated_by_guid", updatedBy).
anormSql.execute()(c)
anormSql().execute()(c)
()
}

Expand Down Expand Up @@ -424,7 +424,7 @@ class TasksDao @Inject() (
bindQuery(UpdateQuery, form).
bind("id", id).
bind("updated_by_guid", updatedBy).
anormSql.execute()(c)
anormSql().execute()(c)
()
}

Expand Down Expand Up @@ -472,8 +472,8 @@ class TasksDao @Inject() (
setJournalDeletedByUserId(c, deletedBy)
Query("delete from tasks")
.equals("id", id)
.anormSql.executeUpdate()(c)
()
.anormSql().executeUpdate()(c)
()
}

def deleteAllByIds(deletedBy: UUID, ids: Seq[String]): Unit = {
Expand All @@ -486,8 +486,8 @@ class TasksDao @Inject() (
setJournalDeletedByUserId(c, deletedBy)
Query("delete from tasks")
.in("id", ids)
.anormSql.executeUpdate()(c)
()
.anormSql().executeUpdate()(c)
()
}

def deleteAllByNumAttempts(deletedBy: UUID, numAttempts: Int): Unit = {
Expand All @@ -500,8 +500,8 @@ class TasksDao @Inject() (
setJournalDeletedByUserId(c, deletedBy)
Query("delete from tasks")
.equals("num_attempts", numAttempts)
.anormSql.executeUpdate()(c)
()
.anormSql().executeUpdate()(c)
()
}

def deleteAllByNumAttemptses(deletedBy: UUID, numAttemptses: Seq[Int]): Unit = {
Expand All @@ -514,8 +514,8 @@ class TasksDao @Inject() (
setJournalDeletedByUserId(c, deletedBy)
Query("delete from tasks")
.in("num_attempts", numAttemptses)
.anormSql.executeUpdate()(c)
()
.anormSql().executeUpdate()(c)
()
}

def deleteAllByNumAttemptsAndNextAttemptAt(deletedBy: UUID, numAttempts: Int, nextAttemptAt: DateTime): Unit = {
Expand All @@ -529,8 +529,8 @@ class TasksDao @Inject() (
Query("delete from tasks")
.equals("num_attempts", numAttempts)
.equals("next_attempt_at", nextAttemptAt)
.anormSql.executeUpdate()(c)
()
.anormSql().executeUpdate()(c)
()
}

def deleteAllByNumAttemptsAndNextAttemptAts(deletedBy: UUID, numAttempts: Int, nextAttemptAts: Seq[DateTime]): Unit = {
Expand All @@ -544,8 +544,8 @@ class TasksDao @Inject() (
Query("delete from tasks")
.equals("num_attempts", numAttempts)
.in("next_attempt_at", nextAttemptAts)
.anormSql.executeUpdate()(c)
()
.anormSql().executeUpdate()(c)
()
}

def deleteAllByTypeId(deletedBy: UUID, typeId: String): Unit = {
Expand All @@ -558,8 +558,8 @@ class TasksDao @Inject() (
setJournalDeletedByUserId(c, deletedBy)
Query("delete from tasks")
.equals("type_id", typeId)
.anormSql.executeUpdate()(c)
()
.anormSql().executeUpdate()(c)
()
}

def deleteAllByTypeIds(deletedBy: UUID, typeIds: Seq[String]): Unit = {
Expand All @@ -572,8 +572,8 @@ class TasksDao @Inject() (
setJournalDeletedByUserId(c, deletedBy)
Query("delete from tasks")
.in("type_id", typeIds)
.anormSql.executeUpdate()(c)
()
.anormSql().executeUpdate()(c)
()
}

def deleteByTypeIdAndType(deletedBy: UUID, typeId: String, `type`: String): Unit = {
Expand All @@ -587,8 +587,8 @@ class TasksDao @Inject() (
Query("delete from tasks")
.equals("type_id", typeId)
.equals("type", `type`)
.anormSql.executeUpdate()(c)
()
.anormSql().executeUpdate()(c)
()
}

def deleteAllByTypeIdAndTypes(deletedBy: UUID, typeId: String, types: Seq[String]): Unit = {
Expand All @@ -602,12 +602,12 @@ class TasksDao @Inject() (
Query("delete from tasks")
.equals("type_id", typeId)
.in("type", types)
.anormSql.executeUpdate()(c)
()
.anormSql().executeUpdate()(c)
()
}

def setJournalDeletedByUserId(c: Connection, deletedBy: UUID): Unit = {
anorm.SQL(s"SET journal.deleted_by_user_id = '${deletedBy}'").executeUpdate()(c)
Query(s"SET journal.deleted_by_user_id = '${deletedBy}'").anormSql().executeUpdate()(c)
()
}

Expand Down
Loading
Loading