/** @author Sławomir Pawluk <*****@*****.**> */
public class CreateNotificationEmailsSample {

  public static final APIClient CLIENT = Common.createApiClient();

  public static void main(String[] args) {
    try {
      // Get authenticated user
      APIUser me = CLIENT.me();

      // Clean notification emails, if exist
      for (APINotificationEmail notificationEmail :
          me.getNotificationEmails().getEntity().getData()) {
        System.out.println(
            String.format("Deleting notification email %s", notificationEmail.getEmail()));
        notificationEmail.delete();
      }

      System.out.println("Now add some notification emails");
      // Create notification email, for specified email, notified always
      me.createNotificationEmail("email@localhost", APINotificationEmail.Type.ALWAYS);

      // Create notification email, for specified email, notified on test run failures
      me.createNotificationEmail("different.email@localhost", APINotificationEmail.Type.ON_FAILURE);

      // Then you can get list of created notification emails
      APIList<APINotificationEmail> notificationEmailsList = me.getNotificationEmails().getEntity();

      System.out.println("Notification emails are:");
      for (APINotificationEmail notificationEmail : notificationEmailsList.getData()) {
        System.out.println(
            String.format(
                "%s, type: %s", notificationEmail.getEmail(), notificationEmail.getType()));
      }

      // You can create notification email for project only
      APIProject project = me.createProject(APIProject.Type.ANDROID);

      project.createNotificationEmail("user@localhost", APINotificationEmail.Type.ON_FAILURE);

      // And get it
      for (APINotificationEmail notificationEmail :
          project.getNotificationEmails().getEntity().getData()) {
        System.out.println(
            String.format(
                "%s, type: %s", notificationEmail.getEmail(), notificationEmail.getType()));
      }

    } catch (APIException apie) {
      System.err.println(apie.getMessage());
    }
  }
}
/** @author Sławomir */
public class UserOperationsSample {

  public static final APIClient CLIENT = Common.createApiClient();

  public static void main(String[] args) {
    try {
      // Get authenticated user
      APIUser me = CLIENT.me();

      // List available data
      printUser(me);

      // Updating user data
      me.setAddress("Address");
      me.setCity("City");
      me.setCode("1234567890");
      me.setCountry("Finland");
      me.setEmail("admin@localhost");
      me.setName("My name is ...");
      me.setOrganization("BitBar");
      me.setPhone("0987654321");
      me.setState("Some state");
      me.setVatID("FR1234890");

      me.update();

      // List data again
      printUser(me);
    } catch (APIException apie) {
      System.err.println(apie.getMessage());
    }
  }

  private static void printUser(APIUser user) {
    System.out.println(String.format("Address: %s", user.getAddress()));
    System.out.println(String.format("City: %s", user.getCity()));
    System.out.println(String.format("Code: %s", user.getCode()));
    System.out.println(String.format("Country: %s", user.getCountry()));
    System.out.println(String.format("Emial: %s", user.getEmail()));
    System.out.println(String.format("Name: %s", user.getName()));
    System.out.println(String.format("Organization: %s", user.getOrganization()));
    System.out.println(String.format("Phone: %s", user.getPhone()));
    System.out.println(String.format("State: %s", user.getState()));
    System.out.println(String.format("Time zone: %s", user.getTimeZone()));
    System.out.println(String.format("Vat ID: %s", user.getVatID()));
  }
}