

To: 
Eric.Lucas <Eric.Lucas@MHPowerSystems.com>; 
Micah.Justad <Micah.Justad@MHPowerSystems.com>; 
Micah.Justad@mpshq.com, 
Casey.Swain <Casey.Swain@MHPowerSystems.com>; 
Casey.Swain@mpshq.com
Ramy.massoud <Ramy.massoud@MHPowerSystems.com>
Ramy.massoud@mpshq.com

lawrence.jett@mpshq.com
Lawrence.Jett@mpshq.com

D:\PTC\Windchill\WC10\wc10_dev\wc10_jad\com\ptc\core\meta\container\common\AttributeTypeSummary.jad

http://hostname/Windchill/meta/LogicalAttributeReport.jsp

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

SACFDescribedByDocumentRevision.java

while(describedByDocumentsResult.hasMoreElements())
{
	/* Start MCAD_8.2 code merge */
	curDoc = ((WTDocument) describedByDocumentsResult.nextElement());
	ibaUtil = new IBAUtil((IBAHolder) curDoc);
	String documentSubType = ibaUtil.getIBAStringValue("RTN_DOCUMENT_SUBTYPE");

	log.debug(CLASSNAME + ":   Found Valid Describing Document: " + curDoc.getIdentity() + "." + curDoc.getIterationInfo().getIdentifier().getValue());
	log.debug(CLASSNAME + ":   Found Valid Document Subtype: " + documentSubType);
	if (documentSubType != null)
	{
		if(documentSubType.equalsIgnoreCase("Parts List (085)"))
		{
			count_085++;
			doc085 = curDoc;
		}
		else if(documentSubType.equalsIgnoreCase("Assembly Drawing (021)"))
		{
			count_021++;
			doc021 = curDoc;
		}
	}
}//end of while loop

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

ApprovedChangesReport.java

	private final String CNTYPENAME= "WCTYPE|wt.change2.WTChangeOrder2|com.ray.RaytheonChangeOrderCommonAttribs|com.ray.RaytheonChangeOrder|com.ray.RaytheonChangeNotice";
	private final String MCNTYPENAME = "WCTYPE|wt.change2.WTChangeOrder2|com.ray.RaytheonChangeOrderCommonAttribs|com.ray.RaytheonChangeOrder|com.ray.RaytheonChangeNotice|com.ray.RaytheonManufacturingChangeNotice";	
	private final String CPTYPENAME = "WCTYPE|wt.change2.WTChangeOrder2|com.ray.RaytheonChangeOrderCommonAttribs|com.ray.RaytheonChangeOrder|com.ray.RaytheonChangeProposal";
	private final String CNATTRNAME = "RTN_SUBTYPE";
	private final String MCNATTRNAME = "RTN_SUBTYPE";
	private final String CPATTRNAME = "RTN_TYPE";
	private final String ECN = "ECN";
	private final String MCN = "MCN";
	private final String ECP = "ECP";
	private final String OBJECTTYPE = "objectType";
	private final String CONSTRAINT = "constraint";


	public void filterGroup()
	{
		if(_filter_in == null || _filter_out == null) return;
		Group group = _filter_in;
		ArrayList<String> removeList = new ArrayList<String>();
		Date approvalDate = null;
		for (int i=0; i<group.getElementCount(); i++)
		{
			Element element = group.getElementAt(i);
			String obid = (String)element.getValue("obid");
			try
			{
				WTChangeOrder2 order = (WTChangeOrder2)BasicWebjectDelegate.getObjectByUfid(obid);
				approvalDate = ReportHelper.getDateStateWasSet(order, ReportHelper.APPROVED_STATE, true);
				element.addAtt(new Att("approvalDate", approvalDate));
				
				if((element.getAtt("IBA|RTN_TYPE").getValue().toString().equals("") || element.getAtt("IBA|RTN_TYPE").getValue() == null) && element.getAtt("IBA|RTN_SUBTYPE") != null)
				{//if the element is an ECN
					String s = element.getAtt("IBA|RTN_SUBTYPE").getValue().toString();
					//if the type doesn't match the filter criteria, mark this element for removal
					if(!s.equalsIgnoreCase(_type) && !_type.equals("All"))
					{
						removeList.add(obid);
					}
				}
				else if((element.getAtt("IBA|RTN_SUBTYPE").getValue().toString().equals("") || element.getAtt("IBA|RTN_SUBTYPE").getValue() == null) && element.getAtt("IBA|RTN_TYPE") != null)
				{//if the element is an ECP
					String s = element.getAtt("IBA|RTN_TYPE").getValue().toString();
					//if the type doesn't match the filter criteria, mark this element for removal
					if(!s.equalsIgnoreCase(_type) && !_type.equals("All"))
					{
						removeList.add(obid);
					}
				}
				if(approvalDate == null)
				{
					//if it's not approved, mark it for removal
					removeList.add(obid);
				}
				else
				{
					if((_start != null && approvalDate.before(_start)) || (_end != null && approvalDate.after(_end)))
					{
						//mark for removal anything that fell outside the defined date range
						removeList.add(obid);
					}
				}
			}
			catch (Exception e)
			{
				ext.raytheon.logger.RaytheonLogR.getLogger().error("Error in ApprovedChanges task", e);
			}
		}
		//remove all of the elements that failed the filter
		for(String s : removeList)
		{
			group.removeElementByUfid(s);
		}
		Enumeration elements = group.getElements();
		while(elements.hasMoreElements())
		{
			Object o = elements.nextElement();
			if(o instanceof Element)
			{
				_filter_out.addElement((Element)o);
 			}
		}
	}

	
	public void getTypes()
	{
		ArrayList<String> cnSet = getTypedDiscreteSet(CNTYPENAME, CNATTRNAME);
		ArrayList<String> mcnSet = getTypedDiscreteSet(MCNTYPENAME, MCNATTRNAME);
		ArrayList<String> cpSet = getTypedDiscreteSet(CPTYPENAME, CPATTRNAME);
		Element element = null;

		if (_mode != null && _mode.equals(ENGINEERING_MODE))
		{
			for(String s : cnSet)
			{
				element = new Element();
				element.addAtt(new Att(OBJECTTYPE, ECN));
				element.addAtt(new Att(CONSTRAINT, s));
				_subTypes.addElement(element);
			}

			for(String s : cpSet)
			{
				element = new Element();
				element.addAtt(new Att(OBJECTTYPE, ECP));
				element.addAtt(new Att(CONSTRAINT, s));
				_subTypes.addElement(element);
			}
		}
		else
		{
			for(String s : mcnSet)
			{
				element = new Element();
				element.addAtt(new Att(OBJECTTYPE, MCN));
				element.addAtt(new Att(CONSTRAINT, s));
				_subTypes.addElement(element);
			}
		}		
	}

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

