|  1 |     | 
   package org.kuali.student.enrollment.class1.lui.model;  | 
  |  2 |     | 
     | 
  |  3 |     | 
   import java.util.ArrayList;  | 
  |  4 |     | 
   import java.util.Date;  | 
  |  5 |     | 
   import java.util.List;  | 
  |  6 |     | 
   import java.util.Set;  | 
  |  7 |     | 
     | 
  |  8 |     | 
   import javax.persistence.*;  | 
  |  9 |     | 
     | 
  |  10 |     | 
   import org.kuali.student.common.entity.KSEntityConstants;  | 
  |  11 |     | 
   import org.kuali.student.enrollment.class1.lrc.model.ResultValuesGroupEntity;  | 
  |  12 |     | 
   import org.kuali.student.enrollment.lui.dto.LuiInfo;  | 
  |  13 |     | 
   import org.kuali.student.enrollment.lui.infc.Lui;  | 
  |  14 |     | 
   import org.kuali.student.enrollment.lui.infc.LuiIdentifier;  | 
  |  15 |     | 
   import org.kuali.student.r2.common.entity.MetaEntity;  | 
  |  16 |     | 
   import org.kuali.student.r2.common.infc.Attribute;  | 
  |  17 |     | 
   import org.kuali.student.r2.common.util.RichTextHelper;  | 
  |  18 |     | 
   import org.kuali.student.r2.common.util.constants.LuiServiceConstants;  | 
  |  19 |     | 
   import org.kuali.student.r2.lum.clu.infc.LuCode;  | 
  |  20 |     | 
     | 
  |  21 |     | 
   @Entity  | 
  |  22 |     | 
   @Table(name = "KSEN_LUI")  | 
  |  23 |     | 
   public class LuiEntity extends MetaEntity { | 
  |  24 |     | 
     | 
  |  25 |     | 
       @Column(name = "NAME")  | 
  |  26 |     | 
       private String name;  | 
  |  27 |     | 
       @Column(name = "DESCR_FORMATTED", length = KSEntityConstants.EXTRA_LONG_TEXT_LENGTH)  | 
  |  28 |     | 
       private String formatted;  | 
  |  29 |     | 
       @Column(name = "DESCR_PLAIN", length = KSEntityConstants.EXTRA_LONG_TEXT_LENGTH)  | 
  |  30 |     | 
       private String plain;  | 
  |  31 |     | 
       @Column(name = "LUI_TYPE")  | 
  |  32 |     | 
       private String luiType;  | 
  |  33 |     | 
       @Column(name = "LUI_STATE")  | 
  |  34 |     | 
       private String luiState;  | 
  |  35 |     | 
       @Column(name = "CLU_ID")  | 
  |  36 |     | 
       private String cluId;  | 
  |  37 |     | 
       @Column(name = "ATP_ID")  | 
  |  38 |     | 
       private String atpId;  | 
  |  39 |     | 
       @Column(name = "REF_URL")  | 
  |  40 |     | 
       private String referenceURL;  | 
  |  41 |     | 
       @Column(name = "MAX_SEATS")  | 
  |  42 |     | 
       private Integer maxSeats;  | 
  |  43 |     | 
       @Column(name = "MIN_SEATS")  | 
  |  44 |     | 
       private Integer minSeats;  | 
  |  45 |     | 
       @Column(name = "SCHEDULE_ID")  | 
  |  46 |     | 
       private String scheduleId;  | 
  |  47 |     | 
       @Temporal(TemporalType.TIMESTAMP)  | 
  |  48 |     | 
       @Column(name = "EFF_DT")  | 
  |  49 |     | 
       private Date effectiveDate;  | 
  |  50 |     | 
       @Temporal(TemporalType.TIMESTAMP)  | 
  |  51 |     | 
       @Column(name = "EXPIR_DT")  | 
  |  52 |     | 
       private Date expirationDate;  | 
  |  53 |     | 
     | 
  |  54 |     | 
       @ManyToMany  | 
  |  55 |     | 
       @JoinTable(name="KSEN_LUI_RESULT_VAL_GRP",  | 
  |  56 |     | 
               joinColumns=  | 
  |  57 |     | 
               @JoinColumn(name="LUI_ID", referencedColumnName="ID"),  | 
  |  58 |     | 
               inverseJoinColumns=  | 
  |  59 |     | 
               @JoinColumn(name="RESULT_VAL_GRP_ID", referencedColumnName="ID")  | 
  |  60 |     | 
       )  | 
  |  61 |     | 
       private List<ResultValuesGroupEntity> resultValuesGroups;  | 
  |  62 |     | 
     | 
  |  63 |     | 
       @ManyToMany  | 
  |  64 |     | 
       @JoinTable(name="KSEN_LUI_UNITS_CONT_OWNER",  | 
  |  65 |     | 
               joinColumns=  | 
  |  66 |     | 
               @JoinColumn(name="LUI_ID", referencedColumnName="ID"),  | 
  |  67 |     | 
               inverseJoinColumns=  | 
  |  68 |     | 
               @JoinColumn(name="ORG_ID", referencedColumnName="ORG_ID")  | 
  |  69 |     | 
       )  | 
  |  70 |     | 
       private List<LuiUnitsContentOwnerEntity> luiContentOwner;  | 
  |  71 |     | 
     | 
  |  72 |     | 
       @ManyToMany  | 
  |  73 |     | 
       @JoinTable(name="KSEN_LUI_UNITS_DEPLOYMENT",  | 
  |  74 |     | 
               joinColumns=  | 
  |  75 |     | 
               @JoinColumn(name="LUI_ID", referencedColumnName="ID"),  | 
  |  76 |     | 
               inverseJoinColumns=  | 
  |  77 |     | 
               @JoinColumn(name="ORG_ID", referencedColumnName="ORG_ID")  | 
  |  78 |     | 
       )  | 
  |  79 |     | 
       private List<LuiUnitsDeploymentEntity> luiUnitsDeployment;  | 
  |  80 |     | 
     | 
  |  81 |     | 
     | 
  |  82 |     | 
       @OneToMany(cascade = CascadeType.ALL, mappedBy = "lui")  | 
  |  83 |     | 
       private List<LuiIdentifierEntity> identifiers;  | 
  |  84 |     | 
       @OneToMany(cascade = CascadeType.ALL, mappedBy = "lui")  | 
  |  85 |     | 
       private List<LuCodeEntity> luiCodes;  | 
  |  86 |     | 
     | 
  |  87 |     | 
     | 
  |  88 |     | 
     | 
  |  89 |     | 
       @OneToMany(cascade = CascadeType.ALL, mappedBy = "owner")  | 
  |  90 |     | 
       private List<LuiAttributeEntity> attributes;  | 
  |  91 |     | 
     | 
  |  92 |    0 |        public LuiEntity() { | 
  |  93 |    0 |        }  | 
  |  94 |     | 
     | 
  |  95 |     | 
       public LuiEntity(Lui lui) { | 
  |  96 |    0 |            super(lui);  | 
  |  97 |    0 |            this.setId(lui.getId());  | 
  |  98 |    0 |            this.setLuiType(lui.getTypeKey());  | 
  |  99 |    0 |            this.setAtpId(lui.getAtpId());  | 
  |  100 |    0 |            this.setCluId(lui.getCluId());  | 
  |  101 |     | 
     | 
  |  102 |    0 |            fromDto(lui);  | 
  |  103 |    0 |        }  | 
  |  104 |     | 
     | 
  |  105 |     | 
       public void fromDto(Lui lui) { | 
  |  106 |    0 |            this.setName(lui.getName());  | 
  |  107 |    0 |            this.setMaxSeats(lui.getMaximumEnrollment());  | 
  |  108 |    0 |            this.setMinSeats(lui.getMinimumEnrollment());  | 
  |  109 |    0 |            this.setReferenceURL(lui.getReferenceURL());  | 
  |  110 |    0 |            this.setLuiState(lui.getStateKey());  | 
  |  111 |    0 |            this.setEffectiveDate(lui.getEffectiveDate());  | 
  |  112 |    0 |            this.setExpirationDate(lui.getExpirationDate());  | 
  |  113 |    0 |            if (lui.getDescr() == null) { | 
  |  114 |    0 |                this.setDescrFormatted(null);  | 
  |  115 |    0 |                this.setDescrPlain(null);  | 
  |  116 |     | 
           } else { | 
  |  117 |    0 |                this.setDescrFormatted(lui.getDescr().getFormatted());  | 
  |  118 |    0 |                this.setDescrPlain(lui.getDescr().getPlain());  | 
  |  119 |     | 
           }  | 
  |  120 |     | 
     | 
  |  121 |    0 |            this.setLuiCodes(new ArrayList<LuCodeEntity>());  | 
  |  122 |    0 |            for (LuCode luCode : lui.getLuiCodes()) { | 
  |  123 |    0 |                this.getLuiCodes().add(new LuCodeEntity(luCode));  | 
  |  124 |     | 
           }  | 
  |  125 |     | 
     | 
  |  126 |     | 
             | 
  |  127 |     | 
             | 
  |  128 |    0 |            this.setIdentifiers(new ArrayList<LuiIdentifierEntity>());  | 
  |  129 |    0 |            if (lui.getOfficialIdentifier() != null) { | 
  |  130 |    0 |                this.getIdentifiers().add(new LuiIdentifierEntity(lui.getOfficialIdentifier()));  | 
  |  131 |     | 
           }  | 
  |  132 |    0 |            for (LuiIdentifier identifier : lui.getAlternateIdentifiers()) { | 
  |  133 |    0 |                this.getIdentifiers().add(new LuiIdentifierEntity(identifier));  | 
  |  134 |     | 
           }  | 
  |  135 |     | 
     | 
  |  136 |    0 |            List<LuiUnitsContentOwnerEntity> luiUnitsContentOwnerEntities = new ArrayList<LuiUnitsContentOwnerEntity>();  | 
  |  137 |     | 
     | 
  |  138 |    0 |            if(lui.getUnitsContentOwner()!=null){ | 
  |  139 |    0 |                for(String unitContentOrgId: lui.getUnitsContentOwner() ){ | 
  |  140 |    0 |                    LuiUnitsContentOwnerEntity luiUnitContentOwner = new LuiUnitsContentOwnerEntity();  | 
  |  141 |    0 |                    luiUnitContentOwner.setLui(this);  | 
  |  142 |    0 |                    luiUnitContentOwner.setOrgId(unitContentOrgId);  | 
  |  143 |    0 |                    luiUnitsContentOwnerEntities.add(luiUnitContentOwner) ;  | 
  |  144 |    0 |                }  | 
  |  145 |     | 
           }  | 
  |  146 |     | 
     | 
  |  147 |     | 
     | 
  |  148 |    0 |            List<LuiUnitsDeploymentEntity> luiUnitsDeploymentEntities = new ArrayList<LuiUnitsDeploymentEntity>();  | 
  |  149 |    0 |            if(lui.getUnitsDeployment()!=null){ | 
  |  150 |    0 |                for(String unitDeploymentOrgId: lui.getUnitsDeployment() ){ | 
  |  151 |    0 |                    LuiUnitsDeploymentEntity luiDeployment = new LuiUnitsDeploymentEntity();  | 
  |  152 |    0 |                    luiDeployment.setLui(this);  | 
  |  153 |    0 |                    luiDeployment.setOrgId(unitDeploymentOrgId);  | 
  |  154 |    0 |                    luiUnitsDeploymentEntities.add(luiDeployment) ;  | 
  |  155 |    0 |                }  | 
  |  156 |     | 
           }  | 
  |  157 |     | 
     | 
  |  158 |     | 
     | 
  |  159 |     | 
             | 
  |  160 |    0 |            this.setAttributes(new ArrayList<LuiAttributeEntity>());  | 
  |  161 |    0 |            for (Attribute att : lui.getAttributes()) { | 
  |  162 |    0 |                this.getAttributes().add(new LuiAttributeEntity(att));  | 
  |  163 |     | 
           }  | 
  |  164 |     | 
     | 
  |  165 |    0 |            this.resultValuesGroups = resultValuesGroups;  | 
  |  166 |     | 
     | 
  |  167 |     | 
     | 
  |  168 |    0 |        }  | 
  |  169 |     | 
     | 
  |  170 |     | 
       public LuiInfo toDto() { | 
  |  171 |    0 |            LuiInfo info = new LuiInfo();  | 
  |  172 |    0 |            info.setId(getId());  | 
  |  173 |    0 |            info.setName(name);  | 
  |  174 |    0 |            info.setAtpId(atpId);  | 
  |  175 |    0 |            info.setCluId(cluId);  | 
  |  176 |    0 |            info.setMaximumEnrollment(maxSeats);  | 
  |  177 |    0 |            info.setMinimumEnrollment(minSeats);  | 
  |  178 |    0 |            info.setEffectiveDate(effectiveDate);  | 
  |  179 |    0 |            info.setExpirationDate(expirationDate);  | 
  |  180 |    0 |            info.setReferenceURL(referenceURL);  | 
  |  181 |    0 |            info.setTypeKey(luiType);  | 
  |  182 |    0 |            info.setStateKey(luiState);  | 
  |  183 |    0 |            info.setMeta(super.toDTO());  | 
  |  184 |    0 |            info.setDescr(new RichTextHelper().toRichTextInfo(plain, formatted));  | 
  |  185 |     | 
     | 
  |  186 |     | 
             | 
  |  187 |    0 |            if (luiCodes != null) { | 
  |  188 |    0 |                for (LuCodeEntity luCode : luiCodes) { | 
  |  189 |    0 |                    info.getLuiCodes().add(luCode.toDto());  | 
  |  190 |     | 
               }  | 
  |  191 |     | 
           }  | 
  |  192 |     | 
     | 
  |  193 |     | 
             | 
  |  194 |    0 |            if (identifiers != null) { | 
  |  195 |    0 |                for (LuiIdentifierEntity identifier : identifiers) { | 
  |  196 |    0 |                    if (LuiServiceConstants.LUI_IDENTIFIER_OFFICIAL_TYPE_KEY.equals(identifier.getType())) { | 
  |  197 |    0 |                        info.setOfficialIdentifier(identifier.toDto());  | 
  |  198 |     | 
                   } else { | 
  |  199 |    0 |                        info.getAlternateIdentifiers().add(identifier.toDto());  | 
  |  200 |     | 
                   }  | 
  |  201 |     | 
               }  | 
  |  202 |     | 
           }  | 
  |  203 |     | 
     | 
  |  204 |     | 
             | 
  |  205 |    0 |            if (getAttributes() != null) { | 
  |  206 |    0 |                for (LuiAttributeEntity att : getAttributes()) { | 
  |  207 |    0 |                    info.getAttributes().add(att.toDto());  | 
  |  208 |     | 
               }  | 
  |  209 |     | 
           }  | 
  |  210 |    0 |            List<String> unitsDeploymentOrgIds = new ArrayList<String>();  | 
  |  211 |    0 |            if( this.luiUnitsDeployment!= null)   { | 
  |  212 |    0 |                for(LuiUnitsDeploymentEntity unitsDep : this.luiUnitsDeployment){ | 
  |  213 |     | 
     | 
  |  214 |    0 |                  unitsDeploymentOrgIds.add(unitsDep.getOrgId());  | 
  |  215 |     | 
               }  | 
  |  216 |     | 
           }  | 
  |  217 |    0 |            info.setUnitsContentOwner(unitsDeploymentOrgIds);  | 
  |  218 |     | 
     | 
  |  219 |    0 |            List<String> unitsContentOrgIds = new ArrayList<String>();  | 
  |  220 |     | 
     | 
  |  221 |    0 |            if(this.luiContentOwner!=null){ | 
  |  222 |    0 |                for(LuiUnitsContentOwnerEntity unitsContent : this.luiContentOwner){ | 
  |  223 |     | 
     | 
  |  224 |    0 |                    unitsContentOrgIds.add(unitsContent.getOrgId());  | 
  |  225 |     | 
               }  | 
  |  226 |     | 
           }  | 
  |  227 |     | 
     | 
  |  228 |     | 
     | 
  |  229 |    0 |            info.setUnitsContentOwner(unitsContentOrgIds);  | 
  |  230 |    0 |            return info;  | 
  |  231 |     | 
       }  | 
  |  232 |     | 
     | 
  |  233 |     | 
       public Integer getMaxSeats() { | 
  |  234 |    0 |            return maxSeats;  | 
  |  235 |     | 
       }  | 
  |  236 |     | 
     | 
  |  237 |     | 
       public void setMaxSeats(Integer maxSeats) { | 
  |  238 |    0 |            this.maxSeats = maxSeats;  | 
  |  239 |    0 |        }  | 
  |  240 |     | 
     | 
  |  241 |     | 
       public Integer getMinSeats() { | 
  |  242 |    0 |            return minSeats;  | 
  |  243 |     | 
       }  | 
  |  244 |     | 
     | 
  |  245 |     | 
       public void setMinSeats(Integer minSeats) { | 
  |  246 |    0 |            this.minSeats = minSeats;  | 
  |  247 |    0 |        }  | 
  |  248 |     | 
     | 
  |  249 |     | 
       public Date getEffectiveDate() { | 
  |  250 |    0 |            return effectiveDate;  | 
  |  251 |     | 
       }  | 
  |  252 |     | 
     | 
  |  253 |     | 
       public void setEffectiveDate(Date effectiveDate) { | 
  |  254 |    0 |            this.effectiveDate = effectiveDate;  | 
  |  255 |    0 |        }  | 
  |  256 |     | 
     | 
  |  257 |     | 
       public Date getExpirationDate() { | 
  |  258 |    0 |            return expirationDate;  | 
  |  259 |     | 
       }  | 
  |  260 |     | 
     | 
  |  261 |     | 
       public void setExpirationDate(Date expirationDate) { | 
  |  262 |    0 |            this.expirationDate = expirationDate;  | 
  |  263 |    0 |        }  | 
  |  264 |     | 
     | 
  |  265 |     | 
       public String getCluId() { | 
  |  266 |    0 |            return cluId;  | 
  |  267 |     | 
       }  | 
  |  268 |     | 
     | 
  |  269 |     | 
       public void setCluId(String cluId) { | 
  |  270 |    0 |            this.cluId = cluId;  | 
  |  271 |    0 |        }  | 
  |  272 |     | 
     | 
  |  273 |     | 
       public String getName() { | 
  |  274 |    0 |            return name;  | 
  |  275 |     | 
       }  | 
  |  276 |     | 
     | 
  |  277 |     | 
       public void setName(String name) { | 
  |  278 |    0 |            this.name = name;  | 
  |  279 |    0 |        }  | 
  |  280 |     | 
     | 
  |  281 |     | 
       public String getAtpId() { | 
  |  282 |    0 |            return atpId;  | 
  |  283 |     | 
       }  | 
  |  284 |     | 
     | 
  |  285 |     | 
       public void setAtpId(String atpId) { | 
  |  286 |    0 |            this.atpId = atpId;  | 
  |  287 |    0 |        }  | 
  |  288 |     | 
     | 
  |  289 |     | 
       public String getDescrFormatted() { | 
  |  290 |    0 |            return formatted;  | 
  |  291 |     | 
       }  | 
  |  292 |     | 
     | 
  |  293 |     | 
       public void setDescrFormatted(String formatted) { | 
  |  294 |    0 |            this.formatted = formatted;  | 
  |  295 |    0 |        }  | 
  |  296 |     | 
     | 
  |  297 |     | 
       public String getDescrPlain() { | 
  |  298 |    0 |            return plain;  | 
  |  299 |     | 
       }  | 
  |  300 |     | 
     | 
  |  301 |     | 
       public void setDescrPlain(String plain) { | 
  |  302 |    0 |            this.plain = plain;  | 
  |  303 |    0 |        }  | 
  |  304 |     | 
     | 
  |  305 |     | 
       public String getLuiType() { | 
  |  306 |    0 |            return luiType;  | 
  |  307 |     | 
       }  | 
  |  308 |     | 
     | 
  |  309 |     | 
       public void setLuiType(String luiType) { | 
  |  310 |    0 |            this.luiType = luiType;  | 
  |  311 |    0 |        }  | 
  |  312 |     | 
     | 
  |  313 |     | 
       public String getLuiState() { | 
  |  314 |    0 |            return luiState;  | 
  |  315 |     | 
       }  | 
  |  316 |     | 
     | 
  |  317 |     | 
       public void setLuiState(String luiState) { | 
  |  318 |    0 |            this.luiState = luiState;  | 
  |  319 |    0 |        }  | 
  |  320 |     | 
     | 
  |  321 |     | 
       public String getReferenceURL() { | 
  |  322 |    0 |            return referenceURL;  | 
  |  323 |     | 
       }  | 
  |  324 |     | 
     | 
  |  325 |     | 
       public void setReferenceURL(String referenceURL) { | 
  |  326 |    0 |            this.referenceURL = referenceURL;  | 
  |  327 |    0 |        }  | 
  |  328 |     | 
     | 
  |  329 |     | 
         | 
  |  330 |     | 
         | 
  |  331 |     | 
         | 
  |  332 |     | 
         | 
  |  333 |     | 
         | 
  |  334 |     | 
         | 
  |  335 |     | 
         | 
  |  336 |     | 
         | 
  |  337 |     | 
         | 
  |  338 |     | 
         | 
  |  339 |     | 
         | 
  |  340 |     | 
         | 
  |  341 |     | 
         | 
  |  342 |     | 
         | 
  |  343 |     | 
         | 
  |  344 |     | 
         | 
  |  345 |     | 
         | 
  |  346 |     | 
         | 
  |  347 |     | 
         | 
  |  348 |     | 
         | 
  |  349 |     | 
         | 
  |  350 |     | 
         | 
  |  351 |     | 
         | 
  |  352 |     | 
       public void setAttributes(List<LuiAttributeEntity> attributes) { | 
  |  353 |    0 |            this.attributes = attributes;  | 
  |  354 |    0 |        }  | 
  |  355 |     | 
     | 
  |  356 |     | 
       public List<LuiIdentifierEntity> getIdentifiers() { | 
  |  357 |    0 |            return identifiers;  | 
  |  358 |     | 
       }  | 
  |  359 |     | 
     | 
  |  360 |     | 
       public void setIdentifiers(List<LuiIdentifierEntity> identifiers) { | 
  |  361 |    0 |            this.identifiers = identifiers;  | 
  |  362 |    0 |        }  | 
  |  363 |     | 
     | 
  |  364 |     | 
       public List<LuiAttributeEntity> getAttributes() { | 
  |  365 |    0 |            return attributes;  | 
  |  366 |     | 
       }  | 
  |  367 |     | 
     | 
  |  368 |     | 
       public String getFormatted() { | 
  |  369 |    0 |            return formatted;  | 
  |  370 |     | 
       }  | 
  |  371 |     | 
     | 
  |  372 |     | 
       public void setFormatted(String formatted) { | 
  |  373 |    0 |            this.formatted = formatted;  | 
  |  374 |    0 |        }  | 
  |  375 |     | 
     | 
  |  376 |     | 
       public String getPlain() { | 
  |  377 |    0 |            return plain;  | 
  |  378 |     | 
       }  | 
  |  379 |     | 
     | 
  |  380 |     | 
       public void setPlain(String plain) { | 
  |  381 |    0 |            this.plain = plain;  | 
  |  382 |    0 |        }  | 
  |  383 |     | 
     | 
  |  384 |     | 
         | 
  |  385 |     | 
     | 
  |  386 |     | 
     | 
  |  387 |     | 
     | 
  |  388 |     | 
       public List<LuCodeEntity> getLuiCodes() { | 
  |  389 |    0 |            return luiCodes;  | 
  |  390 |     | 
       }  | 
  |  391 |     | 
     | 
  |  392 |     | 
       public void setLuiCodes(List<LuCodeEntity> luiCodes) { | 
  |  393 |    0 |            this.luiCodes = luiCodes;  | 
  |  394 |    0 |        }  | 
  |  395 |     | 
   }  |