Ejemplo n.º 1
0
  //	@Transactional(TransactionPropagationType.REQUIRED)
  //	@TransactionAttribute(TransactionAttributeType.REQUIRED)
  public void updateTextContentItem(ContentItemI item, String content) {

    ContentItem _item = item.getDelegate();

    if (renderingPipeline.renderEditor(_item, currentUser).equals(content)) {
      log.error("!!!!!!!!!!!!!!!!! renderingPipeline fails");
      return;
      // throw new TextContentNotChangedException("Could not create TextContentUpdate for an
      // unchanged text content");
    }
    StoringService storingPipeline = (StoringService) Component.getInstance("storingPipeline");

    TextContent tc = new TextContent(_item);
    tc.setXmlString(storingPipeline.processHtmlSource(_item.getResource(), content));
    tc = storingPipeline.processTextContent(_item.getResource(), tc);

    entityManager.persist(tc);

    // TODO: check whether content has changed and create version
    // TODO: maybe we can check this even before the pipeline runs?
    UpdateTextContentService utcs =
        (UpdateTextContentService) Component.getInstance("updateTextContentService");
    if (content != null) {
      utcs.updateTextContent(_item, tc);
    }

    _item.setTextContent(tc);

    Events.instance().raiseEvent(KiWiEvents.ACTIVITY_EDITCONTENTITEM, currentUser, _item);
    Events.instance().raiseTransactionSuccessEvent(KiWiEvents.CONTENT_UPDATED, _item);
  }
  /*
   * (non-Javadoc)
   *
   * @see
   * com.mydomain.maizsoft.cargaarchivos.IArchivoXMLNotas#guardarArchivoXml()
   */
  @Override
  public String guardarArchivoXml() {

    ConfiguracionesSistema path = entityManager.find(ConfiguracionesSistema.class, 1l);
    ConfiguracionesSistema pathbackup = entityManager.find(ConfiguracionesSistema.class, 20l);
    String pathFinal =
        path.getDetallesPropiedad() + "//" + pathbackup.getDetallesPropiedad() + "//";
    Calendar calendar = Calendar.getInstance();
    SimpleDateFormat simple = new SimpleDateFormat("yyyyddMMhhmmss");
    String date = simple.format(calendar.getTime());
    setNombre(date + "_backupNotas.xml");
    setPath(pathFinal);
    File directorio = new File(pathFinal);
    if (!directorio.exists()) {
      directorio.mkdirs();
    }

    try {
      open();
      write();

    } catch (Exception e) {
      FacesMessages mensaje = (FacesMessages) Component.getInstance(FacesMessages.class);
      mensaje.add("Se produjo un error técnico :(");
    }

    FacesMessages mensaje = (FacesMessages) Component.getInstance(FacesMessages.class);
    mensaje.add("Se genero el archivo " + getNombre() + " exitosamente :-)");

    return "";
  }
Ejemplo n.º 3
0
  protected void sendResetPasswordEmail(User user, String newPassword) {
    Person person = (Person) Component.getInstance(Person.class);
    person.setFirstName(user.getFirstName());
    person.setAddress(user.getEmail());
    person.setPassword(newPassword);

    MailSender mailSender = (MailSender) Component.getInstance(MailSender.class);
    mailSender.sendResetPassword();
  }
Ejemplo n.º 4
0
  protected void sendNewRegistrationEmail(User user, String password) {
    Person person = (Person) Component.getInstance(Person.class);
    person.setFirstName(user.getFirstName());
    person.setAddress(user.getEmail());
    person.setUserId(user.getId());
    person.setPassword(password);

    MailSender mailSender = (MailSender) Component.getInstance(MailSender.class);
    mailSender.sendNewUser();
  }
