Skip to content

Commit

Permalink
better contentUpdatedSinceDateTime handling
Browse files Browse the repository at this point in the history
  • Loading branch information
cameroncaci committed Nov 1, 2023
1 parent e36793d commit 3d17f27
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

import java.io.IOException;

import javax.xml.datatype.DatatypeConfigurationException;

import org.slf4j.LoggerFactory;
import ch.qos.logback.classic.Logger;

Expand All @@ -39,6 +41,8 @@ public class GetTableController {
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "Success", content = {
@Content(mediaType = "application/json", schema = @Schema(implementation = GetTableResponse.class)) }),
@ApiResponse(responseCode = "400", description = "Bad Request", content = {
@Content(mediaType = "application/json") }),
@ApiResponse(responseCode = "500", description = "Internal Server Error", content = {
@Content(mediaType = "application/json") })
})
Expand All @@ -48,8 +52,11 @@ public ResponseEntity<GetTableResponse> getTable(@Valid @RequestBody GetTableReq
GetTableResponse response = getTableService.getTableRequest(requestBody);
return ResponseEntity.ok(response);
} catch (IOException e) {
logger.error("Error processing GetTable request", e);
logger.error("Error processing attachment for GetTable request", e);
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
} catch (DatatypeConfigurationException e) {
logger.error("Error processing XMLGregorianCalendar type for provided contentUpdatedSinceDateTime value for GetTable request", e);
return ResponseEntity.status(HttpStatus.BAD_REQUEST).build();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.milmove.trdmlambda.milmove.model.gettable;

import javax.xml.datatype.XMLGregorianCalendar;

import com.milmove.trdmlambda.milmove.contraints.ContentUpdatedSinceDateTimeConstraint;
import com.milmove.trdmlambda.milmove.contraints.PhysicalNameConstraint;

Expand All @@ -12,6 +10,6 @@ public class GetTableRequest {
@PhysicalNameConstraint
private String physicalName;
@ContentUpdatedSinceDateTimeConstraint
private XMLGregorianCalendar contentUpdatedSinceDateTime;
private String contentUpdatedSinceDateTime; // To be converted to javax.xml.datatype.XMLGregorianCalendar
private boolean returnContent;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

import java.io.IOException;
import java.util.Map;

import javax.xml.datatype.DatatypeConfigurationException;
import javax.xml.datatype.DatatypeFactory;
import javax.xml.stream.XMLStreamException;

import org.apache.commons.io.output.ByteArrayOutputStream;
Expand Down Expand Up @@ -59,8 +62,9 @@ public GetTableService(TrdmProps trdmProps, ClientPasswordCallback clientPasswor
* @param request GetTableRequest
* @return GetTableResponse
* @throws IOException attachment processing failure
* @throws DatatypeConfigurationException user provided string for contentUpdatedSinceDateTime not valid for XMLGregorianCalendar type
*/
public GetTableResponse getTableRequest(GetTableRequest request) throws IOException {
public GetTableResponse getTableRequest(GetTableRequest request) throws IOException, DatatypeConfigurationException {
return createSoapRequest(request);
}

Expand All @@ -70,16 +74,19 @@ public GetTableResponse getTableRequest(GetTableRequest request) throws IOExcept
* @param request - GetTableRequest
* @return built SOAP XML body with header.
* @throws IOException
* @throws DatatypeConfigurationException
* @throws XMLStreamException
*/
private GetTableResponse createSoapRequest(GetTableRequest request) throws IOException {
private GetTableResponse createSoapRequest(GetTableRequest request) throws IOException, DatatypeConfigurationException {

ReturnTableRequestElement requestElement = new ReturnTableRequestElement();
ReturnTableInput input = new ReturnTableInput();
TRDM trdm = new TRDM();
trdm.setPhysicalName(request.getPhysicalName());
trdm.setReturnContent(request.isReturnContent());
trdm.setContentUpdatedSinceDateTime(request.getContentUpdatedSinceDateTime());
trdm.setReturnContent(Boolean.valueOf(request.isReturnContent()));
trdm.setContentUpdatedSinceDateTime(DatatypeFactory.newInstance()
.newXMLGregorianCalendar(request.getContentUpdatedSinceDateTime()));

input.setTRDM(trdm);
requestElement.setInput(input);
Expand Down

0 comments on commit 3d17f27

Please sign in to comment.