Example usage for java.lang RuntimeException printStackTrace

List of usage examples for java.lang RuntimeException printStackTrace

Introduction

In this page you can find the example usage for java.lang RuntimeException printStackTrace.

Prototype

public void printStackTrace() 

Source Link

Document

Prints this throwable and its backtrace to the standard error stream.

Usage

From source file:org.sakaiproject.tool.assessment.ui.listener.author.ImportQuestionsToAuthoringFromSearch.java

public boolean importItems(SearchQuestionBean searchQuestionBean) {
    try {/*w w w .  j av a 2s.  c  o m*/
        ArrayList destItems = ContextUtil.paramArrayValueLike("importCheckbox");

        if (destItems.size() > 0) {
            if (searchQuestionBean.isComesFromPool()) {

                ItemService delegate = new ItemService();
                ItemAuthorBean itemauthor = (ItemAuthorBean) ContextUtil.lookupBean("itemauthor");
                ItemFacade itemfacade = null;
                ArrayList<ItemFacade> sortedQuestions = new ArrayList<ItemFacade>();
                QuestionPoolBean qpoolbean = (QuestionPoolBean) ContextUtil.lookupBean("questionpool");
                QuestionPoolDataBean contextCurrentPool = qpoolbean.getCurrentPool();
                String protocol = serverConfigurationService.getServerUrl();
                String toContext = AgentFacade.getCurrentSiteId();

                for (Object itemID : destItems) {
                    ItemFacade resultItemFacade = delegate.getItem(Long.valueOf((String) itemID),
                            AgentFacade.getAgentString());
                    ItemData clonedItem = delegate.cloneItem(resultItemFacade.getData());
                    clonedItem.setItemId(Long.valueOf(0));
                    clonedItem.setItemIdString("0");
                    Set newItemTextSet = PersistenceService.getInstance().getAssessmentFacadeQueries()
                            .prepareItemTextSet(clonedItem, clonedItem.getItemTextSet(), protocol, toContext);
                    Set newItemAttachmentSet = PersistenceService.getInstance().getAssessmentFacadeQueries()
                            .prepareItemAttachmentSet(clonedItem, clonedItem.getItemAttachmentSet(), protocol,
                                    toContext);
                    clonedItem.setItemTextSet(newItemTextSet);
                    clonedItem.setItemAttachmentSet(newItemAttachmentSet);
                    itemfacade = new ItemFacade(clonedItem);
                    sortedQuestions.add(itemfacade);
                }

                Collections.sort(sortedQuestions, new Comparator<ItemFacade>() {
                    @Override
                    public int compare(ItemFacade obj1, ItemFacade obj2) {
                        return obj1.getText().compareTo(obj2.getText());
                    }
                });

                Iterator iter = sortedQuestions.iterator();
                while (iter.hasNext()) {
                    // path instead. so we will fix it here
                    itemfacade = (ItemFacade) iter.next();
                    setRelativePathInAttachment(itemfacade.getItemAttachmentList());
                    itemfacade.setSequence(null);
                    itemfacade.setSection(null);
                    delegate.saveItem(itemfacade);

                    EventTrackingService.post(EventTrackingService.newEvent(
                            SamigoConstants.EVENT_ASSESSMENT_SAVEITEM, "/sam/" + AgentFacade.getCurrentSiteId()
                                    + "/saved  itemId=" + itemfacade.getItemId().toString(),
                            true));

                    QuestionPoolService qpdelegate = new QuestionPoolService();

                    //Save the question in the pool
                    if (!qpdelegate.hasItem(itemfacade.getItemIdString(),
                            Long.valueOf(searchQuestionBean.getSelectedQuestionPool()))) {
                        qpdelegate.addItemToPool(itemfacade.getItemId(),
                                Long.valueOf(searchQuestionBean.getSelectedQuestionPool()));

                    }

                    // update POOLID metadata if any and update PARTIID to 0,
                    delegate.deleteItemMetaData(itemfacade.getItemId(), ItemMetaData.POOLID,
                            AgentFacade.getAgentString());
                    delegate.deleteItemMetaData(itemfacade.getItemId(), ItemMetaData.PARTID,
                            AgentFacade.getAgentString());
                    delegate.addItemMetaData(itemfacade.getItemId(), ItemMetaData.PARTID, "0",
                            AgentFacade.getAgentString());

                }

                // reset InsertPosition
                itemauthor.setInsertPosition("");
                //reset the select
                itemauthor.setItemTypeString("");

                //And now we need to update the poolList page with the new questions
                qpoolbean.buildTree();

                qpoolbean.startEditPoolAgain(searchQuestionBean.getSelectedQuestionPool());
                QuestionPoolDataBean currentPool = qpoolbean.getCurrentPool();
                currentPool.setDisplayName(contextCurrentPool.getDisplayName());
                currentPool.setOrganizationName(contextCurrentPool.getOrganizationName());
                currentPool.setDescription(contextCurrentPool.getDescription());
                currentPool.setObjectives(contextCurrentPool.getObjectives());
                currentPool.setKeywords(contextCurrentPool.getKeywords());

                searchQuestionBean.setOutcome("editPool");

            } else {

                AssessmentService assessdelegate = new AssessmentService();
                ItemService delegate = new ItemService();
                SectionService sectiondelegate = new SectionService();
                AssessmentBean assessmentBean = (AssessmentBean) ContextUtil.lookupBean("assessmentBean");
                ItemAuthorBean itemauthor = (ItemAuthorBean) ContextUtil.lookupBean("itemauthor");
                int itempos = 0;
                SectionFacade section = null;
                ItemFacade itemfacade = null;
                boolean newSectionCreated = false;
                ArrayList<ItemFacade> sortedQuestions = new ArrayList<ItemFacade>();
                String protocol = serverConfigurationService.getServerUrl();
                String toContext = AgentFacade.getCurrentSiteId();

                for (Object itemID : destItems) {
                    ItemFacade resultItemFacade = delegate.getItem(Long.valueOf((String) itemID),
                            AgentFacade.getAgentString());
                    ItemData clonedItem = delegate.cloneItem(resultItemFacade.getData());
                    clonedItem.setItemId(Long.valueOf(0));
                    clonedItem.setItemIdString("0");
                    Set newItemTextSet = PersistenceService.getInstance().getAssessmentFacadeQueries()
                            .prepareItemTextSet(clonedItem, clonedItem.getItemTextSet(), protocol, toContext);
                    Set newItemAttachmentSet = PersistenceService.getInstance().getAssessmentFacadeQueries()
                            .prepareItemAttachmentSet(clonedItem, clonedItem.getItemAttachmentSet(), protocol,
                                    toContext);
                    clonedItem.setItemTextSet(newItemTextSet);
                    clonedItem.setItemAttachmentSet(newItemAttachmentSet);
                    itemfacade = new ItemFacade(clonedItem);
                    sortedQuestions.add(itemfacade);
                }

                Collections.sort(sortedQuestions, new Comparator<ItemFacade>() {
                    @Override
                    public int compare(ItemFacade obj1, ItemFacade obj2) {
                        return obj1.getText().compareTo(obj2.getText());
                    }
                });

                Iterator iter = sortedQuestions.iterator();
                while (iter.hasNext()) {
                    // path instead. so we will fix it here
                    itemfacade = (ItemFacade) iter.next();
                    setRelativePathInAttachment(itemfacade.getItemAttachmentList());
                    if ("-1".equals(searchQuestionBean.getSelectedSection())) {
                        if (!newSectionCreated) {
                            // add a new section
                            section = assessdelegate.addSection(assessmentBean.getAssessmentId());
                            newSectionCreated = true;
                        }
                    } else {
                        section = sectiondelegate.getSection(
                                Long.valueOf(searchQuestionBean.getSelectedSection()),
                                AgentFacade.getAgentString());
                    }

                    if (section != null) {
                        itemfacade.setSection(section);
                        if ((itemauthor.getInsertPosition() == null)
                                || ("".equals(itemauthor.getInsertPosition()))) {
                            if (newSectionCreated) {
                                itemfacade.setSequence(itempos + 1);
                            } else {
                                // if adding to the end
                                if (section.getItemSet() != null) {
                                    itemfacade.setSequence(section.getItemSet().size() + 1);
                                } else {
                                    // this is a new part
                                    itemfacade.setSequence(1);
                                }
                            }
                        } else {
                            // if inserting or a question
                            ItemAddListener itemAddListener = new ItemAddListener();
                            int insertPosIntvalue = Integer.valueOf(itemauthor.getInsertPosition()) + itempos;
                            itemAddListener.shiftSequences(delegate, section, insertPosIntvalue);
                            itemfacade.setSequence(insertPosIntvalue + 1);
                        }

                        delegate.saveItem(itemfacade);

                        EventTrackingService
                                .post(EventTrackingService.newEvent(SamigoConstants.EVENT_ASSESSMENT_SAVEITEM,
                                        "/sam/" + AgentFacade.getCurrentSiteId() + "/saved  itemId="
                                                + itemfacade.getItemId().toString(),
                                        true));

                        // remove POOLID metadata if any,
                        delegate.deleteItemMetaData(itemfacade.getItemId(), ItemMetaData.POOLID,
                                AgentFacade.getAgentString());
                        delegate.deleteItemMetaData(itemfacade.getItemId(), ItemMetaData.PARTID,
                                AgentFacade.getAgentString());
                        delegate.addItemMetaData(itemfacade.getItemId(), ItemMetaData.PARTID,
                                section.getSectionId().toString(), AgentFacade.getAgentString());
                    }

                    itempos++; // for next item in the destItem.
                }

                // reset InsertPosition
                itemauthor.setInsertPosition("");
                itemauthor.setItemTypeString("");

                AssessmentFacade assessment = assessdelegate.getAssessment(assessmentBean.getAssessmentId());
                assessmentBean.setAssessment(assessment);

                searchQuestionBean.setOutcome("editAssessment");
            }
            //reset the list of results
            String[] emptyArr = {};
            searchQuestionBean.setDestItems(emptyArr);
            searchQuestionBean.setTextToSearch("");
            searchQuestionBean.setTagToSearch(null);
            searchQuestionBean.setTagToSearchLabel("");
            searchQuestionBean.setResults(null);
            searchQuestionBean.setResultsSize(0);

        } else {
            // nothing is checked
            searchQuestionBean.setOutcome("searchQuestion");
        }
    } catch (RuntimeException e) {
        e.printStackTrace();
        return false;
    }
    return true;
}

