From bdbb585d684ef779f6d28ef116affe47663ca468 Mon Sep 17 00:00:00 2001 From: WarL0ck Date: Wed, 6 Dec 2017 12:43:08 +0700 Subject: [PATCH] =?UTF-8?q?=D0=9F=D1=80=D0=BE=D0=BC=D0=B5=D0=B6=D1=83?= =?UTF-8?q?=D1=82=D0=BE=D1=87=D0=BD=D1=8B=D0=B9=20=D0=BA=D0=BE=D0=BC=D0=BC?= =?UTF-8?q?=D0=B8=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...rxml_jackson_core_jackson_core_2_8_10.xml} | 8 +- ..._jackson_core_jackson_databind_2_8_10.xml} | 8 +- ...format_jackson_dataformat_json_unknown.xml | 13 +++ .../Maven__org_atteo_evo_inflector_1_2_2.xml | 13 +++ ...g_boot_starter_data_rest_1_5_9_RELEASE.xml | 13 +++ ...ata_spring_data_commons_1_13_9_RELEASE.xml | 13 +++ ...ta_spring_data_rest_core_2_6_9_RELEASE.xml | 13 +++ ..._spring_data_rest_webmvc_2_6_9_RELEASE.xml | 13 +++ ..._hateoas_spring_hateoas_0_23_0_RELEASE.xml | 13 +++ ...lugin_spring_plugin_core_1_2_0_RELEASE.xml | 13 +++ ...ringframework_spring_tx_4_3_13_RELEASE.xml | 13 +++ config.properties | 4 +- pom.xml | 17 +++- restClient.iml | 47 ++++++----- .../cft/task/restClient/ConfigController.java | 4 + .../ru/cft/task/restClient/EmailRecord.java | 3 + .../cft/task/restClient/MainController.java | 23 ++---- .../restClient/RestActionsController.java | 82 ++++++++++++++++++- .../cft/task/restClient/RestErrorHandler.java | 12 +++ src/main/resources/form_create.fxml | 19 +++++ src/main/resources/form_delete.fxml | 15 ++++ src/main/resources/form_read.fxml | 19 +++++ .../resources/{form.fxml => form_update.fxml} | 8 +- 23 files changed, 333 insertions(+), 53 deletions(-) rename .idea/libraries/{Maven__com_fasterxml_jackson_core_jackson_core_2_9_2.xml => Maven__com_fasterxml_jackson_core_jackson_core_2_8_10.xml} (65%) rename .idea/libraries/{Maven__com_fasterxml_jackson_core_jackson_databind_2_9_2.xml => Maven__com_fasterxml_jackson_core_jackson_databind_2_8_10.xml} (62%) create mode 100644 .idea/libraries/Maven__com_fasterxml_jackson_dataformat_jackson_dataformat_json_unknown.xml create mode 100644 .idea/libraries/Maven__org_atteo_evo_inflector_1_2_2.xml create mode 100644 .idea/libraries/Maven__org_springframework_boot_spring_boot_starter_data_rest_1_5_9_RELEASE.xml create mode 100644 .idea/libraries/Maven__org_springframework_data_spring_data_commons_1_13_9_RELEASE.xml create mode 100644 .idea/libraries/Maven__org_springframework_data_spring_data_rest_core_2_6_9_RELEASE.xml create mode 100644 .idea/libraries/Maven__org_springframework_data_spring_data_rest_webmvc_2_6_9_RELEASE.xml create mode 100644 .idea/libraries/Maven__org_springframework_hateoas_spring_hateoas_0_23_0_RELEASE.xml create mode 100644 .idea/libraries/Maven__org_springframework_plugin_spring_plugin_core_1_2_0_RELEASE.xml create mode 100644 .idea/libraries/Maven__org_springframework_spring_tx_4_3_13_RELEASE.xml create mode 100644 src/main/java/ru/cft/task/restClient/RestErrorHandler.java create mode 100644 src/main/resources/form_create.fxml create mode 100644 src/main/resources/form_delete.fxml create mode 100644 src/main/resources/form_read.fxml rename src/main/resources/{form.fxml => form_update.fxml} (69%) 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 @@ + + + + + + + + + +