コード例 #1
0
  /**
   * Transforms {@code User} object to {@code UserDTO} object
   *
   * @param user user object which will be transformed to DTO
   * @return user DTO object
   */
  public static UserDTO userToDTO(User user) {
    if (user == null) {
      throw new IllegalArgumentException("User is null");
    }

    if (logger.isDebugEnabled()) {
      logger.debug("Converting User '" + user.getName() + " (" + user.getEmail() + ")' to UserDTO");
    }
    UserDTO result = new UserDTO();
    result.setUuid(user.getUuid());
    result.setName(user.getName());
    result.setProfession(user.getProfession());

    return result;
  }
コード例 #2
0
  /**
   * Transforms JCR {@code Node} into {@code UserDTO} object
   *
   * @param node JCR {@code Node}
   * @return {@code UserDTO} object
   */
  public static UserDTO nodeToUserDTO(Node node) {
    if (node == null) {
      throw new IllegalArgumentException("Node is null");
    }

    UserDTO user = null;
    try {
      user = new UserDTO();
      user.setUuid(node.getIdentifier());
      user.setName(node.getProperty(PROP_NAME.toString()).getString());
      user.setProfession(
          nodeToProfession(
              node.getSession()
                  .getNodeByIdentifier(node.getProperty(PROP_PROFESSION.toString()).getString())));

    } catch (RepositoryException ex) {
      logger.error("Failed to transform JCR Node to UserDTO. " + ex.getMessage());
    }

    return user;
  }