Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

profile parameter can be a comma separated string #249

Merged
merged 4 commits into from
Jun 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,15 @@ ItemIdsResultPage buildItemIdsResultsPage(String setId, List<String> itemIds, in
* @return profiled user set value
*/
void applyProfile(UserSet userSet, LdProfiles profile);

/**
* Gets the profile for pagination urls and item page. Basically gets the profile valid for
* collection page from the list of profiles passed during search request
*
* @param profiles list of candidate profiles
* @return the profile to be applied for generating the pagination
*/
LdProfiles getProfileForPagination(List<LdProfiles> profiles);

/**
* Return the List of entity sets with
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,9 @@ protected ResponseEntity<String> storeUserSet(String userSetJsonLdStr,
throws HttpException {
try {

LdProfiles profile = getProfile(profileStr, request);

// validate params - profile
List<LdProfiles> profiles = getProfiles(profileStr, request);

// parse user set
UserSet webUserSet = getUserSetService().parseUserSetLd(userSetJsonLdStr);

Expand All @@ -116,6 +117,9 @@ protected ResponseEntity<String> storeUserSet(String userSetJsonLdStr,

UserSet storedUserSet = getUserSetService().storeUserSet(webUserSet, authentication);

// get profile for pagination urls and item Page
LdProfiles profile = getUserSetService().getProfileForPagination(profiles);

if (mustFetchItems(storedUserSet, profile)) {
int derefItems =
getDerefItemsCount(storedUserSet, UserSetConfigurationImpl.DEFAULT_ITEMS_PER_PAGE);
Expand Down Expand Up @@ -213,8 +217,9 @@ private ResponseEntity<String> getUserSet(String profileStr, String identifier,
HttpServletRequest request, String sort, String sortOrder, Integer pageNr, int pageSize,
Authentication authentication) throws HttpException {
try {
LdProfiles profile = getProfile(profileStr, request);

// validate params - profile
List<LdProfiles> profiles = getProfiles(profileStr, request);

// retrieve a Set based on its identifier - process query
// if the Set doesn’t exist, respond with HTTP 404
// if the Set is disabled respond with HTTP 410
Expand All @@ -225,6 +230,9 @@ private ResponseEntity<String> getUserSet(String profileStr, String identifier,
getUserSetService().verifyOwnerOrAdmin(userSet, authentication, false);
}

// get profile for pagination urls and item Page
LdProfiles profile = getUserSetService().getProfileForPagination(profiles);

if (mustFetchItems(userSet, profile)) {
// pageNr, if empty default value 0 is sent for fetching items
int page = (pageNr != null) ? pageNr : UserSetUtils.DEFAULT_PAGE;
Expand Down Expand Up @@ -289,8 +297,9 @@ protected ResponseEntity<String> updateUserSet(HttpServletRequest request, Authe
String identifier, String userSetJsonLdStr, String profileStr) throws HttpException {

try {
LdProfiles profile = getProfile(profileStr, request);

// validate params - profile
List<LdProfiles> profiles = getProfiles(profileStr, request);

// check if the Set exists, if not respond with HTTP 404
// retrieve an existing user set based on its identifier
UserSet existingUserSet = getUserSetService().getUserSetById(identifier);
Expand All @@ -308,6 +317,9 @@ protected ResponseEntity<String> updateUserSet(HttpServletRequest request, Authe
// parse fields of the new user set to an object
UserSet newUserSet = getUserSetService().parseUserSetLd(userSetJsonLdStr);

// get profile for pagination urls and item Page
LdProfiles profile = getUserSetService().getProfileForPagination(profiles);

// Respond with HTTP 200
// update an existing user set. merge user sets - insert new fields in existing
// object
Expand Down Expand Up @@ -407,8 +419,12 @@ protected ResponseEntity<String> publishUnpublishUserSet(String identifier,
UserSet updatedUserSet =
getUserSetService().publishUnpublishUserSet(identifier, issued, authentication, publish);

// validate params - profile
List<LdProfiles> profiles = getProfiles(profileStr, request);
// get profile for pagination urls and item Page
LdProfiles profile = getUserSetService().getProfileForPagination(profiles);

// serialize to JsonLd
LdProfiles profile = getProfile(profileStr, request);
String serializedUserSetJsonLdStr = serializeUserSet(profile, updatedUserSet);
String etag =
generateETag(updatedUserSet.getModified(), WebFields.FORMAT_JSONLD, getApiVersion());
Expand Down Expand Up @@ -470,8 +486,9 @@ protected ResponseEntity<String> insertItemIntoUserSet(HttpServletRequest reques
String position, String profileStr) throws HttpException {

try {
LdProfiles profile = getProfile(profileStr, request);

// validate params - profile
List<LdProfiles> profiles = getProfiles(profileStr, request);

// check if the Set exists, if not respond with HTTP 404
// retrieve an existing user set based on its identifier
UserSet existingUserSet = getUserSetService().getUserSetById(identifier);
Expand Down Expand Up @@ -502,6 +519,10 @@ protected ResponseEntity<String> insertItemIntoUserSet(HttpServletRequest reques
checkIfMatchHeader(eTagOrigin, request);
UserSet updatedUserSet =
getUserSetService().insertItem(datasetId, localId, position, existingUserSet);

// get profile for pagination urls and item Page
LdProfiles profile = getUserSetService().getProfileForPagination(profiles);

String serializedUserSetJsonLdStr = serializeUserSet(profile, updatedUserSet);

String etag =
Expand Down Expand Up @@ -648,8 +669,9 @@ protected ResponseEntity<String> deleteItemFromUserSet(HttpServletRequest reques
String profileStr) throws HttpException {

try {
LdProfiles profile = getProfile(profileStr, request);

// validate params - profile
List<LdProfiles> profiles = getProfiles(profileStr, request);

// check if the Set exists, if not respond with HTTP 404
// retrieve an existing user set based on its identifier
UserSet existingUserSet = getUserSetService().getUserSetById(identifier);
Expand Down Expand Up @@ -688,6 +710,9 @@ protected ResponseEntity<String> deleteItemFromUserSet(HttpServletRequest reques
// update an existing user set
UserSet updatedUserSet = getUserSetService().updateItemList(existingUserSet);

// get profile for pagination urls and item Page
LdProfiles profile = getUserSetService().getProfileForPagination(profiles);

// serialize to JsonLd
String serializedUserSetJsonLdStr = serializeUserSet(profile, updatedUserSet);
String etag =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public abstract class BaseUserSetServiceImpl implements UserSetService {

@Resource(name = UserSetConfiguration.BEAN_SET_PERSITENCE_SERVICE)
PersistentUserSetService mongoPersistance;

UserSetUtils userSetUtils = new UserSetUtils();

UserSetSearchApiUtils userSetSearchApiUtils = new UserSetSearchApiUtils();
Expand Down Expand Up @@ -459,13 +459,7 @@ private boolean isUri(String value) {
return value.startsWith("http://") || value.startsWith("https://");
}

/**
* Gets the profile for pagination urls and item page. Basically gets the profile valid for
* collection page from the list of profiles passed during search request
*
* @param profiles
* @return
*/
@Override
public LdProfiles getProfileForPagination(List<LdProfiles> profiles) {
LdProfiles profile = null;
for (LdProfiles ldProfile : profiles) {
Expand Down
Loading