[
https://issues.apache.org/jira/browse/ISIS-917?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14186689#comment-14186689
]
Vladimir Nisevic commented on ISIS-917:
---------------------------------------
Hi Dan, using the feature I've found next strange behaviour.
Given my custom representation class
{code}
package webapp;
import java.io.IOException;
import java.util.Arrays;
import javax.ws.rs.core.Response;
import a1.ase.esb.AsePublicService;
import a1.ase.viewmodel.Address;
import org.codehaus.jackson.map.ObjectMapper;
import org.apache.isis.applib.DomainObjectContainer;
import org.apache.isis.applib.annotation.ActionSemantics;
import org.apache.isis.applib.annotation.ActionSemantics.Of;
import org.apache.isis.applib.annotation.DomainService;
import org.apache.isis.applib.annotation.Named;
import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
import
org.apache.isis.viewer.restfulobjects.rendering.domainobjects.ActionResultReprRenderer;
import
org.apache.isis.viewer.restfulobjects.rendering.domainobjects.ObjectAndActionInvocation;
import
org.apache.isis.viewer.restfulobjects.rendering.service.RepresentationServiceForRestfulObjects;
@DomainService
public class AseRestCustomRepresentation extends
RepresentationServiceForRestfulObjects {
@Override
public Response actionResult(Context rendererContext,
ObjectAndActionInvocation objectAndActionInvocation,
ActionResultReprRenderer.SelfLink selfLink) {
String[] actionIds = { "retreiveAddressForLkmsId" };
if
(Arrays.asList(actionIds).contains(objectAndActionInvocation.getAction().getId()))
{
ObjectMapper objectMapper = new ObjectMapper();
try {
ObjectAdapter returnedAdapter =
objectAndActionInvocation.getReturnedAdapter();
if (returnedAdapter != null) {
String writeValueAsString =
objectMapper.writeValueAsString(returnedAdapter.getObject());
return buildResponse(Response.ok(writeValueAsString));
}
return buildResponse(Response.ok());
} catch (IOException e) {
e.printStackTrace();
}
return buildResponse(Response.serverError());
}
return super.actionResult(rendererContext, objectAndActionInvocation,
selfLink);
}
// region > injected services
@javax.inject.Inject
private DomainObjectContainer container;
@javax.inject.Inject
private AsePublicService asePublicService;
// endregion
@ActionSemantics(Of.SAFE)
public Address retreiveAddressForLkmsId(final @Named("lkmsid") String
lkmsId) {
return asePublicService.retrieveAddressForLkmsId(lkmsId, false);
}
}
{code}
When calling the method retreiveAddressForLkmsId with GET Request
http://localhost:8080/restful/services/AseRestCustomRepresentation/actions/retreiveAddressForLkmsId/invoke?lkmsid=123
Then the RO viewer shows error
{code}
{
-lkmsid: {
value: 123,
invalidReason: "is not a string"
},
x-ro-invalidReason: "'lkmsid' is mandatory"
}
{code}
When I call the method retreiveAddressForLkmsId with GET Request
http://localhost:8080/restful/services/AseRestCustomRepresentation/actions/retreiveAddressForLkmsId/invoke?lkmsid=aa
Then the RO viewer accepts aa as String parameter 'lkmsid'
> Support pluggable representations for the RO viewer (object and list
> representations)
> -------------------------------------------------------------------------------------
>
> Key: ISIS-917
> URL: https://issues.apache.org/jira/browse/ISIS-917
> Project: Isis
> Issue Type: New Feature
> Components: Core: Viewer: RestfulObjects
> Affects Versions: core-1.6.0
> Reporter: Dan Haywood
> Fix For: core-1.7.0
>
>
> This ticket is to factor out the logic in the RO viewer that builds the JSON
> representation and put it behind a @DomainService.
> As a first cut, I think it's only the object representation and list
> representations that need to be pluggable.
> Ultimately I would like to get to a point where the representation used
> honours the Accept header (Content-Type), but will probably iterate to get
> there.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)