Example usage for java.lang Integer longValue

List of usage examples for java.lang Integer longValue

Introduction

In this page you can find the example usage for java.lang Integer longValue.

Prototype

public long longValue() 

Source Link

Document

Returns the value of this Integer as a long after a widening primitive conversion.

Usage

From source file:org.cloudfoundry.identity.uaa.oauth.UaaTokenServices.java

/**
 * This method is implemented to support older API calls that assume the
 * presence of a token store/*from  ww  w . j av a 2  s. c o m*/
 */
@Override
public OAuth2AccessToken readAccessToken(String accessToken) {
    TokenValidation tokenValidation = validateToken(accessToken);
    Map<String, Object> claims = tokenValidation.getClaims();
    accessToken = tokenValidation.getJwt().getEncoded();

    // Expiry is verified by check_token
    CompositeAccessToken token = new CompositeAccessToken(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<>(scopes));
    }
    String clientId = (String) claims.get(CID);
    ClientDetails client = clientDetailsService.loadClientByClientId(clientId);
    String userId = (String) claims.get(USER_ID);
    // Only check user access tokens
    if (null != userId) {
        @SuppressWarnings("unchecked")
        ArrayList<String> tokenScopes = (ArrayList<String>) claims.get(SCOPE);
        Set<String> autoApprovedScopes = getAutoApprovedScopes(claims.get(GRANT_TYPE), tokenScopes, client);
        checkForApproval(userId, clientId, tokenScopes, autoApprovedScopes);
    }

    return token;
}

From source file:org.egov.works.services.AbstractEstimateService.java

private void persistBudgetAppropriationDetails(final AbstractEstimate abstractEstimate,
        final BudgetUsage budgetUsage) {
    AbstractEstimateAppropriation estimateAppropriation = null;
    final Integer finYearId = budgetUsage.getFinancialYearId();
    final Date endingDate = financialYearHibernateDAO.getFinancialYearById(finYearId.longValue())
            .getEndingDate();/*from   ww  w  .  j a v a  2 s.c  om*/
    estimateAppropriation = estimateAppropriationService.findByNamedQuery("getBudgetUsageForEstimateByFinYear",
            abstractEstimate.getId(), finYearId.intValue());

    if (estimateAppropriation != null) {
        estimateAppropriation.setBalanceAvailable(getBudgetAvailable(abstractEstimate, endingDate));
        estimateAppropriation.setBudgetUsage(budgetUsage);
    } else {
        estimateAppropriation = new AbstractEstimateAppropriation();
        estimateAppropriation.setAbstractEstimate(abstractEstimate);
        estimateAppropriation.setBalanceAvailable(getBudgetAvailable(abstractEstimate, endingDate));
        estimateAppropriation.setBudgetUsage(budgetUsage);
    }
    estimateAppropriationService.persist(estimateAppropriation);
}

From source file:com.houghtonassociates.bamboo.plugins.dao.GerritService.java

