public void setCredentialsAuthExtras(final Intent intent) {
   if (intent != null) {
     intent.putExtra(
         Intents.EXTRA_CREDENTIALS_AUTH_USERNAME,
         StringUtils.defaultIfBlank(username, StringUtils.EMPTY));
     intent.putExtra(
         Intents.EXTRA_CREDENTIALS_AUTH_PASSWORD,
         StringUtils.defaultIfBlank(password, StringUtils.EMPTY));
   }
 }
Пример #2
0
  /**
   * Method to read the configuration.
   *
   * @throws IOException I/O error.
   */
  @PostConstruct
  public final void initialize() throws IOException {
    final Properties props = new Properties();
    if (this.configFile.exists()) {
      try (InputStream input = new FileInputStream(this.configFile)) {
        props.load(input);
      }
    }

    this.suites =
        StringUtils.defaultIfBlank(props.getProperty("suites"), "main, contrib, non-free");
    this.baseRepository =
        StringUtils.defaultIfBlank(
            props.getProperty("baseRepository"), "http://ftp.de.debian.org/debian/");
  }
Пример #3
0
 /**
  * 전체 사용자 목록을 보여준다.
  *
  * <p>when 관리자 페이지의 사용자 관리
  *
  * <p>사이트에 가입된 사용자 목록을 {@code loginId} 로 조회하여 목록을 {@link Page} 형태로 보여준다. 페이징 사이즈는 {@link
  * User#USER_COUNT_PER_PAGE}를 참조한다.
  *
  * @param pageNum pager number
  * @param loginId loginId
  * @return the result
  * @see {@link User#findUsers(int, String)}
  */
 public static Result userList(int pageNum, String query) {
   String state =
       StringUtils.defaultIfBlank(request().getQueryString("state"), UserState.ACTIVE.name());
   UserState userState = UserState.valueOf(state);
   Page<User> users = User.findUsers(pageNum - 1, query, userState);
   return ok(userList.render("title.siteSetting", users, userState, query));
 }
