Configurable download URL generation (#296)

Configurable download URL generation.

Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>
This commit is contained in:
Kai Zimmermann
2016-09-28 09:18:03 +02:00
committed by GitHub
parent 0cc1cfcc8c
commit 5c53bef164
77 changed files with 2114 additions and 1110 deletions

View File

@@ -9,6 +9,7 @@
package org.eclipse.hawkbit.dmf.json.model;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
@@ -18,9 +19,6 @@ import com.fasterxml.jackson.annotation.JsonProperty;
/**
* JSON representation of action update status.
*
*
*
*/
@JsonInclude(Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
@@ -32,7 +30,7 @@ public class ActionUpdateStatus {
@JsonProperty(required = true)
private ActionStatus actionStatus;
@JsonProperty
private final List<String> message = new ArrayList<>();
private List<String> message;
public Long getActionId() {
return actionId;
@@ -59,7 +57,19 @@ public class ActionUpdateStatus {
}
public List<String> getMessage() {
return message;
if (message == null) {
return Collections.emptyList();
}
return Collections.unmodifiableList(message);
}
public boolean addMessage(final String message) {
if (this.message == null) {
this.message = new ArrayList<>();
}
return this.message.add(message);
}
}

View File

@@ -8,7 +8,7 @@
*/
package org.eclipse.hawkbit.dmf.json.model;
import java.util.EnumMap;
import java.util.Collections;
import java.util.Map;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
@@ -25,15 +25,6 @@ import com.fasterxml.jackson.annotation.JsonProperty;
@JsonInclude(Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
public class Artifact {
/**
* Represented the supported protocols for artifact url's.
*
*/
public enum UrlProtocol {
COAP, HTTP, HTTPS
}
@JsonProperty
private String filename;
@@ -44,13 +35,17 @@ public class Artifact {
private Long size;
@JsonProperty
private Map<UrlProtocol, String> urls = new EnumMap<>(UrlProtocol.class);
private Map<String, String> urls;
public Map<UrlProtocol, String> getUrls() {
return urls;
public Map<String, String> getUrls() {
if (urls == null) {
return Collections.emptyMap();
}
return Collections.unmodifiableMap(urls);
}
public void setUrls(final Map<UrlProtocol, String> urls) {
public void setUrls(final Map<String, String> urls) {
this.urls = urls;
}

View File

@@ -8,7 +8,8 @@
*/
package org.eclipse.hawkbit.dmf.json.model;
import java.util.LinkedList;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
@@ -30,7 +31,7 @@ public class DownloadAndUpdateRequest {
private String targetSecurityToken;
@JsonProperty
private final List<SoftwareModule> softwareModules = new LinkedList<>();
private List<SoftwareModule> softwareModules;
public Long getActionId() {
return actionId;
@@ -49,7 +50,11 @@ public class DownloadAndUpdateRequest {
}
public List<SoftwareModule> getSoftwareModules() {
return softwareModules;
if (softwareModules == null) {
return Collections.emptyList();
}
return Collections.unmodifiableList(softwareModules);
}
/**
@@ -59,6 +64,10 @@ public class DownloadAndUpdateRequest {
* the module
*/
public void addSoftwareModule(final SoftwareModule createSoftwareModule) {
if (softwareModules == null) {
softwareModules = new ArrayList<>();
}
softwareModules.add(createSoftwareModule);
}

View File

@@ -8,7 +8,7 @@
*/
package org.eclipse.hawkbit.dmf.json.model;
import java.util.LinkedList;
import java.util.Collections;
import java.util.List;
import com.fasterxml.jackson.annotation.JsonIgnore;
@@ -35,7 +35,7 @@ public class SoftwareModule {
@JsonProperty
private String moduleVersion;
@JsonProperty
private List<Artifact> artifacts = new LinkedList<>();
private List<Artifact> artifacts;
public String getModuleType() {
return moduleType;
@@ -54,7 +54,11 @@ public class SoftwareModule {
}
public List<Artifact> getArtifacts() {
return artifacts;
if (artifacts == null) {
return Collections.emptyList();
}
return Collections.unmodifiableList(artifacts);
}
public Long getModuleId() {

View File

@@ -8,6 +8,7 @@
*/
package org.eclipse.hawkbit.dmf.json.model;
import java.util.Collections;
import java.util.Map;
import java.util.TreeMap;
@@ -27,16 +28,47 @@ public class TenantSecurityToken {
public static final String AUTHORIZATION_HEADER = "Authorization";
@JsonProperty
private final String tenant;
@JsonProperty
@JsonProperty(required = false)
private String tenant;
@JsonProperty(required = false)
private final Long tenantId;
@JsonProperty(required = false)
private final String controllerId;
@JsonProperty(required = false)
private Map<String, String> headers = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
private final Long targetId;
@JsonProperty(required = false)
private Map<String, String> headers;
@JsonProperty(required = false)
private final FileResource fileResource;
/**
* Constructor.
*
* @param tenant
* the tenant for the security token
* @param tenantId
* alternative tenant identification by technical ID
* @param controllerId
* the ID of the controller for the security token
* @param targetId
* alternative target identification by technical ID
* @param fileResource
* the file to obtain
*/
@JsonCreator
public TenantSecurityToken(@JsonProperty("tenant") final String tenant,
@JsonProperty("tenantId") final Long tenantId, @JsonProperty("controllerId") final String controllerId,
@JsonProperty("targetId") final Long targetId,
@JsonProperty("fileResource") final FileResource fileResource) {
this.tenant = tenant;
this.tenantId = tenantId;
this.controllerId = controllerId;
this.targetId = targetId;
this.fileResource = fileResource;
}
/**
* Constructor.
*
@@ -47,13 +79,26 @@ public class TenantSecurityToken {
* @param fileResource
* the file to obtain
*/
@JsonCreator
public TenantSecurityToken(@JsonProperty("tenant") final String tenant,
@JsonProperty("controllerId") final String controllerId,
@JsonProperty("fileResource") final FileResource fileResource) {
public TenantSecurityToken(final String tenant, final String controllerId, final FileResource fileResource) {
this(tenant, null, controllerId, null, fileResource);
}
/**
* Constructor.
*
* @param tenantId
* the tenant for the security token
* @param targetId
* target identification by technical ID
* @param fileResource
* the file to obtain
*/
public TenantSecurityToken(final Long tenantId, final Long targetId, final FileResource fileResource) {
this(null, tenantId, null, targetId, fileResource);
}
public void setTenant(final String tenant) {
this.tenant = tenant;
this.controllerId = controllerId;
this.fileResource = fileResource;
}
public String getTenant() {
@@ -65,13 +110,25 @@ public class TenantSecurityToken {
}
public Map<String, String> getHeaders() {
return headers;
if (headers == null) {
return Collections.emptyMap();
}
return Collections.unmodifiableMap(headers);
}
public FileResource getFileResource() {
return fileResource;
}
public Long getTenantId() {
return tenantId;
}
public Long getTargetId() {
return targetId;
}
/**
* Gets a header value.
*
@@ -80,6 +137,10 @@ public class TenantSecurityToken {
* @return the value
*/
public String getHeader(final String name) {
if (headers == null) {
return null;
}
return headers.get(name);
}
@@ -88,6 +149,24 @@ public class TenantSecurityToken {
this.headers.putAll(headers);
}
/**
* Associates the specified header value with the specified name.
*
* @param name
* of the header
* @param value
* of the header
*
* @return the previous value associated with the <tt>name</tt>, or
* <tt>null</tt> if there was no mapping for <tt>name</tt>.
*/
public String putHeader(final String name, final String value) {
if (headers == null) {
headers = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
}
return headers.put(name, value);
}
/**
* File resource descriptor which is used to ask for the resource to
* download e.g. The lookup of the file can be different e.g. by SHA1 hash
@@ -99,6 +178,8 @@ public class TenantSecurityToken {
@JsonProperty(required = false)
private String sha1;
@JsonProperty(required = false)
private Long artifactId;
@JsonProperty(required = false)
private String filename;
@JsonProperty(required = false)
private SoftwareModuleFilenameResource softwareModuleFilenameResource;
@@ -128,6 +209,14 @@ public class TenantSecurityToken {
this.softwareModuleFilenameResource = softwareModuleFilenameResource;
}
public Long getArtifactId() {
return artifactId;
}
public void setArtifactId(final Long artifactId) {
this.artifactId = artifactId;
}
/**
* factory method to create a file resource for an SHA1 lookup.
*
@@ -141,6 +230,19 @@ public class TenantSecurityToken {
return resource;
}
/**
* factory method to create a file resource for an artifact ID lookup.
*
* @param artifactId
* the artifact IF key of the file to obtain
* @return the {@link FileResource} with SHA1 key set
*/
public static FileResource createFileResourceByArtifactId(final Long artifactId) {
final FileResource resource = new FileResource();
resource.artifactId = artifactId;
return resource;
}
/**
* factory method to create a file resource for an filename lookup.
*
@@ -173,7 +275,7 @@ public class TenantSecurityToken {
@Override
public String toString() {
return "FileResource [sha1=" + sha1 + ", filename=" + filename + "]";
return "FileResource [sha1=" + sha1 + ", artifactId=" + artifactId + ", filename=" + filename + "]";
}
/**