-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: examples for module comment and work records added (#19)
Interceptor v3.0.0 required
- Loading branch information
Showing
10 changed files
with
225 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
42 changes: 42 additions & 0 deletions
42
...hook_samples/delete_non_resolved_module_comments/DeleteNonResolvedModuleCommentsHook.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
2 changes: 2 additions & 0 deletions
2
hook-samples/delete-non-resolved-module-comments/src/main/resources/META-INF/MANIFEST.MF
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
57 changes: 57 additions & 0 deletions
57
...olarion/extension/interceptor/hook_samples/delete_work_records/DeleteWorkRecordsHook.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
2 changes: 2 additions & 0 deletions
2
hook-samples/delete-work-records/src/main/resources/META-INF/MANIFEST.MF
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters