Skip to content

Commit

Permalink
feat: add missing relationships to entities
Browse files Browse the repository at this point in the history
  • Loading branch information
borisrizov-zf committed Feb 9, 2024
1 parent 103e7f2 commit 56a48eb
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ public class Wallet extends MIWBaseEntity {
@Convert(converter = StringToDidDocumentConverter.class)
private DidDocument didDocument;

@OneToMany(mappedBy = "wallet", cascade = CascadeType.ALL, orphanRemoval = true)
private List<WalletKey> walletKeys;

@Transient
private List<VerifiableCredential> verifiableCredentials;
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,20 @@
package org.eclipse.tractusx.managedidentitywallets.dao.entity;

import com.fasterxml.jackson.annotation.JsonIgnore;
import jakarta.persistence.*;
import lombok.*;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.MapsId;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.eclipse.tractusx.managedidentitywallets.domain.KeyPair;

/**
* The type Wallet key.
Expand All @@ -42,9 +54,6 @@ public class WalletKey extends MIWBaseEntity {
@Column(name = "id", columnDefinition = "serial", nullable = false, unique = true)
private Long id;

@Column(nullable = false)
private Long walletId;

@Column(nullable = false)
private String vaultAccessToken;

Expand All @@ -57,5 +66,14 @@ public class WalletKey extends MIWBaseEntity {
@Column(nullable = false)
private String publicKey;

@ManyToOne
@MapsId
@JoinColumn(name = "walletId", columnDefinition = "bigint")
private Wallet wallet;

private String keyId;

public KeyPair toDto() {
return new KeyPair(keyId, privateKey, publicKey);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
package org.eclipse.tractusx.managedidentitywallets.dao.repository;

import com.smartsensesolutions.java.commons.base.repository.BaseRepository;
import org.eclipse.tractusx.managedidentitywallets.dao.entity.Wallet;
import org.eclipse.tractusx.managedidentitywallets.dao.entity.WalletKey;
import org.springframework.stereotype.Repository;

Expand All @@ -37,4 +38,8 @@ public interface WalletKeyRepository extends BaseRepository<WalletKey, Long> {
* @return the by wallet id
*/
WalletKey getByWalletId(Long id);

WalletKey findFirstByWallet_Bpn(String bpn);

WalletKey findFirstByWallet_Did(String did);
}
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ private Wallet createWallet(CreateWalletRequest request, boolean authority, Stri

//Save key
walletKeyService.getRepository().save(WalletKey.builder()
.walletId(wallet.getId())
.wallet(wallet)
.keyId(keyId)
.referenceKey("dummy ref key, removed once vault setup is ready")
.vaultAccessToken("dummy vault access token, removed once vault setup is ready")
Expand Down

0 comments on commit 56a48eb

Please sign in to comment.