Bläddra i källkod

avoid violating unique index, give each uninitialized device a unique name

tags/v0.1.8
Jonathan Cobb 4 år sedan
förälder
incheckning
284a06d4ba
2 ändrade filer med 6 tillägg och 6 borttagningar
  1. +2
    -3
      bubble-server/src/main/java/bubble/dao/device/DeviceDAO.java
  2. +4
    -3
      bubble-server/src/main/java/bubble/model/device/Device.java

+ 2
- 3
bubble-server/src/main/java/bubble/dao/device/DeviceDAO.java Visa fil

@@ -10,8 +10,7 @@ import java.io.File;
import java.util.List;

import static bubble.ApiConstants.HOME_DIR;
import static bubble.model.device.Device.UNINITIALIZED_DEVICE;
import static bubble.model.device.Device.newUninitializedDevice;
import static bubble.model.device.Device.*;
import static org.cobbzilla.util.io.FileUtil.abs;
import static org.cobbzilla.util.io.FileUtil.touch;

@@ -90,6 +89,6 @@ public class DeviceDAO extends AccountOwnedEntityDAO<Device> {
}

public List<Device> findByAccountAndUninitialized(String accountUuid) {
return findByFields("account", accountUuid, "name", UNINITIALIZED_DEVICE);
return findByFieldEqualAndFieldLike("account", accountUuid, "name", UNINITIALIZED_DEVICE_LIKE);
}
}

+ 4
- 3
bubble-server/src/main/java/bubble/model/device/Device.java Visa fil

@@ -37,6 +37,7 @@ public class Device extends IdentifiableBase implements HasAccount {
public static final String[] UPDATE_FIELDS = { "name", "enabled" };

public static final String UNINITIALIZED_DEVICE = "__uninitialized_device__";
public static final String UNINITIALIZED_DEVICE_LIKE = UNINITIALIZED_DEVICE+"%";

public Device (Device other) { copy(this, other, CREATE_FIELDS); }

@@ -44,7 +45,7 @@ public class Device extends IdentifiableBase implements HasAccount {

public static Device newUninitializedDevice(String networkUuid, String accountUuid) {
return new Device()
.setName(UNINITIALIZED_DEVICE)
.setName(UNINITIALIZED_DEVICE+randomUUID().toString())
.setNetwork(networkUuid)
.setAccount(accountUuid)
.initTotpKey();
@@ -52,7 +53,7 @@ public class Device extends IdentifiableBase implements HasAccount {

public static Device firstDeviceForNewNetwork(BubbleNetwork network) {
return new Device(randomUUID().toString())
.setName(UNINITIALIZED_DEVICE)
.setName(UNINITIALIZED_DEVICE+randomUUID().toString())
.setNetwork(network.getUuid())
.setAccount(network.getAccount())
.initTotpKey();
@@ -81,7 +82,7 @@ public class Device extends IdentifiableBase implements HasAccount {
@ECIndex @Column(nullable=false)
@Getter @Setter private Boolean enabled = true;

public boolean uninitialized () { return name.equals(UNINITIALIZED_DEVICE); }
public boolean uninitialized () { return name.startsWith(UNINITIALIZED_DEVICE); }
public boolean initialized () { return !uninitialized(); }

@ECSearchable @ECField(index=40)


Laddar…
Avbryt
Spara