cancel
Showing results for 
Search instead for 
Did you mean: 

Some questions about CAF

Former Member
0 Kudos

Hello all,

I'm new to CAF and I'm creating a first application following some how-to guides. However, I have some basic doubts which I would like to solve...

First to all, I have imported a WebService called <i>SearchEquipment</i> where its input is a Search Request (IDEquipment or EquipmentName), and its output are:

1. IDEquipment

2. EquipmentName

3. All descriptions according to all equipments that correspond with one of the both Search Request.

For instance, IDEquipment = 174* and EquipmentName= "null" and the response is:

1741, XXXX, description1

1742, XXXY, description2

Now, I want to create a new WebService with exactly the same Bussiness logic. So, my questions are:

1. According to the Entity Service: How should I create that attributes? (IDEquipment and nameEquipment are not mandatories) . In the datasource option, What's the meaning of map by minValue?.

2. According to the Application Service: I have created a new opperation in the entity service but, the input parameters in the application service are QueryFilter. I would like to parse this QueryFilter attributes to String. How works the API called

CreateStringFilter (parameters meaning) etc?

Thanks in advance!,

Marta.

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Firstly the idea of composite is not to duplicate any backend functionality but "reuse". If you already have a webservice that you can import into caf core as External service, then wrap that service to an Entity service.

1. For entity service, you can create the attributes that makes sense for your requirement. For e.g. if you create an entity service called Equipment. create 3 attributes - id, name and description. Make the id attribute as the primary key. The datasource is your external web service that you plan to use. So you'd need to map the id attribute to the min value of the webservice id (under input parameters). Also map name attribute from entity to the web service.

2. Since any operation created on Entity mimics a "SELECT" SQL query on that entity, caf implements the "WHERE" clause as a Query filter. So if you are creating a new method in Applicaton Service, you'll need to invoke the entity service method with a Query Filter i.e. QueryFilter.getQueryFilter(id). If you want to pass multiple parameters, create a Query filter for each parameter.

In your case, creating an Application Service operation is not recommended. You can directly use the findBy method on the EntityService.

Thanx,

Mahesh

Former Member
0 Kudos

Hello Mahesh,

My problem is the following one:

I have found the method "CreateStringFilter", but i don´t know the parameters input.

+public static QueryFilter createStringFilter(String action, String value, String name, boolean bAttribute)

{

QueryFilter filter = new QueryFilter();

filter.action = action;

filter.valueLow = value;

filter.attribute = name;

filter.datatype = "String";

filter.isString = true;

if(bAttribute)

filter.operation = "attribute";

else

filter.operation = "category";

return filter;

}+

I explain myself :

1º Wsdl imported like external services consists of the search of equipments of three different forms:

a) Filling up idEquipment and leaving nameEquipment empty.

b) Filling up nameEquipment and leaving idEquipment empty.

c) Filling up nameEquipment and idEquipment.

This wsdl gives back a list with the equipment found according to the given criterion.

2º Then i have created entity service which needs two input attributes. (idEquipment, nameEquipment), so that idEquipment and nameEquipment are of QueryFilter type.

3º Soon I have created aplication service with method "BuscarEquipos":

+public java.util.List BuscarEquipos(java.lang.String idEquipment, java.lang.String nameEquipment) throws com.sap.caf.rt.exception.ServiceException {

// logging

java.lang.String CAF_user = sessionContext.getCallerPrincipal().getName();

java.lang.String CAF_methodHeader = BusquedaEquiposAppBean.JARM_REQUEST + ":" + "BuscarEquipos(java.lang.String, java.lang.String)";

Object[] CAF_parameters = new Object[] {idEquipment, nameEquipment};

com.sap.caf.rt.util.CAFPublicLogger.entering(CAF_user, BusquedaEquiposAppBean.JARM_REQUEST, CAF_methodHeader, BusquedaEquiposAppBean.location, CAF_parameters);

java.util.List retValue;

try {

//@@custom code start - BuscarEquipos(java.lang.String, java.lang.String)

retValue = null;

QueryFilter idEquipmentQF = QueryFilter.createStringFilter(QueryFilter.ACTION_EXACT,idEquipment,"idEquipment",true);

idEquipmentQF.condition= "==";

QueryFilter nameEquipmentQF = QueryFilter.createStringFilter(QueryFilter.ACTION_EXACT,nameEquipment,"nameEquipment",true);

nameEquipmentQF.condition= "==";

retValue = this.getBusquedaEquiposService().buscarEquipos(nameEquipmentQF,idEquipmentQF);

//@@custom code end - BuscarEquipos(java.lang.String, java.lang.String)

return retValue;

} finally {

com.sap.caf.rt.util.CAFPublicLogger.exiting(CAF_user, BusquedaEquiposAppBean.JARM_REQUEST, CAF_methodHeader, BusquedaEquiposAppBean.location, CAF_parameters);

}

}+

4º Also I have configurated the service from Service Registry for XI.

5º The error is the following one: "com.sap.caf.rt.exception.CAFFindException".

Questions:

- What value I must give action of the QueryFilter?

- What I must make to leave idEquipment and nameEquipment without being key attributes?

Best Regards,

Marta Sánchez.

Former Member
0 Kudos

In your applicaton service method all you need to do is this:

QueryFilter idEquipmentQF = new QueryFilter(idEquipment);

QueryFilter nameEquipmentQF = new QueryFilter(nameEquipment);

retValue = this.getBusquedaEquiposService().buscarEquipos(nameEquipmentQF,idEquipmentQF); // make sure the order of the parameter is correct

You don't need to use createStringFilter() method.

Thanx,

Mahesh

