use of com.codename1.rad.models.Property.Name in project CodeRAD by shannah.
the class ResultParserTest method simpleJSONTest.
private void simpleJSONTest() throws Exception {
EntityType personType = new EntityTypeBuilder().string(Person.name).string(Person.email).Date(Person.birthDate).build();
ResultParser parser = new ResultParser(personType).property("name", Person.name).property("email", Person.email).property("dob", Person.birthDate, dateStr -> {
if (!(dateStr instanceof String)) {
return null;
}
String str = (String) dateStr;
if (str.isEmpty()) {
return null;
}
SimpleDateFormat fmt = new SimpleDateFormat("MMM d, yyyy");
try {
return fmt.parse(str);
} catch (ParseException ex) {
Log.e(ex);
return null;
}
});
String json = "{\"name\":\"Paul\", \"email\":\"paul@example.com\", \"dob\" : \"December 27, 1978\"}";
Entity person = parser.parseRow(Result.fromContent(json, Result.JSON), personType.newInstance());
assertEqual("Paul", person.getEntity().getText(Person.name));
assertEqual("paul@example.com", person.getEntity().getText(Person.email));
}
use of com.codename1.rad.models.Property.Name in project CodeRAD by shannah.
the class ResultParserTest method dateFormatXMLTest.
private void dateFormatXMLTest() throws Exception {
EntityType personType = new EntityTypeBuilder().string(Person.name).string(Person.email).Date(Person.birthDate).build();
ResultParser parser = new ResultParser(personType).property("/person/name", Person.name).property("/person/email", Person.email).property("/person/dob", Person.birthDate, new SimpleDateFormat("MMM d, yyyy"));
String json = "<person><name>Paul</name> <email>paul@example.com</email> <dob>December 27, 1978</dob></person>";
XMLParser xparser = new XMLParser();
Element root = xparser.parse(new StringReader("<?xml version='1.0'?>\n" + json));
Entity person = parser.parseRow(Result.fromContent(root), personType.newInstance());
assertEqual("Paul", person.getEntity().getText(Person.name));
assertEqual("paul@example.com", person.getEntity().getText(Person.email));
}
use of com.codename1.rad.models.Property.Name in project CodeRAD by shannah.
the class ResultParserTest method dateFormatTest.
private void dateFormatTest() throws Exception {
EntityType personType = new EntityTypeBuilder().string(Person.name).string(Person.email).Date(Person.birthDate).build();
ResultParser parser = new ResultParser(personType).property("name", Person.name).property("email", Person.email).property("dob", Person.birthDate, new SimpleDateFormat("MMM d, yyyy"));
String json = "{\"name\":\"Paul\", \"email\":\"paul@example.com\", \"dob\" : \"December 27, 1978\"}";
Entity person = parser.parseRow(Result.fromContent(json, Result.JSON), personType.newInstance());
assertEqual("Paul", person.getEntity().getText(Person.name));
assertEqual("paul@example.com", person.getEntity().getText(Person.email));
}
use of com.codename1.rad.models.Property.Name in project CodeRAD by shannah.
the class ContentType method createObjectType.
public static <V> ContentType<V> createObjectType(Class<V> representationClass) {
if (representationClass == Entity.class) {
return (ContentType<V>) EntityType;
}
if (representationClass == EntityList.class) {
return (ContentType<V>) EntityListType;
}
return new ContentType<V>(new Name(representationClass.getName()), representationClass) {
private boolean isEntity;
private boolean isEntityList;
{
isEntity = Entity.class.isAssignableFrom(representationClass);
isEntityList = EntityList.class.isAssignableFrom(representationClass);
;
}
@Override
public boolean equals(Object obj) {
return obj.getClass() == this.getClass() && ((ContentType) obj).getRepresentationClass() == representationClass;
}
@Override
public boolean isEntity() {
return isEntity;
}
@Override
public boolean isEntityList() {
return isEntityList;
}
@Override
public int hashCode() {
return representationClass.hashCode();
}
@Override
public boolean canConvertFrom(ContentType otherType) {
return representationClass.isAssignableFrom(otherType.representationClass);
}
@Override
public <U> V from(ContentType<U> otherType, U data) {
if (representationClass.isAssignableFrom(otherType.representationClass)) {
return (V) data;
}
return super.from(otherType, data);
}
@Override
public <U> U to(ContentType<U> otherType, V data) {
if (otherType.representationClass.isAssignableFrom(representationClass)) {
return (U) data;
}
return super.to(otherType, data);
}
};
}
use of com.codename1.rad.models.Property.Name in project CodenameOne by codenameone.
the class Message method sendMessageViaCloudSync.
/**
* <p>Send an email message using the Codename One cloud to send the message, notice that this API
* will only work for pro accounts.</p>
* <script src="https://gist.github.com/codenameone/8229c1d4627ab3a1f17e.js"></script>
*
* @param sender the name of the sender, notice all email will arrive from Codename One to avoid spam issues
* @param recipient the email for the recipient
* @param recipientName the display name for the recipient
* @param subject e-mail subject
* @param plainTextBody when sending an HTML message you should also attach a plain text fallback message,
* this is redundant if the email is a plain text message to begin with
* @return true if sending succeeded
*/
public boolean sendMessageViaCloudSync(String sender, String recipient, String recipientName, String subject, String plainTextBody) {
ConnectionRequest r = createMessage(sender, recipient, recipientName, subject, plainTextBody);
r.setFailSilently(true);
NetworkManager.getInstance().addToQueueAndWait(r);
return r.getResposeCode() == 200;
}
Aggregations