Java 类com.google.appengine.api.datastore.PhoneNumber 实例源码

项目:internet-radio-gae    文件:CustomerManager.java   
/**
   * Update Customer attributes.
   * Update's the given customer's attributes in the datastore.
   * @param email
   *            : the email of the customer whose attributes will be updated
   * @param customerName
   *            : the new name to give to the customer
   * @param customerPhone
   *            : the new phone to give to the customer
   * @param customerGender
   *            : the new gender to give to the customer
   * @param customerAddress
   *            : the new address to give to the customer
   * @param customerComments
   *            : the new comments to give to the customer
* @throws MissingRequiredFieldsException 
* @throws InvalidFieldFormatException 
   */
public static void updateCustomerAttributes(Email email, String customerName, 
        PhoneNumber customerPhone, Customer.Gender customerGender, PostalAddress customerAddress,
        String customerComments) throws MissingRequiredFieldsException, InvalidFieldFormatException {   

    PersistenceManager pm = PMF.get().getPersistenceManager();

    Transaction tx = pm.currentTransaction();
    try {
        Key key = KeyFactory.createKey(Customer.class.getSimpleName(), email.getEmail());
        Customer customer = pm.getObjectById(Customer.class, key);
        tx.begin();
        customer.setCustomerName(customerName);
        customer.setCustomerPhone(customerPhone);
        customer.setCustomerGender(customerGender);
        customer.setCustomerAddress(customerAddress);
        customer.setCustomerComments(customerComments);
        tx.commit();
        log.info("Customer \"" + email.getEmail() + "\"'s attributes updated in datastore.");
    }
    finally {
        if (tx.isActive()) {
            tx.rollback();
        }
        pm.close();
    }
}
项目:internet-radio-gae    文件:Customer.java   
/**
 * Set Customer phone.
 * @param customerPhone
 *          : customer phone
 * @throws InvalidFieldFormatException 
 */
public void setCustomerPhone(PhoneNumber customerPhone) 
        throws MissingRequiredFieldsException, InvalidFieldFormatException {
    if (customerPhone == null || customerPhone.getNumber().trim().isEmpty()) {
        throw new MissingRequiredFieldsException(this.getClass(), 
    "Customer phone is missing.");
    }

    // Check phone number format
    if (!FieldValidator.isValidPhoneNumber(customerPhone.getNumber())) {
        throw new InvalidFieldFormatException(this.getClass(), "Invalid phone number.");
    }

    this.customerPhone = customerPhone;
}
项目:appengine-tck    文件:StringDataTest.java   
@Test
public void testPhoneNumType() {
    String propertyName = "phoneProp";
    List<Entity> elist = doQuery(kindName, propertyName, PhoneNumber.class, true);
    PhoneNumber phonenum = (PhoneNumber) elist.get(0).getProperty(propertyName);
    PhoneNumber sameDat = (PhoneNumber) elist.get(0).getProperty(propertyName);
    PhoneNumber diffDat = (PhoneNumber) elist.get(1).getProperty(propertyName);
    assertTrue(phonenum.equals(sameDat));
    assertFalse(phonenum.equals(diffDat));
    assertEquals("408-123-4567", phonenum.getNumber());
    assertEquals(0, phonenum.compareTo(sameDat));
    assertTrue(phonenum.compareTo(diffDat) != 0);
    assertEquals(phonenum.hashCode(), phonenum.hashCode());
}
项目:appengine-tck    文件:QueryTest.java   
@Before
public void createData() throws InterruptedException {
    clearData(kindName);

    List<Entity> elist = new ArrayList<>();
    for (int i = 0; i < count; i++) {
        Entity newRec = new Entity(kindName, rootKey);
        newRec.setProperty("stringData", "string data" + i);
        newRec.setProperty("timestamp", new Date());
        newRec.setProperty("shortBlobData", new ShortBlob(("shortBlobData" + i).getBytes()));
        newRec.setProperty("intData", 20 * i);
        newRec.setProperty("textData", new Text("textData" + i));
        newRec.setProperty("floatData", 1234 + 0.1 * i);
        newRec.setProperty("booleanData", true);
        newRec.setProperty("urlData", new Link("http://www.google.com"));
        newRec.setProperty("emailData", new Email("somebody123" + i + "@google.com"));
        newRec.setProperty("phoneData", new PhoneNumber("408-123-000" + i));
        newRec.setProperty("adressData", new PostalAddress("123 st. CA 12345" + i));
        newRec.setProperty("ratingData", new Rating(10 * i));
        newRec.setProperty("geoptData", new GeoPt((float) (i + 0.12), (float) (i + 0.98)));
        newRec.setProperty("categoryData", new Category("category" + i));
        newRec.setProperty("intList", Arrays.asList(i, 50 + i, 90 + i));
        elist.add(newRec);
    }
    service.put(elist);

    sync(1000);
}
项目:internet-radio-gae    文件:Customer.java   
/**
 * Customer constructor.
 * @param user
 *          : user for this customer
 * @param customerName
 *          : customer name
 * @param customerPhone
 *          : customer phone
 * @param customerGender
 *          : customer gender
 * @param customerAddress
 *          : customer address
 * @param customerComments
 *          : customer comments
 * @throws MissingRequiredFieldsException
 * @throws InvalidFieldFormatException
 */
