001 package org.kuali.student.lum.common.client.widgets; 002 003 import java.util.List; 004 005 import org.kuali.student.common.ui.client.widgets.DataHelper; 006 import org.kuali.student.core.assembly.data.Data; 007 import org.kuali.student.core.assembly.data.LookupMetadata; 008 import org.kuali.student.core.assembly.data.LookupParamMetadata; 009 import org.kuali.student.core.search.dto.SearchParam; 010 import org.kuali.student.lum.lu.dto.MembershipQueryInfo; 011 012 public class CluSetRangeDataHelper implements DataHelper { 013 014 private LookupMetadata lookupMetadata; 015 016 @Override 017 public String parse(Data data) { 018 MembershipQueryInfo membershipQueryInfo; 019 StringBuilder labelText = new StringBuilder(); 020 int paramCounter = 0; 021 membershipQueryInfo = CluSetRangeModelUtil.INSTANCE.toMembershipQueryInfo(data); 022 if (membershipQueryInfo != null) { 023 if (membershipQueryInfo.getQueryParamValueList() != null && 024 !membershipQueryInfo.getQueryParamValueList().isEmpty()) { 025 for (SearchParam searchParam : membershipQueryInfo.getQueryParamValueList()) { 026 if (paramCounter > 0) { 027 labelText.append(" "); 028 } 029 labelText.append(getParameterDisplayName(searchParam.getKey())).append(": "); 030 labelText.append("<b>").append(searchParam.getValue()).append("</b>"); 031 paramCounter++; 032 } 033 } else { 034 labelText.append("All Courses"); 035 } 036 } 037 return labelText.toString(); 038 } 039 040 @Override 041 public String getKey(Data data) { 042 return parse(data); 043 } 044 045 private String getParameterDisplayName(String parameterKey) { 046 String parameterDisplayName = null; 047 if (lookupMetadata == null) { 048 parameterDisplayName = parameterKey; 049 } else { 050 List<LookupParamMetadata> searchParams = lookupMetadata.getParams(); 051 if (searchParams != null) { 052 for (LookupParamMetadata searchParam : searchParams) { 053 if (nullSafeEquals(searchParam.getKey(), parameterKey)) { 054 parameterDisplayName = searchParam.getName(); 055 } 056 } 057 } 058 if (parameterDisplayName == null) { 059 parameterDisplayName = parameterKey; 060 } 061 } 062 return parameterDisplayName; 063 } 064 065 private boolean nullSafeEquals(Object str1, Object str2) { 066 return (str1 == null && str2 == null || 067 str1 != null && str2 != null && str1.equals(str2)); 068 } 069 070 public LookupMetadata getLookupMetadata() { 071 return lookupMetadata; 072 } 073 074 public void setLookupMetadata(LookupMetadata lookupMetadata) { 075 this.lookupMetadata = lookupMetadata; 076 } 077 078 }