@@ -694,46 +694,7 @@ public Map<String, String> copyAttachment(
694694 entity != null ? EntityUtils .toString (entity , StandardCharsets .UTF_8 ) : "" ;
695695
696696 if (response .getStatusLine ().getStatusCode () == 201 ) {
697- // Process successful response
698- Map <String , String > resultMap = new HashMap <>();
699-
700- JSONObject jsonObject = new JSONObject (responseBody );
701-
702- // Enumerate succinctProperties fields if present
703- JSONObject props = jsonObject .optJSONObject ("succinctProperties" );
704-
705- String cmisName =
706- props != null ? props .optString ("cmis:name" ) : jsonObject .optString ("cmis:name" );
707- String cmisMimeType =
708- props != null
709- ? props .optString ("cmis:contentStreamMimeType" )
710- : jsonObject .optString ("cmis:contentStreamMimeType" );
711- String cmisDescription =
712- props != null
713- ? props .optString ("cmis:description" )
714- : jsonObject .optString ("cmis:description" );
715- String cmisObjectId =
716- props != null
717- ? props .optString ("cmis:objectId" )
718- : jsonObject .optString ("cmis:objectId" );
719-
720- // Add standard properties
721- resultMap .put ("cmis:name" , cmisName );
722- resultMap .put ("cmis:contentStreamMimeType" , cmisMimeType );
723- resultMap .put ("cmis:description" , cmisDescription );
724- resultMap .put ("cmis:objectId" , cmisObjectId );
725-
726- // Extract custom properties from SDM response
727- if (props != null && customPropertiesInSDM != null && !customPropertiesInSDM .isEmpty ()) {
728- for (String customProperty : customPropertiesInSDM ) {
729- if (props .has (customProperty )) {
730- Object value = props .get (customProperty );
731- resultMap .put (customProperty , value != null ? value .toString () : "" );
732- }
733- }
734- }
735-
736- return resultMap ;
697+ return processCopyAttachmentResponse (responseBody , customPropertiesInSDM );
737698 }
738699
739700 // On error, throw exception with error information
@@ -745,4 +706,40 @@ public Map<String, String> copyAttachment(
745706 throw new ServiceException (SDMConstants .FAILED_TO_COPY_ATTACHMENT , e );
746707 }
747708 }
709+
710+ private Map <String , String > processCopyAttachmentResponse (
711+ String responseBody , Set <String > customPropertiesInSDM ) {
712+ Map <String , String > resultMap = new HashMap <>();
713+ JSONObject jsonObject = new JSONObject (responseBody );
714+ JSONObject props = jsonObject .optJSONObject ("succinctProperties" );
715+
716+ // Extract standard CMIS properties
717+ resultMap .put ("cmis:name" , extractProperty (props , jsonObject , "cmis:name" ));
718+ resultMap .put (
719+ "cmis:contentStreamMimeType" ,
720+ extractProperty (props , jsonObject , "cmis:contentStreamMimeType" ));
721+ resultMap .put ("cmis:description" , extractProperty (props , jsonObject , "cmis:description" ));
722+ resultMap .put ("cmis:objectId" , extractProperty (props , jsonObject , "cmis:objectId" ));
723+
724+ // Extract custom properties from SDM response
725+ extractCustomProperties (props , customPropertiesInSDM , resultMap );
726+
727+ return resultMap ;
728+ }
729+
730+ private String extractProperty (JSONObject props , JSONObject jsonObject , String propertyName ) {
731+ return props != null ? props .optString (propertyName ) : jsonObject .optString (propertyName );
732+ }
733+
734+ private void extractCustomProperties (
735+ JSONObject props , Set <String > customPropertiesInSDM , Map <String , String > resultMap ) {
736+ if (props != null && customPropertiesInSDM != null && !customPropertiesInSDM .isEmpty ()) {
737+ for (String customProperty : customPropertiesInSDM ) {
738+ if (props .has (customProperty )) {
739+ Object value = props .get (customProperty );
740+ resultMap .put (customProperty , value != null ? value .toString () : "" );
741+ }
742+ }
743+ }
744+ }
748745}
0 commit comments