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:
@@ -12,7 +12,7 @@ import java.io.InputStream;
|
||||
|
||||
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.artifact.repository.model.DbArtifactHash;
|
||||
import org.hibernate.validator.constraints.NotEmpty;
|
||||
|
||||
@@ -42,7 +42,7 @@ public interface ArtifactRepository {
|
||||
* @throws ArtifactStoreException
|
||||
* in case storing of the artifact was not successful
|
||||
*/
|
||||
DbArtifact store(@NotEmpty String tenant, @NotNull InputStream content, @NotEmpty String filename,
|
||||
AbstractDbArtifact store(@NotEmpty String tenant, @NotNull InputStream content, @NotEmpty String filename,
|
||||
String contentType);
|
||||
|
||||
/**
|
||||
@@ -69,7 +69,7 @@ public interface ArtifactRepository {
|
||||
* in case {@code hash} is provided and not matching to the
|
||||
* calculated hashes during storing
|
||||
*/
|
||||
DbArtifact store(@NotEmpty String tenant, @NotNull InputStream content, @NotEmpty String filename,
|
||||
AbstractDbArtifact store(@NotEmpty String tenant, @NotNull InputStream content, @NotEmpty String filename,
|
||||
String contentType, DbArtifactHash hash);
|
||||
|
||||
/**
|
||||
@@ -86,7 +86,7 @@ public interface ArtifactRepository {
|
||||
void deleteBySha1(@NotEmpty String tenant, @NotEmpty String sha1Hash);
|
||||
|
||||
/**
|
||||
* Retrieves a {@link DbArtifact} from the store by it's SHA1 hash.
|
||||
* Retrieves a {@link AbstractDbArtifact} from the store by it's SHA1 hash.
|
||||
*
|
||||
* @param tenant
|
||||
* the tenant to store the artifact
|
||||
@@ -97,7 +97,7 @@ public interface ArtifactRepository {
|
||||
* @throws MethodNotSupportedException
|
||||
* if implementation does not support the operation
|
||||
*/
|
||||
DbArtifact getArtifactBySha1(@NotEmpty String tenant, @NotEmpty String sha1Hash);
|
||||
AbstractDbArtifact getArtifactBySha1(@NotEmpty String tenant, @NotEmpty String sha1Hash);
|
||||
|
||||
/**
|
||||
* Deletes all artifacts of given tenant.
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
/**
|
||||
* 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.artifact.repository.model;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* Database representation of artifact.
|
||||
*
|
||||
*/
|
||||
public abstract class AbstractDbArtifact {
|
||||
|
||||
private final String artifactId;
|
||||
private final DbArtifactHash hashes;
|
||||
private final long size;
|
||||
private final String contentType;
|
||||
|
||||
protected AbstractDbArtifact(final String artifactId, final DbArtifactHash hashes, final long size,
|
||||
final String contentType) {
|
||||
Assert.notNull(artifactId, "Artifact ID cannot be null");
|
||||
Assert.notNull(hashes, "Hashes cannot be null");
|
||||
this.artifactId = artifactId;
|
||||
this.hashes = hashes;
|
||||
this.size = size;
|
||||
this.contentType = contentType;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ID of the artifact
|
||||
*/
|
||||
public String getArtifactId() {
|
||||
return artifactId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return hashes of the artifact
|
||||
*/
|
||||
public DbArtifactHash getHashes() {
|
||||
return hashes;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return site of the artifact in bytes
|
||||
*/
|
||||
public long getSize() {
|
||||
return size;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return content-type if known by the repository or <code>null</code>
|
||||
*/
|
||||
public String getContentType() {
|
||||
return contentType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an {@link InputStream} on this artifact. Caller has to take care
|
||||
* of closing the stream. Repeatable calls open a new {@link InputStream}.
|
||||
*
|
||||
* @return {@link InputStream} to read from artifact.
|
||||
*/
|
||||
public abstract InputStream getFileInputStream();
|
||||
}
|
||||
@@ -1,79 +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.artifact.repository.model;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
|
||||
/**
|
||||
* Database representation of artifact.
|
||||
*
|
||||
*/
|
||||
public class DbArtifact {
|
||||
|
||||
private String artifactId;
|
||||
|
||||
private DbArtifactHash hashes;
|
||||
|
||||
private Long size;
|
||||
|
||||
private String contentType;
|
||||
|
||||
private InputStream fileInputStream;
|
||||
|
||||
private OutputStream fileOutputStream;
|
||||
|
||||
public void setArtifactId(final String artifactId) {
|
||||
this.artifactId = artifactId;
|
||||
}
|
||||
|
||||
public String getArtifactId() {
|
||||
return artifactId;
|
||||
}
|
||||
|
||||
public DbArtifactHash getHashes() {
|
||||
return hashes;
|
||||
}
|
||||
|
||||
public void setHashes(final DbArtifactHash hashes) {
|
||||
this.hashes = hashes;
|
||||
}
|
||||
|
||||
public Long getSize() {
|
||||
return size;
|
||||
}
|
||||
|
||||
public void setSize(final Long size) {
|
||||
this.size = size;
|
||||
}
|
||||
|
||||
public void setContentType(final String contentType) {
|
||||
this.contentType = contentType;
|
||||
}
|
||||
|
||||
public String getContentType() {
|
||||
return contentType;
|
||||
}
|
||||
|
||||
public void setFileInputStream(final InputStream fileInputStream) {
|
||||
this.fileInputStream = fileInputStream;
|
||||
}
|
||||
|
||||
public InputStream getFileInputStream() {
|
||||
return fileInputStream;
|
||||
}
|
||||
|
||||
public OutputStream getFileOutputStream() {
|
||||
return fileOutputStream;
|
||||
}
|
||||
|
||||
public void setFileOutputStream(final OutputStream fileOutputStream) {
|
||||
this.fileOutputStream = fileOutputStream;
|
||||
}
|
||||
}
|
||||
@@ -14,9 +14,9 @@ package org.eclipse.hawkbit.artifact.repository.model;
|
||||
*/
|
||||
public class DbArtifactHash {
|
||||
|
||||
private String sha1;
|
||||
private final String sha1;
|
||||
|
||||
private String md5;
|
||||
private final String md5;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
@@ -27,19 +27,10 @@ public class DbArtifactHash {
|
||||
* the md5 hash
|
||||
*/
|
||||
public DbArtifactHash(final String sha1, final String md5) {
|
||||
super();
|
||||
this.sha1 = sha1;
|
||||
this.md5 = md5;
|
||||
}
|
||||
|
||||
public void setSha1(final String sha1) {
|
||||
this.sha1 = sha1;
|
||||
}
|
||||
|
||||
public void setMd5(final String md5) {
|
||||
this.md5 = md5;
|
||||
}
|
||||
|
||||
public String getSha1() {
|
||||
return sha1;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user