Skip to content

Commit

Permalink
feat(rest): create new enpoint to upload component csv file.
Browse files Browse the repository at this point in the history
Signed-off-by: Nikesh kumar <[email protected]>
  • Loading branch information
Nikesh kumar authored and nikkuma7 committed Oct 22, 2024
1 parent 00d70bc commit ae9010e
Show file tree
Hide file tree
Showing 5 changed files with 360 additions and 60 deletions.
1 change: 1 addition & 0 deletions rest/resource-server/src/docs/asciidoc/api-guide.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -311,3 +311,4 @@ include::ecc.adoc[]
include::importExport.adoc[]
include::attachmentCleanUp.adoc[]
include::databaseSanitation.adoc[]
include::importExport.adoc[]
60 changes: 58 additions & 2 deletions rest/resource-server/src/docs/asciidoc/importExport.adoc
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
//
// Copyright Siemens AG, 2024. Part of the SW360 Portal Project.
//
// This program and the accompanying materials are made
Expand Down Expand Up @@ -77,4 +76,61 @@ A `GET` request to download the component information in csv format.
include::{snippets}/should_document_get_download_component_details/curl-request.adoc[]

===== Example response
include::{snippets}/should_document_get_download_component_details/http-response.adoc[]
include::{snippets}/should_document_get_download_component_details/http-response.adoc[]
=======
[[upload-component]]
==== Upload component csv file.
A `POST` request help to upload the component csv file.
[red]#Request parameter#
|===
|Parameter |Description
|componentFile
|Upload the component csv file.
|===
===== Example request
include::{snippets}/should_document_upload_component_file/curl-request.adoc[]
===== Example response
include::{snippets}/should_document_upload_component_file/http-response.adoc[]
[[upload-release]]
==== Upload release link csv file.
A `POST` request help to upload the release csv file.
[red]#Request parameter#
|===
|Parameter |Description
|releaseFile
|Upload the release link csv file.
|===
===== Example request
include::{snippets}/should_document_upload_release_link_file/curl-request.adoc[]
===== Example response
include::{snippets}/should_document_upload_release_link_file/http-response.adoc[]
[[upload-component-attachment]]
==== Upload component attachment file.
A `POST` request help to upload the component attachment file.
[red]#Request parameter#
|===
|Parameter |Description
|component
|Upload the component attachment file.
|===
===== Example request
include::{snippets}/should_document_upload_component_attachment_file/curl-request.adoc[]
===== Example response
include::{snippets}/should_document_upload_component_attachment_file/http-response.adoc[]
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,15 @@
import java.io.IOException;

import org.apache.thrift.TException;
import org.apache.thrift.transport.TTransportException;
import org.eclipse.sw360.datahandler.thrift.users.User;
import org.eclipse.sw360.rest.resourceserver.core.RestControllerHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.eclipse.sw360.datahandler.common.CommonUtils;
import org.eclipse.sw360.datahandler.thrift.RequestStatus;
import org.eclipse.sw360.datahandler.thrift.RequestSummary;
import org.eclipse.sw360.rest.resourceserver.project.ProjectController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.rest.webmvc.BasePathAwareController;
import org.springframework.data.rest.webmvc.RepositoryLinksResource;
Expand All @@ -38,6 +43,13 @@
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import org.springframework.http.HttpStatus.Series;
import org.springframework.http.MediaType;
import org.springframework.web.HttpMediaTypeNotAcceptableException;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;

