@@ -687,6 +687,64 @@ public String copyAttachment(
687687 }
688688 }
689689
690+ public Map <String , Object > moveAttachment (
691+ String appUrl ,
692+ String entityName ,
693+ String facetName ,
694+ String targetEntityID ,
695+ String sourceFolderId ,
696+ List <String > objectIds ,
697+ String sourceFacet )
698+ throws IOException {
699+ String objectIdsString = String .join ("," , objectIds );
700+ String url =
701+ "https://"
702+ + appUrl
703+ + "/api/admin/"
704+ + entityName
705+ + "(ID="
706+ + targetEntityID
707+ + ",IsActiveEntity=false)/"
708+ + facetName
709+ + "/"
710+ + "AdminService.moveAttachments" ;
711+
712+ MediaType mediaType = MediaType .parse ("application/json" );
713+
714+ StringBuilder jsonPayload = new StringBuilder ();
715+ jsonPayload .append ("{" );
716+ jsonPayload .append ("\" sourceFolderId\" : \" " ).append (sourceFolderId ).append ("\" ," );
717+ jsonPayload .append ("\" up__ID\" : \" " ).append (targetEntityID ).append ("\" ," );
718+ jsonPayload .append ("\" objectIds\" : \" " ).append (objectIdsString ).append ("\" " );
719+
720+ if (sourceFacet != null && !sourceFacet .isEmpty ()) {
721+ jsonPayload .append (",\" sourceFacet\" : \" " ).append (sourceFacet ).append ("\" " );
722+ }
723+
724+ jsonPayload .append ("}" );
725+
726+ RequestBody body = RequestBody .create (jsonPayload .toString (), mediaType );
727+
728+ Request request =
729+ new Request .Builder ().url (url ).post (body ).addHeader ("Authorization" , token ).build ();
730+
731+ try (Response response = executeWithRetry (request )) {
732+ String responseBody = response .body ().string ();
733+
734+ if (!response .isSuccessful ()) {
735+ throw new IOException (
736+ "Could not move attachments: " + response .code () + " - " + responseBody );
737+ }
738+
739+ @ SuppressWarnings ("unchecked" )
740+ Map <String , Object > result = objectMapper .readValue (responseBody , Map .class );
741+ return result ;
742+ } catch (IOException e ) {
743+ System .out .println ("Error while moving attachments: " + e .getMessage ());
744+ throw new IOException (e );
745+ }
746+ }
747+
690748 public String createLink (
691749 String appUrl ,
692750 String entityName ,
0 commit comments