Windchill 图文档DWG使用队列生成表示法
标签:des style blog http java color 使用 os
问题描述
解决方案
使用队列将生成表示法的任务发送到master机器执行。相关代码如下:
package ext.zwcad.servers.from2;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import wt.content.ApplicationData;
import wt.content.ContentHelper;
import wt.content.ContentItem;
import wt.content.ContentRoleType;
import wt.content.Streamed;
import wt.epm.EPMDocument;
import wt.fc.PersistenceHelper;
import wt.fc.QueryResult;
import wt.filter.NavigationCriteria;
import wt.method.RemoteAccess;
import wt.org.UserNotFoundException;
import wt.org.WTPrincipal;
import wt.pom.ObjectIsStaleException;
import wt.pom.PersistenceException;
import wt.pom.UniquenessException;
import wt.queue.ProcessingQueue;
import wt.queue.QueueHelper;
import wt.services.ManagerException;
import wt.services.StandardManager;
import wt.session.SessionContext;
import wt.session.SessionHelper;
import wt.util.WTException;
import com.ptc.wvs.common.util.WVSProperties;
import com.ptc.wvs.server.publish.PublishJob;
import com.ptc.wvs.server.publish.PublishQueueHelper;
import com.ptc.wvs.server.util.PublishUtils;
import ext.zwcad.servers.ZwServerUtil;
public class zwViewStandardManager extends StandardManager implements RemoteAccess {
private static final long serialVersionUID = 5249640497492866903L;
private static WVSProperties wvsProp = new WVSProperties();
private static String RepresentationName = "Representation Name";
private static String RepresentationDescription = "Representation Description";
/**
* 新建表示法 RepresentationHelper.service.emitReadyToPublishEvent(对象)
*
* @param WTObject
* @param dwgFile
* @throws WTException
* @throws IOException
*/
public static void transformEPMDocView(String oid)
throws WTException, IOException {
// System.out.println("==============transformEPMDocView==============");
// System.out.println(epmDoc);
// System.out.println(dwgPath);
try {
EPMDocument epmDoc = ZwServerUtil.findEPM(oid);
File viewFile = getViewFile(epmDoc);
if (null == viewFile) return;
NavigationCriteria cri = null;
PublishJob job = new PublishJob(true, PublishUtils
.getRefFromObject(epmDoc), cri, null, true, RepresentationName,
RepresentationDescription, 0);
job.setNumberNameVersion(epmDoc);
job.setProcessType(0);
job.setRequestType(6);
job.setRequestSource(1);
job.setSyncInfo(null);
String publishOptions = "tempfile=" + viewFile.getName()
+ ",thumbnail=true" + ",origfile=" + epmDoc.getCADName();
job.setActionFileString(publishOptions);
job.setSubmitTime(System.currentTimeMillis());
job.setLogFile(new File(wvsProp.getPublishTempUploadDir()
+ File.separator + "_epm_publish.log"));
PublishQueueHelper.addPublishEntry(job);
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* 生成可视化临时文件
*
* @param dwgFile
* @return
* @throws IOException
*/
private static File getViewFile(EPMDocument doc) throws IOException {
String fileName = doc.getCADName();
String extension = fileName.substring(fileName.lastIndexOf("."));
File viewFile = null;
try {
QueryResult qr = ContentHelper.service.getContentsByRole(doc,
ContentRoleType.PRIMARY);
InputStream is = null;
byte[] bs = null;
while (qr.hasMoreElements()) {
ContentItem contentitem = (ContentItem) qr.nextElement();
ApplicationData applicationdata = (ApplicationData) contentitem;
Streamed streamed = (Streamed) applicationdata.getStreamData()
.getObject();
is = streamed.retrieveStream();
bs = new byte[(int) applicationdata.getFileSize()];
is.read(bs);
}
File file = new File(wvsProp.getPublishTempUploadDir());
if (!file.exists()) {
file.mkdirs();
}
viewFile = File.createTempFile("_" + System.currentTimeMillis(),
extension, new File(wvsProp.getPublishTempUploadDir()));
FileOutputStream fos = new FileOutputStream(viewFile);
fos.write(bs);
fos.flush();
fos.close();
} catch (WTException e) {
e.printStackTrace();
} finally {
}
return viewFile;
}
private static final String CLASSNAME = zwViewStandardManager.class.getName();
private static final String DATA_DELIVERY_QUEUE_NAME = "zwsoftView";
private static int DATA_DELIVERY_QUEUE_INTERVAL=300;
private ProcessingQueue dataDeliveryQueue;
public static zwViewStandardManager newStandardDataDeliveryService() throws WTException {
zwViewStandardManager service = new zwViewStandardManager();
service.initialize();
return service;
}
@Override
protected void performStartupProcess() throws ManagerException {
// System.out.println("============Delivery Service Starting...");
SessionContext context = SessionContext.newContext();
try {
SessionHelper.manager.setAdministrator();
dataDeliveryQueue = QueueHelper.manager.getQueue(DATA_DELIVERY_QUEUE_NAME);
if (dataDeliveryQueue == null){
createQueue(DATA_DELIVERY_QUEUE_NAME, DATA_DELIVERY_QUEUE_INTERVAL);
}
}catch (UserNotFoundException e) {
System.err.println("Sync Service: failed to set Administrator (ok if installation)");
SessionContext.setContext(context);
return;
}catch (WTException e) {
e.printStackTrace();
throw new ManagerException(this, "Could not initialize sync service.");
}finally {
SessionContext.setContext(context);
}
}
public boolean sendToDeliveryQueue(EPMDocument epmDoc)
throws WTException {
WTPrincipal administrator=SessionHelper.manager.getAdministrator();
if (administrator == null) {
System.out.println("sendToDeliveryQueue: failed to set Administrator (ok if installation)");
return false;
}
WTPrincipal currentUser = SessionContext.setEffectivePrincipal(administrator);
if(dataDeliveryQueue==null){
performStartupProcess();
}
if(!QueueHelper.manager.isActive(dataDeliveryQueue)){
QueueHelper.manager.startQueue(dataDeliveryQueue);
}
try {
Class> aclass[] = { String.class };
Object aobj[] = { epmDoc.toString() };
dataDeliveryQueue.addEntry(administrator, "transformEPMDocView", CLASSNAME, aclass, aobj);
} catch (Exception exception) {
if (exception instanceof WTException)
throw (WTException)exception;
else throw new WTException(exception);
} finally {
SessionContext.setEffectivePrincipal(currentUser);
}
return true;
}
/**
* 创建队列
* @param s
* @param i
* @return
* @throws WTException
*/
private ProcessingQueue createQueue(String s, int i) throws WTException {
// System.out.println("==========createQueue=============");
ProcessingQueue processingqueue = null;
try {
processingqueue = QueueHelper.manager.createQueue(s);
QueueHelper.manager.setInterval(processingqueue, i);
processingqueue = (ProcessingQueue)PersistenceHelper.manager.save(processingqueue);
} catch (ObjectIsStaleException objectisstaleexception) {
processingqueue = QueueHelper.manager.getQueue(s);
} catch (UniquenessException uniquenessexception) {
processingqueue = QueueHelper.manager.getQueue(s);
} catch (PersistenceException persistenceexception) {
processingqueue = QueueHelper.manager.getQueue(s);
}
return processingqueue;
}
}
调用方法
zwViewStandardManager server = zwViewStandardManager.newStandardDataDeliveryService();
server.sendToDeliveryQueue(epm);
Windchill 图文档DWG使用队列生成表示法,搜素材,soscw.com
Windchill 图文档DWG使用队列生成表示法
标签:des style blog http java color 使用 os
原文地址:http://www.cnblogs.com/sosomaxba/p/3868484.html
评论