-
Notifications
You must be signed in to change notification settings - Fork 101
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
Conversation
88d3634
to
37e42ff
Compare
37e42ff
to
b2c45c0
Compare
@@ -0,0 +1,20 @@ | |||
// | |||
// Copyright Siemens AG, 2017. Part of the SW360 Portal Project. |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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"); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
b2c45c0
to
1bb6b5f
Compare
964696a
to
8a99b66
Compare
There was a problem hiding this 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. |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
...a/org/eclipse/sw360/rest/resourceserver/DatabaseSanitation/DatabaseSanitationController.java
Outdated
Show resolved
Hide resolved
return resource; | ||
} | ||
@RequestMapping(value = DATABASESANITATION_URL + "/searchDuplicate", method = RequestMethod.GET) | ||
public ResponseEntity<CollectionModel<?>> searchDuplicateIdentifiers()throws TException { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indentation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
There was a problem hiding this comment.
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") |
There was a problem hiding this comment.
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"); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
There was a problem hiding this comment.
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
a387789
to
dc17c89
Compare
dc17c89
to
96dabb4
Compare
96dabb4
to
c9a7d9a
Compare
c9a7d9a
to
c4e3d67
Compare
c4e3d67
to
a4e37e7
Compare
a4e37e7
to
bd2dd9b
Compare
Testing was successful. |
if (sw360Exp.getErrorCode() == 403) { | ||
throw new AccessDeniedException("User has not admin access"); | ||
} if (sw360Exp.getErrorCode() == 204) { | ||
throw new SW360Exception(sw360Exp.getMessage()).setErrorCode(204); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
indentation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
Signed-off-by: Nikesh kumar <[email protected]>
bd2dd9b
to
6d9f362
Compare
There was a problem hiding this 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.
Issue: #2224
Suggest Reviewer
How To Test?
http://localhost:8080/resource/api/datasanitation/searchDublicate
Checklist
Must: