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

feat(rest): Create a new endpoint for database Sanitation. #2223

Merged
merged 1 commit into from
May 8, 2024

Conversation

nikkuma7
Copy link
Contributor

@nikkuma7 nikkuma7 commented Dec 1, 2023

Please provide a summary of your changes here.

  • Which issue is this pull request belonging to and how is it solving it? (Refer to issue here)
  • Did you add or update any new dependencies that are required for your change?

Issue: #2224

Suggest Reviewer

You can suggest reviewers here with an @mention.

How To Test?

http://localhost:8080/resource/api/datasanitation/searchDublicate

How should these changes be tested by the reviewer?
Have you implemented any additional tests?

Checklist

Must:

  • All related issues are referenced in commit messages and in PR

@rudra-superrr rudra-superrr added the WIP work in progress label Dec 1, 2023
@nikkuma7 nikkuma7 force-pushed the fix/dataBaseSantitation branch 3 times, most recently from 88d3634 to 37e42ff Compare December 6, 2023 09:08
@ag4ums ag4ums added needs code review needs general test This is general testing, meaning that there is no org specific issue to check for and removed WIP work in progress labels Dec 7, 2023
@nikkuma7 nikkuma7 force-pushed the fix/dataBaseSantitation branch from 37e42ff to b2c45c0 Compare December 14, 2023 07:24
@@ -0,0 +1,20 @@
//
// Copyright Siemens AG, 2017. Part of the SW360 Portal Project.
Copy link
Contributor

Choose a reason for hiding this comment

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

Please update the copyright year.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done.

resource.add(linkTo(DatabaseSanitationController.class).slash("api" + DATABASESANITATION_URL).withRel("dataSanitation"));
return resource;
}
@RequestMapping(value = DATABASESANITATION_URL + "/searchDublicate", method = RequestMethod.GET)
Copy link
Contributor

Choose a reason for hiding this comment

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

Please correct the spelling /searchDublicate to /searchDuplicate or /findDuplicate

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done.

resource.add(linkTo(DatabaseSanitationController.class).slash("api" + DATABASESANITATION_URL).withRel("dataSanitation"));
return resource;
}
@RequestMapping(value = DATABASESANITATION_URL + "/searchDublicate", method = RequestMethod.GET)
Copy link
Contributor

Choose a reason for hiding this comment

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

This endpoint should be only visible to user with admin privileges. Now it seems visible to all. Please add @PreAuthorize("hasAuthority('ADMIN')") at controller level.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done.

@Value("${sw360.thrift-server-url:http://localhost:8080}")
private String thriftServerUrl;

public Map<String, Object> dublicateIdentifiers(User sw360User, HttpServletRequest request) throws TException {
Copy link
Contributor

Choose a reason for hiding this comment

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

parameters sw360User and request never used. Kindly remove those.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done.

}
}
if (oneIsNull(duplicateComponents, duplicateReleases, duplicateProjects, duplicateReleaseSources)) {
throw new HttpMessageNotReadableException("Some duplicates are null");
Copy link
Contributor

Choose a reason for hiding this comment

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

HttpMessageNotReadableException is used for client side error. Seems like this is not applicable here and same in line 75

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done.

} catch (Exception e) {
throw new TException(e.getMessage());
}
HttpStatus status = request == null ? HttpStatus.NO_CONTENT : HttpStatus.OK;
Copy link
Contributor

Choose a reason for hiding this comment

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

Request is always non null here. This seems to be not valid check

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done.


@MockBean
ProjectService.Iface projectClient;
private HttpServletRequest request;
Copy link
Contributor

Choose a reason for hiding this comment

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

this variable request is never used. Please remove this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done.

