Search in sources :

Example 6 with NotFoundException

use of com.google.api.server.spi.response.NotFoundException in project cryptonomica by Cryptonomica.

the class StripePaymentsAPI method checkPaymentVerificationCode.

// end of processStripePayment
@ApiMethod(name = "checkPaymentVerificationCode", path = "checkPaymentVerificationCode", httpMethod = ApiMethod.HttpMethod.POST)
@SuppressWarnings("unused")
public StringWrapperObject checkPaymentVerificationCode(final HttpServletRequest httpServletRequest, final User googleUser, @Named("fingerprint") final String fingerprint, @Named("paymentVerificationCode") final String paymentVerificationCode) throws Exception {
    /* --- Ensure cryptonomica registered user */
    final CryptonomicaUser cryptonomicaUser = UserTools.ensureCryptonomicaRegisteredUser(googleUser);
    /* record login: */
    Login login = UserTools.registerLogin(httpServletRequest, googleUser);
    /* --- Check form: */
    LOG.warning("paymentVerificationCode from user: " + paymentVerificationCode);
    /* --- create return object */
    StringWrapperObject result = new StringWrapperObject();
    /* --- get OpenPGP key data */
    PGPPublicKeyData pgpPublicKeyData = null;
    pgpPublicKeyData = ofy().load().type(PGPPublicKeyData.class).filter("fingerprintStr", fingerprint).first().now();
    // 
    if (pgpPublicKeyData == null) {
        throw new Exception("OpenPGP public key certificate not found in our database for " + fingerprint);
    }
    // 
    if (!pgpPublicKeyData.getUserEmail().getEmail().equalsIgnoreCase(cryptonomicaUser.getEmail().getEmail())) {
        throw new Exception("Google Account email and email in key certificate does not much");
    }
    // first check for null:
    if (pgpPublicKeyData.getPaid() != null && pgpPublicKeyData.getPaid()) {
        throw new Exception("Verification of key " + fingerprint + " already paid");
    }
    // 
    StripePaymentForKeyVerification stripePaymentForKeyVerification = null;
    List<StripePaymentForKeyVerification> paymentForKeyVerificationList = ofy().load().type(StripePaymentForKeyVerification.class).filter("fingerprint", fingerprint).list();
    if (paymentForKeyVerificationList == null || paymentForKeyVerificationList.size() < 1) {
        throw new Exception("No payments for verification of the key " + fingerprint + "found");
    } else if (paymentForKeyVerificationList.size() > 1) {
        throw new Exception("Multiple payments exist for the key: " + fingerprint + ", please write to support@cryptonomica.net");
    } else {
        stripePaymentForKeyVerification = paymentForKeyVerificationList.get(0);
    }
    OnlineVerification onlineVerification = ofy().load().key(Key.create(OnlineVerification.class, fingerprint)).now();
    if (onlineVerification == null) {
        throw new NotFoundException("OnlineVerification record not found in data base");
    }
    if (stripePaymentForKeyVerification.getPaymentVerificationCode().equalsIgnoreCase(paymentVerificationCode)) {
        stripePaymentForKeyVerification.setVerified(true);
        Key<CryptonomicaUser> cryptonomicaUserKey = Key.create(CryptonomicaUser.class, googleUser.getUserId());
        Key<Login> loginKey = Key.create(cryptonomicaUserKey, Login.class, login.getId());
        stripePaymentForKeyVerification.setCheckPaymentVerificationCodeLogin(loginKey);
        // async
        ofy().save().entity(stripePaymentForKeyVerification);
        // add data to PGP Public Key and save:
        pgpPublicKeyData.setPaid(true);
        ofy().save().entity(pgpPublicKeyData).now();
        // add data to OnlineVerification and save:
        // onlineVerification.setPaimentVerified(Boolean.TRUE);
        onlineVerification.setPaymentVerified(Boolean.TRUE);
        // <<<<<<<<<< set as ready to manual review
        onlineVerification.setOnlineVerificationFinished(Boolean.TRUE);
        // async
        ofy().save().entity(onlineVerification);
        result.setMessage("Code verified!");
    } else {
        stripePaymentForKeyVerification.setFailedVerificationAttemps(stripePaymentForKeyVerification.getFailedVerificationAttemps() + 1);
        if (stripePaymentForKeyVerification.getFailedVerificationAttemps() >= 5) {
            throw new Exception("The number of attempts is exhausted. Please, write to support@cryptonomica.net");
        } else {
            throw new Exception("Code does not much. It was attempt # " + stripePaymentForKeyVerification.getFailedVerificationAttemps());
        }
    }
    // On this step user completed entering verification data, send email to compliance:
    ArrayList<VerificationDocument> verificationDocumentArrayList = new ArrayList<>();
    int verificationDocumentsListSize = ofy().load().type(VerificationDocument.class).filter("fingerprint", fingerprint).filter("hidden", false).list().size();
    LOG.warning("verificationDocumentsListSize: " + verificationDocumentsListSize);
    if (verificationDocumentsListSize > 0) {
        List<VerificationDocument> verificationDocumentList = ofy().load().type(VerificationDocument.class).filter("fingerprint", fingerprint).filter("hidden", false).list();
        verificationDocumentArrayList.addAll(verificationDocumentList);
        LOG.warning(GSON.toJson(verificationDocumentArrayList));
    }
    OnlineVerificationView onlineVerificationView = new OnlineVerificationView(onlineVerification, verificationDocumentArrayList);
    Gson prettyGson = new GsonBuilder().setPrettyPrinting().create();
    final Queue queue = QueueFactory.getDefaultQueue();
    queue.add(TaskOptions.Builder.withUrl("/_ah/SendGridServlet").param("email", "verification@cryptonomica.net").param("messageSubject", "[verification] Request for online verification").param("messageText", "New request for online verification received: \n\n" + "see entered data on:\n" + "https://cryptonomica.net/#/onlineVerificationView/" + fingerprint + "\n\n" + "verification request data in JSON format: \n\n" + prettyGson.toJson(onlineVerificationView)));
    return result;
}
Also used : GsonBuilder(com.google.gson.GsonBuilder) NotFoundException(com.google.api.server.spi.response.NotFoundException) Gson(com.google.gson.Gson) NotFoundException(com.google.api.server.spi.response.NotFoundException) Queue(com.google.appengine.api.taskqueue.Queue) ApiMethod(com.google.api.server.spi.config.ApiMethod)

