Skip to content

Commit

Permalink
feat!: ch.sbb.polarion.extension.generic usage (#36)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jumas authored May 31, 2024
1 parent e4e877f commit ca4ca3b
Show file tree
Hide file tree
Showing 67 changed files with 388 additions and 2,523 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,5 @@ replay_pid*

target/
*.iml
hooks/*.iml
dependency-reduced-pom.xml
31 changes: 31 additions & 0 deletions hooks/only-assignee-can-delete/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Compiled class file
*.class

# Log file
*.log

# BlueJ files
*.ctxt

# Package Files #
*.jar
*.war
*.nar
*.ear
*.zip
*.tar.gz
*.rar

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
replay_pid*
.idea/*

# code style config
!.idea/codeStyles
.idea/codeStyles/*
!.idea/codeStyles/Project.xml
!.idea/codeStyles/codeStyleConfig.xml

target/
*.iml
4 changes: 2 additions & 2 deletions hooks/only-assignee-can-delete/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<packaging>jar</packaging>

<properties>
<ch.sbb.polarion.extension.interceptor.version>1.0.0-SNAPSHOT</ch.sbb.polarion.extension.interceptor.version>
<ch.sbb.polarion.extension.interceptor.version>1.1.1</ch.sbb.polarion.extension.interceptor.version>

<maven-jar-plugin.Automatic-Module-Name>ch.sbb.polarion.extension.interceptor_hooks.only_assignee_can_delete</maven-jar-plugin.Automatic-Module-Name>
<maven-jar-plugin.Extension-Context>only-assignee-can-delete</maven-jar-plugin.Extension-Context>
Expand All @@ -18,7 +18,7 @@

<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<polarion.version>2310</polarion.version>
<polarion.version>2404</polarion.version>

<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.build.timestamp.format>yyyy-MM-dd HH:mm</maven.build.timestamp.format>
Expand Down
31 changes: 31 additions & 0 deletions hooks/plan-save/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Compiled class file
*.class

# Log file
*.log

# BlueJ files
*.ctxt

# Package Files #
*.jar
*.war
*.nar
*.ear
*.zip
*.tar.gz
*.rar

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
replay_pid*
.idea/*

# code style config
!.idea/codeStyles
.idea/codeStyles/*
!.idea/codeStyles/Project.xml
!.idea/codeStyles/codeStyleConfig.xml

target/
*.iml
4 changes: 2 additions & 2 deletions hooks/plan-save/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<packaging>jar</packaging>

<properties>
<ch.sbb.polarion.extension.interceptor.version>1.0.0-SNAPSHOT</ch.sbb.polarion.extension.interceptor.version>
<ch.sbb.polarion.extension.interceptor.version>1.1.1</ch.sbb.polarion.extension.interceptor.version>

<maven-jar-plugin.Automatic-Module-Name>ch.sbb.polarion.extension.interceptor_hooks.plan_save</maven-jar-plugin.Automatic-Module-Name>
<maven-jar-plugin.Extension-Context>plan-save</maven-jar-plugin.Extension-Context>
Expand All @@ -18,7 +18,7 @@

<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<polarion.version>2310</polarion.version>
<polarion.version>2404</polarion.version>

<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.build.timestamp.format>yyyy-MM-dd HH:mm</maven.build.timestamp.format>
Expand Down
31 changes: 31 additions & 0 deletions hooks/single-assignee/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Compiled class file
*.class

# Log file
*.log

# BlueJ files
*.ctxt

# Package Files #
*.jar
*.war
*.nar
*.ear
*.zip
*.tar.gz
*.rar

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
replay_pid*
.idea/*

# code style config
!.idea/codeStyles
.idea/codeStyles/*
!.idea/codeStyles/Project.xml
!.idea/codeStyles/codeStyleConfig.xml

target/
*.iml
4 changes: 2 additions & 2 deletions hooks/single-assignee/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<packaging>jar</packaging>

<properties>
<ch.sbb.polarion.extension.interceptor.version>1.0.0-SNAPSHOT</ch.sbb.polarion.extension.interceptor.version>
<ch.sbb.polarion.extension.interceptor.version>1.1.1</ch.sbb.polarion.extension.interceptor.version>

<maven-jar-plugin.Automatic-Module-Name>ch.sbb.polarion.extension.interceptor_hooks.single_assignee</maven-jar-plugin.Automatic-Module-Name>
<maven-jar-plugin.Extension-Context>single-assignee</maven-jar-plugin.Extension-Context>
Expand All @@ -18,7 +18,7 @@

<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<polarion.version>2310</polarion.version>
<polarion.version>2404</polarion.version>

<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.build.timestamp.format>yyyy-MM-dd HH:mm</maven.build.timestamp.format>
Expand Down
31 changes: 31 additions & 0 deletions hooks/testrun/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Compiled class file
*.class

# Log file
*.log

# BlueJ files
*.ctxt

# Package Files #
*.jar
*.war
*.nar
*.ear
*.zip
*.tar.gz
*.rar

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
replay_pid*
.idea/*

# code style config
!.idea/codeStyles
.idea/codeStyles/*
!.idea/codeStyles/Project.xml
!.idea/codeStyles/codeStyleConfig.xml

target/
*.iml
4 changes: 2 additions & 2 deletions hooks/testrun/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<packaging>jar</packaging>

<properties>
<ch.sbb.polarion.extension.interceptor.version>1.0.0-SNAPSHOT</ch.sbb.polarion.extension.interceptor.version>
<ch.sbb.polarion.extension.interceptor.version>1.1.1</ch.sbb.polarion.extension.interceptor.version>

<maven-jar-plugin.Automatic-Module-Name>ch.sbb.polarion.extension.interceptor_hooks.testrun</maven-jar-plugin.Automatic-Module-Name>
<maven-jar-plugin.Extension-Context>testrun</maven-jar-plugin.Extension-Context>
Expand All @@ -18,7 +18,7 @@

<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<polarion.version>2310</polarion.version>
<polarion.version>2404</polarion.version>

<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.build.timestamp.format>yyyy-MM-dd HH:mm</maven.build.timestamp.format>
Expand Down
31 changes: 31 additions & 0 deletions hooks/title-length-check/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Compiled class file
*.class

# Log file
*.log

# BlueJ files
*.ctxt

# Package Files #
*.jar
*.war
*.nar
*.ear
*.zip
*.tar.gz
*.rar

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
replay_pid*
.idea/*

# code style config
!.idea/codeStyles
.idea/codeStyles/*
!.idea/codeStyles/Project.xml
!.idea/codeStyles/codeStyleConfig.xml

target/
*.iml
4 changes: 2 additions & 2 deletions hooks/title-length-check/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<packaging>jar</packaging>

<properties>
<ch.sbb.polarion.extension.interceptor.version>1.0.0-SNAPSHOT</ch.sbb.polarion.extension.interceptor.version>
<ch.sbb.polarion.extension.interceptor.version>1.1.1</ch.sbb.polarion.extension.interceptor.version>

<maven-jar-plugin.Automatic-Module-Name>ch.sbb.polarion.extension.interceptor_hooks.title_length_check</maven-jar-plugin.Automatic-Module-Name>
<maven-jar-plugin.Extension-Context>title-length-check</maven-jar-plugin.Extension-Context>
Expand All @@ -18,7 +18,7 @@

<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<polarion.version>2310</polarion.version>
<polarion.version>2404</polarion.version>

<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.build.timestamp.format>yyyy-MM-dd HH:mm</maven.build.timestamp.format>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,60 +1,14 @@
package ch.sbb.polarion.extension.interceptor;

import com.polarion.core.util.logging.Logger;
import org.apache.commons.io.IOUtils;
import org.jetbrains.annotations.NotNull;
import ch.sbb.polarion.extension.generic.GenericUiServlet;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.InputStream;
import java.io.Serial;

public class InterceptorAdminUiServlet extends HttpServlet {

private static final Logger logger = Logger.getLogger(InterceptorAdminUiServlet.class);

public class InterceptorAdminUiServlet extends GenericUiServlet {
@Serial
private static final long serialVersionUID = 4323903250755251706L;
private static final String WEB_APP_NAME = "interceptor-admin";

private static void setContentType(@NotNull String uri, @NotNull HttpServletResponse response) {
if (uri.endsWith(".js")) {
response.setContentType("text/javascript");
} else if (uri.endsWith(".html")) {
response.setContentType("text/html");
} else if (uri.endsWith(".png")) {
response.setContentType("image/png");
} else if (uri.endsWith(".css")) {
response.setContentType("text/css");
}
}

@Override
protected void service(HttpServletRequest request, HttpServletResponse response) {
String uri = request.getRequestURI();
String relativeUri = uri.substring("/polarion/".length());

if (relativeUri.startsWith(WEB_APP_NAME + "/ui/")) {
serveResource(response, relativeUri.substring((WEB_APP_NAME + "/ui").length()));
}
}

private void serveResource(@NotNull HttpServletResponse response, @NotNull String uri) {
try (InputStream inputStream = getServletContext().getResourceAsStream(uri)) {
private static final long serialVersionUID = 1652935384860901702L;

if (inputStream == null) {
response.sendError(HttpServletResponse.SC_NOT_FOUND);
} else {
try (ServletOutputStream outputStream = response.getOutputStream()) {
setContentType(uri, response);
IOUtils.copy(inputStream, outputStream);
}
}
} catch (IOException e) {
logger.error(e.getMessage(), e);
}
public InterceptorAdminUiServlet() {
super("interceptor-admin");
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package ch.sbb.polarion.extension.interceptor.model;

import ch.sbb.polarion.extension.interceptor.settings.SettingsRegistry;
import ch.sbb.polarion.extension.generic.settings.NamedSettings;
import ch.sbb.polarion.extension.generic.settings.NamedSettingsRegistry;
import ch.sbb.polarion.extension.generic.settings.SettingId;
import ch.sbb.polarion.extension.interceptor.settings.HookModel;
import ch.sbb.polarion.extension.interceptor.util.ScopeUtils;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.polarion.alm.projects.model.IUniqueObject;
Expand Down Expand Up @@ -46,7 +47,7 @@ public ActionHook(List<ItemType> itemTypes, ActionType actionType, String versio

public HookModel loadSettings(boolean forceUpdate) {
if (forceUpdate || settings == null) {
settings = SettingsRegistry.INSTANCE.getByHookName(getName()).read(ScopeUtils.SCOPE_DEFAULT, null);
settings = (HookModel) NamedSettingsRegistry.INSTANCE.getByFeatureName(getName()).read("", SettingId.fromName(NamedSettings.DEFAULT_NAME), null);
}
return settings;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package ch.sbb.polarion.extension.interceptor.model;

import ch.sbb.polarion.extension.generic.settings.NamedSettingsRegistry;
import ch.sbb.polarion.extension.interceptor.settings.HookSettings;
import ch.sbb.polarion.extension.interceptor.settings.SettingsRegistry;
import ch.sbb.polarion.extension.interceptor.util.HookJarUtils;
import com.polarion.core.util.logging.Logger;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

public enum HooksRegistry {

Expand All @@ -22,8 +21,8 @@ public synchronized void refresh() {
hooks.clear();
hooks.addAll(HookJarUtils.loadHooks());
logger.info(hooks.size() + " hooks loaded.");
SettingsRegistry.INSTANCE
.register(HooksRegistry.HOOKS.list().stream().map(HookSettings::new).collect(Collectors.toList()));
NamedSettingsRegistry.INSTANCE.getAll().clear();
hooks.forEach(hook -> NamedSettingsRegistry.INSTANCE.getAll().add(new HookSettings(hook)));
}

public List<ActionHook> list() {
Expand Down
Loading

0 comments on commit ca4ca3b

Please sign in to comment.