From source file:com.bizintelapps.bugtracker.service.impl.TaskServiceImpl.java

private void sendTaskAlert(Task task) {
    Set<String> set = new HashSet<String>();
    String subject = "";
    set.add(task.getOwner().getUsername());
    String assignedTo = "N/A";
    if (task.getAssignedTo() != null) {
        assignedTo = task.getAssignedTo().getFirstname() + " " + task.getAssignedTo().getLastname();
        subject += task.getAssignedTo().getFirstname() + ", ";
        set.add(task.getAssignedTo().getUsername());
    }/*from ww w.j  av a2s . co m*/
    String assignedBy = "N/A";
    if (task.getAssignedBy() != null) {
        assignedBy = task.getAssignedBy().getFirstname() + " " + task.getAssignedBy().getLastname();
        set.add(task.getAssignedBy().getUsername());
    }
    String project = "Todo";
    if (task.getProject() != null) {
        project = task.getProject().getName();
    }
    if (task.getNotificationEmails() != null && task.getNotificationEmails().length() > 5) {
        String[] emails = task.getNotificationEmails().split(",");
        for (String email : emails) {
            set.add(email);
        }
    }
    String id = "New";
    if (task.getId() != null) {
        id = task.getId().toString();
    }
    subject += task.getTitle();
    String assignedDate = "N/A";
    if (task.getAssignedDate() != null) {
        assignedDate = task.getAssignedDate().toString();
    }
    String deadline = "N/A";
    if (task.getDeadline() != null) {
        deadline = task.getDeadline().toString();
    }
    String completedDate = "N/A";
    if (task.getCompletedDate() != null) {
        completedDate = task.getCompletedDate().toString();
    }
    String body = "<table>" + "<tr><td>Task #</td><td>" + id + "</td></tr>" + "<tr><td>Title</td><td>"
            + task.getTitle() + "</td></tr>" + "<tr><td>Assigned To</td><td>" + assignedTo + "</td></tr>"
            + "<tr><td>Assigned On</td><td>" + assignedDate + "</td></tr>" + "<tr><td>Assigned By</td><td>"
            + assignedBy + "</td></tr>" + "<tr><td>Created By</td><td>" + task.getOwner().getFirstname() + " "
            + task.getOwner().getLastname() + "</td></tr>" + "<tr><td>Created On</td><td>"
            + task.getCreateDate() + "</td></tr>" + "<tr><td>Project</td><td>" + project + "</td></tr>"
            + "<tr><td>Status</td><td>" + task.getStatus() + "</td></tr>" + "<tr><td>Priority</td><td>"
            + task.getPriority() + "</td></tr>" + "<tr><td>Estimated Hours</td><td>" + task.getEstimatedHours()
            + "</td></tr>" + "<tr><td>Hours Spend</td><td>" + task.getSpendHours() + "</td></tr>"
            + "<tr><td>Finish By</td><td>" + deadline + "</td></tr>" + "<tr><td>Completed Date</td><td>"
            + completedDate + "</td></tr>" + "<tr><td>Description</td><td>" + task.getDescription()
            + "</td></tr>" + "</table>";
    try {
        String[] tos = new String[set.size()];
        int count = 0;
        for (String s : set) {
            tos[count++] = s;
        }
        mailSender.sendMail(tos, subject, body);
    } catch (RuntimeException re) {
        re.printStackTrace();
    }
}

