Search in sources :

Example 1 with UserProfile

use of com.palantir.example.profile.protos.generated.ProfilePersistence.UserProfile in project atlasdb by palantir.

the class ProfileStoreTest method storeUser.

private UUID storeUser() {
    return runWithRetry(store -> {
        UUID userId = store.storeNewUser(USER);
        UserProfile storedData = store.getUserData(userId);
        Assert.assertEquals(USER, storedData);
        return userId;
    });
}
Also used : UserProfile(com.palantir.example.profile.protos.generated.ProfilePersistence.UserProfile) UUID(java.util.UUID)

Example 2 with UserProfile

use of com.palantir.example.profile.protos.generated.ProfilePersistence.UserProfile in project atlasdb by palantir.

the class ProfileStoreTest method testStore.

@Test
public void testStore() {
    final UUID userId = storeUser();
    runWithRetry(store -> {
        UserProfile storedData = store.getUserData(userId);
        Assert.assertEquals(USER, storedData);
        return userId;
    });
}
Also used : UserProfile(com.palantir.example.profile.protos.generated.ProfilePersistence.UserProfile) UUID(java.util.UUID) Test(org.junit.Test)

Example 3 with UserProfile

use of com.palantir.example.profile.protos.generated.ProfilePersistence.UserProfile in project atlasdb by palantir.

the class ProfileStoreTest method storeImage.

private void storeImage(final UUID userId) {
    runWithRetry(store -> {
        Sha256Hash imageHash = Sha256Hash.computeHash(IMAGE);
        store.updateImage(userId, imageHash, new ByteArrayInputStream(IMAGE));
        UserProfile storedData = store.getUserData(userId);
        Assert.assertEquals(USER, storedData);
        return null;
    });
}
Also used : UserProfile(com.palantir.example.profile.protos.generated.ProfilePersistence.UserProfile) ByteArrayInputStream(java.io.ByteArrayInputStream) Sha256Hash(com.palantir.util.crypto.Sha256Hash)

Example 4 with UserProfile

use of com.palantir.example.profile.protos.generated.ProfilePersistence.UserProfile in project atlasdb by palantir.

the class ProfileStore method updateImage.

public void updateImage(UUID userId, Sha256Hash hash, InputStream imageData) {
    UserProfile userData = getUserData(userId);
    Preconditions.checkNotNull(userData, "userData cannot be null");
    UserPhotosStreamStore streamStore = UserPhotosStreamStore.of(txnMgr, tables);
    Long oldStreamId = getPhotoStreamId(userId);
    if (oldStreamId != null) {
        // Unmark old stream before we overwrite it.
        streamStore.unmarkStreamAsUsed(tx, oldStreamId, EncodingUtils.encodeUUID(userId));
    }
    // This will either store a new stream and mark it as used
    // or return an old stream that matches the hash and mark it as used.
    long streamId = streamStore.getByHashOrStoreStreamAndMarkAsUsed(tx, hash, imageData, EncodingUtils.encodeUUID(userId));
    UserProfileTable table = tables.getUserProfileTable(tx);
    table.putPhotoStreamId(UserProfileRow.of(userId), streamId);
}
Also used : UserPhotosStreamStore(com.palantir.example.profile.schema.generated.UserPhotosStreamStore) UserProfileTable(com.palantir.example.profile.schema.generated.UserProfileTable) UserProfile(com.palantir.example.profile.protos.generated.ProfilePersistence.UserProfile)

Example 5 with UserProfile

use of com.palantir.example.profile.protos.generated.ProfilePersistence.UserProfile in project atlasdb by palantir.

the class ProfileStore method getUserData.

public UserProfile getUserData(UUID userId) {
    UserProfileTable table = tables.getUserProfileTable(tx);
    Map<UserProfileRow, UserProfile> result = table.getMetadatas(ImmutableSet.of(UserProfileRow.of(userId)));
    if (result.isEmpty()) {
        return null;
    } else {
        return Iterables.getOnlyElement(result.values());
    }
}
Also used : UserProfileTable(com.palantir.example.profile.schema.generated.UserProfileTable) UserProfile(com.palantir.example.profile.protos.generated.ProfilePersistence.UserProfile) UserProfileRow(com.palantir.example.profile.schema.generated.UserProfileTable.UserProfileRow)

Aggregations

UserProfile (com.palantir.example.profile.protos.generated.ProfilePersistence.UserProfile)5 UserProfileTable (com.palantir.example.profile.schema.generated.UserProfileTable)2 UUID (java.util.UUID)2 UserPhotosStreamStore (com.palantir.example.profile.schema.generated.UserPhotosStreamStore)1 UserProfileRow (com.palantir.example.profile.schema.generated.UserProfileTable.UserProfileRow)1 Sha256Hash (com.palantir.util.crypto.Sha256Hash)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 Test (org.junit.Test)1