Upgrade sonar to new 6.2 installation (#456)
* Upgrade to new sonar instance. Fix new identified issues. Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>
This commit is contained in:
@@ -8,12 +8,6 @@
|
||||
*/
|
||||
package org.eclipse.hawkbit.mgmt.rest.resource;
|
||||
|
||||
import static org.eclipse.hawkbit.mgmt.rest.resource.MgmtDistributionSetTypeMapper.toResponse;
|
||||
import static org.eclipse.hawkbit.mgmt.rest.resource.MgmtDistributionSetTypeMapper.toTypesResponse;
|
||||
import static org.eclipse.hawkbit.mgmt.rest.resource.MgmtSoftwareModuleTypeMapper.toResponse;
|
||||
import static org.eclipse.hawkbit.mgmt.rest.resource.MgmtSoftwareModuleTypeMapper.toTypesResponse;
|
||||
import static org.springframework.http.HttpStatus.CREATED;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.hawkbit.mgmt.json.model.MgmtId;
|
||||
@@ -39,6 +33,7 @@ import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.domain.Slice;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
@@ -95,7 +90,7 @@ public class MgmtDistributionSetTypeResource implements MgmtDistributionSetTypeR
|
||||
@PathVariable("distributionSetTypeId") final Long distributionSetTypeId) {
|
||||
|
||||
final DistributionSetType foundType = findDistributionSetTypeWithExceptionIfNotFound(distributionSetTypeId);
|
||||
return ResponseEntity.ok(toResponse(foundType));
|
||||
return ResponseEntity.ok(MgmtDistributionSetTypeMapper.toResponse(foundType));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -111,9 +106,10 @@ public class MgmtDistributionSetTypeResource implements MgmtDistributionSetTypeR
|
||||
@PathVariable("distributionSetTypeId") final Long distributionSetTypeId,
|
||||
@RequestBody final MgmtDistributionSetTypeRequestBodyPut restDistributionSetType) {
|
||||
|
||||
return ResponseEntity.ok(toResponse(distributionSetManagement.updateDistributionSetType(entityFactory
|
||||
.distributionSetType().update(distributionSetTypeId)
|
||||
.description(restDistributionSetType.getDescription()).colour(restDistributionSetType.getColour()))));
|
||||
return ResponseEntity.ok(MgmtDistributionSetTypeMapper
|
||||
.toResponse(distributionSetManagement.updateDistributionSetType(entityFactory.distributionSetType()
|
||||
.update(distributionSetTypeId).description(restDistributionSetType.getDescription())
|
||||
.colour(restDistributionSetType.getColour()))));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -123,7 +119,8 @@ public class MgmtDistributionSetTypeResource implements MgmtDistributionSetTypeR
|
||||
final List<DistributionSetType> createdSoftwareModules = distributionSetManagement.createDistributionSetTypes(
|
||||
MgmtDistributionSetTypeMapper.smFromRequest(entityFactory, distributionSetTypes));
|
||||
|
||||
return ResponseEntity.status(CREATED).body(toTypesResponse(createdSoftwareModules));
|
||||
return ResponseEntity.status(HttpStatus.CREATED)
|
||||
.body(MgmtDistributionSetTypeMapper.toTypesResponse(createdSoftwareModules));
|
||||
}
|
||||
|
||||
private DistributionSetType findDistributionSetTypeWithExceptionIfNotFound(final Long distributionSetTypeId) {
|
||||
@@ -136,7 +133,7 @@ public class MgmtDistributionSetTypeResource implements MgmtDistributionSetTypeR
|
||||
@PathVariable("distributionSetTypeId") final Long distributionSetTypeId) {
|
||||
|
||||
final DistributionSetType foundType = findDistributionSetTypeWithExceptionIfNotFound(distributionSetTypeId);
|
||||
return ResponseEntity.ok(toTypesResponse(foundType.getMandatoryModuleTypes()));
|
||||
return ResponseEntity.ok(MgmtSoftwareModuleTypeMapper.toTypesResponse(foundType.getMandatoryModuleTypes()));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -151,7 +148,7 @@ public class MgmtDistributionSetTypeResource implements MgmtDistributionSetTypeR
|
||||
throw new SoftwareModuleTypeNotInDistributionSetTypeException(softwareModuleTypeId, distributionSetTypeId);
|
||||
}
|
||||
|
||||
return ResponseEntity.ok(toResponse(foundSmType));
|
||||
return ResponseEntity.ok(MgmtSoftwareModuleTypeMapper.toResponse(foundSmType));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -166,7 +163,7 @@ public class MgmtDistributionSetTypeResource implements MgmtDistributionSetTypeR
|
||||
throw new SoftwareModuleTypeNotInDistributionSetTypeException(softwareModuleTypeId, distributionSetTypeId);
|
||||
}
|
||||
|
||||
return ResponseEntity.ok(toResponse(foundSmType));
|
||||
return ResponseEntity.ok(MgmtSoftwareModuleTypeMapper.toResponse(foundSmType));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -174,7 +171,7 @@ public class MgmtDistributionSetTypeResource implements MgmtDistributionSetTypeR
|
||||
@PathVariable("distributionSetTypeId") final Long distributionSetTypeId) {
|
||||
|
||||
final DistributionSetType foundType = findDistributionSetTypeWithExceptionIfNotFound(distributionSetTypeId);
|
||||
return ResponseEntity.ok(toTypesResponse(foundType.getOptionalModuleTypes()));
|
||||
return ResponseEntity.ok(MgmtSoftwareModuleTypeMapper.toTypesResponse(foundType.getOptionalModuleTypes()));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -61,13 +61,11 @@ public class MgmtDownloadArtifactResource implements MgmtDownloadArtifactRestApi
|
||||
@ResponseBody
|
||||
public ResponseEntity<InputStream> downloadArtifact(@PathVariable("softwareModuleId") final Long softwareModuleId,
|
||||
@PathVariable("artifactId") final Long artifactId) {
|
||||
final SoftwareModule module = findSoftwareModuleWithExceptionIfNotFound(softwareModuleId, artifactId);
|
||||
final SoftwareModule module = softwareManagement.findSoftwareModuleById(softwareModuleId)
|
||||
.orElseThrow(() -> new EntityNotFoundException(SoftwareModule.class, softwareModuleId));
|
||||
final Artifact artifact = module.getArtifact(artifactId)
|
||||
.orElseThrow(() -> new EntityNotFoundException(Artifact.class, artifactId));
|
||||
|
||||
if (null == module || !module.getArtifact(artifactId).isPresent()) {
|
||||
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
|
||||
}
|
||||
|
||||
final Artifact artifact = module.getArtifact(artifactId).get();
|
||||
final DbArtifact file = artifactManagement.loadArtifactBinary(artifact.getSha1Hash())
|
||||
.orElseThrow(() -> new ArtifactBinaryNotFoundException(artifact.getSha1Hash()));
|
||||
final HttpServletRequest request = requestResponseContextHolder.getHttpServletRequest();
|
||||
@@ -81,14 +79,4 @@ public class MgmtDownloadArtifactResource implements MgmtDownloadArtifactRestApi
|
||||
|
||||
}
|
||||
|
||||
private SoftwareModule findSoftwareModuleWithExceptionIfNotFound(final Long softwareModuleId,
|
||||
final Long artifactId) {
|
||||
final SoftwareModule module = softwareManagement.findSoftwareModuleById(softwareModuleId)
|
||||
.orElseThrow(() -> new EntityNotFoundException(SoftwareModule.class, softwareModuleId));
|
||||
if (artifactId != null && !module.getArtifact(artifactId).isPresent()) {
|
||||
throw new EntityNotFoundException(Artifact.class, artifactId);
|
||||
}
|
||||
return module;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -8,11 +8,6 @@
|
||||
*/
|
||||
package org.eclipse.hawkbit.mgmt.rest.resource;
|
||||
|
||||
import static com.google.common.net.HttpHeaders.CONTENT_DISPOSITION;
|
||||
import static com.google.common.net.HttpHeaders.CONTENT_LENGTH;
|
||||
import static com.google.common.net.HttpHeaders.ETAG;
|
||||
import static org.springframework.http.MediaType.APPLICATION_OCTET_STREAM_VALUE;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
@@ -30,6 +25,7 @@ import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
@@ -37,6 +33,7 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.context.WebApplicationContext;
|
||||
|
||||
import com.google.common.io.ByteStreams;
|
||||
import com.google.common.net.HttpHeaders;
|
||||
|
||||
/**
|
||||
* A resource for download artifacts.
|
||||
@@ -94,10 +91,10 @@ public class MgmtDownloadResource implements MgmtDownloadRestApi {
|
||||
final HttpServletResponse response = requestResponseContextHolder.getHttpServletResponse();
|
||||
final String etag = artifact.getHashes().getSha1();
|
||||
final long length = artifact.getSize();
|
||||
response.setHeader(CONTENT_DISPOSITION, "attachment;filename=" + downloadId);
|
||||
response.setHeader(ETAG, etag);
|
||||
response.setContentType(APPLICATION_OCTET_STREAM_VALUE);
|
||||
response.setHeader(CONTENT_LENGTH, String.valueOf(length));
|
||||
response.setHeader(HttpHeaders.CONTENT_DISPOSITION, "attachment;filename=" + downloadId);
|
||||
response.setHeader(HttpHeaders.ETAG, etag);
|
||||
response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
|
||||
response.setContentLengthLong(length);
|
||||
|
||||
try (InputStream inputstream = artifact.getFileInputStream()) {
|
||||
ByteStreams.copy(inputstream, requestResponseContextHolder.getHttpServletResponse().getOutputStream());
|
||||
|
||||
@@ -8,13 +8,6 @@
|
||||
*/
|
||||
package org.eclipse.hawkbit.mgmt.rest.resource;
|
||||
|
||||
import static org.eclipse.hawkbit.mgmt.rest.resource.MgmtSoftwareModuleMapper.artifactsToResponse;
|
||||
import static org.eclipse.hawkbit.mgmt.rest.resource.MgmtSoftwareModuleMapper.toResponse;
|
||||
import static org.eclipse.hawkbit.mgmt.rest.resource.MgmtSoftwareModuleMapper.toResponseSwMetadata;
|
||||
import static org.springframework.http.HttpStatus.BAD_REQUEST;
|
||||
import static org.springframework.http.HttpStatus.CREATED;
|
||||
import static org.springframework.http.HttpStatus.INTERNAL_SERVER_ERROR;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
@@ -77,7 +70,7 @@ public class MgmtSoftwareModuleResource implements MgmtSoftwareModuleRestApi {
|
||||
@RequestParam(value = "sha1sum", required = false) final String sha1Sum) {
|
||||
|
||||
if (file.isEmpty()) {
|
||||
return new ResponseEntity<>(BAD_REQUEST);
|
||||
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
String fileName = optionalFileName;
|
||||
|
||||
@@ -89,10 +82,10 @@ public class MgmtSoftwareModuleResource implements MgmtSoftwareModuleRestApi {
|
||||
final Artifact result = artifactManagement.createArtifact(file.getInputStream(), softwareModuleId, fileName,
|
||||
md5Sum == null ? null : md5Sum.toLowerCase(), sha1Sum == null ? null : sha1Sum.toLowerCase(), false,
|
||||
file.getContentType());
|
||||
return ResponseEntity.status(CREATED).body(toResponse(result));
|
||||
return ResponseEntity.status(HttpStatus.CREATED).body(MgmtSoftwareModuleMapper.toResponse(result));
|
||||
} catch (final IOException e) {
|
||||
LOG.error("Failed to store artifact", e);
|
||||
return new ResponseEntity<>(INTERNAL_SERVER_ERROR);
|
||||
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -101,7 +94,7 @@ public class MgmtSoftwareModuleResource implements MgmtSoftwareModuleRestApi {
|
||||
@PathVariable("softwareModuleId") final Long softwareModuleId) {
|
||||
|
||||
final SoftwareModule module = findSoftwareModuleWithExceptionIfNotFound(softwareModuleId, null);
|
||||
return ResponseEntity.ok(artifactsToResponse(module.getArtifacts()));
|
||||
return ResponseEntity.ok(MgmtSoftwareModuleMapper.artifactsToResponse(module.getArtifacts()));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -115,7 +108,7 @@ public class MgmtSoftwareModuleResource implements MgmtSoftwareModuleRestApi {
|
||||
|
||||
final SoftwareModule module = findSoftwareModuleWithExceptionIfNotFound(softwareModuleId, artifactId);
|
||||
|
||||
return ResponseEntity.ok(toResponse(module.getArtifact(artifactId).get()));
|
||||
return ResponseEntity.ok(MgmtSoftwareModuleMapper.toResponse(module.getArtifact(artifactId).get()));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -161,7 +154,7 @@ public class MgmtSoftwareModuleResource implements MgmtSoftwareModuleRestApi {
|
||||
@PathVariable("softwareModuleId") final Long softwareModuleId) {
|
||||
|
||||
final SoftwareModule findBaseSoftareModule = findSoftwareModuleWithExceptionIfNotFound(softwareModuleId, null);
|
||||
return ResponseEntity.ok(toResponse(findBaseSoftareModule));
|
||||
return ResponseEntity.ok(MgmtSoftwareModuleMapper.toResponse(findBaseSoftareModule));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -173,7 +166,8 @@ public class MgmtSoftwareModuleResource implements MgmtSoftwareModuleRestApi {
|
||||
.createSoftwareModule(MgmtSoftwareModuleMapper.smFromRequest(entityFactory, softwareModules));
|
||||
LOG.debug("{} softwareModules created, return status {}", softwareModules.size(), HttpStatus.CREATED);
|
||||
|
||||
return ResponseEntity.status(CREATED).body(toResponse(createdSoftwareModules));
|
||||
return ResponseEntity.status(HttpStatus.CREATED)
|
||||
.body(MgmtSoftwareModuleMapper.toResponse(createdSoftwareModules));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -181,7 +175,7 @@ public class MgmtSoftwareModuleResource implements MgmtSoftwareModuleRestApi {
|
||||
@PathVariable("softwareModuleId") final Long softwareModuleId,
|
||||
@RequestBody final MgmtSoftwareModuleRequestBodyPut restSoftwareModule) {
|
||||
|
||||
return ResponseEntity.ok(toResponse(
|
||||
return ResponseEntity.ok(MgmtSoftwareModuleMapper.toResponse(
|
||||
softwareManagement.updateSoftwareModule(entityFactory.softwareModule().update(softwareModuleId)
|
||||
.description(restSoftwareModule.getDescription()).vendor(restSoftwareModule.getVendor()))));
|
||||
}
|
||||
@@ -221,7 +215,8 @@ public class MgmtSoftwareModuleResource implements MgmtSoftwareModuleRestApi {
|
||||
}
|
||||
|
||||
return ResponseEntity
|
||||
.ok(new PagedList<>(toResponseSwMetadata(metaDataPage.getContent()), metaDataPage.getTotalElements()));
|
||||
.ok(new PagedList<>(MgmtSoftwareModuleMapper.toResponseSwMetadata(metaDataPage.getContent()),
|
||||
metaDataPage.getTotalElements()));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -232,7 +227,7 @@ public class MgmtSoftwareModuleResource implements MgmtSoftwareModuleRestApi {
|
||||
.findSoftwareModuleMetadata(softwareModuleId, metadataKey).orElseThrow(
|
||||
() -> new EntityNotFoundException(SoftwareModuleMetadata.class, softwareModuleId, metadataKey));
|
||||
|
||||
return ResponseEntity.ok(toResponseSwMetadata(findOne));
|
||||
return ResponseEntity.ok(MgmtSoftwareModuleMapper.toResponseSwMetadata(findOne));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -241,7 +236,7 @@ public class MgmtSoftwareModuleResource implements MgmtSoftwareModuleRestApi {
|
||||
final SoftwareModuleMetadata updated = softwareManagement.updateSoftwareModuleMetadata(softwareModuleId,
|
||||
entityFactory.generateMetadata(metadataKey, metadata.getValue()));
|
||||
|
||||
return ResponseEntity.ok(toResponseSwMetadata(updated));
|
||||
return ResponseEntity.ok(MgmtSoftwareModuleMapper.toResponseSwMetadata(updated));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -260,7 +255,7 @@ public class MgmtSoftwareModuleResource implements MgmtSoftwareModuleRestApi {
|
||||
final List<SoftwareModuleMetadata> created = softwareManagement.createSoftwareModuleMetadata(softwareModuleId,
|
||||
MgmtSoftwareModuleMapper.fromRequestSwMetadata(entityFactory, metadataRest));
|
||||
|
||||
return ResponseEntity.status(CREATED).body(toResponseSwMetadata(created));
|
||||
return ResponseEntity.status(HttpStatus.CREATED).body(MgmtSoftwareModuleMapper.toResponseSwMetadata(created));
|
||||
}
|
||||
|
||||
private SoftwareModule findSoftwareModuleWithExceptionIfNotFound(final Long softwareModuleId,
|
||||
|
||||
Reference in New Issue
Block a user