login.setAuthors(new ArrayList ());
login.setAuthors_map(new HashMap());
JSONObject jsonObject = (JSONObject) new JSONParser().parse(data);
for (Object c : (JSONArray) jsonObject.get("objects")){
jsonObject = (JSONObject) c;
Author author = new Author(Integer.parseInt((String)jsonObject.get("id")),(String) jsonObject.get("name"),(String) jsonObject.get("email"));
login.getAuthors().add(author);
login.getAuthors_map().put(author.getId(), author);
}
} catch (ParseException ex) {
Logger.getLogger(Login.class.getName()).log(Level.SEVERE, null, ex);
}
flag = true;
}
else {
flag=false;
}
data = new RestClient().apacheHttpClientGet(Login.url+"api/reservation/product/?format=json", username.getText(), password.getPassword());
if( data!=null) {
try {
login.setProducts(new ArrayList ());
login.setProducts_map(new HashMap());
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) login.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);
}
Product product = new Product(Integer.parseInt((String)jsonObject.get("id")),author,(String) jsonObject.get("name"),(String) jsonObject.get("genre"),date);
product.setCount((long) jsonObject.get("count"));
if (product!=null){
login.getProducts().add(product);
login.getProducts_map().put(product.getId(), product);
}
}
} catch (ParseException ex) {
Logger.getLogger(Login.class.getName()).log(Level.SEVERE, null, ex);
}
flag = true;
}
else {
flag = false;
}
data = new RestClient().apacheHttpClientGet(Login.url+"api/reservation/video/?format=json", username.getText(), password.getPassword());
if( data!=null) {
try {
login.setVideos(new ArrayList ());
login.setVideos_map(new HashMap());
JSONObject jsonObject = (JSONObject) new JSONParser().parse(data);
for (Object c : (JSONArray) jsonObject.get("objects")){
jsonObject = (JSONObject) c;
Author author = (Author) login.getAuthors_map().get(Integer.parseInt((String)jsonObject.get("id")));
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);
}
Video video = new Video (Integer.parseInt((String)jsonObject.get("id")),author,(String) jsonObject.get("name"),(String) jsonObject.get("genre"),date);
video.setCount((long) jsonObject.get("count"));
login.getVideos().add(video);
login.getVideos_map().put(video.getId(), video);
}
} catch (ParseException ex) {
Logger.getLogger(Login.class.getName()).log(Level.SEVERE, null, ex);
}
flag = true;
}
else {
flag = false;
}
data = new RestClient().apacheHttpClientGet(Login.url+"api/reservation/book/?format=json", username.getText(), password.getPassword());
if( data!=null) {
try {
login.setBooks(new ArrayList ());
login.setBooks_map(new HashMap());
JSONObject jsonObject = (JSONObject) new JSONParser().parse(data);
for (Object c : (JSONArray) jsonObject.get("objects")){
jsonObject = (JSONObject) c;
Author author = (Author) login.getAuthors_map().get(Integer.parseInt((String)jsonObject.get("id")));
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);
}
Book book = new Book (Integer.parseInt((String)jsonObject.get("id")),author,(String) jsonObject.get("name"),(String) jsonObject.get("genre"),date);
book.setCount((long) jsonObject.get("count"));
login.getBooks().add(book);
login.getBooks_map().put(book.getId(), book);
}
} catch (ParseException ex) {
Logger.getLogger(Login.class.getName()).log(Level.SEVERE, null, ex);
}
flag = true;
}
else {
flag = false;
}
data = new RestClient().apacheHttpClientGet(Login.url+"api/reservation/reservation/?format=json", username.getText(), password.getPassword());
if( data!=null) {
try {
login.setReservations(new ArrayList ());
login.setReservations_map(new HashMap());
JSONObject jsonObject = (JSONObject) new JSONParser().parse(data);
for (Object c : (JSONArray) jsonObject.get("objects")){
jsonObject = (JSONObject) c;
System.out.println((String)jsonObject.get("user"));
Matcher makeMatch = Pattern.compile("\\d+").matcher((String)jsonObject.get("product"));
makeMatch.find();
String inputInt = makeMatch.group();
Product product = (Product) login.getProducts_map().get(Integer.parseInt(inputInt));
Author author = (Author) login.getAuthors_map().get(product.getAuthor().getId());
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
Date reserv_date_start=null;
Date reserv_finish =null;
try {
reserv_date_start = sdf.parse((String) jsonObject.get("reserv_date_start"));