コード例 #1
0
  private AccountInfo checkIn(AccountInfo acc) {
    // TODO Auto-generated method stub
    if (client == null) {
      acc.state = UNKNOWN_FAIL;
      return acc;
    }
    ArrayList<BasicNameValuePair> valueList = new ArrayList<BasicNameValuePair>();
    try {
      UrlEncodedFormEntity urlEncodedFormEntity = new UrlEncodedFormEntity(valueList, "UTF-8");
      HttpPost post = new HttpPost("http://www.xiami.com/task/signin");
      post.setHeader("Referer", "http://www.xiami.com/");
      post.setEntity(urlEncodedFormEntity);
      HttpResponse response = client.execute(post);
      if (response.getStatusLine().getStatusCode() == 200) {
        acc = isCheck(acc);
        if (acc.day > 0) acc.state = SUCCESS;
        else acc.state = CHECK_FAIL;
      } else {
        acc.state = SERVER_FAIL;
      }
    } catch (ParseException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (ClientProtocolException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

    return acc;
  }
コード例 #2
0
 private AccountInfo isCheck(AccountInfo acc, String html) {
   // TODO Auto-generated method stub
   int days = 0;
   //
   // String integral = "";
   // String level = "";
   // String dayNum = "";
   // /** get check days */
   // String str = Regular.get(html, "sidebar", "checkin_popup");
   // integral = Regular.get(Regular.get(str, "help9_2", "</a>"),
   // "<strong>",
   // "</strong>");
   // level = Regular.get(str, "level_popup\">", "<p>");
   // dayNum = Regular.get(str, "done\">", "</b>");
   // if (dayNum.contains(V_DAY))
   // days = Integer.parseInt(dayNum.replace(V_DAY, "").trim());
   // acc.integral = integral;
   // acc.level = level;
   // acc.day = days;
   // acc.tip = integral + "-" + level + "-" + dayNum;
   //
   if (html.contains("每日签到")) {
     acc.day = 0;
   } else {
     String dayNum = Regular.get(html, "已连续签到", "天");
     days = Integer.parseInt(dayNum.trim());
     acc.day = days;
   }
   return acc;
 }
コード例 #3
0
ファイル: EmailManager.java プロジェクト: Cauac/MailLibrary
 private Socket getIncommingSocket() throws IOException {
   Socket s;
   if (info.isUseSSL()) {
     SSLSocketFactory sslsocketfactory = (SSLSocketFactory) SSLSocketFactory.getDefault();
     s = sslsocketfactory.createSocket(info.getIncomingServerName(), info.getIncomingPort());
   } else {
     s = new Socket(info.getIncomingServerName(), info.getIncomingPort());
   }
   return s;
 }
コード例 #4
0
 /**
  * Takes an AccountInfo object and compares its pin to the pin it has on record for the given
  * account number. Returns true if the pin is correct, or throws an authorization exception if the
  * pin is incorrect or the account number does not exist in its records.
  */
 public boolean authenticatePin(AccountInfo account)
     throws AuthorizationException, RemoteException {
   Integer pinOnRecord = authValues.get(account.getAccountNum());
   if (pinOnRecord == null) {
     throw new AuthorizationException("No such account exists");
   }
   if (pinOnRecord.equals(account.getPin())) {
     return true;
   }
   throw new AuthorizationException("Incorrect PIN");
 }
コード例 #5
0
 public boolean add(AccountInfo info) throws SQLException {
   Statement statement = connection.createStatement();
   return statement.execute(
       "INSERT INTO account VALUES ('"
           + info.getSite()
           + "', '"
           + info.getAccount()
           + "', '"
           + info.getPassword()
           + "');");
 }
コード例 #6
0
ファイル: EmailManager.java プロジェクト: Cauac/MailLibrary
  public int getMailsCount() throws IOException, ProtocolException {
    int count = 0;
    Socket s = this.getIncommingSocket();
    ReceiveProtocol protocol = this.getIncommingProtocol(s);

    protocol.startSession();
    protocol.authorization(info.getUsername(), info.getPassword());
    count = protocol.letterCount();
    protocol.closeSession();
    s.close();
    return count;
  }
コード例 #7
0
ファイル: EmailManager.java プロジェクト: Cauac/MailLibrary
  public boolean sendMessage(Letter l) throws IOException, ProtocolException {
    boolean result = false;
    Socket s = this.getOutGoingSocket();
    PostProtocol protocol = this.getOutGoingProtocol(s);

    protocol.startSession(info.getOutgoingServerName());
    protocol.authorization(info.getUsername(), info.getPassword());
    result = protocol.sendMessage(l);
    protocol.closeSession();
    s.close();
    return result;
  }
コード例 #8
0
ファイル: EmailManager.java プロジェクト: Cauac/MailLibrary
  public boolean deleteMessage(int number) throws IOException, ProtocolException {
    boolean result = false;
    Socket s = this.getIncommingSocket();
    ReceiveProtocol protocol = this.getIncommingProtocol(s);

    protocol.startSession();
    protocol.authorization(info.getUsername(), info.getPassword());
    result = protocol.deleteMessage(number);
    protocol.closeSession();
    s.close();
    return result;
  }
コード例 #9
0
ファイル: EmailManager.java プロジェクト: Cauac/MailLibrary
  public Letter getLetter(int number) throws IOException, ProtocolException {
    Letter l;
    Socket s = this.getIncommingSocket();
    ReceiveProtocol protocol = this.getIncommingProtocol(s);

    protocol.startSession();
    protocol.authorization(info.getUsername(), info.getPassword());
    l = protocol.openMessage(number);
    protocol.closeSession();
    s.close();
    return l;
  }
コード例 #10
0
ファイル: EmailManager.java プロジェクト: Cauac/MailLibrary
  public LetterInfo[] getMailsInfoList() throws IOException, ProtocolException {
    LetterInfo[] letterInfo;
    Socket s = this.getIncommingSocket();
    ReceiveProtocol protocol = this.getIncommingProtocol(s);

    protocol.startSession();
    protocol.authorization(info.getUsername(), info.getPassword());
    int letterCount = protocol.letterCount();
    letterInfo = new LetterInfo[letterCount];
    for (int i = 0; i < letterCount; i++) {
      letterInfo[i] = protocol.messageInfo(letterCount - i);
    }
    protocol.closeSession();
    s.close();
    return letterInfo;
  }
コード例 #11
0
 public void dialogDNA(String str) {
   String bindState = "";
   try {
     JSONObject obj = new JSONObject(str);
     bindState = obj.getString("bindstate");
     if (bindState.equals("1")) { // 已经绑定
       info.setBindState(obj.getString("bindstate"));
       info.setNum(obj.getString("bankcardno"));
       info.setNameStr(obj.getString("name"));
       info.setAdd(obj.getString("bankaddress"));
       info.setBankName(obj.getString("bankname"));
     }
   } catch (JSONException e) {
     e.printStackTrace();
   }
   setContentView(getMoneyDialog());
 }
コード例 #12
0
ファイル: EmailManager.java プロジェクト: Cauac/MailLibrary
 private ReceiveProtocol getIncommingProtocol(Socket s) throws IOException, ProtocolException {
   ReceiveProtocol protocol;
   if (info.getInProtocolType().equals("POP3")) {
     protocol = new POP3(s.getInputStream(), s.getOutputStream());
   } else {
     protocol = new IMAP(s.getInputStream(), s.getOutputStream());
   }
   return protocol;
 }
コード例 #13
0
 /** 创建提现信息类 */
 public AccountInfo createAccountInfo(JSONObject json) {
   AccountInfo info = new AccountInfo();
   try {
     info.setState(json.getString("stat"));
     info.setNameStr(json.getString("name"));
     info.setMoney(json.getString("amount"));
     info.setNum(json.getString("bankcardno"));
     info.setAllbankname(json.getString("allbankname"));
     info.setAdd(json.getString("areaname"));
     info.setBank(json.getString("bankname"));
     info.setCashdetailId(json.getString("cashdetailid"));
   } catch (JSONException e) {
     e.printStackTrace();
   }
   return info;
 }
コード例 #14
0
 /** 提现待审核窗口 */
 protected View waitDialog() {
   start = true;
   LayoutInflater inflater = LayoutInflater.from(this);
   View waitView = inflater.inflate(R.layout.get_money_stating, null);
   nameText = (TextView) waitView.findViewById(R.id.get_money_name);
   bankText = (TextView) waitView.findViewById(R.id.get_money_bank);
   addText = (TextView) waitView.findViewById(R.id.get_money_bank_address);
   numText = (TextView) waitView.findViewById(R.id.get_money_bank_num);
   moneyText = (TextView) waitView.findViewById(R.id.get_money_money);
   Button submit = (Button) waitView.findViewById(R.id.get_money_img_submit);
   submit.setBackgroundResource(R.drawable.join_info_btn_selecter);
   Button cancel = (Button) waitView.findViewById(R.id.get_money_img_cancel);
   cancel.setBackgroundResource(R.drawable.join_info_btn_selecter);
   Button exit = (Button) waitView.findViewById(R.id.get_money_img_exit);
   exit.setBackgroundResource(R.drawable.join_info_btn_selecter);
   submit.setOnClickListener(
       new OnClickListener() {
         public void onClick(View v) {
           //				setContentView(getMoneyDialog());
           checkDNA();
         }
       });
   cancel.setOnClickListener(
       new OnClickListener() {
         public void onClick(View v) {
           cancelNet();
         }
       });
   exit.setOnClickListener(
       new OnClickListener() {
         public void onClick(View v) {
           finish();
         }
       });
   nameText.append(info.getNameStr());
   bankText.append(info.getBank());
   addText.append(info.getAdd());
   numText.append(info.getNum());
   moneyText.append(info.getMoney());
   return waitView;
 }
コード例 #15
0
  private AccountInfo loginIn(AccountInfo acc) {
    // TODO Auto-generated method stub
    if (client == null) {
      acc.state = UNKNOWN_FAIL;
      return acc;
    }
    ArrayList<BasicNameValuePair> valueList = new ArrayList<BasicNameValuePair>();
    BasicNameValuePair value = null;
    value = new BasicNameValuePair("email", acc.name);
    valueList.add(value);
    value = new BasicNameValuePair("password", acc.pass);
    valueList.add(value);
    value = new BasicNameValuePair("LoginButton", "登录");
    valueList.add(value);

    try {
      UrlEncodedFormEntity urlEncodedFormEntity = new UrlEncodedFormEntity(valueList, "UTF-8");
      HttpPost post = new HttpPost("http://www.xiami.com/web/login");
      post.setHeader("Referer", "http://www.xiami.com/web/login");
      post.setEntity(urlEncodedFormEntity);
      HttpResponse response = client.execute(post);

      if (response.getStatusLine().getStatusCode() == 200) {
        String res = EntityUtils.toString(response.getEntity(), "UTF-8");
        if (res.contains("会员登录")) {
          if (res.contains("请输入验证码")) {
            acc.state = LOGIN_VALIDATE_FAIL;
          } else {
            acc.state = LOGIN_FAIL;
          }
        } else if (res.contains("快捷操作")) {
          acc = isCheck(acc);
          if (acc.day > 0) acc.state = IS_CHECKED;
          else acc.state = SUCCESS;
        } else {
          acc.state = SERVER_FAIL;
        }
      } else {
        acc.state = SERVER_FAIL;
      }
    } catch (ParseException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (ClientProtocolException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

    return acc;
  }
コード例 #16
0
  public AccountInfo check(AccountInfo acc) {
    // TODO Auto-generated method stub
    if (!NetCheck.isConnected(context)) {
      acc.state = NET_FAIL;
      acc.tip = state2Tip(acc.state, "");
      log(acc.tip);
      return acc;
    }
    log(context.getString(R.string.logStart));
    initClient();
    D.e(">>>>check start , name : " + acc.name);
    log(context.getString(R.string.logName) + acc.name);
    log(context.getString(R.string.logLogining));
    acc = loginIn(acc);
    if (acc.state == SUCCESS) { // 登录成功,未签到
      log(context.getString(R.string.logLoginSuccess));
      // 签到
      log(context.getString(R.string.logChecking));
      acc = checkIn(acc);
      if (acc.state == SUCCESS) { // 签到成功
        acc.lastCheck = System.currentTimeMillis();
        log(context.getString(R.string.logCheckinSuccess));
        log(context.getString(R.string.logTime) + DateHelper.longToString(acc.lastCheck));
      } else { // 签到失败
        acc.tip = state2Tip(acc.state, "");
        // log(context.getString(R.string.logCheckinFail));
        log(acc.tip);
      }
    } else if (acc.state == IS_CHECKED) { // 登录成功,已签到
      log(context.getString(R.string.logLoginSuccess));
      log(context.getString(R.string.logCheckined));
      acc.lastCheck = System.currentTimeMillis();
      log(context.getString(R.string.logCheckinSuccess));
      log(context.getString(R.string.logTime) + DateHelper.longToString(acc.lastCheck));
    } else { // 未知错误
      acc.tip = state2Tip(acc.state, "");
      // log(context.getString(R.string.logCheckinFail));
      log(acc.tip);
    }

    shutdown();
    D.e(">>>>check end , state : " + acc.state + " , tip : " + acc.tip);
    log(context.getString(R.string.logEnd));
    return acc;
  }
コード例 #17
0
 public void errorCode_0000() {
   if (isQuery) {
     isQuery = false;
     info = createAccountInfo(json);
     state = Integer.parseInt(info.getState());
     switch (state) {
       case 0: // 提现窗口
         //				setContentView(getMoneyDialog());
         checkDNA();
         break;
       case 31: // 修改提现窗口
         //				changeDialog();
         break;
       case 1: // 待审核
         setContentView(waitDialog());
         break;
       case 102: // 审核中
         setContentView(waitingDialog());
         break;
       case 103: // 审核中
         setContentView(waitingDialog());
         break;
       case 104: // 驳回
         setContentView(failDialog());
         break;
       case 106: // 驳回
         setContentView(failDialog());
         break;
       case 105: // 已通过审核
         setContentView(successDialog());
         break;
     }
   } else {
     Toast.makeText(AccountWithdrawActivity.this, message, Toast.LENGTH_SHORT).show();
     finish();
   }
 }
コード例 #18
0
  /** 提现窗口 */
  protected View getMoneyDialog() {
    start = true;
    LayoutInflater inflater = LayoutInflater.from(this);
    View getView = inflater.inflate(R.layout.get_money_submit, null);
    LinearLayout layout1 = (LinearLayout) getView.findViewById(R.id.LinearLayout_one);
    LinearLayout layout2 = (LinearLayout) getView.findViewById(R.id.LinearLayout_two);
    LinearLayout layout3 = (LinearLayout) getView.findViewById(R.id.LinearLayout_third);
    final EditText name = (EditText) getView.findViewById(R.id.get_money_name_edit);
    final Spinner money_brank = (Spinner) getView.findViewById(R.id.get_money_bank_spinner);
    //
    allcountries = new ArrayList<String>();
    if (info.getAllbankname() != null && info.getAllbankname().length > 0) {
      allName = info.getAllbankname();
    } else {
      allName = allBankName;
    }
    for (int i = 0; i < allName.length; i++) {
      allcountries.add(allName[i]);
    }
    adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, allcountries);
    adapter.setDropDownViewResource(R.layout.myspinner_dropdown);
    money_brank.setAdapter(adapter);
    //
    money_brank.setOnItemSelectedListener(
        new OnItemSelectedListener() {
          @Override
          public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
            int position = money_brank.getSelectedItemPosition();
            bankName = allName[position];
          }

          @Override
          public void onNothingSelected(AdapterView<?> arg0) {}
        });
    final TextView drawbalanceText = (TextView) getView.findViewById(R.id.withdraw_drawbalance);
    if (drawBStr == null || drawBStr == "" || drawBStr == "null") {
      drawBStr = "联网获取失败";
    }
    drawbalanceText.setText("您的账户可提现余额为:" + drawBStr);
    final String drawMoney = drawBStr.substring(0, drawBStr.length() - 1);
    final EditText money_bank_start =
        (EditText) getView.findViewById(R.id.get_money_bank_start_edit);
    final EditText money_bank_num = (EditText) getView.findViewById(R.id.get_money_bank_num_edit);
    final EditText money = (EditText) getView.findViewById(R.id.get_money_money_edit);
    Button submit = (Button) getView.findViewById(R.id.get_money_img_submit);
    submit.setBackgroundResource(R.drawable.join_info_btn_selecter);
    Button cancel = (Button) getView.findViewById(R.id.get_money_img_back);
    cancel.setBackgroundResource(R.drawable.join_info_btn_selecter);
    submit.setOnClickListener(
        new OnClickListener() {
          public void onClick(View v) {
            ChangeWithdrawPojo changeWithdPojo = new ChangeWithdrawPojo();
            String nameStr = name.getText().toString();
            String moneyStr = money.getText().toString();
            String bankNameStr = bankName;
            String bankAreaStr = money_bank_start.getText().toString();
            String bankNoStr = money_bank_num.getText().toString();
            changeWithdPojo.setUserno(userno);
            changeWithdPojo.setPhonenum(phonenum);
            changeWithdPojo.setSessionid(sessionid);
            if (info.getBankName().equals("") || info.getBankName().equals("null")) {
              changeWithdPojo.setBankname(bankNameStr);
            } else {
              changeWithdPojo.setBankname(info.getBankName());
            }
            if (nameStr.equals("")) {
              Toast.makeText(AccountWithdrawActivity.this, "持卡人名不能为空!", Toast.LENGTH_SHORT).show();
            } else if (bankAreaStr.equals("")) {
              Toast.makeText(AccountWithdrawActivity.this, "开卡地址不能为空!", Toast.LENGTH_SHORT).show();
            } else if (bankNoStr.equals("")) {
              Toast.makeText(AccountWithdrawActivity.this, "银行卡号不能为空!", Toast.LENGTH_SHORT).show();
            } else if (moneyStr.equals("")) {
              Toast.makeText(AccountWithdrawActivity.this, "提现金额不能为空!", Toast.LENGTH_SHORT).show();
            } else if (Integer.parseInt(moneyStr) < 1) {
              Toast.makeText(AccountWithdrawActivity.this, "至少提现一元!", Toast.LENGTH_SHORT).show();
            } else if (Float.parseFloat(moneyStr) > Float.parseFloat(drawMoney)) {
              Toast.makeText(AccountWithdrawActivity.this, "您提现的金额大于您的可提现余额!", Toast.LENGTH_SHORT)
                  .show();
            } else {
              changeWithdPojo.setName(nameStr);
              changeWithdPojo.setAmount(PublicMethod.toFen(moneyStr));
              changeWithdPojo.setAraeaname(bankAreaStr);
              changeWithdPojo.setBankcardno(bankNoStr);
              accountWithdrawNet(changeWithdPojo);
            }
          }
        });
    cancel.setOnClickListener(
        new OnClickListener() {
          public void onClick(View v) {
            finish();
          }
        });
    name.append(info.getNameStr());
    money_bank_start.append(info.getAdd());
    money_bank_num.append(info.getNum());
    if (info.getBindState().equals("1")) { // dna是否绑定
      layout1.setVisibility(LinearLayout.GONE);
      layout3.setVisibility(LinearLayout.GONE);
      if (info.getBankName().equals("") || info.getBankName().equals("null")) {
        layout2.setVisibility(LinearLayout.VISIBLE);
      } else {
        layout2.setVisibility(LinearLayout.GONE);
      }
      money_bank_num.setEnabled(false);
    }
    return getView;
  }
コード例 #19
0
  /** 提现窗口 */
  protected View getMoneyDialog() {
    start = true;
    LayoutInflater inflater = LayoutInflater.from(this);
    View getView = inflater.inflate(R.layout.get_money_submit, null);
    final EditText name = (EditText) getView.findViewById(R.id.get_money_name_edit);
    final Spinner money_brank = (Spinner) getView.findViewById(R.id.get_money_bank_spinner);
    //
    allcountries = new ArrayList<String>();
    if (info.getAllbankname() != null && info.getAllbankname().length > 0) {
      allName = info.getAllbankname();
    } else {
      allName = allBankName;
    }
    for (int i = 0; i < allName.length; i++) {
      allcountries.add(allName[i]);
    }
    adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, allcountries);
    adapter.setDropDownViewResource(R.layout.myspinner_dropdown);
    money_brank.setAdapter(adapter);
    //
    money_brank.setOnItemSelectedListener(
        new OnItemSelectedListener() {
          @Override
          public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
            int position = money_brank.getSelectedItemPosition();
            bankName = allName[position];
          }

          @Override
          public void onNothingSelected(AdapterView<?> arg0) {}
        });
    final EditText money_bank_start =
        (EditText) getView.findViewById(R.id.get_money_bank_start_edit);
    final EditText money_bank_num = (EditText) getView.findViewById(R.id.get_money_bank_num_edit);
    final EditText money = (EditText) getView.findViewById(R.id.get_money_money_edit);
    Button submit = (Button) getView.findViewById(R.id.get_money_img_submit);
    submit.setBackgroundResource(R.drawable.join_info_btn_selecter);
    Button cancel = (Button) getView.findViewById(R.id.get_money_img_back);
    cancel.setBackgroundResource(R.drawable.join_info_btn_selecter);
    submit.setOnClickListener(
        new OnClickListener() {
          public void onClick(View v) {
            ChangeWithdrawPojo changeWithdPojo = new ChangeWithdrawPojo();
            String nameStr = name.getText().toString();
            String moneyStr = money.getText().toString();
            String bankNameStr = bankName;
            String bankAreaStr = money_bank_start.getText().toString();
            String bankNoStr = money_bank_num.getText().toString();
            changeWithdPojo.setUserno(userno);
            changeWithdPojo.setPhonenum(phonenum);
            changeWithdPojo.setSessionid(sessionid);
            changeWithdPojo.setBankname(bankNameStr);
            if (nameStr.equals("")) {
              Toast.makeText(AccountWithdrawActivity.this, "持卡人名不能为空!", Toast.LENGTH_SHORT).show();
            } else if (bankAreaStr.equals("")) {
              Toast.makeText(AccountWithdrawActivity.this, "开卡地址不能为空!", Toast.LENGTH_SHORT).show();
            } else if (bankNoStr.equals("")) {
              Toast.makeText(AccountWithdrawActivity.this, "银行卡号不能为空!", Toast.LENGTH_SHORT).show();
            } else if (moneyStr.equals("")) {
              Toast.makeText(AccountWithdrawActivity.this, "提现金额不能为空!", Toast.LENGTH_SHORT).show();
            } else if (Integer.parseInt(moneyStr) < 1) {
              Toast.makeText(AccountWithdrawActivity.this, "至少提现一元!", Toast.LENGTH_SHORT).show();
            } else {
              changeWithdPojo.setName(nameStr);
              changeWithdPojo.setAmount(PublicMethod.toFen(moneyStr));
              changeWithdPojo.setAraeaname(bankAreaStr);
              changeWithdPojo.setBankcardno(bankNoStr);
              accountWithdrawNet(changeWithdPojo);
            }
          }
        });
    cancel.setOnClickListener(
        new OnClickListener() {
          public void onClick(View v) {
            finish();
          }
        });
    name.append(info.getNameStr());
    money_bank_start.append(info.getAdd());
    money_bank_num.append(info.getNum());
    money.append(info.getMoney());
    return getView;
  }
