From 2a6aa47b31e72e119b7d0fc65aa68fae8f02bab5 Mon Sep 17 00:00:00 2001 From: Armin Schrenk Date: Wed, 20 Mar 2024 16:16:22 +0100 Subject: [PATCH] migrate LegacyDevice to repository pattern --- .../cryptomator/hub/api/DeviceResource.java | 6 +++-- .../hub/api/LegacyDeviceRepository.java | 10 +++++++++ .../hub/entities/LegacyDevice.java | 22 ++++++++++++++++--- 3 files changed, 33 insertions(+), 5 deletions(-) create mode 100644 backend/src/main/java/org/cryptomator/hub/api/LegacyDeviceRepository.java diff --git a/backend/src/main/java/org/cryptomator/hub/api/DeviceResource.java b/backend/src/main/java/org/cryptomator/hub/api/DeviceResource.java index b351466ae..294cb050e 100644 --- a/backend/src/main/java/org/cryptomator/hub/api/DeviceResource.java +++ b/backend/src/main/java/org/cryptomator/hub/api/DeviceResource.java @@ -63,6 +63,8 @@ public class DeviceResource { DeviceRepository deviceRepo; @Inject LegacyAccessTokenRepository legacyAccessTokenRepo; + @Inject + LegacyDeviceRepository legacyDeviceRepo; @Inject JsonWebToken jwt; @@ -98,8 +100,8 @@ public Response createOrUpdate(@Valid @NotNull DeviceDto dto, @PathParam("device device.setCreationTime(Instant.now().truncatedTo(ChronoUnit.MILLIS)); device.setType(dto.type != null ? dto.type : Device.Type.DESKTOP); // default to desktop for backwards compatibilit); - if (LegacyDevice.deleteById(device.getId())) { - assert LegacyDevice.findById(device.getId()) == null; + if (legacyDeviceRepo.deleteById(device.getId())) { + assert legacyDeviceRepo.findById(device.getId()) == null; LOG.info("Deleted Legacy Device during re-registration of Device " + deviceId); } } diff --git a/backend/src/main/java/org/cryptomator/hub/api/LegacyDeviceRepository.java b/backend/src/main/java/org/cryptomator/hub/api/LegacyDeviceRepository.java new file mode 100644 index 000000000..bf2820d01 --- /dev/null +++ b/backend/src/main/java/org/cryptomator/hub/api/LegacyDeviceRepository.java @@ -0,0 +1,10 @@ +package org.cryptomator.hub.api; + +import io.quarkus.hibernate.orm.panache.PanacheRepositoryBase; +import jakarta.enterprise.context.ApplicationScoped; +import org.cryptomator.hub.entities.LegacyDevice; + +@ApplicationScoped +@Deprecated +public class LegacyDeviceRepository implements PanacheRepositoryBase { +} diff --git a/backend/src/main/java/org/cryptomator/hub/entities/LegacyDevice.java b/backend/src/main/java/org/cryptomator/hub/entities/LegacyDevice.java index 160b7907a..8369b172c 100644 --- a/backend/src/main/java/org/cryptomator/hub/entities/LegacyDevice.java +++ b/backend/src/main/java/org/cryptomator/hub/entities/LegacyDevice.java @@ -9,14 +9,30 @@ @Deprecated @Entity @Table(name = "device_legacy") -public class LegacyDevice extends PanacheEntityBase { +public class LegacyDevice { @Id @Column(name = "id", nullable = false) - public String id; + String id; @Column(name = "owner_id", nullable = false) - public String ownerId; + String ownerId; + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getOwnerId() { + return ownerId; + } + + public void setOwnerId(String ownerId) { + this.ownerId = ownerId; + } // Further attributes omitted, as they are no longer used. The above ones are exceptions, as they are referenced via JPQL for joining.