|
|
|
@ -10,7 +10,9 @@ import com.fr.report.entity.VcsEntity;
|
|
|
|
|
import com.fr.stable.StringUtils; |
|
|
|
|
import com.fr.workspace.WorkContext; |
|
|
|
|
import com.fr.workspace.server.vcs.VcsOperator; |
|
|
|
|
import com.fr.workspace.server.vcs.v2.VcsTaskResult; |
|
|
|
|
|
|
|
|
|
import javax.swing.SwingUtilities; |
|
|
|
|
import javax.swing.SwingWorker; |
|
|
|
|
import java.util.ArrayList; |
|
|
|
|
import java.util.List; |
|
|
|
@ -26,7 +28,7 @@ import java.util.concurrent.ExecutionException;
|
|
|
|
|
public class VcsOperatorWorker { |
|
|
|
|
private int count = 0; |
|
|
|
|
|
|
|
|
|
private static final int FREQ = 5; |
|
|
|
|
private static final int FREQ = 6; |
|
|
|
|
|
|
|
|
|
private String successStr; |
|
|
|
|
|
|
|
|
@ -102,21 +104,16 @@ public class VcsOperatorWorker {
|
|
|
|
|
* |
|
|
|
|
* @param vcsEntities 需要还原的版本 |
|
|
|
|
*/ |
|
|
|
|
public void batchRestore(List<VcsEntity> vcsEntities) { |
|
|
|
|
List<String> failedList = new ArrayList<>(); |
|
|
|
|
startProcess(vcsEntities, failedList, (vcsEntity, operator) -> { |
|
|
|
|
public void batchRestore(List<VcsEntity> vcsEntities, VcsTableOperatorListener listener) { |
|
|
|
|
VcsProcessFailedWrapper wrapper = new VcsProcessFailedWrapper(); |
|
|
|
|
startProcess(vcsEntities, wrapper, (vcsEntity, operator) -> { |
|
|
|
|
String fileName = vcsEntity.getFilename(); |
|
|
|
|
boolean result = true; |
|
|
|
|
try { |
|
|
|
|
operator.restoreVersion(fileName); |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
FineLoggerFactory.getLogger().error(e.getMessage(), e); |
|
|
|
|
result = false; |
|
|
|
|
VcsTaskResult result = operator.restoreVersion(fileName); |
|
|
|
|
if (!result.isSuccess()) { |
|
|
|
|
wrapper.addFailedEntity(vcsEntity); |
|
|
|
|
} |
|
|
|
|
if (!result) { |
|
|
|
|
failedList.add(fileName+PREFIX+vcsEntity.getVersion()+TAIL); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
return result; |
|
|
|
|
}, listener); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -126,25 +123,21 @@ public class VcsOperatorWorker {
|
|
|
|
|
* @param vcsEntities 需要删除的版本 |
|
|
|
|
* @param all 是否需要删除所有版本 |
|
|
|
|
*/ |
|
|
|
|
public void batchDelete(List<VcsEntity> vcsEntities, boolean all) { |
|
|
|
|
List<String> failedList = new ArrayList<>(); |
|
|
|
|
startProcess(vcsEntities, failedList, (vcsEntity, operator) -> { |
|
|
|
|
public void batchDelete(List<VcsEntity> vcsEntities, boolean all, VcsTableOperatorListener listener) { |
|
|
|
|
VcsProcessFailedWrapper wrapper = new VcsProcessFailedWrapper(); |
|
|
|
|
startProcess(vcsEntities, wrapper, (vcsEntity, operator) -> { |
|
|
|
|
String fileName = vcsEntity.getFilename(); |
|
|
|
|
boolean result = true; |
|
|
|
|
try { |
|
|
|
|
if (all) { |
|
|
|
|
operator.deleteVersionForRecycle(fileName); |
|
|
|
|
} else { |
|
|
|
|
operator.deleteVersion(fileName, vcsEntity.getVersion()); |
|
|
|
|
} |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
FineLoggerFactory.getLogger().error(e.getMessage(), e); |
|
|
|
|
result = false; |
|
|
|
|
VcsTaskResult result; |
|
|
|
|
if (all) { |
|
|
|
|
result = operator.deleteVersionForRecycle(fileName); |
|
|
|
|
} else { |
|
|
|
|
result = operator.deleteVersion(fileName, vcsEntity.getVersion(), VcsEntity.CommitType.TYPE_DEFAULT); |
|
|
|
|
} |
|
|
|
|
if (!result) { |
|
|
|
|
failedList.add(fileName+PREFIX+vcsEntity.getVersion()+TAIL); |
|
|
|
|
if (!result.isSuccess()) { |
|
|
|
|
wrapper.addFailedEntity(vcsEntity); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
return result; |
|
|
|
|
}, listener); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -153,9 +146,9 @@ public class VcsOperatorWorker {
|
|
|
|
|
* |
|
|
|
|
* @param entity VcsEntity |
|
|
|
|
*/ |
|
|
|
|
public void doDelete(VcsEntity entity) { |
|
|
|
|
public void doDelete(VcsEntity entity, VcsTableOperatorListener listener) { |
|
|
|
|
String fileName = entity.getFilename(); |
|
|
|
|
start4Single(entity, (vcsEntity, operator) -> operator.deleteVersionForRecycle(fileName), fileName + everyFailedStr); |
|
|
|
|
start4Single(entity, (vcsEntity, operator) -> operator.deleteVersionForRecycle(fileName), fileName + everyFailedStr, listener); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@ -163,12 +156,11 @@ public class VcsOperatorWorker {
|
|
|
|
|
* |
|
|
|
|
* @param entity 版本 |
|
|
|
|
*/ |
|
|
|
|
public void deleteTargetVersion(VcsEntity entity) { |
|
|
|
|
public void deleteTargetVersion(VcsEntity entity, VcsTableOperatorListener listener) { |
|
|
|
|
String fileName = entity.getFilename(); |
|
|
|
|
int version = entity.getVersion(); |
|
|
|
|
start4Single(entity, (vcsEntity, operator) -> { |
|
|
|
|
operator.deleteVersion(fileName, version); |
|
|
|
|
}, fileName + everyFailedStr); |
|
|
|
|
VcsEntity.CommitType commitType = entity.getCommitType(); |
|
|
|
|
start4Single(entity, (vcsEntity, operator) -> operator.deleteVersion(fileName, version, commitType), fileName + everyFailedStr, listener); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -177,16 +169,17 @@ public class VcsOperatorWorker {
|
|
|
|
|
* |
|
|
|
|
* @param entity 版本 |
|
|
|
|
*/ |
|
|
|
|
public void updateEntityAnnotation(VcsEntity entity) { |
|
|
|
|
public void updateEntityAnnotation(VcsEntity entity, VcsTableOperatorListener listener) { |
|
|
|
|
start4Single(entity, (vcsEntity, operator) -> { |
|
|
|
|
operator.updateVersion(entity); |
|
|
|
|
}, everyFailedStr); |
|
|
|
|
return new VcsTaskResult(true); |
|
|
|
|
}, everyFailedStr, listener); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void startProcess(List<VcsEntity> vcsEntities, List<String> failedList, VcsWorkerOperator workerOperator) { |
|
|
|
|
private void startProcess(List<VcsEntity> vcsEntities, VcsProcessFailedWrapper wrapper, VcsWorkerOperator workerOperator, VcsTableOperatorListener listener) { |
|
|
|
|
try { |
|
|
|
|
dialog.getProgressBar().setMaximum(vcsEntities.size()); |
|
|
|
|
start4Batch(vcsEntities, failedList, workerOperator); |
|
|
|
|
start4Batch(vcsEntities, wrapper, workerOperator, listener); |
|
|
|
|
dialog.showDialog(); |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
FineLoggerFactory.getLogger().error(e.getMessage(), e); |
|
|
|
@ -202,13 +195,15 @@ public class VcsOperatorWorker {
|
|
|
|
|
return (count > FREQ && count % FREQ == 0) || count < FREQ; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void start4Single(VcsEntity entity, VcsWorkerOperator vcsWorkerOperator, String failedTip) { |
|
|
|
|
private void start4Single(VcsEntity entity, VcsWorkerOperator vcsWorkerOperator, String failedTip, VcsTableOperatorListener listener) { |
|
|
|
|
new SwingWorker<Boolean, Void>() { |
|
|
|
|
@Override |
|
|
|
|
protected void done() { |
|
|
|
|
try { |
|
|
|
|
if (!get()) { |
|
|
|
|
FineJOptionPane.showMessageDialog(DesignerContext.getDesignerFrame(), failedTip); |
|
|
|
|
FineJOptionPane.showMessageDialog(SwingUtilities.getWindowAncestor(DesignerContext.getDesignerFrame()), failedTip); |
|
|
|
|
} else { |
|
|
|
|
listener.updateUI(); |
|
|
|
|
} |
|
|
|
|
} catch (InterruptedException | ExecutionException e) { |
|
|
|
|
throw new RuntimeException(e); |
|
|
|
@ -218,16 +213,16 @@ public class VcsOperatorWorker {
|
|
|
|
|
protected Boolean doInBackground() throws Exception { |
|
|
|
|
try { |
|
|
|
|
VcsOperator operator = WorkContext.getCurrent().get(VcsOperator.class); |
|
|
|
|
vcsWorkerOperator.process(entity, operator); |
|
|
|
|
VcsTaskResult result = vcsWorkerOperator.process(entity, operator); |
|
|
|
|
return result.isSuccess(); |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
}.execute(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void start4Batch(List<VcsEntity> vcsEntities, List<String> failedList, VcsWorkerOperator workerOperator) { |
|
|
|
|
private void start4Batch(List<VcsEntity> vcsEntities, VcsProcessFailedWrapper wrapper, VcsWorkerOperator workerOperator, VcsTableOperatorListener listener) { |
|
|
|
|
new SwingWorker<Boolean, Integer>() { |
|
|
|
|
@Override |
|
|
|
|
protected Boolean doInBackground() throws Exception { |
|
|
|
@ -239,7 +234,7 @@ public class VcsOperatorWorker {
|
|
|
|
|
publish(count); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return failedList.isEmpty(); |
|
|
|
|
return wrapper.isAllSuccess(); |
|
|
|
|
} |
|
|
|
|
@Override |
|
|
|
|
protected void process(List<Integer> chunks) { |
|
|
|
@ -249,7 +244,9 @@ public class VcsOperatorWorker {
|
|
|
|
|
protected void done() { |
|
|
|
|
dialog.closeDialog(); |
|
|
|
|
try { |
|
|
|
|
List<String> failedList = wrapper.getDetailFailedList(); |
|
|
|
|
showErrorDetailPane(get(), failedList, failedList.size(), vcsEntities.size() - failedList.size()); |
|
|
|
|
listener.updateUI(wrapper); |
|
|
|
|
} catch (InterruptedException | ExecutionException e) { |
|
|
|
|
throw new RuntimeException(e); |
|
|
|
|
} |
|
|
|
@ -286,6 +283,6 @@ public class VcsOperatorWorker {
|
|
|
|
|
* @param vcsEntity 版本 |
|
|
|
|
* @param operator 操作类 |
|
|
|
|
*/ |
|
|
|
|
void process(VcsEntity vcsEntity, VcsOperator operator) throws Exception; |
|
|
|
|
VcsTaskResult process(VcsEntity vcsEntity, VcsOperator operator) throws Exception; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|