SGVUtils.java

	public static QueryResult searchBE( String beType, String filter ) throws Exception {
//		System.out.println( "\n SGVUtils.searchBE beType=" + beType + "	filter=" + filter );
		if ( SERVER ) {

//			String typePrefixefix = WTProperties.getLocalProperties().getProperty( "ext.sgv.softTypes.prefix", "net.atcsg.if.za.aa5webde002.SGV" );
			String typePrefix = SGVProperties.getProperty( "ext.sgv.softTypes.prefix", "net.atcsg.if.za.aa5webde004.SGV" );
			TypeIdentifier typeId = TypeHelper.getTypeIdentifier( "WCTYPE|wt.doc.WTDocument|" + typePrefix + ".SgvBusinessEntity|" + typePrefix + "." + beType.substring( 2 ) );
//			System.out.println( "TypeIdentifier=" + typeId );
			filter = filter.replace( '*', '%' );
			if ( !filter.startsWith( "%" ) ) {
				filter = "%" + filter;
			}
			if ( !filter.endsWith( "%" ) ) {
				filter = filter + "%";
			}
			QuerySpec qs = new QuerySpec( wt.doc.WTDocument.class );
			qs.setAdvancedQueryEnabled( true );
			SearchCondition sc = wt.type.TypedUtility.getSearchCondition( typeId, true );
			if ( sc == null ) {
				System.out.println( "SGVUtils.searchBE: Non trovato il TypeIdentifier per il tipo =" + beType );
				return null;
			}
			qs.appendWhere( sc );
			qs.appendAnd();
			qs.appendSearchCondition( new SearchCondition( WTDocument.class, "master>name", SearchCondition.LIKE, filter.replace( '*', '%' ) + "%", false ) );
			qs.appendAnd();
			qs.appendWhere( new SearchCondition( WTDocument.class, Iterated.ITERATION_INFO + "." + IterationInfo.LATEST, SearchCondition.IS_TRUE ) );
			System.out.println( " search cond=" + sc.toString() );
			QueryResult qr = PersistenceHelper.manager.find( qs );
			return qr;

		} else {

			try {
				RemoteMethodServer method = RemoteMethodServer.getDefault();
//				method.setUserName(user);
//				method.setPassword(password);
				Class aclass[] = { String.class, String.class };
				Object aobj[] = { beType, filter };
				return (QueryResult) method.invoke( "searchBE", "ext.sgv.utility.SGVUtils", null, aclass, aobj );
			} catch ( InvocationTargetException invocationtargetexception ) {
				Throwable throwable = invocationtargetexception.getTargetException();
				if ( throwable instanceof WTException ) {
					throw (WTException) throwable;
				} else {
					Object aobj1[] = { "searchBE" };
					throw new WTException( throwable, "wt.fc.fcResource", "0", aobj1 );
				}
			} catch ( RemoteException remoteexception ) {
				Object aobj2[] = { "searchBE" };
				throw new WTException( remoteexception, "wt.fc.fcResource", "0", aobj2 );
			}

		}
	}	 // end-searchBE

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

