Permalink
Browse files

Issue #2 solved, httpAdapter and JsonObject mapper replaced with spri…

…ng's RestTemplate object. Service layer impl changed.
  • Loading branch information...
dgkncelik committed Jul 1, 2018
1 parent 6d0677a commit a8a30d3e7408ecfe0147242ebe17f256621ac51c
@@ -6,6 +6,7 @@
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import tr.edu.itu.cavabunga.lib.entity.Participant;
import java.util.List;
@@ -20,4 +21,7 @@
return this.cavabungaClientService.retrieveCalendarsByOwner("testuser");
}
@GetMapping(value = "2")
public List<Participant> test2(){ return this.cavabungaClientService.retrieveParticipant("testuser");}
}

This file was deleted.

Oops, something went wrong.

This file was deleted.

Oops, something went wrong.
@@ -33,23 +33,23 @@ public CavabungaClientService(ComponentRestService componentRestService,
public List<Participant> retrieveParticipant(String userName){
try {
return participantRestService.recieveParticipantFromServer("participant/" + userName, RequestMethod.GET);
return participantRestService.getParticipantFromServer("participant/" + userName);
}catch (Exception e){
throw new ClientException("Couldnt recieve participant with username: " + userName + " ,message:" + e.getMessage());
}
}
public List<Component> retrieveComponentById(Long id){
try {
return componentRestService.recieveComponentFromServer("component/" + id.toString(), RequestMethod.GET);
return componentRestService.getComponentFromServer("component/" + id.toString());
}catch (Exception e){
throw new ClientException("Couldnt recieve component with id of " + id.toString() + " ,message:" + e.getMessage());
}
}
public List<Component> retrieveComponentsByOwner(String userName){
try {
return componentRestService.recieveComponentFromServer("participant/" + userName + "/components", RequestMethod.GET);
return componentRestService.getComponentFromServer("participant/" + userName + "/components");
}catch (Exception e){
throw new ClientException("Coulnd recieve participants components username: " + userName + " ,message:" + e.getMessage());
}
@@ -58,7 +58,7 @@ public CavabungaClientService(ComponentRestService componentRestService,
public List<Component> retrieveCalendarsByOwner(String userName){
List<Component> calendars = new ArrayList<>();
try {
for (Component c : componentRestService.recieveComponentFromServer("participant/" + userName + "/components", RequestMethod.GET)){
for (Component c : componentRestService.getComponentFromServer("participant/" + userName + "/components")){
if(c instanceof Calendar){
calendars.add(c);
}
@@ -1,43 +1,39 @@
package tr.edu.itu.cavabunga.client.service;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.web.client.RestTemplate;
import tr.edu.itu.cavabunga.client.configuration.CavabungaClientConfiguration;
import tr.edu.itu.cavabunga.client.http.HttpAdapter;
import tr.edu.itu.cavabunga.client.http.JsonObjectMapper;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestMethod;
import tr.edu.itu.cavabunga.lib.entity.Component;
import tr.edu.itu.cavabunga.lib.http.ComponentResponse;
import tr.edu.itu.cavabunga.lib.http.Response;
import java.util.List;
@Data
@Service
public class ComponentRestService {
private HttpAdapter httpAdapter;
private JsonObjectMapper jsonObjectMapper;
private CavabungaClientConfiguration cavabungaClientConfiguration;
private RestTemplate restTemplate;
private RestTemplateBuilder restTemplateBuilder;
@Autowired
public ComponentRestService(HttpAdapter httpAdapter,
JsonObjectMapper jsonObjectMapper,
CavabungaClientConfiguration cavabungaClientConfiguration){
public ComponentRestService(CavabungaClientConfiguration cavabungaClientConfiguration,
RestTemplateBuilder restTemplateBuilder){
this.cavabungaClientConfiguration = cavabungaClientConfiguration;
this.httpAdapter = httpAdapter;
this.jsonObjectMapper = jsonObjectMapper;
this.restTemplateBuilder = restTemplateBuilder;
this.restTemplate = restTemplateBuilder.build();
}
public String sendComponentToServer(tr.edu.itu.cavabunga.lib.entity.Component component,
RequestMethod requestMethod,
String apiUri){
return this.httpAdapter.doRequest(this.cavabungaClientConfiguration.getCavabungaServerUrl() + ":" + this.cavabungaClientConfiguration.getCavabungaServerPort() + "/" + apiUri,
requestMethod,
this.jsonObjectMapper.mapComponentToJson(component));
public void postComponentToServer(tr.edu.itu.cavabunga.lib.entity.Component component, String apiUri){
this.restTemplate.postForEntity(this.cavabungaClientConfiguration.getCavabungaServerUrl() + ":" + this.cavabungaClientConfiguration.getCavabungaServerPort() + "/" + apiUri,
component, Response.class);
}
public List<Component> recieveComponentFromServer(String apiUri, RequestMethod requestMethod){
return this.jsonObjectMapper.mapFromJsonToComponentResponseList( this.httpAdapter.doRequest(this.cavabungaClientConfiguration.getCavabungaServerUrl() + ":" + this.cavabungaClientConfiguration.getCavabungaServerPort() + "/" + apiUri,
requestMethod, ""));
public List<Component> getComponentFromServer(String apiUri){
return this.restTemplate.getForEntity(this.cavabungaClientConfiguration.getCavabungaServerUrl() + ":" + this.cavabungaClientConfiguration.getCavabungaServerPort() + "/" + apiUri,ComponentResponse.class).getBody().getData();
}
}
@@ -1,44 +1,36 @@
package tr.edu.itu.cavabunga.client.service;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.web.client.RestTemplate;
import tr.edu.itu.cavabunga.client.configuration.CavabungaClientConfiguration;
import tr.edu.itu.cavabunga.client.http.HttpAdapter;
import tr.edu.itu.cavabunga.client.http.JsonObjectMapper;
import tr.edu.itu.cavabunga.lib.entity.Parameter;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestMethod;
import tr.edu.itu.cavabunga.lib.http.ParameterResponse;
import tr.edu.itu.cavabunga.lib.http.Response;
import java.util.List;
@Service
@Data
public class ParameterRestService {
private HttpAdapter httpAdapter;
private JsonObjectMapper jsonObjectMapper;
private CavabungaClientConfiguration cavabungaClientConfiguration;
private RestTemplate restTemplate;
private RestTemplateBuilder restTemplateBuilder;
@Autowired
public ParameterRestService(HttpAdapter httpAdapter,
JsonObjectMapper jsonObjectMapper,
CavabungaClientConfiguration cavabungaClientConfiguration){
this.httpAdapter = httpAdapter;
this.jsonObjectMapper = jsonObjectMapper;
public ParameterRestService(CavabungaClientConfiguration cavabungaClientConfiguration, RestTemplateBuilder restTemplateBuilder){
this.cavabungaClientConfiguration = cavabungaClientConfiguration;
this.restTemplateBuilder = restTemplateBuilder;
this.restTemplate = restTemplateBuilder.build();
}
public String sendParameterToServer(Parameter parameter,
RequestMethod requestMethod,
String apiUri){
return this.httpAdapter.doRequest(this.cavabungaClientConfiguration.getCavabungaServerUrl() + ":" + this.cavabungaClientConfiguration.getCavabungaServerPort() + "/" + apiUri,
requestMethod,
this.jsonObjectMapper.mapParameterToJson(parameter));
public void postParameterToServer(Parameter parameter, String apiUri){
this.restTemplate.postForEntity(this.cavabungaClientConfiguration.getCavabungaServerUrl() + ":" + this.cavabungaClientConfiguration.getCavabungaServerPort() + "/" + apiUri, parameter, Response.class);
}
public List<Parameter> recieveParameterFromServer(String apiUri,
RequestMethod requestMethod){
return this.jsonObjectMapper.mapFromJsonToParameterResponseList( this.httpAdapter.doRequest(this.cavabungaClientConfiguration.getCavabungaServerUrl() + ":" + this.cavabungaClientConfiguration.getCavabungaServerPort() + "/" + apiUri,
requestMethod, ""));
public List<Parameter> getParameterFromServer(String apiUri){
return this.restTemplate.getForEntity(this.cavabungaClientConfiguration.getCavabungaServerUrl() + ":" + this.cavabungaClientConfiguration.getCavabungaServerPort() + "/" + apiUri, ParameterResponse.class).getBody().getData();
}
}
Oops, something went wrong.

0 comments on commit a8a30d3

Please sign in to comment.