Skip to content

Commit

Permalink
[FSTORE-697] handle timezones in validation report timestamp (#1301)
Browse files Browse the repository at this point in the history
  • Loading branch information
vatj authored Feb 17, 2023
1 parent c6a47b1 commit 7b546a0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
import javax.ejb.TransactionAttribute;
import javax.ejb.TransactionAttributeType;
import javax.ws.rs.core.UriInfo;

import java.util.TimeZone;
import java.util.stream.Collectors;
import java.text.SimpleDateFormat;
import org.json.JSONObject;
Expand Down Expand Up @@ -70,7 +72,9 @@ public ValidationResultDTO build(UriInfo uriInfo, Project project,
metaJson.put("ingestionResult", validationResult.getIngestionResult());
// Same validation string as in validationController to parse time provided by GE
String formatDateString = "yyyy-MM-dd'T'hh:mm:ss.SSSSSSX";
String validationTime = new SimpleDateFormat(formatDateString).format(validationResult.getValidationTime());
SimpleDateFormat isoFormat = new SimpleDateFormat(formatDateString);
isoFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
String validationTime = isoFormat.format(validationResult.getValidationTime());
metaJson.put("validationTime", validationTime);
dto.setMeta(metaJson.toString());
dto.setValidationTime(validationTime);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.TimeZone;
import java.util.logging.Level;
import java.util.logging.Logger;

Expand Down Expand Up @@ -263,7 +264,9 @@ public ValidationReport convertReportDTOToPersistent(Users user, Featuregroup fe
JSONObject reportMeta = new JSONObject(reportDTO.getMeta());
String validationTimeString = reportMeta.getString("validation_time");
String formatDateString = "yyyyMMdd'T'HHmmss.SSS";
validationTime = new SimpleDateFormat(formatDateString).parse(
SimpleDateFormat isoFormat = new SimpleDateFormat(formatDateString);
isoFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
validationTime = isoFormat.parse(
validationTimeString.substring(0, validationTimeString.length() - 4));
} catch (JSONException | ParseException exception) {
validationTime = new Date();
Expand Down Expand Up @@ -311,16 +314,16 @@ private Inode registerValidationReportToDisk(Users user, Featuregroup featuregro
udfso.mkdir(reportDirPath.toString());
}
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HHmmss");
formatter.setTimeZone(TimeZone.getTimeZone("UTC"));
String fileName = String.format("validation_report_%s.json", formatter.format(validationTime));
Path reportPath = new Path(reportDirPath, fileName);
if (udfso.exists(reportPath)) {
throw new FeaturestoreException(RESTCodes.FeaturestoreErrorCode.ERROR_SAVING_ON_DISK_VALIDATION_REPORT,
Level.SEVERE, String.format("Validation report with file name %s already exists.", fileName));
}
udfso.create(reportPath, reportJSON.toString());
Inode inode = inodeController.getInodeAtPath(reportPath.toString());

return inode;

return inodeController.getInodeAtPath(reportPath.toString());
} catch (DatasetException | HopsSecurityException | IOException e) {
throw new FeaturestoreException(RESTCodes.FeaturestoreErrorCode.ERROR_SAVING_ON_DISK_VALIDATION_REPORT,
Level.WARNING, e.getMessage());
Expand Down

0 comments on commit 7b546a0

Please sign in to comment.