File tree 16 files changed +291
-44
lines changed
main/java/io/securecodebox/persistence/defectdojo/model
test/java/io/securecodebox/persistence/defectdojo/model
16 files changed +291
-44
lines changed Original file line number Diff line number Diff line change 16
16
@ AllArgsConstructor
17
17
@ EqualsAndHashCode
18
18
@ JsonInclude (JsonInclude .Include .NON_NULL )
19
- public final class Endpoint implements Model {
19
+ public final class Endpoint implements Model , HasId {
20
20
@ JsonProperty
21
21
private long id ;
22
22
@@ -49,10 +49,11 @@ public final class Endpoint implements Model {
49
49
50
50
@ Override
51
51
public boolean equalsQueryString (Map <String , Object > queryParams ) {
52
- if (queryParams == null ) {
52
+ if (QueryParamsComparator . isNull ( queryParams ) ) {
53
53
return false ;
54
54
}
55
55
56
- return queryParams . containsKey ( "id" ) && queryParams . get ( "id" ). equals ( this . id );
56
+ return QueryParamsComparator . isIdEqual ( this , queryParams );
57
57
}
58
+
58
59
}
Original file line number Diff line number Diff line change 17
17
@ AllArgsConstructor
18
18
@ EqualsAndHashCode
19
19
@ JsonInclude (JsonInclude .Include .NON_NULL )
20
- public final class Engagement implements Model {
20
+ public final class Engagement implements Model , HasId , HasName {
21
21
@ JsonProperty ("branch_tag" )
22
22
private String branch ;
23
23
24
24
@ JsonProperty
25
- private Long id ;
25
+ private long id ;
26
26
27
27
@ JsonProperty
28
28
private String name ;
@@ -94,15 +94,15 @@ public final class Engagement implements Model {
94
94
95
95
@ Override
96
96
public boolean equalsQueryString (Map <String , Object > queryParams ) {
97
- if (queryParams == null ) {
97
+ if (QueryParamsComparator . isNull ( queryParams ) ) {
98
98
return false ;
99
99
}
100
100
101
- if (queryParams . containsKey ( "id" ) && queryParams . get ( "id" ) != null && queryParams . get ( "id" ). equals ( this . id )) {
101
+ if (QueryParamsComparator . isIdEqual ( this , queryParams )) {
102
102
return true ;
103
103
}
104
104
105
- if (queryParams . containsKey ( "name" ) && queryParams . get ( "name" ) != null && queryParams . get ( "name" ). equals ( this . name )) {
105
+ if (QueryParamsComparator . isNameEqual ( this , queryParams )) {
106
106
return true ;
107
107
}
108
108
Original file line number Diff line number Diff line change 21
21
@ AllArgsConstructor
22
22
@ EqualsAndHashCode
23
23
@ JsonInclude (JsonInclude .Include .NON_NULL )
24
- public final class Finding implements Model {
24
+ public final class Finding implements Model , HasId {
25
25
@ JsonProperty
26
26
private long id ;
27
27
@@ -121,11 +121,11 @@ public String getNumericalSeverity() {
121
121
122
122
@ Override
123
123
public boolean equalsQueryString (Map <String , Object > queryParams ) {
124
- if (queryParams == null ) {
124
+ if (QueryParamsComparator . isNull ( queryParams ) ) {
125
125
return false ;
126
126
}
127
127
128
- return queryParams . containsKey ( "id" ) && queryParams . get ( "id" ). equals ( this . id );
128
+ return QueryParamsComparator . isIdEqual ( this , queryParams );
129
129
}
130
130
131
131
public enum Severity {
Original file line number Diff line number Diff line change 17
17
@ AllArgsConstructor
18
18
@ EqualsAndHashCode
19
19
@ JsonInclude (JsonInclude .Include .NON_NULL )
20
- public final class Group implements Model {
20
+ public final class Group implements Model , HasId , HasName {
21
21
@ JsonProperty
22
22
private long id ;
23
23
@@ -36,15 +36,15 @@ public final class Group implements Model {
36
36
37
37
@ Override
38
38
public boolean equalsQueryString (Map <String , Object > queryParams ) {
39
- if (queryParams == null ) {
39
+ if (QueryParamsComparator . isNull ( queryParams ) ) {
40
40
return false ;
41
41
}
42
42
43
- if (queryParams . containsKey ( "id" ) && queryParams . get ( "id" ). equals ( this . id )) {
43
+ if (QueryParamsComparator . isIdEqual ( this , queryParams )) {
44
44
return true ;
45
45
}
46
46
47
- if (queryParams . containsKey ( "name" ) && queryParams . get ( "name" ). equals ( this . name )) {
47
+ if (QueryParamsComparator . isNameEqual ( this , queryParams )) {
48
48
return true ;
49
49
}
50
50
Original file line number Diff line number Diff line change
1
+ // SPDX-FileCopyrightText: the secureCodeBox authors
2
+ //
3
+ // SPDX-License-Identifier: Apache-2.0
4
+
5
+ package io .securecodebox .persistence .defectdojo .model ;
6
+
7
+ /**
8
+ * Interface to mark {@link Model models} which have an id
9
+ * <p>
10
+ * This type is package private because it is an implementation detail of the models and
11
+ * z should not be used outside of this package.
12
+ * </p>
13
+ */
14
+ interface HasId {
15
+ long getId ();
16
+
17
+ void setId (long id );
18
+ }
Original file line number Diff line number Diff line change
1
+ // SPDX-FileCopyrightText: the secureCodeBox authors
2
+ //
3
+ // SPDX-License-Identifier: Apache-2.0
4
+
5
+ package io .securecodebox .persistence .defectdojo .model ;
6
+
7
+ /**
8
+ * Interface to mark {@link Model models} which have a name
9
+ * <p>
10
+ * This type is package private because it is an implementation detail of the models and
11
+ * z should not be used outside of this package.
12
+ * </p>
13
+ */
14
+ interface HasName {
15
+ String getName ();
16
+
17
+ void setName (String id );
18
+ }
Original file line number Diff line number Diff line change 17
17
@ AllArgsConstructor
18
18
@ EqualsAndHashCode
19
19
@ JsonInclude (JsonInclude .Include .NON_NULL )
20
- public final class Product implements Model {
20
+ public final class Product implements Model , HasId , HasName {
21
21
@ JsonProperty
22
22
private long id ;
23
23
@@ -53,15 +53,15 @@ public final class Product implements Model {
53
53
54
54
@ Override
55
55
public boolean equalsQueryString (Map <String , Object > queryParams ) {
56
- if (queryParams == null ) {
56
+ if (QueryParamsComparator . isNull ( queryParams ) ) {
57
57
return false ;
58
58
}
59
59
60
- if (queryParams . containsKey ( "id" ) && queryParams . get ( "id" ). equals ( this . id )) {
60
+ if (QueryParamsComparator . isIdEqual ( this , queryParams )) {
61
61
return true ;
62
62
}
63
63
64
- if (queryParams . containsKey ( "name" ) && queryParams . get ( "name" ). equals ( this . name )) {
64
+ if (QueryParamsComparator . isNameEqual ( this , queryParams )) {
65
65
return true ;
66
66
}
67
67
Original file line number Diff line number Diff line change 16
16
@ AllArgsConstructor
17
17
@ EqualsAndHashCode
18
18
@ JsonInclude (JsonInclude .Include .NON_NULL )
19
- public final class ProductType implements Model {
19
+ public final class ProductType implements Model , HasId , HasName {
20
20
@ JsonProperty
21
21
private long id ;
22
22
@@ -32,15 +32,15 @@ public final class ProductType implements Model {
32
32
33
33
@ Override
34
34
public boolean equalsQueryString (Map <String , Object > queryParams ) {
35
- if (queryParams == null ) {
35
+ if (QueryParamsComparator . isNull ( queryParams ) ) {
36
36
return false ;
37
37
}
38
38
39
- if (queryParams . containsKey ( "id" ) && queryParams . get ( "id" ). equals ( this . id )) {
39
+ if (QueryParamsComparator . isIdEqual ( this , queryParams )) {
40
40
return true ;
41
41
}
42
42
43
- if (queryParams . containsKey ( "name" ) && queryParams . get ( "name" ). equals ( this . name )) {
43
+ if (QueryParamsComparator . isNameEqual ( this , queryParams )) {
44
44
return true ;
45
45
}
46
46
Original file line number Diff line number Diff line change
1
+ // SPDX-FileCopyrightText: the secureCodeBox authors
2
+ //
3
+ // SPDX-License-Identifier: Apache-2.0
4
+
5
+ package io .securecodebox .persistence .defectdojo .model ;
6
+
7
+ import java .util .Map ;
8
+
9
+ /**
10
+ * Pure static helper class
11
+ * <p>
12
+ * This type is package private because it is an implementation detail of the models and
13
+ * should not be used outside of this package.
14
+ * </p>
15
+ */
16
+ final class QueryParamsComparator {
17
+
18
+ static final String QUERY_PARAM_KEY_FOR_ID = "id" ;
19
+ static final String QUERY_PARAM_KEY_FOR_NAME = "name" ;
20
+
21
+ private QueryParamsComparator () {
22
+ super ();
23
+ }
24
+
25
+ static boolean isNull (Object o ) {
26
+ return o == null ;
27
+ }
28
+
29
+ static boolean isIdEqual (HasId model , Map <String , Object > queryParams ) {
30
+ if (isNull (model )) {
31
+ return false ;
32
+ }
33
+
34
+ if (isNull (queryParams )) {
35
+ return false ;
36
+ }
37
+
38
+ if (!queryParams .containsKey (QUERY_PARAM_KEY_FOR_ID )) {
39
+ return false ;
40
+ }
41
+
42
+ // FIXME: Since th generic type for value is Object, possible NPE here!
43
+ return queryParams .get (QUERY_PARAM_KEY_FOR_ID ).equals (model .getId ());
44
+ }
45
+
46
+ static boolean isNameEqual (HasName model , Map <String , Object > queryParams ) {
47
+ if (isNull (model )) {
48
+ return false ;
49
+ }
50
+
51
+ if (isNull (queryParams )) {
52
+ return false ;
53
+ }
54
+
55
+ if (!queryParams .containsKey (QUERY_PARAM_KEY_FOR_NAME )) {
56
+ return false ;
57
+ }
58
+
59
+ if (isNull (queryParams .get (QUERY_PARAM_KEY_FOR_NAME ))) {
60
+ return false ;
61
+ }
62
+
63
+ return queryParams .get (QUERY_PARAM_KEY_FOR_NAME ).equals (model .getName ());
64
+ }
65
+ }
Original file line number Diff line number Diff line change 17
17
@ AllArgsConstructor
18
18
@ EqualsAndHashCode
19
19
@ JsonInclude (JsonInclude .Include .NON_NULL )
20
- public final class RiskAcceptance implements Model {
20
+ public final class RiskAcceptance implements Model , HasId {
21
21
@ JsonProperty
22
22
private long id ;
23
23
@@ -58,10 +58,10 @@ public final class RiskAcceptance implements Model {
58
58
59
59
@ Override
60
60
public boolean equalsQueryString (Map <String , Object > queryParams ) {
61
- if (queryParams == null ) {
61
+ if (QueryParamsComparator . isNull ( queryParams ) ) {
62
62
return false ;
63
63
}
64
64
65
- return queryParams . containsKey ( "id" ) && queryParams . get ( "id" ). equals ( this . id );
65
+ return QueryParamsComparator . isIdEqual ( this , queryParams );
66
66
}
67
67
}
Original file line number Diff line number Diff line change 18
18
@ AllArgsConstructor
19
19
@ EqualsAndHashCode
20
20
@ JsonInclude (JsonInclude .Include .NON_NULL )
21
- public final class Test implements Model {
21
+ public final class Test implements Model , HasId {
22
22
@ JsonProperty
23
23
private long id ;
24
24
@@ -63,11 +63,11 @@ public final class Test implements Model {
63
63
64
64
@ Override
65
65
public boolean equalsQueryString (Map <String , Object > queryParams ) {
66
- if (queryParams == null ) {
66
+ if (QueryParamsComparator . isNull ( queryParams ) ) {
67
67
return false ;
68
68
}
69
69
70
- if (queryParams . containsKey ( "id" ) && queryParams . get ( "id" ). equals ( this . id )) {
70
+ if (QueryParamsComparator . isIdEqual ( this , queryParams )) {
71
71
return true ;
72
72
}
73
73
Original file line number Diff line number Diff line change 16
16
@ AllArgsConstructor
17
17
@ EqualsAndHashCode
18
18
@ JsonInclude (JsonInclude .Include .NON_NULL )
19
- public final class TestType implements Model {
19
+ public final class TestType implements Model , HasId , HasName {
20
20
@ JsonProperty
21
21
private long id ;
22
22
@@ -33,15 +33,15 @@ public final class TestType implements Model {
33
33
34
34
@ Override
35
35
public boolean equalsQueryString (Map <String , Object > queryParams ) {
36
- if (queryParams == null ) {
36
+ if (QueryParamsComparator . isNull ( queryParams ) ) {
37
37
return false ;
38
38
}
39
39
40
- if (queryParams . containsKey ( "id" ) && queryParams . get ( "id" ). equals ( this . id )) {
40
+ if (QueryParamsComparator . isIdEqual ( this , queryParams )) {
41
41
return true ;
42
42
}
43
43
44
- if (queryParams . containsKey ( "name" ) && queryParams . get ( "name" ). equals ( this . name )) {
44
+ if (QueryParamsComparator . isNameEqual ( this , queryParams )) {
45
45
return true ;
46
46
}
47
47
Original file line number Diff line number Diff line change 16
16
@ AllArgsConstructor
17
17
@ EqualsAndHashCode
18
18
@ JsonInclude (JsonInclude .Include .NON_NULL )
19
- public final class ToolConfig implements Model {
19
+ public final class ToolConfig implements Model , HasId , HasName {
20
20
@ JsonProperty
21
21
private long id ;
22
22
@@ -38,15 +38,15 @@ public final class ToolConfig implements Model {
38
38
39
39
@ Override
40
40
public boolean equalsQueryString (Map <String , Object > queryParams ) {
41
- if (queryParams == null ) {
41
+ if (QueryParamsComparator . isNull ( queryParams ) ) {
42
42
return false ;
43
43
}
44
44
45
- if (queryParams . containsKey ( "id" ) && queryParams . get ( "id" ). equals ( this . id )) {
45
+ if (QueryParamsComparator . isIdEqual ( this , queryParams )) {
46
46
return true ;
47
47
}
48
48
49
- if (queryParams . containsKey ( "name" ) && queryParams . get ( "name" ). equals ( this . name )) {
49
+ if (QueryParamsComparator . isNameEqual ( this , queryParams )) {
50
50
return true ;
51
51
}
52
52
Original file line number Diff line number Diff line change 16
16
@ AllArgsConstructor
17
17
@ EqualsAndHashCode
18
18
@ JsonInclude (JsonInclude .Include .NON_NULL )
19
- public final class ToolType implements Model {
19
+ public final class ToolType implements Model , HasId , HasName {
20
20
@ JsonProperty
21
21
private long id ;
22
22
@@ -29,15 +29,15 @@ public final class ToolType implements Model {
29
29
30
30
@ Override
31
31
public boolean equalsQueryString (Map <String , Object > queryParams ) {
32
- if (queryParams == null ) {
32
+ if (QueryParamsComparator . isNull ( queryParams ) ) {
33
33
return false ;
34
34
}
35
35
36
- if (queryParams . containsKey ( "id" ) && queryParams . get ( "id" ). equals ( this . id )) {
36
+ if (QueryParamsComparator . isIdEqual ( this , queryParams )) {
37
37
return true ;
38
38
}
39
39
40
- if (queryParams . containsKey ( "name" ) && queryParams . get ( "name" ). equals ( this . name )) {
40
+ if (QueryParamsComparator . isNameEqual ( this , queryParams )) {
41
41
return true ;
42
42
}
43
43
You can’t perform that action at this time.
0 commit comments