Skip to content

Commit 855fae0

Browse files
committed
immutable resumes
если находимся не в режиме дебага, то - скрываем кнопки уделения и редактирования для неизменных резюме - для особо умных, чтобы не удалили через прямой запрос, делается доп проверка в сервлете
1 parent 73310ca commit 855fae0

File tree

8 files changed

+69
-9
lines changed

8 files changed

+69
-9
lines changed

.gitignore

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,4 @@
33
out
44
log
55
lib
6-
7-
8-
6+
storage

config/resumes.properties

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
storage.dir=C:/projects/basejava/storage
22

3+
immutable.uuid.one = 11111111-c3d9-4a5c-1111-ed49a6da0a0f
4+
immutable.uuid.two = 22222222-c3d9-4a5c-2222-ed49a6da0a0f
5+
debug.mode = true
6+
37
# Replace by Heroku credentials
48
db.url=jdbc:postgresql://localhost:5432/resumes
59
db.user=postgres

src/ru/javawebinar/basejava/Config.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@
66
import java.io.File;
77
import java.io.IOException;
88
import java.io.InputStream;
9+
import java.util.Arrays;
10+
import java.util.HashSet;
911
import java.util.Properties;
12+
import java.util.Set;
1013

1114
public class Config {
1215
private static final String PROPS = "/resumes.properties";
@@ -15,6 +18,12 @@ public class Config {
1518
private final File storageDir;
1619
private final Storage storage;
1720

21+
private final boolean debugMode;
22+
23+
private final Set<String> immutableUuids = new HashSet<>();
24+
private final String immutableUuidOne;
25+
private final String immutableUuidTwo;
26+
1827
public static Config get() {
1928
return INSTANCE;
2029
}
@@ -25,6 +34,12 @@ private Config() {
2534
props.load(is);
2635
storageDir = new File(props.getProperty("storage.dir"));
2736
storage = new SqlStorage(props.getProperty("db.url"), props.getProperty("db.user"), props.getProperty("db.password"));
37+
38+
debugMode = Boolean.parseBoolean(props.getProperty("debug.mode"));
39+
40+
immutableUuidOne = props.getProperty("immutable.uuid.one");
41+
immutableUuidTwo = props.getProperty("immutable.uuid.two");
42+
immutableUuids.addAll(Arrays.asList(immutableUuidOne, immutableUuidTwo));
2843
} catch (IOException e) {
2944
throw new IllegalStateException("Invalid config file " + PROPS);
3045
}
@@ -37,4 +52,20 @@ public File getStorageDir() {
3752
public Storage getStorage() {
3853
return storage;
3954
}
55+
56+
public Set<String> getImmutableUuids() {
57+
return immutableUuids;
58+
}
59+
60+
public boolean debugMode() {
61+
return debugMode;
62+
}
63+
64+
public String getImmutableUuidOne() {
65+
return immutableUuidOne;
66+
}
67+
68+
public String getImmutableUuidTwo() {
69+
return immutableUuidTwo;
70+
}
4071
}

src/ru/javawebinar/basejava/web/ResumeServlet.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,30 @@ private enum THEME {
2626
private Storage storage; // = Config.get().getStorage();
2727
private final Set<String> themes = new HashSet<>(); // https://stackoverflow.com/a/4936895/548473
2828

29+
private Set<String> immutableUuids;
30+
private boolean debugMode;
31+
2932
@Override
3033
public void init(ServletConfig config) throws ServletException {
3134
super.init(config);
32-
storage = Config.get().getStorage();
35+
final Config cfg = Config.get();
36+
storage = cfg.getStorage();
3337
for (THEME t : THEME.values()) {
3438
themes.add(t.name());
3539
}
40+
immutableUuids = cfg.getImmutableUuids();
41+
debugMode = cfg.debugMode();
3642
}
3743

3844
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws javax.servlet.ServletException, IOException {
3945
request.setCharacterEncoding("UTF-8");
4046
String uuid = request.getParameter("uuid");
4147
String fullName = request.getParameter("fullName");
4248

49+
if (!debugMode && immutableUuids.contains(uuid) ) {
50+
response.sendRedirect("resume?theme=" + getTheme(request));
51+
}
52+
4353
final boolean isCreate = (uuid == null || uuid.length() == 0);
4454
Resume r;
4555
if (isCreate) {

test/ru/javawebinar/basejava/TestData.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,19 @@ public class TestData {
1111
public static final String UUID_3 = UUID.randomUUID().toString();
1212
public static final String UUID_4 = UUID.randomUUID().toString();
1313

14+
public static final Resume R1_IMMUTABLE;
15+
public static final Resume R2_IMMUTABLE;
16+
1417
public static final Resume R1;
1518
public static final Resume R2;
1619
public static final Resume R3;
1720
public static final Resume R4;
1821

1922
static {
23+
Config config = Config.get();
24+
R1_IMMUTABLE = new Resume(config.getImmutableUuidOne(), "Григорий Кислин");
25+
R2_IMMUTABLE = new Resume(config.getImmutableUuidTwo(), "Николай Ларин");
26+
2027
R1 = new Resume(UUID_1, "Name1");
2128
R2 = new Resume(UUID_2, "Name2");
2229
R3 = new Resume(UUID_3, "Name3");

test/ru/javawebinar/basejava/storage/AbstractStorageTest.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ public void save() throws Exception {
7575
storage.save(R4);
7676
assertSize(4);
7777
assertGet(R4);
78+
storage.save(R1_IMMUTABLE);
79+
storage.save(R2_IMMUTABLE);
80+
assertSize(6);
7881
}
7982

8083
@Test(expected = ExistStorageException.class)

web/WEB-INF/jsp/edit.jsp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
<%@ page import="ru.javawebinar.basejava.model.OrganizationSection" %>
44
<%@ page import="ru.javawebinar.basejava.model.SectionType" %>
55
<%@ page import="ru.javawebinar.basejava.util.DateUtil" %>
6+
<%@ page import="ru.javawebinar.basejava.Config" %>
67
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
78
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
89
<html>
@@ -91,8 +92,11 @@
9192
<div class="spacer"></div>
9293

9394
<div class="button-section">
94-
<button class="red-cancel-button" onclick="window.history.back()">Отменить</button>
95-
<button class="green-submit-button" type="submit">Сохранить</button>
95+
<button class="red-cancel-button" type="button" onclick="window.history.back()">Отменить</button>
96+
<% Config cfg = Config.get(); %>
97+
<c:if test="<%=cfg.debugMode() || !cfg.getImmutableUuids().contains(resume.getUuid())%>">
98+
<button class="green-submit-button" type="submit">Сохранить</button>
99+
</c:if>
96100
</div>
97101

98102
</div>

web/WEB-INF/jsp/list.jsp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<%@ page import="ru.javawebinar.basejava.model.ContactType" %>
2+
<%@ page import="ru.javawebinar.basejava.Config" %>
23
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
34
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
45

@@ -58,9 +59,11 @@
5859
</a>
5960
</td>
6061
<td class="img-column">
61-
<a class="no-underline-anchor" href="resume?uuid=${resume.uuid}&action=delete&theme=${theme}">
62-
<img src="img/${theme}/remove.svg" alt="">
63-
</a>
62+
<c:if test="<%=!Config.get().getImmutableUuids().contains(resume.getUuid())%>">
63+
<a class="no-underline-anchor" href="resume?uuid=${resume.uuid}&action=delete&theme=${theme}">
64+
<img src="img/${theme}/remove.svg" alt="">
65+
</a>
66+
</c:if>
6467
</td>
6568
</tr>
6669
</c:forEach>

0 commit comments

Comments
 (0)