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

Community Tip - Have a PTC product question you need answered fast? Chances are someone has asked it before. Learn about the community search. X

WTDocument Type how to change it?

Marc-AndreVervi
1-Newbie

WTDocument Type how to change it?

Is ther a way to change a Document Type after it has been created?

Let say it has been created as a "Reference Document", it also has been revised a couple times, and I'd like to change it for "Minutes Meeting" Type of WTDocument, witch has a different lifecycle. I also want to keep all versions, all history of the document.

The only way I found is to delete and re-create the Document the I can choose the type, but that way I loose all history. 😞

Anyone knows a better way? Maybe there's a way to change it directly in the Oracle Database?

Thanks,

1 REPLY 1

Hi I do not know if it is too late but....

I did this query update based on document number. But prior to execute the sql code you have to find the type ID (BRANCHIDA2TYPEDEFINITIONREFE, IDA2TYPEDEFINITIONREFERENCE) to change.

For this scope I used these java classes (but you can used other tricks - ie. a SQL code).

Regards,

Vittorio

----- ChangeTypeSql ---

import com.ptc.core.meta.common.RemoteWorkerHandler;
import java.io.PrintStream;

public class ChangeTypeSql
{

public ChangeTypeSql()
{
}

public static void main(String args[])
{
System.out.println("-------------------------------------------------------------------------------------------------------------");
System.out.println("Uso: ChangeTypeSql <logical identifier> per ricavare BRANCHIDA2TYPEDEFINITIONREFE IDA2TYPEDEFINITIONREFERENCE\n");
System.out.println("Uso: ChangeTypeSql <da logical identifier> <a logical identifier> per ricavare istruzione SQL di aggiornamento");
System.out.println("-------------------------------------------------------------------------------------------------------------\n\n");
try
{
System.out.println(RemoteWorkerHandler.handleRemoteWorker(new ChangeTypeSqlRW(), args));
}
catch(Exception exception)
{
exception.printStackTrace();
System.exit(-1);
}
System.exit(0);
}
}

------ ChangeTypeSqlRW ---

import java.util.*;
import java.lang.*;
import java.io.PrintStream;

import com.ptc.core.meta.common.*;
import com.ptc.core.meta.common.impl.WCTypeIdentifier;
import com.ptc.core.meta.type.mgmt.server.impl.StandardTypeDefinitionCache;
import wt.introspection.*;
import wt.services.applicationcontext.implementation.DefaultServiceProvider;
import wt.type.*;


