use of net.cryptonomica.entities.Arbitrator in project cryptonomica by Cryptonomica.
the class ArbitratorsAPI method showAllArbitrators.
@ApiMethod(name = "showAllArbitrators", path = "showAllArbitrators", httpMethod = ApiMethod.HttpMethod.POST)
@SuppressWarnings("unused")
public ArrayList<ArbitratorGeneralView> showAllArbitrators(final User googleUser) throws Exception {
/* --- Ensure authorization: */
UserTools.ensureCryptonomicaRegisteredUser(googleUser);
/* --- Load list of all arbitrators: */
List<Arbitrator> arbitratorsList = ofy().load().type(Arbitrator.class).list();
/* --- Create an empty list to store arbitrators data */
ArrayList<ArbitratorGeneralView> arbitratorGeneralViewArrayList = new ArrayList<>();
/* --- fill the arbitratorGeneralViewArrayList */
if (arbitratorsList != null) {
for (Arbitrator arbitrator : arbitratorsList) {
// load CryptonomicaUser data for notary:
CryptonomicaUser arbitratorCryptonomicaUser = ofy().load().key(Key.create(CryptonomicaUser.class, arbitrator.getId())).now();
// make ArbitratorGeneralView:
ArbitratorGeneralView arbitratorGeneralView = new ArbitratorGeneralView(arbitratorCryptonomicaUser, arbitrator);
// add to ArrayList:
arbitratorGeneralViewArrayList.add(arbitratorGeneralView);
}
}
// end: if loop
LOG.warning("arbitratorGeneralViewArrayList: " + new Gson().toJson(arbitratorGeneralViewArrayList));
return arbitratorGeneralViewArrayList;
}
use of net.cryptonomica.entities.Arbitrator in project cryptonomica by Cryptonomica.
the class ArbitratorsAPI method addArbitrator.
@ApiMethod(name = "addArbitrator", path = "addArbitrator", httpMethod = ApiMethod.HttpMethod.POST)
@SuppressWarnings("unused")
public ArbitratorGeneralView addArbitrator(final User googleUser, final AddArbitratorForm addArbitratorForm) throws Exception {
/* --- Ensure cryptonomica officer: */
UserTools.ensureCryptonomicaOfficer(googleUser);
/* --- Check form: */
if (addArbitratorForm.getId() == null) {
throw new IllegalArgumentException("User ID is missing");
}
// create arbitrator from form:
Arbitrator arbitrator = new Arbitrator(addArbitratorForm);
// save arbitrator in DS:
Key<Arbitrator> arbitratorKey = ofy().save().entity(arbitrator).now();
// add info to CryptonomicaUser
CryptonomicaUser arbitratorCryptonomicaUser = ofy().load().key(Key.create(CryptonomicaUser.class, arbitrator.getId())).now();
arbitratorCryptonomicaUser.setArbitrator(Boolean.TRUE);
ofy().save().entity(arbitratorCryptonomicaUser).now();
// create ArbitratorGeneralView
ArbitratorGeneralView arbitratorGeneralView = new ArbitratorGeneralView(arbitratorCryptonomicaUser, arbitrator);
LOG.warning("new arbitrator created: " + new Gson().toJson(arbitratorGeneralView));
return arbitratorGeneralView;
}
Aggregations