Beispiel #1
0
 public void clear(AjaxBehaviorEvent event) {
   groupEdit = new Group();
   filmEdit = new Distribution();
   filmEdit.setStatus(StatusEnum.NEW);
   clearSubmittedValues(event.getComponent(), "groupDialog");
   clearSubmittedValues(event.getComponent(), "filmDialog");
   if (!groupItem.isEmpty()) {
     filmEdit.setGroup((Group) groupItem.get(0).getValue());
   }
   dialogChangeGroup(null);
 }
Beispiel #2
0
  public void testTorrent(AjaxBehaviorEvent event) {
    // TODO Это точно такая же часть как и в testMessage
    FacesContext context = FacesContext.getCurrentInstance();
    UIComponent component = UIComponent.getCurrentComponent(context);
    String url = (String) ((UIInput) component.findComponent("filmLinkRutracker")).getValue();

    WebBrowser webBrowser = new WebBrowser(LogEnum.WEB.getLog());
    //

    String regexp =
        (String) ((UIInput) component.findComponent("filmRegexpSerialNumber")).getValue();
    FacesMessage message = new FacesMessage();
    try {
      webBrowser.goToUrl(url);
      filmEdit.setTitle(webBrowser.getTitle());
      TorrentFile torrent = webBrowser.downloadTorrentFile(webBrowser.getTorrentUrl());
      ByteArrayInputStream bais = new ByteArrayInputStream(torrent.getContent());
      TorrentInfo info = new TorrentInfo(new BufferedInputStream(bais));
      StringBuilder builder = new StringBuilder();
      for (String fileName : info.getInfo()) {
        builder
            .append(fileName)
            .append(" № серии: \"")
            .append(MessageUtils.parseEpisode(fileName, regexp))
            .append("\"  ");
      }
      message.setSummary(builder.toString());
      message.setSeverity(FacesMessage.SEVERITY_INFO);
    } catch (CoreException e) {
      message.setSeverity(FacesMessage.SEVERITY_ERROR);
      message.setSummary(e.getMessage());
    }
    context.addMessage("otherMessageHidden", message);
    context.renderResponse();
  }
Beispiel #3
0
  public void saveFilm(AjaxBehaviorEvent event) {
    WebBrowser webBrowser = new WebBrowser(LogEnum.WEB.getLog());
    try {
      webBrowser.goToUrl(filmEdit.getLinkRutracker());
      filmEdit.setTitle(webBrowser.getTitle());
    } catch (CoreException e) {
      // TODO Избавится от такого большого исключения сделать один статический метод
      FacesMessage error = new FacesMessage();
      error.setSeverity(FacesMessage.SEVERITY_ERROR);
      error.setSummary(e.getMessage());
      throw new ValidatorException(error);
    }

    if (filmEdit.getType() != TypeDistributionEnum.SERIALS.getType()) {
      filmEdit.setRegexpSerialNumber(null);
      filmEdit.setSeasonNumber(null);
    }
    DaoFactory.getInstance().getDistributionDao().addDistribution(filmEdit);
    if (filmList.size() > 0) filmList.add(0, filmEdit);
    filmList.add(filmEdit);
  }
Beispiel #4
0
  private List<Distribution> prepareFilmList() {
    List<Distribution> filmList = null;
    filmList = new ArrayList<Distribution>();
    Collections.sort(
        allFilmList,
        new Comparator<Distribution>() {
          @Override
          public int compare(Distribution o1, Distribution o2) {
            return o1.getId().compareTo(o2.getId());
          }
        });
    if (!sortByDate) Collections.reverse(allFilmList);

    for (Distribution film : allFilmList) {
      if ((selectGroupData == null || film.getGroup().equals(selectGroupData))
          && (film.getStatus() == actualStatus || actualStatus == null)
          && film.getTitle().toLowerCase().contains(findFilmParam.toLowerCase())) {
        filmList.add(film);
      }
    }
    return filmList;
  }
Beispiel #5
0
  public void testMessage(AjaxBehaviorEvent event) {
    FacesContext context = FacesContext.getCurrentInstance();
    UIComponent component = UIComponent.getCurrentComponent(context);
    String url = (String) ((UIInput) component.findComponent("filmLinkRutracker")).getValue();

    WebBrowser webBrowser = new WebBrowser(LogEnum.WEB.getLog());
    FacesMessage message = new FacesMessage();
    try {
      webBrowser.goToUrl(url);
      String title = webBrowser.getTitle();
      filmEdit.setTitle(title);
      String regexp = (String) ((UIInput) component.findComponent("filmMailRegexp")).getValue();
      String mailMessage =
          (String) ((UIInput) component.findComponent("filmMailMessage")).getValue();
      message.setSummary(MessageUtils.createMessage(title, regexp, mailMessage));
      message.setSeverity(FacesMessage.SEVERITY_INFO);
    } catch (CoreException e) {
      message.setSeverity(FacesMessage.SEVERITY_ERROR);
      message.setSummary(e.getMessage());
    }
    context.addMessage("otherMessageHidden", message);
    context.renderResponse();
  }
Beispiel #6
0
 public void deleteFilm(AjaxBehaviorEvent event) {
   Distribution distribution = filmModel.getRowData();
   DaoFactory.getInstance().getDistributionDao().removeDistribution(distribution.getId());
   filmList.remove(distribution);
   //        getAllFilm();
 }
Beispiel #7
0
 public void dialogChangeGroup(AjaxBehaviorEvent event) {
   if (filmEdit != null && filmEdit.getGroup() != null) {
     filmEdit.setMailMessage(filmEdit.getGroup().getEmailMessage());
     filmEdit.setMailRegexp(filmEdit.getGroup().getEmailRegexp());
   }
 }