Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
1.9 kB
2
Indexable
Never
    private FeatureChangeConfig.ChangeTriggerHook applyTemplate(
            FeatureChangeConfig.ChangeTriggerHook hook, HookData data) {

        FeatureChangeConfig.ChangeTriggerHook converted = hook.toBuilder().build();
        try {
            JsonNode jsonNode = objectMapper.convertValue(data, JsonNode.class);

            Context context = Context
                    .newBuilder(jsonNode)
                    .resolver(FeatureChangeJsonNodeValueResolver.INSTANCE,
                            JavaBeanValueResolver.INSTANCE,
                            FieldValueResolver.INSTANCE,
                            MapValueResolver.INSTANCE,
                            MethodValueResolver.INSTANCE
                    )
                    .build();

            if (converted.getMethod().contains(Handlebars.DELIM_START)) {
                converted.setMethod(handlebars.compileInline(converted.getMethod()).apply(context));
            }
            if (converted.getUrl().contains(Handlebars.DELIM_START)) {
                converted.setUrl(handlebars.compileInline(converted.getUrl()).apply(context));
            }
            if (converted.getHeaders() != null
                    && converted.getHeaders().contains(Handlebars.DELIM_START)) {
                converted.setHeaders(
                        handlebars.compileInline(converted.getHeaders()).apply(context));
            }
            if (converted.getBody() != null
                    && converted.getBody().contains(Handlebars.DELIM_START)) {
                converted.setBody(handlebars.compileInline(converted.getBody()).apply(context));
            }
        } catch (Exception e) {
            throw new PortalException("applyTemplate error - ", e);
        }
        return converted;
    }
///////////////////

entityManager.find(FeatureChange.class, featureChangeId,
                LockModeType.PESSIMISTIC_WRITE);
Leave a Comment