-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
author Andrei Bordak <[email protected]> 1733336210 +0400 committer Andrei Bordak <[email protected]> 1733990640 +0400 MODLD-594: Resource date fields MODLD-594: Remove unnecessary test MODLD-594: Extracted migration MODLD-594 MErge commit MODLD-594 MErge commit MODLD-594: Remove temp dependency MODLD-594: Redundant import
- Loading branch information
1 parent
a75ab33
commit 112ca64
Showing
11 changed files
with
210 additions
and
2 deletions.
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
...ain/java/org/folio/linked/data/configuration/jpa/audit/LinkedDataAuditEntityListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package org.folio.linked.data.configuration.jpa.audit; | ||
|
||
import static java.util.Optional.ofNullable; | ||
|
||
import jakarta.persistence.PrePersist; | ||
import lombok.AllArgsConstructor; | ||
import org.folio.linked.data.model.entity.Resource; | ||
import org.springframework.beans.factory.ObjectFactory; | ||
import org.springframework.data.auditing.AuditingHandler; | ||
import org.springframework.data.jpa.domain.support.AuditingEntityListener; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
@AllArgsConstructor | ||
public class LinkedDataAuditEntityListener extends AuditingEntityListener { | ||
|
||
private ObjectFactory<AuditingHandler> handler; | ||
|
||
@Override | ||
@PrePersist | ||
public void touchForCreate(Object target) { | ||
if (target instanceof Resource resource) { | ||
if (resource.getCreatedBy() == null) { | ||
ofNullable(handler.getObject()) | ||
.ifPresent(object -> object.markCreated(target)); | ||
} | ||
} | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/main/java/org/folio/linked/data/configuration/jpa/audit/LinkedDataAuditorAware.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package org.folio.linked.data.configuration.jpa.audit; | ||
|
||
import java.util.Optional; | ||
import java.util.UUID; | ||
import lombok.RequiredArgsConstructor; | ||
import org.folio.spring.FolioExecutionContext; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.data.domain.AuditorAware; | ||
import org.springframework.data.jpa.repository.config.EnableJpaAuditing; | ||
|
||
@Configuration | ||
@EnableJpaAuditing(modifyOnCreate = false) | ||
@RequiredArgsConstructor | ||
public class LinkedDataAuditorAware implements AuditorAware<UUID> { | ||
|
||
private final FolioExecutionContext folioExecutionContext; | ||
|
||
@Override | ||
public Optional<UUID> getCurrentAuditor() { | ||
return Optional.ofNullable(folioExecutionContext.getUserId()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
...in/resources/changelog/scripts/v-1.0.0/resource_graph/migration/resources_date_fields.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
alter table resources | ||
add column created_date timestamp default current_timestamp not null, | ||
add column updated_date timestamp default current_timestamp not null, | ||
add column created_by uuid, | ||
add column updated_by uuid, | ||
add column version int default 0 not null; | ||
|
||
comment on column resources.created_date is 'Date and time when resource first added to data graph'; | ||
comment on column resources.created_by is 'UUID of user who added resource to data graph'; | ||
comment on column resources.updated_date is 'Date and time when resource last updated'; | ||
comment on column resources.updated_by is 'UUID of user who performed the last update to the resource'; | ||
comment on column resources.version is 'Version of the resource'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.