/** * 创建指定名称基线 * @throws WTException */ public static ManagedBaseline createBaseline() throws WTException { PersistableAdapter persistableAdapter = new PersistableAdapter("wt.vc.baseline.ManagedBaseline", null, null); persistableAdapter.load( "name"); persistableAdapter.set("name", "testBaseline"); ManagedBaseline baseline = (ManagedBaseline) persistableAdapter.apply(); baseline = (ManagedBaseline) PersistenceHelper.manager.save(baseline); return baseline; }
/** * 将BOM包括父件加入基线 * @throws WTException */ public static void insertIntoBaseline(String pOid, String bOid) throws WTException { WTPart rootPart = null; WTCollection collection = new WTArrayList(); NmOid nmOid = NmOid.newNmOid(pOid); Object refObj = nmOid.getRefObject(); if (refObj != null && refObj instanceof WTPart){ rootPart = (WTPart) refObj; } WTCollection collections = findBOM(rootPart, collection); ManagedBaseline baseline = null; nmOid = nmOid.newNmOid(bOid); refObj = nmOid.getRefObject(); if (refObj != null && refObj instanceof ManagedBaseline){ baseline = (ManagedBaseline) refObj; baseline = (ManagedBaseline) BaselineHelper.service.addToBaseline(rootPart, baseline); } for (Object obj : collections.persistableCollection()){ WTPart part = (WTPart) obj; baseline = (ManagedBaseline) BaselineHelper.service.addToBaseline(part, baseline); } } /** * 递归查找BOM所有子件 * @param part * @param collection * @return * @throws WTException */ public static WTCollection findBOM(WTPart part, WTCollection collection) throws WTException { WTPartConfigSpec wtPartConfigSpec = WTPartHelper.service.findWTPartConfigSpec(); WTPartStandardConfigSpec standardConfigSpec = wtPartConfigSpec.getStandard(); QueryResult qr = WTPartHelper.service.getUsesWTParts(part, standardConfigSpec); while (qr.hasMoreElements()){ Object[] arr = (Object[]) qr.nextElement(); if (arr[1] instanceof WTPart){ WTPart part1 = (WTPart) arr[1]; collection.add(part1); findBOM(part1,collection); } } return collection; }
/** * 基线中删除对象 * @throws WTException */ public static void deletePartFromBaseline(String pOid, String bOid) throws WTException { WTPart part = null; NmOid nmOid = NmOid.newNmOid(pOid); Object obj = nmOid.getRefObject(); if (obj != null && obj instanceof WTPart){ part = (WTPart) obj; } ManagedBaseline baseline = null; nmOid = nmOid.newNmOid(bOid); obj = nmOid.getRefObject(); if (obj != null && obj instanceof ManagedBaseline){ baseline = (ManagedBaseline) obj; } if (part != null && baseline != null){ baseline = (ManagedBaseline) BaselineHelper.service.removeFromBaseline(part, baseline); } }
/** * 锁定基线 * @throws WTException */ public static void lockBaseline(String bOid) throws WTException, WTPropertyVetoException { ManagedBaseline baseline = null; NmOid nmOid = NmOid.newNmOid(bOid); Object obj = nmOid.getRefObject(); if (obj != null && obj instanceof ManagedBaseline){ baseline = (ManagedBaseline) obj; baseline = (ManagedBaseline) LockHelper.service.lock(baseline, SessionHelper.manager.getPrincipalReference()); } } /** * 解锁基线 * @param bOid * @throws WTException * @throws WTPropertyVetoException */ public static void unlockBaseline(String bOid) throws WTException, WTPropertyVetoException { ManagedBaseline baseline = null; NmOid nmOid = NmOid.newNmOid(bOid); Object obj = nmOid.getRefObject(); if (obj != null && obj instanceof ManagedBaseline){ baseline = (ManagedBaseline) obj; baseline = (ManagedBaseline) LockHelper.service.unlock(baseline, SessionHelper.manager.getPrincipalReference()); } }
标签:obj,baseline,ManagedBaseline,基线,nmOid,相关,操作,null,throws From: https://www.cnblogs.com/SHH269157/p/16771403.html