Class TemporaryIdentifiersManager<INT>
- java.lang.Object
-
- jetbrains.buildServer.serverSide.identifiers.TemporaryIdentifiersManager<INT>
-
- All Implemented Interfaces:
ExternalIdGenerator
,IdentifiersManager<INT>
public class TemporaryIdentifiersManager<INT> extends Object implements IdentifiersManager<INT>
Allows registering new extId-configId pairs without writing them into DB.
-
-
Constructor Summary
Constructors Constructor Description TemporaryIdentifiersManager(BaseIdentifiersManager<INT> delegate)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description INT
configIdToInternal(String configId)
Looks for the internal identifier by the given config id.void
consumeEntityIds(Consumer<EntityId<INT>> consumer)
Consumes entityIds in this managerboolean
externalIdSatisfiesConvention(String externalId, String entityName, String parentExtId)
Returns true if provided external id satisfies convention used to generate new idsINT
externalToInternal(String extId)
Looks for the internal identifier by the given external one.List<INT>
externalToInternal(List<String> extIds)
Looks for the internal identifiers by the given external onesEntityId<INT>
findEntityIdByConfigId(String configId)
Looks for a registered entity id by the given config id.EntityId<INT>
findEntityIdByExternalId(String extId)
Looks for a registered entity id by the given external id.EntityId<INT>
findEntityIdByInternalId(INT intId)
Looks for a registered entity id by the given internal id.EntityId<INT>
generateAndRegisterBrandNewExternalId(String parentExtId, String name)
Generates a unique external identifier by the given parent external identifier and a user string (usually name), and register the just generated identifier as a brand new one.String
generateNewExternalId(String parentExtId, String name, Set<String> excludeAdditionalIds)
Generates a new external id based on the given name and (optionally) parent external id.String
generateNewExternalId(String parentExtId, String name, Set<String> excludeIds, boolean adjustCase)
Generates a new external id based on the given name and (optionally) parent external id.INT
generateNewIntId(String newExtId)
Set<String>
getAllExternalIds()
Provides with all known external identifiers.Set<String>
getAllExternalIds(INT intId)
Returns all external ids that correspond to theintId
.Set<INT>
getAllInternalIds()
Provides with all known internal identifiers.Map<String,EntityId<INT>>
getNewConfigIds()
Set<EntityId<INT>>
getNewEntities()
Collection<EntityId<INT>>
getNewOrChangedEntities()
String
internalToExternal(INT intId)
Looks for the external identifier by the given internal one.List<String>
internalToExternal(List<INT> intIds)
Looks for the external identifiers by the given internal ones.boolean
isExternalIdAlias(String externalId)
Check whether the external id is an alias (but not a primary external id).void
markRemoved(EntityId<INT> entityId, String originProjectIntId)
Marks specified entityId as removed and sets the origin project internal id to the given valuevoid
modifyConfigId(EntityId<INT> entityId, String newConfigId, CustomIdChangeApplier<String> configApplier)
Modifies the given config identifier to the given new one.void
modifyExternalId(EntityId<INT> entityId, String newExternalId, CustomIdChangeApplier<String> externalApplier)
Modifies the given external identifier to the given new one.void
reassignInternalId(EntityId<INT> entityId, INT internalId, CustomIdChangeApplier<INT> applier)
Assigns the specified internalId to the given entity and runs provided applier after that.void
reassignInternalIdInMemory(EntityId<INT> entityId, INT internalId)
Reassigns internal id in memory only, does not change anything in database.EntityId<INT>
refreshFromDbIfNecessary(String extId, String configId)
Looks for a registered entity id by the given config id and ext id and refresh from db if necessary.String
regenerateExternalId(String parentExtId, String name, String currentExternalId)
Regenerates an external id based on the given name and (optionally) parent external id.EntityId<INT>
registerBrandNewExternalId(String extId)
Registers the given external identifier with a brand new internal one.EntityId<INT>
registerOrReuseExternalAndConfigId(String extId, String configId)
Registers the given external identifier and config id pair.boolean
removeExternalIdAlias(String externalIdAlias)
Removes the external id alias (but not a primary external id) from the model and database.void
resetRemoved(Collection<EntityId<INT>> entityIds)
Resets removed mark for the given entityIdvoid
validateExternalId(String extId, EntityId<INT> curObjId)
Validates given external identifier
-
-
-
Constructor Detail
-
TemporaryIdentifiersManager
public TemporaryIdentifiersManager(@NotNull BaseIdentifiersManager<INT> delegate)
-
-
Method Detail
-
registerBrandNewExternalId
@NotNull public EntityId<INT> registerBrandNewExternalId(@NotNull String extId)
Description copied from interface:IdentifiersManager
Registers the given external identifier with a brand new internal one. If such external identifier was already registered, the correspondent internal one is dropped (and is not reused).- Specified by:
registerBrandNewExternalId
in interfaceIdentifiersManager<INT>
- Parameters:
extId
- the external identifier to register.- Returns:
- new associated internal identifier.
-
registerOrReuseExternalAndConfigId
@NotNull public EntityId<INT> registerOrReuseExternalAndConfigId(@NotNull String extId, @Nullable String configId) throws InvalidIdentifierException
Description copied from interface:IdentifiersManager
Registers the given external identifier and config id pair. If specified config id exists in database it's internal id will be used, otherwise new internal id will be generated.- Specified by:
registerOrReuseExternalAndConfigId
in interfaceIdentifiersManager<INT>
- Parameters:
extId
- the external identifier to register.configId
- the config identifier to register, if null new config id is generated.- Returns:
- associated internal identifier.
- Throws:
InvalidIdentifierException
-
findEntityIdByConfigId
@Nullable public EntityId<INT> findEntityIdByConfigId(@NotNull String configId)
Description copied from interface:IdentifiersManager
Looks for a registered entity id by the given config id.- Specified by:
findEntityIdByConfigId
in interfaceIdentifiersManager<INT>
- Parameters:
configId
- config id, case insensitive.- Returns:
- found entity id or null when not found.
-
refreshFromDbIfNecessary
@Nullable public EntityId<INT> refreshFromDbIfNecessary(@NotNull String extId, @Nullable String configId)
Description copied from interface:IdentifiersManager
Looks for a registered entity id by the given config id and ext id and refresh from db if necessary. Called by secondary nodes while loading new entities- Specified by:
refreshFromDbIfNecessary
in interfaceIdentifiersManager<INT>
- Returns:
- found entity id or null when not found.
-
findEntityIdByExternalId
@Nullable public EntityId<INT> findEntityIdByExternalId(@NotNull String extId)
Description copied from interface:IdentifiersManager
Looks for a registered entity id by the given external id.- Specified by:
findEntityIdByExternalId
in interfaceIdentifiersManager<INT>
- Returns:
- found entity id or null when not found.
-
externalToInternal
@NotNull public List<INT> externalToInternal(@NotNull List<String> extIds)
Description copied from interface:IdentifiersManager
Looks for the internal identifiers by the given external ones- Specified by:
externalToInternal
in interfaceIdentifiersManager<INT>
- Parameters:
extIds
- list of external IDs. Nulls are allowed.- Returns:
- List of internal IDs. List size is always equal to initial one. For unknown IDs null will be returned
-
externalToInternal
@Nullable public INT externalToInternal(@Nullable String extId)
Description copied from interface:IdentifiersManager
Looks for the internal identifier by the given external one.- Specified by:
externalToInternal
in interfaceIdentifiersManager<INT>
- Parameters:
extId
- external identifier (case insensitive).- Returns:
- the internal identifier if found, or null if not found.
-
validateExternalId
public void validateExternalId(@NotNull String extId, @Nullable EntityId<INT> curObjId)
Description copied from interface:IdentifiersManager
Validates given external identifier- Specified by:
validateExternalId
in interfaceIdentifiersManager<INT>
- Parameters:
extId
- identifier to validate
-
generateAndRegisterBrandNewExternalId
@NotNull public EntityId<INT> generateAndRegisterBrandNewExternalId(@Nullable String parentExtId, @NotNull String name) throws InvalidIdentifierException
Description copied from interface:IdentifiersManager
Generates a unique external identifier by the given parent external identifier and a user string (usually name), and register the just generated identifier as a brand new one.- Specified by:
generateAndRegisterBrandNewExternalId
in interfaceIdentifiersManager<INT>
- Parameters:
parentExtId
- the parent's external identifier (optional).name
- the user string (name).- Returns:
- just created identifiers pair.
- Throws:
InvalidIdentifierException
-
generateNewExternalId
@NotNull public String generateNewExternalId(@Nullable String parentExtId, @NotNull String name, @Nullable Set<String> excludeAdditionalIds)
Description copied from interface:ExternalIdGenerator
Generates a new external id based on the given name and (optionally) parent external id. May adjust the case of the name part of the id to comply with external id conventions- Specified by:
generateNewExternalId
in interfaceExternalIdGenerator
- Parameters:
parentExtId
- the parent's external identifier (optional).name
- the user string (name).excludeAdditionalIds
- an additional set of ids that are already used (i.e. the result should not be one of them). The current assigned external ids are excluded by default.- Returns:
- new external id
-
generateNewExternalId
@NotNull public String generateNewExternalId(@Nullable String parentExtId, @NotNull String name, @Nullable Set<String> excludeIds, boolean adjustCase)
Description copied from interface:ExternalIdGenerator
Generates a new external id based on the given name and (optionally) parent external id.- Specified by:
generateNewExternalId
in interfaceExternalIdGenerator
- Parameters:
parentExtId
- the parent's external identifier (optional).name
- the user string (name).excludeIds
- an additional set of ids that are already used (i.e. the result should not be one of them). The current assigned external ids are excluded by default.adjustCase
- If true, the method is allowed to adjust the case of the name part of the external id- Returns:
- new external id
-
externalIdSatisfiesConvention
public boolean externalIdSatisfiesConvention(@NotNull String externalId, @NotNull String entityName, @NotNull String parentExtId)
Description copied from interface:ExternalIdGenerator
Returns true if provided external id satisfies convention used to generate new ids- Specified by:
externalIdSatisfiesConvention
in interfaceExternalIdGenerator
- Parameters:
externalId
- external ids to checkentityName
- name of the entity whose external id is to be verifiedparentExtId
- parent external id- Returns:
- see above
-
findEntityIdByInternalId
@Nullable public EntityId<INT> findEntityIdByInternalId(@NotNull INT intId)
Description copied from interface:IdentifiersManager
Looks for a registered entity id by the given internal id.- Specified by:
findEntityIdByInternalId
in interfaceIdentifiersManager<INT>
- Parameters:
intId
- internal id.- Returns:
- found entity id or null when not found.
-
modifyExternalId
public void modifyExternalId(@NotNull EntityId<INT> entityId, @NotNull String newExternalId, @Nullable CustomIdChangeApplier<String> externalApplier) throws DuplicateExternalIdException, NoSuchExternalIdException
Description copied from interface:IdentifiersManager
Modifies the given external identifier to the given new one.- Specified by:
modifyExternalId
in interfaceIdentifiersManager<INT>
- Parameters:
entityId
- the entity id where to modify its external id.newExternalId
- the new external id.externalApplier
- external procedure to make changes in files when successful.- Throws:
DuplicateExternalIdException
- thrown when such external identifier already exists.NoSuchExternalIdException
-
modifyConfigId
public void modifyConfigId(@NotNull EntityId<INT> entityId, @NotNull String newConfigId, @Nullable CustomIdChangeApplier<String> configApplier) throws DuplicateConfigIdException
Description copied from interface:IdentifiersManager
Modifies the given config identifier to the given new one.- Specified by:
modifyConfigId
in interfaceIdentifiersManager<INT>
- Parameters:
entityId
- the entity id where to modify its config id.newConfigId
- the new config id.configApplier
- external procedure to make changes in files when successful.- Throws:
DuplicateConfigIdException
-
reassignInternalId
public void reassignInternalId(@NotNull EntityId<INT> entityId, @NotNull INT internalId, @Nullable CustomIdChangeApplier<INT> applier)
Description copied from interface:IdentifiersManager
Assigns the specified internalId to the given entity and runs provided applier after that. The internalId should come from an entityId present in DB and marked as removed, otherwise anIllegalArgumentException
is thrown. Makes the extId of the given internalId becomes an alias for the entityId. Also creates a new deleted entity with extId='{entityId.extId}_Detached', intId={entityId.intId}, cfgId={entityId.cfgId}, so that {entityId.intId} can then be specified as internalId to in this method.- Specified by:
reassignInternalId
in interfaceIdentifiersManager<INT>
-
reassignInternalIdInMemory
public void reassignInternalIdInMemory(@NotNull EntityId<INT> entityId, @NotNull INT internalId)
Description copied from interface:IdentifiersManager
Reassigns internal id in memory only, does not change anything in database. Should be used in case of multi node event about internal id changes.- Specified by:
reassignInternalIdInMemory
in interfaceIdentifiersManager<INT>
-
removeExternalIdAlias
public boolean removeExternalIdAlias(@NotNull String externalIdAlias) throws FailedToRemoveExternalIdAlias
Description copied from interface:IdentifiersManager
Removes the external id alias (but not a primary external id) from the model and database. If no nether alias nor internal id found, just silently returns.- Specified by:
removeExternalIdAlias
in interfaceIdentifiersManager<INT>
- Parameters:
externalIdAlias
- the alias to remove.- Returns:
- whether the entry was really removed (from the database).
- Throws:
FailedToRemoveExternalIdAlias
- when could not remove.
-
isExternalIdAlias
public boolean isExternalIdAlias(@NotNull String externalId)
Description copied from interface:IdentifiersManager
Check whether the external id is an alias (but not a primary external id).- Specified by:
isExternalIdAlias
in interfaceIdentifiersManager<INT>
- Parameters:
externalId
- the external id to check.- Returns:
- whether the externalId is an alias
-
internalToExternal
@Nullable public String internalToExternal(@Nullable INT intId)
Description copied from interface:IdentifiersManager
Looks for the external identifier by the given internal one.- Specified by:
internalToExternal
in interfaceIdentifiersManager<INT>
- Parameters:
intId
- internal identifier (case sensitive).- Returns:
- the external identifier if found, or null if not found.
-
internalToExternal
@NotNull public List<String> internalToExternal(@NotNull List<INT> intIds)
Description copied from interface:IdentifiersManager
Looks for the external identifiers by the given internal ones.- Specified by:
internalToExternal
in interfaceIdentifiersManager<INT>
- Parameters:
intIds
- list of internal IDs. Nulls are allowed.- Returns:
- List of external IDs. List size is always equal to initial one. For unknown IDs null will be returned
-
configIdToInternal
@Nullable public INT configIdToInternal(@Nullable String configId)
Description copied from interface:IdentifiersManager
Looks for the internal identifier by the given config id.- Specified by:
configIdToInternal
in interfaceIdentifiersManager<INT>
- Parameters:
configId
- config identifier (case insensitive).- Returns:
- the internal identifier if found, or null if not found.
-
getAllInternalIds
@NotNull public Set<INT> getAllInternalIds()
Description copied from interface:IdentifiersManager
Provides with all known internal identifiers.- Specified by:
getAllInternalIds
in interfaceIdentifiersManager<INT>
- Returns:
- internal identifiers as a set of case-sensitive strings.
-
getAllExternalIds
@NotNull public Set<String> getAllExternalIds()
Description copied from interface:IdentifiersManager
Provides with all known external identifiers.- Specified by:
getAllExternalIds
in interfaceIdentifiersManager<INT>
- Returns:
- external identifiers as a set of case-insensitive strings.
-
getAllExternalIds
@NotNull public Set<String> getAllExternalIds(@NotNull INT intId)
Description copied from interface:IdentifiersManager
Returns all external ids that correspond to theintId
. There is a main one, or probably several aliases.If the
intId
is not found, empty set is returned.- Specified by:
getAllExternalIds
in interfaceIdentifiersManager<INT>
- Parameters:
intId
- internal identifier (case sensitive).- Returns:
- set of corresponding external ids
-
regenerateExternalId
@NotNull public String regenerateExternalId(@Nullable String parentExtId, @NotNull String name, @NotNull String currentExternalId)
Description copied from interface:ExternalIdGenerator
Regenerates an external id based on the given name and (optionally) parent external id. The current external id is not taken into account, so the result can be the current id (but with another case).- Specified by:
regenerateExternalId
in interfaceExternalIdGenerator
- Parameters:
parentExtId
- the parent's external identifier (optional).name
- the user string (name).currentExternalId
- the external id an object currently has- Returns:
- new external id
-
getNewOrChangedEntities
@NotNull public Collection<EntityId<INT>> getNewOrChangedEntities()
- Returns:
- all new entity ids as well as entity ids with modified external id
-
getNewEntities
@NotNull public Set<EntityId<INT>> getNewEntities()
- Returns:
- new entity ids, i.e. those with new internal identifier
-
markRemoved
public void markRemoved(@NotNull EntityId<INT> entityId, @Nullable String originProjectIntId)
Description copied from interface:IdentifiersManager
Marks specified entityId as removed and sets the origin project internal id to the given value- Specified by:
markRemoved
in interfaceIdentifiersManager<INT>
-
resetRemoved
public void resetRemoved(@NotNull Collection<EntityId<INT>> entityIds)
Description copied from interface:IdentifiersManager
Resets removed mark for the given entityId- Specified by:
resetRemoved
in interfaceIdentifiersManager<INT>
-
consumeEntityIds
public void consumeEntityIds(@NotNull Consumer<EntityId<INT>> consumer)
Description copied from interface:IdentifiersManager
Consumes entityIds in this manager- Specified by:
consumeEntityIds
in interfaceIdentifiersManager<INT>
-
-