Search in sources :

Example 1 with Doc

use of io.vertigo.vega.webservice.stereotype.Doc in project vertigo by KleeGroup.

the class AnnotationsWebServiceScannerUtil method buildWebServiceDefinition.

private static Optional<WebServiceDefinition> buildWebServiceDefinition(final Method method) {
    final WebServiceDefinitionBuilder builder = WebServiceDefinition.builder(method);
    final PathPrefix pathPrefix = method.getDeclaringClass().getAnnotation(PathPrefix.class);
    if (pathPrefix != null) {
        builder.withPathPrefix(pathPrefix.value());
    }
    for (final Annotation annotation : method.getAnnotations()) {
        if (annotation instanceof GET) {
            builder.with(Verb.GET, ((GET) annotation).value());
        } else if (annotation instanceof POST) {
            builder.with(Verb.POST, ((POST) annotation).value());
        } else if (annotation instanceof PUT) {
            builder.with(Verb.PUT, ((PUT) annotation).value());
        } else if (annotation instanceof PATCH) {
            builder.with(Verb.PATCH, ((PATCH) annotation).value());
        } else if (annotation instanceof DELETE) {
            builder.with(Verb.DELETE, ((DELETE) annotation).value());
        } else if (annotation instanceof AnonymousAccessAllowed) {
            builder.withNeedAuthentication(false);
        } else if (annotation instanceof SessionLess) {
            builder.withNeedSession(false);
        } else if (annotation instanceof SessionInvalidate) {
            builder.withSessionInvalidate(true);
        } else if (annotation instanceof ExcludedFields) {
            builder.addExcludedFields(((ExcludedFields) annotation).value());
        } else if (annotation instanceof IncludedFields) {
            builder.addIncludedFields(((IncludedFields) annotation).value());
        } else if (annotation instanceof AccessTokenPublish) {
            builder.withAccessTokenPublish(true);
        } else if (annotation instanceof AccessTokenMandatory) {
            builder.withAccessTokenMandatory(true);
        } else if (annotation instanceof AccessTokenConsume) {
            builder.withAccessTokenMandatory(true);
            builder.withAccessTokenConsume(true);
        } else if (annotation instanceof ServerSideSave) {
            builder.withServerSideSave(true);
        } else if (annotation instanceof AutoSortAndPagination) {
            builder.withAutoSortAndPagination(true);
        } else if (annotation instanceof Doc) {
            builder.withDoc(((Doc) annotation).value());
        }
    }
    if (builder.hasVerb()) {
        final Type[] paramType = method.getGenericParameterTypes();
        final Annotation[][] parameterAnnotation = method.getParameterAnnotations();
        for (int i = 0; i < paramType.length; i++) {
            final WebServiceParam webServiceParam = buildWebServiceParam(parameterAnnotation[i], paramType[i]);
            builder.addWebServiceParam(webServiceParam);
        }
        // ---
        return Optional.of(builder.build());
    }
    return Optional.empty();
}
Also used : SessionLess(io.vertigo.vega.webservice.stereotype.SessionLess) IncludedFields(io.vertigo.vega.webservice.stereotype.IncludedFields) AutoSortAndPagination(io.vertigo.vega.webservice.stereotype.AutoSortAndPagination) AccessTokenMandatory(io.vertigo.vega.webservice.stereotype.AccessTokenMandatory) POST(io.vertigo.vega.webservice.stereotype.POST) ServerSideSave(io.vertigo.vega.webservice.stereotype.ServerSideSave) SessionInvalidate(io.vertigo.vega.webservice.stereotype.SessionInvalidate) Annotation(java.lang.annotation.Annotation) PUT(io.vertigo.vega.webservice.stereotype.PUT) PATCH(io.vertigo.vega.webservice.stereotype.PATCH) AccessTokenConsume(io.vertigo.vega.webservice.stereotype.AccessTokenConsume) AccessTokenPublish(io.vertigo.vega.webservice.stereotype.AccessTokenPublish) DELETE(io.vertigo.vega.webservice.stereotype.DELETE) WebServiceParamType(io.vertigo.vega.webservice.metamodel.WebServiceParam.WebServiceParamType) Type(java.lang.reflect.Type) WebServiceParam(io.vertigo.vega.webservice.metamodel.WebServiceParam) GET(io.vertigo.vega.webservice.stereotype.GET) WebServiceDefinitionBuilder(io.vertigo.vega.webservice.metamodel.WebServiceDefinitionBuilder) Doc(io.vertigo.vega.webservice.stereotype.Doc) AnonymousAccessAllowed(io.vertigo.vega.webservice.stereotype.AnonymousAccessAllowed) PathPrefix(io.vertigo.vega.webservice.stereotype.PathPrefix) ExcludedFields(io.vertigo.vega.webservice.stereotype.ExcludedFields)

