Package org.apache.isis.viewer.json.applib

Examples of org.apache.isis.viewer.json.applib.JsonRepresentation$HasExtensions


        final RestfulResponse<DomainObjectRepresentation> restfulResponseBefore = client.followT(linkToSimpleEntity);
        final DomainObjectRepresentation simpleEntityBefore = restfulResponseBefore.getEntity();
        final Boolean before = simpleEntityBefore.getProperty("flag").getBoolean("value");

        // and given 'toggle' action on repo
        final JsonRepresentation givenAction = givenAction("simples", "toggle");
        final ObjectActionRepresentation actionRepr = givenAction.as(ObjectActionRepresentation.class);

        // when
        final LinkRepresentation invokeLink = actionRepr.getInvoke();

        // then
        assertThat(invokeLink, is(not(nullValue())));

        final JsonRepresentation args = invokeLink.getArguments();
        assertThat(args.size(), is(1));
        assertThat(args.mapHas("object"), is(true));

        // when
        args.mapPut("object", linkToSimpleEntity);
        final RestfulResponse<JsonRepresentation> restfulResponse = client.followT(invokeLink, args);

        // then
        assertThat(restfulResponse.getStatus(), is(HttpStatusCode.NO_CONTENT));
View Full Code Here


        // given simple entity with 'flag' property set to true
        final LinkRepresentation linkToSimpleEntity = givenLinkToSimpleEntity(0);

        // given
        final JsonRepresentation givenAction = givenAction("simples", "update");
        final ObjectActionRepresentation actionRepr = givenAction.as(ObjectActionRepresentation.class);

        // when
        final LinkRepresentation invokeLink = actionRepr.getInvoke();

        // then
        assertThat(invokeLink, is(not(nullValue())));

        final JsonRepresentation args = invokeLink.getArguments();
        assertThat(args.size(), is(0));
        assertThat(args.mapHas("object"), is(true));
        assertThat(args.mapHas("name"), is(true));
        assertThat(args.mapHas("flag"), is(true));
        assertThat(args.mapHas("Boolean"), is(true));
        assertThat(args.mapHas("int"), is(true));
        assertThat(args.mapHas("integer"), is(true));
        assertThat(args.mapHas("long1"), is(true));
        assertThat(args.mapHas("long2"), is(true));
        assertThat(args.mapHas("double1"), is(true));
        assertThat(args.mapHas("double2"), is(true));
        assertThat(args.mapHas("bigInteger"), is(true));
        assertThat(args.mapHas("bigDecimal"), is(true));

        // when
        args.mapPut("name", "New Name");
        args.mapPut("flag", true);
        final RestfulResponse<DomainObjectRepresentation> restfulResponse = client.followT(invokeLink, args);

        // then
        final DomainObjectRepresentation objectRepr = restfulResponse.getEntity();
View Full Code Here

        final RestfulResponse<DomainObjectRepresentation> restfulResponse = request.executeT();

        assertThat(restfulResponse.getStatus(), is(HttpStatusCode.OK));
        final DomainObjectRepresentation repr = restfulResponse.getEntity();

        final JsonRepresentation membersList = repr.getMembers();
        assertThat(membersList, isArray());

        JsonRepresentation actionRepr;

        actionRepr = membersList.getRepresentation("[id=%s]", "list");
        assertThat(actionRepr.getRepresentation("links[rel=details]"), is(not(nullValue())));
        assertThat(actionRepr.getRepresentation("links[rel=details].value"), is(not(nullValue()))); // followed

        actionRepr = membersList.getRepresentation("[id=%s]", "newTransientEntity");
        assertThat(actionRepr.getRepresentation("links[rel=details]"), is(not(nullValue())));
        assertThat(actionRepr.getRepresentation("links[rel=details].value"), is(nullValue())); // not
                                                                                               // followed
    }
View Full Code Here

        final RestfulResponse<DomainObjectRepresentation> restfulResponse = request.executeT();

        assertThat(restfulResponse.getStatus(), is(HttpStatusCode.OK));
        final DomainObjectRepresentation repr = restfulResponse.getEntity();

        final JsonRepresentation actionLinkRepr = repr.getAction(actionId);
        return actionLinkRepr.getRepresentation("links[rel=details].value");
    }
View Full Code Here

        return services.getRepresentation("values[id=%s]", serviceId).asLink().getHref();
    }

    private LinkRepresentation givenLinkToSimpleEntity(final int num) throws JsonParseException, JsonMappingException, IOException, Exception {
        // given
        final JsonRepresentation givenAction = givenAction("simples", "list");
        final ObjectActionRepresentation actionRepr = givenAction.as(ObjectActionRepresentation.class);

        // when
        final LinkRepresentation invokeLink = actionRepr.getInvoke();

        // then
View Full Code Here

        // given
        final ListRepresentation repr = givenRepresentation();

        // when
        final JsonRepresentation values = repr.getValues();

        // then
        for (final LinkRepresentation link : values.arrayIterable(LinkRepresentation.class)) {
            final RestfulResponse<JsonRepresentation> followJsonResp = client.follow(link);
            assertThat(followJsonResp.getStatus().getFamily(), is(Family.SUCCESSFUL));

            final JsonRepresentation followRepr = followJsonResp.getEntity();
            final LinkRepresentation self = followRepr.getLink("links[rel=self]");

            assertThat(self.getHref(), is(link.getHref()));
        }
    }
