zoukankan      html  css  js  c++  java
  • PTC FlexPLM rfa 接口自动创建产品规格

    <%-- Copyright (c) 2006 PTC FlexPLM All Rights Reserved --%>
    
    <%-- /////////////////////////////////////////////////////////////////////////////////////--%>
    <%-- //////////////////////////////// JSP HEADERS ////////////////////////////////////////--%>
    <%-- /////////////////////////////////////////////////////////////////////////////////////--%>
    <%@ page    language="java"
                import= "   java.util.*,
                            java.io.*,
                            wt.util.*,
                            java.net.*,
                            com.lcs.wc.util.*,
                            com.lcs.wc.document.*,
                            com.lcs.wc.flextype.*,
                            com.lcs.wc.product.*,
                            com.lcs.wc.foundation.LCSQuery,
                            com.lcs.wc.db.SearchResults,
                            com.lcs.wc.client.web.PageManager,
                            com.lcs.wc.client.web.WebControllers,
                            com.lcs.wc.client.Activities,
                            com.lcs.wc.flextype.*,
                            com.lcs.wc.foundation.*,
                            com.lcs.wc.db.*,
                            com.lcs.wc.part.*,
                            wt.part.*,
                            wt.part.WTPartMaster,
                            com.lcs.wc.sourcing.*,
                            com.lcs.wc.season.*,
                            com.lcs.wc.specification.*
                            "
    
    %>  
    <%-- /////////////////////////////////////////////////////////////////////////////////////--%>
    <%-- //////////////////////////////// BEAN INITIALIZATIONS ///////////////////////////////--%>
    <%-- /////////////////////////////////////////////////////////////////////////////////////--%>
    <jsp:useBean id="documentModel" scope="request" class="com.lcs.wc.document.LCSDocumentClientModel" />
    <jsp:useBean id="lcsContext" class="com.lcs.wc.client.ClientContext" scope="session"/>
    
    <%-- ////////////////////////////////////////////////////////////////////////////////////--%>
    <%-- ////////////////////////////// INITIALIZATION JSP CODE /////////////////////////////--%>
    <%-- ////////////////////////////////////////////////////////////////////////////////////--%>
    <%!
        public static final String DEFAULT_ENCODING = 
            LCSProperties.get("com.lcs.wc.util.CharsetFilter.Charset","UTF-8");
        public static boolean DEBUG = LCSProperties.getBoolean("jsp.xml.AIPlugin.verbose");
        public static String FILE_PATH = null;
    
        static {
            try  {
                WTProperties wtproperties = WTProperties.getLocalProperties();
                String wtHome = wtproperties.getProperty("wt.home");                    
                FILE_PATH = FormatHelper.formatOSFolderLocation(LCSProperties.get("com.lcs.wc.content.documentfilePath", "C:"));
                FILE_PATH = wtHome + FILE_PATH;
    
            } catch(Exception e){
                e.printStackTrace();
            }
        }
    %>
    <%-- /////////////////////////////////////////////////////////////////////////////////////--%>
    <%-- //////////////////////////////// PROCESSING  ////////////////////////////////////////--%>
    <%-- /////////////////////////////////////////////////////////////////////////////////////--%>
    <%
        try {
            String fileName = request.getHeader("content-location");
            if (!FormatHelper.hasContent(fileName)) {
                throw new LCSException(RB.DOCUMENT, "noFileName_ERR", RB.objA);     
            }
            fileName = FILE_PATH + File.separatorChar + fileName;
            fileName = FileRenamer.rename(fileName);
            System.out.println("\t File Name " + fileName);
            boolean hasError = false;
            InputStream input = request.getInputStream();
            FileOutputStream output = new FileOutputStream(fileName);
            byte buffer[] = new byte[1024];
            int len = -1;
            try {
                while ((len = input.read(buffer, 0, buffer.length)) > 0) {
                    output.write(buffer, 0, len);
                }
            } finally {
                if (output != null)
                    output.close();
            }
            File file = new File(fileName);
            if (!file.exists()) {
                System.out.println("\t No File ");
                //throw new LCSException("No File " + fileName);
                Object params[] = { fileName };
                throw new LCSException(RB.DOCUMENT, "noFile_ERR", params);            
            }
            if (file.length() == 0) {
                System.out.println("\t Zero Length file");
            Object params[] = { fileName };
                throw new LCSException(RB.DOCUMENT, "noContentInFile_MSG", params);
            }
            FileUploadHelper.processFile(fileName, file, documentModel, 
                request.getHeader("content-location"), request.getParameter("specificationId"));
            LCSDocument document = documentModel.getBusinessObject();
            document = (LCSDocument)wt.fc.PersistenceHelper.manager.refresh(document);
            String xmlStr = new XMLHelper().generateXML(document);
            buffer = xmlStr.getBytes(DEFAULT_ENCODING);
            response.setContentLength(buffer.length);
            response.setStatus(response.SC_OK);
            System.out.println("\t Response " + response.SC_OK);
            
            //changed by jackchain
            //2012-11-19
            //自动创建产品规格,关联产品文档
            //Start
            System.out.println("\t Jackchain reached here 到此一游!");        
            String owner=""+document.getValue("ownerReference");//获取WTPartMaster
            wt.part.WTPartMaster wt = (wt.part.WTPartMaster)(LCSQuery.findObjectById(owner));
            String SKU=wt.getName();
            //声明查询
            PreparedQueryStatement statement = new PreparedQueryStatement();
            statement.appendFromTable("LCSPRODUCT");
            String flextypePath = "Product"; 
            FlexType flextype = FlexTypeCache.getFlexTypeFromPath(flextypePath);
            statement.appendSelectColumn("LCSPRODUCT", flextype.getAttribute("productName").getVariableName());
            statement.appendSelectColumn("LCSPRODUCT", "BRANCHIDITERATIONINFO");
            //款号条件
            if(SKU.trim().length()>0){
                statement.appendAndIfNeeded();
                statement.appendCriteria(new Criteria("LCSPRODUCT",flextype.getAttribute("EPAstyleNumber").getVariableName(),SKU,Criteria.EQUALS));
            }
            statement.appendAndIfNeeded();
            statement.appendCriteria(new Criteria("LCSPRODUCT", "VERSIONIDA2VERSIONINFO", "A", Criteria.EQUALS));        
            statement.appendAndIfNeeded();
            statement.appendCriteria(new Criteria("LCSPRODUCT", "LATESTITERATIONINFO", "1", Criteria.EQUALS));        
            SearchResults results = LCSQuery.runDirectQuery(statement);
            Vector vRlt = results.getResults();
            int iRecNum = vRlt.size();        
            if (iRecNum == 1) {//找到产品
                FlexObject obj = (FlexObject) vRlt.get(0);//获取产品
                String oid="VR:com.lcs.wc.product.LCSProduct:"+obj.getString("LCSPRODUCT.BRANCHIDITERATIONINFO");
                LCSProduct product = (LCSProduct)(new LCSProductQuery()).findObjectById(oid);
                CreateSpec(product);
            }
            else{
                System.out.println("EP > not find product :"+SKU+" the specfication created failure!");
            }
            //End
            
            response.getWriter().write(xmlStr);
         } catch (Throwable e) {
            e.printStackTrace();
            String msg = new XMLHelper().generateErrorMessage(e);
            LCSErrorLog.logRequest(request, msg);
            System.out.println("\t Response " + response.SC_INTERNAL_SERVER_ERROR);
            byte[] buffer = msg.getBytes(DEFAULT_ENCODING);
            response.setContentLength(buffer.length);
            response.setContentType("text/plain");
            response.setStatus(response.SC_INTERNAL_SERVER_ERROR);
            java.io.Writer writer = response.getWriter();
            writer.write(msg);
         }
         
    %>
    <%!
        public void CreateSpec(LCSProduct product){
            //建立关联
                try{
                        String componentIds="";
                        LCSProductQuery prodQuery = new LCSProductQuery();
                        Collection prodImagePages = prodQuery.findImagePages(product, null, null, true);
                        prodImagePages = CollectionUtil.distinctResults(prodImagePages, "LCSDOCUMENT.BRANCHIDITERATIONINFO");
                        FlexType imagePageRootType = FlexTypeCache.getFlexTypeFromPath("Document\\Images Page");
                        Iterator imagePageIter = prodImagePages.iterator();
                       while(imagePageIter.hasNext()){
                           FlexObject obj_temp = (FlexObject) imagePageIter.next();
                           componentIds = "VR:com.lcs.wc.document.LCSDocument:" + obj_temp.getString("LCSDOCUMENT.BRANCHIDITERATIONINFO");
                       }
                       if(componentIds.equals(""))
                       {
                            System.out.println("AIPluginUploadContent.jsp > CreateSpec > 没有找到图片");
                            return;
                       }
                       //获取季节
                        String sourceIds="";
                        String specOwnerId="";
                        Collection sourcing = LCSSourcingConfigQuery.getSourcingConfigsForProduct(product);
                        Iterator it = sourcing.iterator();
                        LCSSourcingConfig configSource=null;
                        boolean isfindLY=false;
                        while (it.hasNext()) {
                            configSource = (LCSSourcingConfig)it.next();
                            if(configSource.getSourcingConfigName().contains("001")&&configSource.getSourcingConfigName().contains("Primary")){
                                sourceIds=("VR:com.lcs.wc.sourcing.LCSSourcingConfig:"+configSource.getBranchIdentifier());
                                specOwnerId=("OR:"+configSource.getProductMaster());
                                break;
                            }
                        }
                        if(sourceIds.equals("")||specOwnerId.equals("")){
                            System.out.println("AIPluginUploadContent.jsp > CreateSpec > 没有找到采购来源");
                            return;
                        }
                        //获取季节
                        String seasonIds="";
                        SeasonProductLocator seasonProductLocator = new SeasonProductLocator();
                        LCSSeasonProductLink seasonProductLink = seasonProductLocator.getSeasonProductLink(product);
                        LCSSeason season = (LCSSeason)seasonProductLocator.getSeasonRev(seasonProductLink);
                        seasonIds=("VR:com.lcs.wc.season.LCSSeason:"+season.getBranchIdentifier());
                        
                        SearchResults rs = FlexSpecQuery.findSpecsByOwner((WTPartMaster)product.getMaster(), (WTPartMaster)season.getMaster(), null, null);
                        Collection coll = LCSQuery.getObjectsFromResults(rs, "VR:com.lcs.wc.specification.FlexSpecification:", "FLEXSPECIFICATION.BRANCHIDITERATIONINFO");
                        if(coll.size()>0){
                            System.out.println("AIPluginUploadContent.jsp > CreateSpec > 已存在规格!");
                            return;
                        }
                        
                        System.out.println("sourceIds = " + sourceIds);
                        System.out.println("seasonIds = " + seasonIds);
                        System.out.println("specOwnerId = " + specOwnerId);
                        System.out.println("componentIds = " + componentIds);
                        
                        Collection listSourceIDs = new ArrayList();
                        listSourceIDs.add(sourceIds);
                        Collection listSeasonIds = new ArrayList();
                        listSeasonIds.add(seasonIds);
                        Collection listComponentIds = new ArrayList();
                        listComponentIds.add(componentIds);                
                        FlexType specFlexType = FlexTypeCache.getFlexTypeFromPath("Specification");                
                        FlexSpecificationClientModel flexSpecModel = new FlexSpecificationClientModel();                
                        flexSpecModel.setFlexType(specFlexType);
                        flexSpecModel.setSpecOwnerId(specOwnerId);
                        flexSpecModel.setSpecSourceId(sourceIds);
                        flexSpecModel.setTypeId("OR:"+specFlexType.getIdentity());
                        flexSpecModel.setValue("specName","自动生成");                
                        Map paramsMap=new HashMap();
                        paramsMap.put("parentSpec","");                
                        (new FlexSpecLogic()).saveSpec(flexSpecModel,listSourceIDs,listSeasonIds,listComponentIds,paramsMap);
                        System.out.println("AIPluginUploadContent.jsp > CreateSpec > successful");
                    }
                    catch(Exception error){
                        System.out.println("AIPluginUploadContent.jsp > CreateSpec > "+error);
                    }
        }
    %>
    
    
     
  • 相关阅读:
    c# DataTable获取某个列的集合
    DataTable中的select()用法(转)
    java中,数组toString()方法,数组常用操作
    C# 如何重写ToString函数及重写的意义,自定义类重写ToString()方法
    重写List 的ToString方法 -------C#
    设置响应报文头 image/jpeg
    response 设置响应头的常用几种方法
    [C#]Http请求报头设置
    HttpContext.Current.Session.Abandon() 大坑 要注意
    for循环拼接字符串去掉最后的逗号
  • 原文地址:https://www.cnblogs.com/qidian10/p/2777635.html
Copyright © 2011-2022 走看看