@Override public String toJson(UID v) { return v.getId(); }
public UserNotFoundException(UID uid) { super(String.format("User with given id '%s' not found", uid.getId())); } }
@Override public byte[] convert(UID v) { return v.getId().getBytes(UTF_8); }
public String getId() { return user.getUID().getId(); }
public static User fromUser(com.dremio.service.users.User user) { return new User(user.getUID().getId(), user.getUserName()); } }
public void setWiki(String entityId, Wiki wiki) throws NamespaceException { Preconditions.checkNotNull(entityId, "Entity id is required."); validateEntity(entityId); final CollaborationWiki collaborationWiki = new CollaborationWiki(); collaborationWiki.setText(wiki.getText()); collaborationWiki.setCreatedAt(System.currentTimeMillis()); // store the user User user = null; try { user = sabotContext.getUserService().getUser(context.getUserPrincipal().getName()); } catch (UserNotFoundException e) { throw new RuntimeException(String.format("Could not load user [%s].", context.getUserPrincipal().getName())); } collaborationWiki.setId(UUID.randomUUID().toString()); collaborationWiki.setUserId(user.getUID().getId()); final Optional<CollaborationWiki> existingWiki = wikiStore.getLatestWikiForEntityId(entityId); collaborationWiki.setVersion(existingWiki.transform(l -> { // check if versions match Long existingVersion = l.getVersion(); Long newVersion = wiki.getVersion(); if (!existingVersion.equals(newVersion)) { throw new ConcurrentModificationException(String.format("The provided version [%s] does not match the stored version [%s].", newVersion, existingVersion)); } // We create a new entry for each update but keep incrementing the version (for sorting). Because we do this we can't // rely on the store to do the version incrementing and therefore do it manually. return existingVersion + 1L; }).or(0L)); collaborationWiki.setEntityId(entityId); wikiStore.save(collaborationWiki); }
tokenDetails.expiresAt, userConfig.getEmail(), userConfig.getUID().getId(), true, userConfig.getCreatedAt(),
@Override public void convert(DocumentWriter writer, UID key, UserInfo userInfo) { UserConfig userConfig = userInfo.getConfig(); writer.write(UserIndexKeys.UID, userConfig.getUid().getId()); writer.write(UserIndexKeys.NAME, userConfig.getUserName()); writer.write(UserIndexKeys.FIRST_NAME, userConfig.getFirstName()); writer.write(UserIndexKeys.LAST_NAME, userConfig.getLastName()); writer.write(UserIndexKeys.EMAIL, userConfig.getEmail()); } }
@Test public void testGetUserById() throws Exception { final UserService userService = l(UserService.class); com.dremio.service.users.User user1 = userService.getUser("user1"); User user = expectSuccess(getBuilder(getPublicAPI(3).path(USER_PATH).path(user1.getUID().getId())).buildGet(), User.class); assertEquals(user.getId(), user1.getUID().getId()); assertEquals(user.getName(), user1.getUserName()); }
@Test public void testGetUserByName() throws Exception { final UserService userService = l(UserService.class); User user = expectSuccess(getBuilder(getPublicAPI(3).path(USER_PATH).path("by-name").path(createdUser.getUserName())).buildGet(), User.class); assertEquals(user.getId(), createdUser.getUID().getId()); assertEquals(user.getName(), createdUser.getUserName()); }
@Override public User getUser(UID uid) throws UserNotFoundException { final String userName = uid.getId(); switch (userName) { case TEST_USER_1: case TEST_USER_2: case ADMIN_USER: case "anonymous": return SimpleUser.newBuilder() .setUID(new UID(userName)) .setUserName(userName) .setEmail(userName + "@dremio.test") .setFirstName(userName + " FN") .setLastName(userName + " LN") .build(); case SystemUser.SYSTEM_USERNAME: return SystemUser.SYSTEM_USER; default: throw new UserNotFoundException(userName); } }