Ejemplo n.º 5
0
  protected void notifySupport(SystemException e) {
    ErrorMessage errorMessage = (ErrorMessage) Component.getInstance(ErrorMessage.class);
    errorMessage.setDate(DateUtils.now(TIMESTAMP_FORMAT));
    errorMessage.setClassName(e.getClassName());
    errorMessage.setMethodName(e.getMethodName());
    errorMessage.setMessage(e.getMessage());
    errorMessage.setStackTrace(getStackTrace(e));

    MailSender mailSender = (MailSender) Component.getInstance(MailSender.class);
    mailSender.sendException();
  }
  //	@Transactional
  @Asynchronous
  @Observer(value = KiWiEvents.CONTENT_UPDATED + "AsyncIE")
  public void onContentUpdatedAsyncIE(ContentItem item, User currentUser, Identity identity) {
    CurrentUserFactory currentUserFactory =
        (CurrentUserFactory) Component.getInstance("currentUserFactory");
    currentUserFactory.setCurrentUser(currentUser);

    InformationExtractionService service =
        (InformationExtractionService)
            Component.getInstance("kiwi.informationextraction.informationExtractionService");

    if (service.getOnline()) {
      service.extractInformationAsync(item);
    }
  }
  /*
   * (non-Javadoc)
   *
   * @see com.mydomain.maizsoft.cargaarchivos.ArchivoXML#read()
   */
  @Override
  public void read() {

    @SuppressWarnings("deprecation")
    SAXBuilder leer = new SAXBuilder(false);
    try {
      Document document = leer.build(getPath() + getNombre());

      Element raiz = document.getRootElement();
      raiz.getAttributeValue(ConstantesArchivosXML.SUPERPADRE);

      Element padre = raiz.getChild(ConstantesArchivosXML.PADRE);

      List usuarios = raiz.getChildren(ConstantesArchivosXML.PADRE);

      Iterator padres = usuarios.iterator();

      while (padres.hasNext()) {
        Element elePadre = (Element) padres.next();
        Element idPadre = elePadre.getChild(ConstantesArchivosXML.PADREID);
        List cursos = elePadre.getChildren(ConstantesArchivosXML.HIJO);
        Iterator hijos = cursos.iterator();
        long var2 = Long.parseLong(idPadre.getText());
        HistorialNotas nueva = new HistorialNotas();
        nueva.setUserAccount(entityManager.find(Usuario.class, var2));

        while (hijos.hasNext()) {
          Element eleHijo = (Element) hijos.next();
          Element idHijo = eleHijo.getChild(ConstantesArchivosXML.HIJOID);
          Element semestre = eleHijo.getChild(ConstantesArchivosXML.HIJOSEMESTRE);
          Element nota = eleHijo.getChild(ConstantesArchivosXML.HIJONOTA);
          long var = Long.parseLong(idHijo.getText());
          nueva.setGrupoCurso(entityManager.find(GrupoCurso.class, var));
          double notad = Double.parseDouble(nota.getText());
          nueva.setSemestre(semestre.getText());
          nueva.setNota(notad);
          entityManager.persist(nueva);
        }
      }

    } catch (Exception e) {
      FacesMessages mensaje = (FacesMessages) Component.getInstance(FacesMessages.class);
      mensaje.add("Se produjo un error técnico :(");
    }

    FacesMessages mensaje = (FacesMessages) Component.getInstance(FacesMessages.class);
    mensaje.add("Proceso exitoso :-)");
  }
Ejemplo n.º 8
0
  public static LanguageSelector instance() {
    if (!Contexts.isSessionContextActive()) {
      throw new IllegalStateException("No active session context");
    }

    return (LanguageSelector) Component.getInstance(LanguageSelector.class, ScopeType.SESSION);
  }
 // kick the task processing up
 @Observer(KiWiEvents.SEAM_POSTINIT)
 public void runTasks() throws Exception {
   InformationExtractionService service =
       (InformationExtractionService)
           Component.getInstance("kiwi.informationextraction.informationExtractionService");
   service.runTasks(1000L);
 }
 @Observer(value = KiWiEvents.CONTENT_UPDATED)
 public void onContentUpdated(ContentItem item) {
   User currentUser = (User) Component.getInstance("currentUser");
   Events.instance()
       .raiseAsynchronousEvent(
           KiWiEvents.CONTENT_UPDATED + "AsyncIE", item, currentUser, Identity.instance());
 }
Ejemplo n.º 11
0
  /**
   * Attach the passed in entity with the EntityManager retrieved from Seam.
   *
   * @param entity
   * @return The attached entity
   */
  @Override
  public Object fetchEntity(Object entity, String[] fetch) {
    EntityManager em = (EntityManager) Component.getInstance(emName);
    if (em == null)
      throw new RuntimeException("Could not find entity, EntityManager [" + emName + "] not found");

    Serializable id = (Serializable) Entity.forClass(entity.getClass()).getIdentifier(entity);
    if (id == null) return null;

    if (fetch == null || em.getDelegate().getClass().getName().indexOf(".hibernate.") < 0)
      return em.find(entity.getClass(), id);

    for (String f : fetch) {
      Query q =
          em.createQuery(
              "select e from "
                  + entity.getClass().getName()
                  + " e left join fetch e."
                  + f
                  + " where e = :entity");
      q.setParameter("entity", entity);
      entity = q.getSingleResult();
    }
    return entity;
  }
