Wednesday, 14 December 2016

SOA Service Client : Upload File in Teamcenter

How to Upload File into Teamcenter ?

private static void importXML(String sFullFilePath, String sSiteId, String sDestSiteId) throws Exception
    {
        String sFileName = sFullFilePath.substring(sFullFilePath.lastIndexOf("/") + 1);

        File file = new File(sFullFilePath);

        /* now we can get file ticket and use that file for import */

 //com.teamcenter.services.strong.core.FileManagementService

        FileManagementService fileMgntService = FileManagementService.getService(connection);

        FileManagement.TransientFileInfo[] fileinfo = new FileManagement.TransientFileInfo[1];

        fileinfo[0] = new FileManagement.TransientFileInfo();

        fileinfo[0].deleteFlag = false;

        fileinfo[0].fileName = sFileName;

        fileinfo[0].isBinary = false;

        GetTransientFileTicketsResponse resp = fileMgntService.getTransientFileTicketsForUpload(fileinfo);

        String sPLMXMLTicket = resp.transientFileTicketInfos[0].ticket;

        /* now we will upload the file using ticket */

        String sDirectory = file.getParent();
        String bootStrapURL = getTeamcenterPreference(connection, "Fms_BootStrap_Urls", "site");
        FileManagementUtility utility = new FileManagementUtility(connection, null, null,

        new String[] { bootStrapURL }, sDirectory);

        utility.putFileViaTicket(sPLMXMLTicket, file);

 //com.teamcenter.services.internal.strong.globalmultisite.ImportExportService

        ImportExportService serv = ImportExportService.getService(connection);

        TransferFormula formula = new TransferFormula();

        String arrTick[] = new String[1];

        arrTick[0] = sPLMXMLTicket;

        ImportObjectsResponse importObjectsResponse = serv.importObjects(Integer.parseInt(sSiteId), "AB",

                arrTick, formula, false);

        /* check for errors and if found throw exception */

        if (importObjectsResponse.servicedata.sizeOfPartialErrors() > 0)
        {
           ErrorStack errStack = importObjectsResponse.servicedata.getPartialError(0);
            String sErr = "";

            for (String sPartialError : errStack.getMessages())
            {
               sErr = sErr + sPartialError;
            }
            System.out.println(sErr);
        }
    }

No comments:

Post a Comment