Skip to content

Commit

Permalink
feat(documents): added documentSize (#1164)
Browse files Browse the repository at this point in the history
Refs: #880
Reviewed-By: Phil Schneider <[email protected]>
  • Loading branch information
AnuragNagpure authored Nov 22, 2024
1 parent df5cd4c commit 29ee3c3
Show file tree
Hide file tree
Showing 26 changed files with 10,320 additions and 79 deletions.
3 changes: 3 additions & 0 deletions docs/api/registration-service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1640,6 +1640,9 @@ components:
format: uuid
documentName:
type: string
documentSize:
type: integer
format: int64
additionalProperties: false
UrlInformation:
type: object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ private async Task HandleCompanyCertificateCreationAsync(CompanyCertificateTypeI
{
var (documentContent, hash) = await document.GetContentAndHash(cancellationToken).ConfigureAwait(ConfigureAwaitOptions.None);
var doc = portalRepositories.GetInstance<IDocumentRepository>().CreateDocument(document.FileName, documentContent,
hash, mediaTypeId, DocumentTypeId.COMPANY_CERTIFICATE, x =>
hash, mediaTypeId, DocumentTypeId.COMPANY_CERTIFICATE, document.Length, x =>
{
x.CompanyUserId = _identityData.IdentityId;
x.DocumentStatusId = DocumentStatusId.LOCKED;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ private async Task<Guid> ProcessAndCreateDocument(SdFactoryResponseModelTitle ti
hash,
MediaTypeId.JSON,
DocumentTypeId.SELF_DESCRIPTION,
documentContent.Length,
doc => { doc.DocumentStatusId = DocumentStatusId.LOCKED; });
return document.Id;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ public async Task UploadOfferAssignedAppLeadImageDocumentByIdAsync(Guid appId, I

var documentRepository = _portalRepositories.GetInstance<IDocumentRepository>();
var (documentContent, hash) = await document.GetContentAndHash(cancellationToken).ConfigureAwait(ConfigureAwaitOptions.None);
var doc = documentRepository.CreateDocument(document.FileName, documentContent, hash, documentContentType, DocumentTypeId.APP_LEADIMAGE, x =>
var doc = documentRepository.CreateDocument(document.FileName, documentContent, hash, documentContentType, DocumentTypeId.APP_LEADIMAGE, documentContent.Length, x =>
{
x.CompanyUserId = _identityData.IdentityId;
x.DocumentStatusId = DocumentStatusId.LOCKED;
Expand Down
2 changes: 1 addition & 1 deletion src/marketplace/Offers.Library.Web/OfferDocumentService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public async Task UploadDocumentAsync(Guid id, DocumentTypeId documentTypeId, IF

var documentData = await document.GetContentAndHash(cancellationToken).ConfigureAwait(ConfigureAwaitOptions.None);

var doc = _portalRepositories.GetInstance<IDocumentRepository>().CreateDocument(document.FileName, documentData.Content, documentData.Hash, mediaTypeId, documentTypeId, x =>
var doc = _portalRepositories.GetInstance<IDocumentRepository>().CreateDocument(document.FileName, documentData.Content, documentData.Hash, mediaTypeId, documentTypeId, document.Length, x =>
{
x.CompanyUserId = _identityData.IdentityId;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@

namespace Org.Eclipse.TractusX.Portal.Backend.PortalBackend.DBAccess.Models;

public record UploadDocuments(Guid DocumentId, string DocumentName);
public record UploadDocuments(Guid DocumentId, string DocumentName, long DocumentSize);

Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public void AttachAndModifyCompanyCertificateDetails(Guid id, Action<CompanyCert

public void AttachAndModifyCompanyCertificateDocumentDetails(Guid id, Action<Document>? initialize, Action<Document> updateFields)
{
var entity = new Document(id, null!, null!, null!, default, default, default, default);
var entity = new Document(id, null!, null!, null!, default, default, default, default, default);
initialize?.Invoke(entity);
_context.Attach(entity);
updateFields.Invoke(entity);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ namespace Org.Eclipse.TractusX.Portal.Backend.PortalBackend.DBAccess.Repositorie
public class DocumentRepository(PortalDbContext dbContext) : IDocumentRepository
{
/// <inheritdoc />
public Document CreateDocument(string documentName, byte[] documentContent, byte[] hash, MediaTypeId mediaTypeId, DocumentTypeId documentTypeId, Action<Document>? setupOptionalFields)
public Document CreateDocument(string documentName, byte[] documentContent, byte[] hash, MediaTypeId mediaTypeId, DocumentTypeId documentTypeId, long documentLength, Action<Document>? setupOptionalFields)
{
var document = new Document(
Guid.NewGuid(),
Expand All @@ -41,7 +41,8 @@ public Document CreateDocument(string documentName, byte[] documentContent, byte
mediaTypeId,
DateTimeOffset.UtcNow,
DocumentStatusId.PENDING,
documentTypeId);
documentTypeId,
documentLength / 1024);

setupOptionalFields?.Invoke(document);
return dbContext.Documents.Add(document).Entity;
Expand Down Expand Up @@ -77,7 +78,8 @@ public Document CreateDocument(string documentName, byte[] documentContent, byte
.Select(document =>
new UploadDocuments(
document!.Id,
document!.DocumentName))))
document!.DocumentName,
document!.DocumentSize))))
)
.SingleOrDefaultAsync();

Expand Down Expand Up @@ -113,7 +115,7 @@ public Document CreateDocument(string documentName, byte[] documentContent, byte

/// <inheritdoc />
public void RemoveDocument(Guid documentId) =>
dbContext.Documents.Remove(new Document(documentId, null!, null!, null!, default, default, default, default));
dbContext.Documents.Remove(new Document(documentId, null!, null!, null!, default, default, default, default, default));

/// <inheritdoc />
public Task<Document?> GetDocumentByIdAsync(Guid documentId) =>
Expand Down Expand Up @@ -141,7 +143,7 @@ public void RemoveDocument(Guid documentId) =>
/// <inheritdoc />
public void AttachAndModifyDocument(Guid documentId, Action<Document>? initialize, Action<Document> modify)
{
var document = new Document(documentId, null!, null!, null!, default, default, default, default);
var document = new Document(documentId, null!, null!, null!, default, default, default, default, default);
initialize?.Invoke(document);
dbContext.Attach(document);
modify(document);
Expand All @@ -151,7 +153,7 @@ public void AttachAndModifyDocuments(IEnumerable<(Guid DocumentId, Action<Docume
{
var initial = documentData.Select(x =>
{
var document = new Document(x.DocumentId, null!, null!, null!, default, default, default, default);
var document = new Document(x.DocumentId, null!, null!, null!, default, default, default, default, default);
x.Initialize?.Invoke(document);
return (Document: document, x.Modify);
}
Expand Down Expand Up @@ -231,7 +233,7 @@ public void AttachAndModifyDocuments(IEnumerable<(Guid DocumentId, Action<Docume

/// <inheritdoc />
public void RemoveDocuments(IEnumerable<Guid> documentIds) =>
dbContext.Documents.RemoveRange(documentIds.Select(documentId => new Document(documentId, null!, null!, null!, default, default, default, default)));
dbContext.Documents.RemoveRange(documentIds.Select(documentId => new Document(documentId, null!, null!, null!, default, default, default, default, default)));

public Task<(byte[] Content, string FileName, bool IsDocumentTypeMatch, MediaTypeId MediaTypeId)> GetDocumentAsync(Guid documentId, IEnumerable<DocumentTypeId> documentTypeIds) =>
dbContext.Documents
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,10 @@ public interface IDocumentRepository
/// <param name="hash">Hash of the document</param>
/// <param name="mediaTypeId">The documents mediaType</param>
/// <param name="documentTypeId">the document type id</param>
/// <param name="documentSize">the document size</param>
/// <param name="setupOptionalFields">Action to setup the additional fields</param>
/// <returns>Returns the created document</returns>
Document CreateDocument(string documentName, byte[] documentContent, byte[] hash, MediaTypeId mediaTypeId, DocumentTypeId documentTypeId, Action<Document>? setupOptionalFields);
Document CreateDocument(string documentName, byte[] documentContent, byte[] hash, MediaTypeId mediaTypeId, DocumentTypeId documentTypeId, long documentLength, Action<Document>? setupOptionalFields);

/// <summary>
/// Gets the document with the given id from the persistence layer.
Expand Down
Loading

0 comments on commit 29ee3c3

Please sign in to comment.