Search in sources :

Example 1 with Documentation

use of com.liferay.apio.architect.documentation.Documentation in project com-liferay-apio-architect by liferay.

the class DocumentationMessageBodyWriter method writeTo.

@Override
public void writeTo(Documentation documentation, Class<?> aClass, Type type, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream outputStream) throws IOException, WebApplicationException {
    OutputStreamWriter outputStreamWriter = new OutputStreamWriter(outputStream, StandardCharsets.UTF_8);
    PrintWriter printWriter = new PrintWriter(outputStreamWriter, true);
    Optional<DocumentationMessageMapper> optional = _documentationMessageMapperManager.getDocumentationMessageMapperOptional(_request);
    DocumentationMessageMapper documentationMessageMapper = optional.orElseThrow(NotSupportedException::new);
    RequestInfo requestInfo = RequestInfo.create(builder -> builder.httpHeaders(_httpHeaders).httpServletRequest(_httpServletRequest).serverURL(_providerManager.provideMandatory(_httpServletRequest, ServerURL.class)).embedded(_providerManager.provideOptional(_httpServletRequest, Embedded.class).orElse(__ -> false)).fields(_providerManager.provideOptional(_httpServletRequest, Fields.class).orElse(__ -> string -> true)).language(_providerManager.provideOptional(_httpServletRequest, Language.class).orElse(Locale::getDefault)).build());
    DocumentationWriter documentationWriter = DocumentationWriter.create(builder -> builder.documentation(documentation).documentationMessageMapper(documentationMessageMapper).requestInfo(requestInfo).build());
    httpHeaders.put(CONTENT_TYPE, Collections.singletonList(documentationMessageMapper.getMediaType()));
    printWriter.println(documentationWriter.write());
    printWriter.close();
}
Also used : CONTENT_TYPE(javax.ws.rs.core.HttpHeaders.CONTENT_TYPE) Provider(javax.ws.rs.ext.Provider) RequestInfo(com.liferay.apio.architect.request.RequestInfo) Embedded(com.liferay.apio.architect.response.control.Embedded) DocumentationMessageMapperManager(com.liferay.apio.architect.wiring.osgi.manager.message.json.DocumentationMessageMapperManager) MessageBodyWriter(javax.ws.rs.ext.MessageBodyWriter) HttpServletRequest(javax.servlet.http.HttpServletRequest) MediaType(javax.ws.rs.core.MediaType) Component(org.osgi.service.component.annotations.Component) Locale(java.util.Locale) Documentation(com.liferay.apio.architect.documentation.Documentation) Fields(com.liferay.apio.architect.response.control.Fields) OutputStreamWriter(java.io.OutputStreamWriter) ProviderManager(com.liferay.apio.architect.wiring.osgi.manager.ProviderManager) NotSupportedException(javax.ws.rs.NotSupportedException) OutputStream(java.io.OutputStream) PrintWriter(java.io.PrintWriter) Context(javax.ws.rs.core.Context) DocumentationMessageMapper(com.liferay.apio.architect.message.json.DocumentationMessageMapper) ServerURL(com.liferay.apio.architect.url.ServerURL) IOException(java.io.IOException) StandardCharsets(java.nio.charset.StandardCharsets) MultivaluedMap(javax.ws.rs.core.MultivaluedMap) Language(com.liferay.apio.architect.language.Language) HttpHeaders(javax.ws.rs.core.HttpHeaders) Type(java.lang.reflect.Type) Annotation(java.lang.annotation.Annotation) Optional(java.util.Optional) WebApplicationException(javax.ws.rs.WebApplicationException) DocumentationWriter(com.liferay.apio.architect.writer.DocumentationWriter) Request(javax.ws.rs.core.Request) Reference(org.osgi.service.component.annotations.Reference) Collections(java.util.Collections) Fields(com.liferay.apio.architect.response.control.Fields) DocumentationWriter(com.liferay.apio.architect.writer.DocumentationWriter) OutputStreamWriter(java.io.OutputStreamWriter) NotSupportedException(javax.ws.rs.NotSupportedException) RequestInfo(com.liferay.apio.architect.request.RequestInfo) PrintWriter(java.io.PrintWriter) DocumentationMessageMapper(com.liferay.apio.architect.message.json.DocumentationMessageMapper)

Example 2 with Documentation

use of com.liferay.apio.architect.documentation.Documentation in project com-liferay-apio-architect by liferay.

the class RootEndpointImpl method activate.

@Activate
public void activate() {
    RequestFunction<Optional<APITitle>> apiTitleRequestFunction = httpServletRequest -> _providerManager.provideOptional(httpServletRequest, APITitle.class);
    RequestFunction<Optional<APIDescription>> apiDescriptionRequestFunction = httpServletRequest -> _providerManager.provideOptional(httpServletRequest, APIDescription.class);
    _documentation = new Documentation(apiTitleRequestFunction, apiDescriptionRequestFunction);
}
Also used : JsonObject(com.google.gson.JsonObject) CollectionRouterManager(com.liferay.apio.architect.wiring.osgi.manager.router.CollectionRouterManager) ItemRoutes(com.liferay.apio.architect.routes.ItemRoutes) ExceptionSupplierUtil.notFound(com.liferay.apio.architect.endpoint.ExceptionSupplierUtil.notFound) NestedCollectionRoutes(com.liferay.apio.architect.routes.NestedCollectionRoutes) RequestFunction(com.liferay.apio.architect.alias.RequestFunction) BinaryEndpoint(com.liferay.apio.architect.endpoint.BinaryEndpoint) HttpServletRequest(javax.servlet.http.HttpServletRequest) MediaType(javax.ws.rs.core.MediaType) Component(org.osgi.service.component.annotations.Component) NestedCollectionRouterManager(com.liferay.apio.architect.wiring.osgi.manager.router.NestedCollectionRouterManager) Documentation(com.liferay.apio.architect.documentation.Documentation) Activate(org.osgi.service.component.annotations.Activate) ProviderManager(com.liferay.apio.architect.wiring.osgi.manager.ProviderManager) SingleModel(com.liferay.apio.architect.single.model.SingleModel) ReusableNestedCollectionRouterManager(com.liferay.apio.architect.wiring.osgi.manager.router.ReusableNestedCollectionRouterManager) RootEndpoint(com.liferay.apio.architect.endpoint.RootEndpoint) Try(com.liferay.apio.architect.functional.Try) PathIdentifierMapperManager(com.liferay.apio.architect.wiring.osgi.manager.PathIdentifierMapperManager) Context(javax.ws.rs.core.Context) APIDescription(com.liferay.apio.architect.documentation.APIDescription) RepresentableManager(com.liferay.apio.architect.wiring.osgi.manager.representable.RepresentableManager) ServerURL(com.liferay.apio.architect.url.ServerURL) Path(com.liferay.apio.architect.uri.Path) APITitle(com.liferay.apio.architect.documentation.APITitle) IdentifierClassManager(com.liferay.apio.architect.wiring.osgi.manager.representable.IdentifierClassManager) List(java.util.List) Response(javax.ws.rs.core.Response) FormEndpoint(com.liferay.apio.architect.endpoint.FormEndpoint) Optional(java.util.Optional) Reference(org.osgi.service.component.annotations.Reference) ItemRouterManager(com.liferay.apio.architect.wiring.osgi.manager.router.ItemRouterManager) Optional(java.util.Optional) Documentation(com.liferay.apio.architect.documentation.Documentation) Activate(org.osgi.service.component.annotations.Activate)

Example 3 with Documentation

use of com.liferay.apio.architect.documentation.Documentation in project com-liferay-apio-architect by liferay.

the class MockDocumentationWriter method write.

/**
 * Writes a {@link Documentation} object.
 *
 * @param httpHeaders the request's HTTP headers
 * @param documentationMessageMapper the {@code DocumentationMessageMapper}
 *        to use for writing the JSON object
 */
public static JsonObject write(HttpHeaders httpHeaders, DocumentationMessageMapper documentationMessageMapper) {
    RequestInfo requestInfo = getRequestInfo(httpHeaders);
    Documentation documentation = new Documentation(__ -> Optional.of(() -> "Title"), __ -> Optional.of(() -> "Description"));
    DocumentationWriter documentationWriter = DocumentationWriter.create(builder -> builder.documentation(documentation).documentationMessageMapper(documentationMessageMapper).requestInfo(requestInfo).build());
    return new Gson().fromJson(documentationWriter.write(), JsonObject.class);
}
Also used : Documentation(com.liferay.apio.architect.documentation.Documentation) DocumentationWriter(com.liferay.apio.architect.writer.DocumentationWriter) Gson(com.google.gson.Gson) RequestInfo(com.liferay.apio.architect.request.RequestInfo) MockWriterUtil.getRequestInfo(com.liferay.apio.architect.test.util.writer.MockWriterUtil.getRequestInfo)

Aggregations

Documentation (com.liferay.apio.architect.documentation.Documentation)3 RequestInfo (com.liferay.apio.architect.request.RequestInfo)2 ServerURL (com.liferay.apio.architect.url.ServerURL)2 ProviderManager (com.liferay.apio.architect.wiring.osgi.manager.ProviderManager)2 DocumentationWriter (com.liferay.apio.architect.writer.DocumentationWriter)2 Optional (java.util.Optional)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 Context (javax.ws.rs.core.Context)2 MediaType (javax.ws.rs.core.MediaType)2 Component (org.osgi.service.component.annotations.Component)2 Reference (org.osgi.service.component.annotations.Reference)2 Gson (com.google.gson.Gson)1 JsonObject (com.google.gson.JsonObject)1 RequestFunction (com.liferay.apio.architect.alias.RequestFunction)1 APIDescription (com.liferay.apio.architect.documentation.APIDescription)1 APITitle (com.liferay.apio.architect.documentation.APITitle)1 BinaryEndpoint (com.liferay.apio.architect.endpoint.BinaryEndpoint)1 ExceptionSupplierUtil.notFound (com.liferay.apio.architect.endpoint.ExceptionSupplierUtil.notFound)1 FormEndpoint (com.liferay.apio.architect.endpoint.FormEndpoint)1 RootEndpoint (com.liferay.apio.architect.endpoint.RootEndpoint)1