package com.oracle.determinations.interview.engine.userplugins;
import com.oracle.determinations.interview.engine.DocumentGeneratorService;
import com.oracle.determinations.interview.engine.exceptions.DocumentGenerationException;
import com.oracle.determinations.interview.engine.local.AttributeGoal;
import com.oracle.determinations.interview.engine.plugins.docgen.DocumentGenerationParameters;
import com.oracle.determinations.interview.util.TypedInputStream;
import com.oracle.determinations.web.platform.controller.SessionContext;
import com.oracle.determinations.web.platform.eventmodel.events.OnInvestigationEndedEvent;
import com.oracle.determinations.web.platform.eventmodel.handlers.OnInvestigationEndedEventHandler;
import com.oracle.determinations.web.platform.plugins.PlatformSessionPlugin;
import com.oracle.determinations.web.platform.plugins.PlatformSessionRegisterArgs;
public class SaveTxtDocument implements OnInvestigationEndedEventHandler {
//REQUIRED - by OnInvestigationEndedEventHandler interface
public void handleEvent(Object sender, OnInvestigationEndedEvent event) {
AttributeGoal iGoal = (AttributeGoal)event.getInvestigatedGoal();
String goalID = iGoal.getAttribute().getName();
if(iGoal.getAttribute().getName().equals("tickets") && iGoal.isKnown())
{
SessionContext session = event.getSessionContext();
DocumentGeneratorService dgs = session.getInterviewSession().getDocumentGeneratorService();
try
{
DocumentGenerationParameters dgp = new DocumentGenerationParameters("docGen", "", "", "TXT");
TypedInputStream document = dgs.generateDocument("TXT", dgp);
//Do something with the document e.g. email, or save to a datasource
}
catch(DocumentGenerationException dge)
{
// The 'TXT' Document Generator plugin is not registered
}
}
}
//REQUIRED - for Plugin architecture
public SaveTxtDocument()
{
}
//REQUIRED - by PlatformSessionPlugin interface
public PlatformSessionPlugin getInstance(PlatformSessionRegisterArgs args) {
//Demonstration of a Plugin only registering if the current rulebase is 'DocumentGeneration'
if (args.getContext().getInterviewSession().getRulebase().getIdentifier().equals("DocumentGeneration")){
return new SaveTxtDocument();
} else {
return null;
}
}
}