Search in sources :

Example 1 with ArbitratorGeneralView

use of net.cryptonomica.returns.ArbitratorGeneralView 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;
}
Also used : ArrayList(java.util.ArrayList) Gson(com.google.gson.Gson) Arbitrator(net.cryptonomica.entities.Arbitrator) CryptonomicaUser(net.cryptonomica.entities.CryptonomicaUser) ArbitratorGeneralView(net.cryptonomica.returns.ArbitratorGeneralView) ApiMethod(com.google.api.server.spi.config.ApiMethod)

Example 2 with ArbitratorGeneralView

use of net.cryptonomica.returns.ArbitratorGeneralView 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;
}
Also used : Gson(com.google.gson.Gson) Arbitrator(net.cryptonomica.entities.Arbitrator) CryptonomicaUser(net.cryptonomica.entities.CryptonomicaUser) ArbitratorGeneralView(net.cryptonomica.returns.ArbitratorGeneralView) ApiMethod(com.google.api.server.spi.config.ApiMethod)

Aggregations

ApiMethod (com.google.api.server.spi.config.ApiMethod)2 Gson (com.google.gson.Gson)2 Arbitrator (net.cryptonomica.entities.Arbitrator)2 CryptonomicaUser (net.cryptonomica.entities.CryptonomicaUser)2 ArbitratorGeneralView (net.cryptonomica.returns.ArbitratorGeneralView)2 ArrayList (java.util.ArrayList)1