Skip to content

Commit

Permalink
#550 Log api errors from HISinOne to error log
Browse files Browse the repository at this point in the history
  • Loading branch information
Possommi committed Nov 4, 2024
1 parent 13c32ac commit 1d6036a
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand All @@ -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;
}

Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
}

Expand Down Expand Up @@ -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<PublicationAccessTypeValue> accessTypes = response.readEntity(
new GenericType<List<PublicationAccessTypeValue>>() {
});
Expand Down Expand Up @@ -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<ResearchAreaKdsfValue> availableTypes = response.readEntity(
new GenericType<List<ResearchAreaKdsfValue>>() {
});
Expand Down Expand Up @@ -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<GlobalIdentifierType> availableTypes = response.readEntity(
new GenericType<List<GlobalIdentifierType>>() {
});
Expand All @@ -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<PublicationTypeValue> pubTypeValues = response.readEntity(
new GenericType<List<PublicationTypeValue>>() {
});
Expand Down Expand Up @@ -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<DocumentType> ofBook = bookResp.readEntity(new GenericType<List<DocumentType>>() {
});
ofBook.addAll(articleResp.readEntity(new GenericType<List<DocumentType>>() {
Expand Down Expand Up @@ -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<QualificationThesisValue> thesisValues = response.readEntity(
new GenericType<List<QualificationThesisValue>>() {
});
Expand Down Expand Up @@ -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<SubjectAreaValue> subjectAreas = response.readEntity(
new GenericType<List<SubjectAreaValue>>() {
Expand All @@ -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<PublicationCreatorTypeValue> creatorTypes = response.readEntity(
new GenericType<List<PublicationCreatorTypeValue>>() {
Expand Down Expand Up @@ -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<VisibilityValue> visState = response.readEntity(
new GenericType<List<VisibilityValue>>() {
Expand Down Expand Up @@ -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<PublicationState> pubState = response.readEntity(
new GenericType<List<PublicationState>>() {
Expand Down Expand Up @@ -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<LanguageValue> languageValues = response.readEntity(new GenericType<List<LanguageValue>>() {
});

Expand Down Expand Up @@ -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));
}
}

0 comments on commit 1d6036a

Please sign in to comment.