List of usage examples for java.lang Long intValue
public int intValue()
From source file:com.gst.infrastructure.campaigns.sms.serialization.SmsCampaignValidator.java
public void validateForUpdate(String json) { if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); }/* w w w .j a v a2 s. c om*/ final Type typeOfMap = new TypeToken<Map<String, Object>>() { }.getType(); this.fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, json, SmsCampaignValidator.supportedParamsForUpdate); final JsonElement element = this.fromApiJsonHelper.parse(json); final List<ApiParameterError> dataValidationErrors = new ArrayList<>(); final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors) .resource(SmsCampaignValidator.RESOURCE_NAME); final String campaignName = this.fromApiJsonHelper.extractStringNamed(SmsCampaignValidator.campaignName, element); baseDataValidator.reset().parameter(SmsCampaignValidator.campaignName).value(campaignName).notBlank() .notExceedingLengthOf(100); final Long campaignType = this.fromApiJsonHelper.extractLongNamed(SmsCampaignValidator.campaignType, element); baseDataValidator.reset().parameter(SmsCampaignValidator.campaignType).value(campaignType).notNull() .integerGreaterThanZero(); final Long triggerType = this.fromApiJsonHelper.extractLongNamed(SmsCampaignValidator.triggerType, element); baseDataValidator.reset().parameter(SmsCampaignValidator.triggerType).value(triggerType).notNull() .integerGreaterThanZero(); if (triggerType.intValue() == SmsCampaignTriggerType.SCHEDULE.getValue()) { if (this.fromApiJsonHelper.parameterExists(SmsCampaignValidator.recurrenceParamName, element)) { final String recurrenceParamName = this.fromApiJsonHelper .extractStringNamed(SmsCampaignValidator.recurrenceParamName, element); baseDataValidator.reset().parameter(SmsCampaignValidator.recurrenceParamName) .value(recurrenceParamName).notBlank(); } if (this.fromApiJsonHelper.parameterExists(SmsCampaignValidator.recurrenceStartDate, element)) { final String recurrenceStartDate = this.fromApiJsonHelper .extractStringNamed(SmsCampaignValidator.recurrenceStartDate, element); baseDataValidator.reset().parameter(SmsCampaignValidator.recurrenceStartDate) .value(recurrenceStartDate).notBlank(); } } if (this.fromApiJsonHelper.parameterExists(SmsCampaignValidator.runReportId, element)) { final Long runReportId = this.fromApiJsonHelper.extractLongNamed(SmsCampaignValidator.runReportId, element); baseDataValidator.reset().parameter(SmsCampaignValidator.runReportId).value(runReportId).notNull() .integerGreaterThanZero(); } final String message = this.fromApiJsonHelper.extractStringNamed(SmsCampaignValidator.message, element); baseDataValidator.reset().parameter(SmsCampaignValidator.message).value(message).notBlank() .notExceedingLengthOf(480); final JsonElement paramValueJsonObject = this.fromApiJsonHelper .extractJsonObjectNamed(SmsCampaignValidator.paramValue, element); if (triggerType.intValue() != SmsCampaignTriggerType.TRIGGERED.getValue()) { baseDataValidator.reset().parameter(SmsCampaignValidator.paramValue).value(paramValueJsonObject) .notBlank(); if (paramValueJsonObject != null && paramValueJsonObject.isJsonObject()) { for (Map.Entry<String, JsonElement> entry : paramValueJsonObject.getAsJsonObject().entrySet()) { final JsonElement inner = entry.getValue(); baseDataValidator.reset().parameter(entry.getKey()).value(inner).notBlank(); } } } throwExceptionIfValidationWarningsExist(dataValidationErrors); }
From source file:com.recomdata.transmart.data.export.util.FileWriterUtil.java
public String getClobAsString(Clob clob) { String strVal = ""; Reader reader = null;// ww w. ja va2 s . co m StringBuffer strBuf = null; try { if (null != clob) { Long clobLength = (null != clob) ? clob.length() : 0; reader = clob.getCharacterStream(); if (null != clobLength && clobLength > 0 && null != reader) { //Here length of String is being rounded to 5000 * n, this is because the buffer size is 5000 //Sometimes the cloblength is less than 5000 * n char[] buffer = new char[clobLength.intValue()]; @SuppressWarnings("unused") int count = 0; strBuf = new StringBuffer(); while ((count = reader.read(buffer)) > 0) { strBuf.append(buffer); } strVal = strBuf.toString(); } } } catch (IOException e) { log.info(e.getMessage()); } catch (SQLException e2) { log.info("SQLException :: " + e2.getMessage()); } finally { try { if (null != reader) reader.close(); //Nullify the objects so they become ready for Garbage Collection reader = null; strBuf = null; clob = null; super.finalize(); } catch (IOException e) { log.info("Error closing Reader in getClobAsString"); } catch (Throwable e) { log.info("Error during super.finalize()"); } } return strVal; }
From source file:biomine.bmvis2.crawling.CrawlSuggestionList.java
private ArrayList<NodeType> fetchList(String q, int type, int organism) throws IOException { ArrayList<NodeType> ret = new ArrayList<NodeType>(); if (q.length() == 0) return ret; String typePar = type <= 0 ? "" : ("type=" + type + "__"); String orgPar = organism <= 0 ? "" : ("organism=" + organism + "__"); String dbPar = db == null ? "" : ("db=" + URLEncoder.encode(db, "UTF-8") + "__"); URL u = new URL(WebConstants.DEFAULT_BASEURL + "suggest.cgi?" + orgPar + typePar + dbPar + "term=" + URLEncoder.encode(q, "UTF-8")); System.out.println("querying " + u + " organism=" + organism + " type=" + type); String jsonStr = URLUtils.getURLContents(u); if (type != 0) { NodeType back = new NodeType(); back.name = "back to unfiltered results"; back.tcode = 0;/*from w w w. java 2s . com*/ back.ocode = 0; ret.add(back); } try { JSONArray ja = (JSONArray) JSONValue.parse(jsonStr); for (Object orgz : ja) { JSONObject orgtype = (JSONObject) orgz; Long tcodeL = (Long) orgtype.get("type"); int tcode = tcodeL.intValue(); Long ocodeL = (Long) orgtype.get("organism"); int ocode = ocodeL.intValue(); NodeType curType = null; curType = new NodeType(); curType.tcode = tcode; curType.ocode = ocode; curType.name = orgtype.get("text").toString(); curType.more = orgtype.get("unshown").toString(); ret.add(curType); JSONArray match = (JSONArray) orgtype.get("matches"); for (Object o : match) { JSONObject node = (JSONObject) o; String code = node.get("term").toString(); String name = node.get("title").toString(); NodeItem it = new NodeItem(code, name); curType.items.add(it); } } } catch (ClassCastException e) { throw new IOException("Invalid JSON from server", e); } return ret; }
From source file:com.creditcloud.common.entities.dao.AbstractReadDAO.java
/** * /*from w w w. j a v a 2s.co m*/ * list entity by criteriaInfo * * @param criteriaInfo * @return */ public PagedResult<T> findAll(CriteriaInfo criteriaInfo) { EntityManager em = getEntityManager(); ParamInfo paramInfo = criteriaInfo.getParamInfo(); PageInfo pageInfo = criteriaInfo.getPageInfo(); SortInfo sortInfo = criteriaInfo.getSortInfo(); StringBuilder from = new StringBuilder(); from.append(String.format("%s t ", entityClass.getSimpleName())); StringBuilder where = new StringBuilder(); Map<String, Object> paramMap = new HashMap<>(); where = prepareWhereCondition(paramInfo, paramMap, where); StringBuilder orderBy = new StringBuilder(" "); if (sortInfo != null) { Iterator<SortItem> iterator = sortInfo.getSortItems().iterator(); while (iterator.hasNext()) { SortItem item = iterator.next(); orderBy.append("t.").append(item.getFieldName()).append(" ") .append(item.isDescending() ? "desc" : "asc").append(","); } orderBy = new StringBuilder(orderBy.substring(0, orderBy.length() - 1)); ; } String query = toSql(where, from, orderBy, false); String countquery = toSql(where, from, orderBy, true); TypedQuery<T> cq = em.createQuery(query, entityClass); //?? TypedQuery<Long> countq = em.createQuery(countquery, Long.class); for (String key : paramMap.keySet()) { Object value = paramMap.get(key); cq.setParameter(key, value); countq.setParameter(key, value); } Long countResult = countq.getSingleResult(); if (pageInfo != null) { cq.setFirstResult(pageInfo.getOffset()); cq.setMaxResults(pageInfo.getSize()); } return new PagedResult(cq.getResultList(), countResult == null ? 0 : countResult.intValue()); }
From source file:com.gst.infrastructure.campaigns.sms.serialization.SmsCampaignValidator.java
public void validateCreate(String json) { if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); }//from ww w . j a va 2s . c om final Type typeOfMap = new TypeToken<Map<String, Object>>() { }.getType(); this.fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, json, SmsCampaignValidator.supportedParams); final JsonElement element = this.fromApiJsonHelper.parse(json); final List<ApiParameterError> dataValidationErrors = new ArrayList<>(); final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors) .resource(SmsCampaignValidator.RESOURCE_NAME); final String campaignName = this.fromApiJsonHelper.extractStringNamed(SmsCampaignValidator.campaignName, element); baseDataValidator.reset().parameter(SmsCampaignValidator.campaignName).value(campaignName).notBlank() .notExceedingLengthOf(100); final Long campaignType = this.fromApiJsonHelper.extractLongNamed(SmsCampaignValidator.campaignType, element); baseDataValidator.reset().parameter(SmsCampaignValidator.campaignType).value(campaignType).notNull() .integerGreaterThanZero(); final Long triggerType = this.fromApiJsonHelper.extractLongNamed(SmsCampaignValidator.triggerType, element); baseDataValidator.reset().parameter(SmsCampaignValidator.triggerType).value(triggerType).notNull() .integerGreaterThanZero(); if (triggerType.intValue() == SmsCampaignTriggerType.SCHEDULE.getValue()) { final Integer frequencyParam = this.fromApiJsonHelper .extractIntegerWithLocaleNamed(SmsCampaignValidator.frequencyParamName, element); baseDataValidator.reset().parameter(SmsCampaignValidator.frequencyParamName).value(frequencyParam) .notNull().integerGreaterThanZero(); final String intervalParam = this.fromApiJsonHelper .extractStringNamed(SmsCampaignValidator.intervalParamName, element); baseDataValidator.reset().parameter(SmsCampaignValidator.intervalParamName).value(intervalParam) .notBlank(); if (frequencyParam != null && frequencyParam.equals(CalendarFrequencyType.WEEKLY.getValue())) { final String repeatsOnDayParam = this.fromApiJsonHelper .extractStringNamed(SmsCampaignValidator.repeatsOnDayParamName, element); baseDataValidator.reset().parameter(SmsCampaignValidator.repeatsOnDayParamName) .value(repeatsOnDayParam).notBlank(); } final String recurrenceStartDate = this.fromApiJsonHelper .extractStringNamed(SmsCampaignValidator.recurrenceStartDate, element); baseDataValidator.reset().parameter(SmsCampaignValidator.recurrenceStartDate).value(recurrenceStartDate) .notBlank(); } final Long runReportId = this.fromApiJsonHelper.extractLongNamed(SmsCampaignValidator.runReportId, element); baseDataValidator.reset().parameter(SmsCampaignValidator.runReportId).value(runReportId).notNull() .integerGreaterThanZero(); final String message = this.fromApiJsonHelper.extractStringNamed(SmsCampaignValidator.message, element); baseDataValidator.reset().parameter(SmsCampaignValidator.message).value(message).notBlank() .notExceedingLengthOf(480); final JsonElement paramValueJsonObject = this.fromApiJsonHelper .extractJsonObjectNamed(SmsCampaignValidator.paramValue, element); if (triggerType.intValue() != SmsCampaignTriggerType.TRIGGERED.getValue()) { baseDataValidator.reset().parameter(SmsCampaignValidator.paramValue).value(paramValueJsonObject) .notBlank(); if (paramValueJsonObject != null && paramValueJsonObject.isJsonObject()) { for (Map.Entry<String, JsonElement> entry : paramValueJsonObject.getAsJsonObject().entrySet()) { final JsonElement inner = entry.getValue(); baseDataValidator.reset().parameter(entry.getKey()).value(inner).notBlank(); } } } if (this.fromApiJsonHelper.parameterExists(SmsCampaignValidator.submittedOnDateParamName, element)) { final LocalDate submittedOnDate = this.fromApiJsonHelper .extractLocalDateNamed(SmsCampaignValidator.submittedOnDateParamName, element); baseDataValidator.reset().parameter(SmsCampaignValidator.submittedOnDateParamName) .value(submittedOnDate).notNull(); } throwExceptionIfValidationWarningsExist(dataValidationErrors); }
From source file:com.abiquo.server.core.enterprise.RoleDAO.java
public Collection<Role> findExactly(final Enterprise enterprise, final String filter, final String orderBy, final boolean desc, final Integer offset, final Integer numResults, final boolean discardNullEnterprises) { Criteria criteria = createCriteriaExactly(enterprise, filter, orderBy, desc, discardNullEnterprises); Long total = count(criteria); criteria = createCriteriaExactly(enterprise, filter, orderBy, desc, discardNullEnterprises); criteria.setFirstResult(offset * numResults); criteria.setMaxResults(numResults);// ww w.ja v a 2 s .c o m List<Role> result = getResultList(criteria); PagedList<Role> page = new PagedList<Role>(); page.addAll(result); page.setCurrentElement(offset); page.setPageSize(numResults); page.setTotalResults(total.intValue()); return page; }
From source file:com.sfs.captor.controller.AlternativeFlowAction.java
/** * Add business rule action/* w w w . j a v a2 s . c o m*/ */ public void addBusinessRule() { Long cnt = getFlowStepRuleCount(); this.flowStepRule = new FlowStepRule(cnt.intValue() + 1); // product release is inherited this.flowStepRule.setProductRelease(this.useCase.getProductRelease()); }
From source file:com.mb.framework.util.DateTimeUtil.java
public static long daysDiff(Date dueDate, Date today) { Long daysDiff = new Long(0); if (dueDate.after(today)) { daysDiff = (dueDate.getTime() - today.getTime()) / (1000 * 60 * 60 * 24); }/*from ww w .j ava2 s .c om*/ return daysDiff.intValue(); }
From source file:mx.edu.um.mateo.inventario.dao.impl.FacturaAlmacenDaoHibernate.java
@Override @Transactional(readOnly = true)/*ww w . j a v a 2 s .com*/ public Map<String, Object> lista(Map<String, Object> params) { log.debug("Buscando lista de facturas con params {}", params); if (params == null) { params = new HashMap<>(); } if (!params.containsKey("max")) { params.put("max", 10); } else { params.put("max", Math.min((Integer) params.get("max"), 100)); } if (params.containsKey("pagina")) { Long pagina = (Long) params.get("pagina"); Long offset = (pagina - 1) * (Integer) params.get("max"); params.put("offset", offset.intValue()); } if (!params.containsKey("offset")) { params.put("offset", 0); } Criteria criteria = currentSession().createCriteria(FacturaAlmacen.class); Criteria countCriteria = currentSession().createCriteria(FacturaAlmacen.class); if (params.containsKey("almacen")) { criteria.createCriteria("almacen").add(Restrictions.idEq(params.get("almacen"))); countCriteria.createCriteria("almacen").add(Restrictions.idEq(params.get("almacen"))); } if (params.containsKey("fechaIniciado")) { log.debug("Buscando desde {}", params.get("fechaIniciado")); criteria.add(Restrictions.ge("fechaCreacion", params.get("fechaIniciado"))); countCriteria.add(Restrictions.ge("fechaCreacion", params.get("fechaIniciado"))); } else { Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.DAY_OF_MONTH, 1); calendar.set(Calendar.HOUR_OF_DAY, 0); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.SECOND, 0); calendar.set(Calendar.MILLISECOND, 1); log.debug("Asignando busqueda desde {}", calendar.getTime()); criteria.add(Restrictions.ge("fechaCreacion", calendar.getTime())); countCriteria.add(Restrictions.ge("fechaCreacion", calendar.getTime())); } if (params.containsKey("fechaTerminado")) { log.debug("Buscando hasta {}", params.get("fechaTerminado")); criteria.add(Restrictions.le("fechaCreacion", params.get("fechaTerminado"))); countCriteria.add(Restrictions.le("fechaCreacion", params.get("fechaTerminado"))); } if (params.containsKey("filtro")) { String filtro = (String) params.get("filtro"); Disjunction propiedades = Restrictions.disjunction(); propiedades.add(Restrictions.ilike("folio", filtro, MatchMode.ANYWHERE)); criteria.add(propiedades); countCriteria.add(propiedades); } if (params.containsKey("order")) { String campo = (String) params.get("order"); if (params.get("sort").equals("desc")) { criteria.addOrder(Order.desc(campo)); } else { criteria.addOrder(Order.asc(campo)); } } else { criteria.createCriteria("estatus").addOrder(Order.asc("prioridad")); } criteria.addOrder(Order.desc("fechaModificacion")); if (!params.containsKey("reporte")) { criteria.setFirstResult((Integer) params.get("offset")); criteria.setMaxResults((Integer) params.get("max")); } params.put("facturas", criteria.list()); countCriteria.setProjection(Projections.rowCount()); params.put("cantidad", (Long) countCriteria.list().get(0)); return params; }
From source file:eu.europa.ec.markt.dss.validation102853.https.CommonsDataLoader.java
/** * Configure the proxy with the required credential if needed * * @param httpClientBuilder/*from ww w. j a v a 2 s . c o m*/ * @param credsProvider * @param url * @return * @throws java.net.MalformedURLException */ private HttpClientBuilder configureProxy(HttpClientBuilder httpClientBuilder, CredentialsProvider credsProvider, String url) throws DSSException { try { if (proxyPreferenceManager == null) { return httpClientBuilder; } 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; 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(); } else // noinspection ConstantConditions if (proxyHTTP) { 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(); } if (DSSUtils.isNotEmpty(proxyUser) && DSSUtils.isNotEmpty(proxyPassword)) { LOG.debug("proxy user: " + proxyUser + ":" + proxyPassword); AuthScope proxyAuth = new AuthScope(proxyHost, proxyPort); UsernamePasswordCredentials proxyCredentials = new UsernamePasswordCredentials(proxyUser, proxyPassword); credsProvider.setCredentials(proxyAuth, proxyCredentials); } LOG.debug("proxy host/port: " + proxyHost + ":" + proxyPort); // TODO SSL peer shut down incorrectly when protocol is https HttpHost proxy = new HttpHost(proxyHost, proxyPort, Protocol.HTTP.getName()); return httpClientBuilder.setProxy(proxy); } catch (MalformedURLException e) { throw new DSSException(e); } }