/modules/apps/headless/headless-admin-user/headless-admin-user-client/src/main/java/com/liferay/headless/admin/user/client/resource/v1_0/UserAccountResource.java
https://github.com/kiyoshilee/liferay-portal · Java · 501 lines · 350 code · 134 blank · 17 comment · 44 complexity · 953a4604d94f5826649cb491e9012149 MD5 · raw file
- /**
- * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
- *
- * This library is free software; you can redistribute it and/or modify it under
- * the terms of the GNU Lesser General Public License as published by the Free
- * Software Foundation; either version 2.1 of the License, or (at your option)
- * any later version.
- *
- * This library is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
- * details.
- */
- package com.liferay.headless.admin.user.client.resource.v1_0;
- import com.liferay.headless.admin.user.client.dto.v1_0.UserAccount;
- import com.liferay.headless.admin.user.client.http.HttpInvoker;
- import com.liferay.headless.admin.user.client.pagination.Page;
- import com.liferay.headless.admin.user.client.pagination.Pagination;
- import com.liferay.headless.admin.user.client.serdes.v1_0.UserAccountSerDes;
- import java.util.LinkedHashMap;
- import java.util.Locale;
- import java.util.Map;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- import javax.annotation.Generated;
- /**
- * @author Javier Gamarra
- * @generated
- */
- @Generated("")
- public interface UserAccountResource {
- public static Builder builder() {
- return new Builder();
- }
- public UserAccount getMyUserAccount() throws Exception;
- public HttpInvoker.HttpResponse getMyUserAccountHttpResponse()
- throws Exception;
- public Page<UserAccount> getOrganizationUserAccountsPage(
- Long organizationId, String search, String filterString,
- Pagination pagination, String sortString)
- throws Exception;
- public HttpInvoker.HttpResponse getOrganizationUserAccountsPageHttpResponse(
- Long organizationId, String search, String filterString,
- Pagination pagination, String sortString)
- throws Exception;
- public Page<UserAccount> getSiteUserAccountsPage(
- Long siteId, String search, String filterString,
- Pagination pagination, String sortString)
- throws Exception;
- public HttpInvoker.HttpResponse getSiteUserAccountsPageHttpResponse(
- Long siteId, String search, String filterString,
- Pagination pagination, String sortString)
- throws Exception;
- public Page<UserAccount> getUserAccountsPage(
- String search, String filterString, Pagination pagination,
- String sortString)
- throws Exception;
- public HttpInvoker.HttpResponse getUserAccountsPageHttpResponse(
- String search, String filterString, Pagination pagination,
- String sortString)
- throws Exception;
- public UserAccount getUserAccount(Long userAccountId) throws Exception;
- public HttpInvoker.HttpResponse getUserAccountHttpResponse(
- Long userAccountId)
- throws Exception;
- public static class Builder {
- public Builder authentication(String login, String password) {
- _login = login;
- _password = password;
- return this;
- }
- public UserAccountResource build() {
- return new UserAccountResourceImpl(this);
- }
- public Builder endpoint(String host, int port, String scheme) {
- _host = host;
- _port = port;
- _scheme = scheme;
- return this;
- }
- public Builder header(String key, String value) {
- _headers.put(key, value);
- return this;
- }
- public Builder locale(Locale locale) {
- _locale = locale;
- return this;
- }
- public Builder parameter(String key, String value) {
- _parameters.put(key, value);
- return this;
- }
- private Builder() {
- }
- private Map<String, String> _headers = new LinkedHashMap<>();
- private String _host = "localhost";
- private Locale _locale;
- private String _login = "test@liferay.com";
- private String _password = "test";
- private Map<String, String> _parameters = new LinkedHashMap<>();
- private int _port = 8080;
- private String _scheme = "http";
- }
- public static class UserAccountResourceImpl implements UserAccountResource {
- public UserAccount getMyUserAccount() throws Exception {
- HttpInvoker.HttpResponse httpResponse =
- getMyUserAccountHttpResponse();
- String content = httpResponse.getContent();
- _logger.fine("HTTP response content: " + content);
- _logger.fine("HTTP response message: " + httpResponse.getMessage());
- _logger.fine(
- "HTTP response status code: " + httpResponse.getStatusCode());
- try {
- return UserAccountSerDes.toDTO(content);
- }
- catch (Exception e) {
- _logger.log(
- Level.WARNING,
- "Unable to process HTTP response: " + content, e);
- throw e;
- }
- }
- public HttpInvoker.HttpResponse getMyUserAccountHttpResponse()
- throws Exception {
- HttpInvoker httpInvoker = HttpInvoker.newHttpInvoker();
- if (_builder._locale != null) {
- httpInvoker.header(
- "Accept-Language", _builder._locale.toLanguageTag());
- }
- for (Map.Entry<String, String> entry :
- _builder._headers.entrySet()) {
- httpInvoker.header(entry.getKey(), entry.getValue());
- }
- for (Map.Entry<String, String> entry :
- _builder._parameters.entrySet()) {
- httpInvoker.parameter(entry.getKey(), entry.getValue());
- }
- httpInvoker.httpMethod(HttpInvoker.HttpMethod.GET);
- httpInvoker.path(
- _builder._scheme + "://" + _builder._host + ":" +
- _builder._port +
- "/o/headless-admin-user/v1.0/my-user-account");
- httpInvoker.userNameAndPassword(
- _builder._login + ":" + _builder._password);
- return httpInvoker.invoke();
- }
- public Page<UserAccount> getOrganizationUserAccountsPage(
- Long organizationId, String search, String filterString,
- Pagination pagination, String sortString)
- throws Exception {
- HttpInvoker.HttpResponse httpResponse =
- getOrganizationUserAccountsPageHttpResponse(
- organizationId, search, filterString, pagination,
- sortString);
- String content = httpResponse.getContent();
- _logger.fine("HTTP response content: " + content);
- _logger.fine("HTTP response message: " + httpResponse.getMessage());
- _logger.fine(
- "HTTP response status code: " + httpResponse.getStatusCode());
- return Page.of(content, UserAccountSerDes::toDTO);
- }
- public HttpInvoker.HttpResponse
- getOrganizationUserAccountsPageHttpResponse(
- Long organizationId, String search, String filterString,
- Pagination pagination, String sortString)
- throws Exception {
- HttpInvoker httpInvoker = HttpInvoker.newHttpInvoker();
- if (_builder._locale != null) {
- httpInvoker.header(
- "Accept-Language", _builder._locale.toLanguageTag());
- }
- for (Map.Entry<String, String> entry :
- _builder._headers.entrySet()) {
- httpInvoker.header(entry.getKey(), entry.getValue());
- }
- for (Map.Entry<String, String> entry :
- _builder._parameters.entrySet()) {
- httpInvoker.parameter(entry.getKey(), entry.getValue());
- }
- httpInvoker.httpMethod(HttpInvoker.HttpMethod.GET);
- if (search != null) {
- httpInvoker.parameter("search", String.valueOf(search));
- }
- if (filterString != null) {
- httpInvoker.parameter("filter", filterString);
- }
- if (pagination != null) {
- httpInvoker.parameter(
- "page", String.valueOf(pagination.getPage()));
- httpInvoker.parameter(
- "pageSize", String.valueOf(pagination.getPageSize()));
- }
- if (sortString != null) {
- httpInvoker.parameter("sort", sortString);
- }
- httpInvoker.path(
- _builder._scheme + "://" + _builder._host + ":" +
- _builder._port +
- "/o/headless-admin-user/v1.0/organizations/{organizationId}/user-accounts",
- organizationId);
- httpInvoker.userNameAndPassword(
- _builder._login + ":" + _builder._password);
- return httpInvoker.invoke();
- }
- public Page<UserAccount> getSiteUserAccountsPage(
- Long siteId, String search, String filterString,
- Pagination pagination, String sortString)
- throws Exception {
- HttpInvoker.HttpResponse httpResponse =
- getSiteUserAccountsPageHttpResponse(
- siteId, search, filterString, pagination, sortString);
- String content = httpResponse.getContent();
- _logger.fine("HTTP response content: " + content);
- _logger.fine("HTTP response message: " + httpResponse.getMessage());
- _logger.fine(
- "HTTP response status code: " + httpResponse.getStatusCode());
- return Page.of(content, UserAccountSerDes::toDTO);
- }
- public HttpInvoker.HttpResponse getSiteUserAccountsPageHttpResponse(
- Long siteId, String search, String filterString,
- Pagination pagination, String sortString)
- throws Exception {
- HttpInvoker httpInvoker = HttpInvoker.newHttpInvoker();
- if (_builder._locale != null) {
- httpInvoker.header(
- "Accept-Language", _builder._locale.toLanguageTag());
- }
- for (Map.Entry<String, String> entry :
- _builder._headers.entrySet()) {
- httpInvoker.header(entry.getKey(), entry.getValue());
- }
- for (Map.Entry<String, String> entry :
- _builder._parameters.entrySet()) {
- httpInvoker.parameter(entry.getKey(), entry.getValue());
- }
- httpInvoker.httpMethod(HttpInvoker.HttpMethod.GET);
- if (search != null) {
- httpInvoker.parameter("search", String.valueOf(search));
- }
- if (filterString != null) {
- httpInvoker.parameter("filter", filterString);
- }
- if (pagination != null) {
- httpInvoker.parameter(
- "page", String.valueOf(pagination.getPage()));
- httpInvoker.parameter(
- "pageSize", String.valueOf(pagination.getPageSize()));
- }
- if (sortString != null) {
- httpInvoker.parameter("sort", sortString);
- }
- httpInvoker.path(
- _builder._scheme + "://" + _builder._host + ":" +
- _builder._port +
- "/o/headless-admin-user/v1.0/sites/{siteId}/user-accounts",
- siteId);
- httpInvoker.userNameAndPassword(
- _builder._login + ":" + _builder._password);
- return httpInvoker.invoke();
- }
- public Page<UserAccount> getUserAccountsPage(
- String search, String filterString, Pagination pagination,
- String sortString)
- throws Exception {
- HttpInvoker.HttpResponse httpResponse =
- getUserAccountsPageHttpResponse(
- search, filterString, pagination, sortString);
- String content = httpResponse.getContent();
- _logger.fine("HTTP response content: " + content);
- _logger.fine("HTTP response message: " + httpResponse.getMessage());
- _logger.fine(
- "HTTP response status code: " + httpResponse.getStatusCode());
- return Page.of(content, UserAccountSerDes::toDTO);
- }
- public HttpInvoker.HttpResponse getUserAccountsPageHttpResponse(
- String search, String filterString, Pagination pagination,
- String sortString)
- throws Exception {
- HttpInvoker httpInvoker = HttpInvoker.newHttpInvoker();
- if (_builder._locale != null) {
- httpInvoker.header(
- "Accept-Language", _builder._locale.toLanguageTag());
- }
- for (Map.Entry<String, String> entry :
- _builder._headers.entrySet()) {
- httpInvoker.header(entry.getKey(), entry.getValue());
- }
- for (Map.Entry<String, String> entry :
- _builder._parameters.entrySet()) {
- httpInvoker.parameter(entry.getKey(), entry.getValue());
- }
- httpInvoker.httpMethod(HttpInvoker.HttpMethod.GET);
- if (search != null) {
- httpInvoker.parameter("search", String.valueOf(search));
- }
- if (filterString != null) {
- httpInvoker.parameter("filter", filterString);
- }
- if (pagination != null) {
- httpInvoker.parameter(
- "page", String.valueOf(pagination.getPage()));
- httpInvoker.parameter(
- "pageSize", String.valueOf(pagination.getPageSize()));
- }
- if (sortString != null) {
- httpInvoker.parameter("sort", sortString);
- }
- httpInvoker.path(
- _builder._scheme + "://" + _builder._host + ":" +
- _builder._port +
- "/o/headless-admin-user/v1.0/user-accounts");
- httpInvoker.userNameAndPassword(
- _builder._login + ":" + _builder._password);
- return httpInvoker.invoke();
- }
- public UserAccount getUserAccount(Long userAccountId) throws Exception {
- HttpInvoker.HttpResponse httpResponse = getUserAccountHttpResponse(
- userAccountId);
- String content = httpResponse.getContent();
- _logger.fine("HTTP response content: " + content);
- _logger.fine("HTTP response message: " + httpResponse.getMessage());
- _logger.fine(
- "HTTP response status code: " + httpResponse.getStatusCode());
- try {
- return UserAccountSerDes.toDTO(content);
- }
- catch (Exception e) {
- _logger.log(
- Level.WARNING,
- "Unable to process HTTP response: " + content, e);
- throw e;
- }
- }
- public HttpInvoker.HttpResponse getUserAccountHttpResponse(
- Long userAccountId)
- throws Exception {
- HttpInvoker httpInvoker = HttpInvoker.newHttpInvoker();
- if (_builder._locale != null) {
- httpInvoker.header(
- "Accept-Language", _builder._locale.toLanguageTag());
- }
- for (Map.Entry<String, String> entry :
- _builder._headers.entrySet()) {
- httpInvoker.header(entry.getKey(), entry.getValue());
- }
- for (Map.Entry<String, String> entry :
- _builder._parameters.entrySet()) {
- httpInvoker.parameter(entry.getKey(), entry.getValue());
- }
- httpInvoker.httpMethod(HttpInvoker.HttpMethod.GET);
- httpInvoker.path(
- _builder._scheme + "://" + _builder._host + ":" +
- _builder._port +
- "/o/headless-admin-user/v1.0/user-accounts/{userAccountId}",
- userAccountId);
- httpInvoker.userNameAndPassword(
- _builder._login + ":" + _builder._password);
- return httpInvoker.invoke();
- }
- private UserAccountResourceImpl(Builder builder) {
- _builder = builder;
- }
- private static final Logger _logger = Logger.getLogger(
- UserAccountResource.class.getName());
- private Builder _builder;
- }
- }