Skip to content
Snippets Groups Projects
Commit 16b22b31 authored by Thiemo Belmega's avatar Thiemo Belmega
Browse files

Clean up resource and bean classes

* Remove catch clauses, throw exceptions in GET methods
* Remove BusinessObjectRessource.class
* Move constants form BusinessObjectRessourceClass to subclasses
parent d112e4af
No related branches found
No related tags found
No related merge requests found
......@@ -38,17 +38,9 @@ public class ApplicationBean extends BusinessObjectBean {
}
public static ApplicationBean getBean(String id) {
try {
Application app = (Application)DatabaseController.getInstance().load(id);
return new ApplicationBean(app);
} catch (SQLException e) {
e.printStackTrace();
} catch (InvalidIdException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return null;
public static ApplicationBean getBean(String id) throws InvalidIdException, SQLException, IOException {
Application app = (Application)DatabaseController.getInstance().load(id);
return new ApplicationBean(app);
}
}
......@@ -3,7 +3,6 @@ package de.unipotsdam.cs.toolup.ws.beans;
import de.unipotsdam.cs.toolup.database.DatabaseController;
import de.unipotsdam.cs.toolup.exceptions.InvalidIdException;
import de.unipotsdam.cs.toolup.model.Category;
import de.unipotsdam.cs.toolup.model.Feature;
import java.io.IOException;
import java.sql.SQLException;
......@@ -19,18 +18,10 @@ public class CategoryBean extends BusinessObjectBean{
}
public static CategoryBean getBean(String id) {
try {
Category cat = (Category) DatabaseController.getInstance().load(id);
return new CategoryBean(cat);
} catch (SQLException e) {
e.printStackTrace();
} catch (InvalidIdException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return null;
public static CategoryBean getBean(String id) throws IOException, SQLException, InvalidIdException {
Category cat = (Category) DatabaseController.getInstance().load(id);
return new CategoryBean(cat);
}
}
......
......@@ -17,19 +17,9 @@ public class FeatureBean extends BusinessObjectBean{
this.applications = feat.getRelatedApplications();
}
public static FeatureBean getBean(String id) {
try {
Feature feat = (Feature) DatabaseController.getInstance().load(id);
return new FeatureBean(feat);
} catch (SQLException e) {
e.printStackTrace();
} catch (InvalidIdException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return null;
public static FeatureBean getBean(String id) throws IOException, SQLException, InvalidIdException {
Feature feat = (Feature) DatabaseController.getInstance().load(id);
return new FeatureBean(feat);
}
}
......
......@@ -9,13 +9,13 @@ import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
@Path(BusinessObjectResource.PATH_APPLICATION)
public class ApplicationResource extends BusinessObjectResource {
@Path("application")
public class ApplicationResource {
@GET
@Path("/{id}")
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
public ApplicationBean get(@PathParam(PARAM_ID) String id) {
public ApplicationBean get(@PathParam("id") String id) throws Exception {
return ApplicationBean.getBean(id);
}
......
package de.unipotsdam.cs.toolup.ws.resource;
import de.unipotsdam.cs.toolup.database.DatabaseController;
import de.unipotsdam.cs.toolup.exceptions.InvalidIdException;
import de.unipotsdam.cs.toolup.model.BusinessObject;
import de.unipotsdam.cs.toolup.model.NullBusinessObject;
import java.io.IOException;
import java.sql.SQLException;
public class BusinessObjectResource {
protected static final String PATH_APPLICATION = "application";
protected static final String PATH_FEATURE = "feature";
protected static final String PATH_CATEGORY = "category";
protected static final String PARAM_ID = "id";
protected BusinessObject getBusinessObject(String id) {
try {
return DatabaseController.getInstance().load(id);
} catch (SQLException | IOException | InvalidIdException e) {
e.printStackTrace();
return NullBusinessObject.getInstance();
}
}
}
......@@ -9,13 +9,13 @@ import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
@Path(BusinessObjectResource.PATH_CATEGORY)
public class CategoryResource extends BusinessObjectResource {
@Path("category")
public class CategoryResource {
@GET
@Path("/{id}")
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
public CategoryBean get(@PathParam(PARAM_ID) String id) {
public CategoryBean get(@PathParam("id") String id) throws Exception{
return CategoryBean.getBean(id);
}
}
......@@ -9,13 +9,13 @@ import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
@Path(BusinessObjectResource.PATH_FEATURE)
public class FeatureResource extends BusinessObjectResource {
@Path("feature")
public class FeatureResource {
@GET
@Path("/{id}")
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
public FeatureBean get(@PathParam(PARAM_ID) String id) {
public FeatureBean get(@PathParam("id") String id) throws Exception {
return FeatureBean.getBean(id);
}
}
......@@ -27,11 +27,11 @@ public class IntegrationTestWebService {
private static final String CATEGORY_RESOURCE_URL = "/category/";
private static final String FEATURE_RESOURCE_URL = "/feature/";
private HttpClient client = HttpClientBuilder.create().build();
@Test
public void testThatGetRequestReturnsStatusCodeOK() throws Exception {
//arrange
HttpClient client = HttpClientBuilder.create().build();
HttpGet request = new HttpGet(TOOLUP_URL + APPLICATION_RESOURCE_URL + BusinessObjectTest.APPLICATION_TEST_ID_1);
request.addHeader(HttpHeaders.ACCEPT, ContentType.APPLICATION_JSON.getMimeType());
......@@ -45,7 +45,6 @@ public class IntegrationTestWebService {
@Test
public void testThatGetRequestReturnsMimeTypeJson() throws Exception {
//arrange
HttpClient client = HttpClientBuilder.create().build();
HttpGet request = new HttpGet(TOOLUP_URL + APPLICATION_RESOURCE_URL + BusinessObjectTest.APPLICATION_TEST_ID_1);
request.addHeader(HttpHeaders.ACCEPT, ContentType.APPLICATION_JSON.getMimeType());
......@@ -61,7 +60,6 @@ public class IntegrationTestWebService {
//arrange
BusinessObject expectedBO = DatabaseController.getInstance().load(BusinessObjectTest.CATEGORY_TEST_ID_11);
HttpClient client = HttpClientBuilder.create().build();
HttpGet request = new HttpGet(TOOLUP_URL + CATEGORY_RESOURCE_URL + BusinessObjectTest.CATEGORY_TEST_ID_11);
request.addHeader(HttpHeaders.ACCEPT, ContentType.APPLICATION_JSON.getMimeType());
......@@ -81,7 +79,6 @@ public class IntegrationTestWebService {
//arrange
BusinessObject expectedBO = DatabaseController.getInstance().load( BusinessObjectTest.FEATURE_TEST_ID_21);
HttpClient client = HttpClientBuilder.create().build();
HttpGet request = new HttpGet(TOOLUP_URL + FEATURE_RESOURCE_URL + BusinessObjectTest.FEATURE_TEST_ID_21);
request.addHeader(HttpHeaders.ACCEPT, ContentType.APPLICATION_JSON.getMimeType());
......@@ -101,7 +98,6 @@ public class IntegrationTestWebService {
//arrange
BusinessObject expectedBO = DatabaseController.getInstance().load(BusinessObjectTest.APPLICATION_TEST_ID_1);
HttpClient client = HttpClientBuilder.create().build();
HttpGet request = new HttpGet(TOOLUP_URL + APPLICATION_RESOURCE_URL + BusinessObjectTest.APPLICATION_TEST_ID_1);
request.addHeader(HttpHeaders.ACCEPT, ContentType.APPLICATION_JSON.getMimeType());
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment