Search in sources :

Example 1 with SearchPGPPublicKeysReturn

use of net.cryptonomica.returns.SearchPGPPublicKeysReturn in project cryptonomica by Cryptonomica.

the class PGPPublicKeyAPI method getMyKeys.

@ApiMethod(name = "getMyKeys", path = "getMyKeys", httpMethod = ApiMethod.HttpMethod.POST)
@SuppressWarnings("unused")
public // 4) by first and last names
SearchPGPPublicKeysReturn getMyKeys(// final HttpServletRequest httpServletRequest,
final User googleUser) throws Exception {
    // authorization
    UserTools.ensureCryptonomicaRegisteredUser(googleUser);
    // 
    Key<CryptonomicaUser> cryptonomicaUserKey = Key.create(CryptonomicaUser.class, googleUser.getUserId());
    List<PGPPublicKeyData> result = ofy().load().type(PGPPublicKeyData.class).ancestor(cryptonomicaUserKey).list();
    SearchPGPPublicKeysReturn searchPGPPublicKeysReturn;
    if (result.size() > 0) {
        searchPGPPublicKeysReturn = new SearchPGPPublicKeysReturn("this is list of your keys, if any:", new ArrayList<>(result));
    } else {
        searchPGPPublicKeysReturn = new SearchPGPPublicKeysReturn("You have no keys, yet.", new ArrayList<>(result));
    }
    return searchPGPPublicKeysReturn;
}
Also used : PGPPublicKeyData(net.cryptonomica.entities.PGPPublicKeyData) SearchPGPPublicKeysReturn(net.cryptonomica.returns.SearchPGPPublicKeysReturn) ArrayList(java.util.ArrayList) CryptonomicaUser(net.cryptonomica.entities.CryptonomicaUser) ApiMethod(com.google.api.server.spi.config.ApiMethod)

Example 2 with SearchPGPPublicKeysReturn

use of net.cryptonomica.returns.SearchPGPPublicKeysReturn in project cryptonomica by Cryptonomica.

the class PGPPublicKeyAPI method getUsersKeysByUserId.

@ApiMethod(name = "getUsersKeysByUserId", path = "getUsersKeysByUserId", httpMethod = ApiMethod.HttpMethod.POST)
@SuppressWarnings("unused")
public // get keys by user ID
SearchPGPPublicKeysReturn getUsersKeysByUserId(// final HttpServletRequest httpServletRequest,
final User googleUser, final GetUsersKeysByUserIdForm getUsersKeysByUserIdForm) throws Exception {
    // authorization
    UserTools.ensureCryptonomicaRegisteredUser(googleUser);
    // 
    SearchPGPPublicKeysReturn searchPGPPublicKeysReturn = new SearchPGPPublicKeysReturn("this are keys of user: " + getUsersKeysByUserIdForm.getUserId(), new ArrayList<>(ofy().load().type(PGPPublicKeyData.class).ancestor(Key.create(CryptonomicaUser.class, getUsersKeysByUserIdForm.getUserId())).list()));
    return searchPGPPublicKeysReturn;
}
Also used : SearchPGPPublicKeysReturn(net.cryptonomica.returns.SearchPGPPublicKeysReturn) ApiMethod(com.google.api.server.spi.config.ApiMethod)

Example 3 with SearchPGPPublicKeysReturn

use of net.cryptonomica.returns.SearchPGPPublicKeysReturn in project cryptonomica by Cryptonomica.

the class PGPPublicKeyAPI method searchPGPPublicKeys.

@ApiMethod(name = "searchPGPPublicKeys", path = "searchPGPPublicKeys", httpMethod = ApiMethod.HttpMethod.POST)
@SuppressWarnings("unused")
public // 4) by first and last names
SearchPGPPublicKeysReturn searchPGPPublicKeys(// final HttpServletRequest httpServletRequest,
final User googleUser, final SearchPGPPublicKeysForm searchPGPPublicKeysForm) throws Exception {
    // authorization
    UserTools.ensureCryptonomicaRegisteredUser(googleUser);
    // 
    String fingerprint = searchPGPPublicKeysForm.getFingerprint();
    String keyID = searchPGPPublicKeysForm.getKeyID();
    String userID = searchPGPPublicKeysForm.getUserID();
    String firstName = searchPGPPublicKeysForm.getFirstName();
    String lastName = searchPGPPublicKeysForm.getLastName();
    String cryptonomicaUserId = searchPGPPublicKeysForm.getCryptonomicaUserId();
    Email userEmail = null;
    if (searchPGPPublicKeysForm.getUserEmail() != null) {
        userEmail = new Email(searchPGPPublicKeysForm.getUserEmail());
    }
    List<? extends PGPPublicKeyData> result;
    if (fingerprint != null) {
        result = ofy().load().type(PGPPublicKeyData.class).filter("fingerprint", fingerprint).list();
    } else if (keyID != null) {
        result = ofy().load().type(PGPPublicKeyData.class).filter("keyID", keyID).list();
    } else if (userEmail != null) {
        result = ofy().load().type(PGPPublicKeyData.class).filter("userEmail", userEmail).list();
    } else if (firstName != null && lastName != null) {
        result = ofy().load().type(PGPPublicKeyData.class).filter("firstName", firstName).filter("lastName", lastName).list();
    } else if (cryptonomicaUserId != null) {
        result = ofy().load().type(PGPPublicKeyData.class).filter("cryptonomicaUserId", cryptonomicaUserId).list();
    } else {
        throw new Exception("invalid search query: " + new Gson().toJson(searchPGPPublicKeysForm));
    }
    SearchPGPPublicKeysReturn searchPGPPublicKeysReturn = new SearchPGPPublicKeysReturn();
    if (result.size() > 0) {
        searchPGPPublicKeysReturn.PublicKeyDatasToGeneralViews(new ArrayList<PGPPublicKeyData>(result));
        searchPGPPublicKeysReturn.setMessageToUser("search results:");
    } else {
        searchPGPPublicKeysReturn.PublicKeyDatasToGeneralViews(new ArrayList<PGPPublicKeyData>());
        searchPGPPublicKeysReturn.setMessageToUser("no records found");
    }
    return searchPGPPublicKeysReturn;
}
Also used : PGPPublicKeyData(net.cryptonomica.entities.PGPPublicKeyData) Email(com.google.appengine.api.datastore.Email) SearchPGPPublicKeysReturn(net.cryptonomica.returns.SearchPGPPublicKeysReturn) Gson(com.google.gson.Gson) ApiMethod(com.google.api.server.spi.config.ApiMethod)

Aggregations

ApiMethod (com.google.api.server.spi.config.ApiMethod)3 SearchPGPPublicKeysReturn (net.cryptonomica.returns.SearchPGPPublicKeysReturn)3 PGPPublicKeyData (net.cryptonomica.entities.PGPPublicKeyData)2 Email (com.google.appengine.api.datastore.Email)1 Gson (com.google.gson.Gson)1 ArrayList (java.util.ArrayList)1 CryptonomicaUser (net.cryptonomica.entities.CryptonomicaUser)1