Exemplo n.º 1
0
  @Override
  @Modifying
  @Transactional(isolation = Isolation.READ_UNCOMMITTED)
  public boolean clearArtifactBinary(final Artifact existing) {

    for (final Artifact lArtifact :
        localArtifactRepository.findByGridFsFileName(
            ((JpaArtifact) existing).getGridFsFileName())) {
      if (!lArtifact.getSoftwareModule().isDeleted()
          && Long.compare(
                  lArtifact.getSoftwareModule().getId(), existing.getSoftwareModule().getId())
              != 0) {
        return false;
      }
    }

    try {
      LOG.debug(
          "deleting artifact from repository {}", ((JpaArtifact) existing).getGridFsFileName());
      artifactRepository.deleteBySha1(((JpaArtifact) existing).getGridFsFileName());
      return true;
    } catch (final ArtifactStoreException e) {
      throw new ArtifactDeleteFailedException(e);
    }
  }
  private Artifact convertArtifact(
      final Target target, final org.eclipse.hawkbit.repository.model.Artifact localArtifact) {
    final Artifact artifact = new Artifact();

    artifact.setUrls(
        artifactUrlHandler
            .getUrls(
                new URLPlaceholder(
                    systemManagement.getTenantMetadata().getTenant(),
                    systemManagement.getTenantMetadata().getId(),
                    target.getControllerId(),
                    target.getId(),
                    new SoftwareData(
                        localArtifact.getSoftwareModule().getId(),
                        localArtifact.getFilename(),
                        localArtifact.getId(),
                        localArtifact.getSha1Hash())),
                ApiType.DMF)
            .stream()
            .collect(Collectors.toMap(e -> e.getProtocol(), e -> e.getRef())));

    artifact.setFilename(localArtifact.getFilename());
    artifact.setHashes(new ArtifactHash(localArtifact.getSha1Hash(), localArtifact.getMd5Hash()));
    artifact.setSize(localArtifact.getSize());
    return artifact;
  }