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;
});
}
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;
});
}
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;
});
}
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);
}
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());
}
}
Aggregations