-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
215 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
components/ui/src/main/java/com/pcf/tripit/flightui/Fcontroller.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package com.pcf.tripit.flightui; | ||
|
||
public class Fcontroller { | ||
} |
65 changes: 65 additions & 0 deletions
65
components/ui/src/main/java/com/pcf/tripit/flightui/FlightClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package com.pcf.tripit.flightui; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.core.ParameterizedTypeReference; | ||
import org.springframework.http.HttpMethod; | ||
import org.springframework.web.client.RestOperations; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class FlightClient { | ||
|
||
private static ParameterizedTypeReference<List<FlightUI>> flightListType = new ParameterizedTypeReference<List<FlightUI>>() { | ||
}; | ||
private static ParameterizedTypeReference<FlightUI> flightType = new ParameterizedTypeReference<FlightUI>() { | ||
}; | ||
private String flightURL; | ||
private RestOperations restOperations; | ||
private static final int CACHE_SIZE = 5; | ||
private final List<FlightUI> lastRead = new ArrayList<>(CACHE_SIZE); | ||
private static final Logger log = LoggerFactory.getLogger(FlightClient.class); | ||
|
||
public FlightClient(String flightURL, RestOperations restOperations) { | ||
this.flightURL = flightURL; | ||
this.restOperations = restOperations; | ||
} | ||
|
||
public void create(FlightUI hotel) { | ||
restOperations.postForEntity(flightURL, hotel, FlightUI.class); | ||
} | ||
|
||
// @HystrixCommand(fallbackMethod="getAllFallback",commandProperties = { | ||
// @HystrixProperty(name="execution.isolation.strategy", value="SEMAPHORE") | ||
//}) | ||
public List<FlightUI> getAll() { | ||
List<FlightUI> read = restOperations.exchange(flightURL, HttpMethod.GET, null, flightListType).getBody(); | ||
log.debug("Read {} podcasts from {}", read.size(), flightURL); | ||
|
||
lastRead.clear(); | ||
int copyCount = (read.size() < CACHE_SIZE) ? read.size() : CACHE_SIZE; | ||
for (int i =0; i < copyCount; i++) | ||
lastRead.add(read.get(i)); | ||
log.debug("Copied {} hotels into the cache", copyCount); | ||
|
||
return read; | ||
} | ||
|
||
public List<FlightUI> getDates(String begin, String end){ | ||
String finalUrl = flightURL +"/filter?begin="+begin+"&end="+end; | ||
return restOperations.exchange(finalUrl, HttpMethod.GET, null, flightListType).getBody(); | ||
} | ||
|
||
public List<FlightUI> getAllFallback() { | ||
log.debug("Returning {} hotels from the fallback method", lastRead.size()); | ||
|
||
return lastRead; | ||
} | ||
|
||
public FlightUI bookHotel(String name, String address, String city, String begin, String end){ | ||
String finalUrl = flightURL +"/book?name="+name+"&address="+address+"&city="+city+"&begin="+begin+"&end="+end; | ||
FlightUI hotelUI = restOperations.exchange(finalUrl, HttpMethod.GET, null, flightType).getBody(); | ||
return hotelUI; | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
components/ui/src/main/java/com/pcf/tripit/flightui/FlightInitialList.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package com.pcf.tripit.flightui; | ||
|
||
public class FlightInitialList { | ||
} |
83 changes: 83 additions & 0 deletions
83
components/ui/src/main/java/com/pcf/tripit/flightui/FlightUI.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package com.pcf.tripit.flightui; | ||
|
||
import java.util.Date; | ||
|
||
public class FlightUI { | ||
|
||
private String airlinesName; | ||
private String flightNumber; | ||
private String departureTime; | ||
private String arrivalTime; | ||
private String from; | ||
private String to; | ||
private int cost; | ||
|
||
public FlightUI() { | ||
} | ||
|
||
public FlightUI(String airlinesName, String flightNumber, String departureTime, String arrivalTime, String from, String to, int cost) { | ||
this.airlinesName = airlinesName; | ||
this.flightNumber = flightNumber; | ||
this.departureTime = departureTime; | ||
this.arrivalTime = arrivalTime; | ||
this.from = from; | ||
this.to = to; | ||
this.cost = cost; | ||
} | ||
|
||
public String getAirlinesName() { | ||
return airlinesName; | ||
} | ||
|
||
public void setAirlinesName(String airlinesName) { | ||
this.airlinesName = airlinesName; | ||
} | ||
|
||
public String getFlightNumber() { | ||
return flightNumber; | ||
} | ||
|
||
public void setFlightNumber(String flightNumber) { | ||
this.flightNumber = flightNumber; | ||
} | ||
|
||
public String getDepartureTime() { | ||
return departureTime; | ||
} | ||
|
||
public void setDepartureTime(String departureTime) { | ||
this.departureTime = departureTime; | ||
} | ||
|
||
public String getArrivalTime() { | ||
return arrivalTime; | ||
} | ||
|
||
public void setArrivalTime(String arrivalTime) { | ||
this.arrivalTime = arrivalTime; | ||
} | ||
|
||
public String getFrom() { | ||
return from; | ||
} | ||
|
||
public void setFrom(String from) { | ||
this.from = from; | ||
} | ||
|
||
public String getTo() { | ||
return to; | ||
} | ||
|
||
public void setTo(String to) { | ||
this.to = to; | ||
} | ||
|
||
public int getCost() { | ||
return cost; | ||
} | ||
|
||
public void setCost(int cost) { | ||
this.cost = cost; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters