Реализация exception

This commit is contained in:
WarL0ck 2017-12-02 16:04:20 +07:00
parent 1202c79210
commit 964f6bc028
8 changed files with 349 additions and 196 deletions

384
.idea/workspace.xml generated
View File

@ -2,49 +2,14 @@
<project version="4"> <project version="4">
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="6452b13b-5b16-420c-9e2d-0c40791a2ae8" name="Default" comment=""> <list default="true" id="6452b13b-5b16-420c-9e2d-0c40791a2ae8" name="Default" comment="">
<change type="DELETED" beforePath="$PROJECT_DIR$/.idea/libraries/Maven__antlr_antlr_2_7_7.xml" afterPath="" /> <change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/src/main/java/ru/cft/task/restServer/EmailException.java" />
<change type="DELETED" beforePath="$PROJECT_DIR$/.idea/libraries/Maven__com_vaadin_external_google_android_json_0_0_20131108_vaadin1.xml" afterPath="" /> <change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/src/main/java/ru/cft/task/restServer/ErrorResponse.java" />
<change type="DELETED" beforePath="$PROJECT_DIR$/.idea/libraries/Maven__dom4j_dom4j_1_6_1.xml" afterPath="" /> <change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/src/main/resources/banner.txt" />
<change type="DELETED" beforePath="$PROJECT_DIR$/.idea/libraries/Maven__javax_transaction_javax_transaction_api_1_2.xml" afterPath="" />
<change type="DELETED" beforePath="$PROJECT_DIR$/.idea/libraries/Maven__junit_junit_4_12.xml" afterPath="" />
<change type="DELETED" beforePath="$PROJECT_DIR$/.idea/libraries/Maven__org_apache_tomcat_tomcat_jdbc_8_5_23.xml" afterPath="" />
<change type="DELETED" beforePath="$PROJECT_DIR$/.idea/libraries/Maven__org_apache_tomcat_tomcat_juli_8_5_23.xml" afterPath="" />
<change type="DELETED" beforePath="$PROJECT_DIR$/.idea/libraries/Maven__org_aspectj_aspectjweaver_1_8_13.xml" afterPath="" />
<change type="DELETED" beforePath="$PROJECT_DIR$/.idea/libraries/Maven__org_assertj_assertj_core_2_6_0.xml" afterPath="" />
<change type="DELETED" beforePath="$PROJECT_DIR$/.idea/libraries/Maven__org_atteo_evo_inflector_1_2_2.xml" afterPath="" />
<change type="DELETED" beforePath="$PROJECT_DIR$/.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml" afterPath="" />
<change type="DELETED" beforePath="$PROJECT_DIR$/.idea/libraries/Maven__org_hamcrest_hamcrest_library_1_3.xml" afterPath="" />
<change type="DELETED" beforePath="$PROJECT_DIR$/.idea/libraries/Maven__org_hibernate_common_hibernate_commons_annotations_5_0_1_Final.xml" afterPath="" />
<change type="DELETED" beforePath="$PROJECT_DIR$/.idea/libraries/Maven__org_hibernate_hibernate_core_5_0_12_Final.xml" afterPath="" />
<change type="DELETED" beforePath="$PROJECT_DIR$/.idea/libraries/Maven__org_hibernate_hibernate_entitymanager_5_0_12_Final.xml" afterPath="" />
<change type="DELETED" beforePath="$PROJECT_DIR$/.idea/libraries/Maven__org_hibernate_javax_persistence_hibernate_jpa_2_1_api_1_0_0_Final.xml" afterPath="" />
<change type="DELETED" beforePath="$PROJECT_DIR$/.idea/libraries/Maven__org_javassist_javassist_3_21_0_GA.xml" afterPath="" />
<change type="DELETED" beforePath="$PROJECT_DIR$/.idea/libraries/Maven__org_jboss_jandex_2_0_0_Final.xml" afterPath="" />
<change type="DELETED" beforePath="$PROJECT_DIR$/.idea/libraries/Maven__org_mockito_mockito_core_1_10_19.xml" afterPath="" />
<change type="DELETED" beforePath="$PROJECT_DIR$/.idea/libraries/Maven__org_objenesis_objenesis_2_1.xml" afterPath="" />
<change type="DELETED" beforePath="$PROJECT_DIR$/.idea/libraries/Maven__org_skyscreamer_jsonassert_1_4_0.xml" afterPath="" />
<change type="DELETED" beforePath="$PROJECT_DIR$/.idea/libraries/Maven__org_springframework_boot_spring_boot_starter_aop_1_5_9_RELEASE.xml" afterPath="" />
<change type="DELETED" beforePath="$PROJECT_DIR$/.idea/libraries/Maven__org_springframework_boot_spring_boot_starter_data_jpa_1_5_9_RELEASE.xml" afterPath="" />
<change type="DELETED" beforePath="$PROJECT_DIR$/.idea/libraries/Maven__org_springframework_boot_spring_boot_starter_jdbc_1_5_9_RELEASE.xml" afterPath="" />
<change type="DELETED" beforePath="$PROJECT_DIR$/.idea/libraries/Maven__org_springframework_boot_spring_boot_starter_test_1_5_9_RELEASE.xml" afterPath="" />
<change type="DELETED" beforePath="$PROJECT_DIR$/.idea/libraries/Maven__org_springframework_boot_spring_boot_test_1_5_9_RELEASE.xml" afterPath="" />
<change type="DELETED" beforePath="$PROJECT_DIR$/.idea/libraries/Maven__org_springframework_boot_spring_boot_test_autoconfigure_1_5_9_RELEASE.xml" afterPath="" />
<change type="DELETED" beforePath="$PROJECT_DIR$/.idea/libraries/Maven__org_springframework_data_spring_data_commons_2_0_2_RELEASE.xml" afterPath="" />
<change type="DELETED" beforePath="$PROJECT_DIR$/.idea/libraries/Maven__org_springframework_data_spring_data_jpa_1_11_9_RELEASE.xml" afterPath="" />
<change type="DELETED" beforePath="$PROJECT_DIR$/.idea/libraries/Maven__org_springframework_data_spring_data_rest_core_2_6_9_RELEASE.xml" afterPath="" />
<change type="DELETED" beforePath="$PROJECT_DIR$/.idea/libraries/Maven__org_springframework_hateoas_spring_hateoas_0_23_0_RELEASE.xml" afterPath="" />
<change type="DELETED" beforePath="$PROJECT_DIR$/.idea/libraries/Maven__org_springframework_plugin_spring_plugin_core_1_2_0_RELEASE.xml" afterPath="" />
<change type="DELETED" beforePath="$PROJECT_DIR$/.idea/libraries/Maven__org_springframework_spring_aspects_4_3_13_RELEASE.xml" afterPath="" />
<change type="DELETED" beforePath="$PROJECT_DIR$/.idea/libraries/Maven__org_springframework_spring_jdbc_4_3_13_RELEASE.xml" afterPath="" />
<change type="DELETED" beforePath="$PROJECT_DIR$/.idea/libraries/Maven__org_springframework_spring_orm_4_3_13_RELEASE.xml" afterPath="" />
<change type="DELETED" beforePath="$PROJECT_DIR$/.idea/libraries/Maven__org_springframework_spring_test_4_3_13_RELEASE.xml" afterPath="" />
<change type="DELETED" beforePath="$PROJECT_DIR$/.idea/libraries/Maven__org_springframework_spring_tx_4_3_13_RELEASE.xml" afterPath="" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/.idea/workspace.xml" afterPath="$PROJECT_DIR$/.idea/workspace.xml" /> <change type="MODIFICATION" beforePath="$PROJECT_DIR$/.idea/workspace.xml" afterPath="$PROJECT_DIR$/.idea/workspace.xml" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/pom.xml" afterPath="$PROJECT_DIR$/pom.xml" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/restServer.iml" afterPath="$PROJECT_DIR$/restServer.iml" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/src/main/java/ru/cft/task/restServer/EmailBook.java" afterPath="$PROJECT_DIR$/src/main/java/ru/cft/task/restServer/EmailBook.java" /> <change type="MODIFICATION" beforePath="$PROJECT_DIR$/src/main/java/ru/cft/task/restServer/EmailBook.java" afterPath="$PROJECT_DIR$/src/main/java/ru/cft/task/restServer/EmailBook.java" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/src/main/java/ru/cft/task/restServer/EmailBookController.java" afterPath="$PROJECT_DIR$/src/main/java/ru/cft/task/restServer/EmailBookController.java" /> <change type="MODIFICATION" beforePath="$PROJECT_DIR$/src/main/java/ru/cft/task/restServer/EmailBookController.java" afterPath="$PROJECT_DIR$/src/main/java/ru/cft/task/restServer/EmailBookController.java" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/src/main/java/ru/cft/task/restServer/EmailRecord.java" afterPath="$PROJECT_DIR$/src/main/java/ru/cft/task/restServer/EmailRecord.java" /> <change type="MODIFICATION" beforePath="$PROJECT_DIR$/src/main/java/ru/cft/task/restServer/EmailRecord.java" afterPath="$PROJECT_DIR$/src/main/java/ru/cft/task/restServer/EmailRecord.java" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/src/main/resources/application.properties" afterPath="$PROJECT_DIR$/src/main/resources/application.properties" />
</list> </list>
<ignored path="$PROJECT_DIR$/out/" /> <ignored path="$PROJECT_DIR$/out/" />
<ignored path="$PROJECT_DIR$/target/" /> <ignored path="$PROJECT_DIR$/target/" />
@ -122,21 +87,11 @@
</component> </component>
<component name="FileEditorManager"> <component name="FileEditorManager">
<leaf SIDE_TABS_SIZE_LIMIT_KEY="300"> <leaf SIDE_TABS_SIZE_LIMIT_KEY="300">
<file leaf-file-name="pom.xml" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/pom.xml">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="1190">
<caret line="70" column="0" lean-forward="false" selection-start-line="70" selection-start-column="0" selection-end-line="70" selection-end-column="0" />
<folding />
</state>
</provider>
</entry>
</file>
<file leaf-file-name="Main.java" pinned="false" current-in-tab="false"> <file leaf-file-name="Main.java" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/main/java/ru/cft/task/restServer/Main.java"> <entry file="file://$PROJECT_DIR$/src/main/java/ru/cft/task/restServer/Main.java">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="136"> <state relative-caret-position="204">
<caret line="8" column="0" lean-forward="false" selection-start-line="8" selection-start-column="0" selection-end-line="8" selection-end-column="0" /> <caret line="12" column="0" lean-forward="true" selection-start-line="12" selection-start-column="0" selection-end-line="12" selection-end-column="0" />
<folding> <folding>
<element signature="imports" expanded="true" /> <element signature="imports" expanded="true" />
<element signature="e#241#242#0" expanded="true" /> <element signature="e#241#242#0" expanded="true" />
@ -146,42 +101,48 @@
</provider> </provider>
</entry> </entry>
</file> </file>
<file leaf-file-name="EmailRecord.java" pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/src/main/java/ru/cft/task/restServer/EmailRecord.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="119">
<caret line="7" column="23" lean-forward="false" selection-start-line="7" selection-start-column="23" selection-end-line="7" selection-end-column="23" />
<folding>
<element signature="e#700#701#0" expanded="true" />
<element signature="e#769#770#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
</file>
<file leaf-file-name="EmailBook.java" pinned="false" current-in-tab="false"> <file leaf-file-name="EmailBook.java" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/main/java/ru/cft/task/restServer/EmailBook.java"> <entry file="file://$PROJECT_DIR$/src/main/java/ru/cft/task/restServer/EmailBook.java">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="442"> <state relative-caret-position="-374">
<caret line="39" column="36" lean-forward="true" selection-start-line="39" selection-start-column="36" selection-end-line="39" selection-end-column="36" /> <caret line="5" column="17" lean-forward="true" selection-start-line="5" selection-start-column="17" selection-end-line="5" selection-end-column="17" />
<folding />
</state>
</provider>
</entry>
</file>
<file leaf-file-name="EmailRecord.java" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/main/java/ru/cft/task/restServer/EmailRecord.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="119">
<caret line="7" column="24" lean-forward="false" selection-start-line="7" selection-start-column="24" selection-end-line="7" selection-end-column="24" />
<folding> <folding>
<element signature="imports" expanded="true" /> <element signature="e#419#420#0" expanded="true" />
<element signature="e#334#335#0" expanded="true" /> <element signature="e#446#447#0" expanded="true" />
<element signature="e#374#375#0" expanded="true" />
<element signature="e#822#823#0" expanded="true" />
<element signature="e#856#857#0" expanded="true" />
</folding> </folding>
</state> </state>
</provider> </provider>
</entry> </entry>
</file> </file>
<file leaf-file-name="EmailBookController.java" pinned="false" current-in-tab="false"> <file leaf-file-name="EmailException.java" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/main/java/ru/cft/task/restServer/EmailException.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="34">
<caret line="2" column="13" lean-forward="false" selection-start-line="2" selection-start-column="13" selection-end-line="2" selection-end-column="13" />
<folding />
</state>
</provider>
</entry>
</file>
<file leaf-file-name="EmailBookController.java" pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/src/main/java/ru/cft/task/restServer/EmailBookController.java"> <entry file="file://$PROJECT_DIR$/src/main/java/ru/cft/task/restServer/EmailBookController.java">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="408"> <state relative-caret-position="428">
<caret line="24" column="5" lean-forward="true" selection-start-line="24" selection-start-column="5" selection-end-line="24" selection-end-column="5" /> <caret line="45" column="0" lean-forward="false" selection-start-line="45" selection-start-column="0" selection-end-line="45" selection-end-column="0" />
<folding> <folding>
<element signature="imports" expanded="true" /> <element signature="imports" expanded="true" />
<element signature="e#2412#2413#0" expanded="true" />
<element signature="e#2452#2453#0" expanded="true" />
</folding> </folding>
</state> </state>
</provider> </provider>
@ -192,8 +153,8 @@
<component name="FileTemplateManagerImpl"> <component name="FileTemplateManagerImpl">
<option name="RECENT_TEMPLATES"> <option name="RECENT_TEMPLATES">
<list> <list>
<option value="Class" />
<option value="Interface" /> <option value="Interface" />
<option value="Class" />
</list> </list>
</option> </option>
</component> </component>
@ -212,9 +173,12 @@
<option value="$PROJECT_DIR$/src/main/resources/log4j.properties" /> <option value="$PROJECT_DIR$/src/main/resources/log4j.properties" />
<option value="$PROJECT_DIR$/src/main/java/ru/cft/task/restServer/BookStatus.java" /> <option value="$PROJECT_DIR$/src/main/java/ru/cft/task/restServer/BookStatus.java" />
<option value="$PROJECT_DIR$/src/main/java/ru/cft/task/restServer/Main.java" /> <option value="$PROJECT_DIR$/src/main/java/ru/cft/task/restServer/Main.java" />
<option value="$PROJECT_DIR$/src/main/java/ru/cft/task/restServer/EmailRecord.java" />
<option value="$PROJECT_DIR$/pom.xml" /> <option value="$PROJECT_DIR$/pom.xml" />
<option value="$PROJECT_DIR$/src/main/java/ru/cft/task/restServer/EmailException.java" />
<option value="$PROJECT_DIR$/src/main/java/ru/cft/task/restServer/ErrorResponse.java" />
<option value="$PROJECT_DIR$/src/main/resources/application.properties" /> <option value="$PROJECT_DIR$/src/main/resources/application.properties" />
<option value="$PROJECT_DIR$/src/main/resources/banner.txt" />
<option value="$PROJECT_DIR$/src/main/java/ru/cft/task/restServer/EmailRecord.java" />
<option value="$PROJECT_DIR$/src/main/java/ru/cft/task/restServer/EmailBook.java" /> <option value="$PROJECT_DIR$/src/main/java/ru/cft/task/restServer/EmailBook.java" />
<option value="$PROJECT_DIR$/src/main/java/ru/cft/task/restServer/EmailBookController.java" /> <option value="$PROJECT_DIR$/src/main/java/ru/cft/task/restServer/EmailBookController.java" />
</list> </list>
@ -293,8 +257,9 @@
<foldersAlwaysOnTop value="true" /> <foldersAlwaysOnTop value="true" />
</navigator> </navigator>
<panes> <panes>
<pane id="Scratches" /> <pane id="Scope" />
<pane id="PackagesPane" /> <pane id="PackagesPane" />
<pane id="Scratches" />
<pane id="AndroidView" /> <pane id="AndroidView" />
<pane id="ProjectPane"> <pane id="ProjectPane">
<subPane> <subPane>
@ -340,7 +305,6 @@
<select /> <select />
</subPane> </subPane>
</pane> </pane>
<pane id="Scope" />
</panes> </panes>
</component> </component>
<component name="PropertiesComponent"> <component name="PropertiesComponent">
@ -510,7 +474,14 @@
<option name="project" value="LOCAL" /> <option name="project" value="LOCAL" />
<updated>1512039223736</updated> <updated>1512039223736</updated>
</task> </task>
<option name="localTasksCounter" value="6" /> <task id="LOCAL-00006" summary="Промежуточный коммит">
<created>1512137481973</created>
<option name="number" value="00006" />
<option name="presentableId" value="LOCAL-00006" />
<option name="project" value="LOCAL" />
<updated>1512137481973</updated>
</task>
<option name="localTasksCounter" value="7" />
<servers /> <servers />
</component> </component>
<component name="ToolWindowManager"> <component name="ToolWindowManager">
@ -522,10 +493,10 @@
<window_info id="Palette&#9;" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="3" side_tool="false" content_ui="tabs" /> <window_info id="Palette&#9;" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="3" side_tool="false" content_ui="tabs" />
<window_info id="Image Layers" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="2" side_tool="false" content_ui="tabs" /> <window_info id="Image Layers" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="2" side_tool="false" content_ui="tabs" />
<window_info id="Capture Analysis" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="4" side_tool="false" content_ui="tabs" /> <window_info id="Capture Analysis" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="4" side_tool="false" content_ui="tabs" />
<window_info id="Event Log" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.25454545" sideWeight="0.5063966" order="7" side_tool="true" content_ui="tabs" /> <window_info id="Event Log" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.25416204" sideWeight="0.51171875" order="7" side_tool="true" content_ui="tabs" />
<window_info id="Maven Projects" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.32995737" sideWeight="0.5" order="3" side_tool="false" content_ui="tabs" /> <window_info id="Maven Projects" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.32995737" sideWeight="0.5" order="3" side_tool="false" content_ui="tabs" />
<window_info id="Run" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.25416204" sideWeight="0.4936034" order="2" side_tool="false" content_ui="tabs" /> <window_info id="Run" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.25416204" sideWeight="0.48828125" order="2" side_tool="false" content_ui="tabs" />
<window_info id="Version Control" active="true" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.27413985" sideWeight="0.4904051" order="7" side_tool="false" content_ui="tabs" /> <window_info id="Version Control" active="true" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.27413985" sideWeight="0.4890625" order="7" side_tool="false" content_ui="tabs" />
<window_info id="Terminal" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.32941177" sideWeight="0.4978678" order="7" side_tool="false" content_ui="tabs" /> <window_info id="Terminal" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.32941177" sideWeight="0.4978678" order="7" side_tool="false" content_ui="tabs" />
<window_info id="Capture Tool" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="2" side_tool="false" content_ui="tabs" /> <window_info id="Capture Tool" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="2" side_tool="false" content_ui="tabs" />
<window_info id="Designer" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="2" side_tool="false" content_ui="tabs" /> <window_info id="Designer" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="2" side_tool="false" content_ui="tabs" />
@ -592,7 +563,8 @@
<MESSAGE value="Add ignore" /> <MESSAGE value="Add ignore" />
<MESSAGE value="Init commit" /> <MESSAGE value="Init commit" />
<MESSAGE value="Реализация книги" /> <MESSAGE value="Реализация книги" />
<option name="LAST_COMMIT_MESSAGE" value="Реализация книги" /> <MESSAGE value="Промежуточный коммит" />
<option name="LAST_COMMIT_MESSAGE" value="Промежуточный коммит" />
</component> </component>
<component name="XDebuggerManager"> <component name="XDebuggerManager">
<breakpoint-manager> <breakpoint-manager>
@ -605,6 +577,76 @@
<option name="FILTER_TARGETS" value="false" /> <option name="FILTER_TARGETS" value="false" />
</component> </component>
<component name="editorHistoryManager"> <component name="editorHistoryManager">
<entry file="file://$PROJECT_DIR$/src/main/java/ru/cft/task/restServer/EmailBook.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="918">
<caret line="61" column="0" lean-forward="false" selection-start-line="61" selection-start-column="0" selection-end-line="61" selection-end-column="0" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/pom.xml">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="1190">
<caret line="70" column="0" lean-forward="false" selection-start-line="70" selection-start-column="0" selection-end-line="70" selection-end-column="0" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/main/java/ru/cft/task/restServer/Main.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="136">
<caret line="8" column="0" lean-forward="false" selection-start-line="8" selection-start-column="0" selection-end-line="8" selection-end-column="0" />
<folding>
<element signature="imports" expanded="true" />
<element signature="e#241#242#0" expanded="true" />
<element signature="e#296#297#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/main/java/ru/cft/task/restServer/EmailRecord.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="119">
<caret line="7" column="23" lean-forward="false" selection-start-line="7" selection-start-column="23" selection-end-line="7" selection-end-column="23" />
<folding>
<element signature="e#700#701#0" expanded="false" />
<element signature="e#756#757#0" expanded="false" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/main/java/ru/cft/task/restServer/EmailException.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="51">
<caret line="3" column="0" lean-forward="false" selection-start-line="3" selection-start-column="0" selection-end-line="3" selection-end-column="0" />
<folding>
<element signature="e#231#232#0" expanded="false" />
<element signature="e#261#262#0" expanded="false" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/main/java/ru/cft/task/restServer/EmailBook.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="289">
<caret line="23" column="85" lean-forward="false" selection-start-line="23" selection-start-column="85" selection-end-line="23" selection-end-column="85" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/main/java/ru/cft/task/restServer/EmailBookController.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="663">
<caret line="43" column="56" lean-forward="false" selection-start-line="43" selection-start-column="56" selection-end-line="43" selection-end-column="56" />
<folding>
<element signature="imports" expanded="true" />
<element signature="e#2412#2413#0" expanded="true" />
<element signature="e#2452#2453#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/pom.xml"> <entry file="file://$PROJECT_DIR$/pom.xml">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="1445"> <state relative-caret-position="1445">
@ -630,8 +672,8 @@
<state relative-caret-position="323"> <state relative-caret-position="323">
<caret line="24" column="59" lean-forward="false" selection-start-line="24" selection-start-column="59" selection-end-line="24" selection-end-column="59" /> <caret line="24" column="59" lean-forward="false" selection-start-line="24" selection-start-column="59" selection-end-line="24" selection-end-column="59" />
<folding> <folding>
<element signature="e#700#701#0" expanded="true" /> <element signature="e#700#701#0" expanded="false" />
<element signature="e#769#770#0" expanded="true" /> <element signature="e#756#757#0" expanded="false" />
</folding> </folding>
</state> </state>
</provider> </provider>
@ -640,13 +682,7 @@
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="85"> <state relative-caret-position="85">
<caret line="6" column="50" lean-forward="false" selection-start-line="6" selection-start-column="50" selection-end-line="6" selection-end-column="50" /> <caret line="6" column="50" lean-forward="false" selection-start-line="6" selection-start-column="50" selection-end-line="6" selection-end-column="50" />
<folding> <folding />
<element signature="imports" expanded="true" />
<element signature="e#334#335#0" expanded="true" />
<element signature="e#374#375#0" expanded="true" />
<element signature="e#822#823#0" expanded="true" />
<element signature="e#856#857#0" expanded="true" />
</folding>
</state> </state>
</provider> </provider>
</entry> </entry>
@ -656,6 +692,8 @@
<caret line="34" column="0" lean-forward="true" selection-start-line="34" selection-start-column="0" selection-end-line="34" selection-end-column="0" /> <caret line="34" column="0" lean-forward="true" selection-start-line="34" selection-start-column="0" selection-end-line="34" selection-end-column="0" />
<folding> <folding>
<element signature="imports" expanded="true" /> <element signature="imports" expanded="true" />
<element signature="e#2412#2413#0" expanded="true" />
<element signature="e#2452#2453#0" expanded="true" />
</folding> </folding>
</state> </state>
</provider> </provider>
@ -685,8 +723,8 @@
<state relative-caret-position="323"> <state relative-caret-position="323">
<caret line="24" column="59" lean-forward="false" selection-start-line="24" selection-start-column="59" selection-end-line="24" selection-end-column="59" /> <caret line="24" column="59" lean-forward="false" selection-start-line="24" selection-start-column="59" selection-end-line="24" selection-end-column="59" />
<folding> <folding>
<element signature="e#700#701#0" expanded="true" /> <element signature="e#700#701#0" expanded="false" />
<element signature="e#769#770#0" expanded="true" /> <element signature="e#756#757#0" expanded="false" />
</folding> </folding>
</state> </state>
</provider> </provider>
@ -695,13 +733,7 @@
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="85"> <state relative-caret-position="85">
<caret line="6" column="50" lean-forward="true" selection-start-line="6" selection-start-column="50" selection-end-line="6" selection-end-column="50" /> <caret line="6" column="50" lean-forward="true" selection-start-line="6" selection-start-column="50" selection-end-line="6" selection-end-column="50" />
<folding> <folding />
<element signature="imports" expanded="true" />
<element signature="e#334#335#0" expanded="true" />
<element signature="e#374#375#0" expanded="true" />
<element signature="e#822#823#0" expanded="true" />
<element signature="e#856#857#0" expanded="true" />
</folding>
</state> </state>
</provider> </provider>
</entry> </entry>
@ -711,6 +743,8 @@
<caret line="34" column="0" lean-forward="true" selection-start-line="34" selection-start-column="0" selection-end-line="34" selection-end-column="0" /> <caret line="34" column="0" lean-forward="true" selection-start-line="34" selection-start-column="0" selection-end-line="34" selection-end-column="0" />
<folding> <folding>
<element signature="imports" expanded="true" /> <element signature="imports" expanded="true" />
<element signature="e#2412#2413#0" expanded="true" />
<element signature="e#2452#2453#0" expanded="true" />
</folding> </folding>
</state> </state>
</provider> </provider>
@ -741,6 +775,8 @@
<caret line="13" column="0" lean-forward="false" selection-start-line="13" selection-start-column="0" selection-end-line="13" selection-end-column="0" /> <caret line="13" column="0" lean-forward="false" selection-start-line="13" selection-start-column="0" selection-end-line="13" selection-end-column="0" />
<folding> <folding>
<element signature="imports" expanded="true" /> <element signature="imports" expanded="true" />
<element signature="e#2412#2413#0" expanded="true" />
<element signature="e#2452#2453#0" expanded="true" />
</folding> </folding>
</state> </state>
</provider> </provider>
@ -750,8 +786,8 @@
<state relative-caret-position="34"> <state relative-caret-position="34">
<caret line="2" column="24" lean-forward="false" selection-start-line="2" selection-start-column="24" selection-end-line="2" selection-end-column="24" /> <caret line="2" column="24" lean-forward="false" selection-start-line="2" selection-start-column="24" selection-end-line="2" selection-end-column="24" />
<folding> <folding>
<element signature="e#700#701#0" expanded="true" /> <element signature="e#700#701#0" expanded="false" />
<element signature="e#769#770#0" expanded="true" /> <element signature="e#756#757#0" expanded="false" />
</folding> </folding>
</state> </state>
</provider> </provider>
@ -761,13 +797,7 @@
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="493"> <state relative-caret-position="493">
<caret line="29" column="5" lean-forward="false" selection-start-line="29" selection-start-column="5" selection-end-line="29" selection-end-column="5" /> <caret line="29" column="5" lean-forward="false" selection-start-line="29" selection-start-column="5" selection-end-line="29" selection-end-column="5" />
<folding> <folding />
<element signature="imports" expanded="true" />
<element signature="e#334#335#0" expanded="true" />
<element signature="e#374#375#0" expanded="true" />
<element signature="e#822#823#0" expanded="true" />
<element signature="e#856#857#0" expanded="true" />
</folding>
</state> </state>
</provider> </provider>
</entry> </entry>
@ -797,6 +827,8 @@
<caret line="13" column="0" lean-forward="false" selection-start-line="13" selection-start-column="0" selection-end-line="13" selection-end-column="0" /> <caret line="13" column="0" lean-forward="false" selection-start-line="13" selection-start-column="0" selection-end-line="13" selection-end-column="0" />
<folding> <folding>
<element signature="imports" expanded="true" /> <element signature="imports" expanded="true" />
<element signature="e#2412#2413#0" expanded="true" />
<element signature="e#2452#2453#0" expanded="true" />
</folding> </folding>
</state> </state>
</provider> </provider>
@ -806,8 +838,8 @@
<state relative-caret-position="34"> <state relative-caret-position="34">
<caret line="2" column="24" lean-forward="false" selection-start-line="2" selection-start-column="24" selection-end-line="2" selection-end-column="24" /> <caret line="2" column="24" lean-forward="false" selection-start-line="2" selection-start-column="24" selection-end-line="2" selection-end-column="24" />
<folding> <folding>
<element signature="e#700#701#0" expanded="true" /> <element signature="e#700#701#0" expanded="false" />
<element signature="e#769#770#0" expanded="true" /> <element signature="e#756#757#0" expanded="false" />
</folding> </folding>
</state> </state>
</provider> </provider>
@ -817,13 +849,7 @@
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="459"> <state relative-caret-position="459">
<caret line="27" column="75" lean-forward="true" selection-start-line="27" selection-start-column="75" selection-end-line="27" selection-end-column="75" /> <caret line="27" column="75" lean-forward="true" selection-start-line="27" selection-start-column="75" selection-end-line="27" selection-end-column="75" />
<folding> <folding />
<element signature="imports" expanded="true" />
<element signature="e#334#335#0" expanded="true" />
<element signature="e#374#375#0" expanded="true" />
<element signature="e#822#823#0" expanded="true" />
<element signature="e#856#857#0" expanded="true" />
</folding>
</state> </state>
</provider> </provider>
</entry> </entry>
@ -853,6 +879,8 @@
<caret line="21" column="0" lean-forward="false" selection-start-line="21" selection-start-column="0" selection-end-line="21" selection-end-column="0" /> <caret line="21" column="0" lean-forward="false" selection-start-line="21" selection-start-column="0" selection-end-line="21" selection-end-column="0" />
<folding> <folding>
<element signature="imports" expanded="true" /> <element signature="imports" expanded="true" />
<element signature="e#2412#2413#0" expanded="true" />
<element signature="e#2452#2453#0" expanded="true" />
</folding> </folding>
</state> </state>
</provider> </provider>
@ -883,6 +911,8 @@
<caret line="17" column="37" lean-forward="false" selection-start-line="17" selection-start-column="37" selection-end-line="17" selection-end-column="37" /> <caret line="17" column="37" lean-forward="false" selection-start-line="17" selection-start-column="37" selection-end-line="17" selection-end-column="37" />
<folding> <folding>
<element signature="imports" expanded="true" /> <element signature="imports" expanded="true" />
<element signature="e#2412#2413#0" expanded="true" />
<element signature="e#2452#2453#0" expanded="true" />
</folding> </folding>
</state> </state>
</provider> </provider>
@ -893,10 +923,58 @@
<entry file="jar://$MAVEN_REPOSITORY$/org/springframework/boot/spring-boot/1.5.9.RELEASE/spring-boot-1.5.9.RELEASE.jar!/org/springframework/boot/SpringApplication.class" /> <entry file="jar://$MAVEN_REPOSITORY$/org/springframework/boot/spring-boot/1.5.9.RELEASE/spring-boot-1.5.9.RELEASE.jar!/org/springframework/boot/SpringApplication.class" />
<entry file="file://$PROJECT_DIR$/src/main/resources/log4j.properties" /> <entry file="file://$PROJECT_DIR$/src/main/resources/log4j.properties" />
<entry file="file://$PROJECT_DIR$/src/main/java/ru/cft/task/restServer/BookStatus.java" /> <entry file="file://$PROJECT_DIR$/src/main/java/ru/cft/task/restServer/BookStatus.java" />
<entry file="file://$PROJECT_DIR$/.idea/workspace.xml">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="0">
<caret line="0" column="0" lean-forward="false" selection-start-line="0" selection-start-column="0" selection-end-line="0" selection-end-column="0" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/main/java/ru/cft/task/restServer/ErrorResponse.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="357">
<caret line="21" column="0" lean-forward="false" selection-start-line="21" selection-start-column="0" selection-end-line="21" selection-end-column="0" />
<folding>
<element signature="e#148#149#0" expanded="false" />
<element signature="e#180#181#0" expanded="false" />
<element signature="e#227#228#0" expanded="false" />
<element signature="e#269#270#0" expanded="false" />
<element signature="e#303#304#0" expanded="false" />
<element signature="e#333#334#0" expanded="false" />
<element signature="e#379#380#0" expanded="false" />
<element signature="e#417#418#0" expanded="false" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/main/resources/banner.txt">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="68">
<caret line="4" column="0" lean-forward="true" selection-start-line="4" selection-start-column="0" selection-end-line="4" selection-end-column="0" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/main/resources/application.properties">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="51">
<caret line="3" column="0" lean-forward="true" selection-start-line="3" selection-start-column="0" selection-end-line="3" selection-end-column="0" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/pom.xml">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="272">
<caret line="16" column="11" lean-forward="true" selection-start-line="16" selection-start-column="11" selection-end-line="16" selection-end-column="11" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/main/java/ru/cft/task/restServer/Main.java"> <entry file="file://$PROJECT_DIR$/src/main/java/ru/cft/task/restServer/Main.java">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="136"> <state relative-caret-position="204">
<caret line="8" column="0" lean-forward="false" selection-start-line="8" selection-start-column="0" selection-end-line="8" selection-end-column="0" /> <caret line="12" column="0" lean-forward="true" selection-start-line="12" selection-start-column="0" selection-end-line="12" selection-end-column="0" />
<folding> <folding>
<element signature="imports" expanded="true" /> <element signature="imports" expanded="true" />
<element signature="e#241#242#0" expanded="true" /> <element signature="e#241#242#0" expanded="true" />
@ -905,53 +983,41 @@
</state> </state>
</provider> </provider>
</entry> </entry>
<entry file="file://$PROJECT_DIR$/pom.xml">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="1190">
<caret line="70" column="0" lean-forward="false" selection-start-line="70" selection-start-column="0" selection-end-line="70" selection-end-column="0" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/main/resources/application.properties">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="34">
<caret line="2" column="23" lean-forward="false" selection-start-line="2" selection-start-column="23" selection-end-line="2" selection-end-column="23" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/main/java/ru/cft/task/restServer/EmailBookController.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="408">
<caret line="24" column="5" lean-forward="true" selection-start-line="24" selection-start-column="5" selection-end-line="24" selection-end-column="5" />
<folding>
<element signature="imports" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/main/java/ru/cft/task/restServer/EmailBook.java"> <entry file="file://$PROJECT_DIR$/src/main/java/ru/cft/task/restServer/EmailBook.java">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="442"> <state relative-caret-position="-374">
<caret line="39" column="36" lean-forward="true" selection-start-line="39" selection-start-column="36" selection-end-line="39" selection-end-column="36" /> <caret line="5" column="17" lean-forward="true" selection-start-line="5" selection-start-column="17" selection-end-line="5" selection-end-column="17" />
<folding> <folding />
<element signature="imports" expanded="true" />
<element signature="e#334#335#0" expanded="true" />
<element signature="e#374#375#0" expanded="true" />
<element signature="e#822#823#0" expanded="true" />
<element signature="e#856#857#0" expanded="true" />
</folding>
</state> </state>
</provider> </provider>
</entry> </entry>
<entry file="file://$PROJECT_DIR$/src/main/java/ru/cft/task/restServer/EmailRecord.java"> <entry file="file://$PROJECT_DIR$/src/main/java/ru/cft/task/restServer/EmailRecord.java">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="119"> <state relative-caret-position="119">
<caret line="7" column="23" lean-forward="false" selection-start-line="7" selection-start-column="23" selection-end-line="7" selection-end-column="23" /> <caret line="7" column="24" lean-forward="false" selection-start-line="7" selection-start-column="24" selection-end-line="7" selection-end-column="24" />
<folding> <folding>
<element signature="e#700#701#0" expanded="true" /> <element signature="e#419#420#0" expanded="true" />
<element signature="e#769#770#0" expanded="true" /> <element signature="e#446#447#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/main/java/ru/cft/task/restServer/EmailException.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="34">
<caret line="2" column="13" lean-forward="false" selection-start-line="2" selection-start-column="13" selection-end-line="2" selection-end-column="13" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/main/java/ru/cft/task/restServer/EmailBookController.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="428">
<caret line="45" column="0" lean-forward="false" selection-start-line="45" selection-start-column="0" selection-end-line="45" selection-end-column="0" />
<folding>
<element signature="imports" expanded="true" />
<element signature="e#2412#2413#0" expanded="true" />
<element signature="e#2452#2453#0" expanded="true" />
</folding> </folding>
</state> </state>
</provider> </provider>