コード例 #20
0
  /**
   * method to get stored accounts from registry
   *
   * @param registry Registry
   * @return list of AccountInfo
   * @throws IssueTrackerException thrown if unable to obtain resources from registry
   */
  public static List<AccountInfo> getAccounts(Registry registry) throws IssueTrackerException {

    List<AccountInfo> accounts = new ArrayList<AccountInfo>();
    try {

      // check whether resources exist at the registry path
      if (registry.resourceExists(IssueTrackerConstants.ISSUE_TRACKERS_RESOURCE_PATH)) {

        // get the collection
        Collection collection =
            (Collection) registry.get(IssueTrackerConstants.ISSUE_TRACKERS_RESOURCE_PATH);

        if (null != collection) {

          // get paths of resources in the collection
          String[] paths = collection.getChildren();

          // for each resource construct the corresponding AccountInfo instance and add it to the
          // list
          for (String path : paths) {

            AccountInfo accountInfo = new AccountInfo();
            GenericCredentials credentials = new GenericCredentials();

            if (registry.resourceExists(path)) {
              Resource resource = registry.get(path);

              List<String> accountPropertySet =
                  resource.getPropertyValues(IssueTrackerConstants.ACCOUNT_KEY);
              accountInfo.setKey(accountPropertySet.get(accountPropertySet.size() - 1));

              List<String> urlPropertySet =
                  resource.getPropertyValues(IssueTrackerConstants.ISSUE_TRACKER_URL);
              String url = urlPropertySet.get(urlPropertySet.size() - 1);

              List<String> usernamePropertySet =
                  resource.getPropertyValues(IssueTrackerConstants.ACCOUNT_LOGIN_USERNAME);
              String username = usernamePropertySet.get(usernamePropertySet.size() - 1);

              List<String> emailPropertySet =
                  resource.getPropertyValues(IssueTrackerConstants.ACCOUNT_EMAIL);
              String email = emailPropertySet.get(emailPropertySet.size() - 1);

              List<String> uidPropertySet =
                  resource.getPropertyValues(IssueTrackerConstants.ACCOUNT_UID);
              String uid = uidPropertySet.get(uidPropertySet.size() - 1);

              List<String> hasSupportPropertySet =
                  resource.getPropertyValues(IssueTrackerConstants.HAS_SUPPORT_ACCOUNT);
              String hasSupport = hasSupportPropertySet.get(usernamePropertySet.size() - 1);

              List<String> passwordPropertySet;

              passwordPropertySet =
                  resource.getPropertyValues(
                      IssueTrackerConstants.ACCOUNT_PASSWORD_HIDDEN_PROPERTY);

              // for users with older accounts hidden password property does not exist. for them,
              // have to get the older property
              // until the account is edited.
              if (null == passwordPropertySet) {
                passwordPropertySet =
                    resource.getPropertyValues(IssueTrackerConstants.ACCOUNT_PASSWORD);
              }

              String password = "";
              if (null != passwordPropertySet) {

                String encryptedPassword = passwordPropertySet.get(passwordPropertySet.size() - 1);

                password =
                    new String(
                        CryptoUtil.getDefaultCryptoUtil()
                            .base64DecodeAndDecrypt(encryptedPassword));
              }
              String isAutoReportingEnabled =
                  resource.getProperty(IssueTrackerConstants.AUTO_REPORTING);

              if (null != isAutoReportingEnabled
                  && IssueTrackerConstants.IS_AUTO_REPORTING_ENABLED.equals(
                      isAutoReportingEnabled)) {
                accountInfo.setAutoReportingEnable(true);

                AutoReportingSettings settings = new AutoReportingSettings();
                String projectName =
                    resource.getProperty(IssueTrackerConstants.AUTO_REPORTING_PROJECT);
                settings.setProjectName(projectName);
                String priority =
                    resource.getProperty(IssueTrackerConstants.AUTO_REPORTING_PRIORITY);
                settings.setPriority(priority);
                String type = resource.getProperty(IssueTrackerConstants.AUTO_REPORTING_ISSUE_TYPE);
                settings.setIssueType(type);
                accountInfo.setAutoReportingSettings(settings);
              } else {
                accountInfo.setAutoReportingEnable(false);
              }

              if (!"".equals(url) && !"".equals(username) && !"".equals(password)) {
                credentials.setUrl(url);
                credentials.setUsername(username);
                credentials.setPassword(password);
                accountInfo.setCredentials(credentials);
                accountInfo.setEmail(email);
                accountInfo.setUid(uid);
                accountInfo.setHasSupportAccount(Boolean.getBoolean(hasSupport));
                accounts.add(accountInfo);
              }
            }
          }
        }
      }
    } catch (RegistryException e) {
      ExceptionHandler.handleException("Error getting resources from registry", e, log);
    } catch (CryptoException e) {
      ExceptionHandler.handleException("Error decrypting password", e, log);
    }

    return accounts;
  }
