Overview

In the menu at the left File Management (FM) can be added and maintained. A FM is used to keep track of something normally involving a document but not necessary. A good example is to keep track of bank payment files coming from an ERP system. The payment files are processed signed and sent to the bank and then the bank send back feedback about the payment. FM is perfect to keep track of the flow and also provide an excellent documentation about what has been sent. 

Each FM added in the left menu could be stored in its own database currently MySQL and SQL Server is supported. By default the FA is stored in the internal 360 database. There is also an option to use a specific database schema for each FM. If schema is not specified the FM's and their documents are stored in the same tables but with unique ids that will separate them.

In the left menu new FM's can be created.
 
The form to create a new FM. The pool selected is where documents and all attachments are stored, everything is stored in the database thus a backup of the database will contain all files and information about the FM. 
In the example bellow the schema BANK is used, a new set of database tables is created for each schema. If 2 FM's use the same schema they will share the same database tables.

The classpath and the ControllerClass is used to provide actions in the UI. 



The example is using a SQL Server and a look in at the database tables 



When a controller class is specified and it provides actions a menu at each document is displayed. In the example bellow the controller provides a send to bank action 


The controller class is created in the workbench, create a class and select other and the screen bellow is shown.



The wizard generate some sample code which has been removed bellow. The BankHandler class implements MgmtController which is important and the first method getActions populate a map with the action key and description. The second parameter item is the item the action was performed at. The item can be used to get the parentid which is the Id of the FM, the status and other values can also be used to provide different actions depending on properties of the item.

The second method handleAction is called when an action is selected. The key parameter is the key of the action in the sample bellow when the key SEND is passed the MgmtAPI is used to get the first attached file and after the file is sent to the bank the document is updated with a new status and also new progress values.

public class BankHandler implements MgmtController{
	public void getActions(Map<String, String> actions, MgmtItem item){
		// Add action key plus a description that will be displayed in the context menu
		if(item.getStatus() == MgmtAPI.STATUS_CREATED){			
			actions.put("SEND", "Send to bank");
		}
	}
	public void handleAction(String key, MgmtItem item) throws Exception{
		if(key.equals("SEND")){
			MgmtAPI con = new MgmtAPI();
			// Get the first attachment
			MgmtAttachment att= item.getAttachment(0);
			// Download the file
			String filepath = "c:\\temp\\"+UUIDGenerator.generate();			
			con.getFile(item.getParentid(), att.getId(), filepath);
			// Now send the filepath file to the bank
			sendToBank(filepath);
			// Update the status, set the document to PROGRESS and the progress step to 1 out of 5			
			con.update(item.getParentid(), item.getId(), null, null, MgmtAPI.STATUS_PROGRESS, 0, 1, 5);
		}
	}

Performing the SEND action will change the status and also remove the action icon since the getAction method in the sample check  that the document is in status CREATED. 



The file is send to the bank and we will use the MgmtAPI to do any additional work with the document.
For tracking reasons we would like to attach all bank response files to the corresponding document. 

To update a document 2 parameter are required the parentid which is the Id of the FM and the itemId which is the Id of the document. The document Id is something you set when adding the document in the first place. It could be an order number, transaction number or anything. If you never need to update a document it could simply be a genereted UUID. 


When a response file from the bank arrives the document status is updated and total amount payed is added as extra value. The arrived file is also attached to the document. 

First a connection to the local WebAdmin is done with the  new MgmtAPI().
The parentid which is the id of the FM is retrieved through the API. Note this is the same id displayed in the browser address bar when selecting a FM in the left menu.


MgmtAPI con = new MgmtAPI();
			
Mgmt m = con.get("BankPayments");
String parentid = m.getId();
			
con.update(parentid, itemid, null, null, MgmtAPI.STATUS_OK, 0, 0, 0);
con.addDoc(parentid, itemid, null, filepath);
con.setExtra(parentid, itemid, "Tot Payed", "235.45", MgmtAPI.TYPE_GREY_LABEL);


After the code above have executed the document has changed status to green OK and has now 2 attachments which is also indicated with an image followed by (2). The figure bellow shows when the document is expanded, the extra field Tot payed is printed first and then some standard fields. The attachments are listed last and selecting the name will try to show the attachment in the browser using a plugin e.g. pdf. The download image at the right will download the attachment