4343import java .io .InputStream ;
4444import java .util .ArrayList ;
4545
46- /**
47- * Moved from ListQueryUpdateService.java
48- * by iansigmon on 2/16/16.
49- */
5046public class AttachmentDataIterator extends WrapperDataIterator
5147{
5248 final VirtualFile attachmentDir ;
@@ -92,19 +88,21 @@ public boolean next() throws BatchValidationException
9288 for (_AttachmentUploadHelper p : attachmentColumns )
9389 {
9490 Object attachmentValue = get (p .index );
91+ if (null == attachmentValue )
92+ continue ;
93+
9594 String filename ;
9695 AttachmentFile attachmentFile ;
9796
98- if (null == attachmentValue )
99- continue ;
100- else if (attachmentValue instanceof String str )
97+ if (attachmentValue instanceof String str )
10198 {
10299 if (null == attachmentDir )
103100 {
104- errors .addRowError (new ValidationException ( "Row " + get ( 0 ) + ": " + "Can't upload '" + str + "' to field " + p .domainProperty . getName () + " with type " + p . domainProperty . getType (). getLabel () + "." ));
101+ errors .addRowError (propertyValidationException ( p .domainProperty , attachmentValue ));
105102 return false ;
106103 }
107- filename = (String ) attachmentValue ;
104+
105+ filename = str ;
108106 InputStream aIS = attachmentDir .getDir (p .domainProperty .getName ()).getInputStream (p .uniquifier .uniquify (filename ));
109107 if (aIS == null )
110108 {
@@ -113,25 +111,25 @@ else if (attachmentValue instanceof String str)
113111 }
114112 attachmentFile = new InputStreamAttachmentFile (aIS , filename );
115113 }
116- else if (attachmentValue instanceof AttachmentFile )
114+ else if (attachmentValue instanceof AttachmentFile file )
117115 {
118- attachmentFile = ( AttachmentFile ) attachmentValue ;
116+ attachmentFile = file ;
119117 filename = attachmentFile .getFilename ();
120118 }
121- else if (attachmentValue instanceof File )
119+ else if (attachmentValue instanceof File file )
122120 {
123- attachmentFile = new FileAttachmentFile (( File ) attachmentValue );
121+ attachmentFile = new FileAttachmentFile (file );
124122 filename = attachmentFile .getFilename ();
125123 }
126124 else
127125 {
128- errors .addRowError (new ValidationException ( "Row " + get ( 0 ) + ": " + "Unable to create attachment file." ));
126+ errors .addRowError (propertyValidationException ( p . domainProperty , attachmentValue ));
129127 return false ;
130128 }
131129
132130 if (entityIdIndex == 0 )
133131 {
134- errors .addRowError (new ValidationException ( "Row " + get ( 0 ) + ": " + "Unable to create attachment file." ));
132+ errors .addRowError (rowValidationException ( "Unable to create attachment file." ));
135133 return false ;
136134 }
137135
@@ -172,6 +170,16 @@ else if (attachmentValue instanceof File)
172170 }
173171 }
174172
173+ private ValidationException propertyValidationException (DomainProperty property , Object value )
174+ {
175+ return rowValidationException (String .format ("Can't upload '%s' to field %s with type %s." , value , property .getName (), property .getType ().getLabel ()));
176+ }
177+
178+ private ValidationException rowValidationException (String message )
179+ {
180+ return new ValidationException ("Row " + get (0 ) + ": " + message );
181+ }
182+
175183 public static DataIteratorBuilder getAttachmentDataIteratorBuilder (TableInfo ti , @ NotNull final DataIteratorBuilder builder ,
176184 final User user ,
177185 @ Nullable final VirtualFile attachmentDir ,
0 commit comments