|
@@ -153,16 +153,41 @@ namespace BO.AppServer.Business.Services
|
|
|
return new ResultValueDto<DocumentRDto>(newDocument.Map<Metadocument, DocumentRDto>());
|
|
return new ResultValueDto<DocumentRDto>(newDocument.Map<Metadocument, DocumentRDto>());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ public async Task<ResultsValueDto<ArtifactRDto>> ClearDocumentArtifactsAsync(long workspaceId, long documentId, bool force)
|
|
|
|
|
+ {
|
|
|
|
|
+
|
|
|
|
|
+ var document = CheckAndGetDocument(workspaceId, documentId);
|
|
|
|
|
+ CheckDocumentStatusForUpdate(document, force);
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ var artifacts = _repoArtifact.GetArtifacts(documentId).ToArray(); // must be to array
|
|
|
|
|
+ foreach (var artifact in artifacts)
|
|
|
|
|
+ {
|
|
|
|
|
+ await _srvStorage.DeleteContent(artifact.Id);
|
|
|
|
|
+ _repoArtifact.Remove(artifact.Id);
|
|
|
|
|
+ Log.LogInformation($"Document '{document.Name}' ({documentId}) artifact '{artifact.Name + artifact.Extension}' ({artifact.Id}) removed.");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ document.Modified = DateTime.Now;
|
|
|
|
|
+ document.ModifiedByUser = GetCurrentUser();
|
|
|
|
|
+ _repoDocument.Set(document);
|
|
|
|
|
+ _repoArtifact.Commit();
|
|
|
|
|
+ _repoDocument.Commit();
|
|
|
|
|
+
|
|
|
|
|
+ return new ResultsValueDto<ArtifactRDto>(artifacts.MapList<Artifact, ArtifactRDto>());
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
|
|
|
public async Task<ResultValueDto<ArtifactRDto>> AppendArtifactAsync(long workspaceId, long documentId,
|
|
public async Task<ResultValueDto<ArtifactRDto>> AppendArtifactAsync(long workspaceId, long documentId,
|
|
|
- ArtifactCDto artifact, ArtifactTypeEnum type, Stream content)
|
|
|
|
|
|
|
+ ArtifactCDto artifact,bool replace, ArtifactTypeEnum type, Stream content)
|
|
|
{
|
|
{
|
|
|
//TODO: Rewrite better way - mainly rollback scenario
|
|
//TODO: Rewrite better way - mainly rollback scenario
|
|
|
|
|
|
|
|
var document = CheckAndGetDocument(workspaceId, documentId);
|
|
var document = CheckAndGetDocument(workspaceId, documentId);
|
|
|
- var exists = document.Artifacts.Any(x =>
|
|
|
|
|
- x.Name.ToLower() == artifact.Name.ToLower() && x.Extension.ToLower() == artifact.Extension.ToLower());
|
|
|
|
|
- if (exists)
|
|
|
|
|
|
|
+ var existingArtifact = _repoArtifact.GetArtifactByName(documentId, artifact.Name, artifact.Extension);
|
|
|
|
|
+ if (existingArtifact!=null && !replace)
|
|
|
{
|
|
{
|
|
|
var exc = new EntityAlreadyExistsException(typeof(Artifact), artifact.Name + "." + artifact.Extension);
|
|
var exc = new EntityAlreadyExistsException(typeof(Artifact), artifact.Name + "." + artifact.Extension);
|
|
|
Log.LogWarning(exc.Message);
|
|
Log.LogWarning(exc.Message);
|
|
@@ -177,8 +202,8 @@ namespace BO.AppServer.Business.Services
|
|
|
throw exc;
|
|
throw exc;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- var newArtifact = _repoArtifact.New();
|
|
|
|
|
-
|
|
|
|
|
|
|
+ var newArtifact = (existingArtifact != null && replace) ? existingArtifact : _repoArtifact.New();
|
|
|
|
|
+
|
|
|
newArtifact.Name = artifact.Name;
|
|
newArtifact.Name = artifact.Name;
|
|
|
newArtifact.Extension = artifact.Extension;
|
|
newArtifact.Extension = artifact.Extension;
|
|
|
newArtifact.Length = content.Length;
|
|
newArtifact.Length = content.Length;
|
|
@@ -199,10 +224,10 @@ namespace BO.AppServer.Business.Services
|
|
|
|
|
|
|
|
return new ResultValueDto<ArtifactRDto>(newArtifact.Map<Artifact, ArtifactRDto>());
|
|
return new ResultValueDto<ArtifactRDto>(newArtifact.Map<Artifact, ArtifactRDto>());
|
|
|
|
|
|
|
|
-
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+
|
|
|
public async Task<Tuple<Stream, string>> GetArtifactAsync(long workspaceId, long documentId, long artifactId)
|
|
public async Task<Tuple<Stream, string>> GetArtifactAsync(long workspaceId, long documentId, long artifactId)
|
|
|
{
|
|
{
|
|
|
var artifact = CheckAndGetArtifact(workspaceId, documentId, artifactId);
|
|
var artifact = CheckAndGetArtifact(workspaceId, documentId, artifactId);
|
|
@@ -253,11 +278,34 @@ namespace BO.AppServer.Business.Services
|
|
|
return document;
|
|
return document;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ private void CheckDocumentStatusForUpdate(Metadocument document, bool force)
|
|
|
|
|
+ {
|
|
|
|
|
+ if (document == null)
|
|
|
|
|
+ throw new ArgumentNullException(nameof(document));
|
|
|
|
|
+
|
|
|
|
|
+ var currentStatus = (DocumentStatusEnum)document.Status;
|
|
|
|
|
+ var allowedStatus = new DocumentStatusEnum[]
|
|
|
|
|
+ {
|
|
|
|
|
+ DocumentStatusEnum.New,
|
|
|
|
|
+ DocumentStatusEnum.Pending,
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ if (!allowedStatus.Contains(currentStatus))
|
|
|
|
|
+ {
|
|
|
|
|
+ var message = $"Document '{document.Name}' [{document.Id}] has not allowed status '{currentStatus}' for operation UPDATE. Allowed statuses are {string.Join(",", allowedStatus)}.";
|
|
|
|
|
+ Log.LogWarning(message + (force ? " Skip due Force flag." : string.Empty));
|
|
|
|
|
+ if (!force)
|
|
|
|
|
+ throw new InvalidDocumentStateException(document.Name, document.Id, currentStatus, "update");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
private Artifact CheckAndGetArtifact(long workspaceId, long documentId, long artifactId)
|
|
private Artifact CheckAndGetArtifact(long workspaceId, long documentId, long artifactId)
|
|
|
{
|
|
{
|
|
|
CheckAndGetWorkspace(workspaceId);
|
|
CheckAndGetWorkspace(workspaceId);
|
|
|
CheckAndGetDocument(workspaceId, documentId);
|
|
CheckAndGetDocument(workspaceId, documentId);
|
|
|
- var artifact = _repoDocument.GetArtifact(documentId, artifactId);
|
|
|
|
|
|
|
+ var artifact = _repoArtifact.GetArtifact(documentId, artifactId);
|
|
|
if (artifact == null)
|
|
if (artifact == null)
|
|
|
{
|
|
{
|
|
|
var exc = new EntityNotExistsException(typeof(Artifact), nameof(Artifact.Id), artifactId);
|
|
var exc = new EntityNotExistsException(typeof(Artifact), nameof(Artifact.Id), artifactId);
|