<?xml version="1.0" standalone="yes"?>
<%@taglib uri="http://www.ptc.com/infoengine/taglib/core" prefix="ie"%>
<%@ page import="com.infoengine.object.factory.Att"%>
<%@ page import="com.infoengine.object.factory.Element"%>
<!DOCTYPE PROCESS>

<process name="get-single-object">

  <description>
    get-single-object for dcaConfig tool
  </description>

<!--switching debug on & off, degug of input groups-->
<%
	boolean VERBOSE = false;
	Group groupIn = getGroupIn();
//	groupIn.setName("jdbcPdmInput");
	if(VERBOSE){
		System.out.println("_______________in AccessPDM Query Task");
		//getContextGroup("FORM").toXML(new java.io.PrintWriter(System.out),true) ;
		getContextGroup("FORM").printTree();
		System.out.println(" AccessPDM Query Task, groupIn.getName()="+groupIn.getName());
		//groupIn.toXML(new java.io.PrintWriter(System.out),true) ;
		groupIn.printTree() ;
	}
	String thisRepository = "test";
	if(groupIn.getElementCount()>0){
		thisRepository = ext.adapter.federation.UfidHelper.getRepository( groupIn.getElementAt(0).getUfid() );
	}
%>
<%
//build where clause from ufid
String ufidIn = (String)getParam("dca_object_ref");
if(ufidIn==null) ufidIn = groupIn.getElementAt(0).getUfid();
if(ufidIn==null) return;
// ext.devtools.dca.config:search.table.2:dcaRepos.mvonhasselbach.ptc.com@dcaRepos.mvonhasselbach.ptc.com
String localId = ext.adapter.federation.UfidHelper.getShortOid(ufidIn);
int sepIdx1 = localId.indexOf(":");
String pckg = localId.substring( 0, sepIdx1);
int sepIdx2 = localId.indexOf("__");
String id = localId.substring( sepIdx1+1, sepIdx2);
String context = localId.substring( sepIdx2+2);
if(VERBOSE) System.out.println("pckg: "+pckg+" id: "+id+" context: "+context);
// (ID=&apos;*&apos;)&amp;(PACKAGE=&apos;*ext*&apos;)&amp;(TAG=&apos;Simp*&apos;)
String where = "(ID='"+id+"')&(PACKAGE='"+pckg+"')&(CONTEXT='"+context+"')";
System.out.println("where: "+where);
%>
	<ie:webject name="Query-Objects" type="OBJ">
		<ie:param name="instance"  data="${@FORM[]supporting-adapter[*]}" valueSeparator=";" delim=";" default="windchill"/>
		<ie:param name="AUTHORIZATION" data="${SERVER[]AUTHORIZATION[0]}"/>
		<ie:param name="ATTRIBUTE" data="*"/>
		<ie:param name="CLASS"   data="repository.csv"/>
		<ie:param name="WHERE"   data="<%=where%>"/>
		<ie:param name="group_out"  data="baseElem"/>
	</ie:webject>
	<%
	Element baseEl = getGroup("baseElem").getElementAt(0);
	String childTag = (String)baseEl.getValue("TAG");
	String previewable = "false";
	if( "SimpleFrame".equalsIgnoreCase( childTag) || "CompositeFrame".equalsIgnoreCase( childTag) ){ 
		baseEl.addAtt( new Att("previewable", "true"));
		baseEl.addAtt( new Att("previewLocation", baseEl.getValue("PACKAGE")+":"+baseEl.getValue("ID")));
	}
	%>
	<ie:webject name="Set-Metadata" type="GRP">
		<ie:param name="group_in"  data="baseElem"/>
		<ie:param name="SCOPE"  data="ELEMENT"/>
		<ie:param name="ELEMENT"  data="*"/>
		<ie:param name="NAME"   data="com.infoengine.object.type"/>
		<ie:param name="VALUE"  data="DCAElement"/>
		<ie:param name="NAME"   data="com.infoengine.object.id"/>
		<ie:param name="VALUE"  data="${baseElem[0]PACKAGE[]}:${baseElem[0]ID[]}__${baseElem[0]CONTEXT[]}:<%=thisRepository%>@<%=thisRepository%>"/>
		<ie:param name="NAME"   data="com.infoengine.element.id"/>
		<ie:param name="VALUE"  data="${baseElem[0]PACKAGE[]}:${baseElem[0]ID[]}__${baseElem[0]CONTEXT[]}:<%=thisRepository%>@<%=thisRepository%>"/>
	</ie:webject>
	<ie:webject name="Copy-Group" type="GRP">
		<ie:param name="GROUP_IN" data="baseElem"/>
		<ie:param name="group_out"  data="${@FORM[]group_out[]}" default="output"/>
	</ie:webject>

	<%
		//if(VERBOSE)getGroup("output").printTree() ;
	%>
</process>
