Skip to content

Commit

Permalink
Adding Book image and page URL
Browse files Browse the repository at this point in the history
Adding more data into the DB
  • Loading branch information
agoncal committed Sep 13, 2013
1 parent a5bf2f9 commit d611da7
Show file tree
Hide file tree
Showing 9 changed files with 149 additions and 43 deletions.
6 changes: 6 additions & 0 deletions 02-JavaOne2013/DEMO.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# Getting ready

* Intellij IDEA (Cardea)
* Command line
* Saved searched

# Generate project

# Generate entities
Expand Down
9 changes: 5 additions & 4 deletions 02-JavaOne2013/agoncal-application-javaone2013.fsh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ set ACCEPT_DEFAULTS true ;
@/* == Creating the project == */;
@/* ========================== */;

new-project --named agoncal-application-javaone2013140 --topLevelPackage org.agoncal.application.javaone2013 --type war ;
new-project --named agoncal-application-javaone2013140 --topLevelPackage org.agoncal.application.javaone2013 --type war --createMain ;


@/* ============================ */;
Expand Down Expand Up @@ -61,10 +61,12 @@ field string --named title ;
field string --named author ;
field string --named description ;
field number --type java.lang.Float --named price ;
field number --type java.lang.Integer --named nbOfPage ;
field temporal --type DATE --named publicationDate ;
field number --type java.lang.Integer --named nbOfPages ;
field string --named publisher ;
field temporal --type DATE --named publicationDate ;
field custom --named language --type org.agoncal.application.javaone2013.model.Language.java ;
field string --named imageURL ;
field string --named pageURL ;

constraint NotNull --onProperty isbn ;
constraint NotNull --onProperty title ;
Expand Down Expand Up @@ -134,7 +136,6 @@ project remove-dependency org.jboss.spec.javax.ejb:jboss-ejb-api_3.1_spec ;
project remove-dependency org.jboss.spec.javax.faces:jboss-jsf-api_2.1_spec ;
project add-dependency javax:javaee-api:7.0:provided ;


