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

Community Tip - Did you know you can set a signature that will be added to all your posts? Set it here! X

Custom Rest Endpoint doesnt execute

NT_10748259
10-Marble

Custom Rest Endpoint doesnt execute

I get the following error when trying to run a custom Rest Endpoint (concept : Fetch all contents for resulting items in an ECN). I cant figure out what I am doing wrong. 

Web Service Response 

 

{
  "error": {
    "code": null,
    "message": "The key value '' is invalid."
  }
}

 

MethodServer Log

 

com.ptc.odata.windchill.servlet.WcRestServlet {userID} - An unexpected REST error occured
Wrong parameter value.
	at org.apache.olingo.server.core.uri.parser.ParserHelper.parseFunctionParameters(ParserHelper.java:203)
	at org.apache.olingo.server.core.uri.parser.ResourcePathParser.functionCall(ResourcePathParser.java:388)
	at org.apache.olingo.server.core.uri.parser.ResourcePathParser.leadingResourcePathSegment(ResourcePathParser.java:229)
	at org.apache.olingo.server.core.uri.parser.ResourcePathParser.parsePathSegment(ResourcePathParser.java:88)
	at org.apache.olingo.server.core.uri.parser.Parser.parseUri(Parser.java:234)
	at org.apache.olingo.server.core.ODataHandlerImpl.processInternal(ODataHandlerImpl.java:139)
	at org.apache.olingo.server.core.ODataHandlerImpl.process(ODataHandlerImpl.java:85)
	at org.apache.olingo.server.core.ODataHttpHandlerImpl.process(ODataHttpHandlerImpl.java:74)
	at org.apache.olingo.server.core.ODataHttpHandlerImpl.process(ODataHttpHandlerImpl.java:88)
	at com.ptc.odata.windchill.entity.service.RetryableRequestMediator.process(RetryableRequestMediator.java:470)
	at com.ptc.odata.windchill.servlet.WcRestServlet.service(WcRestServlet.java:163)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:741)

 

WTHome/codebase/rest/custom/domain/ChangeMgmt/v4/import.json

 

{
   "imports":[
      {
         "name":"PTC",
         "version":"3"
      }
   ],
   "functions":[
      {
         "name":"MVIChangeNoticeContents",
         "importName":"MVIChangeNoticeContents",
         "description":"Get ECN Primary and Secondary Contents",
         "includeInServiceDocument":true,
         "parameters":[
            {
               "name":"changeOID",
               "type":"String",
               "isNullable":false,
	       "required":true
            }
          ],
         "returnType":{
            "type":"String",
            "isCollection":false
         }
      }
   ],
   "actions":[
   ]
}

 

 

WTHome/codebase/rest/custom/domain/ChangeMgmt/v4/import.js

 

function function_MVIChangeNoticeContents(data, params) {
   var MVIRESTChangeHelper = Java.type('ext.mv.odata.entity.service.MVIRESTChangeHelper');
   return MVIRESTChangeHelper.getContentsFromChangeNotice(data, params);
}

 

 

WTHome/codebase/ext/mv/odata/entity/service/MVIRESTChangeHelper.java

 

package ext.mv.odata.entity.service;

import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.Map;

import ext.mv.odata.entity.model.MVIContentHolder;
import wt.content.ContentHelper;
import wt.content.ContentHolder;
import wt.content.ContentItem;
import wt.content.ContentRoleType;
import wt.content.FormatContentHolder;
import wt.doc.WTDocument;
import wt.fc.Persistable;
import wt.fc.QueryResult;
import wt.fc.ReferenceFactory;
import wt.fc.WTReference;
import wt.util.WTException;

import com.fasterxml.jackson.databind.ObjectMapper; 
import com.fasterxml.jackson.databind.ObjectWriter;
import org.json.JSONObject;

import com.ptc.odata.core.entity.function.FunctionProcessorData;
import org.apache.olingo.commons.api.data.Parameter;


public class MVIRESTChangeHelper {
	
	// Given a Change Notice OID 
	// This code will provide a json list of all primary and secondary objects with thier doc ids
	public static String getContentsFromChangeNotice(FunctionProcessorData data, Map params) throws WTException, Exception { 

		Parameter param = (Parameter) params.get("changeOID");
		String paramvalue = null;
		if (param != null && !param.getValue().equals("")) {
			paramvalue = (String) param.getValue();	
		}	
		String changeNoticeOID = paramvalue;
		ReferenceFactory rf = new ReferenceFactory ();		
		WTReference reference= (WTReference)rf.getReference(changeNoticeOID);
		Persistable pers=(Persistable)reference.getObject();
		
		// get change notice
		wt.change2.WTChangeOrder2 changeOrder = (wt.change2.WTChangeOrder2) pers;

		// get change activities
		wt.fc.QueryResult qrChangeActivities = wt.change2.ChangeHelper2.service.getChangeActivities(changeOrder);

		List<MVIContentHolder> contents = new ArrayList<MVIContentHolder>();
		while (qrChangeActivities.hasMoreElements()) {
			wt.change2.WTChangeActivity2 ca = (wt.change2.WTChangeActivity2) qrChangeActivities.nextElement();
			
			wt.fc.QueryResult qrResultingObjects = wt.change2.ChangeHelper2.service.getChangeablesAfter(ca);
			while(qrResultingObjects.hasMoreElements()) {
				try {
					Object o = qrResultingObjects.nextElement();
					
					if (o instanceof wt.doc.WTDocument) {
						WTDocument doc = (WTDocument) o;;
						ContentHolder holder = (FormatContentHolder) ContentHelper.service.getContents((ContentHolder)doc);
						ContentItem contentPrimary = ((FormatContentHolder) holder).getPrimary();
						
						List<ContentItem> lstCI = new ArrayList<ContentItem>();
						
						QueryResult qr = ContentHelper.service.getContentsByRole(doc,ContentRoleType.SECONDARY);
						while(qr.hasMoreElements()){
						                ContentItem ci = (ContentItem)qr.nextElement();
						                lstCI.add(ci);
						}
						
						MVIContentHolder mch = new MVIContentHolder();
						mch.setDocID(doc.getDisplayIdentifier().toString());
						mch.setPrimaryContent(contentPrimary);
						mch.setSecondaryContents(lstCI);
						
						contents.add(mch);
					}
				} catch (Exception e)  {}
			}
		}
		ObjectWriter ow = new ObjectMapper().writer().withDefaultPrettyPrinter();
		String json = ow.writeValueAsString(contents);
		return json;
	}

}

 

Any ideas?

1 REPLY 1

Hi @NT_10748259 

It seams that you should provide some parameters but you provide empty one or you should provide something but you don't define it.in the request . 

PetrH

Announcements

Top Tags