From source file:org.eclipse.scanning.event.SubscriberImpl.java

private void createDiseminateThread() {

    if (!isSynchronous())
        return; // If asynch we do not run events in order and wait until they return.
    if (queue != null)
        return;//from w w  w . j av  a2 s. c  o m
    queue = new LinkedBlockingQueue<>(); // Small, if they do work and things back-up, exceptions will occur.

    final Thread despachter = new Thread(new Runnable() {
        public void run() {
            while (isConnected()) {
                try {
                    DiseminateEvent event = queue.take();
                    if (event == DiseminateEvent.STOP)
                        return;
                    diseminate(event);

                } catch (RuntimeException e) {
                    e.printStackTrace();
                    logger.error("RuntimeException occured despatching event", e);
                    continue;

                } catch (Exception e) {
                    e.printStackTrace();
                    logger.error("Stopping event despatch thread ", e);
                    return;
                }
            }
            System.out.println(Thread.currentThread().getName() + " disconnecting events.");
        }
    }, "Submitter despatch thread " + getSubmitQueueName());
    despachter.setDaemon(true);
    despachter.setPriority(Thread.NORM_PRIORITY + 1);
    despachter.start();
}

From source file:org.xsystem.sql2.http.PageServlet2.java

synchronized void loadRepository() {
    PageLoader loader = new PageLoader();
    EnviromentImpl enviroment = createEnviroment();
    pagesConfig = null;/* www.ja va  2s.  c om*/
    try {
        loader.load(repositoryPath);
        pagesConfig = new Config();
        pagesConfig.setConnectionManager(loader.getConnectionManager());
        pagesConfig.setActions(loader.getActions());
        pagesConfig.setConnections(loader.getConnections());
        pagesConfig.setAfterCreateConnectionEventListeners(loader.getAfterCreateConnectionEventListeners());
        pagesConfig.setBeforeCloseConnectionEventListeners(loader.getBeforeCloseConnectionEventListeners());
        pagesConfig.setFileStorages(loader.getFileStorages());
        pagesConfig.setErrorHandler(loader.getErrorHandler());
        pagesConfig.setObjectNames(loader.getObjectNames());

        Set<File> fileSet = loader.getFileSet();
        List<File> listFile = new ArrayList();
        listFile.addAll(fileSet);

        if (fileWatcher != null) {
            if (fileWatcher.isStopped()) {
                fileWatcher.stopThread();
            }
        }
        fileWatcher = new FilesWatcher(listFile, (f -> {
            changeFile(f);
        }));
        fileWatcher.start();

    } catch (RuntimeException ex) {
        ex.printStackTrace();
        errorReport = Auxilary.throwableToString(ex);
    } finally {
        destroyEnviroment(enviroment);
    }
}

