001package com.identityworksllc.iiq.common.service; 002 003import sailpoint.api.SailPointContext; 004import sailpoint.object.ServiceDefinition; 005import sailpoint.tools.GeneralException; 006 007/** 008 * Interface to ensure that nobody breaks the contract of {@link BaseCommonService} 009 */ 010public interface BaseServiceImplementation { 011 012 /** 013 * Hook to execute after execution of the service implementation. If you 014 * override this, be sure to invoke super.afterExecution() so that 015 * the default behaviors still occur. 016 * 017 * @param context The IIQ context 018 * @throws GeneralException if anything goes wrong 019 */ 020 default void afterExecution(SailPointContext context) throws GeneralException { 021 022 } 023 024 /** 025 * Hook to execute before execution of the service implementation. If you 026 * override this, be sure to invoke super.afterExecution() so that 027 * the default behaviors still occur. 028 * 029 * @param context The IIQ context 030 * @throws GeneralException if anything goes wrong 031 */ 032 default void beforeExecution(SailPointContext context) throws GeneralException { 033 034 } 035 036 /** 037 * Gets the service definition 038 * @return The service definition, supplied by the Servicer at runtime 039 */ 040 ServiceDefinition getDefinition(); 041 042 /** 043 * The main entry point of the service, invoked by the Servicer 044 * @param context The IIQ context for this service run 045 * @throws GeneralException if the service execution failed 046 */ 047 void execute(SailPointContext context) throws GeneralException; 048 049 /** 050 * Your code goes here and will be invoked by {@link #execute(SailPointContext)} after some setup and validation 051 * 052 * @param context IIQ context 053 * @throws GeneralException if any failures occur 054 */ 055 void implementation(SailPointContext context) throws GeneralException; 056 057 /** 058 * Increments the execution count and sets the executed-once flag to true 059 */ 060 void incrementExecutions(); 061 062 /** 063 * Return the number of executions that should be skipped on service 064 * startup. This can allow the IIQ server to start up without having 065 * to worry about this service doing weird stuff during initialization 066 * or heavy startup load. 067 * 068 * The subclass can override this, or the ServiceDefinition can specify 069 * 'skipExecutionCount' as an attribute. 070 * 071 * @return The number of executions that should be skipped, default 0 072 */ 073 default int skipExecutionCount() { 074 ServiceDefinition self = getDefinition(); 075 if (self != null) { 076 if (self.getAttributes().containsKey("skipExecutionCount")) { 077 int skipExecutionCount = self.getInt("skipExecutionCount"); 078 if (skipExecutionCount > 0) { 079 return skipExecutionCount; 080 } 081 } 082 } 083 return 0; 084 } 085 086}