Skip to content

Commit

Permalink
Merge pull request eclipse-sw360#1972 from siemens/fix/projectcount
Browse files Browse the repository at this point in the history
feat(rest) : api to get count of projects

Reviewed by: [email protected]
Tested by: [email protected]
  • Loading branch information
ag4ums authored Jun 12, 2023
2 parents 444d214 + 669d6f9 commit af7f8ca
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
14 changes: 14 additions & 0 deletions rest/resource-server/src/docs/asciidoc/projects.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -650,3 +650,17 @@ include::{snippets}/should_document_import_sbom/curl-request.adoc[]

===== Example response
include::{snippets}/should_document_import_sbom/http-response.adoc[]

[[resources-project-getprojectcount]]
==== Get project count of a user

A `GET` request will get project count of a user.

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

===== Response structure
include::{snippets}/should_document_get_project_count/response-fields.adoc[]

===== Example response
include::{snippets}/should_document_get_project_count/http-response.adoc[]
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import com.google.gson.JsonObject;

import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang.StringUtils;
Expand All @@ -39,7 +41,9 @@
import org.eclipse.sw360.datahandler.thrift.ReleaseRelationship;
import org.eclipse.sw360.datahandler.thrift.RequestStatus;
import org.eclipse.sw360.datahandler.thrift.RequestSummary;
import org.eclipse.sw360.datahandler.thrift.SW360Exception;
import org.eclipse.sw360.datahandler.thrift.Source;
import org.eclipse.sw360.datahandler.thrift.ThriftClients;
import org.eclipse.sw360.datahandler.thrift.attachments.Attachment;
import org.eclipse.sw360.datahandler.thrift.attachments.AttachmentContent;
import org.eclipse.sw360.datahandler.thrift.attachments.AttachmentType;
Expand All @@ -58,6 +62,7 @@
import org.eclipse.sw360.datahandler.thrift.projects.ProjectClearingState;
import org.eclipse.sw360.datahandler.thrift.projects.ProjectLink;
import org.eclipse.sw360.datahandler.thrift.projects.ProjectProjectRelationship;
import org.eclipse.sw360.datahandler.thrift.projects.ProjectService;
import org.eclipse.sw360.datahandler.thrift.users.User;
import org.eclipse.sw360.datahandler.thrift.vendors.Vendor;
import org.eclipse.sw360.datahandler.thrift.vulnerabilities.ProjectVulnerabilityRating;
Expand Down Expand Up @@ -1209,4 +1214,17 @@ public static TSerializer getJsonSerializer() {
}
return null;
}

@RequestMapping(value = PROJECTS_URL + "/projectcount", method = RequestMethod.GET)
public void getUserProjectCount(HttpServletResponse response) throws TException {
User sw360User = restControllerHelper.getSw360UserFromAuthentication();
try {
JsonObject resultJson = new JsonObject();
resultJson.addProperty("status", "success");
resultJson.addProperty("count", projectService.getMyAccessibleProjectCounts(sw360User));
response.getWriter().write(resultJson.toString());
}catch (IOException e) {
throw new SW360Exception(e.getMessage());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1666,4 +1666,19 @@ public void should_document_import_sbom() throws Exception {
.queryParam("type", "SPDX");
this.mockMvc.perform(builder).andExpect(status().isOk()).andDo(this.documentationHandler.document());
}

@Test
public void should_document_get_project_count() throws Exception {
String accessToken = TestHelper.getAccessToken(mockMvc, testUserId, testUserPassword);
this.mockMvc.perform(get("/api/projects/projectcount")
.header("Authorization", "Bearer " + accessToken)
.accept(MediaTypes.HAL_JSON)
.contentType(MediaTypes.HAL_JSON))
.andExpect(status().isOk())
.andDo(this.documentationHandler.document(
responseFields(
fieldWithPath("status").description("status of the API. Possible values are `<success|failure>`").optional(),
fieldWithPath("count").description("Count of projects for a user.").optional()
)));
}
}

0 comments on commit af7f8ca

Please sign in to comment.