@@ -726,7 +726,7 @@ private DocumentPage convertToDocumentPage(JerseyResultIterator iterator, boolea
726726 JerseyResult result = iterator .next ();
727727 DocumentRecord record ;
728728 if ( hasMetadata ) {
729- if ( iterator .hasNext () ) {
729+ if ( ! iterator .hasNext () ) {
730730 throw new MarkLogicInternalException (
731731 "Metadata and content parts should always come in pairs!" );
732732 }
@@ -750,6 +750,8 @@ private JerseyResultIterator getBulkDocumentsImpl(RequestLogger reqlog,
750750
751751 String path = "documents" ;
752752 RequestParameters params = new RequestParameters ();
753+ boolean withContent = true ;
754+ addCategoryParams (categories , params , withContent );
753755 if (format != null ) params .add ("format" , format .toString ().toLowerCase ());
754756 for (String uri : uris ) {
755757 params .add ("uri" , uri );
@@ -764,6 +766,8 @@ private JerseyResultIterator getBulkDocumentsImpl(RequestLogger reqlog,
764766 Set <Metadata > categories , Format format , RequestParameters extraParams )
765767 throws ResourceNotFoundException , ForbiddenUserException , FailedRequestException {
766768 MultivaluedMap <String , String > params = new MultivaluedMapImpl ();
769+ boolean withContent = true ;
770+ addCategoryParams (categories , params , withContent );
767771 if (searchHandle != null && view != null ) params .add ("view" , view .toString ().toLowerCase ());
768772 if (start > 1 ) params .add ("start" , Long .toString (start ));
769773 if (pageLength > 0 ) params .add ("pageLength" , Long .toString (pageLength ));
@@ -1605,6 +1609,39 @@ private void completeTransaction(String transactionId, String result)
16051609 response .close ();
16061610 }
16071611
1612+ private void addCategoryParams (Set <Metadata > categories , MultivaluedMap <String , String > params ,
1613+ boolean withContent )
1614+ {
1615+ if (withContent && categories == null || categories .size () == 0 ) {
1616+ params .add ("category" , "content" );
1617+ } else {
1618+ if (withContent ) params .add ("category" , "content" );
1619+ if (categories .contains (Metadata .ALL )) {
1620+ params .add ("category" , "metadata" );
1621+ } else {
1622+ for (Metadata category : categories ) {
1623+ params .add ("category" , category .name ().toLowerCase ());
1624+ }
1625+ }
1626+ }
1627+ }
1628+ private void addCategoryParams (Set <Metadata > categories , RequestParameters params ,
1629+ boolean withContent )
1630+ {
1631+ if (withContent && categories == null || categories .size () == 0 ) {
1632+ params .add ("category" , "content" );
1633+ } else {
1634+ if (withContent ) params .add ("category" , "content" );
1635+ if (categories .contains (Metadata .ALL )) {
1636+ params .add ("category" , "metadata" );
1637+ } else {
1638+ for (Metadata category : categories ) {
1639+ params .add ("category" , category .name ().toLowerCase ());
1640+ }
1641+ }
1642+ }
1643+ }
1644+
16081645 private MultivaluedMap <String , String > makeDocumentParams (String uri ,
16091646 Set <Metadata > categories , String transactionId ,
16101647 RequestParameters extraParams ) {
0 commit comments