@Test
  public void testGetUserProfileNodeCreateFalse() {
    // get the orion credentials service
    IOrionCredentialsService orionCredentialsService =
        UserServiceHelper.getDefault().getUserStore();

    // particulars for the new user
    String login = "******";
    String name = "Existing Node";
    String email = "*****@*****.**";
    String password = "******";

    // create user pattern is to persist the new user in the metadata store first
    UserInfo userInfo = new UserInfo();
    userInfo.setUserName(login);
    userInfo.setFullName(name);
    try {
      OrionConfiguration.getMetaStore().createUser(userInfo);
    } catch (CoreException e) {
      fail("Could not create user in IMetaStore: " + e.getLocalizedMessage());
    }

    // create the new user using the IOrionCredentialsService
    User user = new User(userInfo.getUniqueId(), login, name, password);
    user.setEmail(email);
    User createdUser = orionCredentialsService.createUser(user);

    // get the profile node
    IOrionUserProfileService orionUserProfileService =
        UserServiceHelper.getDefault().getUserProfileService();
    IOrionUserProfileNode userProfileNode =
        orionUserProfileService.getUserProfileNode(createdUser.getUid(), false);
    assertNotNull(userProfileNode);
  }
  @Test
  public void testGetUserProfileNodeCreateTrue() {
    // get the orion credentials service
    IOrionCredentialsService orionCredentialsService =
        UserServiceHelper.getDefault().getUserStore();

    // particulars for the new user
    String login = "******";
    String name = "Create Node";
    String email = "*****@*****.**";
    String password = "******";

    // create user pattern is to persist the new user in the metadata store first
    UserInfo userInfo = new UserInfo();
    userInfo.setUserName(login);
    userInfo.setFullName(name);
    try {
      OrionConfiguration.getMetaStore().createUser(userInfo);
    } catch (CoreException e) {
      fail("Could not create user in IMetaStore: " + e.getLocalizedMessage());
    }

    // create the new user using the IOrionCredentialsService
    User user = new User(userInfo.getUniqueId(), login, name, password);
    user.setEmail(email);
    User createdUser = orionCredentialsService.createUser(user);

    // get the profile node
    IOrionUserProfileService orionUserProfileService =
        UserServiceHelper.getDefault().getUserProfileService();
    IOrionUserProfileNode userProfileNode =
        orionUserProfileService.getUserProfileNode(createdUser.getUid(), true);

    IOrionUserProfileNode generalProfilePart =
        userProfileNode.getUserProfileNode(IOrionUserProfileConstants.GENERAL_PROFILE_PART);
    try {
      generalProfilePart.put("GitMail", email, false);
      generalProfilePart.put("GitName", name, false);
      generalProfilePart.flush();
    } catch (CoreException e) {
      fail("Could not update the user profile node: " + e.getLocalizedMessage());
    }

    // read back the profile node
    IOrionUserProfileNode readProfileNode =
        orionUserProfileService.getUserProfileNode(
            createdUser.getUid(), IOrionUserProfileConstants.GENERAL_PROFILE_PART);
    try {
      String gitMail = readProfileNode.get("GitMail", null);
      assertNotNull(gitMail);
      assertEquals(email, gitMail);
      String gitName = readProfileNode.get("GitName", null);
      assertNotNull(gitName);
      assertEquals(name, gitName);
    } catch (CoreException e) {
      fail("Could not read the user profile node: " + e.getLocalizedMessage());
    }
  }
  @Test
  public void testGetUserProfileNode() {
    // get the orion credentials service
    IOrionCredentialsService orionCredentialsService =
        UserServiceHelper.getDefault().getUserStore();

    // particulars for the new user
    String login = "******";
    String name = "Profile Node";
    String email = "*****@*****.**";
    String password = "******";

    // create user pattern is to persist the new user in the metadata store first
    UserInfo userInfo = new UserInfo();
    userInfo.setUserName(login);
    userInfo.setFullName(name);
    try {
      OrionConfiguration.getMetaStore().createUser(userInfo);
    } catch (CoreException e) {
      fail("Could not create user in IMetaStore: " + e.getLocalizedMessage());
    }

    // create the new user using the IOrionCredentialsService
    User user = new User(userInfo.getUniqueId(), login, name, password);
    user.setEmail(email);
    User createdUser = orionCredentialsService.createUser(user);

    // get the profile node
    IOrionUserProfileService orionUserProfileService =
        UserServiceHelper.getDefault().getUserProfileService();
    IOrionUserProfileNode userProfileNode =
        orionUserProfileService.getUserProfileNode(
            createdUser.getUid(), IOrionUserProfileConstants.GENERAL_PROFILE_PART);

    // set the last login timestamp
    String lastLogin = new Long(System.currentTimeMillis()).toString();
    try {
      userProfileNode.put(IOrionUserProfileConstants.LAST_LOGIN_TIMESTAMP, lastLogin, false);
      userProfileNode.flush();
    } catch (CoreException e) {
      fail("Could not put the user profile node: " + e.getLocalizedMessage());
    }

    // read back the profile node
    IOrionUserProfileNode readProfileNode =
        orionUserProfileService.getUserProfileNode(
            createdUser.getUid(), IOrionUserProfileConstants.GENERAL_PROFILE_PART);
    try {
      String readLastLogin =
          readProfileNode.get(IOrionUserProfileConstants.LAST_LOGIN_TIMESTAMP, null);
      assertNotNull(readLastLogin);
      assertEquals(lastLogin, readLastLogin);
    } catch (CoreException e) {
      fail("Could not read the user profile node: " + e.getLocalizedMessage());
    }
  }
