From 98c8bbf9a767dab821ef4d571e57c2d32c7ce276 Mon Sep 17 00:00:00 2001 From: Patrick Hobusch Date: Wed, 9 Jul 2025 00:00:54 +0200 Subject: [PATCH 1/3] WIP --- .../commons/constants/BootstrAPI.java | 4 +- .../commons/model/AbstractDirectoryModel.java | 3 + .../commons/model/type/_AllModelStatus.java | 33 +++++ .../rest/_AbstractAllResourceImpl.java | 24 ++++ .../commons/rest/api/_AllResource.java | 34 +++++ .../service/_AbstractAllServiceImpl.java | 59 +++++++++ .../commons/service/api/_AllService.java | 14 ++ confluence/Apis/AllApi.md | 34 +++++ confluence/Models/AbstractDirectoryModel.md | 2 +- confluence/Models/DirectoryCrowdModel.md | 2 +- confluence/Models/DirectoryDelegatingModel.md | 2 +- confluence/Models/DirectoryGenericModel.md | 2 +- confluence/Models/DirectoryInternalModel.md | 2 +- confluence/Models/DirectoryLdapModel.md | 2 +- confluence/Models/_AllModel.md | 12 ++ confluence/Models/_AllModelStatus.md | 11 ++ confluence/README.md | 3 + .../confluence/model/_AllModel.java | 33 +++++ .../confluence/rest/_AllResourceImpl.java | 28 ++++ crowd/Apis/AllApi.md | 34 +++++ crowd/Models/AbstractDirectoryModel.md | 2 +- crowd/Models/DirectoryCrowdModel.md | 2 +- crowd/Models/DirectoryDelegatingModel.md | 2 +- crowd/Models/DirectoryGenericModel.md | 2 +- crowd/Models/DirectoryInternalModel.md | 2 +- crowd/Models/DirectoryLdapModel.md | 2 +- crowd/Models/_AllModel.md | 12 ++ crowd/Models/_AllModelStatus.md | 11 ++ crowd/README.md | 3 + .../crowd/config/ServiceConfig.java | 9 ++ .../bootstrapi/crowd/model/AllModel.java | 26 ---- .../bootstrapi/crowd/model/_AllModel.java | 33 +++++ .../crowd/rest/_AllResourceImpl.java | 28 ++++ .../crowd/service/_AllServiceImpl.java | 125 ++++++++++++++++++ .../crowd/service/api/AllService.java | 10 -- .../crowd/rest/AllResourceTest.java | 64 +++++++++ .../crowd/service/DirectoriesServiceTest.java | 1 - jira/Apis/AllApi.md | 34 +++++ jira/Models/AbstractDirectoryModel.md | 2 +- jira/Models/DirectoryCrowdModel.md | 2 +- jira/Models/DirectoryDelegatingModel.md | 2 +- jira/Models/DirectoryGenericModel.md | 2 +- jira/Models/DirectoryInternalModel.md | 2 +- jira/Models/DirectoryLdapModel.md | 2 +- jira/Models/_AllModel.md | 12 ++ jira/Models/_AllModelStatus.md | 11 ++ jira/README.md | 3 + .../bootstrapi/jira/model/_AllModel.java | 34 +++++ .../jira/rest/_AllResourceImpl.java | 28 ++++ 49 files changed, 750 insertions(+), 56 deletions(-) create mode 100644 commons/src/main/java/com/deftdevs/bootstrapi/commons/model/type/_AllModelStatus.java create mode 100644 commons/src/main/java/com/deftdevs/bootstrapi/commons/rest/_AbstractAllResourceImpl.java create mode 100644 commons/src/main/java/com/deftdevs/bootstrapi/commons/rest/api/_AllResource.java create mode 100644 commons/src/main/java/com/deftdevs/bootstrapi/commons/service/_AbstractAllServiceImpl.java create mode 100644 commons/src/main/java/com/deftdevs/bootstrapi/commons/service/api/_AllService.java create mode 100644 confluence/Apis/AllApi.md create mode 100644 confluence/Models/_AllModel.md create mode 100644 confluence/Models/_AllModelStatus.md create mode 100644 confluence/src/main/java/com/deftdevs/bootstrapi/confluence/model/_AllModel.java create mode 100644 confluence/src/main/java/com/deftdevs/bootstrapi/confluence/rest/_AllResourceImpl.java create mode 100644 crowd/Apis/AllApi.md create mode 100644 crowd/Models/_AllModel.md create mode 100644 crowd/Models/_AllModelStatus.md delete mode 100644 crowd/src/main/java/com/deftdevs/bootstrapi/crowd/model/AllModel.java create mode 100644 crowd/src/main/java/com/deftdevs/bootstrapi/crowd/model/_AllModel.java create mode 100644 crowd/src/main/java/com/deftdevs/bootstrapi/crowd/rest/_AllResourceImpl.java create mode 100644 crowd/src/main/java/com/deftdevs/bootstrapi/crowd/service/_AllServiceImpl.java delete mode 100644 crowd/src/main/java/com/deftdevs/bootstrapi/crowd/service/api/AllService.java create mode 100644 crowd/src/test/java/com/deftdevs/bootstrapi/crowd/rest/AllResourceTest.java create mode 100644 jira/Apis/AllApi.md create mode 100644 jira/Models/_AllModel.md create mode 100644 jira/Models/_AllModelStatus.md create mode 100644 jira/src/main/java/com/deftdevs/bootstrapi/jira/model/_AllModel.java create mode 100644 jira/src/main/java/com/deftdevs/bootstrapi/jira/rest/_AllResourceImpl.java diff --git a/commons/src/main/java/com/deftdevs/bootstrapi/commons/constants/BootstrAPI.java b/commons/src/main/java/com/deftdevs/bootstrapi/commons/constants/BootstrAPI.java index 644ae427..0578727b 100644 --- a/commons/src/main/java/com/deftdevs/bootstrapi/commons/constants/BootstrAPI.java +++ b/commons/src/main/java/com/deftdevs/bootstrapi/commons/constants/BootstrAPI.java @@ -2,7 +2,9 @@ public class BootstrAPI { - public static final String ALL = "all"; + public static final String _ALL = "_all"; + public static final String _ROOT = "/"; + public static final String APPLICATION = "application"; public static final String APPLICATIONS = "applications"; public static final String APPLICATION_LINK = "application-link"; diff --git a/commons/src/main/java/com/deftdevs/bootstrapi/commons/model/AbstractDirectoryModel.java b/commons/src/main/java/com/deftdevs/bootstrapi/commons/model/AbstractDirectoryModel.java index 19e534a4..a9050606 100644 --- a/commons/src/main/java/com/deftdevs/bootstrapi/commons/model/AbstractDirectoryModel.java +++ b/commons/src/main/java/com/deftdevs/bootstrapi/commons/model/AbstractDirectoryModel.java @@ -61,4 +61,7 @@ public abstract class AbstractDirectoryModel { @XmlElement private Date updatedDate; + @XmlElement + private Boolean testConnection; + } diff --git a/commons/src/main/java/com/deftdevs/bootstrapi/commons/model/type/_AllModelStatus.java b/commons/src/main/java/com/deftdevs/bootstrapi/commons/model/type/_AllModelStatus.java new file mode 100644 index 00000000..8dfcc8f0 --- /dev/null +++ b/commons/src/main/java/com/deftdevs/bootstrapi/commons/model/type/_AllModelStatus.java @@ -0,0 +1,33 @@ +package com.deftdevs.bootstrapi.commons.model.type; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import javax.ws.rs.core.Response; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + +@Data +@NoArgsConstructor +@AllArgsConstructor +@XmlRootElement(name = "status") +public class _AllModelStatus { + + @XmlElement + private int status; + + @XmlElement + private String message; + + @XmlElement + private String details; + + public static _AllModelStatus success() { + return new _AllModelStatus(Response.Status.OK.getStatusCode(), "Success", null); + } + + public static _AllModelStatus error(Response.Status status, String message, String details) { + return new _AllModelStatus(status.getStatusCode(), message, details); + } +} diff --git a/commons/src/main/java/com/deftdevs/bootstrapi/commons/rest/_AbstractAllResourceImpl.java b/commons/src/main/java/com/deftdevs/bootstrapi/commons/rest/_AbstractAllResourceImpl.java new file mode 100644 index 00000000..c1b6d948 --- /dev/null +++ b/commons/src/main/java/com/deftdevs/bootstrapi/commons/rest/_AbstractAllResourceImpl.java @@ -0,0 +1,24 @@ +package com.deftdevs.bootstrapi.commons.rest; + +import com.deftdevs.bootstrapi.commons.rest.api._AllResource; +import com.deftdevs.bootstrapi.commons.service.api._AllService; + +import javax.ws.rs.core.Response; + +public abstract class _AbstractAllResourceImpl<_AllModel> + implements _AllResource<_AllModel> { + + private final _AllService<_AllModel> allService; + + public _AbstractAllResourceImpl( + final _AllService<_AllModel> allService) { + + this.allService = allService; + } + + public Response setAll( + final _AllModel allModel) { + + return Response.ok(allService.setAll(allModel)).build(); + } +} diff --git a/commons/src/main/java/com/deftdevs/bootstrapi/commons/rest/api/_AllResource.java b/commons/src/main/java/com/deftdevs/bootstrapi/commons/rest/api/_AllResource.java new file mode 100644 index 00000000..7b548d35 --- /dev/null +++ b/commons/src/main/java/com/deftdevs/bootstrapi/commons/rest/api/_AllResource.java @@ -0,0 +1,34 @@ +package com.deftdevs.bootstrapi.commons.rest.api; + +import com.deftdevs.bootstrapi.commons.constants.BootstrAPI; +import com.deftdevs.bootstrapi.commons.model.ErrorCollection; +import com.deftdevs.bootstrapi.commons.model.SettingsModel; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; + +import javax.validation.constraints.NotNull; +import javax.ws.rs.PUT; +import javax.ws.rs.core.Response; + +public interface _AllResource<_AllModel> { + + @PUT + @Operation( + summary = BootstrAPI._ALL, + responses = { + @ApiResponse( + responseCode = "200", content = @Content(schema = @Schema(implementation = SettingsModel.class)), + description = BootstrAPI._ALL + ), + @ApiResponse( + responseCode = "default", content = @Content(schema = @Schema(implementation = ErrorCollection.class)), + description = BootstrAPI._ALL + ), + } + ) + Response setAll( + @NotNull final _AllModel bean); + +} diff --git a/commons/src/main/java/com/deftdevs/bootstrapi/commons/service/_AbstractAllServiceImpl.java b/commons/src/main/java/com/deftdevs/bootstrapi/commons/service/_AbstractAllServiceImpl.java new file mode 100644 index 00000000..da63c299 --- /dev/null +++ b/commons/src/main/java/com/deftdevs/bootstrapi/commons/service/_AbstractAllServiceImpl.java @@ -0,0 +1,59 @@ +package com.deftdevs.bootstrapi.commons.service; + +import com.deftdevs.bootstrapi.commons.model.type._AllModelStatus; +import com.deftdevs.bootstrapi.commons.service.api._AllService; + +import javax.ws.rs.core.Response; +import java.util.Map; +import java.util.function.Consumer; +import java.util.function.Function; + +public abstract class _AbstractAllServiceImpl<_A> implements _AllService<_A> { + + protected _AllModelStatus setEntity( + final T entity, + final Function updateFunction, + final Consumer resultConsumer) { + + if (entity == null) { + return null; + } + + try { + final T updatedEntity = updateFunction.apply(entity); + resultConsumer.accept(updatedEntity); + return _AllModelStatus.success(); + } catch (Exception e) { + return _AllModelStatus.error( + Response.Status.INTERNAL_SERVER_ERROR, + "Failed to apply ...", + e.getMessage() + ); + } + } + + @SuppressWarnings("unchecked") + protected _AllModelStatus setEntities( + final Map entityMap, + final Function getIdentifier, + final Function, Map> updateFunction, + final Consumer> resultConsumer) { + + if (entityMap == null || entityMap.isEmpty()) { + return null; + } + + try { + final Map updatedEntities = updateFunction.apply(entityMap); + resultConsumer.accept((Map) updatedEntities); + return _AllModelStatus.success(); + } catch (Exception e) { + return _AllModelStatus.error( + Response.Status.INTERNAL_SERVER_ERROR, + "Failed to apply ...", + e.getMessage() + ); + } + } + +} diff --git a/commons/src/main/java/com/deftdevs/bootstrapi/commons/service/api/_AllService.java b/commons/src/main/java/com/deftdevs/bootstrapi/commons/service/api/_AllService.java new file mode 100644 index 00000000..61adc85f --- /dev/null +++ b/commons/src/main/java/com/deftdevs/bootstrapi/commons/service/api/_AllService.java @@ -0,0 +1,14 @@ +package com.deftdevs.bootstrapi.commons.service.api; + +public interface _AllService<_AllModel> { + + /** + * Apply a complete configuration. + * + * @param allModel the configuration to apply + * @return the updated configuration with status + */ + _AllModel setAll( + _AllModel allModel); + +} diff --git a/confluence/Apis/AllApi.md b/confluence/Apis/AllApi.md new file mode 100644 index 00000000..99f0bab6 --- /dev/null +++ b/confluence/Apis/AllApi.md @@ -0,0 +1,34 @@ +# AllApi + +All URIs are relative to *https://CONFLUENCE_URL/rest/bootstrapi/1* + +| Method | HTTP request | Description | +|------------- | ------------- | -------------| +| [**setAll**](AllApi.md#setAll) | **PUT** / | _all | + + + +# **setAll** +> SettingsModel setAll(\_AllModel) + +_all + +### Parameters + +|Name | Type | Description | Notes | +|------------- | ------------- | ------------- | -------------| +| **\_AllModel** | [**_AllModel**](../Models/_AllModel.md)| | | + +### Return type + +[**SettingsModel**](../Models/SettingsModel.md) + +### Authorization + +[basicAuth](../README.md#basicAuth) + +### HTTP request headers + +- **Content-Type**: application/json +- **Accept**: application/json + diff --git a/confluence/Models/AbstractDirectoryModel.md b/confluence/Models/AbstractDirectoryModel.md index 7ef166ee..cde79f6a 100644 --- a/confluence/Models/AbstractDirectoryModel.md +++ b/confluence/Models/AbstractDirectoryModel.md @@ -9,8 +9,8 @@ | **active** | **Boolean** | | [optional] [default to null] | | **createdDate** | **Date** | | [optional] [default to null] | | **updatedDate** | **Date** | | [optional] [default to null] | -| **type** | **String** | | [default to null] | | **testConnection** | **Boolean** | | [optional] [default to null] | +| **type** | **String** | | [default to null] | | **connector** | [**DirectoryDelegatingConnector**](DirectoryDelegatingConnector.md) | | [optional] [default to null] | | **configuration** | [**DirectoryDelegatingConfiguration**](DirectoryDelegatingConfiguration.md) | | [optional] [default to null] | | **permissions** | [**DirectoryLdapPermissions**](DirectoryLdapPermissions.md) | | [optional] [default to null] | diff --git a/confluence/Models/DirectoryCrowdModel.md b/confluence/Models/DirectoryCrowdModel.md index 655455e4..d58a9ad3 100644 --- a/confluence/Models/DirectoryCrowdModel.md +++ b/confluence/Models/DirectoryCrowdModel.md @@ -9,8 +9,8 @@ | **active** | **Boolean** | | [optional] [default to null] | | **createdDate** | **Date** | | [optional] [default to null] | | **updatedDate** | **Date** | | [optional] [default to null] | -| **type** | **String** | | [default to null] | | **testConnection** | **Boolean** | | [optional] [default to null] | +| **type** | **String** | | [default to null] | | **server** | [**DirectoryCrowdServer**](DirectoryCrowdServer.md) | | [optional] [default to null] | | **permissions** | [**DirectoryCrowdPermissions**](DirectoryCrowdPermissions.md) | | [optional] [default to null] | | **advanced** | [**DirectoryCrowdAdvanced**](DirectoryCrowdAdvanced.md) | | [optional] [default to null] | diff --git a/confluence/Models/DirectoryDelegatingModel.md b/confluence/Models/DirectoryDelegatingModel.md index 241e45d1..01c3480b 100644 --- a/confluence/Models/DirectoryDelegatingModel.md +++ b/confluence/Models/DirectoryDelegatingModel.md @@ -9,8 +9,8 @@ | **active** | **Boolean** | | [optional] [default to null] | | **createdDate** | **Date** | | [optional] [default to null] | | **updatedDate** | **Date** | | [optional] [default to null] | -| **type** | **String** | | [default to null] | | **testConnection** | **Boolean** | | [optional] [default to null] | +| **type** | **String** | | [default to null] | | **server** | [**DirectoryLdapServer**](DirectoryLdapServer.md) | | [optional] [default to null] | | **permissions** | [**DirectoryPermissions**](DirectoryPermissions.md) | | [optional] [default to null] | | **advanced** | [**DirectoryInternalAdvanced**](DirectoryInternalAdvanced.md) | | [optional] [default to null] | diff --git a/confluence/Models/DirectoryGenericModel.md b/confluence/Models/DirectoryGenericModel.md index ec59bab6..71c67548 100644 --- a/confluence/Models/DirectoryGenericModel.md +++ b/confluence/Models/DirectoryGenericModel.md @@ -9,8 +9,8 @@ | **active** | **Boolean** | | [optional] [default to null] | | **createdDate** | **Date** | | [optional] [default to null] | | **updatedDate** | **Date** | | [optional] [default to null] | -| **type** | **String** | | [default to null] | | **testConnection** | **Boolean** | | [optional] [default to null] | +| **type** | **String** | | [default to null] | | **server** | [**DirectoryLdapServer**](DirectoryLdapServer.md) | | [optional] [default to null] | | **permissions** | [**DirectoryLdapPermissions**](DirectoryLdapPermissions.md) | | [optional] [default to null] | | **advanced** | [**DirectoryInternalAdvanced**](DirectoryInternalAdvanced.md) | | [optional] [default to null] | diff --git a/confluence/Models/DirectoryInternalModel.md b/confluence/Models/DirectoryInternalModel.md index 472b0c05..2ccbe759 100644 --- a/confluence/Models/DirectoryInternalModel.md +++ b/confluence/Models/DirectoryInternalModel.md @@ -9,8 +9,8 @@ | **active** | **Boolean** | | [optional] [default to null] | | **createdDate** | **Date** | | [optional] [default to null] | | **updatedDate** | **Date** | | [optional] [default to null] | -| **type** | **String** | | [default to null] | | **testConnection** | **Boolean** | | [optional] [default to null] | +| **type** | **String** | | [default to null] | | **server** | [**DirectoryLdapServer**](DirectoryLdapServer.md) | | [optional] [default to null] | | **permissions** | [**DirectoryPermissions**](DirectoryPermissions.md) | | [optional] [default to null] | | **advanced** | [**DirectoryInternalAdvanced**](DirectoryInternalAdvanced.md) | | [optional] [default to null] | diff --git a/confluence/Models/DirectoryLdapModel.md b/confluence/Models/DirectoryLdapModel.md index c5c48bfe..97eb576e 100644 --- a/confluence/Models/DirectoryLdapModel.md +++ b/confluence/Models/DirectoryLdapModel.md @@ -9,8 +9,8 @@ | **active** | **Boolean** | | [optional] [default to null] | | **createdDate** | **Date** | | [optional] [default to null] | | **updatedDate** | **Date** | | [optional] [default to null] | -| **type** | **String** | | [default to null] | | **testConnection** | **Boolean** | | [optional] [default to null] | +| **type** | **String** | | [default to null] | | **server** | [**DirectoryLdapServer**](DirectoryLdapServer.md) | | [optional] [default to null] | | **permissions** | [**DirectoryLdapPermissions**](DirectoryLdapPermissions.md) | | [optional] [default to null] | | **advanced** | [**DirectoryInternalAdvanced**](DirectoryInternalAdvanced.md) | | [optional] [default to null] | diff --git a/confluence/Models/_AllModel.md b/confluence/Models/_AllModel.md new file mode 100644 index 00000000..34153397 --- /dev/null +++ b/confluence/Models/_AllModel.md @@ -0,0 +1,12 @@ +# _AllModel +## Properties + +| Name | Type | Description | Notes | +|------------ | ------------- | ------------- | -------------| +| **settings** | [**SettingsModel**](SettingsModel.md) | | [optional] [default to null] | +| **users** | [**Map**](UserModel.md) | | [optional] [default to null] | +| **groups** | [**Map**](GroupModel.md) | | [optional] [default to null] | +| **status** | [**Map**](_AllModelStatus.md) | | [optional] [default to null] | + +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) + diff --git a/confluence/Models/_AllModelStatus.md b/confluence/Models/_AllModelStatus.md new file mode 100644 index 00000000..ed699765 --- /dev/null +++ b/confluence/Models/_AllModelStatus.md @@ -0,0 +1,11 @@ +# _AllModelStatus +## Properties + +| Name | Type | Description | Notes | +|------------ | ------------- | ------------- | -------------| +| **status** | **Integer** | | [optional] [default to null] | +| **message** | **String** | | [optional] [default to null] | +| **details** | **String** | | [optional] [default to null] | + +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) + diff --git a/confluence/README.md b/confluence/README.md index fe3bab2e..2b15d90f 100644 --- a/confluence/README.md +++ b/confluence/README.md @@ -7,6 +7,7 @@ All URIs are relative to *https://CONFLUENCE_URL/rest/bootstrapi/1* | Class | Method | HTTP request | Description | |------------ | ------------- | ------------- | -------------| +| *AllApi* | [**setAll**](Apis/AllApi.md#setAll) | **PUT** / | _all | | *ApplicationLinkApi* | [**createApplicationLink**](Apis/ApplicationLinkApi.md#createApplicationLink) | **POST** /application-link | Create an application link | *ApplicationLinkApi* | [**deleteApplicationLink**](Apis/ApplicationLinkApi.md#deleteApplicationLink) | **DELETE** /application-link/{uuid} | Delete an application link | *ApplicationLinkApi* | [**getApplicationLink**](Apis/ApplicationLinkApi.md#getApplicationLink) | **GET** /application-link/{uuid} | Get an application link | @@ -94,6 +95,8 @@ All URIs are relative to *https://CONFLUENCE_URL/rest/bootstrapi/1* - [SettingsModel](./Models/SettingsModel.md) - [SettingsSecurityModel](./Models/SettingsSecurityModel.md) - [UserModel](./Models/UserModel.md) + - [_AllModel](./Models/_AllModel.md) + - [_AllModelStatus](./Models/_AllModelStatus.md) diff --git a/confluence/src/main/java/com/deftdevs/bootstrapi/confluence/model/_AllModel.java b/confluence/src/main/java/com/deftdevs/bootstrapi/confluence/model/_AllModel.java new file mode 100644 index 00000000..60641c97 --- /dev/null +++ b/confluence/src/main/java/com/deftdevs/bootstrapi/confluence/model/_AllModel.java @@ -0,0 +1,33 @@ +package com.deftdevs.bootstrapi.confluence.model; + +import com.deftdevs.bootstrapi.commons.model.GroupModel; +import com.deftdevs.bootstrapi.commons.model.SettingsModel; +import com.deftdevs.bootstrapi.commons.model.UserModel; +import com.deftdevs.bootstrapi.commons.model.type._AllModelStatus; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; +import java.util.Map; + +@Data +@NoArgsConstructor +@AllArgsConstructor +@XmlRootElement(name = "all") +public class _AllModel { + + @XmlElement + private SettingsModel settings; + + @XmlElement + private Map users; + + @XmlElement + private Map groups; + + @XmlElement + private Map status; + +} diff --git a/confluence/src/main/java/com/deftdevs/bootstrapi/confluence/rest/_AllResourceImpl.java b/confluence/src/main/java/com/deftdevs/bootstrapi/confluence/rest/_AllResourceImpl.java new file mode 100644 index 00000000..8ba18e21 --- /dev/null +++ b/confluence/src/main/java/com/deftdevs/bootstrapi/confluence/rest/_AllResourceImpl.java @@ -0,0 +1,28 @@ +package com.deftdevs.bootstrapi.confluence.rest; + +import com.atlassian.plugins.rest.api.security.annotation.SystemAdminOnly; +import com.deftdevs.bootstrapi.commons.constants.BootstrAPI; +import com.deftdevs.bootstrapi.commons.rest._AbstractAllResourceImpl; +import com.deftdevs.bootstrapi.commons.service.api._AllService; +import com.deftdevs.bootstrapi.confluence.model._AllModel; +import io.swagger.v3.oas.annotations.tags.Tag; + +import javax.ws.rs.Consumes; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; + +@Path(BootstrAPI._ROOT) +@Tag(name = BootstrAPI._ALL) +@Consumes(MediaType.APPLICATION_JSON) +@Produces(MediaType.APPLICATION_JSON) +@SystemAdminOnly +public class _AllResourceImpl extends _AbstractAllResourceImpl<_AllModel> { + + public _AllResourceImpl( + final _AllService<_AllModel> allService) { + + super(allService); + } + +} diff --git a/crowd/Apis/AllApi.md b/crowd/Apis/AllApi.md new file mode 100644 index 00000000..e5c536e4 --- /dev/null +++ b/crowd/Apis/AllApi.md @@ -0,0 +1,34 @@ +# AllApi + +All URIs are relative to *https://CROWD_URL/rest/bootstrapi/1* + +| Method | HTTP request | Description | +|------------- | ------------- | -------------| +| [**setAll**](AllApi.md#setAll) | **PUT** / | _all | + + + +# **setAll** +> SettingsModel setAll(\_AllModel) + +_all + +### Parameters + +|Name | Type | Description | Notes | +|------------- | ------------- | ------------- | -------------| +| **\_AllModel** | [**_AllModel**](../Models/_AllModel.md)| | | + +### Return type + +[**SettingsModel**](../Models/SettingsModel.md) + +### Authorization + +[basicAuth](../README.md#basicAuth) + +### HTTP request headers + +- **Content-Type**: application/json +- **Accept**: application/json + diff --git a/crowd/Models/AbstractDirectoryModel.md b/crowd/Models/AbstractDirectoryModel.md index 7ef166ee..cde79f6a 100644 --- a/crowd/Models/AbstractDirectoryModel.md +++ b/crowd/Models/AbstractDirectoryModel.md @@ -9,8 +9,8 @@ | **active** | **Boolean** | | [optional] [default to null] | | **createdDate** | **Date** | | [optional] [default to null] | | **updatedDate** | **Date** | | [optional] [default to null] | -| **type** | **String** | | [default to null] | | **testConnection** | **Boolean** | | [optional] [default to null] | +| **type** | **String** | | [default to null] | | **connector** | [**DirectoryDelegatingConnector**](DirectoryDelegatingConnector.md) | | [optional] [default to null] | | **configuration** | [**DirectoryDelegatingConfiguration**](DirectoryDelegatingConfiguration.md) | | [optional] [default to null] | | **permissions** | [**DirectoryLdapPermissions**](DirectoryLdapPermissions.md) | | [optional] [default to null] | diff --git a/crowd/Models/DirectoryCrowdModel.md b/crowd/Models/DirectoryCrowdModel.md index 655455e4..d58a9ad3 100644 --- a/crowd/Models/DirectoryCrowdModel.md +++ b/crowd/Models/DirectoryCrowdModel.md @@ -9,8 +9,8 @@ | **active** | **Boolean** | | [optional] [default to null] | | **createdDate** | **Date** | | [optional] [default to null] | | **updatedDate** | **Date** | | [optional] [default to null] | -| **type** | **String** | | [default to null] | | **testConnection** | **Boolean** | | [optional] [default to null] | +| **type** | **String** | | [default to null] | | **server** | [**DirectoryCrowdServer**](DirectoryCrowdServer.md) | | [optional] [default to null] | | **permissions** | [**DirectoryCrowdPermissions**](DirectoryCrowdPermissions.md) | | [optional] [default to null] | | **advanced** | [**DirectoryCrowdAdvanced**](DirectoryCrowdAdvanced.md) | | [optional] [default to null] | diff --git a/crowd/Models/DirectoryDelegatingModel.md b/crowd/Models/DirectoryDelegatingModel.md index 241e45d1..01c3480b 100644 --- a/crowd/Models/DirectoryDelegatingModel.md +++ b/crowd/Models/DirectoryDelegatingModel.md @@ -9,8 +9,8 @@ | **active** | **Boolean** | | [optional] [default to null] | | **createdDate** | **Date** | | [optional] [default to null] | | **updatedDate** | **Date** | | [optional] [default to null] | -| **type** | **String** | | [default to null] | | **testConnection** | **Boolean** | | [optional] [default to null] | +| **type** | **String** | | [default to null] | | **server** | [**DirectoryLdapServer**](DirectoryLdapServer.md) | | [optional] [default to null] | | **permissions** | [**DirectoryPermissions**](DirectoryPermissions.md) | | [optional] [default to null] | | **advanced** | [**DirectoryInternalAdvanced**](DirectoryInternalAdvanced.md) | | [optional] [default to null] | diff --git a/crowd/Models/DirectoryGenericModel.md b/crowd/Models/DirectoryGenericModel.md index ec59bab6..71c67548 100644 --- a/crowd/Models/DirectoryGenericModel.md +++ b/crowd/Models/DirectoryGenericModel.md @@ -9,8 +9,8 @@ | **active** | **Boolean** | | [optional] [default to null] | | **createdDate** | **Date** | | [optional] [default to null] | | **updatedDate** | **Date** | | [optional] [default to null] | -| **type** | **String** | | [default to null] | | **testConnection** | **Boolean** | | [optional] [default to null] | +| **type** | **String** | | [default to null] | | **server** | [**DirectoryLdapServer**](DirectoryLdapServer.md) | | [optional] [default to null] | | **permissions** | [**DirectoryLdapPermissions**](DirectoryLdapPermissions.md) | | [optional] [default to null] | | **advanced** | [**DirectoryInternalAdvanced**](DirectoryInternalAdvanced.md) | | [optional] [default to null] | diff --git a/crowd/Models/DirectoryInternalModel.md b/crowd/Models/DirectoryInternalModel.md index 472b0c05..2ccbe759 100644 --- a/crowd/Models/DirectoryInternalModel.md +++ b/crowd/Models/DirectoryInternalModel.md @@ -9,8 +9,8 @@ | **active** | **Boolean** | | [optional] [default to null] | | **createdDate** | **Date** | | [optional] [default to null] | | **updatedDate** | **Date** | | [optional] [default to null] | -| **type** | **String** | | [default to null] | | **testConnection** | **Boolean** | | [optional] [default to null] | +| **type** | **String** | | [default to null] | | **server** | [**DirectoryLdapServer**](DirectoryLdapServer.md) | | [optional] [default to null] | | **permissions** | [**DirectoryPermissions**](DirectoryPermissions.md) | | [optional] [default to null] | | **advanced** | [**DirectoryInternalAdvanced**](DirectoryInternalAdvanced.md) | | [optional] [default to null] | diff --git a/crowd/Models/DirectoryLdapModel.md b/crowd/Models/DirectoryLdapModel.md index c5c48bfe..97eb576e 100644 --- a/crowd/Models/DirectoryLdapModel.md +++ b/crowd/Models/DirectoryLdapModel.md @@ -9,8 +9,8 @@ | **active** | **Boolean** | | [optional] [default to null] | | **createdDate** | **Date** | | [optional] [default to null] | | **updatedDate** | **Date** | | [optional] [default to null] | -| **type** | **String** | | [default to null] | | **testConnection** | **Boolean** | | [optional] [default to null] | +| **type** | **String** | | [default to null] | | **server** | [**DirectoryLdapServer**](DirectoryLdapServer.md) | | [optional] [default to null] | | **permissions** | [**DirectoryLdapPermissions**](DirectoryLdapPermissions.md) | | [optional] [default to null] | | **advanced** | [**DirectoryInternalAdvanced**](DirectoryInternalAdvanced.md) | | [optional] [default to null] | diff --git a/crowd/Models/_AllModel.md b/crowd/Models/_AllModel.md new file mode 100644 index 00000000..c7e7c5d1 --- /dev/null +++ b/crowd/Models/_AllModel.md @@ -0,0 +1,12 @@ +# _AllModel +## Properties + +| Name | Type | Description | Notes | +|------------ | ------------- | ------------- | -------------| +| **settings** | [**SettingsModel**](SettingsModel.md) | | [optional] [default to null] | +| **applications** | [**Map**](ApplicationModel.md) | | [optional] [default to null] | +| **directories** | [**Map**](AbstractDirectoryModel.md) | | [optional] [default to null] | +| **status** | [**Map**](_AllModelStatus.md) | | [optional] [default to null] | + +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) + diff --git a/crowd/Models/_AllModelStatus.md b/crowd/Models/_AllModelStatus.md new file mode 100644 index 00000000..ed699765 --- /dev/null +++ b/crowd/Models/_AllModelStatus.md @@ -0,0 +1,11 @@ +# _AllModelStatus +## Properties + +| Name | Type | Description | Notes | +|------------ | ------------- | ------------- | -------------| +| **status** | **Integer** | | [optional] [default to null] | +| **message** | **String** | | [optional] [default to null] | +| **details** | **String** | | [optional] [default to null] | + +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) + diff --git a/crowd/README.md b/crowd/README.md index fddb0417..b78b7fd1 100644 --- a/crowd/README.md +++ b/crowd/README.md @@ -7,6 +7,7 @@ All URIs are relative to *https://CROWD_URL/rest/bootstrapi/1* | Class | Method | HTTP request | Description | |------------ | ------------- | ------------- | -------------| +| *AllApi* | [**setAll**](Apis/AllApi.md#setAll) | **PUT** / | _all | | *ApplicationApi* | [**createApplication**](Apis/ApplicationApi.md#createApplication) | **POST** /application | Create an application | *ApplicationApi* | [**deleteApplication**](Apis/ApplicationApi.md#deleteApplication) | **DELETE** /application/{id} | Delete an application | *ApplicationApi* | [**getApplication**](Apis/ApplicationApi.md#getApplication) | **GET** /application/{id} | Get an application | @@ -89,6 +90,8 @@ All URIs are relative to *https://CROWD_URL/rest/bootstrapi/1* - [SettingsBrandingLoginPageModel](./Models/SettingsBrandingLoginPageModel.md) - [SettingsModel](./Models/SettingsModel.md) - [UserModel](./Models/UserModel.md) + - [_AllModel](./Models/_AllModel.md) + - [_AllModelStatus](./Models/_AllModelStatus.md) diff --git a/crowd/src/main/java/com/deftdevs/bootstrapi/crowd/config/ServiceConfig.java b/crowd/src/main/java/com/deftdevs/bootstrapi/crowd/config/ServiceConfig.java index b2fda085..3bdddb4d 100644 --- a/crowd/src/main/java/com/deftdevs/bootstrapi/crowd/config/ServiceConfig.java +++ b/crowd/src/main/java/com/deftdevs/bootstrapi/crowd/config/ServiceConfig.java @@ -1,6 +1,7 @@ package com.deftdevs.bootstrapi.crowd.config; import com.deftdevs.bootstrapi.commons.service.api.*; +import com.deftdevs.bootstrapi.crowd.model._AllModel; import com.deftdevs.bootstrapi.crowd.service.*; import com.deftdevs.bootstrapi.crowd.service.api.*; import org.springframework.beans.factory.annotation.Autowired; @@ -16,6 +17,14 @@ public class ServiceConfig { @Autowired private HelperConfig helperConfig; + @Bean + public _AllService<_AllModel> _allService() { + return new _AllServiceImpl( + crowdSettingsGeneralService(), + directoriesService(), + applicationsService()); + } + @Bean public ApplicationLinksService applicationLinksService() { return new ApplicationLinksServiceImpl( diff --git a/crowd/src/main/java/com/deftdevs/bootstrapi/crowd/model/AllModel.java b/crowd/src/main/java/com/deftdevs/bootstrapi/crowd/model/AllModel.java deleted file mode 100644 index 94eb5694..00000000 --- a/crowd/src/main/java/com/deftdevs/bootstrapi/crowd/model/AllModel.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.deftdevs.bootstrapi.crowd.model; - -import com.deftdevs.bootstrapi.commons.model.SettingsModel; -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.Builder; -import lombok.NoArgsConstructor; - -import javax.xml.bind.annotation.XmlElement; -import javax.xml.bind.annotation.XmlRootElement; -import java.util.List; - -@Data -@Builder -@NoArgsConstructor -@AllArgsConstructor -@XmlRootElement(name = "all") -public class AllModel { - - @XmlElement - private SettingsModel settings; - - @XmlElement - private List applications; - -} diff --git a/crowd/src/main/java/com/deftdevs/bootstrapi/crowd/model/_AllModel.java b/crowd/src/main/java/com/deftdevs/bootstrapi/crowd/model/_AllModel.java new file mode 100644 index 00000000..2c2e43ff --- /dev/null +++ b/crowd/src/main/java/com/deftdevs/bootstrapi/crowd/model/_AllModel.java @@ -0,0 +1,33 @@ +package com.deftdevs.bootstrapi.crowd.model; + +import com.deftdevs.bootstrapi.commons.constants.BootstrAPI; +import com.deftdevs.bootstrapi.commons.model.AbstractDirectoryModel; +import com.deftdevs.bootstrapi.commons.model.SettingsModel; +import com.deftdevs.bootstrapi.commons.model.type._AllModelStatus; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; +import java.util.Map; + +@Data +@NoArgsConstructor +@AllArgsConstructor +@XmlRootElement(name = BootstrAPI._ALL) +public class _AllModel { + + @XmlElement + private SettingsModel settings; + + @XmlElement + private Map applications; + + @XmlElement + private Map directories; + + @XmlElement + private Map status; + +} diff --git a/crowd/src/main/java/com/deftdevs/bootstrapi/crowd/rest/_AllResourceImpl.java b/crowd/src/main/java/com/deftdevs/bootstrapi/crowd/rest/_AllResourceImpl.java new file mode 100644 index 00000000..b2d0ee92 --- /dev/null +++ b/crowd/src/main/java/com/deftdevs/bootstrapi/crowd/rest/_AllResourceImpl.java @@ -0,0 +1,28 @@ +package com.deftdevs.bootstrapi.crowd.rest; + +import com.atlassian.plugins.rest.api.security.annotation.SystemAdminOnly; +import com.deftdevs.bootstrapi.commons.constants.BootstrAPI; +import com.deftdevs.bootstrapi.commons.rest._AbstractAllResourceImpl; +import com.deftdevs.bootstrapi.commons.service.api._AllService; +import com.deftdevs.bootstrapi.crowd.model._AllModel; +import io.swagger.v3.oas.annotations.tags.Tag; + +import javax.ws.rs.Consumes; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; + +@Path(BootstrAPI._ROOT) +@Tag(name = BootstrAPI._ALL) +@Consumes(MediaType.APPLICATION_JSON) +@Produces(MediaType.APPLICATION_JSON) +@SystemAdminOnly +public class _AllResourceImpl extends _AbstractAllResourceImpl<_AllModel> { + + public _AllResourceImpl( + final _AllService<_AllModel> allService) { + + super(allService); + } + +} diff --git a/crowd/src/main/java/com/deftdevs/bootstrapi/crowd/service/_AllServiceImpl.java b/crowd/src/main/java/com/deftdevs/bootstrapi/crowd/service/_AllServiceImpl.java new file mode 100644 index 00000000..201db601 --- /dev/null +++ b/crowd/src/main/java/com/deftdevs/bootstrapi/crowd/service/_AllServiceImpl.java @@ -0,0 +1,125 @@ +package com.deftdevs.bootstrapi.crowd.service; + +import com.deftdevs.bootstrapi.commons.model.AbstractDirectoryModel; +import com.deftdevs.bootstrapi.commons.model.type._AllModelStatus; +import com.deftdevs.bootstrapi.commons.service._AbstractAllServiceImpl; +import com.deftdevs.bootstrapi.commons.service.api.DirectoriesService; +import com.deftdevs.bootstrapi.crowd.model.ApplicationModel; +import com.deftdevs.bootstrapi.crowd.model._AllModel; +import com.deftdevs.bootstrapi.crowd.service.api.ApplicationsService; +import com.deftdevs.bootstrapi.crowd.service.api.CrowdSettingsGeneralService; + +import javax.ws.rs.core.Response; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.function.BiFunction; +import java.util.function.Function; + +public class _AllServiceImpl extends _AbstractAllServiceImpl<_AllModel> { + + private final CrowdSettingsGeneralService settingsService; + private final DirectoriesService directoriesService; + private final ApplicationsService applicationsService; + + public _AllServiceImpl( + final CrowdSettingsGeneralService settingsService, + final DirectoriesService directoriesService, + final ApplicationsService applicationsService) { + + this.settingsService = settingsService; + this.directoriesService = directoriesService; + this.applicationsService = applicationsService; + } + + @Override + public _AllModel setAll( + final _AllModel allModel) { + + final _AllModel result = new _AllModel(); + final Map status = new HashMap<>(); + + setEntity(allModel.getSettings(), settingsService::setSettingsGeneral, result::setSettings); + + setEntities(allModel.getDirectories(), AbstractDirectoryModel::getName, directoriesService::setDirectories, result::setDirectories); + + setEntities(allModel.getApplications(), ApplicationModel::getName, applicationsService::setApplications, result::setApplications); + +// // Process entities using a generic handler +// processEntities(allModel.getGroups(), "groups", GroupModel::getName, GroupsService::setGroups, result::setGroups, status); +// +// processEntities(allModel.getUsers(), "users", UserModel::getUsername, +// users -> usersService.setUsers(1L, users), result::setUsers, status); +// +// processEntities(allModel.getApplications(), "applications", ApplicationModel::getName, +// applicationsService::setApplications, result::setApplications, status); + + result.setStatus(status); + return result; + } + + private void processEntities( + Map entityMap, + String entityType, + Function getIdentifier, + Function, List> updateFunction, + BiFunction, _AllModel, _AllModel> resultSetter, + Map status) { + + if (entityMap == null || entityMap.isEmpty()) { + return; + } + + try { + // Validate entity identifiers + for (Map.Entry entry : entityMap.entrySet()) { + String key = entry.getKey(); + T entity = entry.getValue(); + String identifier = getIdentifier.apply(entity); + + if (identifier == null) { + // Try to set the key as the identifier using reflection + try { + entity.getClass().getMethod("set" + entityType.substring(0, 1).toUpperCase() + + entityType.substring(1, entityType.length() - 1), String.class) + .invoke(entity, key); + } catch (Exception e) { + // If reflection fails, report the error + status.put(entityType, _AllModelStatus.error( + Response.Status.BAD_REQUEST, + entityType + " identifier missing", + "Could not set identifier for key: " + key + )); + return; + } + } else if (!key.equals(identifier)) { + status.put(entityType, _AllModelStatus.error( + Response.Status.BAD_REQUEST, + entityType.substring(0, 1).toUpperCase() + entityType.substring(1) + " identifier mismatch", + String.format("Map key '%s' does not match %s '%s'", key, entityType.substring(0, entityType.length() - 1), identifier) + )); + return; + } + } + + if (!status.containsKey(entityType)) { + List entityList = new ArrayList<>(entityMap.values()); + List updatedEntities = updateFunction.apply(entityList); + + Map resultMap = new HashMap<>(); + for (T entity : updatedEntities) { + resultMap.put(getIdentifier.apply(entity), entity); + } + resultSetter.apply(resultMap, null); + status.put(entityType, _AllModelStatus.success()); + } + } catch (Exception e) { + status.put(entityType, _AllModelStatus.error( + Response.Status.BAD_REQUEST, + "Failed to apply " + entityType + " configuration", + e.getMessage() + )); + } + } +} diff --git a/crowd/src/main/java/com/deftdevs/bootstrapi/crowd/service/api/AllService.java b/crowd/src/main/java/com/deftdevs/bootstrapi/crowd/service/api/AllService.java deleted file mode 100644 index 71e5a090..00000000 --- a/crowd/src/main/java/com/deftdevs/bootstrapi/crowd/service/api/AllService.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.deftdevs.bootstrapi.crowd.service.api; - -import com.deftdevs.bootstrapi.crowd.model.AllModel; - -public interface AllService { - - void setAll( - AllModel allModel); - -} diff --git a/crowd/src/test/java/com/deftdevs/bootstrapi/crowd/rest/AllResourceTest.java b/crowd/src/test/java/com/deftdevs/bootstrapi/crowd/rest/AllResourceTest.java new file mode 100644 index 00000000..2ef1d69c --- /dev/null +++ b/crowd/src/test/java/com/deftdevs/bootstrapi/crowd/rest/AllResourceTest.java @@ -0,0 +1,64 @@ +package com.deftdevs.bootstrapi.crowd.rest; + +import com.deftdevs.bootstrapi.commons.model.SettingsModel; +import com.deftdevs.bootstrapi.crowd.model.ApplicationModel; +import com.deftdevs.bootstrapi.crowd.model._AllModel; +import com.deftdevs.bootstrapi.commons.model.type._AllModelStatus; +import com.deftdevs.bootstrapi.commons.service.api._AllService; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; + +import javax.ws.rs.core.Response; +import java.util.HashMap; +import java.util.Map; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.mockito.Mockito.*; + +@ExtendWith(MockitoExtension.class) +public class AllResourceTest { + + @Mock + private _AllService<_AllModel> allService; + + private _AllResourceImpl configurationResource; + + private _AllModel allModel; + + @BeforeEach + public void setup() { + configurationResource = new _AllResourceImpl(allService); + + // Setup test data + allModel = new _AllModel(); + allModel.setSettings(SettingsModel.EXAMPLE_1); + + // Setup applications map + Map applications = new HashMap<>(); + applications.put(ApplicationModel.EXAMPLE_1.getName(), ApplicationModel.EXAMPLE_1); + allModel.setApplications(applications); + + Map status = new HashMap<>(); + status.put("settings", _AllModelStatus.success()); + status.put("users", _AllModelStatus.success()); + status.put("groups", _AllModelStatus.success()); + status.put("applications", _AllModelStatus.success()); + allModel.setStatus(status); + } + + @Test + public void testSetConfiguration() { + doReturn(allModel).when(allService).setAll(any()); + + Response response = configurationResource.setAll(allModel); + assertEquals(200, response.getStatus()); + + _AllModel responseModel = (_AllModel) response.getEntity(); + assertEquals(allModel, responseModel); + + verify(allService).setAll(allModel); + } +} diff --git a/crowd/src/test/java/com/deftdevs/bootstrapi/crowd/service/DirectoriesServiceTest.java b/crowd/src/test/java/com/deftdevs/bootstrapi/crowd/service/DirectoriesServiceTest.java index 94fa7f75..5e5867cc 100644 --- a/crowd/src/test/java/com/deftdevs/bootstrapi/crowd/service/DirectoriesServiceTest.java +++ b/crowd/src/test/java/com/deftdevs/bootstrapi/crowd/service/DirectoriesServiceTest.java @@ -91,7 +91,6 @@ public void testSetDirectoriesAddNewUnsupportedType() { final AbstractDirectoryModel directoryModel = DirectoryModelUtil.toDirectoryModel(directoryAzureAd); final Map directoryModels = Collections.singletonMap(directoryModel.getName(), directoryModel); - final boolean testConnection = false; assertThrows(BadRequestException.class, () -> { spy.setDirectories(directoryModels); diff --git a/jira/Apis/AllApi.md b/jira/Apis/AllApi.md new file mode 100644 index 00000000..83d417e4 --- /dev/null +++ b/jira/Apis/AllApi.md @@ -0,0 +1,34 @@ +# AllApi + +All URIs are relative to *https://JIRA_URL/rest/bootstrapi/1* + +| Method | HTTP request | Description | +|------------- | ------------- | -------------| +| [**setAll**](AllApi.md#setAll) | **PUT** / | _all | + + + +# **setAll** +> SettingsModel setAll(\_AllModel) + +_all + +### Parameters + +|Name | Type | Description | Notes | +|------------- | ------------- | ------------- | -------------| +| **\_AllModel** | [**_AllModel**](../Models/_AllModel.md)| | | + +### Return type + +[**SettingsModel**](../Models/SettingsModel.md) + +### Authorization + +[basicAuth](../README.md#basicAuth) + +### HTTP request headers + +- **Content-Type**: application/json +- **Accept**: application/json + diff --git a/jira/Models/AbstractDirectoryModel.md b/jira/Models/AbstractDirectoryModel.md index 7ef166ee..cde79f6a 100644 --- a/jira/Models/AbstractDirectoryModel.md +++ b/jira/Models/AbstractDirectoryModel.md @@ -9,8 +9,8 @@ | **active** | **Boolean** | | [optional] [default to null] | | **createdDate** | **Date** | | [optional] [default to null] | | **updatedDate** | **Date** | | [optional] [default to null] | -| **type** | **String** | | [default to null] | | **testConnection** | **Boolean** | | [optional] [default to null] | +| **type** | **String** | | [default to null] | | **connector** | [**DirectoryDelegatingConnector**](DirectoryDelegatingConnector.md) | | [optional] [default to null] | | **configuration** | [**DirectoryDelegatingConfiguration**](DirectoryDelegatingConfiguration.md) | | [optional] [default to null] | | **permissions** | [**DirectoryLdapPermissions**](DirectoryLdapPermissions.md) | | [optional] [default to null] | diff --git a/jira/Models/DirectoryCrowdModel.md b/jira/Models/DirectoryCrowdModel.md index 655455e4..d58a9ad3 100644 --- a/jira/Models/DirectoryCrowdModel.md +++ b/jira/Models/DirectoryCrowdModel.md @@ -9,8 +9,8 @@ | **active** | **Boolean** | | [optional] [default to null] | | **createdDate** | **Date** | | [optional] [default to null] | | **updatedDate** | **Date** | | [optional] [default to null] | -| **type** | **String** | | [default to null] | | **testConnection** | **Boolean** | | [optional] [default to null] | +| **type** | **String** | | [default to null] | | **server** | [**DirectoryCrowdServer**](DirectoryCrowdServer.md) | | [optional] [default to null] | | **permissions** | [**DirectoryCrowdPermissions**](DirectoryCrowdPermissions.md) | | [optional] [default to null] | | **advanced** | [**DirectoryCrowdAdvanced**](DirectoryCrowdAdvanced.md) | | [optional] [default to null] | diff --git a/jira/Models/DirectoryDelegatingModel.md b/jira/Models/DirectoryDelegatingModel.md index 241e45d1..01c3480b 100644 --- a/jira/Models/DirectoryDelegatingModel.md +++ b/jira/Models/DirectoryDelegatingModel.md @@ -9,8 +9,8 @@ | **active** | **Boolean** | | [optional] [default to null] | | **createdDate** | **Date** | | [optional] [default to null] | | **updatedDate** | **Date** | | [optional] [default to null] | -| **type** | **String** | | [default to null] | | **testConnection** | **Boolean** | | [optional] [default to null] | +| **type** | **String** | | [default to null] | | **server** | [**DirectoryLdapServer**](DirectoryLdapServer.md) | | [optional] [default to null] | | **permissions** | [**DirectoryPermissions**](DirectoryPermissions.md) | | [optional] [default to null] | | **advanced** | [**DirectoryInternalAdvanced**](DirectoryInternalAdvanced.md) | | [optional] [default to null] | diff --git a/jira/Models/DirectoryGenericModel.md b/jira/Models/DirectoryGenericModel.md index ec59bab6..71c67548 100644 --- a/jira/Models/DirectoryGenericModel.md +++ b/jira/Models/DirectoryGenericModel.md @@ -9,8 +9,8 @@ | **active** | **Boolean** | | [optional] [default to null] | | **createdDate** | **Date** | | [optional] [default to null] | | **updatedDate** | **Date** | | [optional] [default to null] | -| **type** | **String** | | [default to null] | | **testConnection** | **Boolean** | | [optional] [default to null] | +| **type** | **String** | | [default to null] | | **server** | [**DirectoryLdapServer**](DirectoryLdapServer.md) | | [optional] [default to null] | | **permissions** | [**DirectoryLdapPermissions**](DirectoryLdapPermissions.md) | | [optional] [default to null] | | **advanced** | [**DirectoryInternalAdvanced**](DirectoryInternalAdvanced.md) | | [optional] [default to null] | diff --git a/jira/Models/DirectoryInternalModel.md b/jira/Models/DirectoryInternalModel.md index 472b0c05..2ccbe759 100644 --- a/jira/Models/DirectoryInternalModel.md +++ b/jira/Models/DirectoryInternalModel.md @@ -9,8 +9,8 @@ | **active** | **Boolean** | | [optional] [default to null] | | **createdDate** | **Date** | | [optional] [default to null] | | **updatedDate** | **Date** | | [optional] [default to null] | -| **type** | **String** | | [default to null] | | **testConnection** | **Boolean** | | [optional] [default to null] | +| **type** | **String** | | [default to null] | | **server** | [**DirectoryLdapServer**](DirectoryLdapServer.md) | | [optional] [default to null] | | **permissions** | [**DirectoryPermissions**](DirectoryPermissions.md) | | [optional] [default to null] | | **advanced** | [**DirectoryInternalAdvanced**](DirectoryInternalAdvanced.md) | | [optional] [default to null] | diff --git a/jira/Models/DirectoryLdapModel.md b/jira/Models/DirectoryLdapModel.md index c5c48bfe..97eb576e 100644 --- a/jira/Models/DirectoryLdapModel.md +++ b/jira/Models/DirectoryLdapModel.md @@ -9,8 +9,8 @@ | **active** | **Boolean** | | [optional] [default to null] | | **createdDate** | **Date** | | [optional] [default to null] | | **updatedDate** | **Date** | | [optional] [default to null] | -| **type** | **String** | | [default to null] | | **testConnection** | **Boolean** | | [optional] [default to null] | +| **type** | **String** | | [default to null] | | **server** | [**DirectoryLdapServer**](DirectoryLdapServer.md) | | [optional] [default to null] | | **permissions** | [**DirectoryLdapPermissions**](DirectoryLdapPermissions.md) | | [optional] [default to null] | | **advanced** | [**DirectoryInternalAdvanced**](DirectoryInternalAdvanced.md) | | [optional] [default to null] | diff --git a/jira/Models/_AllModel.md b/jira/Models/_AllModel.md new file mode 100644 index 00000000..34153397 --- /dev/null +++ b/jira/Models/_AllModel.md @@ -0,0 +1,12 @@ +# _AllModel +## Properties + +| Name | Type | Description | Notes | +|------------ | ------------- | ------------- | -------------| +| **settings** | [**SettingsModel**](SettingsModel.md) | | [optional] [default to null] | +| **users** | [**Map**](UserModel.md) | | [optional] [default to null] | +| **groups** | [**Map**](GroupModel.md) | | [optional] [default to null] | +| **status** | [**Map**](_AllModelStatus.md) | | [optional] [default to null] | + +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) + diff --git a/jira/Models/_AllModelStatus.md b/jira/Models/_AllModelStatus.md new file mode 100644 index 00000000..ed699765 --- /dev/null +++ b/jira/Models/_AllModelStatus.md @@ -0,0 +1,11 @@ +# _AllModelStatus +## Properties + +| Name | Type | Description | Notes | +|------------ | ------------- | ------------- | -------------| +| **status** | **Integer** | | [optional] [default to null] | +| **message** | **String** | | [optional] [default to null] | +| **details** | **String** | | [optional] [default to null] | + +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) + diff --git a/jira/README.md b/jira/README.md index 70f20fbf..ebb27321 100644 --- a/jira/README.md +++ b/jira/README.md @@ -7,6 +7,7 @@ All URIs are relative to *https://JIRA_URL/rest/bootstrapi/1* | Class | Method | HTTP request | Description | |------------ | ------------- | ------------- | -------------| +| *AllApi* | [**setAll**](Apis/AllApi.md#setAll) | **PUT** / | _all | | *ApplicationLinkApi* | [**createApplicationLink**](Apis/ApplicationLinkApi.md#createApplicationLink) | **POST** /application-link | Create an application link | *ApplicationLinkApi* | [**deleteApplicationLink**](Apis/ApplicationLinkApi.md#deleteApplicationLink) | **DELETE** /application-link/{uuid} | Delete an application link | *ApplicationLinkApi* | [**getApplicationLink**](Apis/ApplicationLinkApi.md#getApplicationLink) | **GET** /application-link/{uuid} | Get an application link | @@ -79,6 +80,8 @@ All URIs are relative to *https://JIRA_URL/rest/bootstrapi/1* - [SettingsModel](./Models/SettingsModel.md) - [SettingsSecurityModel](./Models/SettingsSecurityModel.md) - [UserModel](./Models/UserModel.md) + - [_AllModel](./Models/_AllModel.md) + - [_AllModelStatus](./Models/_AllModelStatus.md) diff --git a/jira/src/main/java/com/deftdevs/bootstrapi/jira/model/_AllModel.java b/jira/src/main/java/com/deftdevs/bootstrapi/jira/model/_AllModel.java new file mode 100644 index 00000000..46fdfa07 --- /dev/null +++ b/jira/src/main/java/com/deftdevs/bootstrapi/jira/model/_AllModel.java @@ -0,0 +1,34 @@ +package com.deftdevs.bootstrapi.jira.model; + +import com.deftdevs.bootstrapi.commons.constants.BootstrAPI; +import com.deftdevs.bootstrapi.commons.model.GroupModel; +import com.deftdevs.bootstrapi.commons.model.SettingsModel; +import com.deftdevs.bootstrapi.commons.model.UserModel; +import com.deftdevs.bootstrapi.commons.model.type._AllModelStatus; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; +import java.util.Map; + +@Data +@NoArgsConstructor +@AllArgsConstructor +@XmlRootElement(name = BootstrAPI._ALL) +public class _AllModel { + + @XmlElement + private SettingsModel settings; + + @XmlElement + private Map users; + + @XmlElement + private Map groups; + + @XmlElement + private Map status; + +} diff --git a/jira/src/main/java/com/deftdevs/bootstrapi/jira/rest/_AllResourceImpl.java b/jira/src/main/java/com/deftdevs/bootstrapi/jira/rest/_AllResourceImpl.java new file mode 100644 index 00000000..0b0af18e --- /dev/null +++ b/jira/src/main/java/com/deftdevs/bootstrapi/jira/rest/_AllResourceImpl.java @@ -0,0 +1,28 @@ +package com.deftdevs.bootstrapi.jira.rest; + +import com.atlassian.plugins.rest.api.security.annotation.SystemAdminOnly; +import com.deftdevs.bootstrapi.commons.constants.BootstrAPI; +import com.deftdevs.bootstrapi.commons.rest._AbstractAllResourceImpl; +import com.deftdevs.bootstrapi.commons.service.api._AllService; +import com.deftdevs.bootstrapi.jira.model._AllModel; +import io.swagger.v3.oas.annotations.tags.Tag; + +import javax.ws.rs.Consumes; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; + +@Path(BootstrAPI._ROOT) +@Tag(name = BootstrAPI._ALL) +@Consumes(MediaType.APPLICATION_JSON) +@Produces(MediaType.APPLICATION_JSON) +@SystemAdminOnly +public class _AllResourceImpl extends _AbstractAllResourceImpl<_AllModel> { + + public _AllResourceImpl( + final _AllService<_AllModel> allService) { + + super(allService); + } + +} From c23d8b4fe65bc7c41f7802ffe4bd6a913f41be50 Mon Sep 17 00:00:00 2001 From: Patrick Hobusch Date: Tue, 24 Feb 2026 21:26:46 +0800 Subject: [PATCH 2/3] WIP_REWORK --- .../commons/model/AbstractDirectoryModel.java | 3 - .../commons/model/type/_AllModelAccessor.java | 9 ++ .../rest/_AbstractAllResourceImpl.java | 22 ++++- .../commons/rest/api/_AllResource.java | 12 +-- .../service/_AbstractAllServiceImpl.java | 48 +++++++--- .../commons/service/api/_AllService.java | 4 +- .../confluence/model/_AllModel.java | 3 +- .../bootstrapi/crowd/model/_AllModel.java | 3 +- .../crowd/service/_AllServiceImpl.java | 90 ++----------------- .../crowd/rest/AllResourceTest.java | 3 +- .../bootstrapi/jira/model/_AllModel.java | 3 +- 11 files changed, 85 insertions(+), 115 deletions(-) create mode 100644 commons/src/main/java/com/deftdevs/bootstrapi/commons/model/type/_AllModelAccessor.java diff --git a/commons/src/main/java/com/deftdevs/bootstrapi/commons/model/AbstractDirectoryModel.java b/commons/src/main/java/com/deftdevs/bootstrapi/commons/model/AbstractDirectoryModel.java index a9050606..19e534a4 100644 --- a/commons/src/main/java/com/deftdevs/bootstrapi/commons/model/AbstractDirectoryModel.java +++ b/commons/src/main/java/com/deftdevs/bootstrapi/commons/model/AbstractDirectoryModel.java @@ -61,7 +61,4 @@ public abstract class AbstractDirectoryModel { @XmlElement private Date updatedDate; - @XmlElement - private Boolean testConnection; - } diff --git a/commons/src/main/java/com/deftdevs/bootstrapi/commons/model/type/_AllModelAccessor.java b/commons/src/main/java/com/deftdevs/bootstrapi/commons/model/type/_AllModelAccessor.java new file mode 100644 index 00000000..c586adff --- /dev/null +++ b/commons/src/main/java/com/deftdevs/bootstrapi/commons/model/type/_AllModelAccessor.java @@ -0,0 +1,9 @@ +package com.deftdevs.bootstrapi.commons.model.type; + +import java.util.Map; + +public interface _AllModelAccessor { + + Map getStatus(); + +} diff --git a/commons/src/main/java/com/deftdevs/bootstrapi/commons/rest/_AbstractAllResourceImpl.java b/commons/src/main/java/com/deftdevs/bootstrapi/commons/rest/_AbstractAllResourceImpl.java index c1b6d948..423ce4f7 100644 --- a/commons/src/main/java/com/deftdevs/bootstrapi/commons/rest/_AbstractAllResourceImpl.java +++ b/commons/src/main/java/com/deftdevs/bootstrapi/commons/rest/_AbstractAllResourceImpl.java @@ -1,11 +1,14 @@ package com.deftdevs.bootstrapi.commons.rest; +import com.deftdevs.bootstrapi.commons.model.type._AllModelAccessor; +import com.deftdevs.bootstrapi.commons.model.type._AllModelStatus; import com.deftdevs.bootstrapi.commons.rest.api._AllResource; import com.deftdevs.bootstrapi.commons.service.api._AllService; import javax.ws.rs.core.Response; +import java.util.Map; -public abstract class _AbstractAllResourceImpl<_AllModel> +public abstract class _AbstractAllResourceImpl<_AllModel extends _AllModelAccessor> implements _AllResource<_AllModel> { private final _AllService<_AllModel> allService; @@ -19,6 +22,21 @@ public _AbstractAllResourceImpl( public Response setAll( final _AllModel allModel) { - return Response.ok(allService.setAll(allModel)).build(); + final _AllModel result = allService.setAll(allModel); + final int overallStatus = computeOverallStatus(result.getStatus()); + return Response.status(overallStatus).entity(result).build(); + } + + private static int computeOverallStatus( + final Map statusMap) { + + if (statusMap == null || statusMap.isEmpty()) { + return Response.Status.OK.getStatusCode(); + } + + return statusMap.values().stream() + .mapToInt(_AllModelStatus::getStatus) + .max() + .orElse(Response.Status.OK.getStatusCode()); } } diff --git a/commons/src/main/java/com/deftdevs/bootstrapi/commons/rest/api/_AllResource.java b/commons/src/main/java/com/deftdevs/bootstrapi/commons/rest/api/_AllResource.java index 7b548d35..e0df0a7b 100644 --- a/commons/src/main/java/com/deftdevs/bootstrapi/commons/rest/api/_AllResource.java +++ b/commons/src/main/java/com/deftdevs/bootstrapi/commons/rest/api/_AllResource.java @@ -2,7 +2,7 @@ import com.deftdevs.bootstrapi.commons.constants.BootstrAPI; import com.deftdevs.bootstrapi.commons.model.ErrorCollection; -import com.deftdevs.bootstrapi.commons.model.SettingsModel; +import com.deftdevs.bootstrapi.commons.model.type._AllModelAccessor; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.media.Content; import io.swagger.v3.oas.annotations.media.Schema; @@ -12,19 +12,19 @@ import javax.ws.rs.PUT; import javax.ws.rs.core.Response; -public interface _AllResource<_AllModel> { +public interface _AllResource<_AllModel extends _AllModelAccessor> { @PUT @Operation( - summary = BootstrAPI._ALL, + summary = "Apply a complete configuration", responses = { @ApiResponse( - responseCode = "200", content = @Content(schema = @Schema(implementation = SettingsModel.class)), - description = BootstrAPI._ALL + responseCode = "200", + description = "Configuration applied successfully" ), @ApiResponse( responseCode = "default", content = @Content(schema = @Schema(implementation = ErrorCollection.class)), - description = BootstrAPI._ALL + description = BootstrAPI.ERROR_COLLECTION_RESPONSE_DESCRIPTION ), } ) diff --git a/commons/src/main/java/com/deftdevs/bootstrapi/commons/service/_AbstractAllServiceImpl.java b/commons/src/main/java/com/deftdevs/bootstrapi/commons/service/_AbstractAllServiceImpl.java index da63c299..7db34a8c 100644 --- a/commons/src/main/java/com/deftdevs/bootstrapi/commons/service/_AbstractAllServiceImpl.java +++ b/commons/src/main/java/com/deftdevs/bootstrapi/commons/service/_AbstractAllServiceImpl.java @@ -1,5 +1,6 @@ package com.deftdevs.bootstrapi.commons.service; +import com.deftdevs.bootstrapi.commons.model.type._AllModelAccessor; import com.deftdevs.bootstrapi.commons.model.type._AllModelStatus; import com.deftdevs.bootstrapi.commons.service.api._AllService; @@ -8,12 +9,14 @@ import java.util.function.Consumer; import java.util.function.Function; -public abstract class _AbstractAllServiceImpl<_A> implements _AllService<_A> { +public abstract class _AbstractAllServiceImpl<_AllModel extends _AllModelAccessor> implements _AllService<_AllModel> { protected _AllModelStatus setEntity( + final String entityType, final T entity, final Function updateFunction, - final Consumer resultConsumer) { + final Consumer resultConsumer, + final Map statusMap) { if (entity == null) { return null; @@ -22,22 +25,27 @@ protected _AllModelStatus setEntity( try { final T updatedEntity = updateFunction.apply(entity); resultConsumer.accept(updatedEntity); - return _AllModelStatus.success(); + final _AllModelStatus status = _AllModelStatus.success(); + statusMap.put(entityType, status); + return status; } catch (Exception e) { - return _AllModelStatus.error( - Response.Status.INTERNAL_SERVER_ERROR, - "Failed to apply ...", - e.getMessage() + final _AllModelStatus status = _AllModelStatus.error( + resolveStatus(e), + String.format("Failed to apply %s configuration", entityType), + e.getMessage() ); + statusMap.put(entityType, status); + return status; } } @SuppressWarnings("unchecked") protected _AllModelStatus setEntities( + final String entityType, final Map entityMap, - final Function getIdentifier, final Function, Map> updateFunction, - final Consumer> resultConsumer) { + final Consumer> resultConsumer, + final Map statusMap) { if (entityMap == null || entityMap.isEmpty()) { return null; @@ -46,14 +54,28 @@ protected _AllModelStatus setEntities( try { final Map updatedEntities = updateFunction.apply(entityMap); resultConsumer.accept((Map) updatedEntities); - return _AllModelStatus.success(); + final _AllModelStatus status = _AllModelStatus.success(); + statusMap.put(entityType, status); + return status; } catch (Exception e) { - return _AllModelStatus.error( - Response.Status.INTERNAL_SERVER_ERROR, - "Failed to apply ...", + final _AllModelStatus status = _AllModelStatus.error( + resolveStatus(e), + String.format("Failed to apply %s configuration", entityType), e.getMessage() ); + statusMap.put(entityType, status); + return status; + } + } + + private static Response.Status resolveStatus(final Exception e) { + if (e instanceof com.deftdevs.bootstrapi.commons.exception.web.BadRequestException) { + return Response.Status.BAD_REQUEST; + } + if (e instanceof com.deftdevs.bootstrapi.commons.exception.web.NotFoundException) { + return Response.Status.NOT_FOUND; } + return Response.Status.INTERNAL_SERVER_ERROR; } } diff --git a/commons/src/main/java/com/deftdevs/bootstrapi/commons/service/api/_AllService.java b/commons/src/main/java/com/deftdevs/bootstrapi/commons/service/api/_AllService.java index 61adc85f..9afbbbf9 100644 --- a/commons/src/main/java/com/deftdevs/bootstrapi/commons/service/api/_AllService.java +++ b/commons/src/main/java/com/deftdevs/bootstrapi/commons/service/api/_AllService.java @@ -1,6 +1,8 @@ package com.deftdevs.bootstrapi.commons.service.api; -public interface _AllService<_AllModel> { +import com.deftdevs.bootstrapi.commons.model.type._AllModelAccessor; + +public interface _AllService<_AllModel extends _AllModelAccessor> { /** * Apply a complete configuration. diff --git a/confluence/src/main/java/com/deftdevs/bootstrapi/confluence/model/_AllModel.java b/confluence/src/main/java/com/deftdevs/bootstrapi/confluence/model/_AllModel.java index 60641c97..486353bd 100644 --- a/confluence/src/main/java/com/deftdevs/bootstrapi/confluence/model/_AllModel.java +++ b/confluence/src/main/java/com/deftdevs/bootstrapi/confluence/model/_AllModel.java @@ -3,6 +3,7 @@ import com.deftdevs.bootstrapi.commons.model.GroupModel; import com.deftdevs.bootstrapi.commons.model.SettingsModel; import com.deftdevs.bootstrapi.commons.model.UserModel; +import com.deftdevs.bootstrapi.commons.model.type._AllModelAccessor; import com.deftdevs.bootstrapi.commons.model.type._AllModelStatus; import lombok.AllArgsConstructor; import lombok.Data; @@ -16,7 +17,7 @@ @NoArgsConstructor @AllArgsConstructor @XmlRootElement(name = "all") -public class _AllModel { +public class _AllModel implements _AllModelAccessor { @XmlElement private SettingsModel settings; diff --git a/crowd/src/main/java/com/deftdevs/bootstrapi/crowd/model/_AllModel.java b/crowd/src/main/java/com/deftdevs/bootstrapi/crowd/model/_AllModel.java index 2c2e43ff..f973f55d 100644 --- a/crowd/src/main/java/com/deftdevs/bootstrapi/crowd/model/_AllModel.java +++ b/crowd/src/main/java/com/deftdevs/bootstrapi/crowd/model/_AllModel.java @@ -3,6 +3,7 @@ import com.deftdevs.bootstrapi.commons.constants.BootstrAPI; import com.deftdevs.bootstrapi.commons.model.AbstractDirectoryModel; import com.deftdevs.bootstrapi.commons.model.SettingsModel; +import com.deftdevs.bootstrapi.commons.model.type._AllModelAccessor; import com.deftdevs.bootstrapi.commons.model.type._AllModelStatus; import lombok.AllArgsConstructor; import lombok.Data; @@ -16,7 +17,7 @@ @NoArgsConstructor @AllArgsConstructor @XmlRootElement(name = BootstrAPI._ALL) -public class _AllModel { +public class _AllModel implements _AllModelAccessor { @XmlElement private SettingsModel settings; diff --git a/crowd/src/main/java/com/deftdevs/bootstrapi/crowd/service/_AllServiceImpl.java b/crowd/src/main/java/com/deftdevs/bootstrapi/crowd/service/_AllServiceImpl.java index 201db601..f74c83ad 100644 --- a/crowd/src/main/java/com/deftdevs/bootstrapi/crowd/service/_AllServiceImpl.java +++ b/crowd/src/main/java/com/deftdevs/bootstrapi/crowd/service/_AllServiceImpl.java @@ -1,21 +1,14 @@ package com.deftdevs.bootstrapi.crowd.service; -import com.deftdevs.bootstrapi.commons.model.AbstractDirectoryModel; import com.deftdevs.bootstrapi.commons.model.type._AllModelStatus; import com.deftdevs.bootstrapi.commons.service._AbstractAllServiceImpl; import com.deftdevs.bootstrapi.commons.service.api.DirectoriesService; -import com.deftdevs.bootstrapi.crowd.model.ApplicationModel; import com.deftdevs.bootstrapi.crowd.model._AllModel; import com.deftdevs.bootstrapi.crowd.service.api.ApplicationsService; import com.deftdevs.bootstrapi.crowd.service.api.CrowdSettingsGeneralService; -import javax.ws.rs.core.Response; -import java.util.ArrayList; import java.util.HashMap; -import java.util.List; import java.util.Map; -import java.util.function.BiFunction; -import java.util.function.Function; public class _AllServiceImpl extends _AbstractAllServiceImpl<_AllModel> { @@ -38,88 +31,15 @@ public _AllModel setAll( final _AllModel allModel) { final _AllModel result = new _AllModel(); - final Map status = new HashMap<>(); + final Map statusMap = new HashMap<>(); - setEntity(allModel.getSettings(), settingsService::setSettingsGeneral, result::setSettings); + setEntity("settings", allModel.getSettings(), settingsService::setSettingsGeneral, result::setSettings, statusMap); - setEntities(allModel.getDirectories(), AbstractDirectoryModel::getName, directoriesService::setDirectories, result::setDirectories); + setEntities("directories", allModel.getDirectories(), directoriesService::setDirectories, result::setDirectories, statusMap); - setEntities(allModel.getApplications(), ApplicationModel::getName, applicationsService::setApplications, result::setApplications); + setEntities("applications", allModel.getApplications(), applicationsService::setApplications, result::setApplications, statusMap); -// // Process entities using a generic handler -// processEntities(allModel.getGroups(), "groups", GroupModel::getName, GroupsService::setGroups, result::setGroups, status); -// -// processEntities(allModel.getUsers(), "users", UserModel::getUsername, -// users -> usersService.setUsers(1L, users), result::setUsers, status); -// -// processEntities(allModel.getApplications(), "applications", ApplicationModel::getName, -// applicationsService::setApplications, result::setApplications, status); - - result.setStatus(status); + result.setStatus(statusMap); return result; } - - private void processEntities( - Map entityMap, - String entityType, - Function getIdentifier, - Function, List> updateFunction, - BiFunction, _AllModel, _AllModel> resultSetter, - Map status) { - - if (entityMap == null || entityMap.isEmpty()) { - return; - } - - try { - // Validate entity identifiers - for (Map.Entry entry : entityMap.entrySet()) { - String key = entry.getKey(); - T entity = entry.getValue(); - String identifier = getIdentifier.apply(entity); - - if (identifier == null) { - // Try to set the key as the identifier using reflection - try { - entity.getClass().getMethod("set" + entityType.substring(0, 1).toUpperCase() + - entityType.substring(1, entityType.length() - 1), String.class) - .invoke(entity, key); - } catch (Exception e) { - // If reflection fails, report the error - status.put(entityType, _AllModelStatus.error( - Response.Status.BAD_REQUEST, - entityType + " identifier missing", - "Could not set identifier for key: " + key - )); - return; - } - } else if (!key.equals(identifier)) { - status.put(entityType, _AllModelStatus.error( - Response.Status.BAD_REQUEST, - entityType.substring(0, 1).toUpperCase() + entityType.substring(1) + " identifier mismatch", - String.format("Map key '%s' does not match %s '%s'", key, entityType.substring(0, entityType.length() - 1), identifier) - )); - return; - } - } - - if (!status.containsKey(entityType)) { - List entityList = new ArrayList<>(entityMap.values()); - List updatedEntities = updateFunction.apply(entityList); - - Map resultMap = new HashMap<>(); - for (T entity : updatedEntities) { - resultMap.put(getIdentifier.apply(entity), entity); - } - resultSetter.apply(resultMap, null); - status.put(entityType, _AllModelStatus.success()); - } - } catch (Exception e) { - status.put(entityType, _AllModelStatus.error( - Response.Status.BAD_REQUEST, - "Failed to apply " + entityType + " configuration", - e.getMessage() - )); - } - } } diff --git a/crowd/src/test/java/com/deftdevs/bootstrapi/crowd/rest/AllResourceTest.java b/crowd/src/test/java/com/deftdevs/bootstrapi/crowd/rest/AllResourceTest.java index 2ef1d69c..69242953 100644 --- a/crowd/src/test/java/com/deftdevs/bootstrapi/crowd/rest/AllResourceTest.java +++ b/crowd/src/test/java/com/deftdevs/bootstrapi/crowd/rest/AllResourceTest.java @@ -43,8 +43,7 @@ public void setup() { Map status = new HashMap<>(); status.put("settings", _AllModelStatus.success()); - status.put("users", _AllModelStatus.success()); - status.put("groups", _AllModelStatus.success()); + status.put("directories", _AllModelStatus.success()); status.put("applications", _AllModelStatus.success()); allModel.setStatus(status); } diff --git a/jira/src/main/java/com/deftdevs/bootstrapi/jira/model/_AllModel.java b/jira/src/main/java/com/deftdevs/bootstrapi/jira/model/_AllModel.java index 46fdfa07..2ab910ad 100644 --- a/jira/src/main/java/com/deftdevs/bootstrapi/jira/model/_AllModel.java +++ b/jira/src/main/java/com/deftdevs/bootstrapi/jira/model/_AllModel.java @@ -4,6 +4,7 @@ import com.deftdevs.bootstrapi.commons.model.GroupModel; import com.deftdevs.bootstrapi.commons.model.SettingsModel; import com.deftdevs.bootstrapi.commons.model.UserModel; +import com.deftdevs.bootstrapi.commons.model.type._AllModelAccessor; import com.deftdevs.bootstrapi.commons.model.type._AllModelStatus; import lombok.AllArgsConstructor; import lombok.Data; @@ -17,7 +18,7 @@ @NoArgsConstructor @AllArgsConstructor @XmlRootElement(name = BootstrAPI._ALL) -public class _AllModel { +public class _AllModel implements _AllModelAccessor { @XmlElement private SettingsModel settings; From 8b96e6d963d8276ba31e76620040affd08384258 Mon Sep 17 00:00:00 2001 From: Patrick Hobusch Date: Tue, 24 Feb 2026 22:35:42 +0800 Subject: [PATCH 3/3] WIP_ALL_IMPL --- .../commons/model/AuthenticationModel.java | 25 ++++ .../commons/model/MailServerModel.java | 31 +++++ ...gsModel.java => SettingsGeneralModel.java} | 6 +- .../AbstractSettingsGeneralResourceImpl.java | 31 +++++ .../rest/AbstractSettingsResourceImpl.java | 31 ----- ...urce.java => SettingsGeneralResource.java} | 8 +- ...rvice.java => SettingsGeneralService.java} | 4 +- ...est.java => SettingsGeneralModelTest.java} | 0 ....java => SettingsGeneralResourceTest.java} | 22 ++-- .../impl/TestSettingsGeneralResourceImpl.java | 12 ++ .../rest/impl/TestSettingsResourceImpl.java | 12 -- ...tractSettingsGeneralResourceFuncTest.java} | 12 +- confluence/Apis/AllApi.md | 4 +- confluence/Apis/SettingsApi.md | 10 +- confluence/Models/SettingsGeneralModel.md | 13 ++ confluence/Models/SettingsModel.md | 9 +- confluence/Models/_AllModel.md | 8 +- confluence/README.md | 1 + .../confluence/config/ServiceConfig.java | 14 +++ .../confluence/model/SettingsModel.java | 33 ++++++ .../confluence/model/_AllModel.java | 28 ++++- ....java => SettingsGeneralResourceImpl.java} | 8 +- .../service/SettingsServiceImpl.java | 8 +- .../confluence/service/_AllServiceImpl.java | 112 ++++++++++++++++++ .../api/ConfluenceSettingsService.java | 6 +- .../service/SettingsServiceTest.java | 14 +-- .../rest/SettingsGeneralResourceFuncTest.java | 12 ++ .../rest/SettingsResourceFuncTest.java | 12 -- crowd/Apis/AllApi.md | 4 +- crowd/Apis/SettingsApi.md | 10 +- crowd/Models/SettingsGeneralModel.md | 13 ++ crowd/Models/SettingsModel.md | 7 +- crowd/Models/_AllModel.md | 8 +- crowd/README.md | 1 + .../crowd/config/ServiceConfig.java | 9 +- .../bootstrapi/crowd/model/SettingsModel.java | 25 ++++ .../bootstrapi/crowd/model/_AllModel.java | 24 +++- ....java => SettingsGeneralResourceImpl.java} | 8 +- .../crowd/service/SettingsServiceImpl.java | 8 +- .../crowd/service/_AllServiceImpl.java | 76 +++++++++++- .../api/CrowdSettingsGeneralService.java | 6 +- .../crowd/rest/AllResourceTest.java | 9 +- .../crowd/service/SettingsServiceTest.java | 6 +- .../rest/SettingsGeneralResourceFuncTest.java | 16 +++ .../crowd/rest/SettingsResourceFuncTest.java | 16 --- jira/Apis/AllApi.md | 4 +- jira/Apis/SettingsApi.md | 10 +- jira/Models/SettingsGeneralModel.md | 13 ++ jira/Models/SettingsModel.md | 8 +- jira/Models/_AllModel.md | 8 +- jira/README.md | 1 + .../bootstrapi/jira/config/ServiceConfig.java | 13 ++ .../bootstrapi/jira/model/SettingsModel.java | 29 +++++ .../bootstrapi/jira/model/_AllModel.java | 25 +++- ....java => SettingsGeneralResourceImpl.java} | 8 +- .../jira/service/SettingsServiceImpl.java | 10 +- .../jira/service/_AllServiceImpl.java | 106 +++++++++++++++++ .../jira/service/api/JiraSettingsService.java | 6 +- .../jira/service/JiraSettingsServiceTest.java | 12 +- .../jira/service/SettingsServiceTest.java | 12 +- .../rest/SettingsGeneralResourceFuncTest.java | 5 + .../jira/rest/SettingsResourceFuncTest.java | 5 - 62 files changed, 787 insertions(+), 220 deletions(-) create mode 100644 commons/src/main/java/com/deftdevs/bootstrapi/commons/model/AuthenticationModel.java create mode 100644 commons/src/main/java/com/deftdevs/bootstrapi/commons/model/MailServerModel.java rename commons/src/main/java/com/deftdevs/bootstrapi/commons/model/{SettingsModel.java => SettingsGeneralModel.java} (86%) create mode 100644 commons/src/main/java/com/deftdevs/bootstrapi/commons/rest/AbstractSettingsGeneralResourceImpl.java delete mode 100644 commons/src/main/java/com/deftdevs/bootstrapi/commons/rest/AbstractSettingsResourceImpl.java rename commons/src/main/java/com/deftdevs/bootstrapi/commons/rest/api/{SettingsResource.java => SettingsGeneralResource.java} (86%) rename commons/src/main/java/com/deftdevs/bootstrapi/commons/service/api/{SettingsService.java => SettingsGeneralService.java} (72%) rename commons/src/test/java/com/deftdevs/bootstrapi/commons/model/{SettingsModelTest.java => SettingsGeneralModelTest.java} (100%) rename commons/src/test/java/com/deftdevs/bootstrapi/commons/rest/{SettingsResourceTest.java => SettingsGeneralResourceTest.java} (56%) create mode 100644 commons/src/test/java/com/deftdevs/bootstrapi/commons/rest/impl/TestSettingsGeneralResourceImpl.java delete mode 100644 commons/src/test/java/com/deftdevs/bootstrapi/commons/rest/impl/TestSettingsResourceImpl.java rename commons/src/test/java/it/com/deftdevs/bootstrapi/commons/rest/{AbstractSettingsResourceFuncTest.java => AbstractSettingsGeneralResourceFuncTest.java} (84%) create mode 100644 confluence/Models/SettingsGeneralModel.md create mode 100644 confluence/src/main/java/com/deftdevs/bootstrapi/confluence/model/SettingsModel.java rename confluence/src/main/java/com/deftdevs/bootstrapi/confluence/rest/{SettingsResourceImpl.java => SettingsGeneralResourceImpl.java} (69%) create mode 100644 confluence/src/main/java/com/deftdevs/bootstrapi/confluence/service/_AllServiceImpl.java create mode 100644 confluence/src/test/java/it/com/deftdevs/bootstrapi/confluence/rest/SettingsGeneralResourceFuncTest.java delete mode 100644 confluence/src/test/java/it/com/deftdevs/bootstrapi/confluence/rest/SettingsResourceFuncTest.java create mode 100644 crowd/Models/SettingsGeneralModel.md create mode 100644 crowd/src/main/java/com/deftdevs/bootstrapi/crowd/model/SettingsModel.java rename crowd/src/main/java/com/deftdevs/bootstrapi/crowd/rest/{SettingsResourceImpl.java => SettingsGeneralResourceImpl.java} (69%) create mode 100644 crowd/src/test/java/it/com/deftdevs/bootstrapi/crowd/rest/SettingsGeneralResourceFuncTest.java delete mode 100644 crowd/src/test/java/it/com/deftdevs/bootstrapi/crowd/rest/SettingsResourceFuncTest.java create mode 100644 jira/Models/SettingsGeneralModel.md create mode 100644 jira/src/main/java/com/deftdevs/bootstrapi/jira/model/SettingsModel.java rename jira/src/main/java/com/deftdevs/bootstrapi/jira/rest/{SettingsResourceImpl.java => SettingsGeneralResourceImpl.java} (69%) create mode 100644 jira/src/main/java/com/deftdevs/bootstrapi/jira/service/_AllServiceImpl.java create mode 100644 jira/src/test/java/it/com/deftdevs/bootstrapi/jira/rest/SettingsGeneralResourceFuncTest.java delete mode 100644 jira/src/test/java/it/com/deftdevs/bootstrapi/jira/rest/SettingsResourceFuncTest.java diff --git a/commons/src/main/java/com/deftdevs/bootstrapi/commons/model/AuthenticationModel.java b/commons/src/main/java/com/deftdevs/bootstrapi/commons/model/AuthenticationModel.java new file mode 100644 index 00000000..909488f4 --- /dev/null +++ b/commons/src/main/java/com/deftdevs/bootstrapi/commons/model/AuthenticationModel.java @@ -0,0 +1,25 @@ +package com.deftdevs.bootstrapi.commons.model; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; +import java.util.Map; + +import static com.deftdevs.bootstrapi.commons.constants.BootstrAPI.AUTHENTICATION; + +@Data +@NoArgsConstructor +@AllArgsConstructor +@XmlRootElement(name = AUTHENTICATION) +public class AuthenticationModel { + + @XmlElement + private Map idps; + + @XmlElement + private AuthenticationSsoModel sso; + +} diff --git a/commons/src/main/java/com/deftdevs/bootstrapi/commons/model/MailServerModel.java b/commons/src/main/java/com/deftdevs/bootstrapi/commons/model/MailServerModel.java new file mode 100644 index 00000000..0b75d942 --- /dev/null +++ b/commons/src/main/java/com/deftdevs/bootstrapi/commons/model/MailServerModel.java @@ -0,0 +1,31 @@ +package com.deftdevs.bootstrapi.commons.model; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + +import static com.deftdevs.bootstrapi.commons.constants.BootstrAPI.MAIL_SERVER; + +@Data +@NoArgsConstructor +@AllArgsConstructor +@XmlRootElement(name = MAIL_SERVER) +public class MailServerModel { + + @XmlElement + private MailServerSmtpModel smtp; + + @XmlElement + private MailServerPopModel pop; + + // Example instances for documentation and tests + + public static final MailServerModel EXAMPLE_1 = new MailServerModel( + MailServerSmtpModel.EXAMPLE_1, + MailServerPopModel.EXAMPLE_1 + ); + +} diff --git a/commons/src/main/java/com/deftdevs/bootstrapi/commons/model/SettingsModel.java b/commons/src/main/java/com/deftdevs/bootstrapi/commons/model/SettingsGeneralModel.java similarity index 86% rename from commons/src/main/java/com/deftdevs/bootstrapi/commons/model/SettingsModel.java rename to commons/src/main/java/com/deftdevs/bootstrapi/commons/model/SettingsGeneralModel.java index 1689a097..64e4f7d6 100644 --- a/commons/src/main/java/com/deftdevs/bootstrapi/commons/model/SettingsModel.java +++ b/commons/src/main/java/com/deftdevs/bootstrapi/commons/model/SettingsGeneralModel.java @@ -19,7 +19,7 @@ @AllArgsConstructor @XmlRootElement(name = BootstrAPI.SETTINGS) @XmlAccessorType(XmlAccessType.FIELD) -public class SettingsModel { +public class SettingsGeneralModel { @XmlElement private URI baseUrl; @@ -46,7 +46,7 @@ public String getMode() { // Example instances for documentation and tests - public static final SettingsModel EXAMPLE_1 = SettingsModel.builder() + public static final SettingsGeneralModel EXAMPLE_1 = SettingsGeneralModel.builder() .title("Example") .baseUrl(URI.create("https://example.com")) .mode("private") @@ -54,7 +54,7 @@ public String getMode() { .externalUserManagement(true) .build(); - public static final SettingsModel EXAMPLE_1_NO_MODE = SettingsModel.builder() + public static final SettingsGeneralModel EXAMPLE_1_NO_MODE = SettingsGeneralModel.builder() .title("Example") .baseUrl(URI.create("https://example.com")) .mode(null) diff --git a/commons/src/main/java/com/deftdevs/bootstrapi/commons/rest/AbstractSettingsGeneralResourceImpl.java b/commons/src/main/java/com/deftdevs/bootstrapi/commons/rest/AbstractSettingsGeneralResourceImpl.java new file mode 100644 index 00000000..b93da638 --- /dev/null +++ b/commons/src/main/java/com/deftdevs/bootstrapi/commons/rest/AbstractSettingsGeneralResourceImpl.java @@ -0,0 +1,31 @@ +package com.deftdevs.bootstrapi.commons.rest; + +import com.deftdevs.bootstrapi.commons.model.SettingsGeneralModel; +import com.deftdevs.bootstrapi.commons.rest.api.SettingsGeneralResource; +import com.deftdevs.bootstrapi.commons.service.api.SettingsGeneralService; + +import javax.ws.rs.core.Response; + +public abstract class AbstractSettingsGeneralResourceImpl> + implements SettingsGeneralResource { + + private final S settingsService; + + public AbstractSettingsGeneralResourceImpl( + final S settingsService) { + + this.settingsService = settingsService; + } + + @Override + public Response getSettings() { + final B settingsModel = settingsService.getSettingsGeneral(); + return Response.ok(settingsModel).build(); + } + + @Override + public Response setSettings(B settingsModel) { + final B updatedSettingsGeneralModel = settingsService.setSettingsGeneral(settingsModel); + return Response.ok(updatedSettingsGeneralModel).build(); + } +} diff --git a/commons/src/main/java/com/deftdevs/bootstrapi/commons/rest/AbstractSettingsResourceImpl.java b/commons/src/main/java/com/deftdevs/bootstrapi/commons/rest/AbstractSettingsResourceImpl.java deleted file mode 100644 index c1c4c405..00000000 --- a/commons/src/main/java/com/deftdevs/bootstrapi/commons/rest/AbstractSettingsResourceImpl.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.deftdevs.bootstrapi.commons.rest; - -import com.deftdevs.bootstrapi.commons.model.SettingsModel; -import com.deftdevs.bootstrapi.commons.rest.api.SettingsResource; -import com.deftdevs.bootstrapi.commons.service.api.SettingsService; - -import javax.ws.rs.core.Response; - -public abstract class AbstractSettingsResourceImpl> - implements SettingsResource { - - private final S settingsService; - - public AbstractSettingsResourceImpl( - final S settingsService) { - - this.settingsService = settingsService; - } - - @Override - public Response getSettings() { - final B settingsModel = settingsService.getSettingsGeneral(); - return Response.ok(settingsModel).build(); - } - - @Override - public Response setSettings(B settingsModel) { - final B updatedSettingsModel = settingsService.setSettingsGeneral(settingsModel); - return Response.ok(updatedSettingsModel).build(); - } -} diff --git a/commons/src/main/java/com/deftdevs/bootstrapi/commons/rest/api/SettingsResource.java b/commons/src/main/java/com/deftdevs/bootstrapi/commons/rest/api/SettingsGeneralResource.java similarity index 86% rename from commons/src/main/java/com/deftdevs/bootstrapi/commons/rest/api/SettingsResource.java rename to commons/src/main/java/com/deftdevs/bootstrapi/commons/rest/api/SettingsGeneralResource.java index 8e415842..6bfcbe8a 100644 --- a/commons/src/main/java/com/deftdevs/bootstrapi/commons/rest/api/SettingsResource.java +++ b/commons/src/main/java/com/deftdevs/bootstrapi/commons/rest/api/SettingsGeneralResource.java @@ -2,7 +2,7 @@ import com.deftdevs.bootstrapi.commons.constants.BootstrAPI; import com.deftdevs.bootstrapi.commons.model.ErrorCollection; -import com.deftdevs.bootstrapi.commons.model.SettingsModel; +import com.deftdevs.bootstrapi.commons.model.SettingsGeneralModel; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.media.Content; import io.swagger.v3.oas.annotations.media.Schema; @@ -12,14 +12,14 @@ import javax.ws.rs.PUT; import javax.ws.rs.core.Response; -public interface SettingsResource { +public interface SettingsGeneralResource { @GET @Operation( summary = BootstrAPI.SETTINGS_GENERAL_GET_SUMMARY, responses = { @ApiResponse( - responseCode = "200", content = @Content(schema = @Schema(implementation = SettingsModel.class)), + responseCode = "200", content = @Content(schema = @Schema(implementation = SettingsGeneralModel.class)), description = BootstrAPI.SETTINGS_GENERAL_GET_RESPONSE_DESCRIPTION ), @ApiResponse( @@ -35,7 +35,7 @@ public interface SettingsResource { summary = BootstrAPI.SETTINGS_GENERAL_PUT_SUMMARY, responses = { @ApiResponse( - responseCode = "200", content = @Content(schema = @Schema(implementation = SettingsModel.class)), + responseCode = "200", content = @Content(schema = @Schema(implementation = SettingsGeneralModel.class)), description = BootstrAPI.SETTINGS_GENERAL_PUT_RESPONSE_DESCRIPTION ), @ApiResponse( diff --git a/commons/src/main/java/com/deftdevs/bootstrapi/commons/service/api/SettingsService.java b/commons/src/main/java/com/deftdevs/bootstrapi/commons/service/api/SettingsGeneralService.java similarity index 72% rename from commons/src/main/java/com/deftdevs/bootstrapi/commons/service/api/SettingsService.java rename to commons/src/main/java/com/deftdevs/bootstrapi/commons/service/api/SettingsGeneralService.java index 7bbf8fa2..bb41c8e0 100644 --- a/commons/src/main/java/com/deftdevs/bootstrapi/commons/service/api/SettingsService.java +++ b/commons/src/main/java/com/deftdevs/bootstrapi/commons/service/api/SettingsGeneralService.java @@ -1,9 +1,9 @@ package com.deftdevs.bootstrapi.commons.service.api; -import com.deftdevs.bootstrapi.commons.model.SettingsModel; +import com.deftdevs.bootstrapi.commons.model.SettingsGeneralModel; -public interface SettingsService { +public interface SettingsGeneralService { /** * Get the settings. diff --git a/commons/src/test/java/com/deftdevs/bootstrapi/commons/model/SettingsModelTest.java b/commons/src/test/java/com/deftdevs/bootstrapi/commons/model/SettingsGeneralModelTest.java similarity index 100% rename from commons/src/test/java/com/deftdevs/bootstrapi/commons/model/SettingsModelTest.java rename to commons/src/test/java/com/deftdevs/bootstrapi/commons/model/SettingsGeneralModelTest.java diff --git a/commons/src/test/java/com/deftdevs/bootstrapi/commons/rest/SettingsResourceTest.java b/commons/src/test/java/com/deftdevs/bootstrapi/commons/rest/SettingsGeneralResourceTest.java similarity index 56% rename from commons/src/test/java/com/deftdevs/bootstrapi/commons/rest/SettingsResourceTest.java rename to commons/src/test/java/com/deftdevs/bootstrapi/commons/rest/SettingsGeneralResourceTest.java index 588bd515..327076d4 100644 --- a/commons/src/test/java/com/deftdevs/bootstrapi/commons/rest/SettingsResourceTest.java +++ b/commons/src/test/java/com/deftdevs/bootstrapi/commons/rest/SettingsGeneralResourceTest.java @@ -1,8 +1,8 @@ package com.deftdevs.bootstrapi.commons.rest; -import com.deftdevs.bootstrapi.commons.model.SettingsModel; -import com.deftdevs.bootstrapi.commons.rest.impl.TestSettingsResourceImpl; -import com.deftdevs.bootstrapi.commons.service.api.SettingsService; +import com.deftdevs.bootstrapi.commons.model.SettingsGeneralModel; +import com.deftdevs.bootstrapi.commons.rest.impl.TestSettingsGeneralResourceImpl; +import com.deftdevs.bootstrapi.commons.service.api.SettingsGeneralService; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -15,40 +15,40 @@ import static org.mockito.Mockito.doReturn; @ExtendWith(MockitoExtension.class) -class SettingsResourceTest { +class SettingsGeneralResourceTest { @Mock - private SettingsService settingsService; + private SettingsGeneralService settingsService; - private TestSettingsResourceImpl resource; + private TestSettingsGeneralResourceImpl resource; @BeforeEach public void setup() { - resource = new TestSettingsResourceImpl(settingsService); + resource = new TestSettingsGeneralResourceImpl(settingsService); } @Test void testGetSettings() { - final SettingsModel bean = SettingsModel.EXAMPLE_1; + final SettingsGeneralModel bean = SettingsGeneralModel.EXAMPLE_1; doReturn(bean).when(settingsService).getSettingsGeneral(); final Response response = resource.getSettings(); assertEquals(200, response.getStatus()); - final SettingsModel settingsModel = (SettingsModel) response.getEntity(); + final SettingsGeneralModel settingsModel = (SettingsGeneralModel) response.getEntity(); assertEquals(settingsModel, bean); } @Test void testSetSettings() { - final SettingsModel bean = SettingsModel.EXAMPLE_1; + final SettingsGeneralModel bean = SettingsGeneralModel.EXAMPLE_1; doReturn(bean).when(settingsService).setSettingsGeneral(bean); final Response response = resource.setSettings(bean); assertEquals(200, response.getStatus()); - final SettingsModel settingsModel = (SettingsModel) response.getEntity(); + final SettingsGeneralModel settingsModel = (SettingsGeneralModel) response.getEntity(); assertEquals(settingsModel, bean); } diff --git a/commons/src/test/java/com/deftdevs/bootstrapi/commons/rest/impl/TestSettingsGeneralResourceImpl.java b/commons/src/test/java/com/deftdevs/bootstrapi/commons/rest/impl/TestSettingsGeneralResourceImpl.java new file mode 100644 index 00000000..135137c6 --- /dev/null +++ b/commons/src/test/java/com/deftdevs/bootstrapi/commons/rest/impl/TestSettingsGeneralResourceImpl.java @@ -0,0 +1,12 @@ +package com.deftdevs.bootstrapi.commons.rest.impl; + +import com.deftdevs.bootstrapi.commons.rest.AbstractSettingsGeneralResourceImpl; +import com.deftdevs.bootstrapi.commons.service.api.SettingsGeneralService; + +public class TestSettingsGeneralResourceImpl extends AbstractSettingsGeneralResourceImpl { + + public TestSettingsGeneralResourceImpl(SettingsGeneralService settingsService) { + super(settingsService); + } + +} diff --git a/commons/src/test/java/com/deftdevs/bootstrapi/commons/rest/impl/TestSettingsResourceImpl.java b/commons/src/test/java/com/deftdevs/bootstrapi/commons/rest/impl/TestSettingsResourceImpl.java deleted file mode 100644 index db9c2e44..00000000 --- a/commons/src/test/java/com/deftdevs/bootstrapi/commons/rest/impl/TestSettingsResourceImpl.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.deftdevs.bootstrapi.commons.rest.impl; - -import com.deftdevs.bootstrapi.commons.rest.AbstractSettingsResourceImpl; -import com.deftdevs.bootstrapi.commons.service.api.SettingsService; - -public class TestSettingsResourceImpl extends AbstractSettingsResourceImpl { - - public TestSettingsResourceImpl(SettingsService settingsService) { - super(settingsService); - } - -} diff --git a/commons/src/test/java/it/com/deftdevs/bootstrapi/commons/rest/AbstractSettingsResourceFuncTest.java b/commons/src/test/java/it/com/deftdevs/bootstrapi/commons/rest/AbstractSettingsGeneralResourceFuncTest.java similarity index 84% rename from commons/src/test/java/it/com/deftdevs/bootstrapi/commons/rest/AbstractSettingsResourceFuncTest.java rename to commons/src/test/java/it/com/deftdevs/bootstrapi/commons/rest/AbstractSettingsGeneralResourceFuncTest.java index 91266a6f..88cb147f 100644 --- a/commons/src/test/java/it/com/deftdevs/bootstrapi/commons/rest/AbstractSettingsResourceFuncTest.java +++ b/commons/src/test/java/it/com/deftdevs/bootstrapi/commons/rest/AbstractSettingsGeneralResourceFuncTest.java @@ -1,7 +1,7 @@ package it.com.deftdevs.bootstrapi.commons.rest; import com.deftdevs.bootstrapi.commons.constants.BootstrAPI; -import com.deftdevs.bootstrapi.commons.model.SettingsModel; +import com.deftdevs.bootstrapi.commons.model.SettingsGeneralModel; import com.fasterxml.jackson.databind.ObjectMapper; import org.junit.jupiter.api.Test; @@ -11,7 +11,7 @@ import static org.junit.jupiter.api.Assertions.*; -public abstract class AbstractSettingsResourceFuncTest { +public abstract class AbstractSettingsGeneralResourceFuncTest { private final ObjectMapper objectMapper = new ObjectMapper(); @@ -21,7 +21,7 @@ void testGetSettings() throws Exception { .request(); assertEquals(Response.Status.OK.getStatusCode(), settingsResponse.statusCode()); - final SettingsModel settingsModel = objectMapper.readValue(settingsResponse.body(), SettingsModel.class); + final SettingsGeneralModel settingsModel = objectMapper.readValue(settingsResponse.body(), SettingsGeneralModel.class); assertNotNull(settingsModel.getTitle()); } @@ -31,7 +31,7 @@ void testSetSettings() throws Exception { .request(HttpMethod.PUT, getExampleModel()); assertEquals(Response.Status.OK.getStatusCode(), settingsResponse.statusCode()); - final SettingsModel settingsModel = objectMapper.readValue(settingsResponse.body(), SettingsModel.class); + final SettingsGeneralModel settingsModel = objectMapper.readValue(settingsResponse.body(), SettingsGeneralModel.class); assertEquals(getExampleModel(), settingsModel); } @@ -73,7 +73,7 @@ void testSetSettingsUnauthorized() throws Exception { assertEquals(Response.Status.FORBIDDEN.getStatusCode(), settingsResponse.statusCode()); } - protected SettingsModel getExampleModel() { - return SettingsModel.EXAMPLE_1; + protected SettingsGeneralModel getExampleModel() { + return SettingsGeneralModel.EXAMPLE_1; } } diff --git a/confluence/Apis/AllApi.md b/confluence/Apis/AllApi.md index 99f0bab6..2ee156ed 100644 --- a/confluence/Apis/AllApi.md +++ b/confluence/Apis/AllApi.md @@ -9,7 +9,7 @@ All URIs are relative to *https://CONFLUENCE_URL/rest/bootstrapi/1* # **setAll** -> SettingsModel setAll(\_AllModel) +> _AllModel setAll(\_AllModel) _all @@ -21,7 +21,7 @@ _all ### Return type -[**SettingsModel**](../Models/SettingsModel.md) +[**_AllModel**](../Models/_AllModel.md) ### Authorization diff --git a/confluence/Apis/SettingsApi.md b/confluence/Apis/SettingsApi.md index ced46831..723e19c3 100644 --- a/confluence/Apis/SettingsApi.md +++ b/confluence/Apis/SettingsApi.md @@ -108,7 +108,7 @@ This endpoint does not need any parameter. # **getSettings** -> SettingsModel getSettings() +> SettingsGeneralModel getSettings() Get the general settings @@ -117,7 +117,7 @@ This endpoint does not need any parameter. ### Return type -[**SettingsModel**](../Models/SettingsModel.md) +[**SettingsGeneralModel**](../Models/SettingsGeneralModel.md) ### Authorization @@ -252,7 +252,7 @@ Set the custom HTML # **setSettings** -> SettingsModel setSettings(SettingsModel) +> SettingsGeneralModel setSettings(SettingsGeneralModel) Set the general settings @@ -260,11 +260,11 @@ Set the general settings |Name | Type | Description | Notes | |------------- | ------------- | ------------- | -------------| -| **SettingsModel** | [**SettingsModel**](../Models/SettingsModel.md)| | [optional] | +| **SettingsGeneralModel** | [**SettingsGeneralModel**](../Models/SettingsGeneralModel.md)| | [optional] | ### Return type -[**SettingsModel**](../Models/SettingsModel.md) +[**SettingsGeneralModel**](../Models/SettingsGeneralModel.md) ### Authorization diff --git a/confluence/Models/SettingsGeneralModel.md b/confluence/Models/SettingsGeneralModel.md new file mode 100644 index 00000000..8ebe677b --- /dev/null +++ b/confluence/Models/SettingsGeneralModel.md @@ -0,0 +1,13 @@ +# SettingsGeneralModel +## Properties + +| Name | Type | Description | Notes | +|------------ | ------------- | ------------- | -------------| +| **baseUrl** | **URI** | | [optional] [default to null] | +| **mode** | **String** | | [optional] [default to null] | +| **title** | **String** | | [optional] [default to null] | +| **contactMessage** | **String** | | [optional] [default to null] | +| **externalUserManagement** | **Boolean** | | [optional] [default to null] | + +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) + diff --git a/confluence/Models/SettingsModel.md b/confluence/Models/SettingsModel.md index f4eb0e7f..a9c90eac 100644 --- a/confluence/Models/SettingsModel.md +++ b/confluence/Models/SettingsModel.md @@ -3,11 +3,10 @@ | Name | Type | Description | Notes | |------------ | ------------- | ------------- | -------------| -| **baseUrl** | **URI** | | [optional] [default to null] | -| **mode** | **String** | | [optional] [default to null] | -| **title** | **String** | | [optional] [default to null] | -| **contactMessage** | **String** | | [optional] [default to null] | -| **externalUserManagement** | **Boolean** | | [optional] [default to null] | +| **general** | [**SettingsGeneralModel**](SettingsGeneralModel.md) | | [optional] [default to null] | +| **security** | [**SettingsSecurityModel**](SettingsSecurityModel.md) | | [optional] [default to null] | +| **branding** | [**SettingsBrandingColorSchemeModel**](SettingsBrandingColorSchemeModel.md) | | [optional] [default to null] | +| **customHtml** | [**SettingsCustomHtmlModel**](SettingsCustomHtmlModel.md) | | [optional] [default to null] | [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/confluence/Models/_AllModel.md b/confluence/Models/_AllModel.md index 34153397..cd6000f3 100644 --- a/confluence/Models/_AllModel.md +++ b/confluence/Models/_AllModel.md @@ -4,8 +4,12 @@ | Name | Type | Description | Notes | |------------ | ------------- | ------------- | -------------| | **settings** | [**SettingsModel**](SettingsModel.md) | | [optional] [default to null] | -| **users** | [**Map**](UserModel.md) | | [optional] [default to null] | -| **groups** | [**Map**](GroupModel.md) | | [optional] [default to null] | +| **directories** | [**Map**](AbstractDirectoryModel.md) | | [optional] [default to null] | +| **applicationLinks** | [**Map**](ApplicationLinkModel.md) | | [optional] [default to null] | +| **authentication** | [**AuthenticationModel**](AuthenticationModel.md) | | [optional] [default to null] | +| **licenses** | **List** | | [optional] [default to null] | +| **mailServer** | [**MailServerModel**](MailServerModel.md) | | [optional] [default to null] | +| **permissionsGlobal** | [**PermissionsGlobalModel**](PermissionsGlobalModel.md) | | [optional] [default to null] | | **status** | [**Map**](_AllModelStatus.md) | | [optional] [default to null] | [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/confluence/README.md b/confluence/README.md index 2b15d90f..1487b2b2 100644 --- a/confluence/README.md +++ b/confluence/README.md @@ -92,6 +92,7 @@ All URIs are relative to *https://CONFLUENCE_URL/rest/bootstrapi/1* - [PermissionsGlobalModel](./Models/PermissionsGlobalModel.md) - [SettingsBrandingColorSchemeModel](./Models/SettingsBrandingColorSchemeModel.md) - [SettingsCustomHtmlModel](./Models/SettingsCustomHtmlModel.md) + - [SettingsGeneralModel](./Models/SettingsGeneralModel.md) - [SettingsModel](./Models/SettingsModel.md) - [SettingsSecurityModel](./Models/SettingsSecurityModel.md) - [UserModel](./Models/UserModel.md) diff --git a/confluence/src/main/java/com/deftdevs/bootstrapi/confluence/config/ServiceConfig.java b/confluence/src/main/java/com/deftdevs/bootstrapi/confluence/config/ServiceConfig.java index d0f39f51..c9e079ea 100644 --- a/confluence/src/main/java/com/deftdevs/bootstrapi/confluence/config/ServiceConfig.java +++ b/confluence/src/main/java/com/deftdevs/bootstrapi/confluence/config/ServiceConfig.java @@ -1,6 +1,7 @@ package com.deftdevs.bootstrapi.confluence.config; import com.deftdevs.bootstrapi.commons.service.api.*; +import com.deftdevs.bootstrapi.confluence.model._AllModel; import com.deftdevs.bootstrapi.confluence.service.*; import com.deftdevs.bootstrapi.confluence.service.api.CachesService; import com.deftdevs.bootstrapi.confluence.service.api.ConfluenceAuthenticationService; @@ -18,6 +19,19 @@ public class ServiceConfig { @Autowired private HelperConfig helperConfig; + @Bean + public _AllService<_AllModel> _allService() { + return new _AllServiceImpl( + confluenceSettingsService(), + directoriesService(), + applicationLinksService(), + confluenceAuthenticationService(), + licensesService(), + mailServerService(), + permissionsService(), + settingsBrandingService()); + } + @Bean public ApplicationLinksService applicationLinksService() { return new ApplicationLinksServiceImpl( diff --git a/confluence/src/main/java/com/deftdevs/bootstrapi/confluence/model/SettingsModel.java b/confluence/src/main/java/com/deftdevs/bootstrapi/confluence/model/SettingsModel.java new file mode 100644 index 00000000..a03142a0 --- /dev/null +++ b/confluence/src/main/java/com/deftdevs/bootstrapi/confluence/model/SettingsModel.java @@ -0,0 +1,33 @@ +package com.deftdevs.bootstrapi.confluence.model; + +import com.deftdevs.bootstrapi.commons.model.SettingsBrandingColorSchemeModel; +import com.deftdevs.bootstrapi.commons.model.SettingsGeneralModel; +import com.deftdevs.bootstrapi.commons.model.SettingsSecurityModel; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + +import static com.deftdevs.bootstrapi.commons.constants.BootstrAPI.SETTINGS; + +@Data +@NoArgsConstructor +@AllArgsConstructor +@XmlRootElement(name = SETTINGS) +public class SettingsModel { + + @XmlElement + private SettingsGeneralModel general; + + @XmlElement + private SettingsSecurityModel security; + + @XmlElement + private SettingsBrandingColorSchemeModel branding; + + @XmlElement + private SettingsCustomHtmlModel customHtml; + +} diff --git a/confluence/src/main/java/com/deftdevs/bootstrapi/confluence/model/_AllModel.java b/confluence/src/main/java/com/deftdevs/bootstrapi/confluence/model/_AllModel.java index 486353bd..230a91df 100644 --- a/confluence/src/main/java/com/deftdevs/bootstrapi/confluence/model/_AllModel.java +++ b/confluence/src/main/java/com/deftdevs/bootstrapi/confluence/model/_AllModel.java @@ -1,8 +1,11 @@ package com.deftdevs.bootstrapi.confluence.model; -import com.deftdevs.bootstrapi.commons.model.GroupModel; -import com.deftdevs.bootstrapi.commons.model.SettingsModel; -import com.deftdevs.bootstrapi.commons.model.UserModel; +import com.deftdevs.bootstrapi.commons.constants.BootstrAPI; +import com.deftdevs.bootstrapi.commons.model.AbstractDirectoryModel; +import com.deftdevs.bootstrapi.commons.model.ApplicationLinkModel; +import com.deftdevs.bootstrapi.commons.model.AuthenticationModel; +import com.deftdevs.bootstrapi.commons.model.MailServerModel; +import com.deftdevs.bootstrapi.commons.model.PermissionsGlobalModel; import com.deftdevs.bootstrapi.commons.model.type._AllModelAccessor; import com.deftdevs.bootstrapi.commons.model.type._AllModelStatus; import lombok.AllArgsConstructor; @@ -11,22 +14,35 @@ import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; +import java.util.List; import java.util.Map; @Data @NoArgsConstructor @AllArgsConstructor -@XmlRootElement(name = "all") +@XmlRootElement(name = BootstrAPI._ALL) public class _AllModel implements _AllModelAccessor { @XmlElement private SettingsModel settings; @XmlElement - private Map users; + private Map directories; @XmlElement - private Map groups; + private Map applicationLinks; + + @XmlElement + private AuthenticationModel authentication; + + @XmlElement + private List licenses; + + @XmlElement + private MailServerModel mailServer; + + @XmlElement + private PermissionsGlobalModel permissionsGlobal; @XmlElement private Map status; diff --git a/confluence/src/main/java/com/deftdevs/bootstrapi/confluence/rest/SettingsResourceImpl.java b/confluence/src/main/java/com/deftdevs/bootstrapi/confluence/rest/SettingsGeneralResourceImpl.java similarity index 69% rename from confluence/src/main/java/com/deftdevs/bootstrapi/confluence/rest/SettingsResourceImpl.java rename to confluence/src/main/java/com/deftdevs/bootstrapi/confluence/rest/SettingsGeneralResourceImpl.java index 8809c6c3..948a1436 100644 --- a/confluence/src/main/java/com/deftdevs/bootstrapi/confluence/rest/SettingsResourceImpl.java +++ b/confluence/src/main/java/com/deftdevs/bootstrapi/confluence/rest/SettingsGeneralResourceImpl.java @@ -2,8 +2,8 @@ import com.atlassian.plugins.rest.api.security.annotation.SystemAdminOnly; import com.deftdevs.bootstrapi.commons.constants.BootstrAPI; -import com.deftdevs.bootstrapi.commons.model.SettingsModel; -import com.deftdevs.bootstrapi.commons.rest.AbstractSettingsResourceImpl; +import com.deftdevs.bootstrapi.commons.model.SettingsGeneralModel; +import com.deftdevs.bootstrapi.commons.rest.AbstractSettingsGeneralResourceImpl; import com.deftdevs.bootstrapi.confluence.service.api.ConfluenceSettingsService; import io.swagger.v3.oas.annotations.tags.Tag; @@ -18,10 +18,10 @@ @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) @SystemAdminOnly -public class SettingsResourceImpl extends AbstractSettingsResourceImpl { +public class SettingsGeneralResourceImpl extends AbstractSettingsGeneralResourceImpl { @Inject - public SettingsResourceImpl( + public SettingsGeneralResourceImpl( final ConfluenceSettingsService settingsService) { super(settingsService); diff --git a/confluence/src/main/java/com/deftdevs/bootstrapi/confluence/service/SettingsServiceImpl.java b/confluence/src/main/java/com/deftdevs/bootstrapi/confluence/service/SettingsServiceImpl.java index 645bc895..438a4d42 100644 --- a/confluence/src/main/java/com/deftdevs/bootstrapi/confluence/service/SettingsServiceImpl.java +++ b/confluence/src/main/java/com/deftdevs/bootstrapi/confluence/service/SettingsServiceImpl.java @@ -3,7 +3,7 @@ import com.atlassian.confluence.setup.settings.CustomHtmlSettings; import com.atlassian.confluence.setup.settings.GlobalSettingsManager; import com.atlassian.confluence.setup.settings.Settings; -import com.deftdevs.bootstrapi.commons.model.SettingsModel; +import com.deftdevs.bootstrapi.commons.model.SettingsGeneralModel; import com.deftdevs.bootstrapi.commons.model.SettingsSecurityModel; import com.deftdevs.bootstrapi.confluence.model.SettingsCustomHtmlModel; import com.deftdevs.bootstrapi.confluence.service.api.ConfluenceSettingsService; @@ -21,10 +21,10 @@ public SettingsServiceImpl( } @Override - public SettingsModel getSettingsGeneral() { + public SettingsGeneralModel getSettingsGeneral() { final Settings settings = globalSettingsManager.getGlobalSettings(); - return SettingsModel.builder() + return SettingsGeneralModel.builder() .baseUrl(URI.create(settings.getBaseUrl())) .title(settings.getSiteTitle()) .contactMessage(settings.getCustomContactMessage()) @@ -33,7 +33,7 @@ public SettingsModel getSettingsGeneral() { } @Override - public SettingsModel setSettingsGeneral(SettingsModel settingsModel) { + public SettingsGeneralModel setSettingsGeneral(SettingsGeneralModel settingsModel) { final Settings settings = globalSettingsManager.getGlobalSettings(); if (settingsModel.getBaseUrl() != null) { diff --git a/confluence/src/main/java/com/deftdevs/bootstrapi/confluence/service/_AllServiceImpl.java b/confluence/src/main/java/com/deftdevs/bootstrapi/confluence/service/_AllServiceImpl.java new file mode 100644 index 00000000..568cf721 --- /dev/null +++ b/confluence/src/main/java/com/deftdevs/bootstrapi/confluence/service/_AllServiceImpl.java @@ -0,0 +1,112 @@ +package com.deftdevs.bootstrapi.confluence.service; + +import com.deftdevs.bootstrapi.commons.model.AuthenticationModel; +import com.deftdevs.bootstrapi.commons.model.MailServerModel; +import com.deftdevs.bootstrapi.commons.model.type._AllModelStatus; +import com.deftdevs.bootstrapi.commons.service._AbstractAllServiceImpl; +import com.deftdevs.bootstrapi.commons.service.api.ApplicationLinksService; +import com.deftdevs.bootstrapi.commons.service.api.DirectoriesService; +import com.deftdevs.bootstrapi.commons.service.api.LicensesService; +import com.deftdevs.bootstrapi.commons.service.api.MailServerService; +import com.deftdevs.bootstrapi.commons.service.api.PermissionsService; +import com.deftdevs.bootstrapi.commons.service.api.SettingsBrandingService; +import com.deftdevs.bootstrapi.confluence.model.SettingsModel; +import com.deftdevs.bootstrapi.confluence.model._AllModel; +import com.deftdevs.bootstrapi.confluence.service.api.ConfluenceAuthenticationService; +import com.deftdevs.bootstrapi.confluence.service.api.ConfluenceSettingsService; + +import java.util.HashMap; +import java.util.Map; + +public class _AllServiceImpl extends _AbstractAllServiceImpl<_AllModel> { + + private final ConfluenceSettingsService settingsService; + private final DirectoriesService directoriesService; + private final ApplicationLinksService applicationLinksService; + private final ConfluenceAuthenticationService authenticationService; + private final LicensesService licensesService; + private final MailServerService mailServerService; + private final PermissionsService permissionsService; + private final SettingsBrandingService settingsBrandingService; + + public _AllServiceImpl( + final ConfluenceSettingsService settingsService, + final DirectoriesService directoriesService, + final ApplicationLinksService applicationLinksService, + final ConfluenceAuthenticationService authenticationService, + final LicensesService licensesService, + final MailServerService mailServerService, + final PermissionsService permissionsService, + final SettingsBrandingService settingsBrandingService) { + + this.settingsService = settingsService; + this.directoriesService = directoriesService; + this.applicationLinksService = applicationLinksService; + this.authenticationService = authenticationService; + this.licensesService = licensesService; + this.mailServerService = mailServerService; + this.permissionsService = permissionsService; + this.settingsBrandingService = settingsBrandingService; + } + + @Override + public _AllModel setAll( + final _AllModel allModel) { + + final _AllModel result = new _AllModel(); + final Map statusMap = new HashMap<>(); + + // Settings wrapper + final SettingsModel settingsInput = allModel.getSettings(); + if (settingsInput != null) { + final SettingsModel settingsResult = new SettingsModel(); + setEntity("settings/general", settingsInput.getGeneral(), + settingsService::setSettingsGeneral, settingsResult::setGeneral, statusMap); + setEntity("settings/security", settingsInput.getSecurity(), + settingsService::setSettingsSecurity, settingsResult::setSecurity, statusMap); + setEntity("settings/branding", settingsInput.getBranding(), + settingsBrandingService::setColourScheme, settingsResult::setBranding, statusMap); + setEntity("settings/customHtml", settingsInput.getCustomHtml(), + settingsService::setCustomHtml, settingsResult::setCustomHtml, statusMap); + result.setSettings(settingsResult); + } + + setEntities("directories", allModel.getDirectories(), + directoriesService::setDirectories, result::setDirectories, statusMap); + + setEntities("applicationLinks", allModel.getApplicationLinks(), + applicationLinksService::setApplicationLinks, result::setApplicationLinks, statusMap); + + // Authentication wrapper + final AuthenticationModel authInput = allModel.getAuthentication(); + if (authInput != null) { + final AuthenticationModel authResult = new AuthenticationModel(); + setEntities("authentication/idps", authInput.getIdps(), + authenticationService::setAuthenticationIdps, authResult::setIdps, statusMap); + setEntity("authentication/sso", authInput.getSso(), + authenticationService::setAuthenticationSso, authResult::setSso, statusMap); + result.setAuthentication(authResult); + } + + setEntity("licenses", allModel.getLicenses(), + keys -> { licensesService.setLicenses(keys); return keys; }, + result::setLicenses, statusMap); + + // Mail server wrapper + final MailServerModel mailServerInput = allModel.getMailServer(); + if (mailServerInput != null) { + final MailServerModel mailServerResult = new MailServerModel(); + setEntity("mailServer/smtp", mailServerInput.getSmtp(), + mailServerService::setMailServerSmtp, mailServerResult::setSmtp, statusMap); + setEntity("mailServer/pop", mailServerInput.getPop(), + mailServerService::setMailServerPop, mailServerResult::setPop, statusMap); + result.setMailServer(mailServerResult); + } + + setEntity("permissionsGlobal", allModel.getPermissionsGlobal(), + permissionsService::setPermissionsGlobal, result::setPermissionsGlobal, statusMap); + + result.setStatus(statusMap); + return result; + } +} diff --git a/confluence/src/main/java/com/deftdevs/bootstrapi/confluence/service/api/ConfluenceSettingsService.java b/confluence/src/main/java/com/deftdevs/bootstrapi/confluence/service/api/ConfluenceSettingsService.java index cb60ebc7..a820dea6 100644 --- a/confluence/src/main/java/com/deftdevs/bootstrapi/confluence/service/api/ConfluenceSettingsService.java +++ b/confluence/src/main/java/com/deftdevs/bootstrapi/confluence/service/api/ConfluenceSettingsService.java @@ -1,13 +1,13 @@ package com.deftdevs.bootstrapi.confluence.service.api; -import com.deftdevs.bootstrapi.commons.model.SettingsModel; +import com.deftdevs.bootstrapi.commons.model.SettingsGeneralModel; import com.deftdevs.bootstrapi.commons.model.SettingsSecurityModel; import com.deftdevs.bootstrapi.commons.service.api.SettingsSecurityService; -import com.deftdevs.bootstrapi.commons.service.api.SettingsService; +import com.deftdevs.bootstrapi.commons.service.api.SettingsGeneralService; import com.deftdevs.bootstrapi.confluence.model.SettingsCustomHtmlModel; public interface ConfluenceSettingsService extends - SettingsService, + SettingsGeneralService, SettingsSecurityService { SettingsCustomHtmlModel getCustomHtml(); diff --git a/confluence/src/test/java/com/deftdevs/bootstrapi/confluence/service/SettingsServiceTest.java b/confluence/src/test/java/com/deftdevs/bootstrapi/confluence/service/SettingsServiceTest.java index 06f07919..c0315750 100644 --- a/confluence/src/test/java/com/deftdevs/bootstrapi/confluence/service/SettingsServiceTest.java +++ b/confluence/src/test/java/com/deftdevs/bootstrapi/confluence/service/SettingsServiceTest.java @@ -5,7 +5,7 @@ import com.atlassian.confluence.setup.settings.CustomHtmlSettings; import com.atlassian.confluence.setup.settings.GlobalSettingsManager; import com.atlassian.confluence.setup.settings.Settings; -import com.deftdevs.bootstrapi.commons.model.SettingsModel; +import com.deftdevs.bootstrapi.commons.model.SettingsGeneralModel; import com.deftdevs.bootstrapi.commons.model.SettingsSecurityModel; import com.deftdevs.bootstrapi.confluence.model.SettingsCustomHtmlModel; import org.junit.jupiter.api.BeforeEach; @@ -39,9 +39,9 @@ void testGetSettingsGeneral() { doReturn(settings).when(globalSettingsManager).getGlobalSettings(); - final SettingsModel settingsModel = settingsService.getSettingsGeneral(); + final SettingsGeneralModel settingsModel = settingsService.getSettingsGeneral(); - final SettingsModel settingsModelRef = SettingsModel.builder() + final SettingsGeneralModel settingsModelRef = SettingsGeneralModel.builder() .baseUrl(URI.create(settings.getBaseUrl())) .title(settings.getSiteTitle()) .contactMessage(settings.getCustomContactMessage()) @@ -58,20 +58,20 @@ void testSetSettingsGeneral() { final Settings updateSettings = new OtherTestSettings(); - final SettingsModel requestModel = SettingsModel.builder() + final SettingsGeneralModel requestModel = SettingsGeneralModel.builder() .baseUrl(URI.create(updateSettings.getBaseUrl())) .title(updateSettings.getSiteTitle()) .contactMessage(updateSettings.getCustomContactMessage()) .externalUserManagement(updateSettings.isExternalUserManagement()) .build(); - final SettingsModel responseModel = settingsService.setSettingsGeneral(requestModel); + final SettingsGeneralModel responseModel = settingsService.setSettingsGeneral(requestModel); final ArgumentCaptor settingsCaptor = ArgumentCaptor.forClass(Settings.class); verify(globalSettingsManager).updateGlobalSettings(settingsCaptor.capture()); final Settings settings = settingsCaptor.getValue(); - final SettingsModel settingsModel = SettingsModel.builder() + final SettingsGeneralModel settingsModel = SettingsGeneralModel.builder() .baseUrl(URI.create(settings.getBaseUrl())) .title(settings.getSiteTitle()) .contactMessage(settings.getCustomContactMessage()) @@ -84,7 +84,7 @@ void testSetSettingsGeneral() { @Test void testSetSettingsDefaultConfig(){ - final SettingsModel settingsModel = SettingsModel.builder().build(); + final SettingsGeneralModel settingsModel = SettingsGeneralModel.builder().build(); final Settings defaultSettings = new DefaultTestSettings(); doReturn(defaultSettings).when(globalSettingsManager).getGlobalSettings(); diff --git a/confluence/src/test/java/it/com/deftdevs/bootstrapi/confluence/rest/SettingsGeneralResourceFuncTest.java b/confluence/src/test/java/it/com/deftdevs/bootstrapi/confluence/rest/SettingsGeneralResourceFuncTest.java new file mode 100644 index 00000000..0ce82df3 --- /dev/null +++ b/confluence/src/test/java/it/com/deftdevs/bootstrapi/confluence/rest/SettingsGeneralResourceFuncTest.java @@ -0,0 +1,12 @@ +package it.com.deftdevs.bootstrapi.confluence.rest; + +import com.deftdevs.bootstrapi.commons.model.SettingsGeneralModel; +import it.com.deftdevs.bootstrapi.commons.rest.AbstractSettingsGeneralResourceFuncTest; + +public class SettingsGeneralResourceFuncTest extends AbstractSettingsGeneralResourceFuncTest { + + @Override + protected SettingsGeneralModel getExampleModel() { + return SettingsGeneralModel.EXAMPLE_1_NO_MODE; + } +} diff --git a/confluence/src/test/java/it/com/deftdevs/bootstrapi/confluence/rest/SettingsResourceFuncTest.java b/confluence/src/test/java/it/com/deftdevs/bootstrapi/confluence/rest/SettingsResourceFuncTest.java deleted file mode 100644 index fbfb0ebb..00000000 --- a/confluence/src/test/java/it/com/deftdevs/bootstrapi/confluence/rest/SettingsResourceFuncTest.java +++ /dev/null @@ -1,12 +0,0 @@ -package it.com.deftdevs.bootstrapi.confluence.rest; - -import com.deftdevs.bootstrapi.commons.model.SettingsModel; -import it.com.deftdevs.bootstrapi.commons.rest.AbstractSettingsResourceFuncTest; - -public class SettingsResourceFuncTest extends AbstractSettingsResourceFuncTest { - - @Override - protected SettingsModel getExampleModel() { - return SettingsModel.EXAMPLE_1_NO_MODE; - } -} diff --git a/crowd/Apis/AllApi.md b/crowd/Apis/AllApi.md index e5c536e4..dadcc835 100644 --- a/crowd/Apis/AllApi.md +++ b/crowd/Apis/AllApi.md @@ -9,7 +9,7 @@ All URIs are relative to *https://CROWD_URL/rest/bootstrapi/1* # **setAll** -> SettingsModel setAll(\_AllModel) +> _AllModel setAll(\_AllModel) _all @@ -21,7 +21,7 @@ _all ### Return type -[**SettingsModel**](../Models/SettingsModel.md) +[**_AllModel**](../Models/_AllModel.md) ### Authorization diff --git a/crowd/Apis/SettingsApi.md b/crowd/Apis/SettingsApi.md index 7b783d13..a9b82cdd 100644 --- a/crowd/Apis/SettingsApi.md +++ b/crowd/Apis/SettingsApi.md @@ -35,7 +35,7 @@ This endpoint does not need any parameter. # **getSettings** -> SettingsModel getSettings() +> SettingsGeneralModel getSettings() Get the general settings @@ -44,7 +44,7 @@ This endpoint does not need any parameter. ### Return type -[**SettingsModel**](../Models/SettingsModel.md) +[**SettingsGeneralModel**](../Models/SettingsGeneralModel.md) ### Authorization @@ -107,7 +107,7 @@ Set the logo # **setSettings** -> SettingsModel setSettings(SettingsModel) +> SettingsGeneralModel setSettings(SettingsGeneralModel) Set the general settings @@ -115,11 +115,11 @@ Set the general settings |Name | Type | Description | Notes | |------------- | ------------- | ------------- | -------------| -| **SettingsModel** | [**SettingsModel**](../Models/SettingsModel.md)| | [optional] | +| **SettingsGeneralModel** | [**SettingsGeneralModel**](../Models/SettingsGeneralModel.md)| | [optional] | ### Return type -[**SettingsModel**](../Models/SettingsModel.md) +[**SettingsGeneralModel**](../Models/SettingsGeneralModel.md) ### Authorization diff --git a/crowd/Models/SettingsGeneralModel.md b/crowd/Models/SettingsGeneralModel.md new file mode 100644 index 00000000..8ebe677b --- /dev/null +++ b/crowd/Models/SettingsGeneralModel.md @@ -0,0 +1,13 @@ +# SettingsGeneralModel +## Properties + +| Name | Type | Description | Notes | +|------------ | ------------- | ------------- | -------------| +| **baseUrl** | **URI** | | [optional] [default to null] | +| **mode** | **String** | | [optional] [default to null] | +| **title** | **String** | | [optional] [default to null] | +| **contactMessage** | **String** | | [optional] [default to null] | +| **externalUserManagement** | **Boolean** | | [optional] [default to null] | + +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) + diff --git a/crowd/Models/SettingsModel.md b/crowd/Models/SettingsModel.md index f4eb0e7f..6a6a5063 100644 --- a/crowd/Models/SettingsModel.md +++ b/crowd/Models/SettingsModel.md @@ -3,11 +3,8 @@ | Name | Type | Description | Notes | |------------ | ------------- | ------------- | -------------| -| **baseUrl** | **URI** | | [optional] [default to null] | -| **mode** | **String** | | [optional] [default to null] | -| **title** | **String** | | [optional] [default to null] | -| **contactMessage** | **String** | | [optional] [default to null] | -| **externalUserManagement** | **Boolean** | | [optional] [default to null] | +| **general** | [**SettingsGeneralModel**](SettingsGeneralModel.md) | | [optional] [default to null] | +| **branding** | [**SettingsBrandingLoginPageModel**](SettingsBrandingLoginPageModel.md) | | [optional] [default to null] | [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/crowd/Models/_AllModel.md b/crowd/Models/_AllModel.md index c7e7c5d1..32538708 100644 --- a/crowd/Models/_AllModel.md +++ b/crowd/Models/_AllModel.md @@ -4,8 +4,14 @@ | Name | Type | Description | Notes | |------------ | ------------- | ------------- | -------------| | **settings** | [**SettingsModel**](SettingsModel.md) | | [optional] [default to null] | -| **applications** | [**Map**](ApplicationModel.md) | | [optional] [default to null] | | **directories** | [**Map**](AbstractDirectoryModel.md) | | [optional] [default to null] | +| **applications** | [**Map**](ApplicationModel.md) | | [optional] [default to null] | +| **applicationLinks** | [**Map**](ApplicationLinkModel.md) | | [optional] [default to null] | +| **licenses** | **List** | | [optional] [default to null] | +| **mailServer** | [**MailServerModel**](MailServerModel.md) | | [optional] [default to null] | +| **mailTemplates** | [**MailTemplatesModel**](MailTemplatesModel.md) | | [optional] [default to null] | +| **sessionConfig** | [**SessionConfigModel**](SessionConfigModel.md) | | [optional] [default to null] | +| **trustedProxies** | **List** | | [optional] [default to null] | | **status** | [**Map**](_AllModelStatus.md) | | [optional] [default to null] | [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/crowd/README.md b/crowd/README.md index b78b7fd1..1332e75e 100644 --- a/crowd/README.md +++ b/crowd/README.md @@ -88,6 +88,7 @@ All URIs are relative to *https://CROWD_URL/rest/bootstrapi/1* - [MailTemplatesModel](./Models/MailTemplatesModel.md) - [SessionConfigModel](./Models/SessionConfigModel.md) - [SettingsBrandingLoginPageModel](./Models/SettingsBrandingLoginPageModel.md) + - [SettingsGeneralModel](./Models/SettingsGeneralModel.md) - [SettingsModel](./Models/SettingsModel.md) - [UserModel](./Models/UserModel.md) - [_AllModel](./Models/_AllModel.md) diff --git a/crowd/src/main/java/com/deftdevs/bootstrapi/crowd/config/ServiceConfig.java b/crowd/src/main/java/com/deftdevs/bootstrapi/crowd/config/ServiceConfig.java index 3bdddb4d..061042a0 100644 --- a/crowd/src/main/java/com/deftdevs/bootstrapi/crowd/config/ServiceConfig.java +++ b/crowd/src/main/java/com/deftdevs/bootstrapi/crowd/config/ServiceConfig.java @@ -21,8 +21,15 @@ public class ServiceConfig { public _AllService<_AllModel> _allService() { return new _AllServiceImpl( crowdSettingsGeneralService(), + settingsBrandingService(), directoriesService(), - applicationsService()); + applicationsService(), + applicationLinksService(), + licensesService(), + mailServerService(), + mailTemplatesService(), + sessionConfigService(), + trustedProxiesService()); } @Bean diff --git a/crowd/src/main/java/com/deftdevs/bootstrapi/crowd/model/SettingsModel.java b/crowd/src/main/java/com/deftdevs/bootstrapi/crowd/model/SettingsModel.java new file mode 100644 index 00000000..d698125d --- /dev/null +++ b/crowd/src/main/java/com/deftdevs/bootstrapi/crowd/model/SettingsModel.java @@ -0,0 +1,25 @@ +package com.deftdevs.bootstrapi.crowd.model; + +import com.deftdevs.bootstrapi.commons.model.SettingsGeneralModel; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + +import static com.deftdevs.bootstrapi.commons.constants.BootstrAPI.SETTINGS; + +@Data +@NoArgsConstructor +@AllArgsConstructor +@XmlRootElement(name = SETTINGS) +public class SettingsModel { + + @XmlElement + private SettingsGeneralModel general; + + @XmlElement + private SettingsBrandingLoginPageModel branding; + +} diff --git a/crowd/src/main/java/com/deftdevs/bootstrapi/crowd/model/_AllModel.java b/crowd/src/main/java/com/deftdevs/bootstrapi/crowd/model/_AllModel.java index f973f55d..d049c546 100644 --- a/crowd/src/main/java/com/deftdevs/bootstrapi/crowd/model/_AllModel.java +++ b/crowd/src/main/java/com/deftdevs/bootstrapi/crowd/model/_AllModel.java @@ -2,7 +2,8 @@ import com.deftdevs.bootstrapi.commons.constants.BootstrAPI; import com.deftdevs.bootstrapi.commons.model.AbstractDirectoryModel; -import com.deftdevs.bootstrapi.commons.model.SettingsModel; +import com.deftdevs.bootstrapi.commons.model.ApplicationLinkModel; +import com.deftdevs.bootstrapi.commons.model.MailServerModel; import com.deftdevs.bootstrapi.commons.model.type._AllModelAccessor; import com.deftdevs.bootstrapi.commons.model.type._AllModelStatus; import lombok.AllArgsConstructor; @@ -11,6 +12,7 @@ import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; +import java.util.List; import java.util.Map; @Data @@ -22,11 +24,29 @@ public class _AllModel implements _AllModelAccessor { @XmlElement private SettingsModel settings; + @XmlElement + private Map directories; + @XmlElement private Map applications; @XmlElement - private Map directories; + private Map applicationLinks; + + @XmlElement + private List licenses; + + @XmlElement + private MailServerModel mailServer; + + @XmlElement + private MailTemplatesModel mailTemplates; + + @XmlElement + private SessionConfigModel sessionConfig; + + @XmlElement + private List trustedProxies; @XmlElement private Map status; diff --git a/crowd/src/main/java/com/deftdevs/bootstrapi/crowd/rest/SettingsResourceImpl.java b/crowd/src/main/java/com/deftdevs/bootstrapi/crowd/rest/SettingsGeneralResourceImpl.java similarity index 69% rename from crowd/src/main/java/com/deftdevs/bootstrapi/crowd/rest/SettingsResourceImpl.java rename to crowd/src/main/java/com/deftdevs/bootstrapi/crowd/rest/SettingsGeneralResourceImpl.java index 22299041..fd13dea8 100644 --- a/crowd/src/main/java/com/deftdevs/bootstrapi/crowd/rest/SettingsResourceImpl.java +++ b/crowd/src/main/java/com/deftdevs/bootstrapi/crowd/rest/SettingsGeneralResourceImpl.java @@ -2,8 +2,8 @@ import com.atlassian.plugins.rest.api.security.annotation.SystemAdminOnly; import com.deftdevs.bootstrapi.commons.constants.BootstrAPI; -import com.deftdevs.bootstrapi.commons.model.SettingsModel; -import com.deftdevs.bootstrapi.commons.rest.AbstractSettingsResourceImpl; +import com.deftdevs.bootstrapi.commons.model.SettingsGeneralModel; +import com.deftdevs.bootstrapi.commons.rest.AbstractSettingsGeneralResourceImpl; import com.deftdevs.bootstrapi.crowd.service.api.CrowdSettingsGeneralService; import io.swagger.v3.oas.annotations.tags.Tag; @@ -19,10 +19,10 @@ @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) @SystemAdminOnly -public class SettingsResourceImpl extends AbstractSettingsResourceImpl { +public class SettingsGeneralResourceImpl extends AbstractSettingsGeneralResourceImpl { @Inject - public SettingsResourceImpl( + public SettingsGeneralResourceImpl( final CrowdSettingsGeneralService settingsService) { super(settingsService); diff --git a/crowd/src/main/java/com/deftdevs/bootstrapi/crowd/service/SettingsServiceImpl.java b/crowd/src/main/java/com/deftdevs/bootstrapi/crowd/service/SettingsServiceImpl.java index ec4f6d64..a8cee89d 100644 --- a/crowd/src/main/java/com/deftdevs/bootstrapi/crowd/service/SettingsServiceImpl.java +++ b/crowd/src/main/java/com/deftdevs/bootstrapi/crowd/service/SettingsServiceImpl.java @@ -3,7 +3,7 @@ import com.atlassian.crowd.manager.property.PropertyManager; import com.atlassian.crowd.manager.property.PropertyManagerException; import com.deftdevs.bootstrapi.commons.exception.web.InternalServerErrorException; -import com.deftdevs.bootstrapi.commons.model.SettingsModel; +import com.deftdevs.bootstrapi.commons.model.SettingsGeneralModel; import com.deftdevs.bootstrapi.crowd.service.api.CrowdSettingsGeneralService; public class SettingsServiceImpl @@ -18,9 +18,9 @@ public SettingsServiceImpl( } @Override - public SettingsModel getSettingsGeneral() { + public SettingsGeneralModel getSettingsGeneral() { try { - return SettingsModel.builder() + return SettingsGeneralModel.builder() .baseUrl(propertyManager.getBaseUrl()) .title(propertyManager.getDeploymentTitle()) .build(); @@ -30,7 +30,7 @@ public SettingsModel getSettingsGeneral() { } @Override - public SettingsModel setSettingsGeneral(SettingsModel settingsModel) { + public SettingsGeneralModel setSettingsGeneral(SettingsGeneralModel settingsModel) { if (settingsModel.getBaseUrl() != null) { propertyManager.setBaseUrl(settingsModel.getBaseUrl()); } diff --git a/crowd/src/main/java/com/deftdevs/bootstrapi/crowd/service/_AllServiceImpl.java b/crowd/src/main/java/com/deftdevs/bootstrapi/crowd/service/_AllServiceImpl.java index f74c83ad..19ceea62 100644 --- a/crowd/src/main/java/com/deftdevs/bootstrapi/crowd/service/_AllServiceImpl.java +++ b/crowd/src/main/java/com/deftdevs/bootstrapi/crowd/service/_AllServiceImpl.java @@ -1,11 +1,20 @@ package com.deftdevs.bootstrapi.crowd.service; +import com.deftdevs.bootstrapi.commons.model.MailServerModel; import com.deftdevs.bootstrapi.commons.model.type._AllModelStatus; import com.deftdevs.bootstrapi.commons.service._AbstractAllServiceImpl; +import com.deftdevs.bootstrapi.commons.service.api.ApplicationLinksService; import com.deftdevs.bootstrapi.commons.service.api.DirectoriesService; +import com.deftdevs.bootstrapi.commons.service.api.LicensesService; +import com.deftdevs.bootstrapi.commons.service.api.MailServerService; +import com.deftdevs.bootstrapi.crowd.model.SettingsModel; import com.deftdevs.bootstrapi.crowd.model._AllModel; import com.deftdevs.bootstrapi.crowd.service.api.ApplicationsService; +import com.deftdevs.bootstrapi.crowd.service.api.CrowdSettingsBrandingService; import com.deftdevs.bootstrapi.crowd.service.api.CrowdSettingsGeneralService; +import com.deftdevs.bootstrapi.crowd.service.api.MailTemplatesService; +import com.deftdevs.bootstrapi.crowd.service.api.SessionConfigService; +import com.deftdevs.bootstrapi.crowd.service.api.TrustedProxiesService; import java.util.HashMap; import java.util.Map; @@ -13,17 +22,38 @@ public class _AllServiceImpl extends _AbstractAllServiceImpl<_AllModel> { private final CrowdSettingsGeneralService settingsService; + private final CrowdSettingsBrandingService brandingService; private final DirectoriesService directoriesService; private final ApplicationsService applicationsService; + private final ApplicationLinksService applicationLinksService; + private final LicensesService licensesService; + private final MailServerService mailServerService; + private final MailTemplatesService mailTemplatesService; + private final SessionConfigService sessionConfigService; + private final TrustedProxiesService trustedProxiesService; public _AllServiceImpl( final CrowdSettingsGeneralService settingsService, + final CrowdSettingsBrandingService brandingService, final DirectoriesService directoriesService, - final ApplicationsService applicationsService) { + final ApplicationsService applicationsService, + final ApplicationLinksService applicationLinksService, + final LicensesService licensesService, + final MailServerService mailServerService, + final MailTemplatesService mailTemplatesService, + final SessionConfigService sessionConfigService, + final TrustedProxiesService trustedProxiesService) { this.settingsService = settingsService; + this.brandingService = brandingService; this.directoriesService = directoriesService; this.applicationsService = applicationsService; + this.applicationLinksService = applicationLinksService; + this.licensesService = licensesService; + this.mailServerService = mailServerService; + this.mailTemplatesService = mailTemplatesService; + this.sessionConfigService = sessionConfigService; + this.trustedProxiesService = trustedProxiesService; } @Override @@ -33,11 +63,49 @@ public _AllModel setAll( final _AllModel result = new _AllModel(); final Map statusMap = new HashMap<>(); - setEntity("settings", allModel.getSettings(), settingsService::setSettingsGeneral, result::setSettings, statusMap); + // Settings wrapper + final SettingsModel settingsInput = allModel.getSettings(); + if (settingsInput != null) { + final SettingsModel settingsResult = new SettingsModel(); + setEntity("settings/general", settingsInput.getGeneral(), + settingsService::setSettingsGeneral, settingsResult::setGeneral, statusMap); + setEntity("settings/branding", settingsInput.getBranding(), + brandingService::setLoginPage, settingsResult::setBranding, statusMap); + result.setSettings(settingsResult); + } - setEntities("directories", allModel.getDirectories(), directoriesService::setDirectories, result::setDirectories, statusMap); + setEntities("directories", allModel.getDirectories(), + directoriesService::setDirectories, result::setDirectories, statusMap); - setEntities("applications", allModel.getApplications(), applicationsService::setApplications, result::setApplications, statusMap); + setEntities("applications", allModel.getApplications(), + applicationsService::setApplications, result::setApplications, statusMap); + + setEntities("applicationLinks", allModel.getApplicationLinks(), + applicationLinksService::setApplicationLinks, result::setApplicationLinks, statusMap); + + setEntity("licenses", allModel.getLicenses(), + keys -> { licensesService.setLicenses(keys); return keys; }, + result::setLicenses, statusMap); + + // Mail server wrapper + final MailServerModel mailServerInput = allModel.getMailServer(); + if (mailServerInput != null) { + final MailServerModel mailServerResult = new MailServerModel(); + setEntity("mailServer/smtp", mailServerInput.getSmtp(), + mailServerService::setMailServerSmtp, mailServerResult::setSmtp, statusMap); + setEntity("mailServer/pop", mailServerInput.getPop(), + mailServerService::setMailServerPop, mailServerResult::setPop, statusMap); + result.setMailServer(mailServerResult); + } + + setEntity("mailTemplates", allModel.getMailTemplates(), + mailTemplatesService::setMailTemplates, result::setMailTemplates, statusMap); + + setEntity("sessionConfig", allModel.getSessionConfig(), + sessionConfigService::setSessionConfig, result::setSessionConfig, statusMap); + + setEntity("trustedProxies", allModel.getTrustedProxies(), + trustedProxiesService::setTrustedProxies, result::setTrustedProxies, statusMap); result.setStatus(statusMap); return result; diff --git a/crowd/src/main/java/com/deftdevs/bootstrapi/crowd/service/api/CrowdSettingsGeneralService.java b/crowd/src/main/java/com/deftdevs/bootstrapi/crowd/service/api/CrowdSettingsGeneralService.java index a7098e91..610100cb 100644 --- a/crowd/src/main/java/com/deftdevs/bootstrapi/crowd/service/api/CrowdSettingsGeneralService.java +++ b/crowd/src/main/java/com/deftdevs/bootstrapi/crowd/service/api/CrowdSettingsGeneralService.java @@ -1,8 +1,8 @@ package com.deftdevs.bootstrapi.crowd.service.api; -import com.deftdevs.bootstrapi.commons.model.SettingsModel; -import com.deftdevs.bootstrapi.commons.service.api.SettingsService; +import com.deftdevs.bootstrapi.commons.model.SettingsGeneralModel; +import com.deftdevs.bootstrapi.commons.service.api.SettingsGeneralService; public interface CrowdSettingsGeneralService extends - SettingsService { + SettingsGeneralService { } diff --git a/crowd/src/test/java/com/deftdevs/bootstrapi/crowd/rest/AllResourceTest.java b/crowd/src/test/java/com/deftdevs/bootstrapi/crowd/rest/AllResourceTest.java index 69242953..b763fa8a 100644 --- a/crowd/src/test/java/com/deftdevs/bootstrapi/crowd/rest/AllResourceTest.java +++ b/crowd/src/test/java/com/deftdevs/bootstrapi/crowd/rest/AllResourceTest.java @@ -1,7 +1,8 @@ package com.deftdevs.bootstrapi.crowd.rest; -import com.deftdevs.bootstrapi.commons.model.SettingsModel; +import com.deftdevs.bootstrapi.commons.model.SettingsGeneralModel; import com.deftdevs.bootstrapi.crowd.model.ApplicationModel; +import com.deftdevs.bootstrapi.crowd.model.SettingsModel; import com.deftdevs.bootstrapi.crowd.model._AllModel; import com.deftdevs.bootstrapi.commons.model.type._AllModelStatus; import com.deftdevs.bootstrapi.commons.service.api._AllService; @@ -34,7 +35,9 @@ public void setup() { // Setup test data allModel = new _AllModel(); - allModel.setSettings(SettingsModel.EXAMPLE_1); + final SettingsModel settings = new SettingsModel(); + settings.setGeneral(SettingsGeneralModel.EXAMPLE_1); + allModel.setSettings(settings); // Setup applications map Map applications = new HashMap<>(); @@ -42,7 +45,7 @@ public void setup() { allModel.setApplications(applications); Map status = new HashMap<>(); - status.put("settings", _AllModelStatus.success()); + status.put("settings/general", _AllModelStatus.success()); status.put("directories", _AllModelStatus.success()); status.put("applications", _AllModelStatus.success()); allModel.setStatus(status); diff --git a/crowd/src/test/java/com/deftdevs/bootstrapi/crowd/service/SettingsServiceTest.java b/crowd/src/test/java/com/deftdevs/bootstrapi/crowd/service/SettingsServiceTest.java index c146d736..c1af5d19 100644 --- a/crowd/src/test/java/com/deftdevs/bootstrapi/crowd/service/SettingsServiceTest.java +++ b/crowd/src/test/java/com/deftdevs/bootstrapi/crowd/service/SettingsServiceTest.java @@ -3,7 +3,7 @@ import com.atlassian.crowd.manager.property.PropertyManager; import com.atlassian.crowd.manager.property.PropertyManagerException; import com.deftdevs.bootstrapi.commons.exception.web.InternalServerErrorException; -import com.deftdevs.bootstrapi.commons.model.SettingsModel; +import com.deftdevs.bootstrapi.commons.model.SettingsGeneralModel; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -12,7 +12,7 @@ import java.net.URISyntaxException; -import static com.deftdevs.bootstrapi.commons.model.SettingsModel.EXAMPLE_1_NO_MODE; +import static com.deftdevs.bootstrapi.commons.model.SettingsGeneralModel.EXAMPLE_1_NO_MODE; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.Mockito.*; @@ -23,7 +23,7 @@ public class SettingsServiceTest { @Mock private PropertyManager propertyManager; - public static final SettingsModel SETTINGS_MODEL = EXAMPLE_1_NO_MODE; + public static final SettingsGeneralModel SETTINGS_MODEL = EXAMPLE_1_NO_MODE; private SettingsServiceImpl settingsService; diff --git a/crowd/src/test/java/it/com/deftdevs/bootstrapi/crowd/rest/SettingsGeneralResourceFuncTest.java b/crowd/src/test/java/it/com/deftdevs/bootstrapi/crowd/rest/SettingsGeneralResourceFuncTest.java new file mode 100644 index 00000000..df5912df --- /dev/null +++ b/crowd/src/test/java/it/com/deftdevs/bootstrapi/crowd/rest/SettingsGeneralResourceFuncTest.java @@ -0,0 +1,16 @@ +package it.com.deftdevs.bootstrapi.crowd.rest; + +import com.deftdevs.bootstrapi.commons.model.SettingsGeneralModel; +import it.com.deftdevs.bootstrapi.commons.rest.AbstractSettingsGeneralResourceFuncTest; + +public class SettingsGeneralResourceFuncTest extends AbstractSettingsGeneralResourceFuncTest { + + @Override + protected SettingsGeneralModel getExampleModel() { + return SettingsGeneralModel.builder() + .baseUrl(SettingsGeneralModel.EXAMPLE_1.getBaseUrl()) + .title(SettingsGeneralModel.EXAMPLE_1.getTitle()) + .build(); + } + +} diff --git a/crowd/src/test/java/it/com/deftdevs/bootstrapi/crowd/rest/SettingsResourceFuncTest.java b/crowd/src/test/java/it/com/deftdevs/bootstrapi/crowd/rest/SettingsResourceFuncTest.java deleted file mode 100644 index ca31a892..00000000 --- a/crowd/src/test/java/it/com/deftdevs/bootstrapi/crowd/rest/SettingsResourceFuncTest.java +++ /dev/null @@ -1,16 +0,0 @@ -package it.com.deftdevs.bootstrapi.crowd.rest; - -import com.deftdevs.bootstrapi.commons.model.SettingsModel; -import it.com.deftdevs.bootstrapi.commons.rest.AbstractSettingsResourceFuncTest; - -public class SettingsResourceFuncTest extends AbstractSettingsResourceFuncTest { - - @Override - protected SettingsModel getExampleModel() { - return SettingsModel.builder() - .baseUrl(SettingsModel.EXAMPLE_1.getBaseUrl()) - .title(SettingsModel.EXAMPLE_1.getTitle()) - .build(); - } - -} diff --git a/jira/Apis/AllApi.md b/jira/Apis/AllApi.md index 83d417e4..a71ed295 100644 --- a/jira/Apis/AllApi.md +++ b/jira/Apis/AllApi.md @@ -9,7 +9,7 @@ All URIs are relative to *https://JIRA_URL/rest/bootstrapi/1* # **setAll** -> SettingsModel setAll(\_AllModel) +> _AllModel setAll(\_AllModel) _all @@ -21,7 +21,7 @@ _all ### Return type -[**SettingsModel**](../Models/SettingsModel.md) +[**_AllModel**](../Models/_AllModel.md) ### Authorization diff --git a/jira/Apis/SettingsApi.md b/jira/Apis/SettingsApi.md index 5f33d6c1..adc60745 100644 --- a/jira/Apis/SettingsApi.md +++ b/jira/Apis/SettingsApi.md @@ -36,7 +36,7 @@ This endpoint does not need any parameter. # **getSettings** -> SettingsModel getSettings() +> SettingsGeneralModel getSettings() Get the general settings @@ -45,7 +45,7 @@ This endpoint does not need any parameter. ### Return type -[**SettingsModel**](../Models/SettingsModel.md) +[**SettingsGeneralModel**](../Models/SettingsGeneralModel.md) ### Authorization @@ -105,7 +105,7 @@ Set the banner # **setSettings** -> SettingsModel setSettings(SettingsModel) +> SettingsGeneralModel setSettings(SettingsGeneralModel) Set the general settings @@ -113,11 +113,11 @@ Set the general settings |Name | Type | Description | Notes | |------------- | ------------- | ------------- | -------------| -| **SettingsModel** | [**SettingsModel**](../Models/SettingsModel.md)| | [optional] | +| **SettingsGeneralModel** | [**SettingsGeneralModel**](../Models/SettingsGeneralModel.md)| | [optional] | ### Return type -[**SettingsModel**](../Models/SettingsModel.md) +[**SettingsGeneralModel**](../Models/SettingsGeneralModel.md) ### Authorization diff --git a/jira/Models/SettingsGeneralModel.md b/jira/Models/SettingsGeneralModel.md new file mode 100644 index 00000000..8ebe677b --- /dev/null +++ b/jira/Models/SettingsGeneralModel.md @@ -0,0 +1,13 @@ +# SettingsGeneralModel +## Properties + +| Name | Type | Description | Notes | +|------------ | ------------- | ------------- | -------------| +| **baseUrl** | **URI** | | [optional] [default to null] | +| **mode** | **String** | | [optional] [default to null] | +| **title** | **String** | | [optional] [default to null] | +| **contactMessage** | **String** | | [optional] [default to null] | +| **externalUserManagement** | **Boolean** | | [optional] [default to null] | + +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) + diff --git a/jira/Models/SettingsModel.md b/jira/Models/SettingsModel.md index f4eb0e7f..23d5cc40 100644 --- a/jira/Models/SettingsModel.md +++ b/jira/Models/SettingsModel.md @@ -3,11 +3,9 @@ | Name | Type | Description | Notes | |------------ | ------------- | ------------- | -------------| -| **baseUrl** | **URI** | | [optional] [default to null] | -| **mode** | **String** | | [optional] [default to null] | -| **title** | **String** | | [optional] [default to null] | -| **contactMessage** | **String** | | [optional] [default to null] | -| **externalUserManagement** | **Boolean** | | [optional] [default to null] | +| **general** | [**SettingsGeneralModel**](SettingsGeneralModel.md) | | [optional] [default to null] | +| **security** | [**SettingsSecurityModel**](SettingsSecurityModel.md) | | [optional] [default to null] | +| **banner** | [**SettingsBannerModel**](SettingsBannerModel.md) | | [optional] [default to null] | [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/jira/Models/_AllModel.md b/jira/Models/_AllModel.md index 34153397..cd6000f3 100644 --- a/jira/Models/_AllModel.md +++ b/jira/Models/_AllModel.md @@ -4,8 +4,12 @@ | Name | Type | Description | Notes | |------------ | ------------- | ------------- | -------------| | **settings** | [**SettingsModel**](SettingsModel.md) | | [optional] [default to null] | -| **users** | [**Map**](UserModel.md) | | [optional] [default to null] | -| **groups** | [**Map**](GroupModel.md) | | [optional] [default to null] | +| **directories** | [**Map**](AbstractDirectoryModel.md) | | [optional] [default to null] | +| **applicationLinks** | [**Map**](ApplicationLinkModel.md) | | [optional] [default to null] | +| **authentication** | [**AuthenticationModel**](AuthenticationModel.md) | | [optional] [default to null] | +| **licenses** | **List** | | [optional] [default to null] | +| **mailServer** | [**MailServerModel**](MailServerModel.md) | | [optional] [default to null] | +| **permissionsGlobal** | [**PermissionsGlobalModel**](PermissionsGlobalModel.md) | | [optional] [default to null] | | **status** | [**Map**](_AllModelStatus.md) | | [optional] [default to null] | [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/jira/README.md b/jira/README.md index ebb27321..2f5bbfbd 100644 --- a/jira/README.md +++ b/jira/README.md @@ -77,6 +77,7 @@ All URIs are relative to *https://JIRA_URL/rest/bootstrapi/1* - [MailServerSmtpModel](./Models/MailServerSmtpModel.md) - [PermissionsGlobalModel](./Models/PermissionsGlobalModel.md) - [SettingsBannerModel](./Models/SettingsBannerModel.md) + - [SettingsGeneralModel](./Models/SettingsGeneralModel.md) - [SettingsModel](./Models/SettingsModel.md) - [SettingsSecurityModel](./Models/SettingsSecurityModel.md) - [UserModel](./Models/UserModel.md) diff --git a/jira/src/main/java/com/deftdevs/bootstrapi/jira/config/ServiceConfig.java b/jira/src/main/java/com/deftdevs/bootstrapi/jira/config/ServiceConfig.java index bc0b1f91..0671d8c7 100644 --- a/jira/src/main/java/com/deftdevs/bootstrapi/jira/config/ServiceConfig.java +++ b/jira/src/main/java/com/deftdevs/bootstrapi/jira/config/ServiceConfig.java @@ -1,6 +1,7 @@ package com.deftdevs.bootstrapi.jira.config; import com.deftdevs.bootstrapi.commons.service.api.*; +import com.deftdevs.bootstrapi.jira.model._AllModel; import com.deftdevs.bootstrapi.jira.service.*; import com.deftdevs.bootstrapi.jira.service.api.JiraAuthenticationService; import com.deftdevs.bootstrapi.jira.service.api.JiraSettingsService; @@ -17,6 +18,18 @@ public class ServiceConfig { @Autowired private HelperConfig helperConfig; + @Bean + public _AllService<_AllModel> _allService() { + return new _AllServiceImpl( + jiraSettingsService(), + directoriesService(), + applicationLinksService(), + jiraAuthenticationService(), + licensesService(), + mailServerService(), + permissionsService()); + } + @Bean public ApplicationLinksService applicationLinksService() { return new ApplicationLinksServiceImpl( diff --git a/jira/src/main/java/com/deftdevs/bootstrapi/jira/model/SettingsModel.java b/jira/src/main/java/com/deftdevs/bootstrapi/jira/model/SettingsModel.java new file mode 100644 index 00000000..40f39555 --- /dev/null +++ b/jira/src/main/java/com/deftdevs/bootstrapi/jira/model/SettingsModel.java @@ -0,0 +1,29 @@ +package com.deftdevs.bootstrapi.jira.model; + +import com.deftdevs.bootstrapi.commons.model.SettingsGeneralModel; +import com.deftdevs.bootstrapi.commons.model.SettingsSecurityModel; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + +import static com.deftdevs.bootstrapi.commons.constants.BootstrAPI.SETTINGS; + +@Data +@NoArgsConstructor +@AllArgsConstructor +@XmlRootElement(name = SETTINGS) +public class SettingsModel { + + @XmlElement + private SettingsGeneralModel general; + + @XmlElement + private SettingsSecurityModel security; + + @XmlElement + private SettingsBannerModel banner; + +} diff --git a/jira/src/main/java/com/deftdevs/bootstrapi/jira/model/_AllModel.java b/jira/src/main/java/com/deftdevs/bootstrapi/jira/model/_AllModel.java index 2ab910ad..daaa9b5f 100644 --- a/jira/src/main/java/com/deftdevs/bootstrapi/jira/model/_AllModel.java +++ b/jira/src/main/java/com/deftdevs/bootstrapi/jira/model/_AllModel.java @@ -1,9 +1,11 @@ package com.deftdevs.bootstrapi.jira.model; import com.deftdevs.bootstrapi.commons.constants.BootstrAPI; -import com.deftdevs.bootstrapi.commons.model.GroupModel; -import com.deftdevs.bootstrapi.commons.model.SettingsModel; -import com.deftdevs.bootstrapi.commons.model.UserModel; +import com.deftdevs.bootstrapi.commons.model.AbstractDirectoryModel; +import com.deftdevs.bootstrapi.commons.model.ApplicationLinkModel; +import com.deftdevs.bootstrapi.commons.model.AuthenticationModel; +import com.deftdevs.bootstrapi.commons.model.MailServerModel; +import com.deftdevs.bootstrapi.commons.model.PermissionsGlobalModel; import com.deftdevs.bootstrapi.commons.model.type._AllModelAccessor; import com.deftdevs.bootstrapi.commons.model.type._AllModelStatus; import lombok.AllArgsConstructor; @@ -12,6 +14,7 @@ import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; +import java.util.List; import java.util.Map; @Data @@ -24,10 +27,22 @@ public class _AllModel implements _AllModelAccessor { private SettingsModel settings; @XmlElement - private Map users; + private Map directories; @XmlElement - private Map groups; + private Map applicationLinks; + + @XmlElement + private AuthenticationModel authentication; + + @XmlElement + private List licenses; + + @XmlElement + private MailServerModel mailServer; + + @XmlElement + private PermissionsGlobalModel permissionsGlobal; @XmlElement private Map status; diff --git a/jira/src/main/java/com/deftdevs/bootstrapi/jira/rest/SettingsResourceImpl.java b/jira/src/main/java/com/deftdevs/bootstrapi/jira/rest/SettingsGeneralResourceImpl.java similarity index 69% rename from jira/src/main/java/com/deftdevs/bootstrapi/jira/rest/SettingsResourceImpl.java rename to jira/src/main/java/com/deftdevs/bootstrapi/jira/rest/SettingsGeneralResourceImpl.java index f8b5773b..0730eea6 100644 --- a/jira/src/main/java/com/deftdevs/bootstrapi/jira/rest/SettingsResourceImpl.java +++ b/jira/src/main/java/com/deftdevs/bootstrapi/jira/rest/SettingsGeneralResourceImpl.java @@ -2,8 +2,8 @@ import com.atlassian.plugins.rest.api.security.annotation.SystemAdminOnly; import com.deftdevs.bootstrapi.commons.constants.BootstrAPI; -import com.deftdevs.bootstrapi.commons.model.SettingsModel; -import com.deftdevs.bootstrapi.commons.rest.AbstractSettingsResourceImpl; +import com.deftdevs.bootstrapi.commons.model.SettingsGeneralModel; +import com.deftdevs.bootstrapi.commons.rest.AbstractSettingsGeneralResourceImpl; import com.deftdevs.bootstrapi.jira.service.api.JiraSettingsService; import io.swagger.v3.oas.annotations.tags.Tag; @@ -18,10 +18,10 @@ @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) @SystemAdminOnly -public class SettingsResourceImpl extends AbstractSettingsResourceImpl { +public class SettingsGeneralResourceImpl extends AbstractSettingsGeneralResourceImpl { @Inject - public SettingsResourceImpl( + public SettingsGeneralResourceImpl( final JiraSettingsService settingsService) { super(settingsService); diff --git a/jira/src/main/java/com/deftdevs/bootstrapi/jira/service/SettingsServiceImpl.java b/jira/src/main/java/com/deftdevs/bootstrapi/jira/service/SettingsServiceImpl.java index 961a3437..dad34f63 100644 --- a/jira/src/main/java/com/deftdevs/bootstrapi/jira/service/SettingsServiceImpl.java +++ b/jira/src/main/java/com/deftdevs/bootstrapi/jira/service/SettingsServiceImpl.java @@ -3,7 +3,7 @@ import com.atlassian.jira.config.properties.APKeys; import com.atlassian.jira.config.properties.ApplicationProperties; import com.deftdevs.bootstrapi.commons.exception.web.BadRequestException; -import com.deftdevs.bootstrapi.commons.model.SettingsModel; +import com.deftdevs.bootstrapi.commons.model.SettingsGeneralModel; import com.deftdevs.bootstrapi.commons.model.SettingsSecurityModel; import com.deftdevs.bootstrapi.jira.model.SettingsBannerModel; import com.deftdevs.bootstrapi.jira.service.api.JiraSettingsService; @@ -28,14 +28,14 @@ public SettingsServiceImpl( } @Override - public SettingsModel getSettingsGeneral() { + public SettingsGeneralModel getSettingsGeneral() { final String baseUrl = applicationProperties.getString(JIRA_BASEURL); final String mode = applicationProperties.getString(JIRA_MODE); final String title = applicationProperties.getString(JIRA_TITLE); final String contactMessage = applicationProperties.getString(JIRA_CONTACT_ADMINISTRATORS_MESSSAGE); final Boolean externalUserManagement = Boolean.parseBoolean(applicationProperties.getString(JIRA_OPTION_USER_EXTERNALMGT)); - final SettingsModel settingsModel = SettingsModel.builder() + final SettingsGeneralModel settingsModel = SettingsGeneralModel.builder() .baseUrl(baseUrl != null ? URI.create(baseUrl) : null) .mode(mode) .title(title) @@ -47,8 +47,8 @@ public SettingsModel getSettingsGeneral() { } @Override - public SettingsModel setSettingsGeneral( - final SettingsModel settingsModel) { + public SettingsGeneralModel setSettingsGeneral( + final SettingsGeneralModel settingsModel) { if (settingsModel.getBaseUrl() != null) { applicationProperties.setString(JIRA_BASEURL, settingsModel.getBaseUrl().toString()); diff --git a/jira/src/main/java/com/deftdevs/bootstrapi/jira/service/_AllServiceImpl.java b/jira/src/main/java/com/deftdevs/bootstrapi/jira/service/_AllServiceImpl.java new file mode 100644 index 00000000..f500c5a2 --- /dev/null +++ b/jira/src/main/java/com/deftdevs/bootstrapi/jira/service/_AllServiceImpl.java @@ -0,0 +1,106 @@ +package com.deftdevs.bootstrapi.jira.service; + +import com.deftdevs.bootstrapi.commons.model.AuthenticationModel; +import com.deftdevs.bootstrapi.commons.model.MailServerModel; +import com.deftdevs.bootstrapi.commons.model.type._AllModelStatus; +import com.deftdevs.bootstrapi.commons.service._AbstractAllServiceImpl; +import com.deftdevs.bootstrapi.commons.service.api.ApplicationLinksService; +import com.deftdevs.bootstrapi.commons.service.api.DirectoriesService; +import com.deftdevs.bootstrapi.commons.service.api.LicensesService; +import com.deftdevs.bootstrapi.commons.service.api.MailServerService; +import com.deftdevs.bootstrapi.commons.service.api.PermissionsService; +import com.deftdevs.bootstrapi.jira.model.SettingsModel; +import com.deftdevs.bootstrapi.jira.model._AllModel; +import com.deftdevs.bootstrapi.jira.service.api.JiraAuthenticationService; +import com.deftdevs.bootstrapi.jira.service.api.JiraSettingsService; + +import java.util.HashMap; +import java.util.Map; + +public class _AllServiceImpl extends _AbstractAllServiceImpl<_AllModel> { + + private final JiraSettingsService settingsService; + private final DirectoriesService directoriesService; + private final ApplicationLinksService applicationLinksService; + private final JiraAuthenticationService authenticationService; + private final LicensesService licensesService; + private final MailServerService mailServerService; + private final PermissionsService permissionsService; + + public _AllServiceImpl( + final JiraSettingsService settingsService, + final DirectoriesService directoriesService, + final ApplicationLinksService applicationLinksService, + final JiraAuthenticationService authenticationService, + final LicensesService licensesService, + final MailServerService mailServerService, + final PermissionsService permissionsService) { + + this.settingsService = settingsService; + this.directoriesService = directoriesService; + this.applicationLinksService = applicationLinksService; + this.authenticationService = authenticationService; + this.licensesService = licensesService; + this.mailServerService = mailServerService; + this.permissionsService = permissionsService; + } + + @Override + public _AllModel setAll( + final _AllModel allModel) { + + final _AllModel result = new _AllModel(); + final Map statusMap = new HashMap<>(); + + // Settings wrapper + final SettingsModel settingsInput = allModel.getSettings(); + if (settingsInput != null) { + final SettingsModel settingsResult = new SettingsModel(); + setEntity("settings/general", settingsInput.getGeneral(), + settingsService::setSettingsGeneral, settingsResult::setGeneral, statusMap); + setEntity("settings/security", settingsInput.getSecurity(), + settingsService::setSettingsSecurity, settingsResult::setSecurity, statusMap); + setEntity("settings/banner", settingsInput.getBanner(), + settingsService::setSettingsBanner, settingsResult::setBanner, statusMap); + result.setSettings(settingsResult); + } + + setEntities("directories", allModel.getDirectories(), + directoriesService::setDirectories, result::setDirectories, statusMap); + + setEntities("applicationLinks", allModel.getApplicationLinks(), + applicationLinksService::setApplicationLinks, result::setApplicationLinks, statusMap); + + // Authentication wrapper + final AuthenticationModel authInput = allModel.getAuthentication(); + if (authInput != null) { + final AuthenticationModel authResult = new AuthenticationModel(); + setEntities("authentication/idps", authInput.getIdps(), + authenticationService::setAuthenticationIdps, authResult::setIdps, statusMap); + setEntity("authentication/sso", authInput.getSso(), + authenticationService::setAuthenticationSso, authResult::setSso, statusMap); + result.setAuthentication(authResult); + } + + setEntity("licenses", allModel.getLicenses(), + keys -> { licensesService.setLicenses(keys); return keys; }, + result::setLicenses, statusMap); + + // Mail server wrapper + final MailServerModel mailServerInput = allModel.getMailServer(); + if (mailServerInput != null) { + final MailServerModel mailServerResult = new MailServerModel(); + setEntity("mailServer/smtp", mailServerInput.getSmtp(), + mailServerService::setMailServerSmtp, mailServerResult::setSmtp, statusMap); + setEntity("mailServer/pop", mailServerInput.getPop(), + mailServerService::setMailServerPop, mailServerResult::setPop, statusMap); + result.setMailServer(mailServerResult); + } + + setEntity("permissionsGlobal", allModel.getPermissionsGlobal(), + permissionsService::setPermissionsGlobal, result::setPermissionsGlobal, statusMap); + + result.setStatus(statusMap); + return result; + } +} diff --git a/jira/src/main/java/com/deftdevs/bootstrapi/jira/service/api/JiraSettingsService.java b/jira/src/main/java/com/deftdevs/bootstrapi/jira/service/api/JiraSettingsService.java index 7c6b54d8..8242bb3a 100644 --- a/jira/src/main/java/com/deftdevs/bootstrapi/jira/service/api/JiraSettingsService.java +++ b/jira/src/main/java/com/deftdevs/bootstrapi/jira/service/api/JiraSettingsService.java @@ -1,13 +1,13 @@ package com.deftdevs.bootstrapi.jira.service.api; -import com.deftdevs.bootstrapi.commons.model.SettingsModel; +import com.deftdevs.bootstrapi.commons.model.SettingsGeneralModel; import com.deftdevs.bootstrapi.commons.model.SettingsSecurityModel; import com.deftdevs.bootstrapi.commons.service.api.SettingsSecurityService; -import com.deftdevs.bootstrapi.commons.service.api.SettingsService; +import com.deftdevs.bootstrapi.commons.service.api.SettingsGeneralService; import com.deftdevs.bootstrapi.jira.model.SettingsBannerModel; public interface JiraSettingsService extends - SettingsService, + SettingsGeneralService, SettingsSecurityService { SettingsBannerModel getSettingsBanner(); diff --git a/jira/src/test/java/com/deftdevs/bootstrapi/jira/service/JiraSettingsServiceTest.java b/jira/src/test/java/com/deftdevs/bootstrapi/jira/service/JiraSettingsServiceTest.java index dbd56e8a..ddcba2aa 100644 --- a/jira/src/test/java/com/deftdevs/bootstrapi/jira/service/JiraSettingsServiceTest.java +++ b/jira/src/test/java/com/deftdevs/bootstrapi/jira/service/JiraSettingsServiceTest.java @@ -2,7 +2,7 @@ import com.atlassian.jira.config.properties.ApplicationProperties; import com.deftdevs.bootstrapi.commons.exception.web.BadRequestException; -import com.deftdevs.bootstrapi.commons.model.SettingsModel; +import com.deftdevs.bootstrapi.commons.model.SettingsGeneralModel; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -43,7 +43,7 @@ void testGetSettingsGeneral() { doReturn(CONTACT_MESSAGE).when(applicationProperties).getString(JIRA_CONTACT_ADMINISTRATORS_MESSSAGE); doReturn(EXTERNAL_USER_MANAGEMENT).when(applicationProperties).getString(JIRA_OPTION_USER_EXTERNALMGT); - final SettingsModel settingsModel = settingsService.getSettingsGeneral(); + final SettingsGeneralModel settingsModel = settingsService.getSettingsGeneral(); assertEquals(BASE_URL, settingsModel.getBaseUrl()); assertEquals(MODE_PUBLIC, settingsModel.getMode()); @@ -54,7 +54,7 @@ void testGetSettingsGeneral() { @Test void testSetSettingsGeneral() { - final SettingsModel settingsModel = SettingsModel.builder() + final SettingsGeneralModel settingsModel = SettingsGeneralModel.builder() .baseUrl(BASE_URL) .mode(MODE_PUBLIC) .title(TITLE) @@ -73,7 +73,7 @@ void testSetSettingsGeneral() { @Test void testSetSettingsGeneralEmptyModel() { - final SettingsModel settingsModel = SettingsModel.builder().build(); + final SettingsGeneralModel settingsModel = SettingsGeneralModel.builder().build(); settingsService.setSettingsGeneral(settingsModel); @@ -85,7 +85,7 @@ void testSetSettingsGeneralEmptyModel() { @Test void testSetSettingsGeneralUnsupportedMode() { - final SettingsModel settingsModel = SettingsModel.builder().mode("unsupported").build(); + final SettingsGeneralModel settingsModel = SettingsGeneralModel.builder().mode("unsupported").build(); assertThrows(BadRequestException.class, () -> { settingsService.setSettingsGeneral(settingsModel); @@ -94,7 +94,7 @@ void testSetSettingsGeneralUnsupportedMode() { @Test void testSetSettingsGeneralInvalidCombination() { - final SettingsModel settingsModel = SettingsModel.builder().mode(MODE_PUBLIC).build(); + final SettingsGeneralModel settingsModel = SettingsGeneralModel.builder().mode(MODE_PUBLIC).build(); doReturn(true).when(applicationProperties).getOption(JIRA_OPTION_USER_EXTERNALMGT); assertThrows(BadRequestException.class, () -> { diff --git a/jira/src/test/java/com/deftdevs/bootstrapi/jira/service/SettingsServiceTest.java b/jira/src/test/java/com/deftdevs/bootstrapi/jira/service/SettingsServiceTest.java index c4992884..c176c44f 100644 --- a/jira/src/test/java/com/deftdevs/bootstrapi/jira/service/SettingsServiceTest.java +++ b/jira/src/test/java/com/deftdevs/bootstrapi/jira/service/SettingsServiceTest.java @@ -2,7 +2,7 @@ import com.atlassian.jira.config.properties.ApplicationProperties; import com.deftdevs.bootstrapi.commons.exception.web.BadRequestException; -import com.deftdevs.bootstrapi.commons.model.SettingsModel; +import com.deftdevs.bootstrapi.commons.model.SettingsGeneralModel; import com.deftdevs.bootstrapi.commons.model.SettingsSecurityModel; import com.deftdevs.bootstrapi.jira.model.SettingsBannerModel; import org.junit.jupiter.api.BeforeEach; @@ -45,7 +45,7 @@ void testGetSettingsGeneral() { doReturn(CONTACT_MESSAGE).when(applicationProperties).getString(JIRA_CONTACT_ADMINISTRATORS_MESSSAGE); doReturn(EXTERNAL_USER_MANAGEMENT).when(applicationProperties).getString(JIRA_OPTION_USER_EXTERNALMGT); - final SettingsModel settingsModel = settingsService.getSettingsGeneral(); + final SettingsGeneralModel settingsModel = settingsService.getSettingsGeneral(); assertEquals(BASE_URL, settingsModel.getBaseUrl()); assertEquals(MODE_PUBLIC, settingsModel.getMode()); @@ -56,7 +56,7 @@ void testGetSettingsGeneral() { @Test void testSetSettingsGeneral() { - final SettingsModel settingsModel = SettingsModel.builder() + final SettingsGeneralModel settingsModel = SettingsGeneralModel.builder() .baseUrl(BASE_URL) .mode(MODE_PUBLIC) .title(TITLE) @@ -75,7 +75,7 @@ void testSetSettingsGeneral() { @Test void testSetSettingsGeneralEmptyModel() { - final SettingsModel settingsModel = SettingsModel.builder().build(); + final SettingsGeneralModel settingsModel = SettingsGeneralModel.builder().build(); settingsService.setSettingsGeneral(settingsModel); @@ -109,7 +109,7 @@ void testSetSettingsSecurity() { @Test void testSetSettingsGeneralUnsupportedMode() { - final SettingsModel settingsModel = SettingsModel.builder().mode("unsupported").build(); + final SettingsGeneralModel settingsModel = SettingsGeneralModel.builder().mode("unsupported").build(); assertThrows(BadRequestException.class, () -> { settingsService.setSettingsGeneral(settingsModel); @@ -118,7 +118,7 @@ void testSetSettingsGeneralUnsupportedMode() { @Test void testSetSettingsGeneralInvalidCombination() { - final SettingsModel settingsModel = SettingsModel.builder().mode(MODE_PUBLIC).build(); + final SettingsGeneralModel settingsModel = SettingsGeneralModel.builder().mode(MODE_PUBLIC).build(); doReturn(true).when(applicationProperties).getOption(JIRA_OPTION_USER_EXTERNALMGT); assertThrows(BadRequestException.class, () -> { diff --git a/jira/src/test/java/it/com/deftdevs/bootstrapi/jira/rest/SettingsGeneralResourceFuncTest.java b/jira/src/test/java/it/com/deftdevs/bootstrapi/jira/rest/SettingsGeneralResourceFuncTest.java new file mode 100644 index 00000000..d8d7c2d8 --- /dev/null +++ b/jira/src/test/java/it/com/deftdevs/bootstrapi/jira/rest/SettingsGeneralResourceFuncTest.java @@ -0,0 +1,5 @@ +package it.com.deftdevs.bootstrapi.jira.rest; + +import it.com.deftdevs.bootstrapi.commons.rest.AbstractSettingsGeneralResourceFuncTest; + +public class SettingsGeneralResourceFuncTest extends AbstractSettingsGeneralResourceFuncTest { } diff --git a/jira/src/test/java/it/com/deftdevs/bootstrapi/jira/rest/SettingsResourceFuncTest.java b/jira/src/test/java/it/com/deftdevs/bootstrapi/jira/rest/SettingsResourceFuncTest.java deleted file mode 100644 index cc6cc1a1..00000000 --- a/jira/src/test/java/it/com/deftdevs/bootstrapi/jira/rest/SettingsResourceFuncTest.java +++ /dev/null @@ -1,5 +0,0 @@ -package it.com.deftdevs.bootstrapi.jira.rest; - -import it.com.deftdevs.bootstrapi.commons.rest.AbstractSettingsResourceFuncTest; - -public class SettingsResourceFuncTest extends AbstractSettingsResourceFuncTest { }