Skip to content
This repository has been archived by the owner on Jul 25, 2018. It is now read-only.

Commit

Permalink
chore(rest): harmonize rest fields and documentation
Browse files Browse the repository at this point in the history
- bug fix in tests for search by name (projects, components)
- harmonize fields for resource objects (name, version, type)
- add fields mainlineState, DownloadUrl (release)
- add field uploadedBy (attachments)
- add field al, eccn (eccInformation)
  • Loading branch information
maierthomas committed Mar 6, 2018
1 parent dad4d02 commit 2b023cb
Show file tree
Hide file tree
Showing 19 changed files with 231 additions and 225 deletions.
3 changes: 2 additions & 1 deletion rest/resource-server/src/docs/asciidoc/components.adoc
Expand Up @@ -37,7 +37,8 @@ include::{snippets}/should_document_get_components/links.adoc[]
[[resources-components-list-by-name]]
==== Listing by name

A `GET` request will list all of the service's components by component name.
A `GET` request will list all of the service's components by component name. +
Please set the request parameter `&name=<NAME>`.

===== Response structure

Expand Down
7 changes: 4 additions & 3 deletions rest/resource-server/src/docs/asciidoc/projects.adoc
Expand Up @@ -37,7 +37,8 @@ include::{snippets}/should_document_get_projects/links.adoc[]
[[resources-projects-list-by-name]]
==== Listing by name

A `GET` request will list all of the service's projects by project name.
A `GET` request will list all of the service's projects by project name. +
Please set the request parameter `&name=<NAME>`.

===== Response structure

Expand Down Expand Up @@ -103,7 +104,7 @@ include::{snippets}/should_document_get_project/links.adoc[]
==== Listing releases

A `GET` request will get releases of a single project. +
Only linked releases without any releases of sub-projects (&transitive=false).
Only linked releases without any releases of sub-projects `&transitive=false`.

===== Response structure

Expand All @@ -125,7 +126,7 @@ include::{snippets}/should_document_get_project_releases/links.adoc[]
==== Listing releases (transitive)

A `GET` request will get all releases of a single project (transitive). +
Please set the request parameter (&transitive=true).
Please set the request parameter `&transitive=true`.

===== Response structure

Expand Down
Expand Up @@ -10,7 +10,6 @@
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*/

package org.eclipse.sw360.rest.resourceserver.component;

import lombok.NonNull;
Expand Down Expand Up @@ -79,13 +78,8 @@ public ResponseEntity<Resources<Resource<Component>>> getComponents(@RequestPara
sw360Components.stream()
.filter(component -> componentType == null || componentType.equals(component.componentType.name()))
.forEach(c -> {
c.setDescription(null);
c.setType(null);
c.setCreatedOn(null);
c.setVendorNames(null);
c.setReleaseIds(null);
c.setComponentOwner(null);
componentResources.add(new Resource<>(c));
Component embeddedComponent = restControllerHelper.convertToEmbeddedComponent(c);
componentResources.add(new Resource<>(embeddedComponent));
});

Resources<Resource<Component>> resources = new Resources<>(componentResources);
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright Siemens AG, 2017. Part of the SW360 Portal Project.
* Copyright Siemens AG, 2017-2018. Part of the SW360 Portal Project.
*
* SPDX-License-Identifier: EPL-1.0
*
Expand All @@ -8,11 +8,18 @@
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*/

package org.eclipse.sw360.rest.resourceserver.core;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.eclipse.sw360.datahandler.thrift.components.Component;
import org.eclipse.sw360.datahandler.thrift.components.Release;
import org.eclipse.sw360.datahandler.thrift.licenses.License;
import org.eclipse.sw360.datahandler.thrift.projects.Project;
import org.eclipse.sw360.datahandler.thrift.users.User;
import org.eclipse.sw360.datahandler.thrift.vendors.Vendor;
import org.eclipse.sw360.datahandler.thrift.vulnerabilities.Vulnerability;
import org.eclipse.sw360.datahandler.thrift.vulnerabilities.VulnerabilityDTO;
import org.springframework.hateoas.Link;
import org.springframework.hateoas.Resource;

Expand All @@ -28,6 +35,23 @@ public class HalResource<T> extends Resource<T> {

public HalResource(T content, Link... links) {
super(content, links);
if (content instanceof Project) {
((Project) content).setType(null);
} else if (content instanceof Component) {
((Component) content).setType(null);
} else if (content instanceof Release) {
((Release) content).setType(null);
} else if (content instanceof User) {
((User) content).setType(null);
} else if (content instanceof License) {
((License) content).setType(null);
} else if (content instanceof Vendor) {
((Vendor) content).setType(null);
} else if (content instanceof Vulnerability) {
((Vulnerability) content).setType(null);
} else if (content instanceof VulnerabilityDTO) {
((VulnerabilityDTO) content).setType(null);
}
}

@SuppressWarnings("unchecked")
Expand All @@ -39,17 +63,15 @@ public void addEmbeddedResource(String relation, Object embeddedResource) {
Object embeddedResources = embeddedMap.get(relation);
boolean isPluralRelation = relation.endsWith("s");



// if a relation is plural, the content will always be rendered as an array
if(isPluralRelation) {
if (isPluralRelation) {
if (embeddedResources == null) {
embeddedResources = new ArrayList<>();
}
((List<Object>) embeddedResources).add(embeddedResource);

// if a relation is singular, it would be a single object if there is only one object available
// Otherwise it would be rendered as array
// if a relation is singular, it would be a single object if there is only one object available
// Otherwise it would be rendered as array
} else {
if (embeddedResources == null) {
embeddedResources = embeddedResource;
Expand Down
Expand Up @@ -298,8 +298,6 @@ static abstract class ComponentMixin extends Component {
"createdBy",
"moderators",
"clearingInformation",
"mainlineState",
"downloadurl",
"setAttachments",
"setCreatedOn",
"setRepository",
Expand Down Expand Up @@ -370,7 +368,6 @@ static abstract class ReleaseMixin extends Release {
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonIgnoreProperties({
"attachmentContentId",
"createdBy",
"setAttachmentContentId",
"setAttachmentType",
"setCreatedComment",
Expand Down Expand Up @@ -614,15 +611,11 @@ static abstract class VulnerabilityMixin extends Vulnerability {

@JsonInclude(JsonInclude.Include.NON_EMPTY)
@JsonIgnoreProperties({
"AL",
"ECCN",
"assessorContactPerson",
"assessorDepartment",
"eccComment",
"materialIndexNumber",
"assessmentDate",
"al",
"eccn",
"setEccComment",
"setECCN",
"setEccStatus",
Expand Down

0 comments on commit 2b023cb

Please sign in to comment.