Skip to main content
1-Visitor
November 4, 2011
Solved

Creating a Soft Type in a Java Expression

  • November 4, 2011
  • 1 reply
  • 3477 views

Hi All,

Does anyone know how you can create a soft type using a Java expression (to be used in a workflow).

For example to create a Change Notice:

wt.change2.WTChangeOrder2 co = wt.change2.WTChangeOrder2.newWTChangeOrder2();

But how about if I wanted to create a soft type of the Change Notice object called "HT Change Notice"?

Thanks in advance,

Toby

Best answer by MatthewKnight

If you'd rather start with the WTTypeDefinition, something like this may work:

public static void main(String[] args) {

try {

String logicalID = "wt.doc.WTDocument";

TypeDefinition typeDefinition = getTypeDefinition(logicalID);

TypeDefinitionReference tdr = getTypeDefinitionReference(typeDefinition);

} catch (Exception e) {

e.printStackTrace();

}

}

private static TypeDefinitionReference getTypeDefinitionReference(TypeDefinition td) throws WTException, WTPropertyVetoException {

TypeDefinitionReference tdr = TypeDefinitionReference.newTypeDefinitionReference();

TypeDefinitionForeignKey key = TypeDefinitionForeignKey.newTypeDefinitionForeignKey();

key.setBranchId(td.getBranchIdentifier());

key.setId(PersistenceHelper.getObjectIdentifier(td).getId());

tdr.setKey(key);

return tdr;

}

private static TypeDefinition getTypeDefinition(String logicalID) {

try {

QuerySpec qs = new QuerySpec(WTTypeDefinition.class);

qs.appendWhere(new SearchCondition(WTTypeDefinition.class,WTTypeDefinition.LOGICAL_IDENTIFIER,SearchCondition.EQUAL,logicalID),new int[]{0});

qs.appendAnd();

qs.appendWhere(new SearchCondition(WTTypeDefinition.class,WTTypeDefinition.LATEST_ITERATION,SearchCondition.IS_TRUE),new int[]{0});

return (TypeDefinition)PersistenceHelper.manager.find((StatementSpec)qs).nextElement();

} catch (Exception e) {

return null;

}

}

1 reply

1-Visitor
November 4, 2011

You need to get a TypeDefintionReference. There are several ways you can do that.

Let's assume you have the type String type = "wt.doc.WTDocument|com.CustomDocument"

Generally, it's something like this

TypeDefinitionReference tdr = wt.type.TypedUtility.getTypeDefinitionReference(type);

WTDocument doc = WTDocument.newWTDocument();

doc.setName(....)

doc.setNumber(...)

doc.setContainer(...)

doc.set.................

doc.setTypeDefinitionReference(tdr);

doc = (WTDocument)PersistenceHelper.manager.save(doc)

1-Visitor
November 4, 2011

If you'd rather start with the WTTypeDefinition, something like this may work:

public static void main(String[] args) {

try {

String logicalID = "wt.doc.WTDocument";

TypeDefinition typeDefinition = getTypeDefinition(logicalID);

TypeDefinitionReference tdr = getTypeDefinitionReference(typeDefinition);

} catch (Exception e) {

e.printStackTrace();

}

}

private static TypeDefinitionReference getTypeDefinitionReference(TypeDefinition td) throws WTException, WTPropertyVetoException {

TypeDefinitionReference tdr = TypeDefinitionReference.newTypeDefinitionReference();

TypeDefinitionForeignKey key = TypeDefinitionForeignKey.newTypeDefinitionForeignKey();

key.setBranchId(td.getBranchIdentifier());

key.setId(PersistenceHelper.getObjectIdentifier(td).getId());

tdr.setKey(key);

return tdr;

}

private static TypeDefinition getTypeDefinition(String logicalID) {

try {

QuerySpec qs = new QuerySpec(WTTypeDefinition.class);

qs.appendWhere(new SearchCondition(WTTypeDefinition.class,WTTypeDefinition.LOGICAL_IDENTIFIER,SearchCondition.EQUAL,logicalID),new int[]{0});

qs.appendAnd();

qs.appendWhere(new SearchCondition(WTTypeDefinition.class,WTTypeDefinition.LATEST_ITERATION,SearchCondition.IS_TRUE),new int[]{0});

return (TypeDefinition)PersistenceHelper.manager.find((StatementSpec)qs).nextElement();

} catch (Exception e) {

return null;

}

}

1-Visitor
November 4, 2011

Can the latter be used in a workflow expression? I have not tried the first post yet, but it is very similar to the expression that I have used to create a Change Notice in a workflow before so I shall try that one first.