Hi Ben,
- Create two classes. ShowProjectSequence and CustomPROPLFormProcessor.
package ext.datautility;
import wt.fc.PersistenceHelper;
import wt.pds.StatementSpec;
import wt.pom.POMInitException;
import wt.pom.PersistenceException;
import wt.pom.PersistentObjectManager;
import wt.preference.PreferenceHelper;
import wt.projmgmt.admin.Project2;
import wt.query.QueryException;
import wt.query.QuerySpec;
import wt.session.SessionServerHelper;
import wt.util.WTException;
import wt.util.version.WindchillVersion;
import com.ptc.core.components.descriptor.ModelContext;
import com.ptc.core.components.factory.dataUtilities.DefaultDataUtility;
import com.ptc.core.ui.resources.ComponentMode;
import com.ptc.windchill.instassm.ReleaseIdException;
public class ShowProjectSequence extends DefaultDataUtility {
/**
* Overridden method of {@link DefaultDataUtility}.
*
* @param componentId
* the Component ID.
*
* @param datum
* the object upon which this data utility will worked.
*
* @param modelContext
* the object of {@link ModelContext}.
*
* @exception WTException
* throws {@link WTException}/
*
* @return returns the object.
*/
@Override
public Object getDataValue(String componentId, Object datum,
ModelContext modelContext) throws WTException {
System.out.println("Inside data utility");
/*
* Calling the super class method.
*/
final Object obj = super.getDataValue(componentId, datum, modelContext);
/*
* The data utility only works for ComponentMode create.
*/
if (modelContext.getDescriptorMode().equals(ComponentMode.CREATE)) {
System.out.println("Returning the current sequence.");
/*
* Returning the current sequence.
*/
final String seq = getCurrentSequence();
System.out.println("Sequence Value " + seq);
return seq;
}
/*
* Returning the Object.
*/
return obj;
}
private String getCurrentSequence() throws POMInitException, ReleaseIdException, PersistenceException {
return getCurrentSequenceForTenOne();
}
private String getCurrentSequenceForTenOne() {
final boolean isCreateAccess = SessionServerHelper.manager
.isAccessEnforced();
try{
SessionServerHelper.manager.setAccessEnforced(false);
return String.format("%08d", PersistenceHelper.manager
.find((StatementSpec) new QuerySpec(Project2.class)).size());
} catch (QueryException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (WTException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
finally
{
SessionServerHelper.manager.setAccessEnforced(isCreateAccess);
}
return null;
}
}
and
package ext.test.processor;
import java.util.Iterator;
import java.util.List;
import org.apache.log4j.Logger;
import wt.fc.PersistenceHelper;
import wt.log4j.LogR;
import wt.pds.StatementSpec;
import wt.pom.POMInitException;
import wt.pom.PersistenceException;
import wt.projmgmt.admin.Project2;
import wt.query.QueryException;
import wt.query.QuerySpec;
import wt.session.SessionServerHelper;
import wt.util.WTException;
import com.ptc.core.components.beans.ObjectBean;
import com.ptc.core.components.forms.FormResult;
import com.ptc.netmarkets.project.processor.CreatePROPLProjectFormProcessor;
import com.ptc.netmarkets.util.beans.NmCommandBean;
import com.ptc.windchill.instassm.ReleaseIdException;
//ext.test.processor.CustomPROPLFormProcessor
/**
* Custom Processor for create Project.
*
* @author 'true' 12805 das.kaushik2050@gmail.com
*
* @version 'true' 1.0
*/
public class CustomPROPLFormProcessor extends
CreatePROPLProjectFormProcessor {
/**
* Private variable for Logger.
*/
private static final Logger LOG = LogR
.getLogger(CustomPROPLFormProcessor.class.getName());
/**
* Do operation of {@link CustomPROPLFormProcessor}.
*
* @param arg0
* NmCommandBean
*
* @param paramList
* list of ObjectBean
*
* @throws WTException
* throws {@link WTException}.
*
* @return corresponding {@link FormResult}.
*/
@Override
public FormResult doOperation(NmCommandBean arg0, List<ObjectBean> paramList)
throws WTException {
// FormResult result =
Project2 localProject = null;
ObjectBean objBean = null;
/*
* Fetching the Project2 from List given.
*/
for (Iterator<ObjectBean> localIterator = paramList.iterator(); localIterator
.hasNext();) {
objBean = localIterator.next();
localProject = (Project2) (objBean.getObject());
}
LOG.debug("sub-type checking");
System.out.println("Before Renumbering");
String number = String.valueOf(Integer.parseInt(getCurrentSequence())+1);
/*
* Setting the value of ProjectNumber.
*/
System.out.println(number);
localProject
.setProjectNumber(number);
LOG.debug("After renumbering");
/*
* Storing the object in ObjectBean.
*/
objBean.setObject(localProject);
/*
* Removing all the parameter of the list.
*/
for (int loop = 0; loop < paramList.size(); loop++) {
paramList.remove(loop);
}
/*
* Adding the obejct of Project2 in the List.
*/
paramList.add(objBean);
/*
* List<ObjectBean> listToGive = new ArrayList<ObjectBean>(1);
* listToGive.add(objBean);
*/
/*
* calling the Super class method.
*/
return super.doOperation(arg0, paramList);
}
private String getCurrentSequence() throws POMInitException, ReleaseIdException, PersistenceException {
return getCurrentSequenceForTenOne();
}
private String getCurrentSequenceForTenOne() {
final boolean isCreateAccess = SessionServerHelper.manager
.isAccessEnforced();
try{
SessionServerHelper.manager.setAccessEnforced(false);
/*
* Instead of QuerySpec you can use custom sequence also.
*/
return String.format("%08d", PersistenceHelper.manager
.find((StatementSpec) new QuerySpec(Project2.class)).size());
} catch (QueryException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (WTException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
finally
{
SessionServerHelper.manager.setAccessEnforced(isCreateAccess);
}
return null;
}
}
- Add Below lines in Site.xconf.
<!-- data utility --><Service context="default" name="com.ptc.core.components.descriptor.DataUtility"
targetFile="codebase/com/ptc/core/components/components.dataUtilities.properties">
<Option cardinality="singleton" order="0" overridable="true"
requestor="java.lang.Object"
selector="projectNumber"
serviceClass="ext.datautility.ShowProjectSequence"/>
</Service>
- Run xconfmanager -p to propagate.
- Add below lines in codebase/config/actions/Custom-action.xml
<objecttype class="wt.projmgmt.admin.Project2" name="project" >
<action ajax="row" name="createProplProject" resourceBundle="com.ptc.netmarkets.projmgmt.projmgmtActionsRB" >
<command class="ext.test.processor.CustomPROPLFormProcessor" method="execute" windowType="popup"/>
</action>
</objecttype>
- Restart the server.
Not sure whether PTC will support this but it's working for me.
Sorry for the long reply there is no option to attach any file.
Thanks And Regards,
Kaushik