Пример #4
0
  @Override
  public String importQuestionnareOds(String filename, String questionnaireName) throws Exception {
    SpreadsheetDocument document = SpreadsheetDocument.loadDocument(new File(filename));
    Table sheet = document.getSheetByIndex(0);

    List<String> questions = new ArrayList<>();

    for (int i = 1; i < sheet.getRowList().size(); i++) {
      Row row = sheet.getRowList().get(i);

      String question = getCellStringValue(row, 0);

      if (StringUtils.isBlank(question)) {
        break;
      }

      String levelString = getCellStringValue(row, 1);
      long level = Long.valueOf(StringUtils.replace(levelString, "D", ""));
      String tagsString = getCellStringValue(row, 2);
      List<String> tags = Collections.emptyList();
      if (StringUtils.isNotBlank(tagsString)) {
        tags = Lists.newArrayList(StringUtils.split(tagsString, ", "));
      }
      String tip = StringUtils.defaultIfBlank(getCellStringValue(row, 3), null);

      XContentBuilder builder =
          jsonBuilder()
              .startObject()
              .field("title", question)
              .field("level", level)
              .field("tags", tags)
              .field("tip", tip)
              .endObject();

      IndexResponse indexResponse =
          client
              .prepareIndex(domainResolver.resolveQuestionIndex(), Types.question)
              .setSource(builder)
              .execute()
              .actionGet();

      questions.add(indexResponse.getId());
    }

    XContentBuilder questionnaireBuilder =
        jsonBuilder()
            .startObject()
            .field("name", questionnaireName)
            .field("questions", questions)
            .endObject();

    IndexResponse indexResponse =
        client
            .prepareIndex(domainResolver.resolveQuestionIndex(), Types.questionnaire)
            .setSource(questionnaireBuilder)
            .execute()
            .actionGet();

    return indexResponse.getId();
  }
 private Visibility getVisibility(XWikiDocument doc) {
   String visibility = null;
   BaseObject visibilityObj = doc.getXObject(Visibility.CLASS_REFERENCE);
   if (visibilityObj != null) {
     visibility = visibilityObj.getStringValue("visibility");
   }
   return this.manager.resolveVisibility(StringUtils.defaultIfBlank(visibility, "private"));
 }
  /**
   * 检查活动是否合法 创建的时候:创建人,活动类型,标题
   *
   * @param pai
   * @param domain
   */
  private void actCreateChk(XQActivityVO pai, String domain) {
    if (pai == null) {
      throw new BizException(GlobalErrorCode.INVALID_ARGUMENT, "活动不能为空");
    }
    domain = StringUtils.defaultIfBlank(domain, "xiangqu");

    // 创建人
    if (StringUtils.isBlank(pai.getCreateOper())) {
      throw new BizException(GlobalErrorCode.INVALID_ARGUMENT, "创建人不能为空");
    } else {
      User user = null;
      if (!StringUtils.isBlank(pai.getExtUid())) {
        user = userService.loadExtUser(domain, pai.getExtUid());
      } else if (!StringUtils.isBlank(pai.getCreateOper())) {
        user = userService.loadExtUser(domain, pai.getCreateOper());
      } else {
        user = userService.loadByAdmin(pai.getCreateOper());
      }

      if (user == null || !domain.equals(user.getPartner())) {
        log.debug("用户不存在");
        throw new BizException(GlobalErrorCode.INVALID_ARGUMENT, "用户不存在");
      }

      if (StringUtils.isBlank(pai.getShopId())) {
        pai.setShopId(user.getShopId());
      }
    }

    if (StringUtils.isBlank(pai.getActId())) {
      // 活动名称
      if (StringUtils.isBlank(pai.getActTitle())) {
        throw new BizException(GlobalErrorCode.THIRDPLANT_BUZERROR, "活动名称不能为空");
      }

      // 活动永久的,不需要时间信息
      if (ActivityType.PUBLIC_FOREVER.equals(pai.getActType())) {
        pai.setActState(ActivityStatus.IN_PROGRESS);
        return;
      }

      pai.setActState(ActivityStatus.NOT_STARTED);
      if (pai.getActStartTime() == null || pai.getActEndTime() == null) {
        throw new BizException(GlobalErrorCode.THIRDPLANT_BUZERROR, "活动开始或结束时间不能为空");
      }

      // 活动报名时间
      if (pai.getApplyEndTime() != null
          && pai.getApplyStartTime() != null
          && pai.getApplyEndTime() > pai.getActStartTime()) {
        throw new BizException(GlobalErrorCode.THIRDPLANT_BUZERROR, "活动报名 截止时间不能大于开始时间");
      }
    }
  }
Пример #7
0
  /**
   * 계정을 장금 / 해제한다.
   *
   * <p>when 사용자 관리 페이지의 계정 장금/해제
   *
   * <p>세션 {@code loginId} 가 사이트 관리자이고 삭제할 {@code loginId}가 {@code anonymous}가 아니면 계정 장금 또는 해제한후 사용자
   * 관리페이지로 리다이렉트한다. 세션 {@code loginId} 가 사이트 관리자이고 삭제할 {@code loginId}가 익명사용자이면 경고메세지와 함께사용자 관리페이지로
   * 리다이렉트한다. 세션 {@code loginId} 가 사이트 관리자가 아니면 경고메세지와 함께 Yobi 첫페이지로 리다이렉트한다.
   *
   * @param loginId the login id
   * @return the result
   */
  public static Result toggleAccountLock(String loginId, String state, String query) {
    String stateParam = StringUtils.defaultIfBlank(state, UserState.ACTIVE.name());
    UserState userState = UserState.valueOf(stateParam);

    if (User.findByLoginId(session().get("loginId")).isSiteManager()) {
      User targetUser = User.findByLoginId(loginId);
      if (targetUser.isAnonymous()) {
        flash(Constants.WARNING, "user.notExists.name");
        return redirect(routes.SiteApp.userList(0, null));
      }
      if (targetUser.state == UserState.ACTIVE) {
        targetUser.changeState(UserState.LOCKED);
      } else {
        targetUser.changeState(UserState.ACTIVE);
      }
      return ok(
          userList.render(
              "title.siteSetting", User.findUsers(0, query, userState), userState, query));
    }
    flash(Constants.WARNING, "error.auth.unauthorized.waringMessage");
    return redirect(routes.Application.index());
  }
Пример #8
0
 /**
  * 전체 이슈 목록을 state 별로 보여준다.
  *
  * <p>when 관리자 페이지의 이슈 관리
  *
  * <p>최근작성일로 정렬된 {@code pageNum} 에 해당하는 이슈 목록을 가져온다.
  *
  * @param pageNum page number
  * @return the result
  */
 public static Result issueList(int pageNum) {
   String state = StringUtils.defaultIfBlank(request().getQueryString("state"), State.OPEN.name());
   State currentState = State.valueOf(state.toUpperCase());
   Page<Issue> page = Issue.findIssuesByState(ISSUE_COUNT_PER_PAGE, pageNum - 1, currentState);
   return ok(issueList.render("title.siteSetting", page, currentState));
 }
Пример #9
0
    @Override
    public void onClick(final View arg0) {
      final String bearingText = bearing.getText().toString();
      // combine distance from EditText and distanceUnit saved from Spinner
      final String distanceText =
          distanceView.getText().toString()
              + distanceUnits.get(distanceUnitSelector.getSelectedItemPosition());
      final String latText = buttonLat.getText().toString();
      final String lonText = buttonLon.getText().toString();

      if (StringUtils.isBlank(bearingText)
          && StringUtils.isBlank(distanceText)
          && StringUtils.isBlank(latText)
          && StringUtils.isBlank(lonText)) {
        Dialogs.message(
            EditWaypointActivity.this,
            R.string.err_point_no_position_given_title,
            R.string.err_point_no_position_given);
        return;
      }

      Geopoint coords;

      if (StringUtils.isNotBlank(latText) && StringUtils.isNotBlank(lonText)) {
        try {
          coords = new Geopoint(latText, lonText);
        } catch (final Geopoint.ParseException e) {
          showToast(res.getString(e.resource));
          return;
        }
      } else {
        coords = app.currentGeo().getCoords();
      }

      if (StringUtils.isNotBlank(bearingText) && StringUtils.isNotBlank(distanceText)) {
        // bearing & distance
        double bearing;
        try {
          bearing = Double.parseDouble(bearingText);
        } catch (final NumberFormatException ignored) {
          Dialogs.message(
              EditWaypointActivity.this,
              R.string.err_point_bear_and_dist_title,
              R.string.err_point_bear_and_dist);
          return;
        }

        double distance;
        try {
          distance = DistanceParser.parseDistance(distanceText, !Settings.useImperialUnits());
        } catch (final NumberFormatException ignored) {
          showToast(res.getString(R.string.err_parse_dist));
          return;
        }

        coords = coords.project(bearing, distance);
      }

      final String givenName = waypointName.getText().toString().trim();
      final String name =
          StringUtils.defaultIfBlank(givenName, getDefaultWaypointName(getSelectedWaypointType()));
      final String noteText = note.getText().toString().trim();
      final Geopoint coordsToSave = coords;
      final WaypointType type = getSelectedWaypointType();
      final boolean visited = visitedCheckBox.isChecked();
      final ProgressDialog progress =
          ProgressDialog.show(
              EditWaypointActivity.this,
              getString(R.string.waypoint),
              getString(R.string.waypoint_being_saved),
              true);
      final Handler finishHandler =
          new Handler() {

            @Override
            public void handleMessage(final Message msg) {
              switch (msg.what) {
                case UPLOAD_SUCCESS:
                  progress.dismiss();
                  finish();
                  showToast(
                      getString(
                          R.string.waypoint_coordinates_has_been_modified_on_website,
                          coordsToSave));
                  break;
                case SUCCESS:
                  progress.dismiss();
                  finish();
                  break;
                case UPLOAD_START:
                  progress.setMessage(
                      getString(R.string.waypoint_coordinates_uploading_to_website, coordsToSave));
                  break;
                case UPLOAD_ERROR:
                  progress.dismiss();
                  finish();
                  showToast(getString(R.string.waypoint_coordinates_upload_error));
                  break;
                case UPLOAD_NOT_POSSIBLE:
                  progress.dismiss();
                  finish();
                  showToast(
                      getString(R.string.waypoint_coordinates_couldnt_be_modified_on_website));
                  break;
                case SAVE_ERROR:
                  progress.dismiss();
                  finish(); // TODO: should we close activity here ?
                  showToast(res.getString(R.string.err_waypoint_add_failed));
                  break;
                default:
                  throw new UnsupportedOperationException();
              }
            }
          };

      class SaveWptTask extends AsyncTask<Void, Void, Void> {

        @Override
        protected Void doInBackground(final Void... params) {
          final Waypoint waypoint = new Waypoint(name, type, own);
          waypoint.setGeocode(geocode);
          waypoint.setPrefix(prefix);
          waypoint.setLookup(lookup);
          waypoint.setCoords(coordsToSave);
          waypoint.setNote(noteText);
          waypoint.setVisited(visited);
          waypoint.setId(waypointId);

          final Geocache cache = DataStore.loadCache(geocode, LoadFlags.LOAD_WAYPOINTS);
          if (cache == null) {
            finishHandler.sendEmptyMessage(SAVE_ERROR);
            return null;
          }
          final Waypoint oldWaypoint = cache.getWaypointById(waypointId);
          if (cache.addOrChangeWaypoint(waypoint, true)) {
            DataStore.saveCache(cache, EnumSet.of(SaveFlag.DB));
            if (!StaticMapsProvider.hasAllStaticMapsForWaypoint(geocode, waypoint)) {
              StaticMapsProvider.removeWpStaticMaps(oldWaypoint, geocode);
              if (Settings.isStoreOfflineWpMaps()) {
                StaticMapsProvider.storeWaypointStaticMap(cache, waypoint).subscribe();
              }
            }
            if (modifyLocal.isChecked() || modifyBoth.isChecked()) {
              if (!cache.hasUserModifiedCoords()) {
                final Waypoint origWaypoint =
                    new Waypoint(
                        CgeoApplication.getInstance()
                            .getString(R.string.cache_coordinates_original),
                        WaypointType.ORIGINAL,
                        false);
                origWaypoint.setCoords(cache.getCoords());
                cache.addOrChangeWaypoint(origWaypoint, false);
                cache.setUserModifiedCoords(true);
              }
              cache.setCoords(waypoint.getCoords());
              DataStore.saveChangedCache(cache);
            }
            if (modifyBoth.isChecked() && waypoint.getCoords() != null) {
              finishHandler.sendEmptyMessage(UPLOAD_START);

              if (cache.supportsOwnCoordinates()) {
                final boolean result = uploadModifiedCoords(cache, waypoint.getCoords());
                finishHandler.sendEmptyMessage(result ? SUCCESS : UPLOAD_ERROR);
              } else {
                showToast(getString(R.string.waypoint_coordinates_couldnt_be_modified_on_website));
                finishHandler.sendEmptyMessage(UPLOAD_NOT_POSSIBLE);
              }
            } else {
              finishHandler.sendEmptyMessage(SUCCESS);
            }
          } else {
            finishHandler.sendEmptyMessage(SAVE_ERROR);
          }
          return null;
        }
      }
      new SaveWptTask().execute();
    }