import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.NonNull;
Expand All @@ -47,11 +59,13 @@
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
@RestController
@SecurityRequirement(name = "tokenAuth")
public class ImportExportController implements RepresentationModelProcessor<RepositoryLinksResource> {
public class ImportExportController implements RepresentationModelProcessor<RepositoryLinksResource> {

private static final Logger LOGGER = LoggerFactory.getLogger(ImportExportController.class);
public static final String IMPORTEXPORT_URL = "/importExport";

private static final MediaType form = null;

@NonNull
private final RestControllerHelper restControllerHelper;

Expand All @@ -64,14 +78,8 @@ public RepositoryLinksResource process(RepositoryLinksResource resource) {
return resource;
}

@Operation(
summary = "Download csv component template.",
description = "Download csv component template.",
tags = {"ImportExport"},
parameters = {
@Parameter(name = "Accept", in = ParameterIn.HEADER, required = true),
}
)
@Operation(summary = "Download csv component template.", description = "Download csv component template.", tags = {
"ImportExport" }, parameters = { @Parameter(name = "Accept", in = ParameterIn.HEADER, required = true), })
@PreAuthorize("hasAuthority('WRITE')")
@GetMapping(value = IMPORTEXPORT_URL + "/downloadComponentTemplate")
public void downloadComponentTemplate(HttpServletResponse response) {
Expand All @@ -84,14 +92,8 @@ public void downloadComponentTemplate(HttpServletResponse response) {
}
}

@Operation(
summary = "Download csv attachment sample info.",
description = "Download csv attachment sample information.",
tags = {"ImportExport"},
parameters = {
@Parameter(name = "Accept", in = ParameterIn.HEADER, required = true),
}
)
@Operation(summary = "Download csv attachment sample info.", description = "Download csv attachment sample information.", tags = {
"ImportExport" }, parameters = { @Parameter(name = "Accept", in = ParameterIn.HEADER, required = true), })
@PreAuthorize("hasAuthority('WRITE')")
@GetMapping(value = IMPORTEXPORT_URL + "/downloadAttachmentSample")
public void downloadAttachmentSample(HttpServletResponse response) {
Expand All @@ -104,17 +106,11 @@ public void downloadAttachmentSample(HttpServletResponse response) {
}
}

@Operation(
summary = "Download csv attachment information.",
description = "Download csv attachment information.",
tags = {"ImportExport"},
parameters = {
@Parameter(name = "Accept", in = ParameterIn.HEADER, required = true),
}
)
@Operation(summary = "Download csv attachment information.", description = "Download csv attachment information.", tags = {
"ImportExport" }, parameters = { @Parameter(name = "Accept", in = ParameterIn.HEADER, required = true), })
@PreAuthorize("hasAuthority('WRITE')")
@GetMapping(value = IMPORTEXPORT_URL + "/downloadAttachmentInfo")
public void downloadAttachmentInfo(HttpServletResponse response) {
public void downloadAttachmentInfo(HttpServletResponse response) throws TTransportException{
try {
User sw360User = restControllerHelper.getSw360UserFromAuthentication();
importExportService.getDownloadAttachmentInfo(sw360User, response);
Expand All @@ -124,14 +120,8 @@ public void downloadAttachmentInfo(HttpServletResponse response) {
}
}

@Operation(
summary = "Download csv release sample.",
description = "Download csv release link sample.",
tags = {"ImportExport"},
parameters = {
@Parameter(name = "Accept", in = ParameterIn.HEADER, required = true),
}
)
@Operation(summary = "Download csv release sample.", description = "Download csv release link sample.", tags = {
"ImportExport" }, parameters = { @Parameter(name = "Accept", in = ParameterIn.HEADER, required = true), })
@PreAuthorize("hasAuthority('WRITE')")
@GetMapping(value = IMPORTEXPORT_URL + "/downloadReleaseSample")
public void downloadReleaseSample(HttpServletResponse response) {
Expand All @@ -144,14 +134,8 @@ public void downloadReleaseSample(HttpServletResponse response) {
}
}

@Operation(
summary = "Download csv release link.",
description = "Download csv release link information.",
tags = {"ImportExport"},
parameters = {
@Parameter(name = "Accept", in = ParameterIn.HEADER, required = true),
}
)
@Operation(summary = "Download csv release link.", description = "Download csv release link information.", tags = {
"ImportExport" }, parameters = { @Parameter(name = "Accept", in = ParameterIn.HEADER, required = true), })
@PreAuthorize("hasAuthority('WRITE')")
@GetMapping(value = IMPORTEXPORT_URL + "/downloadReleaseLink")
public void downloadReleaseLink(HttpServletResponse response) {
Expand All @@ -164,14 +148,8 @@ public void downloadReleaseLink(HttpServletResponse response) {
}
}

@Operation(
summary = "Download component in csv format.",
description = "Download component.",
tags = {"ImportExport"},
parameters = {
@Parameter(name = "Accept", in = ParameterIn.HEADER, required = true),
}
)
@Operation(summary = "Download component in csv format.", description = "Download component.", tags = {
"ImportExport" }, parameters = { @Parameter(name = "Accept", in = ParameterIn.HEADER, required = true), })
@PreAuthorize("hasAuthority('WRITE')")
@GetMapping(value = IMPORTEXPORT_URL + "/downloadComponent")
public void downloadComponent(HttpServletResponse response) {
Expand All @@ -198,4 +176,45 @@ public ResponseEntity<String> handleGlobalException(Exception e) {
LOGGER.error("Unhandled exception: {}", e.getMessage(), e);
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(e.getMessage());
}

@Operation(summary = "Upload component csv file.", description = "Upload component csv file.", tags = {
"Component" })
@RequestMapping(value = IMPORTEXPORT_URL + "/uploadComponent", method = RequestMethod.POST, consumes = {
MediaType.MULTIPART_MIXED_VALUE,
MediaType.MULTIPART_FORM_DATA_VALUE }, produces = { MediaType.APPLICATION_JSON_VALUE })
public ResponseEntity<RequestSummary> uploadComponentCsv(
@Parameter(description = "The component csv file to be uploaded.") @RequestParam("componentFile") MultipartFile file,
HttpServletRequest request, HttpServletResponse response) throws TException, IOException, ServletException {

User sw360User = restControllerHelper.getSw360UserFromAuthentication();
RequestSummary requestSummary = importExportService.uploadComponent(sw360User, file, request, response);
return ResponseEntity.ok(requestSummary);
}

@Operation(summary = "release link file.", description = "release link file.", tags = { "Release" })
@RequestMapping(value = IMPORTEXPORT_URL + "/uploadRelease", method = RequestMethod.POST, consumes = {
MediaType.MULTIPART_MIXED_VALUE,
MediaType.MULTIPART_FORM_DATA_VALUE }, produces = { MediaType.APPLICATION_JSON_VALUE })
public ResponseEntity<RequestSummary> uploadReleaseCsv(
@Parameter(description = "The release csv file to be uploaded.") @RequestParam("releaseFile") MultipartFile file,
HttpServletRequest request, HttpServletResponse response) throws TException, IOException, ServletException {

User sw360User = restControllerHelper.getSw360UserFromAuthentication();
RequestSummary requestSummary = importExportService.uploadReleaseLink(sw360User, file, request);
return ResponseEntity.ok(requestSummary);
}

@Operation(summary = "component attachment file.", description = "component attachment file.", tags = {
"Component" })
@RequestMapping(value = IMPORTEXPORT_URL + "/componentAttachment", method = RequestMethod.POST, consumes = {
MediaType.MULTIPART_MIXED_VALUE,
MediaType.MULTIPART_FORM_DATA_VALUE }, produces = { MediaType.APPLICATION_JSON_VALUE })
public ResponseEntity<RequestSummary> uploadComponentAttachment(
@Parameter(description = "The component attachment csv file to be uploaded.") @RequestParam("attachmentFile") MultipartFile file,
HttpServletRequest request, HttpServletResponse response) throws TException, IOException, ServletException {

User sw360User = restControllerHelper.getSw360UserFromAuthentication();
RequestSummary requestSummary = importExportService.uploadComponentAttachment(sw360User, file, request);
return ResponseEntity.ok(requestSummary);
}
}
Loading

0 comments on commit ae9010e

Please sign in to comment.