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);
}
}
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;
}
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);
}
}
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);
}
}
}
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";
}
Aggregations