private void handleShowProteinDomain(Tuple request) throws Exception { if (StringUtils.isNotEmpty(request.getString("domain_id"))) this.getModel().getMutationSearchCriteriaVO().setProteinDomainId(request.getInt("domain_id")); if (StringUtils.isNotEmpty(request.getString("snpbool"))) if (request.getString("snpbool").equals("hide")) this.getModel().getMutationSearchCriteriaVO().setReportedAsSNP(false); SearchService searchService = ServiceLocator.instance().getSearchService(); this.getModel() .setProteinDomainDTO(searchService.findProteinDomain(request.getInt("domain_id"), false)); this.getModel() .setMutationSummaryDTOList( searchService.findMutationsByDomainId(request.getInt("domain_id"))); ((HttpServletRequestTuple) request) .getRequest() .setAttribute("mutationSummaryVOList", this.getModel().getMutationSummaryDTOList()); this.getModel().setRawOutput(this.include(request, this.getModel().getMutationPager())); this.getModel().setHeader((this.getModel().getProteinDomainDTO() == null) ? "Unknown id." : ""); this.getModel().getMbrowse().setProteinDomainDTO(this.getModel().getProteinDomainDTO()); if (this.getModel().getMbrowse().getExonDTOList() == null) this.getModel().getMbrowse().setExonDTOList(searchService.findAllExons()); this.setView(new FreemarkerView("proteindomain.ftl", getModel())); }
private void handleFindMutations(Tuple request) { this.getModel().setMutationSearchCriteriaVO(new MutationSearchCriteriaDTO()); if (StringUtils.isNotEmpty(request.getString("variation"))) this.getModel().getMutationSearchCriteriaVO().setVariation(request.getString("variation")); if (StringUtils.isNotEmpty(request.getString("consequence"))) this.getModel() .getMutationSearchCriteriaVO() .setConsequence(request.getString("consequence")); if (StringUtils.isNotEmpty(request.getString("mutation_id"))) this.getModel().getMutationSearchCriteriaVO().setMutationId(request.getInt("mutation_id")); if (StringUtils.isNotEmpty(request.getString("mid"))) this.getModel().getMutationSearchCriteriaVO().setMid(request.getString("mid")); if (StringUtils.isNotEmpty(request.getString("nuclno"))) this.getModel().getMutationSearchCriteriaVO().setCdnaPosition(request.getInt("nuclno")); if (StringUtils.isNotEmpty(request.getString("aano"))) this.getModel().getMutationSearchCriteriaVO().setCodonChangeNumber(request.getInt("aano")); if (StringUtils.isNotEmpty(request.getString("exon_id"))) this.getModel().getMutationSearchCriteriaVO().setExonId(request.getInt("exon_id")); if (StringUtils.isNotEmpty(request.getString("exon"))) this.getModel().getMutationSearchCriteriaVO().setExonName(request.getString("exon")); if (StringUtils.isNotEmpty(request.getString("type"))) this.getModel().getMutationSearchCriteriaVO().setType(request.getString("type")); if (StringUtils.isNotEmpty(request.getString("domain_id"))) this.getModel().getMutationSearchCriteriaVO().setProteinDomainId(request.getInt("domain_id")); if (StringUtils.isNotEmpty(request.getString("phenotype"))) this.getModel() .getMutationSearchCriteriaVO() .setPhenotypeName(request.getString("phenotype")); if (StringUtils.isNotEmpty(request.getString("inheritance"))) this.getModel() .getMutationSearchCriteriaVO() .setInheritance(request.getString("inheritance")); if (StringUtils.isNotEmpty(request.getString("snpbool"))) if (request.getString("snpbool").equals("hide")) this.getModel().getMutationSearchCriteriaVO().setReportedAsSNP(false); SearchService searchService = ServiceLocator.instance().getSearchService(); this.getModel() .setMutationSummaryDTOList( searchService.findMutations(this.getModel().getMutationSearchCriteriaVO())); ((HttpServletRequestTuple) request) .getRequest() .setAttribute("mutationSummaryDTOList", this.getModel().getMutationSummaryDTOList()); this.getModel().setRawOutput(this.include(request, this.getModel().getMutationPager())); this.getModel().setHeader(this.getModel().getMutationSummaryDTOList().size() + " results."); this.setView(new FreemarkerView("included.ftl", this.getModel())); }
private void handleShowPrevExon(Tuple request) { SearchService searchService = ServiceLocator.instance().getSearchService(); ExonDTO exonDTO = searchService.findPrevExon(request.getInt("exon_id")); request.set("__action", "showExon"); request.set("exon_id", exonDTO.getId()); this.handleShowExon(request); }
/** * Helper function to add a record from UI * * @param request * @return true if add was successfull, false if it wassen't * @throws ParseException * @throws DatabaseException * @throws IOException */ public boolean doAdd(Database db, Tuple request) throws ParseException, DatabaseException, IOException { ScreenMessage msg = null; Entity entity = getModel().create(); boolean result = false; try { db.beginTx(); entity.set(request, false); int updatedRows = 0; if (request.getObject(FormModel.INPUT_BATCHADD) != null && request.getInt(FormModel.INPUT_BATCHADD) > 1) { // batch int i; for (i = 0; i < request.getInt(FormModel.INPUT_BATCHADD); i++) { updatedRows += db.add(entity); } } else { updatedRows = db.add(entity); } db.commitTx(); msg = new ScreenMessage("ADD SUCCESS: affected " + updatedRows, null, true); result = true; // navigate to newly added record pager.last(db); } catch (Exception e) { db.rollbackTx(); msg = new ScreenMessage("ADD FAILED: " + e.getMessage(), null, false); result = false; } getModel().getMessages().add(msg); /* make sure the user sees the newly added record(s) */ // view.setMode(FormScreen.Mode.RECORD_VIEW); // pager.setLimit(1); pager.resetOrderBy(); pager.last(db); // should reset to an order that shows the record on the end return result; }
// @Implements public void set(org.molgenis.util.Tuple tuple, boolean strict) throws Exception { // optimization :-( if (tuple instanceof org.molgenis.util.ResultSetTuple) { // set Id this.setId(tuple.getInt("id")); // set __Type this.set__Type(tuple.getString("__Type")); // set Name this.setName(tuple.getString("name")); } else if (tuple != null) { // set Id if (strict || tuple.getInt("id") != null) this.setId(tuple.getInt("id")); if (tuple.getInt("MolgenisRole_id") != null) this.setId(tuple.getInt("MolgenisRole_id")); // set __Type if (strict || tuple.getString("__Type") != null) this.set__Type(tuple.getString("__Type")); if (tuple.getString("MolgenisRole___Type") != null) this.set__Type(tuple.getString("MolgenisRole___Type")); // set Name if (strict || tuple.getString("name") != null) this.setName(tuple.getString("name")); if (tuple.getString("MolgenisRole_name") != null) this.setName(tuple.getString("MolgenisRole_name")); } // org.apache.log4j.Logger.getLogger("test").debug("set "+this); }
private void handleShowExon(Tuple request) { SearchService searchService = ServiceLocator.instance().getSearchService(); Integer exonId = request.getInt("exon_id"); this.getModel().setExonDTO(searchService.findExonById(exonId)); if (this.getModel().getQueryParametersVO().getShowMutations()) { this.getModel().setMutationSummaryDTOList(searchService.findMutationsByExonId(exonId)); ((HttpServletRequestTuple) request) .getRequest() .setAttribute("mutationSummaryDTOList", this.getModel().getMutationSummaryDTOList()); this.getModel().setRawOutput(this.include(request, this.getModel().getMutationPager())); } this.getModel().setHeader(""); this.getModel().getMbrowse().setExonDTO(this.getModel().getExonDTO()); this.getModel() .getMbrowse() .setMutationSummaryDTOList(this.getModel().getMutationSummaryDTOList()); this.setView(new FreemarkerView("exon.ftl", getModel())); }
public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // Create object to assist a servlet in sending a response to the client OutputStream out = response.getOutputStream(); // PrintWriter out = response.getWriter(); response.setContentType("application/spss"); response.setHeader("Content-disposition", "attachment; filename=Matrix.sav"); PrintStream p = new PrintStream(new BufferedOutputStream(out), false, "UTF8"); response.setStatus(HttpServletResponse.SC_OK); String content = ""; // In case we retrieve the data form DB /* boolean databaseIsAvailable = false; JDBCDatabase db = null; try { db = (JDBCDatabase) this.getDatabase(); databaseIsAvailable = true; } catch (Exception e) { content += "Database unavailable."; content += e.getStackTrace(); } if (databaseIsAvailable) { try { } catch (Exception e) { content += displayUsage(db); content += "\n\n"; content += e.getStackTrace(); } */ try { Tuple req = new HttpServletRequestTuple( request); // the HttpServletRequestTuple should be defined in another servlet ? In // ordert to actually return the matrix contents . // Get the requested id from the user & and get data from DB int matrixId = req.getInt("id"); // TODO: Danny OLD code ?? /*QueryRule q = */ new QueryRule("id", Operator.EQUALS, matrixId); // Data data = db.find(Data.class, q).get(0); content += "TEST write in spss file ."; response.setContentLength(content.length()); p.print(content); p.flush(); p.close(); } catch (Exception e) { e.printStackTrace(); } response.setContentType("application/spss"); response.setHeader("Content-disposition", "attachment; filename=Matrix.sav"); System.out.println("SPSSExport begin...."); // exportToSpss(getMatrix(), out); /* flush it to HTTP */ out.flush(); out.close(); System.out.println("SPSSExport end...."); }
@Override public Show handleRequest(Database db, Tuple request, OutputStream out) { logger.debug("handleRequest(" + request + ")"); // clear the old messages FormModel<E> model = getModel(); model.setMessages(new Vector<ScreenMessage>()); // clear messsages try { String action = request.getString(FormModel.INPUT_ACTION); if (request.getString(FormModel.INPUT_COMMAND) != null) { action = request.getString(FormModel.INPUT_COMMAND); } // get the selected ids into the screen list (if any) model.setSelectedIds(request.getList(FormModel.INPUT_SELECTED)); // if none selected, make empty list if (model.getSelectedIds() == null) model.setSelectedIds(new ArrayList<Object>()); // get the current command if any ScreenCommand command = model.getCommand(action); if (action == null || action.isEmpty()) { logger.debug("action or command does not exist"); return Show.SHOW_MAIN; } // delegate to a command else if (command != null && command instanceof SimpleCommand) { logger.debug("delegating to PluginCommand"); model.setCurrentCommand(command); return command.handleRequest(db, request, out); } else if (action.equals("filter_add")) { this.addFilters(pager, db, request); } else if (action.equals("filter_remove")) { // remove filter int index = request.getInt("filter_id"); model.getUserRules().remove(index); // update pager List<QueryRule> rules = new ArrayList<QueryRule>(); rules.addAll(model.getUserRules()); rules.addAll(model.getSystemRules()); pager.resetFilters(rules); } else if (action.equals("filter_set")) { // remove all existing filters and than add this as a new one. model.setUserRules(new ArrayList<QueryRule>()); this.addFilters(pager, db, request); } else if (action.equals("update")) { this.doUpdate(db, request); } else if (action.equals("remove")) { this.doRemove(db, request); } else if (action.equals("add")) { this.doAdd(db, request); } else if (action.equals("prev")) { pager.prev(db); } else if (action.equals("next")) { pager.next(db); } else if (action.equals("first")) { pager.first(db); } else if (action.equals("last")) { pager.last(db); } else if (action.equals("sort")) { String attribute = getSearchField(request.getString("__sortattribute")); if (pager.getOrderByField().equals(attribute)) { if (pager.getOrderByOperator().equals(Operator.SORTASC)) { pager.setOrderByOperator(Operator.SORTDESC); } else { pager.setOrderByOperator(Operator.SORTASC); } } else { pager.setOrderByField(attribute); pager.setOrderByOperator(Operator.SORTASC); } } else if (action.equals("xref_select")) // this is used to link from // one // form to another based on an xref { this.doXrefselect(request); } else if (action.equals("hideColumn")) { List<String> UserHiddencols = model.getUserHiddenColumns(); String attribute = request.getString("attribute"); if (!UserHiddencols.contains(attribute)) UserHiddencols.add(attribute); model.setUserHiddenColumns(UserHiddencols); } else if (action.equals("showColumn")) { List<String> UserHiddencols = model.getUserHiddenColumns(); String attribute = request.getString("attribute"); if (UserHiddencols.contains(attribute)) UserHiddencols.remove(attribute); model.setUserHiddenColumns(UserHiddencols); } else { logger.debug("action '" + action + "' unknown"); } logger.debug("handleRequest finished."); } catch (Exception e) { e.printStackTrace(); logger.error(e); } return Show.SHOW_MAIN; }