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