public static boolean validateValueType( TextPattern textPattern, ValueType valueType ) { if ( ValueType.TEXT.equals( valueType ) ) { return true; } else if ( ValueType.NUMBER.equals( valueType ) ) { boolean isAllNumbers = true; for ( TextPatternSegment segment : textPattern.getSegments() ) { isAllNumbers = isAllNumbers && isNumericOnly( segment ); } return isAllNumbers; } else { return false; } }
@Override public boolean equals( Object o ) { if ( this == o ) return true; if ( o == null || getClass() != o.getClass() ) return false; Attribute attribute1 = (Attribute) o; if ( attribute != null ? !attribute.equals( attribute1.attribute ) : attribute1.attribute != null ) { return false; } if ( displayName != null ? !displayName.equals( attribute1.displayName ) : attribute1.displayName != null ) { return false; } if ( valueType != null ? !valueType.equals( attribute1.valueType ) : attribute1.valueType != null ) { return false; } if ( code != null ? !code.equals( attribute1.code ) : attribute1.code != null ) { return false; } if ( value != null ? !value.equals( attribute1.value ) : attribute1.value != null ) { return false; } return true; }
private List<TrackedEntityInstance> getTrackedEntityInstanceByPhoneNumber( IncomingSms sms, SMSCommand command, Set<OrganisationUnit> ous ) { List<TrackedEntityAttribute> attributes = trackedEntityAttributeService.getAllTrackedEntityAttributes().stream() .filter( attr -> attr.getValueType().equals( ValueType.PHONE_NUMBER ) ) .collect( Collectors.toList() ); List<TrackedEntityInstance> teis = new ArrayList<>(); attributes.parallelStream() .map( attr -> getParams( attr, sms, command.getProgram(), ous ) ) .forEach( param -> teis.addAll( trackedEntityInstanceService.getTrackedEntityInstances( param, false ) ) ); return teis; }
public String getTrackedEntityInstanceRecipient( TrackedEntityInstance tei, ValueType type ) { Set<TrackedEntityAttributeValue> attributeValues = tei.getTrackedEntityAttributeValues(); for ( TrackedEntityAttributeValue value : attributeValues ) { if ( value != null && value.getAttribute().getValueType().equals( type ) && value.getPlainValue() != null && !value.getPlainValue().trim().isEmpty() ) { return value.getPlainValue(); } } throw new IllegalQueryException( "Tracked entity does not have any attribute of value type: " + type.toString() ); }
@Override public <T extends IdentifiableObject> List<ErrorReport> validate( T object, ObjectBundle bundle ) { List<ErrorReport> errorReports = new ArrayList<>(); // Validate that the RenderType (if any) conforms to the constraints of ValueType or OptionSet. if ( object != null && object.getClass().isAssignableFrom( TrackedEntityAttribute.class ) ) { TrackedEntityAttribute attr = (TrackedEntityAttribute) object; if ( attr.isGenerated() && !attr.getValueType().equals( ValueType.TEXT ) ) { errorReports.add( new ErrorReport( TrackedEntityAttribute.class, ErrorCode.E4010, "generated", attr.getValueType() ) ); } errorReports.addAll( textPatternValid( attr ) ); if ( attr.getFieldMask() != null ) { try { TextPatternParser.parse( "\"" + attr.getFieldMask() + "\"" ); } catch ( TextPatternParser.TextPatternParsingException e ) { errorReports.add( new ErrorReport( TrackedEntityAttribute.class, ErrorCode.E4019, attr.getFieldMask(), "Not a valid TextPattern 'TEXT' segment." )); } } } return errorReports; }