Стабильный релиз
This commit is contained in:
parent
99e5447541
commit
41d2e79fa8
@ -5,13 +5,10 @@ import javafx.fxml.FXML;
|
|||||||
import javafx.scene.control.Button;
|
import javafx.scene.control.Button;
|
||||||
import javafx.scene.control.TextField;
|
import javafx.scene.control.TextField;
|
||||||
import javafx.stage.Stage;
|
import javafx.stage.Stage;
|
||||||
import org.springframework.boot.autoconfigure.security.SecurityProperties;
|
|
||||||
import org.springframework.http.*;
|
import org.springframework.http.*;
|
||||||
import org.springframework.util.LinkedMultiValueMap;
|
import org.springframework.util.LinkedMultiValueMap;
|
||||||
import org.springframework.util.MultiValueMap;
|
import org.springframework.util.MultiValueMap;
|
||||||
import org.springframework.web.client.HttpClientErrorException;
|
|
||||||
import org.springframework.web.client.HttpStatusCodeException;
|
import org.springframework.web.client.HttpStatusCodeException;
|
||||||
import org.springframework.web.client.RestClientException;
|
|
||||||
import org.springframework.web.client.RestTemplate;
|
import org.springframework.web.client.RestTemplate;
|
||||||
import org.springframework.web.util.UriComponentsBuilder;
|
import org.springframework.web.util.UriComponentsBuilder;
|
||||||
|
|
||||||
@ -56,25 +53,18 @@ public class RestActionsController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void cancelAction() {
|
private void createOrUpdate(HttpMethod method, MultiValueMap<String, String> params) {
|
||||||
Stage stage = (Stage) cancel.getScene().getWindow();
|
|
||||||
stage.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void createAction() {
|
|
||||||
RestTemplate restTemplate = new RestTemplate();
|
RestTemplate restTemplate = new RestTemplate();
|
||||||
HttpHeaders headers = new HttpHeaders();
|
HttpHeaders headers = new HttpHeaders();
|
||||||
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
|
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
|
||||||
MultiValueMap<String, String> map = new LinkedMultiValueMap<String, String>();
|
HttpEntity<MultiValueMap<String, String>> entity = new HttpEntity<MultiValueMap<String, String>>(params, headers);
|
||||||
map.add("name", name.getText());
|
|
||||||
map.add("email", email.getText());
|
|
||||||
|
|
||||||
HttpEntity<MultiValueMap<String, String>> entity = new HttpEntity<MultiValueMap<String, String>>(map, headers);
|
|
||||||
try {
|
try {
|
||||||
ResponseEntity<EmailRecord> response = restTemplate.exchange(getRestServerUrl(), HttpMethod.POST, entity, EmailRecord.class);
|
ResponseEntity<EmailRecord> response = restTemplate.exchange(getRestServerUrl(), method, entity, EmailRecord.class);
|
||||||
if (response.getStatusCode() == HttpStatus.OK) {
|
if (response.getStatusCode() == HttpStatus.OK) {
|
||||||
EmailRecord emailRecord = response.getBody();
|
EmailRecord emailRecord = response.getBody();
|
||||||
id.setText(String.valueOf(emailRecord.getId()));
|
id.setText(String.valueOf(emailRecord.getId()));
|
||||||
|
name.setText(emailRecord.getName());
|
||||||
|
email.setText(emailRecord.getEmail());
|
||||||
}
|
}
|
||||||
} catch (HttpStatusCodeException ex) {
|
} catch (HttpStatusCodeException ex) {
|
||||||
try {
|
try {
|
||||||
@ -87,6 +77,18 @@ public class RestActionsController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void cancelAction() {
|
||||||
|
Stage stage = (Stage) cancel.getScene().getWindow();
|
||||||
|
stage.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void createAction() {
|
||||||
|
MultiValueMap<String, String> map = new LinkedMultiValueMap<String, String>();
|
||||||
|
map.add("name", name.getText());
|
||||||
|
map.add("email", email.getText());
|
||||||
|
createOrUpdate(HttpMethod.POST, map);
|
||||||
|
}
|
||||||
|
|
||||||
public void readAction() {
|
public void readAction() {
|
||||||
RestTemplate restTemplate = new RestTemplate();
|
RestTemplate restTemplate = new RestTemplate();
|
||||||
HttpHeaders headers = new HttpHeaders();
|
HttpHeaders headers = new HttpHeaders();
|
||||||
@ -121,10 +123,34 @@ public class RestActionsController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void updateAction() {
|
public void updateAction() {
|
||||||
|
MultiValueMap<String, String> map = new LinkedMultiValueMap<String, String>();
|
||||||
|
map.add("id", id.getText());
|
||||||
|
map.add("name", name.getText());
|
||||||
|
map.add("email", email.getText());
|
||||||
|
createOrUpdate(HttpMethod.PUT, map);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void deleteAction() {
|
public void deleteAction() {
|
||||||
|
RestTemplate restTemplate = new RestTemplate();
|
||||||
|
HttpHeaders headers = new HttpHeaders();
|
||||||
|
headers.set("Accept", MediaType.APPLICATION_JSON_VALUE);
|
||||||
|
String delete_url = getRestServerUrl().concat("/delete/").concat(id.getText());
|
||||||
|
|
||||||
|
HttpEntity<?> entity = new HttpEntity<>(headers);
|
||||||
|
try {
|
||||||
|
ResponseEntity<ErrorResponse> response = restTemplate.exchange(delete_url, HttpMethod.DELETE, entity, ErrorResponse.class);
|
||||||
|
if (response.getStatusCode() == HttpStatus.OK) {
|
||||||
|
ErrorResponse result = response.getBody();
|
||||||
|
Utils.showAlert("info", result.getMessage());
|
||||||
|
}
|
||||||
|
} catch (HttpStatusCodeException ex) {
|
||||||
|
try {
|
||||||
|
ObjectMapper objectMapper = new ObjectMapper();
|
||||||
|
ErrorResponse err = objectMapper.readValue(ex.getResponseBodyAsString(), ErrorResponse.class);
|
||||||
|
Utils.showAlert("error", err.getMessage());
|
||||||
|
} catch (IOException e) {
|
||||||
|
Utils.showAlert("error", e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,11 +5,11 @@
|
|||||||
<?import javafx.scene.control.TextField?>
|
<?import javafx.scene.control.TextField?>
|
||||||
<?import javafx.scene.layout.AnchorPane?>
|
<?import javafx.scene.layout.AnchorPane?>
|
||||||
|
|
||||||
<AnchorPane fx:id="deleteBtn" onDragDetected="#deleteAction" prefHeight="68.0" prefWidth="295.0" xmlns="http://javafx.com/javafx/8.0.141" xmlns:fx="http://javafx.com/fxml/1" fx:controller="ru.cft.task.restClient.RestActionsController">
|
<AnchorPane fx:id="deleteBtn" onDragDetected="#deleteAction" prefHeight="68.0" prefWidth="295.0" xmlns="http://javafx.com/javafx/8.0.121" xmlns:fx="http://javafx.com/fxml/1" fx:controller="ru.cft.task.restClient.RestActionsController">
|
||||||
<children>
|
<children>
|
||||||
<Label layoutX="15.0" layoutY="14.0" text="Идентификатор" />
|
<Label layoutX="15.0" layoutY="14.0" text="Идентификатор" />
|
||||||
<TextField fx:id="id" layoutX="111.0" layoutY="10.0" prefHeight="25.0" prefWidth="181.0" />
|
<TextField fx:id="id" layoutX="111.0" layoutY="10.0" prefHeight="25.0" prefWidth="181.0" />
|
||||||
<Button fx:id="cancel" layoutX="15.0" layoutY="40.0" mnemonicParsing="false" onAction="#cancelAction" text="Отмена" />
|
<Button fx:id="cancel" layoutX="15.0" layoutY="40.0" mnemonicParsing="false" onAction="#cancelAction" text="Отмена" />
|
||||||
<Button fx:id="doAction" layoutX="232.0" layoutY="40.0" mnemonicParsing="false" text="Удалить" />
|
<Button fx:id="doAction" layoutX="232.0" layoutY="40.0" mnemonicParsing="false" onAction="#deleteAction" text="Удалить" />
|
||||||
</children>
|
</children>
|
||||||
</AnchorPane>
|
</AnchorPane>
|
||||||
|
Loading…
Reference in New Issue
Block a user