List of usage examples for java.lang Integer longValue
public long longValue()
From source file:utils.gce.GoogleComputeEngineClient.java
public String createDisk(String name, String diskType, Integer sizeGb) throws GoogleComputeEngineException { if (!zoneName.isPresent()) { throw new GoogleComputeEngineException("zone name not specified"); }// ww w.j a v a2 s .c o m try { Disk disk = new Disk(); disk.setName(name); disk.setZone(zoneName.get()); disk.setSizeGb(sizeGb.longValue()); disk.setType(diskType); Compute.Disks.Insert insert = compute.disks().insert(projectId, zoneName.get(), disk); return insert.execute().getTargetLink(); } catch (IOException e) { throw new GoogleComputeEngineException(e); } }
From source file:org.sigmah.server.policy.ProjectReportPolicy.java
@Transactional protected ProjectReport createReport(User user, PropertyMap properties) { final ProjectReport report = new ProjectReport(); final ProjectReportVersion initialVersion = new ProjectReportVersion(); report.setCurrentVersion(initialVersion); // Defining the common properties report.setName((String) properties.get("name")); initialVersion.setReport(report);/*ww w .ja va2 s . co m*/ initialVersion.setVersion(1); initialVersion.setEditor(user); initialVersion.setEditDate(new Date()); initialVersion.setPhaseName((String) properties.get("phaseName")); final ProjectReportModel model = dao.findModelById((Integer) properties.get("reportModelId")); report.setModel(model); final Integer projectId = (Integer) properties.get("projectId"); if (projectId != null) { final Project project = new Project(); project.setId(projectId); report.setProject(project); } final Integer orgUnitId = (Integer) properties.get("orgUnitId"); if (orgUnitId != null) { final OrgUnit orgUnit = new OrgUnit(); orgUnit.setId(orgUnitId); report.setOrgUnit(orgUnit); } // Parent final Integer flexibleElementId = (Integer) properties.get("flexibleElementId"); final Integer containerId = (Integer) properties.get("containerId"); final boolean multiple; if (properties.get("multiple") == null) multiple = false; else multiple = (Boolean) properties.get("multiple"); final Value flexibleElementValue; if (flexibleElementId != null && containerId != null) { final ReportElement element = new ReportElement(); element.setId(flexibleElementId.longValue()); report.setFlexibleElement(element); flexibleElementValue = updateProjectHandler.retrieveValue(containerId, flexibleElementId, user); if (!multiple && !(flexibleElementValue == null || flexibleElementValue.getValue() == null || "".equals(flexibleElementValue.getValue()))) throw new IllegalStateException( "A report has already been created for the flexible element " + flexibleElementId); } else flexibleElementValue = null; // RichTextElements final ArrayList<RichTextElement> elements = new ArrayList<RichTextElement>(); for (final ProjectReportModelSection section : model.getSections()) iterateOnSection(section, elements, initialVersion); initialVersion.setTexts(elements); // Saving dao.persist(report); // Updating the flexible element if (flexibleElementValue != null) { final String value; if (multiple && flexibleElementValue.getValue() != null) { // Multiple values mode value = flexibleElementValue.getValue() + ValueResultUtils.DEFAULT_VALUE_SEPARATOR + report.getId().toString(); } else { // Single value mode value = report.getId().toString(); } flexibleElementValue.setValue(value); dao.merge(flexibleElementValue); } return report; }
From source file:at.tugraz.ist.akm.webservice.requestprocessor.JsonAPIRequestProcessor.java
private synchronized JSONObject fetchSMSThread(JSONArray params) { JSONObject resultObject = new JSONObject(); String contact_id = ""; int paramsLength = params.length(); int messageCount = this.mSMSThreadMessageCount; try {//from w w w .j a v a 2 s . c om if (paramsLength == 1) { List<TextMessage> threadList = new ArrayList<TextMessage>(); JSONObject jsonParams = params.getJSONObject(0); contact_id = jsonParams.getString("contact_id"); mLog.debug("fetch SMS thread with given contact_id [" + contact_id + "]"); ContactFilter conFilter = new ContactFilter(); conFilter.setId(Integer.parseInt(contact_id)); List<Contact> contacts = mTextingAdapter.fetchContacts(conFilter); mLog.debug("found contacts - list size [" + contacts.size() + "]"); if (contacts.size() == 1) { Contact contact = contacts.get(0); List<Contact.Number> phoneNumbers = contact.getPhoneNumbers(); for (Contact.Number entry : phoneNumbers) { if (messageCount <= 0) { break; } mLog.debug("fetch SMS thread of [" + contact.getDisplayName() + "] with number [" + entry.getNumber() + "]"); List<Integer> threadIds = mTextingAdapter.fetchThreadIds(entry.getNumber()); for (Integer threadId : threadIds) { if (messageCount <= 0) { break; } TextMessageFilter msgFilter = new TextMessageFilter(); msgFilter.setThreadId(threadId.longValue()); msgFilter.setBox(SmsContentConstants.Uri.BASE_URI); mLog.debug("fetch SMS thread with ID [" + threadId + "]"); List<TextMessage> threadMessages = mTextingAdapter.fetchTextMessages(msgFilter); for (TextMessage msg : threadMessages) { if (messageCount <= 0) { break; } threadList.add(msg); messageCount--; } } } // sort the list by date Collections.sort(threadList, new TextMessageThreadSort()); JSONArray thread_messages = new JSONArray(); for (TextMessage msg : threadList) { JSONObject entry = new JSONObject(); if (msg.getPerson() != null && msg.getPerson().compareTo("null") != 0 && msg.getPerson().length() > 0) { entry.put("real_contact_id", contact_id); } else { entry.put("real_contact_id", ""); } entry.put("message", mJsonFactory.createJsonObject(msg)); thread_messages.put(entry); } setSuccessState(resultObject); resultObject.put("thread_messages", thread_messages); resultObject.put("contact_id", contact_id); } else { mLog.warning("contact with id [" + contact_id + "] not found or ambiguous"); this.setErrorState(resultObject, "contact not found"); return resultObject; } } else { this.setErrorState(resultObject, "Corrupt amount of parameters given to fetch sms tread."); return resultObject; } } catch (JSONException jsonException) { mLog.error("Parameters for fetching sms thread could not be extracted from the given api request.", jsonException); } return resultObject; }
From source file:com.emergya.siradmin.invest.InvestmentUpdater.java
public List<LlaveBean> getExistingKeysInChileindica(Integer ano, Integer codigoRegion) { LOGGER.info("Obteniendo llaves para del ao " + ano + " y la regin " + codigoRegion); try {//from w w w .j ava 2 s.c o m List<LlaveBean> keys = null; ConsultaLlavesResponse response = wsConsultaLlaves.getWSConsultaLlavesPort().WSConsultaLlaves( BigInteger.valueOf(ano.longValue()), BigInteger.valueOf(codigoRegion.longValue())); Respuesta respuesta = response.getRespuesta(); if (!BigInteger.ZERO.equals(respuesta.getCodigoRespuesta())) { LOGGER.error( "El servicio web Consulta de llaves " + wsConsultaLlaves.getWSConsultaLlavesPortAddress() + " ha devuelto un cdigo de error " + respuesta.getCodigoRespuesta() + ". El mensaje de error fue: " + respuesta.getTextoRespuesta()); throw new WSCallException(respuesta.getCodigoRespuesta(), respuesta.getTextoRespuesta()); } if (response.getLlavesInversion() != null) { keys = new ArrayList<LlaveBean>(response.getLlavesInversion().length); for (LlavesInversionData projectKey : response.getLlavesInversion()) { LlaveBean key = new LlaveBean(); key.setAno(projectKey.getAno().intValue()); key.setRegion(codigoRegion); key.setcFicha(projectKey.getC_Ficha().intValue()); key.setcInstitucion(projectKey.getC_Institucion().intValue()); key.setcPreinversion(projectKey.getC_Preinversion().intValue()); BigInteger fechaRegistro = projectKey.getFechaRegistro(); if (fechaRegistro != null) { key.setFechaRegistro(fechaRegistro.intValue()); } boolean updatable = service.checkIfProjectMustBeUpdated(key.getRegion(), key.getAno(), key.getcInstitucion(), key.getcPreinversion(), key.getcFicha(), key.getFechaRegistro()); key.setUpdatable(updatable); keys.add(key); } return keys; } else { if (LOGGER.isInfoEnabled()) { LOGGER.info("El WS de consulta de llaves no ha devuelto datos para el ao " + ano + " y la regin " + codigoRegion); } return new ArrayList<LlaveBean>(); } } catch (RemoteException e) { LOGGER.error("Error llamando al servicio web " + wsConsultaLlaves.getWSConsultaLlavesPortAddress(), e); throw new WSCallException(e); } catch (ServiceException e) { LOGGER.error("Error llamando al servicio web " + wsConsultaLlaves.getWSConsultaLlavesPortAddress(), e); throw new WSCallException(e); } }
From source file:csds60analyzer.csds60analyzerGUI.java
public BufferedImage creaImagen() { BufferedImage imagen = null;//from w ww . j a v a2 s . c o m try { SAXBuilder builder = new SAXBuilder(false); Document doc = null; TimeSeriesCollection datos = new TimeSeriesCollection(); if (fichero != null) { doc = builder.build(fichero); Element raiz = doc.getRootElement(); List<Element> dias = raiz.getChildren("dia"); Iterator<Element> diasIT = dias.iterator(); TimeSeries desayunoAntes = new TimeSeries("Desayuno antes"); TimeSeries desayunoDespues = new TimeSeries("Desayuno despus"); TimeSeries almuerzoAntes = new TimeSeries("Almuerzo antes"); TimeSeries almuerzoDespues = new TimeSeries("Almuerzo despus"); TimeSeries cenaAntes = new TimeSeries("Cena antes"); TimeSeries cenaDespues = new TimeSeries("Cena despus"); pdesayuno = 0; pdesant = 0; pdesdes = 0; palmuerzo = 0; palmant = 0; palmdes = 0; pcena = 0; pcenant = 0; pcendes = 0; contdesant = 0; contdesdes = 0; contalmant = 0; contalmdes = 0; contcenant = 0; contcendes = 0; while (diasIT.hasNext()) { Element diaActual = diasIT.next(); Integer fechaActual = Integer.parseInt(diaActual.getChildText("fecha").substring(0, 10)); Calendar fad = GregorianCalendar.getInstance(); fad.setTimeInMillis(fechaActual.longValue() * 1000); int dia = fad.get(Calendar.DAY_OF_MONTH); int mes = fad.get(Calendar.MONTH) + 1; int ano = fad.get(Calendar.YEAR); if (diaActual.getChildren().toString().contains("desayunoantes")) { int desayunoAntesActual = Integer.parseInt(diaActual.getChildText("desayunoantes")); desayunoAntes.add(new Day(dia, mes, ano), desayunoAntesActual); pdesant = pdesant + desayunoAntesActual; contdesant++; } if (diaActual.getChildren().toString().contains("desayunodespues")) { int desayunoDespuesActual = Integer.parseInt(diaActual.getChildText("desayunodespues")); desayunoDespues.add(new Day(dia, mes, ano), desayunoDespuesActual); pdesdes = pdesdes + desayunoDespuesActual; contdesdes++; } if (diaActual.getChildren().toString().contains("almuerzoantes")) { int almuerzoAntesActual = Integer.parseInt(diaActual.getChildText("almuerzoantes")); almuerzoAntes.add(new Day(dia, mes, ano), almuerzoAntesActual); palmant = palmant + almuerzoAntesActual; contalmant++; } if (diaActual.getChildren().toString().contains("almuerzodespues")) { int almuerzoDespuesActual = Integer.parseInt(diaActual.getChildText("almuerzodespues")); almuerzoDespues.add(new Day(dia, mes, ano), almuerzoDespuesActual); palmdes = palmdes + almuerzoDespuesActual; contalmdes++; } if (diaActual.getChildren().toString().contains("cenaantes")) { int cenaAntesActual = Integer.parseInt(diaActual.getChildText("cenaantes")); cenaAntes.add(new Day(dia, mes, ano), cenaAntesActual); pcenant = pcenant + cenaAntesActual; contcenant++; } if (diaActual.getChildren().toString().contains("cenadespues")) { int cenaDespuesActual = Integer.parseInt(diaActual.getChildText("cenadespues")); cenaDespues.add(new Day(dia, mes, ano), cenaDespuesActual); pcendes = pcendes + cenaDespuesActual; contcendes++; } } //controlar la division por cero if ((contdesant + contdesdes) > 0) pdesayuno = (pdesant + pdesdes) / (contdesant + contdesdes); if (contdesant > 0) pdesant = pdesant / contdesant; if (contdesdes > 0) pdesdes = pdesdes / contdesdes; if ((contalmant + contalmdes) > 0) palmuerzo = (palmant + palmdes) / (contalmant + contalmdes); if (contalmant > 0) palmant = palmant / contalmant; if (contalmdes > 0) palmdes = palmdes / contalmdes; if ((contcenant + contcendes) > 0) pcena = (pcenant + pcendes) / (contcenant + contcendes); if (contcenant > 0) pcenant = pcenant / contcenant; if (contcendes > 0) pcendes = pcendes / contcendes; datos.addSeries(desayunoAntes); datos.addSeries(desayunoDespues); datos.addSeries(almuerzoAntes); datos.addSeries(almuerzoDespues); datos.addSeries(cenaAntes); datos.addSeries(cenaDespues); } JFreeChart graficaJfree = ChartFactory.createTimeSeriesChart("Anlisis", " ", "Glucosa (mg)", datos, true, true, false); XYPlot plot = (XYPlot) graficaJfree.getPlot(); plot.setBackgroundPaint(Color.getHSBColor(0f, 0f, .88f)); plot.setDomainGridlinePaint(Color.getHSBColor(0f, 0f, .35f)); plot.setDomainTickBandPaint(Color.getHSBColor(0f, 0f, .93f)); plot.setOutlinePaint(Color.getHSBColor(0f, 0f, 0.35f)); plot.setRangeGridlinePaint(Color.getHSBColor(0f, 0f, 0.35f)); XYLineAndShapeRenderer plot2 = (XYLineAndShapeRenderer) plot.getRenderer(); if (!CBdesayunoantes.getState()) plot2.setSeriesLinesVisible(0, false); plot2.setSeriesPaint(0, Color.getHSBColor(.3f, 1f, .5f)); //plot2.setSeriesStroke(0,new BasicStroke(2.0f,BasicStroke.CAP_ROUND,BasicStroke.JOIN_ROUND,1.0f)); if (!CBdesayunodespues.getState()) plot2.setSeriesLinesVisible(1, false); plot2.setSeriesPaint(1, Color.getHSBColor(.2f, 1f, .9f)); if (!CBalmuerzoantes.getState()) plot2.setSeriesLinesVisible(2, false); plot2.setSeriesPaint(2, Color.getHSBColor(.0f, 1f, .6f)); if (!CBalmuerzodespues.getState()) plot2.setSeriesLinesVisible(3, false); plot2.setSeriesPaint(3, Color.getHSBColor(.0f, 1f, .9f)); if (!CBcenaantes.getState()) plot2.setSeriesLinesVisible(4, false); plot2.setSeriesPaint(4, Color.getHSBColor(.6f, 1f, .4f)); if (!CBcenadespues.getState()) plot2.setSeriesLinesVisible(5, false); plot2.setSeriesPaint(5, Color.getHSBColor(.6f, 1f, 1f)); imagen = graficaJfree.createBufferedImage(800, 600); } catch (Exception e) { e.printStackTrace(); } return imagen; }
From source file:org.cloudfoundry.identity.uaa.oauth.token.UaaTokenServices.java
/** * This method is implemented to support older API calls that assume the * presence of a token store//from w w w. ja v a 2 s . c om */ @Override public OAuth2AccessToken readAccessToken(String accessToken) { Map<String, Object> claims = getClaimsForToken(accessToken); // Expiry is verified by check_token OpenIdToken token = new OpenIdToken(accessToken); token.setTokenType(OAuth2AccessToken.BEARER_TYPE); Integer exp = (Integer) claims.get(EXP); if (null != exp) { token.setExpiration(new Date(exp.longValue() * 1000l)); } @SuppressWarnings("unchecked") ArrayList<String> scopes = (ArrayList<String>) claims.get(SCOPE); if (null != scopes && scopes.size() > 0) { token.setScope(new HashSet<String>(scopes)); } String email = (String) claims.get(EMAIL); // Only check user access tokens if (null != email) { String userId = (String) claims.get(USER_ID); UaaUser user = userDatabase.retrieveUserById(userId); Integer accessTokenIssuedAt = (Integer) claims.get(IAT); long accessTokenIssueDate = accessTokenIssuedAt.longValue() * 1000l; // If the user changed their password, expire the access token if (user.getModified().after(new Date(accessTokenIssueDate))) { logger.debug("User was last modified at " + user.getModified() + " access token was issued at " + new Date(accessTokenIssueDate)); throw new InvalidTokenException("Invalid access token (password changed): " + accessToken); } // Check approvals to make sure they're all valid, approved and not // more recent // than the token itself String clientId = (String) claims.get(CLIENT_ID); ClientDetails client = clientDetailsService.loadClientByClientId(clientId); @SuppressWarnings("unchecked") ArrayList<String> tokenScopes = (ArrayList<String>) claims.get(SCOPE); Set<String> autoApprovedScopes = getAutoApprovedScopes(claims.get(GRANT_TYPE), tokenScopes, client); if (autoApprovedScopes.containsAll(tokenScopes)) { return token; } checkForApproval(userId, clientId, tokenScopes, autoApprovedScopes, new Date(accessTokenIssueDate)); } return token; }
From source file:com.p5solutions.core.jpa.orm.EntityPersisterImpl.java
@Override public Long executeDML(String sql, Map<String, Object> params) { MapSqlParameterSource paramSource = new MapSqlParameterSource(params); // TODO <Object> should be of type T? how? import // org.apache.poi.hssf.record.formula.functions.T;?? Integer updated = getJdbcTemplate().execute(sql, paramSource, new PersistPreparedStatementCallback<Integer>()); return updated != null ? updated.longValue() : 0L; //return 0L;/*from w ww . j a va 2 s.co m*/ }
From source file:org.jasig.portal.portlet.container.cache.PortletCacheControlServiceImpl.java
/** * Construct an appropriate Cache {@link Element} for the cacheKey and data. * The element's ttl will be set depending on whether expiration or validation method is indicated from the CacheControl and the cache's configuration. * /*from ww w.ja va 2 s . c om*/ * @param cacheKey * @param data * @param cacheConfig * @param cacheControl * @return */ protected Element constructCacheElement(Serializable cacheKey, CachedPortletData data, CacheConfiguration cacheConfig, CacheControl cacheControl) { // if validation method is being triggered, ignore expirationTime and defer to cache configuration if (StringUtils.isNotBlank(cacheControl.getETag())) { return new Element(cacheKey, data); } Integer cacheControlTTL = cacheControl.getExpirationTime(); if (cacheControlTTL < 0) { // using expiration method, negative value for CacheControl#expirationTime means "forever" (e.g. ignore and defer to cache configuration) return new Element(cacheKey, data); } Long cacheConfigTTL = cacheConfig.getTimeToLiveSeconds(); Long min = Math.min(cacheConfigTTL, cacheControlTTL.longValue()); return new Element(cacheKey, data, null, null, min.intValue()); }
From source file:eu.europa.ec.fisheries.uvms.spatial.service.bean.impl.MapConfigServiceBean.java
private ProjectionDto getProjection(Integer id) { List<ProjectionDto> projectionDtoList = repository.findProjectionById(id.longValue()); return (projectionDtoList != null && !projectionDtoList.isEmpty()) ? projectionDtoList.get(0) : null; }
From source file:org.cloudfoundry.identity.uaa.oauth.token.UaaTokenServices.java
@Override public OAuth2AccessToken refreshAccessToken(String refreshTokenValue, TokenRequest request) throws AuthenticationException { if (null == refreshTokenValue) { throw new InvalidTokenException("Invalid refresh token (empty token)"); }//from w w w . j av a 2 s. co m if (!"refresh_token".equals(request.getRequestParameters().get("grant_type"))) { throw new InvalidGrantException( "Invalid grant type: " + request.getRequestParameters().get("grant_type")); } Map<String, Object> claims = getClaimsForToken(refreshTokenValue); // TODO: Should reuse the access token you get after the first // successful authentication. // You will get an invalid_grant error if your previous token has not // expired yet. // OAuth2RefreshToken refreshToken = // tokenStore.readRefreshToken(refreshTokenValue); // if (refreshToken == null) { // throw new InvalidGrantException("Invalid refresh token: " + // refreshTokenValue); // } String clientId = (String) claims.get(CID); if (clientId == null || !clientId.equals(request.getClientId())) { throw new InvalidGrantException("Wrong client for this refresh token: " + refreshTokenValue); } String userid = (String) claims.get(USER_ID); // TODO: Need to add a lookup by id so that the refresh token does not // need to contain a name UaaUser user = userDatabase.retrieveUserById(userid); Integer refreshTokenIssuedAt = (Integer) claims.get(IAT); long refreshTokenIssueDate = refreshTokenIssuedAt.longValue() * 1000l; // If the user changed their password, expire the refresh token if (user.getModified().after(new Date(refreshTokenIssueDate))) { logger.debug("User was last modified at " + user.getModified() + " refresh token was issued at " + new Date(refreshTokenIssueDate)); throw new InvalidTokenException("Invalid refresh token (password changed): " + refreshTokenValue); } Integer refreshTokenExpiry = (Integer) claims.get(EXP); long refreshTokenExpireDate = refreshTokenExpiry.longValue() * 1000l; if (new Date(refreshTokenExpireDate).before(new Date())) { throw new InvalidTokenException("Invalid refresh token (expired): " + refreshTokenValue + " expired at " + new Date(refreshTokenExpireDate)); } @SuppressWarnings("unchecked") ArrayList<String> tokenScopes = (ArrayList<String>) claims.get(SCOPE); // default request scopes to what is in the refresh token Set<String> requestedScopes = request.getScope(); if (requestedScopes.isEmpty()) { requestedScopes = new HashSet<String>(tokenScopes); } // The user may not request scopes that were not part of the refresh // token if (tokenScopes.isEmpty() || !tokenScopes.containsAll(requestedScopes)) { throw new InvalidScopeException( "Unable to narrow the scope of the client authentication to " + requestedScopes + ".", new HashSet<String>(tokenScopes)); } // from this point on, we only care about the scopes requested, not what // is in the refresh token // ensure all requested scopes are approved: either automatically or // explicitly by the user ClientDetails client = clientDetailsService.loadClientByClientId(clientId); String grantType = claims.get(GRANT_TYPE).toString(); checkForApproval(userid, clientId, requestedScopes, getAutoApprovedScopes(grantType, tokenScopes, client), new Date(refreshTokenIssueDate)); // if we have reached so far, issue an access token Integer validity = client.getAccessTokenValiditySeconds(); @SuppressWarnings("unchecked") Map<String, String> additionalAuthorizationInfo = (Map<String, String>) claims.get(ADDITIONAL_AZ_ATTR); Set<String> audience = new HashSet<>((ArrayList<String>) claims.get(AUD)); OAuth2AccessToken accessToken = createAccessToken(user.getId(), user.getUsername(), user.getEmail(), validity != null ? validity.intValue() : accessTokenValiditySeconds, null, requestedScopes, clientId, audience /*request.createOAuth2Request(client).getResourceIds()*/, grantType, refreshTokenValue, additionalAuthorizationInfo, new HashSet<String>()); //TODO populate response types return accessToken; }