Skip to content

Commit

Permalink
fix(rest): create new endpoint for import OSADL information in admin …
Browse files Browse the repository at this point in the history
…tab.

Signed-off-by: Nikesh kumar <[email protected]>
  • Loading branch information
Nikesh kumar committed Oct 5, 2023
1 parent 4666d87 commit d320027
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 0 deletions.
10 changes: 10 additions & 0 deletions rest/resource-server/src/docs/asciidoc/licenses.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,13 @@ include::{snippets}/should_document_get_download_license_archive/curl-request.ad
===== Example response
include::{snippets}/should_document_get_download_license_archive/http-response.adoc[]

[[import-osadl-info]]
==== Import osadl information

A `POST` request will import osadl licenses info.

===== Example request
include::{snippets}/should_document_import_osadl_info/curl-request.adoc[]

===== Example response
include::{snippets}/should_document_import_osadl_info/http-response.adoc[]
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.thrift.TException;
import org.eclipse.sw360.datahandler.thrift.RequestSummary;
import org.eclipse.sw360.datahandler.thrift.licenses.License;
import org.eclipse.sw360.datahandler.thrift.licenses.Obligation;
import org.eclipse.sw360.datahandler.thrift.users.User;
Expand Down Expand Up @@ -186,4 +187,15 @@ public void downloadLicenseArchive(HttpServletRequest request,HttpServletRespons
licenseService.getDownloadLicenseArchive(sw360User,request,response);

}

@RequestMapping(value = LICENSES_URL + "/import/OSADL", method = RequestMethod.POST)
public ResponseEntity<RequestSummary> importOsadlInfo() throws TException {
User sw360User = restControllerHelper.getSw360UserFromAuthentication();
RequestSummary requestSummary=licenseService.importOsadlInformation(sw360User);
requestSummary.setMessage("OSADL license has imported successfully");
requestSummary.unsetTotalAffectedElements();
requestSummary.unsetTotalElements();
HttpStatus status = HttpStatus.OK;
return new ResponseEntity<>(requestSummary,status);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -210,4 +210,14 @@ public void getDownloadLicenseArchive(User sw360User ,HttpServletRequest request
private void copyDataStreamToResponse(HttpServletResponse response, ByteArrayInputStream buffer) throws IOException {
FileCopyUtils.copy(buffer, response.getOutputStream());
}

public RequestSummary importOsadlInformation(User sw360User) throws TException {
LicenseService.Iface sw360LicenseClient = getThriftLicenseClient();
if (PermissionUtils.isUserAtLeast(UserGroup.ADMIN, sw360User)) {
RequestSummary osdlLicenseStatus = sw360LicenseClient.importAllOSADLLicenses(sw360User);
return osdlLicenseStatus;
} else {
throw new HttpMessageNotReadableException("Unable to import All Spdx license. User is not admin");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import org.eclipse.sw360.datahandler.thrift.licenses.ObligationLevel;
import org.eclipse.sw360.datahandler.thrift.licenses.ObligationType;
import org.eclipse.sw360.datahandler.thrift.Quadratic;
import org.eclipse.sw360.datahandler.thrift.RequestStatus;
import org.eclipse.sw360.datahandler.thrift.RequestSummary;
import org.eclipse.sw360.rest.resourceserver.user.Sw360UserService;
import org.junit.Before;
import org.junit.Test;
Expand Down Expand Up @@ -61,6 +63,7 @@ public class LicenseSpecTest extends TestRestDocsSpecBase {

private License license;
private Obligation obligation1, obligation2;
private RequestSummary requestSummary = new RequestSummary();

@Before
@SuppressWarnings("unchecked")
Expand All @@ -87,13 +90,16 @@ public void before() throws TException, IOException {
List<License> licenseList = new ArrayList<>();
licenseList.add(license);
licenseList.add(license2);

requestSummary.setRequestStatus(RequestStatus.SUCCESS);

given(this.licenseServiceMock.getLicenses()).willReturn(licenseList);
given(this.licenseServiceMock.getLicenseById(eq(license.getId()))).willReturn(license);
Mockito.doNothing().when(licenseServiceMock).deleteLicenseById(any(), any());
Mockito.doNothing().when(licenseServiceMock).deleteAllLicenseInfo(any());
Mockito.doNothing().when(licenseServiceMock).importSpdxInformation(any());
Mockito.doNothing().when(licenseServiceMock).getDownloadLicenseArchive(any(), any(), any());
given(this.licenseServiceMock.importOsadlInformation(any())).willReturn(requestSummary);
obligation1 = new Obligation();
obligation1.setId("0001");
obligation1.setTitle("Obligation 1");
Expand Down Expand Up @@ -234,4 +240,13 @@ public void should_document_import_spdx_info() throws Exception {
.accept(MediaTypes.HAL_JSON))
.andExpect(status().isOk());
}

public void should_document_import_osadl_info() throws Exception {
String accessToken = TestHelper.getAccessToken(mockMvc, testUserId, testUserPassword);
mockMvc.perform(post("/api/licenses/import/OSADL")
.header("Authorization", "Bearer " + accessToken)
.accept(MediaTypes.HAL_JSON))
.andExpect(status().isOk());
}

}

0 comments on commit d320027

Please sign in to comment.