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

insert multiple items #266

Merged
merged 9 commits into from
Nov 8, 2024
Merged

insert multiple items #266

merged 9 commits into from
Nov 8, 2024

Conversation

SrdjanStevanetic
Copy link
Contributor

No description provided.

try {
positionFinal = Integer.parseInt(position);
} catch (RuntimeException e) {
return -1;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

invalid should not return -1

/**
* This method updates existing item list
*
* @param existingUserSet
* @return updated user set
*/
UserSet updateItemList(UserSet existingUserSet);
UserSet updateUserSetInMongo(UserSet existingUserSet);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should not be renamed, this method is meant to update only the list of items and the total, not the metadata. The purpose should be inline with the method name

@@ -257,4 +261,6 @@ ItemIdsResultPage buildItemIdsResultsPage(String setId, List<String> itemIds, in

void validateGallerySize(UserSet webUserSet, int newItems) throws ItemValidationException;

UserSet updatePagination(UserSet userSet, UserSetConfiguration config);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should not me public method, it is meant to be internal to the service

@@ -482,6 +498,83 @@ protected ResponseEntity<String> insertItemIntoUserSet(HttpServletRequest reques

UserSet updatedUserSet =
getUserSetService().insertItem(datasetId, localId, position, existingUserSet);
getUserSetService().updatePagination(updatedUserSet, getConfiguration());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the update pagination should be called within the service not from the controller

// retrieve an existing user set based on its identifier
UserSet existingUserSet = getUserSetService().getUserSetById(identifier);

if (existingUserSet.isOpenSet()) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The validation here is dupplicated with the code from insertItemIntoUserSet, should be refactored to eliminate dupplication.

// for entity user sets, add users with 'editor' role as contributors
addContributorForEntitySet(existingUserSet, authentication);

boolean itemsRemoved=false;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the processing of the items belongs to the business logic and must be moved to the service method


//update the pagination fields of the set (used only for the serialization to the output)
@Override
public UserSet updatePagination(UserSet userSet, UserSetConfiguration config) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be protected not public

*/
for(String newItem : items) {
int itemindex=usersetItems.indexOf(newItem);
if(itemindex>=0) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use contains method instead

/*remove all duplicate items from the set and count the number
of removed pinned items, to change the pinned field
*/
for(String newItem : items) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not implemented according to the specs, we need to implement a method which computes the list of dupplicated items first and than to update the list

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is implemented according to the specs, the method is finding the duplicates using a foor loop, not the streams, because we also need to update the pinned field if the duplicated items were pinned before, and that is all done in one foor loop.

/*remove from the new items the ones that were pinned before
*and from the user set the ones that are duplicates
*/
for(String newItem : newItemsCopy) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not implemented according to the specs, we need to implement a method which computes the list of dupplicated items first and than to update the list

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is implemented according to the specs, similar as the comment above.

@gsergiu gsergiu merged commit 074858a into develop Nov 8, 2024
1 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants