Skip to content

Commit

Permalink
feat: examples for module comment and work records added (#19)
Browse files Browse the repository at this point in the history
Interceptor v3.0.0 required
  • Loading branch information
grigoriev authored Aug 8, 2024
1 parent 2580b39 commit b0185b1
Show file tree
Hide file tree
Showing 10 changed files with 225 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
This project contains samples of hooks for Polarion [Interceptor Manager extension](https://github.com/SchweizerischeBundesbahnen/ch.sbb.polarion.extension.interceptor-manager).

The following hooks are available:
- [Delete Non-resolved Module Comments](hook-samples/delete-non-resolved-module-comments/README.md)
- [Delete Work Records](hook-samples/delete-work-records/README.md)
- [Module Save Time Logger](hook-samples/module-save-time-logger/README.md)
- [Only Assignee Can Delete](hook-samples/only-assignee-can-delete/README.md)
- [Plan Save](hook-samples/plan-save/README.md)
Expand Down
3 changes: 3 additions & 0 deletions hook-samples/delete-non-resolved-module-comments/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Hook sample for Polarion Interceptor extension

This hook allows the removal of only unresolved comments from the document.
56 changes: 56 additions & 0 deletions hook-samples/delete-non-resolved-module-comments/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?xml version="1.0" encoding="UTF-8"?>
<project>
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>ch.sbb.polarion.extensions</groupId>
<artifactId>ch.sbb.polarion.extension.interceptor-manager.hook-samples</artifactId>
<version>2.1.1-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>

<artifactId>ch.sbb.polarion.extension.interceptor-manager.hook-samples.delete-non-resolved-module-comments</artifactId>
<packaging>jar</packaging>

<properties>
<maven-jar-plugin.Automatic-Module-Name>ch.sbb.polarion.extension.interceptor.hooks_samples.delete_non_resolved_module_comments</maven-jar-plugin.Automatic-Module-Name>
<maven-jar-plugin.Extension-Context>delete-non-resolved-module-comments</maven-jar-plugin.Extension-Context>
</properties>

<dependencies>
<!-- Polarion artifacts -->
<dependency>
<groupId>com.polarion.alm.projects</groupId>
<artifactId>projects</artifactId>
<version>${polarion.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.polarion.alm.tracker</groupId>
<artifactId>tracker</artifactId>
<version>${polarion.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.polarion.platform.persistence</groupId>
<artifactId>platform-persistence</artifactId>
<version>${polarion.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.polarion.core.util</groupId>
<artifactId>util</artifactId>
<version>${polarion.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package ch.sbb.polarion.extension.interceptor.hook_samples.delete_non_resolved_module_comments;

import ch.sbb.polarion.extension.interceptor_manager.model.ActionHook;
import ch.sbb.polarion.extension.interceptor_manager.model.HookExecutor;
import ch.sbb.polarion.extension.interceptor_manager.util.PropertiesUtils;
import com.polarion.alm.tracker.model.IModuleComment;
import com.polarion.core.util.logging.Logger;
import com.polarion.platform.persistence.model.IPObject;
import org.jetbrains.annotations.NotNull;

@SuppressWarnings("unused")
public class DeleteNonResolvedModuleCommentsHook extends ActionHook implements HookExecutor {

public static final String DESCRIPTION = "Allow the removal of only unresolved comments from the document.";

public static final Logger logger = Logger.getLogger(DeleteNonResolvedModuleCommentsHook.class);

public DeleteNonResolvedModuleCommentsHook() {
super(ItemType.MODULE_COMMENT, ActionType.DELETE, DESCRIPTION);
}

@Override
public String preAction(@NotNull IPObject object) {
IModuleComment moduleComment = (IModuleComment) object;

if (moduleComment.isResolvedComment()) {
return "'Resolved' comments can not be deleted.";
} else {
return null;
}
}

@Override
public @NotNull HookExecutor getExecutor() {
return this; //there is no need to create a separate executor instance coz only 'pre' action used
}

@Override
public String getDefaultSettings() {
return PropertiesUtils.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Name: Document comments hook for Polarion ALM Interceptor plugin
Main-Class: ch.sbb.polarion.extension.interceptor.hook_samples.delete_non_resolved_module_comments.DeleteNonResolvedModuleCommentsHook
3 changes: 3 additions & 0 deletions hook-samples/delete-work-records/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Hook sample for Polarion Interceptor extension

This hook allow deletion of work records only from the current month.
56 changes: 56 additions & 0 deletions hook-samples/delete-work-records/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?xml version="1.0" encoding="UTF-8"?>
<project>
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>ch.sbb.polarion.extensions</groupId>
<artifactId>ch.sbb.polarion.extension.interceptor-manager.hook-samples</artifactId>
<version>2.1.1-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>

<artifactId>ch.sbb.polarion.extension.interceptor-manager.hook-samples.delete-work-records</artifactId>
<packaging>jar</packaging>

<properties>
<maven-jar-plugin.Automatic-Module-Name>ch.sbb.polarion.extension.interceptor.hooks_samples.delete_work_records</maven-jar-plugin.Automatic-Module-Name>
<maven-jar-plugin.Extension-Context>delete-work-records</maven-jar-plugin.Extension-Context>
</properties>

<dependencies>
<!-- Polarion artifacts -->
<dependency>
<groupId>com.polarion.alm.projects</groupId>
<artifactId>projects</artifactId>
<version>${polarion.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.polarion.alm.tracker</groupId>
<artifactId>tracker</artifactId>
<version>${polarion.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.polarion.platform.persistence</groupId>
<artifactId>platform-persistence</artifactId>
<version>${polarion.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.polarion.core.util</groupId>
<artifactId>util</artifactId>
<version>${polarion.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package ch.sbb.polarion.extension.interceptor.hook_samples.delete_work_records;

import ch.sbb.polarion.extension.interceptor_manager.model.ActionHook;
import ch.sbb.polarion.extension.interceptor_manager.model.HookExecutor;
import ch.sbb.polarion.extension.interceptor_manager.util.PropertiesUtils;
import com.polarion.alm.tracker.model.IWorkRecord;
import com.polarion.core.util.logging.Logger;
import com.polarion.core.util.types.DateOnly;
import com.polarion.platform.persistence.model.IPObject;
import org.jetbrains.annotations.NotNull;

import java.util.Calendar;
import java.util.Date;

@SuppressWarnings("unused")
public class DeleteWorkRecordsHook extends ActionHook implements HookExecutor {

public static final String DESCRIPTION = "Allow deletion of work records only from the current month.";

public static final Logger logger = Logger.getLogger(DeleteWorkRecordsHook.class);

public DeleteWorkRecordsHook() {
super(ItemType.WORK_RECORD, ActionType.DELETE, DESCRIPTION);
}

@Override
public String preAction(@NotNull IPObject object) {
IWorkRecord workRecord = (IWorkRecord) object;
DateOnly workRecordDate = workRecord.getDate();

if (!isDateInCurrentMonth(workRecordDate.getDate())) {
return "Only work records added in the current month can be deleted.";
} else {
return null;
}
}

private static boolean isDateInCurrentMonth(@NotNull Date date) {
Calendar currentCalendar = Calendar.getInstance();

Calendar checkCalendar = Calendar.getInstance();
checkCalendar.setTime(date);

return currentCalendar.get(Calendar.YEAR) == checkCalendar.get(Calendar.YEAR) &&
currentCalendar.get(Calendar.MONTH) == checkCalendar.get(Calendar.MONTH);
}

@Override
public @NotNull HookExecutor getExecutor() {
return this; //there is no need to create a separate executor instance coz only 'pre' action used
}

@Override
public String getDefaultSettings() {
return PropertiesUtils.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Name: Work records hook for Polarion ALM Interceptor plugin
Main-Class: ch.sbb.polarion.extension.interceptor.hook_samples.delete_work_records.DeleteWorkRecordsHook
2 changes: 2 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
<packaging>pom</packaging>

<modules>
<module>hook-samples/delete-non-resolved-module-comments</module>
<module>hook-samples/delete-work-records</module>
<module>hook-samples/module-save-time-logger</module>
<module>hook-samples/only-assignee-can-delete</module>
<module>hook-samples/plan-save</module>
Expand Down

0 comments on commit b0185b1

Please sign in to comment.