Skip to content

Commit 1cfa50d

Browse files
committed
Add a new field - objectPath and format the class.
1 parent 737e288 commit 1cfa50d

File tree

1 file changed

+39
-11
lines changed

1 file changed

+39
-11
lines changed

src/main/java/org/dataone/indexer/queue/IndexQueueMessageParser.java

Lines changed: 39 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,13 @@ public class IndexQueueMessageParser {
2121
private final static String HEADER_ID = "id";
2222
//The header name in the message to store the index type
2323
private final static String HEADER_INDEX_TYPE = "index_type";
24-
24+
//The header name in the message to store the path of the object
25+
private final static String HEADER_PATH = "path";
2526
private Identifier identifier = null;
2627
private String indexType = null;
2728
private int priority = 1;
28-
29+
private String objectPath;
30+
2931
private static Log logger = LogFactory.getLog(IndexQueueMessageParser.class);
3032

3133
/**
@@ -46,33 +48,49 @@ public void parse(AMQP.BasicProperties properties, byte[] body) throws InvalidRe
4648
}
4749
Object pidObj = headers.get(HEADER_ID);
4850
if (pidObj == null) {
49-
throw new InvalidRequest("0000", "The identifier cannot be null in the index queue message.");
51+
throw new InvalidRequest(
52+
"0000", "The identifier cannot be null in the index queue message.");
5053
}
5154
String pid = ((LongString)pidObj).toString();
52-
if (pid == null || pid.trim().equals("")) {
53-
throw new InvalidRequest("0000", "The identifier cannot be null or blank in the index queue message.");
55+
if (pid == null || pid.isBlank()) {
56+
throw new InvalidRequest(
57+
"0000", "The identifier cannot be null or blank in the index queue message.");
5458
}
5559
logger.debug("IndexQueueMessageParser.parse - the identifier in the message is " + pid);
5660
identifier = new Identifier();
5761
identifier.setValue(pid);
5862

5963
Object typeObj = headers.get(HEADER_INDEX_TYPE);
6064
if (typeObj == null) {
61-
throw new InvalidRequest("0000", "The index type cannot be null in the index queue message.");
65+
throw new InvalidRequest(
66+
"0000", "The index type cannot be null in the index queue message for " + pid);
6267
}
6368
indexType = ((LongString)typeObj).toString();
64-
if (indexType == null || indexType.trim().equals("")) {
65-
throw new InvalidRequest("0000", "The index type cannot be null or blank in the index queue message.");
69+
if (indexType == null || indexType.isBlank()) {
70+
throw new InvalidRequest(
71+
"0000",
72+
"The index type cannot be null or blank in the index queue message for " + pid);
73+
}
74+
logger.debug("The index type in the message is " + indexType + " for " + pid);
75+
Object pathObject = headers.get(HEADER_PATH);
76+
if (pathObject != null) {
77+
objectPath = ((LongString)pathObject).toString();
6678
}
67-
logger.debug("IndexQueueMessageParser.parse - the index type in the message is " + indexType);
79+
logger.debug(
80+
"The file path of the object which will be indexed in the message is " + objectPath +
81+
" for " + pid);
6882

6983
try {
7084
priority = properties.getPriority();
7185
} catch (NullPointerException e) {
72-
logger.info("IndexQueueMessageParser.parse - the priority is not set in the message and we will set it one.");
86+
logger.info(
87+
"IndexQueueMessageParser.parse - the priority is not set in the message and we "
88+
+ "will set it one.");
7389
priority =1;
7490
}
75-
logger.debug("IndexQueueMessageParser.parse - the priority in the message is " + priority);
91+
logger.debug(
92+
"IndexQueueMessageParser.parse - the priority in the message is " + priority + " for "
93+
+ pid);
7694
}
7795

7896
/**
@@ -99,4 +117,14 @@ public int getPriority() {
99117
return priority;
100118
}
101119

120+
/**
121+
* Get the file path of the object, which will be indexed,
122+
* after calling the parse method to parse the index queue message.
123+
* @return the file path of the object. It can be null or blank, which
124+
* means we don't have the object in the system.
125+
*/
126+
public String getObjectPath() {
127+
return objectPath;
128+
}
129+
102130
}

0 commit comments

Comments
 (0)