001/* 002 * (C) Copyright 2010 Nuxeo SAS (http://nuxeo.com/) and contributors. 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the GNU Lesser General Public License 006 * (LGPL) version 2.1 which accompanies this distribution, and is available at 007 * http://www.gnu.org/licenses/lgpl.html 008 * 009 * This library is distributed in the hope that it will be useful, 010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 012 * Lesser General Public License for more details. 013 * 014 * Contributors: 015 * Nuxeo - initial API and implementation 016 */ 017 018package org.nuxeo.connect.client.status; 019 020import java.util.Calendar; 021 022import org.nuxeo.connect.connector.ConnectSecurityError; 023import org.nuxeo.connect.data.SubscriptionStatus; 024 025/** 026 * Simple Wrapper to add label computation to the {@link SubscriptionStatus} 027 * 028 * @author tiry 029 */ 030public class SubscriptionStatusWrapper extends SubscriptionStatus { 031 032 protected boolean isSecurityError = false; 033 034 protected boolean canNotReachConnectServer = false; 035 036 protected boolean versionMismatch = false; 037 038 protected Calendar refreshDate; 039 040 public SubscriptionStatusWrapper(String errorMessage) { 041 this.errorMessage = errorMessage; 042 refreshDate = Calendar.getInstance(); 043 } 044 045 public SubscriptionStatusWrapper(ConnectSecurityError securityException) { 046 this(securityException.getMessage()); 047 isSecurityError = true; 048 } 049 050 public SubscriptionStatusWrapper(SubscriptionStatus status) { 051 contractStatus = status.getContractStatus(); 052 description = status.getDescription(); 053 instanceType = status.getInstanceType(); 054 message = status.getMessage(); 055 errorMessage = status.getErrorMessage(); 056 endDate = status.getEndDate(); 057 refreshDate = Calendar.getInstance(); 058 } 059 060 public String getinstanceTypeLabel() { 061 return "label.instancetype." + getInstanceType().toString(); 062 } 063 064 public String getContractStatusLabel() { 065 return "label.subscriptionStatus." + getContractStatus(); 066 } 067 068 public boolean isError() { 069 return errorMessage != null || isSecurityError || versionMismatch || canNotReachConnectServer; 070 } 071 072 public boolean isConnectServerUnreachable() { 073 return canNotReachConnectServer; 074 } 075 076 public boolean isVersionMismatch() { 077 return versionMismatch; 078 } 079 080 public boolean isSecurityError() { 081 return isSecurityError; 082 } 083 084 public Calendar getRefreshDate() { 085 return refreshDate; 086 } 087 088}