View File

@ -2,46 +2,62 @@ package ru.cft.task.restServer;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.ArrayList; import java.util.HashMap;
import java.util.List; import java.util.Map;
import java.util.concurrent.atomic.AtomicLong;
@Component @Component
public class EmailBook { public class EmailBook {
private List<EmailRecord> book; private Map<Long, EmailRecord> book;
private final AtomicLong new_id = new AtomicLong();
public EmailBook() { public EmailBook() {
book = new ArrayList<>(); book = new HashMap<>();
} }
public long addEmailRecord(String name, String email) { public EmailRecord addEmailRecord(long id, String name, String email) throws EmailException {
long id = new_id.incrementAndGet(); for (Map.Entry<Long, EmailRecord> rec : book.entrySet()) {
book.add(new EmailRecord(id, name, email)); if (rec.getValue().getEmail() == email) {
return id; throw new EmailException("Запись с email " + email + " уже есть в базе");
}
}
EmailRecord new_rec = new EmailRecord(id, name, email);
book.put(id, new_rec);
return new_rec;
} }
public boolean removeEmailRecord(long id) { public boolean removeEmailRecord(long id) throws EmailException {
for (EmailRecord rec : book) { if (book.containsKey(id)) {
if (rec.getId() == id) { book.remove(id);
book.remove(rec);
return true; return true;
} }
} throw new EmailException("Запись с id = " + id + " не найдена");
return false;
} }
public int count() { public int count() {
return book.size(); return book.size();
} }
public EmailRecord findRec(long id) { public EmailRecord findRecordById(long id) throws EmailException {
for (EmailRecord rec : book) { if (book.containsKey(id)) {
if (rec.getId() == id) { return book.get(id);
book.remove(rec); }
return rec; throw new EmailException("Запись с id = " + id + " не найдена");
}
public EmailRecord findRecordByName(String name) throws EmailException {
for (Map.Entry<Long, EmailRecord> rec : book.entrySet()) {
if (rec.getValue().getName().toLowerCase() == name.toLowerCase()) {
return rec.getValue();
} }
} }
return null; throw new EmailException("Запись с именем " + name + " не найдена");
}
public EmailRecord findRecordByEmail(String email) throws EmailException {
for (Map.Entry<Long, EmailRecord> rec : book.entrySet()) {
if (rec.getValue().getEmail().toLowerCase() == email.toLowerCase()) {
return rec.getValue();
}
}
throw new EmailException("Запись с email " + email + " не найдена");
} }
} }