Ejemplo n.º 4
0
  private boolean sendNotification(
      HttpServletRequest request,
      HttpServletResponse response,
      Repository db,
      String login,
      String commit,
      String url,
      String authorName,
      String message)
      throws ServletException, URISyntaxException, IOException, JSONException, CoreException,
          Exception {
    UserEmailUtil util = UserEmailUtil.getUtil();
    if (!util.isEmailConfigured()) {
      return statusHandler.handleRequest(
          request,
          response,
          new ServerStatus(
              IStatus.ERROR,
              HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
              "Smpt server not configured",
              null));
    }
    IOrionCredentialsService userAdmin = UserServiceHelper.getDefault().getUserStore();
    User user = (User) userAdmin.getUser(UserConstants.KEY_LOGIN, login);
    try {
      if (reviewRequestEmail == null) {
        reviewRequestEmail = new EmailContent(EMAIL_REVIEW_REQUEST_FILE);
      }

      String emailAdress = user.getEmail();

      util.sendEmail(
          reviewRequestEmail.getTitle(),
          reviewRequestEmail
              .getContent()
              .replaceAll(EMAIL_COMMITER_NAME, authorName)
              .replaceAll(EMAIL_URL_LINK, url)
              .replaceAll(EMAIL_COMMIT_MESSAGE, message),
          emailAdress);

      JSONObject result = new JSONObject();
      result.put(GitConstants.KEY_RESULT, "Email sent");
      OrionServlet.writeJSONResponse(
          request, response, result, JsonURIUnqualificationStrategy.ALL_NO_GIT);
      return true;
    } catch (Exception e) {
      return statusHandler.handleRequest(
          request,
          response,
          new ServerStatus(
              IStatus.ERROR,
              HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
              "User doesn't exist",
              null));
    }
  };
