Refactor Management interfaces: find/get pattern (#2609)
Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com>
This commit is contained in:
@@ -53,7 +53,6 @@ import org.eclipse.hawkbit.repository.UpdateMode;
|
||||
import org.eclipse.hawkbit.repository.artifact.model.DbArtifact;
|
||||
import org.eclipse.hawkbit.repository.artifact.urlhandler.ArtifactUrlHandler;
|
||||
import org.eclipse.hawkbit.repository.event.remote.DownloadProgressEvent;
|
||||
import org.eclipse.hawkbit.repository.exception.ArtifactBinaryNotFoundException;
|
||||
import org.eclipse.hawkbit.repository.exception.CancelActionNotAllowedException;
|
||||
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
|
||||
import org.eclipse.hawkbit.repository.exception.InvalidConfirmationFeedbackException;
|
||||
@@ -180,9 +179,7 @@ public class DdiRootController implements DdiRootControllerRestApi {
|
||||
} else {
|
||||
// Artifact presence is ensured in 'checkModule'
|
||||
final Artifact artifact = module.getArtifactByFilename(fileName).orElseThrow(NoSuchElementException::new);
|
||||
final DbArtifact file = artifactManagement
|
||||
.loadArtifactBinary(artifact.getSha1Hash(), module.getId(), module.isEncrypted())
|
||||
.orElseThrow(() -> new ArtifactBinaryNotFoundException(artifact.getSha1Hash()));
|
||||
final DbArtifact file = artifactManagement.loadArtifactBinary(artifact.getSha1Hash(), module.getId(), module.isEncrypted());
|
||||
|
||||
final String ifMatch = RequestResponseContextHolder.getHttpServletRequest().getHeader(HttpHeaders.IF_MATCH);
|
||||
if (ifMatch != null && !HttpUtil.matchesHttpHeader(ifMatch, artifact.getSha1Hash())) {
|
||||
@@ -694,7 +691,7 @@ public class DdiRootController implements DdiRootControllerRestApi {
|
||||
}
|
||||
|
||||
private Target findTarget(final String controllerId) {
|
||||
return controllerManagement.getByControllerId(controllerId)
|
||||
return controllerManagement.findByControllerId(controllerId)
|
||||
.orElseThrow(() -> new EntityNotFoundException(Target.class, controllerId));
|
||||
}
|
||||
|
||||
|
||||
@@ -60,8 +60,8 @@ public class SecurityTokenAuthenticator extends Authenticator.AbstractAuthentica
|
||||
final String presentedToken = authHeader.substring(OFFSET_TARGET_TOKEN);
|
||||
|
||||
return systemSecurityContext.runAsSystemAsTenant(() -> controllerSecurityToken.getTargetId() != null
|
||||
? controllerManagement.get(controllerSecurityToken.getTargetId())
|
||||
: controllerManagement.getByControllerId(controllerSecurityToken.getControllerId()),
|
||||
? controllerManagement.find(controllerSecurityToken.getTargetId())
|
||||
: controllerManagement.findByControllerId(controllerSecurityToken.getControllerId()),
|
||||
controllerSecurityToken.getTenant())
|
||||
// validate if the presented token is the same as the one set for the target
|
||||
.filter(target -> presentedToken.equals(
|
||||
|
||||
@@ -78,7 +78,7 @@ class SecurityTokenAuthenticatorTest {
|
||||
final Target target = Mockito.mock(Target.class);
|
||||
when(target.getControllerId()).thenReturn(CONTROLLER_ID);
|
||||
when(target.getSecurityToken()).thenReturn(SECURITY_TOKEN);
|
||||
when(controllerManagementMock.getByControllerId(CONTROLLER_ID)).thenReturn(Optional.of(target));
|
||||
when(controllerManagementMock.findByControllerId(CONTROLLER_ID)).thenReturn(Optional.of(target));
|
||||
|
||||
assertThat(authenticator.authenticate(securityToken))
|
||||
.isNotNull()
|
||||
|
||||
Reference in New Issue
Block a user