001    /*
002     * Copyright 2009-2015 UnboundID Corp.
003     * All Rights Reserved.
004     */
005    /*
006     * Copyright (C) 2015 UnboundID Corp.
007     *
008     * This program is free software; you can redistribute it and/or modify
009     * it under the terms of the GNU General Public License (GPLv2 only)
010     * or the terms of the GNU Lesser General Public License (LGPLv2.1 only)
011     * as published by the Free Software Foundation.
012     *
013     * This program is distributed in the hope that it will be useful,
014     * but WITHOUT ANY WARRANTY; without even the implied warranty of
015     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
016     * GNU General Public License for more details.
017     *
018     * You should have received a copy of the GNU General Public License
019     * along with this program; if not, see <http://www.gnu.org/licenses>.
020     */
021    package com.unboundid.ldap.sdk.unboundidds;
022    
023    
024    
025    import java.util.Date;
026    
027    import com.unboundid.ldap.sdk.Entry;
028    import com.unboundid.ldap.sdk.ReadOnlyEntry;
029    import com.unboundid.util.NotMutable;
030    import com.unboundid.util.ThreadSafety;
031    import com.unboundid.util.ThreadSafetyLevel;
032    
033    
034    
035    /**
036     * <BLOCKQUOTE>
037     *   <B>NOTE:</B>  This class is part of the Commercial Edition of the UnboundID
038     *   LDAP SDK for Java.  It is not available for use in applications that
039     *   include only the Standard Edition of the LDAP SDK, and is not supported for
040     *   use in conjunction with non-UnboundID products.
041     * </BLOCKQUOTE>
042     * This class provides a data structure for representing an administrative entry
043     * as exposed by the alerts backend in the UnboundID Directory Server.  Alert
044     * entries provide information about warnings, errors, or other significant
045     * events that could impact the availability or function of the UnboundID
046     * Directory Server.
047     */
048    @NotMutable()
049    @ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE)
050    public final class AlertEntry
051           extends ReadOnlyEntry
052    {
053      /**
054       * The name of the structural object class that will be used for entries
055       * containing information about administrative alerts.
056       */
057      public static final String OC_ALERT = "ds-admin-alert";
058    
059    
060    
061      /**
062       * The name of the attribute that contains the fully-qualified name of the
063       * server class that generated the alert notification.
064       */
065      public static final String ATTR_ALERT_GENERATOR = "ds-alert-generator";
066    
067    
068    
069      /**
070       * The name of the attribute that contains the unique ID assigned to the alert
071       * notification.
072       */
073      public static final String ATTR_ALERT_ID = "ds-alert-id";
074    
075    
076    
077      /**
078       * The name of the attribute that contains a message with additional
079       * information about the alert notification.
080       */
081      public static final String ATTR_ALERT_MESSAGE = "ds-alert-message";
082    
083    
084    
085      /**
086       * The name of the attribute that contains the severity of the alert
087       * notification.
088       */
089      public static final String ATTR_ALERT_SEVERITY = "ds-alert-severity";
090    
091    
092    
093      /**
094       * The name of the attribute that contains the time that the alert
095       * notification was generated.
096       */
097      public static final String ATTR_ALERT_TIME = "ds-alert-time";
098    
099    
100    
101      /**
102       * The name of the attribute that contains the name of the alert type.
103       */
104      public static final String ATTR_ALERT_TYPE = "ds-alert-type";
105    
106    
107    
108      /**
109       * The name of the attribute that contains the OID assigned to the alert type.
110       */
111      public static final String ATTR_ALERT_TYPE_OID = "ds-alert-type-oid";
112    
113    
114    
115      /**
116       * The serial version UID for this serializable class.
117       */
118      private static final long serialVersionUID = -2912778595612338699L;
119    
120    
121    
122      // The severity for this alert entry.
123      private final AlertSeverity alertSeverity;
124    
125      // The time that the alert notification was generated.
126      private final Date alertTime;
127    
128      // The fully-qualified name of the alert generator class.
129      private final String alertGeneratorClass;
130    
131      // The unique identifier assigned to the alert notification.
132      private final String alertID;
133    
134      // The message for the alert notification.
135      private final String alertMessage;
136    
137      // The name of the alert type for the alert notification.
138      private final String alertType;
139    
140      // The OID for the alert type.
141      private final String alertTypeOID;
142    
143    
144    
145      /**
146       * Creates a new alert entry from the provided entry.
147       *
148       * @param  entry  The entry from which to create this alert entry.
149       */
150      public AlertEntry(final Entry entry)
151      {
152        super(entry);
153    
154        alertGeneratorClass = entry.getAttributeValue(ATTR_ALERT_GENERATOR);
155        alertID             = entry.getAttributeValue(ATTR_ALERT_ID);
156        alertMessage        = entry.getAttributeValue(ATTR_ALERT_MESSAGE);
157        alertType           = entry.getAttributeValue(ATTR_ALERT_TYPE);
158        alertTypeOID        = entry.getAttributeValue(ATTR_ALERT_TYPE_OID);
159    
160        alertTime = entry.getAttributeValueAsDate(ATTR_ALERT_TIME);
161    
162        final String severityStr = entry.getAttributeValue(ATTR_ALERT_SEVERITY);
163        if (severityStr == null)
164        {
165          alertSeverity = null;
166        }
167        else
168        {
169          alertSeverity = AlertSeverity.forName(severityStr);
170        }
171      }
172    
173    
174    
175      /**
176       * Retrieves the fully-qualified name of the class that generated the alert
177       * notification.
178       *
179       * @return  The fully-qualified name of the class that generated the alert
180       *          notification, or {@code null} if it was not included in the alert
181       *          entry.
182       */
183      public String getAlertGeneratorClass()
184      {
185        return alertGeneratorClass;
186      }
187    
188    
189    
190      /**
191       * Retrieves the unique identifier for the alert notification.
192       *
193       * @return  The unique identifier for the alert notification, or {@code null}
194       *          if it was not included in the alert entry.
195       */
196      public String getAlertID()
197      {
198        return alertID;
199      }
200    
201    
202    
203      /**
204       * Retrieves the message for the alert notification.
205       *
206       * @return  The message for the alert notification, or {@code null} if it was
207       *          not included in the alert entry.
208       */
209      public String getAlertMessage()
210      {
211        return alertMessage;
212      }
213    
214    
215    
216      /**
217       * Retrieves the severity for the alert notification.
218       *
219       * @return  The severity for the alert notification, or {@code null} if it was
220       *          not included in the alert entry, or if it included an unknown
221       *          severity.
222       */
223      public AlertSeverity getAlertSeverity()
224      {
225        return alertSeverity;
226      }
227    
228    
229    
230      /**
231       * Retrieves the time that the alert notification was generated.
232       *
233       * @return  The time that the alert notification was generated, or
234       *          {@code null} if it was not included in the alert entry or if the
235       *          alert time value could not be parsed.
236       */
237      public Date getAlertTime()
238      {
239        return alertTime;
240      }
241    
242    
243    
244      /**
245       * Retrieves the name of the alert type for the alert notification.
246       *
247       * @return  The name of the alert type for the alert notification, or
248       *          {@code null} if it was not included in the alert entry.
249       */
250      public String getAlertType()
251      {
252        return alertType;
253      }
254    
255    
256    
257      /**
258       * Retrieves the OID of the alert type for the alert notification.
259       *
260       * @return  The OID of the alert type for the alert notification, or
261       *          {@code null} if it was not included in the alert entry.
262       */
263      public String getAlertTypeOID()
264      {
265        return alertTypeOID;
266      }
267    }