ReferenceFactory rf = new ReferenceFactory();                
WTContainer container = (WTContainer)(rf.getReference("wt.pdmlink.PDMLinkProduct:XXXXX")).getObject();
WTContainerRef containerRef = WTContainerRef.newWTContainerRef(container);

WorkPackage pkg = WorkPackage.newWorkPackage();
pkg.setTypeDefinitionReference( TypedUtility.getTypeDefinitionReference(pkg.getClass().getName()+"|com.ptcts.SubPackage") );
pkg.setNumber("<NUMBER>");
pkg.setName("<NAME>");
pkg.setContextObjectReference(containerRef);
pkg.setContainerReference(containerRef);
pkg = (WorkPackage) WPHelper.service.save(pkg);

TypedUtility.getTypeDefinitionReference(pkg.getClass().getName()+"|com.ptcts.SubPackage");

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

QuerySpec qs = new QuerySpec(WCTYPE|wt.doc.WTDocument.class|<MYCUSTOM_TYPE>);

-----------------------------

TypeDefinitionReference typeDefRef = TypedUtility.getTypeDefinitionReference("<customtype>"));

qs=new QuerySpec( new SearchCondition(WTDocument.class,"typeDefinitionReference.key.id", SearchCondition.EQUAL, typeDefRef.getKey().getId()));

-----------------------------

bad:

TypeDefinitionReference typeDefRef = TypedUtility.getTypeDefinitionReference("xxx.xx.yy.AdviceAndInstruction");

QuerySpec qs = new QuerySpec(new wt.query.SearchCondition(wt.doc.WTDocument.class,"typeDefinitionReference.key.id", wt.query.SearchCondition.EQUAL, typeDefRef.getKey().getId()));

qs.setQueryLimit(10000);

-----------------------------

IdentifierFactory IDENTIFIER_FACTORY = (IdentifierFactory) DefaultServiceProvider.getService(IdentifierFactory.class, "logical");

TypeIdentifier tid = (TypeIdentifier) IDENTIFIER_FACTORY.get("xxx.xx.yy.AdviceAndInstruction");

QuerySpec qs = new QuerySpec();

int idx = qs.addClassList(WTDocument.class, true);

SearchCondition sc = TypedUtilityServiceHelper.service.getSearchCondition(tid, true);

qs.appendWhere(sc, new int[] { idx });

qs.appendAnd();

int index = 0;

qs.appendWhere(new SearchCondition(WTDocument.class,Iterated.LATEST_ITERATION, SearchCondition.IS_TRUE),

new int[] { index });

System.out.println("query3: " + qs);

QueryResult qr = PersistenceHelper.manager.find(qs);

while (qr.hasMoreElements()) {
  Persistable[] ar = (Persistable[]) qr.nextElement();
  WTDocument doc = (WTDocument) ar[idx];
  System.out.println(part
  + " - " + doc.getName() + " - "
  + TypedUtilityServiceHelper.service.getExternalTypeIdentifier(doc));
}

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

http://maheshmhetre.blogspot.com/2014/07/soft-type-how-to-get-type-definition.html

Soft Type - How to get type definition reference id 

When we want to find the list of soft type objects and with the help of QuerySpec in Windchill, we need to use soft types type definition reference id in the QuerySpec condition.

Below code snippet will be useful in writing this QuerySpec

TypeDefinitionReference typeDefRef = TypedUtility.getTypeDefinitionReference("com.maheshmhetre.epmdoc.TestEPMDocument");

if (typeDefRef != null) {
qs.appendWhere(new SearchCondition(EPMDocument.class, "typeDefinitionReference.key.id", SearchCondition.EQUAL,typeDefRef.getKey().getId()));
}

Here com.maheshmhetre.epmdoc.TestEPMDocument is the Internal Name of the soft type. This value can be retrieved from soft type details from Type and Attribute Manager.

-----------------------------

TypeDefinitionReference typeDefRef = TypedUtility.getTypeDefinitionReference("subtypename"));

sc = new SearchCondition(WTPart.class, "typeDefinitionReference.key.id", SearchCondition.EQUAL, typeDefRef.getKey().getId());

