) MockFactory.mockSuppliersMap.get(entityClass);
+ T entity = getResponseFromEntityAddRequest(entitySupplier.get(), HttpStatus.CREATED);
+
+ sendEntityWithIncorrectField(
+ entity,
+ fieldName,
+ incorrectValue,
+ restRootsMap.get(entityClass) + UPDATE_PATH,
+ HttpMethod.PUT,
+ expectedErrorStatusCode);
+ }
+
+ /**
+ * Check update of an entity with incorrect field (with incorrect value or with violating such constraints, as NotNull, Unique)
+ * at corresponding REST resource, which path is detected by class by means of {@link #restRootsMap}.
+ * Field value is set via java reflection mechanisms.
+ * Difference with {@link #updateEntityWithIncorrectField(Class, String, Object, HttpStatus)} consist in that this method
+ * performs update for properly created entity from REST resource.
+ *
In a case of absence of {@link HttpClientErrorException} or {@link HttpServerErrorException}, method fails with assertion error
+ * NOTICE: This behaviour will be changed after REST layer response codes regulation
+ *
+ * @param entity an entity class
+ * @param fieldName a field, which should be changed
+ * @param incorrectValue incorrect value for changing field
+ * @param expectedErrorStatusCode expected HTTP status code error
+ * @param type of the entity both of request and response
+ * @param type of the field
+ */
+ public static void updateEntityWithIncorrectField(T entity, String fieldName, V incorrectValue,
+ HttpStatus expectedErrorStatusCode) {
+ sendEntityWithIncorrectField(
+ entity,
+ fieldName,
+ incorrectValue,
+ restRootsMap.get(entity.getClass()) + UPDATE_PATH,
+ HttpMethod.PUT,
+ expectedErrorStatusCode);
+ }
+
+ /**
+ * Check sending of an entity with incorrect field (with incorrect value or with violating such constraints, as NotNull, Unique)
+ * to a given REST resource. Field is changed via java reflection mechanisms.
* Method checks for expected exception and, in a case of its' absence, it will fail with assertion error
* NOTICE: This behaviour will be changed after REST layer response codes regulation
*
- * @param entity an entity (eg. mock entity supplier)
+ * @param entity an entity, which should be sent
* @param fieldName a field, which should be changed
* @param incorrectValue incorrect value for changing field
* @param url URL of receiving POST request REST-resource
* @param expectedErrorStatusCode expected HTTP status code error
* @param type of the entity both of request and response
- * @param type of the filed
+ * @param type of the field
*/
- public static void sendEntityWithIncorrectField(T entity, String fieldName, V incorrectValue, String url,
- HttpMethod httpMethod, HttpStatus expectedErrorStatusCode)
- throws NoSuchFieldException, IllegalAccessException {
- setField(entity, fieldName, incorrectValue);
- getBodyOfResponseToSendEntityRequest(entity, url, httpMethod, expectedErrorStatusCode);
- fail("No expected exception occurs during sending of an entity with incorrect field");
+ private static void sendEntityWithIncorrectField(T entity, String fieldName,
+ V incorrectValue, String url, HttpMethod httpMethod,
+ HttpStatus expectedErrorStatusCode) {
+ try {
+ setField(entity, fieldName, incorrectValue);
+ getBodyOfResponseToSendEntityRequest(entity, url, httpMethod, expectedErrorStatusCode);
+ } catch (NoSuchFieldException | IllegalAccessException e) {
+ fail(e.toString());
+ }
}
/**
@@ -256,8 +386,7 @@ private static T getBodyOfResponseToSendEntityRequest(T entity, String url,
httpHeaders.setContentType(MediaType.APPLICATION_JSON_UTF8);
HttpEntity httpEntity = new HttpEntity<>(entity, httpHeaders);
- RestTemplate restTemplate = new RestTemplate();
- ResponseEntity responseEntity = restTemplate.exchange(
+ ResponseEntity responseEntity = new RestTemplate().exchange(
url,
httpMethod,
httpEntity,
diff --git a/rest/src/main/java/io/khasang/ba/config/AppConfig.java b/rest/src/main/java/io/khasang/ba/config/AppConfig.java
index aa2a580..04d85e9 100644
--- a/rest/src/main/java/io/khasang/ba/config/AppConfig.java
+++ b/rest/src/main/java/io/khasang/ba/config/AppConfig.java
@@ -96,11 +96,6 @@ public CustomerRequestTypeDao customerRequestTypeDao() {
return new CustomerRequestTypeDaoImpl(CustomerRequestType.class);
}
- @Bean
- public AddressDao addressDao() {
- return new AddressDaoImpl(Address.class);
- }
-
@Bean
public CategoryDao categoryDao() {
return new CategoryDaoImpl(Category.class);
@@ -110,4 +105,9 @@ public CategoryDao categoryDao() {
public CustomerRequestStageDao customerRequestStageDao() {
return new CustomerRequestStageDaoImpl(CustomerRequestStage.class);
}
+
+ @Bean
+ public CustomerRequestStageNameDao customerRequestStageNameDao() {
+ return new CustomerRequestStageNameDaoImpl(CustomerRequestStageName.class);
+ }
}
diff --git a/rest/src/main/java/io/khasang/ba/controller/AddressController.java b/rest/src/main/java/io/khasang/ba/controller/AddressController.java
deleted file mode 100644
index 3e8cdac..0000000
--- a/rest/src/main/java/io/khasang/ba/controller/AddressController.java
+++ /dev/null
@@ -1,46 +0,0 @@
-package io.khasang.ba.controller;
-
-import io.khasang.ba.entity.Address;
-import io.khasang.ba.service.AddressService;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Controller;
-import org.springframework.web.bind.annotation.*;
-
-import java.util.List;
-
-@Controller
-@RequestMapping(value = "/address")
-public class AddressController {
- @Autowired
- private AddressService addressService;
-
- @RequestMapping(value = "/get/all", method = RequestMethod.GET, produces = "application/json;charset=utf-8")
- @ResponseBody
- public List getAll() {
- return addressService.getAllAddresses();
- }
-
- @RequestMapping(value = "/get/{id}", method = RequestMethod.GET, produces = "application/json;charset=utf-8")
- @ResponseBody
- public Address getAddress(@PathVariable(value = "id") long id) {
- return addressService.getAddressById(id);
- }
-
- @RequestMapping(value = "/add", method = RequestMethod.POST, produces = "application/json;charset=utf-8")
- @ResponseBody
- public Address addAddress(@RequestBody Address address) {
- return addressService.addAddress(address);
- }
-
- @RequestMapping(value = "/update", method = RequestMethod.PUT, produces = "application/json;charset=utf-8")
- @ResponseBody
- public Address updateAddress(@RequestBody Address address) {
- return addressService.updateAddress(address);
- }
-
- @RequestMapping(value = "/delete/{id}", method = RequestMethod.DELETE, produces = "application/json;charset=utf-8")
- @ResponseBody
- public Address deleteAddress(@PathVariable(value = "id") long id) {
- return addressService.deleteAddress(id);
- }
-}
diff --git a/rest/src/main/java/io/khasang/ba/controller/CategoryController.java b/rest/src/main/java/io/khasang/ba/controller/CategoryController.java
index 9326387..70c6835 100644
--- a/rest/src/main/java/io/khasang/ba/controller/CategoryController.java
+++ b/rest/src/main/java/io/khasang/ba/controller/CategoryController.java
@@ -3,43 +3,43 @@
import io.khasang.ba.entity.Category;
import io.khasang.ba.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Controller;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.List;
-@Controller
+@RestController
@RequestMapping(value = "/category")
public class CategoryController {
+
@Autowired
private CategoryService categoryService;
- @RequestMapping(value = "/get/all", method = RequestMethod.GET, produces = "application/json;charset=utf-8")
- @ResponseBody
- public List getAll() {
- return categoryService.getAllCategories();
- }
-
- @RequestMapping(value = "/get/{id}", method = RequestMethod.GET, produces = "application/json;charset=utf-8")
- @ResponseBody
- public Category getCategory(@PathVariable(value = "id") long id) {
- return categoryService.getCategoryById(id);
- }
-
- @RequestMapping(value = "/add", method = RequestMethod.POST, produces = "application/json;charset=utf-8")
- @ResponseBody
+ @ResponseStatus(code = HttpStatus.CREATED)
+ @PostMapping(value = "/add", produces = "application/json;charset=utf-8")
public Category addCategory(@RequestBody Category category) {
return categoryService.addCategory(category);
}
- @RequestMapping(value = "/update", method = RequestMethod.PUT, produces = "application/json;charset=utf-8")
- @ResponseBody
+ @GetMapping(value = "/get/{id}", produces = "application/json;charset=utf-8")
+ public ResponseEntity getCategoryById(@PathVariable(value = "id") long id) {
+ Category category = categoryService.getCategoryById(id);
+ return category == null ? ResponseEntity.notFound().build() : ResponseEntity.ok(category);
+ }
+
+ @PutMapping(value = "/update", produces = "application/json;charset=utf-8")
public Category updateCategory(@RequestBody Category category) {
return categoryService.updateCategory(category);
}
- @RequestMapping(value = "/delete/{id}", method = RequestMethod.DELETE, produces = "application/json;charset=utf-8")
- @ResponseBody
+ @GetMapping(value = "/get/all", produces = "application/json;charset=utf-8")
+ public List getAllCategories() {
+ return categoryService.getAllCategories();
+ }
+
+ @ResponseStatus(code = HttpStatus.NO_CONTENT)
+ @DeleteMapping(value = "/delete/{id}", produces = "application/json;charset=utf-8")
public Category deleteCategory(@PathVariable(value = "id") long id) {
return categoryService.deleteCategory(id);
}
diff --git a/rest/src/main/java/io/khasang/ba/controller/CustomerController.java b/rest/src/main/java/io/khasang/ba/controller/CustomerController.java
index c47f5e2..c7aa620 100644
--- a/rest/src/main/java/io/khasang/ba/controller/CustomerController.java
+++ b/rest/src/main/java/io/khasang/ba/controller/CustomerController.java
@@ -3,7 +3,8 @@
import io.khasang.ba.entity.Customer;
import io.khasang.ba.service.CustomerService;
import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Controller;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@@ -11,40 +12,40 @@
/**
* Controller for REST layer of Customer management: provided POST, GET, PUT and DELETE functionality
*/
-@Controller
+@RestController
@RequestMapping(value = "/customer")
+// TODO ControllerAdvice and throwing of an exception in service layer
public class CustomerController {
@Autowired
private CustomerService CustomerService;
- @RequestMapping(value = "/add", method = RequestMethod.POST, produces = "application/json;charset=utf-8")
- @ResponseBody
+ @PostMapping(value = "/add", consumes = "application/json;charset=utf-8")
+ @ResponseStatus(HttpStatus.CREATED)
public Customer addCustomer(@RequestBody Customer newCustomer) {
return CustomerService.addCustomer(newCustomer);
}
- @RequestMapping(value = "/get/{id}", method = RequestMethod.GET, produces = "application/json;charset=utf-8")
- @ResponseBody
- public Customer getCustomerById(@PathVariable(value = "id") long id) {
- return CustomerService.getCustomerById(id);
+ @GetMapping(value = "/get/{id}")
+ public ResponseEntity getCustomerById(@PathVariable(value = "id") long id) {
+ Customer customer = CustomerService.getCustomerById(id);
+
+ return (customer != null) ? ResponseEntity.ok(customer) : ResponseEntity.notFound().build();
}
- @RequestMapping(value = "/update", method = RequestMethod.PUT, produces = "application/json;charset=utf-8")
- @ResponseBody
+ @PutMapping(value = "/update", consumes = "application/json;charset=utf-8")
public Customer updateCustomer(@RequestBody Customer updatedCustomer) {
return CustomerService.updateCustomer(updatedCustomer);
}
- @RequestMapping(value = "/get/all", method = RequestMethod.GET, produces = "application/json;charset=utf-8")
- @ResponseBody
+ @GetMapping(value = "/get/all")
public List getAllCustomers() {
return CustomerService.getAllCustomers();
}
- @RequestMapping(value = "/delete/{id}", method = RequestMethod.DELETE, produces = "application/json;charset=utf-8")
- @ResponseBody
- public Customer deleteCustomer(@PathVariable(value = "id") long id) {
- return CustomerService.deleteCustomer(id);
+ @DeleteMapping(value = "/delete/{id}")
+ @ResponseStatus(HttpStatus.NO_CONTENT)
+ public void deleteCustomer(@PathVariable(value = "id") long id) {
+ CustomerService.deleteCustomer(id);
}
}
diff --git a/rest/src/main/java/io/khasang/ba/controller/CustomerRequestStageNameController.java b/rest/src/main/java/io/khasang/ba/controller/CustomerRequestStageNameController.java
new file mode 100644
index 0000000..0edb67d
--- /dev/null
+++ b/rest/src/main/java/io/khasang/ba/controller/CustomerRequestStageNameController.java
@@ -0,0 +1,54 @@
+package io.khasang.ba.controller;
+
+import io.khasang.ba.entity.CustomerRequestStageName;
+import io.khasang.ba.service.CustomerRequestStageNameService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.List;
+
+/**
+ * Controller for REST layer of CustomerRequestStageName management: provided POST, GET, PUT and DELETE functionality
+ */
+@RestController
+@RequestMapping(value = "/customer_request_stage_name")
+// TODO ControllerAdvice and throwing of an exception in service layer
+public class CustomerRequestStageNameController {
+
+ @Autowired
+ private CustomerRequestStageNameService CustomerRequestStageNameService;
+
+ @PostMapping(value = "/add", consumes = "application/json;charset=utf-8")
+ @ResponseStatus(HttpStatus.CREATED)
+ public CustomerRequestStageName addCustomerRequestStageName(@RequestBody CustomerRequestStageName newCustomerRequestStageName) {
+ return CustomerRequestStageNameService.addCustomerRequestStageName(newCustomerRequestStageName);
+ }
+
+ @GetMapping(value = "/get/{id}")
+ public ResponseEntity getCustomerRequestStageNameById(@PathVariable(value = "id") long id) {
+ CustomerRequestStageName CustomerRequestStageName = CustomerRequestStageNameService.getCustomerRequestStageNameById(id);
+
+ return CustomerRequestStageName != null ?
+ ResponseEntity.ok(CustomerRequestStageName) : ResponseEntity.notFound().build();
+ }
+
+ @PutMapping(value = "/update", consumes = "application/json;charset=utf-8")
+ // TODO Check updating of nonexistent entity
+ public CustomerRequestStageName updateCustomerRequestStageName(@RequestBody CustomerRequestStageName updatedCustomerRequestStageName) {
+ return CustomerRequestStageNameService.updateCustomerRequestStageName(updatedCustomerRequestStageName);
+ }
+
+ @GetMapping(value = "/get/all")
+ public List getAllCustomerRequestStageNames() {
+ return CustomerRequestStageNameService.getAllCustomerRequestStageNames();
+ }
+
+ @DeleteMapping(value = "/delete/{id}")
+ @ResponseStatus(HttpStatus.NO_CONTENT)
+ // TODO Check DELETE non-existent entity
+ public void deleteCustomerRequestStageName(@PathVariable(value = "id") long id) {
+ CustomerRequestStageNameService.deleteCustomerRequestStageName(id);
+ }
+}
diff --git a/rest/src/main/java/io/khasang/ba/controller/OperatorController.java b/rest/src/main/java/io/khasang/ba/controller/OperatorController.java
index ffb3ec8..f5f7ab9 100644
--- a/rest/src/main/java/io/khasang/ba/controller/OperatorController.java
+++ b/rest/src/main/java/io/khasang/ba/controller/OperatorController.java
@@ -3,7 +3,8 @@
import io.khasang.ba.entity.Operator;
import io.khasang.ba.service.OperatorService;
import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Controller;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@@ -11,40 +12,39 @@
/**
* Controller for REST layer of Operator management: provided POST, GET, PUT and DELETE functionality
*/
-@Controller
+@RestController
@RequestMapping(value = "/operator")
public class OperatorController {
@Autowired
private OperatorService operatorService;
- @RequestMapping(value = "/add", method = RequestMethod.POST, produces = "application/json;charset=utf-8")
- @ResponseBody
+ @PostMapping(value = "/add", consumes = "application/json;charset=utf-8")
+ @ResponseStatus(HttpStatus.CREATED)
public Operator addOperator(@RequestBody Operator newOperator) {
return operatorService.addOperator(newOperator);
}
- @RequestMapping(value = "/get/{id}", method = RequestMethod.GET, produces = "application/json;charset=utf-8")
- @ResponseBody
- public Operator getOperatorById(@PathVariable(value = "id") long id) {
- return operatorService.getOperatorById(id);
+ @GetMapping(value = "/get/{id}")
+ public ResponseEntity getOperatorById(@PathVariable(value = "id") long id) {
+ Operator operator = operatorService.getOperatorById(id);
+
+ return (operator != null) ? ResponseEntity.ok(operator) : ResponseEntity.notFound().build();
}
- @RequestMapping(value = "/update", method = RequestMethod.PUT, produces = "application/json;charset=utf-8")
- @ResponseBody
+ @PutMapping(value = "/update", consumes = "application/json;charset=utf-8")
public Operator updateOperator(@RequestBody Operator updatedOperator) {
return operatorService.updateOperator(updatedOperator);
}
- @RequestMapping(value = "/get/all", method = RequestMethod.GET, produces = "application/json;charset=utf-8")
- @ResponseBody
+ @GetMapping(value = "/get/all")
public List getAllOperators() {
return operatorService.getAllOperators();
}
- @RequestMapping(value = "/delete/{id}", method = RequestMethod.DELETE, produces = "application/json;charset=utf-8")
- @ResponseBody
- public Operator deleteOperator(@PathVariable(value = "id") long id) {
- return operatorService.deleteOperator(id);
+ @DeleteMapping(value = "/delete/{id}")
+ @ResponseStatus(HttpStatus.NO_CONTENT)
+ public void deleteOperator(@PathVariable(value = "id") long id) {
+ operatorService.deleteOperator(id);
}
}
diff --git a/rest/src/main/java/io/khasang/ba/controller/PointOfInterestController.java b/rest/src/main/java/io/khasang/ba/controller/PointOfInterestController.java
index ccd8475..cfac0f9 100644
--- a/rest/src/main/java/io/khasang/ba/controller/PointOfInterestController.java
+++ b/rest/src/main/java/io/khasang/ba/controller/PointOfInterestController.java
@@ -3,45 +3,44 @@
import io.khasang.ba.entity.PointOfInterest;
import io.khasang.ba.service.PointOfInterestService;
import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Controller;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.List;
-@Controller
+@RestController
@RequestMapping("/pointOfInterest")
public class PointOfInterestController {
@Autowired
PointOfInterestService pointOfInterestService;
- @RequestMapping(value = "/add", method = RequestMethod.POST, produces = "application/json;charset=utf-8")
- @ResponseBody
+ @ResponseStatus(code = HttpStatus.CREATED)
+ @PostMapping(value = "/add", produces = "application/json;charset=utf-8")
public PointOfInterest addPointOfInterest(@RequestBody PointOfInterest pointOfInterest) {
pointOfInterestService.addPointOfInterest(pointOfInterest);
return pointOfInterest;
}
- @ResponseBody
- @RequestMapping(value = "/get/{id}", method = RequestMethod.GET, produces = "application/json;charset=utf-8")
- public PointOfInterest getPointOfInterestById(@PathVariable(value = "id") long id) {
- return pointOfInterestService.getPointOfInterestById(id);
+ @GetMapping(value = "/get/{id}", produces = "application/json;charset=utf-8")
+ public ResponseEntity getPointOfInterestById(@PathVariable(value = "id") long id) {
+ PointOfInterest pointOfInterest = pointOfInterestService.getPointOfInterestById(id);
+ return pointOfInterest == null ? ResponseEntity.notFound().build() : ResponseEntity.ok(pointOfInterest);
}
- @ResponseBody
- @RequestMapping(value = "/get/all", method = RequestMethod.GET, produces = "application/json;charset=utf-8")
- public List getAllPointOfInterests() {
- return pointOfInterestService.getAllPointOfInterest();
- }
-
- @ResponseBody
- @RequestMapping(value = "/update", method = RequestMethod.PUT, produces = "application/json;charset=utf-8")
+ @PutMapping(value = "/update", produces = "application/json;charset=utf-8")
public PointOfInterest updatePointOfInterest(@RequestBody PointOfInterest pointOfInterest) {
return pointOfInterestService.updatePointOfInterest(pointOfInterest);
}
- @ResponseBody
- @RequestMapping(value = "/delete/{id}", method = RequestMethod.DELETE, produces = "application/json;charset=utf-8")
+ @GetMapping(value = "/get/all", produces = "application/json;charset=utf-8")
+ public List getAllPointOfInterests() {
+ return pointOfInterestService.getAllPointOfInterest();
+ }
+
+ @ResponseStatus(code = HttpStatus.NO_CONTENT)
+ @DeleteMapping(value = "/delete/{id}", produces = "application/json;charset=utf-8")
public PointOfInterest deletePointOfInterest(@PathVariable(value = "id") long id) {
return pointOfInterestService.deletePointOfInterest(id);
}
diff --git a/rest/src/main/java/io/khasang/ba/dao/AddressDao.java b/rest/src/main/java/io/khasang/ba/dao/AddressDao.java
deleted file mode 100644
index a7ecf61..0000000
--- a/rest/src/main/java/io/khasang/ba/dao/AddressDao.java
+++ /dev/null
@@ -1,6 +0,0 @@
-package io.khasang.ba.dao;
-
-import io.khasang.ba.entity.Address;
-
-public interface AddressDao extends BasicDao {
-}
diff --git a/rest/src/main/java/io/khasang/ba/dao/CustomerRequestStageNameDao.java b/rest/src/main/java/io/khasang/ba/dao/CustomerRequestStageNameDao.java
new file mode 100644
index 0000000..c484ee1
--- /dev/null
+++ b/rest/src/main/java/io/khasang/ba/dao/CustomerRequestStageNameDao.java
@@ -0,0 +1,7 @@
+package io.khasang.ba.dao;
+
+
+import io.khasang.ba.entity.CustomerRequestStageName;
+
+public interface CustomerRequestStageNameDao extends BasicDao {
+}
\ No newline at end of file
diff --git a/rest/src/main/java/io/khasang/ba/dao/impl/AddressDaoImpl.java b/rest/src/main/java/io/khasang/ba/dao/impl/AddressDaoImpl.java
deleted file mode 100644
index e7bf56f..0000000
--- a/rest/src/main/java/io/khasang/ba/dao/impl/AddressDaoImpl.java
+++ /dev/null
@@ -1,10 +0,0 @@
-package io.khasang.ba.dao.impl;
-
-import io.khasang.ba.dao.AddressDao;
-import io.khasang.ba.entity.Address;
-
-public class AddressDaoImpl extends BasicDaoImpl implements AddressDao {
- public AddressDaoImpl(Class entityClass) {
- super(entityClass);
- }
-}
diff --git a/rest/src/main/java/io/khasang/ba/dao/impl/CustomerRequestStageNameDaoImpl.java b/rest/src/main/java/io/khasang/ba/dao/impl/CustomerRequestStageNameDaoImpl.java
new file mode 100644
index 0000000..6458ca8
--- /dev/null
+++ b/rest/src/main/java/io/khasang/ba/dao/impl/CustomerRequestStageNameDaoImpl.java
@@ -0,0 +1,11 @@
+package io.khasang.ba.dao.impl;
+
+import io.khasang.ba.dao.CustomerRequestStageNameDao;
+import io.khasang.ba.entity.CustomerRequestStageName;
+
+public class CustomerRequestStageNameDaoImpl extends BasicDaoImpl
+ implements CustomerRequestStageNameDao {
+ public CustomerRequestStageNameDaoImpl(Class entityClass) {
+ super(entityClass);
+ }
+}
\ No newline at end of file
diff --git a/rest/src/main/java/io/khasang/ba/entity/Address.java b/rest/src/main/java/io/khasang/ba/entity/Address.java
deleted file mode 100644
index fc87f5e..0000000
--- a/rest/src/main/java/io/khasang/ba/entity/Address.java
+++ /dev/null
@@ -1,150 +0,0 @@
-package io.khasang.ba.entity;
-
-import org.hibernate.annotations.ColumnDefault;
-
-import javax.persistence.*;
-import javax.validation.constraints.NotNull;
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * This entity storages address something
- * minimal requariment on input is City, Street and Hause.
- */
-
-@Entity
-public class Address {
- @Id
- @GeneratedValue(strategy = GenerationType.AUTO)
- private long id;
-
- private String region;
-
- @NotNull
- private String city;
-
- @NotNull
- private String street;
- private int postcode;
-
- @NotNull
- private String hause;
-
- private String office;
-
- //Geographic coordinates latitude
- @ColumnDefault(value = "0.000000")
- private double latitude;
-
- //Geographic coordinates longitude
- @ColumnDefault(value = "0.000000")
- private double longitude;
-
- public Address() {
- }
-
- public Address(String region, String city, String street, int postcode, String hause) {
- this.region = region;
- this.city = city;
- this.street = street;
- this.postcode = postcode;
- this.hause = hause;
- }
-
- public Address(String city, String street, String hause, String office) {
- this.city = city;
- this.street = street;
- this.hause = hause;
- this.office = office;
- }
-
- public Address(String region, String city, String street, int postcode, String hause, String office,
- double latitude, double longitude) {
- this.region = region;
- this.city = city;
- this.street = street;
- this.postcode = postcode;
- this.hause = hause;
- this.office = office;
- this.latitude = latitude;
- this.longitude = longitude;
- }
-
- public Address(String city, String street, String hause) {
- this.city = city;
- this.street = street;
- this.hause = hause;
- }
-
- public long getId() {
- return id;
- }
-
- public void setId(long id) {
- this.id = id;
- }
-
- public String getRegion() {
- return region;
- }
-
- public void setRegion(String region) {
- this.region = region;
- }
-
- public String getCity() {
- return city;
- }
-
- public void setCity(String city) {
- this.city = city;
- }
-
- public String getStreet() {
- return street;
- }
-
- public void setStreet(String street) {
- this.street = street;
- }
-
- public int getPostcode() {
- return postcode;
- }
-
- public void setPostcode(int postcode) {
- this.postcode = postcode;
- }
-
- public String getHause() {
- return hause;
- }
-
- public void setHause(String hause) {
- this.hause = hause;
- }
-
- public String getOffice() {
- return office;
- }
-
- public void setOffice(String office) {
- this.office = office;
- }
-
- public double getLatitude() {
- return latitude;
- }
-
- public void setLatitude(double latitude) {
- this.latitude = latitude;
- }
-
- public double getLongitude() {
- return longitude;
- }
-
- public void setLongitude(double longitude) {
- this.longitude = longitude;
- }
-}
diff --git a/rest/src/main/java/io/khasang/ba/entity/Category.java b/rest/src/main/java/io/khasang/ba/entity/Category.java
index 60180e3..d7ea612 100644
--- a/rest/src/main/java/io/khasang/ba/entity/Category.java
+++ b/rest/src/main/java/io/khasang/ba/entity/Category.java
@@ -1,40 +1,28 @@
package io.khasang.ba.entity;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import org.hibernate.annotations.NaturalId;
+import org.hibernate.validator.constraints.NotBlank;
+
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
-import javax.validation.constraints.NotNull;
+
+/**
+ * Entity Category include some type as supermarket, restaurants, e.g.
+ */
@Entity
+@Data
+@NoArgsConstructor
public class Category {
@Id
- @GeneratedValue(strategy = GenerationType.AUTO)
- private long id;
+ @GeneratedValue(strategy = GenerationType.IDENTITY)
+ private Long id;
- @NotNull
+ @NotBlank
+ @NaturalId
private String name;
-
- public Category() {
- }
-
- public Category(String name) {
- this.name = name;
- }
-
- public long getId() {
- return id;
- }
-
- public void setId(long id) {
- this.id = id;
- }
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-}
+}
\ No newline at end of file
diff --git a/rest/src/main/java/io/khasang/ba/entity/CustomerRequestStageName.java b/rest/src/main/java/io/khasang/ba/entity/CustomerRequestStageName.java
new file mode 100644
index 0000000..35e351e
--- /dev/null
+++ b/rest/src/main/java/io/khasang/ba/entity/CustomerRequestStageName.java
@@ -0,0 +1,30 @@
+package io.khasang.ba.entity;
+
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import org.hibernate.annotations.NaturalId;
+import org.hibernate.validator.constraints.NotBlank;
+
+import javax.persistence.*;
+
+/**
+ * A customer request stage name entity class. Allows to group customer request stages by names, i.e.
+ * each {@link CustomerRequestStage} has a relation with this entity.
+ */
+
+@Data
+@Entity
+@Table(name = "customer_request_stage_names")
+public class CustomerRequestStageName {
+
+ @Id
+ @GeneratedValue(strategy = GenerationType.AUTO)
+ @EqualsAndHashCode.Exclude
+ private Long id;
+
+ @NotBlank
+ @NaturalId(mutable = true)
+ private String name;
+
+ private String description;
+}
diff --git a/rest/src/main/java/io/khasang/ba/entity/Operator.java b/rest/src/main/java/io/khasang/ba/entity/Operator.java
index 8c13672..32da468 100644
--- a/rest/src/main/java/io/khasang/ba/entity/Operator.java
+++ b/rest/src/main/java/io/khasang/ba/entity/Operator.java
@@ -1,101 +1,41 @@
package io.khasang.ba.entity;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
import org.hibernate.annotations.NaturalId;
-import org.hibernate.validator.constraints.NotEmpty;
+import org.hibernate.validator.constraints.NotBlank;
import javax.persistence.*;
import java.time.LocalDateTime;
-import java.util.Objects;
/**
- * Operator entity class. Operators in are users, handling customers' requests
+ * Operator entity class. Operators are users, handling customers' requests
*/
+@Data
@Entity
@Table(name = "operators")
public class Operator {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
+ @EqualsAndHashCode.Exclude
private Long id;
- @NotEmpty
+ @NotBlank
@NaturalId
private String login;
@Column(name = "registration_date", columnDefinition = "TIMESTAMP")
+ @EqualsAndHashCode.Exclude
private LocalDateTime registrationTimestamp;
- @NotEmpty
+ @NotBlank
private String password;
- @NotEmpty
+ @NotBlank
@Column(unique = true)
private String email;
@Embedded
private OperatorInformation operatorInformation;
-
- public Long getId() {
- return id;
- }
-
- public void setId(Long id) {
- this.id = id;
- }
-
- public String getLogin() {
- return login;
- }
-
- public void setLogin(String login) {
- this.login = login;
- }
-
- public LocalDateTime getRegistrationTimestamp() {
- return registrationTimestamp;
- }
-
- public void setRegistrationTimestamp(LocalDateTime registrationTimestamp) {
- this.registrationTimestamp = registrationTimestamp;
- }
-
- public String getPassword() {
- return password;
- }
-
- public void setPassword(String password) {
- this.password = password;
- }
-
- public String getEmail() {
- return email;
- }
-
- public void setEmail(String email) {
- this.email = email;
- }
-
- public OperatorInformation getOperatorInformation() {
- return operatorInformation;
- }
-
- public void setOperatorInformation(OperatorInformation operatorInformation) {
- this.operatorInformation = operatorInformation;
- }
-
- @Override
- public boolean equals(Object o) {
- if (this == o) return true;
- if (o == null || getClass() != o.getClass()) return false;
- Operator operator = (Operator) o;
- return Objects.equals(login, operator.login) &&
- Objects.equals(password, operator.password) &&
- Objects.equals(email, operator.email) &&
- Objects.equals(operatorInformation, operator.operatorInformation);
- }
-
- @Override
- public int hashCode() {
- return Objects.hash(login, password, email, operatorInformation);
- }
}
diff --git a/rest/src/main/java/io/khasang/ba/entity/OperatorInformation.java b/rest/src/main/java/io/khasang/ba/entity/OperatorInformation.java
index 11e7355..01dcb39 100644
--- a/rest/src/main/java/io/khasang/ba/entity/OperatorInformation.java
+++ b/rest/src/main/java/io/khasang/ba/entity/OperatorInformation.java
@@ -1,12 +1,14 @@
package io.khasang.ba.entity;
+import lombok.Data;
+
import javax.persistence.Embeddable;
import java.time.LocalDate;
-import java.util.Objects;
/**
* Embeddable class with common information about operator, all field can be nullable and non unique
*/
+@Data
@Embeddable
public class OperatorInformation {
@@ -19,61 +21,4 @@ public class OperatorInformation {
private String city;
private String about;
-
- public String getFullName() {
- return fullName;
- }
-
- public void setFullName(String fullName) {
- this.fullName = fullName;
- }
-
- public LocalDate getBirthDate() {
- return birthDate;
- }
-
- public void setBirthDate(LocalDate birthDate) {
- this.birthDate = birthDate;
- }
-
- public String getCountry() {
- return country;
- }
-
- public void setCountry(String country) {
- this.country = country;
- }
-
- public String getCity() {
- return city;
- }
-
- public void setCity(String city) {
- this.city = city;
- }
-
- public String getAbout() {
- return about;
- }
-
- public void setAbout(String about) {
- this.about = about;
- }
-
- @Override
- public boolean equals(Object o) {
- if (this == o) return true;
- if (o == null || getClass() != o.getClass()) return false;
- OperatorInformation that = (OperatorInformation) o;
- return Objects.equals(fullName, that.fullName) &&
- Objects.equals(birthDate, that.birthDate) &&
- Objects.equals(country, that.country) &&
- Objects.equals(city, that.city) &&
- Objects.equals(about, that.about);
- }
-
- @Override
- public int hashCode() {
- return Objects.hash(fullName, birthDate, country, city, about);
- }
}
diff --git a/rest/src/main/java/io/khasang/ba/entity/PointOfInterest.java b/rest/src/main/java/io/khasang/ba/entity/PointOfInterest.java
index 8975000..c77b767 100644
--- a/rest/src/main/java/io/khasang/ba/entity/PointOfInterest.java
+++ b/rest/src/main/java/io/khasang/ba/entity/PointOfInterest.java
@@ -1,7 +1,11 @@
package io.khasang.ba.entity;
import com.fasterxml.jackson.annotation.JsonFormat;
+import io.khasang.ba.entity.embeddable.Address;
+import lombok.Data;
+import lombok.NoArgsConstructor;
import org.hibernate.annotations.ColumnDefault;
+import org.hibernate.validator.constraints.NotBlank;
import javax.persistence.*;
import java.time.LocalTime;
@@ -11,96 +15,30 @@
* include category etc.
*/
@Entity
-@Table(name = "pointsOfInterest")
+@Table(name = "points_of_interest")
+@Data
+@NoArgsConstructor
public class PointOfInterest {
@Id
- @GeneratedValue(strategy = GenerationType.AUTO)
- private long id;
+ @GeneratedValue(strategy = GenerationType.IDENTITY)
+ private Long id;
+ @NotBlank
private String name;
@ColumnDefault(value = "'unknown'")
private String category;
- @Column(columnDefinition = "TIME")
+ @Column(name = "start_work", columnDefinition = "TIME")
@ColumnDefault(value = "'00:00:00'")
@JsonFormat(pattern = "HH:mm")
private LocalTime startWork;
@ColumnDefault(value = "0")
- private int workTime;
- private String address;
+ @Column(name = "work_time")
+ private Integer workTime;
- //Geographic coordinates latitude
- @ColumnDefault(value = "0.000000")
- private double latitude;
-
- //Geographic coordinates longitude
- @ColumnDefault(value = "0.000000")
- private double longitude;
-
- public long getId() {
- return id;
- }
-
- public void setId(long id) {
- this.id = id;
- }
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- public String getCategory() {
- return category;
- }
-
- public void setCategory(String category) {
- this.category = category;
- }
-
- public LocalTime getStartWork() {
- return startWork;
- }
-
- public void setStartWork(LocalTime startWork) {
- this.startWork = startWork;
- }
-
- public int getWorkTime() {
- return workTime;
- }
-
- public void setWorkTime(int workTime) {
- this.workTime = workTime >= 0 ? workTime : 0;
- }
-
- public String getAddress() {
- return address;
- }
-
- public void setAddress(String address) {
- this.address = address;
- }
-
- public double getLatitude() {
- return latitude;
- }
-
- public void setLatitude(double latitude) {
- this.latitude = latitude;
- }
-
- public double getLongitude() {
- return longitude;
- }
-
- public void setLongitude(double longitude) {
- this.longitude = longitude;
- }
+ @Embedded
+ private Address address;
}
diff --git a/rest/src/main/java/io/khasang/ba/entity/embeddable/Address.java b/rest/src/main/java/io/khasang/ba/entity/embeddable/Address.java
new file mode 100644
index 0000000..3eabc28
--- /dev/null
+++ b/rest/src/main/java/io/khasang/ba/entity/embeddable/Address.java
@@ -0,0 +1,39 @@
+package io.khasang.ba.entity.embeddable;
+
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import org.hibernate.annotations.ColumnDefault;
+import org.hibernate.validator.constraints.NotBlank;
+
+import javax.persistence.Embeddable;
+
+/**
+ * This class storages address something
+ * minimal requariment on input is City, Street and Build.
+ */
+
+@Embeddable
+@Data
+@NoArgsConstructor
+public class Address {
+ private String region;
+
+ @NotBlank
+ private String city;
+
+ @NotBlank
+ private String street;
+
+ private String postcode;
+
+ @NotBlank
+ private String build;
+
+ private String room;
+
+ @ColumnDefault(value = "0.000000")
+ private Double latitude;
+
+ @ColumnDefault(value = "0.000000")
+ private Double longitude;
+}
diff --git a/rest/src/main/java/io/khasang/ba/service/AddressService.java b/rest/src/main/java/io/khasang/ba/service/AddressService.java
deleted file mode 100644
index 754dd22..0000000
--- a/rest/src/main/java/io/khasang/ba/service/AddressService.java
+++ /dev/null
@@ -1,46 +0,0 @@
-package io.khasang.ba.service;
-
-import io.khasang.ba.entity.Address;
-
-import java.util.List;
-
-public interface AddressService {
- /**
- * method for add address
- *
- * @param address = address for adding
- * @return created address
- */
- Address addAddress(Address address);
-
- /**
- * method for getting address by specific id
- *
- * @param id - address
- * @return address by id
- */
- Address getAddressById(long id);
-
- /**
- * method gor getting all addresses
- *
- * @return all addresses
- */
- List getAllAddresses();
-
- /**
- * method for update address
- *
- * @param address - address update
- * @return updated address
- */
- Address updateAddress(Address address);
-
- /**
- * method for delete address by id
- *
- * @param id - address id for delete
- * @return deleted address
- */
- Address deleteAddress(long id);
-}
diff --git a/rest/src/main/java/io/khasang/ba/service/CustomerRequestStageNameService.java b/rest/src/main/java/io/khasang/ba/service/CustomerRequestStageNameService.java
new file mode 100644
index 0000000..976bca7
--- /dev/null
+++ b/rest/src/main/java/io/khasang/ba/service/CustomerRequestStageNameService.java
@@ -0,0 +1,50 @@
+package io.khasang.ba.service;
+
+import io.khasang.ba.entity.CustomerRequestStageName;
+
+import java.util.List;
+
+/**
+ * Service layer interface for {@link CustomerRequestStageName} management
+ */
+public interface CustomerRequestStageNameService {
+
+ /**
+ * Add new CustomerRequestStageName
+ *
+ * @param newCustomerRequestStageName New instance of CustomerRequestStageName
+ * @return Added {@link CustomerRequestStageName} instance
+ */
+ CustomerRequestStageName addCustomerRequestStageName(CustomerRequestStageName newCustomerRequestStageName);
+
+ /**
+ * Get CustomerRequestStageName by id
+ *
+ * @param id Identifier of the desired CustomerRequestStageName
+ * @return Found {@link CustomerRequestStageName} instance
+ */
+ CustomerRequestStageName getCustomerRequestStageNameById(long id);
+
+ /**
+ * Update existing CustomerRequestStageName with new instance
+ *
+ * @param updatedCustomerRequestStageName Updated CustomerRequestStageName instance
+ * @return Updated {@link CustomerRequestStageName} instance
+ */
+ CustomerRequestStageName updateCustomerRequestStageName(CustomerRequestStageName updatedCustomerRequestStageName);
+
+ /**
+ * Get all CustomerRequestStageNames
+ *
+ * @return {@link List} instance of all CustomerRequestStageNames
+ */
+ List getAllCustomerRequestStageNames();
+
+ /**
+ * Delete CustomerRequestStageName by id
+ *
+ * @param id Identifier of the CustomerRequestStageName which should be deleted
+ * @return Deleted {@link CustomerRequestStageName} instance
+ */
+ CustomerRequestStageName deleteCustomerRequestStageName(long id);
+}
\ No newline at end of file
diff --git a/rest/src/main/java/io/khasang/ba/service/impl/AddressServiceImpl.java b/rest/src/main/java/io/khasang/ba/service/impl/AddressServiceImpl.java
deleted file mode 100644
index fe65369..0000000
--- a/rest/src/main/java/io/khasang/ba/service/impl/AddressServiceImpl.java
+++ /dev/null
@@ -1,40 +0,0 @@
-package io.khasang.ba.service.impl;
-
-import io.khasang.ba.dao.AddressDao;
-import io.khasang.ba.entity.Address;
-import io.khasang.ba.service.AddressService;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Service;
-
-import java.util.List;
-
-@Service
-public class AddressServiceImpl implements AddressService {
- @Autowired
- AddressDao addressDao;
-
- @Override
- public Address addAddress(Address address) {
- return addressDao.add(address);
- }
-
- @Override
- public Address getAddressById(long id) {
- return addressDao.getById(id);
- }
-
- @Override
- public List getAllAddresses() {
- return addressDao.getAll();
- }
-
- @Override
- public Address updateAddress(Address address) {
- return addressDao.update(address);
- }
-
- @Override
- public Address deleteAddress(long id) {
- return addressDao.delete(this.getAddressById(id));
- }
-}
diff --git a/rest/src/main/java/io/khasang/ba/service/impl/CustomerRequestStageNameServiceImpl.java b/rest/src/main/java/io/khasang/ba/service/impl/CustomerRequestStageNameServiceImpl.java
new file mode 100644
index 0000000..44fff95
--- /dev/null
+++ b/rest/src/main/java/io/khasang/ba/service/impl/CustomerRequestStageNameServiceImpl.java
@@ -0,0 +1,73 @@
+package io.khasang.ba.service.impl;
+
+import io.khasang.ba.dao.CustomerRequestStageNameDao;
+import io.khasang.ba.entity.CustomerRequestStageName;
+import io.khasang.ba.service.CustomerRequestStageNameService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+
+/**
+ * Implementation of {@link CustomerRequestStageNameService} based on DAO-layer utilization
+ */
+@Service
+public class CustomerRequestStageNameServiceImpl implements CustomerRequestStageNameService {
+
+ @Autowired
+ private CustomerRequestStageNameDao CustomerRequestStageNameDao;
+
+ /**
+ * Add new CustomerRequestStageName
+ *
+ * @param newCustomerRequestStageName New instance of CustomerRequestStageName
+ * @return Added {@link CustomerRequestStageName} instance
+ */
+ @Override
+ public CustomerRequestStageName addCustomerRequestStageName(CustomerRequestStageName newCustomerRequestStageName) {
+ return CustomerRequestStageNameDao.add(newCustomerRequestStageName);
+ }
+
+ /**
+ * Get CustomerRequestStageName by id
+ *
+ * @param id Identifier of the desired CustomerRequestStageName
+ * @return Found {@link CustomerRequestStageName} instance
+ */
+ @Override
+ public CustomerRequestStageName getCustomerRequestStageNameById(long id) {
+ return CustomerRequestStageNameDao.getById(id);
+ }
+
+ /**
+ * Update existing CustomerRequestStageName with new instance
+ *
+ * @param updatedCustomerRequestStageName Updated CustomerRequestStageName instance
+ * @return Updated {@link CustomerRequestStageName} instance
+ */
+ @Override
+ public CustomerRequestStageName updateCustomerRequestStageName(CustomerRequestStageName updatedCustomerRequestStageName) {
+ return CustomerRequestStageNameDao.update(updatedCustomerRequestStageName);
+ }
+
+ /**
+ * Get all CustomerRequestStageNames
+ *
+ * @return {@link List} instance of all CustomerRequestStageNames
+ */
+ @Override
+ public List getAllCustomerRequestStageNames() {
+ return CustomerRequestStageNameDao.getAll();
+ }
+
+ /**
+ * Delete CustomerRequestStageName by id
+ *
+ * @param id Identifier of the CustomerRequestStageName which should be deleted
+ * @return Deleted {@link CustomerRequestStageName} instance
+ */
+ @Override
+ public CustomerRequestStageName deleteCustomerRequestStageName(long id) {
+ return CustomerRequestStageNameDao.delete(getCustomerRequestStageNameById(id));
+ }
+}