Пример #10
0
  /**
   * 更新mdn live (apply)
   *
   * @param mdnLiveItem
   * @param liveDomain 直播服务域名
   * @param liveBandwidth 直播加速服务带宽(含单位)
   * @param liveProtocol 播放协议数组
   * @param bandwidth 出口带宽(含单位)
   * @param name 频道名称
   * @param guid 频道GUID
   * @param streamOutMode 直播流输出模式:1-Encoder模式;2-Transfer模式
   * @param encoderMode 编码器模式:1-HTTP拉流;2-RTMP推流
   * @param httpUrlEncoder HTTP拉流编码模式下的HTTP流地址
   * @param httpBitrate HTTP拉流编码模式下的HTTP流混合码率
   * @param hlsUrlEncoder RTMP推流编码模式下的M3U8流地址
   * @param hlsBitrateEncoder RTMP推流编码模式下的M3U8流混合码率
   * @param httpUrl HTTP流地址
   * @param httpBitrateEncoder HTTP流混合码率
   * @param hlsUrl M3U8流地址
   * @param hlsBitrate M3U8流混合码率
   */
  @Transactional(readOnly = false)
  public void updateMdnLiveItemToApply(
      MdnLiveItem mdnLiveItem,
      String bandwidth,
      String name,
      String guid,
      String liveDomain,
      String liveBandwidth,
      String liveProtocol,
      Integer streamOutMode,
      Integer encoderMode,
      String httpUrlEncoder,
      String httpBitrateEncoder,
      String hlsUrlEncoder,
      String hlsBitrateEncoder,
      String httpUrl,
      String httpBitrate,
      String hlsUrl,
      String hlsBitrate) {

    mdnLiveItem.setBandwidth(bandwidth);
    mdnLiveItem.setName(name);
    mdnLiveItem.setGuid(guid);
    mdnLiveItem.setLiveDomain(liveDomain);
    mdnLiveItem.setLiveBandwidth(liveBandwidth);
    mdnLiveItem.setLiveProtocol(liveProtocol);
    mdnLiveItem.setStreamOutMode(streamOutMode);

    if (MdnConstant.OutputMode.Encoder模式.toInteger().equals(streamOutMode)) {

      mdnLiveItem.setEncoderMode(encoderMode);

      if (MdnConstant.EncoderMode.拉流模式.toInteger().equals(encoderMode)) {

        mdnLiveItem.setHttpBitrate(StringUtils.defaultIfBlank(httpUrlEncoder, null));
        mdnLiveItem.setHttpUrl(StringUtils.defaultIfBlank(httpBitrateEncoder, null));

        mdnLiveItem.setHlsBitrate(null);
        mdnLiveItem.setHlsUrl(null);

      } else if (MdnConstant.EncoderMode.推流模式.toInteger().equals(encoderMode)) {

        mdnLiveItem.setHttpBitrate(null);
        mdnLiveItem.setHttpUrl(null);

        mdnLiveItem.setHlsBitrate(StringUtils.defaultIfBlank(hlsBitrateEncoder, null));
        mdnLiveItem.setHlsUrl(StringUtils.defaultIfBlank(hlsUrlEncoder, null));

      } else {
        mdnLiveItem.setHttpBitrate(null);
        mdnLiveItem.setHttpUrl(null);

        mdnLiveItem.setHlsBitrate(null);
        mdnLiveItem.setHlsUrl(null);
      }

    } else {

      mdnLiveItem.setEncoderMode(MdnConstant.EncoderMode.缺省模式.toInteger());

      mdnLiveItem.setHttpBitrate(httpBitrate);
      mdnLiveItem.setHttpUrl(httpUrl);

      mdnLiveItem.setHlsBitrate(hlsBitrate);
      mdnLiveItem.setHlsUrl(hlsUrl);
    }

    comm.mdnService.saveOrUpdate(mdnLiveItem);
  }
