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);
}
}
}
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;
}
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();
}
}
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();
}
}
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();
}
}
Aggregations