@@ -80,16 +80,50 @@ public List<Pair<String, String>> getDataBaseIDParameters() throws AqualityExcep
80
80
return list ;
81
81
}
82
82
83
+ public List <Pair <String , String >> getIdAndProjectIdSearchParameters () throws AqualityException {
84
+ List <Pair <String , String >> list = new ArrayList <>();
85
+ List <Field > classFields = this .getClassFields ();
86
+ for (Field field : classFields ) {
87
+ DataBaseName nameAnnotation = field .getAnnotation (DataBaseName .class );
88
+ DataBaseSearchable searchAnnotation = field .getAnnotation (DataBaseSearchable .class );
89
+ if (nameAnnotation != null && searchAnnotation != null ) {
90
+ try {
91
+ field .setAccessible (true );
92
+ String value = "" ;
93
+ if (Objects .equals (field .getName (), "id" ) || Objects .equals (field .getName (), "project_id" )) {
94
+ value = getStringValue (field .get (this ));
95
+ }
96
+ if (nameAnnotation .name ().equals ("request_limit" ) && (value .equals ("0" ) || value .equals ("" ))) {
97
+ value = "100000" ;
98
+ }
99
+ Pair <String , String > pair = new Pair <>(nameAnnotation .name (), value );
100
+ list .add (pair );
101
+
102
+ } catch (IllegalAccessException e ) {
103
+ throw new AqualityException (String .format ("Cannot read Field: %s" , field .getName ()));
104
+ }
105
+ }
106
+ }
107
+
108
+ if (list .isEmpty ()) {
109
+ throw new AqualityException ("Entity has no id parameter" );
110
+ }
111
+
112
+ return list ;
113
+ }
114
+
83
115
public List <Pair <String , String >> getIdSearchParameters (Integer id ) throws AqualityException {
84
116
List <Pair <String , String >> list = new ArrayList <>();
85
117
List <Field > classFields = this .getClassFields ();
118
+ boolean hasOverrideIdAnnotation = hasOverrideIdAnnotation (OverrideIDName .class );
86
119
for (Field field : classFields ) {
87
120
DataBaseName nameAnnotation = field .getAnnotation (DataBaseName .class );
88
121
DataBaseSearchable searchAnnotation = field .getAnnotation (DataBaseSearchable .class );
122
+ OverrideIDName override = field .getAnnotation (OverrideIDName .class );
89
123
if (nameAnnotation != null && searchAnnotation != null ){
90
124
field .setAccessible (true );
91
125
String value = "" ;
92
- if (Objects .equals (field .getName (), "id" )) {
126
+ if (( Objects .equals (field .getName (), "id" ) && ! hasOverrideIdAnnotation ) || override != null ) {
93
127
value = id .toString ();
94
128
}
95
129
if (nameAnnotation .name ().equals ("request_limit" ) && (value .equals ("0" ) || value .equals ("" ))){
@@ -107,24 +141,43 @@ public List<Pair<String, String>> getIdSearchParameters(Integer id) throws Aqual
107
141
return list ;
108
142
}
109
143
110
- public Integer getId () throws AqualityException {
144
+ public Integer getIdOrOverrideId () throws AqualityException {
111
145
List <Field > classFields = this .getClassFields ();
146
+ boolean hasOverrideIdAnnotation = hasOverrideIdAnnotation (OverrideIDName .class );
112
147
for (Field field : classFields ) {
113
148
field .setAccessible (true );
114
- if (Objects .equals (field .getName (), "id" )) {
115
- Object value ;
149
+ OverrideIDName override = field .getAnnotation (OverrideIDName .class );
150
+ if ((Objects .equals (field .getName (), "id" ) && !hasOverrideIdAnnotation ) || override != null ) {
151
+ String value ;
116
152
try {
117
- value = field .get (this );
153
+ value = getStringValue ( field .get (this ) );
118
154
} catch (IllegalAccessException e ) {
119
155
throw new AqualityException (String .format ("Cannot read Field: %s" , field .getName ()));
120
156
}
121
- return Integer .valueOf (getStringValue ( value ) );
157
+ return value . isEmpty () ? null : Integer .valueOf (value );
122
158
}
123
159
}
124
160
125
161
throw new AqualityException ("Entity has no id parameter" );
126
162
}
127
163
164
+ public boolean hasProjectId () throws AqualityException {
165
+ List <Field > classFields = this .getClassFields ();
166
+ for (Field field : classFields ) {
167
+ field .setAccessible (true );
168
+ if (Objects .equals (field .getName (), "project_id" )) {
169
+ Object value ;
170
+ try {
171
+ value = field .get (this );
172
+ } catch (IllegalAccessException e ) {
173
+ throw new AqualityException (String .format ("Cannot read Field: %s" , field .getName ()));
174
+ }
175
+ return !getStringValue (value ).isEmpty ();
176
+ }
177
+ }
178
+ return false ;
179
+ }
180
+
128
181
public void getSearchTemplateFromRequestParameters (@ NotNull HttpServletRequest req ) throws AqualityException {
129
182
getTemplate (req , DataBaseSearchable .class );
130
183
}
@@ -160,6 +213,16 @@ private boolean hasIdAnnotation(Class<DataBaseID> dataBaseIDClass){
160
213
return false ;
161
214
}
162
215
216
+ private boolean hasOverrideIdAnnotation (Class <OverrideIDName > dataBaseIDClass ){
217
+ List <Field > classFields = this .getClassFields ();
218
+ for (Field field : classFields ) {
219
+ if (field .getAnnotation (dataBaseIDClass ) != null ){
220
+ return true ;
221
+ }
222
+ }
223
+ return false ;
224
+ }
225
+
163
226
private List <Field > getClassFields (){
164
227
List <Field > declaredFields = new ArrayList <>();
165
228
Class <?> superclass = this .getClass ();
0 commit comments