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";
}
use of javax.faces.application.FacesMessage in project muikku by otavanopisto.
the class PostRedirectMessagesSupport method beforePhase.
@Override
public void beforePhase(PhaseEvent event) {
if (PhaseId.RENDER_RESPONSE.equals(event.getPhaseId())) {
FacesContext facesContext = event.getFacesContext();
if (!facesContext.getResponseComplete()) {
Map<String, Object> sessionMap = facesContext.getExternalContext().getSessionMap();
@SuppressWarnings("unchecked") List<FacesMessage> messages = (List<FacesMessage>) sessionMap.get(FacesUtils.POST_REDIRECT_SESSION_KEY);
if (messages != null) {
for (FacesMessage message : messages) {
facesContext.addMessage(null, message);
}
sessionMap.remove(FacesUtils.POST_REDIRECT_SESSION_KEY);
}
}
}
}
use of javax.faces.application.FacesMessage in project survey by markoniemi.
the class FacesUtil method showMessage.
public static String showMessage(String id, String messageKey) {
FacesContext facesContext = FacesContext.getCurrentInstance();
ResourceBundle resourceBundle = facesContext.getApplication().getResourceBundle(facesContext, "messages");
String message = resourceBundle.getString(messageKey);
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(message));
return null;
}
Aggregations