Skip to content

Commit

Permalink
[LOG] 🔊 Improve log by watching controllers
Browse files Browse the repository at this point in the history
Co-authored-by: Antoine Brunetti <[email protected]>
Signed-off-by: Cécile Chemin <[email protected]>
  • Loading branch information
CChemin and antoine-brunetti committed Oct 31, 2023
1 parent 5483a40 commit 21f7899
Show file tree
Hide file tree
Showing 25 changed files with 532 additions and 1,957 deletions.
13 changes: 0 additions & 13 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -136,22 +136,11 @@
<artifactId>sugoi-api-jms-store-provider</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>fr.insee.sugoi</groupId>
<artifactId>sugoi-api-event-log</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>fr.insee.sugoi</groupId>
<artifactId>sugoi-api-event-webhook</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>fr.insee.sugoi</groupId>
<artifactId>sugoi-api-event-metrics</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>fr.insee.sugoi</groupId>
<artifactId>sugoi-api-jms-utils</artifactId>
Expand Down Expand Up @@ -328,9 +317,7 @@
<module>sugoi-api-rest-services</module>
<module>sugoi-api-rest-old-services</module>
<module>sugoi-api-rest-commons-services</module>
<module>sugoi-api-event-log</module>
<module>sugoi-api-event-webhook</module>
<module>sugoi-api-event-metrics</module>
<module>sugoi-api-converter</module>
<module>sugoi-api-distribution</module>
<module>sugoi-api-file-config-provider</module>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,54 +18,16 @@ public class EventKeysConfig {
private EventKeysConfig() {}

public static final String REALM = "realm";
public static final String REALM_NAME = "realmName";
public static final String USERSTORAGE = "userStorage";
public static final String ORGANIZATION = "organization";
public static final String ORGANIZATION_ID = "organizationId";
public static final String ORGANIZATION_FILTER = "organizationFilter";

public static final String APPLICATION = "application";
public static final String APPLICATION_ID = "applicationId";
public static final String APPLICATION_NAME = "appName";
public static final String APPLICATION_FILTER = "applicationFilter";

public static final String GROUP = "group";
public static final String GROUP_ID = "groupId";
public static final String GROUP_NAME = "groupName";
public static final String GROUP_FILTER = "groupFilter";

public static final String HABILITATION = "habilitation";
public static final String HABILITATION_ID = "habilitationId";
public static final String HABILITATION_NAME = "habilitationName";
public static final String HABILITATION_FILTER = "habilitationFilter";

public static final String USER = "user";
public static final String USER_ID = "userId";
public static final String USER_NAME = "userName";
public static final String USER_MAIL = "userMail";
public static final String USER_FILTER = "userFilter";
public static final String USER_PROPERTIES = "userProperties";

public static final String MAILS = "mails";
public static final String ADDRESS = "address";
public static final String PROPERTIES = "properties";

public static final String PAGEABLE = "pageable";
public static final String PAGEABLE_RESULT = "pageableResult";
public static final String TYPE_RECHERCHE = "typeRecherche";
public static final String SENDMODES = "sendModes";

public static final String MUST_CHANGE_PASSWORD = "mustChangePassword";
public static final String PASSWORD_CHANGE_REQUEST = "pcr";
public static final String PASSWORD = "password";

public static final String ERROR = "error";

public static final String ATTRIBUTE_KEY = "attribute-key";
public static final String ATTRIBUTE_VALUE = "attribute-value";

public static final String TYPE = "type";

public static final String NEW_PASSWORD = "new-password";
public static final String OLD_PASSWORD = "old-password";
public static final String WEBSERVICE_TAG = "webserviceTag";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,90 +14,7 @@
package fr.insee.sugoi.core.event.model;

public enum SugoiEventTypeEnum {
CREATE_USER,
DELETE_USER,
UPDATE_USER,
FIND_USERS,
FIND_USER_BY_ID,
FIND_USER_BY_MAIL,
FIND_REALMS,
FIND_REALM_BY_ID,
CREATE_REALM,
DELETE_REALM,
UPDATE_REALM,
CREATE_ORGANIZATION,
DELETE_ORGANIZATION,
UPDATE_ORGANIZATION,
FIND_ORGANIZATIONS,
FIND_ORGANIZATION_BY_ID,
CREATE_HABILITATION,
DELETE_HABILITATION,
UPDATE_HABILITATION,
FIND_HABILITATIONS,
FIND_HABILITATION_BY_ID,
CREATE_GROUP,
DELETE_GROUP,
UPDATE_GROUP,
FIND_GROUPS,
FIND_GROUP_BY_ID,
CREATE_APPLICATION,
DELETE_APPLICATION,
UPDATE_APPLICATION,
FIND_APPLICATIONS,
FIND_APPLICATION_BY_ID,
CHANGE_PASSWORD,
INIT_PASSWORD,
REINIT_PASSWORD,
VALIDATE_CREDENTIAL,
ADD_USER_TO_GROUP,
DELETE_USER_FROM_GROUP,
CREATE_USER_ERROR,
DELETE_USER_ERROR,
UPDATE_USER_ERROR,
CREATE_REALM_ERROR,
DELETE_REALM_ERROR,
UPDATE_REALM_ERROR,
CREATE_ORGANIZATION_ERROR,
DELETE_ORGANIZATION_ERROR,
UPDATE_ORGANIZATION_ERROR,
CREATE_HABILITATION_ERROR,
DELETE_HABILITATION_ERROR,
UPDATE_HABILITATION_ERROR,
CREATE_GROUP_ERROR,
DELETE_GROUP_ERROR,
UPDATE_GROUP_ERROR,
CREATE_APPLICATION_ERROR,
DELETE_APPLICATION_ERROR,
UPDATE_APPLICATION_ERROR,
CHANGE_PASSWORD_ERROR,
INIT_PASSWORD_ERROR,
RESET_PASSWORD_ERROR,
VALIDATE_CREDENTIAL_ERROR,
ADD_USER_TO_GROUP_ERROR,
DELETE_USER_FROM_GROUP_ERROR,
FIND_USERS_ERROR,
FIND_USER_BY_ID_ERROR,
FIND_USER_BY_MAIL_ERROR,
FIND_REALMS_ERROR,
FIND_REALM_BY_ID_ERROR,
FIND_ORGANIZATIONS_ERROR,
FIND_ORGANIZATION_BY_ID_ERROR,
FIND_HABILITATIONS_ERROR,
FIND_HABILITATION_BY_ID_ERROR,
FIND_GROUPS_ERROR,
FIND_GROUP_BY_ID_ERROR,
FIND_APPLICATIONS_ERROR,
FIND_APPLICATION_BY_ID_ERROR,
ADD_APP_MANAGED_ATTRIBUTES,
ADD_APP_MANAGED_ATTRIBUTES_ERROR,
DELETE_APP_MANAGED_ATTRIBUTES,
DELETE_APP_MANAGED_ATTRIBUTES_ERROR,
SEND_LOGIN,
SEND_LOGIN_ERROR,
DELETE_USER_FROM_GROUP_MANAGER,
ADD_USER_TO_GROUP_MANAGER,
GET_GROUP_MANAGER,
DELETE_USER_FROM_GROUP_MANAGER_ERROR,
ADD_USER_TO_GROUP_MANAGER_ERROR,
GET_GROUP_MANAGER_ERROR
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@
package fr.insee.sugoi.core.service.impl;

import fr.insee.sugoi.core.configuration.GlobalKeysConfig;
import fr.insee.sugoi.core.event.configuration.EventKeysConfig;
import fr.insee.sugoi.core.event.model.SugoiEventTypeEnum;
import fr.insee.sugoi.core.event.publisher.SugoiEventPublisher;
import fr.insee.sugoi.core.model.ProviderRequest;
import fr.insee.sugoi.core.model.ProviderResponse;
import fr.insee.sugoi.core.model.ProviderResponse.ProviderResponseStatus;
Expand All @@ -30,149 +27,66 @@
import fr.insee.sugoi.model.paging.PageResult;
import fr.insee.sugoi.model.paging.PageableResult;
import fr.insee.sugoi.model.paging.SearchType;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class ApplicationServiceImpl implements ApplicationService {

@Autowired private StoreProvider storeProvider;
@Autowired private SugoiEventPublisher sugoiEventPublisher;
@Autowired private RealmProvider realmProvider;

@Override
public ProviderResponse create(
String realm, Application application, ProviderRequest providerRequest) {
try {
ProviderResponse response =
storeProvider.getWriterStore(realm).createApplication(application, providerRequest);
sugoiEventPublisher.publishCustomEvent(
realm,
null,
SugoiEventTypeEnum.CREATE_APPLICATION,
Map.ofEntries(Map.entry(EventKeysConfig.APPLICATION, application)));
if (!providerRequest.isAsynchronousAllowed()
&& response.getStatus().equals(ProviderResponseStatus.OK)) {
response.setEntity(findById(realm, application.getName()));
}
return response;
} catch (Exception e) {
sugoiEventPublisher.publishCustomEvent(
realm,
null,
SugoiEventTypeEnum.CREATE_APPLICATION_ERROR,
Map.ofEntries(
Map.entry(EventKeysConfig.APPLICATION, application),
Map.entry(EventKeysConfig.ERROR, e.toString())));
throw e;
ProviderResponse response =
storeProvider.getWriterStore(realm).createApplication(application, providerRequest);
if (!providerRequest.isAsynchronousAllowed()
&& response.getStatus().equals(ProviderResponseStatus.OK)) {
response.setEntity(findById(realm, application.getName()));
}
return response;
}

@Override
public ProviderResponse delete(String realm, String id, ProviderRequest providerRequest) {
try {
ProviderResponse response =
storeProvider.getWriterStore(realm).deleteApplication(id, providerRequest);
sugoiEventPublisher.publishCustomEvent(
realm,
null,
SugoiEventTypeEnum.DELETE_APPLICATION,
Map.ofEntries(Map.entry(EventKeysConfig.APPLICATION_ID, id)));
return response;
} catch (Exception e) {
sugoiEventPublisher.publishCustomEvent(
realm,
null,
SugoiEventTypeEnum.DELETE_APPLICATION_ERROR,
Map.ofEntries(
Map.entry(EventKeysConfig.APPLICATION_ID, id),
Map.entry(EventKeysConfig.ERROR, e.toString())));
throw e;
}
ProviderResponse response =
storeProvider.getWriterStore(realm).deleteApplication(id, providerRequest);
return response;
}

@Override
public ProviderResponse update(
String realm, Application application, ProviderRequest providerRequest) {
try {
ProviderResponse response =
storeProvider.getWriterStore(realm).updateApplication(application, providerRequest);
sugoiEventPublisher.publishCustomEvent(
realm,
null,
SugoiEventTypeEnum.UPDATE_APPLICATION,
Map.ofEntries(Map.entry(EventKeysConfig.APPLICATION, application)));
if (!providerRequest.isAsynchronousAllowed()
&& response.getStatus().equals(ProviderResponseStatus.OK)) {
response.setEntity(findById(realm, application.getName()));
}
return response;
} catch (Exception e) {
sugoiEventPublisher.publishCustomEvent(
realm,
null,
SugoiEventTypeEnum.UPDATE_APPLICATION_ERROR,
Map.ofEntries(
Map.entry(EventKeysConfig.APPLICATION, application),
Map.entry(EventKeysConfig.ERROR, e.toString())));
throw e;
ProviderResponse response =
storeProvider.getWriterStore(realm).updateApplication(application, providerRequest);
if (!providerRequest.isAsynchronousAllowed()
&& response.getStatus().equals(ProviderResponseStatus.OK)) {
response.setEntity(findById(realm, application.getName()));
}
return response;
}

@Override
public Application findById(String realm, String id) {
try {
Application app =
storeProvider
.getReaderStore(realm)
.getApplication(id)
.orElseThrow(() -> new ApplicationNotFoundException(realm, id));
sugoiEventPublisher.publishCustomEvent(
realm,
null,
SugoiEventTypeEnum.FIND_APPLICATION_BY_ID,
Map.ofEntries(Map.entry(EventKeysConfig.APPLICATION_ID, id)));
return app;
} catch (Exception e) {
sugoiEventPublisher.publishCustomEvent(
realm,
null,
SugoiEventTypeEnum.FIND_APPLICATION_BY_ID_ERROR,
Map.ofEntries(
Map.entry(EventKeysConfig.APPLICATION_ID, id),
Map.entry(EventKeysConfig.ERROR, e.toString())));
throw e;
}
Application app =
storeProvider
.getReaderStore(realm)
.getApplication(id)
.orElseThrow(() -> new ApplicationNotFoundException(realm, id));
return app;
}

@Override
public PageResult<Application> findByProperties(
String realm, Application applicationFilter, PageableResult pageableResult) {
try {
Realm r = realmProvider.load(realm).orElseThrow(() -> new RealmNotFoundException(realm));
pageableResult.setSizeWithMax(
Integer.parseInt(
r.getProperties().get(GlobalKeysConfig.APPLICATIONS_MAX_OUTPUT_SIZE).get(0)));
PageResult<Application> apps =
storeProvider
.getReaderStore(realm)
.searchApplications(applicationFilter, pageableResult, SearchType.AND.name());
sugoiEventPublisher.publishCustomEvent(
realm,
null,
SugoiEventTypeEnum.FIND_APPLICATIONS,
Map.ofEntries(Map.entry(EventKeysConfig.APPLICATION_FILTER, applicationFilter)));
return apps;
} catch (Exception e) {
sugoiEventPublisher.publishCustomEvent(
realm,
null,
SugoiEventTypeEnum.FIND_APPLICATIONS_ERROR,
Map.ofEntries(
Map.entry(EventKeysConfig.APPLICATION_FILTER, applicationFilter),
Map.entry(EventKeysConfig.ERROR, e.toString())));
throw e;
}
Realm r = realmProvider.load(realm).orElseThrow(() -> new RealmNotFoundException(realm));
pageableResult.setSizeWithMax(
Integer.parseInt(
r.getProperties().get(GlobalKeysConfig.APPLICATIONS_MAX_OUTPUT_SIZE).get(0)));
PageResult<Application> apps =
storeProvider
.getReaderStore(realm)
.searchApplications(applicationFilter, pageableResult, SearchType.AND.name());
return apps;
}
}
Loading

0 comments on commit 21f7899

Please sign in to comment.