Exemple #1
0
  public Term add(String name, String shortDescription, String description) {
    name = name.replace("\"", "").replace("«", "").replace("»", "").trim();
    name =
        WordUtils.capitalize(
            name,
            new char[] {
              '@'
            }); // Делаем первую букву большой, @ - знак который не появляеться в названии, чтобы
    // поднялась только первая буква всей фразы
    Term term = termDao.getByName(name);
    if (term == null) {
      term = termDao.save(new Term(name, shortDescription, description));
      if (shortDescription != null)
        term.setTaggedShortDescription(termsMarker.mark(shortDescription));
      if (description != null) term.setTaggedDescription(termsMarker.mark(description));
      String termName = term.getName();
      log.info("Added: " + termName);
      if (TermUtils.isComposite(termName)) {
        String target = TermUtils.getNonCosmicCodePart(termName);
        if (target != null) {
          findAliases(term, target, termName.replace(target, ""));
        }
      } else if (!TermUtils.isCosmicCode(termName)) {
        findAliases(term, termName, "");
      }
      publisher.publishEvent(new NewTermEvent(term));
    } else {
      String oldShortDescription = null;
      if (shortDescription != null && !shortDescription.isEmpty()) {
        oldShortDescription = term.getShortDescription();
        term.setShortDescription(shortDescription);
        term.setTaggedShortDescription(termsMarker.mark(shortDescription));
      }
      String oldDescription = null;
      if (description != null && !description.isEmpty()) {
        oldDescription = term.getDescription();
        term.setDescription(description);
        term.setTaggedDescription(termsMarker.mark(description));
      }
      termDao.save(term);
      publisher.publishEvent(new TermUpdatedEvent(term, oldShortDescription, oldDescription));
    }

    new Thread(
            new Runnable() {
              @Override
              public void run() {
                termsMap.reload();
              }
            })
        .start();

    return term;
  }