Interface StructureSyncManager
StructureSyncManager manages the whole synchronization engine.
There are several synchronizers in the system, provided by <structure-synchronizer>
modules, and each synchronizer may have several instances, represented by SyncInstance.
Synchronizer instance is a configured synchronizer, installed onto a specific structure. Synchronizer
instances are addressed via unique ID.
This class does not check permissions of the caller.
If the calling code works on behalf of a user, it must check whether
the user has permission level on the subject structure.
PermissionLevel.ADMIN
- Author:
- Igor Sereda
-
Method Summary
Modifier and TypeMethodDescriptiongetInstalledSynchronizer(Long instanceId) Retrieves an instance of installed synchronizer.getInstalledSynchronizersForStructure(Long structureId) Retrieves all synchronizer instances installed for the given structure.installSynchronizer(StructureSynchronizer synchronizer, Long structureId, Object params, ApplicationUser user) Installs a new synchronizer for a structure.longinstallSynchronizerOffline(String moduleKey, String parameters, Long structureId, String ownerKey, boolean autosyncEnabled) Installs synchronizer based on the serialized data.booleanisAutosyncEnabled(Long instanceId) Checks if incremental synchronization is enabled for the specified synchronizervoidStarts full synchronization in the specified direction.voidresyncOnce(StructureSynchronizer synchronizer, Object params, Long structureId, ApplicationUser user, Long processId) Runs full resync without installing the synchronizer.voidsetAutosyncEnabled(Long instanceId, boolean enabled) Enables or disables the incremental synchronization for the specified synchronizer.voidDisables and uninstalls all synchronizers for all structures.voiduninstallSynchronizer(Long instanceId) Disables and uninstalls synchronizer with the specified ID.voiduninstallSynchronizersForStructure(Long structureId) Convenience method that disables and uninstalls all synchronizers for the specified structure.updateSynchronizer(Long instanceId, Object params, ApplicationUser user) Updates the parameters and/or the owner of an installed synchronizer.
-
Method Details
-
getInstalledSynchronizer
Retrieves an instance of installed synchronizer.- Parameters:
instanceId- the ID of the instance- Returns:
- synchronizer instance, or null if there's no instance with such ID
-
getInstalledSynchronizersForStructure
Retrieves all synchronizer instances installed for the given structure.- Parameters:
structureId- the ID of the structure- Returns:
- a list of installed synchronizer instances
-
installSynchronizer
@NotNull SyncInstance installSynchronizer(@NotNull StructureSynchronizer synchronizer, @NotNull Long structureId, @Nullable Object params, @Nullable ApplicationUser user) throws StructureSynchronizerException Installs a new synchronizer for a structure. Synchronizer configuration is persisted - it will be there after JIRA restart - but the synchronizer is not yet enabled for incremental synchronization. To enable the synchronizer, usesetAutosyncEnabled(java.lang.Long, boolean)orresync(java.lang.Long, boolean, java.lang.Long).- Parameters:
synchronizer- the type of the synchronizer to be installedstructureId- the ID of the structureparams- synchronization parameters, of the type accepted by the synchronizeruser- the user account, under which the synchronization will run.null(anonymous) is not allowed- Returns:
- the new instance of the synchronizer
- Throws:
StructureSynchronizerException- if the synchronizer cannot be installed
-
installSynchronizerOffline
long installSynchronizerOffline(@NotNull String moduleKey, @Nullable String parameters, @NotNull Long structureId, @Nullable String ownerKey, boolean autosyncEnabled) throws StructureSynchronizerException Installs synchronizer based on the serialized data. The effect is the same as with
installSynchronizer(com.almworks.jira.structure.api.sync.StructureSynchronizer, java.lang.Long, java.lang.Object, com.atlassian.jira.user.ApplicationUser), but the parameters allow to define synchronizer without resolving data into the classes required by theinstallSynchronizermethod.This method also allows installing a synchronizer that is currently not present in the system - for example, if a plugin that provides it is disabled. The synchronizer will be installed but
SyncInstancewill not be created until the synchronizer module is available.- Parameters:
moduleKey- the full module key of the synchronizer moduleparameters- serialized parameters (as previously returned byStructureSynchronizer.storeParameters(Object)). Note that empty String is treated the same way asnull.structureId- the ID of the structureownerKey- user key of the synchronizer ownerautosyncEnabled- if true, the autosync should be initially enabled for this structure- Returns:
- the ID of the installed synchronizer instance
- Throws:
StructureSynchronizerException- if the synchronizer cannot be installed
-
uninstallSynchronizer
Disables and uninstalls synchronizer with the specified ID. If the synchronization is running, it may finish.- Parameters:
instanceId- the ID of the synchronizer
-
uninstallAllSynchronizers
void uninstallAllSynchronizers()Disables and uninstalls all synchronizers for all structures. -
uninstallSynchronizersForStructure
Convenience method that disables and uninstalls all synchronizers for the specified structure.- Parameters:
structureId- the ID of the structure
-
isAutosyncEnabled
Checks if incremental synchronization is enabled for the specified synchronizer- Parameters:
instanceId- the ID of the synchronizer instance- Returns:
- true if the synchronizer is present and has autosync enabled
-
setAutosyncEnabled
void setAutosyncEnabled(@Nullable Long instanceId, boolean enabled) throws StructureSynchronizerException Enables or disables the incremental synchronization for the specified synchronizer.- Parameters:
instanceId- the ID of the synchronizer instanceenabled- if true, the autosync is enabled- Throws:
StructureSynchronizerException- if the incremental synchronization for this synchronizer cannot be enabled
-
resync
void resync(@Nullable Long instanceId, boolean andEnable, @Nullable Long processId) throws StructureSynchronizerException Starts full synchronization in the specified direction.
- Parameters:
instanceId- the ID of the installed synchronizerandEnable- if true, incremental synchronization will be enabled right after the resync job is scheduled, making sure that no changes will be missedprocessId- if not null, resync progress will be reported via this ID- Throws:
StructureSynchronizerException- if resync could not be started
-
resyncOnce
void resyncOnce(@NotNull StructureSynchronizer synchronizer, @Nullable Object params, @NotNull Long structureId, @Nullable ApplicationUser user, @Nullable Long processId) throws StructureSynchronizerException Runs full resync without installing the synchronizer. (For example, this is used by Export and Import features.)
Parameters of the appropriate type are required to run the synchronizer. Those are typically collected from the user via synchronizer module form and created with
StructureSynchronizer.buildParametersFromForm(java.util.Map<java.lang.String, ?>, com.atlassian.jira.web.action.JiraWebActionSupport)or can be created by the custom code which is aware of the class of the synchronizer parameters. Note that ifStructureSynchronizer.storeParameters(Object)returns an empty String forparams, then the synchronizer will be called withnullparameters.- Parameters:
synchronizer- the synchronizer to runparams- synchronizer parametersstructureId- the ID of the structureuser- the user account under which the synchronization should runprocessId- if not null, resync progress will be reported via this ID- Throws:
StructureSynchronizerException- if the synchronization could not be started
-
updateSynchronizer
@NotNull SyncInstance updateSynchronizer(@Nullable Long instanceId, @Nullable Object params, @Nullable ApplicationUser user) throws StructureSynchronizerException Updates the parameters and/or the owner of an installed synchronizer. Incremental synchronization must be disabled when calling this method.- Parameters:
instanceId- the ID of the installed synchronizerparams- new synchronization parameters, of the type accepted by the synchronizer. Ifnullor ifStructureSynchronizer.storeParameters(Object)returnsnullor an empty String for the specified object, the synchronizer will keep using its current parameters.user- the user account under which this synchronizer will run after the update. Ifnull, the synchronizer will keep running under its current account- Returns:
- the new instance of the synchronizer if
useris notnullorparamsare notnull, otherwise the existing instance - Throws:
StructureSynchronizerException- if the synchronizer could not be updated
-