1 21 package com.jaspersoft.jasperserver.war.validation; 22 23 import java.util.List ; 24 25 import org.springframework.validation.Errors; 26 import org.springframework.validation.Validator; 27 28 import com.jaspersoft.jasperserver.api.metadata.olap.domain.MondrianConnection; 30 import com.jaspersoft.jasperserver.api.metadata.olap.domain.OlapUnit; 31 import com.jaspersoft.jasperserver.api.metadata.olap.service.impl.OlapConnectionServiceImpl; 32 import com.jaspersoft.jasperserver.war.common.JasperServerConst; 33 import com.jaspersoft.jasperserver.war.common.JasperServerUtil; 34 import com.jaspersoft.jasperserver.war.dto.FileResourceWrapper; 35 import com.jaspersoft.jasperserver.war.dto.InputControlWrapper; 36 import com.jaspersoft.jasperserver.war.dto.OlapUnitWrapper; 37 39 43 public class OlapDetailsValidator implements Validator { 44 45 public boolean supports(Class clazz) { 46 return OlapUnitWrapper.class.isAssignableFrom(clazz); 47 } 48 49 public void validate(Object o, Errors errors) { 50 OlapUnitWrapper olapDetails = (OlapUnitWrapper) o; 51 validateNameLabelDesc(olapDetails, errors); validateSchemaUpload(olapDetails, errors); } 54 55 public void validateNameLabelDesc(OlapUnitWrapper ouWrapper, Errors errors) { 56 OlapUnit ou = ouWrapper.getOlapUnit(); 57 if (ou.getLabel() == null || ou.getLabel().trim().length() == 0) { 58 errors.rejectValue("olapUnit.label", null, 59 "OLAP label must not be empty"); 60 } else { 61 if (ouWrapper.getOlapUnit().getLabel().length() > 100) { 62 errors 63 .rejectValue("olapUnit.label", null, 64 "OLAP label should not be longer than 100 characters"); 65 } else if (!JasperServerUtil.regExValidateLabel(ou.getLabel())) 66 errors.rejectValue("olapUnit.label", null, 67 "OLAP label contains invalid characters"); 68 } 69 70 if (ou.getName() == null || ou.getName().trim().length() == 0) { 71 errors.rejectValue("olapUnit.name", null, 72 "OLAP name must not be empty"); 73 } else { 74 if (ou.getName().length() > 100) { 75 errors.rejectValue("olapUnit.name", null, 76 "OLAP name should not be longer than 100 characters"); 77 } else if (!JasperServerUtil.regExValidateName(ou.getName())) 78 errors.rejectValue("olapUnit.name", null, 79 "OLAP name contains invalid characters"); 80 else { 81 if (ouWrapper.isNewMode() 82 && ouWrapper.getExistingResources() != null) { 83 List res = ouWrapper.getExistingResources(); 84 for (int i = 0; i < res.size(); i++) { 85 String preExtName = (String ) res.get(i); 86 if (preExtName.equalsIgnoreCase(ou.getName().trim())) { 87 errors 88 .rejectValue("olapUnit.name", null, 89 "A Resource with the chosen name already exists"); 90 break; 91 } 92 } 93 } 94 } 95 } 96 97 if (ou.getDescription() != null && ou.getDescription().length() > 300) 98 errors 99 .rejectValue("olapUnit.description", null, 100 "OLAP description should not be longer than 300 characters"); 101 } 102 103 public void validateMdxQuery(OlapUnitWrapper ouWrapper, Errors errors) { 104 OlapUnit ou = ouWrapper.getOlapUnit(); 105 106 if (ou.getMdxQuery() == null || ou.getMdxQuery().trim().length() == 0) { 107 errors.rejectValue("olapUnit.mdxQuery", null, 108 "OLAP MDX Query must not be empty"); 109 } 110 else if (ou.getMdxQuery() != null && ou.getMdxQuery().length() > 4096) { 111 errors.rejectValue("olapUnit.mdxQuery", null, 112 "OLAP MDX Query should not be longer than 4096 characters"); 113 } 114 115 } 129 130 public void validateURIString(OlapUnitWrapper olapUnit, Errors errors) { 131 if (olapUnit.getSource() == null) { 132 errors.rejectValue("source", null, "Select a valid schema source"); 133 } else { 134 if (olapUnit.getSource().equals( 135 JasperServerConst.FIELD_CHOICE_CONT_REPO)) { 136 if (olapUnit.getSchemaUri() == null 137 || olapUnit.getSchemaUri().length() == 0) { 138 errors.rejectValue("schemaUri", null, 139 "Select a resuable schema "); 140 } 141 } 142 } 143 144 } 145 146 public void validateSchemaUpload(OlapUnitWrapper wrapper, Errors errors) { 147 } 164 165 public void validateResources(OlapUnitWrapper wrapper, Errors errors) { 166 boolean allResLocated = true; 167 boolean allControlsLocated = true; 168 List sugRes = wrapper.getSuggestedResources(); 169 if (sugRes != null && !sugRes.isEmpty()) { 170 for (int i = 0; i < sugRes.size(); i++) { 171 FileResourceWrapper resWrap = (FileResourceWrapper) sugRes 172 .get(i); 173 if (!resWrap.isLocated()) { 174 allResLocated = false; 175 break; 176 } 177 } 178 } 179 List sugContr = wrapper.getSuggestedControls(); 180 if (sugContr != null && !sugContr.isEmpty()) { 181 for (int i = 0; i < sugContr.size(); i++) { 182 InputControlWrapper icWrap = (InputControlWrapper) sugContr 183 .get(i); 184 if (!icWrap.isLocated()) { 185 allControlsLocated = false; 186 break; 187 } 188 } 189 } 190 if (!allControlsLocated && !allResLocated) 191 errors.rejectValue("validationMessage", null, 192 "All suggested Resources and Controls must be located"); 193 else if (!allControlsLocated) 194 errors.rejectValue("validationMessage", null, 195 "All suggested Controls must be located"); 196 else if (!allResLocated) 197 errors.rejectValue("validationMessage", null, 198 "All suggested Resources must be located"); 199 200 } 201 202 } | Popular Tags |