Coverage Report - org.kuali.student.r2.common.dto.ContextInfo
 
Classes in this File Line Coverage Branch Coverage Complexity
ContextInfo
0%
0/38
0%
0/4
1.154
 
 1  
 /*
 2  
  * Copyright 2011 The Kuali Foundation
 3  
  *
 4  
  * Licensed under the Educational Community License, Version 1.0 (the
 5  
  * "License"); you may not use this file except in compliance with the
 6  
  * License.  You may obtain a copy of the License at
 7  
  *
 8  
  * http://www.opensource.org/licenses/ecl1.php
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 15  
  */
 16  
 package org.kuali.student.r2.common.dto;
 17  
 
 18  
 import java.io.Serializable;
 19  
 import java.util.Date;
 20  
 import java.util.List;
 21  
 
 22  
 import javax.xml.bind.annotation.XmlAccessType;
 23  
 import javax.xml.bind.annotation.XmlAccessorType;
 24  
 import javax.xml.bind.annotation.XmlAnyElement;
 25  
 import javax.xml.bind.annotation.XmlElement;
 26  
 import javax.xml.bind.annotation.XmlType;
 27  
 
 28  
 import org.kuali.student.r2.common.infc.Context;
 29  
 import org.w3c.dom.Element;
 30  
 
 31  
 /**
 32  
  * The DTO for a Context.
 33  
  *
 34  
  * @author Kamal
 35  
  */
 36  0
 @XmlAccessorType(XmlAccessType.FIELD)
 37  
 @XmlType(name = "ContextInfo", propOrder = {"authenticatedPrincipalId", 
 38  
                 "principalId",
 39  
                 "currentDate", 
 40  
                 "locale", 
 41  
                 "timeZone",
 42  
                 "attributes", 
 43  
                 "_futureElements"})
 44  
 
 45  
 public class ContextInfo
 46  
         extends HasAttributesInfo
 47  
         implements Context, Serializable {
 48  
 
 49  
     private static final long serialVersionUID = 1L;
 50  
 
 51  
     @XmlElement
 52  
     private String authenticatedPrincipalId;
 53  
 
 54  
     @XmlElement
 55  
     private String principalId;
 56  
 
 57  
     @XmlElement
 58  
     private Date currentDate;
 59  
 
 60  
     @XmlElement
 61  
     private LocaleInfo locale;
 62  
 
 63  
     @XmlElement
 64  
     private String timeZone;
 65  
 
 66  
     @XmlAnyElement
 67  
     private List<Element> _futureElements;
 68  
 
 69  
 
 70  
     /**
 71  
      * Constructs a new ContextInfo.
 72  
      */
 73  0
     public ContextInfo() {
 74  0
         this.locale = new LocaleInfo();
 75  0
         this.currentDate = new Date();
 76  0
     }
 77  
 
 78  
     /**
 79  
      * Constructs a new ContextInfo from another Context.
 80  
      *
 81  
      * @param context the context to copy
 82  
      */
 83  
     public ContextInfo(Context context) {
 84  0
         super(context);
 85  
 
 86  0
         this.authenticatedPrincipalId = context.getAuthenticatedPrincipalId();
 87  0
         this.principalId = context.getPrincipalId();
 88  
 
 89  0
         if (context.getLocale() != null) {
 90  0
             this.locale = new LocaleInfo(context.getLocale());
 91  
         }
 92  
 
 93  0
         if (context.getCurrentDate() != null) {
 94  0
             this.currentDate = new Date(context.getCurrentDate().getTime());
 95  
         } else {
 96  0
             this.currentDate = new Date();
 97  
         }
 98  
 
 99  0
         this.timeZone = context.getTimeZone();
 100  0
     }
 101  
 
 102  
     @Override
 103  
     public String getAuthenticatedPrincipalId() {
 104  0
         return authenticatedPrincipalId;
 105  
     }
 106  
 
 107  
     public void setAuthenticatedPrincipalId(String authenticatedPrincipalId) {
 108  0
         this.authenticatedPrincipalId = authenticatedPrincipalId;
 109  0
     }
 110  
 
 111  
     @Override
 112  
     public String getPrincipalId() {
 113  0
         return principalId;
 114  
     }
 115  
 
 116  
     public void setPrincipalId(String principalId) {
 117  0
         this.principalId = principalId;
 118  0
     }
 119  
 
 120  
     @Override
 121  
     public Date getCurrentDate() {
 122  0
         return currentDate;
 123  
     }
 124  
 
 125  
     public void setCurrentDate(Date currentDate) {
 126  0
         this.currentDate = currentDate;
 127  0
     }
 128  
 
 129  
     @Override
 130  
     public LocaleInfo getLocale() {
 131  0
         return this.locale;
 132  
     }
 133  
 
 134  
     public void setLocale(LocaleInfo locale) {
 135  0
         this.locale = locale;
 136  0
     }
 137  
 
 138  
     @Override
 139  
     public String getTimeZone() {
 140  0
         return timeZone;
 141  
     }
 142  
 
 143  
     public void setTimeZone(String timeZone) {
 144  0
         this.timeZone = timeZone;
 145  0
     }
 146  
 
 147  
     // Compatibility methods
 148  
 
 149  
     @Deprecated
 150  
     public static ContextInfo getInstance(String principalId, String localeLanguage, String localeRegion) {
 151  0
         LocaleInfo localeInfo = new LocaleInfo();
 152  0
         localeInfo.setLocaleLanguage(localeLanguage);
 153  0
         localeInfo.setLocaleRegion(localeRegion);
 154  
 
 155  0
         ContextInfo ctx = new ContextInfo();
 156  0
         ctx.setAuthenticatedPrincipalId(principalId);
 157  0
         ctx.setPrincipalId(principalId);
 158  0
         ctx.setLocale(localeInfo);
 159  
 
 160  0
         return ctx;
 161  
     }
 162  
 }