@PublicSpi public abstract class AbstractSynchronizer extends Object implements 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:
SyncDirection todo implement & explain| Modifier and Type | Class and Description |
|---|---|
protected static interface |
AbstractSynchronizer.SyncRunAuditEntry |
| Modifier and Type | Field and Description |
|---|---|
protected SyncAuditLog |
myAuditLog |
protected RowManager |
myRowManager |
protected StructureComponents |
myStructureComponents |
protected StructureManager |
myStructureManager |
| Modifier | Constructor and Description |
|---|---|
protected |
AbstractSynchronizer(StructureComponents structureComponents)
Constructs an instance of the synchronizer.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addDefaultFormParameters(Map<String,Object> params)
Adds to the map the default values for the parameters in the synchronizer parameters form.
|
protected Map<String,Object> |
castParameters(Object p) |
protected abstract AbstractSynchronizer.SyncRunAuditEntry |
doResync(SyncInstance instance,
ForestSource forestSource) |
protected abstract AbstractSynchronizer.SyncRunAuditEntry |
doSync(SyncInstance instance,
IncrementalSyncData data,
ForestSource forestSource) |
protected static AbstractSynchronizer.SyncRunAuditEntry |
failure(String reason) |
protected static AbstractSynchronizer.SyncRunAuditEntry |
failure(Throwable throwable) |
protected static AbstractSynchronizer.SyncRunAuditEntry |
failure(Throwable throwable,
String reason) |
SynchronizerDescriptor |
getDescriptor() |
protected Issue |
getIssue(long issueId)
Retrieves an instance of
Issue. |
protected Issue |
getIssue(String key)
Retrieves an instance of issue by issue key.
|
protected Issue |
getIssueByRowId(long rowId) |
static long |
getIssueIdByRow(StructureRow structureRow) |
protected long |
getIssueIdByRowId(long rowId) |
protected IssueManager |
getIssueManager() |
protected String |
getText(String key,
Object... parameters)
Looks up i18n text using the i18n bean from the module's plugin and the current
user's locale.
|
void |
init(SynchronizerDescriptor descriptor)
Called by the module descriptor on initialization.
|
protected MapObject |
parametersAsMapObject(Object p)
Returns a
MapObject wrapper around the parameters map. |
protected MapObject |
parametersAsNNMapObject(Object p) |
Map<String,Object> |
restoreParameters(String data)
Deserializes a string previously created
StructureSynchronizer.storeParameters(Object) into this synchronizer's
parameters object. |
void |
resync(SyncInstance instance,
ForestSource forestSource)
Perform full resync.
|
String |
storeParameters(Object parameters)
Serializes parameters into a string (for example, JSON) for storing in the database.
|
protected static AbstractSynchronizer.SyncRunAuditEntry |
success(List<MapObject> actions) |
void |
sync(SyncInstance instance,
IncrementalSyncData syncData,
ForestSource forestSource)
Perform incremental synchronization.
|
protected boolean |
verifyStructureEditPermissions(long structureId)
Checks that the user has at least
PermissionLevel.EDIT permission on the specified structure. |
protected boolean |
verifyStructureEditPermissions(long structureId,
SyncLogger log)
Checks that the user has at least
PermissionLevel.EDIT permission on the specified structure. |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitaddFormParameters, buildParametersFromForm, getConfigDescription, getConfigDescriptionDetails, getPossibleResyncEffects, isAutosyncSupported, isAvailableprotected final StructureComponents myStructureComponents
protected final StructureManager myStructureManager
protected final RowManager myRowManager
protected final SyncAuditLog myAuditLog
protected AbstractSynchronizer(StructureComponents structureComponents)
structureComponents - services directorypublic void init(SynchronizerDescriptor descriptor)
descriptor - descriptor for this module@NotNull public SynchronizerDescriptor getDescriptor()
getDescriptor in interface StructureSynchronizer@NotNull protected String getText(@NotNull String key, Object... parameters)
key - text keyparameters - optional parameterspublic void addDefaultFormParameters(@NotNull
Map<String,Object> params)
StructureSynchronizeraddDefaultFormParameters in interface StructureSynchronizerparams - the map of parameters that the synchronizer can add topublic String storeParameters(Object parameters) throws IOException
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 null by Structure.
It is recommended to return null instead of empty String.
storeParameters in interface StructureSynchronizerparameters - sync parametersIOException - if parameters cannot be storedpublic Map<String,Object> restoreParameters(String data) throws IOException
StructureSynchronizerStructureSynchronizer.storeParameters(Object) into this synchronizer's
parameters object.restoreParameters in interface StructureSynchronizerdata - string with serialized parameters; never an empty StringIOException - if there's a problem reading parametersprotected MapObject parametersAsMapObject(Object p)
MapObject wrapper around the parameters map. MapObject can be useful for reading values.protected boolean verifyStructureEditPermissions(long structureId)
PermissionLevel.EDIT permission on the specified structure.structureId - the ID of the structureprotected boolean verifyStructureEditPermissions(long structureId,
SyncLogger log)
PermissionLevel.EDIT permission on the specified structure.structureId - the ID of the structurelog - logging helper that 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 use verifyStructureEditPermissions(long)@Nullable protected Issue getIssue(long issueId)
Issue.issueId - the ID of the issue@Nullable
protected Issue getIssue(@NotNull
String key)
key - issue key@NotNull protected IssueManager getIssueManager()
@Nullable protected Issue getIssueByRowId(long rowId)
protected final long getIssueIdByRowId(long rowId)
public static long getIssueIdByRow(StructureRow structureRow)
public void sync(@NotNull
SyncInstance instance,
@NotNull
IncrementalSyncData syncData,
@NotNull
ForestSource forestSource)
throws StructureException
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 StructureJobManager shortly 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.
sync in interface StructureSynchronizerinstance - 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 retrieve Forest forStructureExceptionpublic void resync(@NotNull
SyncInstance instance,
@NotNull
ForestSource forestSource)
throws StructureException
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.
resync in interface StructureSynchronizerinstance - the configured instance of the synchronizerforestSource - the source from which to retrieve Forest for
the synchronized structure and to which to apply Structure updatesStructureExceptionStructureSyncManager.resync(java.lang.Long, boolean, java.lang.Long)@NotNull protected abstract AbstractSynchronizer.SyncRunAuditEntry doSync(@NotNull SyncInstance instance, @NotNull IncrementalSyncData data, @NotNull ForestSource forestSource) throws StructureException
StructureException@NotNull protected abstract AbstractSynchronizer.SyncRunAuditEntry doResync(@NotNull SyncInstance instance, @NotNull ForestSource forestSource) throws StructureException
StructureExceptionprotected static AbstractSynchronizer.SyncRunAuditEntry success(List<MapObject> actions)
protected static AbstractSynchronizer.SyncRunAuditEntry failure(String reason)
protected static AbstractSynchronizer.SyncRunAuditEntry failure(Throwable throwable)
protected static AbstractSynchronizer.SyncRunAuditEntry failure(Throwable throwable, String reason)
Copyright © 2021 ALM Works. All Rights Reserved.