Cleanup around Hooks and Hook templates
This commit is contained in:
committed by
Aleksandar Vidakovic
parent
2bb6445b4b
commit
073b1b04b6
+3
-5
@@ -24,9 +24,7 @@ import java.util.Set;
|
||||
|
||||
public final class HookApiConstants {
|
||||
|
||||
private HookApiConstants() {
|
||||
|
||||
}
|
||||
private HookApiConstants() {}
|
||||
|
||||
public static final String HOOK_RESOURCE_NAME = "HOOK";
|
||||
|
||||
@@ -72,10 +70,10 @@ public final class HookApiConstants {
|
||||
|
||||
public static final String SMSProviderIdParamName = "SMS Provider Id";
|
||||
|
||||
static final Set<String> RESPONSE_DATA_PARAMETERS = new HashSet<>(Arrays.asList(nameParamName, displayNameParamName,
|
||||
public static final Set<String> RESPONSE_DATA_PARAMETERS = new HashSet<>(Arrays.asList(nameParamName, displayNameParamName,
|
||||
templateIdParamName, isActiveParamName, configParamName, eventsParamName, templateNameParamName));
|
||||
|
||||
static final Set<String> UPDATE_REQUEST_DATA_PARAMETERS = new HashSet<>(Arrays.asList(nameParamName, displayNameParamName,
|
||||
public static final Set<String> UPDATE_REQUEST_DATA_PARAMETERS = new HashSet<>(Arrays.asList(nameParamName, displayNameParamName,
|
||||
templateIdParamName, isActiveParamName, configParamName, eventsParamName, templateNameParamName));
|
||||
|
||||
}
|
||||
|
||||
+2
-14
@@ -42,6 +42,7 @@ import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.core.Context;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.UriInfo;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.apache.fineract.commands.domain.CommandWrapper;
|
||||
import org.apache.fineract.commands.service.CommandWrapperBuilder;
|
||||
import org.apache.fineract.commands.service.PortfolioCommandSourceWritePlatformService;
|
||||
@@ -52,16 +53,14 @@ import org.apache.fineract.infrastructure.core.serialization.DefaultToApiJsonSer
|
||||
import org.apache.fineract.infrastructure.hooks.data.HookData;
|
||||
import org.apache.fineract.infrastructure.hooks.service.HookReadPlatformService;
|
||||
import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Path("/hooks")
|
||||
@Consumes({ MediaType.APPLICATION_JSON })
|
||||
@Produces({ MediaType.APPLICATION_JSON })
|
||||
@Component
|
||||
@Scope("singleton")
|
||||
@Tag(name = "Hooks", description = "Hooks are a mechanism to trigger custom code on the occurence of events. ")
|
||||
@RequiredArgsConstructor
|
||||
public class HookApiResource {
|
||||
|
||||
private final PlatformSecurityContext context;
|
||||
@@ -70,17 +69,6 @@ public class HookApiResource {
|
||||
private final ApiRequestParameterHelper apiRequestParameterHelper;
|
||||
private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService;
|
||||
|
||||
@Autowired
|
||||
public HookApiResource(final PlatformSecurityContext context, final HookReadPlatformService readPlatformService,
|
||||
final DefaultToApiJsonSerializer<HookData> toApiJsonSerializer, final ApiRequestParameterHelper apiRequestParameterHelper,
|
||||
final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService) {
|
||||
this.context = context;
|
||||
this.readPlatformService = readPlatformService;
|
||||
this.toApiJsonSerializer = toApiJsonSerializer;
|
||||
this.apiRequestParameterHelper = apiRequestParameterHelper;
|
||||
this.commandsSourceWritePlatformService = commandsSourceWritePlatformService;
|
||||
}
|
||||
|
||||
@GET
|
||||
@Operation(summary = "Retrieve Hooks", description = "Returns the list of hooks.\n" + "\n" + "Example Requests:\n" + "\n" + "hooks")
|
||||
@ApiResponses({
|
||||
|
||||
+2
-14
@@ -20,24 +20,12 @@ package org.apache.fineract.infrastructure.hooks.data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
import lombok.Data;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@Data
|
||||
public class Entity implements Serializable {
|
||||
|
||||
private String name;
|
||||
|
||||
private List<String> actions;
|
||||
|
||||
public void setName(final String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public void setActions(final List<String> actions) {
|
||||
this.actions = actions;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+5
-14
@@ -19,7 +19,12 @@
|
||||
package org.apache.fineract.infrastructure.hooks.data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
@Getter
|
||||
public final class Event implements Serializable {
|
||||
|
||||
private final String actionName;
|
||||
@@ -28,18 +33,4 @@ public final class Event implements Serializable {
|
||||
public static Event instance(final String actionName, final String entityName) {
|
||||
return new Event(actionName, entityName);
|
||||
}
|
||||
|
||||
private Event(final String actionName, final String entityName) {
|
||||
this.actionName = actionName;
|
||||
this.entityName = entityName;
|
||||
}
|
||||
|
||||
public String getActionName() {
|
||||
return this.actionName;
|
||||
}
|
||||
|
||||
public String getEntityName() {
|
||||
return this.entityName;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+3
-18
@@ -67,35 +67,20 @@ public class EventResultSetExtractor implements ResultSetExtractor<List<Grouping
|
||||
final Grouping group = new Grouping();
|
||||
group.setName(groupingEntry.getKey());
|
||||
for (final Map.Entry<String, List<String>> entityEntry : groupingEntry.getValue().entrySet()) {
|
||||
final List<String> actions = new ArrayList<>();
|
||||
final Entity entity = new Entity();
|
||||
entity.setName(entityEntry.getKey());
|
||||
for (final String action : entityEntry.getValue()) {
|
||||
actions.add(action);
|
||||
}
|
||||
final List<String> actions = new ArrayList<>(entityEntry.getValue());
|
||||
Collections.sort(actions);
|
||||
entity.setActions(actions);
|
||||
entities.add(entity);
|
||||
}
|
||||
|
||||
Collections.sort(entities, new Comparator<Entity>() {
|
||||
|
||||
@Override
|
||||
public int compare(final Entity entity1, final Entity entity2) {
|
||||
return entity1.getName().compareTo(entity2.getName());
|
||||
}
|
||||
});
|
||||
entities.sort(Comparator.comparing(Entity::getName));
|
||||
group.setEntities(entities);
|
||||
groupings.add(group);
|
||||
}
|
||||
|
||||
Collections.sort(groupings, new Comparator<Grouping>() {
|
||||
|
||||
@Override
|
||||
public int compare(final Grouping grouping1, final Grouping grouping2) {
|
||||
return grouping1.getName().compareTo(grouping2.getName());
|
||||
}
|
||||
});
|
||||
groupings.sort(Comparator.comparing(Grouping::getName));
|
||||
|
||||
return groupings;
|
||||
}
|
||||
|
||||
+7
-24
@@ -19,8 +19,13 @@
|
||||
package org.apache.fineract.infrastructure.hooks.data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
@Getter
|
||||
public final class Field implements Serializable {
|
||||
|
||||
private final String fieldName;
|
||||
@@ -30,32 +35,10 @@ public final class Field implements Serializable {
|
||||
private final String placeholder;
|
||||
|
||||
public static Field fromConfig(final String fieldName, final String fieldValue) {
|
||||
return new Field(null, fieldName, fieldValue, null, null);
|
||||
return new Field(fieldName, fieldValue, null, null, null);
|
||||
}
|
||||
|
||||
public static Field fromSchema(final String fieldType, final String fieldName, final Boolean optional, final String placeholder) {
|
||||
return new Field(fieldType, fieldName, null, optional, placeholder);
|
||||
return new Field(fieldName, null, fieldType, optional, placeholder);
|
||||
}
|
||||
|
||||
private Field(final String fieldType, final String fieldName, final String fieldValue, final Boolean optional,
|
||||
final String placeholder) {
|
||||
this.fieldType = fieldType;
|
||||
this.fieldName = fieldName;
|
||||
this.fieldValue = fieldValue;
|
||||
this.optional = optional;
|
||||
this.placeholder = placeholder;
|
||||
}
|
||||
|
||||
public String getFieldName() {
|
||||
return this.fieldName;
|
||||
}
|
||||
|
||||
public String getFieldValue() {
|
||||
return this.fieldValue;
|
||||
}
|
||||
|
||||
public String getFieldType() {
|
||||
return this.fieldType;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+2
-14
@@ -20,24 +20,12 @@ package org.apache.fineract.infrastructure.hooks.data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
import lombok.Data;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@Data
|
||||
public class Grouping implements Serializable {
|
||||
|
||||
private String name;
|
||||
|
||||
private List<Entity> entities;
|
||||
|
||||
public void setName(final String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public void setEntities(final List<Entity> entities) {
|
||||
this.entities = entities;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+7
-41
@@ -21,7 +21,12 @@ package org.apache.fineract.infrastructure.hooks.data;
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDate;
|
||||
import java.util.List;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
@Getter
|
||||
public final class HookData implements Serializable {
|
||||
|
||||
private final Long id;
|
||||
@@ -44,7 +49,7 @@ public final class HookData implements Serializable {
|
||||
public static HookData instance(final Long id, final String name, final String displayName, final boolean isActive,
|
||||
final LocalDate createdAt, final LocalDate updatedAt, final Long templateId, final List<Event> registeredEvents,
|
||||
final List<Field> config, final String templateName) {
|
||||
return new HookData(id, name, displayName, isActive, createdAt, updatedAt, templateId, registeredEvents, config, templateName, null,
|
||||
return new HookData(id, name, displayName, isActive, createdAt, updatedAt, templateId, templateName, registeredEvents, config, null,
|
||||
null);
|
||||
}
|
||||
|
||||
@@ -55,45 +60,6 @@ public final class HookData implements Serializable {
|
||||
public static HookData templateExisting(final HookData hookData, final List<HookTemplateData> templates,
|
||||
final List<Grouping> groupings) {
|
||||
return new HookData(hookData.id, hookData.name, hookData.displayName, hookData.isActive, hookData.createdAt, hookData.updatedAt,
|
||||
hookData.templateId, hookData.events, hookData.config, hookData.templateName, templates, groupings);
|
||||
hookData.templateId, hookData.templateName, hookData.events, hookData.config, templates, groupings);
|
||||
}
|
||||
|
||||
private HookData(final Long id, final String name, final String displayName, final Boolean isActive, final LocalDate createdAt,
|
||||
final LocalDate updatedAt, final Long templateId, final List<Event> events, final List<Field> config, final String templateName,
|
||||
final List<HookTemplateData> templates, final List<Grouping> groupings) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.displayName = displayName;
|
||||
this.isActive = isActive;
|
||||
this.createdAt = createdAt;
|
||||
this.updatedAt = updatedAt;
|
||||
this.templateId = templateId;
|
||||
this.templateName = templateName;
|
||||
|
||||
// associations
|
||||
this.events = events;
|
||||
this.config = config;
|
||||
|
||||
// template
|
||||
this.templates = templates;
|
||||
this.groupings = groupings;
|
||||
|
||||
}
|
||||
|
||||
public Long getHookId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
public List<HookTemplateData> getTemplates() {
|
||||
return this.templates;
|
||||
}
|
||||
|
||||
public List<Grouping> getGroupings() {
|
||||
return this.groupings;
|
||||
}
|
||||
|
||||
public String getTemplateName() {
|
||||
return this.templateName;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+4
-9
@@ -20,8 +20,11 @@ package org.apache.fineract.infrastructure.hooks.data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
public final class HookTemplateData implements Serializable {
|
||||
|
||||
private final Long id;
|
||||
@@ -34,16 +37,8 @@ public final class HookTemplateData implements Serializable {
|
||||
return new HookTemplateData(id, name, schema);
|
||||
}
|
||||
|
||||
private HookTemplateData(final Long id, final String name, final List<Field> schema) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
|
||||
// associations
|
||||
this.schema = schema;
|
||||
}
|
||||
|
||||
public Long getServiceId() {
|
||||
return this.id;
|
||||
return id;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+1
-3
@@ -68,9 +68,7 @@ public class Hook extends AbstractAuditableCustom {
|
||||
@JoinColumn(name = "ugd_template_id", referencedColumnName = "id", nullable = true)
|
||||
private Template ugdTemplate;
|
||||
|
||||
protected Hook() {
|
||||
//
|
||||
}
|
||||
protected Hook() {}
|
||||
|
||||
public static Hook fromJson(final JsonCommand command, final HookTemplate template, final Set<HookConfiguration> config,
|
||||
final Set<HookResource> events, final Template ugdTemplate) {
|
||||
|
||||
+4
-16
@@ -19,25 +19,13 @@
|
||||
package org.apache.fineract.infrastructure.hooks.event;
|
||||
|
||||
import java.io.Serializable;
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
@Getter
|
||||
public class HookEventSource implements Serializable {
|
||||
|
||||
private final String entityName;
|
||||
|
||||
private final String actionName;
|
||||
|
||||
public HookEventSource(final String entityName, final String actionName) {
|
||||
|
||||
this.entityName = entityName;
|
||||
this.actionName = actionName;
|
||||
}
|
||||
|
||||
public String getEntityName() {
|
||||
return this.entityName;
|
||||
}
|
||||
|
||||
public String getActionName() {
|
||||
return this.actionName;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+2
-7
@@ -18,30 +18,25 @@
|
||||
*/
|
||||
package org.apache.fineract.infrastructure.hooks.handler;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.apache.fineract.commands.annotation.CommandType;
|
||||
import org.apache.fineract.commands.handler.NewCommandSourceHandler;
|
||||
import org.apache.fineract.infrastructure.core.api.JsonCommand;
|
||||
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
|
||||
import org.apache.fineract.infrastructure.hooks.service.HookWritePlatformService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@Service
|
||||
@CommandType(entity = "HOOK", action = "CREATE")
|
||||
@RequiredArgsConstructor
|
||||
public class CreateHookCommandHandler implements NewCommandSourceHandler {
|
||||
|
||||
private final HookWritePlatformService writePlatformService;
|
||||
|
||||
@Autowired
|
||||
public CreateHookCommandHandler(final HookWritePlatformService writePlatformService) {
|
||||
this.writePlatformService = writePlatformService;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@Override
|
||||
public CommandProcessingResult processCommand(final JsonCommand command) {
|
||||
|
||||
return this.writePlatformService.createHook(command);
|
||||
}
|
||||
|
||||
|
||||
+2
-8
@@ -18,31 +18,25 @@
|
||||
*/
|
||||
package org.apache.fineract.infrastructure.hooks.handler;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.apache.fineract.commands.annotation.CommandType;
|
||||
import org.apache.fineract.commands.handler.NewCommandSourceHandler;
|
||||
import org.apache.fineract.infrastructure.core.api.JsonCommand;
|
||||
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
|
||||
import org.apache.fineract.infrastructure.hooks.service.HookWritePlatformService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@Service
|
||||
@CommandType(entity = "HOOK", action = "DELETE")
|
||||
@RequiredArgsConstructor
|
||||
public class DeleteHookCommandHandler implements NewCommandSourceHandler {
|
||||
|
||||
private final HookWritePlatformService writePlatformService;
|
||||
|
||||
@Autowired
|
||||
public DeleteHookCommandHandler(final HookWritePlatformService writePlatformService) {
|
||||
this.writePlatformService = writePlatformService;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@Override
|
||||
public CommandProcessingResult processCommand(final JsonCommand command) {
|
||||
|
||||
return this.writePlatformService.deleteHook(command.entityId());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+2
-8
@@ -18,31 +18,25 @@
|
||||
*/
|
||||
package org.apache.fineract.infrastructure.hooks.handler;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.apache.fineract.commands.annotation.CommandType;
|
||||
import org.apache.fineract.commands.handler.NewCommandSourceHandler;
|
||||
import org.apache.fineract.infrastructure.core.api.JsonCommand;
|
||||
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
|
||||
import org.apache.fineract.infrastructure.hooks.service.HookWritePlatformService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@Service
|
||||
@CommandType(entity = "HOOK", action = "UPDATE")
|
||||
@RequiredArgsConstructor
|
||||
public class UpdateHookCommandHandler implements NewCommandSourceHandler {
|
||||
|
||||
private final HookWritePlatformService writePlatformService;
|
||||
|
||||
@Autowired
|
||||
public UpdateHookCommandHandler(final HookWritePlatformService writePlatformService) {
|
||||
this.writePlatformService = writePlatformService;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@Override
|
||||
public CommandProcessingResult processCommand(final JsonCommand command) {
|
||||
|
||||
return this.writePlatformService.updateHook(command.entityId(), command);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+5
-14
@@ -19,6 +19,8 @@
|
||||
package org.apache.fineract.infrastructure.hooks.listener;
|
||||
|
||||
import java.util.List;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.fineract.infrastructure.core.domain.FineractPlatformTenant;
|
||||
import org.apache.fineract.infrastructure.core.service.ThreadLocalContextUtil;
|
||||
import org.apache.fineract.infrastructure.hooks.domain.Hook;
|
||||
@@ -29,28 +31,17 @@ import org.apache.fineract.infrastructure.hooks.processor.HookProcessorProvider;
|
||||
import org.apache.fineract.infrastructure.hooks.service.HookReadPlatformService;
|
||||
import org.apache.fineract.infrastructure.security.service.TenantDetailsService;
|
||||
import org.apache.fineract.useradministration.domain.AppUser;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
@Slf4j
|
||||
public class FineractHookListener implements HookListener {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(FineractHookListener.class);
|
||||
|
||||
private final HookProcessorProvider hookProcessorProvider;
|
||||
private final HookReadPlatformService hookReadPlatformService;
|
||||
private final TenantDetailsService tenantDetailsService;
|
||||
|
||||
@Autowired
|
||||
public FineractHookListener(final HookProcessorProvider hookProcessorProvider, final HookReadPlatformService hookReadPlatformService,
|
||||
final TenantDetailsService tenantDetailsService) {
|
||||
this.hookReadPlatformService = hookReadPlatformService;
|
||||
this.hookProcessorProvider = hookProcessorProvider;
|
||||
this.tenantDetailsService = tenantDetailsService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onApplicationEvent(final HookEvent event) {
|
||||
final String tenantIdentifier = event.getTenantIdentifier();
|
||||
@@ -73,7 +64,7 @@ public class FineractHookListener implements HookListener {
|
||||
try {
|
||||
processor.process(hook, appUser, payload, entityName, actionName, tenantIdentifier, authToken);
|
||||
} catch (Throwable e) {
|
||||
LOG.error("Hook {} failed in HookProcessor {} for tenantIdentifier/user {}/{}, entityName: {}, actionName: {}, payload {} ",
|
||||
log.error("Hook {} failed in HookProcessor {} for tenantIdentifier/user {}/{}, entityName: {}, actionName: {}, payload {} ",
|
||||
hook.getId(), processor.getClass().getSimpleName(), tenantIdentifier, appUser, entityName, actionName, payload, e);
|
||||
}
|
||||
}
|
||||
|
||||
+3
-3
@@ -26,18 +26,18 @@ import com.google.gson.JsonObject;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.apache.fineract.infrastructure.hooks.domain.Hook;
|
||||
import org.apache.fineract.infrastructure.hooks.domain.HookConfiguration;
|
||||
import org.apache.fineract.useradministration.domain.AppUser;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import retrofit2.Callback;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class ElasticSearchHookProcessor implements HookProcessor {
|
||||
|
||||
@Autowired
|
||||
private ProcessorHelper processorHelper;
|
||||
private final ProcessorHelper processorHelper;
|
||||
|
||||
@Override
|
||||
public void process(final Hook hook, @SuppressWarnings("unused") final AppUser appUser, final String payload, final String entityName,
|
||||
|
||||
+5
-17
@@ -28,6 +28,8 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.fineract.infrastructure.core.exception.GeneralPlatformDomainRuleException;
|
||||
import org.apache.fineract.infrastructure.hooks.domain.Hook;
|
||||
import org.apache.fineract.infrastructure.hooks.domain.HookConfiguration;
|
||||
@@ -40,16 +42,13 @@ import org.apache.fineract.template.domain.Template;
|
||||
import org.apache.fineract.template.domain.TemplateRepository;
|
||||
import org.apache.fineract.template.service.TemplateMergeService;
|
||||
import org.apache.fineract.useradministration.domain.AppUser;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
@RequiredArgsConstructor
|
||||
public class MessageGatewayHookProcessor implements HookProcessor {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(MessageGatewayHookProcessor.class);
|
||||
|
||||
private final ClientRepositoryWrapper clientRepository;
|
||||
private final TemplateRepository templateRepository;
|
||||
private final TemplateMergeService templateMergeService;
|
||||
@@ -57,17 +56,6 @@ public class MessageGatewayHookProcessor implements HookProcessor {
|
||||
private final SmsMessageRepository smsMessageRepository;
|
||||
private final SmsMessageScheduledJobService smsMessageScheduledJobService;
|
||||
|
||||
@Autowired
|
||||
public MessageGatewayHookProcessor(ClientRepositoryWrapper clientRepository, TemplateRepository templateRepository,
|
||||
TemplateMergeService templateMergeService, SmsMessageRepository smsMessageRepository,
|
||||
SmsMessageScheduledJobService smsMessageScheduledJobService) {
|
||||
this.clientRepository = clientRepository;
|
||||
this.templateRepository = templateRepository;
|
||||
this.templateMergeService = templateMergeService;
|
||||
this.smsMessageRepository = smsMessageRepository;
|
||||
this.smsMessageScheduledJobService = smsMessageScheduledJobService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void process(final Hook hook, @SuppressWarnings("unused") final AppUser appUser, final String payload, final String entityName,
|
||||
final String actionName, final String tenantIdentifier, final String authToken) throws IOException {
|
||||
@@ -95,7 +83,7 @@ public class MessageGatewayHookProcessor implements HookProcessor {
|
||||
template = templates.get(0);
|
||||
}
|
||||
if (template == null) {
|
||||
LOG.error("Error : {} with name {}", "Template not found", templateName);
|
||||
log.error("Error : {} with name {}", "Template not found", templateName);
|
||||
throw new GeneralPlatformDomainRuleException("error.msg.templates.not.found", "Template not found", templateName);
|
||||
}
|
||||
|
||||
|
||||
+2
-11
@@ -29,6 +29,7 @@ import com.google.gson.JsonParser;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.apache.fineract.infrastructure.hooks.domain.Hook;
|
||||
import org.apache.fineract.infrastructure.hooks.domain.HookConfiguration;
|
||||
import org.apache.fineract.infrastructure.hooks.domain.HookConfigurationRepository;
|
||||
@@ -37,11 +38,11 @@ import org.apache.fineract.portfolio.client.domain.Client;
|
||||
import org.apache.fineract.portfolio.client.domain.ClientRepositoryWrapper;
|
||||
import org.apache.fineract.template.service.TemplateMergeService;
|
||||
import org.apache.fineract.useradministration.domain.AppUser;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import retrofit2.Callback;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class TwilioHookProcessor implements HookProcessor {
|
||||
|
||||
private final HookConfigurationRepository hookConfigurationRepository;
|
||||
@@ -49,16 +50,6 @@ public class TwilioHookProcessor implements HookProcessor {
|
||||
private final ClientRepositoryWrapper clientRepositoryWrapper;
|
||||
private final ProcessorHelper processorHelper;
|
||||
|
||||
@Autowired
|
||||
public TwilioHookProcessor(final HookConfigurationRepository hookConfigurationRepository,
|
||||
final TemplateMergeService templateMergeService, final ClientRepositoryWrapper clientRepositoryWrapper,
|
||||
ProcessorHelper processorHelper) {
|
||||
this.hookConfigurationRepository = hookConfigurationRepository;
|
||||
this.templateMergeService = templateMergeService;
|
||||
this.clientRepositoryWrapper = clientRepositoryWrapper;
|
||||
this.processorHelper = processorHelper;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void process(final Hook hook, @SuppressWarnings("unused") final AppUser appUser, final String payload, final String entityName,
|
||||
final String actionName, final String tenantIdentifier, final String authToken) throws IOException {
|
||||
|
||||
+2
-6
@@ -27,23 +27,19 @@ import com.google.gson.JsonParser;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.apache.fineract.infrastructure.hooks.domain.Hook;
|
||||
import org.apache.fineract.infrastructure.hooks.domain.HookConfiguration;
|
||||
import org.apache.fineract.useradministration.domain.AppUser;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import retrofit2.Callback;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class WebHookProcessor implements HookProcessor {
|
||||
|
||||
private final ProcessorHelper processorHelper;
|
||||
|
||||
@Autowired
|
||||
public WebHookProcessor(ProcessorHelper processorHelper) {
|
||||
this.processorHelper = processorHelper;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void process(final Hook hook, @SuppressWarnings("unused") final AppUser appUser, final String payload, final String entityName,
|
||||
final String actionName, final String tenantIdentifier, final String authToken) {
|
||||
|
||||
+2
-6
@@ -27,6 +27,7 @@ import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.fineract.infrastructure.core.data.ApiParameterError;
|
||||
import org.apache.fineract.infrastructure.core.data.DataValidatorBuilder;
|
||||
@@ -34,10 +35,10 @@ import org.apache.fineract.infrastructure.core.exception.InvalidJsonException;
|
||||
import org.apache.fineract.infrastructure.core.exception.PlatformApiDataValidationException;
|
||||
import org.apache.fineract.infrastructure.core.serialization.FromJsonHelper;
|
||||
import org.apache.fineract.infrastructure.hooks.api.HookApiConstants;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class HookCommandFromApiJsonDeserializer {
|
||||
|
||||
/**
|
||||
@@ -47,11 +48,6 @@ public class HookCommandFromApiJsonDeserializer {
|
||||
Arrays.asList("name", "displayName", "isActive", "events", "config", "templateId"));
|
||||
private final FromJsonHelper fromApiJsonHelper;
|
||||
|
||||
@Autowired
|
||||
public HookCommandFromApiJsonDeserializer(final FromJsonHelper fromApiJsonHelper) {
|
||||
this.fromApiJsonHelper = fromApiJsonHelper;
|
||||
}
|
||||
|
||||
public void validateForCreate(final String json) {
|
||||
if (StringUtils.isBlank(json)) {
|
||||
throw new InvalidJsonException();
|
||||
|
||||
+19
-37
@@ -23,6 +23,7 @@ import java.sql.SQLException;
|
||||
import java.time.LocalDate;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.apache.fineract.infrastructure.core.domain.JdbcSupport;
|
||||
import org.apache.fineract.infrastructure.hooks.data.Event;
|
||||
import org.apache.fineract.infrastructure.hooks.data.EventResultSetExtractor;
|
||||
@@ -34,7 +35,6 @@ import org.apache.fineract.infrastructure.hooks.domain.Hook;
|
||||
import org.apache.fineract.infrastructure.hooks.domain.HookRepository;
|
||||
import org.apache.fineract.infrastructure.hooks.exception.HookNotFoundException;
|
||||
import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.dao.EmptyResultDataAccessException;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
@@ -42,37 +42,30 @@ import org.springframework.jdbc.core.RowMapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class HookReadPlatformServiceImpl implements HookReadPlatformService {
|
||||
|
||||
private final JdbcTemplate jdbcTemplate;
|
||||
private final HookRepository hookRepository;
|
||||
private final PlatformSecurityContext context;
|
||||
|
||||
@Autowired
|
||||
public HookReadPlatformServiceImpl(final PlatformSecurityContext context, final HookRepository hookRepository,
|
||||
final JdbcTemplate jdbcTemplate) {
|
||||
this.context = context;
|
||||
this.hookRepository = hookRepository;
|
||||
this.jdbcTemplate = jdbcTemplate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<HookData> retrieveAllHooks() {
|
||||
this.context.authenticatedUser();
|
||||
final HookMapper rm = new HookMapper(this.jdbcTemplate);
|
||||
context.authenticatedUser();
|
||||
final HookMapper rm = new HookMapper(jdbcTemplate);
|
||||
final String sql = "select " + rm.schema() + " order by h.name";
|
||||
|
||||
return this.jdbcTemplate.query(sql, rm); // NOSONAR
|
||||
return jdbcTemplate.query(sql, rm); // NOSONAR
|
||||
}
|
||||
|
||||
@Override
|
||||
public HookData retrieveHook(final Long hookId) {
|
||||
try {
|
||||
this.context.authenticatedUser();
|
||||
final HookMapper rm = new HookMapper(this.jdbcTemplate);
|
||||
context.authenticatedUser();
|
||||
final HookMapper rm = new HookMapper(jdbcTemplate);
|
||||
final String sql = "select " + rm.schema() + " where h.id = ?";
|
||||
|
||||
return this.jdbcTemplate.queryForObject(sql, rm, new Object[] { hookId }); // NOSONAR
|
||||
return jdbcTemplate.queryForObject(sql, rm, hookId); // NOSONAR
|
||||
} catch (final EmptyResultDataAccessException e) {
|
||||
throw new HookNotFoundException(hookId, e);
|
||||
}
|
||||
@@ -82,24 +75,23 @@ public class HookReadPlatformServiceImpl implements HookReadPlatformService {
|
||||
@Override
|
||||
@Cacheable(value = "hooks", key = "T(org.apache.fineract.infrastructure.core.service.ThreadLocalContextUtil).getTenant().getTenantIdentifier().concat('HK')")
|
||||
public List<Hook> retrieveHooksByEvent(final String entityName, final String actionName) {
|
||||
|
||||
return this.hookRepository.findAllHooksListeningToEvent(entityName, actionName);
|
||||
return hookRepository.findAllHooksListeningToEvent(entityName, actionName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public HookData retrieveNewHookDetails(final String templateName) {
|
||||
|
||||
this.context.authenticatedUser();
|
||||
final TemplateMapper rm = new TemplateMapper(this.jdbcTemplate);
|
||||
context.authenticatedUser();
|
||||
final TemplateMapper rm = new TemplateMapper(jdbcTemplate);
|
||||
final String sql;
|
||||
List<HookTemplateData> templateData;
|
||||
|
||||
if (templateName == null) {
|
||||
sql = "select " + rm.schema() + " order by s.name";
|
||||
templateData = this.jdbcTemplate.query(sql, rm); // NOSONAR
|
||||
templateData = jdbcTemplate.query(sql, rm); // NOSONAR
|
||||
} else {
|
||||
sql = "select " + rm.schema() + " where s.name = ? order by s.name";
|
||||
templateData = this.jdbcTemplate.query(sql, rm, new Object[] { templateName }); // NOSONAR
|
||||
templateData = jdbcTemplate.query(sql, rm, templateName); // NOSONAR
|
||||
}
|
||||
|
||||
final List<Grouping> events = getTemplateForEvents();
|
||||
@@ -111,17 +103,14 @@ public class HookReadPlatformServiceImpl implements HookReadPlatformService {
|
||||
final String sql = "select p.grouping, p.entity_name, p.action_name from m_permission p "
|
||||
+ " where p.action_name NOT LIKE '%CHECKER%' AND p.action_name NOT LIKE '%READ%' " + " order by p.grouping, p.entity_name ";
|
||||
final EventResultSetExtractor extractor = new EventResultSetExtractor();
|
||||
return this.jdbcTemplate.query(sql, extractor);
|
||||
return jdbcTemplate.query(sql, extractor);
|
||||
}
|
||||
|
||||
@RequiredArgsConstructor
|
||||
private static final class HookMapper implements RowMapper<HookData> {
|
||||
|
||||
private final JdbcTemplate jdbcTemplate;
|
||||
|
||||
HookMapper(final JdbcTemplate jdbcTemplate) {
|
||||
this.jdbcTemplate = jdbcTemplate;
|
||||
}
|
||||
|
||||
public String schema() {
|
||||
return " h.id, s.name as name, h.name as display_name, h.is_active, h.created_date,"
|
||||
+ " h.lastmodified_date, h.ugd_template_id, tp.name as ugd_template_name, "
|
||||
@@ -152,7 +141,7 @@ public class HookReadPlatformServiceImpl implements HookReadPlatformService {
|
||||
final HookEventMapper rm = new HookEventMapper();
|
||||
final String sql = "select " + rm.schema() + " where h.id= ?";
|
||||
|
||||
return this.jdbcTemplate.query(sql, rm, new Object[] { hookId }); // NOSONAR
|
||||
return jdbcTemplate.query(sql, rm, hookId); // NOSONAR
|
||||
}
|
||||
|
||||
private List<Field> retrieveConfig(final Long hookId) {
|
||||
@@ -160,9 +149,7 @@ public class HookReadPlatformServiceImpl implements HookReadPlatformService {
|
||||
final HookConfigMapper rm = new HookConfigMapper();
|
||||
final String sql = "select " + rm.schema() + " where h.id= ? order by hc.field_name";
|
||||
|
||||
final List<Field> fields = this.jdbcTemplate.query(sql, rm, new Object[] { hookId }); // NOSONAR
|
||||
|
||||
return fields;
|
||||
return jdbcTemplate.query(sql, rm, hookId); // NOSONAR
|
||||
}
|
||||
}
|
||||
|
||||
@@ -194,14 +181,11 @@ public class HookReadPlatformServiceImpl implements HookReadPlatformService {
|
||||
}
|
||||
}
|
||||
|
||||
@RequiredArgsConstructor
|
||||
private static final class TemplateMapper implements RowMapper<HookTemplateData> {
|
||||
|
||||
private final JdbcTemplate jdbcTemplate;
|
||||
|
||||
TemplateMapper(final JdbcTemplate jdbcTemplate) {
|
||||
this.jdbcTemplate = jdbcTemplate;
|
||||
}
|
||||
|
||||
public String schema() {
|
||||
return " s.id, s.name from m_hook_templates s ";
|
||||
}
|
||||
@@ -221,9 +205,7 @@ public class HookReadPlatformServiceImpl implements HookReadPlatformService {
|
||||
final TemplateSchemaMapper rm = new TemplateSchemaMapper();
|
||||
final String sql = "select " + rm.schema() + " where s.id= ? order by hs.field_name ";
|
||||
|
||||
final List<Field> fields = this.jdbcTemplate.query(sql, rm, new Object[] { templateId }); // NOSONAR
|
||||
|
||||
return fields;
|
||||
return jdbcTemplate.query(sql, rm, templateId); // NOSONAR;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+2
-15
@@ -37,6 +37,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import javax.persistence.PersistenceException;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.apache.commons.lang3.exception.ExceptionUtils;
|
||||
import org.apache.fineract.infrastructure.core.api.JsonCommand;
|
||||
import org.apache.fineract.infrastructure.core.data.ApiParameterError;
|
||||
@@ -62,7 +63,6 @@ import org.apache.fineract.infrastructure.security.service.PlatformSecurityConte
|
||||
import org.apache.fineract.template.domain.Template;
|
||||
import org.apache.fineract.template.domain.TemplateRepository;
|
||||
import org.apache.fineract.template.exception.TemplateNotFoundException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
import org.springframework.dao.DataIntegrityViolationException;
|
||||
import org.springframework.orm.jpa.JpaSystemException;
|
||||
@@ -70,6 +70,7 @@ import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class HookWritePlatformServiceJpaRepositoryImpl implements HookWritePlatformService {
|
||||
|
||||
private final PlatformSecurityContext context;
|
||||
@@ -80,20 +81,6 @@ public class HookWritePlatformServiceJpaRepositoryImpl implements HookWritePlatf
|
||||
private final FromJsonHelper fromApiJsonHelper;
|
||||
private final ProcessorHelper processorHelper;
|
||||
|
||||
@Autowired
|
||||
public HookWritePlatformServiceJpaRepositoryImpl(final PlatformSecurityContext context, final HookRepository hookRepository,
|
||||
final HookTemplateRepository hookTemplateRepository, final TemplateRepository ugdTemplateRepository,
|
||||
final HookCommandFromApiJsonDeserializer fromApiJsonDeserializer, final FromJsonHelper fromApiJsonHelper,
|
||||
ProcessorHelper processorHelper) {
|
||||
this.context = context;
|
||||
this.hookRepository = hookRepository;
|
||||
this.hookTemplateRepository = hookTemplateRepository;
|
||||
this.ugdTemplateRepository = ugdTemplateRepository;
|
||||
this.fromApiJsonDeserializer = fromApiJsonDeserializer;
|
||||
this.fromApiJsonHelper = fromApiJsonHelper;
|
||||
this.processorHelper = processorHelper;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@Override
|
||||
@CacheEvict(value = "hooks", allEntries = true)
|
||||
|
||||
+3
-17
@@ -25,6 +25,7 @@ import java.util.Map;
|
||||
import java.util.Set;
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.jms.Queue;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.apache.activemq.command.ActiveMQQueue;
|
||||
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
|
||||
import org.apache.fineract.infrastructure.core.service.ThreadLocalContextUtil;
|
||||
@@ -50,35 +51,20 @@ import org.apache.fineract.portfolio.savings.domain.SavingsAccountTransaction;
|
||||
import org.apache.fineract.portfolio.shareaccounts.domain.ShareAccount;
|
||||
import org.apache.fineract.useradministration.domain.Role;
|
||||
import org.apache.fineract.useradministration.domain.RoleRepository;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class NotificationDomainServiceImpl implements NotificationDomainService {
|
||||
|
||||
private final BusinessEventNotifierService businessEventNotifierService;
|
||||
final PlatformSecurityContext context;
|
||||
private final PlatformSecurityContext context;
|
||||
private final RoleRepository roleRepository;
|
||||
private final OfficeRepository officeRepository;
|
||||
private final TopicSubscriberReadPlatformService topicSubscriberReadPlatformService;
|
||||
private final NotificationEventService notificationEvent;
|
||||
private final SpringEventPublisher springEventPublisher;
|
||||
|
||||
@Autowired
|
||||
public NotificationDomainServiceImpl(final BusinessEventNotifierService businessEventNotifierService,
|
||||
final PlatformSecurityContext context, final RoleRepository roleRepository,
|
||||
final TopicSubscriberReadPlatformService topicSubscriberReadPlatformService, final OfficeRepository officeRepository,
|
||||
final NotificationEventService notificationEvent, final SpringEventPublisher springEventPublisher) {
|
||||
|
||||
this.businessEventNotifierService = businessEventNotifierService;
|
||||
this.context = context;
|
||||
this.roleRepository = roleRepository;
|
||||
this.topicSubscriberReadPlatformService = topicSubscriberReadPlatformService;
|
||||
this.officeRepository = officeRepository;
|
||||
this.notificationEvent = notificationEvent;
|
||||
this.springEventPublisher = springEventPublisher;
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
public void addListeners() {
|
||||
businessEventNotifierService.addBusinessEventPostListeners(BusinessEvents.CLIENTS_CREATE, new ClientCreatedListener());
|
||||
|
||||
Reference in New Issue
Block a user