2323import java .util .HashMap ;
2424import java .util .Map ;
2525import java .util .UUID ;
26+ import java .util .concurrent .atomic .LongAdder ;
2627import java .util .stream .Collectors ;
2728import okhttp3 .FormBody ;
2829import okhttp3 .OkHttpClient ;
2930import okhttp3 .Request ;
3031import okhttp3 .Response ;
3132import org .datatransferproject .api .launcher .Monitor ;
3233import org .datatransferproject .spi .transfer .idempotentexecutor .IdempotentImportExecutor ;
34+ import org .datatransferproject .spi .transfer .idempotentexecutor .ItemImportResult ;
3335import org .datatransferproject .spi .transfer .provider .ImportResult ;
3436import org .datatransferproject .spi .transfer .provider .Importer ;
3537import org .datatransferproject .types .common .models .social .SocialActivityAttachment ;
@@ -77,25 +79,32 @@ public ImportResult importItem(
7779 monitor .debug (
7880 () -> String .format ("Number of Posts: %d" , resource .getCounts ().get ("activitiesCount" )));
7981
82+ final LongAdder totalImportedFilesSizes = new LongAdder ();
8083 // Import social activity
8184 for (SocialActivityModel activity : resource .getActivities ()) {
8285 if (activity .getType () == SocialActivityType .NOTE
8386 || activity .getType () == SocialActivityType .POST ) {
84- executor .executeAndSwallowIOExceptions (
85- Integer .toString (activity .hashCode ()),
86- activity .getTitle (),
87- () -> insertActivity (activity , authData ));
87+ executor .importAndSwallowIOExceptions (
88+ activity ,
89+ currentActivity -> {
90+ ItemImportResult <String > insertActivityResult = insertActivity (activity , authData );
91+ if (insertActivityResult != null && insertActivityResult .hasBytes ()) {
92+ totalImportedFilesSizes .add (insertActivityResult .getBytes ());
93+ }
94+ return insertActivityResult ;
95+ });
8896 }
8997 }
9098
91- return new ImportResult ( ImportResult . ResultType . OK );
99+ return ImportResult . OK . copyWithBytes ( totalImportedFilesSizes . longValue () );
92100 }
93101
94- private String insertActivity (SocialActivityModel activity , TokensAndUrlAuthData authData )
102+ private ItemImportResult < String > insertActivity (SocialActivityModel activity , TokensAndUrlAuthData authData )
95103 throws IOException {
96104 Map <String , String > imageMap = new HashMap <>();
97105 Map <String , String > linkMap = new HashMap <>();
98106
107+ Long size = null ;
99108 String content = activity .getContent () == null ? "" : activity .getContent ();
100109 String title = activity .getTitle () == null ? "" : activity .getTitle ();
101110 String location =
@@ -155,6 +164,7 @@ private String insertActivity(SocialActivityModel activity, TokensAndUrlAuthData
155164
156165 FormBody formBody = builder .build ();
157166 requestBuilder .post (formBody );
167+ size = formBody .contentLength ();
158168
159169 try (Response response = client .newCall (requestBuilder .build ()).execute ()) {
160170 int code = response .code ();
@@ -165,7 +175,7 @@ private String insertActivity(SocialActivityModel activity, TokensAndUrlAuthData
165175 "Error occurred in request for adding entry, message: %s" , response .message ()));
166176 }
167177
168- return response .message ();
178+ return ItemImportResult . success ( response .message (), size );
169179 }
170180 }
171181}
0 commit comments