-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2218 from Siemens-Healthineers/fix/incorrect-erro…
…r-displayed-during-comp-creation-2215 fix(importCDX): Update failed component creation error message Reviewed by: anupam.ghosh@siemens.com Tested by: anupam.ghosh@siemens.com
- Loading branch information
Showing
7 changed files
with
418 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// | ||
// Copyright Siemens AG, 2017-2018. 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-ecc]] | ||
=== Ecc | ||
|
||
The Ecc resource is used to list ecc. | ||
|
||
|
||
[[resources-ecc-list]] | ||
==== Listing ecc details | ||
|
||
A `GET` request will list all of the service's ecc. | ||
|
||
===== Example request | ||
include::{snippets}/should_document_get_ecc/curl-request.adoc[] | ||
|
||
===== Example response | ||
include::{snippets}/should_document_get_ecc/http-response.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
85 changes: 85 additions & 0 deletions
85
...ce-server/src/main/java/org/eclipse/sw360/rest/resourceserver/ecc/SW360EccController.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,85 @@ | ||
/* | ||
* Copyright Siemens AG, 2017-2019. | ||
* Copyright Bosch Software Innovations GmbH, 2017-2018. | ||
* 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.ecc; | ||
|
||
import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.linkTo; | ||
|
||
import java.net.URISyntaxException; | ||
import java.util.List; | ||
|
||
import javax.servlet.http.HttpServletRequest; | ||
|
||
import org.apache.thrift.TException; | ||
import org.eclipse.sw360.datahandler.common.SW360Constants; | ||
import org.eclipse.sw360.datahandler.resourcelists.PaginationParameterException; | ||
import org.eclipse.sw360.datahandler.resourcelists.PaginationResult; | ||
import org.eclipse.sw360.datahandler.resourcelists.ResourceClassNotFoundException; | ||
import org.eclipse.sw360.datahandler.thrift.users.User; | ||
import org.eclipse.sw360.rest.resourceserver.core.RestControllerHelper; | ||
import org.jose4j.json.internal.json_simple.JSONArray; | ||
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.CollectionModel; | ||
import org.springframework.hateoas.EntityModel; | ||
import org.springframework.hateoas.Link; | ||
import org.springframework.hateoas.PagedModel; | ||
import org.springframework.hateoas.server.RepresentationModelProcessor; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import io.swagger.v3.oas.annotations.Parameter; | ||
import io.swagger.v3.oas.annotations.security.SecurityRequirement; | ||
import lombok.NonNull; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@BasePathAwareController | ||
@RequiredArgsConstructor(onConstructor = @__(@Autowired)) | ||
@RestController | ||
@SecurityRequirement(name = "tokenAuth") | ||
public class SW360EccController implements RepresentationModelProcessor<RepositoryLinksResource> { | ||
|
||
public static final String ECC_URL = "/ecc"; | ||
|
||
@NonNull | ||
private final SW360EccService sw360EccService; | ||
|
||
@NonNull | ||
private final RestControllerHelper restControllerHelper; | ||
|
||
@Override | ||
public RepositoryLinksResource process(RepositoryLinksResource resource) { | ||
resource.add(linkTo(SW360EccController.class).slash("api/ecc").withRel("ecc")); | ||
return resource; | ||
} | ||
|
||
@GetMapping(value = ECC_URL) | ||
public ResponseEntity<CollectionModel<?>> getEccDetails(HttpServletRequest request, Pageable pageable) | ||
throws TException, URISyntaxException { | ||
User user = restControllerHelper.getSw360UserFromAuthentication(); | ||
JSONArray eccData = null; | ||
try { | ||
eccData = sw360EccService.getECCPageData(user, pageable); | ||
} catch (Exception e) { | ||
throw new TException(e.getMessage()); | ||
} | ||
PaginationResult<?> paginationResult = new PaginationResult<>(eccData); | ||
CollectionModel<?> resources = sw360EccService.getPaginatedEccData(eccData,paginationResult); | ||
return new ResponseEntity<>(resources, HttpStatus.OK); | ||
} | ||
|
||
} |
212 changes: 212 additions & 0 deletions
212
...ource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/ecc/SW360EccService.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,212 @@ | ||
/* | ||
* Copyright Siemens AG, 2017-2019. | ||
* Copyright Bosch Software Innovations GmbH, 2017-2018. | ||
* 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.ecc; | ||
|
||
import static com.google.common.base.Strings.nullToEmpty; | ||
import static java.lang.Math.min; | ||
import static org.eclipse.sw360.datahandler.common.CommonUtils.nullToEmptyString; | ||
|
||
import java.net.URISyntaxException; | ||
import java.util.Collections; | ||
import java.util.Comparator; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
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.common.CommonUtils; | ||
import org.eclipse.sw360.datahandler.common.SW360Utils; | ||
import org.eclipse.sw360.datahandler.resourcelists.PaginationResult; | ||
import org.eclipse.sw360.datahandler.thrift.PaginationData; | ||
import org.eclipse.sw360.datahandler.thrift.components.ComponentService; | ||
import org.eclipse.sw360.datahandler.thrift.components.Release; | ||
import org.eclipse.sw360.datahandler.thrift.users.User; | ||
import org.eclipse.sw360.rest.resourceserver.core.RestControllerHelper; | ||
import org.jose4j.json.internal.json_simple.JSONArray; | ||
import org.jose4j.json.internal.json_simple.JSONObject; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.hateoas.CollectionModel; | ||
import org.springframework.hateoas.Link; | ||
import org.springframework.hateoas.PagedModel; | ||
import org.springframework.stereotype.Service; | ||
|
||
import com.google.common.collect.Maps; | ||
|
||
import lombok.NonNull; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@Service | ||
@RequiredArgsConstructor(onConstructor = @__(@Autowired)) | ||
public class SW360EccService { | ||
@Value("${sw360.thrift-server-url:http://localhost:8080}") | ||
private String thriftServerUrl; | ||
|
||
@NonNull | ||
private final RestControllerHelper restControllerHelper; | ||
|
||
// ECC release view datatables, index of columns | ||
private static final String RELEASE_DT_ROW_ECC_STATUS = "status"; | ||
private static final String RELEASE_DT_ROW_NAME = "name"; | ||
private static final String RELEASE_DT_ROW_VERSION = "version"; | ||
private static final String RELEASE_DT_ROW_GROUP = "group"; | ||
private static final String RELEASE_DT_ROW_ASSESSOR_CONTACT_PERSON = "assessor_contact_person"; | ||
private static final String RELEASE_DT_ROW_ASSESSOR_DEPARTMENT = "assessor_dept"; | ||
private static final String RELEASE_DT_ROW_ASSESSMENT_DATE = "assessment_date"; | ||
|
||
public JSONArray getECCPageData(User user,Pageable pageable) throws TException { | ||
JSONArray jsonReleases = new JSONArray(); | ||
try { | ||
PaginationData pageData = getPaginationData(pageable); | ||
Map<PaginationData, List<Release>> releaseList = getReleaseList(user, pageData); | ||
jsonReleases = getReleaseData(releaseList.values().iterator().next(), pageable); | ||
} catch (Exception e) { | ||
throw new TException(e.getMessage()); | ||
} | ||
return jsonReleases; | ||
} | ||
|
||
private Map<PaginationData, List<Release>> getReleaseList(User user, PaginationData pageData) throws TException { | ||
ComponentService.Iface client = getThriftComponentClient(); | ||
Map<PaginationData, List<Release>> releaseSummary = Maps.newHashMap(); | ||
try { | ||
releaseSummary = client.getAccessibleReleasesWithPagination(user, pageData); | ||
} catch (TException e) { | ||
throw new TException(e.getMessage()); | ||
} | ||
return releaseSummary; | ||
} | ||
|
||
private JSONArray getReleaseData(List<Release> releaseList, Pageable pageable) { | ||
List<Release> sortedReleases = sortReleaseList(releaseList, pageable); | ||
long count = getReleaseDataCount(pageable, releaseList.size()); | ||
final int start = 0; | ||
JSONArray releaseData = new JSONArray(); | ||
for (int i = start; i < count; i++) { | ||
JSONObject jsonObject = new JSONObject(); | ||
Release release = sortedReleases.get(i); | ||
jsonObject.put("id", release.getId()); | ||
jsonObject.put("DT_RowId", release.getId()); | ||
jsonObject.put("status", nullToEmptyString(release.getEccInformation().getEccStatus())); | ||
jsonObject.put("name", SW360Utils.printName(release)); | ||
jsonObject.put("version", nullToEmpty(release.getVersion())); | ||
jsonObject.put("group", nullToEmptyString(release.getCreatorDepartment())); | ||
jsonObject.put("assessor_contact_person", | ||
nullToEmptyString(release.getEccInformation().getAssessorContactPerson())); | ||
jsonObject.put("assessor_dept", nullToEmptyString(release.getEccInformation().getAssessorDepartment())); | ||
jsonObject.put("assessment_date", nullToEmptyString(release.getEccInformation().getAssessmentDate())); | ||
releaseData.add(jsonObject); | ||
} | ||
return releaseData; | ||
} | ||
|
||
private static long getReleaseDataCount(Pageable pageable, int maxSize) { | ||
if (pageable.getPageSize() == -1) { | ||
return maxSize; | ||
} else { | ||
return min(pageable.getPageNumber() + pageable.getPageSize(), maxSize); | ||
} | ||
} | ||
|
||
private List<Release> sortReleaseList(List<Release> releaseList, Pageable pageable) { | ||
boolean isAsc = pageable.getSort().iterator().next().isAscending(); | ||
|
||
switch (pageable.getSort().iterator().next().getProperty()) { | ||
case RELEASE_DT_ROW_ECC_STATUS: | ||
Collections.sort(releaseList, compareByECCStatus(isAsc)); | ||
break; | ||
case RELEASE_DT_ROW_NAME: | ||
Collections.sort(releaseList, compareByName(isAsc)); | ||
break; | ||
case RELEASE_DT_ROW_VERSION: | ||
Collections.sort(releaseList, compareByVersion(isAsc)); | ||
break; | ||
case RELEASE_DT_ROW_GROUP: | ||
Collections.sort(releaseList, compareByCreatorGroup(isAsc)); | ||
break; | ||
case RELEASE_DT_ROW_ASSESSOR_CONTACT_PERSON: | ||
Collections.sort(releaseList, compareByAssessorContactPerson(isAsc)); | ||
break; | ||
case RELEASE_DT_ROW_ASSESSOR_DEPARTMENT: | ||
Collections.sort(releaseList, compareByAssessorDept(isAsc)); | ||
break; | ||
case RELEASE_DT_ROW_ASSESSMENT_DATE: | ||
Collections.sort(releaseList, compareByAssessmentDate(isAsc)); | ||
break; | ||
default: | ||
break; | ||
} | ||
return releaseList; | ||
} | ||
|
||
private static Comparator<Release> compareByECCStatus(boolean isAscending) { | ||
Comparator<Release> comparator = Comparator | ||
.comparing(r -> CommonUtils.nullToEmptyString(r.getEccInformation().getEccStatus())); | ||
return isAscending ? comparator : comparator.reversed(); | ||
} | ||
|
||
private static Comparator<Release> compareByName(boolean isAscending) { | ||
Comparator<Release> comparator = Comparator.comparing(r -> CommonUtils.nullToEmptyString(r.getName())); | ||
return isAscending ? comparator : comparator.reversed(); | ||
} | ||
|
||
private static Comparator<Release> compareByVersion(boolean isAscending) { | ||
Comparator<Release> comparator = Comparator.comparing(r -> CommonUtils.nullToEmptyString(r.getVersion())); | ||
return isAscending ? comparator : comparator.reversed(); | ||
} | ||
|
||
private static Comparator<Release> compareByCreatorGroup(boolean isAscending) { | ||
Comparator<Release> comparator = Comparator | ||
.comparing(r -> CommonUtils.nullToEmptyString(r.getCreatorDepartment())); | ||
return isAscending ? comparator : comparator.reversed(); | ||
} | ||
|
||
private static Comparator<Release> compareByAssessorContactPerson(boolean isAscending) { | ||
Comparator<Release> comparator = Comparator | ||
.comparing(r -> CommonUtils.nullToEmptyString(r.getEccInformation().getAssessorContactPerson())); | ||
return isAscending ? comparator : comparator.reversed(); | ||
} | ||
|
||
private static Comparator<Release> compareByAssessorDept(boolean isAscending) { | ||
Comparator<Release> comparator = Comparator | ||
.comparing(r -> CommonUtils.nullToEmptyString(r.getEccInformation().getAssessorDepartment())); | ||
return isAscending ? comparator : comparator.reversed(); | ||
} | ||
|
||
private static Comparator<Release> compareByAssessmentDate(boolean isAscending) { | ||
Comparator<Release> comparator = Comparator | ||
.comparing(r -> CommonUtils.nullToEmptyString(r.getEccInformation().getAssessmentDate())); | ||
return isAscending ? comparator : comparator.reversed(); | ||
} | ||
|
||
private ComponentService.Iface getThriftComponentClient() throws TTransportException { | ||
THttpClient thriftClient = new THttpClient(thriftServerUrl + "/components/thrift"); | ||
TProtocol protocol = new TCompactProtocol(thriftClient); | ||
return new ComponentService.Client(protocol); | ||
} | ||
|
||
private PaginationData getPaginationData(Pageable pageable) { | ||
return new PaginationData().setDisplayStart((int) pageable.getOffset()).setRowsPerPage(pageable.getPageSize()) | ||
.setSortColumnNumber(0); | ||
} | ||
|
||
public CollectionModel<?> getPaginatedEccData(JSONArray eccData, PaginationResult<?> paginationResult) throws URISyntaxException{ | ||
PagedModel.PageMetadata pageMetadata = restControllerHelper.createPageMetadata(paginationResult); | ||
List<Link> pagingLinks = restControllerHelper.getPaginationLinks(paginationResult, restControllerHelper.getAPIBaseUrl()); | ||
return PagedModel.of(eccData, pageMetadata, pagingLinks); | ||
} | ||
} |
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.