List of usage examples for java.lang Long intValue
public int intValue()
From source file:com.autentia.wuija.persistence.impl.hibernate.HibernateDao.java
private <T> Pair<List<T>, Long> findAndCountScalarQuery(HibernateCallback queryCallback, String countHql, int maxResults, Object[] values) { final Pair<List<T>, Long> pair = new Pair<List<T>, Long>(); // Si hay paginacin, hay que hacer un select count para saber el nmero de registros totales. if (maxResults > 0) { final Long rowCount = Long.valueOf(getHibernateTemplate().find(countHql, values).size()); pair.setRight(rowCount);// ww w . j a v a2 s. c o m // Pequeo shortcut: si no hay resultados, ni siquiera se hace la bsqueda. if (rowCount.intValue() == 0) { final List<T> emptyList = Collections.emptyList(); pair.setLeft(emptyList); return pair; } } final List<T> list = findByHibernateCallback(queryCallback); pair.setLeft(list); // Si todava no se ha calculado el numero total de registros, se saca del tamao de la lista de resultados. if (pair.getRight() == null) { pair.setRight(Long.valueOf(list.size())); } return pair; }
From source file:com.mobileman.projecth.web.controller.patient.PatientController.java
@Transactional @RequestMapping(method = RequestMethod.POST, value = "/patient/save_fragebogen_anpassen") public @ResponseBody String saveFragebogenAnnpassen(HttpServletRequest request, Model model) { String result = ""; // save into session FragebogenAnnpasenData fragebogenAnnpasendata = new FragebogenAnnpasenData(request.getSession()); fragebogenAnnpasendata.storeData(request); FragebogenAnnpasenDataHolder holder = fragebogenAnnpasendata.getData(); Map<Long, Map<String, Object>> fragebogenAnnpasenDataHolderdata = holder.getData(); DataHolder dataHolder = new DataHolder(request); Patient patient = dataHolder.getPatient(); Disease disease = dataHolder.getDisease(); Long patientId = patient.getId(); Long diseaseId = disease.getId(); Iterator it = fragebogenAnnpasenDataHolderdata.entrySet().iterator(); while (it.hasNext()) { Map.Entry entry = (Map.Entry) it.next(); Map<String, Object> question = (Map<String, Object>) entry.getValue(); String questionIdString = (String) question.get("question_id"); String questionTypeString = (String) question.get("type"); String questionActionString = (String) question.get("action"); String questionTextString = (String) question.get("question"); String questionExplanationString = (String) question.get("explanation"); Map<Long, String> questionOptions = (Map<Long, String>) question.get("option"); QuestionType questionType = null; boolean editQuestionType = false; // yes/no question if (questionTypeString.equals("0")) { //find standart yes/no question type questionType = findQuestionType(Type.SINGLE_CHOICE_LIST, AnswerDataType.BOOLEAN); }// w w w. ja va 2 s .c o m // multiple choice question if (questionTypeString.equals("1")) { editQuestionType = true; //new question type questionType = new QuestionType(); questionType.setUser(patient); questionType.setType(Type.SINGLE_CHOICE_LIST); questionType.setAnswerDataType(AnswerDataType.TEXT); List<Answer> answers = new ArrayList<Answer>(); Answer answer = null; //NO ANSWER answer = new Answer(); answer.setAnswer("Kaine Angabe"); answer.setSortOrder(answers.size()); answer.setKind(Kind.NO_ANSWER); answer.setQuestionType(questionType); answers.add(answer); Iterator optionIt = questionOptions.entrySet().iterator(); while (optionIt.hasNext()) { Map.Entry optionEntry = (Map.Entry) optionIt.next(); Long optionOrder = (Long) optionEntry.getKey(); String option = (String) optionEntry.getValue(); answer = new Answer(); answer.setAnswer(option); answer.setSortOrder(optionOrder.intValue()); answer.setKind(Kind.DEFAULT); answer.setQuestionType(questionType); answers.add(answer); } questionType.setAnswers(answers); } // text question if (questionTypeString.equals("2")) { //find standart text question type questionType = findQuestionType(Type.SINGLE_ANSWER_ENTER, AnswerDataType.TEXT); } String explanationText = null; if (!questionExplanationString.isEmpty()) { explanationText = questionExplanationString; } if (!questionIdString.isEmpty()) { if (questionActionString.equals("EDIT")) { Question customQuestion = questionService.findById(Long.valueOf(questionIdString)); customQuestion.setExplanation(explanationText); customQuestion.setText(questionTextString); if (editQuestionType) { questionType.getAnswers().remove(0); List<Answer> customQuestionAnswers = customQuestion.getQuestionType().getAnswers(); for (int index = 0; index < customQuestionAnswers.size(); index++) { Answer customQuestionAnswer = customQuestionAnswers.get(index); customQuestionAnswer.setAnswer(questionType.getAnswers().get(index).getAnswer()); } } questionService.update(customQuestion); result = "ok"; } if (questionActionString.equals("DELETE")) { try { questionService.deleteCustomQuestion(Long.valueOf(questionIdString)); result = "ok"; } catch (Exception e) { result = "error"; } } } else { Long newId = null; if (questionType.getId() != null) { newId = patientService.addCustomQuestion(patientId, diseaseId, questionTextString, explanationText, questionType.getId()); } else { newId = patientService.addCustomQuestion(patientId, diseaseId, questionTextString, explanationText, questionType); } result = newId.toString(); } } return result; }
From source file:com.mnxfst.testing.handler.exec.client.PTestPlanExecutorClient.java
/** * Executes the client/*from w ww. ja va 2 s . co m*/ * @param args */ protected void executeClient(String[] args) { try { CommandLineProcessor commandLineProcessor = new CommandLineProcessor(); Map<String, Serializable> commandLineValues = commandLineProcessor .parseCommandLine(PTestPlanExecutorClient.class.getName(), args, getCommandLineOptions()); if (commandLineValues != null && !commandLineValues.isEmpty()) { Long threads = (Long) commandLineValues.get(CLI_VALUE_MAP_KEY_THREADS); Long recurrences = (Long) commandLineValues.get(CLI_VALUE_MAP_KEY_RECURRENCES); String recurrenceType = (String) commandLineValues.get(CLI_VALUE_MAP_KEY_RECURRENCE_TYPE); String testplanFile = (String) commandLineValues.get(CLI_VALUE_MAP_KEY_TESTPLAN); String hosts = (String) commandLineValues.get(CLI_VALUE_MAP_KEY_SERVER_HOSTS); Long port = (Long) commandLineValues.get(CLI_VALUE_MAP_KEY_SERVER_PORT); byte[] testplan = loadTestplan(testplanFile); System.out.println(threads + "-" + recurrences + "-" + hosts); executeTestplan(threads.intValue(), recurrences.intValue(), recurrenceType, testplan, hosts.split(","), port.intValue()); } } catch (Exception e) { System.out.println("Error while executing client: " + e.getMessage()); e.printStackTrace(); } }
From source file:br.ufc.deti.ecgweb.domain.exam.EcgService.java
public List<EcgSignalRange> getPWaveFromAlgorithm(Long channelId, Long algorithmId) { EcgChannel channel = ecgChannelRepository.findOne(channelId); List<EcgSignal> signals = channel.getSignals(); int sampleRate = channel.getEcg().getSampleRate().intValue(); AbstractPWaveAlgorithm algorithm = PWaveAlgorithmFactory.getPWaveAlgorithm(algorithmId.intValue()); return algorithm.getPWaves(signals, sampleRate); }
From source file:br.ufc.deti.ecgweb.domain.exam.EcgService.java
public List<EcgSignalRange> getTWaveFromAlgorithm(Long channelId, Long algorithmId) { EcgChannel channel = ecgChannelRepository.findOne(channelId); List<EcgSignal> signals = channel.getSignals(); int sampleRate = channel.getEcg().getSampleRate().intValue(); AbstractTWaveAlgorithm algorithm = TWaveAlgorithmFactory.getTWaveAlgorithm(algorithmId.intValue()); return algorithm.getTWaves(signals, sampleRate); }
From source file:com.dotcms.rest.LicenseResource.java
@POST @Path("/free/{params:.*}") public Response freeLicense(@Context HttpServletRequest request, @PathParam("params") String params) { InitDataObject initData = webResource.init(params, true, request, true, PortletID.CONFIGURATION.toString()); String localServerId = APILocator.getServerAPI().readServerId(); String remoteServerId = initData.getParamsMap().get("serverid"); String serial = initData.getParamsMap().get("serial"); try {// ww w .j a va 2 s . c om //If we are removing a remote Server we need to create a ServerAction. if (UtilMethods.isSet(remoteServerId) && !remoteServerId.equals("undefined")) { ResetLicenseServerAction resetLicenseServerAction = new ResetLicenseServerAction(); Long timeoutSeconds = new Long(1); ServerActionBean resetLicenseServerActionBean = resetLicenseServerAction .getNewServerAction(localServerId, remoteServerId, timeoutSeconds); resetLicenseServerActionBean = APILocator.getServerActionAPI() .saveServerActionBean(resetLicenseServerActionBean); //Waits for 3 seconds in order all the servers respond. int maxWaitTime = timeoutSeconds.intValue() * 1000 + Config.getIntProperty("CLUSTER_SERVER_THREAD_SLEEP", 2000); int passedWaitTime = 0; //Trying to NOT wait whole 3 secons for returning the info. while (passedWaitTime <= maxWaitTime) { try { Thread.sleep(10); passedWaitTime += 10; resetLicenseServerActionBean = APILocator.getServerActionAPI() .findServerActionBean(resetLicenseServerActionBean.getId()); //No need to wait if we have all Action results. if (resetLicenseServerActionBean != null && resetLicenseServerActionBean.isCompleted()) { passedWaitTime = maxWaitTime + 1; } } catch (InterruptedException ex) { Thread.currentThread().interrupt(); passedWaitTime = maxWaitTime + 1; } } //If we reach the timeout and the server didn't respond. //We assume the server is down and remove the license from the table. if (!resetLicenseServerActionBean.isCompleted()) { resetLicenseServerActionBean.setCompleted(true); resetLicenseServerActionBean.setFailed(true); resetLicenseServerActionBean.setResponse(new com.dotmarketing.util.json.JSONObject() .put(ServerAction.ERROR_STATE, "Server did NOT respond on time")); APILocator.getServerActionAPI().saveServerActionBean(resetLicenseServerActionBean); LicenseUtil.freeLicenseOnRepo(serial, remoteServerId); //If it was completed but we got some error, we need to alert it. } else if (resetLicenseServerActionBean.isCompleted() && resetLicenseServerActionBean.isFailed()) { throw new Exception( resetLicenseServerActionBean.getResponse().getString(ServerAction.ERROR_STATE)); } //If the server we are removing license is local. } else { HibernateUtil.startTransaction(); LicenseUtil.freeLicenseOnRepo(); HibernateUtil.commitTransaction(); } AdminLogger.log(LicenseResource.class, "freeLicense", "License From Repo Freed", initData.getUser()); } catch (Exception exception) { Logger.error(this, "can't free license ", exception); try { if (HibernateUtil.getSession().isOpen()) { HibernateUtil.rollbackTransaction(); } } catch (DotHibernateException dotHibernateException) { Logger.warn(this, "can't rollback", dotHibernateException); } return Response.serverError().build(); } return Response.ok().build(); }
From source file:blue.lapis.pore.impl.entity.PorePlayer.java
private int getStatistic(org.spongepowered.api.statistic.Statistic statistic) { Long l = getHandle().getStatisticData().statistics().get().get(statistic); return l != null ? l.intValue() : 0; }
From source file:eu.europa.esig.dss.client.http.commons.CommonsDataLoader.java
/** * Configure the proxy with the required credential if needed * * @param httpClientBuilder//from ww w. j av a 2s .c o m * @param credentialsProvider * @param url * @return */ private HttpClientBuilder configureProxy(HttpClientBuilder httpClientBuilder, CredentialsProvider credentialsProvider, String url) throws DSSException { if (proxyPreferenceManager == null) { return httpClientBuilder; } try { final String protocol = new URL(url).getProtocol(); final boolean proxyHTTPS = Protocol.isHttps(protocol) && proxyPreferenceManager.isHttpsEnabled(); final boolean proxyHTTP = Protocol.isHttp(protocol) && proxyPreferenceManager.isHttpEnabled(); if (!proxyHTTPS && !proxyHTTP) { return httpClientBuilder; } String proxyHost = null; int proxyPort = 0; String proxyUser = null; String proxyPassword = null; String proxyExcludedHosts = null; if (proxyHTTPS) { LOG.debug("Use proxy https parameters"); final Long port = proxyPreferenceManager.getHttpsPort(); proxyPort = port != null ? port.intValue() : 0; proxyHost = proxyPreferenceManager.getHttpsHost(); proxyUser = proxyPreferenceManager.getHttpsUser(); proxyPassword = proxyPreferenceManager.getHttpsPassword(); proxyExcludedHosts = proxyPreferenceManager.getHttpsExcludedHosts(); } else if (proxyHTTP) { // noinspection ConstantConditions LOG.debug("Use proxy http parameters"); final Long port = proxyPreferenceManager.getHttpPort(); proxyPort = port != null ? port.intValue() : 0; proxyHost = proxyPreferenceManager.getHttpHost(); proxyUser = proxyPreferenceManager.getHttpUser(); proxyPassword = proxyPreferenceManager.getHttpPassword(); proxyExcludedHosts = proxyPreferenceManager.getHttpExcludedHosts(); } if (StringUtils.isNotEmpty(proxyUser) && StringUtils.isNotEmpty(proxyPassword)) { AuthScope proxyAuth = new AuthScope(proxyHost, proxyPort); UsernamePasswordCredentials proxyCredentials = new UsernamePasswordCredentials(proxyUser, proxyPassword); credentialsProvider.setCredentials(proxyAuth, proxyCredentials); } LOG.debug("proxy host/port: " + proxyHost + ":" + proxyPort); // TODO SSL peer shut down incorrectly when protocol is https final HttpHost proxy = new HttpHost(proxyHost, proxyPort, Protocol.HTTP.getName()); if (StringUtils.isNotEmpty(proxyExcludedHosts)) { final String[] hosts = proxyExcludedHosts.split("[,; ]"); HttpRoutePlanner routePlanner = new DefaultProxyRoutePlanner(proxy) { @Override public HttpRoute determineRoute(final HttpHost host, final HttpRequest request, final HttpContext context) throws HttpException { String hostname = (host != null ? host.getHostName() : null); if ((hosts != null) && (hostname != null)) { for (String h : hosts) { if (hostname.equalsIgnoreCase(h)) { // bypass proxy for that hostname return new HttpRoute(host); } } } return super.determineRoute(host, request, context); } }; httpClientBuilder.setRoutePlanner(routePlanner); } final HttpClientBuilder httpClientBuilder1 = httpClientBuilder.setProxy(proxy); updated = false; return httpClientBuilder1; } catch (MalformedURLException e) { throw new DSSException(e); } }
From source file:info.magnolia.ui.workbench.container.AbstractJcrContainer.java
/** * ***************************************** *//*from www . j av a 2 s . c o m*/ @Override public int indexOfId(Object itemId) { if (!containsId(itemId)) { return -1; } int size = size(); ensureItemIndices(); boolean wrappedAround = false; while (!wrappedAround) { for (Long i : itemIndexes.keySet()) { if (itemIndexes.get(i).equals(itemId)) { return i.intValue(); } } // load in the next page. int nextIndex = (currentOffset / (pageLength * cacheRatio) + 1) * (pageLength * cacheRatio); if (nextIndex >= size) { // Container wrapped around, start from index 0. wrappedAround = true; nextIndex = 0; } updateOffsetAndCache(nextIndex); } return -1; }
From source file:com.oncore.calorders.rest.service.extension.OrderHistoryFacadeRESTExtension.java
/** * Fetch all orders grouped by status/*from ww w . j ava2s . c om*/ * * @param departmentId a valid department id * @return a structure of order totals grouped by status * * @throws com.oncore.calorders.core.exceptions.DataAccessException */ @GET @Path("fetchOrderStatusSummary/{departmentId}") @Produces({ MediaType.APPLICATION_JSON }) public OrderStatusSummaryData fetchOrderStatusSummary(@PathParam("departmentId") Integer departmentId) throws DataAccessException { OrderStatusSummaryData orderStatusSummaryData = new OrderStatusSummaryData(); OrderStatusData orderStatusData = null; OrdStatusCd ordStatusCd = null; Department department = null; try { Logger.debug(LOG, "Hey testing logging, the fetchOrderStatusSummary is being called!"); department = getEntityManager().createNamedQuery("Department.findByDepUid", Department.class) .setParameter("depUid", departmentId).getSingleResult(); ordStatusCd = getEntityManager().createNamedQuery("OrdStatusCd.findByCode", OrdStatusCd.class) .setParameter("code", "CANC").getSingleResult(); TypedQuery<Long> query = getEntityManager().createQuery( "SELECT COUNT(o) FROM OrderHistory o WHERE o.depUidFk = :departmentId AND o.ordStatusCd = :code", Long.class).setParameter("departmentId", department).setParameter("code", ordStatusCd); Long count = query.getSingleResult(); List<Integer> items = new ArrayList<>(1); orderStatusData = new OrderStatusData(); orderStatusData.setName("Cancelled"); items.add(count.intValue()); orderStatusData.setItems(items); orderStatusSummaryData.getItems().add(orderStatusData); ordStatusCd = getEntityManager().createNamedQuery("OrdStatusCd.findByCode", OrdStatusCd.class) .setParameter("code", "PRCS").getSingleResult(); query = getEntityManager().createQuery( "SELECT COUNT(o) FROM OrderHistory o WHERE o.depUidFk = :departmentId AND o.ordStatusCd = :code", Long.class).setParameter("departmentId", department).setParameter("code", ordStatusCd); count = query.getSingleResult(); items = new ArrayList<>(1); orderStatusData = new OrderStatusData(); orderStatusData.setName("Processing"); items.add(count.intValue()); orderStatusData.setItems(items); orderStatusSummaryData.getItems().add(orderStatusData); ordStatusCd = getEntityManager().createNamedQuery("OrdStatusCd.findByCode", OrdStatusCd.class) .setParameter("code", "SHIP").getSingleResult(); query = getEntityManager().createQuery( "SELECT COUNT(o) FROM OrderHistory o WHERE o.depUidFk = :departmentId AND o.ordStatusCd = :code", Long.class).setParameter("departmentId", department).setParameter("code", ordStatusCd); count = query.getSingleResult(); items = new ArrayList<>(1); orderStatusData = new OrderStatusData(); orderStatusData.setName("Shipped"); items.add(count.intValue()); orderStatusData.setItems(items); orderStatusSummaryData.getItems().add(orderStatusData); ordStatusCd = getEntityManager().createNamedQuery("OrdStatusCd.findByCode", OrdStatusCd.class) .setParameter("code", "SUBT").getSingleResult(); query = getEntityManager().createQuery( "SELECT COUNT(o) FROM OrderHistory o WHERE o.depUidFk = :departmentId AND o.ordStatusCd = :code", Long.class).setParameter("departmentId", department).setParameter("code", ordStatusCd); count = query.getSingleResult(); items = new ArrayList<>(1); orderStatusData = new OrderStatusData(); orderStatusData.setName("Submitted"); items.add(count.intValue()); orderStatusData.setItems(items); orderStatusSummaryData.getItems().add(orderStatusData); } catch (Exception ex) { Logger.error(LOG, FormatHelper.getStackTrace(ex)); throw new DataAccessException(ex, ErrorCode.DATAACCESSERROR); } return orderStatusSummaryData; }