From source file:org.taverna.server.localworker.impl.WorkerCore.java

private void buildUR(Status status) {
    try {/*from www.ja  v a  2 s.c  o m*/
        Date now = new Date();
        ur = new JobUsageRecord(wd.getName());
        ur.addUser(System.getProperty("user.name"), null);
        ur.addStartAndEnd(start, now);
        ur.addWallDuration(now.getTime() - start.getTime());
        ur.setStatus(status.toString());
        ur.addHost(InetAddress.getLocalHost().getHostName());
        if (urreceiver != null)
            urreceiver.acceptUsageRecord(ur.marshal());
    } catch (RuntimeException e) {
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.mbv.web.rest.controller.VpGrnController.java

/**
 * @???id?/*from   ww  w .  j  a  v a  2s . c om*/
 * @2015915
 * @param
 * @version
 */
@RequestMapping(value = "/findVpGrnById", method = RequestMethod.POST)
@ResponseBody
public void findVpGrn(@RequestBody VpGrnVo vo, HttpServletResponse response) throws MbvException {
    // vo
    if (vo == null || vo.getEntity() == null) {
        throw new MbvException("??");
    }
    try {
        VpGrnEntity entity = vpGrnService.getVpGrnByEntity(vo.getEntity());
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("data", entity);
        // ??
        returnSuccess(response, map);
    } catch (MbvException me) {
        me.printStackTrace();
        throw new MbvException(me.getMessage());
    } catch (RuntimeException re) {
        re.printStackTrace();
        throw new MbvException(MbvConstant.MBV_SYS_ERROR_TIP);
    } catch (Exception e) {
        e.printStackTrace();
        throw new MbvException(MbvConstant.MBV_SYS_ERROR_TIP);
    }
}

From source file:org.godhuli.rhipe.RHMRHelper.java

public void mapRedFinished(
        TaskInputOutputContext<WritableComparable, RHBytesWritable, WritableComparable, RHBytesWritable> ctx) {
    try {//  ww w .ja v  a 2  s .  c  o m
        if (!doPipe_) {
            return;
        }
        try {
            if (clientOut_ != null) {
                clientOut_.flush();
                clientOut_.close();
            }
        } catch (IOException io) {
        }

        waitOutputThreads(ctx);
        if (sim != null)
            sim.destroy();
    } catch (RuntimeException e) {
        e.printStackTrace();
        throw e;
    }
}

From source file:com.mbv.web.rest.controller.VpGrnController.java

/**
 * @???Id?//from ww  w.  j  a  va2  s.  c om
 * @2015917
 * @param
 * @version
 * @throws Exception
 */
@RequestMapping(value = "/deleteVpGrnById", method = RequestMethod.POST)
@ResponseBody
public void deleteVpGrnById(@RequestBody VpGrnVo vo, HttpServletResponse response) throws Exception {
    // vo
    if (vo == null || vo.getEntity() == null || vo.getEntity().getDocState() == null
            || "".equals(vo.getEntity().getDocState()) || vo.getEntity().getId() < 1) {
        throw new MbvException("???");
    }
    log.info("id:" + vo.getEntity().getId() + ",docState:" + vo.getEntity().getDocState());
    try {
        boolean deleteResult = vpGrnService.deleteVpGrnById(vo.getEntity());
        if (deleteResult) {
            log.info("??");
        }
        // ??
        returnSuccess(response, null);
    } catch (MbvException me) {
        me.printStackTrace();
        throw new MbvException(me.getMessage());
    } catch (RuntimeException re) {
        re.printStackTrace();
        throw new MbvException(MbvConstant.MBV_SYS_ERROR_TIP);
    } catch (Exception e) {
        e.printStackTrace();
        throw new MbvException(MbvConstant.MBV_SYS_ERROR_TIP);
    }
}

From source file:com.mbv.web.rest.controller.VpGrnController.java

/**
 * @???docCode?//from  ww  w.j  av a2s.com
 * @2015915
 * @param
 * @version
 */
@RequestMapping(value = "/findVpGrnByDocCode", method = RequestMethod.POST)
@ResponseBody
public void findVpGrnByDocCode(@RequestBody VpGrnVo vo, HttpServletRequest request,
        HttpServletResponse response) throws MbvException {
    // vo
    if (vo == null || vo.getEntity() == null || vo.getEntity().getDocCode() == null
            || "".equals(vo.getEntity().getDocCode())) {
        throw new MbvException("??");
    }
    log.info("findVpGrnByDocCode docCode:" + vo.getEntity().getDocCode());
    try {
        VpGrnBean Bean = vpGrnService.getVpGrnBeanByEntity(vo.getEntity());
        if (Bean == null) {
            throw new MbvException("????");
        }
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("data", Bean);
        // ??
        returnSuccess(response, map);
    } catch (MbvException me) {
        me.printStackTrace();
        throw new MbvException(me.getMessage());
    } catch (RuntimeException re) {
        re.printStackTrace();
        throw new MbvException(MbvConstant.MBV_SYS_ERROR_TIP);
    } catch (Exception e) {
        e.printStackTrace();
        throw new MbvException(MbvConstant.MBV_SYS_ERROR_TIP);
    }
}

From source file:com.mbv.web.rest.controller.VpGrnController.java

/**
 * @??excel// w  w w .ja  v a  2  s .co  m
 * @2015916
 * @param
 * @version
 */
@RequestMapping(value = "/importGrn", method = RequestMethod.POST)
@ResponseBody
public void importBill(@RequestParam(value = "add_vpGrn_importedFile", required = false) MultipartFile file,
        HttpServletRequest request, HttpServletResponse response) {
    JSONObject json = new JSONObject();
    try {
        // ?
        if (file.isEmpty()) {
            throw new MbvException("??");
        }
        // ??
        if (file.getSize() > 20971520) {
            throw new Exception("?20M?");
        }
        json = importFile(file);
    } catch (MbvException me) {
        me.printStackTrace();
        json.put("success", false);
        json.put("msg", me.getMessage());
    } catch (RuntimeException re) {
        re.printStackTrace();
        json.put("success", false);
        json.put("msg", re.getMessage());
    } catch (Exception e) {
        e.printStackTrace();
        json.put("success", false);
        json.put("msg", e.getMessage());
    }
    // ???
    outPrintJson(response, json.toString());
}