Search in sources :

Example 46 with FacesMessage

use of javax.faces.application.FacesMessage in project tutorials by eugenp.

the class MemberController method register.

public void register() throws Exception {
    try {
        memberRegistration.register(newMember);
        FacesMessage m = new FacesMessage(FacesMessage.SEVERITY_INFO, "Registered!", "Registration successful");
        facesContext.addMessage(null, m);
        initNewMember();
    } catch (Exception e) {
        String errorMessage = getRootErrorMessage(e);
        FacesMessage m = new FacesMessage(FacesMessage.SEVERITY_ERROR, errorMessage, "Registration unsuccessful");
        facesContext.addMessage(null, m);
    }
}
Also used : FacesMessage(javax.faces.application.FacesMessage)

Example 47 with FacesMessage

use of javax.faces.application.FacesMessage in project core by weld.

the class CommentBoard method post.

public Boolean post() {
    if (comment == null || blog == null) {
        return null;
    }
    BlogEntry entry = repository.getEntry(blog.getEntryId());
    if (entry == null) {
        return null;
    }
    comment.checkAuthor();
    repository.addComment(comment, entry);
    FacesContext ctx = FacesContext.getCurrentInstance();
    ctx.addMessage(null, new FacesMessage("Thanks for leaving a comment!"));
    // FIXME doesn't seem to be working; must investigate
    ctx.getExternalContext().getFlash().setKeepMessages(true);
    return true;
}
Also used : FacesContext(javax.faces.context.FacesContext) FacesMessage(javax.faces.application.FacesMessage)

Example 48 with FacesMessage

use of javax.faces.application.FacesMessage in project fit3d by fkaiserbio.

the class LoginView method submit.

public void submit() throws IOException {
    System.out.println(username + ":" + password);
    FacesContext context = FacesContext.getCurrentInstance();
    ExternalContext externalContext = context.getExternalContext();
    HttpServletRequest request = (HttpServletRequest) externalContext.getRequest();
    try {
        request.login(username, password);
        logger.info("authenticated {}", request.getUserPrincipal());
        externalContext.redirect(requestedUri);
    } catch (ServletException e) {
        context.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "Bad login", null));
        logger.warn("failed login attempt {}:{}", username, password);
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletException(javax.servlet.ServletException) FacesContext(javax.faces.context.FacesContext) ExternalContext(javax.faces.context.ExternalContext) FacesMessage(javax.faces.application.FacesMessage)

Example 49 with FacesMessage

use of javax.faces.application.FacesMessage in project fit3d by fkaiserbio.

the class SubmitJobView method analyzeTargetList.

private void analyzeTargetList() throws IOException {
    // check if target list contains exclusively PDB-IDs
    List<String> pdbIdentifiers = Files.lines(targetListPath).filter(Pattern.compile("^" + PDBIdentifier.PATTERN.pattern() + "$").asPredicate()).distinct().collect(Collectors.toList());
    List<String> chainIdentifiers = Files.lines(targetListPath).filter(Pattern.compile("^" + PDBIdentifier.PATTERN.pattern() + "\\s[0-9A-Za-z]+$").asPredicate()).distinct().collect(Collectors.toList());
    if (!pdbIdentifiers.isEmpty() && !chainIdentifiers.isEmpty()) {
        if (!blocked) {
            blocked = true;
            RequestContext.getCurrentInstance().update("mainForm:submitButton");
        }
        FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR, "Error", "Your target list is a mix of PDB-IDs and chain-IDs.");
        FacesContext.getCurrentInstance().addMessage(null, message);
    } else {
        if (!pdbIdentifiers.isEmpty()) {
            targetListSize = pdbIdentifiers.size();
            chainTargetList = false;
            pdbTargetList = true;
            if (blocked) {
                blocked = false;
                RequestContext.getCurrentInstance().update("mainForm:submitButton");
            }
            targetListPath = jobPath.resolve("targets.txt");
            Files.write(jobPath.resolve("targets.txt"), pdbIdentifiers.stream().collect(Collectors.joining("\n")).getBytes());
            logger.info("copied PDB-ID target list to {}", targetListPath);
        } else if (!chainIdentifiers.isEmpty()) {
            targetListSize = chainIdentifiers.size();
            pdbTargetList = false;
            chainTargetList = true;
            if (blocked) {
                blocked = false;
                RequestContext.getCurrentInstance().update("mainForm:submitButton");
            }
            targetListPath = jobPath.resolve("targets.txt");
            Files.write(targetListPath, chainIdentifiers.stream().collect(Collectors.joining("\n")).getBytes());
            logger.info("copied chain-ID target list to {}", targetListPath);
        } else {
            if (!blocked) {
                blocked = true;
                RequestContext.getCurrentInstance().update("mainForm:submitButton");
            }
            FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR, "Error", "Your target list does not contain valid PDB-IDs.");
            FacesContext.getCurrentInstance().addMessage(null, message);
        }
    }
}
Also used : FacesMessage(javax.faces.application.FacesMessage)

