Removed external artifact from repository.

Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>
This commit is contained in:
kaizimmerm
2016-10-20 12:03:17 +02:00
parent ec874232d3
commit 0332d31146
59 changed files with 531 additions and 1312 deletions

View File

@@ -32,7 +32,7 @@ import org.eclipse.hawkbit.ddi.json.model.DdiPolling;
import org.eclipse.hawkbit.ddi.rest.api.DdiRestConstants;
import org.eclipse.hawkbit.repository.SystemManagement;
import org.eclipse.hawkbit.repository.model.Action;
import org.eclipse.hawkbit.repository.model.LocalArtifact;
import org.eclipse.hawkbit.repository.model.Artifact;
import org.eclipse.hawkbit.repository.model.Target;
import org.eclipse.hawkbit.tenancy.TenantAware;
import org.springframework.hateoas.Link;
@@ -85,13 +85,13 @@ public final class DataConversionHelper {
final org.eclipse.hawkbit.repository.model.SoftwareModule module,
final ArtifactUrlHandler artifactUrlHandler, final SystemManagement systemManagement) {
return module.getLocalArtifacts().stream()
return module.getArtifacts().stream()
.map(artifact -> createArtifact(target, artifactUrlHandler, artifact, systemManagement))
.collect(Collectors.toList());
}
private static DdiArtifact createArtifact(final Target target, final ArtifactUrlHandler artifactUrlHandler,
final LocalArtifact artifact, final SystemManagement systemManagement) {
final Artifact artifact, final SystemManagement systemManagement) {
final DdiArtifact file = new DdiArtifact();
file.setHashes(new DdiArtifactHash(artifact.getSha1Hash(), artifact.getMd5Hash()));
file.setFilename(artifact.getFilename());
@@ -157,8 +157,8 @@ public final class DataConversionHelper {
return result;
}
static void writeMD5FileResponse(final String fileName, final HttpServletResponse response,
final LocalArtifact artifact) throws IOException {
static void writeMD5FileResponse(final String fileName, final HttpServletResponse response, final Artifact artifact)
throws IOException {
final StringBuilder builder = new StringBuilder();
builder.append(artifact.getMd5Hash());
builder.append(" ");

View File

@@ -23,7 +23,7 @@ import org.eclipse.hawkbit.repository.RepositoryConstants;
import org.eclipse.hawkbit.repository.model.Action;
import org.eclipse.hawkbit.repository.model.Action.Status;
import org.eclipse.hawkbit.repository.model.ActionStatus;
import org.eclipse.hawkbit.repository.model.LocalArtifact;
import org.eclipse.hawkbit.repository.model.Artifact;
import org.eclipse.hawkbit.repository.model.Target;
import org.eclipse.hawkbit.rest.util.RequestResponseContextHolder;
import org.eclipse.hawkbit.rest.util.RestResourceConversionHelper;
@@ -71,7 +71,7 @@ public class DdiArtifactStoreController implements DdiDlArtifactStoreControllerR
@Override
public ResponseEntity<InputStream> downloadArtifactByFilename(@PathVariable("tenant") final String tenant,
@PathVariable("fileName") final String fileName, @AuthenticationPrincipal final String targetid) {
final List<LocalArtifact> foundArtifacts = artifactManagement.findLocalArtifactByFilename(fileName);
final List<Artifact> foundArtifacts = artifactManagement.findArtifactByFilename(fileName);
if (foundArtifacts.isEmpty()) {
LOG.warn("Software artifact with name {} could not be found.", fileName);
@@ -82,13 +82,13 @@ public class DdiArtifactStoreController implements DdiDlArtifactStoreControllerR
LOG.warn("Software artifact name {} is not unique. We will use the first entry.", fileName);
}
ResponseEntity<InputStream> result;
final LocalArtifact artifact = foundArtifacts.get(0);
final Artifact artifact = foundArtifacts.get(0);
final String ifMatch = requestResponseContextHolder.getHttpServletRequest().getHeader("If-Match");
if (ifMatch != null && !RestResourceConversionHelper.matchesHttpHeader(ifMatch, artifact.getSha1Hash())) {
result = new ResponseEntity<>(HttpStatus.PRECONDITION_FAILED);
} else {
final DbArtifact file = artifactManagement.loadLocalArtifactBinary(artifact);
final DbArtifact file = artifactManagement.loadArtifactBinary(artifact);
// we set a download status only if we are aware of the
// targetid, i.e. authenticated and not anonymous
@@ -112,7 +112,7 @@ public class DdiArtifactStoreController implements DdiDlArtifactStoreControllerR
@Override
public ResponseEntity<Void> downloadArtifactMD5ByFilename(@PathVariable("tenant") final String tenant,
@PathVariable("fileName") final String fileName) {
final List<LocalArtifact> foundArtifacts = artifactManagement.findLocalArtifactByFilename(fileName);
final List<Artifact> foundArtifacts = artifactManagement.findArtifactByFilename(fileName);
if (foundArtifacts.isEmpty()) {
LOG.warn("Softeare artifact with name {} could not be found.", fileName);
@@ -133,7 +133,7 @@ public class DdiArtifactStoreController implements DdiDlArtifactStoreControllerR
}
private ActionStatus checkAndReportDownloadByTarget(final HttpServletRequest request, final String targetid,
final LocalArtifact artifact) {
final Artifact artifact) {
final Target target = controllerManagement.updateLastTargetQuery(targetid,
IpUtil.getClientIpFromRequest(request, securityProperties));

View File

@@ -38,7 +38,7 @@ import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
import org.eclipse.hawkbit.repository.model.Action;
import org.eclipse.hawkbit.repository.model.Action.Status;
import org.eclipse.hawkbit.repository.model.ActionStatus;
import org.eclipse.hawkbit.repository.model.LocalArtifact;
import org.eclipse.hawkbit.repository.model.Artifact;
import org.eclipse.hawkbit.repository.model.SoftwareModule;
import org.eclipse.hawkbit.repository.model.Target;
import org.eclipse.hawkbit.rest.util.RequestResponseContextHolder;
@@ -154,9 +154,9 @@ public class DdiRootController implements DdiRootControllerRestApi {
// Exception squid:S3655 - Optional access is checked in checkModule
// subroutine
@SuppressWarnings("squid:S3655")
final LocalArtifact artifact = module.getLocalArtifactByFilename(fileName).get();
final Artifact artifact = module.getArtifactByFilename(fileName).get();
final DbArtifact file = artifactManagement.loadLocalArtifactBinary(artifact);
final DbArtifact file = artifactManagement.loadArtifactBinary(artifact);
final String ifMatch = requestResponseContextHolder.getHttpServletRequest().getHeader("If-Match");
if (ifMatch != null && !RestResourceConversionHelper.matchesHttpHeader(ifMatch, artifact.getSha1Hash())) {
@@ -196,7 +196,7 @@ public class DdiRootController implements DdiRootControllerRestApi {
}
private static boolean checkModule(final String fileName, final SoftwareModule module) {
return null == module || !module.getLocalArtifactByFilename(fileName).isPresent();
return null == module || !module.getArtifactByFilename(fileName).isPresent();
}
@Override
@@ -219,7 +219,7 @@ public class DdiRootController implements DdiRootControllerRestApi {
try {
DataConversionHelper.writeMD5FileResponse(fileName, requestResponseContextHolder.getHttpServletResponse(),
module.getLocalArtifactByFilename(fileName).get());
module.getArtifactByFilename(fileName).get());
} catch (final IOException e) {
LOG.error("Failed to stream MD5 File", e);
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);

View File

@@ -35,7 +35,6 @@ import org.eclipse.hawkbit.repository.model.Action;
import org.eclipse.hawkbit.repository.model.Action.Status;
import org.eclipse.hawkbit.repository.model.Artifact;
import org.eclipse.hawkbit.repository.model.DistributionSet;
import org.eclipse.hawkbit.repository.model.LocalArtifact;
import org.eclipse.hawkbit.repository.model.Target;
import org.eclipse.hawkbit.repository.test.util.WithUser;
import org.eclipse.hawkbit.rest.AbstractRestIntegrationTestWithMongoDB;
@@ -99,7 +98,7 @@ public class DdiArtifactDownloadTest extends AbstractRestIntegrationTestWithMong
// create artifact
final byte random[] = RandomUtils.nextBytes(5 * 1024);
final LocalArtifact artifact = artifactManagement.createLocalArtifact(new ByteArrayInputStream(random),
final Artifact artifact = artifactManagement.createArtifact(new ByteArrayInputStream(random),
ds.findFirstModuleByType(osType).getId(), "file1", false);
// no artifact available
@@ -193,7 +192,7 @@ public class DdiArtifactDownloadTest extends AbstractRestIntegrationTestWithMong
.andExpect(status().isNotFound());
// test now consistent data to test allowed methods
final Artifact artifact = artifactManagement.createLocalArtifact(new ByteArrayInputStream(random),
final Artifact artifact = artifactManagement.createArtifact(new ByteArrayInputStream(random),
ds.findFirstModuleByType(osType).getId(), "file1", false);
mvc.perform(
@@ -268,7 +267,7 @@ public class DdiArtifactDownloadTest extends AbstractRestIntegrationTestWithMong
// create artifact
final byte random[] = RandomUtils.nextBytes(ARTIFACT_SIZE);
final LocalArtifact artifact = artifactManagement.createLocalArtifact(new ByteArrayInputStream(random),
final Artifact artifact = artifactManagement.createArtifact(new ByteArrayInputStream(random),
ds.findFirstModuleByType(osType).getId(), "file1", false);
// download fails as artifact is not yet assigned
@@ -309,7 +308,7 @@ public class DdiArtifactDownloadTest extends AbstractRestIntegrationTestWithMong
// create artifact
final byte random[] = RandomUtils.nextBytes(5 * 1024);
final LocalArtifact artifact = artifactManagement.createLocalArtifact(new ByteArrayInputStream(random),
final Artifact artifact = artifactManagement.createArtifact(new ByteArrayInputStream(random),
ds.findFirstModuleByType(osType).getId(), "file1", false);
// download
@@ -349,8 +348,8 @@ public class DdiArtifactDownloadTest extends AbstractRestIntegrationTestWithMong
// create artifact
final byte random[] = RandomUtils.nextBytes(ARTIFACT_SIZE);
artifactManagement.createLocalArtifact(new ByteArrayInputStream(random),
ds.findFirstModuleByType(osType).getId(), "file1.tar.bz2", false);
artifactManagement.createArtifact(new ByteArrayInputStream(random), ds.findFirstModuleByType(osType).getId(),
"file1.tar.bz2", false);
// download fails as artifact is not yet assigned to target
deploymentManagement.assignDistributionSet(ds, targets);
@@ -383,7 +382,7 @@ public class DdiArtifactDownloadTest extends AbstractRestIntegrationTestWithMong
// create artifact
final byte random[] = RandomUtils.nextBytes(ARTIFACT_SIZE);
final Artifact artifact = artifactManagement.createLocalArtifact(new ByteArrayInputStream(random),
final Artifact artifact = artifactManagement.createArtifact(new ByteArrayInputStream(random),
ds.findFirstModuleByType(osType).getId(), "file1", false);
// download fails as artifact is not yet assigned to target
@@ -435,7 +434,7 @@ public class DdiArtifactDownloadTest extends AbstractRestIntegrationTestWithMong
// create artifact
final byte random[] = RandomUtils.nextBytes(resultLength);
final Artifact artifact = artifactManagement.createLocalArtifact(new ByteArrayInputStream(random),
final Artifact artifact = artifactManagement.createArtifact(new ByteArrayInputStream(random),
ds.findFirstModuleByType(osType).getId(), "file1", false);
assertThat(random.length).isEqualTo(resultLength);
@@ -539,7 +538,7 @@ public class DdiArtifactDownloadTest extends AbstractRestIntegrationTestWithMong
// create artifact
final byte random[] = RandomUtils.nextBytes(5 * 1024);
final Artifact artifact = artifactManagement.createLocalArtifact(new ByteArrayInputStream(random),
final Artifact artifact = artifactManagement.createArtifact(new ByteArrayInputStream(random),
ds.findFirstModuleByType(osType).getId(), "file1.tar.bz2", false);
// download fails as artifact is not yet assigned to target
@@ -559,7 +558,7 @@ public class DdiArtifactDownloadTest extends AbstractRestIntegrationTestWithMong
// create artifact
final byte random[] = RandomUtils.nextBytes(5 * 1024);
final Artifact artifact = artifactManagement.createLocalArtifact(new ByteArrayInputStream(random),
final Artifact artifact = artifactManagement.createArtifact(new ByteArrayInputStream(random),
ds.findFirstModuleByType(osType).getId(), "file1.tar.bz2", false);
// download

View File

@@ -32,8 +32,8 @@ import org.eclipse.hawkbit.repository.model.Action;
import org.eclipse.hawkbit.repository.model.Action.ActionType;
import org.eclipse.hawkbit.repository.model.Action.Status;
import org.eclipse.hawkbit.repository.model.ActionStatus;
import org.eclipse.hawkbit.repository.model.Artifact;
import org.eclipse.hawkbit.repository.model.DistributionSet;
import org.eclipse.hawkbit.repository.model.LocalArtifact;
import org.eclipse.hawkbit.repository.model.RepositoryModelConstants;
import org.eclipse.hawkbit.repository.model.Target;
import org.eclipse.hawkbit.repository.model.TargetUpdateStatus;
@@ -87,7 +87,7 @@ public class DdiDeploymentBaseTest extends AbstractRestIntegrationTestWithMongoD
tenantAware.getCurrentTenant(), target.getName(), softwareModuleId)).andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk()).andExpect(jsonPath("$", hasSize(0)));
testdataFactory.createLocalArtifacts(softwareModuleId);
testdataFactory.createArtifacts(softwareModuleId);
mvc.perform(get("/{tenant}/controller/v1/{targetNotExist}/softwaremodules/{softwareModuleId}/artifacts",
tenantAware.getCurrentTenant(), target.getName(), softwareModuleId)).andDo(MockMvcResultPrinter.print())
@@ -107,9 +107,9 @@ public class DdiDeploymentBaseTest extends AbstractRestIntegrationTestWithMongoD
final DistributionSet ds2 = testdataFactory.createDistributionSet("2", true);
final byte random[] = RandomUtils.nextBytes(5 * 1024);
final LocalArtifact artifact = artifactManagement.createLocalArtifact(new ByteArrayInputStream(random),
final Artifact artifact = artifactManagement.createArtifact(new ByteArrayInputStream(random),
ds.findFirstModuleByType(osType).getId(), "test1", false);
final LocalArtifact artifactSignature = artifactManagement.createLocalArtifact(new ByteArrayInputStream(random),
final Artifact artifactSignature = artifactManagement.createArtifact(new ByteArrayInputStream(random),
ds.findFirstModuleByType(osType).getId(), "test1.signature", false);
final Target savedTarget = targetManagement.createTarget(target);
@@ -270,9 +270,9 @@ public class DdiDeploymentBaseTest extends AbstractRestIntegrationTestWithMongoD
final DistributionSet ds2 = testdataFactory.createDistributionSet("2", true);
final byte random[] = RandomUtils.nextBytes(5 * 1024);
final LocalArtifact artifact = artifactManagement.createLocalArtifact(new ByteArrayInputStream(random),
final Artifact artifact = artifactManagement.createArtifact(new ByteArrayInputStream(random),
ds.findFirstModuleByType(osType).getId(), "test1", false);
final LocalArtifact artifactSignature = artifactManagement.createLocalArtifact(new ByteArrayInputStream(random),
final Artifact artifactSignature = artifactManagement.createArtifact(new ByteArrayInputStream(random),
ds.findFirstModuleByType(osType).getId(), "test1.signature", false);
final Target savedTarget = targetManagement.createTarget(target);
@@ -394,9 +394,9 @@ public class DdiDeploymentBaseTest extends AbstractRestIntegrationTestWithMongoD
final DistributionSet ds2 = testdataFactory.createDistributionSet("2", true);
final byte random[] = RandomUtils.nextBytes(5 * 1024);
final LocalArtifact artifact = artifactManagement.createLocalArtifact(new ByteArrayInputStream(random),
final Artifact artifact = artifactManagement.createArtifact(new ByteArrayInputStream(random),
ds.findFirstModuleByType(osType).getId(), "test1", false);
final LocalArtifact artifactSignature = artifactManagement.createLocalArtifact(new ByteArrayInputStream(random),
final Artifact artifactSignature = artifactManagement.createArtifact(new ByteArrayInputStream(random),
ds.findFirstModuleByType(osType).getId(), "test1.signature", false);
final Target savedTarget = targetManagement.createTarget(target);

View File

@@ -24,7 +24,6 @@ import org.eclipse.hawkbit.dmf.json.model.TenantSecurityToken.FileResource;
import org.eclipse.hawkbit.repository.ArtifactManagement;
import org.eclipse.hawkbit.repository.ControllerManagement;
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
import org.eclipse.hawkbit.repository.model.LocalArtifact;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.AmqpRejectAndDontRequeueException;
@@ -122,7 +121,7 @@ public class AmqpAuthenticationMessageHandler extends BaseAmqpService {
* download this artifact
*/
private void checkIfArtifactIsAssignedToTarget(final TenantSecurityToken secruityToken,
final LocalArtifact localArtifact) {
final org.eclipse.hawkbit.repository.model.Artifact localArtifact) {
if (secruityToken.getControllerId() != null) {
checkByControllerId(localArtifact, secruityToken.getControllerId());
@@ -135,7 +134,8 @@ public class AmqpAuthenticationMessageHandler extends BaseAmqpService {
}
private void checkByTargetId(final LocalArtifact localArtifact, final Long targetId) {
private void checkByTargetId(final org.eclipse.hawkbit.repository.model.Artifact localArtifact,
final Long targetId) {
LOG.debug("no anonymous download request, doing authentication check for target {} and artifact {}", targetId,
localArtifact);
if (!controllerManagement.hasTargetArtifactAssigned(targetId, localArtifact)) {
@@ -146,7 +146,8 @@ public class AmqpAuthenticationMessageHandler extends BaseAmqpService {
LOG.info("download security check for target {} and artifact {} granted", targetId, localArtifact);
}
private void checkByControllerId(final LocalArtifact localArtifact, final String controllerId) {
private void checkByControllerId(final org.eclipse.hawkbit.repository.model.Artifact localArtifact,
final String controllerId) {
LOG.debug("no anonymous download request, doing authentication check for target {} and artifact {}",
controllerId, localArtifact);
if (!controllerManagement.hasTargetArtifactAssigned(controllerId, localArtifact)) {
@@ -157,14 +158,14 @@ public class AmqpAuthenticationMessageHandler extends BaseAmqpService {
LOG.info("download security check for target {} and artifact {} granted", controllerId, localArtifact);
}
private LocalArtifact findLocalArtifactByFileResource(final FileResource fileResource) {
private org.eclipse.hawkbit.repository.model.Artifact findArtifactByFileResource(final FileResource fileResource) {
if (fileResource.getSha1() != null) {
return artifactManagement.findFirstLocalArtifactsBySHA1(fileResource.getSha1());
return artifactManagement.findFirstArtifactBySHA1(fileResource.getSha1());
} else if (fileResource.getFilename() != null) {
return artifactManagement.findLocalArtifactByFilename(fileResource.getFilename()).stream().findFirst()
return artifactManagement.findArtifactByFilename(fileResource.getFilename()).stream().findFirst()
.orElse(null);
} else if (fileResource.getArtifactId() != null) {
return artifactManagement.findLocalArtifact(fileResource.getArtifactId());
return artifactManagement.findArtifact(fileResource.getArtifactId());
} else if (fileResource.getSoftwareModuleFilenameResource() != null) {
return artifactManagement
.findByFilenameAndSoftwareModule(fileResource.getSoftwareModuleFilenameResource().getFilename(),
@@ -191,7 +192,8 @@ public class AmqpAuthenticationMessageHandler extends BaseAmqpService {
try {
SecurityContextHolder.getContext().setAuthentication(authenticationManager.doAuthenticate(secruityToken));
final LocalArtifact localArtifact = findLocalArtifactByFileResource(fileResource);
final org.eclipse.hawkbit.repository.model.Artifact localArtifact = findArtifactByFileResource(
fileResource);
if (localArtifact == null) {
LOG.info("target {} requested file resource {} which does not exists to download",
@@ -201,7 +203,7 @@ public class AmqpAuthenticationMessageHandler extends BaseAmqpService {
checkIfArtifactIsAssignedToTarget(secruityToken, localArtifact);
final Artifact artifact = convertDbArtifact(artifactManagement.loadLocalArtifactBinary(localArtifact));
final Artifact artifact = convertDbArtifact(artifactManagement.loadArtifactBinary(localArtifact));
if (artifact == null) {
throw new EntityNotFoundException();
}

View File

@@ -29,7 +29,6 @@ import org.eclipse.hawkbit.eventbus.EventSubscriber;
import org.eclipse.hawkbit.repository.SystemManagement;
import org.eclipse.hawkbit.repository.eventbus.event.CancelTargetAssignmentEvent;
import org.eclipse.hawkbit.repository.eventbus.event.TargetAssignDistributionSetEvent;
import org.eclipse.hawkbit.repository.model.LocalArtifact;
import org.eclipse.hawkbit.repository.model.Target;
import org.eclipse.hawkbit.security.SystemSecurityContext;
import org.eclipse.hawkbit.util.IpUtil;
@@ -159,12 +158,13 @@ public class AmqpMessageDispatcherService extends BaseAmqpService {
amqpSoftwareModule.setModuleType(softwareModule.getType().getKey());
amqpSoftwareModule.setModuleVersion(softwareModule.getVersion());
final List<Artifact> artifacts = convertArtifacts(target, softwareModule.getLocalArtifacts());
final List<Artifact> artifacts = convertArtifacts(target, softwareModule.getArtifacts());
amqpSoftwareModule.setArtifacts(artifacts);
return amqpSoftwareModule;
}
private List<Artifact> convertArtifacts(final Target target, final List<LocalArtifact> localArtifacts) {
private List<Artifact> convertArtifacts(final Target target,
final List<org.eclipse.hawkbit.repository.model.Artifact> localArtifacts) {
if (localArtifacts.isEmpty()) {
return Collections.emptyList();
}
@@ -173,7 +173,8 @@ public class AmqpMessageDispatcherService extends BaseAmqpService {
.collect(Collectors.toList());
}
private Artifact convertArtifact(final Target target, final LocalArtifact localArtifact) {
private Artifact convertArtifact(final Target target,
final org.eclipse.hawkbit.repository.model.Artifact localArtifact) {
final Artifact artifact = new Artifact();
artifact.setUrls(artifactUrlHandler

View File

@@ -31,10 +31,10 @@ import org.eclipse.hawkbit.repository.ControllerManagement;
import org.eclipse.hawkbit.repository.SystemManagement;
import org.eclipse.hawkbit.repository.TenantConfigurationManagement;
import org.eclipse.hawkbit.repository.jpa.JpaEntityFactory;
import org.eclipse.hawkbit.repository.jpa.model.JpaLocalArtifact;
import org.eclipse.hawkbit.repository.jpa.model.JpaArtifact;
import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule;
import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModuleType;
import org.eclipse.hawkbit.repository.model.LocalArtifact;
import org.eclipse.hawkbit.repository.model.Artifact;
import org.eclipse.hawkbit.repository.model.Target;
import org.eclipse.hawkbit.repository.model.TenantConfigurationValue;
import org.eclipse.hawkbit.repository.model.TenantMetaData;
@@ -154,16 +154,16 @@ public class AmqpControllerAuthenticationTest {
authenticationManager.postConstruct();
final LocalArtifact testArtifact = new JpaLocalArtifact("afilename", "afilename", new JpaSoftwareModule(
final Artifact testArtifact = new JpaArtifact("afilename", "afilename", new JpaSoftwareModule(
new JpaSoftwareModuleType("a key", "a name", null, 1), "a name", null, null, null));
when(artifactManagementMock.findLocalArtifact(ARTIFACT_ID)).thenReturn(testArtifact);
when(artifactManagementMock.findFirstLocalArtifactsBySHA1(SHA1)).thenReturn(testArtifact);
when(artifactManagementMock.findArtifact(ARTIFACT_ID)).thenReturn(testArtifact);
when(artifactManagementMock.findFirstArtifactBySHA1(SHA1)).thenReturn(testArtifact);
final DbArtifact artifact = new DbArtifact();
artifact.setSize(ARTIFACT_SIZE);
artifact.setHashes(new DbArtifactHash("sha1 test", "md5 test"));
when(artifactManagementMock.loadLocalArtifactBinary(testArtifact)).thenReturn(artifact);
when(artifactManagementMock.loadArtifactBinary(testArtifact)).thenReturn(artifact);
amqpMessageHandlerService = new AmqpMessageHandlerService(rabbitTemplate,
mock(AmqpMessageDispatcherService.class), controllerManagementMock, new JpaEntityFactory());

View File

@@ -34,7 +34,6 @@ import org.eclipse.hawkbit.repository.eventbus.event.CancelTargetAssignmentEvent
import org.eclipse.hawkbit.repository.eventbus.event.TargetAssignDistributionSetEvent;
import org.eclipse.hawkbit.repository.model.Artifact;
import org.eclipse.hawkbit.repository.model.DistributionSet;
import org.eclipse.hawkbit.repository.model.LocalArtifact;
import org.eclipse.hawkbit.repository.model.SoftwareModule;
import org.eclipse.hawkbit.repository.model.Target;
import org.eclipse.hawkbit.repository.model.TenantMetaData;
@@ -160,8 +159,8 @@ public class AmqpMessageDispatcherServiceTest extends AbstractIntegrationTest {
final DistributionSet dsA = testdataFactory.createDistributionSet("");
final SoftwareModule module = dsA.getModules().iterator().next();
final List<DbArtifact> receivedList = new ArrayList<>();
for (final Artifact artifact : testdataFactory.createLocalArtifacts(module.getId())) {
module.addArtifact((LocalArtifact) artifact);
for (final Artifact artifact : testdataFactory.createArtifacts(module.getId())) {
module.addArtifact(artifact);
receivedList.add(new DbArtifact());
}
@@ -186,8 +185,7 @@ public class AmqpMessageDispatcherServiceTest extends AbstractIntegrationTest {
module.getArtifacts().forEach(dbArtifact -> {
final Optional<org.eclipse.hawkbit.dmf.json.model.Artifact> found = softwareModule.getArtifacts()
.stream().filter(dmfartifact -> dmfartifact.getFilename()
.equals(((LocalArtifact) dbArtifact).getFilename()))
.stream().filter(dmfartifact -> dmfartifact.getFilename().equals(dbArtifact.getFilename()))
.findFirst();
assertTrue("The artifact should exist in message", found.isPresent());

View File

@@ -49,7 +49,7 @@ import org.eclipse.hawkbit.repository.jpa.model.JpaTarget;
import org.eclipse.hawkbit.repository.jpa.model.helper.SecurityTokenGeneratorHolder;
import org.eclipse.hawkbit.repository.model.Action;
import org.eclipse.hawkbit.repository.model.Action.Status;
import org.eclipse.hawkbit.repository.model.LocalArtifact;
import org.eclipse.hawkbit.repository.model.Artifact;
import org.eclipse.hawkbit.repository.model.SoftwareModule;
import org.eclipse.hawkbit.repository.model.TargetInfo;
import org.eclipse.hawkbit.repository.model.TargetUpdateStatus;
@@ -300,8 +300,8 @@ public class AmqpMessageHandlerServiceTest {
final Message message = amqpMessageHandlerService.getMessageConverter().toMessage(securityToken,
messageProperties);
final LocalArtifact localArtifactMock = mock(LocalArtifact.class);
when(artifactManagementMock.findFirstLocalArtifactsBySHA1(anyString())).thenReturn(localArtifactMock);
final Artifact localArtifactMock = mock(Artifact.class);
when(artifactManagementMock.findFirstArtifactBySHA1(anyString())).thenReturn(localArtifactMock);
when(controllerManagementMock.getActionForDownloadByTargetAndSoftwareModule(anyObject(), anyObject()))
.thenThrow(EntityNotFoundException.class);
@@ -325,12 +325,12 @@ public class AmqpMessageHandlerServiceTest {
messageProperties);
// mock
final LocalArtifact localArtifactMock = mock(LocalArtifact.class);
final Artifact localArtifactMock = mock(Artifact.class);
final DbArtifact dbArtifactMock = mock(DbArtifact.class);
when(artifactManagementMock.findFirstLocalArtifactsBySHA1(anyString())).thenReturn(localArtifactMock);
when(artifactManagementMock.findFirstArtifactBySHA1(anyString())).thenReturn(localArtifactMock);
when(controllerManagementMock.hasTargetArtifactAssigned(securityToken.getControllerId(), localArtifactMock))
.thenReturn(true);
when(artifactManagementMock.loadLocalArtifactBinary(localArtifactMock)).thenReturn(dbArtifactMock);
when(artifactManagementMock.loadArtifactBinary(localArtifactMock)).thenReturn(dbArtifactMock);
when(dbArtifactMock.getArtifactId()).thenReturn("artifactId");
when(dbArtifactMock.getSize()).thenReturn(1L);
when(dbArtifactMock.getHashes()).thenReturn(new DbArtifactHash("sha1", "md5"));

View File

@@ -17,7 +17,7 @@ import org.eclipse.hawkbit.mgmt.rest.api.MgmtDownloadArtifactRestApi;
import org.eclipse.hawkbit.repository.ArtifactManagement;
import org.eclipse.hawkbit.repository.SoftwareManagement;
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
import org.eclipse.hawkbit.repository.model.LocalArtifact;
import org.eclipse.hawkbit.repository.model.Artifact;
import org.eclipse.hawkbit.repository.model.SoftwareModule;
import org.eclipse.hawkbit.rest.util.RequestResponseContextHolder;
import org.eclipse.hawkbit.rest.util.RestResourceConversionHelper;
@@ -52,7 +52,7 @@ public class MgmtDownloadArtifactResource implements MgmtDownloadArtifactRestApi
* @param softwareModuleId
* of the parent SoftwareModule
* @param artifactId
* of the related LocalArtifact
* of the related Artifact
*
* @return responseEntity with status ok if successful
*/
@@ -62,12 +62,12 @@ public class MgmtDownloadArtifactResource implements MgmtDownloadArtifactRestApi
@PathVariable("artifactId") final Long artifactId) {
final SoftwareModule module = findSoftwareModuleWithExceptionIfNotFound(softwareModuleId, artifactId);
if (null == module || !module.getLocalArtifact(artifactId).isPresent()) {
if (null == module || !module.getArtifact(artifactId).isPresent()) {
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
}
final LocalArtifact artifact = module.getLocalArtifact(artifactId).get();
final DbArtifact file = artifactManagement.loadLocalArtifactBinary(artifact);
final Artifact artifact = module.getArtifact(artifactId).get();
final DbArtifact file = artifactManagement.loadArtifactBinary(artifact);
final HttpServletRequest request = requestResponseContextHolder.getHttpServletRequest();
final String ifMatch = request.getHeader("If-Match");
if (ifMatch != null && !RestResourceConversionHelper.matchesHttpHeader(ifMatch, artifact.getSha1Hash())) {
@@ -84,7 +84,7 @@ public class MgmtDownloadArtifactResource implements MgmtDownloadArtifactRestApi
final SoftwareModule module = softwareManagement.findSoftwareModuleById(softwareModuleId);
if (module == null) {
throw new EntityNotFoundException("SoftwareModule with Id {" + softwareModuleId + "} does not exist");
} else if (artifactId != null && !module.getLocalArtifact(artifactId).isPresent()) {
} else if (artifactId != null && !module.getArtifact(artifactId).isPresent()) {
throw new EntityNotFoundException("Artifact with Id {" + artifactId + "} does not exist");
}
return module;

View File

@@ -29,7 +29,6 @@ import org.eclipse.hawkbit.repository.SoftwareManagement;
import org.eclipse.hawkbit.repository.exception.ConstraintViolationException;
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
import org.eclipse.hawkbit.repository.model.Artifact;
import org.eclipse.hawkbit.repository.model.LocalArtifact;
import org.eclipse.hawkbit.repository.model.SoftwareModule;
import org.eclipse.hawkbit.repository.model.SoftwareModuleMetadata;
import org.eclipse.hawkbit.repository.model.SoftwareModuleType;
@@ -156,7 +155,7 @@ public final class MgmtSoftwareModuleMapper {
* @return
*/
static MgmtArtifact toResponse(final Artifact artifact) {
final MgmtArtifact.ArtifactType type = artifact instanceof LocalArtifact ? MgmtArtifact.ArtifactType.LOCAL
final MgmtArtifact.ArtifactType type = artifact instanceof Artifact ? MgmtArtifact.ArtifactType.LOCAL
: MgmtArtifact.ArtifactType.EXTERNAL;
final MgmtArtifact artifactRest = new MgmtArtifact();
@@ -165,16 +164,14 @@ public final class MgmtSoftwareModuleMapper {
artifactRest.setSize(artifact.getSize());
artifactRest.setHashes(new MgmtArtifactHash(artifact.getSha1Hash(), artifact.getMd5Hash()));
if (artifact instanceof LocalArtifact) {
artifactRest.setProvidedFilename(((LocalArtifact) artifact).getFilename());
}
artifactRest.setProvidedFilename(artifact.getFilename());
MgmtRestModelMapper.mapBaseToBase(artifactRest, artifact);
artifactRest.add(linkTo(methodOn(MgmtSoftwareModuleRestApi.class)
.getArtifact(artifact.getSoftwareModule().getId(), artifact.getId())).withRel("self"));
if (artifact instanceof LocalArtifact) {
if (artifact instanceof Artifact) {
artifactRest.add(linkTo(methodOn(MgmtDownloadArtifactResource.class)
.downloadArtifact(artifact.getSoftwareModule().getId(), artifact.getId())).withRel("download"));
}

View File

@@ -86,9 +86,9 @@ public class MgmtSoftwareModuleResource implements MgmtSoftwareModuleRestApi {
}
try {
final Artifact result = artifactManagement.createLocalArtifact(file.getInputStream(), softwareModuleId,
fileName, md5Sum == null ? null : md5Sum.toLowerCase(),
sha1Sum == null ? null : sha1Sum.toLowerCase(), false, file.getContentType());
final Artifact result = artifactManagement.createArtifact(file.getInputStream(), softwareModuleId, fileName,
md5Sum == null ? null : md5Sum.toLowerCase(), sha1Sum == null ? null : sha1Sum.toLowerCase(), false,
file.getContentType());
return ResponseEntity.status(CREATED).body(toResponse(result));
} catch (final IOException e) {
LOG.error("Failed to store artifact", e);
@@ -116,7 +116,7 @@ public class MgmtSoftwareModuleResource implements MgmtSoftwareModuleRestApi {
final SoftwareModule module = findSoftwareModuleWithExceptionIfNotFound(softwareModuleId, artifactId);
return ResponseEntity.ok(toResponse(module.getLocalArtifact(artifactId).get()));
return ResponseEntity.ok(toResponse(module.getArtifact(artifactId).get()));
}
@Override
@@ -125,7 +125,7 @@ public class MgmtSoftwareModuleResource implements MgmtSoftwareModuleRestApi {
@PathVariable("artifactId") final Long artifactId) {
findSoftwareModuleWithExceptionIfNotFound(softwareModuleId, artifactId);
artifactManagement.deleteLocalArtifact(artifactId);
artifactManagement.deleteArtifact(artifactId);
return ResponseEntity.ok().build();
}
@@ -200,7 +200,7 @@ public class MgmtSoftwareModuleResource implements MgmtSoftwareModuleRestApi {
public ResponseEntity<Void> deleteSoftwareModule(@PathVariable("softwareModuleId") final Long softwareModuleId) {
final SoftwareModule module = findSoftwareModuleWithExceptionIfNotFound(softwareModuleId, null);
softwareManagement.deleteSoftwareModule(module);
softwareManagement.deleteSoftwareModule(module.getId());
return ResponseEntity.ok().build();
}
@@ -239,7 +239,7 @@ public class MgmtSoftwareModuleResource implements MgmtSoftwareModuleRestApi {
@PathVariable("metadataKey") final String metadataKey) {
final SoftwareModule sw = findSoftwareModuleWithExceptionIfNotFound(softwareModuleId, null);
final SoftwareModuleMetadata findOne = softwareManagement.findSoftwareModuleMetadata(sw, metadataKey);
final SoftwareModuleMetadata findOne = softwareManagement.findSoftwareModuleMetadata(sw.getId(), metadataKey);
return ResponseEntity.ok(toResponseSwMetadata(findOne));
}
@@ -260,7 +260,7 @@ public class MgmtSoftwareModuleResource implements MgmtSoftwareModuleRestApi {
@PathVariable("metadataKey") final String metadataKey) {
final SoftwareModule sw = findSoftwareModuleWithExceptionIfNotFound(softwareModuleId, null);
softwareManagement.deleteSoftwareModuleMetadata(sw, metadataKey);
softwareManagement.deleteSoftwareModuleMetadata(sw.getId(), metadataKey);
return ResponseEntity.ok().build();
}
@@ -284,7 +284,7 @@ public class MgmtSoftwareModuleResource implements MgmtSoftwareModuleRestApi {
if (module == null) {
throw new EntityNotFoundException("SoftwareModule with Id {" + softwareModuleId + "} does not exist");
}
if (artifactId != null && !module.getLocalArtifact(artifactId).isPresent()) {
if (artifactId != null && !module.getArtifact(artifactId).isPresent()) {
throw new EntityNotFoundException("Artifact with Id {" + artifactId + "} does not exist");
}

View File

@@ -47,7 +47,7 @@ public class MgmtDownloadResourceTest extends AbstractRestIntegrationTestWithMon
final DistributionSet distributionSet = testdataFactory.createDistributionSet("Test");
final SoftwareModule softwareModule = distributionSet.getModules().stream().findFirst().get();
final Artifact artifact = testdataFactory.createLocalArtifacts(softwareModule.getId()).stream().findFirst().get();
final Artifact artifact = testdataFactory.createArtifacts(softwareModule.getId()).stream().findFirst().get();
downloadIdCache.put(downloadIdSha1, new DownloadArtifactCache(DownloadType.BY_SHA1, artifact.getSha1Hash()));
}

View File

@@ -39,7 +39,6 @@ import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants;
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
import org.eclipse.hawkbit.repository.model.Artifact;
import org.eclipse.hawkbit.repository.model.DistributionSet;
import org.eclipse.hawkbit.repository.model.LocalArtifact;
import org.eclipse.hawkbit.repository.model.SoftwareModule;
import org.eclipse.hawkbit.repository.model.SoftwareModuleMetadata;
import org.eclipse.hawkbit.repository.test.util.HashGeneratorUtils;
@@ -148,8 +147,7 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW
// check rest of response compared to DB
final MgmtArtifact artResult = ResourceUtility
.convertArtifactResponse(mvcResult.getResponse().getContentAsString());
final Long artId = ((LocalArtifact) softwareManagement.findSoftwareModuleWithDetails(sm.getId()).getArtifacts()
.get(0)).getId();
final Long artId = softwareManagement.findSoftwareModuleWithDetails(sm.getId()).getArtifacts().get(0).getId();
assertThat(artResult.getArtifactId()).as("Wrong artifact id").isEqualTo(artId);
assertThat(JsonPath.compile("$._links.self.href").read(mvcResult.getResponse().getContentAsString()).toString())
.as("Link contains no self url")
@@ -164,33 +162,32 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW
private void assertArtifact(final SoftwareModule sm, final byte[] random) throws IOException {
// check result in db...
// repo
assertThat(artifactManagement.countLocalArtifactsAll()).as("Wrong artifact size").isEqualTo(1);
assertThat(artifactManagement.countArtifactsAll()).as("Wrong artifact size").isEqualTo(1);
// binary
assertTrue("Wrong artifact content",
IOUtils.contentEquals(new ByteArrayInputStream(random),
artifactManagement
.loadLocalArtifactBinary((LocalArtifact) softwareManagement
.findSoftwareModuleWithDetails(sm.getId()).getArtifacts().get(0))
artifactManagement.loadArtifactBinary(
softwareManagement.findSoftwareModuleWithDetails(sm.getId()).getArtifacts().get(0))
.getFileInputStream()));
// hashes
assertThat(artifactManagement.findLocalArtifactByFilename("origFilename").get(0).getSha1Hash())
.as("Wrong sha1 hash").isEqualTo(HashGeneratorUtils.generateSHA1(random));
assertThat(artifactManagement.findArtifactByFilename("origFilename").get(0).getSha1Hash()).as("Wrong sha1 hash")
.isEqualTo(HashGeneratorUtils.generateSHA1(random));
assertThat(artifactManagement.findLocalArtifactByFilename("origFilename").get(0).getMd5Hash())
.as("Wrong md5 hash").isEqualTo(HashGeneratorUtils.generateMD5(random));
assertThat(artifactManagement.findArtifactByFilename("origFilename").get(0).getMd5Hash()).as("Wrong md5 hash")
.isEqualTo(HashGeneratorUtils.generateMD5(random));
// metadata
assertThat(((LocalArtifact) softwareManagement.findSoftwareModuleWithDetails(sm.getId()).getArtifacts().get(0))
.getFilename()).as("wrong metadata of the filename").isEqualTo("origFilename");
assertThat(softwareManagement.findSoftwareModuleWithDetails(sm.getId()).getArtifacts().get(0).getFilename())
.as("wrong metadata of the filename").isEqualTo("origFilename");
}
@Test
@Description("Verfies that the system does not accept empty artifact uploads. Expected response: BAD REQUEST")
public void emptyUploadArtifact() throws Exception {
assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).hasSize(0);
assertThat(artifactManagement.countLocalArtifactsAll()).isEqualTo(0);
assertThat(artifactManagement.countArtifactsAll()).isEqualTo(0);
SoftwareModule sm = entityFactory.generateSoftwareModule(osType, "name 1", "version 1", null, null);
sm = softwareManagement.createSoftwareModule(sm);
@@ -229,7 +226,7 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW
public void uploadArtifactWithCustomName() throws Exception {
SoftwareModule sm = entityFactory.generateSoftwareModule(osType, "name 1", "version 1", null, null);
sm = softwareManagement.createSoftwareModule(sm);
assertThat(artifactManagement.countLocalArtifactsAll()).isEqualTo(0);
assertThat(artifactManagement.countArtifactsAll()).isEqualTo(0);
// create test file
final byte random[] = RandomStringUtils.random(5 * 1024).getBytes();
@@ -244,10 +241,10 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW
// check result in db...
// repo
assertThat(artifactManagement.countLocalArtifactsAll()).isEqualTo(1);
assertThat(artifactManagement.countArtifactsAll()).isEqualTo(1);
// hashes
assertThat(artifactManagement.findLocalArtifactByFilename("customFilename")).as("Local artifact is wrong")
assertThat(artifactManagement.findArtifactByFilename("customFilename")).as("Local artifact is wrong")
.hasSize(1);
}
@@ -256,7 +253,7 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW
public void uploadArtifactWithHashCheck() throws Exception {
SoftwareModule sm = entityFactory.generateSoftwareModule(osType, "name 1", "version 1", null, null);
sm = softwareManagement.createSoftwareModule(sm);
assertThat(artifactManagement.countLocalArtifactsAll()).isEqualTo(0);
assertThat(artifactManagement.countArtifactsAll()).isEqualTo(0);
// create test file
final byte random[] = RandomStringUtils.random(5 * 1024).getBytes();
@@ -303,9 +300,9 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW
final byte random[] = RandomStringUtils.random(5 * 1024).getBytes();
final Artifact artifact = artifactManagement.createLocalArtifact(new ByteArrayInputStream(random), sm.getId(),
final Artifact artifact = artifactManagement.createArtifact(new ByteArrayInputStream(random), sm.getId(),
"file1", false);
final Artifact artifact2 = artifactManagement.createLocalArtifact(new ByteArrayInputStream(random), sm.getId(),
final Artifact artifact2 = artifactManagement.createArtifact(new ByteArrayInputStream(random), sm.getId(),
"file2", false);
final MvcResult result = mvc
@@ -326,7 +323,7 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW
Arrays.equals(result2.getResponse().getContentAsByteArray(), random));
assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).as("Softwaremodule size is wrong").hasSize(1);
assertThat(artifactManagement.countLocalArtifactsAll()).isEqualTo(2);
assertThat(artifactManagement.countArtifactsAll()).isEqualTo(2);
}
@Test
@@ -337,7 +334,7 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW
sm = softwareManagement.createSoftwareModule(sm);
final byte random[] = RandomStringUtils.random(5 * 1024).getBytes();
final Artifact artifact = artifactManagement.createLocalArtifact(new ByteArrayInputStream(random), sm.getId(),
final Artifact artifact = artifactManagement.createArtifact(new ByteArrayInputStream(random), sm.getId(),
"file1", false);
// perform test
@@ -364,9 +361,9 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW
final byte random[] = RandomStringUtils.random(5 * 1024).getBytes();
final Artifact artifact = artifactManagement.createLocalArtifact(new ByteArrayInputStream(random), sm.getId(),
final Artifact artifact = artifactManagement.createArtifact(new ByteArrayInputStream(random), sm.getId(),
"file1", false);
final Artifact artifact2 = artifactManagement.createLocalArtifact(new ByteArrayInputStream(random), sm.getId(),
final Artifact artifact2 = artifactManagement.createArtifact(new ByteArrayInputStream(random), sm.getId(),
"file2", false);
mvc.perform(get("/rest/v1/softwaremodules/{smId}/artifacts", sm.getId()).accept(MediaType.APPLICATION_JSON))
@@ -413,7 +410,7 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW
.andDo(MockMvcResultPrinter.print()).andExpect(status().isNotFound());
// SM does not exist
artifactManagement.createLocalArtifact(new ByteArrayInputStream(random), sm.getId(), "file1", false);
artifactManagement.createArtifact(new ByteArrayInputStream(random), sm.getId(), "file1", false);
mvc.perform(get("/rest/v1/softwaremodules/1234567890/artifacts")).andDo(MockMvcResultPrinter.print())
.andExpect(status().isNotFound());
@@ -834,15 +831,15 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW
.isEqualTo("http://localhost/rest/v1/softwaremodules/" + ahCreated.getId() + "/artifacts");
assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).as("Wrong softwaremodule size").hasSize(3);
assertThat(softwareManagement.findSoftwareModulesByType(pageReq, osType).getContent().get(0).getName())
assertThat(softwareManagement.findSoftwareModulesByType(pageReq, osType.getId()).getContent().get(0).getName())
.as("Softwaremoudle name is wrong").isEqualTo(os.getName());
assertThat(softwareManagement.findSoftwareModulesByType(pageReq, osType).getContent().get(0).getCreatedBy())
.as("Softwaremoudle created by is wrong").isEqualTo("uploadTester");
assertThat(softwareManagement.findSoftwareModulesByType(pageReq, osType).getContent().get(0).getCreatedAt())
.as("Softwaremoudle created at is wrong").isGreaterThanOrEqualTo(current);
assertThat(softwareManagement.findSoftwareModulesByType(pageReq, runtimeType).getContent().get(0).getName())
.as("Softwaremoudle name is wrong").isEqualTo(jvm.getName());
assertThat(softwareManagement.findSoftwareModulesByType(pageReq, appType).getContent().get(0).getName())
assertThat(softwareManagement.findSoftwareModulesByType(pageReq, osType.getId()).getContent().get(0)
.getCreatedBy()).as("Softwaremoudle created by is wrong").isEqualTo("uploadTester");
assertThat(softwareManagement.findSoftwareModulesByType(pageReq, osType.getId()).getContent().get(0)
.getCreatedAt()).as("Softwaremoudle created at is wrong").isGreaterThanOrEqualTo(current);
assertThat(softwareManagement.findSoftwareModulesByType(pageReq, runtimeType.getId()).getContent().get(0)
.getName()).as("Softwaremoudle name is wrong").isEqualTo(jvm.getName());
assertThat(softwareManagement.findSoftwareModulesByType(pageReq, appType.getId()).getContent().get(0).getName())
.as("Softwaremoudle name is wrong").isEqualTo(ah.getName());
}
@@ -855,17 +852,17 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW
final byte random[] = RandomStringUtils.random(5 * 1024).getBytes();
artifactManagement.createLocalArtifact(new ByteArrayInputStream(random), sm.getId(), "file1", false);
artifactManagement.createArtifact(new ByteArrayInputStream(random), sm.getId(), "file1", false);
assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).as("Softwaremoudle size is wrong").hasSize(1);
assertThat(artifactManagement.countLocalArtifactsAll()).isEqualTo(1);
assertThat(artifactManagement.countArtifactsAll()).isEqualTo(1);
mvc.perform(delete("/rest/v1/softwaremodules/{smId}", sm.getId())).andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk());
assertThat(softwareManagement.findSoftwareModulesAll(pageReq))
.as("After delete no softwarmodule should be available").isEmpty();
assertThat(artifactManagement.countLocalArtifactsAll()).isEqualTo(0);
assertThat(artifactManagement.countArtifactsAll()).isEqualTo(0);
}
@Test
@@ -875,11 +872,11 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW
final byte random[] = RandomStringUtils.random(5 * 1024).getBytes();
artifactManagement.createLocalArtifact(new ByteArrayInputStream(random),
ds1.findFirstModuleByType(appType).getId(), "file1", false);
artifactManagement.createArtifact(new ByteArrayInputStream(random), ds1.findFirstModuleByType(appType).getId(),
"file1", false);
assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).hasSize(3);
assertThat(artifactManagement.countLocalArtifactsAll()).isEqualTo(1);
assertThat(artifactManagement.countArtifactsAll()).isEqualTo(1);
mvc.perform(delete("/rest/v1/softwaremodules/{smId}", ds1.findFirstModuleByType(appType).getId()))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk());
@@ -891,7 +888,7 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW
// all 3 are now marked as deleted
assertThat(softwareManagement.findSoftwareModulesAll(pageReq).getNumber())
.as("After delete no softwarmodule should be available").isEqualTo(0);
assertThat(artifactManagement.countLocalArtifactsAll()).isEqualTo(1);
assertThat(artifactManagement.countArtifactsAll()).isEqualTo(1);
}
@Test
@@ -904,15 +901,15 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW
final byte random[] = RandomStringUtils.random(5 * 1024).getBytes();
// Create 2 artifacts
final LocalArtifact artifact = artifactManagement.createLocalArtifact(new ByteArrayInputStream(random),
sm.getId(), "file1", false);
artifactManagement.createLocalArtifact(new ByteArrayInputStream(random), sm.getId(), "file2", false);
final Artifact artifact = artifactManagement.createArtifact(new ByteArrayInputStream(random), sm.getId(),
"file1", false);
artifactManagement.createArtifact(new ByteArrayInputStream(random), sm.getId(), "file2", false);
// check repo before delete
assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).hasSize(1);
assertThat(softwareManagement.findSoftwareModuleWithDetails(sm.getId()).getArtifacts()).hasSize(2);
assertThat(artifactManagement.countLocalArtifactsAll()).isEqualTo(2);
assertThat(artifactManagement.countArtifactsAll()).isEqualTo(2);
// delete
mvc.perform(delete("/rest/v1/softwaremodules/{smId}/artifacts/{artId}", sm.getId(), artifact.getId()))
@@ -921,7 +918,7 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW
// check that only one artifact is still alive and still assigned
assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).as("After the sm should be marked as deleted")
.hasSize(1);
assertThat(artifactManagement.countLocalArtifactsAll()).isEqualTo(1);
assertThat(artifactManagement.countArtifactsAll()).isEqualTo(1);
assertThat(softwareManagement.findSoftwareModuleWithDetails(sm.getId()).getArtifacts())
.as("After delete artifact should available for marked as deleted sm's").hasSize(1);
@@ -950,8 +947,8 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW
.andExpect(jsonPath("[1]key", equalTo(knownKey2)))
.andExpect(jsonPath("[1]value", equalTo(knownValue2)));
final SoftwareModuleMetadata metaKey1 = softwareManagement.findSoftwareModuleMetadata(sm, knownKey1);
final SoftwareModuleMetadata metaKey2 = softwareManagement.findSoftwareModuleMetadata(sm, knownKey2);
final SoftwareModuleMetadata metaKey1 = softwareManagement.findSoftwareModuleMetadata(sm.getId(), knownKey1);
final SoftwareModuleMetadata metaKey2 = softwareManagement.findSoftwareModuleMetadata(sm.getId(), knownKey2);
assertThat(metaKey1.getValue()).as("Metadata key is wrong").isEqualTo(knownValue1);
assertThat(metaKey2.getValue()).as("Metadata key is wrong").isEqualTo(knownValue2);
@@ -978,7 +975,7 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW
.andExpect(content().contentType(MediaType.APPLICATION_JSON))
.andExpect(jsonPath("key", equalTo(knownKey))).andExpect(jsonPath("value", equalTo(updateValue)));
final SoftwareModuleMetadata assertDS = softwareManagement.findSoftwareModuleMetadata(sm, knownKey);
final SoftwareModuleMetadata assertDS = softwareManagement.findSoftwareModuleMetadata(sm.getId(), knownKey);
assertThat(assertDS.getValue()).as("Metadata is wrong").isEqualTo(updateValue);
}
@@ -998,7 +995,7 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk());
try {
softwareManagement.findSoftwareModuleMetadata(sm, knownKey);
softwareManagement.findSoftwareModuleMetadata(sm.getId(), knownKey);
fail("expected EntityNotFoundException but didn't throw");
} catch (final EntityNotFoundException e) {
// ok as expected

View File

@@ -42,11 +42,11 @@ public class SMRessourceMisingMongoDbConnectionTest extends AbstractRestIntegrat
mongodExecutable.stop();
assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).hasSize(0);
assertThat(artifactManagement.countLocalArtifactsAll()).isEqualTo(0);
assertThat(artifactManagement.countArtifactsAll()).isEqualTo(0);
SoftwareModule sm = entityFactory.generateSoftwareModule(softwareManagement.findSoftwareModuleTypeByKey("os"),
"name 1", "version 1", null, null);
sm = softwareManagement.createSoftwareModule(sm);
assertThat(artifactManagement.countLocalArtifactsAll()).isEqualTo(0);
assertThat(artifactManagement.countArtifactsAll()).isEqualTo(0);
// create test file
final byte random[] = RandomStringUtils.random(5 * 1024).getBytes();
@@ -64,10 +64,11 @@ public class SMRessourceMisingMongoDbConnectionTest extends AbstractRestIntegrat
assertThat(exceptionInfo.getMessage()).isEqualTo(SpServerError.SP_ARTIFACT_UPLOAD_FAILED.getMessage());
// ensure that the JPA transaction was rolled back
assertThat(artifactManagement.countLocalArtifactsAll()).isEqualTo(0);
assertThat(artifactManagement.countArtifactsAll()).isEqualTo(0);
}
@Override
@After
public void cleanCurrentCollection() {
// not needed, mongodb is stopped already

View File

@@ -32,10 +32,6 @@
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
</dependency>
<dependency>
<groupId>cz.jirutka.rsql</groupId>
<artifactId>rsql-parser</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.hateoas</groupId>
<artifactId>spring-hateoas</artifactId>

View File

@@ -23,9 +23,6 @@ import org.eclipse.hawkbit.repository.exception.GridFSDBFileNotFoundException;
import org.eclipse.hawkbit.repository.exception.InvalidMD5HashException;
import org.eclipse.hawkbit.repository.exception.InvalidSHA1HashException;
import org.eclipse.hawkbit.repository.model.Artifact;
import org.eclipse.hawkbit.repository.model.ExternalArtifact;
import org.eclipse.hawkbit.repository.model.ExternalArtifactProvider;
import org.eclipse.hawkbit.repository.model.LocalArtifact;
import org.eclipse.hawkbit.repository.model.SoftwareModule;
import org.hibernate.validator.constraints.NotEmpty;
import org.springframework.data.domain.Page;
@@ -38,59 +35,12 @@ import org.springframework.security.access.prepost.PreAuthorize;
*
*/
public interface ArtifactManagement {
/**
* Creates {@link ExternalArtifact} based on given provider.
*
* @param externalRepository
* the artifact is located in
* @param urlSuffix
* of the artifact
* {@link ExternalArtifactProvider#getDefaultSuffix()} is used if
* empty.
* @param moduleId
* to assign the artifact to
*
* @return created {@link ExternalArtifact}
*
* @throws EntityNotFoundException
* if {@link SoftwareModule} with given ID does not exist
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_CREATE_REPOSITORY)
ExternalArtifact createExternalArtifact(@NotNull ExternalArtifactProvider externalRepository, String urlSuffix,
@NotNull Long moduleId);
/**
* @return the total amount of local artifacts stored in the artifact
* management
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
Long countLocalArtifactsAll();
/**
* @return the total amount of external artifacts stored in the artifact
* management
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
Long countExternalArtifactsAll();
/**
* Persists {@link ExternalArtifactProvider} based on given properties.
*
* @param name
* of the provided
* @param description
* which is optional
* @param basePath
* of all {@link ExternalArtifact}s of the provider
* @param defaultUrlSuffix
* that is used if {@link ExternalArtifact#getUrlSuffix()} is
* empty.
* @return created {@link ExternalArtifactProvider}
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_CREATE_REPOSITORY)
ExternalArtifactProvider createExternalArtifactProvider(@NotEmpty String name, String description,
@NotNull String basePath, String defaultUrlSuffix);
Long countArtifactsAll();
/**
* Persists artifact binary as provided by given InputStream. assign the
@@ -106,12 +56,12 @@ public interface ArtifactManagement {
* to <code>true</code> if the artifact binary can be overridden
* if it already exists
*
* @return uploaded {@link LocalArtifact}
* @return uploaded {@link Artifact}
*
* @throw ArtifactUploadFailedException if upload fails
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY)
LocalArtifact createLocalArtifact(@NotNull InputStream inputStream, @NotNull Long moduleId, final String filename,
Artifact createArtifact(@NotNull InputStream inputStream, @NotNull Long moduleId, final String filename,
final boolean overrideExisting);
/**
@@ -130,13 +80,13 @@ public interface ArtifactManagement {
* @param contentType
* the contentType of the file
*
* @return uploaded {@link LocalArtifact}
* @return uploaded {@link Artifact}
*
* @throw ArtifactUploadFailedException if upload fails
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY)
LocalArtifact createLocalArtifact(@NotNull InputStream inputStream, @NotNull Long moduleId,
@NotNull String filename, final boolean overrideExisting, @NotNull String contentType);
Artifact createArtifact(@NotNull InputStream inputStream, @NotNull Long moduleId, @NotNull String filename,
final boolean overrideExisting, @NotNull String contentType);
/**
* Persists artifact binary as provided by given InputStream. assign the
@@ -157,7 +107,7 @@ public interface ArtifactManagement {
* if it already exists
* @param contentType
* the contentType of the file
* @return uploaded {@link LocalArtifact}
* @return uploaded {@link Artifact}
*
* @throws EntityNotFoundException
* if given software module does not exist
@@ -171,24 +121,12 @@ public interface ArtifactManagement {
* if check against provided SHA1 checksum failed
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_CREATE_REPOSITORY)
LocalArtifact createLocalArtifact(@NotNull InputStream stream, @NotNull Long moduleId, @NotEmpty String filename,
Artifact createArtifact(@NotNull InputStream stream, @NotNull Long moduleId, @NotEmpty String filename,
String providedMd5Sum, String providedSha1Sum, boolean overrideExisting, String contentType);
/**
* Deletes {@link Artifact} based on given id.
*
* @param id
* of the {@link Artifact} that has to be deleted.
* @throws ArtifactDeleteFailedException
* if deletion failed (MongoDB is not available)
*
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_DELETE_REPOSITORY)
void deleteExternalArtifact(@NotNull Long id);
/**
* Garbage collects local artifact binary file if only referenced by given
* {@link LocalArtifact} metadata object.
* {@link Artifact} metadata object.
*
* @param onlyByThisReferenced
* the related local artifact
@@ -196,7 +134,7 @@ public interface ArtifactManagement {
* @return <code>true</code> if an binary was actually garbage collected
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_DELETE_REPOSITORY)
boolean clearLocalArtifactBinary(@NotNull LocalArtifact onlyByThisReferenced);
boolean clearArtifactBinary(@NotNull Artifact onlyByThisReferenced);
/**
* Deletes {@link Artifact} based on given id.
@@ -208,19 +146,19 @@ public interface ArtifactManagement {
*
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_DELETE_REPOSITORY)
void deleteLocalArtifact(@NotNull Long id);
void deleteArtifact(@NotNull Long id);
/**
* Searches for {@link LocalArtifact} with given {@link Identifiable}.
* Searches for {@link Artifact} with given {@link Identifiable}.
*
* @param id
* to search for
* @return found {@link LocalArtifact} or <code>null</code> is it could not
* be found.
* @return found {@link Artifact} or <code>null</code> is it could not be
* found.
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY + SpringEvalExpressions.HAS_AUTH_OR
+ SpringEvalExpressions.IS_CONTROLLER)
LocalArtifact findLocalArtifact(@NotNull Long id);
Artifact findArtifact(@NotNull Long id);
/**
* Find by artifact by software module id and filename.
@@ -229,11 +167,11 @@ public interface ArtifactManagement {
* file name
* @param softwareModuleId
* software module id.
* @return LocalArtifact if artifact present
* @return Artifact if artifact present
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY + SpringEvalExpressions.HAS_AUTH_OR
+ SpringEvalExpressions.IS_CONTROLLER)
List<LocalArtifact> findByFilenameAndSoftwareModule(@NotNull String filename, @NotNull Long softwareModuleId);
List<Artifact> findByFilenameAndSoftwareModule(@NotNull String filename, @NotNull Long softwareModuleId);
/**
* Find all local artifact by sha1 and return the first artifact.
@@ -244,18 +182,18 @@ public interface ArtifactManagement {
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY + SpringEvalExpressions.HAS_AUTH_OR
+ SpringEvalExpressions.IS_CONTROLLER)
LocalArtifact findFirstLocalArtifactsBySHA1(@NotNull String sha1);
Artifact findFirstArtifactBySHA1(@NotNull String sha1);
/**
* Searches for {@link Artifact} with given file name.
*
* @param filename
* to search for
* @return found List of {@link LocalArtifact}s.
* @return found List of {@link Artifact}s.
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY + SpringEvalExpressions.HAS_AUTH_OR
+ SpringEvalExpressions.IS_CONTROLLER)
List<LocalArtifact> findLocalArtifactByFilename(@NotNull String filename);
List<Artifact> findArtifactByFilename(@NotNull String filename);
/**
* Get local artifact for a base software module.
@@ -264,38 +202,13 @@ public interface ArtifactManagement {
* Pageable
* @param swId
* software module id
* @return Page<LocalArtifact>
* @return Page<Artifact>
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
Page<LocalArtifact> findLocalArtifactBySoftwareModule(@NotNull Pageable pageReq, @NotNull Long swId);
Page<Artifact> findArtifactBySoftwareModule(@NotNull Pageable pageReq, @NotNull Long swId);
/**
* Finds {@link SoftwareModule} by given id.
*
* @param id
* to search for
* @return the found {@link SoftwareModule}s or <code>null</code> if not
* found.
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY + SpringEvalExpressions.HAS_AUTH_OR
+ SpringEvalExpressions.IS_CONTROLLER)
SoftwareModule findSoftwareModuleById(@NotNull Long id);
/**
* Retrieves software module including details (
* {@link SoftwareModule#getArtifacts()}).
*
* @param id
* parameter
* @param isDeleted
* parameter
* @return the found {@link SoftwareModule}s
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
SoftwareModule findSoftwareModuleWithDetails(@NotNull Long id);
/**
* Loads {@link DbArtifact} from store for given {@link LocalArtifact}.
* Loads {@link DbArtifact} from store for given {@link Artifact}.
*
* @param artifact
* to search for
@@ -306,6 +219,6 @@ public interface ArtifactManagement {
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_DOWNLOAD_ARTIFACT + SpringEvalExpressions.HAS_AUTH_OR
+ SpringEvalExpressions.HAS_CONTROLLER_DOWNLOAD)
DbArtifact loadLocalArtifactBinary(@NotNull LocalArtifact artifact);
DbArtifact loadArtifactBinary(@NotNull Artifact artifact);
}

View File

@@ -24,8 +24,8 @@ import org.eclipse.hawkbit.repository.exception.TooManyStatusEntriesException;
import org.eclipse.hawkbit.repository.model.Action;
import org.eclipse.hawkbit.repository.model.Action.Status;
import org.eclipse.hawkbit.repository.model.ActionStatus;
import org.eclipse.hawkbit.repository.model.Artifact;
import org.eclipse.hawkbit.repository.model.DistributionSet;
import org.eclipse.hawkbit.repository.model.LocalArtifact;
import org.eclipse.hawkbit.repository.model.SoftwareModule;
import org.eclipse.hawkbit.repository.model.Target;
import org.eclipse.hawkbit.repository.model.TargetInfo;
@@ -200,7 +200,7 @@ public interface ControllerManagement {
* otherwise {@code false}
*/
@PreAuthorize(SpringEvalExpressions.IS_CONTROLLER)
boolean hasTargetArtifactAssigned(@NotNull String controllerId, @NotNull LocalArtifact localArtifact);
boolean hasTargetArtifactAssigned(@NotNull String controllerId, @NotNull Artifact localArtifact);
/**
* Checks if a given target has currently or has even been assigned to the
@@ -219,7 +219,7 @@ public interface ControllerManagement {
* otherwise {@code false}
*/
@PreAuthorize(SpringEvalExpressions.IS_CONTROLLER)
boolean hasTargetArtifactAssigned(@NotNull Long targetId, @NotNull LocalArtifact localArtifact);
boolean hasTargetArtifactAssigned(@NotNull Long targetId, @NotNull Artifact localArtifact);
/**
* Registers retrieved status for given {@link Target} and {@link Action} if

View File

@@ -16,12 +16,12 @@ import javax.validation.constraints.NotNull;
import org.eclipse.hawkbit.repository.model.Action;
import org.eclipse.hawkbit.repository.model.Action.Status;
import org.eclipse.hawkbit.repository.model.ActionStatus;
import org.eclipse.hawkbit.repository.model.Artifact;
import org.eclipse.hawkbit.repository.model.BaseEntity;
import org.eclipse.hawkbit.repository.model.DistributionSet;
import org.eclipse.hawkbit.repository.model.DistributionSetMetadata;
import org.eclipse.hawkbit.repository.model.DistributionSetTag;
import org.eclipse.hawkbit.repository.model.DistributionSetType;
import org.eclipse.hawkbit.repository.model.LocalArtifact;
import org.eclipse.hawkbit.repository.model.Rollout;
import org.eclipse.hawkbit.repository.model.RolloutGroup;
import org.eclipse.hawkbit.repository.model.SoftwareModule;
@@ -376,10 +376,10 @@ public interface EntityFactory {
TargetTag generateTargetTag(@NotNull String name, String description, String colour);
/**
* Generates an empty {@link LocalArtifact} without persisting it.
* Generates an empty {@link Artifact} without persisting it.
*
* @return {@link LocalArtifact} object
* @return {@link Artifact} object
*/
LocalArtifact generateLocalArtifact();
Artifact generateArtifact();
}

View File

@@ -42,12 +42,12 @@ public interface SoftwareManagement {
*
* @param searchText
* to search for in name and version
* @param type
* to filter the result
* @param typeId
* to filter the result by type
* @return number of found {@link SoftwareModule}s
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
Long countSoftwareModuleByFilters(String searchText, SoftwareModuleType type);
Long countSoftwareModuleByFilters(String searchText, Long typeId);
/**
* Count all {@link SoftwareModule}s in the repository that are not marked
@@ -58,16 +58,6 @@ public interface SoftwareManagement {
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
Long countSoftwareModulesAll();
/**
* Counts {@link SoftwareModule}s with given {@link SoftwareModuleType}.
*
* @param type
* to count
* @return number of found {@link SoftwareModule}s
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
Long countSoftwareModulesByType(@NotNull SoftwareModuleType type);
/**
* @return number of {@link SoftwareModuleType}s in the repository.
*/
@@ -146,31 +136,31 @@ public interface SoftwareManagement {
/**
* Deletes the given {@link SoftwareModule} {@link Entity}.
*
* @param bsm
* @param moduleId
* is the {@link SoftwareModule} to be deleted
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_DELETE_REPOSITORY)
void deleteSoftwareModule(@NotNull SoftwareModule bsm);
void deleteSoftwareModule(@NotNull Long moduleId);
/**
* deletes a software module meta data entry.
*
* @param softwareModule
* @param moduleId
* where meta data has to be deleted
* @param key
* of the metda data element
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY)
void deleteSoftwareModuleMetadata(@NotNull SoftwareModule softwareModule, @NotEmpty String key);
void deleteSoftwareModuleMetadata(@NotNull Long moduleId, @NotEmpty String key);
/**
* Deletes {@link SoftwareModule}s which is any if the given ids.
*
* @param ids
* @param moduleIds
* of the Software Modules to be deleted
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_DELETE_REPOSITORY)
void deleteSoftwareModules(@NotNull Collection<Long> ids);
void deleteSoftwareModules(@NotNull Collection<Long> moduleIds);
/**
* Deletes or marks as delete in case the type is in use.
@@ -192,20 +182,6 @@ public interface SoftwareManagement {
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
Page<SoftwareModule> findSoftwareModuleByAssignedTo(@NotNull Pageable pageable, @NotNull DistributionSet set);
/**
* @param pageable
* the page request to page the result set
* @param set
* to search for
* @param type
* to filter
* @return all {@link SoftwareModule}s that are assigned to given
* {@link DistributionSet} filtered by {@link SoftwareModuleType}.
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
Page<SoftwareModule> findSoftwareModuleByAssignedToAndType(@NotNull Pageable pageable, @NotNull DistributionSet set,
@NotNull SoftwareModuleType type);
/**
* Filter {@link SoftwareModule}s with given
* {@link SoftwareModule#getName()} or {@link SoftwareModule#getVersion()}
@@ -215,13 +191,12 @@ public interface SoftwareManagement {
* page parameter
* @param searchText
* to be filtered as "like" on {@link SoftwareModule#getName()}
* @param type
* @param typeId
* to be filtered as "like" on {@link SoftwareModule#getType()}
* @return the page of found {@link SoftwareModule}
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
Slice<SoftwareModule> findSoftwareModuleByFilters(@NotNull Pageable pageable, String searchText,
SoftwareModuleType type);
Slice<SoftwareModule> findSoftwareModuleByFilters(@NotNull Pageable pageable, String searchText, Long typeId);
/**
* Finds {@link SoftwareModule} by given id.
@@ -253,7 +228,7 @@ public interface SoftwareManagement {
/**
* finds a single software module meta data by its id.
*
* @param softwareModule
* @param moduleId
* where meta data has to be found
* @param key
* of the meta data element
@@ -262,7 +237,7 @@ public interface SoftwareManagement {
* in case the meta data does not exists for the given key
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
SoftwareModuleMetadata findSoftwareModuleMetadata(@NotNull SoftwareModule softwareModule, @NotEmpty String key);
SoftwareModuleMetadata findSoftwareModuleMetadata(@NotNull Long moduleId, @NotEmpty String key);
/**
* finds all meta data by the given software module id.
@@ -316,14 +291,13 @@ public interface SoftwareManagement {
* the ID of distribution set to be ordered on top
* @param searchText
* filtered as "like" on {@link SoftwareModule#getName()}
* @param type
* @param typeId
* filtered as "equal" on {@link SoftwareModule#getType()}
* @return the page of found {@link SoftwareModule}
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
Slice<AssignedSoftwareModule> findSoftwareModuleOrderBySetAssignmentAndModuleNameAscModuleVersionAsc(
@NotNull Pageable pageable, @NotNull Long orderByDistributionId, String searchText,
SoftwareModuleType type);
@NotNull Pageable pageable, @NotNull Long orderByDistributionId, String searchText, Long typeId);
/**
* Retrieves all software modules. Deleted ones are filtered.
@@ -370,12 +344,12 @@ public interface SoftwareManagement {
*
* @param pageable
* page parameters
* @param type
* @param typeId
* to be filtered on
* @return the found {@link SoftwareModule}s
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
Slice<SoftwareModule> findSoftwareModulesByType(@NotNull Pageable pageable, @NotNull SoftwareModuleType type);
Slice<SoftwareModule> findSoftwareModulesByType(@NotNull Pageable pageable, @NotNull Long typeId);
/**
*

View File

@@ -17,6 +17,10 @@ import com.google.common.io.BaseEncoding;
*
*/
public interface Artifact extends TenantAwareBaseEntity {
/**
* @return the filename that was provided during upload.
*/
String getFilename();
/**
* @return {@link SoftwareModule} this {@link Artifact} belongs to.

View File

@@ -1,41 +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.model;
import java.net.URL;
/**
* External artifact representation with all the necessary information to
* generate an artifact {@link URL} at runtime.
*
*/
public interface ExternalArtifact extends Artifact {
/**
* @return {@link ExternalArtifactProvider} of this {@link Artifact}.
*/
ExternalArtifactProvider getExternalArtifactProvider();
/**
* @return generated download {@link URL}.
*/
String getUrl();
/**
* @return suffix for {@link URL} generation.
*/
String getUrlSuffix();
/**
* @param urlSuffix
* the urlSuffix to set
*/
void setUrlSuffix(String urlSuffix);
}

View File

@@ -1,28 +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.model;
import org.eclipse.hawkbit.artifact.repository.ArtifactRepository;
/**
* Tenant specific locally stored artifact representation that is used by
* {@link SoftwareModule}s . It contains all information that is provided by the
* user while all update server generated information related to the artifact
* (hash, length) is stored directly with the binary itself in the
* {@link ArtifactRepository}.
*
*/
public interface LocalArtifact extends Artifact {
/**
* @return the filename that was provided during upload.
*/
String getFilename();
}

View File

@@ -21,38 +21,40 @@ public interface SoftwareModule extends NamedVersionedEntity {
* @param artifact
* is added to the assigned {@link Artifact}s.
*/
void addArtifact(LocalArtifact artifact);
/**
* @param artifact
* is added to the assigned {@link Artifact}s.
*/
void addArtifact(ExternalArtifact artifact);
void addArtifact(Artifact artifact);
/**
* @param artifactId
* to look for
* @return found {@link Artifact}
*/
Optional<LocalArtifact> getLocalArtifact(Long artifactId);
default Optional<Artifact> getArtifact(final Long artifactId) {
if (getArtifacts().isEmpty()) {
return Optional.empty();
}
return getArtifacts().stream().filter(artifact -> artifact.getId().equals(artifactId)).findFirst();
}
/**
* @param fileName
* to look for
* @return found {@link Artifact}
*/
Optional<LocalArtifact> getLocalArtifactByFilename(String fileName);
default Optional<Artifact> getArtifactByFilename(final String fileName) {
if (getArtifacts().isEmpty()) {
return Optional.empty();
}
return getArtifacts().stream().filter(artifact -> artifact.getFilename().equalsIgnoreCase(fileName.trim()))
.findFirst();
}
/**
* @return immutable list of all artifacts
*/
List<Artifact> getArtifacts();
/**
* @return immutable list of local artifacts only
*/
List<LocalArtifact> getLocalArtifacts();
/**
* @return the vendor of this software module
*/
@@ -66,15 +68,9 @@ public interface SoftwareModule extends NamedVersionedEntity {
/**
* @param artifact
* is removed from the assigned {@link LocalArtifact}s.
* is removed from the assigned {@link Artifact}s.
*/
void removeArtifact(LocalArtifact artifact);
/**
* @param artifact
* is removed from the assigned {@link ExternalArtifact}s.
*/
void removeArtifact(ExternalArtifact artifact);
void removeArtifact(Artifact artifact);
/**
* @return the type of the software module

View File

@@ -1,23 +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.jpa;
import org.eclipse.hawkbit.repository.jpa.model.JpaExternalArtifactProvider;
import org.eclipse.hawkbit.repository.model.ExternalArtifactProvider;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Transactional;
/**
* Repository for {@link ExternalArtifactProvider}.
*
*/
@Transactional(readOnly = true, isolation = Isolation.READ_UNCOMMITTED)
public interface ExternalArtifactProviderRepository extends BaseEntityRepository<JpaExternalArtifactProvider, Long> {
}

View File

@@ -1,37 +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.jpa;
import org.eclipse.hawkbit.repository.jpa.model.JpaExternalArtifact;
import org.eclipse.hawkbit.repository.model.ExternalArtifact;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Transactional;
/**
* {@link ExternalArtifact} repository.
*
*/
@Transactional(readOnly = true, isolation = Isolation.READ_UNCOMMITTED)
public interface ExternalArtifactRepository extends BaseEntityRepository<JpaExternalArtifact, Long> {
/**
* Searches for external artifact for a base software module.
*
* @param pageReq
* Pageable
* @param swId
* software module id
*
* @return Page<ExternalArtifact>
*/
Page<JpaExternalArtifact> findBySoftwareModuleId(Pageable pageReq, final Long swId);
}

View File

@@ -24,21 +24,15 @@ import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
import org.eclipse.hawkbit.repository.exception.GridFSDBFileNotFoundException;
import org.eclipse.hawkbit.repository.exception.InvalidMD5HashException;
import org.eclipse.hawkbit.repository.exception.InvalidSHA1HashException;
import org.eclipse.hawkbit.repository.jpa.model.JpaExternalArtifact;
import org.eclipse.hawkbit.repository.jpa.model.JpaExternalArtifactProvider;
import org.eclipse.hawkbit.repository.jpa.model.JpaLocalArtifact;
import org.eclipse.hawkbit.repository.jpa.model.JpaArtifact;
import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule;
import org.eclipse.hawkbit.repository.jpa.specifications.SoftwareModuleSpecification;
import org.eclipse.hawkbit.repository.model.ExternalArtifact;
import org.eclipse.hawkbit.repository.model.ExternalArtifactProvider;
import org.eclipse.hawkbit.repository.model.LocalArtifact;
import org.eclipse.hawkbit.repository.model.Artifact;
import org.eclipse.hawkbit.repository.model.SoftwareModule;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Transactional;
@@ -57,24 +51,18 @@ public class JpaArtifactManagement implements ArtifactManagement {
@Autowired
private LocalArtifactRepository localArtifactRepository;
@Autowired
private ExternalArtifactRepository externalArtifactRepository;
@Autowired
private SoftwareModuleRepository softwareModuleRepository;
@Autowired
private ExternalArtifactProviderRepository externalArtifactProviderRepository;
@Autowired
private ArtifactRepository artifactRepository;
private static LocalArtifact checkForExistingArtifact(final String filename, final boolean overrideExisting,
private static Artifact checkForExistingArtifact(final String filename, final boolean overrideExisting,
final SoftwareModule softwareModule) {
if (softwareModule.getLocalArtifactByFilename(filename).isPresent()) {
if (softwareModule.getArtifactByFilename(filename).isPresent()) {
if (overrideExisting) {
LOG.debug("overriding existing artifact with new filename {}", filename);
return softwareModule.getLocalArtifactByFilename(filename).get();
return softwareModule.getArtifactByFilename(filename).get();
} else {
throw new EntityAlreadyExistsException("File with that name already exists in the Software Module");
}
@@ -85,33 +73,14 @@ public class JpaArtifactManagement implements ArtifactManagement {
@Override
@Modifying
@Transactional(isolation = Isolation.READ_UNCOMMITTED)
public ExternalArtifact createExternalArtifact(final ExternalArtifactProvider externalRepository,
final String urlSuffix, final Long moduleId) {
final SoftwareModule module = getModuleAndThrowExceptionIfThatFails(moduleId);
return externalArtifactRepository.save(new JpaExternalArtifact(externalRepository, urlSuffix, module));
}
@Override
@Modifying
@Transactional(isolation = Isolation.READ_UNCOMMITTED)
public ExternalArtifactProvider createExternalArtifactProvider(final String name, final String description,
final String basePath, final String defaultUrlSuffix) {
return externalArtifactProviderRepository
.save(new JpaExternalArtifactProvider(name, description, basePath, defaultUrlSuffix));
}
@Override
@Modifying
@Transactional(isolation = Isolation.READ_UNCOMMITTED)
public LocalArtifact createLocalArtifact(final InputStream stream, final Long moduleId, final String filename,
public Artifact createArtifact(final InputStream stream, final Long moduleId, final String filename,
final String providedMd5Sum, final String providedSha1Sum, final boolean overrideExisting,
final String contentType) {
DbArtifact result = null;
final SoftwareModule softwareModule = getModuleAndThrowExceptionIfThatFails(moduleId);
final LocalArtifact existing = checkForExistingArtifact(filename, overrideExisting, softwareModule);
final Artifact existing = checkForExistingArtifact(filename, overrideExisting, softwareModule);
try {
result = artifactRepository.store(stream, filename, contentType,
@@ -135,25 +104,10 @@ public class JpaArtifactManagement implements ArtifactManagement {
@Override
@Modifying
@Transactional(isolation = Isolation.READ_UNCOMMITTED)
public void deleteExternalArtifact(final Long id) {
final ExternalArtifact existing = externalArtifactRepository.findOne(id);
public boolean clearArtifactBinary(final Artifact existing) {
if (null == existing) {
return;
}
existing.getSoftwareModule().removeArtifact(existing);
softwareModuleRepository.save((JpaSoftwareModule) existing.getSoftwareModule());
externalArtifactRepository.delete(id);
}
@Override
@Modifying
@Transactional(isolation = Isolation.READ_UNCOMMITTED)
public boolean clearLocalArtifactBinary(final LocalArtifact existing) {
for (final LocalArtifact lArtifact : localArtifactRepository
.findByGridFsFileName(((JpaLocalArtifact) existing).getGridFsFileName())) {
for (final Artifact lArtifact : localArtifactRepository
.findByGridFsFileName(((JpaArtifact) existing).getGridFsFileName())) {
if (!lArtifact.getSoftwareModule().isDeleted()
&& Long.compare(lArtifact.getSoftwareModule().getId(), existing.getSoftwareModule().getId()) != 0) {
return false;
@@ -161,8 +115,8 @@ public class JpaArtifactManagement implements ArtifactManagement {
}
try {
LOG.debug("deleting artifact from repository {}", ((JpaLocalArtifact) existing).getGridFsFileName());
artifactRepository.deleteBySha1(((JpaLocalArtifact) existing).getGridFsFileName());
LOG.debug("deleting artifact from repository {}", ((JpaArtifact) existing).getGridFsFileName());
artifactRepository.deleteBySha1(((JpaArtifact) existing).getGridFsFileName());
return true;
} catch (final ArtifactStoreException e) {
throw new ArtifactDeleteFailedException(e);
@@ -172,14 +126,14 @@ public class JpaArtifactManagement implements ArtifactManagement {
@Override
@Modifying
@Transactional(isolation = Isolation.READ_UNCOMMITTED)
public void deleteLocalArtifact(final Long id) {
final JpaLocalArtifact existing = localArtifactRepository.findOne(id);
public void deleteArtifact(final Long id) {
final JpaArtifact existing = localArtifactRepository.findOne(id);
if (null == existing) {
return;
}
clearLocalArtifactBinary(existing);
clearArtifactBinary(existing);
existing.getSoftwareModule().removeArtifact(existing);
softwareModuleRepository.save((JpaSoftwareModule) existing.getSoftwareModule());
@@ -187,74 +141,45 @@ public class JpaArtifactManagement implements ArtifactManagement {
}
@Override
public LocalArtifact findLocalArtifact(final Long id) {
public Artifact findArtifact(final Long id) {
return localArtifactRepository.findOne(id);
}
@Override
public List<LocalArtifact> findByFilenameAndSoftwareModule(final String filename, final Long softwareModuleId) {
public List<Artifact> findByFilenameAndSoftwareModule(final String filename, final Long softwareModuleId) {
return localArtifactRepository.findByFilenameAndSoftwareModuleId(filename, softwareModuleId);
}
@Override
public LocalArtifact findFirstLocalArtifactsBySHA1(final String sha1) {
public Artifact findFirstArtifactBySHA1(final String sha1) {
return localArtifactRepository.findFirstByGridFsFileName(sha1);
}
@Override
public List<LocalArtifact> findLocalArtifactByFilename(final String filename) {
public List<Artifact> findArtifactByFilename(final String filename) {
return localArtifactRepository.findByFilename(filename);
}
@Override
public Page<LocalArtifact> findLocalArtifactBySoftwareModule(final Pageable pageReq, final Long swId) {
public Page<Artifact> findArtifactBySoftwareModule(final Pageable pageReq, final Long swId) {
return localArtifactRepository.findBySoftwareModuleId(pageReq, swId);
}
@Override
public SoftwareModule findSoftwareModuleById(final Long id) {
final Specification<JpaSoftwareModule> spec = SoftwareModuleSpecification.byId(id);
return softwareModuleRepository.findOne(spec);
}
@Override
public SoftwareModule findSoftwareModuleWithDetails(final Long id) {
final SoftwareModule result = findSoftwareModuleById(id);
if (result != null) {
result.getArtifacts().size();
}
return result;
}
private SoftwareModule getModuleAndThrowExceptionIfThatFails(final Long moduleId) {
final SoftwareModule softwareModule = findSoftwareModuleWithDetails(moduleId);
if (softwareModule == null) {
LOG.debug("no software module with ID {} exists", moduleId);
throw new EntityNotFoundException("Software Module: " + moduleId);
}
return softwareModule;
}
@Override
public DbArtifact loadLocalArtifactBinary(final LocalArtifact artifact) {
final DbArtifact result = artifactRepository
.getArtifactBySha1(((JpaLocalArtifact) artifact).getGridFsFileName());
public DbArtifact loadArtifactBinary(final Artifact artifact) {
final DbArtifact result = artifactRepository.getArtifactBySha1(((JpaArtifact) artifact).getGridFsFileName());
if (result == null) {
throw new GridFSDBFileNotFoundException(((JpaLocalArtifact) artifact).getGridFsFileName());
throw new GridFSDBFileNotFoundException(((JpaArtifact) artifact).getGridFsFileName());
}
return result;
}
private LocalArtifact storeArtifactMetadata(final SoftwareModule softwareModule, final String providedFilename,
final DbArtifact result, final LocalArtifact existing) {
JpaLocalArtifact artifact = (JpaLocalArtifact) existing;
private Artifact storeArtifactMetadata(final SoftwareModule softwareModule, final String providedFilename,
final DbArtifact result, final Artifact existing) {
JpaArtifact artifact = (JpaArtifact) existing;
if (existing == null) {
artifact = new JpaLocalArtifact(result.getHashes().getSha1(), providedFilename, softwareModule);
artifact = new JpaArtifact(result.getHashes().getSha1(), providedFilename, softwareModule);
}
artifact.setMd5Hash(result.getHashes().getMd5());
artifact.setSha1Hash(result.getHashes().getSha1());
@@ -267,26 +192,32 @@ public class JpaArtifactManagement implements ArtifactManagement {
@Override
@Modifying
@Transactional(isolation = Isolation.READ_UNCOMMITTED)
public LocalArtifact createLocalArtifact(final InputStream inputStream, final Long moduleId, final String filename,
public Artifact createArtifact(final InputStream inputStream, final Long moduleId, final String filename,
final boolean overrideExisting) {
return createLocalArtifact(inputStream, moduleId, filename, null, null, overrideExisting, null);
return createArtifact(inputStream, moduleId, filename, null, null, overrideExisting, null);
}
@Override
@Modifying
@Transactional(isolation = Isolation.READ_UNCOMMITTED)
public LocalArtifact createLocalArtifact(final InputStream inputStream, final Long moduleId, final String filename,
public Artifact createArtifact(final InputStream inputStream, final Long moduleId, final String filename,
final boolean overrideExisting, final String contentType) {
return createLocalArtifact(inputStream, moduleId, filename, null, null, overrideExisting, contentType);
return createArtifact(inputStream, moduleId, filename, null, null, overrideExisting, contentType);
}
@Override
public Long countLocalArtifactsAll() {
public Long countArtifactsAll() {
return localArtifactRepository.count();
}
@Override
public Long countExternalArtifactsAll() {
return externalArtifactRepository.count();
private SoftwareModule getModuleAndThrowExceptionIfThatFails(final Long moduleId) {
final SoftwareModule softwareModule = softwareModuleRepository.findOne(moduleId);
if (softwareModule == null) {
LOG.debug("no software module with ID {} exists", moduleId);
throw new EntityNotFoundException("Software Module: " + moduleId);
}
return softwareModule;
}
}

View File

@@ -41,8 +41,8 @@ import org.eclipse.hawkbit.repository.jpa.specifications.ActionSpecifications;
import org.eclipse.hawkbit.repository.model.Action;
import org.eclipse.hawkbit.repository.model.Action.Status;
import org.eclipse.hawkbit.repository.model.ActionStatus;
import org.eclipse.hawkbit.repository.model.Artifact;
import org.eclipse.hawkbit.repository.model.DistributionSet;
import org.eclipse.hawkbit.repository.model.LocalArtifact;
import org.eclipse.hawkbit.repository.model.SoftwareModule;
import org.eclipse.hawkbit.repository.model.Target;
import org.eclipse.hawkbit.repository.model.TargetInfo;
@@ -150,7 +150,7 @@ public class JpaControllerManagement implements ControllerManagement {
}
@Override
public boolean hasTargetArtifactAssigned(final String controllerId, final LocalArtifact localArtifact) {
public boolean hasTargetArtifactAssigned(final String controllerId, final Artifact localArtifact) {
final Target target = targetRepository.findByControllerId(controllerId);
if (target == null) {
return false;
@@ -159,7 +159,7 @@ public class JpaControllerManagement implements ControllerManagement {
}
@Override
public boolean hasTargetArtifactAssigned(final Long targetId, final LocalArtifact localArtifact) {
public boolean hasTargetArtifactAssigned(final Long targetId, final Artifact localArtifact) {
final Target target = targetRepository.findOne(targetId);
if (target == null) {
return false;

View File

@@ -14,11 +14,11 @@ import org.apache.commons.lang3.StringUtils;
import org.eclipse.hawkbit.repository.EntityFactory;
import org.eclipse.hawkbit.repository.jpa.model.JpaAction;
import org.eclipse.hawkbit.repository.jpa.model.JpaActionStatus;
import org.eclipse.hawkbit.repository.jpa.model.JpaArtifact;
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet;
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetMetadata;
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetTag;
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetType;
import org.eclipse.hawkbit.repository.jpa.model.JpaLocalArtifact;
import org.eclipse.hawkbit.repository.jpa.model.JpaRollout;
import org.eclipse.hawkbit.repository.jpa.model.JpaRolloutGroup;
import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule;
@@ -30,11 +30,11 @@ import org.eclipse.hawkbit.repository.jpa.model.JpaTargetTag;
import org.eclipse.hawkbit.repository.model.Action;
import org.eclipse.hawkbit.repository.model.Action.Status;
import org.eclipse.hawkbit.repository.model.ActionStatus;
import org.eclipse.hawkbit.repository.model.Artifact;
import org.eclipse.hawkbit.repository.model.DistributionSet;
import org.eclipse.hawkbit.repository.model.DistributionSetMetadata;
import org.eclipse.hawkbit.repository.model.DistributionSetTag;
import org.eclipse.hawkbit.repository.model.DistributionSetType;
import org.eclipse.hawkbit.repository.model.LocalArtifact;
import org.eclipse.hawkbit.repository.model.Rollout;
import org.eclipse.hawkbit.repository.model.RolloutGroup;
import org.eclipse.hawkbit.repository.model.SoftwareModule;
@@ -135,12 +135,13 @@ public class JpaEntityFactory implements EntityFactory {
}
@Override
public TargetFilterQuery generateTargetFilterQuery(String name, String query) {
public TargetFilterQuery generateTargetFilterQuery(final String name, final String query) {
return new JpaTargetFilterQuery(name, query);
}
@Override
public TargetFilterQuery generateTargetFilterQuery(String name, String query, DistributionSet autoAssignDS) {
public TargetFilterQuery generateTargetFilterQuery(final String name, final String query,
final DistributionSet autoAssignDS) {
return new JpaTargetFilterQuery(name, query, (JpaDistributionSet) autoAssignDS);
}
@@ -220,8 +221,8 @@ public class JpaEntityFactory implements EntityFactory {
}
@Override
public LocalArtifact generateLocalArtifact() {
return new JpaLocalArtifact();
public Artifact generateArtifact() {
return new JpaArtifact();
}
}

View File

@@ -45,15 +45,15 @@ import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModuleType;
import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule_;
import org.eclipse.hawkbit.repository.jpa.model.SwMetadataCompositeKey;
import org.eclipse.hawkbit.repository.jpa.rsql.RSQLUtility;
import org.eclipse.hawkbit.repository.rsql.VirtualPropertyReplacer;
import org.eclipse.hawkbit.repository.jpa.specifications.SoftwareModuleSpecification;
import org.eclipse.hawkbit.repository.jpa.specifications.SpecificationsBuilder;
import org.eclipse.hawkbit.repository.model.Artifact;
import org.eclipse.hawkbit.repository.model.AssignedSoftwareModule;
import org.eclipse.hawkbit.repository.model.DistributionSet;
import org.eclipse.hawkbit.repository.model.LocalArtifact;
import org.eclipse.hawkbit.repository.model.SoftwareModule;
import org.eclipse.hawkbit.repository.model.SoftwareModuleMetadata;
import org.eclipse.hawkbit.repository.model.SoftwareModuleType;
import org.eclipse.hawkbit.repository.rsql.VirtualPropertyReplacer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.AuditorAware;
import org.springframework.data.domain.Page;
@@ -178,11 +178,11 @@ public class JpaSoftwareManagement implements SoftwareManagement {
}
@Override
public Slice<SoftwareModule> findSoftwareModulesByType(final Pageable pageable, final SoftwareModuleType type) {
public Slice<SoftwareModule> findSoftwareModulesByType(final Pageable pageable, final Long typeId) {
final List<Specification<JpaSoftwareModule>> specList = new LinkedList<>();
Specification<JpaSoftwareModule> spec = SoftwareModuleSpecification.equalType((JpaSoftwareModuleType) type);
Specification<JpaSoftwareModule> spec = SoftwareModuleSpecification.equalType(typeId);
specList.add(spec);
spec = SoftwareModuleSpecification.isDeletedFalse();
@@ -205,23 +205,11 @@ public class JpaSoftwareManagement implements SoftwareManagement {
return new PageImpl<>(Collections.unmodifiableList(findAll.getContent()), pageable, findAll.getTotalElements());
}
@Override
public Long countSoftwareModulesByType(final SoftwareModuleType type) {
final List<Specification<JpaSoftwareModule>> specList = new ArrayList<>(2);
Specification<JpaSoftwareModule> spec = SoftwareModuleSpecification.equalType((JpaSoftwareModuleType) type);
specList.add(spec);
spec = SoftwareModuleSpecification.isDeletedFalse();
specList.add(spec);
return countSwModuleByCriteriaAPI(specList);
}
@Override
public SoftwareModule findSoftwareModuleById(final Long id) {
return artifactManagement.findSoftwareModuleById(id);
final Specification<JpaSoftwareModule> spec = SoftwareModuleSpecification.byId(id);
return softwareModuleRepository.findOne(spec);
}
@Override
@@ -246,8 +234,8 @@ public class JpaSoftwareManagement implements SoftwareManagement {
}
private void deleteGridFsArtifacts(final JpaSoftwareModule swModule) {
for (final LocalArtifact localArtifact : swModule.getLocalArtifacts()) {
artifactManagement.clearLocalArtifactBinary(localArtifact);
for (final Artifact localArtifact : swModule.getArtifacts()) {
artifactManagement.clearArtifactBinary(localArtifact);
}
}
@@ -311,7 +299,12 @@ public class JpaSoftwareManagement implements SoftwareManagement {
@Override
public SoftwareModule findSoftwareModuleWithDetails(final Long id) {
return artifactManagement.findSoftwareModuleWithDetails(id);
final SoftwareModule result = findSoftwareModuleById(id);
if (result != null) {
result.getArtifacts().size();
}
return result;
}
@Override
@@ -344,7 +337,7 @@ public class JpaSoftwareManagement implements SoftwareManagement {
@Override
public Slice<SoftwareModule> findSoftwareModuleByFilters(final Pageable pageable, final String searchText,
final SoftwareModuleType type) {
final Long typeId) {
final List<Specification<JpaSoftwareModule>> specList = new ArrayList<>(4);
@@ -356,8 +349,8 @@ public class JpaSoftwareManagement implements SoftwareManagement {
specList.add(spec);
}
if (null != type) {
spec = SoftwareModuleSpecification.equalType((JpaSoftwareModuleType) type);
if (null != typeId) {
spec = SoftwareModuleSpecification.equalType(typeId);
specList.add(spec);
}
@@ -375,9 +368,7 @@ public class JpaSoftwareManagement implements SoftwareManagement {
@Override
public Slice<AssignedSoftwareModule> findSoftwareModuleOrderBySetAssignmentAndModuleNameAscModuleVersionAsc(
final Pageable pageable, final Long orderByDistributionId, final String searchText,
final SoftwareModuleType ty) {
final JpaSoftwareModuleType type = (JpaSoftwareModuleType) ty;
final Pageable pageable, final Long orderByDistributionId, final String searchText, final Long typeId) {
final List<AssignedSoftwareModule> resultList = new ArrayList<>();
final int pageSize = pageable.getPageSize();
@@ -391,7 +382,7 @@ public class JpaSoftwareManagement implements SoftwareManagement {
.join(JpaSoftwareModule_.assignedTo);
// build the specifications and then to predicates necessary by the
// given filters
final Predicate[] specPredicate = specificationsToPredicate(buildSpecificationList(searchText, type),
final Predicate[] specPredicate = specificationsToPredicate(buildSpecificationList(searchText, typeId),
assignedRoot, assignedQuery, cb,
cb.equal(assignedDsJoin.get(JpaDistributionSet_.id), orderByDistributionId));
// if we have some predicates then add it to the where clause of the
@@ -422,11 +413,11 @@ public class JpaSoftwareManagement implements SoftwareManagement {
Predicate[] unassignedSpec;
if (!assignedSoftwareModules.isEmpty()) {
unassignedSpec = specificationsToPredicate(buildSpecificationList(searchText, type), unassignedRoot,
unassignedSpec = specificationsToPredicate(buildSpecificationList(searchText, typeId), unassignedRoot,
unassignedQuery, cb, cb.not(unassignedRoot.get(JpaSoftwareModule_.id)
.in(assignedSoftwareModules.stream().map(sw -> sw.getId()).collect(Collectors.toList()))));
} else {
unassignedSpec = specificationsToPredicate(buildSpecificationList(searchText, type), unassignedRoot,
unassignedSpec = specificationsToPredicate(buildSpecificationList(searchText, typeId), unassignedRoot,
unassignedQuery, cb);
}
@@ -443,13 +434,13 @@ public class JpaSoftwareManagement implements SoftwareManagement {
}
private static List<Specification<JpaSoftwareModule>> buildSpecificationList(final String searchText,
final JpaSoftwareModuleType type) {
final Long typeId) {
final List<Specification<JpaSoftwareModule>> specList = new ArrayList<>(3);
if (!Strings.isNullOrEmpty(searchText)) {
specList.add(SoftwareModuleSpecification.likeNameOrVersion(searchText));
}
if (type != null) {
specList.add(SoftwareModuleSpecification.equalType(type));
if (typeId != null) {
specList.add(SoftwareModuleSpecification.equalType(typeId));
}
specList.add(SoftwareModuleSpecification.isDeletedFalse());
return specList;
@@ -464,7 +455,7 @@ public class JpaSoftwareManagement implements SoftwareManagement {
}
@Override
public Long countSoftwareModuleByFilters(final String searchText, final SoftwareModuleType type) {
public Long countSoftwareModuleByFilters(final String searchText, final Long typeId) {
final List<Specification<JpaSoftwareModule>> specList = new ArrayList<>(3);
@@ -476,8 +467,8 @@ public class JpaSoftwareManagement implements SoftwareManagement {
specList.add(spec);
}
if (null != type) {
spec = SoftwareModuleSpecification.equalType((JpaSoftwareModuleType) type);
if (null != typeId) {
spec = SoftwareModuleSpecification.equalType(typeId);
specList.add(spec);
}
@@ -541,13 +532,6 @@ public class JpaSoftwareManagement implements SoftwareManagement {
return softwareModuleRepository.findByAssignedTo(pageable, (JpaDistributionSet) set);
}
@Override
public Page<SoftwareModule> findSoftwareModuleByAssignedToAndType(final Pageable pageable,
final DistributionSet set, final SoftwareModuleType type) {
return softwareModuleRepository.findByAssignedToAndType(pageable, (JpaDistributionSet) set,
(JpaSoftwareModuleType) type);
}
@Override
@Transactional(isolation = Isolation.READ_UNCOMMITTED)
@Modifying
@@ -597,8 +581,8 @@ public class JpaSoftwareManagement implements SoftwareManagement {
@Override
@Transactional(isolation = Isolation.READ_UNCOMMITTED)
@Modifying
public void deleteSoftwareModuleMetadata(final SoftwareModule softwareModule, final String key) {
softwareModuleMetadataRepository.delete(new SwMetadataCompositeKey(softwareModule, key));
public void deleteSoftwareModuleMetadata(final Long moduleId, final String key) {
softwareModuleMetadataRepository.delete(new SwMetadataCompositeKey(moduleId, key));
}
@Override
@@ -635,8 +619,8 @@ public class JpaSoftwareManagement implements SoftwareManagement {
}
@Override
public SoftwareModuleMetadata findSoftwareModuleMetadata(final SoftwareModule softwareModule, final String key) {
return findSoftwareModuleMetadata(new SwMetadataCompositeKey(softwareModule, key));
public SoftwareModuleMetadata findSoftwareModuleMetadata(final Long moduleId, final String key) {
return findSoftwareModuleMetadata(new SwMetadataCompositeKey(moduleId, key));
}
private SoftwareModuleMetadata findSoftwareModuleMetadata(final SwMetadataCompositeKey id) {
@@ -661,8 +645,8 @@ public class JpaSoftwareManagement implements SoftwareManagement {
@Override
@Modifying
@Transactional(isolation = Isolation.READ_UNCOMMITTED)
public void deleteSoftwareModule(final SoftwareModule bsm) {
deleteSoftwareModules(Sets.newHashSet(bsm.getId()));
public void deleteSoftwareModule(final Long moduleId) {
deleteSoftwareModules(Sets.newHashSet(moduleId));
}
@Override

View File

@@ -83,15 +83,9 @@ public class JpaSystemManagement implements CurrentTenantCacheKeyGenerator, Syst
@Autowired
private DistributionSetTagRepository distributionSetTagRepository;
@Autowired
private ExternalArtifactRepository externalArtifactRepository;
@Autowired
private LocalArtifactRepository artifactRepository;
@Autowired
private ExternalArtifactProviderRepository externalArtifactProviderRepository;
@Autowired
private TenantConfigurationRepository tenantConfigurationRepository;
@@ -229,8 +223,6 @@ public class JpaSystemManagement implements CurrentTenantCacheKeyGenerator, Syst
rolloutGroupRepository.deleteByTenantIgnoreCase(tenant);
rolloutRepository.deleteByTenantIgnoreCase(tenant);
artifactRepository.deleteByTenantIgnoreCase(tenant);
externalArtifactRepository.deleteByTenantIgnoreCase(tenant);
externalArtifactProviderRepository.deleteByTenantIgnoreCase(tenant);
targetTagRepository.deleteByTenantIgnoreCase(tenant);
distributionSetTagRepository.deleteByTenantIgnoreCase(tenant);
distributionSetRepository.deleteByTenantIgnoreCase(tenant);

View File

@@ -11,8 +11,8 @@ package org.eclipse.hawkbit.repository.jpa;
import java.util.List;
import java.util.Optional;
import org.eclipse.hawkbit.repository.jpa.model.JpaLocalArtifact;
import org.eclipse.hawkbit.repository.model.LocalArtifact;
import org.eclipse.hawkbit.repository.jpa.model.JpaArtifact;
import org.eclipse.hawkbit.repository.model.Artifact;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;
@@ -20,11 +20,11 @@ import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Transactional;
/**
* {@link LocalArtifact} repository.
* {@link Artifact} repository.
*
*/
@Transactional(readOnly = true, isolation = Isolation.READ_UNCOMMITTED)
public interface LocalArtifactRepository extends BaseEntityRepository<JpaLocalArtifact, Long> {
public interface LocalArtifactRepository extends BaseEntityRepository<JpaArtifact, Long> {
/**
* Counts artifacts size where the related software module is not
@@ -32,7 +32,7 @@ public interface LocalArtifactRepository extends BaseEntityRepository<JpaLocalAr
*
* @return sum of artifacts size in bytes
*/
@Query("SELECT SUM(la.size) FROM JpaLocalArtifact la WHERE la.softwareModule.deleted = 0")
@Query("SELECT SUM(la.size) FROM JpaArtifact la WHERE la.softwareModule.deleted = 0")
Optional<Long> getSumOfUndeletedArtifactSize();
/**
@@ -46,32 +46,31 @@ public interface LocalArtifactRepository extends BaseEntityRepository<JpaLocalAr
Long countBySoftwareModuleDeleted(boolean deleted);
/**
* Searches for a {@link LocalArtifact} based on given gridFsFileName.
* Searches for a {@link Artifact} based on given gridFsFileName.
*
* @param gridFsFileName
* to search
* @return list of {@link LocalArtifact}s.
* @return list of {@link Artifact}s.
*/
List<LocalArtifact> findByGridFsFileName(String gridFsFileName);
List<Artifact> findByGridFsFileName(String gridFsFileName);
/**
* Searches for a {@link LocalArtifact} based on given gridFsFileName.
* Searches for a {@link Artifact} based on given gridFsFileName.
*
* @param gridFsFileName
* to search
* @return {@link LocalArtifact} the first in the result list
* @return {@link Artifact} the first in the result list
*/
JpaLocalArtifact findFirstByGridFsFileName(String gridFsFileName);
JpaArtifact findFirstByGridFsFileName(String gridFsFileName);
/**
* Searches for a {@link LocalArtifact} based user provided filename at
* upload.
* Searches for a {@link Artifact} based user provided filename at upload.
*
* @param filename
* to search
* @return list of {@link LocalArtifact}.
* @return list of {@link Artifact}.
*/
List<LocalArtifact> findByFilename(String filename);
List<Artifact> findByFilename(String filename);
/**
* Searches for local artifact for a base software module.
@@ -81,20 +80,20 @@ public interface LocalArtifactRepository extends BaseEntityRepository<JpaLocalAr
* @param swId
* software module id
*
* @return Page<LocalArtifact>
* @return Page<Artifact>
*/
Page<LocalArtifact> findBySoftwareModuleId(Pageable pageReq, final Long swId);
Page<Artifact> findBySoftwareModuleId(Pageable pageReq, final Long swId);
/**
* Searches for a {@link LocalArtifact} based user provided filename at
* upload and selected software module id.
* Searches for a {@link Artifact} based user provided filename at upload
* and selected software module id.
*
* @param filename
* to search
* @param softwareModuleId
* selected software module id
* @return list of {@link LocalArtifact}.
* @return list of {@link Artifact}.
*/
List<LocalArtifact> findByFilenameAndSoftwareModuleId(final String filename, final Long softwareModuleId);
List<Artifact> findByFilenameAndSoftwareModuleId(final String filename, final Long softwareModuleId);
}

View File

@@ -107,7 +107,7 @@ public interface SoftwareModuleRepository
* @return all {@link SoftwareModule}s that are assigned to given
* {@link DistributionSet} filtered by {@link SoftwareModuleType}.
*/
Page<SoftwareModule> findByAssignedToAndType(Pageable pageable, JpaDistributionSet set, JpaSoftwareModuleType type);
Page<SoftwareModule> findByAssignedToAndType(Pageable pageable, JpaDistributionSet set, SoftwareModuleType type);
/**
* retrieves all software modules with a given {@link SoftwareModuleType}

View File

@@ -1,66 +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.jpa.model;
import javax.persistence.Column;
import javax.persistence.MappedSuperclass;
import org.eclipse.hawkbit.repository.model.Artifact;
import org.eclipse.hawkbit.repository.model.SoftwareModule;
/**
* Tenant specific locally stored artifact representation that is used by
* {@link SoftwareModule}.
*/
@MappedSuperclass
// exception squid:S2160 - BaseEntity equals/hashcode is handling correctly for
// sub entities
@SuppressWarnings("squid:S2160")
public abstract class AbstractJpaArtifact extends AbstractJpaTenantAwareBaseEntity implements Artifact {
private static final long serialVersionUID = 1L;
@Column(name = "sha1_hash", length = 40, nullable = true)
private String sha1Hash;
@Column(name = "md5_hash", length = 32, nullable = true)
private String md5Hash;
@Column(name = "file_size")
private long size;
@Override
public abstract SoftwareModule getSoftwareModule();
@Override
public String getMd5Hash() {
return md5Hash;
}
@Override
public String getSha1Hash() {
return sha1Hash;
}
public void setMd5Hash(final String md5Hash) {
this.md5Hash = md5Hash;
}
public void setSha1Hash(final String sha1Hash) {
this.sha1Hash = sha1Hash;
}
@Override
public long getSize() {
return size;
}
public void setSize(final long size) {
this.size = size;
}
}

View File

@@ -20,7 +20,7 @@ import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import org.eclipse.hawkbit.repository.model.LocalArtifact;
import org.eclipse.hawkbit.repository.model.Artifact;
import org.eclipse.hawkbit.repository.model.SoftwareModule;
import com.mongodb.gridfs.GridFS;
@@ -36,7 +36,7 @@ import com.mongodb.gridfs.GridFSFile;
// exception squid:S2160 - BaseEntity equals/hashcode is handling correctly for
// sub entities
@SuppressWarnings("squid:S2160")
public class JpaLocalArtifact extends AbstractJpaArtifact implements LocalArtifact {
public class JpaArtifact extends AbstractJpaTenantAwareBaseEntity implements Artifact {
private static final long serialVersionUID = 1L;
@NotNull
@@ -53,10 +53,19 @@ public class JpaLocalArtifact extends AbstractJpaArtifact implements LocalArtifa
@JoinColumn(name = "software_module", nullable = false, updatable = false, foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_assigned_sm"))
private JpaSoftwareModule softwareModule;
@Column(name = "sha1_hash", length = 40, nullable = true)
private String sha1Hash;
@Column(name = "md5_hash", length = 32, nullable = true)
private String md5Hash;
@Column(name = "file_size")
private long size;
/**
* Default constructor.
*/
public JpaLocalArtifact() {
public JpaArtifact() {
super();
}
@@ -70,7 +79,7 @@ public class JpaLocalArtifact extends AbstractJpaArtifact implements LocalArtifa
* @param softwareModule
* of this artifact
*/
public JpaLocalArtifact(@NotNull final String gridFsFileName, @NotNull final String filename,
public JpaArtifact(@NotNull final String gridFsFileName, @NotNull final String filename,
final SoftwareModule softwareModule) {
setSoftwareModule(softwareModule);
this.gridFsFileName = gridFsFileName;
@@ -78,23 +87,30 @@ public class JpaLocalArtifact extends AbstractJpaArtifact implements LocalArtifa
}
@Override
public int hashCode() { // NOSONAR - as this is generated
final int prime = 31;
int result = super.hashCode();
result = prime * result + this.getClass().getName().hashCode();
return result;
public String getMd5Hash() {
return md5Hash;
}
@Override
public boolean equals(final Object obj) { // NOSONAR - as this is generated
if (!super.equals(obj)) {
return false;
}
if (!(obj instanceof LocalArtifact)) {
return false;
}
public String getSha1Hash() {
return sha1Hash;
}
return true;
public void setMd5Hash(final String md5Hash) {
this.md5Hash = md5Hash;
}
public void setSha1Hash(final String sha1Hash) {
this.sha1Hash = sha1Hash;
}
@Override
public long getSize() {
return size;
}
public void setSize(final long size) {
this.size = size;
}
@Override

View File

@@ -1,145 +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.jpa.model;
import java.net.URL;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.ConstraintMode;
import javax.persistence.Entity;
import javax.persistence.ForeignKey;
import javax.persistence.Index;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import org.eclipse.hawkbit.repository.model.ExternalArtifact;
import org.eclipse.hawkbit.repository.model.ExternalArtifactProvider;
import org.eclipse.hawkbit.repository.model.SoftwareModule;
/**
* External artifact representation with all the necessary information to
* generate an artifact {@link URL} at runtime.
*
*/
@Table(name = "sp_external_artifact", indexes = {
@Index(name = "sp_idx_external_artifact_prim", columnList = "id,tenant") })
@Entity
// exception squid:S2160 - BaseEntity equals/hashcode is handling correctly for
// sub entities
@SuppressWarnings("squid:S2160")
public class JpaExternalArtifact extends AbstractJpaArtifact implements ExternalArtifact {
private static final long serialVersionUID = 1L;
@ManyToOne
@JoinColumn(name = "provider", nullable = false, updatable = false, foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_art_to_ext_provider"))
private JpaExternalArtifactProvider externalArtifactProvider;
@Column(name = "url_suffix", length = 512)
@Size(max = 512)
private String urlSuffix;
// CascadeType.PERSIST as we register ourself at the BSM
@ManyToOne(optional = false, cascade = { CascadeType.PERSIST })
@JoinColumn(name = "software_module", nullable = false, updatable = false, foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_external_assigned_sm"))
private JpaSoftwareModule softwareModule;
/**
* Default constructor.
*/
public JpaExternalArtifact() {
super();
}
/**
* Constructs {@link ExternalArtifact}.
*
* @param externalArtifactProvider
* of the artifact
* @param urlSuffix
* of the artifact
* @param softwareModule
* of the artifact
*/
public JpaExternalArtifact(@NotNull final ExternalArtifactProvider externalArtifactProvider, final String urlSuffix,
final SoftwareModule softwareModule) {
setSoftwareModule(softwareModule);
this.externalArtifactProvider = (JpaExternalArtifactProvider) externalArtifactProvider;
if (urlSuffix != null) {
this.urlSuffix = urlSuffix;
} else {
this.urlSuffix = externalArtifactProvider.getDefaultSuffix();
}
}
/**
* @return the softwareModule
*/
@Override
public SoftwareModule getSoftwareModule() {
return softwareModule;
}
public final void setSoftwareModule(final SoftwareModule softwareModule) {
this.softwareModule = (JpaSoftwareModule) softwareModule;
this.softwareModule.addArtifact(this);
}
@Override
public ExternalArtifactProvider getExternalArtifactProvider() {
return externalArtifactProvider;
}
@Override
public String getUrl() {
return new StringBuilder().append(externalArtifactProvider.getBasePath()).append(urlSuffix).toString();
}
@Override
public String getUrlSuffix() {
return urlSuffix;
}
public void setExternalArtifactProvider(final JpaExternalArtifactProvider externalArtifactProvider) {
this.externalArtifactProvider = externalArtifactProvider;
}
/**
* @param urlSuffix
* the urlSuffix to set
*/
@Override
public void setUrlSuffix(final String urlSuffix) {
this.urlSuffix = urlSuffix;
}
@Override
public int hashCode() { // NOSONAR - as this is generated
final int prime = 31;
int result = super.hashCode();
result = prime * result + this.getClass().getName().hashCode();
return result;
}
@Override
public boolean equals(final Object obj) { // NOSONAR - as this is generated
if (!super.equals(obj)) {
return false;
}
if (!(obj instanceof JpaExternalArtifact)) {
return false;
}
return true;
}
}

View File

@@ -1,87 +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.jpa.model;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Index;
import javax.persistence.Table;
import javax.validation.constraints.Size;
import org.eclipse.hawkbit.repository.model.ExternalArtifact;
import org.eclipse.hawkbit.repository.model.ExternalArtifactProvider;
/**
* JPA implementation of {@link ExternalArtifactProvider}.
*
*/
@Table(name = "sp_external_provider", indexes = {
@Index(name = "sp_idx_external_provider_prim", columnList = "tenant,id") })
@Entity
// exception squid:S2160 - BaseEntity equals/hashcode is handling correctly for
// sub entities
@SuppressWarnings("squid:S2160")
public class JpaExternalArtifactProvider extends AbstractJpaNamedEntity implements ExternalArtifactProvider {
private static final long serialVersionUID = 1L;
@Column(name = "base_url", length = 512, nullable = false)
@Size(max = 512)
private String basePath;
@Column(name = "default_url_suffix", length = 512, nullable = true)
@Size(max = 512)
private String defaultSuffix;
/**
* Constructs {@link ExternalArtifactProvider} based on given properties.
*
* @param name
* of the provided
* @param description
* which is optional
* @param baseURL
* of all {@link ExternalArtifact}s of the provider
* @param defaultUrlSuffix
* that is used if {@link ExternalArtifact#getUrlSuffix()} is
* empty.
*/
public JpaExternalArtifactProvider(final String name, final String description, final String baseURL,
final String defaultUrlSuffix) {
super(name, description);
basePath = baseURL;
defaultSuffix = defaultUrlSuffix;
}
JpaExternalArtifactProvider() {
super();
defaultSuffix = "";
basePath = "";
}
@Override
public String getBasePath() {
return basePath;
}
@Override
public String getDefaultSuffix() {
return defaultSuffix;
}
@Override
public void setBasePath(final String basePath) {
this.basePath = basePath;
}
@Override
public void setDefaultSuffix(final String defaultSuffix) {
this.defaultSuffix = defaultSuffix;
}
}

View File

@@ -10,9 +10,7 @@ package org.eclipse.hawkbit.repository.jpa.model;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.Optional;
import javax.persistence.CascadeType;
import javax.persistence.Column;
@@ -34,15 +32,11 @@ import javax.validation.constraints.Size;
import org.eclipse.hawkbit.repository.model.Artifact;
import org.eclipse.hawkbit.repository.model.DistributionSet;
import org.eclipse.hawkbit.repository.model.ExternalArtifact;
import org.eclipse.hawkbit.repository.model.LocalArtifact;
import org.eclipse.hawkbit.repository.model.SoftwareModule;
import org.eclipse.hawkbit.repository.model.SoftwareModuleMetadata;
import org.eclipse.hawkbit.repository.model.SoftwareModuleType;
import org.eclipse.persistence.annotations.CascadeOnDelete;
import com.google.common.collect.Lists;
/**
* Base Software Module that is supported by OS level provisioning mechanism on
* the edge controller, e.g. OS, JVM, AgentHub.
@@ -77,12 +71,8 @@ public class JpaSoftwareModule extends AbstractJpaNamedVersionedEntity implement
private String vendor;
@CascadeOnDelete
@OneToMany(mappedBy = "softwareModule", cascade = { CascadeType.ALL }, targetEntity = JpaLocalArtifact.class)
private List<LocalArtifact> artifacts;
@CascadeOnDelete
@OneToMany(mappedBy = "softwareModule", cascade = { CascadeType.ALL }, targetEntity = JpaExternalArtifact.class)
private List<ExternalArtifact> externalArtifacts;
@OneToMany(mappedBy = "softwareModule", cascade = { CascadeType.ALL }, targetEntity = JpaArtifact.class)
private List<Artifact> artifacts;
@CascadeOnDelete
@OneToMany(fetch = FetchType.LAZY, cascade = { CascadeType.REMOVE }, targetEntity = JpaSoftwareModuleMetadata.class)
@@ -122,7 +112,7 @@ public class JpaSoftwareModule extends AbstractJpaNamedVersionedEntity implement
* is added to the assigned {@link Artifact}s.
*/
@Override
public void addArtifact(final LocalArtifact artifact) {
public void addArtifact(final Artifact artifact) {
if (null == artifacts) {
artifacts = new ArrayList<>(4);
artifacts.add(artifact);
@@ -134,72 +124,16 @@ public class JpaSoftwareModule extends AbstractJpaNamedVersionedEntity implement
}
}
/**
* @param artifact
* is added to the assigned {@link Artifact}s.
*/
@Override
public void addArtifact(final ExternalArtifact artifact) {
if (null == externalArtifacts) {
externalArtifacts = new LinkedList<>();
externalArtifacts.add(artifact);
return;
}
if (!externalArtifacts.contains(artifact)) {
externalArtifacts.add(artifact);
}
}
@Override
public Optional<LocalArtifact> getLocalArtifact(final Long artifactId) {
if (artifacts == null) {
return Optional.empty();
}
return artifacts.stream().filter(artifact -> artifact.getId().equals(artifactId)).findFirst();
}
@Override
public Optional<LocalArtifact> getLocalArtifactByFilename(final String fileName) {
if (artifacts == null) {
return Optional.empty();
}
return artifacts.stream().filter(artifact -> artifact.getFilename().equalsIgnoreCase(fileName.trim()))
.findFirst();
}
/**
* @return the artifacts
*/
@Override
public List<Artifact> getArtifacts() {
if (artifacts == null && externalArtifacts == null) {
return Collections.emptyList();
} else if (artifacts == null) {
return Collections.unmodifiableList(externalArtifacts);
} else if (externalArtifacts == null) {
return Collections.unmodifiableList(artifacts);
}
final List<Artifact> result = Lists.newLinkedList(artifacts);
result.addAll(externalArtifacts);
return Collections.unmodifiableList(result);
}
/**
* @return local artifacts only
*/
@Override
public List<LocalArtifact> getLocalArtifacts() {
if (artifacts == null) {
return Collections.emptyList();
}
return artifacts;
return Collections.unmodifiableList(artifacts);
}
@Override
@@ -212,23 +146,12 @@ public class JpaSoftwareModule extends AbstractJpaNamedVersionedEntity implement
* is removed from the assigned {@link LocalArtifact}s.
*/
@Override
public void removeArtifact(final LocalArtifact artifact) {
public void removeArtifact(final Artifact artifact) {
if (artifacts != null) {
artifacts.remove(artifact);
}
}
/**
* @param artifact
* is removed from the assigned {@link ExternalArtifact}s.
*/
@Override
public void removeArtifact(final ExternalArtifact artifact) {
if (externalArtifacts != null) {
externalArtifacts.remove(artifact);
}
}
@Override
public void setVendor(final String vendor) {
this.vendor = vendor;

View File

@@ -46,7 +46,7 @@ public class JpaSoftwareModuleMetadata extends AbstractJpaMetaData implements So
}
public SwMetadataCompositeKey getId() {
return new SwMetadataCompositeKey(softwareModule, getKey());
return new SwMetadataCompositeKey(softwareModule.getId(), getKey());
}
@Override

View File

@@ -10,8 +10,6 @@ package org.eclipse.hawkbit.repository.jpa.model;
import java.io.Serializable;
import org.eclipse.hawkbit.repository.model.SoftwareModule;
/**
* The Software Module meta data composite key which contains the meta data key
* and the ID of the software module itself.
@@ -31,13 +29,13 @@ public final class SwMetadataCompositeKey implements Serializable {
}
/**
* @param softwareModule
* @param moduleId
* the software module for this meta data
* @param key
* the key of the meta data
*/
public SwMetadataCompositeKey(final SoftwareModule softwareModule, final String key) {
this.softwareModule = softwareModule.getId();
public SwMetadataCompositeKey(final Long moduleId, final String key) {
this.softwareModule = moduleId;
this.key = key;
}

View File

@@ -14,14 +14,14 @@ import javax.persistence.criteria.SetJoin;
import org.eclipse.hawkbit.repository.jpa.model.JpaAction;
import org.eclipse.hawkbit.repository.jpa.model.JpaAction_;
import org.eclipse.hawkbit.repository.jpa.model.JpaArtifact;
import org.eclipse.hawkbit.repository.jpa.model.JpaArtifact_;
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet;
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet_;
import org.eclipse.hawkbit.repository.jpa.model.JpaLocalArtifact;
import org.eclipse.hawkbit.repository.jpa.model.JpaLocalArtifact_;
import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule;
import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule_;
import org.eclipse.hawkbit.repository.model.Action;
import org.eclipse.hawkbit.repository.model.LocalArtifact;
import org.eclipse.hawkbit.repository.model.Artifact;
import org.eclipse.hawkbit.repository.model.Target;
import org.springframework.data.jpa.domain.Specification;
@@ -50,14 +50,14 @@ public final class ActionSpecifications {
* @return a specification to use with spring JPA
*/
public static Specification<JpaAction> hasTargetAssignedArtifact(final Target target,
final LocalArtifact localArtifact) {
final Artifact localArtifact) {
return (actionRoot, query, criteriaBuilder) -> {
final Join<JpaAction, JpaDistributionSet> dsJoin = actionRoot.join(JpaAction_.distributionSet);
final SetJoin<JpaDistributionSet, JpaSoftwareModule> modulesJoin = dsJoin.join(JpaDistributionSet_.modules);
final ListJoin<JpaSoftwareModule, JpaLocalArtifact> artifactsJoin = modulesJoin
final ListJoin<JpaSoftwareModule, JpaArtifact> artifactsJoin = modulesJoin
.join(JpaSoftwareModule_.artifacts);
return criteriaBuilder.and(
criteriaBuilder.equal(artifactsJoin.get(JpaLocalArtifact_.filename), localArtifact.getFilename()),
criteriaBuilder.equal(artifactsJoin.get(JpaArtifact_.filename), localArtifact.getFilename()),
criteriaBuilder.equal(actionRoot.get(JpaAction_.target), target));
};
}

View File

@@ -13,6 +13,7 @@ import javax.persistence.criteria.Predicate;
import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule;
import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModuleType;
import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModuleType_;
import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule_;
import org.eclipse.hawkbit.repository.model.SoftwareModule;
import org.springframework.data.jpa.domain.Specification;
@@ -39,7 +40,7 @@ public final class SoftwareModuleSpecification {
return (targetRoot, query, cb) -> {
final Predicate predicate = cb.equal(targetRoot.<Long> get(JpaSoftwareModule_.id), moduleId);
targetRoot.fetch(JpaSoftwareModule_.type);
targetRoot.fetch(JpaSoftwareModule_.metadata,JoinType.LEFT);
targetRoot.fetch(JpaSoftwareModule_.metadata, JoinType.LEFT);
query.distinct(true);
return predicate;
};
@@ -77,9 +78,9 @@ public final class SoftwareModuleSpecification {
* to be filtered on
* @return the {@link SoftwareModule} {@link Specification}
*/
public static Specification<JpaSoftwareModule> equalType(final JpaSoftwareModuleType type) {
return (targetRoot, query, cb) -> cb.equal(targetRoot.<JpaSoftwareModuleType> get(JpaSoftwareModule_.type),
type);
public static Specification<JpaSoftwareModule> equalType(final Long type) {
return (targetRoot, query, cb) -> cb.equal(
targetRoot.<JpaSoftwareModuleType> get(JpaSoftwareModule_.type).get(JpaSoftwareModuleType_.id), type);
}
}

View File

@@ -0,0 +1,2 @@
DROP TABLE sp_external_provider;
DROP TABLE sp_external_artifact;

View File

@@ -0,0 +1,2 @@
DROP TABLE sp_external_provider;
DROP TABLE sp_external_artifact;

View File

@@ -56,9 +56,6 @@ public abstract class AbstractJpaIntegrationTest extends AbstractIntegrationTest
@Autowired
protected ActionStatusRepository actionStatusRepository;
@Autowired
protected ExternalArtifactRepository externalArtifactRepository;
@Autowired
protected LocalArtifactRepository artifactRepository;

View File

@@ -55,9 +55,6 @@ public abstract class AbstractJpaIntegrationTestWithMongoDB extends AbstractInte
@Autowired
protected ActionStatusRepository actionStatusRepository;
@Autowired
protected ExternalArtifactRepository externalArtifactRepository;
@Autowired
protected LocalArtifactRepository artifactRepository;

View File

@@ -40,22 +40,21 @@ public class ArtifactManagementFailedMongoDBTest extends AbstractJpaIntegrationT
"version 1", null, null);
sm = softwareModuleRepository.save(sm);
final Artifact result = artifactManagement.createLocalArtifact(new RandomGeneratedInputStream(5 * 1024),
sm.getId(), "file1", false);
final Artifact result = artifactManagement.createArtifact(new RandomGeneratedInputStream(5 * 1024), sm.getId(),
"file1", false);
assertThat(artifactRepository.findAll()).hasSize(1);
mongodExecutable.stop();
try {
artifactManagement.deleteLocalArtifact(result.getId());
artifactManagement.deleteArtifact(result.getId());
fail("deletion should have failed");
} catch (final ArtifactDeleteFailedException e) {
}
try {
artifactManagement.createLocalArtifact(new RandomGeneratedInputStream(5 * 1024), sm.getId(), "file2",
false);
artifactManagement.createArtifact(new RandomGeneratedInputStream(5 * 1024), sm.getId(), "file2", false);
fail("Should not have worked with MongoDb down.");
} catch (final ArtifactUploadFailedException e) {

View File

@@ -9,7 +9,6 @@
package org.eclipse.hawkbit.repository.jpa;
import static org.fest.assertions.api.Assertions.assertThat;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
@@ -22,13 +21,9 @@ import org.apache.commons.lang3.RandomStringUtils;
import org.eclipse.hawkbit.im.authentication.SpPermission;
import org.eclipse.hawkbit.repository.ArtifactManagement;
import org.eclipse.hawkbit.repository.exception.InsufficientPermissionException;
import org.eclipse.hawkbit.repository.jpa.model.JpaExternalArtifact;
import org.eclipse.hawkbit.repository.jpa.model.JpaExternalArtifactProvider;
import org.eclipse.hawkbit.repository.jpa.model.JpaLocalArtifact;
import org.eclipse.hawkbit.repository.jpa.model.JpaArtifact;
import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule;
import org.eclipse.hawkbit.repository.model.Artifact;
import org.eclipse.hawkbit.repository.model.ExternalArtifactProvider;
import org.eclipse.hawkbit.repository.model.LocalArtifact;
import org.eclipse.hawkbit.repository.model.SoftwareModule;
import org.eclipse.hawkbit.repository.test.util.HashGeneratorUtils;
import org.eclipse.hawkbit.repository.test.util.WithUser;
@@ -57,7 +52,7 @@ public class ArtifactManagementTest extends AbstractJpaIntegrationTestWithMongoD
/**
* Test method for
* {@link org.eclipse.hawkbit.repository.ArtifactManagement#createLocalArtifact(java.io.InputStream)}
* {@link org.eclipse.hawkbit.repository.ArtifactManagement#createArtifact(java.io.InputStream)}
* .
*
* @throws IOException
@@ -65,7 +60,7 @@ public class ArtifactManagementTest extends AbstractJpaIntegrationTestWithMongoD
*/
@Test
@Description("Test if a local artifact can be created by API including metadata.")
public void createLocalArtifact() throws NoSuchAlgorithmException, IOException {
public void createArtifact() throws NoSuchAlgorithmException, IOException {
// checkbaseline
assertThat(softwareModuleRepository.findAll()).hasSize(0);
assertThat(artifactRepository.findAll()).hasSize(0);
@@ -84,27 +79,26 @@ public class ArtifactManagementTest extends AbstractJpaIntegrationTestWithMongoD
final byte random[] = RandomStringUtils.random(5 * 1024).getBytes();
final Artifact result = artifactManagement.createLocalArtifact(new ByteArrayInputStream(random), sm.getId(),
"file1", false);
final Artifact result11 = artifactManagement.createLocalArtifact(new ByteArrayInputStream(random), sm.getId(),
final Artifact result = artifactManagement.createArtifact(new ByteArrayInputStream(random), sm.getId(), "file1",
false);
final Artifact result11 = artifactManagement.createArtifact(new ByteArrayInputStream(random), sm.getId(),
"file11", false);
final Artifact result12 = artifactManagement.createLocalArtifact(new ByteArrayInputStream(random), sm.getId(),
final Artifact result12 = artifactManagement.createArtifact(new ByteArrayInputStream(random), sm.getId(),
"file12", false);
final Artifact result2 = artifactManagement.createLocalArtifact(new ByteArrayInputStream(random), sm2.getId(),
final Artifact result2 = artifactManagement.createArtifact(new ByteArrayInputStream(random), sm2.getId(),
"file2", false);
assertThat(result).isInstanceOf(LocalArtifact.class);
assertThat(result).isInstanceOf(Artifact.class);
assertThat(result.getSoftwareModule().getId()).isEqualTo(sm.getId());
assertThat(result2.getSoftwareModule().getId()).isEqualTo(sm2.getId());
assertThat(((JpaLocalArtifact) result).getFilename()).isEqualTo("file1");
assertThat(((JpaLocalArtifact) result).getGridFsFileName()).isNotNull();
assertThat(((JpaArtifact) result).getFilename()).isEqualTo("file1");
assertThat(((JpaArtifact) result).getGridFsFileName()).isNotNull();
assertThat(result).isNotEqualTo(result2);
assertThat(((JpaLocalArtifact) result).getGridFsFileName())
.isEqualTo(((JpaLocalArtifact) result2).getGridFsFileName());
assertThat(((JpaArtifact) result).getGridFsFileName()).isEqualTo(((JpaArtifact) result2).getGridFsFileName());
assertThat(artifactManagement.findLocalArtifactByFilename("file1").get(0).getSha1Hash())
assertThat(artifactManagement.findArtifactByFilename("file1").get(0).getSha1Hash())
.isEqualTo(HashGeneratorUtils.generateSHA1(random));
assertThat(artifactManagement.findLocalArtifactByFilename("file1").get(0).getMd5Hash())
assertThat(artifactManagement.findArtifactByFilename("file1").get(0).getMd5Hash())
.isEqualTo(HashGeneratorUtils.generateMD5(random));
assertThat(artifactRepository.findAll()).hasSize(4);
@@ -122,7 +116,7 @@ public class ArtifactManagementTest extends AbstractJpaIntegrationTestWithMongoD
final byte random[] = RandomStringUtils.random(5 * 1024).getBytes();
artifactManagement.createLocalArtifact(new ByteArrayInputStream(random), sm.getId(), "file1", false);
artifactManagement.createArtifact(new ByteArrayInputStream(random), sm.getId(), "file1", false);
assertThat(artifactRepository.findAll()).hasSize(1);
softwareModuleRepository.deleteAll();
@@ -131,63 +125,7 @@ public class ArtifactManagementTest extends AbstractJpaIntegrationTestWithMongoD
/**
* Test method for
* {@link org.eclipse.hawkbit.repository.ArtifactManagement#createExternalArtifact(org.eclipse.hawkbit.repository.model.ExternalArtifactProvider, java.lang.String)}
* .
*/
@Test
@Description("Tests the creation of an external artifact metadata element.")
public void createExternalArtifact() {
JpaSoftwareModule sm = new JpaSoftwareModule(softwareManagement.findSoftwareModuleTypeByKey("os"), "name 1",
"version 1", null, null);
sm = softwareModuleRepository.save(sm);
JpaSoftwareModule sm2 = new JpaSoftwareModule(softwareManagement.findSoftwareModuleTypeByKey("os"), "name 2",
"version 2", null, null);
sm2 = softwareModuleRepository.save(sm2);
final ExternalArtifactProvider provider = artifactManagement.createExternalArtifactProvider("provider X", null,
"https://fhghdfjgh", "/{version}/");
JpaExternalArtifact result = (JpaExternalArtifact) artifactManagement.createExternalArtifact(provider, null,
sm.getId());
assertNotNull("The result of an external artifact should not be null", result);
assertThat(externalArtifactRepository.findAll()).contains(result).hasSize(1);
assertThat(result.getSoftwareModule().getId()).isEqualTo(sm.getId());
assertThat(result.getUrl()).isEqualTo("https://fhghdfjgh/{version}/");
assertThat(result.getExternalArtifactProvider()).isEqualTo(provider);
result = (JpaExternalArtifact) artifactManagement.createExternalArtifact(provider, "/test", sm2.getId());
assertNotNull("The newly created external artifact should not be null", result);
assertThat(externalArtifactRepository.findAll()).contains(result).hasSize(2);
assertThat(result.getUrl()).isEqualTo("https://fhghdfjgh/test");
assertThat(result.getExternalArtifactProvider()).isEqualTo(provider);
}
@Test
@Description("Tests deletio of an external artifact metadata element.")
public void deleteExternalArtifact() {
assertThat(artifactRepository.findAll()).isEmpty();
JpaSoftwareModule sm = new JpaSoftwareModule(softwareManagement.findSoftwareModuleTypeByKey("os"), "name 1",
"version 1", null, null);
sm = softwareModuleRepository.save(sm);
final JpaExternalArtifactProvider provider = (JpaExternalArtifactProvider) artifactManagement
.createExternalArtifactProvider("provider X", null, "https://fhghdfjgh", "/{version}/");
final JpaExternalArtifact result = (JpaExternalArtifact) artifactManagement.createExternalArtifact(provider,
null, sm.getId());
assertNotNull("The newly created external artifact should not be null", result);
assertThat(externalArtifactRepository.findAll()).contains(result).hasSize(1);
artifactManagement.deleteExternalArtifact(result.getId());
assertThat(externalArtifactRepository.findAll()).isEmpty();
}
/**
* Test method for
* {@link org.eclipse.hawkbit.repository.ArtifactManagement#deleteLocalArtifact(java.lang.Long)}
* {@link org.eclipse.hawkbit.repository.ArtifactManagement#deleteArtifact(java.lang.Long)}
* .
*
* @throws IOException
@@ -195,7 +133,7 @@ public class ArtifactManagementTest extends AbstractJpaIntegrationTestWithMongoD
*/
@Test
@Description("Tests the deletion of a local artifact including metadata.")
public void deleteLocalArtifact() throws NoSuchAlgorithmException, IOException {
public void deleteArtifact() throws NoSuchAlgorithmException, IOException {
JpaSoftwareModule sm = new JpaSoftwareModule(softwareManagement.findSoftwareModuleTypeByKey("os"), "name 1",
"version 1", null, null);
sm = softwareModuleRepository.save(sm);
@@ -206,34 +144,35 @@ public class ArtifactManagementTest extends AbstractJpaIntegrationTestWithMongoD
assertThat(artifactRepository.findAll()).isEmpty();
final Artifact result = artifactManagement.createLocalArtifact(new RandomGeneratedInputStream(5 * 1024),
sm.getId(), "file1", false);
final Artifact result2 = artifactManagement.createLocalArtifact(new RandomGeneratedInputStream(5 * 1024),
final Artifact result = artifactManagement.createArtifact(new RandomGeneratedInputStream(5 * 1024), sm.getId(),
"file1", false);
final Artifact result2 = artifactManagement.createArtifact(new RandomGeneratedInputStream(5 * 1024),
sm2.getId(), "file2", false);
assertThat(artifactRepository.findAll()).hasSize(2);
assertThat(result.getId()).isNotNull();
assertThat(result2.getId()).isNotNull();
assertThat(((JpaLocalArtifact) result).getGridFsFileName())
.isNotEqualTo(((JpaLocalArtifact) result2).getGridFsFileName());
assertThat(operations.findOne(new Query()
.addCriteria(Criteria.where("filename").is(((JpaLocalArtifact) result).getGridFsFileName()))))
assertThat(((JpaArtifact) result).getGridFsFileName())
.isNotEqualTo(((JpaArtifact) result2).getGridFsFileName());
assertThat(operations.findOne(
new Query().addCriteria(Criteria.where("filename").is(((JpaArtifact) result).getGridFsFileName()))))
.isNotNull();
assertThat(operations.findOne(new Query()
.addCriteria(Criteria.where("filename").is(((JpaLocalArtifact) result2).getGridFsFileName()))))
assertThat(operations.findOne(
new Query().addCriteria(Criteria.where("filename").is(((JpaArtifact) result2).getGridFsFileName()))))
.isNotNull();
artifactManagement.deleteLocalArtifact(result.getId());
assertThat(operations.findOne(new Query()
.addCriteria(Criteria.where("filename").is(((JpaLocalArtifact) result).getGridFsFileName())))).isNull();
assertThat(operations.findOne(new Query()
.addCriteria(Criteria.where("filename").is(((JpaLocalArtifact) result2).getGridFsFileName()))))
artifactManagement.deleteArtifact(result.getId());
assertThat(operations.findOne(
new Query().addCriteria(Criteria.where("filename").is(((JpaArtifact) result).getGridFsFileName()))))
.isNull();
assertThat(operations.findOne(
new Query().addCriteria(Criteria.where("filename").is(((JpaArtifact) result2).getGridFsFileName()))))
.isNotNull();
artifactManagement.deleteLocalArtifact(result2.getId());
assertThat(operations.findOne(new Query()
.addCriteria(Criteria.where("filename").is(((JpaLocalArtifact) result2).getGridFsFileName()))))
artifactManagement.deleteArtifact(result2.getId());
assertThat(operations.findOne(
new Query().addCriteria(Criteria.where("filename").is(((JpaArtifact) result2).getGridFsFileName()))))
.isNull();
assertThat(artifactRepository.findAll()).hasSize(0);
@@ -253,33 +192,33 @@ public class ArtifactManagementTest extends AbstractJpaIntegrationTestWithMongoD
final byte random[] = RandomStringUtils.random(5 * 1024).getBytes();
final Artifact result = artifactManagement.createLocalArtifact(new ByteArrayInputStream(random), sm.getId(),
"file1", false);
final Artifact result2 = artifactManagement.createLocalArtifact(new ByteArrayInputStream(random), sm2.getId(),
final Artifact result = artifactManagement.createArtifact(new ByteArrayInputStream(random), sm.getId(), "file1",
false);
final Artifact result2 = artifactManagement.createArtifact(new ByteArrayInputStream(random), sm2.getId(),
"file2", false);
assertThat(artifactRepository.findAll()).hasSize(2);
assertThat(result.getId()).isNotNull();
assertThat(result2.getId()).isNotNull();
assertThat(((JpaLocalArtifact) result).getGridFsFileName())
.isEqualTo(((JpaLocalArtifact) result2).getGridFsFileName());
assertThat(((JpaArtifact) result).getGridFsFileName()).isEqualTo(((JpaArtifact) result2).getGridFsFileName());
assertThat(operations.findOne(new Query()
.addCriteria(Criteria.where("filename").is(((JpaLocalArtifact) result).getGridFsFileName()))))
assertThat(operations.findOne(
new Query().addCriteria(Criteria.where("filename").is(((JpaArtifact) result).getGridFsFileName()))))
.isNotNull();
artifactManagement.deleteLocalArtifact(result.getId());
assertThat(operations.findOne(new Query()
.addCriteria(Criteria.where("filename").is(((JpaLocalArtifact) result).getGridFsFileName()))))
artifactManagement.deleteArtifact(result.getId());
assertThat(operations.findOne(
new Query().addCriteria(Criteria.where("filename").is(((JpaArtifact) result).getGridFsFileName()))))
.isNotNull();
artifactManagement.deleteLocalArtifact(result2.getId());
assertThat(operations.findOne(new Query()
.addCriteria(Criteria.where("filename").is(((JpaLocalArtifact) result).getGridFsFileName())))).isNull();
artifactManagement.deleteArtifact(result2.getId());
assertThat(operations.findOne(
new Query().addCriteria(Criteria.where("filename").is(((JpaArtifact) result).getGridFsFileName()))))
.isNull();
}
/**
* Test method for
* {@link org.eclipse.hawkbit.repository.ArtifactManagement#findLocalArtifact(java.lang.Long)}
* {@link org.eclipse.hawkbit.repository.ArtifactManagement#findArtifact(java.lang.Long)}
* .
*
* @throws IOException
@@ -287,20 +226,20 @@ public class ArtifactManagementTest extends AbstractJpaIntegrationTestWithMongoD
*/
@Test
@Description("Loads an local artifact based on given ID.")
public void findLocalArtifact() throws NoSuchAlgorithmException, IOException {
public void findArtifact() throws NoSuchAlgorithmException, IOException {
SoftwareModule sm = new JpaSoftwareModule(softwareManagement.findSoftwareModuleTypeByKey("os"), "name 1",
"version 1", null, null);
sm = softwareManagement.createSoftwareModule(sm);
final LocalArtifact result = artifactManagement.createLocalArtifact(new RandomGeneratedInputStream(5 * 1024),
sm.getId(), "file1", false);
final Artifact result = artifactManagement.createArtifact(new RandomGeneratedInputStream(5 * 1024), sm.getId(),
"file1", false);
assertThat(artifactManagement.findLocalArtifact(result.getId())).isEqualTo(result);
assertThat(artifactManagement.findArtifact(result.getId())).isEqualTo(result);
}
/**
* Test method for
* {@link org.eclipse.hawkbit.repository.ArtifactManagement#loadLocalArtifactBinary(java.lang.Long)}
* {@link org.eclipse.hawkbit.repository.ArtifactManagement#loadArtifactBinary(java.lang.Long)}
* .
*
* @throws IOException
@@ -308,26 +247,26 @@ public class ArtifactManagementTest extends AbstractJpaIntegrationTestWithMongoD
*/
@Test
@Description("Loads an artifact binary based on given ID.")
public void loadStreamOfLocalArtifact() throws NoSuchAlgorithmException, IOException {
public void loadStreamOfArtifact() throws NoSuchAlgorithmException, IOException {
SoftwareModule sm = new JpaSoftwareModule(softwareManagement.findSoftwareModuleTypeByKey("os"), "name 1",
"version 1", null, null);
sm = softwareManagement.createSoftwareModule(sm);
final byte random[] = RandomStringUtils.random(5 * 1024).getBytes();
final LocalArtifact result = artifactManagement.createLocalArtifact(new ByteArrayInputStream(random),
sm.getId(), "file1", false);
final Artifact result = artifactManagement.createArtifact(new ByteArrayInputStream(random), sm.getId(), "file1",
false);
assertTrue("The stored binary matches the given binary", IOUtils.contentEquals(new ByteArrayInputStream(random),
artifactManagement.loadLocalArtifactBinary(result).getFileInputStream()));
artifactManagement.loadArtifactBinary(result).getFileInputStream()));
}
@Test
@WithUser(allSpPermissions = true, removeFromAllPermission = { SpPermission.DOWNLOAD_REPOSITORY_ARTIFACT })
@Description("Trys and fails to load an artifact without required permission. Checks if expected InsufficientPermissionException is thrown.")
public void loadLocalArtifactBinaryWithoutDownloadArtifactThrowsPermissionDenied() {
public void loadArtifactBinaryWithoutDownloadArtifactThrowsPermissionDenied() {
try {
artifactManagement.loadLocalArtifactBinary(new JpaLocalArtifact());
artifactManagement.loadArtifactBinary(new JpaArtifact());
fail("Should not have worked with missing permission.");
} catch (final InsufficientPermissionException e) {
@@ -336,19 +275,19 @@ public class ArtifactManagementTest extends AbstractJpaIntegrationTestWithMongoD
@Test
@Description("Searches an artifact through the relations of a software module.")
public void findLocalArtifactBySoftwareModule() {
public void findArtifactBySoftwareModule() {
SoftwareModule sm = new JpaSoftwareModule(osType, "name 1", "version 1", null, null);
sm = softwareManagement.createSoftwareModule(sm);
SoftwareModule sm2 = new JpaSoftwareModule(osType, "name 2", "version 2", null, null);
sm2 = softwareManagement.createSoftwareModule(sm2);
assertThat(artifactManagement.findLocalArtifactBySoftwareModule(pageReq, sm.getId())).isEmpty();
assertThat(artifactManagement.findArtifactBySoftwareModule(pageReq, sm.getId())).isEmpty();
final Artifact result = artifactManagement.createLocalArtifact(new RandomGeneratedInputStream(5 * 1024),
sm.getId(), "file1", false);
final Artifact result = artifactManagement.createArtifact(new RandomGeneratedInputStream(5 * 1024), sm.getId(),
"file1", false);
assertThat(artifactManagement.findLocalArtifactBySoftwareModule(pageReq, sm.getId())).hasSize(1);
assertThat(artifactManagement.findArtifactBySoftwareModule(pageReq, sm.getId())).hasSize(1);
}
@Test
@@ -359,8 +298,8 @@ public class ArtifactManagementTest extends AbstractJpaIntegrationTestWithMongoD
assertThat(artifactManagement.findByFilenameAndSoftwareModule("file1", sm.getId())).isEmpty();
artifactManagement.createLocalArtifact(new RandomGeneratedInputStream(5 * 1024), sm.getId(), "file1", false);
artifactManagement.createLocalArtifact(new RandomGeneratedInputStream(5 * 1024), sm.getId(), "file2", false);
artifactManagement.createArtifact(new RandomGeneratedInputStream(5 * 1024), sm.getId(), "file1", false);
artifactManagement.createArtifact(new RandomGeneratedInputStream(5 * 1024), sm.getId(), "file2", false);
assertThat(artifactManagement.findByFilenameAndSoftwareModule("file1", sm.getId())).hasSize(1);

View File

@@ -24,9 +24,9 @@ import javax.validation.ConstraintViolationException;
import org.apache.commons.lang3.RandomUtils;
import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException;
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
import org.eclipse.hawkbit.repository.jpa.model.JpaArtifact;
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet;
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetType;
import org.eclipse.hawkbit.repository.jpa.model.JpaLocalArtifact;
import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule;
import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModuleMetadata;
import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModuleType;
@@ -237,24 +237,29 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTestWithMongoD
ds = (JpaDistributionSet) assignSet(target, ds).getDistributionSet();
// standard searches
assertThat(softwareManagement.findSoftwareModuleByFilters(pageReq, "poky", osType).getContent()).hasSize(1);
assertThat(softwareManagement.findSoftwareModuleByFilters(pageReq, "poky", osType).getContent().get(0))
.isEqualTo(os);
assertThat(softwareManagement.findSoftwareModuleByFilters(pageReq, "oracle%", runtimeType).getContent())
assertThat(softwareManagement.findSoftwareModuleByFilters(pageReq, "poky", osType.getId()).getContent())
.hasSize(1);
assertThat(softwareManagement.findSoftwareModuleByFilters(pageReq, "oracle%", runtimeType).getContent().get(0))
.isEqualTo(jvm);
assertThat(softwareManagement.findSoftwareModuleByFilters(pageReq, "1.0.1", appType).getContent()).hasSize(1);
assertThat(softwareManagement.findSoftwareModuleByFilters(pageReq, "1.0.1", appType).getContent().get(0))
.isEqualTo(ah);
assertThat(softwareManagement.findSoftwareModuleByFilters(pageReq, "1.0%", appType).getContent()).hasSize(2);
assertThat(softwareManagement.findSoftwareModuleByFilters(pageReq, "poky", osType.getId()).getContent().get(0))
.isEqualTo(os);
assertThat(softwareManagement.findSoftwareModuleByFilters(pageReq, "oracle%", runtimeType.getId()).getContent())
.hasSize(1);
assertThat(softwareManagement.findSoftwareModuleByFilters(pageReq, "oracle%", runtimeType.getId()).getContent()
.get(0)).isEqualTo(jvm);
assertThat(softwareManagement.findSoftwareModuleByFilters(pageReq, "1.0.1", appType.getId()).getContent())
.hasSize(1);
assertThat(
softwareManagement.findSoftwareModuleByFilters(pageReq, "1.0.1", appType.getId()).getContent().get(0))
.isEqualTo(ah);
assertThat(softwareManagement.findSoftwareModuleByFilters(pageReq, "1.0%", appType.getId()).getContent())
.hasSize(2);
// no we search with on entity marked as deleted
softwareManagement.deleteSoftwareModule(
softwareManagement.findSoftwareModuleByAssignedToAndType(pageReq, ds, appType).getContent().get(0));
softwareModuleRepository.findByAssignedToAndType(pageReq, ds, appType).getContent().get(0).getId());
assertThat(softwareManagement.findSoftwareModuleByFilters(pageReq, "1.0%", appType).getContent()).hasSize(1);
assertThat(softwareManagement.findSoftwareModuleByFilters(pageReq, "1.0%", appType).getContent().get(0))
assertThat(softwareManagement.findSoftwareModuleByFilters(pageReq, "1.0%", appType.getId()).getContent())
.hasSize(1);
assertThat(softwareManagement.findSoftwareModuleByFilters(pageReq, "1.0%", appType.getId()).getContent().get(0))
.isEqualTo(ah);
}
@@ -294,11 +299,11 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTestWithMongoD
final SoftwareModule two = softwareManagement
.createSoftwareModule(new JpaSoftwareModule(osType, "two", "two", null, ""));
// ignored
softwareManagement.deleteSoftwareModule(
softwareManagement.createSoftwareModule(new JpaSoftwareModule(osType, "deleted", "deleted", null, "")));
softwareManagement.deleteSoftwareModule(softwareManagement
.createSoftwareModule(new JpaSoftwareModule(osType, "deleted", "deleted", null, "")).getId());
softwareManagement.createSoftwareModule(new JpaSoftwareModule(appType, "three", "3.0.2", null, ""));
assertThat(softwareManagement.findSoftwareModulesByType(pageReq, osType).getContent())
assertThat(softwareManagement.findSoftwareModulesByType(pageReq, osType.getId()).getContent())
.as("Expected to find the following number of modules:").hasSize(2).as("with the following elements")
.contains(two, one);
}
@@ -310,29 +315,13 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTestWithMongoD
softwareManagement.createSoftwareModule(new JpaSoftwareModule(osType, "one", "one", null, ""));
softwareManagement.createSoftwareModule(new JpaSoftwareModule(appType, "two", "two", null, ""));
// ignored
softwareManagement.deleteSoftwareModule(
softwareManagement.createSoftwareModule(new JpaSoftwareModule(osType, "deleted", "deleted", null, "")));
softwareManagement.deleteSoftwareModule(softwareManagement
.createSoftwareModule(new JpaSoftwareModule(osType, "deleted", "deleted", null, "")).getId());
assertThat(softwareManagement.countSoftwareModulesAll()).as("Expected to find the following number of modules:")
.isEqualTo(2);
}
@Test
@Description("Counts for software modules by type.")
public void countSoftwareModulesByType() {
// found in test
softwareManagement.createSoftwareModule(new JpaSoftwareModule(osType, "one", "one", null, ""));
softwareManagement.createSoftwareModule(new JpaSoftwareModule(osType, "two", "two", null, ""));
// ignored
softwareManagement.deleteSoftwareModule(
softwareManagement.createSoftwareModule(new JpaSoftwareModule(osType, "deleted", "deleted", null, "")));
softwareManagement.createSoftwareModule(new JpaSoftwareModule(appType, "three", "3.0.2", null, ""));
assertThat(softwareManagement.countSoftwareModulesByType(osType))
.as("Expected to find the following number of modules:").isEqualTo(2);
}
@Test
@Description("Tests the successfull deletion of software module types. Both unused (hard delete) and used ones (soft delete).")
public void deleteAssignedAndUnassignedSoftwareModuleTypes() {
@@ -382,7 +371,7 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTestWithMongoD
final Artifact artifact2 = artifactsIt.next();
// [STEP2]: Delete unassigned SoftwareModule
softwareManagement.deleteSoftwareModule(unassignedModule);
softwareManagement.deleteSoftwareModule(unassignedModule.getId());
// [VERIFY EXPECTED RESULT]:
// verify: SoftwareModule is deleted
@@ -412,7 +401,7 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTestWithMongoD
distributionSetManagement.assignSoftwareModules(disSet, Sets.newHashSet(assignedModule));
// [STEP3]: Delete the assigned SoftwareModule
softwareManagement.deleteSoftwareModule(assignedModule);
softwareManagement.deleteSoftwareModule(assignedModule.getId());
// [VERIFY EXPECTED RESULT]:
// verify: assignedModule is marked as deleted
@@ -454,7 +443,7 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTestWithMongoD
distributionSetManagement.deleteDistributionSet(disSet);
// [STEP5]: Delete the assigned SoftwareModule
softwareManagement.deleteSoftwareModule(assignedModule);
softwareManagement.deleteSoftwareModule(assignedModule.getId());
// [VERIFY EXPECTED RESULT]:
// verify: assignedModule is marked as deleted
@@ -488,7 +477,7 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTestWithMongoD
SoftwareModule moduleX = createSoftwareModuleWithArtifacts(osType, "modulex", "v1.0", 0);
// [STEP2]: Create newArtifactX and add it to SoftwareModuleX
artifactManagement.createLocalArtifact(new ByteArrayInputStream(source), moduleX.getId(), "artifactx", false);
artifactManagement.createArtifact(new ByteArrayInputStream(source), moduleX.getId(), "artifactx", false);
moduleX = softwareManagement.findSoftwareModuleWithDetails(moduleX.getId());
final Artifact artifactX = moduleX.getArtifacts().iterator().next();
@@ -496,7 +485,7 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTestWithMongoD
SoftwareModule moduleY = createSoftwareModuleWithArtifacts(osType, "moduley", "v1.0", 0);
// [STEP4]: Assign the same ArtifactX to SoftwareModuleY
artifactManagement.createLocalArtifact(new ByteArrayInputStream(source), moduleY.getId(), "artifactx", false);
artifactManagement.createArtifact(new ByteArrayInputStream(source), moduleY.getId(), "artifactx", false);
moduleY = softwareManagement.findSoftwareModuleWithDetails(moduleY.getId());
final Artifact artifactY = moduleY.getArtifacts().iterator().next();
@@ -504,7 +493,7 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTestWithMongoD
assertThat(operations.find(new Query())).hasSize(1);
// [STEP5]: Delete SoftwareModuleX
softwareManagement.deleteSoftwareModule(moduleX);
softwareManagement.deleteSoftwareModule(moduleX.getId());
// [VERIFY EXPECTED RESULT]:
// verify: SoftwareModuleX is deleted, and ModuelY still exists
@@ -540,14 +529,14 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTestWithMongoD
// [STEP1]: Create SoftwareModuleX and add a new ArtifactX
SoftwareModule moduleX = createSoftwareModuleWithArtifacts(osType, "modulex", "v1.0", 0);
artifactManagement.createLocalArtifact(new ByteArrayInputStream(source), moduleX.getId(), "artifactx", false);
artifactManagement.createArtifact(new ByteArrayInputStream(source), moduleX.getId(), "artifactx", false);
moduleX = softwareManagement.findSoftwareModuleWithDetails(moduleX.getId());
final Artifact artifactX = moduleX.getArtifacts().iterator().next();
// [STEP2]: Create SoftwareModuleY and add the same ArtifactX
SoftwareModule moduleY = createSoftwareModuleWithArtifacts(osType, "moduley", "v1.0", 0);
artifactManagement.createLocalArtifact(new ByteArrayInputStream(source), moduleY.getId(), "artifactx", false);
artifactManagement.createArtifact(new ByteArrayInputStream(source), moduleY.getId(), "artifactx", false);
moduleY = softwareManagement.findSoftwareModuleWithDetails(moduleY.getId());
final Artifact artifactY = moduleY.getArtifacts().iterator().next();
@@ -563,10 +552,10 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTestWithMongoD
deploymentManagement.assignDistributionSet(disSetY, Lists.newArrayList(target));
// [STEP5]: Delete SoftwareModuleX
softwareManagement.deleteSoftwareModule(moduleX);
softwareManagement.deleteSoftwareModule(moduleX.getId());
// [STEP6]: Delete SoftwareModuleY
softwareManagement.deleteSoftwareModule(moduleY);
softwareManagement.deleteSoftwareModule(moduleY.getId());
// [VERIFY EXPECTED RESULT]:
moduleX = softwareManagement.findSoftwareModuleById(moduleX.getId());
@@ -597,7 +586,7 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTestWithMongoD
new JpaSoftwareModule(type, name, version, "description of artifact " + name, ""));
for (int i = 0; i < numberArtifacts; i++) {
artifactManagement.createLocalArtifact(new RandomGeneratedInputStream(5 * 1024), softwareModule.getId(),
artifactManagement.createArtifact(new RandomGeneratedInputStream(5 * 1024), softwareModule.getId(),
"file" + (i + 1), false);
}
@@ -622,16 +611,16 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTestWithMongoD
assertThat(artifactRepository.findAll()).hasSize(results.length);
for (final Artifact result : results) {
assertThat(result.getId()).isNotNull();
assertThat(operations.findOne(new Query()
.addCriteria(Criteria.where("filename").is(((JpaLocalArtifact) result).getGridFsFileName()))))
assertThat(operations.findOne(
new Query().addCriteria(Criteria.where("filename").is(((JpaArtifact) result).getGridFsFileName()))))
.isNotNull();
}
}
private void assertArtfiactNull(final Artifact... results) {
for (final Artifact result : results) {
assertThat(operations.findOne(new Query()
.addCriteria(Criteria.where("filename").is(((JpaLocalArtifact) result).getGridFsFileName()))))
assertThat(operations.findOne(
new Query().addCriteria(Criteria.where("filename").is(((JpaArtifact) result).getGridFsFileName()))))
.isNull();
}
}
@@ -664,18 +653,18 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTestWithMongoD
final DistributionSet set = distributionSetManagement.createDistributionSet(new JpaDistributionSet("set", "1",
"desc", testDsType, Lists.newArrayList(one, two, deleted, four, differentName)));
softwareManagement.deleteSoftwareModule(deleted);
softwareManagement.deleteSoftwareModule(deleted.getId());
// with filter on name, version and module type
assertThat(softwareManagement.findSoftwareModuleOrderBySetAssignmentAndModuleNameAscModuleVersionAsc(pageReq,
set.getId(), "found", testType).getContent())
set.getId(), "found", testType.getId()).getContent())
.as("Found modules with given name, given module type and the assigned ones first")
.containsExactly(new AssignedSoftwareModule(one, true), new AssignedSoftwareModule(two, true),
new AssignedSoftwareModule(unassigned, false));
// with filter on module type only
assertThat(softwareManagement.findSoftwareModuleOrderBySetAssignmentAndModuleNameAscModuleVersionAsc(pageReq,
set.getId(), null, testType).getContent())
set.getId(), null, testType.getId()).getContent())
.as("Found modules with given module type and the assigned ones first").containsExactly(
new AssignedSoftwareModule(differentName, true), new AssignedSoftwareModule(one, true),
new AssignedSoftwareModule(two, true), new AssignedSoftwareModule(unassigned, false));
@@ -715,12 +704,12 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTestWithMongoD
.createSoftwareModule(new JpaSoftwareModule(testType, "deleted", "deleted", null, ""));
distributionSetManagement.createDistributionSet(new JpaDistributionSet("set", "1", "desc", testDsType,
Lists.newArrayList(one, two, deleted, four, differentName)));
softwareManagement.deleteSoftwareModule(deleted);
softwareManagement.deleteSoftwareModule(deleted.getId());
// test
assertThat(softwareManagement.countSoftwareModuleByFilters("found", testType))
assertThat(softwareManagement.countSoftwareModuleByFilters("found", testType.getId()))
.as("Number of modules with given name or version and type").isEqualTo(3);
assertThat(softwareManagement.countSoftwareModuleByFilters(null, testType))
assertThat(softwareManagement.countSoftwareModuleByFilters(null, testType.getId()))
.as("Number of modules with given type").isEqualTo(4);
assertThat(softwareManagement.countSoftwareModuleByFilters(null, null)).as("Number of modules overall")
.isEqualTo(5);
@@ -742,7 +731,7 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTestWithMongoD
.createSoftwareModule(new JpaSoftwareModule(testType, "deleted", "deleted", null, ""));
distributionSetManagement.createDistributionSet(
new JpaDistributionSet("set", "1", "desc", testDsType, Lists.newArrayList(deleted, four)));
softwareManagement.deleteSoftwareModule(deleted);
softwareManagement.deleteSoftwareModule(deleted.getId());
assertThat(softwareManagement.countSoftwareModulesAll()).as("Number of undeleted modules").isEqualTo(1);
assertThat(softwareModuleRepository.count()).as("Number of all modules").isEqualTo(2);
@@ -829,7 +818,7 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTestWithMongoD
.createSoftwareModule(new JpaSoftwareModule(testType, "deleted", "deleted", null, ""));
final DistributionSet set = distributionSetManagement.createDistributionSet(
new JpaDistributionSet("set", "1", "desc", testDsType, Lists.newArrayList(one, deleted)));
softwareManagement.deleteSoftwareModule(deleted);
softwareManagement.deleteSoftwareModule(deleted.getId());
assertThat(softwareManagement.findSoftwareModuleByAssignedTo(pageReq, set).getContent())
.as("Found this number of modules").hasSize(2);
@@ -950,7 +939,7 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTestWithMongoD
.as("Contains the created metadata element")
.containsExactly(new JpaSoftwareModuleMetadata(knownKey1, ah, knownValue1));
softwareManagement.deleteSoftwareModuleMetadata(ah, knownKey1);
softwareManagement.deleteSoftwareModuleMetadata(ah.getId(), knownKey1);
assertThat(softwareManagement.findSoftwareModuleById(ah.getId()).getMetadata()).as("Metadata elemenets are")
.isEmpty();
}
@@ -968,7 +957,7 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTestWithMongoD
.getSoftwareModule();
try {
softwareManagement.findSoftwareModuleMetadata(ah, "doesnotexist");
softwareManagement.findSoftwareModuleMetadata(ah.getId(), "doesnotexist");
fail("should not have worked as module metadata with that key does not exist");
} catch (final EntityNotFoundException e) {

View File

@@ -136,14 +136,14 @@ public class SystemManagementTest extends AbstractJpaIntegrationTestWithMongoDB
"version 1", null, null);
sm = softwareModuleRepository.save(sm);
artifactManagement.createLocalArtifact(new ByteArrayInputStream(random), sm.getId(), "file1", false);
artifactManagement.createArtifact(new ByteArrayInputStream(random), sm.getId(), "file1", false);
}
private void createDeletedTestArtifact(final byte[] random) {
final DistributionSet ds = testdataFactory.createDistributionSet("deleted garbage", true);
ds.getModules().stream().forEach(module -> {
artifactManagement.createLocalArtifact(new ByteArrayInputStream(random), module.getId(), "file1", false);
softwareManagement.deleteSoftwareModule(module);
artifactManagement.createArtifact(new ByteArrayInputStream(random), module.getId(), "file1", false);
softwareManagement.deleteSoftwareModule(module.getId());
});
}

View File

@@ -33,7 +33,6 @@ import org.eclipse.hawkbit.repository.model.BaseEntity;
import org.eclipse.hawkbit.repository.model.DistributionSet;
import org.eclipse.hawkbit.repository.model.DistributionSetTag;
import org.eclipse.hawkbit.repository.model.DistributionSetType;
import org.eclipse.hawkbit.repository.model.LocalArtifact;
import org.eclipse.hawkbit.repository.model.NamedEntity;
import org.eclipse.hawkbit.repository.model.NamedVersionedEntity;
import org.eclipse.hawkbit.repository.model.SoftwareModule;
@@ -306,19 +305,19 @@ public class TestdataFactory {
}
/**
* Creates {@link LocalArtifact}s for given {@link SoftwareModule} with a
* small text payload.
* Creates {@link Artifact}s for given {@link SoftwareModule} with a small
* text payload.
*
* @param moduleId
* the {@link Artifact}s belong to.
*
* @return {@link LocalArtifact} entity.
* @return {@link Artifact} entity.
*/
public List<LocalArtifact> createLocalArtifacts(final Long moduleId) {
final List<LocalArtifact> artifacts = new ArrayList<>();
public List<Artifact> createArtifacts(final Long moduleId) {
final List<Artifact> artifacts = new ArrayList<>();
for (int i = 0; i < 3; i++) {
final InputStream stubInputStream = IOUtils.toInputStream("some test data" + i, Charset.forName("UTF-8"));
artifacts.add(artifactManagement.createLocalArtifact(stubInputStream, moduleId, "filename" + i, false));
artifacts.add(artifactManagement.createArtifact(stubInputStream, moduleId, "filename" + i, false));
}

View File

@@ -37,7 +37,7 @@ import javax.servlet.http.HttpServletResponse;
import org.eclipse.hawkbit.artifact.repository.model.DbArtifact;
import org.eclipse.hawkbit.repository.ControllerManagement;
import org.eclipse.hawkbit.repository.model.ActionStatus;
import org.eclipse.hawkbit.repository.model.LocalArtifact;
import org.eclipse.hawkbit.repository.model.Artifact;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.ResponseEntity;
@@ -71,7 +71,7 @@ public final class RestResourceConversionHelper {
*
* @return http code
*/
public static ResponseEntity<InputStream> writeFileResponse(final LocalArtifact artifact,
public static ResponseEntity<InputStream> writeFileResponse(final Artifact artifact,
final HttpServletResponse servletResponse, final HttpServletRequest request, final DbArtifact file) {
return writeFileResponse(artifact, servletResponse, request, file, null, null);
}
@@ -104,7 +104,7 @@ public final class RestResourceConversionHelper {
* @see <a href="https://tools.ietf.org/html/rfc7233">https://tools.ietf.org
* /html/rfc7233</a>
*/
public static ResponseEntity<InputStream> writeFileResponse(final LocalArtifact artifact,
public static ResponseEntity<InputStream> writeFileResponse(final Artifact artifact,
final HttpServletResponse response, final HttpServletRequest request, final DbArtifact file,
final ControllerManagement controllerManagement, final Long statusId) {
@@ -173,7 +173,7 @@ public final class RestResourceConversionHelper {
return result;
}
private static void handleFullFileRequest(final LocalArtifact artifact, final HttpServletResponse response,
private static void handleFullFileRequest(final Artifact artifact, final HttpServletResponse response,
final DbArtifact file, final ControllerManagement controllerManagement, final Long statusId,
final ByteRange full) {
final ByteRange r = full;
@@ -240,7 +240,7 @@ public final class RestResourceConversionHelper {
}
}
private static void handleMultipartRangeRequest(final LocalArtifact artifact, final HttpServletResponse response,
private static void handleMultipartRangeRequest(final Artifact artifact, final HttpServletResponse response,
final DbArtifact file, final ControllerManagement controllerManagement, final Long statusId,
final List<ByteRange> ranges) {
response.setContentType("multipart/byteranges; boundary=" + MULTIPART_BOUNDARY);
@@ -268,7 +268,7 @@ public final class RestResourceConversionHelper {
}
}
private static void handleStandardRangeRequest(final LocalArtifact artifact, final HttpServletResponse response,
private static void handleStandardRangeRequest(final Artifact artifact, final HttpServletResponse response,
final DbArtifact file, final ControllerManagement controllerManagement, final Long statusId,
final List<ByteRange> ranges) {
final ByteRange r = ranges.get(0);

View File

@@ -19,7 +19,7 @@ import java.util.Map;
import org.eclipse.hawkbit.repository.ArtifactManagement;
import org.eclipse.hawkbit.repository.EntityFactory;
import org.eclipse.hawkbit.repository.OffsetBasedPageRequest;
import org.eclipse.hawkbit.repository.model.LocalArtifact;
import org.eclipse.hawkbit.repository.model.Artifact;
import org.eclipse.hawkbit.ui.utils.SPUIDefinitions;
import org.eclipse.hawkbit.ui.utils.SpringContextHelper;
import org.springframework.data.domain.Page;
@@ -33,12 +33,12 @@ import org.vaadin.addons.lazyquerycontainer.QueryDefinition;
* Simple implementation of generics bean query which dynamically loads artifact
* beans.
*/
public class ArtifactBeanQuery extends AbstractBeanQuery<LocalArtifact> {
public class ArtifactBeanQuery extends AbstractBeanQuery<Artifact> {
private static final long serialVersionUID = -333786310371208962L;
private Sort sort = new Sort(Direction.DESC, "filename");
private transient ArtifactManagement artifactManagement = null;
private transient EntityFactory entityFactory;
private transient Page<LocalArtifact> firstPagetArtifacts = null;
private transient Page<Artifact> firstPagetArtifacts = null;
private Long baseSwModuleId = null;
/**
@@ -72,26 +72,26 @@ public class ArtifactBeanQuery extends AbstractBeanQuery<LocalArtifact> {
}
@Override
protected LocalArtifact constructBean() {
return getEntityFactory().generateLocalArtifact();
protected Artifact constructBean() {
return getEntityFactory().generateArtifact();
}
@Override
protected List<LocalArtifact> loadBeans(final int startIndex, final int count) {
Page<LocalArtifact> artifactBeans;
protected List<Artifact> loadBeans(final int startIndex, final int count) {
Page<Artifact> artifactBeans;
if (startIndex == 0 && firstPagetArtifacts != null) {
artifactBeans = firstPagetArtifacts;
} else {
artifactBeans = getArtifactManagement().findLocalArtifactBySoftwareModule(
new OffsetBasedPageRequest(startIndex, count, sort), baseSwModuleId);
artifactBeans = getArtifactManagement()
.findArtifactBySoftwareModule(new OffsetBasedPageRequest(startIndex, count, sort), baseSwModuleId);
}
return artifactBeans.getContent();
}
@Override
protected void saveBeans(final List<LocalArtifact> addedTargets, final List<LocalArtifact> modifiedTargets,
final List<LocalArtifact> removedTargets) {
protected void saveBeans(final List<Artifact> addedTargets, final List<Artifact> modifiedTargets,
final List<Artifact> removedTargets) {
// CRUD operations on Target will be done through repository methods
}
@@ -99,8 +99,8 @@ public class ArtifactBeanQuery extends AbstractBeanQuery<LocalArtifact> {
public int size() {
long size = 0;
if (baseSwModuleId != null) {
firstPagetArtifacts = getArtifactManagement().findLocalArtifactBySoftwareModule(
new PageRequest(0, SPUIDefinitions.PAGE_SIZE, sort), baseSwModuleId);
firstPagetArtifacts = getArtifactManagement()
.findArtifactBySoftwareModule(new PageRequest(0, SPUIDefinitions.PAGE_SIZE, sort), baseSwModuleId);
size = firstPagetArtifacts.getTotalElements();
}
if (size > Integer.MAX_VALUE) {

View File

@@ -278,7 +278,7 @@ public class ArtifactDetailsLayout extends VerticalLayout {
if (ok) {
final ArtifactManagement artifactManagement = SpringContextHelper
.getBean(ArtifactManagement.class);
artifactManagement.deleteLocalArtifact(id);
artifactManagement.deleteArtifact(id);
uINotification.displaySuccess(i18n.get("message.artifact.deleted", fileName));
if (artifactUploadState.getSelectedBaseSwModuleId().isPresent()) {
populateArtifactDetails(artifactUploadState.getSelectedBaseSwModuleId().get(),

View File

@@ -80,8 +80,8 @@ public class BaseSwModuleBeanQuery extends AbstractBeanQuery<ProxyBaseSoftwareMo
.findSoftwareModulesAll(new OffsetBasedPageRequest(startIndex, count, sort));
} else {
swModuleBeans = getSoftwareManagementService()
.findSoftwareModuleByFilters(new OffsetBasedPageRequest(startIndex, count, sort), searchText, type);
swModuleBeans = getSoftwareManagementService().findSoftwareModuleByFilters(
new OffsetBasedPageRequest(startIndex, count, sort), searchText, type.getId());
}
for (final SoftwareModule swModule : swModuleBeans) {
@@ -113,7 +113,7 @@ public class BaseSwModuleBeanQuery extends AbstractBeanQuery<ProxyBaseSoftwareMo
if (type == null && Strings.isNullOrEmpty(searchText)) {
size = getSoftwareManagementService().countSoftwareModulesAll();
} else {
size = getSoftwareManagementService().countSoftwareModuleByFilters(searchText, type);
size = getSoftwareManagementService().countSoftwareModuleByFilters(searchText, type.getId());
}
if (size > Integer.MAX_VALUE) {

View File

@@ -22,7 +22,7 @@ import org.eclipse.hawkbit.repository.ArtifactManagement;
import org.eclipse.hawkbit.repository.exception.ArtifactUploadFailedException;
import org.eclipse.hawkbit.repository.exception.InvalidMD5HashException;
import org.eclipse.hawkbit.repository.exception.InvalidSHA1HashException;
import org.eclipse.hawkbit.repository.model.LocalArtifact;
import org.eclipse.hawkbit.repository.model.Artifact;
import org.eclipse.hawkbit.repository.model.SoftwareModule;
import org.eclipse.hawkbit.ui.artifacts.state.ArtifactUploadState;
import org.eclipse.hawkbit.ui.artifacts.state.CustomFile;
@@ -191,8 +191,7 @@ public class UploadConfirmationWindow implements Button.ClickListener {
final ArtifactManagement artifactManagement = SpringContextHelper.getBean(ArtifactManagement.class);
if (HawkbitCommonUtil.trimAndNullIfEmpty(fileName) != null) {
final Long baseSwId = (Long) item.getItemProperty(BASE_SOFTWARE_ID).getValue();
final List<LocalArtifact> artifactList = artifactManagement.findByFilenameAndSoftwareModule(fileName,
baseSwId);
final List<Artifact> artifactList = artifactManagement.findByFilenameAndSoftwareModule(fileName, baseSwId);
if (!artifactList.isEmpty()) {
warningIconLabel.setVisible(true);
if (isErrorIcon(warningIconLabel)) {
@@ -434,7 +433,7 @@ public class UploadConfirmationWindow implements Button.ClickListener {
final Label errorLabel, final String oldFileName, final Long currentSwId) {
if (warningLabel == null && (errorLabelCount > 1 || (duplicateCount == 1 && errorLabelCount == 1))) {
final ArtifactManagement artifactManagement = SpringContextHelper.getBean(ArtifactManagement.class);
final List<LocalArtifact> artifactList = artifactManagement.findByFilenameAndSoftwareModule(oldFileName,
final List<Artifact> artifactList = artifactManagement.findByFilenameAndSoftwareModule(oldFileName,
currentSwId);
errorLabel.removeStyleName(SPUIStyleDefinitions.ERROR_LABEL);
errorLabel.setDescription(i18n.get(ALREADY_EXISTS_MSG));
@@ -591,7 +590,7 @@ public class UploadConfirmationWindow implements Button.ClickListener {
customFile.getBaseSoftwareModuleName(), customFile.getBaseSoftwareModuleVersion());
if (customFile.getFileName().equals(fileName)
&& baseSwModuleNameVersion.equals(baseSoftwareModuleNameVersion)) {
createLocalArtifact(itemId, customFile.getFilePath(), artifactManagement, bSoftwareModule);
createArtifact(itemId, customFile.getFilePath(), artifactManagement, bSoftwareModule);
}
}
refreshArtifactDetailsLayout = checkIfArtifactDetailsDispalyed(bSoftwareModule.getId());
@@ -619,8 +618,8 @@ public class UploadConfirmationWindow implements Button.ClickListener {
currentUploadResultWindow = null;
}
private void createLocalArtifact(final String itemId, final String filePath,
final ArtifactManagement artifactManagement, final SoftwareModule baseSw) {
private void createArtifact(final String itemId, final String filePath, final ArtifactManagement artifactManagement,
final SoftwareModule baseSw) {
final File newFile = new File(filePath);
final Item item = tabelContainer.getItem(itemId);
@@ -633,7 +632,7 @@ public class UploadConfirmationWindow implements Button.ClickListener {
try (FileInputStream fis = new FileInputStream(newFile)) {
artifactManagement.createLocalArtifact(fis, baseSw.getId(), providedFileName,
artifactManagement.createArtifact(fis, baseSw.getId(), providedFileName,
HawkbitCommonUtil.trimAndNullIfEmpty(md5Checksum),
HawkbitCommonUtil.trimAndNullIfEmpty(sha1Checksum), true, customFile.getMimeType());
saveUploadStatus(providedFileName, swModuleNameVersion, SUCCESS, "");

View File

@@ -43,7 +43,7 @@ public class SwMetadataPopupLayout extends AbstractMetadataPopupLayout<SoftwareM
@Override
protected void checkForDuplicate(final SoftwareModule entity, final String value) {
softwareManagement.findSoftwareModuleMetadata(entity, value);
softwareManagement.findSoftwareModuleMetadata(entity.getId(), value);
}
/**
@@ -80,7 +80,7 @@ public class SwMetadataPopupLayout extends AbstractMetadataPopupLayout<SoftwareM
@Override
protected void deleteMetadata(final SoftwareModule entity, final String key, final String value) {
final SoftwareModuleMetadata swMetadata = entityFactory.generateSoftwareModuleMetadata(entity, key, value);
softwareManagement.deleteSoftwareModuleMetadata(entity, key);
softwareManagement.deleteSoftwareModuleMetadata(entity.getId(), key);
eventBus.publish(this, new MetadataEvent(MetadataUIEvent.DELETE_SOFTWARE_MODULE_METADATA, swMetadata));
}

View File

@@ -79,7 +79,7 @@ public class SwModuleBeanQuery extends AbstractBeanQuery<ProxyBaseSwModuleItem>
final List<ProxyBaseSwModuleItem> proxyBeans = new ArrayList<>();
swModuleBeans = getSoftwareManagement().findSoftwareModuleOrderBySetAssignmentAndModuleNameAscModuleVersionAsc(
new OffsetBasedPageRequest(startIndex, count), orderByDistId, searchText, type);
new OffsetBasedPageRequest(startIndex, count), orderByDistId, searchText, type.getId());
for (final AssignedSoftwareModule swModule : swModuleBeans) {
proxyBeans.add(getProxyBean(swModule));
@@ -114,7 +114,7 @@ public class SwModuleBeanQuery extends AbstractBeanQuery<ProxyBaseSwModuleItem>
if (type == null && Strings.isNullOrEmpty(searchText)) {
size = getSoftwareManagement().countSoftwareModulesAll();
} else {
size = getSoftwareManagement().countSoftwareModuleByFilters(searchText, type);
size = getSoftwareManagement().countSoftwareModuleByFilters(searchText, type.getId());
}
if (size > Integer.MAX_VALUE) {