Skip to content

Commit

Permalink
Detect if profile is set in the target container and add it when crea…
Browse files Browse the repository at this point in the history
…ting a fabric
  • Loading branch information
gashcrumb committed Aug 28, 2013
1 parent 7dcbe76 commit 88d1e6a
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 14 deletions.
53 changes: 43 additions & 10 deletions hawtio-web/src/main/java/io/hawt/web/BrandingServlet.java
@@ -1,25 +1,35 @@
package io.hawt.web;

import org.jolokia.converter.Converters;
import org.jolokia.converter.json.JsonConvertOptions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.management.AttributeNotFoundException;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import java.util.*;

/**
* @author Stan Lewis
*/
public class BrandingServlet extends HttpServlet {

private static final transient Logger LOG = LoggerFactory.getLogger(BrandingServlet.class);

List<String> propertiesToCheck = new ArrayList<String>();
List<String> wantedStrings = new ArrayList<String>();
boolean forceBranding;
boolean useBranding = true;
String profile;
Converters converters = new Converters();
JsonConvertOptions options = JsonConvertOptions.DEFAULT;


@Override
public void init(ServletConfig config) throws ServletException {
Expand All @@ -31,6 +41,7 @@ public void init(ServletConfig config) throws ServletException {

forceBranding = Boolean.parseBoolean(System.getProperty("hawtio.forceBranding", "false"));
useBranding = Boolean.parseBoolean(System.getProperty("hawtio.useBranding", "true"));
profile = System.getProperty("profile");

super.init(config);
}
Expand All @@ -39,17 +50,40 @@ public void init(ServletConfig config) throws ServletException {
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

Map<String, String> answer = new HashMap<String, String>();

answer.put("profile", profile);
answer.put("enable", enableBranding().toString());

response.setContentType("application/json");
final PrintWriter out = response.getWriter();

Object result = null;

try {
result = converters.getToJsonConverter().convertToJson(answer, null, options);
} catch (AttributeNotFoundException e) {
LOG.warn("Failed to convert plugin list to json", e);
}

if (result != null) {
out.write(result.toString());
out.flush();
out.close();
} else {
out.write("{ \"enable\":\"false\"}");
}

}

private Boolean enableBranding() {

if (forceBranding) {
writeTrue(out);
return;
return true;
}

if (!useBranding) {
writeFalse(out);
return;
return false;
}

Properties systemProperties = System.getProperties();
Expand All @@ -66,13 +100,12 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response) t
if (value != null) {
for (String wanted : wantedStrings) {
if (value.contains(wanted)) {
writeTrue(out);
return true;
}
}
}
}

writeFalse(out);
return false;
}

private void writeTrue(PrintWriter out) {
Expand Down
7 changes: 5 additions & 2 deletions hawtio-web/src/main/webapp/app/branding/js/brandingPlugin.ts
@@ -1,14 +1,16 @@
module Branding {

export var enabled = false;
export var profile = null;

$.get('/hawtio/branding', (enabled) => {
Branding.enabled = enabled;
$.get('/hawtio/branding', (response) => {
Branding.enabled = response.enable;

// Branding.enabled = false;
// Branding.enabled = true;

if (Branding.enabled) {
Branding.profile = response.profile;
// pull in branding stylesheet
var link = $("<link>");
$("head").append(link);
Expand Down Expand Up @@ -38,6 +40,7 @@ module Branding {
branding.appLogo = 'img/branding/RHJB_Fuse_UXlogotype_0513LL_white.svg';
branding.loginBg = 'img/branding/login-screen-background.jpg';
branding.fullscreenLogin = true;
branding.profile = Branding.profile;
}

});
Expand Down
8 changes: 7 additions & 1 deletion hawtio-web/src/main/webapp/app/fabric/js/createFabric.ts
@@ -1,6 +1,6 @@
module Fabric {

export function CreateFabricController($scope, jolokia, $location, workspace:Workspace) {
export function CreateFabricController($scope, jolokia, $location, workspace:Workspace, branding) {

$scope.$on('$routeChangeSuccess', () => {
if (workspace.treeContainsDomainAndProperties(Fabric.jmxDomain, {type: "Fabric"})) {
Expand All @@ -24,6 +24,12 @@ module Fabric {
profiles: ['fabric', 'hawtio']
};

if (branding.profile) {
$scope.entity.profiles.push(branding.profile);
}

// console.log("entity: ", $scope.entity);

$scope.forms = {};

$scope.onSubmit = (json, form) => {
Expand Down
Expand Up @@ -2,7 +2,7 @@ module Fabric {

export function customizeSchema(id, schema) {

console.log("Schema: ", schema);
// console.log("Schema: ", schema);

Core.pathSet(schema, ["properties", "name", "required"], true);

Expand Down

0 comments on commit 88d1e6a

Please sign in to comment.