8
8
import java .util .Date ;
9
9
import java .util .List ;
10
10
11
- import javax .faces .context .ExternalContext ;
12
- import javax .ws .rs .client .Client ;
13
- import javax .ws .rs .client .ClientBuilder ;
14
- import javax .ws .rs .client .WebTarget ;
15
- import javax .ws .rs .core .GenericType ;
16
-
17
11
import org .goobi .beans .User ;
18
12
import org .goobi .production .enums .PluginType ;
19
13
import org .goobi .production .plugin .interfaces .IAdministrationPlugin ;
20
14
import org .goobi .production .plugin .interfaces .IPlugin ;
15
+ import org .jfree .util .Log ;
21
16
22
17
import de .intranda .counterscript .model .MetadataInformation ;
23
18
import de .sub .goobi .config .ConfigPlugins ;
24
19
import de .sub .goobi .helper .FacesContextHelper ;
25
20
import de .sub .goobi .helper .Helper ;
21
+ import jakarta .faces .context .ExternalContext ;
22
+ import jakarta .ws .rs .client .Client ;
23
+ import jakarta .ws .rs .client .ClientBuilder ;
24
+ import jakarta .ws .rs .client .WebTarget ;
25
+ import jakarta .ws .rs .core .GenericType ;
26
26
import lombok .Cleanup ;
27
27
import lombok .Data ;
28
28
import net .xeoh .plugins .base .annotations .PluginImplementation ;
29
29
30
30
@ PluginImplementation
31
31
public @ Data class CounterscriptPlugin implements IAdministrationPlugin , IPlugin {
32
32
33
- private String REST_URL = "http://localhost:8081/Counterscript/api/" ;
33
+ private static final long serialVersionUID = 2320742556608952269L ;
34
+ private String restUrl = "http://localhost:8081/Counterscript/api/" ;
34
35
private String token ;
35
36
36
37
private static final String TITLE = "Counterscript" ;
42
43
private boolean includeOutdatedData = false ;
43
44
private String currentNumber ;
44
45
45
- private List <MetadataInformation > dataList = null ;
46
- private List <MetadataInformation > detailList = null ;
46
+ private transient List <MetadataInformation > dataList = null ;
47
+ private transient List <MetadataInformation > detailList = null ;
47
48
48
- private int NUMBER_OF_OBJECTS_PER_PAGE = 10 ;
49
+ private int entriesPerPage = 10 ;
49
50
50
51
private int pageNo = 0 ;
51
52
54
55
public CounterscriptPlugin () {
55
56
User user = Helper .getCurrentUser ();
56
57
if (user != null ) {
57
- NUMBER_OF_OBJECTS_PER_PAGE = user .getTabellengroesse ();
58
+ entriesPerPage = user .getTabellengroesse ();
58
59
}
59
- REST_URL = ConfigPlugins .getPluginConfig (PLUGIN_TITLE ).getString ("rest_url" , "http://localhost:8080/Counterscript/api/" );
60
+ restUrl = ConfigPlugins .getPluginConfig (PLUGIN_TITLE ).getString ("rest_url" , "http://localhost:8080/Counterscript/api/" );
60
61
token = ConfigPlugins .getPluginConfig (PLUGIN_TITLE ).getString ("rest_token" );
61
- // REST_URL = ConfigPlugins.getPluginConfig(this).getString("rest_url", "http://localhost:8080/Counterscript/api/");
62
62
63
63
}
64
64
@@ -72,31 +72,27 @@ public String getTitle() {
72
72
return TITLE ;
73
73
}
74
74
75
- public String getDescription () {
76
- return TITLE ;
77
- }
78
-
79
75
@ Override
80
76
public String getGui () {
81
77
return "/uii/administration_Counterscript.xhtml" ;
82
78
}
83
79
84
80
public void getData () {
85
- Client client = ClientBuilder .newClient ();
86
- WebTarget base = client .target (REST_URL );
87
- WebTarget xml = base .path ("xml" );
88
- if (includeOutdatedData ) {
89
- xml = xml .path ("withinactive" );
90
- }
81
+ try ( Client client = ClientBuilder .newClient ()) {
82
+ WebTarget base = client .target (restUrl );
83
+ WebTarget xml = base .path ("xml" );
84
+ if (includeOutdatedData ) {
85
+ xml = xml .path ("withinactive" );
86
+ }
91
87
92
- if (startDate != null && endDate != null ) {
93
- String start = dateConverter .format (startDate );
94
- String end = dateConverter .format (endDate );
95
- xml = xml .path (start ).path (end );
88
+ if (startDate != null && endDate != null ) {
89
+ String start = dateConverter .format (startDate );
90
+ String end = dateConverter .format (endDate );
91
+ xml = xml .path (start ).path (end );
92
+ }
93
+ dataList = xml .request ().header ("token" , token ).get (new GenericType <List <MetadataInformation >>() {
94
+ });
96
95
}
97
- dataList = xml .request ().header ("token" , token ).get (new GenericType <List <MetadataInformation >>() {
98
- });
99
-
100
96
}
101
97
102
98
public void resetData () {
@@ -105,80 +101,83 @@ public void resetData() {
105
101
}
106
102
107
103
public void getDetails () {
108
- Client client = ClientBuilder .newClient ();
109
- WebTarget base = client .target (REST_URL );
110
- WebTarget xml = base .path ("xml" );
111
- xml = xml .path ("bnumber" ).path (currentNumber );
112
- detailList = xml .request ().header ("token" , token ).get (new GenericType <List <MetadataInformation >>() {
113
- });
104
+ try (Client client = ClientBuilder .newClient ()) {
105
+ WebTarget base = client .target (restUrl );
106
+ WebTarget xml = base .path ("xml" );
107
+ xml = xml .path ("bnumber" ).path (currentNumber );
108
+ detailList = xml .request ().header ("token" , token ).get (new GenericType <List <MetadataInformation >>() {
109
+ });
110
+ }
114
111
}
115
112
116
113
public void download () {
117
114
118
- Client client = ClientBuilder .newClient ();
119
- WebTarget base = client .target (REST_URL );
120
- WebTarget csv = base .path ("csv" );
121
- if (includeOutdatedData ) {
122
- csv = csv .path ("withinactive" );
123
- }
124
-
125
- if (startDate != null && endDate != null ) {
126
- String start = dateConverter .format (startDate );
127
- String end = dateConverter .format (endDate );
128
- csv = csv .path (start ).path (end );
129
- }
130
- csv = csv .queryParam ("token" , token );
131
- try {
132
- ExternalContext ec = FacesContextHelper .getCurrentFacesContext ().getExternalContext ();
133
-
134
- ec .responseReset (); // Some JSF component library or some Filter might have set some headers in the
135
- // buffer beforehand. We want to get rid of them, else it may collide.
136
- ec .setResponseContentType ("text/csv" ); // Check http://www.iana.org/assignments/media-types for all types.
137
- // Use if necessary ExternalContext#getMimeType() for auto-detection
138
- // based on filename.
139
- ec .setResponseHeader ("Content-Disposition" , "attachment; filename=\" counterscript.csv\" " ); // The Save As
140
- // popup magic
141
- // is done here.
142
- // You can give
143
- // it any file
144
- // name you
145
- // want, this
146
- // only won't
147
- // work in MSIE,
148
- // it will use
149
- // current
150
- // request URL
151
- // as file name
152
- // instead.
153
-
154
- OutputStream outStream = ec .getResponseOutputStream ();
155
-
156
- @ Cleanup
157
- InputStream inStream = csv .getUri ().toURL ().openStream ();
158
-
159
- byte [] buffer = new byte [1024 ];
160
-
161
- int length ;
162
-
163
- while ((length = inStream .read (buffer )) > 0 ) {
164
- outStream .write (buffer , 0 , length );
115
+ try (Client client = ClientBuilder .newClient ()) {
116
+ WebTarget base = client .target (restUrl );
117
+ WebTarget csv = base .path ("csv" );
118
+ if (includeOutdatedData ) {
119
+ csv = csv .path ("withinactive" );
165
120
}
166
- FacesContextHelper .getCurrentFacesContext ().responseComplete (); // Important! Otherwise JSF will attempt to
167
- // render the response which obviously will
168
- // fail since it's already written with a
169
- // file and closed.
170
121
171
- } catch (IOException e ) {
122
+ if (startDate != null && endDate != null ) {
123
+ String start = dateConverter .format (startDate );
124
+ String end = dateConverter .format (endDate );
125
+ csv = csv .path (start ).path (end );
126
+ }
127
+ csv = csv .queryParam ("token" , token );
128
+ try {
129
+ ExternalContext ec = FacesContextHelper .getCurrentFacesContext ().getExternalContext ();
130
+
131
+ ec .responseReset (); // Some JSF component library or some Filter might have set some headers in the
132
+ // buffer beforehand. We want to get rid of them, else it may collide.
133
+ ec .setResponseContentType ("text/csv" ); // Check http://www.iana.org/assignments/media-types for all types.
134
+ // Use if necessary ExternalContext#getMimeType() for auto-detection
135
+ // based on filename.
136
+ ec .setResponseHeader ("Content-Disposition" , "attachment; filename=\" counterscript.csv\" " ); // The Save As
137
+ // popup magic
138
+ // is done here.
139
+ // You can give
140
+ // it any file
141
+ // name you
142
+ // want, this
143
+ // only won't
144
+ // work in MSIE,
145
+ // it will use
146
+ // current
147
+ // request URL
148
+ // as file name
149
+ // instead.
150
+
151
+ OutputStream outStream = ec .getResponseOutputStream ();
152
+
153
+ @ Cleanup
154
+ InputStream inStream = csv .getUri ().toURL ().openStream ();
155
+
156
+ byte [] buffer = new byte [1024 ];
157
+
158
+ int length ;
159
+
160
+ while ((length = inStream .read (buffer )) > 0 ) {
161
+ outStream .write (buffer , 0 , length );
162
+ }
163
+ FacesContextHelper .getCurrentFacesContext ().responseComplete (); // Important! Otherwise JSF will attempt to
164
+ // render the response which obviously will
165
+ // fail since it's already written with a
166
+ // file and closed.
167
+
168
+ } catch (IOException e ) {
169
+ Log .error (e );
170
+ }
172
171
}
173
172
}
174
173
175
174
public List <MetadataInformation > getPaginatorList () {
176
175
List <MetadataInformation > subList = new ArrayList <>();
177
176
if (dataList != null ) {
178
- if (dataList .size () > (pageNo * NUMBER_OF_OBJECTS_PER_PAGE ) + NUMBER_OF_OBJECTS_PER_PAGE ) {
179
- subList = dataList .subList (pageNo * NUMBER_OF_OBJECTS_PER_PAGE , (pageNo * NUMBER_OF_OBJECTS_PER_PAGE ) + NUMBER_OF_OBJECTS_PER_PAGE );
177
+ if (dataList .size () > (pageNo * entriesPerPage ) + entriesPerPage ) {
178
+ subList = dataList .subList (pageNo * entriesPerPage , (pageNo * entriesPerPage ) + entriesPerPage );
180
179
} else {
181
- subList = dataList .subList (pageNo * NUMBER_OF_OBJECTS_PER_PAGE , dataList .size ());
180
+ subList = dataList .subList (pageNo * entriesPerPage , dataList .size ());
182
181
}
183
182
}
184
183
return subList ;
@@ -228,8 +227,8 @@ public int getTxtMoveTo() {
228
227
}
229
228
230
229
public int getLastPageNumber () {
231
- int ret = new Double (Math .floor (this .dataList .size () / NUMBER_OF_OBJECTS_PER_PAGE )).intValue ();
232
- if (this .dataList .size () % NUMBER_OF_OBJECTS_PER_PAGE == 0 ) {
230
+ int ret = Double . valueOf (Math .floor (this .dataList .size () / entriesPerPage )).intValue ();
231
+ if (this .dataList .size () % entriesPerPage == 0 ) {
233
232
ret --;
234
233
}
235
234
return ret ;
@@ -244,7 +243,7 @@ public boolean isLastPage() {
244
243
}
245
244
246
245
public boolean hasNextPage () {
247
- return this .dataList .size () > NUMBER_OF_OBJECTS_PER_PAGE ;
246
+ return this .dataList .size () > entriesPerPage ;
248
247
}
249
248
250
249
public boolean hasPreviousPage () {
0 commit comments