/*
 * oxTrust is available under the MIT License (2008). See http://opensource.org/licenses/MIT for full text.
 *
 * Copyright (c) 2014, Gluu
 */

package org.gluu.oxtrust.action;

import static org.jboss.seam.ScopeType.CONVERSATION;

import java.io.Serializable;
import java.util.Date;

import org.gluu.oxtrust.ldap.service.ApplianceService;
import org.gluu.oxtrust.model.GluuAppliance;
import org.gluu.oxtrust.util.OxTrustConstants;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;

/**
 * Action class for health check display
 * 
 * @author Oleksiy Tataryn Date: 11.14.2013
 */
@Scope(CONVERSATION)
@Name("applianceStatusAction")
public class ApplianceStatusAction implements Serializable {

	private static final long serialVersionUID = -7470520478553992898L;

	@In
	private ApplianceService applianceService;

	private String health;

	public String checkHealth() {
		GluuAppliance appliance = applianceService.getAppliance();
		Date lastUpdateDateTime = appliance.getLastUpdate();
		int lastUpdate = 0;
		if (lastUpdateDateTime != null) {
			lastUpdate = (int) (lastUpdateDateTime.getTime() / 1000);
		}

		int currentTime = (int) (System.currentTimeMillis() / 1000);
		int timeSinceLastUpdate = currentTime - lastUpdate;
		if (timeSinceLastUpdate >= 0 && timeSinceLastUpdate < 100) {
			this.setHealth("OK");
		} else {
			this.setHealth("FAIL");
		}

		return OxTrustConstants.RESULT_SUCCESS;
	}

	public String getHealth() {
		return health;
	}

	public void setHealth(String health) {
		this.health = health;
	}

}

@@ -1053,19 +1053,20 @@
 te();%0A%09%09
-int
+long
  lastUpd
@@ -1126,23 +1126,16 @@
 pdate = 
-(int) (
 lastUpda
@@ -1154,24 +1154,16 @@
 etTime()
- / 1000)
 ;%0A%09%09%7D%0A%0A%09
@@ -1163,19 +1163,20 @@
 %0A%09%09%7D%0A%0A%09%09
-int
+long
  current
@@ -1186,15 +1186,8 @@
 e = 
-(int) (
 Syst
@@ -1212,23 +1212,16 @@
 is()
- / 1000);%0A%09%09int
+;%0A%09%09long
  tim

Fix status checker method