# IWS5.Api - FEMA
The IWS5.Api project is a RESTful API which provides endpoints and methods for client applications to consume to facilitate workflow processing by users of the Process Director system. For the FEMA branch specifically, the API is consumed by the [React Rapid Workplace (react-rwp)](https://github.com/Greenfield-Investments/react-rwp) application.

There are a number of differences in IWS5.Api functionality between the FEMA and LPNU branches. The below documentation is for the FEMA branch only. Please read the appropriate documentation for the branch you wish to use.

## Controllers
The primary code found in this project are the [Controllers](Controllers/), which have names ending in `Controller.cs` (auto-detected by ASP.NET) and expose API endpoints for consumption by client applications. These controllers call service methods in the [IWS5.Services](../IWS5.Services/) project, with the exception of [PdfViewerController.cs](Controllers/PdfViewerController.cs) which calls Syncfusion PDF Viewer methods (unused in the FEMA branch but still included). All IWS5.Api endpoints begin with `/api`.

## Code Inconsistencies
Although all of the API methods in this project should work as intended, there are some inconsistencies in their implementations that may be confusing. For example: some methods take a work item's `workItemId` property to locate it, while others take its `workItemReferenceId`. Those values should be the same for a given work item in a fresh deployment, but may not necessarily be. In some cases, these parameters are sometimes labeled as one when they mean the other.

Additionally, some methods return responses using incorrect HTTP response codes, or do not return JSON data in the same format as others. Error handling is also inconsistent. Essentially, these inconsistencies are a clear case of one developer working solely on one set of methods and other developers working solely on others.

Future revisions of the API should solve these inconsistencies.

## Development & Configuration
The IWS5.Api project has three `appsettings.json` files which contain configuration variables that must be set/updated for the API to run:

1. LDAP variables (used for Active Directory authentication):
    1. `server` - The hostname of an Active Directory controller, accessible over the network. Can be either an IP address, hostname, or FQDN.
    2. `port` - The port used for LDAP connection. The default `389` will suffice for most deployments, but `636` can be used for secure connections.
    3. `subDomain` - The subdomain of the Active Directory domain to connect to. If your domain is `gfi.com`, this value would be `gfi`.
    4. `domain` - The extension of the Active Directory domain to connect to. If your domain is `gfi.com`, this value would be `com`.
2. Connection strings (used for database connection):
    1. `GreenfieldPD` - The full connection string to authenticate with a local or production copy of the Process Director database. For example: `Data Source=MY-DATABASE-SERVER;User ID=PDAdmin;Password=MY_SECURE_PASSWORD;Initial Catalog=ProcessDirector;Encrypt=True;Trust Server Certificate=True`. In general, this string is dependent on the SQL Server configuration, but the PDAdmin user (with the `sysadmin` role on the server) should be used.
3. Serilog (logging) - The important variable(s) here are `path`, which control where API log files are written to. The default location is recommended, but can be changed at will.

As previously mentioned, IWS5.Api has *three* of these `appsettings.json` files (or, at least, three that are actually important): `appsettings.json`, `appsettings.QA.json`, and `appsettings.Production.json`. In theory, the publish profile settings used when publishing the project should determine which of these files is actually read during runtime, however this setup is not fully understood. It is recommended to configure all of these files in the same way to prevent configuration mismatches, and the [IWS5.Api setup package script](https://github.com/Greenfield-Investments/setup-packages/tree/main/IWS5.Api) modifies all three with the values for the LDAP and database connections provided by the user during installation.

Additionally, a valid Syncfusion Essential Studio license key must be supplied in [Program.cs](Program.cs) for PDF processing functionalities to work properly.

## Dependencies
To use the LPNU work item signage functionality, the [Java SE Development Kit 25.0.1](https://download.oracle.com/java/25/latest/jdk-25_windows-x64_bin.exe) must be installed.

## Additional Notes
The FEMA branch of IWS5.Api has a few additional methods that are not found in the LPNU branch:

1. `PATCH /api/Document/rename` - Provides the ability to rename a document.
2. `PUT /api/Document/update-doc-content` - Provides the ability to update a document's content (bytes) in-place.
3. `POST /api/WorkItem/clone` - Provides the ability to create a full clone of a work item, including all notes, documents, folder field values, document template field values, and etc.
4. `POST /api/WorkItem/delete` Provides the ability to delete a work item.

There are also some methods found in the LPNU branch that are not found in the FEMA branch. Please see the documentation for the LPNU branch of the IWS5.Api project for details about these missing endpoints.