Skip to content

Commit e7e1a06

Browse files
committed
fixed checkstyle warnings in vocabulary package
1 parent 7ce4b29 commit e7e1a06

14 files changed

+106
-65
lines changed

src/main/java/io/goobi/workflow/api/vocabulary/APIException.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
@Getter
77
public class APIException extends RuntimeException {
8+
private static final long serialVersionUID = -8019383979068126463L;
89
private final String url;
910
private final String method;
1011
private final int statusCode;
@@ -13,7 +14,8 @@ public class APIException extends RuntimeException {
1314
private final Exception cause;
1415

1516
public APIException(String url, String method, int statusCode, String reason, VocabularyException vocabularyCause, Exception cause) {
16-
super("API call was not successful" + (statusCode >= 0 ? " with status code [" + statusCode + "]" : "") + ": " + method + " -> " + url + ", Reason:\n" + reason);
17+
super("API call was not successful" + (statusCode >= 0 ? " with status code [" + statusCode + "]" : "")
18+
+ ": " + method + " -> " + url + ", Reason:\n" + reason);
1719
this.url = url;
1820
this.method = method;
1921
this.statusCode = statusCode;

src/main/java/io/goobi/workflow/api/vocabulary/CRUDAPI.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
package io.goobi.workflow.api.vocabulary;
22

3-
import io.goobi.vocabulary.exchange.Identifiable;
4-
53
import java.util.Optional;
64

5+
import io.goobi.vocabulary.exchange.Identifiable;
6+
77
public abstract class CRUDAPI<InstanceType extends Identifiable, PageResultType> {
88
protected final RESTAPI restApi;
99
private final Class<InstanceType> instanceTypeClass;
1010
private final Class<PageResultType> pageResultTypeClass;
1111
private final String commonEndpoint;
1212
private final String instanceEndpoint;
1313

14-
protected CRUDAPI(String address, Class<InstanceType> instanceTypeClass, Class<PageResultType> pageResultTypeClass, String commonEndpoint, String instanceEndpoint) {
14+
protected CRUDAPI(String address, Class<InstanceType> instanceTypeClass, Class<PageResultType> pageResultTypeClass,
15+
String commonEndpoint, String instanceEndpoint) {
1516
this.restApi = new RESTAPI(address);
1617
this.instanceTypeClass = instanceTypeClass;
1718
this.pageResultTypeClass = pageResultTypeClass;

src/main/java/io/goobi/workflow/api/vocabulary/VocabularyAPIManager.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ private boolean versionIsAtLeast(String minVersion, String version) {
8686
return true;
8787
}
8888

89-
public synchronized static VocabularyAPIManager getInstance() {
89+
public static synchronized VocabularyAPIManager getInstance() {
9090
if (instance == null) {
9191
instance = new VocabularyAPIManager();
9292
}
@@ -132,11 +132,18 @@ public static void download(String url) throws IOException {
132132

133133
Optional<String> fileName = extractFileName(response);
134134
Optional<Integer> contentLength = extractContentLength(response);
135+
// Some Faces component library or some Filter might have set some headers in the buffer beforehand.
136+
// We want to get rid of them, else it may collide.
137+
externalContext.responseReset();
135138

136-
externalContext.responseReset(); // Some Faces component library or some Filter might have set some headers in the buffer beforehand. We want to get rid of them, else it may collide.
137-
externalContext.setResponseContentType(MediaType.APPLICATION_OCTET_STREAM); // Check https://www.iana.org/assignments/media-types for all types.
138-
contentLength.ifPresent(externalContext::setResponseContentLength); // Set it with the file size. This header is optional. It will work if it's omitted, but the download progress will be unknown.
139-
fileName.ifPresent(name -> externalContext.setResponseHeader("Content-Disposition", "attachment; filename=\"" + name + "\"")); // The Save As popup magic is done here. You can give it any file name you want.
139+
// Check https://www.iana.org/assignments/media-types for all types.
140+
externalContext.setResponseContentType(MediaType.APPLICATION_OCTET_STREAM);
141+
142+
// Set it with the file size. This header is optional. It will work if it's omitted, but the download progress will be unknown.
143+
contentLength.ifPresent(externalContext::setResponseContentLength);
144+
145+
// The Save As popup magic is done here. You can give it any file name you want.
146+
fileName.ifPresent(name -> externalContext.setResponseHeader("Content-Disposition", "attachment; filename=\"" + name + "\""));
140147

141148
OutputStream output = externalContext.getResponseOutputStream();
142149
IOUtils.copy(response.readEntity(InputStream.class), output);

src/main/java/io/goobi/workflow/api/vocabulary/VocabularyRecordAPI.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,9 @@
2222
import io.goobi.workflow.api.vocabulary.helper.ExtendedVocabularyRecord;
2323
import io.goobi.workflow.api.vocabulary.helper.RecordListRequest;
2424
import jakarta.faces.model.SelectItem;
25-
import lombok.extern.log4j.Log4j2;
2625

27-
@Log4j2
2826
public class VocabularyRecordAPI {
27+
2928
private static final String IN_VOCABULARY_RECORDS_ENDPOINT = "/api/v1/vocabularies/{{0}}/records";
3029
private static final String METADATA_ENDPOINT = "/api/v1/vocabularies/{{0}}/metadata";
3130
private static final String INSTANCE_ENDPOINT = "/api/v1/records/{{0}}";
@@ -260,8 +259,8 @@ private void cleanUpRecord(VocabularyRecord currentRecord) {
260259
}
261260

262261
private boolean translationIsEmpty(TranslationInstance translationInstance) {
263-
return translationInstance.getValue().isEmpty() ||
264-
translationInstance.getLanguage() == null && "null".equals(translationInstance.getValue());
262+
return translationInstance.getValue().isEmpty()
263+
|| translationInstance.getLanguage() == null && "null".equals(translationInstance.getValue());
265264
}
266265

267266
private boolean valueIsEmpty(FieldValue fieldValue) {
Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
package io.goobi.workflow.api.vocabulary.hateoas;
22

3-
import io.goobi.vocabulary.exchange.HateoasHref;
4-
import lombok.Data;
5-
63
import java.util.List;
74
import java.util.Map;
85

6+
import io.goobi.vocabulary.exchange.HateoasHref;
7+
import lombok.Data;
8+
99
@Data
1010
public abstract class BasePageResult<T> {
11+
//CHECKSTYLE:OFF
12+
// spelling is needed for automatic mapping
1113
private Map<String, HateoasHref> _links;
1214
private PageInformation page;
15+
1316
public abstract List<T> getContent();
17+
//CHECKSTYLE:ON
1418
}

src/main/java/io/goobi/workflow/api/vocabulary/hateoas/FieldTypePageResult.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
package io.goobi.workflow.api.vocabulary.hateoas;
22

3+
import java.util.Collections;
4+
import java.util.List;
5+
36
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
7+
48
import io.goobi.vocabulary.exchange.FieldType;
59
import lombok.Data;
610

7-
import java.util.Collections;
8-
import java.util.List;
9-
1011
@Data
1112
@JsonIgnoreProperties(ignoreUnknown = true)
1213
public class FieldTypePageResult extends BasePageResult<FieldType> {
@@ -15,8 +16,12 @@ private final class EmbeddedWrapper {
1516
private List<FieldType> fieldTypeList;
1617
}
1718

19+
//CHECKSTYLE:OFF
20+
// spelling is needed for automatic mapping
1821
private EmbeddedWrapper _embedded;
22+
//CHECKSTYLE:ON
1923

24+
@Override
2025
public List<FieldType> getContent() {
2126
if (_embedded == null) {
2227
return Collections.emptyList();

src/main/java/io/goobi/workflow/api/vocabulary/hateoas/LanguagePageResult.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
package io.goobi.workflow.api.vocabulary.hateoas;
22

3+
import java.util.Collections;
4+
import java.util.List;
5+
36
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
7+
48
import io.goobi.vocabulary.exchange.Language;
59
import lombok.Data;
610

7-
import java.util.Collections;
8-
import java.util.List;
9-
1011
@Data
1112
@JsonIgnoreProperties(ignoreUnknown = true)
1213
public class LanguagePageResult extends BasePageResult<Language> {
@@ -15,8 +16,12 @@ private final class EmbeddedWrapper {
1516
private List<Language> languageList;
1617
}
1718

19+
//CHECKSTYLE:OFF
20+
// spelling is needed for automatic mapping
1821
private EmbeddedWrapper _embedded;
22+
//CHECKSTYLE:ON
1923

24+
@Override
2025
public List<Language> getContent() {
2126
if (_embedded == null) {
2227
return Collections.emptyList();

src/main/java/io/goobi/workflow/api/vocabulary/hateoas/VocabularyPageResult.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
package io.goobi.workflow.api.vocabulary.hateoas;
22

3+
import java.util.Collections;
4+
import java.util.List;
5+
import java.util.stream.Collectors;
6+
37
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
8+
49
import io.goobi.vocabulary.exchange.Vocabulary;
510
import io.goobi.workflow.api.vocabulary.helper.ExtendedVocabulary;
611
import lombok.Data;
712

8-
import java.util.Collections;
9-
import java.util.List;
10-
import java.util.stream.Collectors;
11-
1213
@Data
1314
@JsonIgnoreProperties(ignoreUnknown = true)
1415
public class VocabularyPageResult extends BasePageResult<ExtendedVocabulary> {
@@ -17,16 +18,21 @@ private final class EmbeddedWrapper {
1718
private List<Vocabulary> vocabularyList;
1819
}
1920

21+
//CHECKSTYLE:OFF
22+
// spelling is needed for automatic mapping
2023
private List<ExtendedVocabulary> content;
2124

2225
private EmbeddedWrapper _embedded;
26+
//CHECKSTYLE:ON
2327

28+
@Override
2429
public List<ExtendedVocabulary> getContent() {
2530
if (content == null) {
2631
if (_embedded == null) {
2732
this.content = Collections.emptyList();
2833
} else {
29-
this.content = _embedded.getVocabularyList().stream()
34+
this.content = _embedded.getVocabularyList()
35+
.stream()
3036
.map(ExtendedVocabulary::new)
3137
.collect(Collectors.toList());
3238
}

src/main/java/io/goobi/workflow/api/vocabulary/hateoas/VocabularyRecordPageResult.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
package io.goobi.workflow.api.vocabulary.hateoas;
22

3+
import java.util.Collections;
4+
import java.util.List;
5+
import java.util.stream.Collectors;
6+
37
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
8+
49
import io.goobi.vocabulary.exchange.VocabularyRecord;
510
import io.goobi.workflow.api.vocabulary.helper.ExtendedVocabularyRecord;
611
import lombok.Data;
712

8-
import java.util.Collections;
9-
import java.util.List;
10-
import java.util.stream.Collectors;
11-
1213
@Data
1314
@JsonIgnoreProperties(ignoreUnknown = true)
1415
public class VocabularyRecordPageResult extends BasePageResult<ExtendedVocabularyRecord> {
@@ -17,16 +18,21 @@ private final class EmbeddedWrapper {
1718
private List<VocabularyRecord> vocabularyRecordList;
1819
}
1920

21+
//CHECKSTYLE:OFF
22+
// spelling is needed for automatic mapping
2023
private EmbeddedWrapper _embedded;
2124

2225
private List<ExtendedVocabularyRecord> content;
26+
//CHECKSTYLE:ON
2327

28+
@Override
2429
public List<ExtendedVocabularyRecord> getContent() {
2530
if (content == null) {
2631
if (_embedded == null) {
2732
this.content = Collections.emptyList();
2833
} else {
29-
this.content = _embedded.getVocabularyRecordList().stream()
34+
this.content = _embedded.getVocabularyRecordList()
35+
.stream()
3036
.map(ExtendedVocabularyRecord::new)
3137
.collect(Collectors.toList());
3238
}

src/main/java/io/goobi/workflow/api/vocabulary/hateoas/VocabularySchemaPageResult.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
package io.goobi.workflow.api.vocabulary.hateoas;
22

3+
import java.util.Collections;
4+
import java.util.List;
5+
36
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
7+
48
import io.goobi.vocabulary.exchange.VocabularySchema;
59
import lombok.Data;
610

7-
import java.util.Collections;
8-
import java.util.List;
9-
1011
@Data
1112
@JsonIgnoreProperties(ignoreUnknown = true)
1213
public class VocabularySchemaPageResult extends BasePageResult<VocabularySchema> {
@@ -15,8 +16,12 @@ private final class EmbeddedWrapper {
1516
private List<VocabularySchema> vocabularySchemaList;
1617
}
1718

19+
//CHECKSTYLE:OFF
20+
// spelling is needed for automatic mapping
1821
private EmbeddedWrapper _embedded;
22+
//CHECKSTYLE:ON
1923

24+
@Override
2025
public List<VocabularySchema> getContent() {
2126
if (_embedded == null) {
2227
return Collections.emptyList();

0 commit comments

Comments
 (0)