private void assignPatchSet(GerritChangeVO info, JSONObject p, boolean isCurrent) throws ParseException {
    log.debug(String.format("Assigning Patchset to: %s", info.toString()));

    PatchSet patch = new PatchSet();

    patch.setNumber(p.getInt(GerritChangeVO.JSON_KEY_PATCH_SET_NUM));
    patch.setRevision(p.getString(GerritChangeVO.JSON_KEY_PATCH_SET_REV));
    patch.setRef(p.getString(GerritChangeVO.JSON_KEY_PATCH_SET_REF));

    JSONObject patchSetUploader = p.getJSONObject(GerritChangeVO.JSON_KEY_PATCH_SET_UPDLOADER);

    if (patchSetUploader.containsKey(GerritChangeVO.JSON_KEY_NAME))
        patch.setUploaderName(patchSetUploader.getString(GerritChangeVO.JSON_KEY_NAME));

    if (patchSetUploader.containsKey(GerritChangeVO.JSON_KEY_EMAIL))
        patch.setUploaderEmail(patchSetUploader.getString(GerritChangeVO.JSON_KEY_EMAIL));

    try {/*from ww w .  j  a v a 2 s  . co m*/
        if (authorSupported) {
            JSONObject author = p.getJSONObject(GerritChangeVO.JSON_KEY_PATCH_SET_AUTHOR);
            if (author != null) {
                patch.setAuthorEmail(author.getString(GerritChangeVO.JSON_KEY_EMAIL));
                patch.setAuthorUserName(author.getString(GerritChangeVO.JSON_KEY_USERNAME));
                patch.setAuthorName(author.getString(GerritChangeVO.JSON_KEY_NAME));
            }
        }
    } catch (JSONException e) {
        authorSupported = false;
        log.error(String.format("Author not supported in release %s: %s", getGerritVersion(), e.getMessage()));
        log.error("Disabling author lookup.");
    }

    Integer patchSetCreatedOn = p.getInt(GerritChangeVO.JSON_KEY_PATCH_SET_CREATED_ON);
    patch.setCreatedOn(new Date(patchSetCreatedOn.longValue() * 1000));

    if (p.containsKey(GerritChangeVO.JSON_KEY_PATCH_SET_APPRVS)) {
        List<JSONObject> approvals = p.getJSONArray(GerritChangeVO.JSON_KEY_PATCH_SET_APPRVS);

        for (JSONObject a : approvals) {
            Approval apprv = new Approval();

            apprv.setType(a.getString(GerritChangeVO.JSON_KEY_PATCH_SET_APPRVS_TYPE));

            if (a.containsKey(GerritChangeVO.JSON_KEY_EMAIL)) {
                apprv.setDescription(a.getString(GerritChangeVO.JSON_KEY_PATCH_SET_APPRVS_DESC));
            }

            apprv.setValue(a.getInt(GerritChangeVO.JSON_KEY_PATCH_SET_APPRVS_VALUE));

            Integer grantedOn = a.getInt(GerritChangeVO.JSON_KEY_PATCH_SET_APPRVS_GRANTED_ON);
            apprv.setGrantedOn(new Date(grantedOn.longValue() * 1000));

            JSONObject by = a.getJSONObject(GerritChangeVO.JSON_KEY_PATCH_SET_APPRVS_BY);

            if (by.containsKey(GerritChangeVO.JSON_KEY_NAME))
                apprv.setByName(by.getString(GerritChangeVO.JSON_KEY_NAME));

            if (by.containsKey(GerritChangeVO.JSON_KEY_EMAIL)) {
                apprv.setByEmail(by.getString(GerritChangeVO.JSON_KEY_EMAIL));
            }

            if (isCurrent) {
                if (apprv.getType().equals("VRIF") || apprv.getType().equals("Verified")) {
                    info.setVerificationScore(info.getVerificationScore() + apprv.getValue());
                } else if (apprv.getType().equals("CRVW")) {
                    info.setReviewScore(info.getReviewScore() + apprv.getValue());
                }
            }

            patch.getApprovals().add(apprv);
        }
    }

    if (p.containsKey(GerritChangeVO.JSON_KEY_PATCH_SET_FILES)) {
        List<JSONObject> fileSets = p.getJSONArray(GerritChangeVO.JSON_KEY_PATCH_SET_FILES);

        for (JSONObject f : fileSets) {
            FileSet fileSet = new FileSet();

            fileSet.setFile(f.getString(GerritChangeVO.JSON_KEY_PATCH_SET_FILES_FILE));
            fileSet.setType(f.getString(GerritChangeVO.JSON_KEY_PATCH_SET_FILES_TYPE));

            if (f.containsKey(GerritChangeVO.JSON_KEY_PATCH_SET_FILES_INSRT)) {
                fileSet.setInsertions(f.getInt(GerritChangeVO.JSON_KEY_PATCH_SET_FILES_INSRT));
            }

            if (f.containsKey(GerritChangeVO.JSON_KEY_PATCH_SET_FILES_DELT)) {
                fileSet.setDeletions(f.getInt(GerritChangeVO.JSON_KEY_PATCH_SET_FILES_DELT));
            }

            patch.getFileSets().add(fileSet);
        }
    }

    if (isCurrent) {
        info.setCurrentPatchSet(patch);
    } else {
        info.getPatchSets().add(patch);
    }

    log.debug(String.format("Patchset assigned: %s", patch.toString()));
}

From source file:org.egov.works.services.AbstractEstimateService.java

private void persistBudgetReleaseDetails(final AbstractEstimate abstractEstimate,
        final BudgetUsage budgetUsage) {
    AbstractEstimateAppropriation estimateAppropriation = null;
    estimateAppropriation = estimateAppropriationService.findByNamedQuery("getLatestBudgetUsageForEstimate",
            abstractEstimate.getId());//from  ww w.j  a  v a  2s  . c  o  m
    final Integer finYearId = estimateAppropriation.getBudgetUsage().getFinancialYearId();
    final Date endingDate = financialYearHibernateDAO.getFinancialYearById(finYearId.longValue())
            .getEndingDate();
    estimateAppropriation.setBalanceAvailable(getBudgetAvailable(abstractEstimate, endingDate));
    estimateAppropriation.setBudgetUsage(budgetUsage);
    estimateAppropriationService.persist(estimateAppropriation);
}

From source file:org.op4j.functions.FnShort.java

/**
 * <p>/* w w w.  j av a2  s .  c  o  m*/
 * It performs a module operation and returns the value
 * of (input mod module) which is always positive 
 * (whereas remainder is not)
 * </p>
 * 
 * @param module the module
 * @return the result of (input mod module)
 */
public final static Function<Short, Short> module(Integer module) {
    return new Module(BigInteger.valueOf(module.longValue()));
}

From source file:org.op4j.functions.FnInteger.java

/**
 * <p>/*from  ww w. j  a v a2 s . c om*/
 * It performs a module operation and returns the value
 * of (input mod module) which is always positive 
 * (whereas remainder is not)
 * </p>
 * 
 * @param module the module
 * @return the result of (input mod module)
 */
public final static Function<Integer, Integer> module(Integer module) {
    return new Module(BigInteger.valueOf(module.longValue()));
}

From source file:org.op4j.functions.FnLong.java

/**
 * <p>/*from   w  ww  .j  a v a2  s.c o  m*/
 * It performs a module operation and returns the value
 * of (input mod module) which is always positive 
 * (whereas remainder is not)
 * </p>
 * 
 * @param module the module
 * @return the result of (input mod module)
 */
public final static Function<Long, Long> module(Integer module) {
    return new Module(BigInteger.valueOf(module.longValue()));
}

From source file:com.fluidops.iwb.api.ProviderServiceImpl.java

@Override
public void saveProvider(URI provider, Integer intervalMs) throws RemoteException, Exception {
    // NOTE: when calling this method in fiwb we ignore the aggregateMask
    // and/* www. j a va 2s. com*/
    // aggregatePersistMask parameter, since no historic data is maintained
    // there
    // the method is reimplemented in fiwbcom->ProviderServiceWithHistory

    /* AbstractFlexProvider state = lookup(provider);
    if (state == null)
    state = new AbstractFlexProvider(); */

    // use the session's provider
    AbstractFlexProvider prov = sessionProvider;

    if (intervalMs != null)
        prov.pollInterval = intervalMs.longValue();

    putProvider(provider, prov);
}

