Search in sources :

Example 16 with FacesMessage

use of javax.faces.application.FacesMessage in project opentheso by miledrousset.

the class SelectedThesaurus method ajouterTheso.

/**
 * Création d'un nouveau thésaurus avec le role
 *
 * @param idUser
 * @param idRole
 */
public void ajouterTheso(int idUser, int idRole) {
    if (editTheso.getTitle() == null || editTheso.getTitle().trim().equals("")) {
        FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, langueBean.getMsg("error") + " :", langueBean.getMsg("theso.error1")));
    } else {
        ThesaurusHelper th = new ThesaurusHelper();
        th.setIdentifierType(identifierType);
        try {
            Connection conn = connect.getPoolConnexion().getConnection();
            conn.setAutoCommit(false);
            String idThesaurus = th.addThesaurusRollBack(conn, null, arkActive);
            if (idThesaurus == null) {
                FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, langueBean.getMsg("error") + " :", langueBean.getMsg("theso.error1")));
                conn.rollback();
                conn.close();
                return;
            }
            if (editTheso.getTitle().isEmpty()) {
                thesaurus.setTitle("theso_" + idThesaurus);
            }
            if (editTheso.getLanguage() == null) {
                editTheso.setLanguage(workLanguage);
            }
            editTheso.setId_thesaurus(idThesaurus);
            if (!th.addThesaurusTraductionRollBack(conn, editTheso)) {
                conn.rollback();
                conn.close();
                return;
            }
            // ajout de role pour le thésaurus à l'utilisateur en cours
            UserHelper userHelper = new UserHelper();
            if (!userHelper.addRole(conn, idUser, idRole, idThesaurus, "")) {
                FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, langueBean.getMsg("error") + " :", langueBean.getMsg("error.BDD")));
                conn.rollback();
                conn.close();
                return;
            }
            conn.commit();
            conn.close();
        } catch (SQLException ex) {
            Logger.getLogger(CurrentUser.class.getName()).log(Level.SEVERE, null, ex);
        }
        maj();
        arrayTheso = new ArrayList<>(th.getListThesaurus(connect.getPoolConnexion(), langueSource).entrySet());
        tree.getSelectedTerme().getUser().updateAuthorizedTheso();
        vue.setCreat(false);
        FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(langueBean.getMsg("info") + " :", langueBean.getMsg("theso.info1.1") + " " + editTheso.getTitle() + " " + langueBean.getMsg("theso.info1.2")));
    // editTheso = new Thesaurus();
    }
// tree.getSelectedTerme().getUser().getUser().getId();
}
Also used : UserHelper(mom.trd.opentheso.bdd.helper.UserHelper) SQLException(java.sql.SQLException) ThesaurusHelper(mom.trd.opentheso.bdd.helper.ThesaurusHelper) Connection(java.sql.Connection) FacesMessage(javax.faces.application.FacesMessage)

Example 17 with FacesMessage

use of javax.faces.application.FacesMessage in project opentheso by miledrousset.

the class SelectedThesaurus method supprimerTheso.

/**
 * Suppréssion d'un thésaurus
 *
 * @param id
 */
public void supprimerTheso(String id) {
    ThesaurusHelper th = new ThesaurusHelper();
    // on vérifie si l'utilisateur n'a plus aucun thésaurus, on garde son dernier role sans thésaurus
    // cette action est temporaire le temps de mettre en place une gestion complète des users et des groupes
    UserHelper userHelper = new UserHelper();
    Connection conn;
    try {
        conn = connect.getPoolConnexion().getConnection();
        conn.setAutoCommit(false);
        if (userHelper.isLastThesoOfUser(connect.getPoolConnexion(), tree.getSelectedTerme().getUser().getUser().getId())) {
            if (!userHelper.deleteOnlyTheThesoFromRole(conn, id)) {
                conn.rollback();
                conn.close();
                return;
            }
        } else {
            if (!userHelper.deleteThisRoleForThisThesaurus(conn, tree.getSelectedTerme().getUser().getUser().getId(), id)) {
                conn.rollback();
                conn.close();
                return;
            }
        }
        conn.commit();
        conn.close();
    } catch (SQLException ex) {
        Logger.getLogger(SelectedThesaurus.class.getName()).log(Level.SEVERE, null, ex);
    }
    ConceptHelper conceptHelper = new ConceptHelper();
    conceptHelper.setNodePreference(nodePreference);
    conceptHelper.deleteAllIdHandle(connect.getPoolConnexion(), id);
    th.deleteThesaurus(connect.getPoolConnexion(), id);
    arrayTheso = new ArrayList<>(th.getListThesaurus(connect.getPoolConnexion(), langueSource).entrySet());
    FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, langueBean.getMsg("info") + " :", conceptHelper.getMessage()));
}
Also used : ConceptHelper(mom.trd.opentheso.bdd.helper.ConceptHelper) UserHelper(mom.trd.opentheso.bdd.helper.UserHelper) SQLException(java.sql.SQLException) ThesaurusHelper(mom.trd.opentheso.bdd.helper.ThesaurusHelper) Connection(java.sql.Connection) FacesMessage(javax.faces.application.FacesMessage)

Example 18 with FacesMessage

use of javax.faces.application.FacesMessage in project opentheso by miledrousset.

the class SelectedThesaurus method editerTheso.

/**
 * Modification d'un thésaurus
 */