Former Member
0 Kudos

Thanks a lot for your information that has been helpful, but however I have some difficulties:

- When I perform a search using the field nameEquipment, It's necessary to insert a blank space in the idEquipment field. So, The idEquipment can't be empty.

- The same for performing a search using idEquipment. nameEquipment can't be empty.

I don't know how to solve this problem using CAF or VC. However, another way to solve this problem could be to create 3 different operations in the entity service:

1. to search equipments by idEquipment.

2. to search equipments by nameEquipment.

3. to search equipments by idEquipment and nameEquipment.

By this way, the SearchEquipment method in the application service will validate both input strings: idEquipment and nameEquipment:

<i>public java.util.List BuscarEquipos(java.lang.String idEquipment, java.lang.String nameEquipment) throws com.sap.caf.rt.exception.CAFFindException, com.sap.caf.rt.exception.ServiceException {

// logging

java.lang.String CAF_user = sessionContext.getCallerPrincipal().getName();

java.lang.String CAF_methodHeader = BusquedaEquiposAppBean.JARM_REQUEST + ":" + "BuscarEquipos(java.lang.String, java.lang.String)";

Object[] CAF_parameters = new Object[] {idEquipment, nameEquipment};

com.sap.caf.rt.util.CAFPublicLogger.entering(CAF_user, BusquedaEquiposAppBean.JARM_REQUEST, CAF_methodHeader, BusquedaEquiposAppBean.location, CAF_parameters);

java.util.List retValue;

try {

//@@custom code start - BuscarEquipos(java.lang.String, java.lang.String)

retValue = null;

QueryFilter idEquipmentQF;

QueryFilter nameEquipmentQF;

//Cambiamos el valor de la entrada del idEquipment.

if (idEquipment.equals(null)|| idEquipment.equals(""))

{

idEquipment = " ";

}

//Cambiamos el valor de la entrada del nameEquipment.

if (nameEquipment.equals(null)|| nameEquipment.equals(""))

{

nameEquipment = " ";

}

//Dependiendo del caso que se de, entonces se hace una llamada a uno u otro

//metodo.

if ((idEquipment!=" ") && (nameEquipment!=" "))

{

idEquipmentQF = new QueryFilter(idEquipment, "==");

nameEquipmentQF = new QueryFilter(nameEquipment, "==");

retValue = this.getBusquedaEquipos1Service().buscarEquipos(idEquipmentQF,nameEquipmentQF);

}

if (idEquipment.equals(" "))

{

nameEquipmentQF = new QueryFilter(nameEquipment, "==");

retValue = this.getBusquedaEquipos1Service().buscarEquipoPorNombre(nameEquipmentQF);

}

if (nameEquipment.equals(" "))

{

idEquipmentQF = new QueryFilter(idEquipment, "==");

retValue = this.getBusquedaEquipos1Service().buscarEquipoPorID(idEquipmentQF);

}

//@@custom code end - BuscarEquipos(java.lang.String, java.lang.String)

return retValue;

} finally {

com.sap.caf.rt.util.CAFPublicLogger.exiting(CAF_user, BusquedaEquiposAppBean.JARM_REQUEST, CAF_methodHeader, BusquedaEquiposAppBean.location, CAF_parameters);

}

}</i>

Ejecuting this new method appears a new error:

- "ERROR. Exception thrown in method BuscarEquipos. The transaction is marked for rollback.:"

Any idea?

Thanks in advance,

Marta.

Former Member
0 Kudos

Remove the logic from App Service and put this logic in your client application:

//Cambiamos el valor de la entrada del idEquipment.

if (idEquipment.equals(null) || idEquipment.trim().equals(""))

{

idEquipment = " ";

}

//Cambiamos el valor de la entrada del nameEquipment.

if (nameEquipment.equals(null) || nameEquipment.trim().equals(""))

{

nameEquipment = " ";

}

And then make the call to the Application Service. The App Service method should just take idEquipment and nameEquipment as param and perform the logic I'd posted before.

Hope this helps.

Thanx,

Mahesh

Former Member
0 Kudos

Thanks a lot Mahesh,

Unfortunately there is not a data-return in the web Service navigator but XI returns all data correctly.

The error is the next one:

HTTP/1.1 500 Internal Server Error

Connection: close

Set-Cookie:

Any idea??

Thanks,

Marta Sánchez.

Former Member
0 Kudos

You should be able to test the Application Service method from Service browser (not via Web Navigator).

Thanx,

Mahesh

Former Member
0 Kudos

Hi,

I have the same problem.I have a web service which takes an id(number) as an input and gives a title message(LongText) corresponding to that id as an output.

I am using this ws in my entity service throw external service.In the entity service,id is declared as a key and title is declared as a normal field.Yhe mapping is like this:

entity>input>id--


external service>input-->id

entity>output>title--


external service>output-->title

I have completed all the steps of using web services as external services how to guide.https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/11669cea-0c01-0010-63b2-b98c35b1b370

Now the problem is when i am executing the method findByID,it is asking a 36 characters fixed length id.

How can i resove this problem.

plz give me some solution.

Thanks

Sampath

Former Member
0 Kudos

Hello Marta,

I found the function to createStringFilter. I hope that he serves to you.

<i>public static QueryFilter createStringFilter(String action, String value, String name, boolean bAttribute)

{

QueryFilter filter = new QueryFilter();

filter.action = action;

filter.valueLow = value;

filter.attribute = name;

filter.datatype = "String";

filter.isString = true;

if(bAttribute)

filter.operation = "attribute";

else

filter.operation = "category";

return filter;

}</i>

Best regards,

Luis Galey.