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