@/* ========================== */;
@/* == Building the project == */;
@/* ========================== */;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,17 @@ public class Book implements Serializable {
private String title;
@NotNull
private String author;
@Column(length = 2000)
@Size(min = 10, max = 2000)
private String description;
private Float price;
private Integer nbOfPage;
private Integer nbOfPages;
private String publisher;
@Temporal(TemporalType.DATE)
private Date publicationDate;
private String publisher;
private Language language;
private String imageURL;
private String pageURL;

// ======================================
// = Constructors =
Expand All @@ -50,12 +53,12 @@ public class Book implements Serializable {
public Book() {
}

public Book(String title, String description, Float price, String isbn, Integer nbOfPage) {
public Book(String title, String description, Float price, String isbn, Integer nbOfPages) {
this.title = title;
this.price = price;
this.description = description;
this.isbn = isbn;
this.nbOfPage = nbOfPage;
this.nbOfPages = nbOfPages;
}

// ======================================
Expand Down Expand Up @@ -102,12 +105,12 @@ public void setIsbn(String isbn) {
this.isbn = isbn;
}

public Integer getNbOfPage() {
return nbOfPage;
public Integer getNbOfPages() {
return nbOfPages;
}

public void setNbOfPage(Integer nbOfPage) {
this.nbOfPage = nbOfPage;
public void setNbOfPages(Integer nbOfPage) {
this.nbOfPages = nbOfPage;
}

public String getAuthor() {
Expand Down Expand Up @@ -141,4 +144,20 @@ public Language getLanguage() {
public void setLanguage(Language language) {
this.language = language;
}

public String getImageURL() {
return imageURL;
}

public void setImageURL(String imageURL) {
this.imageURL = imageURL;
}

public String getPageURL() {
return pageURL;
}

public void setPageURL(String pageURL) {
this.pageURL = pageURL;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ private Predicate[] getSearchPredicates(Root<Book> root) {
if (description != null && !"".equals(description)) {
predicatesList.add(builder.like(root.<String>get("description"), '%' + description + '%'));
}
Integer nbOfPage = this.example.getNbOfPage();
Integer nbOfPage = this.example.getNbOfPages();
if (nbOfPage != null && nbOfPage.intValue() != 0) {
predicatesList.add(builder.equal(root.get("nbOfPage"), nbOfPage));
}
Expand Down
58 changes: 50 additions & 8 deletions 02-JavaOne2013/application/src/main/resources/insert.sql

Large diffs are not rendered by default.

30 changes: 21 additions & 9 deletions 02-JavaOne2013/application/src/main/webapp/book/create.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,10 @@
<h:message for="bookBeanBookPrice" styleClass="error"/>
</h:panelGroup>
<h:outputText/>
<h:outputLabel for="bookBeanBookNbOfPage" value="Nb Of Page:"/>
<h:outputLabel for="bookBeanBookNbOfPages" value="Nb Of Pages:"/>
<h:panelGroup>
<h:inputText id="bookBeanBookNbOfPage" value="#{bookBean.book.nbOfPage}"/>
<h:message for="bookBeanBookNbOfPage" styleClass="error"/>
</h:panelGroup>
<h:outputText/>
<h:outputLabel for="bookBeanBookPublicationDate" value="Publication Date:"/>
<h:panelGroup>
<p:calendar id="bookBeanBookPublicationDate" value="#{bookBean.book.publicationDate}"/>
<h:message for="bookBeanBookPublicationDate" styleClass="error"/>
<h:inputText id="bookBeanBookNbOfPages" value="#{bookBean.book.nbOfPages}"/>
<h:message for="bookBeanBookNbOfPages" styleClass="error"/>
</h:panelGroup>
<h:outputText/>
<h:outputLabel for="bookBeanBookPublisher" value="Publisher:"/>
Expand All @@ -85,6 +79,12 @@
<h:message for="bookBeanBookPublisher" styleClass="error"/>
</h:panelGroup>
<h:outputText/>
<h:outputLabel for="bookBeanBookPublicationDate" value="Publication Date:"/>
<h:panelGroup>
<p:calendar id="bookBeanBookPublicationDate" value="#{bookBean.book.publicationDate}"/>
<h:message for="bookBeanBookPublicationDate" styleClass="error"/>
</h:panelGroup>
<h:outputText/>
<h:outputLabel for="bookBeanBookLanguage" value="Language:"/>
<h:panelGroup>
<h:selectOneMenu id="bookBeanBookLanguage" value="#{bookBean.book.language}">
Expand All @@ -95,6 +95,18 @@
<h:message for="bookBeanBookLanguage" styleClass="error"/>
</h:panelGroup>
<h:outputText/>
<h:outputLabel for="bookBeanBookImageURL" value="Image URL:"/>
<h:panelGroup>
<h:inputText id="bookBeanBookImageURL" value="#{bookBean.book.imageURL}"/>
<h:message for="bookBeanBookImageURL" styleClass="error"/>
</h:panelGroup>
<h:outputText/>
<h:outputLabel for="bookBeanBookPageURL" value="Page URL:"/>
<h:panelGroup>
<h:inputText id="bookBeanBookPageURL" value="#{bookBean.book.pageURL}"/>
<h:message for="bookBeanBookPageURL" styleClass="error"/>
</h:panelGroup>
<h:outputText/>
</h:panelGrid>

<div class="buttons">
Expand Down
6 changes: 3 additions & 3 deletions 02-JavaOne2013/application/src/main/webapp/book/search.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@
<h:message for="bookBeanExampleDescription" styleClass="error"/>
</h:panelGroup>
<h:outputText/>
<h:outputLabel for="bookBeanExampleNbOfPage" value="Nb Of Page:"/>
<h:outputLabel for="bookBeanExampleNbOfPages" value="Nb Of Pages:"/>
<h:panelGroup>
<h:inputText id="bookBeanExampleNbOfPage" value="#{bookBean.example.nbOfPage}"/>
<h:message for="bookBeanExampleNbOfPage" styleClass="error"/>
<h:inputText id="bookBeanExampleNbOfPages" value="#{bookBean.example.nbOfPages}"/>
<h:message for="bookBeanExampleNbOfPages" styleClass="error"/>
</h:panelGroup>
<h:outputText/>
</h:panelGrid>
Expand Down
16 changes: 11 additions & 5 deletions 02-JavaOne2013/application/src/main/webapp/book/view.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,26 @@
<h:outputLabel for="bookBeanBookPrice" value="Price:"/>
<h:outputText id="bookBeanBookPrice" value="#{bookBean.book.price}"/>
<h:outputText/>
<h:outputLabel for="bookBeanBookNbOfPage" value="Nb Of Page:"/>
<h:outputText id="bookBeanBookNbOfPage" value="#{bookBean.book.nbOfPage}"/>
<h:outputLabel for="bookBeanBookNbOfPages" value="Nb Of Pages:"/>
<h:outputText id="bookBeanBookNbOfPages" value="#{bookBean.book.nbOfPages}"/>
<h:outputText/>
<h:outputLabel for="bookBeanBookPublisher" value="Publisher:"/>
<h:outputText id="bookBeanBookPublisher" value="#{bookBean.book.publisher}"/>
<h:outputText/>
<h:outputLabel for="bookBeanBookPublicationDate" value="Publication Date:"/>
<h:outputText id="bookBeanBookPublicationDate" value="#{bookBean.book.publicationDate}">
<f:convertDateTime type="date"/>
</h:outputText>
<h:outputText/>
<h:outputLabel for="bookBeanBookPublisher" value="Publisher:"/>
<h:outputText id="bookBeanBookPublisher" value="#{bookBean.book.publisher}"/>
<h:outputText/>
<h:outputLabel for="bookBeanBookLanguage" value="Language:"/>
<h:outputText id="bookBeanBookLanguage" value="#{bookBean.book.language}"/>
<h:outputText/>
<h:outputLabel for="bookBeanBookImageURL" value="Image URL:"/>
<h:outputText id="bookBeanBookImageURL" value="#{bookBean.book.imageURL}"/>
<h:outputText/>
<h:outputLabel for="bookBeanBookPageURL" value="Page URL:"/>
<h:outputText id="bookBeanBookPageURL" value="#{bookBean.book.pageURL}"/>
<h:outputText/>
</h:panelGrid>

<div class="buttons">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,45 @@
* @author Antonio Goncalves
* http://www.antoniogoncalves.org
* --
* Using the Amazon WebServices to get book informations
* https://affiliate-program.amazon.com/gp/advertising/api/detail/main.html
*/
public class GetBooks {

/*
http://webservices.amazon.com/onca/xml?
Service=AWSECommerceService&
AWSAccessKeyId=[AWS Access Key ID]&
AssociateTag=[Associate ID]&
Operation=ItemLookup&
IdType=ASIN&
ItemId=B00008OE6I&
ResponseGroup=Accessories&
Version=2011-08-01
&Timestamp=[YYYY-MM-DDThh:mm:ssZ]
&Signature=[Request Signature]
*/

public static void main(String[] args) {

// URI uriAmazon = UriBuilder.fromUri("http://webservices.amazon.com/onca/xml").queryParam("Service", "AWSECommerceService").queryParam("AWSAccessKeyId", "AKIAIYNLC7WME6YSY66A").queryParam("AssociateTag", "antgonblo-20").build();
URI uriAmazon = UriBuilder.fromUri("http://free.apisigning.com/onca/xml").queryParam("Service", "AWSECommerceService").queryParam("AWSAccessKeyId", "AKIAIYNLC7WME6YSY66A").build();
URI uriSearch = UriBuilder.fromUri(uriAmazon).queryParam("Operation","ItemSearch").build();
URI uriSearchBooks = UriBuilder.fromUri(uriSearch).queryParam("SearchIndex","Books").build();
Client client = ClientBuilder.newClient();

URI uriSearchBooksByKeyword = UriBuilder.fromUri(uriSearchBooks).queryParam("Keywords","Java EE 7").build();
URI uriSearchBooksWithImages = UriBuilder.fromUri(uriSearchBooks).queryParam("Condition","All").queryParam("ResponseGroup","Images").queryParam("Title","Java EE 7").build();
URI uriSearchBooksWithResponse = UriBuilder.fromUri(uriSearchBooksByKeyword).queryParam("Condition","New").queryParam("ResponseGroup","Large").build();
// URI uriSearchBooksWithImages = UriBuilder.fromUri(uriSearchBooks).queryParam("Condition","All").queryParam("ResponseGroup","Images").queryParam("Title","Java EE 7").build();

System.out.println(uriSearchBooksByKeyword.toString());
System.out.println(uriSearchBooksWithImages.toString());
System.out.println(uriSearchBooksWithResponse.toString());

Response response = client.target(uriSearchBooksByKeyword).request().get();
System.out.println(response.getStatus());
response = client.target(uriSearchBooksWithImages).request().get();
// Response response = client.target(uriSearchBooksByKeyword).request().get();
// System.out.println(response.getStatus());
// System.out.println(response.readEntity(String.class));
Response response = client.target(uriSearchBooksWithResponse).request().get();
System.out.println(response.getStatus());
System.out.println(response.readEntity(String.class));
}
}

0 comments on commit d611da7

Please sign in to comment.