Skip to content

Commit f12ff8e

Browse files
committed
Refactor bean scopes of user, client, ldap server, ldap group, authority and role form.
1 parent 6fe81f9 commit f12ff8e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+2415
-1682
lines changed

Kitodo-DataManagement/src/main/java/org/kitodo/data/database/beans/User.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -643,7 +643,7 @@ public void setDefaultClient(Client defaultClient) {
643643
* <p>
644644
* To allow recreation of an account with the same login the login is cleaned -
645645
* otherwise it would be blocked eternally by the login existence test performed
646-
* in the UserForm.save() function. In addition, all personally identifiable
646+
* in the UserEditView.save() function. In addition, all personally identifiable
647647
* information is removed from the database as well.
648648
*/
649649
public void selfDestruct() {

Kitodo/src/main/java/org/kitodo/production/filters/FilterMenu.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
import org.kitodo.production.enums.FilterString;
2727
import org.kitodo.production.forms.CurrentTaskForm;
2828
import org.kitodo.production.forms.ProcessForm;
29-
import org.kitodo.production.forms.UserForm;
29+
import org.kitodo.production.forms.user.UserListView;
3030
import org.kitodo.production.services.ServiceManager;
3131
import org.kitodo.production.services.data.FilterService;
3232

@@ -76,7 +76,7 @@ public class FilterMenu {
7676

7777
private ProcessForm processForm = null;
7878
private CurrentTaskForm taskForm = null;
79-
private UserForm userForm = null;
79+
private UserListView userListView = null;
8080
private List<Suggestion> suggestions;
8181
private final List<ParsedFilter> parsedFilters;
8282
private String filterInEditMode;
@@ -106,10 +106,10 @@ public FilterMenu(CurrentTaskForm taskForm) {
106106
/**
107107
* Constructor of filter menu for users.
108108
*
109-
* @param userForm instance of UserForm
109+
* @param userListView instance of UserListView
110110
*/
111-
public FilterMenu(UserForm userForm) {
112-
this.userForm = userForm;
111+
public FilterMenu(UserListView userListView) {
112+
this.userListView = userListView;
113113
suggestions = createSuggestionsForUserCategory("");
114114
parsedFilters = new ArrayList<>();
115115
}
@@ -148,7 +148,7 @@ public void updateSuggestions(String input) {
148148
suggestions = createSuggestionsForProcessCategory(input);
149149
} else if (Objects.nonNull(taskForm)) {
150150
suggestions = createSuggestionsForTaskCategory(input);
151-
} else if (Objects.nonNull(userForm)) {
151+
} else if (Objects.nonNull(userListView)) {
152152
suggestions = createSuggestionsForUserCategory(input);
153153
}
154154
} else {
@@ -178,7 +178,7 @@ public void updateSuggestions(String input) {
178178
String category = matcherPreviousCategory.find() ? matcherPreviousCategory.group() : "";
179179
suggestions = createSuggestionsForTaskValue(checkFilterCategory(category, taskCategories), lastPart);
180180
}
181-
} else if (Objects.nonNull(userForm)) {
181+
} else if (Objects.nonNull(userListView)) {
182182
if (matcherNextCategory.find()) {
183183
// strings ends with " | "
184184
suggestions = createSuggestionsForUserCategory(matcherNextCategory.group());
@@ -399,8 +399,8 @@ public void updateFilters() {
399399
processForm.setFilter(newFilter.toString());
400400
} else if (Objects.nonNull(taskForm)) {
401401
taskForm.setFilter(newFilter.toString());
402-
} else if (Objects.nonNull(userForm)) {
403-
userForm.setFilter(newFilter.toString());
402+
} else if (Objects.nonNull(userListView)) {
403+
userListView.setFilter(newFilter.toString());
404404
}
405405
}
406406
}

Kitodo/src/main/java/org/kitodo/production/forms/AuthorityForm.java renamed to Kitodo/src/main/java/org/kitodo/production/forms/AuthorityEditView.java

Lines changed: 23 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
import java.text.MessageFormat;
1515
import java.util.Objects;
1616

17-
import jakarta.enterprise.context.SessionScoped;
17+
import jakarta.annotation.PostConstruct;
18+
import jakarta.faces.view.ViewScoped;
1819
import jakarta.inject.Named;
1920

2021
import org.apache.logging.log4j.LogManager;
@@ -23,28 +24,23 @@
2324
import org.kitodo.data.database.exceptions.DAOException;
2425
import org.kitodo.production.enums.ObjectType;
2526
import org.kitodo.production.helper.Helper;
26-
import org.kitodo.production.model.LazyBeanModel;
2727
import org.kitodo.production.services.ServiceManager;
28-
import org.primefaces.model.SortMeta;
29-
import org.primefaces.model.SortOrder;
3028

31-
@Named("AuthorityForm")
32-
@SessionScoped
33-
public class AuthorityForm extends BaseForm {
34-
private static final Logger logger = LogManager.getLogger(AuthorityForm.class);
35-
private Authority authority = new Authority();
29+
@Named("AuthorityEditView")
30+
@ViewScoped
31+
public class AuthorityEditView extends BaseForm {
32+
33+
public static final String VIEW_PATH = MessageFormat.format(REDIRECT_PATH, "authorityEdit");
34+
35+
private static final Logger logger = LogManager.getLogger(AuthorityEditView.class);
36+
37+
private Authority authority;
3638
private String title;
3739
private String type;
38-
private final String authorityEditPath = MessageFormat.format(REDIRECT_PATH, "authorityEdit");
3940

40-
/**
41-
* Default constructor that also sets the LazyBeanModel instance of this
42-
* bean.
43-
*/
44-
public AuthorityForm() {
45-
super();
46-
super.setLazyBeanModel(new LazyBeanModel(ServiceManager.getAuthorityService()));
47-
sortBy = SortMeta.builder().field("title").order(SortOrder.ASCENDING).build();
41+
@PostConstruct
42+
public void init() {
43+
authority = new Authority();
4844
}
4945

5046
/**
@@ -85,16 +81,6 @@ public void setType(String type) {
8581
this.type = type;
8682
}
8783

88-
/**
89-
* Create new authority.
90-
*
91-
* @return page address
92-
*/
93-
public String newAuthority() {
94-
this.authority = new Authority();
95-
return authorityEditPath;
96-
}
97-
9884
/**
9985
* Save authority.
10086
*
@@ -104,30 +90,13 @@ public String save() {
10490
try {
10591
this.authority.setTitle(this.title + "_" + this.type);
10692
ServiceManager.getAuthorityService().save(this.authority);
107-
return usersPage;
93+
return AuthorityListView.VIEW_PATH;
10894
} catch (DAOException e) {
109-
Helper.setErrorMessage(ERROR_SAVING, new Object[] {ObjectType.AUTHORITY.getTranslationSingular() }, logger,
110-
e);
95+
Helper.setErrorMessage(ERROR_SAVING, new Object[] {ObjectType.AUTHORITY.getTranslationSingular() }, logger, e);
11196
return this.stayOnCurrentPage;
11297
}
11398
}
11499

115-
/**
116-
* Remove authority.
117-
*/
118-
public void delete() {
119-
try {
120-
if (!this.authority.getRoles().isEmpty()) {
121-
Helper.setErrorMessage("authorityAssignedError");
122-
return;
123-
}
124-
ServiceManager.getAuthorityService().remove(this.authority);
125-
} catch (DAOException e) {
126-
Helper.setErrorMessage(ERROR_DELETING, new Object[] {ObjectType.AUTHORITY.getTranslationSingular() },
127-
logger, e);
128-
}
129-
}
130-
131100
/**
132101
* Method being used as viewAction for authority edit form.
133102
*
@@ -136,38 +105,17 @@ public void delete() {
136105
*/
137106
public void load(int id) {
138107
if (!Objects.equals(id, 0)) {
139-
setAuthorityById(id);
108+
try {
109+
authority = ServiceManager.getAuthorityService().getById(id);
110+
title = authority.getTitleWithoutSuffix();
111+
type = authority.getType();
112+
} catch (DAOException e) {
113+
Helper.setErrorMessage(ERROR_LOADING_ONE, new Object[] {ObjectType.ROLE.getTranslationSingular(), id }, logger, e);
114+
}
140115
}
141116
setSaveDisabled(true);
142117
}
143118

144-
/**
145-
* Set authority by id.
146-
*
147-
* @param id
148-
* ID of authority to set
149-
*/
150-
public void setAuthorityById(int id) {
151-
try {
152-
setAuthority(ServiceManager.getAuthorityService().getById(id));
153-
} catch (DAOException e) {
154-
Helper.setErrorMessage(ERROR_LOADING_ONE, new Object[] {ObjectType.ROLE.getTranslationSingular(), id },
155-
logger, e);
156-
}
157-
}
158-
159-
/**
160-
* Set authority.
161-
*
162-
* @param authority
163-
* as org.kitodo.data.database.beans.Authority
164-
*/
165-
public void setAuthority(Authority authority) {
166-
this.authority = authority;
167-
this.title = this.authority.getTitleWithoutSuffix();
168-
this.type = this.authority.getType();
169-
}
170-
171119
/**
172120
* Get authority.
173121
*
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* (c) Kitodo. Key to digital objects e. V. <[email protected]>
3+
*
4+
* This file is part of the Kitodo project.
5+
*
6+
* It is licensed under GNU General Public License version 3 or later.
7+
*
8+
* For the full copyright and license information, please read the
9+
* GPL3-License.txt file that was distributed with this source code.
10+
*/
11+
12+
package org.kitodo.production.forms;
13+
14+
import java.text.MessageFormat;
15+
16+
import jakarta.faces.view.ViewScoped;
17+
import jakarta.inject.Named;
18+
19+
import org.kitodo.production.model.LazyBeanModel;
20+
import org.kitodo.production.services.ServiceManager;
21+
import org.primefaces.model.SortMeta;
22+
import org.primefaces.model.SortOrder;
23+
24+
@Named("AuthorityListView")
25+
@ViewScoped
26+
public class AuthorityListView extends BaseForm {
27+
28+
public static final String VIEW_PATH = MessageFormat.format(REDIRECT_PATH, "users") + "#usersTabView:authoritiesTab";
29+
30+
/**
31+
* Default constructor that also sets the LazyBeanModel instance of this
32+
* bean.
33+
*/
34+
public AuthorityListView() {
35+
super();
36+
super.setLazyBeanModel(new LazyBeanModel(ServiceManager.getAuthorityService()));
37+
sortBy = SortMeta.builder().field("title").order(SortOrder.ASCENDING).build();
38+
}
39+
40+
/**
41+
* Create new authority.
42+
*
43+
* @return page address
44+
*/
45+
public String newAuthority() {
46+
return AuthorityEditView.VIEW_PATH;
47+
}
48+
49+
}

0 commit comments

Comments
 (0)