Skip to content

Commit

Permalink
:enh: updating modifedBy and modifiedOn fields when upating Device's …
Browse files Browse the repository at this point in the history
…last Event reference, as they will not be automatically updated by the @PreUpdate action in this case

Signed-off-by: dseurotech <[email protected]>
  • Loading branch information
dseurotech committed Jan 23, 2024
1 parent 735aa2e commit 476c8c3
Showing 1 changed file with 3 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.eclipse.kapua.commons.jpa.KapuaJpaRepositoryConfiguration;
import org.eclipse.kapua.commons.jpa.KapuaUpdatableEntityJpaRepository;
import org.eclipse.kapua.commons.model.id.KapuaEid;
import org.eclipse.kapua.commons.security.KapuaSecurityUtils;
import org.eclipse.kapua.model.id.KapuaId;
import org.eclipse.kapua.service.device.registry.Device;
import org.eclipse.kapua.service.device.registry.DeviceAttributes;
Expand Down Expand Up @@ -59,6 +60,8 @@ public void updateLastEvent(TxContext tx, KapuaId scopeId, KapuaId deviceId, Kap
final Root<DeviceImpl> root = update.from(DeviceImpl.class);
final Join<DeviceImpl, DeviceEventImpl> lastEventJoin = root.join(DeviceImpl_.lastEvent, JoinType.LEFT);
update.set(root.get(DeviceImpl_.lastEventId), KapuaEid.parseKapuaId(deviceEventId));
update.set(root.get(DeviceImpl_.modifiedBy), KapuaEid.parseKapuaId(KapuaSecurityUtils.getSession().getUserId()));
update.set(root.get(DeviceImpl_.modifiedOn), new Date());
update.where(
cb.and(
cb.equal(root.get(DeviceImpl_.scopeId), KapuaEid.parseKapuaId(scopeId)),
Expand Down

0 comments on commit 476c8c3

Please sign in to comment.