Example 50 with FacesMessage

use of javax.faces.application.FacesMessage in project fit3d by fkaiserbio.

the class SubmitJobView method submit.

public String submit() {
    // determine if too many jobs were submitted in current session
    int jobCount = getJobCountOfCurrentSession();
    if (jobCount > Fit3DWebConstants.JOB_LIMIT) {
        FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR, "Error", "Too many jobs submitted. Please wait until until some jobs are finished.");
        FacesContext.getCurrentInstance().addMessage(null, message);
        return null;
    }
    // determine if too many exchanges were defined
    if (exchangeDefinitions != null) {
        int exchangeCount = (int) exchangeDefinitions.stream().map(ExchangeDefinition::getExchangeAminoAcids).mapToLong(Collection::size).sum();
        if (exchangeCount > Fit3DWebConstants.EXCHANGE_LIMIT) {
            FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR, "Error", "Only " + Fit3DWebConstants.EXCHANGE_LIMIT + " PSEs are allowed. Please use the command line or API version for more complex calculations.");
            FacesContext.getCurrentInstance().addMessage(null, message);
            return null;
        }
    }
    // motif file upload is mandatory
    if (!motifFileUploaded) {
        FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR, "Error", "A motif file is required.");
        FacesContext.getCurrentInstance().addMessage(null, message);
        return null;
    }
    // use predefined target list if no one was provided
    if (!targetListFileUploaded) {
        if (predefinedList == PredefinedList.NONE) {
            FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR, "Error", "Please select or upload a target list.");
            FacesContext.getCurrentInstance().addMessage(null, message);
            return null;
        } else {
            targetListPath = predefinedList.getPath();
            chainTargetList = true;
        }
    }
    Fit3DJobParameters jobParameters = new Fit3DJobParameters();
    jobParameters.setAtomFilterType(atomFilterType);
    jobParameters.setChainTargetList(chainTargetList);
    jobParameters.setPdbTargetList(pdbTargetList);
    if (motifPath.endsWith("4cha_motif.pdb")) {
        targetListPath = motifPath.getParent().resolve("targets.txt");
        logger.info("example run detected, using short target list {}", targetListPath);
        motifPath = motifPath.getParent().resolve("4cha_motif.pdb");
    }
    jobParameters.setMotifPath(motifPath);
    jobParameters.setTargetListPath(targetListPath);
    jobParameters.setRmsdLimit(rmsdLimit);
    jobParameters.setExchangeDefinitions(exchangeDefinitions);
    jobParameters.setStatisticalModelType(statisticalModelType);
    Fit3DJob job = new Fit3DJob(jobIdentifier, sessionManager.getSessionIdentifier(), determineIpAddress(), description, email, jobPath, jobParameters);
    FacesContext facesContext = FacesContext.getCurrentInstance();
    Flash flash = facesContext.getExternalContext().getFlash();
    flash.put("job", job);
    return "success";
}
Also used : Fit3DJobParameters(bio.fkaiser.fit3d.web.model.Fit3DJobParameters) FacesContext(javax.faces.context.FacesContext) Collection(java.util.Collection) Fit3DJob(bio.fkaiser.fit3d.web.model.Fit3DJob) Flash(javax.faces.context.Flash) 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