Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove SimpleDateFormatter #254

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ public PermissionUpdateResponseBuilder getGroups() {
}

private Boolean or(Boolean a, Boolean b) {
if(a == b) {
return a;
}
if(a == null) {
return b;
}
if(a.equals(b) {
return a;
}
return a || b;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,13 @@ public RefsResponse getBranch(String projectId, String id) {
ContextHolder.setContext(projectId);
RefsResponse branchesResponse = new RefsResponse();
Optional<Branch> branchesOption = this.branchRepository.findByBranchId(id);
if (!branchesOption.isPresent()) {
if (branchesOption.isEmpty()) {
throw new NotFoundException(branchesResponse);
}
Branch b = branchesOption.get();
List<RefJson> refs = new ArrayList<>();
Optional<RefJson> refOption = branchIndex.findById(b.getDocId());
if (!refOption.isPresent()) {
if (refOption.isEmpty()) {
logger.error("DefaultBranchService: JSON Not found for {} with docId: {}",
b.getBranchId(), b.getDocId());
throw new NotFoundException(branchesResponse);
Expand Down Expand Up @@ -171,7 +171,7 @@ public RefJson createBranch(String projectId, RefJson branch) {
for (Node n: nodeRepository.findAllByDeleted(false)) {
docIds.add(n.getDocId());
}
try { nodeIndex.addToRef(docIds); } catch(Exception e) {}
try { nodeIndex.addToRef(docIds); } catch(Exception ignored) {}
eventPublisher.forEach((pub) -> pub.publish(
EventObject.create(projectId, branch.getId(), "branch_created", branch)));
return branch;
Expand All @@ -189,7 +189,7 @@ public RefsResponse deleteBranch(String projectId, String id) {
throw new BadRequestException(branchesResponse.addMessage("Cannot delete master"));
}
Optional<Branch> branch = this.branchRepository.findByBranchId(id);
if (!branch.isPresent()) {
if (branch.isEmpty()) {
throw new NotFoundException(branchesResponse);
}
Branch b = branch.get();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package org.openmbee.mms.crud.services;

import java.text.ParseException;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.time.format.DateTimeParseException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
Expand Down Expand Up @@ -57,8 +59,8 @@ public CommitsResponse getRefCommits(String projectId, String refId, Map<String,
}
if (params.containsKey("maxTimestamp")) {
try {
timestamp = Formats.SDF.parse(params.get("maxTimestamp")).toInstant();
} catch (ParseException e) {
timestamp = LocalDateTime.parse(params.get("maxTimestamp"), Formats.FORMATTER).toInstant(ZoneOffset.ofHours(0));
} catch (DateTimeParseException e) {
e.printStackTrace();
throw new BadRequestException("maxTimestamp parse error, use " +
Formats.FORMATTER.format(Instant.now()) + " as example");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.openmbee.mms.crud.services;

import java.text.ParseException;
import java.util.Date;
import java.time.LocalDateTime;
import java.time.format.DateTimeParseException;
import java.util.List;
import java.util.Map;

Expand Down Expand Up @@ -39,13 +39,13 @@ public boolean diffUpdateJson(BaseJson element, Map<String, Object> existing,
Object existingModified = existing.get(BaseJson.MODIFIED);
if (jsonModified != null && !jsonModified.isEmpty() && existingModified != null) {
try {
Date jsonModDate = Formats.SDF.parse(jsonModified);
Date existingModDate = Formats.SDF.parse(existingModified.toString());
if (jsonModDate.before(existingModDate)) {
LocalDateTime jsonModDate = LocalDateTime.parse(jsonModified, Formats.FORMATTER);
LocalDateTime existingModDate = LocalDateTime.parse(existingModified.toString(), Formats.FORMATTER);
if (jsonModDate.isBefore(existingModDate)) {
info.addRejection(element.getId(), new Rejection(element, 409, "Conflict Detected"));
return false;
}
} catch (ParseException e) {
} catch (DateTimeParseException e) {
logger.info("date parse exception:" + jsonModified + " " + existingModified);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.ParseException;
import java.time.LocalDateTime;
import java.time.format.DateTimeParseException;
import java.util.*;

@Service("twcRevisionMmsCommitMapService")
Expand Down Expand Up @@ -68,7 +69,7 @@ public List<CommitJson> getTwcRevisionList(String projectId, String refId, Boole
List<CommitJson> commits = new ArrayList<>();
ContextHolder.setContext(projectId);
Optional<Branch> ref = branchRepository.findByBranchId(refId);
if (!ref.isPresent()) {
if (ref.isEmpty()) {
throw new NotFoundException("Branch not found");
}
try {
Expand All @@ -78,7 +79,7 @@ public List<CommitJson> getTwcRevisionList(String projectId, String refId, Boole
commitIds.add(commit.getCommitId());
});
List<CommitJson> commitJsonList = commitIndex.findAllById(commitIds);
if (null != commitJsonList && commitJsonList.size() > 0) {
if (null != commitJsonList && !commitJsonList.isEmpty()) {
commitJsonList.stream().forEach(commitJsonData -> {
if (commitJsonData.containsKey(TwcConstants.TWCREVISIONID)) {
commits.add(commitJsonData);
Expand Down Expand Up @@ -109,10 +110,10 @@ public CommitsComparator(Boolean reverseOrder) {
@Override
public int compare(CommitJson o, CommitJson t1) {
try {
Date d1 = Formats.SDF.parse((String) o.get(CommitJson.CREATED));
Date d2 = Formats.SDF.parse((String) t1.get(CommitJson.CREATED));
LocalDateTime d1 = LocalDateTime.parse((String) o.get(CommitJson.CREATED), Formats.FORMATTER);
LocalDateTime d2 = LocalDateTime.parse((String) t1.get(CommitJson.CREATED), Formats.FORMATTER);
return ascending ? d1.compareTo(d2) : d2.compareTo(d1);
} catch (ParseException e) {
} catch (DateTimeParseException e) {
logger.error("Error parsing commit dates: " + e.getMessage());
throw new InternalErrorException("Invalid commit created dates.");
}
Expand Down
Loading