Ejemplo n.º 12
0
  //	@TransactionAttribute(TransactionAttributeType.REQUIRED)
  @Override
  public ContentItem saveContentItem(@Update ContentItem item) {

    // TODO: this should rather be solved declaratively by an appropriate modification of @RDF
    item.getResource().setLabel(null, item.getTitle());
    item.setModified(new Date());

    // TODO: this method should raise an event to invalidate all caches that are
    // currently holding an instance of this content item
    if (item.getId() == null) {
      log.debug("Persisting new ContentItem #0 ", item);
      kiwiEntityManager.persist(item);
    } else if (!entityManager.contains(item)) {
      log.info("Merging ContentItem #0 ", item.getId());
      item = entityManager.merge(item);
    } else {
      log.debug("Do nothing with ContentItem #0 ", item.getId());
    }

    // if there is multimedia data in this content item, extract it...
    if (item.getMediaContent() != null) {
      MultimediaService ms = (MultimediaService) Component.getInstance("multimediaService");
      ms.extractMetadata(item);
    }
    return item;
  }
Ejemplo n.º 13
0
  //	@Transactional(TransactionPropagationType.REQUIRED)
  //	@TransactionAttribute(TransactionAttributeType.REQUIRED)
  @Override
  public ContentItem createMediaContentItem(byte[] data, String mimeType, String fileName) {

    ContentItem contentItem = createContentItem();

    UpdateMediaContentService updateMediaContentService =
        (UpdateMediaContentService) Component.getInstance("updateMediaContentService");

    MediaContent mediaContent = new MediaContent(contentItem);
    mediaContent.setData(data);
    mediaContent.setMimeType(mimeType);
    mediaContent.setFileName(fileName);
    entityManager.persist(mediaContent);

    updateMediaContentService.createMediaContentUpdate(contentItem, mediaContent);
    //		entityManager.persist(mediaContent);
    //
    //		contentItem.setMediaContent(mediaContent);
    //
    saveContentItem(contentItem);

    Events.instance().raiseEvent(KiWiEvents.ACTIVITY_EDITCONTENTITEM, currentUser, contentItem);
    Events.instance().raiseTransactionSuccessEvent(KiWiEvents.CONTENT_UPDATED, contentItem);
    return contentItem;
  }
Ejemplo n.º 14
0
  //	@Transactional(TransactionPropagationType.REQUIRED)
  //	@TransactionAttribute(TransactionAttributeType.REQUIRED)
  public void updateTextContentWithoutStoringPipeline(ContentItemI item, String content)
      throws TextContentNotChangedException {

    ContentItem _item = item.getDelegate();

    if (renderingPipeline.renderEditor(_item, currentUser).equals(content)) {
      log.error("!!!!!!!!!!!!!!!!! renderingPipeline fails");
      throw new TextContentNotChangedException(
          "Could not create TextContentUpdate for an unchanged text content");
    }

    TextContent tc = new TextContent(_item);
    // TODO: can this cause some damage? Maybe we should at least do some regex checking
    tc.setXmlString(content);

    // TODO: check whether content has changed and create version
    UpdateTextContentService utcs =
        (UpdateTextContentService) Component.getInstance("updateTextContentService");
    if (content != null) {
      utcs.updateTextContent(_item, tc);
    }

    _item.setTextContent(tc);

    Events.instance().raiseEvent(KiWiEvents.ACTIVITY_EDITCONTENTITEM, currentUser, _item);
    Events.instance().raiseTransactionSuccessEvent(KiWiEvents.CONTENT_UPDATED, _item);
  }