public final class ChangeTypeSqlRW extends RemoteWorker
{

public ChangeTypeSqlRW()
{
}

public Object doWork(Object obj)
throws Exception
{
String as[] = (String[])(String[])obj;
boolean oneType = true;
StringBuffer stringbuffer = new StringBuffer();

if(as.length == 0)
return "Uso: ChangeTypeSql <da logical identifier> <a logical identifier> \nUso: ChangeTypeSql <logical identifier>";

if(as.length == 2)
oneType = false;

TypeIdentifier typeidentifier = null;
String s = null;
Class class1 = null;
try
{
typeidentifier = (TypeIdentifier)IDENTIFIER_FACTORY.get(as[0]);
s = ((WCTypeIdentifier)typeidentifier).getClassnameFromTypename();
stringbuffer.append(as[0] + " typeidentifier: " + typeidentifier + "\n");
class1 = Class.forName(s);
}
catch(Exception exception)
{
return (new StringBuilder()).append("LogicalIdentifier [").append(as[0]).append("] non trovato!").toString();
}
if (oneType) {
TypeDefinitionReference typedefinitionreference = TypedUtility.getTypeDefinitionReference(typeidentifier.getTypename());
long l = typedefinitionreference.getKey().getBranchId();
long l1 = typedefinitionreference.getKey().getId();
boolean flag = s.equals(typeidentifier.getTypename());
ClassInfo classinfo = WTIntrospector.getClassInfo(class1);
String s3 = classinfo.getDatabaseInfo().getBaseTableInfo().getTablename();
String s4 = classinfo.getDatabaseInfo().getBaseTableInfo().getColumnDescriptor("typeDefinitionReference.key.branchId").getColumnName();
String s5 = classinfo.getDatabaseInfo().getBaseTableInfo().getColumnDescriptor("typeDefinitionReference.key.id").getColumnName();
stringbuffer.append("--------------------------------------------------\n");
stringbuffer.append("tabella da aggiornare: " + s3 +"\n");
stringbuffer.append(s4 +": " + l +"\n");
stringbuffer.append(s5 +": " + l1 +"\n");
stringbuffer.append("--------------------------------------------------\n");
stringbuffer.append("Per aggiornare la classe dei documenti\n");
stringbuffer.append("[sqlplus] @UpDateDocTypebyNumber.sql docnumber " + l + " " + l1);
}
else {

// if(!wt.type.Typed.isAssignableFrom(class1))
// return (new StringBuilder()).append("Invalid type '").append(as[0]).append("'!").toString();
TypeIdentifier typeidentifier1 = null;
String s1 = null;
Class class2 = null;
try
{
typeidentifier1 = (TypeIdentifier)IDENTIFIER_FACTORY.get(as[1]);
s1 = ((WCTypeIdentifier)typeidentifier1).getClassnameFromTypename();
stringbuffer.append(as[1] + " typeidentifier: " + typeidentifier1 + "\n");
class2 = Class.forName(s1);
}
catch(Exception exception1)
{
return (new StringBuilder()).append("LogicalIdentifier [").append(as[1]).append("] non trovato!").toString();
}
// if(!wt.type.Typed.isAssignableFrom(class2))
// return (new StringBuilder()).append("Invalid type '").append(as[1]).append("'!").toString();
if(typeidentifier.equals(typeidentifier1))
return "Tipi identici!";
if(!s.equals(s1))
return "Tipi incompatibili!";
String s2 = s;
StandardTypeDefinitionCache standardtypedefinitioncache = (StandardTypeDefinitionCache)StandardTypeDefinitionCache.getInstance();
long al[] = standardtypedefinitioncache.getQueryBranchIds(typeidentifier, false);
TypeDefinitionReference typedefinitionreference = TypedUtility.getTypeDefinitionReference(typeidentifier1.getTypename());
long l = typedefinitionreference.getKey().getBranchId();
long l1 = typedefinitionreference.getKey().getId();
boolean flag = s.equals(typeidentifier.getTypename());
ClassInfo classinfo = WTIntrospector.getClassInfo(class1);
String s3 = classinfo.getDatabaseInfo().getBaseTableInfo().getTablename();
String s4 = classinfo.getDatabaseInfo().getBaseTableInfo().getColumnDescriptor("typeDefinitionReference.key.branchId").getColumnName();
String s5 = classinfo.getDatabaseInfo().getBaseTableInfo().getColumnDescriptor("typeDefinitionReference.key.id").getColumnName();
stringbuffer.append("UPDATE ").append(s3).append("\n");
stringbuffer.append(" SET ").append(s4).append(" = ").append(l).append(",\n");
stringbuffer.append(" ").append(s5).append(" = ").append(l1).append("\n");
stringbuffer.append(" WHERE ").append(s4).append(" IN (");
for(int i = 0; i < al.length; i++)
{
stringbuffer.append(al[i]);
if(i < al.length - 1)
stringbuffer.append(", ");
}

if(flag)
{
stringbuffer.append(")\n");
stringbuffer.append(" OR ").append(s4).append(" = NULL;");
} else
{
stringbuffer.append(");");
}
}

return stringbuffer.toString();
}

public String describeWork(Object obj)
{
return "REMOTE WORK";
}

private static final IdentifierFactory IDENTIFIER_FACTORY = (IdentifierFactory)DefaultServiceProvider.getService("com.ptc.core.meta.common.IdentifierFactory", "logical");
public static final String TYPED_BRANCH_ID = "typeDefinitionReference.key.branchId";
public static final String TYPED_ID = "typeDefinitionReference.key.id";

}

=============================

REM AGGIORNA IL Tipo Documento (classe) per tutti i documenti
REM il cui numero è simile al primo parametro la classe viene
REM definita dai parametri 2 e 3 (ricavati dalla classe ChangeTypeSql.java)
REM Uso: @UpDateDocTypebyNumber.sql docNumber BRANCHIDA2TYPEDEFINITIONREFE IDA2TYPEDEFINITIONREFERENCE
REM --
REM Consigliata eseguire prima @FindDoc2Update.sql docNumber
UPDATE WTDOCUMENT
SET WTDOCUMENT.BRANCHIDA2TYPEDEFINITIONREFE = &2,
WTDOCUMENT.IDA2TYPEDEFINITIONREFERENCE = &3
WHERE WTDOCUMENT.IDA3MASTERREFERENCE IN
(SELECT WTDOCUMENTMASTER.IDA2A2
FROM WTDOCUMENTMASTER
WHERE WTDOCUMENTMASTER.WTDOCUMENTNUMBER LIKE '%&1%'
);
COMMIT;

Top Tags