Example 2 with Doc

use of io.vertigo.vega.webservice.stereotype.Doc in project vertigo by KleeGroup.

the class AdvancedTestWebServices method testInnerBody.

@Doc("Test ws returning UiContext. Send a body with an object of to field : contactId1, contactId2. Each one should be an json of long. You get partial Contacts with clientId in each one")
@ServerSideSave
@ExcludedFields({ "conId", "email", "birthday", "address", "tels" })
@POST("/uiContext")
public UiContext testInnerBody(@InnerBodyParam("contactId1") final long contactIdFrom, @InnerBodyParam("contactId2") final long contactIdTo) {
    final UiContext uiContext = new UiContext();
    uiContext.put("contactFrom", contactDao.get(contactIdFrom));
    uiContext.put("contactTo", contactDao.get(contactIdTo));
    uiContext.put("testLong", 12);
    uiContext.put("testString", "the String test");
    uiContext.put("testDate", DateUtil.newDate());
    uiContext.put("testEscapedString", "the EscapedString \",} test");
    // code 200
    return uiContext;
}
Also used : UiContext(io.vertigo.vega.engines.webservice.json.UiContext) POST(io.vertigo.vega.webservice.stereotype.POST) Doc(io.vertigo.vega.webservice.stereotype.Doc) ServerSideSave(io.vertigo.vega.webservice.stereotype.ServerSideSave) ExcludedFields(io.vertigo.vega.webservice.stereotype.ExcludedFields)

Aggregations

Doc (io.vertigo.vega.webservice.stereotype.Doc)2 ExcludedFields (io.vertigo.vega.webservice.stereotype.ExcludedFields)2 POST (io.vertigo.vega.webservice.stereotype.POST)2 ServerSideSave (io.vertigo.vega.webservice.stereotype.ServerSideSave)2 UiContext (io.vertigo.vega.engines.webservice.json.UiContext)1 WebServiceDefinitionBuilder (io.vertigo.vega.webservice.metamodel.WebServiceDefinitionBuilder)1 WebServiceParam (io.vertigo.vega.webservice.metamodel.WebServiceParam)1 WebServiceParamType (io.vertigo.vega.webservice.metamodel.WebServiceParam.WebServiceParamType)1 AccessTokenConsume (io.vertigo.vega.webservice.stereotype.AccessTokenConsume)1 AccessTokenMandatory (io.vertigo.vega.webservice.stereotype.AccessTokenMandatory)1 AccessTokenPublish (io.vertigo.vega.webservice.stereotype.AccessTokenPublish)1 AnonymousAccessAllowed (io.vertigo.vega.webservice.stereotype.AnonymousAccessAllowed)1 AutoSortAndPagination (io.vertigo.vega.webservice.stereotype.AutoSortAndPagination)1 DELETE (io.vertigo.vega.webservice.stereotype.DELETE)1 GET (io.vertigo.vega.webservice.stereotype.GET)1 IncludedFields (io.vertigo.vega.webservice.stereotype.IncludedFields)1 PATCH (io.vertigo.vega.webservice.stereotype.PATCH)1 PUT (io.vertigo.vega.webservice.stereotype.PUT)1 PathPrefix (io.vertigo.vega.webservice.stereotype.PathPrefix)1 SessionInvalidate (io.vertigo.vega.webservice.stereotype.SessionInvalidate)1