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
}
}
}