Search in sources :

Example 1 with UserProfileTable

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

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

the class ProfileStore method getPhotoStreamId.

private Long getPhotoStreamId(UUID userId) {
    UserProfileTable table = tables.getUserProfileTable(tx);
    Map<UserProfileRow, Long> result = table.getPhotoStreamIds(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) UserProfileRow(com.palantir.example.profile.schema.generated.UserProfileTable.UserProfileRow)

Example 3 with UserProfileTable

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

the class ProfileStore method storeNewUser.

public UUID storeNewUser(UserProfile data) {
    UUID userId = getNewId();
    UserProfileTable table = tables.getUserProfileTable(tx);
    table.putMetadata(UserProfileRow.of(userId), data);
    return userId;
}
Also used : UserProfileTable(com.palantir.example.profile.schema.generated.UserProfileTable) UUID(java.util.UUID)

Example 4 with UserProfileTable

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

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

the class ProfileStore method getUsersWithBirthday.

public Set<UUID> getUsersWithBirthday(long birthEpochDays) {
    UserProfileTable table = tables.getUserProfileTable(tx);
    UserBirthdaysIdxTable idx = UserBirthdaysIdxTable.of(table);
    List<UserBirthdaysIdxColumnValue> columns = idx.getRowColumns(UserBirthdaysIdxRow.of(birthEpochDays));
    return IterableView.of(columns).transform(UserBirthdaysIdxColumnValue.getColumnNameFun()).transform(UserBirthdaysIdxColumn.getIdFun()).immutableSetCopy();
}
Also used : UserProfileTable(com.palantir.example.profile.schema.generated.UserProfileTable) UserBirthdaysIdxColumnValue(com.palantir.example.profile.schema.generated.UserProfileTable.UserBirthdaysIdxTable.UserBirthdaysIdxColumnValue) UserBirthdaysIdxTable(com.palantir.example.profile.schema.generated.UserProfileTable.UserBirthdaysIdxTable)

Aggregations

UserProfileTable (com.palantir.example.profile.schema.generated.UserProfileTable)6 UserProfile (com.palantir.example.profile.protos.generated.ProfilePersistence.UserProfile)2 UserPhotosStreamStore (com.palantir.example.profile.schema.generated.UserPhotosStreamStore)2 UserProfileRow (com.palantir.example.profile.schema.generated.UserProfileTable.UserProfileRow)2 UserBirthdaysIdxTable (com.palantir.example.profile.schema.generated.UserProfileTable.UserBirthdaysIdxTable)1 UserBirthdaysIdxColumnValue (com.palantir.example.profile.schema.generated.UserProfileTable.UserBirthdaysIdxTable.UserBirthdaysIdxColumnValue)1 UUID (java.util.UUID)1