From source file:org.cloudfoundry.identity.uaa.oauth.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  a v a 2 s. com*/

    if (!"refresh_token".equals(request.getRequestParameters().get("grant_type"))) {
        throw new InvalidGrantException(
                "Invalid grant type: " + request.getRequestParameters().get("grant_type"));
    }

    TokenValidation tokenValidation = validateToken(refreshTokenValue);
    Map<String, Object> claims = tokenValidation.getClaims();
    refreshTokenValue = tokenValidation.getJwt().getEncoded();

    @SuppressWarnings("unchecked")
    ArrayList<String> tokenScopes = (ArrayList<String>) claims.get(SCOPE);
    if (isRestrictRefreshGrant() && !tokenScopes.contains(UAA_REFRESH_TOKEN)) {
        throw new InsufficientScopeException(String.format("Expected scope %s is missing", UAA_REFRESH_TOKEN));
    }

    // 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);

    String refreshTokenId = (String) claims.get(JTI);
    String accessTokenId = generateUniqueTokenId();

    boolean opaque = TokenConstants.OPAQUE
            .equals(request.getRequestParameters().get(TokenConstants.REQUEST_TOKEN_FORMAT));
    boolean revocable = opaque || (claims.get(REVOCABLE) == null ? false : (Boolean) claims.get(REVOCABLE));

    // 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);
    ClientDetails client = clientDetailsService.loadClientByClientId(clientId);

    Integer refreshTokenIssuedAt = (Integer) claims.get(IAT);
    long refreshTokenIssueDate = refreshTokenIssuedAt.longValue() * 1000l;

    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));
    }

    // default request scopes to what is in the refresh token
    Set<String> requestedScopes = request.getScope();
    if (requestedScopes.isEmpty()) {
        requestedScopes = new HashSet<>(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<>(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
    String grantType = claims.get(GRANT_TYPE).toString();
    checkForApproval(userid, clientId, requestedScopes, getAutoApprovedScopes(grantType, tokenScopes, client));

    // if we have reached so far, issue an access token
    Integer validity = client.getAccessTokenValiditySeconds();

    String nonce = (String) claims.get(NONCE);

    @SuppressWarnings("unchecked")
    Map<String, String> additionalAuthorizationInfo = (Map<String, String>) claims.get(ADDITIONAL_AZ_ATTR);

    @SuppressWarnings("unchecked")
    Map<String, String> externalAttributes = (Map<String, String>) claims.get(EXTERNAL_ATTR);

    String revocableHashSignature = (String) claims.get(REVOCATION_SIGNATURE);
    if (hasText(revocableHashSignature)) {
        String clientSecretForHash = client.getClientSecret();
        if (clientSecretForHash != null && clientSecretForHash.split(" ").length > 1) {
            clientSecretForHash = clientSecretForHash.split(" ")[1];
        }
        String newRevocableHashSignature = UaaTokenUtils.getRevocableTokenSignature(client, clientSecretForHash,
                user);
        if (!revocableHashSignature.equals(newRevocableHashSignature)) {
            throw new TokenRevokedException(refreshTokenValue);
        }
    }

    Set<String> audience = new HashSet<>((ArrayList<String>) claims.get(AUD));

    int zoneAccessTokenValidity = getZoneAccessTokenValidity();

    CompositeAccessToken accessToken = createAccessToken(accessTokenId, user.getId(), user,
            (claims.get(AUTH_TIME) != null) ? new Date(((Long) claims.get(AUTH_TIME)) * 1000l) : null,
            validity != null ? validity.intValue() : zoneAccessTokenValidity, null, requestedScopes, clientId,
            audience /*request.createOAuth2Request(client).getResourceIds()*/, grantType, refreshTokenValue,
            nonce, additionalAuthorizationInfo, externalAttributes, new HashSet<>(), revocableHashSignature,
            false, null, //TODO populate response types
            null, revocable, null, null);

    DefaultExpiringOAuth2RefreshToken expiringRefreshToken = new DefaultExpiringOAuth2RefreshToken(
            refreshTokenValue, new Date(refreshTokenExpireDate));
    return persistRevocableToken(accessTokenId, refreshTokenId, accessToken, expiringRefreshToken, clientId,
            user.getId(), opaque, revocable);

}

From source file:com.redhat.rhn.frontend.xmlrpc.org.OrgHandler.java

/**
 * Delete an organization./*  ww w .  j  ava2  s . c  om*/
 *
 * @param loggedInUser The current user
 * @param orgId ID of organization to delete.
 * @return 1 on success, exception thrown otherwise.
 *
 * @xmlrpc.doc Delete an organization. The default organization
 * (i.e. orgId=1) cannot be deleted.
 * @xmlrpc.param #param("string", "sessionKey")
 * @xmlrpc.param #param("int", "orgId")
 * @xmlrpc.returntype #return_int_success()
 */
public int delete(User loggedInUser, Integer orgId) {
    ensureUserRole(loggedInUser, RoleFactory.SAT_ADMIN);
    Org org = verifyOrgExists(orgId);

    // Verify we're not trying to delete the default org (id 1):
    Org defaultOrg = OrgFactory.getSatelliteOrg();
    if (orgId.longValue() == defaultOrg.getId().longValue()) {
        throw new SatelliteOrgException();
    }

    OrgFactory.deleteOrg(org.getId(), loggedInUser);

    return 1;
}