Ejemplo n.º 5
0
 public static void doConfigureClone(Git git, String user) throws IOException, CoreException {
   StoredConfig config = git.getRepository().getConfig();
   IOrionUserProfileNode userNode =
       UserServiceHelper.getDefault()
           .getUserProfileService()
           .getUserProfileNode(user, true)
           .getUserProfileNode(IOrionUserProfileConstants.GENERAL_PROFILE_PART);
   if (userNode.get(GitConstants.KEY_NAME, null) != null)
     config.setString(
         ConfigConstants.CONFIG_USER_SECTION,
         null,
         ConfigConstants.CONFIG_KEY_NAME,
         userNode.get(GitConstants.KEY_NAME, null));
   if (userNode.get(GitConstants.KEY_MAIL, null) != null)
     config.setString(
         ConfigConstants.CONFIG_USER_SECTION,
         null,
         ConfigConstants.CONFIG_KEY_EMAIL,
         userNode.get(GitConstants.KEY_MAIL, null));
   config.setBoolean(
       ConfigConstants.CONFIG_CORE_SECTION, null, ConfigConstants.CONFIG_KEY_FILEMODE, false);
   config.save();
 }
  @Test
  public void testGetUserNames() {
    // get the orion credentials service
    IOrionCredentialsService orionCredentialsService =
        UserServiceHelper.getDefault().getUserStore();

    // particulars for the new user
    String login = "******";
    String name = "Test Names";
    String email = "*****@*****.**";
    String password = "******";

    // create user pattern is to persist the new user in the metadata store first
    UserInfo userInfo = new UserInfo();
    userInfo.setUserName(login);
    userInfo.setFullName(name);
    try {
      OrionConfiguration.getMetaStore().createUser(userInfo);
    } catch (CoreException e) {
      fail("Could not create user in IMetaStore: " + e.getLocalizedMessage());
    }

    // create the new user using the IOrionCredentialsService
    User user = new User(userInfo.getUniqueId(), login, name, password);
    user.setEmail(email);
    User createdUser = orionCredentialsService.createUser(user);
    assertNotNull(createdUser);

    // get the profile node
    IOrionUserProfileService orionUserProfileService =
        UserServiceHelper.getDefault().getUserProfileService();
    IOrionUserProfileNode userProfileNode =
        orionUserProfileService.getUserProfileNode(
            createdUser.getUid(), IOrionUserProfileConstants.GENERAL_PROFILE_PART);

    // set the last login timestamp
    String lastLogin = new Long(System.currentTimeMillis()).toString();
    try {
      userProfileNode.put(IOrionUserProfileConstants.LAST_LOGIN_TIMESTAMP, lastLogin, false);
      userProfileNode.flush();
    } catch (CoreException e) {
      fail("Could not put the user profile node: " + e.getLocalizedMessage());
    }

    // get the profile nodes
    orionUserProfileService = UserServiceHelper.getDefault().getUserProfileService();
    String[] userNames = orionUserProfileService.getUserNames();
    List<String> userNamesList = new ArrayList<String>(Arrays.asList(userNames));
    assertTrue(userNamesList.contains(userInfo.getUniqueId()));

    for (String userName : userNamesList) {
      if (userName.equals(userInfo.getUniqueId())) {
        IOrionUserProfileNode readUserProfileNode =
            orionUserProfileService.getUserProfileNode(userName, false);
        String[] childrenNames = readUserProfileNode.childrenNames();
        List<String> childrenNamesList = new ArrayList<String>(Arrays.asList(childrenNames));
        assertTrue(childrenNamesList.contains(IOrionUserProfileConstants.GENERAL_PROFILE_PART));
        assertEquals(1, childrenNamesList.size());
        for (String profilePart : childrenNamesList) {
          assertEquals(IOrionUserProfileConstants.GENERAL_PROFILE_PART, profilePart);
          IOrionUserProfileNode profilePartNode =
              readUserProfileNode.getUserProfileNode(profilePart);
          assertNotNull(profilePartNode);
          try {
            String readLastLogin =
                profilePartNode.get(IOrionUserProfileConstants.LAST_LOGIN_TIMESTAMP, null);
            assertEquals(lastLogin, readLastLogin);
          } catch (CoreException e) {
            fail("Could not read the user profile node: " + e.getLocalizedMessage());
          }
        }
      }
    }
  }