Dhairya-007 opened a new pull request, #29961:
URL: https://github.com/apache/camel/pull/29961

   ## Problem
   
   Two separate things in `GridFsConstants`, both about the same five lines.
   
   **Three headers the producer sets are labelled consumer-only.**
   
   ```java
   @Metadata(label = "consumer", description = "The content type of the file.", 
javaType = "String")
   public static final String FILE_CONTENT_TYPE = Exchange.FILE_CONTENT_TYPE;
   @Metadata(label = "consumer", description = "The size of the file.", 
javaType = "long")
   public static final String FILE_LENGTH = Exchange.FILE_LENGTH;
   @Metadata(label = "consumer", description = "The upload date of the file.", 
javaType = "Date")
   public static final String FILE_LAST_MODIFIED = Exchange.FILE_LAST_MODIFIED;
   ```
   
   The `findOne` producer operation sets all three:
   
   ```java
   Object contentType = metadata.get(GRIDFS_FILE_KEY_CONTENT_TYPE);
   if (contentType != null) {
       exchange.getIn().setHeader(GridFsConstants.FILE_CONTENT_TYPE, 
contentType);
   }
   exchange.getIn().setHeader(GridFsConstants.FILE_LENGTH, file.getLength());
   exchange.getIn().setHeader(GridFsConstants.FILE_LAST_MODIFIED, 
file.getUploadDate());
   ```
   
   So the catalog puts them in the consumer group, and a route doing 
`to("mongodb-gridfs:...?operation=findOne")` has nothing to tell it that the 
size, upload date and content type of the file it just fetched come back as 
headers.
   
   **`Content-Type` and `CamelFileContentType` have the same description while 
meaning opposite directions.**
   
   ```java
   @Metadata(label = "consumer", description = "The content type of the file.", 
javaType = "String")
   public static final String FILE_CONTENT_TYPE = Exchange.FILE_CONTENT_TYPE;
   ...
   @Metadata(label = "producer", description = "The content type of the file.", 
javaType = "String")
   public static final String CONTENT_TYPE = Exchange.CONTENT_TYPE;
   ```
   
   `Content-Type` is read by `create` to store the content type in the file's 
metadata; `CamelFileContentType` is what `findOne` and the consumer give back. 
With one description between them the header table offers two content-type 
headers and no way to pick.
   
   ## Fix
   
   Describe all four by what they actually do, and drop the consumer-only label 
from the three that `findOne` sets.
   
   `FILE_NAME`, three lines below, already does exactly this - no label, and a 
description naming both directions - so this follows the convention the class 
had already set:
   
   ```java
   @Metadata(description = "(producer) The name of the file: the name that 
create gives the file, and the file that"
                           + " findOne, remove, listAll and count look for. 
(consumer) The name of the file that was found.",
             javaType = "String")
   public static final String FILE_NAME = Exchange.FILE_NAME;
   ```
   
   No constant, header name or behaviour changes. The regenerated 
`mongodb-gridfs.json` files are included.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to