Class AbstractSynchronizer
- All Implemented Interfaces:
StructureSynchronizer
AbstractSynchronizer is an abstract base class for the synchronizers that
provides basic implementation for some of the StructureSynchronizer methods
and offers some utility methods for the synchronizers.
The type of the parameters used by this synchronizer is Map<String, Object>.
The basic implementation of the storeParameters(java.lang.Object)
and restoreParameters(java.lang.String) methods use Jackson, expecting that map values
are either basic Java types or are properly annotated (see, for example,
XmlRootElement). todo mention other kinds of annotation?
This class also supports reading and writing some standard properties, such as:
- The "source of truth" as a
SyncDirectiontodo implement & explain
- Author:
- Igor Sereda
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static interface -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final SyncAuditLogprotected final RowManagerprotected final StructureComponentsprotected final StructureManager -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractSynchronizer(StructureComponents structureComponents) Constructs an instance of the synchronizer. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddDefaultFormParameters(Map<String, Object> params) Adds to the map the default values for the parameters in the synchronizer parameters form.protected abstract AbstractSynchronizer.SyncRunAuditEntrydoResync(SyncInstance instance, ForestSource forestSource) protected abstract AbstractSynchronizer.SyncRunAuditEntrydoSync(SyncInstance instance, IncrementalSyncData data, ForestSource forestSource) protected static AbstractSynchronizer.SyncRunAuditEntryprotected static AbstractSynchronizer.SyncRunAuditEntryprotected static AbstractSynchronizer.SyncRunAuditEntryprotected IssuegetIssue(long issueId) Retrieves an instance ofIssue.protected IssueRetrieves an instance of issue by issue key.protected IssuegetIssueByRowId(long rowId) static longgetIssueIdByRow(StructureRow structureRow) protected final longgetIssueIdByRowId(long rowId) protected IssueManagerprotected StringLooks up i18n text using the i18n bean from the module's plugin and the current user's locale.voidinit(SynchronizerDescriptor descriptor) Called by the module descriptor on initialization.protected MapObjectReturns aMapObjectwrapper around the parameters map.protected MapObjectrestoreParameters(String data) Deserializes a string previously createdStructureSynchronizer.storeParameters(Object)into this synchronizer's parameters object.voidresync(SyncInstance instance, ForestSource forestSource) Perform full resync.storeParameters(Object parameters) Serializes parameters into a string (for example, JSON) for storing in the database.protected static AbstractSynchronizer.SyncRunAuditEntryvoidsync(SyncInstance instance, IncrementalSyncData syncData, ForestSource forestSource) Perform incremental synchronization.protected booleanverifyStructureEditPermissions(long structureId) Checks that the user has at leastPermissionLevel.EDITpermission on the specified structure.protected booleanverifyStructureEditPermissions(long structureId, SyncLogger log) Checks that the user has at leastPermissionLevel.EDITpermission on the specified structure.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface StructureSynchronizer
addFormParameters, buildParametersFromForm, getConfigDescription, getConfigDescriptionDetails, getPossibleResyncEffects, isAutosyncSupported, isAvailable
-
Field Details
-
myStructureComponents
-
myStructureManager
-
myRowManager
-
myAuditLog
-
-
Constructor Details
-
AbstractSynchronizer
Constructs an instance of the synchronizer.- Parameters:
structureComponents- services directory
-
-
Method Details
-
init
Called by the module descriptor on initialization.- Parameters:
descriptor- descriptor for this module
-
getDescriptor
- Specified by:
getDescriptorin interfaceStructureSynchronizer- Returns:
- module descriptor, which can be used to retrieve configuration for this synchronizer from the atlassian-plugin.xml
-
getText
Looks up i18n text using the i18n bean from the module's plugin and the current user's locale.- Parameters:
key- text keyparameters- optional parameters- Returns:
- the text or the key, if not found
-
addDefaultFormParameters
Description copied from interface:StructureSynchronizerAdds to the map the default values for the parameters in the synchronizer parameters form. The default values then will be available for the synchronizer's <form> the first time it's loaded.- Specified by:
addDefaultFormParametersin interfaceStructureSynchronizer- Parameters:
params- the map of parameters that the synchronizer can add to
-
storeParameters
Description copied from interface:StructureSynchronizerSerializes parameters into a string (for example, JSON) for storing in the database. The result of using
StructureSynchronizer.restoreParameters(String)on the resulting string should reconstruct the same parameters object.Empty String ("") returned from this method is treated in the same way as
nullby Structure. It is recommended to returnnullinstead of empty String.- Specified by:
storeParametersin interfaceStructureSynchronizer- Parameters:
parameters- sync parameters- Returns:
- string representing serialized parameters, e.g., a JSON string
- Throws:
IOException- if parameters cannot be stored
-
restoreParameters
Description copied from interface:StructureSynchronizerDeserializes a string previously createdStructureSynchronizer.storeParameters(Object)into this synchronizer's parameters object.- Specified by:
restoreParametersin interfaceStructureSynchronizer- Parameters:
data- string with serialized parameters; never an empty String- Returns:
- the parameters object
- Throws:
IOException- if there's a problem reading parameters
-
castParameters
-
parametersAsMapObject
Returns aMapObjectwrapper around the parameters map.MapObjectcan be useful for reading values. -
parametersAsNNMapObject
-
verifyStructureEditPermissions
protected boolean verifyStructureEditPermissions(long structureId) Checks that the user has at leastPermissionLevel.EDITpermission on the specified structure.- Parameters:
structureId- the ID of the structure- Returns:
- true if the current user is allowed to modify the structure
-
verifyStructureEditPermissions
Checks that the user has at leastPermissionLevel.EDITpermission on the specified structure.- Parameters:
structureId- the ID of the structurelog-logging helperthat will be used to log warning in case the structure does not exist or is not accessible; in case you don't need synchronizer information in the logs, you can useverifyStructureEditPermissions(long)- Returns:
- true if the current user is allowed to modify the structure
-
getIssue
@Nullable protected Issue getIssue(long issueId) Retrieves an instance ofIssue.- Parameters:
issueId- the ID of the issue- Returns:
- the issue, or null if the issue cannot be found or there is an exception getting it
-
getIssue
Retrieves an instance of issue by issue key.- Parameters:
key- issue key- Returns:
- the issue, or null if the issue cannot be found or there is an exception getting it
-
getIssueManager
@NotNull protected IssueManager getIssueManager() -
getIssueByRowId
@Nullable protected Issue getIssueByRowId(long rowId) -
getIssueIdByRowId
protected final long getIssueIdByRowId(long rowId) -
getIssueIdByRow
-
sync
public void sync(@NotNull SyncInstance instance, @NotNull IncrementalSyncData syncData, @NotNull ForestSource forestSource) throws StructureException Description copied from interface:StructureSynchronizerPerform incremental synchronization.
This method is called when the synchronizer is installed and enabled, and sync manager detects changes in the structure or in any of the tracked items since the last run. The synchronizer can use the updates to check only those items that have been affected and also to choose the direction of the synchronization based on where the changes have occurred. The update is never empty - there is at least one JIRA or Structure change. The Structure changes are specified up to the version of the forest contained in the data.
The process is decoupled from the changing thread; the synchronization is run as a separate background job with
StructureJobManagershortly after the changes have taken place. In JIRA Data Center, the synchronizer might run on a different node from the one where the changes were made.- Specified by:
syncin interfaceStructureSynchronizer- Parameters:
instance- the configured instance of the synchronizersyncData- the changes since the last incremental synchronization or resync - in JIRA and in StructureforestSource- the source from which to retrieveForestfor- Throws:
StructureException
-
resync
public void resync(@NotNull SyncInstance instance, @NotNull ForestSource forestSource) throws StructureException Description copied from interface:StructureSynchronizerPerform full resync.
This method is called when the user request full resync or runs Import or Export.
The implementation of this method should make structure and other aspect of an issue synchronized, inspecting and making changes to all issues that are subject for synchronization according to the synchronizer's configuration.
The implementation should detect the resync direction on its own: if only one direction is supported, then this direction should be used; if both directions are supported, the direction should be specified in the parameters.
- Specified by:
resyncin interfaceStructureSynchronizer- Parameters:
instance- the configured instance of the synchronizerforestSource- the source from which to retrieveForestfor the synchronized structure and to which to apply Structure updates- Throws:
StructureException- See Also:
-
doSync
@NotNull protected abstract AbstractSynchronizer.SyncRunAuditEntry doSync(@NotNull SyncInstance instance, @NotNull IncrementalSyncData data, @NotNull ForestSource forestSource) throws StructureException - Throws:
StructureException
-
doResync
@NotNull protected abstract AbstractSynchronizer.SyncRunAuditEntry doResync(@NotNull SyncInstance instance, @NotNull ForestSource forestSource) throws StructureException - Throws:
StructureException
-
success
-
failure
-
failure
-
failure
-