I would like to trap the file upload event in IBM Connections, and take some actions. If a particular criteria gets satisfied, the file should be stored within the system, or else should be rejected with a message.
For this, I was exploring the IBM Connections SPI ( Pre-Event Handler hooks ). I have followed the necessary steps required as per the document to create the jar, deploy and change the configurations, but it seems that my code doesn't get called, when a file is uploaded into Connections.
Not sure, where lies the issue, as I don't get any errors too.
PS: I tried the Post Event handler hook and it worked successfully.
Following are the snippets
public class PreHandlerEvents implements PreEventHandler{
@Override
public void destroy() {
// TODO Auto-generated method stub
}
@Override
public void handleEvent(MutableEvent arg0) throws EventHandlerException {
String content = "This is the content to write into file";
File file = new File("filenamePre.txt");
// if file doesnt exists, then create it
if (!file.exists()) {
try {
file.createNewFile();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
FileWriter fw;
try {
fw = new FileWriter(file.getAbsoluteFile());
BufferedWriter bw = new BufferedWriter(fw);
bw.write(content);
bw.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
events-config.xml
<preHandler enabled="true" name="PreHandlerEvents" class="com.connections.PreHandlerEvents">
<subscriptions>
<subscription source="*" type="*" eventName="*"/>
</subscriptions>
</preHandler>
</preHandlers>