Artefact last modified is returned my DMF auth call (#600)
* Last modified is stored as part of artifact and returns accordingly by APIs. Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com> * Fixed tests. Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com> * Check value > 0 Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com> * Use created at. Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com> * Sonar issue fixed. Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>
This commit is contained in:
@@ -23,8 +23,6 @@ import org.eclipse.hawkbit.repository.model.SoftwareModule;
|
||||
import org.eclipse.hawkbit.rest.util.FileStreamingUtil;
|
||||
import org.eclipse.hawkbit.rest.util.HttpUtil;
|
||||
import org.eclipse.hawkbit.rest.util.RequestResponseContextHolder;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
@@ -76,8 +74,7 @@ public class MgmtDownloadArtifactResource implements MgmtDownloadArtifactRestApi
|
||||
return new ResponseEntity<>(HttpStatus.PRECONDITION_FAILED);
|
||||
}
|
||||
|
||||
return FileStreamingUtil.writeFileResponse(file, artifact.getFilename(),
|
||||
artifact.getLastModifiedAt() != null ? artifact.getLastModifiedAt() : artifact.getCreatedAt(),
|
||||
return FileStreamingUtil.writeFileResponse(file, artifact.getFilename(), artifact.getCreatedAt(),
|
||||
requestResponseContextHolder.getHttpServletResponse(), request, null);
|
||||
}
|
||||
|
||||
|
||||
@@ -72,7 +72,7 @@ public class MgmtDownloadResource implements MgmtDownloadRestApi {
|
||||
return ResponseEntity.notFound().build();
|
||||
}
|
||||
|
||||
return FileStreamingUtil.writeFileResponse(artifact, downloadId, null,
|
||||
return FileStreamingUtil.writeFileResponse(artifact, downloadId, 0L,
|
||||
requestResponseContextHolder.getHttpServletResponse(),
|
||||
requestResponseContextHolder.getHttpServletRequest(), null);
|
||||
|
||||
|
||||
@@ -30,10 +30,10 @@ final class MgmtRestModelMapper {
|
||||
static void mapBaseToBase(final MgmtBaseEntity response, final TenantAwareBaseEntity base) {
|
||||
response.setCreatedBy(base.getCreatedBy());
|
||||
response.setLastModifiedBy(base.getLastModifiedBy());
|
||||
if (base.getCreatedAt() != null) {
|
||||
if (base.getCreatedAt() > 0) {
|
||||
response.setCreatedAt(base.getCreatedAt());
|
||||
}
|
||||
if (base.getLastModifiedAt() != null) {
|
||||
if (base.getLastModifiedAt() > 0) {
|
||||
response.setLastModifiedAt(base.getLastModifiedAt());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,9 +34,9 @@ public class MgmtDownloadResourceTest extends AbstractManagementApiIntegrationTe
|
||||
@Autowired
|
||||
private DownloadIdCache downloadIdCache;
|
||||
|
||||
private final String downloadIdSha1 = "downloadIdSha1";
|
||||
private static final String DOWNLOAD_ID_SHA1 = "downloadIdSha1";
|
||||
|
||||
private final String downloadIdNotAvailable = "downloadIdNotAvailable";
|
||||
private static final String DOWNLOAD_ID_NOT_AVAILABLE = "downloadIdNotAvailable";
|
||||
|
||||
@Before
|
||||
public void setupCache() {
|
||||
@@ -45,7 +45,7 @@ public class MgmtDownloadResourceTest extends AbstractManagementApiIntegrationTe
|
||||
final SoftwareModule softwareModule = distributionSet.getModules().stream().findAny().get();
|
||||
final Artifact artifact = testdataFactory.createArtifacts(softwareModule.getId()).stream().findAny().get();
|
||||
|
||||
downloadIdCache.put(downloadIdSha1, new DownloadArtifactCache(DownloadType.BY_SHA1, artifact.getSha1Hash()));
|
||||
downloadIdCache.put(DOWNLOAD_ID_SHA1, new DownloadArtifactCache(DownloadType.BY_SHA1, artifact.getSha1Hash()));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -54,7 +54,7 @@ public class MgmtDownloadResourceTest extends AbstractManagementApiIntegrationTe
|
||||
mvc.perform(get(
|
||||
MgmtRestConstants.DOWNLOAD_ID_V1_REQUEST_MAPPING_BASE
|
||||
+ MgmtRestConstants.DOWNLOAD_ID_V1_REQUEST_MAPPING,
|
||||
tenantAware.getCurrentTenant(), downloadIdNotAvailable)).andDo(MockMvcResultPrinter.print())
|
||||
tenantAware.getCurrentTenant(), DOWNLOAD_ID_NOT_AVAILABLE)).andDo(MockMvcResultPrinter.print())
|
||||
.andExpect(status().isNotFound());
|
||||
|
||||
}
|
||||
@@ -65,14 +65,14 @@ public class MgmtDownloadResourceTest extends AbstractManagementApiIntegrationTe
|
||||
mvc.perform(get(
|
||||
MgmtRestConstants.DOWNLOAD_ID_V1_REQUEST_MAPPING_BASE
|
||||
+ MgmtRestConstants.DOWNLOAD_ID_V1_REQUEST_MAPPING,
|
||||
tenantAware.getCurrentTenant(), downloadIdSha1)).andDo(MockMvcResultPrinter.print())
|
||||
tenantAware.getCurrentTenant(), DOWNLOAD_ID_SHA1)).andDo(MockMvcResultPrinter.print())
|
||||
.andExpect(status().isOk());
|
||||
|
||||
// because cache is empty
|
||||
mvc.perform(get(
|
||||
MgmtRestConstants.DOWNLOAD_ID_V1_REQUEST_MAPPING_BASE
|
||||
+ MgmtRestConstants.DOWNLOAD_ID_V1_REQUEST_MAPPING,
|
||||
tenantAware.getCurrentTenant(), downloadIdSha1)).andDo(MockMvcResultPrinter.print())
|
||||
tenantAware.getCurrentTenant(), DOWNLOAD_ID_SHA1)).andDo(MockMvcResultPrinter.print())
|
||||
.andExpect(status().isNotFound());
|
||||
|
||||
}
|
||||
|
||||
@@ -129,7 +129,7 @@ public class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest
|
||||
.andExpect(jsonPath("content.[0].id", equalTo(status.getId().intValue())))
|
||||
.andExpect(jsonPath("content.[0].type", equalTo("finished")))
|
||||
.andExpect(jsonPath("content.[0].messages", hasSize(1)))
|
||||
.andExpect(jsonPath("content.[0].reportedAt", equalTo(status.getCreatedAt().longValue())))
|
||||
.andExpect(jsonPath("content.[0].reportedAt", equalTo(status.getCreatedAt())))
|
||||
.andExpect(jsonPath("content.[1].type", equalTo("canceling")));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user