1 package org.kuali.student.lum.common.client.widgets; 2 3 import java.util.List; 4 5 import org.kuali.student.common.ui.client.widgets.DataHelper; 6 import org.kuali.student.r1.common.assembly.data.Data; 7 import org.kuali.student.r1.common.assembly.data.LookupMetadata; 8 import org.kuali.student.r1.common.assembly.data.LookupParamMetadata; 9 import org.kuali.student.r2.core.search.dto.SearchParamInfo; 10 import org.kuali.student.r2.lum.clu.dto.MembershipQueryInfo; 11 12 public class CluSetRangeDataHelper implements DataHelper { 13 14 private LookupMetadata lookupMetadata; 15 16 @Override 17 public String parse(Data data) { 18 MembershipQueryInfo membershipQueryInfo; 19 StringBuilder labelText = new StringBuilder(); 20 int paramCounter = 0; 21 membershipQueryInfo = CluSetRangeModelUtil.INSTANCE.toMembershipQueryInfo(data); 22 if (membershipQueryInfo != null) { 23 if (membershipQueryInfo.getQueryParamValues() != null && 24 !membershipQueryInfo.getQueryParamValues().isEmpty()) { 25 for (SearchParamInfo searchParam : membershipQueryInfo.getQueryParamValues()) { 26 if (paramCounter > 0) { 27 labelText.append(" "); 28 } 29 labelText.append(getParameterDisplayName(searchParam.getKey())).append(": "); 30 if (searchParam.getValues().size() == 1) { 31 labelText.append("<b>").append(searchParam.getValues().get(0)).append("</b>"); 32 } else { 33 String value =""; 34 for (String param : searchParam.getValues()) { 35 36 value = value + ", " + param; 37 } 38 labelText.append("<b>").append(value).append("</b>"); 39 } 40 paramCounter++; 41 } 42 } else { 43 labelText.append("All Courses"); 44 } 45 } 46 return labelText.toString(); 47 } 48 49 @Override 50 public String getKey(Data data) { 51 return parse(data); 52 } 53 54 private String getParameterDisplayName(String parameterKey) { 55 String parameterDisplayName = null; 56 if (lookupMetadata == null) { 57 parameterDisplayName = parameterKey; 58 } else { 59 List<LookupParamMetadata> searchParams = lookupMetadata.getParams(); 60 if (searchParams != null) { 61 for (LookupParamMetadata searchParam : searchParams) { 62 if (nullSafeEquals(searchParam.getKey(), parameterKey)) { 63 parameterDisplayName = searchParam.getName(); 64 } 65 } 66 } 67 if (parameterDisplayName == null) { 68 parameterDisplayName = parameterKey; 69 } 70 } 71 return parameterDisplayName; 72 } 73 74 private boolean nullSafeEquals(Object str1, Object str2) { 75 return (str1 == null && str2 == null || 76 str1 != null && str2 != null && str1.equals(str2)); 77 } 78 79 public LookupMetadata getLookupMetadata() { 80 return lookupMetadata; 81 } 82 83 public void setLookupMetadata(LookupMetadata lookupMetadata) { 84 this.lookupMetadata = lookupMetadata; 85 } 86 87 }