Skip to content

Instantly share code, notes, and snippets.

@xlcommunity
Last active August 29, 2015 14:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xlcommunity/73f857c158e4d82eaea5 to your computer and use it in GitHub Desktop.
Save xlcommunity/73f857c158e4d82eaea5 to your computer and use it in GitHub Desktop.
ExampleRepositoryEventListener.java
/*
* THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
* EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. THIS
* CODE AND INFORMATION ARE NOT SUPPORTED BY XEBIALABS.
*/
package ext.deployit.listener;
import com.xebialabs.deployit.engine.spi.event.*;
import com.xebialabs.deployit.plugin.api.udm.ConfigurationItem;
import com.xebialabs.deployit.plugin.api.reflect.Type;
import com.xebialabs.xlrelease.domain.Release;
import nl.javadude.t2bus.Subscribe;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@DeployitEventListener
public class ExampleRepositoryEventListener {
private static final Logger logger = LoggerFactory.getLogger(ExampleRepositoryEventListener.class);
// templates are stored as releases with status 'TEMPLATE'
private static final Type RELEASE_TYPE = Type.valueOf("xlrelease.Release");
@Subscribe
public void receiveCisCreated(CisCreatedEvent event) {
for (ConfigurationItem ci : event.getCis()) {
if (isTemplate(ci)) {
logger.info("Received event after creating template: {}", ci);
}
}
}
private static boolean isTemplate(ConfigurationItem ci) {
return ci.getType().equals(RELEASE_TYPE) && ((Release) ci).isTemplate();
}
@Subscribe
public void receiveCisUpdated(CisUpdatedEvent event) {
for (ConfigurationItem ci : event.getCis()) {
if (isTemplate(ci)) {
logger.info("Received event after updating template: {}", ci);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment