ChangeRebuilder Factor out event for status changes
Change-Id: Ib97b137c1eb6e4e120606d1589d151f56f92c713
This commit is contained in:
@@ -31,11 +31,6 @@ class ChangeMessageEvent extends Event {
|
|||||||
private static final Pattern TOPIC_REMOVED_REGEXP =
|
private static final Pattern TOPIC_REMOVED_REGEXP =
|
||||||
Pattern.compile("^Topic (.+) removed$");
|
Pattern.compile("^Topic (.+) removed$");
|
||||||
|
|
||||||
private static final Pattern STATUS_ABANDONED_REGEXP =
|
|
||||||
Pattern.compile("^Abandoned(\n.*)*$");
|
|
||||||
private static final Pattern STATUS_RESTORED_REGEXP =
|
|
||||||
Pattern.compile("^Restored(\n.*)*$");
|
|
||||||
|
|
||||||
private final ChangeMessage message;
|
private final ChangeMessage message;
|
||||||
private final Change noteDbChange;
|
private final Change noteDbChange;
|
||||||
|
|
||||||
@@ -57,7 +52,6 @@ class ChangeMessageEvent extends Event {
|
|||||||
checkUpdate(update);
|
checkUpdate(update);
|
||||||
update.setChangeMessage(message.getMessage());
|
update.setChangeMessage(message.getMessage());
|
||||||
setTopic(update);
|
setTopic(update);
|
||||||
setStatus(update);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setTopic(ChangeUpdate update) {
|
private void setTopic(ChangeUpdate update) {
|
||||||
@@ -86,21 +80,4 @@ class ChangeMessageEvent extends Event {
|
|||||||
noteDbChange.setTopic(null);
|
noteDbChange.setTopic(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setStatus(ChangeUpdate update) {
|
|
||||||
String msg = message.getMessage();
|
|
||||||
if (msg == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (STATUS_ABANDONED_REGEXP.matcher(msg).matches()) {
|
|
||||||
update.setStatus(Change.Status.ABANDONED);
|
|
||||||
noteDbChange.setStatus(Change.Status.ABANDONED);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (STATUS_RESTORED_REGEXP.matcher(msg).matches()) {
|
|
||||||
update.setStatus(Change.Status.NEW);
|
|
||||||
noteDbChange.setStatus(Change.Status.NEW);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -350,19 +350,17 @@ public class ChangeRebuilderImpl extends ChangeRebuilder {
|
|||||||
|
|
||||||
Change noteDbChange = new Change(null, null, null, null, null);
|
Change noteDbChange = new Change(null, null, null, null, null);
|
||||||
for (ChangeMessage msg : bundle.getChangeMessages()) {
|
for (ChangeMessage msg : bundle.getChangeMessages()) {
|
||||||
if (msg.getPatchSetId() == null) {
|
List<Event> msgEvents = parseChangeMessage(
|
||||||
// No dependency necessary; will get assigned to most recent patch set
|
msg, noteDbChange, change.getCreatedOn());
|
||||||
// in sortAndFillEvents.
|
if (msg.getPatchSetId() != null) {
|
||||||
events.add(
|
PatchSetEvent pse = patchSetEvents.get(msg.getPatchSetId());
|
||||||
new ChangeMessageEvent(msg, noteDbChange, change.getCreatedOn()));
|
if (pse != null) {
|
||||||
continue;
|
for (Event e : msgEvents) {
|
||||||
}
|
e.addDep(pse);
|
||||||
PatchSetEvent pse = patchSetEvents.get(msg.getPatchSetId());
|
}
|
||||||
if (pse != null) {
|
}
|
||||||
events.add(
|
|
||||||
new ChangeMessageEvent(msg, noteDbChange, change.getCreatedOn())
|
|
||||||
.addDep(pse));
|
|
||||||
}
|
}
|
||||||
|
events.addAll(msgEvents);
|
||||||
}
|
}
|
||||||
|
|
||||||
sortAndFillEvents(change, noteDbChange, events, minPsNum);
|
sortAndFillEvents(change, noteDbChange, events, minPsNum);
|
||||||
@@ -391,6 +389,18 @@ public class ChangeRebuilderImpl extends ChangeRebuilder {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private List<Event> parseChangeMessage(ChangeMessage msg, Change noteDbChange,
|
||||||
|
Timestamp changeCreatedOn) {
|
||||||
|
List<Event> events = new ArrayList<>(2);
|
||||||
|
events.add(new ChangeMessageEvent(msg, noteDbChange, changeCreatedOn));
|
||||||
|
Optional<StatusChangeEvent> sce =
|
||||||
|
StatusChangeEvent.parseFromMessage(msg, noteDbChange, changeCreatedOn);
|
||||||
|
if (sce.isPresent()) {
|
||||||
|
events.add(sce.get());
|
||||||
|
}
|
||||||
|
return events;
|
||||||
|
}
|
||||||
|
|
||||||
private static Integer getMinPatchSetNum(ChangeBundle bundle) {
|
private static Integer getMinPatchSetNum(ChangeBundle bundle) {
|
||||||
Integer minPsNum = null;
|
Integer minPsNum = null;
|
||||||
for (PatchSet ps : bundle.getPatchSets()) {
|
for (PatchSet ps : bundle.getPatchSets()) {
|
||||||
|
|||||||
@@ -0,0 +1,80 @@
|
|||||||
|
// Copyright (C) 2016 The Android Open Source Project
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
package com.google.gerrit.server.notedb.rebuild;
|
||||||
|
|
||||||
|
import com.google.common.base.Optional;
|
||||||
|
import com.google.gerrit.reviewdb.client.Account;
|
||||||
|
import com.google.gerrit.reviewdb.client.Change;
|
||||||
|
import com.google.gerrit.reviewdb.client.ChangeMessage;
|
||||||
|
import com.google.gerrit.reviewdb.client.PatchSet;
|
||||||
|
import com.google.gerrit.server.notedb.ChangeUpdate;
|
||||||
|
import com.google.gwtorm.server.OrmException;
|
||||||
|
|
||||||
|
import java.sql.Timestamp;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
class StatusChangeEvent extends Event {
|
||||||
|
private static final Pattern STATUS_ABANDONED_REGEXP =
|
||||||
|
Pattern.compile("^Abandoned(\n.*)*$");
|
||||||
|
private static final Pattern STATUS_RESTORED_REGEXP =
|
||||||
|
Pattern.compile("^Restored(\n.*)*$");
|
||||||
|
|
||||||
|
static Optional<StatusChangeEvent> parseFromMessage(ChangeMessage message,
|
||||||
|
Change noteDbChange, Timestamp changeCreatedOn) {
|
||||||
|
String msg = message.getMessage();
|
||||||
|
if (msg == null) {
|
||||||
|
return Optional.absent();
|
||||||
|
}
|
||||||
|
if (STATUS_ABANDONED_REGEXP.matcher(msg).matches()) {
|
||||||
|
return Optional.of(new StatusChangeEvent(
|
||||||
|
message, noteDbChange, changeCreatedOn, Change.Status.ABANDONED));
|
||||||
|
}
|
||||||
|
if (STATUS_RESTORED_REGEXP.matcher(msg).matches()) {
|
||||||
|
return Optional.of(new StatusChangeEvent(
|
||||||
|
message, noteDbChange, changeCreatedOn, Change.Status.NEW));
|
||||||
|
}
|
||||||
|
return Optional.absent();
|
||||||
|
}
|
||||||
|
|
||||||
|
private final Change noteDbChange;
|
||||||
|
private final Change.Status status;
|
||||||
|
|
||||||
|
private StatusChangeEvent(ChangeMessage message, Change noteDbChange,
|
||||||
|
Timestamp changeCreatedOn, Change.Status status) {
|
||||||
|
this(message.getPatchSetId(), message.getAuthor(),
|
||||||
|
message.getWrittenOn(), noteDbChange, changeCreatedOn, message.getTag(),
|
||||||
|
status);
|
||||||
|
}
|
||||||
|
|
||||||
|
private StatusChangeEvent(PatchSet.Id psId, Account.Id author,
|
||||||
|
Timestamp when, Change noteDbChange, Timestamp changeCreatedOn,
|
||||||
|
String tag, Change.Status status) {
|
||||||
|
super(psId, author, when, changeCreatedOn, tag);
|
||||||
|
this.noteDbChange = noteDbChange;
|
||||||
|
this.status = status;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
boolean uniquePerUpdate() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
void apply(ChangeUpdate update) throws OrmException {
|
||||||
|
checkUpdate(update);
|
||||||
|
update.fixStatus(status);
|
||||||
|
noteDbChange.setStatus(status);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user