-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(REST): Added new Rest API endpoint for reading clearing request
Signed-off-by: Abdul Kapti <abdul.kapti@siemens-healthineers.com>
- Loading branch information
Abdul Kapti
committed
Mar 24, 2021
1 parent
958a8a7
commit 028ee60
Showing
12 changed files
with
382 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
rest/resource-server/src/docs/asciidoc/clearingRequest.adoc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// | ||
// Copyright Siemens AG, 2020. Part of the SW360 Portal Project. | ||
// | ||
// This program and the accompanying materials are made | ||
// available under the terms of the Eclipse Public License 2.0 | ||
// which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
// | ||
// SPDX-License-Identifier: EPL-2.0 | ||
// | ||
|
||
[[resources-clearingRequest]] | ||
=== ClearingRequest | ||
|
||
The ClearingRequest resource is used get the clearing request of a project | ||
|
||
|
||
[[resources-clearingRequest-by-id]] | ||
==== Get clearingRequest by id | ||
|
||
A `GET` request will display the ClearingRequest by id | ||
|
||
===== Response structure | ||
include::{snippets}/should_document_get_clearingrequest/response-fields.adoc[] | ||
|
||
===== Example request | ||
include::{snippets}/should_document_get_clearingrequest/curl-request.adoc[] | ||
|
||
===== Example response | ||
include::{snippets}/should_document_get_clearingrequest/http-response.adoc[] | ||
|
||
|
||
[[resources-clearingRequest-by-project-id]] | ||
==== Get clearingRequest by project id | ||
|
||
A `GET` request will display the ClearingRequest based on the project id | ||
|
||
===== Response structure | ||
include::{snippets}/should_document_get_clearingrequest_by_projectid/response-fields.adoc[] | ||
|
||
===== Example request | ||
include::{snippets}/should_document_get_clearingrequest_by_projectid/curl-request.adoc[] | ||
|
||
===== Example response | ||
include::{snippets}/should_document_get_clearingrequest_by_projectid/http-response.adoc[] |
102 changes: 102 additions & 0 deletions
102
...java/org/eclipse/sw360/rest/resourceserver/clearingrequest/ClearingRequestController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
/* | ||
* Copyright Siemens AG, 2020. Part of the SW360 Portal Project. | ||
* | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
package org.eclipse.sw360.rest.resourceserver.clearingrequest; | ||
|
||
import static org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo; | ||
|
||
import java.net.URISyntaxException; | ||
import java.util.Arrays; | ||
import java.util.HashSet; | ||
import java.util.Map; | ||
import java.util.Set; | ||
|
||
import javax.servlet.http.HttpServletRequest; | ||
|
||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
import org.apache.thrift.TException; | ||
import org.eclipse.sw360.datahandler.thrift.ProjectReleaseRelationship; | ||
import org.eclipse.sw360.datahandler.thrift.projects.ClearingRequest; | ||
import org.eclipse.sw360.datahandler.thrift.projects.Project; | ||
import org.eclipse.sw360.datahandler.thrift.projects.ProjectRelationship; | ||
import org.eclipse.sw360.datahandler.thrift.users.User; | ||
import org.eclipse.sw360.rest.resourceserver.changelog.ChangeLogController; | ||
import org.eclipse.sw360.rest.resourceserver.core.HalResource; | ||
import org.eclipse.sw360.rest.resourceserver.core.RestControllerHelper; | ||
import org.eclipse.sw360.rest.resourceserver.project.Sw360ProjectService; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.data.rest.webmvc.BasePathAwareController; | ||
import org.springframework.data.rest.webmvc.RepositoryLinksResource; | ||
import org.springframework.hateoas.Link; | ||
import org.springframework.hateoas.Resource; | ||
import org.springframework.hateoas.ResourceProcessor; | ||
import org.springframework.hateoas.UriTemplate; | ||
import org.springframework.hateoas.mvc.ControllerLinkBuilder; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.util.StringUtils; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestMethod; | ||
|
||
import lombok.NonNull; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@BasePathAwareController | ||
@RequiredArgsConstructor(onConstructor = @__(@Autowired)) | ||
public class ClearingRequestController implements ResourceProcessor<RepositoryLinksResource> { | ||
|
||
private static final Logger log = LogManager.getLogger(ClearingRequestController.class); | ||
|
||
public static final String CLEARING_REQUEST_URL = "/clearingrequest"; | ||
@Autowired | ||
private Sw360ClearingRequestService sw360ClearingRequestService; | ||
|
||
@NonNull | ||
private final RestControllerHelper restControllerHelper; | ||
|
||
@NonNull | ||
private final Sw360ProjectService projectService; | ||
|
||
@NonNull | ||
private final com.fasterxml.jackson.databind.Module sw360Module; | ||
|
||
|
||
@RequestMapping(value = CLEARING_REQUEST_URL + "/{id}", method = RequestMethod.GET) | ||
public ResponseEntity<Resource<ClearingRequest>> getClearingRequestById(Pageable pageable, @PathVariable("id") String docId, | ||
HttpServletRequest request) throws TException, URISyntaxException { | ||
User sw360User = restControllerHelper.getSw360UserFromAuthentication(); | ||
ClearingRequest clearingRequest = sw360ClearingRequestService.getClearingRequestById(docId, sw360User); | ||
|
||
HttpStatus status = clearingRequest == null ? HttpStatus.NO_CONTENT : HttpStatus.OK; | ||
return new ResponseEntity(clearingRequest, status); | ||
} | ||
|
||
@RequestMapping(value = CLEARING_REQUEST_URL + "/project/{id}", method = RequestMethod.GET) | ||
public ResponseEntity<Resource<ClearingRequest>> getClearingRequestByProjectId(Pageable pageable, @PathVariable("id") String projectId, | ||
HttpServletRequest request) throws TException, URISyntaxException { | ||
User sw360User = restControllerHelper.getSw360UserFromAuthentication(); | ||
ClearingRequest clearingRequest = sw360ClearingRequestService.getClearingRequestByProjectId(projectId, sw360User); | ||
|
||
HttpStatus status = clearingRequest == null ? HttpStatus.NO_CONTENT : HttpStatus.OK; | ||
return new ResponseEntity(clearingRequest, status); | ||
} | ||
|
||
@Override | ||
public RepositoryLinksResource process(RepositoryLinksResource resource) { | ||
final ControllerLinkBuilder controllerLinkBuilder = linkTo(ClearingRequestController.class); | ||
final Link changelogLink = new Link( | ||
new UriTemplate(controllerLinkBuilder.toUri().toString() + "/api" + CLEARING_REQUEST_URL + "/{id}"), | ||
"clearingRequest"); | ||
resource.add(changelogLink); | ||
return resource; | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
...va/org/eclipse/sw360/rest/resourceserver/clearingrequest/Sw360ClearingRequestService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* Copyright Siemens AG, 2020. Part of the SW360 Portal Project. | ||
* | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
package org.eclipse.sw360.rest.resourceserver.clearingrequest; | ||
|
||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
import org.apache.thrift.TException; | ||
import org.apache.thrift.protocol.TCompactProtocol; | ||
import org.apache.thrift.protocol.TProtocol; | ||
import org.apache.thrift.transport.THttpClient; | ||
import org.apache.thrift.transport.TTransportException; | ||
import org.eclipse.sw360.datahandler.thrift.moderation.ModerationService; | ||
import org.eclipse.sw360.datahandler.thrift.projects.ClearingRequest; | ||
import org.eclipse.sw360.datahandler.thrift.users.User; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.stereotype.Service; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
@Service | ||
@RequiredArgsConstructor(onConstructor = @__(@Autowired)) | ||
public class Sw360ClearingRequestService { | ||
private static final Logger log = LogManager.getLogger(Sw360ClearingRequestService.class); | ||
|
||
@Value("${sw360.thrift-server-url:http://localhost:8080}") | ||
private String thriftServerUrl; | ||
|
||
private ModerationService.Iface getThriftModerationClient() throws TTransportException { | ||
THttpClient thriftClient = new THttpClient(thriftServerUrl + "/moderation/thrift"); | ||
TProtocol protocol = new TCompactProtocol(thriftClient); | ||
return new ModerationService.Client(protocol); | ||
} | ||
|
||
public ClearingRequest getClearingRequestByProjectId(String projectId, User sw360User) throws TException { | ||
return getThriftModerationClient().getClearingRequestByProjectId(projectId, sw360User); | ||
} | ||
|
||
public ClearingRequest getClearingRequestById(String id, User sw360User) throws TException { | ||
return getThriftModerationClient().getClearingRequestById(id, sw360User); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.