Example 7 with NotFoundException

use of com.google.api.server.spi.response.NotFoundException in project cryptonomica by Cryptonomica.

the class VerificationAPI method getVerificationByWebSafeString.

// end: getVerificationByID
/* --- Get verification info by web-safe key string: */
@ApiMethod(name = "getVerificationByWebSafeString", path = "getVerificationByWebSafeString", httpMethod = ApiMethod.HttpMethod.GET)
@SuppressWarnings("unused")
public VerificationGeneralView getVerificationByWebSafeString(final HttpServletRequest httpServletRequest, final User googleUser, @Named("verificationWebSafeString") final String verificationWebSafeString) throws // see: https://cloud.google.com/appengine/docs/java/endpoints/exceptions
UnauthorizedException, BadRequestException, NotFoundException {
    /* --- Check authorization: */
    CryptonomicaUser cryptonomicaUser = UserTools.ensureCryptonomicaRegisteredUser(googleUser);
    /* --- Check input: */
    if (verificationWebSafeString == null || verificationWebSafeString.equals("")) {
        throw new BadRequestException("Verification ID missing");
    }
    /* --- Load verification entity from DS: */
    Key<Verification> verificationKey = Key.create(verificationWebSafeString);
    Verification verification = ofy().load().key(verificationKey).now();
    if (verification == null) {
        throw new NotFoundException("Verification info not found");
    }
    /* --- Create new verification info representation: */
    VerificationGeneralView verificationGeneralView = new VerificationGeneralView(verification);
    LOG.warning(new Gson().toJson(verificationGeneralView));
    return verificationGeneralView;
}
Also used : BadRequestException(com.google.api.server.spi.response.BadRequestException) NotFoundException(com.google.api.server.spi.response.NotFoundException) Gson(com.google.gson.Gson) Verification(net.cryptonomica.entities.Verification) VerificationGeneralView(net.cryptonomica.returns.VerificationGeneralView) CryptonomicaUser(net.cryptonomica.entities.CryptonomicaUser) ApiMethod(com.google.api.server.spi.config.ApiMethod)

Example 8 with NotFoundException

use of com.google.api.server.spi.response.NotFoundException in project iosched by google.

the class FcmSendEndpoint method sendUserSync.

/**
 * Ping a user's devices to sync user data. This is likely called when the server makes
 * a change to user data and wants the corresponding user's clients to sync.
 *
 * @param context Servlet context (injected by Endpoints)
 * @param user User making the request (injected by Endpoints)
 * @param userId ID of the user whose devices should sync.
 * @return SendUserSyncResult which contains the number of devices pinged.
 */
@ApiMethod(name = "sendUserSync", path = "users/{userId}", clientIds = { Ids.SERVICE_ACCOUNT_ANONOMYOUS_CLIENT_ID })
public SendUserSyncResult sendUserSync(ServletContext context, User user, @Named("userId") String userId) throws UnauthorizedException, NotFoundException {
    validateServiceAccount(user);
    MessageSender sender = new MessageSender(context);
    List<Device> devices = DeviceStore.findDevicesByUserId(userId);
    if (devices.isEmpty()) {
        throw new NotFoundException("No devices for user found");
    }
    sender.multicastSend(devices, ACTION_SYNC_USER, null);
    return new SendUserSyncResult(devices.size());
}
Also used : MessageSender(com.google.samples.apps.iosched.server.gcm.device.MessageSender) Device(com.google.samples.apps.iosched.server.gcm.db.models.Device) NotFoundException(com.google.api.server.spi.response.NotFoundException) ApiMethod(com.google.api.server.spi.config.ApiMethod)

Example 9 with NotFoundException

use of com.google.api.server.spi.response.NotFoundException in project endpoints-java by cloudendpoints.

the class LocalDiscoveryProvider method getRestDocument.

@Override
public RestDescription getRestDocument(String root, String name, String version) throws NotFoundException {
    ensureDiscoveryResult();
    RestDescription doc = discoveryDocs.get(new ApiKey(name, version, null));
    if (doc == null) {
        throw new NotFoundException("Not Found");
    }
    return replaceRoot(doc, root);
}
Also used : ApiKey(com.google.api.server.spi.config.model.ApiKey) NotFoundException(com.google.api.server.spi.response.NotFoundException) RestDescription(com.google.api.services.discovery.model.RestDescription)

Example 10 with NotFoundException

use of com.google.api.server.spi.response.NotFoundException in project endpoints-java by cloudendpoints.

the class AbstractDiscoveryProvider method getApiConfigs.

ImmutableList<ApiConfig> getApiConfigs(String name, String version) throws NotFoundException {
    ApiKey key = new ApiKey(name, version, null);
    ImmutableList<ApiConfig> configs = configsByKey.get(key);
    if (configs.isEmpty()) {
        logger.atInfo().log("No configuration found for name: %s, version: %s", name, version);
        throw new NotFoundException("Not Found");
    }
    return configs;
}
Also used : ApiKey(com.google.api.server.spi.config.model.ApiKey) NotFoundException(com.google.api.server.spi.response.NotFoundException) ApiConfig(com.google.api.server.spi.config.model.ApiConfig)

Aggregations

NotFoundException (com.google.api.server.spi.response.NotFoundException)13 ApiMethod (com.google.api.server.spi.config.ApiMethod)7 BadRequestException (com.google.api.server.spi.response.BadRequestException)5 Test (org.junit.Test)4 Gson (com.google.gson.Gson)3 ApiKey (com.google.api.server.spi.config.model.ApiKey)2 Queue (com.google.appengine.api.taskqueue.Queue)2 CryptonomicaUser (net.cryptonomica.entities.CryptonomicaUser)2 Verification (net.cryptonomica.entities.Verification)2 VerificationGeneralView (net.cryptonomica.returns.VerificationGeneralView)2 ApiConfig (com.google.api.server.spi.config.model.ApiConfig)1 UnauthorizedException (com.google.api.server.spi.response.UnauthorizedException)1 RestDescription (com.google.api.services.discovery.model.RestDescription)1 GsonBuilder (com.google.gson.GsonBuilder)1 Device (com.google.samples.apps.iosched.server.gcm.db.models.Device)1 MessageSender (com.google.samples.apps.iosched.server.gcm.device.MessageSender)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 BooleanWrapperObject (net.cryptonomica.returns.BooleanWrapperObject)1 OnlineVerificationView (net.cryptonomica.returns.OnlineVerificationView)1