public void editerTheso() {
    if (editTheso.getTitle() == null || editTheso.getTitle().trim().equals("")) {
        FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, langueBean.getMsg("error") + " :", langueBean.getMsg("theso.error1")));
    } else {
        new ThesaurusHelper().UpdateThesaurus(connect.getPoolConnexion(), editTheso);
        vue.setEdit(false);
    }
}
Also used : ThesaurusHelper(mom.trd.opentheso.bdd.helper.ThesaurusHelper) FacesMessage(javax.faces.application.FacesMessage)

Example 19 with FacesMessage

use of javax.faces.application.FacesMessage in project acs-community-packaging by Alfresco.

the class BaseDetailsBean method takeOwnership.

/**
 * Action Handler to take Ownership of the current node
 */
public void takeOwnership(final ActionEvent event) {
    final FacesContext fc = FacesContext.getCurrentInstance();
    try {
        RetryingTransactionHelper txnHelper = Repository.getRetryingTransactionHelper(FacesContext.getCurrentInstance());
        RetryingTransactionCallback<Object> callback = new RetryingTransactionCallback<Object>() {

            public Object execute() throws Throwable {
                getOwnableService().takeOwnership(getNode().getNodeRef());
                String msg = Application.getMessage(fc, MSG_SUCCESS_OWNERSHIP);
                FacesMessage facesMsg = new FacesMessage(FacesMessage.SEVERITY_INFO, msg, msg);
                String formId = Utils.getParentForm(fc, event.getComponent()).getClientId(fc);
                fc.addMessage(formId + ':' + getPropertiesPanelId(), facesMsg);
                getNode().reset();
                return null;
            }
        };
        txnHelper.doInTransaction(callback);
    } catch (Throwable e) {
        Utils.addErrorMessage(MessageFormat.format(Application.getMessage(fc, Repository.ERROR_GENERIC), e.getMessage()), e);
        ReportedException.throwIfNecessary(e);
    }
}
Also used : FacesContext(javax.faces.context.FacesContext) RetryingTransactionHelper(org.alfresco.repo.transaction.RetryingTransactionHelper) RetryingTransactionCallback(org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback) FacesMessage(javax.faces.application.FacesMessage)

Example 20 with FacesMessage

use of javax.faces.application.FacesMessage in project acs-community-packaging by Alfresco.

the class AdminNodeBrowseBean method submitSearch.

/**
 * Action to submit search
 *
 * @return next action
 */
public String submitSearch() {
    long start = System.currentTimeMillis();
    RetryingTransactionCallback<String> searchCallback = new RetryingTransactionCallback<String>() {

        public String execute() throws Throwable {
            if (queryLanguage.equals("noderef")) {
                // ensure node exists
                NodeRef nodeRef = new NodeRef(query);
                boolean exists = getNodeService().exists(nodeRef);
                if (!exists) {
                    throw new AlfrescoRuntimeException("Node " + nodeRef + " does not exist.");
                }
                setNodeRef(nodeRef);
                return "node";
            } else if (queryLanguage.equals("selectnodes")) {
                List<NodeRef> nodes = getSearchService().selectNodes(getNodeRef(), query, null, getNamespaceService(), false);
                searchResults = new SearchResults(nodes);
                return "search";
            }
            // perform search
            searchResults = new SearchResults(getSearchService().query(getNodeRef().getStoreRef(), queryLanguage, query));
            return "search";
        }
    };
    try {
        String result = getTransactionService().getRetryingTransactionHelper().doInTransaction(searchCallback, true);
        this.searchElapsedTime = System.currentTimeMillis() - start;
        return result;
    } catch (Throwable e) {
        FacesContext context = FacesContext.getCurrentInstance();
        FacesMessage message = new FacesMessage();
        message.setSeverity(FacesMessage.SEVERITY_ERROR);
        message.setDetail("Search failed due to: " + e.toString());
        context.addMessage("searchForm:query", message);
        return "error";
    }
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) FacesContext(javax.faces.context.FacesContext) RetryingTransactionCallback(org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) ArrayList(java.util.ArrayList) List(java.util.List) FacesMessage(javax.faces.application.FacesMessage)

Aggregations

FacesMessage (javax.faces.application.FacesMessage)370 ConceptHelper (mom.trd.opentheso.bdd.helper.ConceptHelper)43 SQLException (java.sql.SQLException)40 Connection (java.sql.Connection)34 FacesContext (javax.faces.context.FacesContext)25 ArrayList (java.util.ArrayList)24 UIInput (javax.faces.component.UIInput)24 ValidatorException (javax.faces.validator.ValidatorException)24 GroupHelper (mom.trd.opentheso.bdd.helper.GroupHelper)22 NodeAutoCompletion (mom.trd.opentheso.bdd.helper.nodes.NodeAutoCompletion)22 CandidateHelper (mom.trd.opentheso.bdd.helper.CandidateHelper)19 UserHelper2 (mom.trd.opentheso.bdd.helper.UserHelper2)19 IOException (java.io.IOException)16 NoteHelper (mom.trd.opentheso.bdd.helper.NoteHelper)15 Test (org.junit.Test)13 TermHelper (mom.trd.opentheso.bdd.helper.TermHelper)12 Term (mom.trd.opentheso.bdd.datas.Term)11 UploadedFile (org.primefaces.model.UploadedFile)11 HikariDataSource (com.zaxxer.hikari.HikariDataSource)10 Date (java.util.Date)10