diff --git a/common/src/main/java/de/uni_jena/thunibib/HISinOneCommands.java b/common/src/main/java/de/uni_jena/thunibib/HISinOneCommands.java index 078029192..86602e8e3 100644 --- a/common/src/main/java/de/uni_jena/thunibib/HISinOneCommands.java +++ b/common/src/main/java/de/uni_jena/thunibib/HISinOneCommands.java @@ -52,7 +52,7 @@ public static SysValue publish(String mcrid) { Response response = client.post(conf.getPath(), json)) { if (response.getStatusInfo().getFamily() != Response.Status.Family.SUCCESSFUL) { - LOGGER.error("{}", response.readEntity(String.class)); + LOGGER.error("HISinOne api error: {}", response.readEntity(String.class)); return SysValue.ErroneousSysValue; } @@ -109,7 +109,7 @@ public static SysValue update(String mcrid) { SysValue p = response.readEntity(conf.getResponseEntityClass()); if (response.getStatusInfo().getFamily() != Response.Status.Family.SUCCESSFUL) { - LOGGER.error("{}", response.readEntity(String.class)); + LOGGER.error("HISinOne api error: {}", response.readEntity(String.class)); return SysValue.ErroneousSysValue; } diff --git a/common/src/main/java/de/uni_jena/thunibib/his/xml/HISinOneResolver.java b/common/src/main/java/de/uni_jena/thunibib/his/xml/HISinOneResolver.java index dff07fd1b..1947972e5 100644 --- a/common/src/main/java/de/uni_jena/thunibib/his/xml/HISinOneResolver.java +++ b/common/src/main/java/de/uni_jena/thunibib/his/xml/HISinOneResolver.java @@ -168,6 +168,7 @@ protected SysValue resolveJournal(String fromValue) { Response response = hisClient.get(Journal.getPath() + "/" + hisId)) { if (response.getStatusInfo().getFamily() != Response.Status.Family.SUCCESSFUL) { + logHISMessage(response); return SysValue.ErroneousSysValue; } Journal journal = response.readEntity(Journal.class); @@ -203,6 +204,7 @@ private SysValue resolvePublicationResourceType(String resourceTypeText) { Response response = hisClient.get(PublicationResourceValue.getPath())) { if (response.getStatusInfo().getFamily() != Response.Status.Family.SUCCESSFUL) { + logHISMessage(response); return SysValue.ErroneousSysValue; } @@ -258,6 +260,7 @@ private SysValue resolvePublication(String mcrid) { Response response = hisClient.get(Publication.getPath() + "/" + hisid)) { if (response.getStatusInfo().getFamily() != Response.Status.Family.SUCCESSFUL) { + logHISMessage(response); return SysValue.ErroneousSysValue; } @@ -280,6 +283,7 @@ private SysValue resolvePublisher(String value) { Response response = hisClient.get(PublisherWrappedValue.getPath(), params)) { if (response.getStatusInfo().getFamily() != Response.Status.Family.SUCCESSFUL) { + logHISMessage(response); return SysValue.ErroneousSysValue; } @@ -323,10 +327,15 @@ private SysValue createPublisher(String value) { jsonObject.addProperty("place", "unbekannt"); try (HISInOneClient hisClient = HISinOneClientFactory.create(); - Response resp = hisClient.post(PublisherWrappedValue.getPath(PublisherWrappedValue.PathType.create), + Response response = hisClient.post(PublisherWrappedValue.getPath(PublisherWrappedValue.PathType.create), jsonObject.toString())) { - PublisherWrappedValue publisher = resp.readEntity(PublisherWrappedValue.class); + if (response.getStatusInfo().getFamily() != Response.Status.Family.SUCCESSFUL) { + logHISMessage(response); + return SysValue.ErroneousSysValue; + } + + PublisherWrappedValue publisher = response.readEntity(PublisherWrappedValue.class); PUBLISHER_MAP.put(decodedValue, publisher); return publisher; } @@ -348,6 +357,7 @@ private SysValue resolvePeerReviewedType(String peerReviewedCategId) { Response response = hisClient.get(PeerReviewedValue.getPath())) { if (response.getStatusInfo().getFamily() != Response.Status.Family.SUCCESSFUL) { + logHISMessage(response); return SysValue.ErroneousSysValue; } @@ -389,6 +399,11 @@ private SysValue resolvePublicationAccessType(String accessRightsCategId) { try (HISInOneClient hisClient = HISinOneClientFactory.create(); Response response = hisClient.get(PublicationAccessTypeValue.getPath())) { + if (response.getStatusInfo().getFamily() != Response.Status.Family.SUCCESSFUL) { + logHISMessage(response); + return SysValue.ErroneousSysValue; + } + List accessTypes = response.readEntity( new GenericType>() { }); @@ -431,6 +446,12 @@ private SysValue resolveResearchAreaKdsf(String areaCategId) { try (HISInOneClient hisClient = HISinOneClientFactory.create(); Response response = hisClient.get(ResearchAreaKdsfValue.getPath())) { + + if (response.getStatusInfo().getFamily() != Response.Status.Family.SUCCESSFUL) { + logHISMessage(response); + return SysValue.ErroneousSysValue; + } + List availableTypes = response.readEntity( new GenericType>() { }); @@ -464,6 +485,11 @@ private SysValue resolveIdentifierType(String identifierType) { try (HISInOneClient hisClient = HISinOneClientFactory.create(); Response response = hisClient.get(GlobalIdentifierType.getPath())) { + if (response.getStatusInfo().getFamily() != Response.Status.Family.SUCCESSFUL) { + logHISMessage(response); + return SysValue.ErroneousSysValue; + } + List availableTypes = response.readEntity( new GenericType>() { }); @@ -489,6 +515,11 @@ protected SysValue resolvePublicationType(String ubogenre, String hostGenre) { try (HISInOneClient hisClient = HISinOneClientFactory.create(); Response response = hisClient.get(PublicationTypeValue.getPath())) { + if (response.getStatusInfo().getFamily() != Response.Status.Family.SUCCESSFUL) { + logHISMessage(response); + return SysValue.ErroneousSysValue; + } + List pubTypeValues = response.readEntity( new GenericType>() { }); @@ -526,6 +557,15 @@ private SysValue resolveDocumentType(String ubogenre, String hostGenre) { Response bookResp = hisClient.get(DocumentType.getPath(DocumentType.PathType.book)); Response articleResp = hisClient.get(DocumentType.getPath(DocumentType.PathType.article))) { + if (bookResp.getStatusInfo().getFamily() != Response.Status.Family.SUCCESSFUL) { + logHISMessage(bookResp); + return SysValue.ErroneousSysValue; + } + if (articleResp.getStatusInfo().getFamily() != Response.Status.Family.SUCCESSFUL) { + logHISMessage(articleResp); + return SysValue.ErroneousSysValue; + } + List ofBook = bookResp.readEntity(new GenericType>() { }); ofBook.addAll(articleResp.readEntity(new GenericType>() { @@ -560,6 +600,11 @@ private SysValue resolveThesisType(String ubogenre) { try (HISInOneClient hisClient = HISinOneClientFactory.create(); Response response = hisClient.get(QualificationThesisValue.getPath())) { + if (response.getStatusInfo().getFamily() != Response.Status.Family.SUCCESSFUL) { + logHISMessage(response); + return SysValue.ErroneousSysValue; + } + List thesisValues = response.readEntity( new GenericType>() { }); @@ -598,6 +643,10 @@ private SysValue resolveSubjectArea(String destatisId) { try (HISInOneClient hisClient = HISinOneClientFactory.create(); Response response = hisClient.get(SubjectAreaValue.getPath())) { + if (response.getStatusInfo().getFamily() != Response.Status.Family.SUCCESSFUL) { + logHISMessage(response); + return SysValue.ErroneousSysValue; + } List subjectAreas = response.readEntity( new GenericType>() { @@ -622,6 +671,10 @@ protected SysValue resolveCreatorType(String value) { try (HISInOneClient hisClient = HISinOneClientFactory.create(); Response response = hisClient.get("cs/sys/values/publicationCreatorTypeValue")) { + if (response.getStatusInfo().getFamily() != Response.Status.Family.SUCCESSFUL) { + logHISMessage(response); + return SysValue.ErroneousSysValue; + } List creatorTypes = response.readEntity( new GenericType>() { @@ -653,6 +706,10 @@ protected SysValue resolveVisibility(String statusCategId) { try (HISInOneClient hisClient = HISinOneClientFactory.create(); Response response = hisClient.get(VisibilityValue.getPath())) { + if (response.getStatusInfo().getFamily() != Response.Status.Family.SUCCESSFUL) { + logHISMessage(response); + return SysValue.ErroneousSysValue; + } List visState = response.readEntity( new GenericType>() { @@ -684,6 +741,10 @@ protected SysValue resolveState(String statusCategId) { try (HISInOneClient hisClient = HISinOneClientFactory.create(); Response response = hisClient.get(PublicationState.getPath())) { + if (response.getStatusInfo().getFamily() != Response.Status.Family.SUCCESSFUL) { + logHISMessage(response); + return SysValue.ErroneousSysValue; + } List pubState = response.readEntity( new GenericType>() { @@ -711,7 +772,11 @@ protected SysValue resolveLanguage(String rfc5646) { try (HISInOneClient hisClient = HISinOneClientFactory.create(); Response response = hisClient.get(LanguageValue.getPath())) { - + if (response.getStatusInfo().getFamily() != Response.Status.Family.SUCCESSFUL) { + logHISMessage(response); + return SysValue.ErroneousSysValue; + } + List languageValues = response.readEntity(new GenericType>() { }); @@ -769,4 +834,13 @@ protected boolean exists(String mcrid) { } return true; } + + /** + * Logs the response to the error log. Closes the {@link Response} object. + * + * @param response the response + */ + protected final void logHISMessage(Response response) { + LOGGER.error("HISinOne api message: {}", response.readEntity(String.class)); + } }