Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

public class BootstrAPI {

public static final String ALL = "all";
public static final String _ALL = "_all";

Check failure on line 5 in commons/src/main/java/com/deftdevs/bootstrapi/commons/constants/BootstrAPI.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Rename this constant name to match the regular expression '^[A-Z][A-Z0-9]*(_[A-Z0-9]+)*$'.

See more on https://sonarcloud.io/project/issues?id=deftdevs_bootstrapi&issues=AZ4-8usFsVWpy8fCo6T5&open=AZ4-8usFsVWpy8fCo6T5&pullRequest=222
public static final String _ROOT = "/";

Check failure on line 6 in commons/src/main/java/com/deftdevs/bootstrapi/commons/constants/BootstrAPI.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Rename this constant name to match the regular expression '^[A-Z][A-Z0-9]*(_[A-Z0-9]+)*$'.

See more on https://sonarcloud.io/project/issues?id=deftdevs_bootstrapi&issues=AZ4-8usFsVWpy8fCo6T6&open=AZ4-8usFsVWpy8fCo6T6&pullRequest=222

public static final String APPLICATION = "application";
public static final String APPLICATIONS = "applications";
public static final String APPLICATION_LINK = "application-link";
Expand Down Expand Up @@ -38,20 +40,24 @@
public static final String MAIL_SERVERS = "mail-servers";
public static final String MAIL_SERVER_POP = "pop";
public static final String MAIL_SERVER_SMTP = "smtp";
public static final String MAIL_TEMPLATES = "mail-templates";
public static final String PERMISSION = "permission";
public static final String PERMISSIONS = "permissions";
public static final String PERMISSION_ANONYMOUS_ACCESS = "anonymous-access";
public static final String PERMISSIONS_GLOBAL = "global";
public static final String PING = "ping";
public static final String SESSION_CONFIG = "session-config";
public static final String SETTINGS = "settings";
public static final String SETTINGS_BANNER = "banner";
public static final String SETTINGS_BRANDING = "branding";
public static final String SETTINGS_BRANDING_LOGIN_PAGE = "login-page";
public static final String SETTINGS_BRANDING_LOGO = "logo";
public static final String SETTINGS_CUSTOM_HTML = "custom-html";
public static final String SETTINGS_GENERAL = "general";
public static final String SETTINGS_SECURITY = "security";
public static final String USER = "user";
public static final String USERS = "users";
public static final String TRUSTED_PROXIES = "trusted-proxies";
public static final String USER_PASSWORD = "password";

public static final String MEDIA_TYPE_IMAGE = "image/*";
Expand All @@ -60,7 +66,7 @@
public static final String SETTINGS_GENERAL_GET_SUMMARY = "Get the general settings";
public static final String SETTINGS_GENERAL_GET_RESPONSE_DESCRIPTION = "Returns the general settings";
public static final String SETTINGS_GENERAL_PUT_SUMMARY = "Set the general settings";
public static final String SETTINGS_GENERAL_PUT_RESPONSE_DESCRIPTION = "Returns the general security settings";
public static final String SETTINGS_GENERAL_PUT_RESPONSE_DESCRIPTION = "Returns the updated general settings";
public static final String SETTINGS_SECURITY_GET_SUMMARY = "Get the security settings";
public static final String SETTINGS_SECURITY_GET_RESPONSE_DESCRIPTION = "Returns the security settings";
public static final String SETTINGS_SECURITY_PUT_SUMMARY = "Set the security settings";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
@XmlRootElement
@XmlRootElement(name = "authentication-idps")
@JsonTypeInfo(
use = JsonTypeInfo.Id.NAME,
include = JsonTypeInfo.As.PROPERTY,
Expand Down
Original file line number Diff line number Diff line change
@@ -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<String, AbstractAuthenticationIdpModel> idps;

@XmlElement
private AuthenticationSsoModel sso;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
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;

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
@Builder
@NoArgsConstructor
@AllArgsConstructor
@XmlRootElement(name = SETTINGS + "-" + SETTINGS_BRANDING + "-" + COLOR_SCHEME)
@XmlRootElement(name = SETTINGS + "-" + SETTINGS_BRANDING)
@XmlAccessorType(XmlAccessType.FIELD)
public class SettingsBrandingColorSchemeModel {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.deftdevs.bootstrapi.commons.model;

import com.deftdevs.bootstrapi.commons.constants.BootstrAPI;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.Builder;
Expand All @@ -13,13 +12,16 @@
import javax.xml.bind.annotation.XmlRootElement;
import java.net.URI;

import static com.deftdevs.bootstrapi.commons.constants.BootstrAPI.SETTINGS;
import static com.deftdevs.bootstrapi.commons.constants.BootstrAPI.SETTINGS_GENERAL;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@XmlRootElement(name = BootstrAPI.SETTINGS)
@XmlRootElement(name = SETTINGS + "-" + SETTINGS_GENERAL)
@XmlAccessorType(XmlAccessType.FIELD)
public class SettingsModel {
public class SettingsGeneralModel {

@XmlElement
private URI baseUrl;
Expand All @@ -46,15 +48,15 @@ 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")
.contactMessage("Test Message")
.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)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.deftdevs.bootstrapi.commons.model.type;

import java.util.Map;

public class ServiceResult<T> {

private final T model;
private final Map<String, _AllModelStatus> status;

public ServiceResult(
final T model,
final Map<String, _AllModelStatus> status) {

this.model = model;
this.status = status;
}

public T getModel() {
return model;
}

public Map<String, _AllModelStatus> getStatus() {
return status;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.deftdevs.bootstrapi.commons.model.type;

import java.util.Map;

public interface _AllModelAccessor {

Check warning on line 5 in commons/src/main/java/com/deftdevs/bootstrapi/commons/model/type/_AllModelAccessor.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Rename this interface name to match the regular expression '^[A-Z][a-zA-Z0-9]*$'.

See more on https://sonarcloud.io/project/issues?id=deftdevs_bootstrapi&issues=AZ4-8urpsVWpy8fCo6T3&open=AZ4-8urpsVWpy8fCo6T3&pullRequest=222

Map<String, _AllModelStatus> getStatus();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
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 {

Check warning on line 15 in commons/src/main/java/com/deftdevs/bootstrapi/commons/model/type/_AllModelStatus.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Rename this class name to match the regular expression '^[A-Z][a-zA-Z0-9]*$'.

See more on https://sonarcloud.io/project/issues?id=deftdevs_bootstrapi&issues=AZ4-8urdsVWpy8fCo6T2&open=AZ4-8urdsVWpy8fCo6T2&pullRequest=222

@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) {
final int code = status != null
? status.getStatusCode()
: Response.Status.INTERNAL_SERVER_ERROR.getStatusCode();
return new _AllModelStatus(code, message, details);
}

public static _AllModelStatus error(int statusCode, String message, String details) {
return new _AllModelStatus(statusCode, message, details);
}
}
Original file line number Diff line number Diff line change
@@ -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<B extends SettingsGeneralModel, S extends SettingsGeneralService<B>>
implements SettingsGeneralResource<B> {

private final S settingsService;

public AbstractSettingsGeneralResourceImpl(

Check warning on line 14 in commons/src/main/java/com/deftdevs/bootstrapi/commons/rest/AbstractSettingsGeneralResourceImpl.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Change the visibility of this constructor to "protected".

See more on https://sonarcloud.io/project/issues?id=deftdevs_bootstrapi&issues=AZ4-8urWsVWpy8fCo6T1&open=AZ4-8urWsVWpy8fCo6T1&pullRequest=222
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();
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
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 extends _AllModelAccessor>

Check warning on line 11 in commons/src/main/java/com/deftdevs/bootstrapi/commons/rest/_AbstractAllResourceImpl.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Rename this class name to match the regular expression '^[A-Z][a-zA-Z0-9]*$'.

See more on https://sonarcloud.io/project/issues?id=deftdevs_bootstrapi&issues=AZ4-8urOsVWpy8fCo6Ty&open=AZ4-8urOsVWpy8fCo6Ty&pullRequest=222

Check warning on line 11 in commons/src/main/java/com/deftdevs/bootstrapi/commons/rest/_AbstractAllResourceImpl.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Rename this generic name to match the regular expression '^[A-Z][0-9]?$'.

See more on https://sonarcloud.io/project/issues?id=deftdevs_bootstrapi&issues=AZ4-8urOsVWpy8fCo6T0&open=AZ4-8urOsVWpy8fCo6T0&pullRequest=222
implements _AllResource<_AllModel> {

static final int MULTI_STATUS = 207;

private final _AllService<_AllModel> allService;

public _AbstractAllResourceImpl(

Check warning on line 18 in commons/src/main/java/com/deftdevs/bootstrapi/commons/rest/_AbstractAllResourceImpl.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Change the visibility of this constructor to "protected".

See more on https://sonarcloud.io/project/issues?id=deftdevs_bootstrapi&issues=AZ4-8urOsVWpy8fCo6Tz&open=AZ4-8urOsVWpy8fCo6Tz&pullRequest=222
final _AllService<_AllModel> allService) {

this.allService = allService;
}

@Override
public Response setAll(
final _AllModel allModel) {

final _AllModel result = allService.setAll(allModel);
final int overallStatus = computeOverallStatus(result.getStatus());
return Response.status(overallStatus).entity(result).build();
}

/**
* Aggregates per-sub-field statuses into a single HTTP response code:
* <ul>
* <li>All successful (or empty) → 200 OK.</li>
* <li>All entries share the same status code → that code.</li>
* <li>Any 5xx → 500 Internal Server Error.</li>
* <li>Mixed 2xx/4xx (or multiple distinct 4xx) → 207 Multi-Status.</li>
* </ul>
* 207 is used to signal "partial success" — callers must inspect the
* per-field {@code status} map in the response body to see which
* fields succeeded and which failed.
*/
static int computeOverallStatus(

Check failure on line 45 in commons/src/main/java/com/deftdevs/bootstrapi/commons/rest/_AbstractAllResourceImpl.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Refactor this method to reduce its Cognitive Complexity from 17 to the 15 allowed.

See more on https://sonarcloud.io/project/issues?id=deftdevs_bootstrapi&issues=AZ4_caUJJa4xLpZ-qzhM&open=AZ4_caUJJa4xLpZ-qzhM&pullRequest=222
final Map<String, _AllModelStatus> statusMap) {

if (statusMap == null || statusMap.isEmpty()) {
return Response.Status.OK.getStatusCode();
}

boolean anyServerError = false;
boolean anyClientError = false;
boolean anySuccess = false;
Integer firstClientErrorCode = null;
boolean clientErrorCodesDiffer = false;

for (_AllModelStatus entry : statusMap.values()) {
final int code = entry.getStatus();
if (code >= 500) {
anyServerError = true;
} else if (code >= 400) {
anyClientError = true;
if (firstClientErrorCode == null) {
firstClientErrorCode = code;
} else if (firstClientErrorCode != code) {
clientErrorCodesDiffer = true;
}
} else if (code >= 200 && code < 300) {
anySuccess = true;
}
}

if (anyServerError) {
return Response.Status.INTERNAL_SERVER_ERROR.getStatusCode();
}
if (anyClientError) {
if (anySuccess || clientErrorCodesDiffer) {
return MULTI_STATUS;
}
return firstClientErrorCode;
}
return Response.Status.OK.getStatusCode();
}
}
Loading
Loading