Search in sources :

Example 1 with UserPhotosStreamStore

use of com.palantir.example.profile.schema.generated.UserPhotosStreamStore in project atlasdb by palantir.

the class ProfileStore method deleteImage.

public void deleteImage(UUID userId) {
    Long streamId = getPhotoStreamId(userId);
    if (streamId == null) {
        return;
    }
    UserProfileTable table = tables.getUserProfileTable(tx);
    table.deletePhotoStreamId(UserProfileRow.of(userId));
    UserPhotosStreamStore streamStore = UserPhotosStreamStore.of(txnMgr, tables);
    streamStore.unmarkStreamAsUsed(tx, streamId, EncodingUtils.encodeUUID(userId));
}
Also used : UserPhotosStreamStore(com.palantir.example.profile.schema.generated.UserPhotosStreamStore) UserProfileTable(com.palantir.example.profile.schema.generated.UserProfileTable)

Example 2 with UserPhotosStreamStore

use of com.palantir.example.profile.schema.generated.UserPhotosStreamStore in project atlasdb by palantir.

the class ProfileStore method getImageForUser.

public InputStream getImageForUser(UUID userId) {
    Long photoId = getPhotoStreamId(userId);
    if (photoId == null) {
        return null;
    }
    UserPhotosStreamStore streamStore = UserPhotosStreamStore.of(txnMgr, tables);
    return streamStore.loadStream(tx, photoId);
}
Also used : UserPhotosStreamStore(com.palantir.example.profile.schema.generated.UserPhotosStreamStore)

Example 3 with UserPhotosStreamStore

use of com.palantir.example.profile.schema.generated.UserPhotosStreamStore 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)

Aggregations

UserPhotosStreamStore (com.palantir.example.profile.schema.generated.UserPhotosStreamStore)3 UserProfileTable (com.palantir.example.profile.schema.generated.UserProfileTable)2 UserProfile (com.palantir.example.profile.protos.generated.ProfilePersistence.UserProfile)1