// Path: app/dto/objects/ConnectionDto.java
// public class ConnectionDto {
// 
//     protected String ipAddress;
//     protected String iqn;
// 
//     public ConnectionDto(String ipAddress, String iqn) {
//         this.ipAddress = ipAddress;
//         this.iqn = iqn;
//     }
// 
//     public String getIpAddress() {
//         return ipAddress;
//     }
// 
//     public void setIpAddress(String ipAddress) {
//         this.ipAddress = ipAddress;
//     }
// 
//     public String getIqn() {
//         return iqn;
//     }
// 
//     public void setIqn(String iqn) {
//         this.iqn = iqn;
//     }
// }
// 
// Path: app/dto/response/ServiceResponse.java
// public class ServiceResponse<T> {
// 	
// 	private boolean success;
// 	private String userMessage;
// 	private String errorMessage;
// 	private String sessionId;
// 	
// 	private T data;
// 	
// 	public static <T> ServiceResponse<T> success(String userMessage) {
// 		return ServiceResponse.successToken(userMessage, null, null);
// 	}
// 	
// 	public static <T> ServiceResponse<T> success(T data) {
// 		return ServiceResponse.successToken(null, data, null);
// 	}
// 	
// 	public static <T> ServiceResponse<T> success(String userMessage, T data) {
// 		return ServiceResponse.successToken(userMessage, data, null);
// 	}
// 	
// 	public static <T> ServiceResponse<T> successToken(String userMessage, T data, String token) {
// 		ServiceResponse<T> response = new ServiceResponse<T>();
// 	    response.setSuccess(true);
// 	    response.setData(data);
// 	    response.setUserMessage(userMessage);
// 	    response.setSessionId(token);
// 	    return response;
// 	}
// 	
// 	public static <T> ServiceResponse<T> error(String errorMessage) {
// 	    return error(errorMessage, null);
// 	}
// 	
// 	public static <T> ServiceResponse<T> error(String errorMessage, String sessionId) {
// 		ServiceResponse<T> response = new ServiceResponse<T>();
// 	    response.setSuccess(false);
// 	    response.setErrorMessage(errorMessage);
// 	    response.setSessionId(sessionId);
// 	    return response;
// 	}
// 	
// 	protected ServiceResponse() {
// 		this.success = false;
// 	}
// 	
// 	protected ServiceResponse(String sessionId) {
// 		this.success = true;
// 		this.sessionId = sessionId;
// 	}
// 	
// 	protected ServiceResponse(String sessionId, T data) {
// 		this.success = true;
// 		this.sessionId = sessionId;
// 		this.data = data;
// 	}
// 	
// 	public T getData() {
// 		return data;
// 	}
// 
// 	public void setData(T data) {
// 		this.data = data;
// 	}
// 
// 	public boolean isSuccess() {
// 		return success;
// 	}
// 
// 	public void setSuccess(boolean success) {
// 		this.success = success;
// 	}
// 
// 	public String getUserMessage() {
// 		return userMessage;
// 	}
// 
// 	public void setUserMessage(String userMessage) {
// 		this.userMessage = userMessage;
// 	}
// 
// 	public String getErrorMessage() {
// 		return errorMessage;
// 	}
// 
// 	public void setErrorMessage(String errorMessage) {
// 		this.errorMessage = errorMessage;
// 	}
// 
// 	public String getSessionId() {
// 		return sessionId;
// 	}
// 
// 	public void setSessionId(String sessionId) {
// 		this.sessionId = sessionId;
// 	}
// 	
// 	public String toJsonString() {
// 		return new Gson().toJson(this);
// 	}
// }
// 
// Path: app/models/DatabaseConnection.java
// @Entity
// public class DatabaseConnection extends BaseModel {
// 
//     @Required
//     @MaxSize(20)
//     @Column(name="origin_connection", nullable = false, length = 20)
//     public String originConnection;
// 
// 
//     @Required
//     @MaxSize(20)
//     @Column(name="destination_connection", nullable = false, length = 20)
//     public String destinationConnection;
// 
// }
// 
// Path: app/models/DatabaseIQN.java
// @Entity
// public class DatabaseIQN extends BaseModel {
// 
//     @Required
//     @MaxSize(255)
//     @Column(name="origin_iqn", nullable = false, length = 255)
//     public String originIQN;
// 
// 
//     @Required
//     @MaxSize(255)
//     @Column(name="destination_iqn", nullable = false, length = 255)
//     public String destinationIQN;
// }


import dto.objects.ConnectionDto;
import dto.response.ServiceResponse;
import models.DatabaseConnection;
import models.DatabaseIQN;
import play.jobs.Job;
import play.libs.F;
import java.util.ArrayList;
import java.util.List;
/*
 *   Copyright 2016 ITM, S.A.
 *
 *   Licensed under the Apache License, Version 2.0 (the "License");
 *   you may not use this file except in compliance with the License.
 *   You may obtain a copy of the License at
 * `*   `[`http://www.apache.org/licenses/LICENSE-2.0`](http://www.apache.org/licenses/LICENSE-2.0)
 *
 *   Unless required by applicable law or agreed to in writing, software
 *   distributed under the License is distributed on an "AS IS" BASIS,
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *   See the License for the specific language governing permissions and
 *   limitations under the License.
 */
package jobs.services;



/**
 * Created by jandrad on 2/02/16.
 */


public class ConnectionStatusJob extends Job<ConnectionStatusJob.ConnectionStatus> {

    public enum ConnectionStatus {
        UNKNOWN,
        PRODUCTION,
        CONTINGENCY
    }

    @Override
    public ConnectionStatus doJobWithResult() throws Exception {

        F.Promise<ServiceResponse> storageResponse = new StorageConnectionsJob().now();
        ServiceResponse serviceResponse = storageResponse.get();
        if (serviceResponse.isSuccess()) {

            int contingency = 0;
            int production = 0;
            int unknown = 0;

            //Get connections
// Path: app/dto/objects/ConnectionDto.java
// public class ConnectionDto {
// 
//     protected String ipAddress;
//     protected String iqn;
// 
//     public ConnectionDto(String ipAddress, String iqn) {
//         this.ipAddress = ipAddress;
//         this.iqn = iqn;
//     }
// 
//     public String getIpAddress() {
//         return ipAddress;
//     }
// 
//     public void setIpAddress(String ipAddress) {
//         this.ipAddress = ipAddress;
//     }
// 
//     public String getIqn() {
//         return iqn;
//     }
// 
//     public void setIqn(String iqn) {
//         this.iqn = iqn;
//     }
// }
// 
// Path: app/dto/response/ServiceResponse.java
// public class ServiceResponse<T> {
// 	
// 	private boolean success;
// 	private String userMessage;
// 	private String errorMessage;
// 	private String sessionId;
// 	
// 	private T data;
// 	
// 	public static <T> ServiceResponse<T> success(String userMessage) {
// 		return ServiceResponse.successToken(userMessage, null, null);
// 	}
// 	
// 	public static <T> ServiceResponse<T> success(T data) {
// 		return ServiceResponse.successToken(null, data, null);
// 	}
// 	
// 	public static <T> ServiceResponse<T> success(String userMessage, T data) {
// 		return ServiceResponse.successToken(userMessage, data, null);
// 	}
// 	
// 	public static <T> ServiceResponse<T> successToken(String userMessage, T data, String token) {
// 		ServiceResponse<T> response = new ServiceResponse<T>();
// 	    response.setSuccess(true);
// 	    response.setData(data);
// 	    response.setUserMessage(userMessage);
// 	    response.setSessionId(token);
// 	    return response;
// 	}
// 	
// 	public static <T> ServiceResponse<T> error(String errorMessage) {
// 	    return error(errorMessage, null);
// 	}
// 	
// 	public static <T> ServiceResponse<T> error(String errorMessage, String sessionId) {
// 		ServiceResponse<T> response = new ServiceResponse<T>();
// 	    response.setSuccess(false);
// 	    response.setErrorMessage(errorMessage);
// 	    response.setSessionId(sessionId);
// 	    return response;
// 	}
// 	
// 	protected ServiceResponse() {
// 		this.success = false;
// 	}
// 	
// 	protected ServiceResponse(String sessionId) {
// 		this.success = true;
// 		this.sessionId = sessionId;
// 	}
// 	
// 	protected ServiceResponse(String sessionId, T data) {
// 		this.success = true;
// 		this.sessionId = sessionId;
// 		this.data = data;
// 	}
// 	
// 	public T getData() {
// 		return data;
// 	}
// 
// 	public void setData(T data) {
// 		this.data = data;
// 	}
// 
// 	public boolean isSuccess() {
// 		return success;
// 	}
// 
// 	public void setSuccess(boolean success) {
// 		this.success = success;
// 	}
// 
// 	public String getUserMessage() {
// 		return userMessage;
// 	}
// 
// 	public void setUserMessage(String userMessage) {
// 		this.userMessage = userMessage;
// 	}
// 
// 	public String getErrorMessage() {
// 		return errorMessage;
// 	}
// 
// 	public void setErrorMessage(String errorMessage) {
// 		this.errorMessage = errorMessage;
// 	}
// 
// 	public String getSessionId() {
// 		return sessionId;
// 	}
// 
// 	public void setSessionId(String sessionId) {
// 		this.sessionId = sessionId;
// 	}
// 	
// 	public String toJsonString() {
// 		return new Gson().toJson(this);
// 	}
// }
// 
// Path: app/models/DatabaseConnection.java
// @Entity
// public class DatabaseConnection extends BaseModel {
// 
//     @Required
//     @MaxSize(20)
//     @Column(name="origin_connection", nullable = false, length = 20)
//     public String originConnection;
// 
// 
//     @Required
//     @MaxSize(20)
//     @Column(name="destination_connection", nullable = false, length = 20)
//     public String destinationConnection;
// 
// }
// 
// Path: app/models/DatabaseIQN.java
// @Entity
// public class DatabaseIQN extends BaseModel {
// 
//     @Required
//     @MaxSize(255)
//     @Column(name="origin_iqn", nullable = false, length = 255)
//     public String originIQN;
// 
// 
//     @Required
//     @MaxSize(255)
//     @Column(name="destination_iqn", nullable = false, length = 255)
//     public String destinationIQN;
// }


// Path: app/jobs/services/ConnectionStatusJob.java
import dto.objects.ConnectionDto;
import dto.response.ServiceResponse;
import models.DatabaseConnection;
import models.DatabaseIQN;
import play.jobs.Job;
import play.libs.F;
import java.util.ArrayList;
import java.util.List;

/*
 *   Copyright 2016 ITM, S.A.
 *
 *   Licensed under the Apache License, Version 2.0 (the "License");
 *   you may not use this file except in compliance with the License.
 *   You may obtain a copy of the License at
 * `*   `[`http://www.apache.org/licenses/LICENSE-2.0`](http://www.apache.org/licenses/LICENSE-2.0)
 *
 *   Unless required by applicable law or agreed to in writing, software
 *   distributed under the License is distributed on an "AS IS" BASIS,
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *   See the License for the specific language governing permissions and
 *   limitations under the License.
 */
package jobs.services;



/**
 * Created by jandrad on 2/02/16.
 */


public class ConnectionStatusJob extends Job<ConnectionStatusJob.ConnectionStatus> {

    public enum ConnectionStatus {
        UNKNOWN,
        PRODUCTION,
        CONTINGENCY
    }

    @Override
    public ConnectionStatus doJobWithResult() throws Exception {

        F.Promise<ServiceResponse> storageResponse = new StorageConnectionsJob().now();
        ServiceResponse serviceResponse = storageResponse.get();
        if (serviceResponse.isSuccess()) {

            int contingency = 0;
            int production = 0;
            int unknown = 0;

            //Get connections
            List<DatabaseConnection> connections = DatabaseConnection.find("active = :a").bind("a", true).fetch();