コード例 #21
0
  /**
   * method to persist credentials of a jira account
   *
   * @param registry Registry
   * @param accountInfo AccountInfo
   * @throws IssueTrackerException thrown id unable to store resources in the registry
   */
  public static void persistCredentials(Registry registry, AccountInfo accountInfo)
      throws IssueTrackerException {

    Resource resource = null;

    String path = IssueTrackerConstants.ISSUE_TRACKERS_RESOURCE_PATH + accountInfo.getKey();

    try {
      // if the collection does not exist create one
      if (!registry.resourceExists(IssueTrackerConstants.ISSUE_TRACKERS_RESOURCE_PATH)) {
        Collection collection = registry.newCollection();
        registry.put(IssueTrackerConstants.ISSUE_TRACKERS_RESOURCE_PATH, collection);
      }

      // get registry resource
      if (registry.resourceExists(path)) {
        resource = registry.get(path);
      } else {
        resource = registry.newResource();
      }
    } catch (RegistryException e) {
      ExceptionHandler.handleException("Error accessing registry", e, log);
    }

    // get credentials from account info
    GenericCredentials credentials;
    credentials = accountInfo.getCredentials();

    // set properties of the registry resources
    if (resource != null) {
      resource.addProperty(IssueTrackerConstants.ACCOUNT_KEY, accountInfo.getKey());
      resource.addProperty(IssueTrackerConstants.ISSUE_TRACKER_URL, credentials.getUrl());
      resource.addProperty(IssueTrackerConstants.ACCOUNT_LOGIN_USERNAME, credentials.getUsername());
      resource.addProperty(IssueTrackerConstants.ACCOUNT_EMAIL, accountInfo.getEmail());
      resource.addProperty(IssueTrackerConstants.ACCOUNT_UID, accountInfo.getUid());
      resource.addProperty(
          IssueTrackerConstants.HAS_SUPPORT_ACCOUNT,
          String.valueOf(accountInfo.isHasSupportAccount()));

      // set properties related with automatic reporting
      if (accountInfo.isAutoReportingEnable()) {

        AutoReportingSettings settings = accountInfo.getAutoReportingSettings();
        resource.addProperty(
            IssueTrackerConstants.AUTO_REPORTING, IssueTrackerConstants.IS_AUTO_REPORTING_ENABLED);
        resource.addProperty(
            IssueTrackerConstants.AUTO_REPORTING_PROJECT, settings.getProjectName());
        resource.addProperty(IssueTrackerConstants.AUTO_REPORTING_PRIORITY, settings.getPriority());
        resource.addProperty(
            IssueTrackerConstants.AUTO_REPORTING_ISSUE_TYPE, settings.getIssueType());

      } else {
        resource.addProperty(
            IssueTrackerConstants.AUTO_REPORTING, IssueTrackerConstants.IS_AUTO_REPORTING_DISABLED);
      }

      // encrypt and store password
      String password = credentials.getPassword();

      if (null != password && !"".equals(password)) {
        byte[] bytes = (password).getBytes();

        try {
          String base64String = CryptoUtil.getDefaultCryptoUtil().encryptAndBase64Encode(bytes);
          resource.addProperty(
              IssueTrackerConstants.ACCOUNT_PASSWORD_HIDDEN_PROPERTY, base64String);
        } catch (org.wso2.carbon.core.util.CryptoException e) {
          ExceptionHandler.handleException("Error accessing registry", e, log);
        }
      }
    }

    // put resource to registry
    try {
      registry.put(path, resource);
    } catch (RegistryException e) {
      ExceptionHandler.handleException("Error while persisting accountInfo", e, log);
    }
  }
コード例 #22
0
ファイル: ManagePanel.java プロジェクト: funnyData/mock-stock
  private void insertRankTableRow(int row, final AccountInfo info) {
    NumberFormat fmt = NumberFormat.getFormat("#,##0.00");
    rankGrid.setWidget(row, 0, new Label(String.valueOf(row)));
    rankGrid.getCellFormatter().addStyleName(row, 0, "textCell");
    rankGrid.setWidget(row, 1, new Label(info.getDisplayName()));
    rankGrid.getCellFormatter().addStyleName(row, 1, "textCell");
    rankGrid.setWidget(row, 2, new Label(fmt.format(info.getIntialPrincipal())));
    rankGrid.getCellFormatter().addStyleName(row, 2, "numericCell");
    rankGrid.setWidget(row, 3, new Label(fmt.format(info.getLeftCapitical())));
    rankGrid.getCellFormatter().addStyleName(row, 3, "numericCell");
    rankGrid.setWidget(row, 4, new Label(fmt.format(info.getStockValue())));
    rankGrid.getCellFormatter().addStyleName(row, 4, "numericCell");
    rankGrid.setWidget(row, 5, new Label(fmt.format(info.getTotalValue())));
    rankGrid.getCellFormatter().addStyleName(row, 5, "numericCell");
    rankGrid.setWidget(row, 6, new Label(fmt.format(info.getProfit())));
    rankGrid.getCellFormatter().addStyleName(row, 6, "numericCell");
    rankGrid.setWidget(row, 7, new Label(fmt.format(info.getProfitPct()) + "%"));
    rankGrid.getCellFormatter().addStyleName(row, 7, "numericCell");
    if (info.getProfit() > 0) {
      rankGrid.getCellFormatter().removeStyleName(row, 7, "negativeChange");
      rankGrid.getCellFormatter().addStyleName(row, 7, "positiveChange");
      rankGrid.getCellFormatter().removeStyleName(row, 6, "negativeChange");
      rankGrid.getCellFormatter().addStyleName(row, 6, "positiveChange");
    } else if (info.getProfit() < 0) {
      rankGrid.getCellFormatter().removeStyleName(row, 7, "positiveChange");
      rankGrid.getCellFormatter().addStyleName(row, 7, "negativeChange");
      rankGrid.getCellFormatter().removeStyleName(row, 6, "positiveChange");
      rankGrid.getCellFormatter().addStyleName(row, 6, "negativeChange");
    } else {
      rankGrid.getCellFormatter().removeStyleName(row, 7, "positiveChange");
      rankGrid.getCellFormatter().removeStyleName(row, 7, "negativeChange");
      rankGrid.getCellFormatter().removeStyleName(row, 6, "positiveChange");
      rankGrid.getCellFormatter().removeStyleName(row, 6, "negativeChange");
    }

    if (info.getTotalValue() != 0) {
      rankGrid.setWidget(
          row, 8, new Label(fmt.format(100.0 * info.getStockValue() / info.getTotalValue()) + "%"));
    } else {
      rankGrid.setWidget(row, 8, new Label("--"));
    }
    rankGrid.getCellFormatter().addStyleName(row, 8, "numericCell");

    Anchor link = new Anchor("交易记录");
    rankGrid.setWidget(row, 9, link);
    link.addClickHandler(
        new ClickHandler() {
          public void onClick(ClickEvent event) {
            showTransHistory(info.getUsername(), info.getDisplayName());
          }
        });
    rankGrid.getCellFormatter().addStyleName(row, 9, "textCell");

    Anchor positionBtn = new Anchor("当前持仓");
    rankGrid.setWidget(row, 10, positionBtn);
    positionBtn.addClickHandler(
        new ClickHandler() {
          public void onClick(ClickEvent event) {
            showPosition(info.getUsername(), info.getDisplayName());
          }
        });
    rankGrid.getCellFormatter().addStyleName(row, 10, "textCell");
  }