Develop a Publish Trigger

ediego's Avatar

ediego

11 Jul, 2015 02:02 PM

I am working on a publish trigger to minify certain file types in my CMS. I am using the example http://www.hannonhill.com/kb/Publish-Triggers/ but I have some quest.
1. Is there any documentation on the PublishTrigger SDK and more in depth examples?
2. The code uses system.out to output debug information, but where does that output go?
3. I would like to integrate my plugin logging into the Logging functionality that already exists in cascade server. Is there any documentation or examples that shows how to do that?

thanks.

  1. 1 Posted by ediego on 15 Jul, 2015 07:38 PM

    ediego's Avatar

    anybody ??

  2. 2 Posted by Ryan Griffith on 15 Jul, 2015 08:29 PM

    Ryan Griffith's Avatar

    Hi Emil,

    Our apologies for the delayed response to your discussion, it looks like it was set to private which would be why no one outside of Hannon Hill saw your questions.

    Is there any documentation on the PublishTrigger SDK and more in depth examples?

    Beyond that page, there isn't much else in terms of documentation. As for examples, there is the simple example at the bottom of the page you linked, or you can also access it on the Publish Trigger SDK Github project. I also have a couple of triggers that I published as gists on Github:

    The code uses system.out to output debug information, but where does that output go?

    If I recall, this type of logging is displayed within tomcat/logs/catalina.out.

    I would like to integrate my plugin logging into the Logging functionality that already exists in cascade server. Is there any documentation or examples that shows how to do that?

    There is actually an example of this within the Docx Publish Trigger I linked above.

    Basically, you add the following above your constructor:

    private static final Logger LOG = Logger.getLogger(DocxPublishTrigger.class);
    

    And add logging statements like this one.

    Then, enable debug logging (or whatever level you choose) for your Publish Trigger class by passing in the full path to your class (eg com.cms.publish.client.DocxPublishTrigger).

    Note: replace DocxPublishTrigger with the class name of your Publish Trigger.

    The logging will be output to tomcat/logs/cascade.log.

    Please let me know if you have any questions.

    Thanks!

  3. 3 Posted by ediego on 16 Jul, 2015 12:04 PM

    ediego's Avatar

    Awesome, thanks. I'll take a look at those.

  4. 4 Posted by Ryan Griffith on 16 Jul, 2015 12:33 PM

    Ryan Griffith's Avatar

    Not a problem at all, Emil. I'm going to go ahead and close this discussion, but please feel free to comment or reply to re-open if you have any additional questions.

    Have a great day!

  5. Ryan Griffith closed this discussion on 16 Jul, 2015 12:33 PM.

  6. ediego re-opened this discussion on 20 Jul, 2015 11:40 AM

  7. 5 Posted by ediego on 20 Jul, 2015 11:40 AM

    ediego's Avatar

    I got really far with this over the weekend. I implemented the logging and have the css and js file contents being compressed in the publish trigger. Just have a few questions about how to publish that content. Thanks again for all your help.

    1. Is there any mechanism built into the publish trigger API that allows me to override the file contents that gets published to the Destination? Or does the CMS just publish the content normally and then calls the publish trigger after that step?

    2. If that's the case then do I have to manually FTP the contents of the new file to the Destination?

    3. To cover all the transport types I would need to implement a method to write the compressed file contents to the local filesystem, the database, and a FTP/SFTP server? The file system and FTP/SFTP seem pretty straight forward, but I'm not sure how to implement the database transport. Are there any examples of this ?

  8. 6 Posted by ediego on 22 Jul, 2015 11:59 AM

    ediego's Avatar

    bump

  9. 7 Posted by Ryan Griffith on 23 Jul, 2015 12:13 PM

    Ryan Griffith's Avatar

    Hi Emil,

    After some digging, I was able to locate this related discussion I had with another client, perhaps the thread might prove to be useful.

    Is there any mechanism built into the publish trigger API that allows me to override the file contents that gets published to the Destination? Or does the CMS just publish the content normally and then calls the publish trigger after that step?

    For each asset that gets published during a publish job your publish trigger will be invoked for each available Output and Destination, so this would be after the actual publish. Each time the trigger is invoked, you will have access to the following information:

    • entityType
    • entityId
    • entityPath
    • targetId (if in Global)
    • targetPath (if in Global)
    • destination (same as destinationId below)
    • transportId
    • destinationId
    • destinationName
    • pageConfigurationId
    • unpublish

    For asset content, you should be able to perform additional read operations using the information provided to you. If you are dealing with Files, you should be able to read the File asset to obtain it's content, pass it though some sort of compression and then use the Transport/Destination information to send the file back out, similar to what the .docx trigger does. Pages would be a little more difficult since you would just get structured data and not the rendered content.

    If that's the case then do I have to manually FTP the contents of the new file to the Destination?

    Correct, you would use the Transport/Destination information provided to the publish trigger. See above.

    To cover all the transport types I would need to implement a method to write the compressed file contents to the local filesystem, the database, and a FTP/SFTP server? The file system and FTP/SFTP seem pretty straight forward, but I'm not sure how to implement the database transport. Are there any examples of this ?

    Correct, you would need to implement each type of Transport depending on your use case. For Database Transports, obtaining the connection information would be similar to FTP/SFTP; however, instead of opening an FTP connection you are opening a database connection. If you are dealing with Files, database publishing does only publishes page content (DEFAULT region) and not file content.

    That being said, if you are looking to minify specific files, you could set up a page that has a file chooser and a single DEFAULT region with a Velocity Format that reads the file's content using the Locator Tool and strips all line breaks.

    Please let me know if you have any questions.

    Thanks!

  10. 8 Posted by ediego on 23 Jul, 2015 12:33 PM

    ediego's Avatar

    Thanks. I already have the publish trigger reading the contents of a "File" and compressing them. js and css files. I was just wondering what the best way to write that content out to the destination.

    Since your software supports mysql, oracle and MS SQL then I would have to write classes for all those platforms. Not something I am particularly looking forward. I was just hoping there was a mechanism built into the PublishTrigger API that would allow me to write the modified content, since that functionality is already implemented in the CMS.

    For phase 1 of my Publish Trigger I will just support FTP destinations and filesystem and only worry about database destinations if there is some over whelming need for that.

    Thanks a lot for your help and guidance on this.

  11. 9 Posted by Ryan Griffith on 23 Jul, 2015 01:05 PM

    Ryan Griffith's Avatar

    Hi Emil,

    Since your software supports mysql, oracle and MS SQL then I would have to write classes for all those platforms. Not something I am particularly looking forward. I was just hoping there was a mechanism built into the PublishTrigger API that would allow me to write the modified content, since that functionality is already implemented in the CMS.

    As I mentioned, Database Transports will not publish file content, only system and metadata information about the file. With that said, it sounds as though you won't need to add additional code for these types of Transports.

    As always, please let me know if you have any questions.

    Thanks!

  12. Tim closed this discussion on 11 Aug, 2015 07:12 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac