diff --git a/.idea/libraries/Maven__com_fasterxml_jackson_core_jackson_core_2_9_2.xml b/.idea/libraries/Maven__com_fasterxml_jackson_core_jackson_core_2_8_10.xml
similarity index 65%
rename from .idea/libraries/Maven__com_fasterxml_jackson_core_jackson_core_2_9_2.xml
rename to .idea/libraries/Maven__com_fasterxml_jackson_core_jackson_core_2_8_10.xml
index f0f5ccb..5d9d662 100644
--- a/.idea/libraries/Maven__com_fasterxml_jackson_core_jackson_core_2_9_2.xml
+++ b/.idea/libraries/Maven__com_fasterxml_jackson_core_jackson_core_2_8_10.xml
@@ -1,13 +1,13 @@
-
+
-
+
-
+
-
+
\ No newline at end of file
diff --git a/.idea/libraries/Maven__com_fasterxml_jackson_core_jackson_databind_2_9_2.xml b/.idea/libraries/Maven__com_fasterxml_jackson_core_jackson_databind_2_8_10.xml
similarity index 62%
rename from .idea/libraries/Maven__com_fasterxml_jackson_core_jackson_databind_2_9_2.xml
rename to .idea/libraries/Maven__com_fasterxml_jackson_core_jackson_databind_2_8_10.xml
index 25753a3..df5cb22 100644
--- a/.idea/libraries/Maven__com_fasterxml_jackson_core_jackson_databind_2_9_2.xml
+++ b/.idea/libraries/Maven__com_fasterxml_jackson_core_jackson_databind_2_8_10.xml
@@ -1,13 +1,13 @@
-
+
-
+
-
+
-
+
\ No newline at end of file
diff --git a/.idea/libraries/Maven__com_fasterxml_jackson_dataformat_jackson_dataformat_json_unknown.xml b/.idea/libraries/Maven__com_fasterxml_jackson_dataformat_jackson_dataformat_json_unknown.xml
new file mode 100644
index 0000000..a16e4b7
--- /dev/null
+++ b/.idea/libraries/Maven__com_fasterxml_jackson_dataformat_jackson_dataformat_json_unknown.xml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/libraries/Maven__org_atteo_evo_inflector_1_2_2.xml b/.idea/libraries/Maven__org_atteo_evo_inflector_1_2_2.xml
new file mode 100644
index 0000000..2dde355
--- /dev/null
+++ b/.idea/libraries/Maven__org_atteo_evo_inflector_1_2_2.xml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/libraries/Maven__org_springframework_boot_spring_boot_starter_data_rest_1_5_9_RELEASE.xml b/.idea/libraries/Maven__org_springframework_boot_spring_boot_starter_data_rest_1_5_9_RELEASE.xml
new file mode 100644
index 0000000..33960a7
--- /dev/null
+++ b/.idea/libraries/Maven__org_springframework_boot_spring_boot_starter_data_rest_1_5_9_RELEASE.xml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/libraries/Maven__org_springframework_data_spring_data_commons_1_13_9_RELEASE.xml b/.idea/libraries/Maven__org_springframework_data_spring_data_commons_1_13_9_RELEASE.xml
new file mode 100644
index 0000000..f87de9f
--- /dev/null
+++ b/.idea/libraries/Maven__org_springframework_data_spring_data_commons_1_13_9_RELEASE.xml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/libraries/Maven__org_springframework_data_spring_data_rest_core_2_6_9_RELEASE.xml b/.idea/libraries/Maven__org_springframework_data_spring_data_rest_core_2_6_9_RELEASE.xml
new file mode 100644
index 0000000..3816e08
--- /dev/null
+++ b/.idea/libraries/Maven__org_springframework_data_spring_data_rest_core_2_6_9_RELEASE.xml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/libraries/Maven__org_springframework_data_spring_data_rest_webmvc_2_6_9_RELEASE.xml b/.idea/libraries/Maven__org_springframework_data_spring_data_rest_webmvc_2_6_9_RELEASE.xml
new file mode 100644
index 0000000..43e6a71
--- /dev/null
+++ b/.idea/libraries/Maven__org_springframework_data_spring_data_rest_webmvc_2_6_9_RELEASE.xml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/libraries/Maven__org_springframework_hateoas_spring_hateoas_0_23_0_RELEASE.xml b/.idea/libraries/Maven__org_springframework_hateoas_spring_hateoas_0_23_0_RELEASE.xml
new file mode 100644
index 0000000..92e7f9f
--- /dev/null
+++ b/.idea/libraries/Maven__org_springframework_hateoas_spring_hateoas_0_23_0_RELEASE.xml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/libraries/Maven__org_springframework_plugin_spring_plugin_core_1_2_0_RELEASE.xml b/.idea/libraries/Maven__org_springframework_plugin_spring_plugin_core_1_2_0_RELEASE.xml
new file mode 100644
index 0000000..fbc0452
--- /dev/null
+++ b/.idea/libraries/Maven__org_springframework_plugin_spring_plugin_core_1_2_0_RELEASE.xml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/libraries/Maven__org_springframework_spring_tx_4_3_13_RELEASE.xml b/.idea/libraries/Maven__org_springframework_spring_tx_4_3_13_RELEASE.xml
new file mode 100644
index 0000000..d56e28f
--- /dev/null
+++ b/.idea/libraries/Maven__org_springframework_spring_tx_4_3_13_RELEASE.xml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/config.properties b/config.properties
index e08a733..a62d299 100644
--- a/config.properties
+++ b/config.properties
@@ -1,4 +1,4 @@
#Rest server config
-#Mon Dec 04 22:58:15 KRAT 2017
-port=8080
+#Tue Dec 05 21:32:53 KRAT 2017
+port=8090
url=http\://localhost
diff --git a/pom.xml b/pom.xml
index 3762c51..5c95db8 100644
--- a/pom.xml
+++ b/pom.xml
@@ -101,23 +101,32 @@
org.springframework.boot
- spring-boot-starter-web
+ spring-boot-starter
-
org.springframework.boot
spring-boot-starter-test
test
+
+ org.springframework.boot
+ spring-boot-starter-web
+
+
+ org.springframework.boot
+ spring-boot-starter-data-rest
+
com.fasterxml.jackson.core
jackson-core
- 2.9.2
com.fasterxml.jackson.core
jackson-databind
- 2.9.2
+
+
+ com.fasterxml.jackson.dataformat
+ jackson-dataformat-json
\ No newline at end of file
diff --git a/restClient.iml b/restClient.iml
index 67ea48e..a2c3fce 100644
--- a/restClient.iml
+++ b/restClient.iml
@@ -11,9 +11,9 @@
-
+
@@ -21,22 +21,8 @@
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -53,10 +39,33 @@
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/main/java/ru/cft/task/restClient/ConfigController.java b/src/main/java/ru/cft/task/restClient/ConfigController.java
index 16583ca..01b92c6 100644
--- a/src/main/java/ru/cft/task/restClient/ConfigController.java
+++ b/src/main/java/ru/cft/task/restClient/ConfigController.java
@@ -79,4 +79,8 @@ public class ConfigController {
Stage stage = (Stage) cancel.getScene().getWindow();
stage.close();
}
+
+ public static String getConfigFile() {
+ return CONF_FILE;
+ }
}
diff --git a/src/main/java/ru/cft/task/restClient/EmailRecord.java b/src/main/java/ru/cft/task/restClient/EmailRecord.java
index 32eda96..2a9ea09 100644
--- a/src/main/java/ru/cft/task/restClient/EmailRecord.java
+++ b/src/main/java/ru/cft/task/restClient/EmailRecord.java
@@ -5,6 +5,9 @@ public class EmailRecord {
private String name;
private String email;
+ public EmailRecord() {
+ }
+
public EmailRecord(long id, String name, String email) {
this.id = id;
this.name = name;
diff --git a/src/main/java/ru/cft/task/restClient/MainController.java b/src/main/java/ru/cft/task/restClient/MainController.java
index b6db02a..32d2248 100644
--- a/src/main/java/ru/cft/task/restClient/MainController.java
+++ b/src/main/java/ru/cft/task/restClient/MainController.java
@@ -3,7 +3,9 @@ package ru.cft.task.restClient;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
+import javafx.scene.control.Button;
import javafx.scene.control.MenuItem;
+import javafx.scene.control.TextField;
import javafx.stage.Modality;
import javafx.stage.Stage;
@@ -36,7 +38,7 @@ public class MainController {
System.exit(0);
}
- private Stage showModal(String fxml, String title) {
+ private void showModal(String fxml, String title) {
Stage stage = null;
try {
Scene scene = new Scene(FXMLLoader.load(getClass().getResource(fxml)));
@@ -47,36 +49,29 @@ public class MainController {
stage.setTitle(title);
stage.initOwner(mainStage);
stage.initModality(Modality.APPLICATION_MODAL);
- return stage;
+ stage.showAndWait();
} catch (IOException e) {
Utils.showAlert("error", e.getMessage());
- } finally {
- return stage;
}
}
public void showServerConfig() {
- Stage config = showModal("/config.fxml", srv_config.getText());
- config.showAndWait();
+ showModal("/config.fxml", srv_config.getText());
}
public void createAction() {
- Stage cr = showModal("/form.fxml", create.getText());
- cr.showAndWait();
+ showModal("/form_create.fxml", create.getText());
}
public void readAction() {
- Stage rd = showModal("/form.fxml", read.getText());
- rd.showAndWait();
+ showModal("/form_read.fxml", read.getText());
}
public void updateAction() {
- Stage upd = showModal("/form.fxml", update.getText());
- upd.showAndWait();
+ showModal("/form_update.fxml", update.getText());
}
public void deleteAction() {
- Stage dlt = showModal("/form.fxml", delete.getText());
- dlt.showAndWait();
+ showModal("/form_delete.fxml", delete.getText());
}
}
\ No newline at end of file
diff --git a/src/main/java/ru/cft/task/restClient/RestActionsController.java b/src/main/java/ru/cft/task/restClient/RestActionsController.java
index ca5e41e..d5f2fa2 100644
--- a/src/main/java/ru/cft/task/restClient/RestActionsController.java
+++ b/src/main/java/ru/cft/task/restClient/RestActionsController.java
@@ -4,6 +4,14 @@ import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.TextField;
import javafx.stage.Stage;
+import org.springframework.http.*;
+import org.springframework.web.client.RestClientException;
+import org.springframework.web.client.RestTemplate;
+
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Properties;
public class RestActionsController {
@FXML
@@ -18,11 +26,81 @@ public class RestActionsController {
@FXML
private Button cancel;
- @FXML
- private Button doAction;
+ private String getRestServerUrl() {
+ Properties props = new Properties();
+ InputStream conf_file = null;
+ String url = "";
+ try {
+ conf_file = new FileInputStream(ConfigController.getConfigFile());
+ props.load(conf_file);
+ url = props.getProperty("url", "http://localhost");
+ url += ":" + props.getProperty("port", "8080");
+ } catch (IOException ex) {
+ Utils.showAlert("error", ex.getMessage());
+ } finally {
+ if (conf_file != null) {
+ try {
+ conf_file.close();
+ } catch (IOException ex) {
+ Utils.showAlert("error", ex.getMessage());
+ }
+ }
+ return url;
+ }
+ }
public void cancelAction() {
Stage stage = (Stage) cancel.getScene().getWindow();
stage.close();
}
+
+ public void createAction() {
+ EmailRecord emailRecord = new EmailRecord();
+ emailRecord.setName("Test");
+ emailRecord.setEmail("aaa");
+
+ RestTemplate restTemplate = new RestTemplate();
+ HttpEntity request = new HttpEntity<>(emailRecord);
+ try {
+ ResponseEntity response = restTemplate.exchange(getRestServerUrl(), HttpMethod.POST, request, EmailRecord.class);
+ System.out.println(response.getStatusCode());
+ if (response.getStatusCode() == HttpStatus.OK) {
+ EmailRecord er = response.getBody();
+ id.setText(String.valueOf(er.getId()));
+ }
+ } catch (RestClientException ex) {
+ Utils.showAlert("error", ex.getMessage());
+ }
+ }
+
+ public void readAction() {
+ HttpHeaders headers = new HttpHeaders();
+ headers.add("Accept", MediaType.APPLICATION_JSON_VALUE);
+ headers.setContentType(MediaType.APPLICATION_JSON);
+ headers.set("id", id.getText());
+ headers.set("name", name.getText());
+ headers.set("email", email.getText());
+
+ RestTemplate restTemplate = new RestTemplate();
+ HttpEntity entity = new HttpEntity<>(headers);
+ try {
+ ResponseEntity result = restTemplate.exchange(getRestServerUrl(), HttpMethod.GET, entity, EmailRecord.class);
+ if (result.getStatusCode() == HttpStatus.OK) {
+ EmailRecord emailRecord = result.getBody();
+ id.setText(String.valueOf(emailRecord.getId()));
+ name.setText(emailRecord.getName());
+ email.setText(emailRecord.getEmail());
+ }
+ } catch (RestClientException ex) {
+ Utils.showAlert("error", ex.getMessage());
+ }
+ }
+
+ public void updateAction() {
+
+ }
+
+ public void deleteAction() {
+
+ }
}
diff --git a/src/main/java/ru/cft/task/restClient/RestErrorHandler.java b/src/main/java/ru/cft/task/restClient/RestErrorHandler.java
new file mode 100644
index 0000000..628ea74
--- /dev/null
+++ b/src/main/java/ru/cft/task/restClient/RestErrorHandler.java
@@ -0,0 +1,12 @@
+package ru.cft.task.restClient;
+
+import org.springframework.http.client.ClientHttpResponse;
+import org.springframework.web.client.DefaultResponseErrorHandler;
+
+import java.io.IOException;
+
+public class RestErrorHandler extends DefaultResponseErrorHandler {
+ public void handleError(ClientHttpResponse response) throws IOException {
+ Utils.showAlert("error", response.getStatusText());
+ }
+}
diff --git a/src/main/resources/form_create.fxml b/src/main/resources/form_create.fxml
new file mode 100644
index 0000000..2bdefdd
--- /dev/null
+++ b/src/main/resources/form_create.fxml
@@ -0,0 +1,19 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/main/resources/form_delete.fxml b/src/main/resources/form_delete.fxml
new file mode 100644
index 0000000..4a733d0
--- /dev/null
+++ b/src/main/resources/form_delete.fxml
@@ -0,0 +1,15 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/main/resources/form_read.fxml b/src/main/resources/form_read.fxml
new file mode 100644
index 0000000..faf52f9
--- /dev/null
+++ b/src/main/resources/form_read.fxml
@@ -0,0 +1,19 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/main/resources/form.fxml b/src/main/resources/form_update.fxml
similarity index 69%
rename from src/main/resources/form.fxml
rename to src/main/resources/form_update.fxml
index 42227b1..2f37908 100644
--- a/src/main/resources/form.fxml
+++ b/src/main/resources/form_update.fxml
@@ -8,12 +8,12 @@
-
+
-
-
+
+
-
+