Micha Kops avatar Micha Kops committed cf1f575

Initial import.

Comments (0)

Files changed (5)

+.project
+.settings
+.classpath
+target
+# Togglz Feature Flag Tutorial
+
+A tutorial how to embed feature flags in a Java EE web application.
+
+Please feel free to have a look at [my blog] for further details.
+
+----
+
+**2013 Micha Kops / hasCode.com**
+
+   [my blog]:http://www.hascode.com
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+	<modelVersion>4.0.0</modelVersion>
+	<groupId>com.hascode.tutorial</groupId>
+	<artifactId>togglz-feature-flag-tutorial</artifactId>
+	<version>1.0.0</version>
+
+	<properties>
+		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+		<togglz.version>2.0.0.RC1</togglz.version>
+	</properties>
+
+	<dependencies>
+		<dependency>
+			<groupId>org.togglz</groupId>
+			<artifactId>togglz-core</artifactId>
+			<version>${togglz.version}</version>
+		</dependency>
+		<dependency>
+			<groupId>org.togglz</groupId>
+			<artifactId>togglz-servlet</artifactId>
+			<version>${togglz.version}</version>
+		</dependency>
+		<dependency>
+			<groupId>org.togglz</groupId>
+			<artifactId>togglz-console</artifactId>
+			<version>${togglz.version}</version>
+		</dependency>
+		<dependency>
+			<groupId>org.togglz</groupId>
+			<artifactId>togglz-jsf</artifactId>
+			<version>${togglz.version}</version>
+		</dependency>
+		<dependency>
+			<groupId>org.togglz</groupId>
+			<artifactId>togglz-slf4j</artifactId>
+			<version>${togglz.version}</version>
+		</dependency>
+		<dependency>
+			<groupId>org.glassfish.main.extras</groupId>
+			<artifactId>glassfish-embedded-all</artifactId>
+			<version>3.1.2.2</version>
+			<scope>provided</scope>
+		</dependency>
+	</dependencies>
+
+	<build>
+		<plugins>
+			<plugin>
+				<artifactId>maven-compiler-plugin</artifactId>
+				<configuration>
+					<source>1.7</source>
+					<target>1.7</target>
+				</configuration>
+			</plugin>
+			<plugin>
+				<groupId>org.apache.maven.plugins</groupId>
+				<artifactId>maven-war-plugin</artifactId>
+				<version>2.1.1</version>
+				<configuration>
+					<failOnMissingWebXml>false</failOnMissingWebXml>
+				</configuration>
+			</plugin>
+		</plugins>
+	</build>
+</project>

src/main/java/com/hascode/tutorial/fflag/config/FeatureFlagConfiguration.java

+package com.hascode.tutorial.fflag.config;
+
+import javax.enterprise.context.ApplicationScoped;
+
+import org.togglz.core.Feature;
+import org.togglz.core.manager.TogglzConfig;
+import org.togglz.core.repository.StateRepository;
+import org.togglz.core.repository.mem.InMemoryStateRepository;
+import org.togglz.core.user.UserProvider;
+import org.togglz.servlet.user.ServletUserProvider;
+
+import com.hascode.tutorial.fflag.feature.UserFeatures;
+
+@ApplicationScoped
+public class FeatureFlagConfiguration implements TogglzConfig {
+
+	private static final String FEATURE_FLAG_ADMIN_ROLE = "feature_flag_admin";
+
+	@Override
+	public Class<? extends Feature> getFeatureClass() {
+		return UserFeatures.class;
+	}
+
+	@Override
+	public StateRepository getStateRepository() {
+		return new InMemoryStateRepository();
+	}
+
+	@Override
+	public UserProvider getUserProvider() {
+		return new ServletUserProvider(FEATURE_FLAG_ADMIN_ROLE);
+	}
+
+}

src/main/java/com/hascode/tutorial/fflag/feature/UserFeatures.java

+package com.hascode.tutorial.fflag.feature;
+
+import org.togglz.core.Feature;
+import org.togglz.core.annotation.Label;
+import org.togglz.core.context.FeatureContext;
+
+public enum UserFeatures implements Feature {
+	@Label("Displays basic information for a given user")
+	DISPLAY_SIMPLE_USER_PROFILE,
+
+	@Label("Displays extended information for a given user")
+	DISPLAY_EXTENDED_USER_PROFILE;
+
+	public boolean isActive() {
+		return FeatureContext.getFeatureManager().isActive(this);
+	}
+}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.