001/* 002 * (C) Copyright 2010 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 * 016 * Contributors: 017 * Nuxeo - initial API and implementation 018 */ 019 020package org.nuxeo.connect.client.status; 021 022import java.util.Calendar; 023 024import org.nuxeo.connect.connector.ConnectSecurityError; 025import org.nuxeo.connect.data.SubscriptionStatus; 026 027/** 028 * Simple Wrapper to add label computation to the {@link SubscriptionStatus} 029 * 030 * @author tiry 031 */ 032public class SubscriptionStatusWrapper extends SubscriptionStatus { 033 034 protected boolean isSecurityError = false; 035 036 protected boolean canNotReachConnectServer = false; 037 038 protected boolean versionMismatch = false; 039 040 protected Calendar refreshDate; 041 042 public SubscriptionStatusWrapper(String errorMessage) { 043 this.errorMessage = errorMessage; 044 refreshDate = Calendar.getInstance(); 045 } 046 047 public SubscriptionStatusWrapper(ConnectSecurityError securityException) { 048 this(securityException.getMessage()); 049 isSecurityError = true; 050 } 051 052 public SubscriptionStatusWrapper(SubscriptionStatus status) { 053 contractStatus = status.getContractStatus(); 054 description = status.getDescription(); 055 instanceType = status.getInstanceType(); 056 message = status.getMessage(); 057 errorMessage = status.getErrorMessage(); 058 endDate = status.getEndDate(); 059 refreshDate = Calendar.getInstance(); 060 } 061 062 public String getinstanceTypeLabel() { 063 return "label.instancetype." + getInstanceType().toString(); 064 } 065 066 public String getContractStatusLabel() { 067 return "label.subscriptionStatus." + getContractStatus(); 068 } 069 070 public boolean isError() { 071 return errorMessage != null || isSecurityError || versionMismatch || canNotReachConnectServer; 072 } 073 074 public boolean isConnectServerUnreachable() { 075 return canNotReachConnectServer; 076 } 077 078 public boolean isVersionMismatch() { 079 return versionMismatch; 080 } 081 082 public boolean isSecurityError() { 083 return isSecurityError; 084 } 085 086 public Calendar getRefreshDate() { 087 return refreshDate; 088 } 089 090}