Class BaseBuildTypeIdentity
- java.lang.Object
-
- jetbrains.buildServer.serverSide.impl.BaseBuildTypeIdentity
-
- All Implemented Interfaces:
BuildTypeIdentity
,BuildTypeIdentityEx
,SPersistentEntity
- Direct Known Subclasses:
BuildTypeImpl
,BuildTypeTemplateImpl
public abstract class BaseBuildTypeIdentity extends Object implements BuildTypeIdentityEx
Base class for build template and build configuration.Contains data and behaviour relates to the build template and build configurations identifiers and names.
- Since:
- 8.0
- Author:
- Leonid Bushuev from JetBrains
-
-
Field Summary
Fields Modifier and Type Field Description static String
IGNORE_BUILD_CONF_DEPENDENCIES_ON_MOVE
protected BuildTypeIdentityContext
myContext
protected EntityId<String>
myEntityId
The internal and external identifiers.protected Object
myExtIdChangeLock
protected String
myFormerExternalId
The former external identifier (when the new one has been assigned but not persisted yet).protected String
myName
The name of the identity.protected ProjectEx
myProject
Project this identity belongs to.
-
Constructor Summary
Constructors Modifier Constructor Description protected
BaseBuildTypeIdentity(BuildTypeIdentityContext context, ProjectEx project, EntityId<String> entityId, String name)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract void
auditExternalIdChanged(ConfigAction cause, String oldExternalId, String newExternalId)
protected void
beforeModification()
This method is called from methods that modify the state (the state that should be persisted).boolean
belongsTo(SProject project)
Checks whether this build type or template belongs to the specified project or one of its subprojects, transitively.protected abstract void
checkObsolete()
ConfigAction
createConfigAction(SUser user, String description)
Creates a config action instance associated with this entity and having the specified description.protected abstract ConfigAction
createExternalIdChangedConfigAction()
protected void
createFirstConfigVersionIfHistoryIsEmpty()
protected void
doPersist(ConfigAction cause)
protected void
doPersist(BackgroundPersistTask task)
File
getConfigDirectory()
Returns the directory where this configuration file is saved.protected abstract FileHistory
getConfigHistory()
String
getConfigId()
Returns the entity's config identifier.File
getConfigurationFile()
Returns the configuration file.File
getConfigurationFile(File projectsDir)
Returns the configuration file where this entity is persisted in custom projects directoryEntityId<String>
getEntityId()
Returns the instance of the entity identifier.String
getExternalId()
Returns the external identifier.String
getFullName()
Name of the project and name of the identity.String
getInternalId()
Returns the internal identifier.String
getName()
The name of the identity.SPersistentEntity
getParent()
The parent entity.ProjectEx
getProject()
Returns the project this build type entity belongs to.String
getProjectId()
PersistentEntityVersion
getVersion()
Returns version of this entity which can be used to check if the entity was edited or persisted.protected abstract boolean
isTemplate()
protected abstract void
logChangedConfigToAudit(ConfigAction cause, String description, int versionAfter)
protected abstract void
logRemovingToAudit(ConfigAction cause)
protected void
markEdited()
void
markPersisted(long expectedEditId)
Marks entity as persistedvoid
markUnedited()
protected abstract void
nameChanged(String oldName, String newName)
void
persist()
Persists this entity instance onto disk.void
persist(ConfigAction cause)
Persists this entity on disk.protected abstract void
persistAuxiliaryData()
protected abstract void
persistInternal(ConfigAction cause)
protected abstract void
persistInternal(BackgroundPersistTask task)
protected void
processConfigIfChanged(ConfigAction cause)
void
remove()
Removes this build template or configuration.void
remove(ConfigAction cause)
BackgroundPersistTask
schedulePersisting(String reason)
Schedules background persisting of this entity settings.BackgroundPersistTask
schedulePersisting(ConfigAction cause)
Schedules background persisting of this project settings.void
schedulePersisting(BackgroundPersistTask task)
PersistTask
scheduleRemove(ConfigAction cause)
Schedules remove of this persistent entity.abstract void
sendExtIdChangedEvents(ConfigAction cause, String oldExternalId, String newExternalId)
The method is called when the external identifier has been changed.protected void
sendPersistedEvents(ConfigAction cause)
void
setExternalId(String newExternalId)
Changes the external id of this build template or build configuration.void
setExternalId(ConfigAction cause, String newExternalId)
Changes the external id of this build template or build configuration.void
setExternalId(ConfigAction cause, String newExternalId, boolean sendEvents)
Same as {BuildTypeIdentity.setExternalId(ConfigAction, String)
} but provides control over events processing.void
setName(String newName)
Renames this build type identity.String
toString()
abstract void
unregister()
Removes this object from project model.protected abstract void
warnObsolete()
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface jetbrains.buildServer.serverSide.BuildTypeIdentityEx
getSettings
-
Methods inherited from interface jetbrains.buildServer.serverSide.SPersistentEntity
getReadOnlyReason, isReadOnly, isVirtual
-
-
-
-
Field Detail
-
IGNORE_BUILD_CONF_DEPENDENCIES_ON_MOVE
public static final String IGNORE_BUILD_CONF_DEPENDENCIES_ON_MOVE
- See Also:
- Constant Field Values
-
myContext
@NotNull protected final BuildTypeIdentityContext myContext
-
myProject
@NotNull protected volatile ProjectEx myProject
Project this identity belongs to.
-
myEntityId
@NotNull protected final EntityId<String> myEntityId
The internal and external identifiers.
-
myFormerExternalId
@NotNull protected volatile String myFormerExternalId
The former external identifier (when the new one has been assigned but not persisted yet).
-
myName
@NotNull protected String myName
The name of the identity.
-
myExtIdChangeLock
protected final Object myExtIdChangeLock
-
-
Constructor Detail
-
BaseBuildTypeIdentity
protected BaseBuildTypeIdentity(@NotNull BuildTypeIdentityContext context, @NotNull ProjectEx project, @NotNull EntityId<String> entityId, @NotNull String name)
-
-
Method Detail
-
beforeModification
protected void beforeModification()
This method is called from methods that modify the state (the state that should be persisted). All modification methods must call it before modifications are performed.- Since:
- 8.0
-
getProject
@NotNull public ProjectEx getProject()
Returns the project this build type entity belongs to.- Specified by:
getProject
in interfaceBuildTypeIdentity
- Returns:
- the project this build type entity belongs to.
-
getParent
@Nullable public SPersistentEntity getParent()
Description copied from interface:SPersistentEntity
The parent entity.- Specified by:
getParent
in interfaceSPersistentEntity
- Returns:
- see above.
-
getProjectId
@NotNull public String getProjectId()
-
getEntityId
@NotNull public EntityId<String> getEntityId()
Description copied from interface:BuildTypeIdentityEx
Returns the instance of the entity identifier.This instance (not a copy!) that contains immutable internal id and modifiable external id. When one has changed the external id of this build template or configuration, the external id incide this class instance will be changed too.
- Specified by:
getEntityId
in interfaceBuildTypeIdentityEx
- Returns:
- the instance of the entity identifier.
-
getInternalId
@NotNull public final String getInternalId()
Returns the internal identifier.- Specified by:
getInternalId
in interfaceBuildTypeIdentity
- Returns:
- the internal identifier.
-
getConfigId
@NotNull public String getConfigId()
Description copied from interface:SPersistentEntity
Returns the entity's config identifier. Config identifier uniquely identifies the entity across different TeamCity servers and can't be modified in contrast to external identifier.- Specified by:
getConfigId
in interfaceSPersistentEntity
-
getExternalId
@NotNull public final String getExternalId()
Returns the external identifier.- Specified by:
getExternalId
in interfaceBuildTypeIdentity
- Specified by:
getExternalId
in interfaceSPersistentEntity
- Returns:
- the external identifier.
-
getName
@NotNull public String getName()
Description copied from interface:BuildTypeIdentity
The name of the identity.- Specified by:
getName
in interfaceBuildTypeIdentity
- Specified by:
getName
in interfaceSPersistentEntity
- Returns:
- see above.
- See Also:
BuildTypeIdentity.getFullName()
,BuildTypeIdentity.setName(String)
-
getFullName
@NotNull public String getFullName()
Description copied from interface:BuildTypeIdentity
Name of the project and name of the identity.- Specified by:
getFullName
in interfaceBuildTypeIdentity
- See Also:
BuildTypeIdentity.getName()
-
belongsTo
public boolean belongsTo(@NotNull SProject project)
Description copied from interface:BuildTypeIdentity
Checks whether this build type or template belongs to the specified project or one of its subprojects, transitively.- Specified by:
belongsTo
in interfaceBuildTypeIdentity
- Parameters:
project
- the project to check this configuration to belongs to.- Returns:
- true if belongs.
-
setExternalId
public void setExternalId(@NotNull String newExternalId) throws InvalidIdentifierException, DuplicateExternalIdException
Description copied from interface:BuildTypeIdentity
Changes the external id of this build template or build configuration.This method persists the current entity, and can persist also dependent entities.
- Specified by:
setExternalId
in interfaceBuildTypeIdentity
- Parameters:
newExternalId
- new external identifier. Must be unique (case insensitively) in the scope of all build templates and build configurations (in other words, two projects with build configurations with same external id are not allowed).- Throws:
InvalidIdentifierException
- wrong identifierDuplicateExternalIdException
- a build template or a build configuration
-
setExternalId
public void setExternalId(@NotNull ConfigAction cause, @NotNull String newExternalId) throws InvalidIdentifierException, DuplicateExternalIdException, ObsoleteEntityException
Description copied from interface:BuildTypeIdentity
Changes the external id of this build template or build configuration.This method persists the current entity, and can persist also dependent entities.
- Specified by:
setExternalId
in interfaceBuildTypeIdentity
- Parameters:
cause
- configuration action caused the changenewExternalId
- new external identifier. Must be unique (case insensitively) in the scope of all build templates and build configurations (in other words, two projects with build configurations with same external id are not allowed).- Throws:
InvalidIdentifierException
- wrong identifierDuplicateExternalIdException
- a build template or a build configurationObsoleteEntityException
- when build type/template is not the same as the one in the project model (since 9.1.2)
-
setExternalId
public void setExternalId(@NotNull ConfigAction cause, @NotNull String newExternalId, boolean sendEvents) throws InvalidIdentifierException, DuplicateExternalIdException, ObsoleteEntityException
Description copied from interface:BuildTypeIdentityEx
Same as {BuildTypeIdentity.setExternalId(ConfigAction, String)
} but provides control over events processing. If parameter sendEvents is false, then no events about changing of the external id will be sent. This mode can be useful if the events will be sent later, for instance, in case of bulk edit ids operation.- Specified by:
setExternalId
in interfaceBuildTypeIdentityEx
- Throws:
InvalidIdentifierException
DuplicateExternalIdException
ObsoleteEntityException
-
checkObsolete
protected abstract void checkObsolete()
-
warnObsolete
protected abstract void warnObsolete()
-
sendExtIdChangedEvents
public abstract void sendExtIdChangedEvents(@NotNull ConfigAction cause, @NotNull String oldExternalId, @NotNull String newExternalId)
The method is called when the external identifier has been changed.- Specified by:
sendExtIdChangedEvents
in interfaceBuildTypeIdentityEx
- Parameters:
oldExternalId
- the old external identifier value.newExternalId
- the new external identifier value.
-
createExternalIdChangedConfigAction
@NotNull protected abstract ConfigAction createExternalIdChangedConfigAction()
-
auditExternalIdChanged
protected abstract void auditExternalIdChanged(@NotNull ConfigAction cause, @NotNull String oldExternalId, @NotNull String newExternalId)
-
setName
public void setName(@NotNull String newName) throws DuplicateBuildTypeNameException
Renames this build type identity.- Specified by:
setName
in interfaceBuildTypeIdentity
- Parameters:
newName
- new name- Throws:
DuplicateBuildTypeNameException
- See Also:
BuildTypeIdentity.getName()
,BuildTypeIdentity.getFullName()
-
persist
public final void persist() throws PersistFailedException
Description copied from interface:SPersistentEntity
Persists this entity instance onto disk. Should be called each time when settings are changed, otherwise the changes will be lost after the server restart.- Specified by:
persist
in interfaceSPersistentEntity
- Throws:
PersistFailedException
- if persisting failed
-
persist
public void persist(@NotNull ConfigAction cause) throws PersistFailedException
Description copied from interface:SPersistentEntity
Persists this entity on disk.- Specified by:
persist
in interfaceSPersistentEntity
- Parameters:
cause
- an action which caused persisting- Throws:
PersistFailedException
- if persisting failed
-
schedulePersisting
@NotNull public BackgroundPersistTask schedulePersisting(@NotNull String reason) throws PersistFailedException
Description copied from interface:SPersistentEntity
Schedules background persisting of this entity settings.- Specified by:
schedulePersisting
in interfaceSPersistentEntity
- Parameters:
reason
- provides a reason why persist operation was called- Returns:
- a task which can be used to track the operation progress or wait for the operation to complete
- Throws:
PersistFailedException
- if failed to schedule the operation- See Also:
SPersistentEntity.schedulePersisting(ConfigAction)
-
schedulePersisting
@NotNull public BackgroundPersistTask schedulePersisting(@NotNull ConfigAction cause) throws PersistFailedException
Description copied from interface:SPersistentEntity
Schedules background persisting of this project settings.- Specified by:
schedulePersisting
in interfaceSPersistentEntity
- Parameters:
cause
- an action which caused persisting- Returns:
- a task which can be used to track the operation progress or wait for the operation to complete
- Throws:
PersistFailedException
- if failed to schedule the operation- See Also:
SPersistentEntity.schedulePersisting(String)
-
schedulePersisting
public void schedulePersisting(@NotNull BackgroundPersistTask task) throws PersistFailedException
- Throws:
PersistFailedException
-
sendPersistedEvents
protected void sendPersistedEvents(@NotNull ConfigAction cause)
-
persistInternal
protected abstract void persistInternal(@NotNull ConfigAction cause) throws PersistFailedException
- Throws:
PersistFailedException
-
persistInternal
protected abstract void persistInternal(@NotNull BackgroundPersistTask task) throws PersistFailedException
- Throws:
PersistFailedException
-
doPersist
protected void doPersist(@NotNull ConfigAction cause)
-
doPersist
protected void doPersist(@NotNull BackgroundPersistTask task)
-
persistAuxiliaryData
protected abstract void persistAuxiliaryData()
-
createFirstConfigVersionIfHistoryIsEmpty
protected void createFirstConfigVersionIfHistoryIsEmpty()
-
processConfigIfChanged
protected void processConfigIfChanged(@NotNull ConfigAction cause)
-
getConfigHistory
@NotNull protected abstract FileHistory getConfigHistory() throws IOException
- Throws:
IOException
-
logChangedConfigToAudit
protected abstract void logChangedConfigToAudit(@NotNull ConfigAction cause, @Nullable String description, int versionAfter)
-
getConfigDirectory
@NotNull public File getConfigDirectory()
Returns the directory where this configuration file is saved. If the project is in state when it's just changed external id is not persisted yet, the result of this function is based on the former project external id (in other words, it always points to the actual directory path).The directory can be not existent yet if no build templates or configurations were persisted.
- Returns:
- see above.
-
getConfigurationFile
@NotNull public File getConfigurationFile()
Returns the configuration file. If this build template/type or the project are in the state when it's just changed external id is not persisted yet, the result of this function is based on the former external id (in other words, it points to the actual file path).The file or underlying directory can be not existent yet if no project or build templates or configurations were persisted.
- Specified by:
getConfigurationFile
in interfaceBuildTypeIdentity
- Specified by:
getConfigurationFile
in interfaceSPersistentEntity
- Returns:
- see above.
-
getConfigurationFile
@NotNull public File getConfigurationFile(@NotNull File projectsDir)
Description copied from interface:SPersistentEntity
Returns the configuration file where this entity is persisted in custom projects directory- Specified by:
getConfigurationFile
in interfaceSPersistentEntity
- Parameters:
projectsDir
- path to teamcity projects directory- Returns:
- see above
-
remove
public void remove()
Removes this build template or configuration.This method also makes all changes on the disk and in the database, so calling persist() is not needed after this method.
- Specified by:
remove
in interfaceSPersistentEntity
-
remove
public void remove(@NotNull ConfigAction cause)
-
scheduleRemove
@NotNull public PersistTask scheduleRemove(@NotNull ConfigAction cause) throws PersistFailedException
Description copied from interface:SPersistentEntity
Schedules remove of this persistent entity. Returns task which can be used to wait for the operation to complete.- Specified by:
scheduleRemove
in interfaceSPersistentEntity
- Parameters:
cause
- reason of the remove- Returns:
- a task which can be used to track the operation progress or wait for the operation to complete
- Throws:
PersistFailedException
- if failed to schedule the operation
-
isTemplate
protected abstract boolean isTemplate()
-
unregister
public abstract void unregister()
Description copied from interface:BuildTypeIdentityEx
Removes this object from project model. No changes on disk are performed.- Specified by:
unregister
in interfaceBuildTypeIdentityEx
-
logRemovingToAudit
protected abstract void logRemovingToAudit(@NotNull ConfigAction cause)
-
markEdited
protected void markEdited()
-
markUnedited
public void markUnedited()
-
getVersion
@NotNull public PersistentEntityVersion getVersion()
Description copied from interface:SPersistentEntity
Returns version of this entity which can be used to check if the entity was edited or persisted.- Specified by:
getVersion
in interfaceSPersistentEntity
- Returns:
- see above
-
markPersisted
public void markPersisted(long expectedEditId)
Description copied from interface:SPersistentEntity
Marks entity as persisted- Specified by:
markPersisted
in interfaceSPersistentEntity
- Parameters:
expectedEditId
- expected editId in the end of persist. The entity will be marked as unedited if expected editId is the same as actual, ie. the entity wasn't edited while persist was running
-
createConfigAction
@NotNull public ConfigAction createConfigAction(@Nullable SUser user, @NotNull String description)
Description copied from interface:SPersistentEntity
Creates a config action instance associated with this entity and having the specified description. The config action object can be used inSPersistentEntity.schedulePersisting(ConfigAction)
orSPersistentEntity.scheduleRemove(ConfigAction)
methods to describe the performed action.- Specified by:
createConfigAction
in interfaceSPersistentEntity
- Parameters:
user
- user who performs operation, or null if operation is performed by the systemdescription
- description to set to the config action object- Returns:
- new config action
-
-