<commit_before>/*
 * Copyright 2015 Aroma Tech.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package tech.aroma.banana.authentication.service.operations;

import javax.inject.Inject;
import org.apache.thrift.TException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import tech.aroma.banana.authentication.service.data.Token;
import tech.aroma.banana.authentication.service.data.TokenRepository;
import tech.aroma.banana.thrift.authentication.service.GetApplicationTokenInfoRequest;
import tech.aroma.banana.thrift.authentication.service.GetApplicationTokenInfoResponse;
import tech.aroma.banana.thrift.exceptions.InvalidArgumentException;
import tech.aroma.banana.thrift.exceptions.OperationFailedException;
import tech.sirwellington.alchemy.annotations.access.Internal;
import tech.sirwellington.alchemy.thrift.operations.ThriftOperation;

import static tech.aroma.banana.authentication.service.AuthenticationAssertions.checkRequestNotNull;
import static tech.sirwellington.alchemy.arguments.Arguments.checkThat;
import static tech.sirwellington.alchemy.arguments.assertions.Assertions.notNull;
import static tech.sirwellington.alchemy.arguments.assertions.StringAssertions.nonEmptyString;

/**
 *
 * @author SirWellington
 */
@Internal
final class GetApplicationTokenInfoOperation implements ThriftOperation<GetApplicationTokenInfoRequest, GetApplicationTokenInfoResponse>
{

    private final static Logger LOG = LoggerFactory.getLogger(GetApplicationTokenInfoOperation.class);

    private final TokenRepository tokenRepository;

    @Inject
    GetApplicationTokenInfoOperation(TokenRepository tokenRepository)
    {
        checkThat(tokenRepository).is(notNull());
        
        this.tokenRepository = tokenRepository;
    }

    @Override
    public GetApplicationTokenInfoResponse process(GetApplicationTokenInfoRequest request) throws TException
    {
        LOG.debug("Received request to get token info: {}", request);

        checkRequestNotNull(request);
        
        String tokenId = request.tokenId;
        
        checkThat(tokenId)
            .throwing(ex -> new InvalidArgumentException("tokenId and applicationid are required"))
            .is(nonEmptyString());
        
        Token token = tryGetToken(tokenId);
        
        
        
        return new GetApplicationTokenInfoResponse()
            .setToken(token.asApplicationToken())
            ;
    }

    @Override
    public String toString()
    {
        return "GetApplicationTokenInfoOperation{" + "tokenRepository=" + tokenRepository + '}';
    }

    private Token tryGetToken(String tokenId) throws TException
    {
        Token token;
        
        try
        {
            token = tokenRepository.getToken(tokenId);
        }
        catch (TException ex)
        {
            throw ex;
        }
        catch (Exception ex)
        {
            throw new OperationFailedException("Failed to load token from repository" + ex.getMessage());
        }
        
        checkThat(token)
            .throwing(OperationFailedException.class)
            .is(notNull());
        
        return token;
    }
    

}
<commit_msg>GetApplicationTokenInfoOperation Updates<commit_after>/*
 * Copyright 2015 Aroma Tech.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package tech.aroma.banana.authentication.service.operations;

import javax.inject.Inject;
import org.apache.thrift.TException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import tech.aroma.banana.authentication.service.data.Token;
import tech.aroma.banana.authentication.service.data.TokenRepository;
import tech.aroma.banana.thrift.authentication.service.GetApplicationTokenInfoRequest;
import tech.aroma.banana.thrift.authentication.service.GetApplicationTokenInfoResponse;
import tech.aroma.banana.thrift.exceptions.InvalidArgumentException;
import tech.aroma.banana.thrift.exceptions.OperationFailedException;
import tech.sirwellington.alchemy.annotations.access.Internal;
import tech.sirwellington.alchemy.thrift.operations.ThriftOperation;

import static tech.aroma.banana.authentication.service.AuthenticationAssertions.checkRequestNotNull;
import static tech.sirwellington.alchemy.arguments.Arguments.checkThat;
import static tech.sirwellington.alchemy.arguments.assertions.Assertions.notNull;
import static tech.sirwellington.alchemy.arguments.assertions.StringAssertions.nonEmptyString;

/**
 *
 * @author SirWellington
 */
@Internal
final class GetApplicationTokenInfoOperation implements ThriftOperation<GetApplicationTokenInfoRequest, GetApplicationTokenInfoResponse>
{

    private final static Logger LOG = LoggerFactory.getLogger(GetApplicationTokenInfoOperation.class);

    private final TokenRepository tokenRepository;

    @Inject
    GetApplicationTokenInfoOperation(TokenRepository tokenRepository)
    {
        checkThat(tokenRepository).is(notNull());

        this.tokenRepository = tokenRepository;
    }

    @Override
    public GetApplicationTokenInfoResponse process(GetApplicationTokenInfoRequest request) throws TException
    {
        LOG.debug("Received request to get token info: {}", request);

        checkRequestNotNull(request);

        String tokenId = request.tokenId;

        checkThat(tokenId)
            .throwing(ex -> new InvalidArgumentException("tokenId and applicationid are required"))
            .is(nonEmptyString());

        Token token = tryGetToken(tokenId);

        return new GetApplicationTokenInfoResponse()
            .setToken(token.asApplicationToken());
    }

    private Token tryGetToken(String tokenId) throws TException
    {
        Token token;

        try
        {
            token = tokenRepository.getToken(tokenId);
        }
        catch (TException ex)
        {
            throw ex;
        }
        catch (Exception ex)
        {
            throw new OperationFailedException("Failed to load token from repository" + ex.getMessage());
        }

        checkThat(token)
            .throwing(OperationFailedException.class)
            .is(notNull());

        return token;
    }

    @Override
    public String toString()
    {
        return "GetApplicationTokenInfoOperation{" + "tokenRepository=" + tokenRepository + '}';
    }

}

{'fraction_non_alphanumeric': 0.0803411748521117, 'fraction_numerical': 0.0027514100976750583, 'mean_word_length': 3.509925558312655, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5457315', 'n_tokens_mistral': 1886, 'n_tokens_neox': 1847, 'n_words': 443}