Search in sources :

Example 11 with Account

use of model.Account in project googleads-adsense-examples by googleads.

the class GetAccountTree method displayTree.

/**
 * Auxiliary method to recursively fetch child accounts, displaying them in a tree.
 * @param parentAccount the account to be print a sub-tree for.
 * @param level the depth at which the top account exists in the tree.
 */
private static void displayTree(Adsense adsense, Account parentAccount, int level) throws Exception {
    for (int i = 0; i < level; i++) {
        System.out.print("  ");
    }
    System.out.printf("Account with ID \"%s\" and name \"%s\" was found.\n", parentAccount.getName(), parentAccount.getDisplayName());
    ListChildAccountsResponse response = adsense.accounts().listChildAccounts(parentAccount.getName()).execute();
    List<Account> subAccounts = response.getAccounts();
    if (subAccounts != null && !subAccounts.isEmpty()) {
        for (Account subAccount : subAccounts) {
            displayTree(adsense, subAccount, level + 1);
        }
    }
}
Also used : Account(com.google.api.services.adsense.v2.model.Account) ListChildAccountsResponse(com.google.api.services.adsense.v2.model.ListChildAccountsResponse)

Example 12 with Account

use of model.Account in project googleads-adsense-examples by googleads.

the class AdSenseSample method chooseAccount.

/**
 * Lists all AdSense accounts the user has access to, and prompts them to choose one.
 *
 * @param accounts the list of accounts to choose from.
 * @return the ID of the chosen account.
 */
public static String chooseAccount(List<Account> accounts) {
    String accountId = null;
    if (accounts == null && !accounts.isEmpty()) {
        System.out.println("No AdSense accounts found. Exiting.");
        System.exit(-1);
    } else if (accounts.size() == 1) {
        accountId = accounts.get(0).getName();
        System.out.printf("Only one account found (%s), using it.\n", accountId);
    } else {
        System.out.println("Please choose one of the following accounts:");
        for (int i = 0; i < accounts.size(); i++) {
            Account account = accounts.get(i);
            System.out.printf("%d. %s (%s)\n", i + 1, account.getDisplayName(), account.getName());
        }
        System.out.printf("> ");
        Scanner scan = new Scanner(System.in);
        accountId = accounts.get(scan.nextInt() - 1).getName();
        System.out.printf("Account %s chosen, resuming.\n", accountId);
    }
    System.out.println();
    return accountId;
}
Also used : Account(com.google.api.services.adsense.v2.model.Account) Scanner(java.util.Scanner)

Example 13 with Account

use of model.Account in project Happourse_online_study_web by infiq2000.

the class CourseDetail method doGet.

/**
 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
 */
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    // TODO Auto-generated method stub
    int course_id = Integer.parseInt(request.getParameter("course_id"));
    int uid = (int) request.getSession(false).getAttribute("uid");
    int aid = (int) request.getSession(false).getAttribute("aid");
    try {
        /* Account ac = accUtil.getAccount(aid); */
        Account acc = accUtil.getAccount(aid);
        request.setAttribute("account", acc);
        request.setAttribute("course_id", course_id);
    } catch (SQLException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }
    try {
        Courses detailC = courseUtil.getCourseDetail(course_id);
        request.setAttribute("course_detail", detailC);
        String cate = insUtil.getCate(detailC.getCid());
        request.setAttribute("cate", cate);
        Instructor ins_info = insUtil.getIns_Info(detailC.getIns_id());
        request.setAttribute("ins_info", ins_info);
        List<Chapter> list_chapter = lecUtil.getChapterOfCourse(detailC.getCourses_id());
        request.setAttribute("chapter", list_chapter);
        RequestDispatcher dispatcher;
        if (courseUtil.checkSignedCourse(course_id, uid) == null) {
            dispatcher = request.getRequestDispatcher("/Course_detail.jsp");
        } else {
            dispatcher = request.getRequestDispatcher("/CourseSigned.jsp");
        }
        dispatcher.forward(request, response);
    } catch (SQLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
Also used : Account(Model.Account) SQLException(java.sql.SQLException) Instructor(Model.Instructor) Chapter(Model.Chapter) Courses(Model.Courses) RequestDispatcher(javax.servlet.RequestDispatcher)

Example 14 with Account

use of model.Account in project Happourse_online_study_web by infiq2000.

the class AccountUtil method getAccount.

public Account getAccount(int aid) throws SQLException {
    Connection myConn = null;
    PreparedStatement myStmt = null;
    ResultSet myRS = null;
    try {
        myConn = dataSource.getConnection();
        String sql = "select * from account where aid = ?";
        myStmt = myConn.prepareStatement(sql);
        myStmt.setInt(1, aid);
        myRS = myStmt.executeQuery();
        Account acc = null;
        if (myRS.next()) {
            String userName = myRS.getString("userName");
            String passWord = myRS.getString("passWord");
            boolean type = myRS.getBoolean("type");
            acc = new Account(aid, userName, passWord, type);
        }
        return acc;
    } finally {
        myConn.close();
    }
}
Also used : Account(Model.Account) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Example 15 with Account

use of model.Account in project Happourse_online_study_web by infiq2000.

the class AccountUtil method validation.

public Account validation(String userName, String passWord) throws SQLException {
    Connection myConn = null;
    PreparedStatement myStmt = null;
    ResultSet myRS = null;
    try {
        myConn = dataSource.getConnection();
        String sql = "select * from account where userName = ? and password = ?";
        myStmt = myConn.prepareStatement(sql);
        myStmt.setString(1, userName);
        myStmt.setString(2, passWord);
        myRS = myStmt.executeQuery();
        Account acc = null;
        if (myRS.next()) {
            int aid = myRS.getInt("aid");
            boolean type = myRS.getBoolean("type");
            acc = new Account(aid, userName, passWord, type);
        }
        return acc;
    } finally {
        myConn.close();
    }
}
Also used : Account(Model.Account) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Aggregations

Account (com.google.api.services.adsense.v2.model.Account)5 Account (Model.Account)4 Account (model.Account)4 PreparedStatement (java.sql.PreparedStatement)3 ResultSet (java.sql.ResultSet)3 SQLException (java.sql.SQLException)3 RequestDispatcher (javax.servlet.RequestDispatcher)3 HandleString (util.HandleString)3 Courses (Model.Courses)2 IOException (java.io.IOException)2 Connection (java.sql.Connection)2 User (model.User)2 Chapter (Model.Chapter)1 Instructor (Model.Instructor)1 User (Model.User)1 FileDataStoreFactory (com.google.api.client.util.store.FileDataStoreFactory)1 Adsense (com.google.api.services.adsense.v2.Adsense)1 AdClient (com.google.api.services.adsense.v2.model.AdClient)1 AdUnit (com.google.api.services.adsense.v2.model.AdUnit)1 CustomChannel (com.google.api.services.adsense.v2.model.CustomChannel)1