Skip to content

Commit

Permalink
add feature scopre, to make clear with feature is available in reques…
Browse files Browse the repository at this point in the history
…t, module or global scope
  • Loading branch information
Thorsten Marx committed Aug 22, 2024
1 parent 68df180 commit 191f2f4
Show file tree
Hide file tree
Showing 28 changed files with 100 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.github.thmarx.cms.api.annotations;

/*-
* #%L
* cms-api
* %%
* Copyright (C) 2023 Marx-Software
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/gpl-3.0.html>.
* #L%
*/

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
*
* @author t.marx
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE })
public @interface FeatureScope {

public FeatureScope.Scope[] value() default {};

public enum Scope {
REQUEST,
GLOBAL,
MODULE
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@
* #L%
*/

import com.github.thmarx.cms.api.annotations.FeatureScope;
import com.github.thmarx.cms.api.feature.Feature;

/**
*
* @author t.marx
*/
@FeatureScope(FeatureScope.Scope.REQUEST)
public record AuthFeature (String username) implements Feature {
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@
* #L%
*/

import com.github.thmarx.cms.api.annotations.FeatureScope;
import com.github.thmarx.cms.api.configuration.Configuration;
import com.github.thmarx.cms.api.feature.Feature;

/**
*
* @author t.marx
*/
@FeatureScope({FeatureScope.Scope.GLOBAL, FeatureScope.Scope.MODULE, FeatureScope.Scope.REQUEST})
public record ConfigurationFeature(Configuration configuration) implements Feature {

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@
* #L%
*/

import com.github.thmarx.cms.api.annotations.FeatureScope;
import com.github.thmarx.cms.api.feature.Feature;
import com.github.thmarx.cms.api.mapper.ContentNodeMapper;

/**
*
* @author t.marx
*/
@FeatureScope({FeatureScope.Scope.REQUEST})
public record ContentNodeMapperFeature(ContentNodeMapper contentNodeMapper) implements Feature {


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@
* #L%
*/

import com.github.thmarx.cms.api.annotations.FeatureScope;
import com.github.thmarx.cms.api.content.ContentParser;
import com.github.thmarx.cms.api.feature.Feature;

/**
*
* @author t.marx
*/
@FeatureScope({FeatureScope.Scope.REQUEST})
public record ContentParserFeature(ContentParser contentParser) implements Feature {

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
* #L%
*/

import com.github.thmarx.cms.api.annotations.FeatureScope;
import com.github.thmarx.cms.api.content.ContentResponse;
import com.github.thmarx.cms.api.content.RenderContentFunction;
import com.github.thmarx.cms.api.feature.Feature;
Expand All @@ -33,6 +34,7 @@
*
* @author t.marx
*/
@FeatureScope({FeatureScope.Scope.MODULE})
public record ContentRenderFeature(RenderContentFunction renderContentFunction) implements Feature {

public Optional<ContentResponse> renderContentNode (String uri, Map<String, List<String>> params) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@
* #L%
*/

import com.github.thmarx.cms.api.annotations.FeatureScope;
import com.github.thmarx.cms.api.feature.Feature;
import com.github.thmarx.cms.api.scheduler.CronJobScheduler;

/**
*
* @author t.marx
*/
@FeatureScope({FeatureScope.Scope.MODULE})
public record CronJobSchedulerFeature(CronJobScheduler cronJobScheduler) implements Feature {

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@
* #L%
*/

import com.github.thmarx.cms.api.annotations.FeatureScope;
import com.github.thmarx.cms.api.db.ContentNode;
import com.github.thmarx.cms.api.feature.Feature;

/**
*
* @author t.marx
*/
@FeatureScope({FeatureScope.Scope.REQUEST})
public record CurrentNodeFeature(ContentNode node) implements Feature {

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
* #L%
*/

import com.github.thmarx.cms.api.annotations.FeatureScope;
import com.github.thmarx.cms.api.db.Page;
import com.github.thmarx.cms.api.db.taxonomy.Taxonomy;
import com.github.thmarx.cms.api.feature.Feature;
Expand All @@ -33,6 +34,7 @@
*
* @author t.marx
*/
@FeatureScope({FeatureScope.Scope.REQUEST})
public record CurrentTaxonomyFeature(Taxonomy taxonomy, Optional<String> value, Map<String, Object> meta, Page<ListNode> page) implements Feature {

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@
* #L%
*/

import com.github.thmarx.cms.api.annotations.FeatureScope;
import com.github.thmarx.cms.api.db.DB;
import com.github.thmarx.cms.api.feature.Feature;

/**
*
* @author t.marx
*/
@FeatureScope({FeatureScope.Scope.GLOBAL, FeatureScope.Scope.MODULE})
public record DBFeature(DB db) implements Feature {

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@
* <http://www.gnu.org/licenses/gpl-3.0.html>.
* #L%
*/
import com.github.thmarx.cms.api.annotations.FeatureScope;
import com.github.thmarx.cms.api.eventbus.EventBus;
import com.github.thmarx.cms.api.feature.Feature;
import lombok.extern.slf4j.Slf4j;

/**
*
* @author t.marx
*/
@Slf4j
@FeatureScope({FeatureScope.Scope.GLOBAL, FeatureScope.Scope.MODULE})
public record EventBusFeature(EventBus eventBus) implements Feature {
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@
* #L%
*/

import com.github.thmarx.cms.api.annotations.FeatureScope;
import com.github.thmarx.cms.api.feature.Feature;
import com.github.thmarx.cms.api.hooks.HookSystem;

/**
*
* @author t.marx
*/
@FeatureScope({FeatureScope.Scope.REQUEST})
public record HookSystemFeature(HookSystem hookSystem) implements Feature {

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@
* #L%
*/

import com.github.thmarx.cms.api.annotations.FeatureScope;
import com.github.thmarx.cms.api.feature.Feature;
import com.google.inject.Injector;

/**
*
* @author t.marx
*/
@FeatureScope({FeatureScope.Scope.REQUEST})
public record InjectorFeature(Injector injector) implements Feature {

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@
* #L%
*/

import com.github.thmarx.cms.api.annotations.FeatureScope;
import com.github.thmarx.cms.api.feature.Feature;

/**
*
* @author t.marx
*/
@FeatureScope({FeatureScope.Scope.REQUEST})
public record IsDevModeFeature() implements Feature {

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@
* #L%
*/

import com.github.thmarx.cms.api.annotations.FeatureScope;
import com.github.thmarx.cms.api.feature.Feature;

/**
*
* @author t.marx
*/
@FeatureScope({FeatureScope.Scope.REQUEST})
public record IsPreviewFeature() implements Feature {

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@
* #L%
*/

import com.github.thmarx.cms.api.annotations.FeatureScope;
import com.github.thmarx.cms.api.feature.Feature;
import com.github.thmarx.cms.api.markdown.MarkdownRenderer;

/**
*
* @author t.marx
*/
@FeatureScope({FeatureScope.Scope.REQUEST})
public record MarkdownRendererFeature(MarkdownRenderer markdownRenderer) implements Feature {

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@
* <http://www.gnu.org/licenses/gpl-3.0.html>.
* #L%
*/
import com.github.thmarx.cms.api.annotations.FeatureScope;
import com.github.thmarx.cms.api.feature.Feature;
import com.github.thmarx.modules.api.ModuleManager;
import lombok.extern.slf4j.Slf4j;

/**
*
* @author t.marx
*/
@Slf4j
@FeatureScope({FeatureScope.Scope.MODULE})
public record ModuleManagerFeature(ModuleManager moduleManager) implements Feature {
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
* <http://www.gnu.org/licenses/gpl-3.0.html>.
* #L%
*/
import com.github.thmarx.cms.api.annotations.FeatureScope;
import com.github.thmarx.cms.api.feature.Feature;
import java.util.List;
import java.util.Map;
Expand All @@ -31,6 +32,7 @@
* @author t.marx
*/
@Slf4j
@FeatureScope({FeatureScope.Scope.REQUEST})
public record RequestFeature(String context, String uri, Map<String, List<String>> queryParameters) implements Feature {

public RequestFeature(String uri, Map<String, List<String>> queryParameters) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@
*/

import com.github.thmarx.cms.api.ServerProperties;
import com.github.thmarx.cms.api.annotations.FeatureScope;
import com.github.thmarx.cms.api.feature.Feature;

/**
*
* @author t.marx
*/
@FeatureScope({FeatureScope.Scope.GLOBAL, FeatureScope.Scope.MODULE, FeatureScope.Scope.REQUEST})
public record ServerPropertiesFeature(ServerProperties serverProperties) implements Feature {

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@
* #L%
*/

import com.github.thmarx.cms.api.annotations.FeatureScope;
import com.github.thmarx.cms.api.feature.Feature;
import com.github.thmarx.cms.api.media.MediaService;

/**
*
* @author t.marx
*/
@FeatureScope({FeatureScope.Scope.REQUEST})
public record SiteMediaServiceFeature(MediaService mediaService) implements Feature {

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@
*/

import com.github.thmarx.cms.api.SiteProperties;
import com.github.thmarx.cms.api.annotations.FeatureScope;
import com.github.thmarx.cms.api.feature.Feature;

/**
*
* @author t.marx
*/
@FeatureScope({FeatureScope.Scope.GLOBAL, FeatureScope.Scope.MODULE, FeatureScope.Scope.REQUEST})
public record SitePropertiesFeature(SiteProperties siteProperties) implements Feature {

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.github.thmarx.cms.api.feature.features;

import com.github.thmarx.cms.api.annotations.FeatureScope;
import com.github.thmarx.cms.api.feature.Feature;
import com.github.thmarx.cms.api.theme.Theme;
import lombok.AllArgsConstructor;
Expand Down Expand Up @@ -31,6 +32,7 @@
* @author t.marx
*/
@AllArgsConstructor
@FeatureScope({FeatureScope.Scope.GLOBAL, FeatureScope.Scope.MODULE, FeatureScope.Scope.REQUEST})
public class ThemeFeature implements Feature {

private Theme theme;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
* #L%
*/

import com.github.thmarx.cms.api.annotations.FeatureScope;
import com.github.thmarx.cms.api.feature.Feature;
import com.github.thmarx.cms.api.markdown.MarkdownRenderer;
import com.github.thmarx.cms.api.theme.Theme;
Expand All @@ -33,6 +34,7 @@
* @author t.marx
*/
@Slf4j
@FeatureScope(FeatureScope.Scope.REQUEST)
public record RenderContext(MarkdownRenderer markdownRenderer, ShortCodes shortCodes, Theme theme)
implements AutoCloseable, Feature {

Expand Down
Loading

0 comments on commit 191f2f4

Please sign in to comment.