cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Issue with Eclipse or Code When Changing EPMDocument ID in Java Program

ozclkonur
12-Amethyst

Issue with Eclipse or Code When Changing EPMDocument ID in Java Program

I have a code like this, and I ran it in its current state, and it worked. After that, I changed the ID value in this part ("wt.epm.EPMDocument:114592789") and assigned another EPMDocument ID. Of course, I also changed the file name and file path. When I ran it again, it still tried to send the request using the first information I used. In the console, it gave a warning saying something like "this has already been added" or similar. I tried a few more IDs, but each time it attempted to process using the first information I sent. Is this problem due to Eclipse, or is there an issue in the code? Can you help me?
 
-------------------------------------------------------------------------------------------------------
 
package ext.designtech.utils;

import java.beans.PropertyVetoException;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;

import wt.content.ApplicationData;
import wt.content.ContentHolder;
import wt.content.ContentRoleType;
import wt.content.ContentServerHelper;
import wt.epm.EPMDocument;
import wt.fc.Persistable;
import wt.fc.PersistenceHelper;
import wt.fc.WTObject;
import wt.method.RemoteAccess;
import wt.method.RemoteMethodServer;
import wt.pom.Transaction;
import wt.util.WTException;
import wt.util.WTPropertyVetoException;

public class UploadUtil implements RemoteAccess {

    public static void main(String[] args)
            throws WTException, PropertyVetoException, IOException, InvocationTargetException {

        RemoteMethodServer myServer = RemoteMethodServer.getDefault();
        myServer.setUserName("plm-1");
        myServer.setPassword("Des.23!Tech");

        // Generic kullan?m? düzelttik
        Class[] paramTypes = {};
        Object[] paramValues = {};
        myServer.invoke("upload", UploadUtil.class.getName(), null, paramTypes, paramValues);
    }

    public static void upload() throws WTException, PropertyVetoException, IOException {

        Transaction tx = new Transaction();
        try {

            wt.fc.ObjectIdentifier oid = wt.fc.ObjectIdentifier.newObjectIdentifier("wt.epm.EPMDocument:114592789");

            // Cast i?lemi düzgün ?ekilde yap?ld?
            EPMDocument doc = (EPMDocument) PersistenceHelper.manager.refresh(oid);
            System.out.println(doc);

            ContentHolder ch = (ContentHolder) doc;
            ApplicationData theContent = ApplicationData.newApplicationData(ch);
            String filename = "vns-042754_2ad.pdf";
            File theFile = new File("C:\\Users\\PLM-1\\Desktop\\vns-042754_2ad.pdf");


            if(theContent == null){
               
            theContent.setFileName(filename);
            String path = "C:\\Users\\PLM-1\\Desktop\\vns-042754_2ad.pdf";
            theContent.setUploadedFromPath(path);
            theContent.setRole(ContentRoleType.SECONDARY); // Enum tipi olarak düzeltildi
            System.out.println("---Role Set---");
            theContent.setFileSize(theFile.length());
            }else{
                theContent.setFileName(filename);
                theContent.setUploadedFromPath("C:\\Users\\PLM-1\\Desktop\\vns-042754_2ad.pdf");
                theContent.setFileSize(theFile.length());
            }
           
           
            FileInputStream fis = new FileInputStream(theFile);
           

            System.out.println("--Upload Begin--");

            tx.start();
            theContent = ContentServerHelper.service.updateContent(ch, theContent, fis);
            tx.commit();

            ContentServerHelper.service.updateHolderFormat(doc);
            doc = (EPMDocument) PersistenceHelper.manager.refresh((Persistable) doc, true, true);
            System.out.println("---Attachment attached---");

            fis.close();
        } catch (WTPropertyVetoException e) {
            e.printStackTrace();
            tx.rollback(); // Transaction ba?ar?s?z oldu?unda geri al
        } catch (Exception e) {
            e.printStackTrace();
            tx.rollback(); // Genel hatalar için geri al
        }
    }

}
 
 
6 REPLIES 6

@ozclkonur , I am not sure the steps you followed. If you have a JAR which you created and loaded into ThingWorx, it was loaded into the Java Virtual Machine (JVM). When you make a change to the JAR file. It may be necessary to stop and restart ThingWorx because the JVM may be holding on to the original version of JAR.

As a test I would stop and restart the ThingWorx Server and see if you get better results.

 

HTH

Pehowe

ozclkonur
12-Amethyst
(To:PEHOWE)

I've successfully implemented file deletion, but when I check MethodServer, it keeps logging the same message, repeatedly attempting to send the part with the EPMDocument ID 114592789. This was the ID I tried to process when I first ran the application. Since then, I've attempted to attach parts to different EPMDocument IDs like 129025898, but MethodServer keeps making requests for the initial ID. It continuously shows the same log. Is there a way to clear the MethodServer or bypass this issue?

HelesicPetr
22-Sapphire I
(To:ozclkonur)

Hi @ozclkonur 

You wrote the ID in the code, that is static. So if you rewrite it, you have to implement new version of the class file on the server.

Usually a restart the method server will reload and use the new class file.

This apply also to thingworx if you rebuild class with new version you have to copy it to the final destination and restart the java procsess 

 

If you want to work with more IDs and you want to define it outside of the code, then you have to use some load from file function where you define your IDs and load it in to a memory your code 

PetrH

As others have said, it sounds like you just need to restart the method server to force it to pick up the updated class, but it's worth noting that if you connect to the correct method server in debug mode, you can hot swap code so you don't need to restart for the changes to take effect. There are some limitations, like you cannot hot swap if you add / remove methods or arguments, and typically you need to configure Windchill to start just a single method server, but it's significantly easier to develop code this way.

HelesicPetr
22-Sapphire I
(To:GrahamV)

@GrahamV 

True true, Hotswap is available in the debug mode.

PetrH

ozclkonur
12-Amethyst
(To:GrahamV)

I solved it by thinking that if it always caches the code from the first execution, then I could create a fixed connection and manage the variables through that connection. This approach worked and it functioned as expected. However, I couldn’t use it because I didn’t know how to transfer the Windchill Java code.

Announcements


Top Tags