public Customer(User user, String customerName, 
                PhoneNumber customerPhone, Gender customerGender,
                PostalAddress customerAddress, String customerComments) 
        throws MissingRequiredFieldsException, InvalidFieldFormatException {

    // Check "required field" constraints
    if (user == null || customerName == null || customerPhone == null || customerGender == null ||
            customerAddress == null) {
        throw new MissingRequiredFieldsException(this.getClass(), "One or more required fields are missing.");
    }
    if (customerName.trim().isEmpty() || customerPhone.getNumber().trim().isEmpty() || 
            customerAddress.getAddress().trim().isEmpty()) {
        throw new MissingRequiredFieldsException(this.getClass(), "One or more required fields are missing.");
    }

    // Check phone number format
    if (!FieldValidator.isValidPhoneNumber(customerPhone.getNumber())) {
        throw new InvalidFieldFormatException(this.getClass(), "Invalid phone number.");
    }

    this.user = user;

    // Create key with user email
    this.key = KeyFactory.createKey(Customer.class.getSimpleName(), user.getUserEmail().getEmail());

    this.customerName = customerName;
    this.customerPhone = customerPhone;

    this.gender = customerGender;
    switch(customerGender) {
        case MALE:
            this.customerGender = "male";
            break;
        case FEMALE:
            this.customerGender = "female";
            break;
    }

    this.customerAddress = customerAddress;
    this.status = Status.UNCONFIRMED;
    this.customerStatus = "unconfirmed";
    this.customerComments = customerComments;

    this.ownedUserGroups = new ArrayList<UserGroup>();
    this.followedUserGroups = new ArrayList<Key>();
    this.userRecommendations = new ArrayList<UserRecommendation>();
}
项目:appengine-tck    文件:OrderingTest.java   
@Before
public void setUp() {
    super.setUp();

    values = asList(
        asSet((Object) null),
        asSet((short) -10, -10, -10L),
        asSet((short) 10, 10, 10L, new Rating(10)),
        asSet((short) 20, 20, 20L, new Rating(20)),
        asSet(createDate(2013, 1, 1)),
        asSet(createDate(2013, 5, 5)),
        asSet(1381363199999999L),   // 1 microsecond before 2013-10-10
        asSet(new Date(1381363200000L), 1381363200000000L), // 2013-10-10
        asSet(1381363200000001L),   // 1 microsecond after 2013-10-10
        asSet(false),
        asSet(true),
        asSet(
            "sip sip",
            new ShortBlob("sip sip".getBytes()),
            new PostalAddress("sip sip"),
            new PhoneNumber("sip sip"),
            new Email("sip sip"),
            new IMHandle(IMHandle.Scheme.sip, "sip"),   // this is stored as "sip sip"
            new Link("sip sip"),
            new Category("sip sip"),
            new BlobKey("sip sip")
        ),
        asSet(
            "xmpp xmpp",
            new ShortBlob("xmpp xmpp".getBytes()),
            new PostalAddress("xmpp xmpp"),
            new PhoneNumber("xmpp xmpp"),
            new Email("xmpp xmpp"),
            new IMHandle(IMHandle.Scheme.xmpp, "xmpp"), // this is stored as "xmpp xmpp"
            new Link("xmpp xmpp"),
            new Category("xmpp xmpp"),
            new BlobKey("xmpp xmpp")
        ),
        asSet(-10f, -10d),
        asSet(10f, 10d),
        asSet(20f, 20d),
        asSet(new GeoPt(10f, 10f)),
        asSet(new GeoPt(20f, 20f)),
        asSet(new User("aaa", "aaa"), new User("aaa", "otherAuthDomain")),  // ordering must depend only on the email
        asSet(new User("bbb", "bbb")),
        asSet(KeyFactory.createKey("kind", "aaa")),
        asSet(KeyFactory.createKey("kind", "bbb"))
    );

    entities = new ArrayList<Set<Entity>>();
    for (Set<?> values2 : values) {
        Set<Entity> entities2 = new HashSet<Entity>();
        entities.add(entities2);
        for (Object value : values2) {
            entities2.add(storeTestEntityWithSingleProperty(value));
        }
    }
}
项目:appengine-tck    文件:QueryFilteringByGAEPropertyTypesTest.java   
@Test
public void testPhoneNumberProperty() {
    testEqualityQueries(new PhoneNumber("foo"), new PhoneNumber("bar"));
    testInequalityQueries(new PhoneNumber("111"), new PhoneNumber("222"), new PhoneNumber("333"));
}
项目:internet-radio-gae    文件:CustomerSimple.java   
/**
 * CustomerSimple constructor.
 * @param key
 *          : restaurant key
 * @param customerName
 *          : customer name
 * @param customerPhone
 *          : customer phone
 * @param customerGender
 *          : customer gender
 * @param customerAddress
 *          : customer address
 */
public CustomerSimple(String key, String customerName, 
        PhoneNumber customerPhone, String customerGender,
        PostalAddress customerAddress) {

    this.key = key;
    this.customerName = customerName;
    this.customerPhone = customerPhone;
    this.customerGender = customerGender;
    this.customerAddress = customerAddress;
}
项目:internet-radio-gae    文件:Customer.java   
/**
 * Get Customer phone.
 * @return customer phone
 */
public PhoneNumber getCustomerPhone() {
    return customerPhone;
}