Ejemplo n.º 15
0
  //	@Transactional(TransactionPropagationType.REQUIRED)
  //	@TransactionAttribute(TransactionAttributeType.REQUIRED)
  public void updateTextContentItem(ContentItemI item, Document content) {
    ContentItem _item = item.getDelegate();

    TextContent tc = new TextContent(_item);
    tc.setXmlDocument(content);

    // To check if the content has changed, check whether both contents produce the same output for
    // the editor
    if (_item.getTextContent() != null
        && _item.getTextContent().getXmlString(true).equals(tc.getXmlString(true))) {
      log.error("!!!!!!!!!!!!!!!!! renderingPipeline fails");
      return;
      // throw new TextContentNotChangedException("Could not create TextContentUpdate for an
      // unchanged text content");
    }
    entityManager.persist(tc);

    // TODO: check whether content has changed and create version
    UpdateTextContentService utcs =
        (UpdateTextContentService) Component.getInstance("updateTextContentService");
    if (content != null) {
      utcs.updateTextContent(_item, tc);
    }

    _item.setTextContent(tc);

    Events.instance().raiseEvent(KiWiEvents.ACTIVITY_EDITCONTENTITEM, currentUser, _item);
    Events.instance().raiseTransactionSuccessEvent(KiWiEvents.CONTENT_UPDATED, _item);
  }
  /*
   * (non-Javadoc)
   * @see javax.faces.validator.Validator#validate(javax.faces.context.FacesContext, javax.faces.component.UIComponent, java.lang.Object)
   */
  @Override
  public void validate(FacesContext facesContext, UIComponent uiComponent, Object value)
      throws ValidatorException {
    UserList userList = (UserList) Component.getInstance("userList");
    String messageDetail = null;
    String messageSummary = null;

    String userName = value.toString();
    if (!isValid(userName)) {
      messageDetail = ResourceBundle.instance().getString("validator.email");
      messageSummary = ResourceBundle.instance().getString("validator.email");
    } else {
      Integer userId = userList.getUserIdForUsername(userName);
      if (userId != null) {
        messageDetail =
            ResourceBundle.instance()
                .getString("org.ideaproject.jsf.validator.USERNAME_TAKEN_detail");
        messageSummary =
            ResourceBundle.instance().getString("org.ideaproject.jsf.validator.USERNAME_TAKEN");
      }
    }

    if (messageDetail != null && messageSummary != null) {
      FacesMessage message = new FacesMessage();
      message.setSeverity(FacesMessage.SEVERITY_ERROR);
      message.setSummary(messageSummary);
      message.setDetail(messageDetail);
      throw new ValidatorException(message);
    }
  }
Ejemplo n.º 17
0
  /**
   * Called by the theme negotiation module.
   *
   * @return the local theme associated to the current space (workspace, section, ...) as a
   *     'theme/page' string. Return null otherwise.
   */
  public String getOutcome(Object context) {
    Boolean useOldThemeConf =
        Boolean.valueOf(Framework.getProperty(LocalThemeConfig.OLD_THEME_CONFIGURATION_PROPERTY));
    if (Boolean.FALSE.equals(useOldThemeConf)) {
      return null;
    }

    DocumentModel currentSuperSpace = (DocumentModel) Component.getInstance("currentSuperSpace");
    if (currentSuperSpace == null) {
      return null;
    }

    // Get the placeful local theme configuration for the current
    // workspace.
    LocalThemeConfig localThemeConfig = LocalThemeHelper.getLocalThemeConfig(currentSuperSpace);
    if (localThemeConfig == null) {
      return null;
    }

    // Extract the page path
    String path = localThemeConfig.computePagePath();
    if (path == null) {
      return null;
    }

    // Look up the page
    PageElement page = Manager.getThemeManager().getPageByPath(path);
    if (page != null) {
      return path;
    }
    return null;
  }
Ejemplo n.º 18
0
  public static org.jbpm.graph.exe.ProcessInstance instance() {
    if (!Contexts.isConversationContextActive() || !BusinessProcess.instance().hasCurrentProcess())
      return null; // so we don't start a txn

    return (org.jbpm.graph.exe.ProcessInstance)
        Component.getInstance(ProcessInstance.class, ScopeType.STATELESS);
  }
Ejemplo n.º 19
0
 public static Expressions instance() {
   if (!Contexts.isApplicationContextActive()) {
     return new Expressions();
   } else {
     return (Expressions) Component.getInstance(Expressions.class, ScopeType.APPLICATION);
   }
 }
Ejemplo n.º 20
0
  @Create
  public void seamInit() {
    Seam21GraniteConfig seam21GraniteConfig =
        (Seam21GraniteConfig) Component.getInstance(Seam21GraniteConfig.class, true);

    super.init(seam21GraniteConfig);
  }
