Defining Notifications
From Projectivity Documentation
In this section we will see how to send email notifications when a certain event occurs in Projectivity. Once again we will follow the Customer Management application which defines the following notifications:
- When a customer is created send an email to the Sales Director and to the CEO
- When the status of a customer is modified send an email to the Account Manager
- When a document is created or modified in the repository of a Customer send an email to the Account Manager
In the Projectivity Framework SDK any type of notification is called a Watch. In our example we have 3 different types of watches:
- A watch fired when a workspace is created
- A watch fired when a workspace is modified
- A watch fired when the document structure of a workspace is modified
In order to create a notification the Projectivity Framework SDK has the PredefinedWatch Object.
// We now define 2 watches: 1 for the sales director and another for the ceo
PredefinedWatch newCustomer_SalesDir = new PredefinedWatch(_roleCompanySALESDIR, defNameCompany);
newCustomer_SalesDir.setCustomTemplateKey("custmanagement_new_customer_salesdir");
newCustomer_SalesDir.setOneShotCondition();
PredefinedWatch newCustomer_CEO = new PredefinedWatch(_roleCompanyCEO, defNameCompany);
newCustomer_CEO.setCustomTemplateKey("custmanagement_new_customer_ceo");
newCustomer_CEO.setOneShotCondition();
// Create a collection of watches for the customer type
Collection<PredefinedWatch> customerWatches = new ArrayList<PredefinedWatch>();
customerWatches.add(newCustomer_SalesDir);
customerWatches.add(newCustomer_CEO);
// Now create the watch to send an email to the account manager when the customer status is modified
MetaDataReference custStatusRef = new MetaDataReference(defNameCustomer, "State");
PredefinedWatch custStatusChangeWatch_AccountMngr = new PredefinedWatch(_roleCustomerAMNGR, defNameCustomer, custStatusRef, WatchDTO.ConditionOperator.UPDATED, "", false);
custStatusChangeWatch_AccountMngr.setOneShotCondition();
custStatusChangeWatch_AccountMngr.setCustomTemplateKey("custmanagement_customer_state_accountmngr");
// Now add to the list of watches
customerWatches.add(custStatusChangeWatch_AccountMngr);
// Now create a watch that is fired when the document structure of a Customer is modified
VirtualPath rootPath = new VirtualPath("/");
PredefinedWatch modifDocumentCustWatch_AccountManager = new PredefinedWatch(rootPath, _roleCustomerAMNGR, defNameCustomer);
modifDocumentCustWatch_AccountManager.setOneShotCondition();
modifDocumentCustWatch_AccountManager.setCustomTemplateKey("custmanagement_customer_doc_accountmngr");
// Now add to the list of watches
customerWatches.add(modifDocumentCustWatch_AccountManager);