Пример #11
0
  /**
   * 新增多个直播MdnLiveItem
   *
   * @param mdnItem mdn对象
   * @param liveDomains 直播服务域名数组
   * @param liveBandwidths 直播加速服务带宽(含单位)数组
   * @param liveProtocols 播放协议数组
   * @param bandwidths 出口带宽(含单位)数组
   * @param channelNames 频道名称数组
   * @param channelGUIDs 频道GUID数组
   * @param streamOutModes 直播流输出模式:1-Encoder模式;2-Transfer模式数组
   * @param encoderModes 编码器模式:1-HTTP拉流;2-RTMP推流数组
   * @param httpUrls HTTP流地址数组
   * @param httpBitrates HTTP流混合码率数组
   * @param hlsUrls M3U8流地址数组
   * @param hlsBitrates M3U8流混合码率数组
   */
  @Transactional(readOnly = false)
  public void saveMdnLiveItem(
      MdnItem mdnItem,
      String[] liveDomains,
      String[] liveBandwidths,
      String[] liveProtocols,
      String[] bandwidths,
      String[] channelNames,
      String[] channelGUIDs,
      String[] streamOutModes,
      String[] encoderModes,
      String[] httpUrls,
      String[] httpBitrates,
      String[] hlsUrls,
      String[] hlsBitrates) {

    if (liveDomains != null) {
      for (int i = 0; i < liveDomains.length; i++) {
        MdnLiveItem mdnLiveItem = new MdnLiveItem();

        Integer streamOutMode = Integer.valueOf(streamOutModes[i]);
        Integer encoderMode = Integer.valueOf(encoderModes[i]);

        mdnLiveItem.setMdnItem(mdnItem);
        mdnLiveItem.setLiveDomain(liveDomains[i]);
        mdnLiveItem.setLiveBandwidth(liveBandwidths[i]);
        mdnLiveItem.setLiveProtocol(StringUtils.replace(liveProtocols[i], "-", ","));
        mdnLiveItem.setStreamOutMode(streamOutMode);
        mdnLiveItem.setEncoderMode(encoderMode);
        mdnLiveItem.setName(channelNames[i]);
        mdnLiveItem.setGuid(channelGUIDs[i]);
        mdnLiveItem.setBandwidth(bandwidths[i]);

        if (MdnConstant.OutputMode.Encoder模式.toInteger().equals(streamOutMode)) {

          if (MdnConstant.EncoderMode.拉流模式.toInteger().equals(encoderMode)) {

            if (httpBitrates.length != 0) {
              mdnLiveItem.setHttpBitrate(StringUtils.defaultIfBlank(httpBitrates[i], null));
            }

            if (httpUrls.length != 0) {
              mdnLiveItem.setHttpUrl(StringUtils.defaultIfBlank(httpUrls[i], null));
            }

          } else if (MdnConstant.EncoderMode.推流模式.toInteger().equals(encoderMode)) {

            if (hlsBitrates.length != 0) {
              mdnLiveItem.setHlsBitrate(StringUtils.defaultIfBlank(hlsBitrates[i], null));
            }

            if (hlsUrls.length != 0) {
              mdnLiveItem.setHlsUrl(StringUtils.defaultIfBlank(hlsUrls[i], null));
            }
          }

        } else {

          mdnLiveItem.setEncoderMode(EncoderMode.缺省模式.toInteger());

          mdnLiveItem.setHttpBitrate(httpBitrates[i]);
          mdnLiveItem.setHttpUrl(httpUrls[i]);

          mdnLiveItem.setHlsBitrate(hlsBitrates[i]);
          mdnLiveItem.setHlsUrl(hlsUrls[i]);
        }

        this.saveOrUpdate(mdnLiveItem);
      }
    }
  }
  /** @throws StringNotValidException a */
  public final void onBtnSaveClick() throws StringNotValidException {

    String firstName;
    String lastName;
    TableMain tm;

    try {
      firstName = StringUtils.defaultIfBlank(txtFirstName.getText(), "MusterName");
      lastName = StringUtils.defaultIfBlank(txtLastName.getText(), "MusterName");
      c.setFirstName(firstName);
      c.setLastName(lastName);

      // update table view with name only
      tm =
          MainPresenter.getData()
              .get(
                  MainPresenter.getMainPresenterInstance()
                      .getMainTable()
                      .getSelectionModel()
                      .getSelectedIndex());
      tm.setFirstName(firstName);
      tm.setLastName(lastName);

      // set rest of contact information
      c.setEmail(StringUtils.defaultIfBlank(txtEmail.getText(), "MusterEmail"));
      c.setPhoneNumber(StringUtils.defaultIfBlank(txtPhoneNumber.getText(), "MusterNummer"));
      if (contactImage != null) {
        c.setPhoto(contactImage);
      }
      c.getAddress().setZipCode(StringUtils.defaultString(txtZipCode.getText(), "12345"));
      c.getAddress().setStreet(StringUtils.defaultIfBlank(txtStreet.getText(), "MusterStraße"));
      c.getAddress().setCity(StringUtils.defaultIfBlank(txtCity.getText(), "MusterStadt"));
      c.getAddress().setCountry(StringUtils.defaultIfBlank(txtCountry.getText(), "MusterLand"));

      int housenumber = 0;

      if (!StringUtils.isNumeric(txtHouseNumber.getText()) || (txtHouseNumber.equals("0"))) {
        throw new HouseNumberNotValidException("Diese Hausnummer ist nicht erlaubt");
      }
      housenumber = Integer.parseInt(txtHouseNumber.getText());
      if (housenumber > 300) {
        throw new HouseNumberNotValidException(
            "Hausnummer zu groß: Maximal erlaubte Hausnummer '300'");
      }
      c.getAddress().setHouseNumber(housenumber);

      txtFirstName.clear();
      txtLastName.clear();
      txtBorn.clear();
      txtCity.clear();
      txtEmail.clear();
      txtHouseNumber.clear();
      txtZipCode.clear();
      txtPhoneNumber.clear();

      onBtnBackClick();
      logger.log(Level.INFO, "New Information saved:");

    } catch (Exception e) {
      logger.log(Level.SEVERE, e.getMessage());
    }
  }