Commit c11615d4 authored by hanson.yao's avatar hanson.yao

convert dxPart

parent 2ad037a6
package com.yonde.common;
import com.yonde.part.vo.DxPart;
import wt.fc.ObjectReference;
import wt.fc.Persistable;
import wt.fc.ReferenceFactory;
import wt.org.WTUser;
import wt.part.WTPart;
import wt.type.ClientTypedUtility;
import wt.util.WTException;
import wt.vc.wip.WorkInProgressHelper;
import java.rmi.RemoteException;
import java.util.Locale;
/**
* Created on 2022/12/26
*
* @author
*/
public class BaseConvertUtil {
public static DxPart toDxPart(WTPart wtPart) throws WTException, RemoteException {
DxPart dxPart = new DxPart();
String name = wtPart.getCreatorName();
String fullName = wtPart.getCreatorFullName();
System.out.println("-----name----"+name+"=======fullName===="+fullName);
dxPart.setCreator(String.format("%s(%s)", fullName, name));
WTUser modify = ((WTUser) wtPart.getModifier().getObject());
dxPart.setModifier(String.format("%s(%s)", modify.getFullName(), modify.getName()));
dxPart.setName(wtPart.getName());
dxPart.setNumber(wtPart.getNumber());
System.out.println("-----getPartByNumber----2");
dxPart.setEndItem(wtPart.isEndItem());
System.out.println("-----getPartByNumber----3");
dxPart.setLatest(wtPart.isLatestIteration());
System.out.println("-----getPartByNumber----4");
dxPart.setId(PartUtil.getWTObjectOid(wtPart));
System.out.println("-----getPartByNumber----5");
dxPart.setState(wtPart.getState().getState().getDisplay(Locale.SIMPLIFIED_CHINESE));
String wtType = ClientTypedUtility.getExternalTypeIdentifier(wtPart);
wtType = wtType.substring(wtType.lastIndexOf("|") + 1);
System.out.println("--------wtType------" + wtType);
dxPart.setDefaultUnit(wtPart.getDefaultUnit().getDisplay(Locale.SIMPLIFIED_CHINESE));
dxPart.setMasterId(new ReferenceFactory().getReferenceString(ObjectReference.newObjectReference((wtPart.getMaster().getPersistInfo().getObjectIdentifier()))));
System.out.println("-----getPartByNumber----9");
dxPart.setCheckOuted(WorkInProgressHelper.isCheckedOut(wtPart));
System.out.println("-----getPartByNumber----10");
dxPart.setModifyTime(DateTimeUtil.timeStampToString(wtPart.getModifyTimestamp()));
System.out.println("-----getPartByNumber----11");
dxPart.setCreateTime(DateTimeUtil.timeStampToString(wtPart.getCreateTimestamp()));
System.out.println("-----getPartByNumber----12");
Persistable object = wtPart.getLocker().getObject();
if (object != null) {
WTUser locker = ((WTUser) object);
dxPart.setLockNote(wtPart.getLockNote());
dxPart.setLockDate(DateTimeUtil.timeStampToString(wtPart.getLockDate()));
dxPart.setLocker(String.format("%s(%s)", locker.getFullName(), locker.getName()));
}
dxPart.setVersion(wtPart.getVersionIdentifier().getValue());
dxPart.setIteration(wtPart.getIterationIdentifier().getValue());
return dxPart;
}
}
......@@ -69,9 +69,6 @@ public class IBAHelper implements Serializable, RemoteAccess {
* @throws WTException
*/
public static Hashtable getAllIBAValues(WTObject obj) throws WTException, InvocationTargetException, RemoteException {
// if (!RemoteMethodServer.ServerFlag) {
// return (Hashtable) RemoteMethodServer.getDefault().invoke("getAllIBAValues", IBAHelper.class.getName(), null, new Class[]{WTObject.class}, new Object[]{obj});
// }
Hashtable hashtable = new Hashtable();
if (obj == null) {
return hashtable;
......@@ -83,13 +80,10 @@ public class IBAHelper implements Serializable, RemoteAccess {
if (dac != null) {
AbstractValueView avv[] = null;
avv = dac.getAttributeValues();
System.out.println("==========getAllIBAValues=======9");
for (int j = 0; j < avv.length; j++) {
System.out.println("==========getAllIBAValues=======10:" + j);
String thisIBAName = avv[j].getDefinition().getName();
String thisIBAValue = IBAValueUtility.getLocalizedIBAValueDisplayString(avv[j], LOCALE);
String thisIBAClass = (avv[j].getDefinition()).getAttributeDefinitionClassName();
System.out.println("==========getAllIBAValues=======11:" + j);
AttributeDefDefaultView definition = avv[j].getDefinition();
String thisIBAName = definition.getLogicalIdentifier();
String thisIBAClass = definition.getAttributeDefinitionClassName();
if (thisIBAClass.equals("wt.iba.definition.FloatDefinition")) {
float value = (float) ((FloatValueDefaultView) avv[j]).getValue();
hashtable.put(thisIBAName, new Float(value));
......@@ -97,7 +91,6 @@ public class IBAHelper implements Serializable, RemoteAccess {
long value = ((IntegerValueDefaultView) avv[j]).getValue();
hashtable.put(thisIBAName, String.valueOf(value));
} else if (thisIBAClass.equals("wt.iba.definition.StringDefinition")) {
System.out.println("==========getAllIBAValues=======12:" + j);
String value = ((StringValueDefaultView) avv[j]).getValue();
hashtable.put(thisIBAName, value);
}
......
......@@ -3,6 +3,7 @@ package com.yonde.common;
import com.ptc.core.meta.common.TypeIdentifier;
import com.ptc.core.meta.common.TypeIdentifierHelper;
import com.ptc.windchill.enterprise.copy.server.CoreMetaUtility;
import com.yonde.part.vo.DxPart;
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import wt.fc.*;
......@@ -50,13 +51,13 @@ public class PartUtil implements RemoteAccess {
public static String FOLDER = "FOLDER";
public static Hashtable<WTPart,Hashtable> getPartByNumberAndView(String number, String viewStr, boolean accessControlled) throws WTException {
public static DxPart getPartByNumberAndView(String number, String viewStr, boolean accessControlled) throws WTException {
WTPart part = null;
Hashtable<WTPart,Hashtable> parttable = new Hashtable<WTPart, Hashtable>();
DxPart dxPart = null;
try {
number = number.toUpperCase();
if (!RemoteMethodServer.ServerFlag) {
return (Hashtable) RemoteMethodServer.getDefault().invoke("getPartByNumberAndView", PartUtil.class.getName(),
return (DxPart) RemoteMethodServer.getDefault().invoke("getPartByNumberAndView", PartUtil.class.getName(),
null, new Class[]{String.class, String.class, boolean.class}, new Object[]{number, viewStr, accessControlled});
} else {
boolean enforce = SessionServerHelper.manager.setAccessEnforced(accessControlled);
......@@ -82,7 +83,8 @@ public class PartUtil implements RemoteAccess {
if(part!=null){
Hashtable hashtable = IBAHelper.getAllIBAValues(part);
parttable.put(part,hashtable);
dxPart = BaseConvertUtil.toDxPart(part);
dxPart.setDynamicAttrs(hashtable);
}
} finally {
SessionServerHelper.manager.setAccessEnforced(enforce);
......@@ -93,7 +95,7 @@ public class PartUtil implements RemoteAccess {
} catch (InvocationTargetException e) {
e.printStackTrace();
}
return parttable;
return dxPart;
}
......@@ -327,10 +329,10 @@ public class PartUtil implements RemoteAccess {
return null;
}
public static void main(String[] args) throws WTException, InvocationTargetException, RemoteException {
Hashtable table = getPartByNumberAndView(args[0], args[1], false);
public static void main(String[] args) throws WTException {
DxPart dxPart = getPartByNumberAndView(args[0], args[1], false);
//Hashtable hashtable = IBAHelper.getAllIBAValues(part);
System.out.println("hashtable====>" + table);
System.out.println("dxPart====>" + dxPart.toString());
}
/**
......
package com.yonde.part.service;
import com.yonde.common.DateTimeUtil;
import com.yonde.common.IBAHelper;
import com.yonde.common.PartUtil;
import com.yonde.common.UsageLinkUtil;
import com.yonde.part.vo.DxPart;
import com.yonde.part.vo.DxSourceUsageLink;
import org.springframework.stereotype.Service;
import wt.fc.ObjectReference;
import wt.fc.Persistable;
import wt.fc.ReferenceFactory;
import wt.org.WTUser;
import wt.part.Quantity;
import wt.part.WTPart;
import wt.part.WTPartMaster;
import wt.part.WTPartUsageLink;
import wt.type.ClientTypedUtility;
import wt.util.WTException;
import wt.vc.wip.WorkInProgressHelper;
import java.lang.reflect.InvocationTargetException;
import java.rmi.RemoteException;
import java.util.*;
import java.util.ArrayList;
import java.util.List;
@Service
public class PartService {
public static DxPart getPartByNumber(String number, String view) throws WTException, RemoteException, InvocationTargetException {
public static DxPart getPartByNumber(String number, String view) throws WTException, RemoteException {
System.out.println("-----getPartByNumber----");
boolean accessControlled = false;
DxPart dxPart = new DxPart();
Hashtable hashtable = PartUtil.getPartByNumberAndView(number, view, accessControlled);
System.out.println("-----getPartByNumber----a");
Hashtable ibatable = new Hashtable();
WTPart wtPart =null;
if(hashtable!=null){
Iterator i = hashtable.keySet().iterator();
if (i.hasNext()){
wtPart = (WTPart) i.next();
ibatable = (Hashtable) hashtable.get(wtPart);
}
}
// Hashtable hashtable = IBAHelper.getAllIBAValues(wtPart);
System.out.println("-----wtPart----1"+wtPart);
System.out.println("-----getPartByNumber----b"+hashtable);
if (wtPart != null) {
String name = wtPart.getCreatorName();
String fullName = wtPart.getCreatorFullName();
System.out.println("-----name----"+name+"=======fullName===="+fullName);
// WTUser creat = ((WTUser) wtPart.getCreator().getObject());
dxPart.setCreator(String.format("%s(%s)", fullName, name));
WTUser modify = ((WTUser) wtPart.getModifier().getObject());
dxPart.setModifier(String.format("%s(%s)", modify.getFullName(), modify.getName()));
System.out.println("-----getPartByNumber----1");
dxPart.setName(wtPart.getName());
dxPart.setNumber(wtPart.getNumber());
System.out.println("-----getPartByNumber----2");
dxPart.setEndItem(wtPart.isEndItem());
System.out.println("-----getPartByNumber----3");
dxPart.setLatest(wtPart.isLatestIteration());
System.out.println("-----getPartByNumber----4");
dxPart.setId(PartUtil.getWTObjectOid(wtPart));
System.out.println("-----getPartByNumber----5");
dxPart.setState(wtPart.getState().getState().getDisplay(Locale.SIMPLIFIED_CHINESE));
String wtType = ClientTypedUtility.getExternalTypeIdentifier(wtPart);
wtType = wtType.substring(wtType.lastIndexOf("|") + 1);
System.out.println("--------wtType------" + wtType);
dxPart.setDefaultUnit(wtPart.getDefaultUnit().getDisplay(Locale.SIMPLIFIED_CHINESE));
dxPart.setMasterId(new ReferenceFactory().getReferenceString(ObjectReference.newObjectReference((wtPart.getMaster().getPersistInfo().getObjectIdentifier()))));
System.out.println("-----getPartByNumber----9");
dxPart.setCheckOuted(WorkInProgressHelper.isCheckedOut(wtPart));
System.out.println("-----getPartByNumber----10");
dxPart.setModifyTime(DateTimeUtil.timeStampToString(wtPart.getModifyTimestamp()));
System.out.println("-----getPartByNumber----11");
dxPart.setCreateTime(DateTimeUtil.timeStampToString(wtPart.getCreateTimestamp()));
System.out.println("-----getPartByNumber----12");
Persistable object = wtPart.getLocker().getObject();
if (object != null) {
WTUser locker = ((WTUser) object);
dxPart.setLockNote(wtPart.getLockNote());
dxPart.setLockDate(DateTimeUtil.timeStampToString(wtPart.getLockDate()));
dxPart.setLocker(String.format("%s(%s)", locker.getFullName(), locker.getName()));
}
dxPart.setVersion(wtPart.getVersionIdentifier().getValue());
dxPart.setIteration(wtPart.getIterationIdentifier().getValue());
//dxPart.setDynamicAttrs(hashtable);
}
return dxPart;
return PartUtil.getPartByNumberAndView(number, view, false);
}
/**
......@@ -117,7 +50,7 @@ public class PartService {
dxUsageLink.setAmount(String.valueOf(qt.getAmount()));
dxUsageLink.setUnit(qt.getUnit().toString());
dxUsageLink.setSourceId(oid);
WTPartMaster uses = (WTPartMaster)link.getUses();
WTPartMaster uses = (WTPartMaster) link.getUses();
WTPart child = PartUtil.getLatestPartByNoViewWithState(uses.getNumber(), parent.getViewName(), null, false);
dxUsageLink.setTargetId(PartUtil.getWTObjectOid(child));
dxUsageLink.setSourceId(PartUtil.getWTObjectOid(parent));
......@@ -128,7 +61,7 @@ public class PartService {
}
public static void main(String[] args) throws WTException, InvocationTargetException, RemoteException {
List<DxSourceUsageLink> usageLinks = getUsageLinks(args[0]);
List<DxSourceUsageLink> usageLinks = getUsageLinks(args[0]);
System.out.println(usageLinks.size());
}
......
......@@ -34,8 +34,6 @@ public class DxPart implements Serializable {
private String locker;
private String version;
private String iteration;
//todo dynamicAttrs subTypeDisplayName 无法获取
private Map<String, Object> dynamicAttrs;
/**
* usageLinks bom link
......@@ -213,4 +211,31 @@ public class DxPart implements Serializable {
public void setMasterId(String masterId) {
this.masterId = masterId;
}
@Override
public String toString() {
return "DxPart{" +
"creator='" + creator + '\'' +
", modifier='" + modifier + '\'' +
", number='" + number + '\'' +
", name='" + name + '\'' +
", state='" + state + '\'' +
", endItem=" + endItem +
", latest=" + latest +
", id='" + id + '\'' +
", subTypeName='" + subTypeName + '\'' +
", defaultUnit='" + defaultUnit + '\'' +
", masterId='" + masterId + '\'' +
", checkOuted=" + checkOuted +
", modifyTime='" + modifyTime + '\'' +
", createTime='" + createTime + '\'' +
", lockNote='" + lockNote + '\'' +
", lockDate='" + lockDate + '\'' +
", locker='" + locker + '\'' +
", version='" + version + '\'' +
", iteration='" + iteration + '\'' +
", dynamicAttrs=" + dynamicAttrs +
", sourceUsageLinks=" + sourceUsageLinks +
'}';
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment