Add target filter query feign client resource (#410)

* Add TagretFilter Query client resource

Signed-off-by: SirWayne <dennis.melzer@bosch-si.com>

* Fix methode signature for feign

Signed-off-by: SirWayne <dennis.melzer@bosch-si.com>
This commit is contained in:
Dennis Melzer
2017-01-26 15:01:42 +01:00
committed by Kai Zimmermann
parent 5514658f93
commit a00ea49e47
4 changed files with 78 additions and 4 deletions

View File

@@ -0,0 +1,19 @@
/**
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*/
package org.eclipse.hawkbit.mgmt.client.resource;
import org.eclipse.hawkbit.mgmt.rest.api.MgmtTargetFilterQueryRestApi;
import org.springframework.cloud.netflix.feign.FeignClient;
/**
* Client binding for the Target filter query resource of the management API.
*/
@FeignClient(name = "MgmtTargetFilterQueryClient", url = "${hawkbit.url:localhost:8080}")
public interface MgmtTargetFilterQueryClientResource extends MgmtTargetFilterQueryRestApi {
}

View File

@@ -0,0 +1,55 @@
/**
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*/
package org.eclipse.hawkbit.mgmt.client.resource.builder;
import org.eclipse.hawkbit.mgmt.json.model.targetfilter.MgmtTargetFilterQueryRequestBody;
/**
* Builder pattern for building {@link MgmtTargetFilterQueryRequestBody}.
*/
// Exception squid:S1701 - builder pattern
@SuppressWarnings({ "squid:S1701" })
public class TargetFilterQueryBuilder {
private String name;
private String query;
/**
* @param name
* the name of the filter
* @return the builder itself
*/
public TargetFilterQueryBuilder name(final String name) {
this.name = name;
return this;
}
/**
* @param query
* the query filter
* @return the builder itself
*/
public TargetFilterQueryBuilder query(final String query) {
this.query = query;
return this;
}
/**
* Builds a single entry of {@link MgmtTargetFilterQueryRequestBody} which
* can directly be used to post on the RESTful-API.
*
* @return a single entry of {@link MgmtTargetFilterQueryRequestBody}
*/
public MgmtTargetFilterQueryRequestBody build() {
final MgmtTargetFilterQueryRequestBody body = new MgmtTargetFilterQueryRequestBody();
body.setName(name);
body.setQuery(query);
return body;
}
}

View File

@@ -12,7 +12,6 @@ import java.io.InputStream;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@@ -43,7 +42,7 @@ public interface DdiDlArtifactStoreControllerRestApi {
+ "/{fileName}")
@ResponseBody
ResponseEntity<InputStream> downloadArtifactByFilename(@PathVariable("tenant") final String tenant,
@PathVariable("fileName") final String fileName, @AuthenticationPrincipal final Object principal);
@PathVariable("fileName") final String fileName);
/**
* Handles GET MD5 checksum file download request.

View File

@@ -36,7 +36,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.WebApplicationContext;
@@ -71,7 +71,8 @@ public class DdiArtifactStoreController implements DdiDlArtifactStoreControllerR
@Override
public ResponseEntity<InputStream> downloadArtifactByFilename(@PathVariable("tenant") final String tenant,
@PathVariable("fileName") final String fileName, @AuthenticationPrincipal final Object principal) {
@PathVariable("fileName") final String fileName) {
final Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
final List<Artifact> foundArtifacts = artifactManagement.findArtifactByFilename(fileName);
if (foundArtifacts.isEmpty()) {