View File

@ -1,31 +1,63 @@
package ru.cft.task.restServer; package ru.cft.task.restServer;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RestController;
import java.util.concurrent.atomic.AtomicLong;
@RestController @RestController
@RequestMapping(value = "/")
public class EmailBookController { public class EmailBookController {
private final AtomicLong new_id = new AtomicLong();
@Autowired @Autowired
private EmailBook emailBook; private EmailBook emailBook;
@RequestMapping(method = RequestMethod.POST) @RequestMapping(method = RequestMethod.POST)
public long addEmailRec(@RequestParam(value = "name", defaultValue = "John Unknown") String name, public ResponseEntity<EmailRecord> addEmailRec(@RequestParam(value = "name", defaultValue = "John Unknown") String name,
@RequestParam(value = "email", defaultValue = "john@unknown.ru") String email) { @RequestParam(value = "email", defaultValue = "john@unknown.ru") String email) throws EmailException {
return emailBook.addEmailRecord(name, email); return new ResponseEntity<EmailRecord>(emailBook.addEmailRecord(new_id.incrementAndGet(), name, email), HttpStatus.OK);
} }
@RequestMapping(method = RequestMethod.DELETE) @RequestMapping(method = RequestMethod.DELETE)
public boolean removeEmailRec(@RequestParam(value = "id", required = true) long id) { public ResponseEntity<ErrorResponse> removeEmailRec(@RequestParam(value = "id", required = true) long id) throws EmailException {
return emailBook.removeEmailRecord(id); if (emailBook.removeEmailRecord(id)) {
ErrorResponse message = new ErrorResponse();
message.setErrorCode(HttpStatus.OK.value());
message.setMessage("Запись {id = " + id + "} успешно удалена");
return new ResponseEntity<ErrorResponse>(message, HttpStatus.OK);
}
return null;
} }
@RequestMapping(method = RequestMethod.GET) @RequestMapping(method = RequestMethod.GET)
public EmailRecord findEmailRec(@RequestParam(value = "id", required = true) long id) { public ResponseEntity<EmailRecord> findEmailRec(@RequestParam(value = "id", defaultValue = "") String id,
return emailBook.findRec(id); @RequestParam(value = "name", defaultValue = "") String name,
@RequestParam(value = "email", defaultValue = "") String email
) throws EmailException {
if (!name.isEmpty()) {
return new ResponseEntity<EmailRecord>(emailBook.findRecordByName(name), HttpStatus.OK);
} else if (!email.isEmpty()) {
return new ResponseEntity<EmailRecord>(emailBook.findRecordByEmail(email), HttpStatus.OK);
} else {
return new ResponseEntity<EmailRecord>(emailBook.findRecordById(Long.valueOf(id)), HttpStatus.OK);
}
}
@RequestMapping(value = "/count", method = RequestMethod.GET)
public int countEmailRecords() {
return emailBook.count();
}
@ExceptionHandler({EmailException.class, Exception.class})
public ResponseEntity<ErrorResponse> exceptionHandler(Exception ex) {
ErrorResponse error = new ErrorResponse();
error.setErrorCode(HttpStatus.PRECONDITION_FAILED.value());
error.setMessage(ex.getMessage());
return new ResponseEntity<ErrorResponse>(error, HttpStatus.OK);
} }
} }

View File

@ -0,0 +1,13 @@
package ru.cft.task.restServer;
public class EmailException extends Exception {
private static final long serialVersionUID = 1L;
public EmailException() {
super();
}
public EmailException(String message) {
super(message);
}
}

View File

@ -37,6 +37,6 @@ public class EmailRecord {
@Override @Override
public String toString() { public String toString() {
return "Rec[" + id + "]: " + name + "<" + email + ">"; return "Rec:" + name + "<" + email + ">";
} }
} }

View File

@ -0,0 +1,22 @@
package ru.cft.task.restServer;
public class ErrorResponse {
private int errorCode;
private String message;
public int getErrorCode() {
return errorCode;
}
public void setErrorCode(int errorCode) {
this.errorCode = errorCode;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
}

View File

@ -1,3 +1,3 @@
server.port = 8090 server.port = 8090
spring.profiles.active=local spring.profiles.active=local
logging.level.root=DEBUG logging.level.root=WARN

View File

@ -0,0 +1,4 @@
__ ____ _____
,'_/ / __//_ _/
/ /_ / _/ / /
|__/ /_/ /_/