this.user = user;
listProducts();
}
private void listProducts(){
ProductCreator productcreator = new ProductCreator();
VideoProductBuilder videobuilder = new VideoProductBuilder();
BookProductBuilder bookbuilder = new BookProductBuilder();
String data = new RestClient().apacheHttpClientGet(Login.url+"api/reservation/video/?format=json", this.user.getUsername(), this.user.getPassword());
if( data!=null) {
try {
this.newvideos = new ArrayList();
JSONObject jsonObject = (JSONObject) new JSONParser().parse(data);
for (Object c : (JSONArray) jsonObject.get("objects")){
jsonObject = (JSONObject) c;
Matcher makeMatch = Pattern.compile("\\d+").matcher((String)jsonObject.get("author"));
makeMatch.find();
String inputInt = makeMatch.group();
Author author = (Author) this.login_window.getAuthors_map().get(Integer.parseInt(inputInt));
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
Date date=null;
try {
date = sdf.parse((String) jsonObject.get("pub_date"));
} catch (java.text.ParseException ex) {
Logger.getLogger(Login.class.getName()).log(Level.SEVERE, null, ex);
}
productcreator.setProduct(videobuilder);
productcreator.constructProduct(Integer.parseInt((String)jsonObject.get("id")),author,(String) jsonObject.get("name"),(String) jsonObject.get("genre"),date);
Product product = productcreator.getProduct();
this.newvideos.add(product);
}
} catch (ParseException ex) {
Logger.getLogger(Login.class.getName()).log(Level.SEVERE, null, ex);
}
}
data = new RestClient().apacheHttpClientGet(Login.url+"api/reservation/book/?format=json", this.user.getUsername(), this.user.getPassword());
if( data!=null) {
try {
this.newbooks = new ArrayList();
JSONObject jsonObject = (JSONObject) new JSONParser().parse(data);
for (Object c : (JSONArray) jsonObject.get("objects")){
jsonObject = (JSONObject) c;
Matcher makeMatch = Pattern.compile("\\d+").matcher((String)jsonObject.get("author"));
makeMatch.find();
String inputInt = makeMatch.group();
Author author = (Author) this.login_window.getAuthors_map().get(Integer.parseInt(inputInt));
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
Date date=null;
try {
date = sdf.parse((String) jsonObject.get("pub_date"));
} catch (java.text.ParseException ex) {
Logger.getLogger(Login.class.getName()).log(Level.SEVERE, null, ex);
}
productcreator.setProduct(bookbuilder);
productcreator.constructProduct(Integer.parseInt((String)jsonObject.get("id")),author,(String) jsonObject.get("name"),(String) jsonObject.get("genre"),date);
Product product = productcreator.getProduct();
this.newbooks.add(product);
}
} catch (ParseException ex) {
Logger.getLogger(Login.class.getName()).log(Level.SEVERE, null, ex);
}