Skip to content

Commit

Permalink
Merge pull request #1780 from asanchezr/uat_is31_release
Browse files Browse the repository at this point in the history
Test -> Master - UAT IS31 release
  • Loading branch information
asanchezr authored Jul 21, 2022
2 parents 55ff988 + 0b373a9 commit 0cdd112
Show file tree
Hide file tree
Showing 472 changed files with 164,940 additions and 82,182 deletions.
3 changes: 1 addition & 2 deletions backend/.editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,8 @@ dotnet_diagnostic.SA1124.severity = none
# SA1507 Code should not contain multiple blank lines in a row
dotnet_diagnostic.SA1507.severity = none


# Entity Framework files
[**{entities/ef/*,PIMSContext}.cs]
[**{entities/ef/*,PIMSContext,PimsBaseContext}.cs]
# CS8019: Using directive is unnecessary.
dotnet_diagnostic.CS8019.severity = none

Expand Down
2 changes: 1 addition & 1 deletion backend/api/Areas/Leases/Models/Lease/PropertyModel.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Pims.Api.Models;
using System;
using Pims.Api.Models;

namespace Pims.Api.Areas.Lease.Models.Lease
{
Expand Down
102 changes: 102 additions & 0 deletions backend/api/Areas/Notes/Controllers/NoteController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@

using MapsterMapper;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Pims.Api.Constants;
using Pims.Api.Models.Concepts;
using Pims.Api.Policies;
using Pims.Api.Services;
using Pims.Dal.Security;
using System.Collections.Generic;
using Swashbuckle.AspNetCore.Annotations;

namespace Pims.Api.Areas.Notes.Controllers
{
/// <summary>
/// NoteController class, provides endpoints for interacting with notes.
/// </summary>
[Authorize]
[ApiController]
[ApiVersion("1.0")]
[Area("notes")]
[Route("v{version:apiVersion}/[area]")]
[Route("[area]")]
public class NoteController : ControllerBase
{
#region Variables
private readonly INoteService _noteService;
private readonly IMapper _mapper;
#endregion

#region Constructors

/// <summary>
/// Creates a new instance of a NoteController class, initializes it with the specified arguments.
/// </summary>
/// <param name="noteService"></param>
/// <param name="mapper"></param>
///
public NoteController(INoteService noteService, IMapper mapper)
{
_noteService = noteService;
_mapper = mapper;
}
#endregion

#region Endpoints

/// <summary>
/// Add the specified note.
/// </summary>
/// <param name="type">The parent entity type.</param>
/// <param name="noteModel">The note to add.</param>
/// <returns></returns>
[HttpPost("{type}")]
[HasPermission(Permissions.NoteAdd)]
[Produces("application/json")]
[ProducesResponseType(typeof(EntityNoteModel), 200)]
[SwaggerOperation(Tags = new[] { "note" })]
public IActionResult AddNote(NoteType type, [FromBody] EntityNoteModel noteModel)
{
var createdNote = _noteService.Add(type, noteModel);
return new JsonResult(createdNote);
}

/// <summary>
/// Get the notes for the specified type and entity id.
/// </summary>
/// <param name="type">Used to identify note type.</param>
/// <param name="entityId">Used to identify note's parent entity.</param>
/// <returns></returns>
[HttpGet("{type}/{entityId}")]
[Produces("application/json")]
[HasPermission(Permissions.NoteView)]
[ProducesResponseType(typeof(IEnumerable<NoteModel>), 200)]
[SwaggerOperation(Tags = new[] { "note" })]
public IActionResult GetNotes(NoteType type, long entityId)
{
var notes = _noteService.GetNotes(type, entityId);
var mappedNotes = _mapper.Map<List<NoteModel>>(notes);
return new JsonResult(mappedNotes);
}

/// <summary>
/// Deletes the note for the specified type.
/// </summary>
/// <param name="type">Used to identify note type.</param>
/// <param name="noteId">Used to identify the note and delete it.</param>
/// <returns></returns>
[HttpDelete("{type}/{noteId}")]
[Produces("application/json")]
[HasPermission(Permissions.NoteDelete)]
[ProducesResponseType(typeof(bool), 200)]
[SwaggerOperation(Tags = new[] { "note" })]
public IActionResult DeleteNote(NoteType type, int noteId)
{
_noteService.DeleteNote(type, noteId);
return new JsonResult(true);
}
#endregion
}
}
14 changes: 14 additions & 0 deletions backend/api/Constants/NoteType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System.Runtime.Serialization;
using System.Text.Json.Serialization;

namespace Pims.Api.Constants
{
[JsonConverter(typeof(JsonStringEnumMemberConverter))]
public enum NoteType
{
[EnumMember(Value = "activity")]
Activity,
[EnumMember(Value = "file")]
File
}
}
74 changes: 61 additions & 13 deletions backend/api/Controllers/DocumentController.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Pims.Api.Models;
using Pims.Api.Models.Mayan;
using Pims.Api.Models.Mayan.Document;
using Pims.Api.Models.Mayan.Sync;
using Pims.Api.Policies;
using Pims.Api.Services;
using Pims.Dal.Entities;
using Pims.Dal.Security;
using Swashbuckle.AspNetCore.Annotations;

Expand All @@ -20,16 +26,19 @@ public class DocumentController : ControllerBase
{
#region Variables
private readonly IDocumentService _documentService;
private readonly IDocumentSyncService _documentSyncService;
#endregion

#region Constructors
/// <summary>
/// Creates a new instance of a ErrorController class.
/// </summary>
/// <param name="documentService"></param>
public DocumentController(IDocumentService documentService)
/// <param name="documentSyncService"></param>
public DocumentController(IDocumentService documentService, IDocumentSyncService documentSyncService)
{
_documentService = documentService;
_documentSyncService = documentSyncService;
}
#endregion

Expand All @@ -40,12 +49,12 @@ public DocumentController(IDocumentService documentService)
/// </summary>
[HttpGet("types")]
[HasPermission(Permissions.PropertyAdd)]
[ProducesResponseType(typeof(string), 200)]
[ProducesResponseType(typeof(ExternalResult<QueryResult<DocumentType>>), 200)]
[SwaggerOperation(Tags = new[] { "documents" })]
public IActionResult GetDocumentTypes()
{
var ast = _documentService.GetDocumentTypes();
return new JsonResult(ast);
var result = _documentService.GetDocumentTypes();
return new JsonResult(result);
}

/// <summary>
Expand All @@ -54,38 +63,77 @@ public IActionResult GetDocumentTypes()
[HttpGet]
[HasPermission(Permissions.PropertyAdd)]
[Produces("application/json")]
[ProducesResponseType(typeof(string), 200)]
[ProducesResponseType(typeof(ExternalResult<QueryResult<DocumentDetail>>), 200)]
[SwaggerOperation(Tags = new[] { "documents" })]
public IActionResult GetDocumentList()
{
var ast = _documentService.GetDocumentList();
return new JsonResult(ast);
var result = _documentService.GetDocumentList();
return new JsonResult(result);
}

/// <summary>
/// Downloads the file for the correspoding file and document id.
/// </summary>
[HttpGet("{documentId}/files/{fileId}/download")]
[HasPermission(Permissions.PropertyAdd)]
[ProducesResponseType(typeof(string), 200)]
[ProducesResponseType(typeof(ExternalResult<FileDownload>), 200)]
[SwaggerOperation(Tags = new[] { "documents" })]
public IActionResult DownloadFile(int documentId, int fileId)
{
var ast = _documentService.DownloadFile(documentId, fileId);
return new JsonResult(ast);
var result = _documentService.DownloadFile(documentId, fileId);
return new JsonResult(result);
}

/// <summary>
/// Uploads the passed document.
/// </summary>
[HttpPost]
[HasPermission(Permissions.PropertyAdd)]
[ProducesResponseType(typeof(string), 200)]
[ProducesResponseType(typeof(ExternalResult<DocumentDetail>), 200)]
[SwaggerOperation(Tags = new[] { "documents" })]
public IActionResult UploadDocument([FromForm] int documentType, [FromForm] IFormFile file)
{
var ast = _documentService.UploadDocument(documentType, file);
return new JsonResult(ast);
var result = _documentService.UploadDocument(documentType, file);
return new JsonResult(result);
}

/// <summary>
/// Uploads the passed document.
/// </summary>
[HttpPatch("sync/mayan/documenttype")]
//[HasPermission(Permissions.PropertyAdd)] // TODO: put the correct permission
[ProducesResponseType(typeof(ExternalBatchResult), 200)]
[SwaggerOperation(Tags = new[] { "documents" })]
public IActionResult SyncMayanDocumentTypes([FromBody] SyncModel model)
{
var result = _documentSyncService.SyncMayanDocumentTypes(model);
return new JsonResult(result);
}

/// <summary>
/// Uploads the passed document.
/// </summary>
[HttpPatch("sync/mayan/metadatatype")]
//[HasPermission(Permissions.PropertyAdd)] // TODO: put the correct permission
[ProducesResponseType(typeof(ExternalBatchResult), 200)]
[SwaggerOperation(Tags = new[] { "documents" })]
public IActionResult SyncMayanMetadataTypes([FromBody] SyncModel model)
{
var result = _documentSyncService.SyncMayanMetadataTypes(model);
return new JsonResult(result);
}

/// <summary>
/// Uploads the passed document.
/// </summary>
[HttpPatch("sync/backend/documenttype")]
//[HasPermission(Permissions.PropertyAdd)] // TODO: put the correct permission
[ProducesResponseType(typeof(PimsDocumentTyp), 200)]
[SwaggerOperation(Tags = new[] { "documents" })]
public async Task<IActionResult> SyncDocumentTypes()
{
var result = await _documentSyncService.SyncBackendDocumentTypes();
return new JsonResult(result);
}

#endregion
Expand Down
2 changes: 1 addition & 1 deletion backend/api/Helpers/Extensions/ExceptionExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Pims.Api.Helpers.Exceptions;
using System;
using Pims.Api.Helpers.Exceptions;

namespace Pims.Api.Helpers.Extensions
{
Expand Down
1 change: 0 additions & 1 deletion backend/api/Helpers/Middleware/LogResponseMiddleware.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Threading.Tasks;
Expand Down
27 changes: 27 additions & 0 deletions backend/api/Models/Concepts/Note/ActivityNoteMap.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using Mapster;
using Entity = Pims.Dal.Entities;

namespace Pims.Api.Models.Concepts
{
public class ActivityNoteMap : IRegister
{
public void Register(TypeAdapterConfig config)
{
config.NewConfig<Entity.PimsActivityInstanceNote, EntityNoteModel>()
.PreserveReference(true)
.Map(dest => dest.Id, src => src.PimsActivityInstanceNoteId)
.Map(dest => dest.Note, src => src.Note)
.Map(dest => dest.Parent, src => src)
.Inherits<Entity.IBaseAppEntity, BaseAppModel>();

config.NewConfig<EntityNoteModel, Entity.PimsActivityInstanceNote>()
.Map(dest => dest.PimsActivityInstanceNoteId, src => src.Id)
.Map(dest => dest.Note, src => src.Note)
.Map(dest => dest.ActivityInstanceId, src => src.Parent.Id)
.Inherits<BaseAppModel, Entity.IBaseAppEntity>();

config.NewConfig<Entity.PimsActivityInstanceNote, NoteParentModel>()
.ConstructUsing(src => new NoteParentModel { Id = src.ActivityInstanceId });
}
}
}
27 changes: 27 additions & 0 deletions backend/api/Models/Concepts/Note/EntityNoteModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
namespace Pims.Api.Models.Concepts
{
/// <summary>
/// EntityNoteModel class, provides a model to represent notes associated to entities.
/// </summary>
public class EntityNoteModel : BaseAppModel
{
#region Properties

/// <summary>
/// get/set - The id for this entity-note association.
/// </summary>
public long Id { get; set; }

/// <summary>
/// get/set - The parent entity that owns this note. Notes are associated to parent entities.
/// </summary>
public NoteParentModel Parent { get; set; }

/// <summary>
/// get/set - The note model.
/// </summary>
public NoteModel Note { get; set; }

#endregion
}
}
23 changes: 23 additions & 0 deletions backend/api/Models/Concepts/Note/NoteMap.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using Mapster;
using Entity = Pims.Dal.Entities;

namespace Pims.Api.Models.Concepts
{
public class NoteMap : IRegister
{
public void Register(TypeAdapterConfig config)
{
config.NewConfig<Entity.PimsNote, NoteModel>()
.PreserveReference(true)
.Map(dest => dest.Id, src => src.Id)
.Map(dest => dest.Note, src => src.NoteTxt)
.Map(dest => dest.RowVersion, src => src.ConcurrencyControlNumber)
.Inherits<Entity.IBaseAppEntity, BaseAppModel>();

config.NewConfig<NoteModel, Entity.PimsNote>()
.Map(dest => dest.Id, src => src.Id)
.Map(dest => dest.NoteTxt, src => src.Note)
.Inherits<BaseAppModel, Entity.IBaseAppEntity>();
}
}
}
23 changes: 23 additions & 0 deletions backend/api/Models/Concepts/Note/NoteModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

namespace Pims.Api.Models.Concepts
{
/// <summary>
/// NoteModel class, provides a model to represent notes associated to entities.
/// </summary>
public class NoteModel : BaseAppModel
{
#region Properties

/// <summary>
/// get/set - The id for this note.
/// </summary>
public long Id { get; set; }

/// <summary>
/// get/set - The note text contents.
/// </summary>
public string Note { get; set; }

#endregion
}
}
Loading

0 comments on commit 0cdd112

Please sign in to comment.