-
Notifications
You must be signed in to change notification settings - Fork 57
/
SearchPersonAction.java
102 lines (80 loc) · 2.53 KB
/
SearchPersonAction.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/*
* oxTrust is available under the MIT License (2008). See http://opensource.org/licenses/MIT for full text.
*
* Copyright (c) 2014, Gluu
*/
package org.gluu.oxtrust.action;
import java.io.Serializable;
import java.util.List;
import javax.enterprise.context.ConversationScoped;
import javax.faces.application.FacesMessage;
import javax.inject.Inject;
import javax.inject.Named;
import org.gluu.jsf2.message.FacesMessages;
import org.gluu.jsf2.service.ConversationService;
import org.gluu.oxtrust.ldap.service.IPersonService;
import org.gluu.oxtrust.model.GluuCustomPerson;
import org.gluu.oxtrust.util.OxTrustConstants;
import org.slf4j.Logger;
import org.xdi.service.security.Secure;
import org.xdi.util.Util;
/**
* Action class for search persons
*
* @author Yuriy Movchan Date: 10.22.2010
*/
@Named
@ConversationScoped
@Secure("#{permissionService.hasPermission('person', 'access')}")
public class SearchPersonAction implements Serializable {
private static final long serialVersionUID = -4672682869487324438L;
@Inject
private Logger log;
@Inject
private FacesMessages facesMessages;
@Inject
private ConversationService conversationService;
private String searchPattern;
private String oldSearchPattern;
private boolean firstLaunch = false;
private List<GluuCustomPerson> personList;
@Inject
private IPersonService personService;
public String start() {
firstLaunch = true;
return search();
}
public String search() {
if (!firstLaunch && (this.searchPattern.isEmpty() || this.searchPattern.length() < 2)) {
firstLaunch = false;
facesMessages.add(FacesMessage.SEVERITY_ERROR, "Length of search string should be between 2 and 30");
return OxTrustConstants.RESULT_SUCCESS;
}
if (Util.equals(this.oldSearchPattern, this.searchPattern)) {
firstLaunch = false;
return OxTrustConstants.RESULT_SUCCESS;
}
try {
this.personList = personService.searchPersons(this.searchPattern);
this.oldSearchPattern = this.searchPattern;
this.searchPattern = "";
firstLaunch = false;
} catch (Exception ex) {
log.error("Failed to find persons", ex);
facesMessages.add(FacesMessage.SEVERITY_ERROR, "Failed to find persons");
conversationService.endConversation();
firstLaunch = false;
return OxTrustConstants.RESULT_FAILURE;
}
return OxTrustConstants.RESULT_SUCCESS;
}
public String getSearchPattern() {
return searchPattern;
}
public void setSearchPattern(String searchPattern) {
this.searchPattern = searchPattern;
}
public List<GluuCustomPerson> getPersonList() {
return personList;
}
}