Ejemplo n.º 21
0
  @Observer(KiWiEvents.SEAM_POSTINIT)
  @BypassInterceptors
  public void initialise() {
    log.info("registering RSS/ATOM importer ...");

    ImportService ies = (ImportService) Component.getInstance("kiwi.core.importService");

    ies.registerImporter(this.getName(), "kiwi.service.importer.rss", this);
  }
  @Override
  protected int getMaxProgress() {
    LocaleService localeService = (LocaleService) Component.getInstance(LocaleServiceImpl.class);
    List<HLocale> localeList =
        localeService.getSupportedLanguageByProjectIteration(
            projectIteration.getProject().getSlug(), projectIteration.getSlug());

    return projectIteration.getDocuments().size() * localeList.size();
  }
Ejemplo n.º 23
0
  public String newLogicButton_action() throws EntityNotFoundException {

    ParentSceneConditionSelectionService pscss =
        (ParentSceneConditionSelectionService)
            Component.getInstance(ParentSceneConditionSelectionService.class);
    pscss.setSelectedId(sceneCondition == null ? null : sceneCondition.getId());

    events.raiseEvent("clearSceneConditionSelection");

    return "/sceneLogic.xhtml";
  }
  public static boolean isUserCoordinatorOfLanguage(HLocale lang) {
    HAccount authenticatedAccount = getAuthenticatedAccount();
    PersonDAO personDAO = (PersonDAO) Component.getInstance(PersonDAO.class);

    if (authenticatedAccount != null) {
      return personDAO.isUserInLanguageTeamWithRoles(
          authenticatedAccount.getPerson(), lang, null, null, true);
    }

    return false; // No authenticated user
  }
 @Observer(value = KiWiEvents.ACTIVITY_REMOVETAG)
 public void onRemoveTag(User taggingUser, Tag tag) {
   User currentUser = (User) Component.getInstance("currentUser");
   Events.instance()
       .raiseAsynchronousEvent(
           KiWiEvents.ACTIVITY_REMOVETAG + "AsyncIE",
           taggingUser,
           tag,
           currentUser,
           Identity.instance());
 }
 protected RulesRepository getRepository() {
   if (Contexts.isApplicationContextActive()) {
     return (RulesRepository) Component.getInstance("repository");
   } else {
     try {
       return new RulesRepository(TestEnvironmentSessionHelper.getSession(false));
     } catch (Exception e) {
       throw new IllegalStateException("Unable to get repo to run tests", e);
     }
   }
 }
Ejemplo n.º 27
0
 private void refreshTree() {
   log.debug("Loading menu items tree");
   WikiPreferences wikiPreferences = Preferences.instance().get(WikiPreferences.class);
   tree =
       WikiNodeDAO.instance()
           .findMenuItemTree(
               (WikiDirectory) Component.getInstance("wikiRoot"),
               wikiPreferences.getMainMenuDepth(),
               wikiPreferences.getMainMenuLevels(),
               wikiPreferences.isMainMenuShowAdminOnly());
 }
Ejemplo n.º 28
0
 public Object getAsObject(FacesContext arg0, UIComponent arg1, String arg2)
     throws ConverterException {
   if (arg2 == null) return null;
   try {
     List<Role.AccessLevel> accessLevels =
         (List<Role.AccessLevel>) Component.getInstance("accessLevelsList");
     return accessLevels.get(
         accessLevels.indexOf(new Role.AccessLevel(Integer.valueOf(arg2), null)));
   } catch (NumberFormatException e) {
     throw new ConverterException("Cannot find selected access level", e);
   }
 }
Ejemplo n.º 29
0
 public void write() {
   Document document = new Document(crearEstructuraXML());
   try {
     XMLOutputter out = new XMLOutputter(Format.getPrettyFormat());
     out.output(document, getArchivo());
     getArchivo().flush();
     close();
   } catch (Exception e) {
     FacesMessages mensaje = (FacesMessages) Component.getInstance(FacesMessages.class);
     mensaje.add("Se produjo un error técnico :(");
   }
 }
Ejemplo n.º 30
0
  @Observer("userProfilePhotoRemove")
  public void onRemoveUserProfilePhoto() {
    log.info("userProfilePhotoRemove called, doing user-profile-photo specific persistence");

    currentUser.setProfilePhoto(null);
    kiwiEntityManager.persist(currentUser);
    UserService us = (UserService) Component.getInstance("userService");
    //		us.saveUser(currentUser);

    profilePhoto = null;
    begin();
  }