View Full Code Here

    public Response persist(final InputStream object) {

        init(RepresentationType.DOMAIN_OBJECT);

        final String objectStr = DomainResourceHelper.asStringUtf8(object);
        final JsonRepresentation objectRepr = DomainResourceHelper.readAsMap(objectStr);
        if (!objectRepr.isMap()) {
            throw JsonApplicationException.create(HttpStatusCode.BAD_REQUEST, "Body is not a map; got %s", objectRepr);
        }

        final LinkRepresentation describedByLink = objectRepr.getLink("links[rel=describedby]");
        if (!describedByLink.isLink()) {
            throw JsonApplicationException.create(HttpStatusCode.BAD_REQUEST, "Could not determine type of domain object to persist (no links[rel=describedby] link); got %s", objectRepr);
        }

        final String domainTypeStr = UrlParserUtils.domainTypeFrom(describedByLink);
        if (domainTypeStr == null) {
            throw JsonApplicationException.create(HttpStatusCode.BAD_REQUEST, "Could not determine type of domain object to persist (no href in links[rel=describedby]); got %s", describedByLink);
        }
        final ObjectSpecification domainTypeSpec = getSpecificationLoader().loadSpecification(domainTypeStr);
        if (domainTypeSpec == null) {
            throw JsonApplicationException.create(HttpStatusCode.BAD_REQUEST, "Could not determine type of domain object to persist (no such class '%s')", domainTypeStr);
        }

        final ObjectAdapter objectAdapter = getResourceContext().getPersistenceSession().createInstance(domainTypeSpec);

        final JsonRepresentation propertiesList = objectRepr.getArrayEnsured("members[memberType=property]");
        if (propertiesList == null) {
            throw JsonApplicationException.create(HttpStatusCode.BAD_REQUEST, "Could not find properties list (no members[memberType=property]); got %s", objectRepr);
        }
        if (!DomainResourceHelper.copyOverProperties(getResourceContext(), objectAdapter, propertiesList)) {
            throw JsonApplicationException.create(HttpStatusCode.BAD_REQUEST, objectRepr, "Illegal property value");
View Full Code Here

    public Response object(@PathParam("oid") final String oidStr, final InputStream object) {

        init(RepresentationType.DOMAIN_OBJECT);

        final String objectStr = DomainResourceHelper.asStringUtf8(object);
        final JsonRepresentation objectRepr = DomainResourceHelper.readAsMap(objectStr);
        if (!objectRepr.isMap()) {
            throw JsonApplicationException.create(HttpStatusCode.BAD_REQUEST, "Body is not a map; got %s", objectRepr);
        }

        final ObjectAdapter objectAdapter = getObjectAdapter(oidStr);

        final JsonRepresentation propertiesList = objectRepr.getArrayEnsured("members[memberType=property]");
        if (propertiesList == null) {
            throw JsonApplicationException.create(HttpStatusCode.BAD_REQUEST, "Could not find properties list (no members[memberType=property]); got %s", objectRepr);
        }

        final IsisTransactionManager transactionManager = getResourceContext().getPersistenceSession().getTransactionManager();
View Full Code Here

    @Path("/{oid}/actions/{actionId}/invoke")
    @Produces({ MediaType.APPLICATION_JSON, RestfulMediaType.APPLICATION_JSON_ACTION_RESULT, RestfulMediaType.APPLICATION_JSON_ERROR })
    public Response invokeActionQueryOnly(@PathParam("oid") final String oidStr, @PathParam("actionId") final String actionId) {
        init(RepresentationType.ACTION_RESULT);

        final JsonRepresentation arguments = getResourceContext().getQueryStringAsJsonRepr();

        final ObjectAdapter objectAdapter = getObjectAdapter(oidStr);
        final DomainResourceHelper helper = new DomainResourceHelper(getResourceContext(), objectAdapter);

        return helper.invokeActionQueryOnly(actionId, arguments);
View Full Code Here

    @Path("/{serviceId}/actions/{actionId}/invoke")
    @Produces({ MediaType.APPLICATION_JSON, RestfulMediaType.APPLICATION_JSON_ACTION_RESULT, RestfulMediaType.APPLICATION_JSON_ERROR })
    public Response invokeActionQueryOnly(@PathParam("serviceId") final String serviceId, @PathParam("actionId") final String actionId) {
        init(RepresentationType.ACTION_RESULT);

        final JsonRepresentation arguments = getResourceContext().getQueryStringAsJsonRepr();

        final ObjectAdapter serviceAdapter = getServiceAdapter(serviceId);
        final DomainResourceHelper helper = new DomainResourceHelper(getResourceContext(), serviceAdapter).using(new DomainServiceLinkTo());

        return helper.invokeActionQueryOnly(actionId, arguments);
View Full Code Here

TOP

Related Classes of org.apache.isis.viewer.json.applib.JsonRepresentation$HasExtensions

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.