Skip to content

Commit

Permalink
address code quality issues #EA-3957
Browse files Browse the repository at this point in the history
  • Loading branch information
gsergiu committed Nov 6, 2024
1 parent 6299687 commit 8b8a913
Showing 1 changed file with 16 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package eu.europeana.set.web.service.controller.jsonld;

import static eu.europeana.api.commons.web.definitions.WebFields.FORMAT_JSONLD;
import static eu.europeana.set.definitions.model.vocabulary.WebUserSetModelFields.PINNED_POSITION;
import java.io.IOException;
import java.util.Collections;
import java.util.Date;
Expand Down Expand Up @@ -28,7 +30,6 @@
import eu.europeana.api.commons.definitions.exception.DateParsingException;
import eu.europeana.api.commons.definitions.utils.DateUtils;
import eu.europeana.api.commons.definitions.vocabulary.CommonApiConstants;
import eu.europeana.api.commons.web.definitions.WebFields;
import eu.europeana.api.commons.web.exception.ApplicationAuthenticationException;
import eu.europeana.api.commons.web.exception.HttpException;
import eu.europeana.api.commons.web.exception.InternalServerException;
Expand Down Expand Up @@ -114,7 +115,7 @@ protected ResponseEntity<String> storeUserSet(String userSetJsonLdStr,
String serializedUserSetJsonLdStr = serializeUserSet(LdProfiles.MINIMAL, storedUserSet);

String etag =
generateETag(storedUserSet.getModified(), WebFields.FORMAT_JSONLD, getApiVersion());
generateETag(storedUserSet.getModified(), FORMAT_JSONLD, getApiVersion());

MultiValueMap<String, String> headers = new LinkedMultiValueMap<>(5);
headers.add(HttpHeaders.LINK, UserSetHttpHeaders.VALUE_BASIC_CONTAINER);
Expand Down Expand Up @@ -297,7 +298,7 @@ protected ResponseEntity<String> updateUserSet(HttpServletRequest request, Authe

// check timestamp if provided within the “If-Match” HTTP header, if false
// respond with HTTP 412
String eTagOrigin = generateETag(existingUserSet.getModified(), WebFields.FORMAT_JSONLD, getApiVersion());
String eTagOrigin = generateETag(existingUserSet.getModified(), FORMAT_JSONLD, getApiVersion());
checkIfMatchHeader(eTagOrigin, request);

// parse fields of the new user set to an object
Expand Down Expand Up @@ -397,7 +398,7 @@ protected ResponseEntity<String> publishUnpublishUserSet(String identifier, Auth
// serialize to JsonLd
String serializedUserSetJsonLdStr = serializeUserSet(profile, updatedUserSet);
String etag =
generateETag(updatedUserSet.getModified(), WebFields.FORMAT_JSONLD, getApiVersion());
generateETag(updatedUserSet.getModified(), FORMAT_JSONLD, getApiVersion());

// build response entity with headers
MultiValueMap<String, String> headers = new LinkedMultiValueMap<>(5);
Expand Down Expand Up @@ -479,7 +480,7 @@ protected ResponseEntity<String> insertItemIntoUserSet(HttpServletRequest reques

// if set is not entity set and position is "pin", throw exception
if (!existingUserSet.isEntityBestItemsSet()
&& StringUtils.equals(position, WebUserSetFields.PINNED_POSITION)) {
&& StringUtils.equals(position, PINNED_POSITION)) {
throw new RequestValidationException(UserSetI18nConstants.USER_SET_OPERATION_NOT_ALLOWED,
new String[] {"Pinning item ", existingUserSet.getType()});
}
Expand All @@ -493,7 +494,7 @@ protected ResponseEntity<String> insertItemIntoUserSet(HttpServletRequest reques
// check timestamp if provided within the “If-Match” HTTP header, if false
// respond with HTTP 412
String eTagOrigin =
generateETag(existingUserSet.getModified(), WebFields.FORMAT_JSONLD, getApiVersion());
generateETag(existingUserSet.getModified(), FORMAT_JSONLD, getApiVersion());
checkIfMatchHeader(eTagOrigin, request);

UserSet updatedUserSet =
Expand All @@ -502,7 +503,7 @@ protected ResponseEntity<String> insertItemIntoUserSet(HttpServletRequest reques
String serializedUserSetJsonLdStr = serializeUserSet(LdProfiles.MINIMAL, updatedUserSet);

String etag =
generateETag(updatedUserSet.getModified(), WebFields.FORMAT_JSONLD, getApiVersion());
generateETag(updatedUserSet.getModified(), FORMAT_JSONLD, getApiVersion());

// build response entity with headers
MultiValueMap<String, String> headers = new LinkedMultiValueMap<>();
Expand Down Expand Up @@ -549,7 +550,7 @@ protected ResponseEntity<String> insertMultipleItemsIntoUserSet(HttpServletReque

// if set is not entity best item set and position is "pin", throw exception
if (!existingUserSet.isEntityBestItemsSet()
&& StringUtils.equals(position, WebUserSetFields.PINNED_POSITION)) {
&& StringUtils.equals(position, PINNED_POSITION)) {
throw new RequestValidationException(UserSetI18nConstants.USER_SET_OPERATION_NOT_ALLOWED,
new String[] {"Pinning item ", existingUserSet.getType()});
}
Expand All @@ -568,7 +569,7 @@ protected ResponseEntity<String> insertMultipleItemsIntoUserSet(HttpServletReque
// check timestamp if provided within the “If-Match” HTTP header, if false
// respond with HTTP 412
String eTagOrigin =
generateETag(existingUserSet.getModified(), WebFields.FORMAT_JSONLD, getApiVersion());
generateETag(existingUserSet.getModified(), FORMAT_JSONLD, getApiVersion());
checkIfMatchHeader(eTagOrigin, request);

UserSet updatedUserSet =
Expand All @@ -577,7 +578,7 @@ protected ResponseEntity<String> insertMultipleItemsIntoUserSet(HttpServletReque
String serializedUserSetJsonLdStr = serializeUserSet(LdProfiles.MINIMAL, updatedUserSet);

String etag =
generateETag(updatedUserSet.getModified(), WebFields.FORMAT_JSONLD, getApiVersion());
generateETag(updatedUserSet.getModified(), FORMAT_JSONLD, getApiVersion());

// build response entity with headers
MultiValueMap<String, String> headers = new LinkedMultiValueMap<>();
Expand All @@ -599,7 +600,7 @@ protected ResponseEntity<String> insertMultipleItemsIntoUserSet(HttpServletReque

//returns -1 if not provided
private int parseItemsPosition(String position) throws ParamValidationException {
if(StringUtils.equals(position, WebUserSetFields.PINNED_POSITION)) {
if(StringUtils.equals(position, PINNED_POSITION)) {
return 0;
}
int positionFinal = -1;
Expand Down Expand Up @@ -704,7 +705,7 @@ protected ResponseEntity<String> isItemInUserSet(String wsKey, String identifier
}


@Deprecated
@Deprecated(since="EA-3869", forRemoval = true)
@DeleteMapping(value = {"/set/{identifier}/{datasetId}/{localId}"},
produces = {HttpHeaders.CONTENT_TYPE_JSONLD_UTF8, HttpHeaders.CONTENT_TYPE_JSON_UTF8})
@Operation(description = SwaggerConstants.DELETE_ITEM_NOTE, summary = "Delete a item from the set")
Expand Down Expand Up @@ -768,7 +769,7 @@ protected ResponseEntity<String> deleteItemFromUserSet(Authentication authentica
// serialize to JsonLd
String serializedUserSetJsonLdStr = serializeUserSet(LdProfiles.MINIMAL, updatedUserSet);
String etag =
generateETag(updatedUserSet.getModified(), WebFields.FORMAT_JSONLD, getApiVersion());
generateETag(updatedUserSet.getModified(), FORMAT_JSONLD, getApiVersion());

// respond with HTTP 200 containing the updated Set description as body.
// serialize Set in JSON-LD following the requested profile
Expand Down Expand Up @@ -824,7 +825,7 @@ protected ResponseEntity<String> deleteMultipleItemsFromUserSet(Authentication a
// serialize to JsonLd
String serializedUserSetJsonLdStr = serializeUserSet(LdProfiles.MINIMAL, updatedUserSet);
String etag =
generateETag(updatedUserSet.getModified(), WebFields.FORMAT_JSONLD, getApiVersion());
generateETag(updatedUserSet.getModified(), FORMAT_JSONLD, getApiVersion());

// respond with HTTP 200 containing the updated Set description as body.
// serialize Set in JSON-LD following the requested profile
Expand Down Expand Up @@ -891,7 +892,7 @@ protected ResponseEntity<String> deleteUserSet(HttpServletRequest request, Strin
// check timestamp if provided within the "If-Match" HTTP header, if false
// respond with HTTP 412
String eTagOrigin =
generateETag(existingUserSet.getModified(), WebFields.FORMAT_JSONLD, getApiVersion());
generateETag(existingUserSet.getModified(), FORMAT_JSONLD, getApiVersion());
checkIfMatchHeader(eTagOrigin, request);

// if the user set is disabled and the user is not an admin, respond with HTTP
Expand Down

0 comments on commit 8b8a913

Please sign in to comment.