Cleanup file streaming utilities (#559)

* Cleanup file streaming.

Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>

* Added missing comments.

Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>

* Fix typo.

Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>

* Split utility class.

Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>

* Dependency cleanup.

Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>

* Add missing dependency,

Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>

* Remove repository api dependency from rest core.

Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>

* Fix build and sonar issues.

Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>

* Remove custom ConstraintViolationException

Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>

* RequestMapping should be public.

Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>

* Fix errors.

Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>

* Removed dead code.

Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>

* Not null

Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>

* Fix nullpointer.

Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>

* Code cleanup.

Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>
This commit is contained in:
Kai Zimmermann
2017-07-19 12:43:07 +02:00
committed by GitHub
parent 66feae2756
commit 09b24fa97d
59 changed files with 911 additions and 908 deletions

View File

@@ -13,7 +13,7 @@ import java.util.Optional;
import javax.validation.constraints.NotNull;
import org.eclipse.hawkbit.artifact.repository.model.DbArtifact;
import org.eclipse.hawkbit.artifact.repository.model.AbstractDbArtifact;
import org.eclipse.hawkbit.im.authentication.SpPermission.SpringEvalExpressions;
import org.eclipse.hawkbit.repository.exception.ArtifactDeleteFailedException;
import org.eclipse.hawkbit.repository.exception.ArtifactUploadFailedException;
@@ -196,15 +196,15 @@ public interface ArtifactManagement {
Page<Artifact> findArtifactBySoftwareModule(@NotNull Pageable pageReq, @NotNull Long swId);
/**
* Loads {@link DbArtifact} from store for given {@link Artifact}.
* Loads {@link AbstractDbArtifact} from store for given {@link Artifact}.
*
* @param sha1Hash
* to search for
* @return loaded {@link DbArtifact}
* @return loaded {@link AbstractDbArtifact}
*
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_DOWNLOAD_ARTIFACT + SpringEvalExpressions.HAS_AUTH_OR
+ SpringEvalExpressions.HAS_CONTROLLER_DOWNLOAD)
Optional<DbArtifact> loadArtifactBinary(@NotEmpty String sha1Hash);
Optional<AbstractDbArtifact> loadArtifactBinary(@NotEmpty String sha1Hash);
}

View File

@@ -17,7 +17,6 @@ import javax.validation.constraints.NotNull;
import org.eclipse.hawkbit.im.authentication.SpPermission.SpringEvalExpressions;
import org.eclipse.hawkbit.repository.builder.ActionStatusCreate;
import org.eclipse.hawkbit.repository.event.remote.DownloadProgressEvent;
import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException;
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
import org.eclipse.hawkbit.repository.exception.QuotaExceededException;
@@ -61,22 +60,6 @@ public interface ControllerManagement {
@PreAuthorize(SpringEvalExpressions.IS_CONTROLLER)
Action addCancelActionStatus(@NotNull ActionStatusCreate create);
/**
* Sends the download progress and notifies the event publisher with a
* {@link DownloadProgressEvent}.
*
* @param statusId
* the ID of the {@link ActionStatus}
* @param requestedBytes
* requested bytes of the request
* @param shippedBytesSinceLast
* since the last report
* @param shippedBytesOverall
* for the {@link ActionStatus}
*/
@PreAuthorize(SpringEvalExpressions.IS_CONTROLLER)
void downloadProgress(Long statusId, Long requestedBytes, Long shippedBytesSinceLast, Long shippedBytesOverall);
/**
* Simple addition of a new {@link ActionStatus} entry to the {@link Action}
* . No state changes.

View File

@@ -11,13 +11,13 @@ package org.eclipse.hawkbit.repository;
import java.util.List;
import java.util.Optional;
import javax.validation.ConstraintViolationException;
import javax.validation.constraints.NotNull;
import org.eclipse.hawkbit.im.authentication.SpPermission.SpringEvalExpressions;
import org.eclipse.hawkbit.repository.builder.RolloutCreate;
import org.eclipse.hawkbit.repository.builder.RolloutGroupCreate;
import org.eclipse.hawkbit.repository.builder.RolloutUpdate;
import org.eclipse.hawkbit.repository.exception.ConstraintViolationException;
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
import org.eclipse.hawkbit.repository.exception.EntityReadOnlyException;
import org.eclipse.hawkbit.repository.exception.RSQLParameterSyntaxException;

View File

@@ -8,6 +8,8 @@
*/
package org.eclipse.hawkbit.repository.event.remote;
import org.eclipse.hawkbit.repository.model.ActionStatus;
/**
* TenantAwareEvent that contains an updated download progress for a given
* ActionStatus that was written for a download request.
@@ -17,7 +19,7 @@ public class DownloadProgressEvent extends RemoteTenantAwareEvent {
private static final long serialVersionUID = 1L;
private Long shippedBytesSinceLast;
private long shippedBytesSinceLast;
/**
* Default constructor.
@@ -31,13 +33,16 @@ public class DownloadProgressEvent extends RemoteTenantAwareEvent {
*
* @param tenant
* the tenant
* @param actionStatusId
* of the {@link ActionStatus} the download belongs to
* @param shippedBytesSinceLast
* the shippedBytesSinceLast
* @param applicationId
* the application id.
*/
public DownloadProgressEvent(final String tenant, final Long shippedBytesSinceLast, final String applicationId) {
super(shippedBytesSinceLast, tenant, applicationId);
public DownloadProgressEvent(final String tenant, final Long actionStatusId, final long shippedBytesSinceLast,
final String applicationId) {
super(actionStatusId, tenant, applicationId);
this.shippedBytesSinceLast = shippedBytesSinceLast;
}

View File

@@ -1,64 +0,0 @@
/**
* 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.repository.exception;
import java.util.stream.Collectors;
import org.eclipse.hawkbit.exception.AbstractServerRtException;
import org.eclipse.hawkbit.exception.SpServerError;
/**
* the {@link ConstraintViolationException} is thrown when an entity is tried to
* be saved which has constraint violations
*/
public class ConstraintViolationException extends AbstractServerRtException {
private static final long serialVersionUID = 1L;
private static final String MESSAGE_FORMATTER_SEPARATOR = " ";
/**
* Constructor for {@link ConstraintViolationException}
*
* @param ex
* the javax.validation.ConstraintViolationException which is
* thrown
*/
public ConstraintViolationException(final javax.validation.ConstraintViolationException ex) {
this(getExceptionMessage(ex));
}
/**
* Creates a new {@link ConstraintViolationException} with the error code
* {@link SpServerError#SP_REPO_CONSTRAINT_VIOLATION}.
*
* @param msgText
* the message text for this exception
*/
public ConstraintViolationException(final String msgText) {
super(msgText, SpServerError.SP_REPO_CONSTRAINT_VIOLATION);
}
/**
* Uses the information of
* {@link javax.validation.ConstraintViolationException} to provide a proper
* error message for {@link ConstraintViolationException}
*
* @param ex
* javax.validation.ConstraintViolationException which is thrown
* @return message String with proper error information
*/
public static String getExceptionMessage(final javax.validation.ConstraintViolationException ex) {
return ex
.getConstraintViolations().stream().map(violation -> violation.getPropertyPath()
+ MESSAGE_FORMATTER_SEPARATOR + violation.getMessage() + ".")
.collect(Collectors.joining(MESSAGE_FORMATTER_SEPARATOR));
}
}

View File

@@ -1,30 +0,0 @@
/**
* 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.repository.exception;
import org.eclipse.hawkbit.exception.AbstractServerRtException;
import org.eclipse.hawkbit.exception.SpServerError;
/**
* Thrown if a multi part exception occurred.
*
*/
public final class MultiPartFileUploadException extends AbstractServerRtException {
private static final long serialVersionUID = 1L;
/**
* @param cause
* for the exception
*/
public MultiPartFileUploadException(final Throwable cause) {
super(cause.getMessage(), SpServerError.SP_ARTIFACT_UPLOAD_FAILED, cause);
}
}

View File

@@ -8,7 +8,7 @@
*/
package org.eclipse.hawkbit.repository.model;
import org.eclipse.hawkbit.artifact.repository.model.DbArtifact;
import org.eclipse.hawkbit.artifact.repository.model.AbstractDbArtifact;
/**
* Binaries for a {@link SoftwareModule} Note: the decision which artifacts have
@@ -34,7 +34,7 @@ public interface Artifact extends TenantAwareBaseEntity {
/**
* @return SHA-1 hash of the artifact in Base16 format that identifies the
* {@link DbArtifact} in the system.
* {@link AbstractDbArtifact} in the system.
*/
String getSha1Hash();