@RequestMapping(value = DATABASESANITATION_URL + "/searchDublicate", method = RequestMethod.GET)
public ResponseEntity<CollectionModel<?>> searchDublicateIdentifiers(HttpServletRequest request )throws TException {
try {
User sw360User = restControllerHelper.getSw360UserFromAuthentication();
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove this statement as sw360User is never used.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done.

private Sw360DatabaseSanitationService sanitationService;

@MockBean
ComponentService.Iface componentClient;
Copy link
Contributor

Choose a reason for hiding this comment

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

Mocking client is not required as the service call itself is already mocked at line 95. Hence remove all the statements creating mocking of clients and using that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done.

@nikkuma7 nikkuma7 force-pushed the fix/dataBaseSantitation branch from b2c45c0 to 1bb6b5f Compare January 5, 2024 06:31
@nikkuma7 nikkuma7 force-pushed the fix/dataBaseSantitation branch 3 times, most recently from 964696a to 8a99b66 Compare January 16, 2024 07:41
Copy link
Contributor

@smrutis1 smrutis1 left a comment

Choose a reason for hiding this comment

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

Please look into the changes requested along with the below.

Please follow the java naming convention for the class name. databaseSanitationSpecTest.java to DatabaseSanitationSpecTest.java

[[search-duplicate]]
==== search duplicate identifiers

A `GET` request will fetch the dublicate project and components.
Copy link
Contributor

Choose a reason for hiding this comment

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

Please correct the spelling dublicate to duplicate

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done.

* SPDX-License-Identifier: EPL-2.0
*/

package org.eclipse.sw360.rest.resourceserver.DatabaseSanitation;
Copy link
Contributor

Choose a reason for hiding this comment

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

package name should be small. Rename DatabaseSanitation to databasesanitization / databasesanitation

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done.

return resource;
}
@RequestMapping(value = DATABASESANITATION_URL + "/searchDuplicate", method = RequestMethod.GET)
public ResponseEntity<CollectionModel<?>> searchDuplicateIdentifiers()throws TException {
Copy link
Contributor

Choose a reason for hiding this comment

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

Indentation

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done.

Copy link
Contributor

Choose a reason for hiding this comment

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

Not resolved I think. Can be ignored though.

@Test
public void should_document_search_duplicate() throws Exception {
String accessToken = TestHelper.getAccessToken(mockMvc, testUserId, testUserPassword);
mockMvc.perform(get("/api/dataSanitation/searchDuplicate")
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add the response structure and document as well once the data is added in the response.

duplicateReleaseSources = componentClient.getDuplicateReleaseSources();
duplicateProjects = projectClient.getDuplicateProjects();
} else {
throw new RuntimeException("User is not admin");
Copy link
Contributor

Choose a reason for hiding this comment

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

This will give 500 - Internal Server Error. Appropriate should be 403- Forbidden

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done.

Copy link
Contributor

Choose a reason for hiding this comment

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

Unfortunately, I don't see the changes. Seems like still the runtime exception is thrown which will give a 500 response

@nikkuma7 nikkuma7 force-pushed the fix/dataBaseSantitation branch 2 times, most recently from a387789 to dc17c89 Compare February 6, 2024 06:32
@nikkuma7 nikkuma7 force-pushed the fix/dataBaseSantitation branch from dc17c89 to 96dabb4 Compare February 25, 2024 11:18
@nikkuma7 nikkuma7 force-pushed the fix/dataBaseSantitation branch from 96dabb4 to c9a7d9a Compare March 19, 2024 09:37
@rudra-superrr
Copy link
Contributor

Testing was successful.
image

@rudra-superrr
Copy link
Contributor

One thing, getting 500 error code when no duplicates are found.
image

@rudra-superrr
Copy link
Contributor

image

Either change the description to, used to fetch duplicate projects/components/releases/releaseSources or you can mention, it is used to fetch duplicate identifiers.
Also change search duplicate identifiers --> Search duplicate identifiers.

@nikkuma7 nikkuma7 force-pushed the fix/dataBaseSantitation branch from c9a7d9a to c4e3d67 Compare March 27, 2024 08:20
@heliocastro heliocastro added the New-UI Level for the API and UI level changes for the new-ui label Mar 27, 2024
@rudra-superrr
Copy link
Contributor

Display some message when no content is found.
image

Please change message for the highlighted portion.
image

@nikkuma7 nikkuma7 force-pushed the fix/dataBaseSantitation branch from c4e3d67 to a4e37e7 Compare March 28, 2024 06:18
@nikkuma7
Copy link
Contributor Author

Display some message when no content is found. image

Please change message for the highlighted portion. image

comment addressed.

@nikkuma7 nikkuma7 force-pushed the fix/dataBaseSantitation branch from a4e37e7 to bd2dd9b Compare March 29, 2024 04:52
@rudra-superrr
Copy link
Contributor

Testing was successful.

@rudra-superrr rudra-superrr removed the needs general test This is general testing, meaning that there is no org specific issue to check for label Mar 29, 2024
if (sw360Exp.getErrorCode() == 403) {
throw new AccessDeniedException("User has not admin access");
} if (sw360Exp.getErrorCode() == 204) {
throw new SW360Exception(sw360Exp.getMessage()).setErrorCode(204);
Copy link
Contributor

Choose a reason for hiding this comment

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

indentation

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done.

@nikkuma7 nikkuma7 force-pushed the fix/dataBaseSantitation branch from bd2dd9b to 6d9f362 Compare April 29, 2024 10:02
Copy link
Contributor

@smrutis1 smrutis1 left a comment

Choose a reason for hiding this comment

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

Code looks ok to me.

@rudra-superrr rudra-superrr added the ready ready to merge label May 2, 2024
@ag4ums ag4ums merged commit 43a7692 into eclipse-sw360:main May 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
New-UI Level for the API and UI level changes for the new-ui ready ready to merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants