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 labelText.append("<b>").append(searchParam.getValues().get(0)).append("</b>"); 31 paramCounter++; 32 } 33 } else { 34 labelText.append("All Courses"); 35 } 36 } 37 return labelText.toString(); 38 } 39 40 @Override 41 public String getKey(Data data) { 42 return parse(data); 43 } 44 45 private String getParameterDisplayName(String parameterKey) { 46 String parameterDisplayName = null; 47 if (lookupMetadata == null) { 48 parameterDisplayName = parameterKey; 49 } else { 50 List<LookupParamMetadata> searchParams = lookupMetadata.getParams(); 51 if (searchParams != null) { 52 for (LookupParamMetadata searchParam : searchParams) { 53 if (nullSafeEquals(searchParam.getKey(), parameterKey)) { 54 parameterDisplayName = searchParam.getName(); 55 } 56 } 57 } 58 if (parameterDisplayName == null) { 59 parameterDisplayName = parameterKey; 60 } 61 } 62 return parameterDisplayName; 63 } 64 65 private boolean nullSafeEquals(Object str1, Object str2) { 66 return (str1 == null && str2 == null || 67 str1 != null && str2 != null && str1.equals(str2)); 68 } 69 70 public LookupMetadata getLookupMetadata() { 71 return lookupMetadata; 72 } 73 74 public void setLookupMetadata(LookupMetadata lookupMetadata) { 75 this.lookupMetadata = lookupMetadata; 76 } 77 78 }