|
|
package cn.net.connor.plm.batchRevision;
|
|
|
|
|
|
import java.awt.Frame;
|
|
|
|
|
|
import com.teamcenter.rac.aif.AbstractAIFApplication;
|
|
|
import com.teamcenter.rac.aif.common.actions.AbstractAIFAction;
|
|
|
import com.teamcenter.rac.aif.kernel.AIFComponentContext;
|
|
|
import com.teamcenter.rac.aif.kernel.InterfaceAIFComponent;
|
|
|
import com.teamcenter.rac.kernel.TCComponent;
|
|
|
import com.teamcenter.rac.kernel.TCComponentFolder;
|
|
|
import com.teamcenter.rac.kernel.TCComponentItem;
|
|
|
import com.teamcenter.rac.kernel.TCComponentItemRevision;
|
|
|
import com.teamcenter.rac.kernel.TCComponentPseudoFolder;
|
|
|
import com.teamcenter.rac.kernel.TCComponentReleaseStatus;
|
|
|
import com.teamcenter.rac.kernel.TCException;
|
|
|
import com.teamcenter.rac.kernel.TCSession;
|
|
|
import com.teamcenter.rac.util.MessageBox;
|
|
|
|
|
|
public class BatchRevisionAction extends AbstractAIFAction {
|
|
|
|
|
|
private AbstractAIFApplication application;
|
|
|
private TCSession session;
|
|
|
public BatchRevisionAction(AbstractAIFApplication application, Frame frame, String param) {
|
|
|
super(application, frame, param);
|
|
|
this.application = application;
|
|
|
this.session = (TCSession)application.getSession();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void run() {
|
|
|
// MessageBox.post("触发“批量修订”逻辑!", "我的打印信息", MessageBox.INFORMATION);
|
|
|
System.out.println("触发“批量修订”按钮!");
|
|
|
try {
|
|
|
for (InterfaceAIFComponent targetComponent : application.getTargetComponents()) {
|
|
|
String targetName = targetComponent.getProperty("object_string");
|
|
|
String folderTrueName = null;
|
|
|
if (targetComponent instanceof TCComponentPseudoFolder) {
|
|
|
TCComponentPseudoFolder folder = (TCComponentPseudoFolder)targetComponent;
|
|
|
//选中文件夹所在的版本对象
|
|
|
TCComponentItemRevision owningRevision = (TCComponentItemRevision)folder.getOwningComponent();
|
|
|
|
|
|
String folderName = folder.getStringProperty("object_string");
|
|
|
System.out.println("选中文件夹的显示名称="+folderName+"-"+folder.getType());
|
|
|
if (folderName != null && folderName.equals("问题项")) {
|
|
|
folderTrueName = "CMHasProblemItem";
|
|
|
|
|
|
}else if (folderName != null && folderName.equals("受影响项")) {
|
|
|
folderTrueName = "CMHasImpactedItem";
|
|
|
}
|
|
|
System.out.println("选中文件夹对应的真实名称="+folderTrueName);
|
|
|
|
|
|
if (folderTrueName != null) {
|
|
|
//获取选中文件夹内的对象 -referenceListProperty
|
|
|
TCComponent[] referenceListProperty = owningRevision.getReferenceListProperty(folderTrueName);
|
|
|
if (referenceListProperty != null && referenceListProperty.length > 0) {
|
|
|
|
|
|
// session.getUserService().call("bypass", new Object[] { true });
|
|
|
String xdErroItemRevString = "";//未发布的修订失败的版本对象信息,用换行分割
|
|
|
//将选中文件夹下的对象遍历:升版,并将新版放到【解决方案零组件】-CMHasSolutionItem 下
|
|
|
for (int i = 0; i < referenceListProperty.length; i++) {
|
|
|
TCComponentItemRevision rev = (TCComponentItemRevision)referenceListProperty[i];
|
|
|
TCComponentItem item = rev.getItem();
|
|
|
//判断该版本对象是否已发布,若未发布则跳过,无法修订
|
|
|
if (!isRelease(rev)) {
|
|
|
System.out.println(">>>版本【"+rev.getStringProperty("object_string")+"】未发布,不允许修订,跳过!");
|
|
|
xdErroItemRevString += " "+rev.getStringProperty("object_string")+"\n";
|
|
|
continue;
|
|
|
}else {
|
|
|
//版本已发布,升版,加入文件夹下
|
|
|
try {
|
|
|
TCComponentItemRevision newItemRevision = rev.saveAs(null);
|
|
|
owningRevision.add("CMHasSolutionItem", newItemRevision);
|
|
|
} catch (Exception e) {
|
|
|
try {
|
|
|
TCComponentItemRevision latestItemRevision = rev.getItem().getLatestItemRevision();
|
|
|
owningRevision.add("CMHasSolutionItem", latestItemRevision);
|
|
|
System.out.println("已存在新版本");
|
|
|
}catch (Exception e2) {
|
|
|
e2.printStackTrace();
|
|
|
}
|
|
|
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
// session.getUserService().call("bypass", new Object[] { false });
|
|
|
System.out.println("批量修订完成!");
|
|
|
if (xdErroItemRevString != null && !xdErroItemRevString.equals("")){
|
|
|
MessageBox.post("批量修订完成!\n部分版本修订失败。原因:未发布\n "+xdErroItemRevString, "我的打印信息", MessageBox.INFORMATION);
|
|
|
}else {
|
|
|
MessageBox.post("批量修订完成!", "修订结果", MessageBox.INFORMATION);
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}else {
|
|
|
System.out.println("未获取到文件夹["+folderName+"-"+folderTrueName+"]下的子项!");
|
|
|
MessageBox.post("未获取到文件夹["+folderName+"-"+folderTrueName+"]下的子项!", "修订结果", MessageBox.INFORMATION);
|
|
|
}
|
|
|
|
|
|
}else {
|
|
|
System.out.println("获取选中文件夹的属性真实值失败!");
|
|
|
}
|
|
|
|
|
|
}else {
|
|
|
System.out.println("选中对象【"+targetName+"】的类型 [非文件夹] ,为:"+targetComponent.getType());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
System.out.println("批量修订失败:");
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 判断版本对象是否已发布
|
|
|
* @param rev
|
|
|
* @return
|
|
|
* @throws TCException
|
|
|
*/
|
|
|
private boolean isRelease(TCComponentItemRevision rev) throws TCException {
|
|
|
AIFComponentContext[] releaseList = rev.getChildren("release_status_list");
|
|
|
if (releaseList != null && releaseList.length > 0) {
|
|
|
TCComponentReleaseStatus status = (TCComponentReleaseStatus) releaseList[releaseList.length-1].getComponent();
|
|
|
String releaseName = status.getProperty("name");
|
|
|
if (!releaseName.contains("发布")||!releaseName.contains("TCM")) {
|
|
|
return false;
|
|
|
}else {
|
|
|
return true;
|
|
|
}
|
|
|
}else {
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|